From b569d6545742ca4f75aeb9e26c9cf11184f697c3 Mon Sep 17 00:00:00 2001 From: brandon_chuang Date: Thu, 3 Aug 2017 11:25:13 +0800 Subject: [PATCH 01/67] Add new model, accton-as5912-54xk. --- .../x86-64-accton-as5912-54xk/.gitignore | 2 + .../x86-64/x86-64-accton-as5912-54xk/Makefile | 1 + .../modules/Makefile | 1 + .../x86-64-accton-as5912-54xk/modules/PKG.yml | 1 + .../modules/builds/.gitignore | 1 + .../modules/builds/Makefile | 6 + .../builds/x86-64-accton-as5912-54xk-fan.c | 485 ++++++ .../builds/x86-64-accton-as5912-54xk-leds.c | 377 +++++ .../builds/x86-64-accton-as5912-54xk-psu.c | 288 ++++ .../builds/x86-64-accton-as5912-54xk-sfp.c | 1315 +++++++++++++++++ .../x86-64-accton-as5912-54xk/onlp/Makefile | 1 + .../x86-64-accton-as5912-54xk/onlp/PKG.yml | 1 + .../onlp/builds/Makefile | 2 + .../onlp/builds/lib/Makefile | 45 + .../onlp/builds/onlpdump/Makefile | 46 + .../onlp/builds/src/.module | 1 + .../onlp/builds/src/Makefile | 9 + .../onlp/builds/src/README | 6 + .../onlp/builds/src/module/auto/make.mk | 9 + .../module/auto/x86_64_accton_as5912_54xk.yml | 50 + .../x86_64_accton_as5912_54xk.x | 14 + .../x86_64_accton_as5912_54xk_config.h | 137 ++ .../x86_64_accton_as5912_54xk_dox.h | 26 + .../x86_64_accton_as5912_54xk_porting.h | 107 ++ .../onlp/builds/src/module/make.mk | 10 + .../onlp/builds/src/module/src/Makefile | 9 + .../onlp/builds/src/module/src/debug.c | 45 + .../onlp/builds/src/module/src/fani.c | 363 +++++ .../onlp/builds/src/module/src/ledi.c | 249 ++++ .../onlp/builds/src/module/src/make.mk | 9 + .../onlp/builds/src/module/src/platform_lib.c | 202 +++ .../onlp/builds/src/module/src/platform_lib.h | 94 ++ .../onlp/builds/src/module/src/psui.c | 186 +++ .../onlp/builds/src/module/src/sfpi.c | 325 ++++ .../onlp/builds/src/module/src/sysi.c | 339 +++++ .../onlp/builds/src/module/src/thermali.c | 128 ++ .../src/x86_64_accton_as5912_54xk_config.c | 80 + .../src/x86_64_accton_as5912_54xk_enums.c | 10 + .../src/x86_64_accton_as5912_54xk_int.h | 12 + .../src/x86_64_accton_as5912_54xk_log.c | 18 + .../src/x86_64_accton_as5912_54xk_log.h | 12 + .../src/x86_64_accton_as5912_54xk_module.c | 24 + .../src/x86_64_accton_as5912_54xk_ucli.c | 50 + .../platform-config/Makefile | 1 + .../platform-config/r0/Makefile | 1 + .../platform-config/r0/PKG.yml | 1 + .../src/lib/x86-64-accton-as5912-54xk-r0.yml | 31 + .../x86_64_accton_as5912_54xk_r0/__init__.py | 80 + 48 files changed, 5210 insertions(+) create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/.gitignore create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/.gitignore create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-fan.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-psu.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-sfp.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/lib/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/onlpdump/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/.module create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/README create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/x86_64_accton_as5912_54xk.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk.x create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_config.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_dox.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_porting.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/debug.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/fani.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/ledi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/psui.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sysi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/thermali.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_config.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_enums.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_int.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_log.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_log.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_module.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_ucli.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/lib/x86-64-accton-as5912-54xk-r0.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/python/x86_64_accton_as5912_54xk_r0/__init__.py diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/.gitignore b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/.gitignore new file mode 100644 index 00000000..c6e33123 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/.gitignore @@ -0,0 +1,2 @@ +*x86*64*accton*as5912*54xk*.mk +onlpdump.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/PKG.yml new file mode 100644 index 00000000..5f257ebe --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as5912-54xk ARCH=amd64 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/.gitignore b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/.gitignore new file mode 100644 index 00000000..a65b4177 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/Makefile new file mode 100644 index 00000000..e41d4d88 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-3.16-lts-x86-64-all:amd64 +KMODULES := $(wildcard *.c) +VENDOR := accton +BASENAME := x86-64-accton-as5912-54xk +ARCH := x86_64 +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-fan.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-fan.c new file mode 100644 index 00000000..af6ff09f --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-fan.c @@ -0,0 +1,485 @@ +/* + * A hwmon driver for the Accton as5912 54xk fan + * + * Copyright (C) 2016 Accton Technology Corporation. + * Brandon Chuang + * + * 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 "as5912_54xk_fan" +#define MAX_FAN_SPEED_RPM 25500 + +static struct as5912_54xk_fan_data *as5912_54xk_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[] = { + 0x0F, /* fan 1-6 present status */ + 0x10, /* fan 1-6 direction(0:B2F 1:F2B) */ + 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 as5912_54xk_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 { + 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, + FAN_MAX_RPM +}; + +/* Define attributes + */ +#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 + +static SENSOR_DEVICE_ATTR(fan_max_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN_MAX_RPM); +#define DECLARE_FAN_MAX_RPM_ATTR(index) &sensor_dev_attr_fan_max_speed_rpm.dev_attr.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 *as5912_54xk_fan_attributes[] = { + /* fan related attributes */ + 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(), + DECLARE_FAN_MAX_RPM_ATTR(), + NULL +}; + +#define FAN_DUTY_CYCLE_REG_MASK 0xF +#define FAN_MAX_DUTY_CYCLE 100 +#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 + +static int as5912_54xk_fan_read_value(struct i2c_client *client, u8 reg) +{ + return i2c_smbus_read_byte_data(client, reg); +} + +static int as5912_54xk_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) +{ + return !!(reg_val & BIT(id)); +} + +static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) +{ + return !(reg_val & BIT(id)); +} + +static u8 is_fan_fault(struct as5912_54xk_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); + + error = kstrtoint(buf, 10, &value); + if (error) + return error; + + if (value < 0 || value > FAN_MAX_DUTY_CYCLE) + return -EINVAL; + + as5912_54xk_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ + as5912_54xk_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); + return count; +} + +static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct as5912_54xk_fan_data *data = as5912_54xk_fan_update_device(dev); + ssize_t ret = 0; + + 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 FAN_MAX_RPM: + ret = sprintf(buf, "%d\n", MAX_FAN_SPEED_RPM); + default: + break; + } + } + + return ret; +} + +static const struct attribute_group as5912_54xk_fan_group = { + .attrs = as5912_54xk_fan_attributes, +}; + +static struct as5912_54xk_fan_data *as5912_54xk_fan_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as5912_54xk_fan_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || + !data->valid) { + int i; + + dev_dbg(&client->dev, "Starting as5912_54xk_fan update\n"); + data->valid = 0; + + /* Update fan data + */ + for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { + int status = as5912_54xk_fan_read_value(client, fan_reg[i]); + + if (status < 0) { + data->valid = 0; + mutex_unlock(&data->update_lock); + 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; + } + + mutex_unlock(&data->update_lock); + + return data; +} + +static int as5912_54xk_fan_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as5912_54xk_fan_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as5912_54xk_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, &as5912_54xk_fan_group); + if (status) { + goto exit_free; + } + + data->hwmon_dev = hwmon_device_register(&client->dev); + 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, &as5912_54xk_fan_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as5912_54xk_fan_remove(struct i2c_client *client) +{ + struct as5912_54xk_fan_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as5912_54xk_fan_group); + + return 0; +} + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; + +static const struct i2c_device_id as5912_54xk_fan_id[] = { + { "as5912_54xk_fan", 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as5912_54xk_fan_id); + +static struct i2c_driver as5912_54xk_fan_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = DRVNAME, + }, + .probe = as5912_54xk_fan_probe, + .remove = as5912_54xk_fan_remove, + .id_table = as5912_54xk_fan_id, + .address_list = normal_i2c, +}; + +static int __init as5912_54xk_fan_init(void) +{ + return i2c_add_driver(&as5912_54xk_fan_driver); +} + +static void __exit as5912_54xk_fan_exit(void) +{ + i2c_del_driver(&as5912_54xk_fan_driver); +} + +module_init(as5912_54xk_fan_init); +module_exit(as5912_54xk_fan_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("as5912_54xk_fan driver"); +MODULE_LICENSE("GPL"); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c new file mode 100644 index 00000000..bfb0ec16 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c @@ -0,0 +1,377 @@ +/* + * A LED driver for the accton_as5912_54xk_led + * + * Copyright (C) 2016 Accton Technology Corporation. + * Brandon Chuang + * + * 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 + +#define DRVNAME "accton_as5912_54xk_led" + +#define DEBUG_MODE 1 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif + +extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +struct accton_as5912_54xk_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]; /* Register value, 0 = RELEASE/DIAG LED, + 1 = FAN/PSU LED, + 2 ~ 4 = SYSTEM LED */ +}; + +static struct accton_as5912_54xk_led_data *ledctl = NULL; + +#define LED_CNTRLER_I2C_ADDRESS (0x60) + +#define LED_TYPE_DIAG_REG_MASK (0x0C) +#define LED_MODE_DIAG_GREEN_VALUE (0x04) +#define LED_MODE_DIAG_AMBER_VALUE (0x08) +#define LED_MODE_DIAG_OFF_VALUE (0x0C) + + +#define LED_TYPE_LOC_REG_MASK (0x10) +#define LED_MODE_LOC_AMBER_VALUE (0x00) +#define LED_MODE_LOC_OFF_VALUE (0x10) + +static const u8 led_reg[] = { + 0x65, /* LOC/DIAG/FAN LED */ + 0x66, /* PSU LED */ +}; + +enum led_type { + LED_TYPE_DIAG, + LED_TYPE_LOC, + LED_TYPE_FAN, + LED_TYPE_PSU1, + LED_TYPE_PSU2 +}; + +/* FAN/PSU/DIAG/RELEASE led mode */ +enum led_light_mode { + LED_MODE_OFF = 0, + LED_MODE_GREEN, + LED_MODE_GREEN_BLINK, + LED_MODE_AMBER, + LED_MODE_AMBER_BLINK, + LED_MODE_RED, + LED_MODE_RED_BLINK, + LED_MODE_BLUE, + LED_MODE_BLUE_BLINK, + LED_MODE_AUTO, + LED_MODE_UNKNOWN +}; + +struct led_type_mode { + enum led_type type; + enum led_light_mode mode; + int type_mask; + int mode_value; +}; + +static struct led_type_mode led_type_mode_data[] = { +{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE}, +{LED_TYPE_LOC, LED_MODE_AMBER, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_AMBER_VALUE}, +{LED_TYPE_DIAG, LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE}, +{LED_TYPE_DIAG, LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE}, +{LED_TYPE_DIAG, LED_MODE_AMBER, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_AMBER_VALUE}, +}; + +static int led_reg_val_to_light_mode(enum led_type type, u8 reg_val) { + int i; + + for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { + if (type != led_type_mode_data[i].type) { + continue; + } + + if ((led_type_mode_data[i].type_mask & reg_val) == + led_type_mode_data[i].mode_value) { + return led_type_mode_data[i].mode; + } + } + + return LED_MODE_UNKNOWN; +} + +static u8 led_light_mode_to_reg_val(enum led_type type, + enum led_light_mode mode, u8 reg_val) { + int i; + + for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { + int type_mask, mode_value; + + if (type != led_type_mode_data[i].type) + continue; + + if (mode != led_type_mode_data[i].mode) + continue; + + type_mask = led_type_mode_data[i].type_mask; + mode_value = led_type_mode_data[i].mode_value; + reg_val = (reg_val & ~type_mask) | mode_value; + } + + return reg_val; +} + +static int accton_as5912_54xk_led_read_value(u8 reg) +{ + return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); +} + +static int accton_as5912_54xk_led_write_value(u8 reg, u8 value) +{ + return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); +} + +static void accton_as5912_54xk_led_update(void) +{ + mutex_lock(&ledctl->update_lock); + + if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) + || !ledctl->valid) { + int i; + + dev_dbg(&ledctl->pdev->dev, "Starting accton_as5912_54xk_led update\n"); + ledctl->valid = 0; + + /* Update LED data + */ + for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { + int status = accton_as5912_54xk_led_read_value(led_reg[i]); + + if (status < 0) { + dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg[i], 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_as5912_54xk_led_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode, + u8 reg, enum led_type type) +{ + int reg_val; + + mutex_lock(&ledctl->update_lock); + reg_val = accton_as5912_54xk_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_as5912_54xk_led_write_value(reg, reg_val); + ledctl->valid = 0; + +exit: + mutex_unlock(&ledctl->update_lock); +} + +static void accton_as7312_54xk_led_auto_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ +} + +static enum led_brightness accton_as7312_54xk_led_auto_get(struct led_classdev *cdev) +{ + return LED_MODE_AUTO; +} + +static void accton_as5912_54xk_led_diag_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as5912_54xk_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG); +} + +static enum led_brightness accton_as5912_54xk_led_diag_get(struct led_classdev *cdev) +{ + accton_as5912_54xk_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); +} + +static enum led_brightness accton_as5912_54xk_led_loc_get(struct led_classdev *cdev) +{ + accton_as5912_54xk_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); +} + +static void accton_as5912_54xk_led_loc_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as5912_54xk_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC); +} + +static struct led_classdev accton_as5912_54xk_leds[] = { + [LED_TYPE_LOC] = { + .name = "accton_as5912_54xk_led::loc", + .default_trigger = "unused", + .brightness_set = accton_as5912_54xk_led_loc_set, + .brightness_get = accton_as5912_54xk_led_loc_get, + .max_brightness = LED_MODE_AMBER, + }, + [LED_TYPE_DIAG] = { + .name = "accton_as5912_54xk_led::diag", + .default_trigger = "unused", + .brightness_set = accton_as5912_54xk_led_diag_set, + .brightness_get = accton_as5912_54xk_led_diag_get, + .max_brightness = LED_MODE_AMBER, + }, + [LED_TYPE_PSU1] = { + .name = "accton_as5912_54xk_led::psu1", + .default_trigger = "unused", + .brightness_set = accton_as7312_54xk_led_auto_set, + .brightness_get = accton_as7312_54xk_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_PSU2] = { + .name = "accton_as5912_54xk_led::psu2", + .default_trigger = "unused", + .brightness_set = accton_as7312_54xk_led_auto_set, + .brightness_get = accton_as7312_54xk_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_FAN] = { + .name = "accton_as5912_54xk_led::fan", + .default_trigger = "unused", + .brightness_set = accton_as7312_54xk_led_auto_set, + .brightness_get = accton_as7312_54xk_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, +}; + +static int accton_as5912_54xk_led_probe(struct platform_device *pdev) +{ + int ret, i; + + for (i = 0; i < ARRAY_SIZE(accton_as5912_54xk_leds); i++) { + ret = led_classdev_register(&pdev->dev, &accton_as5912_54xk_leds[i]); + + if (ret < 0) { + break; + } + } + + /* Check if all LEDs were successfully registered */ + if (i != ARRAY_SIZE(accton_as5912_54xk_leds)){ + int j; + + /* only unregister the LEDs that were successfully registered */ + for (j = 0; j < i; j++) { + led_classdev_unregister(&accton_as5912_54xk_leds[i]); + } + } + + return ret; +} + +static int accton_as5912_54xk_led_remove(struct platform_device *pdev) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(accton_as5912_54xk_leds); i++) { + led_classdev_unregister(&accton_as5912_54xk_leds[i]); + } + + return 0; +} + +static struct platform_driver accton_as5912_54xk_led_driver = { + .probe = accton_as5912_54xk_led_probe, + .remove = accton_as5912_54xk_led_remove, + .driver = { + .name = DRVNAME, + .owner = THIS_MODULE, + }, +}; + +static int __init accton_as5912_54xk_led_init(void) +{ + int ret; + + ret = platform_driver_register(&accton_as5912_54xk_led_driver); + if (ret < 0) { + goto exit; + } + + ledctl = kzalloc(sizeof(struct accton_as5912_54xk_led_data), GFP_KERNEL); + if (!ledctl) { + ret = -ENOMEM; + goto exit_driver; + } + + 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); + goto exit_free; + } + + return 0; + +exit_free: + kfree(ledctl); +exit_driver: + platform_driver_unregister(&accton_as5912_54xk_led_driver); +exit: + return ret; +} + +static void __exit accton_as5912_54xk_led_exit(void) +{ + platform_device_unregister(ledctl->pdev); + platform_driver_unregister(&accton_as5912_54xk_led_driver); + kfree(ledctl); +} + +late_initcall(accton_as5912_54xk_led_init); +module_exit(accton_as5912_54xk_led_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("accton_as5912_54xk_led driver"); +MODULE_LICENSE("GPL"); + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-psu.c new file mode 100644 index 00000000..da4ea68b --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-psu.c @@ -0,0 +1,288 @@ +/* + * An hwmon driver for accton as5912_54xk Power Module + * + * Copyright (C) 2014 Accton Technology Corporation. + * Brandon Chuang + * + * 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 + +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 as5912_54xk_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); +extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; + +/* Each client has this additional data + */ +struct as5912_54xk_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[9]; /* Model name, read from eeprom */ +}; + +static struct as5912_54xk_psu_data *as5912_54xk_psu_update_device(struct device *dev); + +enum as5912_54xk_psu_sysfs_attributes { + PSU_PRESENT, + PSU_MODEL_NAME, + 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_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); +static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); + +static struct attribute *as5912_54xk_psu_attributes[] = { + &sensor_dev_attr_psu_present.dev_attr.attr, + &sensor_dev_attr_psu_model_name.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 sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct as5912_54xk_psu_data *data = as5912_54xk_psu_update_device(dev); + u8 status = 0; + + if (attr->index == PSU_PRESENT) { + status = !(data->status & BIT(1 - data->index));; + } + else { /* PSU_POWER_GOOD */ + status = !!(data->status & BIT(3 - data->index)); + } + + return sprintf(buf, "%d\n", status); +} + +static ssize_t show_model_name(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct as5912_54xk_psu_data *data = as5912_54xk_psu_update_device(dev); + + return sprintf(buf, "%s\n", data->model_name); +} + +static const struct attribute_group as5912_54xk_psu_group = { + .attrs = as5912_54xk_psu_attributes, +}; + +static int as5912_54xk_psu_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as5912_54xk_psu_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as5912_54xk_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, &as5912_54xk_psu_group); + if (status) { + goto exit_free; + } + + data->hwmon_dev = hwmon_device_register(&client->dev); + 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, &as5912_54xk_psu_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as5912_54xk_psu_remove(struct i2c_client *client) +{ + struct as5912_54xk_psu_data *data = i2c_get_clientdata(client); + + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as5912_54xk_psu_group); + kfree(data); + + return 0; +} + +enum psu_index +{ + as5912_54xk_psu1, + as5912_54xk_psu2 +}; + +static const struct i2c_device_id as5912_54xk_psu_id[] = { + { "as5912_54xk_psu1", as5912_54xk_psu1 }, + { "as5912_54xk_psu2", as5912_54xk_psu2 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as5912_54xk_psu_id); + +static struct i2c_driver as5912_54xk_psu_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "as5912_54xk_psu", + }, + .probe = as5912_54xk_psu_probe, + .remove = as5912_54xk_psu_remove, + .id_table = as5912_54xk_psu_id, + .address_list = normal_i2c, +}; + +static int as5912_54xk_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)) { + msleep(10); + continue; + } + + if (unlikely(result != data_len)) { + result = -EIO; + msleep(10); + continue; + } + + result = 0; + break; + } + + return result; +} + +static struct as5912_54xk_psu_data *as5912_54xk_psu_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as5912_54xk_psu_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) + || !data->valid) { + int status; + int power_good = 0; + + dev_dbg(&client->dev, "Starting as5912_54xk update\n"); + + /* Read psu status */ + status = accton_i2c_cpld_read(0x60, 0x2); + + if (status < 0) { + dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); + } + else { + data->status = status; + } + + /* Read model name */ + memset(data->model_name, 0, sizeof(data->model_name)); + power_good = data->status & BIT(3 - data->index); + + if (power_good) { + status = as5912_54xk_psu_read_block(client, 0x20, data->model_name, + ARRAY_SIZE(data->model_name)-1); + + if (status < 0) { + data->model_name[0] = '\0'; + dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr); + } + else { + data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0'; + } + } + + data->last_updated = jiffies; + data->valid = 1; + } + + mutex_unlock(&data->update_lock); + + return data; +} + +static int __init as5912_54xk_psu_init(void) +{ + return i2c_add_driver(&as5912_54xk_psu_driver); +} + +static void __exit as5912_54xk_psu_exit(void) +{ + i2c_del_driver(&as5912_54xk_psu_driver); +} + +module_init(as5912_54xk_psu_init); +module_exit(as5912_54xk_psu_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("as5912_54xk_psu driver"); +MODULE_LICENSE("GPL"); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-sfp.c new file mode 100644 index 00000000..14771b1b --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-sfp.c @@ -0,0 +1,1315 @@ +/* + * SFP driver for accton as5912_54xk sfp + * + * Copyright (C) Brandon Chuang + * + * 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 + +#define DRIVER_NAME "as5912_54xk_sfp" /* Platform dependent */ + +#define DEBUG_MODE 0 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif + +#define NUM_OF_SFP_PORT 54 +#define EEPROM_NAME "sfp_eeprom" +#define EEPROM_SIZE 256 /* 256 byte eeprom */ +#define BIT_INDEX(i) (1ULL << (i)) +#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ +#define I2C_RW_RETRY_COUNT 3 +#define I2C_RW_RETRY_INTERVAL 100 /* ms */ + +#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) +#define SFP_EEPROM_A2_I2C_ADDR (0xA2 >> 1) + +#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 +#define SFF8024_DEVICE_ID_SFP 0x3 +#define SFF8024_DEVICE_ID_QSFP 0xC +#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD +#define SFF8024_DEVICE_ID_QSFP28 0x11 + +#define SFF8472_DIAG_MON_TYPE_ADDR 92 +#define SFF8472_DIAG_MON_TYPE_DDM_MASK 0x40 +#define SFF8472_10G_ETH_COMPLIANCE_ADDR 0x3 +#define SFF8472_10G_BASE_MASK 0xF0 + +#define SFF8436_RX_LOS_ADDR 3 +#define SFF8436_TX_FAULT_ADDR 4 +#define SFF8436_TX_DISABLE_ADDR 86 + +/* Platform dependent +++ */ +#define I2C_ADDR_CPLD1 0x60 +#define I2C_ADDR_CPLD2 0x62 +/* Platform dependent --- */ + +static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_port_type(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count); +static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; +static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); +static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); +extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +enum sfp_sysfs_attributes { + PRESENT, + PRESENT_ALL, + PORT_NUMBER, + PORT_TYPE, + DDM_IMPLEMENTED, + TX_FAULT, + TX_FAULT1, + TX_FAULT2, + TX_FAULT3, + TX_FAULT4, + TX_DISABLE, + TX_DISABLE1, + TX_DISABLE2, + TX_DISABLE3, + TX_DISABLE4, + RX_LOS, + RX_LOS1, + RX_LOS2, + RX_LOS3, + RX_LOS4, + RX_LOS_ALL +}; + +/* SFP/QSFP common attributes for sysfs */ +static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); +static SENSOR_DEVICE_ATTR(sfp_port_type, S_IRUGO, show_port_type, NULL, PORT_TYPE); +static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); +static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); +static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); +static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, sfp_show_tx_rx_status, sfp_set_tx_disable, TX_DISABLE); +static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT); + +/* QSFP attributes for sysfs */ +static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); +static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); +static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); +static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); +static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); +static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); +static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); +static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); +static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); +static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); +static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); +static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); +static struct attribute *qsfp_attributes[] = { + &sensor_dev_attr_sfp_port_number.dev_attr.attr, + &sensor_dev_attr_sfp_port_type.dev_attr.attr, + &sensor_dev_attr_sfp_is_present.dev_attr.attr, + &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, + NULL +}; + +/* SFP msa attributes for sysfs */ +static SENSOR_DEVICE_ATTR(sfp_ddm_implemented, S_IRUGO, sfp_show_ddm_implemented, NULL, DDM_IMPLEMENTED); +static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS_ALL); +static struct attribute *sfp_msa_attributes[] = { + &sensor_dev_attr_sfp_port_number.dev_attr.attr, + &sensor_dev_attr_sfp_port_type.dev_attr.attr, + &sensor_dev_attr_sfp_is_present.dev_attr.attr, + &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, + &sensor_dev_attr_sfp_ddm_implemented.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, + NULL +}; + +/* SFP ddm attributes for sysfs */ +static struct attribute *sfp_ddm_attributes[] = { + NULL +}; + +/* Platform dependent +++ */ +#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) + +enum port_numbers { +as5912_54xk_sfp1, as5912_54xk_sfp2, as5912_54xk_sfp3, as5912_54xk_sfp4, as5912_54xk_sfp5, as5912_54xk_sfp6, as5912_54xk_sfp7, as5912_54xk_sfp8, +as5912_54xk_sfp9, as5912_54xk_sfp10, as5912_54xk_sfp11, as5912_54xk_sfp12, as5912_54xk_sfp13, as5912_54xk_sfp14, as5912_54xk_sfp15, as5912_54xk_sfp16, +as5912_54xk_sfp17, as5912_54xk_sfp18, as5912_54xk_sfp19, as5912_54xk_sfp20, as5912_54xk_sfp21, as5912_54xk_sfp22, as5912_54xk_sfp23, as5912_54xk_sfp24, +as5912_54xk_sfp25, as5912_54xk_sfp26, as5912_54xk_sfp27, as5912_54xk_sfp28, as5912_54xk_sfp29, as5912_54xk_sfp30, as5912_54xk_sfp31, as5912_54xk_sfp32, +as5912_54xk_sfp33, as5912_54xk_sfp34, as5912_54xk_sfp35, as5912_54xk_sfp36, as5912_54xk_sfp37, as5912_54xk_sfp38, as5912_54xk_sfp39, as5912_54xk_sfp40, +as5912_54xk_sfp41, as5912_54xk_sfp42, as5912_54xk_sfp43, as5912_54xk_sfp44, as5912_54xk_sfp45, as5912_54xk_sfp46, as5912_54xk_sfp47, as5912_54xk_sfp48, +as5912_54xk_sfp49, as5912_54xk_sfp50, as5912_54xk_sfp51, as5912_54xk_sfp52, as5912_54xk_sfp53, as5912_54xk_sfp54 +}; + +static const struct i2c_device_id sfp_device_id[] = { +{ "as5912_54xk_sfp1", as5912_54xk_sfp1 }, { "as5912_54xk_sfp2", as5912_54xk_sfp2 }, { "as5912_54xk_sfp3", as5912_54xk_sfp3 }, { "as5912_54xk_sfp4", as5912_54xk_sfp4 }, +{ "as5912_54xk_sfp5", as5912_54xk_sfp5 }, { "as5912_54xk_sfp6", as5912_54xk_sfp6 }, { "as5912_54xk_sfp7", as5912_54xk_sfp7 }, { "as5912_54xk_sfp8", as5912_54xk_sfp8 }, +{ "as5912_54xk_sfp9", as5912_54xk_sfp9 }, { "as5912_54xk_sfp10", as5912_54xk_sfp10 }, { "as5912_54xk_sfp11", as5912_54xk_sfp11 }, { "as5912_54xk_sfp12", as5912_54xk_sfp12 }, +{ "as5912_54xk_sfp13", as5912_54xk_sfp13 }, { "as5912_54xk_sfp14", as5912_54xk_sfp14 }, { "as5912_54xk_sfp15", as5912_54xk_sfp15 }, { "as5912_54xk_sfp16", as5912_54xk_sfp16 }, +{ "as5912_54xk_sfp17", as5912_54xk_sfp17 }, { "as5912_54xk_sfp18", as5912_54xk_sfp18 }, { "as5912_54xk_sfp19", as5912_54xk_sfp19 }, { "as5912_54xk_sfp20", as5912_54xk_sfp20 }, +{ "as5912_54xk_sfp21", as5912_54xk_sfp21 }, { "as5912_54xk_sfp22", as5912_54xk_sfp22 }, { "as5912_54xk_sfp23", as5912_54xk_sfp23 }, { "as5912_54xk_sfp24", as5912_54xk_sfp24 }, +{ "as5912_54xk_sfp25", as5912_54xk_sfp25 }, { "as5912_54xk_sfp26", as5912_54xk_sfp26 }, { "as5912_54xk_sfp27", as5912_54xk_sfp27 }, { "as5912_54xk_sfp28", as5912_54xk_sfp28 }, +{ "as5912_54xk_sfp29", as5912_54xk_sfp29 }, { "as5912_54xk_sfp30", as5912_54xk_sfp30 }, { "as5912_54xk_sfp31", as5912_54xk_sfp31 }, { "as5912_54xk_sfp32", as5912_54xk_sfp32 }, +{ "as5912_54xk_sfp33", as5912_54xk_sfp33 }, { "as5912_54xk_sfp34", as5912_54xk_sfp34 }, { "as5912_54xk_sfp35", as5912_54xk_sfp35 }, { "as5912_54xk_sfp36", as5912_54xk_sfp36 }, +{ "as5912_54xk_sfp37", as5912_54xk_sfp37 }, { "as5912_54xk_sfp38", as5912_54xk_sfp38 }, { "as5912_54xk_sfp39", as5912_54xk_sfp39 }, { "as5912_54xk_sfp40", as5912_54xk_sfp40 }, +{ "as5912_54xk_sfp41", as5912_54xk_sfp41 }, { "as5912_54xk_sfp42", as5912_54xk_sfp42 }, { "as5912_54xk_sfp43", as5912_54xk_sfp43 }, { "as5912_54xk_sfp44", as5912_54xk_sfp44 }, +{ "as5912_54xk_sfp45", as5912_54xk_sfp45 }, { "as5912_54xk_sfp46", as5912_54xk_sfp46 }, { "as5912_54xk_sfp47", as5912_54xk_sfp47 }, { "as5912_54xk_sfp48", as5912_54xk_sfp48 }, +{ "as5912_54xk_sfp49", as5912_54xk_sfp49 }, { "as5912_54xk_sfp50", as5912_54xk_sfp50 }, { "as5912_54xk_sfp51", as5912_54xk_sfp51 }, { "as5912_54xk_sfp52", as5912_54xk_sfp52 }, +{ "as5912_54xk_sfp53", as5912_54xk_sfp53 }, { "as5912_54xk_sfp54", as5912_54xk_sfp54 }, +{ /* LIST END */ } +}; +MODULE_DEVICE_TABLE(i2c, sfp_device_id); +/* Platform dependent --- */ + +/* + * list of valid port types + * note OOM_PORT_TYPE_NOT_PRESENT to indicate no + * module is present in this port + */ +typedef enum oom_driver_port_type_e { + OOM_DRIVER_PORT_TYPE_INVALID, + OOM_DRIVER_PORT_TYPE_NOT_PRESENT, + OOM_DRIVER_PORT_TYPE_SFP, + OOM_DRIVER_PORT_TYPE_SFP_PLUS, + OOM_DRIVER_PORT_TYPE_QSFP, + OOM_DRIVER_PORT_TYPE_QSFP_PLUS, + OOM_DRIVER_PORT_TYPE_QSFP28 +} oom_driver_port_type_t; + +enum driver_type_e { + DRIVER_TYPE_SFP_MSA, + DRIVER_TYPE_SFP_DDM, + DRIVER_TYPE_QSFP +}; + +/* Each client has this additional data + */ +struct eeprom_data { + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + struct bin_attribute bin; /* eeprom data */ +}; + +struct sfp_msa_data { + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u64 status[6]; /* bit0:port0, bit1:port1 and so on */ + /* index 0 => tx_fail + 1 => tx_disable + 2 => rx_loss + 3 => device id + 4 => 10G Ethernet Compliance Codes + to distinguish SFP or SFP+ + 5 => DIAGNOSTIC MONITORING TYPE */ + struct eeprom_data eeprom; +}; + +struct sfp_ddm_data { + struct eeprom_data eeprom; +}; + +struct qsfp_data { + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 status[3]; /* bit0:port0, bit1:port1 and so on */ + /* index 0 => tx_fail + 1 => tx_disable + 2 => rx_loss */ + + u8 device_id; + struct eeprom_data eeprom; +}; + +struct sfp_port_data { + struct mutex update_lock; + enum driver_type_e driver_type; + int port; /* CPLD port index */ + oom_driver_port_type_t port_type; + u64 present; /* present status, bit0:port0, bit1:port1 and so on */ + + struct sfp_msa_data *msa; + struct sfp_ddm_data *ddm; + struct qsfp_data *qsfp; + + struct i2c_client *client; +}; + +static ssize_t show_port_number(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); +} + +/* Platform dependent +++ */ +static struct sfp_port_data *sfp_update_present(struct i2c_client *client) +{ + int i = 0, j = 0, status = -1; + u8 reg; + unsigned short cpld_addr; + struct sfp_port_data *data = i2c_get_clientdata(client); + + DEBUG_PRINT("Starting sfp present status update"); + mutex_lock(&data->update_lock); + data->present = 0; + + /* Read present status of port 1~48(SFP port) */ + for (i = 0; i < 2; i++) { + for (j = 0; j < 3; j++) { + cpld_addr = I2C_ADDR_CPLD1 + i*2; + reg = 0x10+j; + status = accton_i2c_cpld_read(cpld_addr, reg); + + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); + goto exit; + } + + DEBUG_PRINT("Present status = 0x%lx\r\n", data->present); + data->present |= (u64)status << ((i*24) + (j%3)*8); + } + } + + /* Read present status of port 49-52(QSFP port) */ + cpld_addr = I2C_ADDR_CPLD2; + reg = 0x52; + status = accton_i2c_cpld_read(cpld_addr, reg); + + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); + goto exit; + } + else { + data->present |= (u64)(status & 0x3F) << 48; + } + + DEBUG_PRINT("Present status = 0x%lx", data->present); +exit: + mutex_unlock(&data->update_lock); + return (status < 0) ? ERR_PTR(status) : data; +} + +static struct sfp_port_data* sfp_update_tx_rx_status(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + int i = 0, j = 0; + int status = -1; + u8 tx_rx_regs[] = {0x14, 0x16, 0x18, 0x20, 0x22, 0x24, 0x30, 0x32, 0x34}; + + if (time_before(jiffies, data->msa->last_updated + HZ + HZ / 2) && data->msa->valid) { + return data; + } + + DEBUG_PRINT("Starting as5912_54xk sfp tx rx status update"); + mutex_lock(&data->update_lock); + data->msa->valid = 0; + memset(data->msa->status, 0, sizeof(data->msa->status)); + + /* Read status of port 1~48(SFP port) */ + for (i = 0; i < 2; i++) { + for (j = 0; j < ARRAY_SIZE(tx_rx_regs); j++) { + unsigned short cpld_addr = I2C_ADDR_CPLD1 + i*2; + + status = accton_i2c_cpld_read(cpld_addr, tx_rx_regs[j]); + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, tx_rx_regs[i], status); + goto exit; + } + + data->msa->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); + } + } + + data->msa->valid = 1; + data->msa->last_updated = jiffies; + +exit: + mutex_unlock(&data->update_lock); + return (status < 0) ? ERR_PTR(status) : data; +} + +static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + unsigned short cpld_addr = 0; + u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; + long disable; + int error; + u8 tx_disable_regs[] = {0x20, 0x22, 0x24}; + + if (data->driver_type == DRIVER_TYPE_QSFP) { + return qsfp_set_tx_disable(dev, da, buf, count); + } + + error = kstrtol(buf, 10, &disable); + if (error) { + return error; + } + + mutex_lock(&data->update_lock); + + if(data->port < 24) { + cpld_addr = I2C_ADDR_CPLD1; + cpld_reg = tx_disable_regs[data->port / 8]; + cpld_bit = 1 << (data->port % 8); + } + else { /* port 24 ~ 48 */ + cpld_addr = I2C_ADDR_CPLD2; + cpld_reg = tx_disable_regs[(data->port - 24) / 8]; + cpld_bit = 1 << (data->port % 8); + } + + /* Read current status */ + cpld_val = accton_i2c_cpld_read(cpld_addr, cpld_reg); + + /* Update tx_disable status */ + if (disable) { + data->msa->status[1] |= BIT_INDEX(data->port); + cpld_val |= cpld_bit; + } + else { + data->msa->status[1] &= ~BIT_INDEX(data->port); + cpld_val &= ~cpld_bit; + } + + accton_i2c_cpld_write(cpld_addr, cpld_reg, cpld_val); + mutex_unlock(&data->update_lock); + return count; +} + +static int sfp_is_port_present(struct i2c_client *client, int port) +{ + struct sfp_port_data *data = i2c_get_clientdata(client); + + data = sfp_update_present(client); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + return !(data->present & BIT_INDEX(data->port)); /* Platform dependent */ +} + +static ssize_t show_present(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); + + if (PRESENT_ALL == attr->index) { + int i; + u8 values[7] = {0}; + struct sfp_port_data *data = sfp_update_present(client); + + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + for (i = 0; i < ARRAY_SIZE(values); i++) { + values[i] = ~(u8)(data->present >> (i * 8)); + } + + /* Return values 1 -> 54 in order */ + return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], + values[3], values[4], values[5], + values[6] & 0x3F); + } + else { + struct sfp_port_data *data = i2c_get_clientdata(client); + int present = sfp_is_port_present(client, data->port); + + if (IS_ERR_VALUE(present)) { + return present; + } + + /* PRESENT */ + return sprintf(buf, "%d\n", present); + } +} +/* Platform dependent --- */ + +static struct sfp_port_data *sfp_update_port_type(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + u8 buf = 0; + int status; + + mutex_lock(&data->update_lock); + + switch (data->driver_type) { + case DRIVER_TYPE_SFP_MSA: + { + status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); + if (unlikely(status < 0)) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + if (buf != SFF8024_DEVICE_ID_SFP) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + status = sfp_eeprom_read(client, SFF8472_10G_ETH_COMPLIANCE_ADDR, &buf, sizeof(buf)); + if (unlikely(status < 0)) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + DEBUG_PRINT("sfp port type (0x3) data = (0x%x)", buf); + data->port_type = buf & SFF8472_10G_BASE_MASK ? OOM_DRIVER_PORT_TYPE_SFP_PLUS : OOM_DRIVER_PORT_TYPE_SFP; + break; + } + case DRIVER_TYPE_QSFP: + { + status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); + if (unlikely(status < 0)) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + DEBUG_PRINT("qsfp port type (0x0) buf = (0x%x)", buf); + switch (buf) { + case SFF8024_DEVICE_ID_QSFP: + data->port_type = OOM_DRIVER_PORT_TYPE_QSFP; + break; + case SFF8024_DEVICE_ID_QSFP_PLUS: + data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; + break; + case SFF8024_DEVICE_ID_QSFP28: + data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; + break; + default: + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + break; + } + default: + break; + } + + mutex_unlock(&data->update_lock); + return data; +} + +static ssize_t show_port_type(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + int present = sfp_is_port_present(client, data->port); + + if (IS_ERR_VALUE(present)) { + return present; + } + + if (!present) { + return sprintf(buf, "%d\n", OOM_DRIVER_PORT_TYPE_NOT_PRESENT); + } + + sfp_update_port_type(dev); + return sprintf(buf, "%d\n", data->port_type); +} + +static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + int i, status = -1; + u8 buf = 0; + u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; + + if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { + return data; + } + + DEBUG_PRINT("Starting sfp tx rx status update"); + mutex_lock(&data->update_lock); + data->qsfp->valid = 0; + memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); + + /* Notify device to update tx fault/ tx disable/ rx los status */ + for (i = 0; i < ARRAY_SIZE(reg); i++) { + status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); + if (unlikely(status < 0)) { + goto exit; + } + } + msleep(200); + + /* Read actual tx fault/ tx disable/ rx los status */ + for (i = 0; i < ARRAY_SIZE(reg); i++) { + status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); + if (unlikely(status < 0)) { + goto exit; + } + + DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); + data->qsfp->status[i] = (buf & 0xF); + } + + data->qsfp->valid = 1; + data->qsfp->last_updated = jiffies; + +exit: + mutex_unlock(&data->update_lock); + return (status < 0) ? ERR_PTR(status) : data; +} + +static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + int present; + u8 val = 0; + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + + present = sfp_is_port_present(client, data->port); + if (IS_ERR_VALUE(present)) { + return present; + } + + if (present == 0) { + /* port is not present */ + return -ENXIO; + } + + data = qsfp_update_tx_rx_status(dev); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + switch (attr->index) { + case TX_FAULT: + val = !!(data->qsfp->status[2] & 0xF); + break; + case TX_FAULT1: + case TX_FAULT2: + case TX_FAULT3: + case TX_FAULT4: + val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); + break; + case TX_DISABLE: + val = data->qsfp->status[1] & 0xF; + break; + case TX_DISABLE1: + case TX_DISABLE2: + case TX_DISABLE3: + case TX_DISABLE4: + val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); + break; + case RX_LOS: + val = !!(data->qsfp->status[0] & 0xF); + break; + case RX_LOS1: + case RX_LOS2: + case RX_LOS3: + case RX_LOS4: + val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); + break; + default: + break; + } + + return sprintf(buf, "%d\n", val); +} + +static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + long disable; + int status; + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + + status = sfp_is_port_present(client, data->port); + if (IS_ERR_VALUE(status)) { + return status; + } + + if (!status) { + /* port is not present */ + return -ENXIO; + } + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + + data = qsfp_update_tx_rx_status(dev); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + mutex_lock(&data->update_lock); + + if (attr->index == TX_DISABLE) { + data->qsfp->status[1] = disable & 0xF; + } + else {/* TX_DISABLE1 ~ TX_DISABLE4*/ + if (disable) { + data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); + } + else { + data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); + } + } + + DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); + status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); + if (unlikely(status < 0)) { + count = status; + } + + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, + char *buf) +{ + int status; + char ddm; + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + + status = sfp_is_port_present(client, data->port); + if (IS_ERR_VALUE(status)) { + return status; + } + + if (status == 0) { + /* port is not present */ + return -ENODEV; + } + + status = sfp_eeprom_read(client, SFF8472_DIAG_MON_TYPE_ADDR, &ddm, sizeof(ddm)); + if (unlikely(status < 0)) { + return status; + } + + return sprintf(buf, "%d\n", !!(ddm & SFF8472_DIAG_MON_TYPE_DDM_MASK)); +} + +/* Platform dependent +++ */ +static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + u8 val = 0, index = 0; + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + + if (data->driver_type == DRIVER_TYPE_QSFP) { + return qsfp_show_tx_rx_status(dev, da, buf); + } + + data = sfp_update_tx_rx_status(dev); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + if(attr->index == RX_LOS_ALL) { + int i = 0; + u8 values[6] = {0}; + + for (i = 0; i < ARRAY_SIZE(values); i++) { + values[i] = (u8)(data->msa->status[2] >> (i * 8)); + } + + /** Return values 1 -> 48 in order */ + return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], + values[3], values[4], values[5]); + } + + switch (attr->index) { + case TX_FAULT: + index = 0; + break; + case TX_DISABLE: + index = 1; + break; + case RX_LOS: + index = 2; + break; + default: + return 0; + } + + val = !!(data->msa->status[index] & BIT_INDEX(data->port)); + return sprintf(buf, "%d\n", val); +} +/* Platform dependent --- */ +static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, + int data_len) +{ +#if USE_I2C_BLOCK_READ + int status, retry = I2C_RW_RETRY_COUNT; + + if (data_len > I2C_SMBUS_BLOCK_MAX) { + data_len = I2C_SMBUS_BLOCK_MAX; + } + + while (retry) { + status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + return status; + } + + return data_len; +#else + int status, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, command, *data); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + return status; + } + + return 1; +#endif + + +} + +static ssize_t sfp_port_write(struct sfp_port_data *data, + const char *buf, loff_t off, size_t count) +{ + ssize_t retval = 0; + + if (unlikely(!count)) { + return count; + } + + /* + * Write data to chip, protecting against concurrent updates + * from this host, but not from other I2C masters. + */ + mutex_lock(&data->update_lock); + + while (count) { + ssize_t status; + + status = sfp_eeprom_write(data->client, off, buf, count); + if (status <= 0) { + if (retval == 0) { + retval = status; + } + break; + } + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&data->update_lock); + return retval; +} + + +static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + int present; + struct sfp_port_data *data; + DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); + data = dev_get_drvdata(container_of(kobj, struct device, kobj)); + + present = sfp_is_port_present(data->client, data->port); + if (IS_ERR_VALUE(present)) { + return present; + } + + if (present == 0) { + /* port is not present */ + return -ENODEV; + } + + return sfp_port_write(data, buf, off, count); +} + +static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, + int data_len) +{ +#if USE_I2C_BLOCK_READ + int status, retry = I2C_RW_RETRY_COUNT; + + if (data_len > I2C_SMBUS_BLOCK_MAX) { + data_len = I2C_SMBUS_BLOCK_MAX; + } + + while (retry) { + status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + goto abort; + } + if (unlikely(status != data_len)) { + status = -EIO; + goto abort; + } + + //result = data_len; + +abort: + return status; +#else + int status, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, command); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); + goto abort; + } + + *data = (u8)status; + status = 1; + +abort: + return status; +#endif +} + +static ssize_t sfp_port_read(struct sfp_port_data *data, + char *buf, loff_t off, size_t count) +{ + ssize_t retval = 0; + + if (unlikely(!count)) { + DEBUG_PRINT("Count = 0, return"); + return count; + } + + /* + * Read data from chip, protecting against concurrent updates + * from this host, but not from other I2C masters. + */ + mutex_lock(&data->update_lock); + + while (count) { + ssize_t status; + + status = sfp_eeprom_read(data->client, off, buf, count); + if (status <= 0) { + if (retval == 0) { + retval = status; + } + break; + } + + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&data->update_lock); + return retval; + +} + +static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + int present; + struct sfp_port_data *data; + DEBUG_PRINT("offset = (%d), count = (%d)", off, count); + data = dev_get_drvdata(container_of(kobj, struct device, kobj)); + + present = sfp_is_port_present(data->client, data->port); + if (IS_ERR_VALUE(present)) { + return present; + } + + if (present == 0) { + /* port is not present */ + return -ENODEV; + } + + return sfp_port_read(data, buf, off, count); +} + +static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) +{ + int err; + + sysfs_bin_attr_init(eeprom); + eeprom->attr.name = EEPROM_NAME; + eeprom->attr.mode = S_IWUSR | S_IRUGO; + eeprom->read = sfp_bin_read; + eeprom->write = sfp_bin_write; + eeprom->size = EEPROM_SIZE; + + /* Create eeprom file */ + err = sysfs_create_bin_file(kobj, eeprom); + if (err) { + return err; + } + + return 0; +} + +static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) +{ + sysfs_remove_bin_file(kobj, eeprom); + return 0; +} + +static const struct attribute_group sfp_msa_group = { + .attrs = sfp_msa_attributes, +}; + +static int sfp_i2c_check_functionality(struct i2c_client *client) +{ +#if USE_I2C_BLOCK_READ + return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); +#else + return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); +#endif +} + +static int sfp_msa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, + struct sfp_msa_data **data) +{ + int status; + struct sfp_msa_data *msa; + + if (!sfp_i2c_check_functionality(client)) { + status = -EIO; + goto exit; + } + + msa = kzalloc(sizeof(struct sfp_msa_data), GFP_KERNEL); + if (!msa) { + status = -ENOMEM; + goto exit; + } + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &sfp_msa_group); + if (status) { + goto exit_free; + } + + /* init eeprom */ + status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin); + if (status) { + goto exit_remove; + } + + *data = msa; + dev_info(&client->dev, "sfp msa '%s'\n", client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); +exit_free: + kfree(msa); +exit: + + return status; +} + +static const struct attribute_group sfp_ddm_group = { + .attrs = sfp_ddm_attributes, +}; + +static int sfp_ddm_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, + struct sfp_ddm_data **data) +{ + int status; + struct sfp_ddm_data *ddm; + + if (!sfp_i2c_check_functionality(client)) { + status = -EIO; + goto exit; + } + + ddm = kzalloc(sizeof(struct sfp_ddm_data), GFP_KERNEL); + if (!ddm) { + status = -ENOMEM; + goto exit; + } + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &sfp_ddm_group); + if (status) { + goto exit_free; + } + + /* init eeprom */ + status = sfp_sysfs_eeprom_init(&client->dev.kobj, &ddm->eeprom.bin); + if (status) { + goto exit_remove; + } + + *data = ddm; + dev_info(&client->dev, "sfp ddm '%s'\n", client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); +exit_free: + kfree(ddm); +exit: + + return status; +} + +static const struct attribute_group qsfp_group = { + .attrs = qsfp_attributes, +}; + +static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, + struct qsfp_data **data) +{ + int status; + struct qsfp_data *qsfp; + + if (!sfp_i2c_check_functionality(client)) { + status = -EIO; + goto exit; + } + + qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); + if (!qsfp) { + status = -ENOMEM; + goto exit; + } + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &qsfp_group); + if (status) { + goto exit_free; + } + + /* init eeprom */ + status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); + if (status) { + goto exit_remove; + } + + *data = qsfp; + dev_info(&client->dev, "qsfp '%s'\n", client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &qsfp_group); +exit_free: + kfree(qsfp); +exit: + + return status; +} + +/* Platform dependent +++ */ +static int sfp_device_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct sfp_port_data *data = NULL; + + data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); + if (!data) { + return -ENOMEM; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->port = dev_id->driver_data; + data->client = client; + + if (dev_id->driver_data >= as5912_54xk_sfp1 && dev_id->driver_data <= as5912_54xk_sfp48) { + if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { + data->driver_type = DRIVER_TYPE_SFP_MSA; + return sfp_msa_probe(client, dev_id, &data->msa); + } + else if (client->addr == SFP_EEPROM_A2_I2C_ADDR) { + data->driver_type = DRIVER_TYPE_SFP_DDM; + return sfp_ddm_probe(client, dev_id, &data->ddm); + } + } + else { /* as5912_54xk_sfp49 ~ as5912_54xk_sfp54 */ + if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { + data->driver_type = DRIVER_TYPE_QSFP; + return qsfp_probe(client, dev_id, &data->qsfp); + } + } + + return -ENODEV; +} +/* Platform dependent --- */ + +static int sfp_msa_remove(struct i2c_client *client, struct sfp_msa_data *data) +{ + sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); + sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); + kfree(data); + return 0; +} + +static int sfp_ddm_remove(struct i2c_client *client, struct sfp_ddm_data *data) +{ + sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); + sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); + kfree(data); + return 0; +} + +static int qfp_remove(struct i2c_client *client, struct qsfp_data *data) +{ + sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); + sysfs_remove_group(&client->dev.kobj, &qsfp_group); + kfree(data); + return 0; +} + +static int sfp_device_remove(struct i2c_client *client) +{ + struct sfp_port_data *data = i2c_get_clientdata(client); + + switch (data->driver_type) { + case DRIVER_TYPE_SFP_MSA: + return sfp_msa_remove(client, data->msa); + case DRIVER_TYPE_SFP_DDM: + return sfp_ddm_remove(client, data->ddm); + case DRIVER_TYPE_QSFP: + return qfp_remove(client, data->qsfp); + } + + return 0; +} + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; + +static struct i2c_driver sfp_driver = { + .driver = { + .name = DRIVER_NAME, + }, + .probe = sfp_device_probe, + .remove = sfp_device_remove, + .id_table = sfp_device_id, + .address_list = normal_i2c, +}; + +static int __init sfp_init(void) +{ + return i2c_add_driver(&sfp_driver); +} + +static void __exit sfp_exit(void) +{ + i2c_del_driver(&sfp_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("accton as5912_54xk_sfp driver"); +MODULE_LICENSE("GPL"); + +late_initcall(sfp_init); +module_exit(sfp_exit); + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/PKG.yml new file mode 100644 index 00000000..f712c797 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-accton-as5912-54xk ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/Makefile new file mode 100644 index 00000000..e7437cb2 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/lib/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/lib/Makefile new file mode 100644 index 00000000..02c4a0cd --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/lib/Makefile @@ -0,0 +1,45 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +############################################################ +include $(ONL)/make/config.amd64.mk + +MODULE := libonlp-x86-64-accton-as5912-54xk +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF x86_64_accton_as5912_54xk onlplib +DEPENDMODULE_HEADERS := sff + +include $(BUILDER)/dependmodules.mk + +SHAREDLIB := libonlp-x86-64-accton-as5912-54xk.so +$(SHAREDLIB)_TARGETS := $(ALL_TARGETS) +include $(BUILDER)/so.mk +.DEFAULT_GOAL := $(SHAREDLIB) + +GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -fPIC +GLOBAL_LINK_LIBS += -lpthread + +include $(BUILDER)/targets.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/onlpdump/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/onlpdump/Makefile new file mode 100644 index 00000000..5435cc0d --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/onlpdump/Makefile @@ -0,0 +1,46 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ +include $(ONL)/make/config.amd64.mk + +.DEFAULT_GOAL := onlpdump + +MODULE := onlpdump +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF onlp x86_64_accton_as5912_54xk onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS + +include $(BUILDER)/dependmodules.mk + +BINARY := onlpdump +$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS) +include $(BUILDER)/bin.mk + +GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1 +GLOBAL_LINK_LIBS += -lpthread -lm + +include $(BUILDER)/targets.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/.module b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/.module new file mode 100644 index 00000000..9cfbcabe --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/.module @@ -0,0 +1 @@ +name: x86_64_accton_as5912_54xk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/Makefile new file mode 100644 index 00000000..579d1811 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +include ../../init.mk +MODULE := x86_64_accton_as5912_54xk +AUTOMODULE := x86_64_accton_as5912_54xk +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/README b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/README new file mode 100644 index 00000000..0148c29c --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/README @@ -0,0 +1,6 @@ +############################################################################### +# +# x86_64_accton_as5912_54xk README +# +############################################################################### + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/make.mk new file mode 100644 index 00000000..491f4807 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# x86_64_accton_as5912_54xk Autogeneration +# +############################################################################### +x86_64_accton_as5912_54xk_AUTO_DEFS := module/auto/x86_64_accton_as5912_54xk.yml +x86_64_accton_as5912_54xk_AUTO_DIRS := module/inc/x86_64_accton_as5912_54xk module/src +include $(BUILDER)/auto.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/x86_64_accton_as5912_54xk.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/x86_64_accton_as5912_54xk.yml new file mode 100644 index 00000000..8898ff3d --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/x86_64_accton_as5912_54xk.yml @@ -0,0 +1,50 @@ +############################################################################### +# +# x86_64_accton_as5912_54xk Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- x86_64_accton_as5912_54xk_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB +- x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 +- x86_64_accton_as5912_54xk_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_as5912_54xk_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_accton_as5912_54xk_config + + portingmacro: + x86_64_accton_as5912_54xk: + macros: + - malloc + - free + - memset + - memcpy + - strncpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk.x b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk.x new file mode 100644 index 00000000..9ec22128 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk.x @@ -0,0 +1,14 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_config.h b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_config.h new file mode 100644 index 00000000..00d1559d --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_config.h @@ -0,0 +1,137 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5912_54xk Configuration Header + * + * @addtogroup x86_64_accton_as5912_54xk-config + * @{ + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5912_54xk_CONFIG_H__ +#define __x86_64_accton_as5912_54xk_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef x86_64_accton_as5912_54xk_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * x86_64_accton_as5912_54xk_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef x86_64_accton_as5912_54xk_CONFIG_INCLUDE_LOGGING +#define x86_64_accton_as5912_54xk_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT +#define x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT +#define x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB +#define x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB +#endif + +/** + * x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI +#define x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * + * Assume chassis fan direction is the same as the PSU fan direction. */ + + +#ifndef x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct x86_64_accton_as5912_54xk_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_accton_as5912_54xk_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_accton_as5912_54xk_config_settings table. */ +extern x86_64_accton_as5912_54xk_config_settings_t x86_64_accton_as5912_54xk_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_accton_as5912_54xk_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_accton_as5912_54xk_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_accton_as5912_54xk_porting.h" + +#endif /* __x86_64_accton_as5912_54xk_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_dox.h b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_dox.h new file mode 100644 index 00000000..8c74d2f9 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_accton_as5912_54xk Doxygen Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5912_54xk_DOX_H__ +#define __x86_64_accton_as5912_54xk_DOX_H__ + +/** + * @defgroup x86_64_accton_as5912_54xk x86_64_accton_as5912_54xk - x86_64_accton_as5912_54xk Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_accton_as5912_54xk-x86_64_accton_as5912_54xk Public Interface + * @defgroup x86_64_accton_as5912_54xk-config Compile Time Configuration + * @defgroup x86_64_accton_as5912_54xk-porting Porting Macros + * + * @} + * + */ + +#endif /* __x86_64_accton_as5912_54xk_DOX_H__ */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_porting.h b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_porting.h new file mode 100644 index 00000000..60fb0289 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/inc/x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_porting.h @@ -0,0 +1,107 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5912_54xk Porting Macros. + * + * @addtogroup x86_64_accton_as5912_54xk-porting + * @{ + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5912_54xk_PORTING_H__ +#define __x86_64_accton_as5912_54xk_PORTING_H__ + + +/* */ +#if x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef x86_64_accton_as5912_54xk_MALLOC + #if defined(GLOBAL_MALLOC) + #define x86_64_accton_as5912_54xk_MALLOC GLOBAL_MALLOC + #elif x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5912_54xk_MALLOC malloc + #else + #error The macro x86_64_accton_as5912_54xk_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5912_54xk_FREE + #if defined(GLOBAL_FREE) + #define x86_64_accton_as5912_54xk_FREE GLOBAL_FREE + #elif x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5912_54xk_FREE free + #else + #error The macro x86_64_accton_as5912_54xk_FREE is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5912_54xk_MEMSET + #if defined(GLOBAL_MEMSET) + #define x86_64_accton_as5912_54xk_MEMSET GLOBAL_MEMSET + #elif x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5912_54xk_MEMSET memset + #else + #error The macro x86_64_accton_as5912_54xk_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5912_54xk_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define x86_64_accton_as5912_54xk_MEMCPY GLOBAL_MEMCPY + #elif x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5912_54xk_MEMCPY memcpy + #else + #error The macro x86_64_accton_as5912_54xk_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5912_54xk_STRNCPY + #if defined(GLOBAL_STRNCPY) + #define x86_64_accton_as5912_54xk_STRNCPY GLOBAL_STRNCPY + #elif x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5912_54xk_STRNCPY strncpy + #else + #error The macro x86_64_accton_as5912_54xk_STRNCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5912_54xk_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define x86_64_accton_as5912_54xk_VSNPRINTF GLOBAL_VSNPRINTF + #elif x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5912_54xk_VSNPRINTF vsnprintf + #else + #error The macro x86_64_accton_as5912_54xk_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5912_54xk_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define x86_64_accton_as5912_54xk_SNPRINTF GLOBAL_SNPRINTF + #elif x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5912_54xk_SNPRINTF snprintf + #else + #error The macro x86_64_accton_as5912_54xk_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5912_54xk_STRLEN + #if defined(GLOBAL_STRLEN) + #define x86_64_accton_as5912_54xk_STRLEN GLOBAL_STRLEN + #elif x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5912_54xk_STRLEN strlen + #else + #error The macro x86_64_accton_as5912_54xk_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __x86_64_accton_as5912_54xk_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/make.mk new file mode 100644 index 00000000..18db6fa2 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/make.mk @@ -0,0 +1,10 @@ +############################################################################### +# +# +# +############################################################################### +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_accton_as5912_54xk_INCLUDES := -I $(THIS_DIR)inc +x86_64_accton_as5912_54xk_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_accton_as5912_54xk_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5912_54xk ucli:x86_64_accton_as5912_54xk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/Makefile new file mode 100644 index 00000000..0fe77db8 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# Local source generation targets. +# +############################################################################### + +ucli: + @../../../../tools/uclihandlers.py x86_64_accton_as5912_54xk_ucli.c + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/debug.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/debug.c new file mode 100644 index 00000000..d9d9ae6c --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/debug.c @@ -0,0 +1,45 @@ +#include "x86_64_accton_as5912_54xk_int.h" + +#if x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEBUG == 1 + +#include + +static char help__[] = + "Usage: debug [options]\n" + " -c CPLD Versions\n" + " -h Help\n" + ; + +int +x86_64_accton_as5912_54xk_debug_main(int argc, char* argv[]) +{ + int c = 0; + int help = 0; + int rv = 0; + + while( (c = getopt(argc, argv, "ch")) != -1) { + switch(c) + { + case 'c': c = 1; break; + case 'h': help = 1; rv = 0; break; + default: help = 1; rv = 1; break; + } + + } + + if(help || argc == 1) { + printf("%s", help__); + return rv; + } + + if(c) { + printf("Not implemented.\n"); + } + + + return 0; +} + +#endif + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/fani.c new file mode 100644 index 00000000..9eb030ce --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/fani.c @@ -0,0 +1,363 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Fan Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +#define PSU_PREFIX_PATH "/sys/bus/i2c/devices/" + +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 MAX_FAN_SPEED 25500 +#define MAX_PSU_FAN_SPEED 25500 + +#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_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\ + 0,\ + 0,\ + ONLP_FAN_MODE_INVALID,\ + } + +/* Static fan information */ +onlp_fan_info_t finfo[] = { + { }, /* Not used */ + CHASSIS_FAN_INFO(1), + CHASSIS_FAN_INFO(2), + CHASSIS_FAN_INFO(3), + CHASSIS_FAN_INFO(4), + CHASSIS_FAN_INFO(5), + CHASSIS_FAN_INFO(6), + 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, ret; + char path[64] = {0}; + + /* get fan present status + */ + ret = onlp_file_read_int(&value, "%s""fan%d_present", FAN_BOARD_PATH, fid); + if (ret < 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) + */ + ret = onlp_file_read_int(&value, "%s""fan%d_fault", FAN_BOARD_PATH, fid); + if (ret < 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) + */ + ret = onlp_file_read_int(&value, "%s""fan%d_direction", FAN_BOARD_PATH, fid); + if (ret < 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_F2B : ONLP_FAN_STATUS_B2F; + + + /* get front fan speed + */ + ret = onlp_file_read_int(&value, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 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 + */ + ret = onlp_file_read_int(&value, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 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 + */ + ret = onlp_file_read_int(&value, "%s""fan_max_speed_rpm", FAN_BOARD_PATH); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + info->percentage = (info->rpm * 100)/value; + + return ONLP_STATUS_OK; +} + +static uint32_t +_onlp_get_fan_direction_on_psu(void) +{ + /* Try to read direction from PSU1. + * If PSU1 is not valid, read from PSU2 + */ + int i = 0; + + for (i = PSU1_ID; i <= PSU2_ID; i++) { + psu_type_t psu_type; + psu_type = get_psu_type(i, NULL, 0); + + if (psu_type == PSU_TYPE_UNKNOWN) { + continue; + } + + if (PSU_TYPE_AC_F2B == psu_type) { + return ONLP_FAN_STATUS_F2B; + } + else { + return ONLP_FAN_STATUS_B2F; + } + } + + 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 fan direction + */ + info->status |= _onlp_get_fan_direction_on_psu(); + + /* get fan fault status + */ + if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_fault", &val) == ONLP_STATUS_OK) { + info->status |= (val > 0) ? ONLP_FAN_STATUS_FAILED : 0; + } + + /* get fan speed + */ + if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == ONLP_STATUS_OK) { + info->rpm = val; + info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED; + } + + 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_fan1_duty_cycle_percentage", p); + case FAN_1_ON_PSU_2: + return psu_ym2651y_pmbus_info_set(PSU2_ID, "psu_fan1_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; + } + + if (onlp_file_write_integer(path, p) < 0) { + AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + + +/* + * This function sets the fan speed of the given OID as per + * the predefined ONLP fan speed modes: off, slow, normal, fast, max. + * + * Interpretation of these modes is up to the platform. + * + */ +int +onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function sets the fan direction of the given OID. + * + * This function is only relevant if the fan OID supports both direction + * capabilities. + * + * This function is optional unless the functionality is available. + */ +int +onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * Generic fan ioctl. Optional. + */ +int +onlp_fani_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/ledi.c new file mode 100644 index 00000000..b1523cb0 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/ledi.c @@ -0,0 +1,249 @@ +/************************************************************ + * + * + * 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 "platform_lib.h" + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_LED(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +#define LED_FORMAT "/sys/class/leds/accton_as5912_54xk_led::%s/brightness" + +/* LED related data + */ +enum led_light_mode { /*must be the same with the definition @ kernel driver */ + LED_MODE_OFF = 0, + LED_MODE_GREEN, + LED_MODE_GREEN_BLINK, + LED_MODE_AMBER, + LED_MODE_AMBER_BLINK, + LED_MODE_RED, + LED_MODE_RED_BLINK, + LED_MODE_BLUE, + LED_MODE_BLUE_BLINK, + LED_MODE_AUTO, + LED_MODE_UNKNOWN +}; + +enum onlp_led_id +{ + LED_LOC = 1, + LED_DIAG, + LED_PSU1, + LED_PSU2, + LED_FAN, +}; + +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_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_LOC, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, +{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_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 *leds[] = /* must map with onlp_led_id */ +{ + NULL, + "loc", + "diag", + "psu1", + "psu2", + "fan" +}; + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t linfo[] = +{ + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_LOC), "Chassis LED 1 (LOC LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE, + }, + { + { ONLP_LED_ID_CREATE(LED_DIAG), "Chassis LED 2 (DIAG LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU1), "Chassis LED 3 (PSU1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU2), "Chassis LED 4 (PSU2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN), "Chassis LED 5 (FAN LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | 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) +{ + /* + * Turn off the LOCATION and DIAG LEDs at startup + */ + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_LOC), ONLP_LED_MODE_OFF); + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_DIAG), ONLP_LED_MODE_OFF); + + return ONLP_STATUS_OK; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int lid, value; + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[ONLP_OID_ID_GET(id)]; + + /* Get LED mode */ + if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) { + DEBUG_PRINT("Unable to read status from file (%s)", leds[lid]); + 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 path[64] = {0}; + + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + sprintf(path, LED_FORMAT, leds[lid]); + + if (onlp_file_write_integer(path, onlp_to_driver_led_mode(lid , mode)) < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +/* + * Generic LED ioctl interface. + */ +int +onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/make.mk new file mode 100644 index 00000000..c1c8d7ec --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### + +LIBRARY := x86_64_accton_as5912_54xk +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.c new file mode 100644 index 00000000..b14867bd --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.c @@ -0,0 +1,202 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include "platform_lib.h" + +#define PSU_NODE_MAX_PATH_LEN 64 + +int _onlp_file_write(char *filename, char *buffer, int buf_size, int data_len) +{ + int fd; + int len; + + if ((buffer == NULL) || (buf_size < 0)) { + return -1; + } + + if ((fd = open(filename, O_WRONLY, S_IWUSR)) == -1) { + return -1; + } + + if ((len = write(fd, buffer, buf_size)) < 0) { + close(fd); + return -1; + } + + if ((close(fd) == -1)) { + return -1; + } + + if ((len > buf_size) || (data_len != 0 && len != data_len)) { + return -1; + } + + return 0; +} + +int onlp_file_write_integer(char *filename, int value) +{ + char buf[8] = {0}; + sprintf(buf, "%d", value); + + return _onlp_file_write(filename, buf, (int)strlen(buf), 0); +} + +int onlp_file_read_binary(char *filename, char *buffer, int buf_size, int data_len) +{ + int fd; + int len; + + if ((buffer == NULL) || (buf_size < 0)) { + return -1; + } + + if ((fd = open(filename, O_RDONLY)) == -1) { + return -1; + } + + if ((len = read(fd, buffer, buf_size)) < 0) { + close(fd); + return -1; + } + + if ((close(fd) == -1)) { + return -1; + } + + if ((len > buf_size) || (data_len != 0 && len != data_len)) { + return -1; + } + + return 0; +} + +int onlp_file_read_string(char *filename, char *buffer, int buf_size, int data_len) +{ + int ret; + + if (data_len >= buf_size) { + return -1; + } + + ret = onlp_file_read_binary(filename, buffer, buf_size-1, data_len); + + if (ret == 0) { + buffer[buf_size-1] = '\0'; + } + + return ret; +} + +#define I2C_PSU_MODEL_NAME_LEN 9 +#define I2C_PSU_FAN_DIR_LEN 3 + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len) +{ + char *node = NULL; + char model_name[I2C_PSU_MODEL_NAME_LEN + 1] = {0}; + char fan_dir[I2C_PSU_FAN_DIR_LEN + 1] = {0}; + + /* Check AC model name */ + node = (id == PSU1_ID) ? PSU1_AC_HWMON_NODE(psu_model_name) : PSU2_AC_HWMON_NODE(psu_model_name); + + if (onlp_file_read_string(node, model_name, sizeof(model_name), 0) != 0) { + return PSU_TYPE_UNKNOWN; + } + + if (strncmp(model_name, "YM-2651Y", strlen("YM-2651Y")) != 0) { + return PSU_TYPE_UNKNOWN; + } + + if (modelname) { + strncpy(modelname, model_name, modelname_len-1); + } + + node = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_fan_dir) : PSU2_AC_PMBUS_NODE(psu_fan_dir); + + if (onlp_file_read_string(node, fan_dir, sizeof(fan_dir), 0) != 0) { + return PSU_TYPE_UNKNOWN; + } + + if (strncmp(fan_dir, "F2B", strlen("F2B")) == 0) { + return PSU_TYPE_AC_F2B; + } + + if (strncmp(fan_dir, "B2F", strlen("B2F")) == 0) { + return PSU_TYPE_AC_B2F; + } + + return PSU_TYPE_UNKNOWN; +} + +int psu_ym2651y_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) { + ret = onlp_file_read_int(value, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + } + else { + ret = onlp_file_read_int(value, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + } + + if (ret < 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_integer(path, value) < 0) { + AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.h new file mode 100644 index 00000000..b17bd084 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.h @@ -0,0 +1,94 @@ +/************************************************************ + * + * + * 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 "x86_64_accton_as5912_54xk_log.h" + +#define CHASSIS_FAN_COUNT 6 +#define CHASSIS_THERMAL_COUNT 5 +#define CHASSIS_PSU_COUNT 2 +#define CHASSIS_LED_COUNT 5 + +#define PSU1_ID 1 +#define PSU2_ID 2 + +#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/11-005b/" +#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/10-0058/" + +#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/11-0053/" +#define PSU2_AC_HWMON_PREFIX "/sys/bus/i2c/devices/10-0050/" + +#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/2-0066/" +#define FAN_NODE(node) FAN_BOARD_PATH#node + +#define IDPROM_PATH "/sys/class/i2c-adapter/i2c-1/1-0057/eeprom" + +int onlp_file_write_integer(char *filename, int value); +int onlp_file_read_binary(char *filename, char *buffer, int buf_size, int data_len); +int onlp_file_read_string(char *filename, char *buffer, int buf_size, int data_len); + +int psu_ym2651y_pmbus_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_F2B, + PSU_TYPE_AC_B2F +} psu_type_t; + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len); + +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_1_ON_PSU1, + THERMAL_1_ON_PSU2, +}; + +#define DEBUG_MODE 0 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printf("%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif + +#endif /* __PLATFORM_LIB_H__ */ + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/psui.c new file mode 100644 index 00000000..6da5aa58 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/psui.c @@ -0,0 +1,186 @@ +/************************************************************ + * + * + * 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 "platform_lib.h" + +#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 VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_PSU(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static 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) { + ret = onlp_file_read_int(value, "%s%s", PSU1_AC_HWMON_PREFIX, node); + } + else if (PSU2_ID == id) { + ret = onlp_file_read_int(value, "%s%s", PSU2_AC_HWMON_PREFIX, node); + } + + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ret; +} + +int +onlp_psui_init(void) +{ + return ONLP_STATUS_OK; +} + +static int +psu_ym2651y_info_get(onlp_psu_info_t* info) +{ + int val = 0; + int index = ONLP_OID_ID_GET(info->hdr.id); + + /* Set capability + */ + info->caps = ONLP_PSU_CAPS_AC; + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Set the associated oid_table */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); + + /* Read voltage, current and power */ + if (psu_ym2651y_pmbus_info_get(index, "psu_v_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_ym2651y_pmbus_info_get(index, "psu_i_out", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (psu_ym2651y_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + 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) { + printf("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) { + printf("Unable to read PSU(%d) node(psu_power_good)\r\n", index); + } + + if (val != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_PSU_STATUS_FAILED; + } + + + /* Get PSU type + */ + psu_type = get_psu_type(index, info->model, sizeof(info->model)); + + switch (psu_type) { + case PSU_TYPE_AC_F2B: + case PSU_TYPE_AC_B2F: + ret = psu_ym2651y_info_get(info); + break; + case PSU_TYPE_UNKNOWN: /* User insert a unknown PSU or unplugged.*/ + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + info->status &= ~ONLP_PSU_STATUS_FAILED; + ret = ONLP_STATUS_OK; + break; + default: + ret = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + 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/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c new file mode 100644 index 00000000..7c80c419 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c @@ -0,0 +1,325 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2016 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 "platform_lib.h" + +#include "x86_64_accton_as5912_54xk_log.h" + +#define NUM_OF_SFP_PORT 54 +#define MAX_SFP_PATH 64 +static char sfp_node_path[MAX_SFP_PATH] = {0}; +#define FRONT_PORT_BUS_INDEX(port) (port+26) + +static char* +sfp_get_port_path_addr(int port, int addr, char *node_name) +{ + sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-00%d/%s", + FRONT_PORT_BUS_INDEX(port), addr, node_name); + return sfp_node_path; +} + +static char* +sfp_get_port_path(int port, char *node_name) +{ + return sfp_get_port_path_addr(port, 50, node_name); +} + +/************************************************************ + * + * SFPI Entry Points + * + ***********************************************************/ +int +onlp_sfpi_init(void) +{ + /* Called at initialization time */ + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) +{ + /* + * Ports {0, 54} + */ + int p; + AIM_BITMAP_INIT(bmap, 64); + AIM_BITMAP_CLR_ALL(bmap); + + for(p = 0; p < NUM_OF_SFP_PORT; p++) { + AIM_BITMAP_SET(bmap, p); + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_is_present(int port) +{ + /* + * Return 1 if present. + * Return 0 if not present. + * Return < 0 if error. + */ + int present; + char *path = sfp_get_port_path(port, "sfp_is_present"); + + if (onlp_file_read_int(&present, path) < 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[7]; + char* path; + FILE* fp; + + AIM_BITMAP_CLR_ALL(dst); + + path = sfp_get_port_path(0, "sfp_is_present_all"); + fp = fopen(path, "r"); + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + int count = fscanf(fp, "%x %x %x %x %x %x %x", + bytes+0, + bytes+1, + bytes+2, + bytes+3, + bytes+4, + bytes+5, + bytes+6 + ); + fclose(fp); + if(count != AIM_ARRAYSIZE(bytes)) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + + /* Mask out non-existant QSFP ports */ + bytes[6] &= 0x3F; + + /* Convert to 64 bit integer in port order */ + int i = 0; + uint64_t presence_all = 0 ; + for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { + presence_all <<= 8; + presence_all |= bytes[i]; + } + + /* Populate bitmap */ + for(i = 0; presence_all; i++) { + AIM_BITMAP_MOD(dst, i, (presence_all & 1)); + presence_all >>= 1; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[6]; + char* path; + FILE* fp; + + path = sfp_get_port_path(0, "sfp_rx_los_all"); + fp = fopen(path, "r"); + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + int count = fscanf(fp, "%x %x %x %x %x %x", + bytes+0, + bytes+1, + bytes+2, + bytes+3, + bytes+4, + bytes+5 + ); + fclose(fp); + if(count != 6) { + AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + + /* Convert to 64 bit integer in port order */ + int i = 0; + uint64_t rx_los_all = 0 ; + for(i = 5; 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]) +{ + char* path = sfp_get_port_path(port, "sfp_eeprom"); + + /* + * Read the SFP eeprom into data[] + * + * Return MISSING if SFP is missing. + * Return OK if eeprom is read + */ + memset(data, 0, 256); + + if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + char* path = sfp_get_port_path_addr(port, 51, "sfp_eeprom"); + memset(data, 0, 256); + + if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) { + AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) +{ + int rv; + + switch(control) + { + case ONLP_SFP_CONTROL_TX_DISABLE: + { + char* path = sfp_get_port_path(port, "sfp_tx_disable"); + + if (onlp_file_write_integer(path, value) != 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; + } + + 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; + char* path = NULL; + + switch(control) + { + case ONLP_SFP_CONTROL_RX_LOS: + { + path = sfp_get_port_path(port, "sfp_rx_los"); + + if (onlp_file_read_int(value, path) < 0) { + AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_FAULT: + { + path = sfp_get_port_path(port, "sfp_tx_fault"); + + if (onlp_file_read_int(value, path) < 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; + } + break; + } + + case ONLP_SFP_CONTROL_TX_DISABLE: + { + path = sfp_get_port_path(port, "sfp_tx_disable"); + + if (onlp_file_read_int(value, path) < 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; + } + + 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/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sysi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sysi.c new file mode 100644 index 00000000..7aa737e0 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sysi.c @@ -0,0 +1,339 @@ +/************************************************************ + * + * + * 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 +#include "platform_lib.h" + +#include "x86_64_accton_as5912_54xk_int.h" +#include "x86_64_accton_as5912_54xk_log.h" + +#define CPLD_VERSION_FORMAT "/sys/bus/i2c/devices/%s/version" +#define NUM_OF_CPLD 2 + +static char* cpld_path[NUM_OF_CPLD] = +{ + "4-0060", + "5-0062" +}; + +const char* +onlp_sysi_platform_get(void) +{ + return "x86-64-accton-as5912-54xk-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)); + + /* 5 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}; + + for (i=0; i < AIM_ARRAYSIZE(cpld_path); i++) { + v[i] = 0; + + if(onlp_file_read_int(v+i, CPLD_VERSION_FORMAT , cpld_path[i]) < 0) { + return ONLP_STATUS_E_INTERNAL; + } + } + + pi->cpld_versions = aim_fstrdup("%d.%d", v[0], v[1]); + return ONLP_STATUS_OK; +} + +void +onlp_sysi_platform_info_free(onlp_platform_info_t* pi) +{ + aim_free(pi->cpld_versions); +} + +#define FAN_DUTY_MAX (100) +#define FAN_DUTY_MID (69) +#define FAN_DUTY_MIN (38) + +#define FANCTRL_DIR_FACTOR (ONLP_FAN_STATUS_B2F) +#define FANCTRL_DIR_FACTOR_DUTY_ADDON (6) + +static int +sysi_fanctrl_fan_fault_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int i; + *adjusted = 0; + + /* Bring fan speed to FAN_DUTY_MAX if any fan is not operational */ + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + if (!(fi[i].status & ONLP_FAN_STATUS_FAILED)) { + continue; + } + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_fan_absent_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int i; + *adjusted = 0; + + /* Bring fan speed to FAN_DUTY_MAX if fan is not present */ + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + if (fi[i].status & ONLP_FAN_STATUS_PRESENT) { + continue; + } + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_fan_unknown_speed_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int fanduty; + int fanduty_min = FAN_DUTY_MIN; + int fanduty_mid = FAN_DUTY_MID; + + *adjusted = 0; + fanduty_min += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + + if (onlp_file_read_int(&fanduty, FAN_NODE(fan_duty_cycle_percentage)) < 0) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + /* Bring fan speed to max if current speed is not expected + */ + if (fanduty != fanduty_min && fanduty != fanduty_mid && fanduty != FAN_DUTY_MAX) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_single_thermal_sensor_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int i; + *adjusted = 0; + + /* When anyone higher than 50 degrees, all fans run with duty 100%. + */ + for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) { + if (ti[i-1].mcelsius < 50000) { + continue; + } + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + /* When anyone higher than 45 degrees, all fans run with duty 62.5%. + */ + for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) { + if (ti[i-1].mcelsius < 45000) { + continue; + } + + int fanduty_mid = FAN_DUTY_MID; + fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_mid); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_overall_thermal_sensor_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int fanduty_min = FAN_DUTY_MIN; + int fanduty_mid = FAN_DUTY_MID; + int i, num_of_sensor = 0, temp_avg = 0; + + *adjusted = 0; + fanduty_min += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + + for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) { + num_of_sensor++; + temp_avg += ti[i-1].mcelsius; + } + + temp_avg /= num_of_sensor; + + if (temp_avg >= 45000) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + else if (temp_avg >= 40000) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_mid); + } + else if (temp_avg < 35000) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_min); + } + + return ONLP_STATUS_OK; +} + +typedef int (*fan_control_policy)(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted); + +fan_control_policy fan_control_policies[] = { +sysi_fanctrl_fan_fault_policy, +sysi_fanctrl_fan_absent_policy, +sysi_fanctrl_fan_unknown_speed_policy, +sysi_fanctrl_single_thermal_sensor_policy, +sysi_fanctrl_overall_thermal_sensor_policy, +}; + +int +onlp_sysi_platform_manage_fans(void) +{ + int i, rc; + onlp_fan_info_t fi[CHASSIS_FAN_COUNT]; + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT]; + + memset(fi, 0, sizeof(fi)); + memset(ti, 0, sizeof(ti)); + + /* Get fan status + */ + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + rc = onlp_fani_info_get(ONLP_FAN_ID_CREATE(i+1), &fi[i]); + + if (rc != ONLP_STATUS_OK) { + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + return ONLP_STATUS_E_INTERNAL; + } + } + + /* Get thermal sensor status + */ + for (i = 0; i < CHASSIS_THERMAL_COUNT; i++) { + rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(i+1), &ti[i]); + + if (rc != ONLP_STATUS_OK) { + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + return ONLP_STATUS_E_INTERNAL; + } + } + + /* Apply thermal policy according the policy list, + * If fan duty is adjusted by one of the policies, skip the others + */ + for (i = 0; i < AIM_ARRAYSIZE(fan_control_policies); i++) { + int adjusted = 0; + + rc = fan_control_policies[i](fi, ti, &adjusted); + if (!adjusted) { + continue; + } + + return rc; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_platform_manage_leds(void) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/thermali.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/thermali.c new file mode 100644 index 00000000..01b995aa --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/thermali.c @@ -0,0 +1,128 @@ +/************************************************************ + * + * + * 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 "platform_lib.h" + +#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/3-0048*temp1_input", + "/sys/bus/i2c/devices/3-0049*temp1_input", + "/sys/bus/i2c/devices/3-004a*temp1_input", + "/sys/bus/i2c/devices/3-004b*temp1_input", + "/sys/bus/i2c/devices/11-005b*psu_temp1_input", + "/sys/bus/i2c/devices/10-0058*psu_temp1_input", +}; + +static char* cpu_coretemp_files[] = + { + "/sys/devices/platform/coretemp.0*temp2_input", + "/sys/devices/platform/coretemp.0*temp3_input", + "/sys/devices/platform/coretemp.0*temp4_input", + "/sys/devices/platform/coretemp.0*temp5_input", + NULL, + }; + +/* Static values */ +static onlp_thermal_info_t linfo[] = { + { }, /* Not used */ + { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), "CPU Core", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-1-48", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "LM75-2-49", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "LM75-3-4A", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "LM75-3-4B", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 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, + ONLP_THERMAL_CAPS_ALL, 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, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + } +}; + +/* + * This will be called to intiialize the thermali subsystem. + */ +int +onlp_thermali_init(void) +{ + return ONLP_STATUS_OK; +} + +/* + * Retrieve the information structure for the given thermal OID. + * + * If the OID is invalid, return ONLP_E_STATUS_INVALID. + * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. + * Otherwise, return ONLP_STATUS_OK with the OID's information. + * + * Note -- it is expected that you fill out the information + * structure even if the sensor described by the OID is not present. + */ +int +onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) +{ + int tid; + VALIDATE(id); + + tid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[tid]; + + if(tid == THERMAL_CPU_CORE) { + int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files); + return rv; + } + + return onlp_file_read_int(&info->mcelsius, devfiles__[tid]); +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_config.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_config.c new file mode 100644 index 00000000..d403bbc7 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_config.c @@ -0,0 +1,80 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* */ +#define __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE(_x) __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(_x) +x86_64_accton_as5912_54xk_config_settings_t x86_64_accton_as5912_54xk_config_settings[] = +{ +#ifdef x86_64_accton_as5912_54xk_CONFIG_INCLUDE_LOGGING + { __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(x86_64_accton_as5912_54xk_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE(x86_64_accton_as5912_54xk_CONFIG_INCLUDE_LOGGING) }, +#else +{ x86_64_accton_as5912_54xk_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5912_54xk_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE(x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5912_54xk_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT + { __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE(x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5912_54xk_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE(x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5912_54xk_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB + { __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB), __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE(x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB) }, +#else +{ x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB(__x86_64_accton_as5912_54xk_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE(x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5912_54xk_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI + { __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE(x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI) }, +#else +{ x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5912_54xk_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME(x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE(x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#else +{ x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5912_54xk_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_accton_as5912_54xk_config_STRINGIFY_VALUE +#undef __x86_64_accton_as5912_54xk_config_STRINGIFY_NAME + +const char* +x86_64_accton_as5912_54xk_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_accton_as5912_54xk_config_settings[i].name; i++) { + if(strcmp(x86_64_accton_as5912_54xk_config_settings[i].name, setting)) { + return x86_64_accton_as5912_54xk_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_accton_as5912_54xk_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_accton_as5912_54xk_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_accton_as5912_54xk_config_settings[i].name, x86_64_accton_as5912_54xk_config_settings[i].value); + } + return i; +} + +/* */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_enums.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_enums.c new file mode 100644 index 00000000..b81cb8ea --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_enums.c @@ -0,0 +1,10 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_int.h b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_int.h new file mode 100644 index 00000000..01360108 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_int.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * x86_64_accton_as5912_54xk Internal Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5912_54xk_INT_H__ +#define __x86_64_accton_as5912_54xk_INT_H__ + +#include + + +#endif /* __x86_64_accton_as5912_54xk_INT_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_log.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_log.c new file mode 100644 index 00000000..f00242a5 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_log.c @@ -0,0 +1,18 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5912_54xk_log.h" +/* + * x86_64_accton_as5912_54xk log struct. + */ +AIM_LOG_STRUCT_DEFINE( + x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT, + x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_log.h b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_log.h new file mode 100644 index 00000000..3414146a --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_log.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5912_54xk_LOG_H__ +#define __x86_64_accton_as5912_54xk_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_accton_as5912_54xk +#include + +#endif /* __x86_64_accton_as5912_54xk_LOG_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_module.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_module.c new file mode 100644 index 00000000..006ff908 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_module.c @@ -0,0 +1,24 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5912_54xk_log.h" + +static int +datatypes_init__(void) +{ +#define x86_64_accton_as5912_54xk_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_as5912_54xk_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_ucli.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_ucli.c new file mode 100644 index 00000000..1a8879ac --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/x86_64_accton_as5912_54xk_ucli.c @@ -0,0 +1,50 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#if x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_accton_as5912_54xk_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as5912_54xk) +} + +/* */ +/* */ + +static ucli_module_t +x86_64_accton_as5912_54xk_ucli_module__ = + { + "x86_64_accton_as5912_54xk_ucli", + NULL, + x86_64_accton_as5912_54xk_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_accton_as5912_54xk_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_accton_as5912_54xk_ucli_module__); + n = ucli_node_create("x86_64_accton_as5912_54xk", NULL, &x86_64_accton_as5912_54xk_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as5912_54xk")); + return n; +} + +#else +void* +x86_64_accton_as5912_54xk_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/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/x86-64-accton-as5912-54xk/platform-config/r0/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/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/x86-64-accton-as5912-54xk/platform-config/r0/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/PKG.yml new file mode 100644 index 00000000..5e3b1810 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as5912-54xk REVISION=r0 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/lib/x86-64-accton-as5912-54xk-r0.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/lib/x86-64-accton-as5912-54xk-r0.yml new file mode 100644 index 00000000..c20f4ac4 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/lib/x86-64-accton-as5912-54xk-r0.yml @@ -0,0 +1,31 @@ +--- + +###################################################################### +# +# platform-config for AS5912 +# +###################################################################### + +x86-64-accton-as5912-54xk-r0: + + grub: + + serial: >- + --port=0x2f8 + --speed=115200 + --word=8 + --parity=no + --stop=1 + + kernel: + <<: *kernel-3-16 + + args: >- + nopat + console=ttyS1,115200n8 + + ##network + ## interfaces: + ## ma1: + ## name: ~ + ## syspath: pci0000:00/0000:00:14.0 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/python/x86_64_accton_as5912_54xk_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/python/x86_64_accton_as5912_54xk_r0/__init__.py new file mode 100644 index 00000000..9922d621 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/python/x86_64_accton_as5912_54xk_r0/__init__.py @@ -0,0 +1,80 @@ +from onl.platform.base import * +from onl.platform.accton import * + +class OnlPlatform_x86_64_accton_as5912_54xk_r0(OnlPlatformAccton, + OnlPlatformPortConfig_48x10_6x40): + PLATFORM='x86-64-accton-as5912-54xk-r0' + MODEL="AS5912-54xk" + SYS_OBJECT_ID=".5912.54" + + def baseconfig(self): + self.insmod("accton_i2c_cpld") + self.insmod("ym2651y") + for m in [ "sfp", "psu", "fan", "leds" ]: + self.insmod("x86-64-accton-as5912-54xk-%s" % m) + + ########### initialize I2C bus 0 ########### + self.new_i2c_devices( + [ + # initialize multiplexer (PCA9548) + ('pca9548', 0x76, 0), + + # initiate chassis fan + ('as5912_54xk_fan', 0x66, 2), + + # inititate LM75 + ('lm75', 0x48, 3), + ('lm75', 0x49, 3), + ('lm75', 0x4a, 3), + ('lm75', 0x4b, 3), + + # initialize CPLDs + ('accton_i2c_cpld', 0x60, 4), + ('accton_i2c_cpld', 0x62, 5), + ] + ) + + ########### initialize I2C bus 1 ########### + self.new_i2c_devices( + [ + # initialize multiplexer (PCA9548) + ('pca9548', 0x74, 1), + + # initiate PSU-1 AC Power + ('as5912_54xk_psu1', 0x53, 11), + ('ym2651', 0x5b, 11), + + # initiate PSU-2 AC Power + ('as5912_54xk_psu2', 0x50, 10), + ('ym2651', 0x58, 10), + + # initiate IDPROM + ('24c02', 0x57, 1), + ] + ) + + # initialize multiplexer (PCA9548) for SFP ports + self.new_i2c_devices( + [ + ('pca9548', 0x72, 1), + ('pca9548', 0x77, 18), + ('pca9548', 0x77, 19), + ('pca9548', 0x77, 20), + ('pca9548', 0x77, 21), + ('pca9548', 0x77, 22), + ('pca9548', 0x77, 23), + ('pca9548', 0x77, 24), + ] + ) + + # initialize SFP devices + for port in range(1, 49): + self.new_i2c_device('as5912_54xk_sfp%d' % port, 0x50, port+25) + self.new_i2c_device('as5912_54xk_sfp%d' % port, 0x51, port+25) + + # initialize QSFP devices + for port in range(49, 55): + self.new_i2c_device('as5912_54xk_sfp%d' % port, 0x50, port+25) + + return True + From bb790e5d13027e2a27783c316ad2683c7e05bfc3 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Mon, 7 Aug 2017 17:47:26 -0700 Subject: [PATCH 02/67] Add EFI support packages to SWI --- builds/any/rootfs/jessie/common/amd64-base-packages.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builds/any/rootfs/jessie/common/amd64-base-packages.yml b/builds/any/rootfs/jessie/common/amd64-base-packages.yml index a07863f3..efaf425b 100644 --- a/builds/any/rootfs/jessie/common/amd64-base-packages.yml +++ b/builds/any/rootfs/jessie/common/amd64-base-packages.yml @@ -11,3 +11,5 @@ - hw-management - sx-kernel - onl-kernel-3.16-lts-x86-64-all-modules +- efibootmgr +- gdisk From a1cf697f67cf55a92cab90c7623435ab4da20a53 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Mon, 7 Aug 2017 17:50:23 -0700 Subject: [PATCH 03/67] Overhaul ONL mtab.yml handling (preparing for UEFI support) - fix timeout handling - add 'optional' field for not-always-required mount points - add 'label' field to disambiguate mtab.yml keys from FS labels --- .../src/python/onl/mounts/__init__.py | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py b/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py index 3c64c0eb..9ee101cd 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py @@ -138,35 +138,53 @@ class OnlMountManager(object): def init(self, timeout=5): - for(k, v) in self.mdata['mounts'].iteritems(): - # - # Get the partition device for the given label. - # The timeout logic is here to handle waiting for the - # block devices to arrive at boot. - # - t = timeout - while t >= 0: - try: - v['device'] = subprocess.check_output("blkid -L %s" % k, shell=True).strip() - break - except subprocess.CalledProcessError: - self.logger.debug("Block label %s does not yet exist..." % k) - time.sleep(1) - t -= 1 + now = time.time() + future = now + timeout - if 'device' not in v: - self.logger.error("Timeout waiting for block label %s after %d seconds." % (k, timeout)) - self.missing = k + md = self.mdata['mounts'] + optional = set(x for x in md if md.get('optional', False)) + pending = set(x for x in md if not md.get('optional', False)) + + def _discover(k): + v = md[k] + lbl = v.get('label', k) + + try: + v['device'] = subprocess.check_output(('blkid', '-L', lbl,)).strip() + except subprocess.CalledProcessError: return False - # - # Make the mount point for future use. - # if not os.path.isdir(v['dir']): - self.logger.debug("Make directory '%s'..." % v['dir']) + self.logger.debug("Make directory '%s'...", v['dir']) os.makedirs(v['dir']) - self.logger.debug("%s @ %s" % (k, v['device'])) + self.logger.debug("%s @ %s", k, v['dir']) + return True + + while True: + + now = time.time() + if now > future: + break + + pending_ = pending + pending = [k for k in pending_ if not _discover(k)] + optional_ = optional + optional = [k for k in optional_ if not _discover(k)] + + if not pending: break + if pending != pending_: continue + if optional != optional_: continue + + self.logger.debug("Still waiting for block devices: %s", + " ".join(pending+optional)) + time.sleep(0.25) + + if pending: + for k in pending+optional: + self.logger.error("Timeout waiting for block label %s after %d seconds.", k, timeout) + + # ignore the any optional labels that were not found def __fsck(self, label, device): self.logger.info("Running fsck on %s [ %s ]..." % (label, device)) From 15efbdc5403241fef790678bad9604ad6d8ebc0c Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Mon, 7 Aug 2017 17:51:07 -0700 Subject: [PATCH 04/67] Add EFI-BOOT mount point - optional - depend on hokey "EFI System" GPT label, YMMV - *TODO* use proper GPT UUID matching --- builds/any/rootfs/jessie/common/overlay/etc/mtab.yml | 8 ++++++++ .../base/all/initrds/loader-initrd-files/src/etc/mtab.yml | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml b/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml index 598e4c69..17e0a6bc 100644 --- a/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml +++ b/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml @@ -17,3 +17,11 @@ mounts: mount: ro dir: /mnt/onl/boot fsck: false + + # ESP (EFI system partition) + EFI-BOOT: + mount: ro + dir: /mnt/onl/efi-boot + fsck: false + label: EFI System + optional: true diff --git a/packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml b/packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml index cb7635b1..17abb840 100644 --- a/packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml +++ b/packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml @@ -18,3 +18,11 @@ mounts: mount: rw dir: /mnt/onl/boot fsck: true + + # ESP (EFI system partition) + EFI-BOOT: + mount: ro + dir: /mnt/onl/efi-boot + fsck: false + label: EFI System + optional: true From a57d222661eec538f69221c977d711d6058d6d0f Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Mon, 7 Aug 2017 17:51:37 -0700 Subject: [PATCH 05/67] Mount efivarfs in loader and propagate it to the SWI --- .../initrds/loader-initrd-files/src/bin/switchroot | 11 +++++++++++ .../all/initrds/loader-initrd-files/src/bin/sysinit | 4 ++++ .../base/all/vendor-config-onl/src/lib/install/lib.sh | 3 +++ .../src/python/onl/install/InstallUtils.py | 5 +++++ 4 files changed, 23 insertions(+) diff --git a/packages/base/all/initrds/loader-initrd-files/src/bin/switchroot b/packages/base/all/initrds/loader-initrd-files/src/bin/switchroot index 91d08334..2eb8ead6 100644 --- a/packages/base/all/initrds/loader-initrd-files/src/bin/switchroot +++ b/packages/base/all/initrds/loader-initrd-files/src/bin/switchroot @@ -49,7 +49,13 @@ done <${mtab} rm -f ${mtab} mount --move /proc /newroot/proc +if [ -d /sys/firmware/efi/efivars ]; then + umount /sys/firmware/efi/efivars || : +fi mount --move /sys /newroot/sys +if [ -d /newroot/sys/firmware/efi/efivars ]; then + mount -t efivarfs efivarfs /newroot/sys/firmware/efi/efivars +fi mount --move /dev /newroot/dev # Switch to /newroot if possible, else re-execute /init @@ -58,3 +64,8 @@ if [ -x /newroot/sbin/init ]; then else exec /init fi + +# Local variables: +# sh-indentation: 4 +# sh-basic-offset: 4 +# End: diff --git a/packages/base/all/initrds/loader-initrd-files/src/bin/sysinit b/packages/base/all/initrds/loader-initrd-files/src/bin/sysinit index b80f85fb..910b3fcf 100755 --- a/packages/base/all/initrds/loader-initrd-files/src/bin/sysinit +++ b/packages/base/all/initrds/loader-initrd-files/src/bin/sysinit @@ -35,6 +35,9 @@ trap "restoreconsole; reboot -f" EXIT # Mount special filesystems mount -t proc proc /proc mount -t sysfs sysfs /sys +if [ -d /sys/firmware/efi/efivars ]; then + mount -t efivarfs efivarfs /sys/firmware/efi/efivars +fi mount -o remount,size=1M /dev case "$(stat -f -c "%T" /tmp)" in tmpfs|ramfs) ;; @@ -144,4 +147,5 @@ trap - EXIT # Local variables: # sh-basic-offset: 4 +# sh-indentation: 4 # End: diff --git a/packages/base/all/vendor-config-onl/src/lib/install/lib.sh b/packages/base/all/vendor-config-onl/src/lib/install/lib.sh index 74dd273f..311bd5d5 100644 --- a/packages/base/all/vendor-config-onl/src/lib/install/lib.sh +++ b/packages/base/all/vendor-config-onl/src/lib/install/lib.sh @@ -113,6 +113,9 @@ installer_mkchroot() { mkdir -p ${rootdir}/dev/pts fi mount -t devpts devpts "${rootdir}/dev/pts" + if test -d "${rootdir}/sys/firmware/efi/efivars"; then + mount -t efivarfs efivarfs "${rootdir}/sys/firmware/efi/efivars" + fi if test ${TMPDIR+set}; then # make the tempdir available to the chroot diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py index 1cc40e4c..9e64bc54 100644 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py @@ -821,6 +821,11 @@ class InitrdContext(SubprocessMixin): cmd = ('mount', '-t', 'sysfs', 'sysfs', dst,) self.check_call(cmd, vmode=self.V1) + dst = os.path.join(self.dir, "sys/firmware/efi/efivars") + if os.path.exists(dst): + cmd = ('mount', '-t', 'efivarfs', 'efivarfs', dst,) + self.check_call(cmd, vmode=self.V1) + # maybe mount devtmpfs if self._hasDevTmpfs: dst = os.path.join(self.dir, "dev") From 766f37e7b3d55cfe52a54e5d3761ffdf6590d2ad Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Tue, 8 Aug 2017 19:51:05 -0700 Subject: [PATCH 06/67] Proactively fix GPT partition tables, see SWL-3971 - try to find the boot device - try to determine if the boot device is GPT - use sgdisk to correct simple errors --- builds/any/installer/installer.sh.in | 3 + .../vendor-config-onl/src/lib/install/lib.sh | 113 ++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/builds/any/installer/installer.sh.in b/builds/any/installer/installer.sh.in index da7a24cb..76b33987 100644 --- a/builds/any/installer/installer.sh.in +++ b/builds/any/installer/installer.sh.in @@ -548,6 +548,9 @@ if test -f preinstall.sh; then ./preinstall.sh $rootdir fi +# make sure any GPT data is valid and clean +installer_fixup_gpt || : + chroot "${rootdir}" $installer_shell if test -f "$postinst"; then diff --git a/packages/base/all/vendor-config-onl/src/lib/install/lib.sh b/packages/base/all/vendor-config-onl/src/lib/install/lib.sh index 311bd5d5..72f6290f 100644 --- a/packages/base/all/vendor-config-onl/src/lib/install/lib.sh +++ b/packages/base/all/vendor-config-onl/src/lib/install/lib.sh @@ -189,6 +189,119 @@ visit_blkid() return 0 } +############################## +# +# Fixup a corrupted GPT partition, within reason +# See SWL-3971 +# +############################## + +blkid_find_gpt_boot() { + local dev label + dev=$1; shift + label=$1; shift + rest="$@" + + installer_say "Examining $dev --> $label" + + # EFI partition shows up as a valid partition with blkid + if test "$label" = "EFI System"; then + installer_say "Found EFI System partition at $dev" + ESP_DEVICE=$(echo "$dev" | sed -e 's/[0-9]$//') + + # this is definitely the boot disk + return 2 + fi + + # sometimes this is hidden from blkid (no filesystem) + if test "$label" = "GRUB-BOOT"; then + installer_say "Found GRUB boot partition at $dev" + GRUB_DEVICE=$(echo "$dev" | sed -e 's/[0-9]$//') + + # probably the boot disk, look for a GPT header + return 0 + fi + + # shows up in blkid but may not be GPT + if test "$label" = "ONIE-BOOT"; then + installer_say "Found ONIE boot partition at $dev" + ONIE_DEVICE=$(echo "$dev" | sed -e 's/[0-9]$//') + + # probably the boot disk, look for a GPT header + return 0 + fi + + # not found, skip + return 0 +} + +installer_fixup_gpt() { + local buf dat sts dev + + buf=$(mktemp -u -t sgdisk-XXXXXX) + + ESP_DEVICE= + GRUB_DEVICE= + ONIE_DEVICE= + visit_blkid blkid_find_gpt_boot + + dev= + if test -b "$ESP_DEVICE"; then + dev=$ESP_DEVICE + elif test -b "$GRUB_DEVICE"; then + sgdisk -p "$GRUB_DEVICE" > "$buf" 2>&1 || : + if grep -q GUID "$buf"; then + dev=$GRUB_DEVICE + fi + elif test -b "$ONIE_DEVICE"; then + sgdisk -p "$ONIE_DEVICE" > "$buf" 2>&1 || : + if grep -q GUID "$buf"; then + # here we assume that the ONIE boot partition is on + # the boot disk + # (additionally we could also look for 'GRUB-BOOT') + dev=$ONIE_DEVICE + fi + fi + test -b "$dev" || return 0 + + # see if it's a clean GPT partition table + if sgdisk -p "$dev" > "$buf" 2>&1; then + sts=0 + else + sts=$? + fi + if test $sts -ne 0; then + cat "$buf" 1>&2 + rm -f "$buf" + installer_say "Cannot reliably get GPT partition table" + return 1 + fi + + case $(cat "$buf") in + *Caution*|*Warning*) + cat $buf 1>&2 + installer_say "Found issues with the GPT partition table" + rm -f "$buf" + ;; + *) + installer_say "Found a clean GPT partition table" + rm -f "$buf" + return 0 + ;; + esac + + installer_say "Attempting to correct the GPT partition table" + + # this is the simple method; gdisk/sfgdisk will correct + # simple errors but not horrendous faults + dat=$(mktemp -u -t sgdisk-XXXXXX) + sgdisk -b "$dat" "$dev" || return 1 + sgdisk -l "$dat" "$dev" || return 1 + rm -f "$dat" + + return 0 +} + # Local variables # mode: sh # sh-basic-offset: 2 From b13aa58847091c9f58d3c05e99f473a898e135be Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 11 Aug 2017 12:30:56 -0700 Subject: [PATCH 07/67] Update to master --- sm/infra | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sm/infra b/sm/infra index 11c32857..af32e738 160000 --- a/sm/infra +++ b/sm/infra @@ -1 +1 @@ -Subproject commit 11c32857abad9b13718506ab8adced9a0e6dfa17 +Subproject commit af32e738740c0f03af9c4d4db4e8ef6d37e835a1 From ee0041c04c2f17535cca1329bbe5dc39499ff3fe Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Mon, 14 Aug 2017 22:03:50 +0000 Subject: [PATCH 08/67] Latest --- sm/bigcode | 2 +- sm/infra | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sm/bigcode b/sm/bigcode index 2e5f97dd..ad064c4d 160000 --- a/sm/bigcode +++ b/sm/bigcode @@ -1 +1 @@ -Subproject commit 2e5f97dd0604c6a60f6da2e588c27027ebdb062d +Subproject commit ad064c4d73903528633954d12fb2f66b9901b331 diff --git a/sm/infra b/sm/infra index 11c32857..b23f2577 160000 --- a/sm/infra +++ b/sm/infra @@ -1 +1 @@ -Subproject commit 11c32857abad9b13718506ab8adced9a0e6dfa17 +Subproject commit b23f2577cb4ab505eb8bdfdd5d599e49da38c142 From 3e89468cd07feacb5c7368883c4e3a1419313d76 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 17 Aug 2017 22:47:54 +0000 Subject: [PATCH 09/67] Don't require link-up on ma1 if NETAUTO is not specified. --- packages/base/all/initrds/loader-initrd-files/src/bin/ifup | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/base/all/initrds/loader-initrd-files/src/bin/ifup b/packages/base/all/initrds/loader-initrd-files/src/bin/ifup index 8ea35729..453a55c9 100644 --- a/packages/base/all/initrds/loader-initrd-files/src/bin/ifup +++ b/packages/base/all/initrds/loader-initrd-files/src/bin/ifup @@ -141,4 +141,7 @@ wait_link_up() return 1 } -wait_link_up $NETDEV 100 +if [ -n "${NETAUTO}" ]; then + wait_link_up $NETDEV 100 +fi +return 0 From d399f33c385923a6091ba2264777188d4267738b Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 18 Aug 2017 09:32:41 -0700 Subject: [PATCH 10/67] Refactor UEFI grub support --- .../src/python/onl/install/BaseInstall.py | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py index 3068f658..e5644fd5 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py @@ -509,14 +509,33 @@ menuentry %(boot_menu_entry)s { initrd /%(platform)s.cpio.gz } +set onie_boot_label="ONIE-BOOT" +set onie_boot_uuid="%(onie_boot_uuid)s" +# filesystem UUID, *not* partition UUID +# (tee hee, GPT GRUB cannot grok partition UUIDs) + +function onie_boot_uefi { + set root='(hd0,gpt1)' + search --no-floppy --fs-uuid --set=root "${onie_boot_uuid}" + echo 'Loading ONIE ...' + chainloader /EFI/onie/grubx64.efi +} + +function onie_boot_dos { + search --no-floppy --label --set=root "${onie_boot_label}" + set saved_entry="0" + save_env saved_entry + echo 'Loading ONIE ...' + chainloader +1 +} + # Menu entry to chainload ONIE menuentry ONIE { - %(set_root_para)s - search --no-floppy %(set_search_para2)s --set=root %(onie_boot)s - %(set_save_entry_para)s - %(set_save_env_para)s - echo 'Loading ONIE ...' - chainloader %(set_chainloader_para)s + if [ -n "${onie_boot_uuid}" ]; then + onie_boot_uefi + else + onie_boot_dos + fi } """ @@ -528,7 +547,10 @@ class GrubInstaller(SubprocessMixin, Base): def __init__(self, *args, **kwargs): Base.__init__(self, *args, **kwargs) - self.isUEFI = False + + @property + def isUEFI(self): + return os.path.isdir('/sys/firmware/efi/efivars') def findGpt(self): self.blkidParts = BlkidParser(log=self.log.getChild("blkid")) @@ -659,20 +681,10 @@ class GrubInstaller(SubprocessMixin, Base): ctx['boot_loading_name'] = sysconfig.installer.os_name if self.isUEFI: - ctx['set_root_para'] = "set root='(hd0,gpt1)'" - ctx['set_search_para2'] = "--fs-uuid" - ctx['set_save_entry_para'] = "" - ctx['set_save_env_para'] = "" dev_UEFI = self.blkidParts['EFI System'] - ctx['onie_boot'] = dev_UEFI.uuid - ctx['set_chainloader_para'] = "/EFI/onie/grubx64.efi" + ctx['onie_boot_uuid'] = dev_UEFI.uuid else: - ctx['set_root_para'] = "" - ctx['set_search_para2'] = "--label" - ctx['set_save_entry_para'] = "set saved_entry=\"0\"" - ctx['set_save_env_para'] = "save_env saved_entry" - ctx['onie_boot'] = "ONIE-BOOT" - ctx['set_chainloader_para'] = "+1" + ctx['onie_boot_uuid'] = "" cf = GRUB_TPL % ctx @@ -775,8 +787,6 @@ class GrubInstaller(SubprocessMixin, Base): if label != 'gpt': self.log.error("invalid GRUB label in platform config: %s", label) return 1 - if os.path.isdir('/sys/firmware/efi/efivars'): - self.isUEFI = True return self.installGpt() From df0f857ccf3359f5d1532d26cee8f817612b7c0e Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 18 Aug 2017 09:32:49 -0700 Subject: [PATCH 11/67] WIP gdisk support --- .../src/python/onl/install/InstallUtils.py | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py index 9e64bc54..49b673a5 100644 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py @@ -9,6 +9,7 @@ import subprocess import tempfile import string import shutil +import re import Fit, Legacy @@ -620,6 +621,158 @@ class PartedParser(SubprocessMixin): def __len__(self): return len(self.parts) +class GdiskDiskEntry: + + DEVICE_RE = re.compile("Disk ([^:]*): .*") + BLOCKS_RE = re.compile("Disk [^:]*: ([0-9][0-9]*) sectors") + LBSZ_RE = re.compile("Logical sector size: ([0-9][0-9]*) bytes") + GUID_RE = re.compile("Disk identifier [(]GUID[)]: ([0-9a-fA-F-][0-9a-fA-F-]*)") + + def __init__(self, device, blocks, lbsz, guid): + self.device = device + + self.blocks = blocks + self.lbsz = lbsz + self.guid = guid + + @classmethod + def fromOutput(cls, buf): + + m = cls.BLOCKS_RE.search(buf) + if m: + blocks = int(m.group(1)) + else: + raise ValueError("cannot get block count") + + m = cls.DEVICE_RE.search(buf) + if m: + device = m.group(1) + else: + raise ValueError("cannot get block count") + + m = cls.LBSZ_RE.search(buf) + if m: + lbsz = int(m.group(1)) + else: + raise ValueError("cannot get block size") + + m = cls.GUID_RE.search(buf) + if m: + guid = m.group(1) + else: + raise ValueError("cannot get block size") + + return cls(device, blocks, lbsz, guid) + +class GdiskPartEntry: + + PGUID_RE = re.compile("Partition GUID code: ([0-9a-fA-F-][0-9a-fA-F-]*) [(]([^)]*)[)]") + PGUID2_RE = re.compile("Partition GUID code: ([0-9a-fA-F-][0-9a-fA-F-]*)") + GUID_RE = re.compile("Partition unique GUID: ([0-9a-fA-F-][0-9a-fA-F-]*)") + START_RE = re.compile("First sector: ([0-9][0-9]*)") + END_RE = re.compile("Last sector: ([0-9][0-9]*)") + SIZE_RE = re.compile("Partition size: ([0-9][0-9]*) sectors") + NAME_RE = re.compile("Partition name: [']([^']+)[']") + + ESP_PGUUID="c12a7328-f81f-11d2-ba4b-00a0c93ec93b" + + def __init__(self, pguid, guid, start, end, sz, pguidName=None, name=None): + self.pguid = pguid + self.pguidName = pguidName + self.guid = guid + self.name = name + self.start = start + self.end = end + self.sz = sz + + @classmethod + def fromOutput(cls, buf): + + m = cls.PGUID_RE.search(buf) + if m: + pguid = m.group(1).lower() + pguidName = m.group(2) + else: + m = cls.PGUID2_RE.search(buf) + if m: + pguid = m.group(1).lower() + pguidName = None + else: + raise ValueError("cannot get partition GUID") + + m = cls.GUID_RE.search(buf) + if m: + guid = m.group(1).lower() + else: + raise ValueError("cannot get partition unique GUID") + + m = cls.START_RE.search(buf) + if m: + start = int(m.group(1)) + else: + raise ValueError("cannot get partition start") + + m = cls.END_RE.search(buf) + if m: + end = int(m.group(1)) + else: + raise ValueError("cannot get partition end") + + m = cls.SIZE_RE.search(buf) + if m: + sz = int(m.group(1)) + else: + raise ValueError("cannot get partition size") + + m = cls.NAME_RE.search(buf) + if m: + name = m.group(1) + else: + name = None + + return cls(pguid, guid, start, end, sz, + pguidName=pguidName, + name=name) + +class GdiskParser(SubprocessMixin): + + def __init__(self, device, log=None): + self.device = device + self.log = log or logging.getLogger("parted") + self.parse() + + def parse(self): + + onieCmd = ('sgdisk', '-p', self.device,) + cmd = ('onie-shell', '-c', " ".join(onieCmd),) + buf = self.check_output(cmd) + self.disk = GdiskDiskEntry.fromOutput(buf) + + parts = {} + for line in buf.splitlines(): + + line = line.strip() + if not line: continue + if not line[0] in string.digits: continue + + partno = int(line.split()[0]) + onieCmd = ('sgdisk', '-i', str(partno), self.device,) + cmd = ('onie-shell', '-c', " ".join(onieCmd),) + buf = self.check_output(cmd) + + ent = GdiskPartEntry.fromOutput(buf) + parts[partno] = ent + + self.parts = [] + for partno in sorted(parts.keys()): + self.parts.append(parts[partno]) + + if self.disk is None: + raise ValueError("no partition table found") + + def __len__(self): + return len(self.parts) + class ProcMountsEntry: def __init__(self, device, dir, fsType, flags={}): From 1ef9dd8e166f41617163c21d2694c497e6d74b19 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 18 Aug 2017 17:53:20 -0700 Subject: [PATCH 12/67] Fixes for optional mount points --- .../src/python/onl/mounts/__init__.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py b/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py index 9ee101cd..6ddedbe5 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py @@ -142,8 +142,8 @@ class OnlMountManager(object): future = now + timeout md = self.mdata['mounts'] - optional = set(x for x in md if md.get('optional', False)) - pending = set(x for x in md if not md.get('optional', False)) + optional = set(x for x in md if md[x].get('optional', False)) + pending = set(x for x in md if not md[x].get('optional', False)) def _discover(k): v = md[k] @@ -220,7 +220,20 @@ class OnlMountManager(object): raise ValueError("invalid labels argument.") if 'all' in labels: - labels = filter(lambda l: l != 'all', labels) + self.mdata['mounts'].keys() + labels = list(labels) + labels.remove('all') + labels = labels + self.mdata['mounts'].keys() + + def _f(label): + mpt = self.mdata['mounts'][label] + dev = mpt.get('device', None) + opt = mpt.get('optional', False) + if dev: return True + if not opt: return True + return False + + labels = [x for x in labels if _f(x)] + # skip labels that do not resolve to a block device (ideally, optional ones) rv = [] for l in list(set(labels)): From 79185302c1ae850a7203c3a621ec9d004d0c3234 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 18 Aug 2017 17:53:36 -0700 Subject: [PATCH 13/67] Finalize sgdisk support --- .../src/python/onl/install/InstallUtils.py | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py index 49b673a5..dac4f222 100644 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py @@ -674,9 +674,12 @@ class GdiskPartEntry: SIZE_RE = re.compile("Partition size: ([0-9][0-9]*) sectors") NAME_RE = re.compile("Partition name: [']([^']+)[']") - ESP_PGUUID="c12a7328-f81f-11d2-ba4b-00a0c93ec93b" + ESP_PGUID = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" + GRUB_PGUID = "21686148-6449-6e6f-744e-656564454649" + ONIE_PGUID = "7412f7d5-a156-4b13-81dc-867174929325" - def __init__(self, pguid, guid, start, end, sz, pguidName=None, name=None): + def __init__(self, device, pguid, guid, start, end, sz, pguidName=None, name=None): + self.device = device self.pguid = pguid self.pguidName = pguidName self.guid = guid @@ -685,8 +688,20 @@ class GdiskPartEntry: self.end = end self.sz = sz + @property + def isEsp(self): + return self.pguid == self.ESP_PGUID + + @property + def isGrub(self): + return self.pguid == self.GRUB_PGUID + + @property + def isOnie(self): + return self.pguid == self.ONIE_PGUID + @classmethod - def fromOutput(cls, buf): + def fromOutput(cls, partDevice, buf): m = cls.PGUID_RE.search(buf) if m: @@ -730,7 +745,8 @@ class GdiskPartEntry: else: name = None - return cls(pguid, guid, start, end, sz, + return cls(partDevice, + pguid, guid, start, end, sz, pguidName=pguidName, name=name) @@ -749,6 +765,7 @@ class GdiskParser(SubprocessMixin): self.disk = GdiskDiskEntry.fromOutput(buf) parts = {} + pidx = 1 for line in buf.splitlines(): line = line.strip() @@ -756,11 +773,23 @@ class GdiskParser(SubprocessMixin): if not line[0] in string.digits: continue partno = int(line.split()[0]) + + partDevice = "%s%d" % (self.device, pidx,) + pidx += 1 + # linux partitions may be numbered differently, + # if there are holes in the GPT partition table + onieCmd = ('sgdisk', '-i', str(partno), self.device,) cmd = ('onie-shell', '-c', " ".join(onieCmd),) - buf = self.check_output(cmd) + try: + buf = self.check_output(cmd) + except subprocess.CalledProcessError as ex: + sys.stdout.write(ex.output) + self.log.warn("sgdisk failed with code %s", ex.returncode) + continue + # skip this partition, but otherwise do not give up - ent = GdiskPartEntry.fromOutput(buf) + ent = GdiskPartEntry.fromOutput(partDevice, buf) parts[partno] = ent self.parts = [] From 77fe26a72bf14704e483e00b881fdc9ad2ce033c Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 18 Aug 2017 17:54:03 -0700 Subject: [PATCH 14/67] Proper ESP identification using GPT partition GUID --- .../src/python/onl/install/BaseInstall.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py index e5644fd5..f2eb3c84 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py @@ -19,6 +19,7 @@ import fnmatch, glob from InstallUtils import SubprocessMixin from InstallUtils import MountContext, BlkidParser, PartedParser from InstallUtils import ProcMountsParser +from InstallUtils import GdiskParser from Plugin import Plugin import onl.YamlUtils @@ -511,8 +512,8 @@ menuentry %(boot_menu_entry)s { set onie_boot_label="ONIE-BOOT" set onie_boot_uuid="%(onie_boot_uuid)s" -# filesystem UUID, *not* partition UUID -# (tee hee, GPT GRUB cannot grok partition UUIDs) +# filesystem UUID, *not* GPT partition GUID, *not* GPT partition unique GUID +# (tee hee, GPT GRUB cannot grok partition attributes) function onie_boot_uefi { set root='(hd0,gpt1)' @@ -681,8 +682,24 @@ class GrubInstaller(SubprocessMixin, Base): ctx['boot_loading_name'] = sysconfig.installer.os_name if self.isUEFI: - dev_UEFI = self.blkidParts['EFI System'] - ctx['onie_boot_uuid'] = dev_UEFI.uuid + # XXX assume boot (ESP) partition is on the same device as GRUB + self.log.info("extracting partition UUIDs for %s", self.device) + gp = GdiskParser(self.device, log=self.log) + + espParts = [x for x in gp.parts if x.isEsp] + if not espParts: + self.log.error("cannot find ESP partition on %s", self.device) + return 1 + espDevice = espParts[0].device + self.log.info("found ESP partition %s", espDevice) + + espParts = [x for x in self.blkidParts if x.device==espDevice] + if not espParts: + self.log.error("cannot find blkid entry for ESP partition on %s", espDevice) + return 1 + self.log.info("found ESP filesystem UUID %s", espParts[0].uuid) + + ctx['onie_boot_uuid'] = espParts[0].uuid else: ctx['onie_boot_uuid'] = "" From 279c12a0b5c975f8fac5e3c056beb8973170c301 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Mon, 21 Aug 2017 22:29:05 +0000 Subject: [PATCH 15/67] Latest --- sm/bigcode | 2 +- sm/infra | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sm/bigcode b/sm/bigcode index ad064c4d..cb9b9e55 160000 --- a/sm/bigcode +++ b/sm/bigcode @@ -1 +1 @@ -Subproject commit ad064c4d73903528633954d12fb2f66b9901b331 +Subproject commit cb9b9e55639d7404b722927ba3e0dd92057f1f71 diff --git a/sm/infra b/sm/infra index b23f2577..fd74bf9c 160000 --- a/sm/infra +++ b/sm/infra @@ -1 +1 @@ -Subproject commit b23f2577cb4ab505eb8bdfdd5d599e49da38c142 +Subproject commit fd74bf9c3fa31901ef3570a1b02e5a9621232fbe From e8fa7a690835c114b3a56d265279ab15f2163c3c Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 22 Aug 2017 22:56:18 +0000 Subject: [PATCH 16/67] Trivial compilation fix. --- .../faultd/src/module/src/faultd_handler.c | 192 +++++++++--------- 1 file changed, 93 insertions(+), 99 deletions(-) diff --git a/packages/base/any/faultd/src/module/src/faultd_handler.c b/packages/base/any/faultd/src/module/src/faultd_handler.c index 7c01ebf1..183b93c8 100644 --- a/packages/base/any/faultd/src/module/src/faultd_handler.c +++ b/packages/base/any/faultd/src/module/src/faultd_handler.c @@ -1,21 +1,21 @@ /**************************************************************************//** * - * - * Copyright 2013, 2014 BigSwitch Networks, Inc. - * + * + * Copyright 2013, 2014 BigSwitch Networks, Inc. + * * Licensed under the Eclipse Public License, Version 1.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.eclipse.org/legal/epl-v10.html - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. - * + * * *****************************************************************************/ #include @@ -46,157 +46,151 @@ static pthread_spinlock_t thread_lock__; -static faultd_client_t* faultd_client__ = NULL; +static faultd_client_t* faultd_client__ = NULL; static faultd_info_t faultd_info__; -static int localfd__ = -1; +static int localfd__ = -1; -inline int signal_backtrace__(void** buffer, int size, ucontext_t* context, +int signal_backtrace__(void** buffer, int size, ucontext_t* context, int distance) { #define IP_STACK_FRAME_NUMBER 3 - - int rv; + + int rv; rv = backtrace(buffer, size); - - if(context) { - distance += IP_STACK_FRAME_NUMBER; - + + if(context) { + distance += IP_STACK_FRAME_NUMBER; + #ifdef __i386__ - buffer[distance] = (void*)(context->uc_mcontext.gregs[REG_EIP]); + buffer[distance] = (void*)(context->uc_mcontext.gregs[REG_EIP]); #endif #ifdef __PPC__ - buffer[distance] = (void*)(context->uc_mcontext.regs->nip); + buffer[distance] = (void*)(context->uc_mcontext.regs->nip); #endif /* Note -- 64bit does not require require modifications */ - } - return rv; -} - #include -static void + } + return rv; +} + #include +static void faultd_signal_handler__(int signal, siginfo_t* siginfo, void* context) { - int rv; + int rv; /* * Make sure we syncronize properly with other threads that * may *also* be faulting */ - rv = pthread_spin_trylock(&thread_lock__); + rv = pthread_spin_trylock(&thread_lock__); - if (rv == EBUSY) { - sigset_t mask; - sigemptyset(&mask); - pselect(0, NULL, NULL, NULL, NULL, &mask); + if (rv == EBUSY) { + sigset_t mask; + sigemptyset(&mask); + pselect(0, NULL, NULL, NULL, NULL, &mask); } - + /* - * Generate our fault information. - */ - faultd_info__.pid = getpid(); - faultd_info__.tid = 0; - faultd_info__.signal = signal; - faultd_info__.signal_code = siginfo->si_code; - faultd_info__.fault_address = siginfo->si_addr; - faultd_info__.last_errno = errno; + * Generate our fault information. + */ + faultd_info__.pid = getpid(); + faultd_info__.tid = 0; + faultd_info__.signal = signal; + faultd_info__.signal_code = siginfo->si_code; + faultd_info__.fault_address = siginfo->si_addr; + faultd_info__.last_errno = errno; - faultd_info__.backtrace_size = signal_backtrace__(faultd_info__.backtrace, + faultd_info__.backtrace_size = signal_backtrace__(faultd_info__.backtrace, AIM_ARRAYSIZE(faultd_info__.backtrace), - context, 0); - faultd_info__.backtrace_symbols = (void*)1; - if(faultd_client__) { - faultd_client_write(faultd_client__, &faultd_info__); + context, 0); + faultd_info__.backtrace_symbols = (void*)1; + if(faultd_client__) { + faultd_client_write(faultd_client__, &faultd_info__); } - if(localfd__ >= 0) { - char* signame = strsignal(faultd_info__.signal); - char* nl = "\n"; - write(localfd__, signame, strlen(signame)+1); - write(localfd__, nl, 2); - backtrace_symbols_fd(faultd_info__.backtrace, - faultd_info__.backtrace_size, - localfd__); + if(localfd__ >= 0) { + char* signame = strsignal(faultd_info__.signal); + char* nl = "\n"; + write(localfd__, signame, strlen(signame)+1); + write(localfd__, nl, 2); + backtrace_symbols_fd(faultd_info__.backtrace, + faultd_info__.backtrace_size, + localfd__); } - /* + /* * Unlock spinlock, in case this signal wasn't fatal */ - pthread_spin_unlock(&thread_lock__); + pthread_spin_unlock(&thread_lock__); } int -faultd_handler_register(int localfd, - const char* pipename, +faultd_handler_register(int localfd, + const char* pipename, const char* binaryname) { - int rv; - struct sigaction saction; - void* dummy_backtrace[1]; - int dummy_backtrace_size; - int fd; + int rv; + struct sigaction saction; + void* dummy_backtrace[1]; + int dummy_backtrace_size; + int fd; - if ( (rv = pthread_spin_init(&thread_lock__, 0)) ) { - return rv; + if ( (rv = pthread_spin_init(&thread_lock__, 0)) ) { + return rv; } - /* - * These calls to backtrace are to assure that - * backtrace() and backtrace_symbols_fd() have actually - * been loaded into our process -- its possible they + /* + * These calls to backtrace are to assure that + * backtrace() and backtrace_symbols_fd() have actually + * been loaded into our process -- its possible they * come from a dynamic library, and we don't want them * to get loaded at fault-time. */ - dummy_backtrace_size = backtrace(dummy_backtrace, 1); - - /** Note - we could just pass an invalid descriptor here, but it - * it flags errors in valgrind. + dummy_backtrace_size = backtrace(dummy_backtrace, 1); + + /** Note - we could just pass an invalid descriptor here, but it + * it flags errors in valgrind. */ - fd = open("/dev/null", O_WRONLY); - backtrace_symbols_fd(dummy_backtrace, dummy_backtrace_size, fd); - close(fd); + fd = open("/dev/null", O_WRONLY); + backtrace_symbols_fd(dummy_backtrace, dummy_backtrace_size, fd); + close(fd); - AIM_MEMSET(&faultd_info__, 0, sizeof(faultd_info__)); - if(!binaryname) { - binaryname = "Not specified."; + AIM_MEMSET(&faultd_info__, 0, sizeof(faultd_info__)); + if(!binaryname) { + binaryname = "Not specified."; } - aim_strlcpy(faultd_info__.binary, binaryname, sizeof(faultd_info__.binary)); - + aim_strlcpy(faultd_info__.binary, binaryname, sizeof(faultd_info__.binary)); - if(pipename) { - faultd_client_create(&faultd_client__, pipename); + + if(pipename) { + faultd_client_create(&faultd_client__, pipename); } - AIM_MEMSET(&saction, 0, sizeof(saction)); - saction.sa_sigaction = faultd_signal_handler__; + AIM_MEMSET(&saction, 0, sizeof(saction)); + saction.sa_sigaction = faultd_signal_handler__; - sigfillset(&saction.sa_mask); - saction.sa_flags = SA_SIGINFO | SA_RESETHAND; - - rv = sigaction (SIGSEGV, &saction, NULL); + sigfillset(&saction.sa_mask); + saction.sa_flags = SA_SIGINFO | SA_RESETHAND; + + rv = sigaction (SIGSEGV, &saction, NULL); rv |= sigaction (SIGILL, &saction, NULL); - rv |= sigaction (SIGFPE, &saction, NULL); + rv |= sigaction (SIGFPE, &saction, NULL); rv |= sigaction (SIGBUS, &saction, NULL); rv |= sigaction (SIGQUIT, &saction, NULL); rv |= sigaction (SIGALRM, &saction, NULL); /* - * SIGUSR2 can be used to request a backtrace explicitly. - * In this case, we don't want to reset the handler. + * SIGUSR2 can be used to request a backtrace explicitly. + * In this case, we don't want to reset the handler. */ - saction.sa_flags = SA_SIGINFO; - rv |= sigaction (SIGUSR2, &saction, NULL); + saction.sa_flags = SA_SIGINFO; + rv |= sigaction (SIGUSR2, &saction, NULL); /* * The local fault handler will attempt to write a subset of - * the fault information (signal type and backtrace) - * to the localfd descriptor if specified. + * the fault information (signal type and backtrace) + * to the localfd descriptor if specified. */ - localfd__ = localfd; + localfd__ = localfd; return rv; } - - - - - - From b26cdbbc37ba3cc1def417a0c8f301f549c9e3ac Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 22 Aug 2017 22:57:30 +0000 Subject: [PATCH 17/67] Patch for building with GCC5/6. --- .../kernels/3.16-lts/patches/gcc-no-pie.patch | 16 ++++++++++++++++ .../base/any/kernels/3.16-lts/patches/series | 1 + 2 files changed, 17 insertions(+) create mode 100644 packages/base/any/kernels/3.16-lts/patches/gcc-no-pie.patch diff --git a/packages/base/any/kernels/3.16-lts/patches/gcc-no-pie.patch b/packages/base/any/kernels/3.16-lts/patches/gcc-no-pie.patch new file mode 100644 index 00000000..c682275b --- /dev/null +++ b/packages/base/any/kernels/3.16-lts/patches/gcc-no-pie.patch @@ -0,0 +1,16 @@ +diff -urpN a/Makefile b/Makefile +--- a/Makefile 2017-08-22 17:42:57.037875653 +0000 ++++ b/Makefile 2017-08-22 17:43:53.089875539 +0000 +@@ -616,6 +616,12 @@ include $(srctree)/arch/$(SRCARCH)/Makef + + KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) + ++# Required for GCC-5/6 ++KBUILD_CFLAGS += $(call cc-option, -fno-pie) ++KBUILD_CFLAGS += $(call cc-option, -no-pie) ++KBUILD_AFLAGS += $(call cc-option, -fno-pie) ++KBUILD_CPPFLAGS += $(call cc-option, -fno-pie) ++ + ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE + KBUILD_CFLAGS += -Os $(call cc-disable-warning,maybe-uninitialized,) + else diff --git a/packages/base/any/kernels/3.16-lts/patches/series b/packages/base/any/kernels/3.16-lts/patches/series index 8c9db7bd..e6a083f7 100644 --- a/packages/base/any/kernels/3.16-lts/patches/series +++ b/packages/base/any/kernels/3.16-lts/patches/series @@ -26,3 +26,4 @@ platform-powerpc-dni-7448-r0.patch platform-powerpc-quanta-lb9-r0.patch driver-support-intel-igb-bcm50210-phy.patch driver-igb-netberg-aurora.patch +gcc-no-pie.patch From f2b0e6aa5716dd195e7f6544c01d1ef40211eaf9 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 22 Aug 2017 22:59:07 +0000 Subject: [PATCH 18/67] The 3.2 kernel is no longer in use. --- packages/base/amd64/upgrade/PKG.yml | 1 - packages/base/amd64/upgrade/builds/Makefile | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/base/amd64/upgrade/PKG.yml b/packages/base/amd64/upgrade/PKG.yml index ae40b753..3717282f 100644 --- a/packages/base/amd64/upgrade/PKG.yml +++ b/packages/base/amd64/upgrade/PKG.yml @@ -1,6 +1,5 @@ prerequisites: packages: - - onl-kernel-3.2-lts-x86-64-all:amd64 - onl-kernel-3.16-lts-x86-64-all:amd64 - onl-kernel-4.9-lts-x86-64-all:amd64 - onl-loader-initrd:amd64 diff --git a/packages/base/amd64/upgrade/builds/Makefile b/packages/base/amd64/upgrade/builds/Makefile index ef428d0f..3a7d529c 100644 --- a/packages/base/amd64/upgrade/builds/Makefile +++ b/packages/base/amd64/upgrade/builds/Makefile @@ -1,8 +1,7 @@ include $(ONL)/make/config.amd64.mk # All amd64 kernels -KERNELS := $(shell $(ONLPM) --find-file onl-kernel-3.2-lts-x86-64-all:amd64 kernel-3.2-lts-x86_64-all) \ - $(shell $(ONLPM) --find-file onl-kernel-3.16-lts-x86-64-all:amd64 kernel-3.16-lts-x86_64-all) \ +KERNELS := $(shell $(ONLPM) --find-file onl-kernel-3.16-lts-x86-64-all:amd64 kernel-3.16-lts-x86_64-all) \ $(shell $(ONLPM) --find-file onl-kernel-4.9-lts-x86-64-all:amd64 kernel-4.9-lts-x86_64-all) From 885dc40fab176b708c91b4d014f53da24becaba6 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 22 Aug 2017 16:06:04 -0700 Subject: [PATCH 19/67] Add stretch repositories. --- REPO/stretch/Makefile | 1 + REPO/stretch/packages/binary-all/Makefile | 1 + REPO/stretch/packages/binary-amd64/Makefile | 1 + REPO/stretch/packages/binary-arm64/Makefile | 1 + REPO/stretch/packages/binary-armel/Makefile | 1 + REPO/stretch/packages/binary-powerpc/Makefile | 1 + 6 files changed, 6 insertions(+) create mode 100644 REPO/stretch/Makefile create mode 100644 REPO/stretch/packages/binary-all/Makefile create mode 100644 REPO/stretch/packages/binary-amd64/Makefile create mode 100644 REPO/stretch/packages/binary-arm64/Makefile create mode 100644 REPO/stretch/packages/binary-armel/Makefile create mode 100644 REPO/stretch/packages/binary-powerpc/Makefile diff --git a/REPO/stretch/Makefile b/REPO/stretch/Makefile new file mode 100644 index 00000000..bfbd6a4b --- /dev/null +++ b/REPO/stretch/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/repo-suite.mk diff --git a/REPO/stretch/packages/binary-all/Makefile b/REPO/stretch/packages/binary-all/Makefile new file mode 100644 index 00000000..6283cc30 --- /dev/null +++ b/REPO/stretch/packages/binary-all/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/repo.mk diff --git a/REPO/stretch/packages/binary-amd64/Makefile b/REPO/stretch/packages/binary-amd64/Makefile new file mode 100644 index 00000000..6283cc30 --- /dev/null +++ b/REPO/stretch/packages/binary-amd64/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/repo.mk diff --git a/REPO/stretch/packages/binary-arm64/Makefile b/REPO/stretch/packages/binary-arm64/Makefile new file mode 100644 index 00000000..6283cc30 --- /dev/null +++ b/REPO/stretch/packages/binary-arm64/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/repo.mk diff --git a/REPO/stretch/packages/binary-armel/Makefile b/REPO/stretch/packages/binary-armel/Makefile new file mode 100644 index 00000000..6283cc30 --- /dev/null +++ b/REPO/stretch/packages/binary-armel/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/repo.mk diff --git a/REPO/stretch/packages/binary-powerpc/Makefile b/REPO/stretch/packages/binary-powerpc/Makefile new file mode 100644 index 00000000..6283cc30 --- /dev/null +++ b/REPO/stretch/packages/binary-powerpc/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/repo.mk From 9a17c1eb23f429b98cc02ead50d94ba5c6e35d48 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 22 Aug 2017 16:08:26 -0700 Subject: [PATCH 20/67] Latest --- sm/bigcode | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sm/bigcode b/sm/bigcode index cb9b9e55..a77f6c6b 160000 --- a/sm/bigcode +++ b/sm/bigcode @@ -1 +1 @@ -Subproject commit cb9b9e55639d7404b722927ba3e0dd92057f1f71 +Subproject commit a77f6c6b1ca1c895f954fdbf37991af49c7496d8 From ed45d128e610568b7351005232c5105a028ce7bd Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 22 Aug 2017 16:08:43 -0700 Subject: [PATCH 21/67] Initial Stretch Builds. Needs cleanup. --- .../stretch/common/all-base-packages.yml | 79 +++++++ .../stretch/common/amd64-base-packages.yml | 13 ++ .../stretch/common/amd64-onl-packages.yml | 11 + .../stretch/common/arm64-base-packages.yml | 1 + .../stretch/common/arm64-onl-packages.yml | 9 + .../stretch/common/armel-base-packages.yml | 1 + .../stretch/common/armel-onl-packages.yml | 9 + .../rootfs/stretch/common/overlay/etc/adjtime | 1 + .../stretch/common/overlay/etc/filesystems | 6 + .../stretch/common/overlay/etc/inetd.conf | 3 + .../rootfs/stretch/common/overlay/etc/inittab | 67 ++++++ .../stretch/common/overlay/etc/mtab.yml | 19 ++ .../etc/profile.d/onl-platform-current.sh | 7 + .../stretch/common/overlay/etc/rssh.conf | 4 + .../common/overlay/etc/snmp/snmpd.conf | 195 ++++++++++++++++++ .../overlay/etc/udev/rules.d/60-block.rules | 1 + .../overlay/etc/udev/rules.d/60-net.rules | 1 + .../rootfs/stretch/common/overlay/sbin/pgetty | 23 +++ .../stretch/common/overlay/sbin/watchdir | 71 +++++++ .../stretch/common/powerpc-base-packages.yml | 11 + .../stretch/common/powerpc-onl-packages.yml | 9 + .../any/rootfs/stretch/standard/standard.yml | 105 ++++++++++ 22 files changed, 646 insertions(+) create mode 100644 builds/any/rootfs/stretch/common/all-base-packages.yml create mode 100644 builds/any/rootfs/stretch/common/amd64-base-packages.yml create mode 100644 builds/any/rootfs/stretch/common/amd64-onl-packages.yml create mode 100644 builds/any/rootfs/stretch/common/arm64-base-packages.yml create mode 100644 builds/any/rootfs/stretch/common/arm64-onl-packages.yml create mode 100644 builds/any/rootfs/stretch/common/armel-base-packages.yml create mode 100644 builds/any/rootfs/stretch/common/armel-onl-packages.yml create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/adjtime create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/filesystems create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/inetd.conf create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/inittab create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/mtab.yml create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/profile.d/onl-platform-current.sh create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/rssh.conf create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/snmp/snmpd.conf create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/udev/rules.d/60-block.rules create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/udev/rules.d/60-net.rules create mode 100755 builds/any/rootfs/stretch/common/overlay/sbin/pgetty create mode 100755 builds/any/rootfs/stretch/common/overlay/sbin/watchdir create mode 100644 builds/any/rootfs/stretch/common/powerpc-base-packages.yml create mode 100644 builds/any/rootfs/stretch/common/powerpc-onl-packages.yml create mode 100644 builds/any/rootfs/stretch/standard/standard.yml diff --git a/builds/any/rootfs/stretch/common/all-base-packages.yml b/builds/any/rootfs/stretch/common/all-base-packages.yml new file mode 100644 index 00000000..e6ef6a3a --- /dev/null +++ b/builds/any/rootfs/stretch/common/all-base-packages.yml @@ -0,0 +1,79 @@ +############################################################ +# +# Common Release Packages for all systems. +# +############################################################ +- base-files +- sysvinit-core +- locales +- python +- apt +- apt-utils +- procps +- net-tools +- iputils-ping +- less +- sudo +- openssh-server +- iproute +- resolvconf +- vim-tiny +- zile +- nano +- lsof +- mingetty +- traceroute +- realpath +- rsyslog +- nfs-common +- netbase +- bsdmainutils +- ifupdown +- psmisc +- make +- python-cherrypy3 +- python-tz +- scapy +- python-pypcap +- snmpd +- snmp +- pciutils +- usbutils +- mtd-utils +- i2c-tools +- isc-dhcp-client +- ntp +- wget +- ethtool +- localepurge +- telnetd +- python-pyinotify +- cpio +- util-linux +- dosfstools +- rssh +- u-boot-tools +- ntpdate +- onlp +- parted +- watchdog +- netplug +- binutils +- file +- smartmontools +- realpath +- iptables +- onl-faultd +- onlp-snmpd +- oom-shim +- python-parted +- python-yaml +- bzip2 +- xz-utils +- unzip +- onl-mibs +- openssl +- gdb +- tcpdump +- strace +- sysstat diff --git a/builds/any/rootfs/stretch/common/amd64-base-packages.yml b/builds/any/rootfs/stretch/common/amd64-base-packages.yml new file mode 100644 index 00000000..a07863f3 --- /dev/null +++ b/builds/any/rootfs/stretch/common/amd64-base-packages.yml @@ -0,0 +1,13 @@ +############################################################ +# +# Common packages for all amd64 systems. +# +############################################################ +- dmidecode +- parted +- smartmontools +- grub2 +- onl-upgrade +- hw-management +- sx-kernel +- onl-kernel-3.16-lts-x86-64-all-modules diff --git a/builds/any/rootfs/stretch/common/amd64-onl-packages.yml b/builds/any/rootfs/stretch/common/amd64-onl-packages.yml new file mode 100644 index 00000000..984f2fc3 --- /dev/null +++ b/builds/any/rootfs/stretch/common/amd64-onl-packages.yml @@ -0,0 +1,11 @@ +############################################################ +# +# These packages are specific to the ONL root filesystem build. +# +############################################################ +- onl-upgrade + + + + + diff --git a/builds/any/rootfs/stretch/common/arm64-base-packages.yml b/builds/any/rootfs/stretch/common/arm64-base-packages.yml new file mode 100644 index 00000000..71c41a67 --- /dev/null +++ b/builds/any/rootfs/stretch/common/arm64-base-packages.yml @@ -0,0 +1 @@ +- u-boot-tools diff --git a/builds/any/rootfs/stretch/common/arm64-onl-packages.yml b/builds/any/rootfs/stretch/common/arm64-onl-packages.yml new file mode 100644 index 00000000..e58df638 --- /dev/null +++ b/builds/any/rootfs/stretch/common/arm64-onl-packages.yml @@ -0,0 +1,9 @@ +############################################################ +# +# These packages are specific to the ONL root filesystem build. +# +############################################################ +- onl-loader-fit + + + diff --git a/builds/any/rootfs/stretch/common/armel-base-packages.yml b/builds/any/rootfs/stretch/common/armel-base-packages.yml new file mode 100644 index 00000000..71c41a67 --- /dev/null +++ b/builds/any/rootfs/stretch/common/armel-base-packages.yml @@ -0,0 +1 @@ +- u-boot-tools diff --git a/builds/any/rootfs/stretch/common/armel-onl-packages.yml b/builds/any/rootfs/stretch/common/armel-onl-packages.yml new file mode 100644 index 00000000..e58df638 --- /dev/null +++ b/builds/any/rootfs/stretch/common/armel-onl-packages.yml @@ -0,0 +1,9 @@ +############################################################ +# +# These packages are specific to the ONL root filesystem build. +# +############################################################ +- onl-loader-fit + + + diff --git a/builds/any/rootfs/stretch/common/overlay/etc/adjtime b/builds/any/rootfs/stretch/common/overlay/etc/adjtime new file mode 100644 index 00000000..7481b115 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/adjtime @@ -0,0 +1 @@ +0.0 0 0.0 diff --git a/builds/any/rootfs/stretch/common/overlay/etc/filesystems b/builds/any/rootfs/stretch/common/overlay/etc/filesystems new file mode 100644 index 00000000..01350bea --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/filesystems @@ -0,0 +1,6 @@ +jffs2 +ubifs +vfat +ext4 +ext3 +ext2 diff --git a/builds/any/rootfs/stretch/common/overlay/etc/inetd.conf b/builds/any/rootfs/stretch/common/overlay/etc/inetd.conf new file mode 100644 index 00000000..367f8d08 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/inetd.conf @@ -0,0 +1,3 @@ +telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd +qotd stream tcp nowait telnetd /usr/sbin/tcpd /sbin/versiond + diff --git a/builds/any/rootfs/stretch/common/overlay/etc/inittab b/builds/any/rootfs/stretch/common/overlay/etc/inittab new file mode 100644 index 00000000..e242bf0a --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/inittab @@ -0,0 +1,67 @@ +# The default runlevel. +id:2:initdefault: + +# Boot-time system configuration/initialization script. +# This is run first except when booting in emergency (-b) mode. +si0::sysinit:/etc/boot.d/boot +si1::sysinit:/etc/init.d/rcS + +# What to do in single-user mode. +~~:S:wait:/sbin/sulogin + +# /etc/init.d executes the S and K scripts upon change +# of runlevel. +# +# Runlevel 0 is halt. +# Runlevel 1 is single-user. +# Runlevels 2-5 are multi-user. +# Runlevel 6 is reboot. + +l0:0:wait:/etc/init.d/rc 0 +l1:1:wait:/etc/init.d/rc 1 +l2:2:wait:/etc/init.d/rc 2 +l3:3:wait:/etc/init.d/rc 3 +l4:4:wait:/etc/init.d/rc 4 +l5:5:wait:/etc/init.d/rc 5 +l6:6:wait:/etc/init.d/rc 6 +# Normally not reached, but fallthrough in case of emergency. +z6:6:respawn:/sbin/sulogin + +# What to do when CTRL-ALT-DEL is pressed. +ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now + +# Action on special keypress (ALT-UpArrow). +#kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work." + +# What to do when the power fails/returns. +pf::powerwait:/etc/init.d/powerfail start +pn::powerfailnow:/etc/init.d/powerfail now +po::powerokwait:/etc/init.d/powerfail stop + +# /sbin/getty invocations for the runlevels. +# +# The "id" field MUST be the same as the last +# characters of the device (after "tty"). +# +# Format: +# ::: +# +# Note that on most Debian systems tty7 is used by the X Window System, +# so if you want to add more getty's go ahead but skip tty7 if you run X. +# +1:2345:respawn:/sbin/getty 38400 tty1 +2:23:respawn:/sbin/getty 38400 tty2 +3:23:respawn:/sbin/getty 38400 tty3 +4:23:respawn:/sbin/getty 38400 tty4 +5:23:respawn:/sbin/getty 38400 tty5 +6:23:respawn:/sbin/getty 38400 tty6 + +# Example how to put a getty on a serial line (for a terminal) +# +#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100 +#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100 + +# Example how to put a getty on a modem line. +# +#T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3 + diff --git a/builds/any/rootfs/stretch/common/overlay/etc/mtab.yml b/builds/any/rootfs/stretch/common/overlay/etc/mtab.yml new file mode 100644 index 00000000..598e4c69 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/mtab.yml @@ -0,0 +1,19 @@ +mounts: + ONL-IMAGES: + mount: ro + dir: /mnt/onl/images + fsck: true + + ONL-DATA: + mount: rw + dir: /mnt/onl/data + + ONL-CONFIG: + mount: ro + dir: /mnt/onl/config + fsck: true + + ONL-BOOT: + mount: ro + dir: /mnt/onl/boot + fsck: false diff --git a/builds/any/rootfs/stretch/common/overlay/etc/profile.d/onl-platform-current.sh b/builds/any/rootfs/stretch/common/overlay/etc/profile.d/onl-platform-current.sh new file mode 100644 index 00000000..5237bbb8 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/profile.d/onl-platform-current.sh @@ -0,0 +1,7 @@ +############################################################ +# +# Add platform specific directories to path. +# +############################################################ +dir=/lib/platform-config/current/onl +export PATH="$PATH:$dir/bin:$dir/sbin:$dir/lib/bin:$dir/lib/sbin" diff --git a/builds/any/rootfs/stretch/common/overlay/etc/rssh.conf b/builds/any/rootfs/stretch/common/overlay/etc/rssh.conf new file mode 100644 index 00000000..33975b18 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/rssh.conf @@ -0,0 +1,4 @@ +logfacility = LOG_USER +allowsftp +allowscp +umask = 022 diff --git a/builds/any/rootfs/stretch/common/overlay/etc/snmp/snmpd.conf b/builds/any/rootfs/stretch/common/overlay/etc/snmp/snmpd.conf new file mode 100644 index 00000000..13eb88f7 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/snmp/snmpd.conf @@ -0,0 +1,195 @@ +############################################################################### +# +# EXAMPLE.conf: +# An example configuration file for configuring the Net-SNMP agent ('snmpd') +# See the 'snmpd.conf(5)' man page for details +# +# Some entries are deliberately commented out, and will need to be explicitly activated +# +############################################################################### +# +# AGENT BEHAVIOUR +# + +# Listen for connections from the local system only +# agentAddress udp:127.0.0.1:161 +# Listen for connections on all interfaces (both IPv4 *and* IPv6) +agentAddress udp:161,udp6:[::1]:161 + + + +############################################################################### +# +# SNMPv3 AUTHENTICATION +# +# Note that these particular settings don't actually belong here. +# They should be copied to the file /var/lib/snmp/snmpd.conf +# and the passwords changed, before being uncommented in that file *only*. +# Then restart the agent + +# createUser authOnlyUser MD5 "remember to change this password" +# createUser authPrivUser SHA "remember to change this one too" DES +# createUser internalUser MD5 "this is only ever used internally, but still change the password" + +# If you also change the usernames (which might be sensible), +# then remember to update the other occurances in this example config file to match. + + + +############################################################################### +# +# ACCESS CONTROL +# + + # system + hrSystem groups only +view systemonly included .1.3.6.1.2.1.1 +view systemonly included .1.3.6.1.2.1.25.1 +view systemonly included .1.3.6.1.4.1.42623 + # Full access from the local host +rocommunity public localhost + # Default access to basic system info + rocommunity public default -V systemonly + # rocommunity6 is for IPv6 + rocommunity6 public default -V systemonly + + # Full access from an example network + # Adjust this network address to match your local + # settings, change the community string, + # and check the 'agentAddress' setting above +#rocommunity secret 10.0.0.0/16 + + # Full read-only access for SNMPv3 + rouser authOnlyUser + # Full write access for encrypted requests + # Remember to activate the 'createUser' lines above +#rwuser authPrivUser priv + +# It's no longer typically necessary to use the full 'com2sec/group/access' configuration +# r[ow]user and r[ow]community, together with suitable views, should cover most requirements + + + +############################################################################### +# +# SYSTEM INFORMATION +# + +# Note that setting these values here, results in the corresponding MIB objects being 'read-only' +# See snmpd.conf(5) for more details +sysLocation Sitting on the Dock of the Bay +sysContact Me + # Application + End-to-End layers +sysServices 72 + + +# +# Process Monitoring +# + # At least one 'mountd' process +proc mountd + # No more than 4 'ntalkd' processes - 0 is OK +proc ntalkd 4 + # At least one 'sendmail' process, but no more than 10 +proc sendmail 10 1 + +# Walk the UCD-SNMP-MIB::prTable to see the resulting output +# Note that this table will be empty if there are no "proc" entries in the snmpd.conf file + + +# +# Disk Monitoring +# + # 10MBs required on root disk, 5% free on /var, 10% free on all other disks +disk / 10000 +disk /var 5% +includeAllDisks 10% + +# Walk the UCD-SNMP-MIB::dskTable to see the resulting output +# Note that this table will be empty if there are no "disk" entries in the snmpd.conf file + + +# +# System Load +# + # Unacceptable 1-, 5-, and 15-minute load averages +load 12 10 5 + +# Walk the UCD-SNMP-MIB::laTable to see the resulting output +# Note that this table *will* be populated, even without a "load" entry in the snmpd.conf file + + + +############################################################################### +# +# ACTIVE MONITORING +# + + # send SNMPv1 traps + trapsink localhost public + # send SNMPv2c traps +#trap2sink localhost public + # send SNMPv2c INFORMs +#informsink localhost public + +# Note that you typically only want *one* of these three lines +# Uncommenting two (or all three) will result in multiple copies of each notification. + + +# +# Event MIB - automatically generate alerts +# + # Remember to activate the 'createUser' lines above +iquerySecName internalUser +rouser internalUser + # generate traps on UCD error conditions +defaultMonitors yes + # generate traps on linkUp/Down +linkUpDownNotifications yes + + + +############################################################################### +# +# EXTENDING THE AGENT +# + +# +# Arbitrary extension commands +# + extend test1 /bin/echo Hello, world! + extend-sh test2 echo Hello, world! ; echo Hi there ; exit 35 +#extend-sh test3 /bin/sh /tmp/shtest + +# Note that this last entry requires the script '/tmp/shtest' to be created first, +# containing the same three shell commands, before the line is uncommented + +# Walk the NET-SNMP-EXTEND-MIB tables (nsExtendConfigTable, nsExtendOutput1Table +# and nsExtendOutput2Table) to see the resulting output + +# Note that the "extend" directive supercedes the previous "exec" and "sh" directives +# However, walking the UCD-SNMP-MIB::extTable should still returns the same output, +# as well as the fuller results in the above tables. + + +# +# "Pass-through" MIB extension command +# +#pass .1.3.6.1.4.1.8072.2.255 /bin/sh PREFIX/local/passtest +#pass .1.3.6.1.4.1.8072.2.255 /usr/bin/perl PREFIX/local/passtest.pl + +# Note that this requires one of the two 'passtest' scripts to be installed first, +# before the appropriate line is uncommented. +# These scripts can be found in the 'local' directory of the source distribution, +# and are not installed automatically. + +# Walk the NET-SNMP-PASS-MIB::netSnmpPassExamples subtree to see the resulting output + + +# +# AgentX Sub-agents +# + # Run as an AgentX master agent + master agentx + # Listen for network connections (from localhost) + # rather than the default named socket /var/agentx/master +#agentXSocket tcp:localhost:705 diff --git a/builds/any/rootfs/stretch/common/overlay/etc/udev/rules.d/60-block.rules b/builds/any/rootfs/stretch/common/overlay/etc/udev/rules.d/60-block.rules new file mode 100644 index 00000000..f2345a37 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/udev/rules.d/60-block.rules @@ -0,0 +1 @@ +SUBSYSTEM=="block", RUN+="/sbin/initblockdev $kernel $env{ACTION}" diff --git a/builds/any/rootfs/stretch/common/overlay/etc/udev/rules.d/60-net.rules b/builds/any/rootfs/stretch/common/overlay/etc/udev/rules.d/60-net.rules new file mode 100644 index 00000000..627e65e4 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/udev/rules.d/60-net.rules @@ -0,0 +1 @@ +SUBSYSTEM=="net", RUN+="/sbin/initnetdev $kernel $env{ACTION}" diff --git a/builds/any/rootfs/stretch/common/overlay/sbin/pgetty b/builds/any/rootfs/stretch/common/overlay/sbin/pgetty new file mode 100755 index 00000000..01ed10dc --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/sbin/pgetty @@ -0,0 +1,23 @@ +#!/bin/sh + +t=/dev/$1 +# if $1 is not set, use linux cmdline console as default tty +[ -z "$1" ] && { + tty=$(/bin/sed 's/.*console=\([^,]*\).*/\1/' /proc/cmdline) + t=/dev/$tty +} + +# Reset the console tty to standard settings +/bin/stty -F $t sane pass8 -ixon -cstopb clocal + +# Kill any processes with the console tty open before starting a new +# login session (login tries to do this, but vhangup() spares processes +# that ignore SIGHUP) +#/usr/bin/lsof -p ^$$ -t $t 0<&- 1>&- 2>&- | /usr/bin/xargs -r /bin/kill -9 + +# Flush tty input and output queues +#/sbin/flushtty <$t + +# We use mingetty instead of agetty, as the latter messes up the tty +# settings if it receives junk characters at the wrong speed +exec /sbin/mingetty --noclear $t diff --git a/builds/any/rootfs/stretch/common/overlay/sbin/watchdir b/builds/any/rootfs/stretch/common/overlay/sbin/watchdir new file mode 100755 index 00000000..3ff32aa7 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/sbin/watchdir @@ -0,0 +1,71 @@ +#!/usr/bin/python +############################################################ +# +# +# Copyright 2013, 2014 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# watchdir +# +############################################################ +import optparse, os.path, sys +import pyinotify + +#pyinotify.log.setLevel(pyinotify.logging.DEBUG) + +op = optparse.OptionParser( usage="%prog [OPTIONS] command") +op.add_option("-w", "--watchdir", action="append", + help="monitor watchdir for changes (may be used multiple times)") +op.add_option("--period", action="store", type="float", + help="run command at most every period sec (default=%default)") +op.add_option("-d", "--daemon", action="store_true", + help="run in background") +op.add_option("--logfile", action="store", + help="send output to logfile when running in background") +op.add_option("--pidfile", action="store", + help="write pid to pidfile when running in background") +op.set_defaults(period=0, logfile="/dev/stdout", pidfile=False) +opts, args = op.parse_args() + +if not opts.watchdir: + op.error("need at least one watchdir") + +os.close(0) +os.open("/dev/null", os.O_RDONLY) + +wm = pyinotify.WatchManager() +n = pyinotify.Notifier(wm, read_freq=opts.period) +def handle(event): + dir = None + for d in opts.watchdir: + if os.path.commonprefix([d, event.pathname]) == d: + dir = d + sys.stdout.write("%s: %s %s\n" % (dir, event.pathname, event)) + sys.stdout.flush() + if args: + os.spawnvp(os.P_WAIT, args[0], + args + [dir, event.pathname, event.maskname]) +wm.add_watch( + opts.watchdir, + pyinotify.IN_ATTRIB | pyinotify.IN_CREATE | pyinotify.IN_DELETE | + pyinotify.IN_MODIFY | pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO, + handle, + rec=True, + auto_add=True) +n.loop(daemonize=opts.daemon, stdout=opts.logfile, stderr=opts.logfile, + pid_file=opts.pidfile) diff --git a/builds/any/rootfs/stretch/common/powerpc-base-packages.yml b/builds/any/rootfs/stretch/common/powerpc-base-packages.yml new file mode 100644 index 00000000..e876f6bd --- /dev/null +++ b/builds/any/rootfs/stretch/common/powerpc-base-packages.yml @@ -0,0 +1,11 @@ +############################################################ +# +# Common packages for all PowerPC systems. +# +############################################################ +- u-boot-tools + + + + + diff --git a/builds/any/rootfs/stretch/common/powerpc-onl-packages.yml b/builds/any/rootfs/stretch/common/powerpc-onl-packages.yml new file mode 100644 index 00000000..e58df638 --- /dev/null +++ b/builds/any/rootfs/stretch/common/powerpc-onl-packages.yml @@ -0,0 +1,9 @@ +############################################################ +# +# These packages are specific to the ONL root filesystem build. +# +############################################################ +- onl-loader-fit + + + diff --git a/builds/any/rootfs/stretch/standard/standard.yml b/builds/any/rootfs/stretch/standard/standard.yml new file mode 100644 index 00000000..48969cbe --- /dev/null +++ b/builds/any/rootfs/stretch/standard/standard.yml @@ -0,0 +1,105 @@ +############################################################ +# +# Standard ONL Debian 9 Root Filesystem Configuration. +# +# Requires: +# ARCH, PLATFORM_LIST +# +# +############################################################ +variables: + !include $ONL/make/versions/version-onl.yml + +Packages: &Packages + - !include $ONL/builds/any/rootfs/$ONL_DEBIAN_SUITE/common/all-base-packages.yml + - !include $ONL/builds/any/rootfs/$ONL_DEBIAN_SUITE/common/${ARCH}-base-packages.yml + - !include $ONL/builds/any/rootfs/$ONL_DEBIAN_SUITE/common/${ARCH}-onl-packages.yml + - !script $ONL/tools/onl-platform-pkgs.py ${PLATFORM_LIST} + +Multistrap: + General: + arch: ${ARCH} + cleanup: true + noauth: true + explicitsuite: false + unpack: true + debootstrap: Debian-Local Local-All Local-Arch ONL + aptsources: Debian ONL + + Debian: + packages: *Packages + source: http://${DEBIAN_MIRROR} + suite: ${ONL_DEBIAN_SUITE} + keyring: debian-archive-keyring + omitdebsrc: true + + Debian-Local: + packages: *Packages + source: http://${APT_CACHE}${DEBIAN_MIRROR} + suite: ${ONL_DEBIAN_SUITE} + keyring: debian-archive-keyring + omitdebsrc: true + + ONL: + packages: *Packages + source: http://apt.opennetlinux.org/debian + suite: unstable + omitdebsrc: true + + Local-All: + source: ${ONLPM_OPTION_REPO}/${ONL_DEBIAN_SUITE}/packages/binary-all + omitdebsrc: true + + Local-Arch: + source: ${ONLPM_OPTION_REPO}/${ONL_DEBIAN_SUITE}/packages/binary-${ARCH} + omitdebsrc: true + +Configure: + overlays: + - ${ONL}/builds/any/rootfs/${ONL_DEBIAN_SUITE}/common/overlay + + update-rc.d: + - 'faultd defaults' + - 'onlpd defaults' + - 'snmpd defaults' + - 'onlp-snmpd defaults' + - 'ssh defaults' + - 'openbsd-inetd remove' + - 'ntp remove' + - 'nfs-common remove' + - 'rpcbind remove' + - 'motd remove' + - 'mountall-bootclean.sh remove' + - 'mountall.sh remove' + - 'checkfs.sh remove' + - 'mtab.sh remove' + - 'checkroot-bootclean.sh remove' + - 'checkroot.sh remove' + - 'mountnfs-bootclean.sh remove' + - 'mountnfs.sh remove' + - 'lm-sensors remove' + - 'netplug defaults' + - 'watchdog defaults' + - 'wd_keepalive remove' + + options: + clean: True + securetty: False + ttys: False + console: True + PermitRootLogin: 'yes' + + users: + root: + password: onl + + manifests: + '/etc/onl/rootfs/manifest.json' : + version : $ONL/make/versions/version-onl.json + platforms : $PLATFORM_LIST + + issue: $VERSION_STRING + + files: + remove: + - /etc/motd From 90489177a524868f24597a999eb65a787e66e945 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Tue, 22 Aug 2017 16:12:22 -0700 Subject: [PATCH 22/67] Unmount the ESP directory for launching the installer --- builds/any/installer/installer.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builds/any/installer/installer.sh.in b/builds/any/installer/installer.sh.in index 76b33987..e3d968aa 100644 --- a/builds/any/installer/installer.sh.in +++ b/builds/any/installer/installer.sh.in @@ -528,7 +528,7 @@ installer_force_umount() { dev=$1; shift mpt=$1; shift case "$mpt" in - /mnt/*) + /mnt/*|/boot/*) installer_say "Unmounting $mpt (--force)" umount "$mpt" ;; From 9bb6e63a1f173553084536a9ff290597d87c40d0 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Tue, 22 Aug 2017 16:13:12 -0700 Subject: [PATCH 23/67] Oops forgot to gather the onieDir - eliminates most uses of proxy grub --- .../all/vendor-config-onl/src/python/onl/install/ShellApp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/ShellApp.py b/packages/base/all/vendor-config-onl/src/python/onl/install/ShellApp.py index e3a5e505..7c5f2c6c 100644 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/ShellApp.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/ShellApp.py @@ -88,7 +88,7 @@ class AppBase(SubprocessMixin, object): sys.exit(code) class OnieBootContext: - """Find the ONIE initrd and umpack/mount it.""" + """Find the ONIE initrd and unpack/mount it.""" def __init__(self, log=None): self.log = log or logging.getLogger(self.__class__.__name__) @@ -128,6 +128,7 @@ class OnieBootContext: initrd = _g(parts[0].dir) if initrd is None: raise ValueError("cannot find ONIE initrd on %s" % parts[0].dir) + self.onieDir = parts[0].dir self.log.debug("found ONIE initrd at %s", initrd) with InitrdContext(initrd=initrd, log=self.log) as self.ictx: self.initrd = initrd From e819231bb56bc3b4f197e1fa2a26ab117945dc28 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Tue, 22 Aug 2017 16:21:16 -0700 Subject: [PATCH 24/67] Fixes to support chroot etc. - use an available chroot when running gdisk - Add a simple onie-shell adapter --- .../src/python/onl/install/InstallUtils.py | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py index dac4f222..ccb4615e 100644 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py @@ -752,16 +752,16 @@ class GdiskPartEntry: class GdiskParser(SubprocessMixin): - def __init__(self, device, log=None): + def __init__(self, device, subprocessContext=subprocess, log=None): self.device = device self.log = log or logging.getLogger("parted") + self.subprocessContext = subprocessContext self.parse() def parse(self): - onieCmd = ('sgdisk', '-p', self.device,) - cmd = ('onie-shell', '-c', " ".join(onieCmd),) - buf = self.check_output(cmd) + cmd = ('sgdisk', '-p', self.device,) + buf = self.subprocessContext.check_output(cmd) self.disk = GdiskDiskEntry.fromOutput(buf) parts = {} @@ -779,10 +779,9 @@ class GdiskParser(SubprocessMixin): # linux partitions may be numbered differently, # if there are holes in the GPT partition table - onieCmd = ('sgdisk', '-i', str(partno), self.device,) - cmd = ('onie-shell', '-c', " ".join(onieCmd),) + cmd = ('sgdisk', '-i', str(partno), self.device,) try: - buf = self.check_output(cmd) + buf = self.subprocessContext.check_output(cmd) except subprocess.CalledProcessError as ex: sys.stdout.write(ex.output) self.log.warn("sgdisk failed with code %s", ex.returncode) @@ -1209,9 +1208,55 @@ class ChrootSubprocessMixin: cmd = ['chroot', self.chrootDir,] + list(cmd) if not self.mounted: - with InitrdContext(self.chrootDir, log=self.log) as ctx: + with InitrdContext(dir=self.chrootDir, log=self.log) as ctx: self.log.debug("+ " + " ".join(cmd)) return subprocess.check_output(cmd, *args, cwd=cwd, **kwargs) else: self.log.debug("+ " + " ".join(cmd)) return subprocess.check_output(cmd, *args, cwd=cwd, **kwargs) + +class OnieSubprocess: + """Simple subprocess mixin that defers to onie-shell.""" + + def __init__(self, log=None): + self.log = log or logging.getLogger("onie") + + def check_call(self, *args, **kwargs): + args = list(args) + kwargs = dict(kwargs) + + cwd = kwargs.pop('cwd', None) + if cwd is not None: + raise ValueError("cwd not supported") + + if args: + cmd = args.pop(0) + else: + cmd = kwargs.pop('cmd') + if isinstance(cmd, basestring): + cmd = ('onie-shell', '-c', 'IFS=;' + cmd,) + else: + cmd = ['onie-shell', '-c',] + " ".join(cmd) + + self.log.debug("+ " + " ".join(cmd)) + subprocess.check_call(cmd, *args, cwd=cwd, **kwargs) + + def check_output(self, *args, **kwargs): + args = list(args) + kwargs = dict(kwargs) + + cwd = kwargs.pop('cwd', None) + if cwd is not None: + raise ValueError("cwd not supported") + + if args: + cmd = args.pop(0) + else: + cmd = kwargs.pop('cmd') + if isinstance(cmd, basestring): + cmd = ('onie-shell', '-c', 'IFS=;' + cmd,) + else: + cmd = ['onie-shell', '-c',] + " ".join(list(cmd)) + + self.log.debug("+ " + " ".join(cmd)) + return subprocess.check_output(cmd, *args, cwd=cwd, **kwargs) From 5bb959a38ef5bcaa01748ea31be610f202192e13 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Tue, 22 Aug 2017 16:23:19 -0700 Subject: [PATCH 25/67] Refactor install support for UEFI - handle proxy- and non-proxy setups - handle boot entry manipulation - properly set the OS name via sysconfig - mount ESP partition for grub-efi --- .../src/python/onl/install/ConfUtils.py | 184 ++++++++++++++---- 1 file changed, 147 insertions(+), 37 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/ConfUtils.py b/packages/base/all/vendor-config-onl/src/python/onl/install/ConfUtils.py index 62e5fc66..3e63541b 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/ConfUtils.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/ConfUtils.py @@ -7,7 +7,11 @@ import os import logging import subprocess from InstallUtils import SubprocessMixin, ChrootSubprocessMixin, MountContext +from InstallUtils import OnieSubprocess from cStringIO import StringIO +import re + +from onl.sysconfig import sysconfig class ConfBase: @@ -90,13 +94,16 @@ class GrubEnv(SubprocessMixin): INSTALL = "grub-install" EDITENV = "grub-editenv" + EFIBOOTMGR = "efibootmgr" # system default ENV_PATH = "/grub/grubenv" # override me + EFI_BOOT_RE = re.compile("Boot([0-9a-fA-F]*)[*] (.*)") + def __init__(self, - bootDir=None, bootPart=None, + bootDir=None, bootPart=None, espPart=None, path=None, log=None): @@ -108,13 +115,16 @@ class GrubEnv(SubprocessMixin): self.__dict__['bootPart'] = bootPart # location of GRUB boot files (mounted directory or unmounted partition) + self.__dict__['espPart'] = espPart + # location of EFI System Partition + self.__dict__['path'] = path or self.ENV_PATH # path to grubenv, relative to above self.__dict__['log'] = log or logging.getLogger("grub") - def mountCtx(self, device): - return MountContext(device, fsType='ext4', log=self.log) + def mountCtx(self, device, fsType='ext4'): + return MountContext(device, fsType=fsType, log=self.log) def asDict(self): if self.bootPart: @@ -164,36 +174,83 @@ class GrubEnv(SubprocessMixin): cmd = (self.EDITENV, p, 'unset', attr,) self.check_call(cmd) + @property + def isUEFI(self): + return os.path.isdir('/sys/firmware/efi/efivars') + def install(self, device): - if self.bootDir is not None: - self.check_call((self.INSTALL, '--boot-directory=' + self.bootDir, device,)) - elif self.bootPart is not None: - with self.mountCtx(self.bootPart) as ctx: - self.check_call((self.INSTALL, '--boot-directory=' + ctx.dir, device,)) + + uidx = None + if self.isUEFI: + buf = self.check_output((self.EFIBOOTMGR,)) + for line in buf.splitlines(False): + m = self.EFI_BOOT_RE.match(line) + if m: + if m.group(2) == sysconfig.installer.os_name: + uidx = m.group(1) + break + if uidx is not None: + self.check_output((self.EFIBOOTMGR, '-b', uidx, '-B',)) + + grubOpts = [] + if self.isUEFI: + grubOpts.append('--target=x86_64-efi') + grubOpts.append('--no-nvram') + grubOpts.append('--recheck') + + grubOpts.append('--bootloader-id=ONL') + # All ONL-derived distros should be able to use + # the same profile + + def _install(): + if self.bootDir is not None: + self.check_call([self.INSTALL, '--boot-directory=' + self.bootDir,] + + grubOpts + + [device,]) + elif self.bootPart is not None: + with self.mountCtx(self.bootPart) as ctx: + self.check_call([self.INSTALL, '--boot-directory=' + ctx.dir,] + + grubOpts + + [device,]) + else: + self.check_call([self.INSTALL,] + grubOpts + [device,]) + + if self.espPart is not None: + with self.mountCtx(self.espPart, fsType=None) as ctx: + grubOpts.append('--efi-directory=' + ctx.dir) + _install() else: - self.check_call((self.INSTALL, device,)) + _install() + + if self.isUEFI: + self.check_call((self.EFIBOOTMGR, + '--create', + '--label', sysconfig.installer.os_name, + '--disk', device, + '--part', '1', + '--loader', '/EFI/ONL/grubx64.efi',)) class ChrootGrubEnv(ChrootSubprocessMixin, GrubEnv): def __init__(self, chrootDir, mounted=False, - bootDir=None, bootPart=None, + bootDir=None, bootPart=None, espPart=None, path=None, log=None): self.__dict__['chrootDir'] = chrootDir self.__dict__['mounted'] = mounted GrubEnv.__init__(self, - bootDir=bootDir, bootPart=bootPart, + bootDir=bootDir, bootPart=bootPart, espPart=espPart, path=path, log=log) - def mountCtx(self, device): + def mountCtx(self, device, fsType='ext4'): return MountContext(device, - chroot=self.chrootDir, fsType='ext4', + chroot=self.chrootDir, fsType=fsType, log=self.log) -class ProxyGrubEnv: +class ProxyGrubEnv(SubprocessMixin): """Pretend to manipulate the GRUB environment. Instead, write a trace of shell commands to a log @@ -211,7 +268,7 @@ class ProxyGrubEnv: def __init__(self, installerConf, - bootDir=None, chroot=True, bootPart=None, + bootDir=None, chroot=True, bootPart=None, espPart=None, path=None, log=None): @@ -226,6 +283,9 @@ class ProxyGrubEnv: self.__dict__['bootPart'] = bootPart # location of GRUB boot files (mounted directory or unmounted partition) + self.__dict__['espPart'] = espPart + # location of EFI System Partition + self.__dict__['chroot'] = chroot # True of the bootDir is inside the chroot, # else bootDir is in the host's file namespace @@ -261,7 +321,8 @@ class ProxyGrubEnv: % (self.path.lstrip('/'),)) cmds.append("mpt=$(mktemp -t -d)") cmds.append("mount %s $mpt" % self.bootPart) - cmds.append(("sts=0; %s %s set %s=\"%s\" || sts=$?" + cmds.append("sts=0") + cmds.append(("%s %s set %s=\"%s\" || sts=$?" % (self.EDITENV, p, attr, val,))) cmds.append("umount $mpt") cmds.append("rmdir $mpt") @@ -291,7 +352,8 @@ class ProxyGrubEnv: % (self.path.lstrip('/'),)) cmds.append("mpt=$(mktemp -t -d)") cmds.append("mount %s $mpt" % self.bootPart) - cmds.append(("sts=0; %s %s unset %s || sts=$?" + cmds.append("sts=0") + cmds.append(("%s %s unset %s || sts=$?" % (self.EDITENV, p, attr,))) cmds.append("umount $mpt") cmds.append("rmdir $mpt") @@ -303,35 +365,83 @@ class ProxyGrubEnv: fd.write(cmd) fd.write("\n") - def install(self, device, isUEFI=False): + @property + def isUEFI(self): + return os.path.isdir('/sys/firmware/efi/efivars') + + def install(self, device): self.log.warn("deferring commands to %s...", self.installerConf.installer_postinst) + + cmds.append("os_name=\"%s\"" % sysconfig.installer.os_name) + + if self.isUEFI: + sub = OnieSubprocess(log=self.log.getChild("onie")) + cmd = (self.EFIBOOTMGR,) + buf = sub.check_output(cmd) + bidx = None + for line in buf.splitlines(False): + m = self.EFI_BOOT_RE.match(line) + if m: + if m.group(2) == sysconfig.installer.os_name: + uidx = m.group(1) + break + + if uidx is not None: + cmds.append("%s -b %s -B || sts=$?" % (self.EFIBOOTMGR, bidx,)) + + grubOpts = [] + if self.isUEFI: + grubOpts.append('--target=x86_64-efi') + grubOpts.append('--no-nvram') + grubOpts.append('--bootloader-id=ONL') + grubOpts.append('--efi-directory=/boot/efi') + grubOpts.append('--recheck') + cmds = [] + + if self.bootPart and not self.bootDir: + cmds.append("bootMpt=$(mktemp -t -d)") + cmds.append("mount %s $bootMpt" % self.bootPart) + + if self.espPart is not None: + cmds.append("espMpt=$(mktemp -t -d)") + cmds.append("mount %s $espMpt" % self.espPart) + + cmds.append("sts=0") + if self.bootDir and self.chroot: p = os.pat.join(self.installerConf.installer_chroot, self.bootDir.lstrip('/')) - cmds.append(("%s --boot-directory=\"%s\" %s" % (self.INSTALL, p, device,))) + cmd = ([self.INSTALL, '--boot-directory=' + p,] + + grubOpts + + [device,]) + cmds.append(" ".join(cmd) + " || sts=$?") elif self.bootDir: p = self.bootDir - cmds.append(("%s --boot-directory=\"%s\" %s" % (self.INSTALL, p, device,))) + cmd = ([self.INSTALL, '--boot-directory=' + p,] + + grubOpts + + [device,]) + cmds.append(" ".join(cmd) + " || sts=$?") elif self.bootPart: - cmds.append("mpt=$(mktemp -t -d)") - cmds.append("mount %s $mpt" % self.bootPart) - if isUEFI: - cmds.append("[ -n \"$(efibootmgr -v | grep 'Open Network Linux')\" ] && (efibootmgr -b $(efibootmgr | grep \"Open Network Linux\" | sed 's/^.*Boot//g'| sed 's/** Open.*$//g') -B)") - cmds.append(("sts=0; %s --target=x86_64-efi --no-nvram --bootloader-id=ONL --efi-directory=/boot/efi --boot-directory=\"$mpt\" --recheck %s || sts=$?" - % (self.INSTALL, device,))) - cmds.append("test $sts -eq 0") - cmds.append(("sts=0; %s --quiet --create --label \"Open Network Linux\" --disk %s --part 1 --loader /EFI/ONL/grubx64.efi || sts=$?" - % (self.EFIBOOTMGR , device,))) - else: - cmds.append(("sts=0; %s --boot-directory=\"$mpt\" %s || sts=$?" - % (self.INSTALL, device,))) - cmds.append("umount $mpt") - cmds.append("rmdir $mpt") - cmds.append("test $sts -eq 0") + cmd = ([self.INSTALL, '--boot-directory=\"$bootMpt\"',] + + grubOpts + + [device,]) + cmds.append(" ".join(cmd) + " || sts=$?") else: - cmds.append(("%s %s" - % (self.INSTALL, device,))) + cmd = ([self.INSTALL,] + + grubOpts + + [device,]) + cmds.append(" ".join(cmd) + " || sts=$?") + + if self.bootPart and not self.bootDir: + cmds.append("umount $bootMpt") + cmds.append("rmdir $bootMpt") + + if self.espPart is not None: + cmds.append("umount $espMpt") + cmds.append("rmdir $espMpt") + + cmds.append("test $sts -eq 0") with open(self.installerConf.installer_postinst, "a") as fd: for cmd in cmds: From 046684f323923eef3a78003f0da4e03bcad0c0d9 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Tue, 22 Aug 2017 16:24:38 -0700 Subject: [PATCH 26/67] Refactor UEFI support - find the ESP partition and its UUID --- .../src/python/onl/install/BaseInstall.py | 71 ++++++++++++++----- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py index f2eb3c84..2ca43c17 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py @@ -20,8 +20,11 @@ from InstallUtils import SubprocessMixin from InstallUtils import MountContext, BlkidParser, PartedParser from InstallUtils import ProcMountsParser from InstallUtils import GdiskParser +from InstallUtils import OnieSubprocess from Plugin import Plugin +import onl.install.ConfUtils + import onl.YamlUtils from onl.sysconfig import sysconfig @@ -549,6 +552,10 @@ class GrubInstaller(SubprocessMixin, Base): def __init__(self, *args, **kwargs): Base.__init__(self, *args, **kwargs) + self.espDevice = None + self.espFsUuid = None + # optionally fill in ESP partition information + @property def isUEFI(self): return os.path.isdir('/sys/firmware/efi/efivars') @@ -635,6 +642,42 @@ class GrubInstaller(SubprocessMixin, Base): return 0 + def findEsp(self): + """Find the block device holding the EFI System Partition. + + XXX assume boot (ESP) partition is on the same device as GRUB + """ + + self.log.info("extracting partition UUIDs for %s", self.device) + + if isinstance(self.im.grubEnv, onl.install.ConfUtils.GrubEnv): + # direct (or chroot) access + gp = GdiskParser(self.device, + subprocessContext=self.im.grubEnv, + log=self.log) + else: + # indirect access using onie-shell + ctx = OnieSubprocess(log=self.log.getChild("onie")) + gp = GdiskParser(self.device, + subprocessContext=ctx, + log=self.log) + + espParts = [x for x in gp.parts if x.isEsp] + if not espParts: + self.log.error("cannot find ESP partition on %s", self.device) + return 1 + self.espDevice = espParts[0].device + self.log.info("found ESP partition %s", self.espDevice) + + espParts = [x for x in self.blkidParts if x.device==self.espDevice] + if not espParts: + self.log.error("cannot find blkid entry for ESP partition on %s", self.espDevice) + return 1 + self.espFsUuid = espParts[0].uuid + self.log.info("found ESP filesystem UUID %s", self.espFsUuid) + + return 0 + def installLoader(self): kernels = [] @@ -682,24 +725,7 @@ class GrubInstaller(SubprocessMixin, Base): ctx['boot_loading_name'] = sysconfig.installer.os_name if self.isUEFI: - # XXX assume boot (ESP) partition is on the same device as GRUB - self.log.info("extracting partition UUIDs for %s", self.device) - gp = GdiskParser(self.device, log=self.log) - - espParts = [x for x in gp.parts if x.isEsp] - if not espParts: - self.log.error("cannot find ESP partition on %s", self.device) - return 1 - espDevice = espParts[0].device - self.log.info("found ESP partition %s", espDevice) - - espParts = [x for x in self.blkidParts if x.device==espDevice] - if not espParts: - self.log.error("cannot find blkid entry for ESP partition on %s", espDevice) - return 1 - self.log.info("found ESP filesystem UUID %s", espParts[0].uuid) - - ctx['onie_boot_uuid'] = espParts[0].uuid + ctx['onie_boot_uuid'] = self.espFsUuid else: ctx['onie_boot_uuid'] = "" @@ -717,7 +743,7 @@ class GrubInstaller(SubprocessMixin, Base): def installGrub(self): self.log.info("Installing GRUB to %s", self.partedDevice.path) - self.im.grubEnv.install(self.partedDevice.path, self.isUEFI) + self.im.grubEnv.install(self.partedDevice.path) return 0 def installGpt(self): @@ -736,6 +762,13 @@ class GrubInstaller(SubprocessMixin, Base): code = self.findGpt() if code: return code + if self.isUEFI: + code = self.findEsp() + if code: return code + self.im.grubEnv.__dict__['espPart'] = self.espDevice + else: + self.im.grubEnv.__dict__['espPart'] = None + self.log.info("Installing to %s starting at partition %d", self.device, self.minpart) From 446c16851c6f53abecb47f6c051d53207cd79cbc Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 22 Aug 2017 16:42:06 -0700 Subject: [PATCH 27/67] Initial builder9. Work In Progress. --- docker/images/builder9/1.0/Dockerfile | 137 ++++++++++++++++++++++++++ docker/images/builder9/1.0/Makefile | 19 ++++ 2 files changed, 156 insertions(+) create mode 100644 docker/images/builder9/1.0/Dockerfile create mode 100644 docker/images/builder9/1.0/Makefile diff --git a/docker/images/builder9/1.0/Dockerfile b/docker/images/builder9/1.0/Dockerfile new file mode 100644 index 00000000..cd109362 --- /dev/null +++ b/docker/images/builder9/1.0/Dockerfile @@ -0,0 +1,137 @@ +FROM debian:9.1 +MAINTAINER Jeff Townsend + +# First round of dependences +RUN apt-get update && apt-get install -y \ + apt \ + apt-cacher-ng \ + apt-file \ + apt-utils \ + autoconf \ + automake \ + autotools-dev \ + bash-completion \ + bc \ + bind9-host \ + binfmt-support \ + binfmt-support \ + bison \ + bsdmainutils \ + build-essential \ + ccache \ + cdbs \ + cpio \ + cryptsetup-bin \ + debhelper \ + debhelper \ + debhelper \ + device-tree-compiler \ + devscripts \ + devscripts \ + dialog \ + dosfstools \ + doxygen \ + dpkg-sig \ + emacs \ + file \ + flex \ + gawk \ + gcc \ + gdb \ + genisoimage \ + git \ + gperf \ + ifupdown \ + iproute \ + iputils-ping \ + isolinux \ + kmod \ + less \ + libc6-dev \ + libcurl4-nss-dev \ + libdouble-conversion-dev \ + libedit-dev \ + libevent-dev \ + libexpat1-dev \ + libgoogle-glog-dev \ + libi2c-dev \ + libkrb5-dev \ + libnuma-dev \ + libsasl2-dev \ + libsnappy-dev \ + libpam-dev \ + libpcap-dev \ + libsnmp-dev \ + libssl-dev \ + libtool \ + libtool-bin \ + locales \ + lsof \ + make \ + mingetty \ + mtd-utils \ + mtools \ + multistrap \ + nano \ + ncurses-dev \ + netbase \ + net-tools \ + nfs-common \ + openssh-server \ + pkg-config \ + pkg-config \ + procps \ + psmisc \ + python \ + python-debian \ + python-dnspython \ + python-yaml \ + qemu \ + qemu-user-static \ + realpath \ + realpath \ + rsyslog \ + ruby \ + ruby-dev \ + rubygems \ + screen \ + squashfs-tools \ + sshpass \ + stgit \ + sudo \ + syslinux-utils \ + telnet \ + texinfo \ + traceroute \ + u-boot-tools \ + vim-tiny \ + wget \ + xorriso \ + zile \ + zip + +RUN apt-get install -y \ +chrpath devscripts dh-autoreconf dh-systemd flex \ +libcap-dev libc-ares-dev libjson-c-dev libpam0g-dev libpcre3-dev \ +libreadline-dev libsystemd-dev pkg-config \ +texlive-generic-recommended texinfo texlive-latex-base + +RUN gem install --version 1.3.3 fpm + +# +# The i2c-dev.h user/kernel header conflict is a nightmare. +# +# The ONLP implementation expects a new file called to be in place which contains the correct user-space driver definitions. +# This should be manually populated here after the toolchains have been installed. +# +RUN cp /usr/include/linux/i2c-dev.h /usr/include/linux/i2c-devices.h + +RUN rm /etc/apt/apt.conf.d/docker-* && \ + wget "https://launchpad.net/ubuntu/+source/qemu/1.4.0+dfsg-1expubuntu3/+build/4336762/+files/qemu-user-static_1.4.0%2Bdfsg-1expubuntu3_amd64.deb" && \ + dpkg -i qemu-user-static_1.4.0+dfsg-1expubuntu3_amd64.deb + +# +# Copy the docker shell init script to /bin +# +COPY docker_shell /bin/docker_shell +COPY container-id /bin/container-id diff --git a/docker/images/builder9/1.0/Makefile b/docker/images/builder9/1.0/Makefile new file mode 100644 index 00000000..cd91ae81 --- /dev/null +++ b/docker/images/builder9/1.0/Makefile @@ -0,0 +1,19 @@ +VERSION=1.0-beta +USER=opennetworklinux +REPO=builder9 + +TOOLS=../../../tools/docker_shell ../../../tools/container-id + +build: check_version + cp $(TOOLS) . + docker build -t $(USER)/$(REPO):$(VERSION) . + rm -rf $(notdir $(TOOLS)) + +# +# Todo: Query remote repository to see if the request version already exists to avoid accidental overwrites +# when a new image is built but the VERSION variable is not updated. +# +check_version: + +push: + docker push $(USER)/$(REPO):$(VERSION) From 0e5f91fb1865a62e9c77dc216236bc87d10efccd Mon Sep 17 00:00:00 2001 From: Zi Zhou Date: Tue, 22 Aug 2017 17:07:23 -0700 Subject: [PATCH 28/67] support 40GBASE-ER4 optics --- .../base/any/onlp/src/sff/module/auto/sff.yml | 2 ++ .../any/onlp/src/sff/module/inc/sff/8436.h | 19 ++++++++++++++++++- .../any/onlp/src/sff/module/inc/sff/sff.h | 2 ++ .../any/onlp/src/sff/module/inc/sff/sff.x | 2 ++ .../base/any/onlp/src/sff/module/src/sff.c | 8 ++++++++ .../any/onlp/src/sff/module/src/sff_enums.c | 2 ++ packages/base/any/onlp/src/sff/sff.mk | 4 ++-- 7 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/base/any/onlp/src/sff/module/auto/sff.yml b/packages/base/any/onlp/src/sff/module/auto/sff.yml index 07b931ea..8977bcad 100644 --- a/packages/base/any/onlp/src/sff/module/auto/sff.yml +++ b/packages/base/any/onlp/src/sff/module/auto/sff.yml @@ -69,6 +69,8 @@ sff_module_types: &sff_module_types desc: "40GBASE-SR2" - 40G_BASE_SM4: desc: "40GBASE-SM4" +- 40G_BASE_ER4: + desc: "40GBASE-ER4" - 25G_BASE_CR: desc: "25GBASE-CR" - 10G_BASE_SR: diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/8436.h b/packages/base/any/onlp/src/sff/module/inc/sff/8436.h index 6383eddf..ee6640ab 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/8436.h +++ b/packages/base/any/onlp/src/sff/module/inc/sff/8436.h @@ -115,7 +115,7 @@ ((idprom[131] & SFF8436_CC131_40GE_ACTIVE) != 0) #define SFF8436_MEDIA_NONE(idprom) \ - (idprom[131] == 0) + ((idprom[131] & 0x7F) == 0) #define SFF8436_CC132_40G_OTN 0x08 #define SFF8436_CC132_OC48_LONG SFF8472_CC4_OC48_LONG @@ -291,6 +291,23 @@ _sff8436_qsfp_40g_sm4(const uint8_t* idprom) return 1; } +static inline int +_sff8436_qsfp_40g_er4(const uint8_t* idprom) +{ + if(!SFF8436_MODULE_QSFP_PLUS_V2(idprom)) { + return 0; + } + + if (idprom[130] != SFF8436_CONN_LC) return 0; + if (!SFF8436_MEDIA_NONE(idprom)) return 0; + + /* 40 kilometer SMF */ + if (idprom[142] != 40) { + return 0; + } + return 1; +} + static inline int _sff8436_bitrate(const uint8_t *idprom) { diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/sff.h b/packages/base/any/onlp/src/sff/module/inc/sff/sff.h index ec9e9c0a..367b6c0e 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/sff.h +++ b/packages/base/any/onlp/src/sff/module/inc/sff/sff.h @@ -110,6 +110,7 @@ typedef enum sff_module_type_e { SFF_MODULE_TYPE_40G_BASE_CR, SFF_MODULE_TYPE_40G_BASE_SR2, SFF_MODULE_TYPE_40G_BASE_SM4, + SFF_MODULE_TYPE_40G_BASE_ER4, SFF_MODULE_TYPE_25G_BASE_CR, SFF_MODULE_TYPE_10G_BASE_SR, SFF_MODULE_TYPE_10G_BASE_LR, @@ -148,6 +149,7 @@ typedef enum sff_module_type_e { "40G_BASE_CR", \ "40G_BASE_SR2", \ "40G_BASE_SM4", \ + "40G_BASE_ER4", \ "25G_BASE_CR", \ "10G_BASE_SR", \ "10G_BASE_LR", \ diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/sff.x b/packages/base/any/onlp/src/sff/module/inc/sff/sff.x index ed354ef1..1efe7884 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/sff.x +++ b/packages/base/any/onlp/src/sff/module/inc/sff/sff.x @@ -20,6 +20,7 @@ SFF_MEDIA_TYPE_ENTRY(40G_BASE_ACTIVE, 40GBASE-ACTIVE) SFF_MEDIA_TYPE_ENTRY(40G_BASE_CR, 40GBASE-CR) SFF_MEDIA_TYPE_ENTRY(40G_BASE_SR2, 40GBASE-SR2) SFF_MEDIA_TYPE_ENTRY(40G_BASE_SM4, 40GBASE-SM4) +SFF_MEDIA_TYPE_ENTRY(40G_BASE_ER4, 40GBASE-ER4) SFF_MEDIA_TYPE_ENTRY(25G_BASE_CR, 25GBASE-CR) SFF_MEDIA_TYPE_ENTRY(10G_BASE_SR, 10GBASE-SR) SFF_MEDIA_TYPE_ENTRY(10G_BASE_LR, 10GBASE-LR) @@ -64,6 +65,7 @@ SFF_MODULE_TYPE_ENTRY(40G_BASE_ACTIVE, 40GBASE-ACTIVE) SFF_MODULE_TYPE_ENTRY(40G_BASE_CR, 40GBASE-CR) SFF_MODULE_TYPE_ENTRY(40G_BASE_SR2, 40GBASE-SR2) SFF_MODULE_TYPE_ENTRY(40G_BASE_SM4, 40GBASE-SM4) +SFF_MODULE_TYPE_ENTRY(40G_BASE_ER4, 40GBASE-ER4) SFF_MODULE_TYPE_ENTRY(25G_BASE_CR, 25GBASE-CR) SFF_MODULE_TYPE_ENTRY(10G_BASE_SR, 10GBASE-SR) SFF_MODULE_TYPE_ENTRY(10G_BASE_LR, 10GBASE-LR) diff --git a/packages/base/any/onlp/src/sff/module/src/sff.c b/packages/base/any/onlp/src/sff/module/src/sff.c index eec75130..34a554a0 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff.c +++ b/packages/base/any/onlp/src/sff/module/src/sff.c @@ -132,6 +132,11 @@ sff_module_type_get(const uint8_t* eeprom) return SFF_MODULE_TYPE_40G_BASE_SM4; } + if (SFF8436_MODULE_QSFP_PLUS_V2(eeprom) + && _sff8436_qsfp_40g_er4(eeprom)) { + return SFF_MODULE_TYPE_40G_BASE_ER4; + } + if (SFF8472_MODULE_SFP(eeprom) && SFF8472_MEDIA_XGE_SR(eeprom) && !_sff8472_media_gbe_sx_fc_hack(eeprom)) @@ -242,6 +247,7 @@ sff_media_type_get(sff_module_type_t mt) case SFF_MODULE_TYPE_40G_BASE_ACTIVE: case SFF_MODULE_TYPE_40G_BASE_SR2: case SFF_MODULE_TYPE_40G_BASE_SM4: + case SFF_MODULE_TYPE_40G_BASE_ER4: case SFF_MODULE_TYPE_10G_BASE_SR: case SFF_MODULE_TYPE_10G_BASE_LR: case SFF_MODULE_TYPE_10G_BASE_LRM: @@ -291,6 +297,7 @@ sff_module_caps_get(sff_module_type_t mt, uint32_t *caps) case SFF_MODULE_TYPE_40G_BASE_CR: case SFF_MODULE_TYPE_40G_BASE_SR2: case SFF_MODULE_TYPE_40G_BASE_SM4: + case SFF_MODULE_TYPE_40G_BASE_ER4: *caps |= SFF_MODULE_CAPS_F_40G; return 0; @@ -687,6 +694,7 @@ sff_info_init(sff_info_t* info, sff_module_type_t mt, case SFF_MODULE_TYPE_40G_BASE_ACTIVE: case SFF_MODULE_TYPE_40G_BASE_SR2: case SFF_MODULE_TYPE_40G_BASE_SM4: + case SFF_MODULE_TYPE_40G_BASE_ER4: case SFF_MODULE_TYPE_4X_MUX: info->sfp_type = SFF_SFP_TYPE_QSFP_PLUS; info->media_type = SFF_MEDIA_TYPE_FIBER; diff --git a/packages/base/any/onlp/src/sff/module/src/sff_enums.c b/packages/base/any/onlp/src/sff/module/src/sff_enums.c index 7f4d2b17..b2ce8fc3 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff_enums.c +++ b/packages/base/any/onlp/src/sff/module/src/sff_enums.c @@ -144,6 +144,7 @@ aim_map_si_t sff_module_type_map[] = { "40G_BASE_CR", SFF_MODULE_TYPE_40G_BASE_CR }, { "40G_BASE_SR2", SFF_MODULE_TYPE_40G_BASE_SR2 }, { "40G_BASE_SM4", SFF_MODULE_TYPE_40G_BASE_SM4 }, + { "40G_BASE_ER4", SFF_MODULE_TYPE_40G_BASE_ER4 }, { "25G_BASE_CR", SFF_MODULE_TYPE_25G_BASE_CR }, { "10G_BASE_SR", SFF_MODULE_TYPE_10G_BASE_SR }, { "10G_BASE_LR", SFF_MODULE_TYPE_10G_BASE_LR }, @@ -179,6 +180,7 @@ aim_map_si_t sff_module_type_desc_map[] = { "40GBASE-CR", SFF_MODULE_TYPE_40G_BASE_CR }, { "40GBASE-SR2", SFF_MODULE_TYPE_40G_BASE_SR2 }, { "40GBASE-SM4", SFF_MODULE_TYPE_40G_BASE_SM4 }, + { "40GBASE-ER4", SFF_MODULE_TYPE_40G_BASE_ER4 }, { "25GBASE-CR", SFF_MODULE_TYPE_25G_BASE_CR }, { "10GBASE-SR", SFF_MODULE_TYPE_10G_BASE_SR }, { "10GBASE-LR", SFF_MODULE_TYPE_10G_BASE_LR }, diff --git a/packages/base/any/onlp/src/sff/sff.mk b/packages/base/any/onlp/src/sff/sff.mk index 8becb2c5..e982638c 100644 --- a/packages/base/any/onlp/src/sff/sff.mk +++ b/packages/base/any/onlp/src/sff/sff.mk @@ -3,12 +3,12 @@ # # Inclusive Makefile for the sff module. # -# Autogenerated 2017-05-22 21:57:32.679978 +# Autogenerated 2017-08-22 22:14:08.507022 # ############################################################################### sff_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) include $(sff_BASEDIR)module/make.mk -include $(sff_BASEDIR)module/auto/make.mk include $(sff_BASEDIR)module/src/make.mk +include $(sff_BASEDIR)module/auto/make.mk include $(sff_BASEDIR)utest/_make.mk From 0e19777233f46f69768d9a93e24a8da4950b5325 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 23 Aug 2017 00:23:48 +0000 Subject: [PATCH 29/67] Compilation fixes for GCC6. --- .../onlp/builds/src/module/src/i2c_chips.c | 4 +- .../onlp/builds/src/module/src/ledi.c | 322 ++++++++-------- .../onlp/builds/src/module/src/psui.c | 357 +++++++++--------- 3 files changed, 340 insertions(+), 343 deletions(-) diff --git a/packages/platforms/celestica/x86-64/x86-64-cel-redstone-xp/onlp/builds/src/module/src/i2c_chips.c b/packages/platforms/celestica/x86-64/x86-64-cel-redstone-xp/onlp/builds/src/module/src/i2c_chips.c index 84b1cfc6..cfdeeb9e 100644 --- a/packages/platforms/celestica/x86-64/x86-64-cel-redstone-xp/onlp/builds/src/module/src/i2c_chips.c +++ b/packages/platforms/celestica/x86-64/x86-64-cel-redstone-xp/onlp/builds/src/module/src/i2c_chips.c @@ -458,7 +458,7 @@ int getCtrlOfBus(void) return getCtrlOfBus_9541(); } -static const struct fan_cpld_reg fan_cpld_reg[FAN_NUM] = { +const struct fan_cpld_reg fan_cpld_reg[FAN_NUM] = { {0x180, 0x181}, {0x182, 0x183}, {0x184, 0x185}, @@ -1952,5 +1952,3 @@ int fanSpeedSet(int id, unsigned short speed) } return ret; } - - diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/ledi.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/ledi.c index e697dce4..4400b2cc 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/ledi.c @@ -2,7 +2,7 @@ * * * Copyright 2014 Big Switch Networks, Inc. - * Copyright (C) 2017 Delta Networks, Inc. + * Copyright (C) 2017 Delta Networks, Inc. * * Licensed under the Eclipse Public License, Version 1.0 (the * "License"); you may not use this file except in compliance @@ -43,44 +43,44 @@ * Get the information for the given LED OID. */ static onlp_led_info_t linfo[] = -{ - { }, /* Not used */ { - { ONLP_LED_ID_CREATE(LED_FRONT_FAN), "FRONT LED (FAN LED)", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING | ONLP_LED_CAPS_AUTO, - }, - { - { ONLP_LED_ID_CREATE(LED_FRONT_SYS), "FRONT LED (SYS LED)", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_AUTO, - }, - { - { ONLP_LED_ID_CREATE(LED_FRONT_PWR), "FRONT LED (PWR LED)", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING, - }, - { - { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1), "FAN TRAY 1 LED", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, - }, - { - { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2), "FAN TRAY 2 LED", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, - }, - { - { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3), "FAN TRAY 3 LED", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, - }, - { - { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4), "FAN TRAY 4 LED", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, - }, -}; + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_FRONT_FAN), "FRONT LED (FAN LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_FRONT_SYS), "FRONT LED (SYS LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_FRONT_PWR), "FRONT LED (PWR LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING, + }, + { + { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1), "FAN TRAY 1 LED", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2), "FAN TRAY 2 LED", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3), "FAN TRAY 3 LED", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4), "FAN TRAY 4 LED", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + }; /* * This function will be called prior to any other onlp_ledi_* functions. */ @@ -104,10 +104,10 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) dev_info.flags = DEFAULT_FLAG; /* Set front panel's mode of leds */ - r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,LED_REG); + r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,LED_REG); int local_id = ONLP_OID_ID_GET(id); switch(local_id) - { + { case LED_FRONT_FAN: if((r_data & 0xc0) == 0x80) info->mode = ONLP_LED_MODE_GREEN; @@ -120,11 +120,11 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) break; case LED_FRONT_SYS: if((r_data & 0x30) == 0x10) - info->mode = ONLP_LED_MODE_GREEN; + info->mode = ONLP_LED_MODE_GREEN; else if((r_data & 0x30) == 0x20) - info->mode = ONLP_LED_MODE_ORANGE; + info->mode = ONLP_LED_MODE_ORANGE; else if((r_data & 0x30) == 0x00) - info->mode = ONLP_LED_MODE_GREEN_BLINKING; + info->mode = ONLP_LED_MODE_GREEN_BLINKING; else return ONLP_STATUS_E_INTERNAL; break; @@ -143,12 +143,12 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG); fantray_present = dni_i2c_lock_read(NULL, &dev_info); if(fantray_present >= 0) - { - if((r_data & 0x01) == 0x01) - info->mode = ONLP_LED_MODE_GREEN; - else - info->mode = ONLP_LED_MODE_ORANGE; - } + { + if((r_data & 0x01) == 0x01) + info->mode = ONLP_LED_MODE_GREEN; + else + info->mode = ONLP_LED_MODE_ORANGE; + } else info->mode = ONLP_LED_MODE_OFF; break; @@ -157,12 +157,12 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG); fantray_present = dni_i2c_lock_read(NULL, &dev_info); if(fantray_present >= 0) - { - if((r_data & 0x04) == 0x04) - info->mode = ONLP_LED_MODE_GREEN; - else - info->mode = ONLP_LED_MODE_ORANGE; - } + { + if((r_data & 0x04) == 0x04) + info->mode = ONLP_LED_MODE_GREEN; + else + info->mode = ONLP_LED_MODE_ORANGE; + } else info->mode = ONLP_LED_MODE_OFF; break; @@ -171,12 +171,12 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG); fantray_present = dni_i2c_lock_read(NULL, &dev_info); if(fantray_present >= 0) - { - if((r_data & 0x10) == 0x10) - info->mode = ONLP_LED_MODE_GREEN; - else - info->mode = ONLP_LED_MODE_ORANGE; - } + { + if((r_data & 0x10) == 0x10) + info->mode = ONLP_LED_MODE_GREEN; + else + info->mode = ONLP_LED_MODE_ORANGE; + } else info->mode = ONLP_LED_MODE_OFF; break; @@ -185,20 +185,20 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG); fantray_present = dni_i2c_lock_read(NULL, &dev_info); if(fantray_present >= 0) - { - if((r_data & 0x40) == 0x40) - info->mode = ONLP_LED_MODE_GREEN; - else - info->mode = ONLP_LED_MODE_ORANGE; - } + { + if((r_data & 0x40) == 0x40) + info->mode = ONLP_LED_MODE_GREEN; + else + info->mode = ONLP_LED_MODE_ORANGE; + } else info->mode = ONLP_LED_MODE_OFF; break; default: break; - } + } /* Set the on/off status */ - if (info->mode == ONLP_LED_MODE_OFF) + if (info->mode == ONLP_LED_MODE_OFF) info->status |= ONLP_LED_STATUS_FAILED; else info->status |=ONLP_LED_STATUS_PRESENT; @@ -250,40 +250,40 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) fan_led_status_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_STAT1_REG); fan_tray_pres_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_STAT2_REG); alarm_reg_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,ALARM_REG); - - switch(local_id) - { - case LED_FRONT_FAN: + + switch(local_id) + { + case LED_FRONT_FAN: /* Clean the bit 7,6 */ front_panel_led_value &= ~0xC0; fan_board_not_present_count = 0; - /* Read cpld fan status to check present. Fan tray 1-4 */ + /* Read cpld fan status to check present. Fan tray 1-4 */ for(i = 0; i < 4; i++) - { - fan_stat2_reg_mask = 0x01 << i; - fan_stat1_reg_mask = 0x01 << (i * 2); - if((fan_tray_pres_value & fan_stat2_reg_mask) == fan_stat2_reg_mask) - fan_board_not_present_count++; - else if((fan_led_status_value & fan_stat1_reg_mask) == fan_stat1_reg_mask) - count++; - } + { + fan_stat2_reg_mask = 0x01 << i; + fan_stat1_reg_mask = 0x01 << (i * 2); + if((fan_tray_pres_value & fan_stat2_reg_mask) == fan_stat2_reg_mask) + fan_board_not_present_count++; + else if((fan_led_status_value & fan_stat1_reg_mask) == fan_stat1_reg_mask) + count++; + } /* Set front light of FAN */ if(count == ALL_FAN_TRAY_EXIST) - { - front_panel_led_value |= 0x80;/*Solid green, FAN operates normally.*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); - } + { + front_panel_led_value |= 0x80;/*Solid green, FAN operates normally.*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } else if (fan_board_not_present_count > 0) - { - front_panel_led_value |= 0xc0;/*Blinking Yellow , FAN is failed */ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); - } + { + front_panel_led_value |= 0xc0;/*Blinking Yellow , FAN is failed */ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } else - { - front_panel_led_value |= 0x40;/*Solid Amber FAN operating is NOT present */ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); - } - + { + front_panel_led_value |= 0x40;/*Solid Amber FAN operating is NOT present */ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } + break; case LED_FRONT_PWR: @@ -298,52 +298,52 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) psu2_state = dni_i2c_lock_read(NULL, &dev_info); if(psu1_state == 1 && psu2_state == 1) - { - power_state = dni_lock_cpld_read_attribute(MASTER_CPLD_PATH,PSU_STAT_REG); - - if((power_state & 0x40) == 0x40 || (power_state & 0x04) == 0x04) { - front_panel_led_value |= 0x06; /*Blinking Amber*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + power_state = dni_lock_cpld_read_attribute(MASTER_CPLD_PATH,PSU_STAT_REG); + + if((power_state & 0x40) == 0x40 || (power_state & 0x04) == 0x04) + { + front_panel_led_value |= 0x06; /*Blinking Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } + else + { + front_panel_led_value |= 0x04; /*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } } - else - { - front_panel_led_value |= 0x04; /*Solid Green*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); - } - } else front_panel_led_value |= 0x02; /*Solid Amber*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); break; - + case LED_FRONT_SYS: /* Clean bit 4,5 */ front_panel_led_value &= ~0x30; - fan_board_not_present_count = 0; + fan_board_not_present_count = 0; /* Read fan eeprom to check present */ for(i = 0;i < 4; i++) - { - fan_stat2_reg_mask = 0x01 << i; - if((fan_tray_pres_value & fan_stat2_reg_mask) == fan_stat2_reg_mask) - fan_board_not_present_count++; - } - if(fan_board_not_present_count > 0 || (alarm_reg_value & 0xff) == 0xff) - { - fan_tray_interface_detected_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,INTERRUPT_REG); - if(fan_tray_interface_detected_value == 0xfe || (alarm_reg_value & 0xff) == 0xff) { - front_panel_led_value |= 0x20; + fan_stat2_reg_mask = 0x01 << i; + if((fan_tray_pres_value & fan_stat2_reg_mask) == fan_stat2_reg_mask) + fan_board_not_present_count++; + } + if(fan_board_not_present_count > 0 || (alarm_reg_value & 0xff) == 0xff) + { + fan_tray_interface_detected_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,INTERRUPT_REG); + if(fan_tray_interface_detected_value == 0xfe || (alarm_reg_value & 0xff) == 0xff) + { + front_panel_led_value |= 0x20; + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH, LED_REG, front_panel_led_value); + } + } + else + { + front_panel_led_value |= 0x10; dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH, LED_REG, front_panel_led_value); } - } - else - { - front_panel_led_value |= 0x10; - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH, LED_REG, front_panel_led_value); - } break; - + case LED_REAR_FAN_TRAY_1: dev_info.addr = FAN_TRAY_1; fantray_present = dni_i2c_lock_read(NULL, &dev_info); @@ -351,15 +351,15 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) rpm1 = dni_i2c_lock_read_attribute(NULL, FAN1_REAR); fan_tray_led_reg_value &= ~0x03; if(fantray_present >= 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) - { - fan_tray_led_reg_value |= 0x01;/*Solid Green*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); - } + { + fan_tray_led_reg_value |= 0x01;/*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } else - { - fan_tray_led_reg_value |= 0x02;/*Solid Amber*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); - } + { + fan_tray_led_reg_value |= 0x02;/*Solid Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } break; case LED_REAR_FAN_TRAY_2: @@ -368,17 +368,17 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) rpm = dni_i2c_lock_read_attribute(NULL, FAN2_FRONT); rpm1 = dni_i2c_lock_read_attribute(NULL, FAN2_REAR); fan_tray_led_reg_value &= ~0x0c; - + if(fantray_present >= 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) - { - fan_tray_led_reg_value |= 0x04;/*Solid Green*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); - } + { + fan_tray_led_reg_value |= 0x04;/*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } else - { - fan_tray_led_reg_value |= 0x08;/*Solid Amber*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); - } + { + fan_tray_led_reg_value |= 0x08;/*Solid Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } break; case LED_REAR_FAN_TRAY_3: @@ -388,15 +388,15 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) rpm = dni_i2c_lock_read_attribute(NULL, FAN3_FRONT); rpm1 = dni_i2c_lock_read_attribute(NULL, FAN3_REAR); if(fantray_present >= 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) - { - fan_tray_led_reg_value |= 0x10;/*Solid Green*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); - } + { + fan_tray_led_reg_value |= 0x10;/*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } else - { - fan_tray_led_reg_value |= 0x20;/*Solid Amber*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); - } + { + fan_tray_led_reg_value |= 0x20;/*Solid Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } break; case LED_REAR_FAN_TRAY_4: @@ -406,16 +406,16 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) rpm = dni_i2c_lock_read_attribute(NULL, FAN4_FRONT); rpm1 = dni_i2c_lock_read_attribute(NULL, FAN4_REAR); if(fantray_present >= 0 && rpm != FAN_ZERO_RPM && rpm !=0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) - { - fan_tray_led_reg_value |= 0x40; /*Solid Green*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); - } + { + fan_tray_led_reg_value |= 0x40; /*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } else - { - fan_tray_led_reg_value |= 0x80;/*Solid Amber*/ - dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); - } - } + { + fan_tray_led_reg_value |= 0x80;/*Solid Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } + } return ONLP_STATUS_OK; } diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag7648/onlp/builds/src/module/src/psui.c b/packages/platforms/delta/x86-64/x86-64-delta-ag7648/onlp/builds/src/module/src/psui.c index 3802b3e0..cdde1a5e 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ag7648/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag7648/onlp/builds/src/module/src/psui.c @@ -57,7 +57,7 @@ } while(0) static long psu_data_convert(unsigned int d, int mult) { - long X, Y, N, n; + long X, Y, N, n; Y = d & 0x07FF; N = (d >> 11) & 0x0f; @@ -73,116 +73,116 @@ static long psu_data_convert(unsigned int d, int mult) static long psu_data_convert_16(unsigned int d, int mult) { - long X; - X = (d * mult) / (1 << 9); - return X; + long X; + X = (d * mult) / (1 << 9); + return X; } - -static int + +static int psu_status_info_get(int id, char *node) { int ret; - char r_data; - ret=i2c_devname_read_byte(CPLD_PSU_NAME,PSU_STATUS_REG); - - if(ret<0) - return -1; - - if (PSU1_ID == id) { - if(!strcmp("present",node)) - r_data=!((ret& PSU_STATUS_PRESENT_BIT(id))>> PSU_STATUS_PRESENT_OFFSET(id)); - else if(!strcmp("good",node)) - r_data=((ret& PSU_STATUS_GOOD_BIT(id))>> PSU_STATUS_GOOD_OFFSET(id)); - else - r_data=-1; - + char r_data; + ret=i2c_devname_read_byte(CPLD_PSU_NAME,PSU_STATUS_REG); + + if(ret<0) + return -1; + + if (PSU1_ID == id) { + if(!strcmp("present",node)) + r_data=!((ret& PSU_STATUS_PRESENT_BIT(id))>> PSU_STATUS_PRESENT_OFFSET(id)); + else if(!strcmp("good",node)) + r_data=((ret& PSU_STATUS_GOOD_BIT(id))>> PSU_STATUS_GOOD_OFFSET(id)); + else + r_data=-1; + } else if (PSU2_ID == id) { - + if(!strcmp("present",node)) - r_data=!((ret& PSU_STATUS_PRESENT_BIT(id))>> PSU_STATUS_PRESENT_OFFSET(id)); - else if(!strcmp("good",node)) - r_data=((ret& PSU_STATUS_GOOD_BIT(id))>> PSU_STATUS_GOOD_OFFSET(id)); - else - r_data=-1; - } + r_data=!((ret& PSU_STATUS_PRESENT_BIT(id))>> PSU_STATUS_PRESENT_OFFSET(id)); + else if(!strcmp("good",node)) + r_data=((ret& PSU_STATUS_GOOD_BIT(id))>> PSU_STATUS_GOOD_OFFSET(id)); + else + r_data=-1; + } else{ - r_data=-1; - } - - return r_data; + r_data=-1; + } + + return r_data; } -static int +static int psu_value_info_get(int id, char *type) { int ret; - char *dev_name; - int reg_offset; - + char *dev_name; + int reg_offset; + if(PSU1_ID == id) dev_name="PSU1_PMBUS"; else dev_name="PSU2_PMBUS"; - - if(!strcmp(type,"vin")) - reg_offset=PSU_PNBUS_VIN_REG; - else if(!strcmp(type,"iin")) - reg_offset=PSU_PNBUS_IIN_REG; - else if(!strcmp(type,"pin")) - reg_offset=PSU_PNBUS_PIN_REG; - else if(!strcmp(type,"vout")) - reg_offset=PSU_PNBUS_VOUT_REG; - else if(!strcmp(type,"iout")) - reg_offset=PSU_PNBUS_IOUT_REG; - else - reg_offset=PSU_PNBUS_POUT_REG; - - ret=i2c_devname_read_word(dev_name,reg_offset); - - if(ret<0) - return -1; - - return ret; + + if(!strcmp(type,"vin")) + reg_offset=PSU_PNBUS_VIN_REG; + else if(!strcmp(type,"iin")) + reg_offset=PSU_PNBUS_IIN_REG; + else if(!strcmp(type,"pin")) + reg_offset=PSU_PNBUS_PIN_REG; + else if(!strcmp(type,"vout")) + reg_offset=PSU_PNBUS_VOUT_REG; + else if(!strcmp(type,"iout")) + reg_offset=PSU_PNBUS_IOUT_REG; + else + reg_offset=PSU_PNBUS_POUT_REG; + + ret=i2c_devname_read_word(dev_name,reg_offset); + + if(ret<0) + return -1; + + return ret; } -static int +static int psu_serial_model_info_get(int id,char *type,char*data,int data_len) { int i,r_data,re_cnt; - char *dev_name; - int reg_offset; - + char *dev_name; + int reg_offset; + if(PSU1_ID == id) dev_name="PSU1_EEPROM"; else dev_name="PSU2_EEPROM"; - - if(!strcmp(type,"serial")) - reg_offset=PSU_PNBUS_SERIAL_REG; - else - reg_offset=PSU_PNBUS_MODEL_REG; - for(i=0;istatus &= ~ONLP_PSU_STATUS_PRESENT; return ONLP_STATUS_OK; } info->status |= ONLP_PSU_STATUS_PRESENT; /* Get power good status */ - val=psu_status_info_get(index,"good"); - - if (val<0) { - AIM_LOG_INFO("Unable to read PSU %d good value)\r\n", index); - return ONLP_STATUS_E_INVALID; + val=psu_status_info_get(index,"good"); + + if (val<0) { + AIM_LOG_INFO("Unable to read PSU %d good value)\r\n", index); + return ONLP_STATUS_E_INVALID; } if (val != PSU_STATUS_POWER_GOOD) { info->status |= ONLP_PSU_STATUS_FAILED; } - + /* Get PSU type */ psu_type = get_psu_type(index, info->model, sizeof(info->model)); switch (psu_type) { - case PSU_TYPE_AC_F2B: - case PSU_TYPE_AC_B2F: - info->caps = ONLP_PSU_CAPS_AC; - ret = ONLP_STATUS_OK; - break; - case PSU_TYPE_UNKNOWN: /* User insert a unknown PSU or unplugged.*/ - info->status |= ONLP_PSU_STATUS_UNPLUGGED; - info->status &= ~ONLP_PSU_STATUS_FAILED; - ret = ONLP_STATUS_OK; - break; - default: - ret = ONLP_STATUS_E_UNSUPPORTED; - break; + case PSU_TYPE_AC_F2B: + case PSU_TYPE_AC_B2F: + info->caps = ONLP_PSU_CAPS_AC; + ret = ONLP_STATUS_OK; + break; + case PSU_TYPE_UNKNOWN: /* User insert a unknown PSU or unplugged.*/ + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + info->status &= ~ONLP_PSU_STATUS_FAILED; + ret = ONLP_STATUS_OK; + break; + default: + ret = ONLP_STATUS_E_UNSUPPORTED; + break; } - /* Get PSU vin,vout*/ - - r_data=psu_value_info_get(index,"vin"); - + /* Get PSU vin,vout*/ + + r_data=psu_value_info_get(index,"vin"); + if (r_data<0) { - AIM_LOG_INFO("Unable to read PSU %d Vin value)\r\n", index); - return ONLP_STATUS_E_INVALID; + AIM_LOG_INFO("Unable to read PSU %d Vin value)\r\n", index); + return ONLP_STATUS_E_INVALID; } - - info->mvin=psu_data_convert(r_data,1000); - - r_data=psu_value_info_get(index,"vout"); - + + info->mvin=psu_data_convert(r_data,1000); + + r_data=psu_value_info_get(index,"vout"); + if (r_data<0) { - AIM_LOG_INFO("Unable to read PSU %d Vout value)\r\n", index); - return ONLP_STATUS_E_INVALID; + AIM_LOG_INFO("Unable to read PSU %d Vout value)\r\n", index); + return ONLP_STATUS_E_INVALID; } - - info->mvout=psu_data_convert_16(r_data,1000); - /* Get PSU iin, iout + + info->mvout=psu_data_convert_16(r_data,1000); + /* Get PSU iin, iout */ - r_data=psu_value_info_get(index,"iin"); - + r_data=psu_value_info_get(index,"iin"); + if (r_data<0) { - AIM_LOG_INFO("Unable to read PSU %d Iin value)\r\n", index); - return ONLP_STATUS_E_INVALID; + AIM_LOG_INFO("Unable to read PSU %d Iin value)\r\n", index); + return ONLP_STATUS_E_INVALID; } - - info->miin=psu_data_convert(r_data,1000); - - r_data=psu_value_info_get(index,"iout"); - + + info->miin=psu_data_convert(r_data,1000); + + r_data=psu_value_info_get(index,"iout"); + if (r_data<0) { - AIM_LOG_INFO("Unable to read PSU %d Iout value)\r\n", index); - return ONLP_STATUS_E_INVALID; + AIM_LOG_INFO("Unable to read PSU %d Iout value)\r\n", index); + return ONLP_STATUS_E_INVALID; } - - info->miout=psu_data_convert(r_data,1000); - - /* Get PSU pin, pout + + info->miout=psu_data_convert(r_data,1000); + + /* Get PSU pin, pout */ - r_data=psu_value_info_get(index,"pin"); - + r_data=psu_value_info_get(index,"pin"); + if (r_data<0) { - AIM_LOG_INFO("Unable to read PSU %d Pin value)\r\n", index); - return ONLP_STATUS_E_INVALID; + AIM_LOG_INFO("Unable to read PSU %d Pin value)\r\n", index); + return ONLP_STATUS_E_INVALID; } - - info->mpin=psu_data_convert(r_data,1000); - - r_data=psu_value_info_get(index,"pout"); - + + info->mpin=psu_data_convert(r_data,1000); + + r_data=psu_value_info_get(index,"pout"); + if (r_data<0) { - AIM_LOG_INFO("Unable to read PSU %d Pout value)\r\n", index); - return ONLP_STATUS_E_INVALID; + AIM_LOG_INFO("Unable to read PSU %d Pout value)\r\n", index); + return ONLP_STATUS_E_INVALID; } - - info->mpout=psu_data_convert(r_data,1000); - /* Get PSU serial + + info->mpout=psu_data_convert(r_data,1000); + /* Get PSU serial */ - ret=psu_serial_model_info_get(index,"serial",sn_data,14); - if (ret!=ONLP_STATUS_OK) { - AIM_LOG_INFO("Unable to read PSU %d SN value)\r\n", index); - return ONLP_STATUS_E_INVALID; + ret=psu_serial_model_info_get(index,"serial",sn_data,14); + if (ret!=ONLP_STATUS_OK) { + AIM_LOG_INFO("Unable to read PSU %d SN value)\r\n", index); + return ONLP_STATUS_E_INVALID; } - - strcpy(info->serial,sn_data); - - /* Get PSU model + + strcpy(info->serial,sn_data); + + /* Get PSU model */ - ret=psu_serial_model_info_get(index,"model",model_data,16); - if (ret!=ONLP_STATUS_OK) { - AIM_LOG_INFO("Unable to read PSU %d model value)\r\n", index); - return ONLP_STATUS_E_INVALID; + ret=psu_serial_model_info_get(index,"model",model_data,16); + if (ret!=ONLP_STATUS_OK) { + AIM_LOG_INFO("Unable to read PSU %d model value)\r\n", index); + return ONLP_STATUS_E_INVALID; } - - strcpy(info->model,model_data); + + strcpy(info->model,model_data); return ONLP_STATUS_OK; } @@ -354,4 +354,3 @@ onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) { return ONLP_STATUS_E_UNSUPPORTED; } - From 653fe0a81e82db63d34c5426a350a5ae076773db Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 23 Aug 2017 13:50:53 +0000 Subject: [PATCH 30/67] Add the build-artifacts repository. --- .gitmodules | 3 +++ sm/build-artifacts | 1 + 2 files changed, 4 insertions(+) create mode 160000 sm/build-artifacts diff --git a/.gitmodules b/.gitmodules index 1d345d4f..20df3fba 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,3 +16,6 @@ [submodule "packages/platforms-closed"] path = packages/platforms-closed url = git@github.com:opennetworklinux/platforms-closed +[submodule "sm/build-artifacts"] + path = sm/build-artifacts + url = git@github.com:opennetworklinux/build-artifacts diff --git a/sm/build-artifacts b/sm/build-artifacts new file mode 160000 index 00000000..01c9f5f7 --- /dev/null +++ b/sm/build-artifacts @@ -0,0 +1 @@ +Subproject commit 01c9f5f7ceab3c942f72b708e643f7b14a8d805c From 9dffd0be827fc8c515c6c2ebe3efc7605fbc74a5 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 23 Aug 2017 14:22:04 +0000 Subject: [PATCH 31/67] The local REPO is now prepopulated from build-artifacts at setup time. --- setup.env | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.env b/setup.env index 7e6f7f33..667ba08f 100755 --- a/setup.env +++ b/setup.env @@ -36,6 +36,10 @@ export BUILDROOTMIRROR=${BUILDROOTMIRROR:-"http://buildroot.opennetlinux.org/dl" # These submodules are required for almost everything. $ONL/tools/submodules.py $ONL sm/infra $ONL/tools/submodules.py $ONL sm/bigcode +$ONL/tools/submodules.py $ONL sm/build-artifacts + +# Prepopulate local REPO with build-artifacts. +cp -R $ONL/sm/build-artifacts/REPO/* $ONL/REPO # Export the current debian suite export ONL_DEBIAN_SUITE=$(lsb_release -c -s) @@ -46,4 +50,4 @@ if [ ! -f $ONL/.git/hooks/post-merge ] && [ -d $ONL/.git ]; then fi # submodule post update scripts. -export ONL_SUBMODULE_UPDATED_SCRIPTS="$ONL/tools/scripts/submodule-updated.sh" \ No newline at end of file +export ONL_SUBMODULE_UPDATED_SCRIPTS="$ONL/tools/scripts/submodule-updated.sh" From 62b1fe997eecd5e80cd7a8a8ea50cd687291d562 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 23 Aug 2017 14:22:43 +0000 Subject: [PATCH 32/67] Updated with buildroot artifacts. --- sm/build-artifacts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sm/build-artifacts b/sm/build-artifacts index 01c9f5f7..54005ad5 160000 --- a/sm/build-artifacts +++ b/sm/build-artifacts @@ -1 +1 @@ -Subproject commit 01c9f5f7ceab3c942f72b708e643f7b14a8d805c +Subproject commit 54005ad5e9e03fe9235cf17378d53a30544dd155 From 81ea33da92190344d989252ef152dfc65444e3b8 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 23 Aug 2017 14:55:00 +0000 Subject: [PATCH 33/67] Update ignore. --- packages/platforms/delta/x86-64/x86-64-delta-ag5648/.gitignore | 3 +-- packages/platforms/quanta/x86-64/x86-64-quanta-ly4r/.gitignore | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/.gitignore b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/.gitignore index 76483140..269535f7 100644 --- a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/.gitignore +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/.gitignore @@ -1,3 +1,2 @@ -*x86*64*delta_agc7648a*.mk +*x86*64*delta*ag5648*.mk onlpdump.mk - diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly4r/.gitignore b/packages/platforms/quanta/x86-64/x86-64-quanta-ly4r/.gitignore index 64d7ff10..651bf060 100755 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly4r/.gitignore +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly4r/.gitignore @@ -1,2 +1,2 @@ -*x86*64*quanta*ly4r*rangeley.mk +*x86*64*quanta*ly4r*.mk onlpdump.mk From dff9cae53eed7fb34c9d8291a7636732b190dee8 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 23 Aug 2017 14:52:57 -0700 Subject: [PATCH 34/67] Publish builder9:1.0. --- docker/images/builder9/1.0/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/images/builder9/1.0/Makefile b/docker/images/builder9/1.0/Makefile index cd91ae81..7b594b45 100644 --- a/docker/images/builder9/1.0/Makefile +++ b/docker/images/builder9/1.0/Makefile @@ -1,4 +1,4 @@ -VERSION=1.0-beta +VERSION=1.0 USER=opennetworklinux REPO=builder9 From 4c4f5c1979033c4a1192b4309bbedb5064cf613d Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 23 Aug 2017 14:53:20 -0700 Subject: [PATCH 35/67] Support the Debian 9 builder. --- docker/tools/onlbuilder | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker/tools/onlbuilder b/docker/tools/onlbuilder index f99746ff..48f20edf 100755 --- a/docker/tools/onlbuilder +++ b/docker/tools/onlbuilder @@ -19,6 +19,7 @@ g_timestamp = datetime.datetime.now().strftime("%Y-%m-%d.%H%M%S") g_builder7_image_name="opennetworklinux/builder7:1.2" g_builder8_image_name="opennetworklinux/builder8:1.7" +g_builder9_image_name="opennetworklinux/builder9:1.0" g_default_image_name=g_builder8_image_name g_default_container_name = "%s_%s" % (g_current_user, g_timestamp) @@ -26,6 +27,9 @@ g_default_user="%s:%s" % (g_current_user, g_current_uid) ap = argparse.ArgumentParser("ONL Docker Build") +ap.add_argument('--9', '-9', + help="Run the Debian 9 version.", + action='store_true', dest='debian9') ap.add_argument('--8', '-8', help="Run the Debian 8 version.", action='store_true', dest='debian8') @@ -117,6 +121,8 @@ if ops.debian7: if ops.debian8: ops.image = g_builder8_image_name +if ops.debian9: + ops.image = g_builder9_image_name if ops.verbose or ops.dry: logger.setLevel(logging.DEBUG) From 8d13652eb6deb3f677379f6f33321128665a41be Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 24 Aug 2017 03:22:53 +0000 Subject: [PATCH 36/67] - Support Debian9 - Deprecate Debian7 --- tools/autobuild/build.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/autobuild/build.sh b/tools/autobuild/build.sh index 80b88dc0..a3b6aff0 100755 --- a/tools/autobuild/build.sh +++ b/tools/autobuild/build.sh @@ -9,7 +9,7 @@ ONL="$(realpath $(dirname $AUTOBUILD_SCRIPT)/../../)" # Default build branch BUILD_BRANCH=master -while getopts ":b:s:d:u:p:vc78r:" opt; do +while getopts ":b:s:d:u:p:vc789r:" opt; do case $opt in 7) ONLB_OPTIONS=--7 @@ -23,6 +23,12 @@ while getopts ":b:s:d:u:p:vc78r:" opt; do echo "Selecting Debian 8 build..." fi ;; + 9) + ONLB_OPTIONS=--9 + if [ -z "$DOCKER_IMAGE" ]; then + echo "Selecting Debian 9 build..." + fi + ;; c) cd $ONL && git submodule update --init --recursive packages/platforms-closed ;; @@ -41,9 +47,9 @@ while getopts ":b:s:d:u:p:vc78r:" opt; do done if [ -z "$ONLB_OPTIONS" ]; then - # Build both suites - $AUTOBUILD_SCRIPT --7 $@ + # Build both 8 and 9 $AUTOBUILD_SCRIPT --8 $@ + $AUTOBUILD_SCRIPT --9 $@ exit $? fi From 39c78d48e134dc445012ee3fd881c5a364a3e1f8 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Thu, 24 Aug 2017 08:04:33 +0000 Subject: [PATCH 37/67] Add new model, accton-as5916-54x. --- .../x86-64-accton-as5916-54x/.gitignore | 2 + .../x86-64/x86-64-accton-as5916-54x/Makefile | 1 + .../x86-64-accton-as5916-54x/modules/Makefile | 1 + .../x86-64-accton-as5916-54x/modules/PKG.yml | 1 + .../modules/builds/.gitignore | 1 + .../modules/builds/Makefile | 6 + .../builds/x86-64-accton-as5916-54x-fan.c | 485 ++++++ .../builds/x86-64-accton-as5916-54x-leds.c | 386 +++++ .../builds/x86-64-accton-as5916-54x-psu.c | 288 ++++ .../builds/x86-64-accton-as5916-54x-sfp.c | 1315 +++++++++++++++++ .../x86-64-accton-as5916-54x/onlp/Makefile | 1 + .../x86-64-accton-as5916-54x/onlp/PKG.yml | 27 + .../onlp/builds/Makefile | 2 + .../onlp/builds/lib/Makefile | 45 + .../onlp/builds/onlpdump/Makefile | 46 + .../onlp/builds/src/.module | 1 + .../onlp/builds/src/Makefile | 9 + .../onlp/builds/src/README | 6 + .../onlp/builds/src/module/auto/make.mk | 9 + .../module/auto/x86_64_accton_as5916_54x.yml | 50 + .../x86_64_accton_as5916_54x.x | 14 + .../x86_64_accton_as5916_54x_config.h | 137 ++ .../x86_64_accton_as5916_54x_dox.h | 26 + .../x86_64_accton_as5916_54x_porting.h | 107 ++ .../onlp/builds/src/module/make.mk | 10 + .../onlp/builds/src/module/src/Makefile | 9 + .../onlp/builds/src/module/src/fani.c | 354 +++++ .../onlp/builds/src/module/src/ledi.c | 256 ++++ .../onlp/builds/src/module/src/make.mk | 9 + .../onlp/builds/src/module/src/platform_lib.c | 124 ++ .../onlp/builds/src/module/src/platform_lib.h | 89 ++ .../onlp/builds/src/module/src/psui.c | 177 +++ .../onlp/builds/src/module/src/sfpi.c | 289 ++++ .../onlp/builds/src/module/src/sysi.c | 339 +++++ .../onlp/builds/src/module/src/thermali.c | 128 ++ .../src/x86_64_accton_as5916_54x_config.c | 80 + .../src/x86_64_accton_as5916_54x_enums.c | 10 + .../module/src/x86_64_accton_as5916_54x_int.h | 12 + .../module/src/x86_64_accton_as5916_54x_log.c | 18 + .../module/src/x86_64_accton_as5916_54x_log.h | 12 + .../src/x86_64_accton_as5916_54x_module.c | 24 + .../src/x86_64_accton_as5916_54x_ucli.c | 50 + .../platform-config/Makefile | 1 + .../platform-config/r1/Makefile | 1 + .../platform-config/r1/PKG.yml | 1 + .../src/lib/x86-64-accton-as5916-54x-r1.yml | 33 + .../x86_64_accton_as5916_54x_r1/__init__.py | 72 + 47 files changed, 5064 insertions(+) create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/.gitignore create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/.gitignore create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-fan.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-leds.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-psu.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-sfp.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/lib/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/onlpdump/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/.module create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/README create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/auto/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/auto/x86_64_accton_as5916_54x.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x.x create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_config.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_dox.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_porting.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/fani.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/ledi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/platform_lib.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/platform_lib.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/psui.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sfpi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sysi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/thermali.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_config.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_enums.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_int.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_module.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_ucli.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/lib/x86-64-accton-as5916-54x-r1.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/python/x86_64_accton_as5916_54x_r1/__init__.py diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/.gitignore b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/.gitignore new file mode 100644 index 00000000..2e2944b3 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/.gitignore @@ -0,0 +1,2 @@ +*x86*64*accton*as5916*54x*.mk +onlpdump.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/PKG.yml new file mode 100644 index 00000000..b6c16c5e --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as5916-54x ARCH=amd64 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/.gitignore b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/.gitignore new file mode 100644 index 00000000..a65b4177 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/Makefile new file mode 100644 index 00000000..0ae14eaa --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-3.16-lts-x86-64-all:amd64 +KMODULES := $(wildcard *.c) +VENDOR := accton +BASENAME := x86-64-accton-as5916-54x +ARCH := x86_64 +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-fan.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-fan.c new file mode 100644 index 00000000..e69660e4 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-fan.c @@ -0,0 +1,485 @@ +/* + * A hwmon driver for the Accton as5916 54x fan + * + * Copyright (C) 2016 Accton Technology Corporation. + * Brandon Chuang + * + * 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 "as5916_54x_fan" +#define MAX_FAN_SPEED_RPM 25500 + +static struct as5916_54x_fan_data *as5916_54x_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[] = { + 0x0F, /* fan 1-6 present status */ + 0x10, /* fan 1-6 direction(0:B2F 1:F2B) */ + 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 as5916_54x_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 { + 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, + FAN_MAX_RPM +}; + +/* Define attributes + */ +#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 + +static SENSOR_DEVICE_ATTR(fan_max_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN_MAX_RPM); +#define DECLARE_FAN_MAX_RPM_ATTR(index) &sensor_dev_attr_fan_max_speed_rpm.dev_attr.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 *as5916_54x_fan_attributes[] = { + /* fan related attributes */ + 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(), + DECLARE_FAN_MAX_RPM_ATTR(), + NULL +}; + +#define FAN_DUTY_CYCLE_REG_MASK 0xF +#define FAN_MAX_DUTY_CYCLE 100 +#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 + +static int as5916_54x_fan_read_value(struct i2c_client *client, u8 reg) +{ + return i2c_smbus_read_byte_data(client, reg); +} + +static int as5916_54x_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) +{ + return !!(reg_val & BIT(id)); +} + +static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) +{ + return !(reg_val & BIT(id)); +} + +static u8 is_fan_fault(struct as5916_54x_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); + + error = kstrtoint(buf, 10, &value); + if (error) + return error; + + if (value < 0 || value > FAN_MAX_DUTY_CYCLE) + return -EINVAL; + + as5916_54x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ + as5916_54x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); + return count; +} + +static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct as5916_54x_fan_data *data = as5916_54x_fan_update_device(dev); + ssize_t ret = 0; + + 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 FAN_MAX_RPM: + ret = sprintf(buf, "%d\n", MAX_FAN_SPEED_RPM); + default: + break; + } + } + + return ret; +} + +static const struct attribute_group as5916_54x_fan_group = { + .attrs = as5916_54x_fan_attributes, +}; + +static struct as5916_54x_fan_data *as5916_54x_fan_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54x_fan_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || + !data->valid) { + int i; + + dev_dbg(&client->dev, "Starting as5916_54x_fan update\n"); + data->valid = 0; + + /* Update fan data + */ + for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { + int status = as5916_54x_fan_read_value(client, fan_reg[i]); + + if (status < 0) { + data->valid = 0; + mutex_unlock(&data->update_lock); + 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; + } + + mutex_unlock(&data->update_lock); + + return data; +} + +static int as5916_54x_fan_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as5916_54x_fan_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as5916_54x_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, &as5916_54x_fan_group); + if (status) { + goto exit_free; + } + + data->hwmon_dev = hwmon_device_register(&client->dev); + 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, &as5916_54x_fan_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as5916_54x_fan_remove(struct i2c_client *client) +{ + struct as5916_54x_fan_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as5916_54x_fan_group); + + return 0; +} + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; + +static const struct i2c_device_id as5916_54x_fan_id[] = { + { "as5916_54x_fan", 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as5916_54x_fan_id); + +static struct i2c_driver as5916_54x_fan_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = DRVNAME, + }, + .probe = as5916_54x_fan_probe, + .remove = as5916_54x_fan_remove, + .id_table = as5916_54x_fan_id, + .address_list = normal_i2c, +}; + +static int __init as5916_54x_fan_init(void) +{ + return i2c_add_driver(&as5916_54x_fan_driver); +} + +static void __exit as5916_54x_fan_exit(void) +{ + i2c_del_driver(&as5916_54x_fan_driver); +} + +module_init(as5916_54x_fan_init); +module_exit(as5916_54x_fan_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("as5916_54x_fan driver"); +MODULE_LICENSE("GPL"); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-leds.c new file mode 100644 index 00000000..7f55dae7 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-leds.c @@ -0,0 +1,386 @@ +/* + * A LED driver for the accton_as5916_54x_led + * + * Copyright (C) 2016 Accton Technology Corporation. + * Brandon Chuang + * + * 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 + +#define DRVNAME "accton_as5916_54x_led" + +#define DEBUG_MODE 1 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif + +extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +struct accton_as5916_54x_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]; /* Register value, 0 = RELEASE/DIAG LED, + 1 = FAN/PSU LED, + 2 ~ 4 = SYSTEM LED */ +}; + +static struct accton_as5916_54x_led_data *ledctl = NULL; + +#define LED_CNTRLER_I2C_ADDRESS (0x60) + +#define LED_TYPE_DIAG_REG_MASK (0x0C) +#define LED_MODE_DIAG_GREEN_VALUE (0x04) +#define LED_MODE_DIAG_ORANGE_VALUE (0x08) +#define LED_MODE_DIAG_OFF_VALUE (0x0C) + + +#define LED_TYPE_LOC_REG_MASK (0x10) +#define LED_MODE_LOC_ORANGE_VALUE (0x00) +#define LED_MODE_LOC_OFF_VALUE (0x10) + +static const u8 led_reg[] = { + 0x65, /* LOC/DIAG/FAN LED */ + 0x66, /* PSU LED */ +}; + +enum led_type { + LED_TYPE_DIAG, + LED_TYPE_LOC, + LED_TYPE_FAN, + LED_TYPE_PSU1, + LED_TYPE_PSU2 +}; + +/* FAN/PSU/DIAG/RELEASE led mode */ +enum led_light_mode { + LED_MODE_OFF, + LED_MODE_RED = 10, + LED_MODE_RED_BLINKING = 11, + LED_MODE_ORANGE = 12, + LED_MODE_ORANGE_BLINKING = 13, + LED_MODE_YELLOW = 14, + LED_MODE_YELLOW_BLINKING = 15, + LED_MODE_GREEN = 16, + LED_MODE_GREEN_BLINKING = 17, + LED_MODE_BLUE = 18, + LED_MODE_BLUE_BLINKING = 19, + LED_MODE_PURPLE = 20, + LED_MODE_PURPLE_BLINKING = 21, + LED_MODE_AUTO = 22, + LED_MODE_AUTO_BLINKING = 23, + LED_MODE_WHITE = 24, + LED_MODE_WHITE_BLINKING = 25, + LED_MODE_CYAN = 26, + LED_MODE_CYAN_BLINKING = 27, + LED_MODE_UNKNOWN = 99 +}; + +struct led_type_mode { + enum led_type type; + enum led_light_mode mode; + int type_mask; + int mode_value; +}; + +static struct led_type_mode led_type_mode_data[] = { +{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE}, +{LED_TYPE_LOC, LED_MODE_ORANGE, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_ORANGE_VALUE}, +{LED_TYPE_DIAG, LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE}, +{LED_TYPE_DIAG, LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE}, +{LED_TYPE_DIAG, LED_MODE_ORANGE, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_ORANGE_VALUE}, +}; + +static int led_reg_val_to_light_mode(enum led_type type, u8 reg_val) { + int i; + + for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { + if (type != led_type_mode_data[i].type) { + continue; + } + + if ((led_type_mode_data[i].type_mask & reg_val) == + led_type_mode_data[i].mode_value) { + return led_type_mode_data[i].mode; + } + } + + return LED_MODE_UNKNOWN; +} + +static u8 led_light_mode_to_reg_val(enum led_type type, + enum led_light_mode mode, u8 reg_val) { + int i; + + for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { + int type_mask, mode_value; + + if (type != led_type_mode_data[i].type) + continue; + + if (mode != led_type_mode_data[i].mode) + continue; + + type_mask = led_type_mode_data[i].type_mask; + mode_value = led_type_mode_data[i].mode_value; + reg_val = (reg_val & ~type_mask) | mode_value; + } + + return reg_val; +} + +static int accton_as5916_54x_led_read_value(u8 reg) +{ + return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); +} + +static int accton_as5916_54x_led_write_value(u8 reg, u8 value) +{ + return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); +} + +static void accton_as5916_54x_led_update(void) +{ + mutex_lock(&ledctl->update_lock); + + if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) + || !ledctl->valid) { + int i; + + dev_dbg(&ledctl->pdev->dev, "Starting accton_as5916_54x_led update\n"); + ledctl->valid = 0; + + /* Update LED data + */ + for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { + int status = accton_as5916_54x_led_read_value(led_reg[i]); + + if (status < 0) { + dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg[i], 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_as5916_54x_led_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode, + u8 reg, enum led_type type) +{ + int reg_val; + + mutex_lock(&ledctl->update_lock); + reg_val = accton_as5916_54x_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_as5916_54x_led_write_value(reg, reg_val); + ledctl->valid = 0; + +exit: + mutex_unlock(&ledctl->update_lock); +} + +static void accton_as7312_54x_led_auto_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ +} + +static enum led_brightness accton_as7312_54x_led_auto_get(struct led_classdev *cdev) +{ + return LED_MODE_AUTO; +} + +static void accton_as5916_54x_led_diag_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as5916_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG); +} + +static enum led_brightness accton_as5916_54x_led_diag_get(struct led_classdev *cdev) +{ + accton_as5916_54x_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); +} + +static enum led_brightness accton_as5916_54x_led_loc_get(struct led_classdev *cdev) +{ + accton_as5916_54x_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); +} + +static void accton_as5916_54x_led_loc_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as5916_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC); +} + +static struct led_classdev accton_as5916_54x_leds[] = { + [LED_TYPE_LOC] = { + .name = "accton_as5916_54x_led::loc", + .default_trigger = "unused", + .brightness_set = accton_as5916_54x_led_loc_set, + .brightness_get = accton_as5916_54x_led_loc_get, + .max_brightness = LED_MODE_ORANGE, + }, + [LED_TYPE_DIAG] = { + .name = "accton_as5916_54x_led::diag", + .default_trigger = "unused", + .brightness_set = accton_as5916_54x_led_diag_set, + .brightness_get = accton_as5916_54x_led_diag_get, + .max_brightness = LED_MODE_GREEN, + }, + [LED_TYPE_PSU1] = { + .name = "accton_as5916_54x_led::psu1", + .default_trigger = "unused", + .brightness_set = accton_as7312_54x_led_auto_set, + .brightness_get = accton_as7312_54x_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_PSU2] = { + .name = "accton_as5916_54x_led::psu2", + .default_trigger = "unused", + .brightness_set = accton_as7312_54x_led_auto_set, + .brightness_get = accton_as7312_54x_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_FAN] = { + .name = "accton_as5916_54x_led::fan", + .default_trigger = "unused", + .brightness_set = accton_as7312_54x_led_auto_set, + .brightness_get = accton_as7312_54x_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, +}; + +static int accton_as5916_54x_led_probe(struct platform_device *pdev) +{ + int ret, i; + + for (i = 0; i < ARRAY_SIZE(accton_as5916_54x_leds); i++) { + ret = led_classdev_register(&pdev->dev, &accton_as5916_54x_leds[i]); + + if (ret < 0) { + break; + } + } + + /* Check if all LEDs were successfully registered */ + if (i != ARRAY_SIZE(accton_as5916_54x_leds)){ + int j; + + /* only unregister the LEDs that were successfully registered */ + for (j = 0; j < i; j++) { + led_classdev_unregister(&accton_as5916_54x_leds[i]); + } + } + + return ret; +} + +static int accton_as5916_54x_led_remove(struct platform_device *pdev) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(accton_as5916_54x_leds); i++) { + led_classdev_unregister(&accton_as5916_54x_leds[i]); + } + + return 0; +} + +static struct platform_driver accton_as5916_54x_led_driver = { + .probe = accton_as5916_54x_led_probe, + .remove = accton_as5916_54x_led_remove, + .driver = { + .name = DRVNAME, + .owner = THIS_MODULE, + }, +}; + +static int __init accton_as5916_54x_led_init(void) +{ + int ret; + + ret = platform_driver_register(&accton_as5916_54x_led_driver); + if (ret < 0) { + goto exit; + } + + ledctl = kzalloc(sizeof(struct accton_as5916_54x_led_data), GFP_KERNEL); + if (!ledctl) { + ret = -ENOMEM; + goto exit_driver; + } + + 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); + goto exit_free; + } + + return 0; + +exit_free: + kfree(ledctl); +exit_driver: + platform_driver_unregister(&accton_as5916_54x_led_driver); +exit: + return ret; +} + +static void __exit accton_as5916_54x_led_exit(void) +{ + platform_device_unregister(ledctl->pdev); + platform_driver_unregister(&accton_as5916_54x_led_driver); + kfree(ledctl); +} + +late_initcall(accton_as5916_54x_led_init); +module_exit(accton_as5916_54x_led_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("accton_as5916_54x_led driver"); +MODULE_LICENSE("GPL"); + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-psu.c new file mode 100644 index 00000000..4627df9c --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-psu.c @@ -0,0 +1,288 @@ +/* + * An hwmon driver for accton as5916_54x Power Module + * + * Copyright (C) 2014 Accton Technology Corporation. + * Brandon Chuang + * + * 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 + +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 as5916_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); +extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; + +/* Each client has this additional data + */ +struct as5916_54x_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[9]; /* Model name, read from eeprom */ +}; + +static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *dev); + +enum as5916_54x_psu_sysfs_attributes { + PSU_PRESENT, + PSU_MODEL_NAME, + 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_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); +static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); + +static struct attribute *as5916_54x_psu_attributes[] = { + &sensor_dev_attr_psu_present.dev_attr.attr, + &sensor_dev_attr_psu_model_name.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 sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct as5916_54x_psu_data *data = as5916_54x_psu_update_device(dev); + u8 status = 0; + + if (attr->index == PSU_PRESENT) { + status = !(data->status & BIT(1 - data->index));; + } + else { /* PSU_POWER_GOOD */ + status = !!(data->status & BIT(3 - data->index)); + } + + return sprintf(buf, "%d\n", status); +} + +static ssize_t show_model_name(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct as5916_54x_psu_data *data = as5916_54x_psu_update_device(dev); + + return sprintf(buf, "%s\n", data->model_name); +} + +static const struct attribute_group as5916_54x_psu_group = { + .attrs = as5916_54x_psu_attributes, +}; + +static int as5916_54x_psu_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as5916_54x_psu_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as5916_54x_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, &as5916_54x_psu_group); + if (status) { + goto exit_free; + } + + data->hwmon_dev = hwmon_device_register(&client->dev); + 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, &as5916_54x_psu_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as5916_54x_psu_remove(struct i2c_client *client) +{ + struct as5916_54x_psu_data *data = i2c_get_clientdata(client); + + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as5916_54x_psu_group); + kfree(data); + + return 0; +} + +enum psu_index +{ + as5916_54x_psu1, + as5916_54x_psu2 +}; + +static const struct i2c_device_id as5916_54x_psu_id[] = { + { "as5916_54x_psu1", as5916_54x_psu1 }, + { "as5916_54x_psu2", as5916_54x_psu2 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as5916_54x_psu_id); + +static struct i2c_driver as5916_54x_psu_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "as5916_54x_psu", + }, + .probe = as5916_54x_psu_probe, + .remove = as5916_54x_psu_remove, + .id_table = as5916_54x_psu_id, + .address_list = normal_i2c, +}; + +static int as5916_54x_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)) { + msleep(10); + continue; + } + + if (unlikely(result != data_len)) { + result = -EIO; + msleep(10); + continue; + } + + result = 0; + break; + } + + return result; +} + +static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54x_psu_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) + || !data->valid) { + int status; + int power_good = 0; + + dev_dbg(&client->dev, "Starting as5916_54x update\n"); + + /* Read psu status */ + status = accton_i2c_cpld_read(0x60, 0x2); + + if (status < 0) { + dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); + } + else { + data->status = status; + } + + /* Read model name */ + memset(data->model_name, 0, sizeof(data->model_name)); + power_good = data->status & BIT(3 - data->index); + + if (power_good) { + status = as5916_54x_psu_read_block(client, 0x20, data->model_name, + ARRAY_SIZE(data->model_name)-1); + + if (status < 0) { + data->model_name[0] = '\0'; + dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr); + } + else { + data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0'; + } + } + + data->last_updated = jiffies; + data->valid = 1; + } + + mutex_unlock(&data->update_lock); + + return data; +} + +static int __init as5916_54x_psu_init(void) +{ + return i2c_add_driver(&as5916_54x_psu_driver); +} + +static void __exit as5916_54x_psu_exit(void) +{ + i2c_del_driver(&as5916_54x_psu_driver); +} + +module_init(as5916_54x_psu_init); +module_exit(as5916_54x_psu_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("as5916_54x_psu driver"); +MODULE_LICENSE("GPL"); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-sfp.c new file mode 100644 index 00000000..c924772b --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-sfp.c @@ -0,0 +1,1315 @@ +/* + * SFP driver for accton as5916_54x sfp + * + * Copyright (C) Brandon Chuang + * + * 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 + +#define DRIVER_NAME "as5916_54x_sfp" /* Platform dependent */ + +#define DEBUG_MODE 0 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif + +#define NUM_OF_SFP_PORT 54 +#define EEPROM_NAME "sfp_eeprom" +#define EEPROM_SIZE 256 /* 256 byte eeprom */ +#define BIT_INDEX(i) (1ULL << (i)) +#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ +#define I2C_RW_RETRY_COUNT 3 +#define I2C_RW_RETRY_INTERVAL 100 /* ms */ + +#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) +#define SFP_EEPROM_A2_I2C_ADDR (0xA2 >> 1) + +#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 +#define SFF8024_DEVICE_ID_SFP 0x3 +#define SFF8024_DEVICE_ID_QSFP 0xC +#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD +#define SFF8024_DEVICE_ID_QSFP28 0x11 + +#define SFF8472_DIAG_MON_TYPE_ADDR 92 +#define SFF8472_DIAG_MON_TYPE_DDM_MASK 0x40 +#define SFF8472_10G_ETH_COMPLIANCE_ADDR 0x3 +#define SFF8472_10G_BASE_MASK 0xF0 + +#define SFF8436_RX_LOS_ADDR 3 +#define SFF8436_TX_FAULT_ADDR 4 +#define SFF8436_TX_DISABLE_ADDR 86 + +/* Platform dependent +++ */ +#define I2C_ADDR_CPLD1 0x60 +#define I2C_ADDR_CPLD2 0x62 +/* Platform dependent --- */ + +static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_port_type(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count); +static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; +static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); +static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); +extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +enum sfp_sysfs_attributes { + PRESENT, + PRESENT_ALL, + PORT_NUMBER, + PORT_TYPE, + DDM_IMPLEMENTED, + TX_FAULT, + TX_FAULT1, + TX_FAULT2, + TX_FAULT3, + TX_FAULT4, + TX_DISABLE, + TX_DISABLE1, + TX_DISABLE2, + TX_DISABLE3, + TX_DISABLE4, + RX_LOS, + RX_LOS1, + RX_LOS2, + RX_LOS3, + RX_LOS4, + RX_LOS_ALL +}; + +/* SFP/QSFP common attributes for sysfs */ +static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); +static SENSOR_DEVICE_ATTR(sfp_port_type, S_IRUGO, show_port_type, NULL, PORT_TYPE); +static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); +static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); +static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); +static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, sfp_show_tx_rx_status, sfp_set_tx_disable, TX_DISABLE); +static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT); + +/* QSFP attributes for sysfs */ +static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); +static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); +static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); +static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); +static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); +static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); +static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); +static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); +static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); +static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); +static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); +static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); +static struct attribute *qsfp_attributes[] = { + &sensor_dev_attr_sfp_port_number.dev_attr.attr, + &sensor_dev_attr_sfp_port_type.dev_attr.attr, + &sensor_dev_attr_sfp_is_present.dev_attr.attr, + &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, + NULL +}; + +/* SFP msa attributes for sysfs */ +static SENSOR_DEVICE_ATTR(sfp_ddm_implemented, S_IRUGO, sfp_show_ddm_implemented, NULL, DDM_IMPLEMENTED); +static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS_ALL); +static struct attribute *sfp_msa_attributes[] = { + &sensor_dev_attr_sfp_port_number.dev_attr.attr, + &sensor_dev_attr_sfp_port_type.dev_attr.attr, + &sensor_dev_attr_sfp_is_present.dev_attr.attr, + &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, + &sensor_dev_attr_sfp_ddm_implemented.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, + NULL +}; + +/* SFP ddm attributes for sysfs */ +static struct attribute *sfp_ddm_attributes[] = { + NULL +}; + +/* Platform dependent +++ */ +#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) + +enum port_numbers { +as5916_54x_sfp1, as5916_54x_sfp2, as5916_54x_sfp3, as5916_54x_sfp4, as5916_54x_sfp5, as5916_54x_sfp6, as5916_54x_sfp7, as5916_54x_sfp8, +as5916_54x_sfp9, as5916_54x_sfp10, as5916_54x_sfp11, as5916_54x_sfp12, as5916_54x_sfp13, as5916_54x_sfp14, as5916_54x_sfp15, as5916_54x_sfp16, +as5916_54x_sfp17, as5916_54x_sfp18, as5916_54x_sfp19, as5916_54x_sfp20, as5916_54x_sfp21, as5916_54x_sfp22, as5916_54x_sfp23, as5916_54x_sfp24, +as5916_54x_sfp25, as5916_54x_sfp26, as5916_54x_sfp27, as5916_54x_sfp28, as5916_54x_sfp29, as5916_54x_sfp30, as5916_54x_sfp31, as5916_54x_sfp32, +as5916_54x_sfp33, as5916_54x_sfp34, as5916_54x_sfp35, as5916_54x_sfp36, as5916_54x_sfp37, as5916_54x_sfp38, as5916_54x_sfp39, as5916_54x_sfp40, +as5916_54x_sfp41, as5916_54x_sfp42, as5916_54x_sfp43, as5916_54x_sfp44, as5916_54x_sfp45, as5916_54x_sfp46, as5916_54x_sfp47, as5916_54x_sfp48, +as5916_54x_sfp49, as5916_54x_sfp50, as5916_54x_sfp51, as5916_54x_sfp52, as5916_54x_sfp53, as5916_54x_sfp54 +}; + +static const struct i2c_device_id sfp_device_id[] = { +{ "as5916_54x_sfp1", as5916_54x_sfp1 }, { "as5916_54x_sfp2", as5916_54x_sfp2 }, { "as5916_54x_sfp3", as5916_54x_sfp3 }, { "as5916_54x_sfp4", as5916_54x_sfp4 }, +{ "as5916_54x_sfp5", as5916_54x_sfp5 }, { "as5916_54x_sfp6", as5916_54x_sfp6 }, { "as5916_54x_sfp7", as5916_54x_sfp7 }, { "as5916_54x_sfp8", as5916_54x_sfp8 }, +{ "as5916_54x_sfp9", as5916_54x_sfp9 }, { "as5916_54x_sfp10", as5916_54x_sfp10 }, { "as5916_54x_sfp11", as5916_54x_sfp11 }, { "as5916_54x_sfp12", as5916_54x_sfp12 }, +{ "as5916_54x_sfp13", as5916_54x_sfp13 }, { "as5916_54x_sfp14", as5916_54x_sfp14 }, { "as5916_54x_sfp15", as5916_54x_sfp15 }, { "as5916_54x_sfp16", as5916_54x_sfp16 }, +{ "as5916_54x_sfp17", as5916_54x_sfp17 }, { "as5916_54x_sfp18", as5916_54x_sfp18 }, { "as5916_54x_sfp19", as5916_54x_sfp19 }, { "as5916_54x_sfp20", as5916_54x_sfp20 }, +{ "as5916_54x_sfp21", as5916_54x_sfp21 }, { "as5916_54x_sfp22", as5916_54x_sfp22 }, { "as5916_54x_sfp23", as5916_54x_sfp23 }, { "as5916_54x_sfp24", as5916_54x_sfp24 }, +{ "as5916_54x_sfp25", as5916_54x_sfp25 }, { "as5916_54x_sfp26", as5916_54x_sfp26 }, { "as5916_54x_sfp27", as5916_54x_sfp27 }, { "as5916_54x_sfp28", as5916_54x_sfp28 }, +{ "as5916_54x_sfp29", as5916_54x_sfp29 }, { "as5916_54x_sfp30", as5916_54x_sfp30 }, { "as5916_54x_sfp31", as5916_54x_sfp31 }, { "as5916_54x_sfp32", as5916_54x_sfp32 }, +{ "as5916_54x_sfp33", as5916_54x_sfp33 }, { "as5916_54x_sfp34", as5916_54x_sfp34 }, { "as5916_54x_sfp35", as5916_54x_sfp35 }, { "as5916_54x_sfp36", as5916_54x_sfp36 }, +{ "as5916_54x_sfp37", as5916_54x_sfp37 }, { "as5916_54x_sfp38", as5916_54x_sfp38 }, { "as5916_54x_sfp39", as5916_54x_sfp39 }, { "as5916_54x_sfp40", as5916_54x_sfp40 }, +{ "as5916_54x_sfp41", as5916_54x_sfp41 }, { "as5916_54x_sfp42", as5916_54x_sfp42 }, { "as5916_54x_sfp43", as5916_54x_sfp43 }, { "as5916_54x_sfp44", as5916_54x_sfp44 }, +{ "as5916_54x_sfp45", as5916_54x_sfp45 }, { "as5916_54x_sfp46", as5916_54x_sfp46 }, { "as5916_54x_sfp47", as5916_54x_sfp47 }, { "as5916_54x_sfp48", as5916_54x_sfp48 }, +{ "as5916_54x_sfp49", as5916_54x_sfp49 }, { "as5916_54x_sfp50", as5916_54x_sfp50 }, { "as5916_54x_sfp51", as5916_54x_sfp51 }, { "as5916_54x_sfp52", as5916_54x_sfp52 }, +{ "as5916_54x_sfp53", as5916_54x_sfp53 }, { "as5916_54x_sfp54", as5916_54x_sfp54 }, +{ /* LIST END */ } +}; +MODULE_DEVICE_TABLE(i2c, sfp_device_id); +/* Platform dependent --- */ + +/* + * list of valid port types + * note OOM_PORT_TYPE_NOT_PRESENT to indicate no + * module is present in this port + */ +typedef enum oom_driver_port_type_e { + OOM_DRIVER_PORT_TYPE_INVALID, + OOM_DRIVER_PORT_TYPE_NOT_PRESENT, + OOM_DRIVER_PORT_TYPE_SFP, + OOM_DRIVER_PORT_TYPE_SFP_PLUS, + OOM_DRIVER_PORT_TYPE_QSFP, + OOM_DRIVER_PORT_TYPE_QSFP_PLUS, + OOM_DRIVER_PORT_TYPE_QSFP28 +} oom_driver_port_type_t; + +enum driver_type_e { + DRIVER_TYPE_SFP_MSA, + DRIVER_TYPE_SFP_DDM, + DRIVER_TYPE_QSFP +}; + +/* Each client has this additional data + */ +struct eeprom_data { + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + struct bin_attribute bin; /* eeprom data */ +}; + +struct sfp_msa_data { + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u64 status[6]; /* bit0:port0, bit1:port1 and so on */ + /* index 0 => tx_fail + 1 => tx_disable + 2 => rx_loss + 3 => device id + 4 => 10G Ethernet Compliance Codes + to distinguish SFP or SFP+ + 5 => DIAGNOSTIC MONITORING TYPE */ + struct eeprom_data eeprom; +}; + +struct sfp_ddm_data { + struct eeprom_data eeprom; +}; + +struct qsfp_data { + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 status[3]; /* bit0:port0, bit1:port1 and so on */ + /* index 0 => tx_fail + 1 => tx_disable + 2 => rx_loss */ + + u8 device_id; + struct eeprom_data eeprom; +}; + +struct sfp_port_data { + struct mutex update_lock; + enum driver_type_e driver_type; + int port; /* CPLD port index */ + oom_driver_port_type_t port_type; + u64 present; /* present status, bit0:port0, bit1:port1 and so on */ + + struct sfp_msa_data *msa; + struct sfp_ddm_data *ddm; + struct qsfp_data *qsfp; + + struct i2c_client *client; +}; + +static ssize_t show_port_number(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); +} + +/* Platform dependent +++ */ +static struct sfp_port_data *sfp_update_present(struct i2c_client *client) +{ + int i = 0, j = 0, status = -1; + u8 reg; + unsigned short cpld_addr; + struct sfp_port_data *data = i2c_get_clientdata(client); + + DEBUG_PRINT("Starting sfp present status update"); + mutex_lock(&data->update_lock); + data->present = 0; + + /* Read present status of port 1~48(SFP port) */ + for (i = 0; i < 2; i++) { + for (j = 0; j < 3; j++) { + cpld_addr = I2C_ADDR_CPLD1 + i*2; + reg = 0x10+j; + status = accton_i2c_cpld_read(cpld_addr, reg); + + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); + goto exit; + } + + DEBUG_PRINT("Present status = 0x%lx\r\n", data->present); + data->present |= (u64)status << ((i*24) + (j%3)*8); + } + } + + /* Read present status of port 49-52(QSFP port) */ + cpld_addr = I2C_ADDR_CPLD2; + reg = 0x52; + status = accton_i2c_cpld_read(cpld_addr, reg); + + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); + goto exit; + } + else { + data->present |= (u64)(status & 0x3F) << 48; + } + + DEBUG_PRINT("Present status = 0x%lx", data->present); +exit: + mutex_unlock(&data->update_lock); + return (status < 0) ? ERR_PTR(status) : data; +} + +static struct sfp_port_data* sfp_update_tx_rx_status(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + int i = 0, j = 0; + int status = -1; + u8 tx_rx_regs[] = {0x14, 0x16, 0x18, 0x20, 0x22, 0x24, 0x30, 0x32, 0x34}; + + if (time_before(jiffies, data->msa->last_updated + HZ + HZ / 2) && data->msa->valid) { + return data; + } + + DEBUG_PRINT("Starting as5916_54x sfp tx rx status update"); + mutex_lock(&data->update_lock); + data->msa->valid = 0; + memset(data->msa->status, 0, sizeof(data->msa->status)); + + /* Read status of port 1~48(SFP port) */ + for (i = 0; i < 2; i++) { + for (j = 0; j < ARRAY_SIZE(tx_rx_regs); j++) { + unsigned short cpld_addr = I2C_ADDR_CPLD1 + i*2; + + status = accton_i2c_cpld_read(cpld_addr, tx_rx_regs[j]); + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, tx_rx_regs[i], status); + goto exit; + } + + data->msa->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); + } + } + + data->msa->valid = 1; + data->msa->last_updated = jiffies; + +exit: + mutex_unlock(&data->update_lock); + return (status < 0) ? ERR_PTR(status) : data; +} + +static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + unsigned short cpld_addr = 0; + u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; + long disable; + int error; + u8 tx_disable_regs[] = {0x20, 0x22, 0x24}; + + if (data->driver_type == DRIVER_TYPE_QSFP) { + return qsfp_set_tx_disable(dev, da, buf, count); + } + + error = kstrtol(buf, 10, &disable); + if (error) { + return error; + } + + mutex_lock(&data->update_lock); + + if(data->port < 24) { + cpld_addr = I2C_ADDR_CPLD1; + cpld_reg = tx_disable_regs[data->port / 8]; + cpld_bit = 1 << (data->port % 8); + } + else { /* port 24 ~ 48 */ + cpld_addr = I2C_ADDR_CPLD2; + cpld_reg = tx_disable_regs[(data->port - 24) / 8]; + cpld_bit = 1 << (data->port % 8); + } + + /* Read current status */ + cpld_val = accton_i2c_cpld_read(cpld_addr, cpld_reg); + + /* Update tx_disable status */ + if (disable) { + data->msa->status[1] |= BIT_INDEX(data->port); + cpld_val |= cpld_bit; + } + else { + data->msa->status[1] &= ~BIT_INDEX(data->port); + cpld_val &= ~cpld_bit; + } + + accton_i2c_cpld_write(cpld_addr, cpld_reg, cpld_val); + mutex_unlock(&data->update_lock); + return count; +} + +static int sfp_is_port_present(struct i2c_client *client, int port) +{ + struct sfp_port_data *data = i2c_get_clientdata(client); + + data = sfp_update_present(client); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + return !(data->present & BIT_INDEX(data->port)); /* Platform dependent */ +} + +static ssize_t show_present(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); + + if (PRESENT_ALL == attr->index) { + int i; + u8 values[7] = {0}; + struct sfp_port_data *data = sfp_update_present(client); + + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + for (i = 0; i < ARRAY_SIZE(values); i++) { + values[i] = ~(u8)(data->present >> (i * 8)); + } + + /* Return values 1 -> 54 in order */ + return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], + values[3], values[4], values[5], + values[6] & 0x3F); + } + else { + struct sfp_port_data *data = i2c_get_clientdata(client); + int present = sfp_is_port_present(client, data->port); + + if (IS_ERR_VALUE(present)) { + return present; + } + + /* PRESENT */ + return sprintf(buf, "%d\n", present); + } +} +/* Platform dependent --- */ + +static struct sfp_port_data *sfp_update_port_type(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + u8 buf = 0; + int status; + + mutex_lock(&data->update_lock); + + switch (data->driver_type) { + case DRIVER_TYPE_SFP_MSA: + { + status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); + if (unlikely(status < 0)) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + if (buf != SFF8024_DEVICE_ID_SFP) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + status = sfp_eeprom_read(client, SFF8472_10G_ETH_COMPLIANCE_ADDR, &buf, sizeof(buf)); + if (unlikely(status < 0)) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + DEBUG_PRINT("sfp port type (0x3) data = (0x%x)", buf); + data->port_type = buf & SFF8472_10G_BASE_MASK ? OOM_DRIVER_PORT_TYPE_SFP_PLUS : OOM_DRIVER_PORT_TYPE_SFP; + break; + } + case DRIVER_TYPE_QSFP: + { + status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); + if (unlikely(status < 0)) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + DEBUG_PRINT("qsfp port type (0x0) buf = (0x%x)", buf); + switch (buf) { + case SFF8024_DEVICE_ID_QSFP: + data->port_type = OOM_DRIVER_PORT_TYPE_QSFP; + break; + case SFF8024_DEVICE_ID_QSFP_PLUS: + data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; + break; + case SFF8024_DEVICE_ID_QSFP28: + data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; + break; + default: + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + break; + } + default: + break; + } + + mutex_unlock(&data->update_lock); + return data; +} + +static ssize_t show_port_type(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + int present = sfp_is_port_present(client, data->port); + + if (IS_ERR_VALUE(present)) { + return present; + } + + if (!present) { + return sprintf(buf, "%d\n", OOM_DRIVER_PORT_TYPE_NOT_PRESENT); + } + + sfp_update_port_type(dev); + return sprintf(buf, "%d\n", data->port_type); +} + +static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + int i, status = -1; + u8 buf = 0; + u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; + + if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { + return data; + } + + DEBUG_PRINT("Starting sfp tx rx status update"); + mutex_lock(&data->update_lock); + data->qsfp->valid = 0; + memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); + + /* Notify device to update tx fault/ tx disable/ rx los status */ + for (i = 0; i < ARRAY_SIZE(reg); i++) { + status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); + if (unlikely(status < 0)) { + goto exit; + } + } + msleep(200); + + /* Read actual tx fault/ tx disable/ rx los status */ + for (i = 0; i < ARRAY_SIZE(reg); i++) { + status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); + if (unlikely(status < 0)) { + goto exit; + } + + DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); + data->qsfp->status[i] = (buf & 0xF); + } + + data->qsfp->valid = 1; + data->qsfp->last_updated = jiffies; + +exit: + mutex_unlock(&data->update_lock); + return (status < 0) ? ERR_PTR(status) : data; +} + +static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + int present; + u8 val = 0; + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + + present = sfp_is_port_present(client, data->port); + if (IS_ERR_VALUE(present)) { + return present; + } + + if (present == 0) { + /* port is not present */ + return -ENXIO; + } + + data = qsfp_update_tx_rx_status(dev); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + switch (attr->index) { + case TX_FAULT: + val = !!(data->qsfp->status[2] & 0xF); + break; + case TX_FAULT1: + case TX_FAULT2: + case TX_FAULT3: + case TX_FAULT4: + val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); + break; + case TX_DISABLE: + val = data->qsfp->status[1] & 0xF; + break; + case TX_DISABLE1: + case TX_DISABLE2: + case TX_DISABLE3: + case TX_DISABLE4: + val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); + break; + case RX_LOS: + val = !!(data->qsfp->status[0] & 0xF); + break; + case RX_LOS1: + case RX_LOS2: + case RX_LOS3: + case RX_LOS4: + val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); + break; + default: + break; + } + + return sprintf(buf, "%d\n", val); +} + +static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + long disable; + int status; + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + + status = sfp_is_port_present(client, data->port); + if (IS_ERR_VALUE(status)) { + return status; + } + + if (!status) { + /* port is not present */ + return -ENXIO; + } + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + + data = qsfp_update_tx_rx_status(dev); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + mutex_lock(&data->update_lock); + + if (attr->index == TX_DISABLE) { + data->qsfp->status[1] = disable & 0xF; + } + else {/* TX_DISABLE1 ~ TX_DISABLE4*/ + if (disable) { + data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); + } + else { + data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); + } + } + + DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); + status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); + if (unlikely(status < 0)) { + count = status; + } + + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, + char *buf) +{ + int status; + char ddm; + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + + status = sfp_is_port_present(client, data->port); + if (IS_ERR_VALUE(status)) { + return status; + } + + if (status == 0) { + /* port is not present */ + return -ENODEV; + } + + status = sfp_eeprom_read(client, SFF8472_DIAG_MON_TYPE_ADDR, &ddm, sizeof(ddm)); + if (unlikely(status < 0)) { + return status; + } + + return sprintf(buf, "%d\n", !!(ddm & SFF8472_DIAG_MON_TYPE_DDM_MASK)); +} + +/* Platform dependent +++ */ +static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + u8 val = 0, index = 0; + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + + if (data->driver_type == DRIVER_TYPE_QSFP) { + return qsfp_show_tx_rx_status(dev, da, buf); + } + + data = sfp_update_tx_rx_status(dev); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + if(attr->index == RX_LOS_ALL) { + int i = 0; + u8 values[6] = {0}; + + for (i = 0; i < ARRAY_SIZE(values); i++) { + values[i] = (u8)(data->msa->status[2] >> (i * 8)); + } + + /** Return values 1 -> 48 in order */ + return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], + values[3], values[4], values[5]); + } + + switch (attr->index) { + case TX_FAULT: + index = 0; + break; + case TX_DISABLE: + index = 1; + break; + case RX_LOS: + index = 2; + break; + default: + return 0; + } + + val = !!(data->msa->status[index] & BIT_INDEX(data->port)); + return sprintf(buf, "%d\n", val); +} +/* Platform dependent --- */ +static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, + int data_len) +{ +#if USE_I2C_BLOCK_READ + int status, retry = I2C_RW_RETRY_COUNT; + + if (data_len > I2C_SMBUS_BLOCK_MAX) { + data_len = I2C_SMBUS_BLOCK_MAX; + } + + while (retry) { + status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + return status; + } + + return data_len; +#else + int status, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, command, *data); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + return status; + } + + return 1; +#endif + + +} + +static ssize_t sfp_port_write(struct sfp_port_data *data, + const char *buf, loff_t off, size_t count) +{ + ssize_t retval = 0; + + if (unlikely(!count)) { + return count; + } + + /* + * Write data to chip, protecting against concurrent updates + * from this host, but not from other I2C masters. + */ + mutex_lock(&data->update_lock); + + while (count) { + ssize_t status; + + status = sfp_eeprom_write(data->client, off, buf, count); + if (status <= 0) { + if (retval == 0) { + retval = status; + } + break; + } + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&data->update_lock); + return retval; +} + + +static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + int present; + struct sfp_port_data *data; + DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); + data = dev_get_drvdata(container_of(kobj, struct device, kobj)); + + present = sfp_is_port_present(data->client, data->port); + if (IS_ERR_VALUE(present)) { + return present; + } + + if (present == 0) { + /* port is not present */ + return -ENODEV; + } + + return sfp_port_write(data, buf, off, count); +} + +static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, + int data_len) +{ +#if USE_I2C_BLOCK_READ + int status, retry = I2C_RW_RETRY_COUNT; + + if (data_len > I2C_SMBUS_BLOCK_MAX) { + data_len = I2C_SMBUS_BLOCK_MAX; + } + + while (retry) { + status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + goto abort; + } + if (unlikely(status != data_len)) { + status = -EIO; + goto abort; + } + + //result = data_len; + +abort: + return status; +#else + int status, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, command); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); + goto abort; + } + + *data = (u8)status; + status = 1; + +abort: + return status; +#endif +} + +static ssize_t sfp_port_read(struct sfp_port_data *data, + char *buf, loff_t off, size_t count) +{ + ssize_t retval = 0; + + if (unlikely(!count)) { + DEBUG_PRINT("Count = 0, return"); + return count; + } + + /* + * Read data from chip, protecting against concurrent updates + * from this host, but not from other I2C masters. + */ + mutex_lock(&data->update_lock); + + while (count) { + ssize_t status; + + status = sfp_eeprom_read(data->client, off, buf, count); + if (status <= 0) { + if (retval == 0) { + retval = status; + } + break; + } + + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&data->update_lock); + return retval; + +} + +static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + int present; + struct sfp_port_data *data; + DEBUG_PRINT("offset = (%d), count = (%d)", off, count); + data = dev_get_drvdata(container_of(kobj, struct device, kobj)); + + present = sfp_is_port_present(data->client, data->port); + if (IS_ERR_VALUE(present)) { + return present; + } + + if (present == 0) { + /* port is not present */ + return -ENODEV; + } + + return sfp_port_read(data, buf, off, count); +} + +static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) +{ + int err; + + sysfs_bin_attr_init(eeprom); + eeprom->attr.name = EEPROM_NAME; + eeprom->attr.mode = S_IWUSR | S_IRUGO; + eeprom->read = sfp_bin_read; + eeprom->write = sfp_bin_write; + eeprom->size = EEPROM_SIZE; + + /* Create eeprom file */ + err = sysfs_create_bin_file(kobj, eeprom); + if (err) { + return err; + } + + return 0; +} + +static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) +{ + sysfs_remove_bin_file(kobj, eeprom); + return 0; +} + +static const struct attribute_group sfp_msa_group = { + .attrs = sfp_msa_attributes, +}; + +static int sfp_i2c_check_functionality(struct i2c_client *client) +{ +#if USE_I2C_BLOCK_READ + return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); +#else + return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); +#endif +} + +static int sfp_msa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, + struct sfp_msa_data **data) +{ + int status; + struct sfp_msa_data *msa; + + if (!sfp_i2c_check_functionality(client)) { + status = -EIO; + goto exit; + } + + msa = kzalloc(sizeof(struct sfp_msa_data), GFP_KERNEL); + if (!msa) { + status = -ENOMEM; + goto exit; + } + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &sfp_msa_group); + if (status) { + goto exit_free; + } + + /* init eeprom */ + status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin); + if (status) { + goto exit_remove; + } + + *data = msa; + dev_info(&client->dev, "sfp msa '%s'\n", client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); +exit_free: + kfree(msa); +exit: + + return status; +} + +static const struct attribute_group sfp_ddm_group = { + .attrs = sfp_ddm_attributes, +}; + +static int sfp_ddm_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, + struct sfp_ddm_data **data) +{ + int status; + struct sfp_ddm_data *ddm; + + if (!sfp_i2c_check_functionality(client)) { + status = -EIO; + goto exit; + } + + ddm = kzalloc(sizeof(struct sfp_ddm_data), GFP_KERNEL); + if (!ddm) { + status = -ENOMEM; + goto exit; + } + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &sfp_ddm_group); + if (status) { + goto exit_free; + } + + /* init eeprom */ + status = sfp_sysfs_eeprom_init(&client->dev.kobj, &ddm->eeprom.bin); + if (status) { + goto exit_remove; + } + + *data = ddm; + dev_info(&client->dev, "sfp ddm '%s'\n", client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); +exit_free: + kfree(ddm); +exit: + + return status; +} + +static const struct attribute_group qsfp_group = { + .attrs = qsfp_attributes, +}; + +static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, + struct qsfp_data **data) +{ + int status; + struct qsfp_data *qsfp; + + if (!sfp_i2c_check_functionality(client)) { + status = -EIO; + goto exit; + } + + qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); + if (!qsfp) { + status = -ENOMEM; + goto exit; + } + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &qsfp_group); + if (status) { + goto exit_free; + } + + /* init eeprom */ + status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); + if (status) { + goto exit_remove; + } + + *data = qsfp; + dev_info(&client->dev, "qsfp '%s'\n", client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &qsfp_group); +exit_free: + kfree(qsfp); +exit: + + return status; +} + +/* Platform dependent +++ */ +static int sfp_device_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct sfp_port_data *data = NULL; + + data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); + if (!data) { + return -ENOMEM; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->port = dev_id->driver_data; + data->client = client; + + if (dev_id->driver_data >= as5916_54x_sfp1 && dev_id->driver_data <= as5916_54x_sfp48) { + if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { + data->driver_type = DRIVER_TYPE_SFP_MSA; + return sfp_msa_probe(client, dev_id, &data->msa); + } + else if (client->addr == SFP_EEPROM_A2_I2C_ADDR) { + data->driver_type = DRIVER_TYPE_SFP_DDM; + return sfp_ddm_probe(client, dev_id, &data->ddm); + } + } + else { /* as5916_54x_sfp49 ~ as5916_54x_sfp54 */ + if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { + data->driver_type = DRIVER_TYPE_QSFP; + return qsfp_probe(client, dev_id, &data->qsfp); + } + } + + return -ENODEV; +} +/* Platform dependent --- */ + +static int sfp_msa_remove(struct i2c_client *client, struct sfp_msa_data *data) +{ + sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); + sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); + kfree(data); + return 0; +} + +static int sfp_ddm_remove(struct i2c_client *client, struct sfp_ddm_data *data) +{ + sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); + sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); + kfree(data); + return 0; +} + +static int qfp_remove(struct i2c_client *client, struct qsfp_data *data) +{ + sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); + sysfs_remove_group(&client->dev.kobj, &qsfp_group); + kfree(data); + return 0; +} + +static int sfp_device_remove(struct i2c_client *client) +{ + struct sfp_port_data *data = i2c_get_clientdata(client); + + switch (data->driver_type) { + case DRIVER_TYPE_SFP_MSA: + return sfp_msa_remove(client, data->msa); + case DRIVER_TYPE_SFP_DDM: + return sfp_ddm_remove(client, data->ddm); + case DRIVER_TYPE_QSFP: + return qfp_remove(client, data->qsfp); + } + + return 0; +} + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; + +static struct i2c_driver sfp_driver = { + .driver = { + .name = DRIVER_NAME, + }, + .probe = sfp_device_probe, + .remove = sfp_device_remove, + .id_table = sfp_device_id, + .address_list = normal_i2c, +}; + +static int __init sfp_init(void) +{ + return i2c_add_driver(&sfp_driver); +} + +static void __exit sfp_exit(void) +{ + i2c_del_driver(&sfp_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("accton as5916_54x_sfp driver"); +MODULE_LICENSE("GPL"); + +late_initcall(sfp_init); +module_exit(sfp_exit); + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml new file mode 100644 index 00000000..facee58f --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml @@ -0,0 +1,27 @@ +variables: + platformbase: x86-64-accton-as5916-54x + r0_install: /lib/platform-config/${platformbase}-r0/onl + r1_install: /lib/platform-config/${platformbase}-r1/onl + +common: + version: 1.0.0 + arch: amd64 + copyright: Copyright 2013, 2014, 2015 Big Switch Networks + maintainer: support@bigswitch.com + support: opennetworklinux@googlegroups.com + changelog: Change changes changes., + +packages: + - name: onlp-${platformbase}-r0 + summary: ONLP Package for the ${platformbase}-r0 platform. + + files: + builds/lib/$BUILD_DIR/x86_64-linux-gnu/bin/libonlp-${platformbase}.so : ${r0_install}/lib/libonlp-${platformbase}.so + builds/onlpdump/$BUILD_DIR/x86_64-linux-gnu/bin/onlpdump : ${r0_install}/bin/ + + - name: onlp-${platformbase}-r1 + summary: ONLP Package for the ${platformbase}-r1 platform. + + files: + builds/lib/$BUILD_DIR/x86_64-linux-gnu/bin/libonlp-${platformbase}.so : ${r1_install}/lib/libonlp-${platformbase}.so + builds/onlpdump/$BUILD_DIR/x86_64-linux-gnu/bin/onlpdump : ${r1_install}/bin/ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/Makefile new file mode 100644 index 00000000..e7437cb2 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/lib/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/lib/Makefile new file mode 100644 index 00000000..1f155bfc --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/lib/Makefile @@ -0,0 +1,45 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +############################################################ +include $(ONL)/make/config.amd64.mk + +MODULE := libonlp-x86-64-accton-as5916-54x +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF x86_64_accton_as5916_54x onlplib +DEPENDMODULE_HEADERS := sff + +include $(BUILDER)/dependmodules.mk + +SHAREDLIB := libonlp-x86-64-accton-as5916-54x.so +$(SHAREDLIB)_TARGETS := $(ALL_TARGETS) +include $(BUILDER)/so.mk +.DEFAULT_GOAL := $(SHAREDLIB) + +GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -fPIC +GLOBAL_LINK_LIBS += -lpthread + +include $(BUILDER)/targets.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/onlpdump/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/onlpdump/Makefile new file mode 100644 index 00000000..0c41fbc0 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/onlpdump/Makefile @@ -0,0 +1,46 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ +include $(ONL)/make/config.amd64.mk + +.DEFAULT_GOAL := onlpdump + +MODULE := onlpdump +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF onlp x86_64_accton_as5916_54x onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS + +include $(BUILDER)/dependmodules.mk + +BINARY := onlpdump +$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS) +include $(BUILDER)/bin.mk + +GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1 +GLOBAL_LINK_LIBS += -lpthread -lm + +include $(BUILDER)/targets.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/.module b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/.module new file mode 100644 index 00000000..b7e5840e --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/.module @@ -0,0 +1 @@ +name: x86_64_accton_as5916_54x diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/Makefile new file mode 100644 index 00000000..10f71d72 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +include ../../init.mk +MODULE := x86_64_accton_as5916_54x +AUTOMODULE := x86_64_accton_as5916_54x +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/README b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/README new file mode 100644 index 00000000..64864843 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/README @@ -0,0 +1,6 @@ +############################################################################### +# +# x86_64_accton_as5916_54x README +# +############################################################################### + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/auto/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/auto/make.mk new file mode 100644 index 00000000..9db4a259 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/auto/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# x86_64_accton_as5916_54x Autogeneration +# +############################################################################### +x86_64_accton_as5916_54x_AUTO_DEFS := module/auto/x86_64_accton_as5916_54x.yml +x86_64_accton_as5916_54x_AUTO_DIRS := module/inc/x86_64_accton_as5916_54x module/src +include $(BUILDER)/auto.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/auto/x86_64_accton_as5916_54x.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/auto/x86_64_accton_as5916_54x.yml new file mode 100644 index 00000000..987f682f --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/auto/x86_64_accton_as5916_54x.yml @@ -0,0 +1,50 @@ +############################################################################### +# +# x86_64_accton_as5916_54x Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB +- X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 +- X86_64_ACCTON_AS5916_54X_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_AS5916_54X_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_accton_as5916_54x_config + + portingmacro: + x86_64_accton_as5916_54x: + macros: + - malloc + - free + - memset + - memcpy + - strncpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x.x b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x.x new file mode 100644 index 00000000..7776b59e --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x.x @@ -0,0 +1,14 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_config.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_config.h new file mode 100644 index 00000000..15a5af00 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_config.h @@ -0,0 +1,137 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5916_54x Configuration Header + * + * @addtogroup x86_64_accton_as5916_54x-config + * @{ + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5916_54x_CONFIG_H__ +#define __x86_64_accton_as5916_54x_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef x86_64_accton_as5916_54x_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING +#define x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT +#define x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT +#define x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB +#define x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB +#endif + +/** + * x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI +#define x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * + * Assume chassis fan direction is the same as the PSU fan direction. */ + + +#ifndef x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct x86_64_accton_as5916_54x_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_accton_as5916_54x_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_accton_as5916_54x_config_settings table. */ +extern x86_64_accton_as5916_54x_config_settings_t x86_64_accton_as5916_54x_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_accton_as5916_54x_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_accton_as5916_54x_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_accton_as5916_54x_porting.h" + +#endif /* __x86_64_accton_as5916_54x_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_dox.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_dox.h new file mode 100644 index 00000000..85d980e3 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_accton_as5916_54x Doxygen Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5916_54x_DOX_H__ +#define __x86_64_accton_as5916_54x_DOX_H__ + +/** + * @defgroup x86_64_accton_as5916_54x x86_64_accton_as5916_54x - x86_64_accton_as5916_54x Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_accton_as5916_54x-x86_64_accton_as5916_54x Public Interface + * @defgroup x86_64_accton_as5916_54x-config Compile Time Configuration + * @defgroup x86_64_accton_as5916_54x-porting Porting Macros + * + * @} + * + */ + +#endif /* __x86_64_accton_as5916_54x_DOX_H__ */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_porting.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_porting.h new file mode 100644 index 00000000..adf4e952 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_porting.h @@ -0,0 +1,107 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5916_54x Porting Macros. + * + * @addtogroup x86_64_accton_as5916_54x-porting + * @{ + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5916_54x_PORTING_H__ +#define __x86_64_accton_as5916_54x_PORTING_H__ + + +/* */ +#if x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef x86_64_accton_as5916_54x_MALLOC + #if defined(GLOBAL_MALLOC) + #define x86_64_accton_as5916_54x_MALLOC GLOBAL_MALLOC + #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_MALLOC malloc + #else + #error The macro x86_64_accton_as5916_54x_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_FREE + #if defined(GLOBAL_FREE) + #define x86_64_accton_as5916_54x_FREE GLOBAL_FREE + #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_FREE free + #else + #error The macro x86_64_accton_as5916_54x_FREE is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_MEMSET + #if defined(GLOBAL_MEMSET) + #define x86_64_accton_as5916_54x_MEMSET GLOBAL_MEMSET + #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_MEMSET memset + #else + #error The macro x86_64_accton_as5916_54x_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define x86_64_accton_as5916_54x_MEMCPY GLOBAL_MEMCPY + #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_MEMCPY memcpy + #else + #error The macro x86_64_accton_as5916_54x_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_STRNCPY + #if defined(GLOBAL_STRNCPY) + #define x86_64_accton_as5916_54x_STRNCPY GLOBAL_STRNCPY + #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_STRNCPY strncpy + #else + #error The macro x86_64_accton_as5916_54x_STRNCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define x86_64_accton_as5916_54x_VSNPRINTF GLOBAL_VSNPRINTF + #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_VSNPRINTF vsnprintf + #else + #error The macro x86_64_accton_as5916_54x_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define x86_64_accton_as5916_54x_SNPRINTF GLOBAL_SNPRINTF + #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_SNPRINTF snprintf + #else + #error The macro x86_64_accton_as5916_54x_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_STRLEN + #if defined(GLOBAL_STRLEN) + #define x86_64_accton_as5916_54x_STRLEN GLOBAL_STRLEN + #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_STRLEN strlen + #else + #error The macro x86_64_accton_as5916_54x_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __x86_64_accton_as5916_54x_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/make.mk new file mode 100644 index 00000000..568066a4 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/make.mk @@ -0,0 +1,10 @@ +############################################################################### +# +# +# +############################################################################### +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_accton_as5916_54x_INCLUDES := -I $(THIS_DIR)inc +x86_64_accton_as5916_54x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_accton_as5916_54x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5916_54x ucli:x86_64_accton_as5916_54x + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/Makefile new file mode 100644 index 00000000..04d2f92b --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# Local source generation targets. +# +############################################################################### + +ucli: + @../../../../tools/uclihandlers.py x86_64_accton_as5916_54x_ucli.c + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/fani.c new file mode 100644 index 00000000..d8319a0d --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/fani.c @@ -0,0 +1,354 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Fan Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +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 MAX_FAN_SPEED 25500 +#define MAX_PSU_FAN_SPEED 25500 + +#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_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\ + 0,\ + 0,\ + ONLP_FAN_MODE_INVALID,\ + } + +/* Static fan information */ +onlp_fan_info_t finfo[] = { + { }, /* Not used */ + CHASSIS_FAN_INFO(1), + CHASSIS_FAN_INFO(2), + CHASSIS_FAN_INFO(3), + CHASSIS_FAN_INFO(4), + CHASSIS_FAN_INFO(5), + CHASSIS_FAN_INFO(6), + 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, ret; + + /* get fan present status + */ + ret = onlp_file_read_int(&value, "%s""fan%d_present", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + + if (value == 0) { + return ONLP_STATUS_OK; /* fan is not present */ + } + info->status |= ONLP_FAN_STATUS_PRESENT; + + + /* get fan fault status (turn on when any one fails) + */ + ret = onlp_file_read_int(&value, "%s""fan%d_fault", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + + if (value > 0) { + info->status |= ONLP_FAN_STATUS_FAILED; + } + + + /* get fan direction (both : the same) + */ + ret = onlp_file_read_int(&value, "%s""fan%d_direction", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + + info->status |= value ? ONLP_FAN_STATUS_F2B : ONLP_FAN_STATUS_B2F; + + + /* get front fan speed + */ + ret = onlp_file_read_int(&value, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + info->rpm = value; + + /* get rear fan speed + */ + ret = onlp_file_read_int(&value, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_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 + */ + ret = onlp_file_read_int(&value, "%s""fan_max_speed_rpm", FAN_BOARD_PATH); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + + info->percentage = (info->rpm * 100)/value; + + return ONLP_STATUS_OK; +} + +static uint32_t +_onlp_get_fan_direction_on_psu(void) +{ + /* Try to read direction from PSU1. + * If PSU1 is not valid, read from PSU2 + */ + int i = 0; + + for (i = PSU1_ID; i <= PSU2_ID; i++) { + psu_type_t psu_type; + psu_type = get_psu_type(i, NULL, 0); + + if (psu_type == PSU_TYPE_UNKNOWN) { + continue; + } + + if (PSU_TYPE_AC_F2B == psu_type) { + return ONLP_FAN_STATUS_F2B; + } + else { + return ONLP_FAN_STATUS_B2F; + } + } + + 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 fan direction + */ + info->status |= _onlp_get_fan_direction_on_psu(); + + /* get fan speed + */ + if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == ONLP_STATUS_OK) { + info->rpm = val; + info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED; + info->status |= (val == 0) ? ONLP_FAN_STATUS_FAILED : 0; + } + + 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_fan1_duty_cycle_percentage", p); + case FAN_1_ON_PSU_2: + return psu_ym2651y_pmbus_info_set(PSU2_ID, "psu_fan1_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; + } + + if (onlp_file_write_int(p, path) < 0) { + AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + + +/* + * This function sets the fan speed of the given OID as per + * the predefined ONLP fan speed modes: off, slow, normal, fast, max. + * + * Interpretation of these modes is up to the platform. + * + */ +int +onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function sets the fan direction of the given OID. + * + * This function is only relevant if the fan OID supports both direction + * capabilities. + * + * This function is optional unless the functionality is available. + */ +int +onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * Generic fan ioctl. Optional. + */ +int +onlp_fani_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/ledi.c new file mode 100644 index 00000000..31a17cc1 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/ledi.c @@ -0,0 +1,256 @@ +/************************************************************ + * + * + * 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 "platform_lib.h" + +#define LED_FORMAT "/sys/class/leds/accton_as5916_54x_led::%s/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_LOC, + LED_DIAG, + LED_PSU1, + LED_PSU2, + LED_FAN, +}; + +enum led_light_mode { + LED_MODE_OFF, + LED_MODE_RED = 10, + LED_MODE_RED_BLINKING = 11, + LED_MODE_ORANGE = 12, + LED_MODE_ORANGE_BLINKING = 13, + LED_MODE_YELLOW = 14, + LED_MODE_YELLOW_BLINKING = 15, + LED_MODE_GREEN = 16, + LED_MODE_GREEN_BLINKING = 17, + LED_MODE_BLUE = 18, + LED_MODE_BLUE_BLINKING = 19, + LED_MODE_PURPLE = 20, + LED_MODE_PURPLE_BLINKING = 21, + LED_MODE_AUTO = 22, + LED_MODE_AUTO_BLINKING = 23, + LED_MODE_WHITE = 24, + LED_MODE_WHITE_BLINKING = 25, + LED_MODE_CYAN = 26, + LED_MODE_CYAN_BLINKING = 27, + LED_MODE_UNKNOWN = 99 +}; + +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_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_LOC, LED_MODE_ORANGE, ONLP_LED_MODE_ORANGE}, +{LED_DIAG, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_DIAG, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, +{LED_DIAG, LED_MODE_ORANGE, ONLP_LED_MODE_ORANGE}, +{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 *leds[] = /* must map with onlp_led_id */ +{ + NULL, + "loc", + "diag", + "psu1", + "psu2", + "fan" +}; + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t linfo[] = +{ + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_LOC), "Chassis LED 1 (LOC LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE, + }, + { + { ONLP_LED_ID_CREATE(LED_DIAG), "Chassis LED 2 (DIAG LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU1), "Chassis LED 3 (PSU1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU2), "Chassis LED 4 (PSU2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN), "Chassis LED 5 (FAN LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | 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) +{ + /* + * Turn off the LOCATION and DIAG LEDs at startup + */ + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_DIAG), ONLP_LED_MODE_OFF); + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_LOC), ONLP_LED_MODE_OFF); + + return ONLP_STATUS_OK; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int lid, value; + + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[ONLP_OID_ID_GET(id)]; + + /* Get LED mode */ + if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) { + DEBUG_PRINT("Unable to read status from file "LED_FORMAT, leds[lid]); + 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; + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + if (onlp_file_write_int(onlp_to_driver_led_mode(lid , mode), LED_FORMAT, leds[lid]) < 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/x86-64-accton-as5916-54x/onlp/builds/src/module/src/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/make.mk new file mode 100644 index 00000000..b3aafcb3 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### + +LIBRARY := x86_64_accton_as5916_54x +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/platform_lib.c new file mode 100644 index 00000000..1837a772 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/platform_lib.c @@ -0,0 +1,124 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include "platform_lib.h" + +#define PSU_NODE_MAX_PATH_LEN 64 +#define PSU_MODEL_NAME_LEN 9 +#define PSU_FAN_DIR_LEN 3 + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len) +{ + int ret = 0, value = 0; + char model[PSU_MODEL_NAME_LEN + 1] = {0}; + char fan_dir[PSU_FAN_DIR_LEN + 1] = {0}; + char *path = NULL; + + if (modelname && modelname_len < PSU_MODEL_NAME_LEN) { + return PSU_TYPE_UNKNOWN; + } + + /* Check AC model name */ + path = (id == PSU1_ID) ? PSU1_AC_EEPROM_NODE(psu_model_name) : PSU2_AC_EEPROM_NODE(psu_model_name); + ret = onlp_file_read((uint8_t*)model, PSU_MODEL_NAME_LEN, &value, path); + if (ret != ONLP_STATUS_OK || value != PSU_MODEL_NAME_LEN) { + return PSU_TYPE_UNKNOWN; + + } + + if (strncmp(model, "YM-2651Y", strlen("YM-2651Y")) != 0) { + return PSU_TYPE_UNKNOWN; + } + + if (modelname) { + strncpy(modelname, model, modelname_len-1); + } + + path = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_fan_dir) : PSU2_AC_PMBUS_NODE(psu_fan_dir); + ret = onlp_file_read((uint8_t*)fan_dir, sizeof(fan_dir), &value, path); + if (ret != ONLP_STATUS_OK) { + return PSU_TYPE_UNKNOWN; + } + + if (strncmp(fan_dir, "F2B", strlen("F2B")) == 0) { + return PSU_TYPE_AC_F2B; + } + + if (strncmp(fan_dir, "B2F", strlen("B2F")) == 0) { + return PSU_TYPE_AC_B2F; + } + + return PSU_TYPE_UNKNOWN; +} + +int psu_ym2651y_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) { + ret = onlp_file_read_int(value, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + } + else { + ret = onlp_file_read_int(value, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + } + + if (ret < 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; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/platform_lib.h new file mode 100644 index 00000000..f00d5d41 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/platform_lib.h @@ -0,0 +1,89 @@ +/************************************************************ + * + * + * 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 "x86_64_accton_as5916_54x_log.h" + +#define CHASSIS_FAN_COUNT 6 +#define CHASSIS_THERMAL_COUNT 5 +#define CHASSIS_LED_COUNT 5 +#define CHASSIS_PSU_COUNT 2 + +#define PSU1_ID 1 +#define PSU2_ID 2 + +#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/18-005b/" +#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/17-0058/" + +#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_EEPROM_PREFIX "/sys/bus/i2c/devices/18-0053/" +#define PSU2_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/17-0050/" + +#define PSU1_AC_EEPROM_NODE(node) PSU1_AC_EEPROM_PREFIX#node +#define PSU2_AC_EEPROM_NODE(node) PSU2_AC_EEPROM_PREFIX#node + +#define FAN_BOARD_PATH "/sys/bus/i2c/devices/9-0066/" +#define FAN_NODE(node) FAN_BOARD_PATH#node + +#define IDPROM_PATH "/sys/bus/i2c/devices/0-0054/eeprom" + +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_1_ON_PSU1, + THERMAL_1_ON_PSU2, +}; + +typedef enum psu_type { + PSU_TYPE_UNKNOWN, + PSU_TYPE_AC_F2B, + PSU_TYPE_AC_B2F +} psu_type_t; + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len); +int psu_ym2651y_pmbus_info_get(int id, char *node, int *value); +int psu_ym2651y_pmbus_info_set(int id, char *node, int value); + +#define DEBUG_MODE 0 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printf("%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif + +#endif /* __PLATFORM_LIB_H__ */ + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/psui.c new file mode 100644 index 00000000..f7f64f0e --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/psui.c @@ -0,0 +1,177 @@ +/************************************************************ + * + * + * 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 "platform_lib.h" + +#define PSU_STATUS_PRESENT 1 +#define PSU_STATUS_POWER_GOOD 1 +#define PSU_NODE_MAX_PATH_LEN 64 + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_PSU(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static int +psu_status_info_get(int id, char *node, int *value) +{ + char *prefix = NULL; + + *value = 0; + + prefix = (id == PSU1_ID) ? PSU1_AC_EEPROM_PREFIX : PSU2_AC_EEPROM_PREFIX; + if (onlp_file_read_int(value, "%s%s", prefix, node) < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s%s)\r\n", prefix, node); + return ONLP_STATUS_E_INTERNAL; + } + + return 0; +} + +int +onlp_psui_init(void) +{ + return ONLP_STATUS_OK; +} + +static int +psu_ym2651y_info_get(onlp_psu_info_t* info) +{ + int val = 0; + int index = ONLP_OID_ID_GET(info->hdr.id); + + /* Set capability + */ + info->caps = ONLP_PSU_CAPS_AC; + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Set the associated oid_table */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); + + /* Read voltage, current and power */ + if (psu_ym2651y_pmbus_info_get(index, "psu_v_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_ym2651y_pmbus_info_get(index, "psu_i_out", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (psu_ym2651y_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + 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) { + printf("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) { + printf("Unable to read PSU(%d) node(psu_power_good)\r\n", index); + } + + if (val != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_PSU_STATUS_FAILED; + } + + + /* Get PSU type + */ + psu_type = get_psu_type(index, info->model, sizeof(info->model)); + + switch (psu_type) { + case PSU_TYPE_AC_F2B: + case PSU_TYPE_AC_B2F: + ret = psu_ym2651y_info_get(info); + break; + case PSU_TYPE_UNKNOWN: /* User insert a unknown PSU or unplugged.*/ + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + info->status &= ~ONLP_PSU_STATUS_FAILED; + ret = ONLP_STATUS_OK; + break; + default: + ret = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + 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/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sfpi.c new file mode 100644 index 00000000..7309efbe --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sfpi.c @@ -0,0 +1,289 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2017 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 "platform_lib.h" + +#include "x86_64_accton_as5916_54x_log.h" + +#define NUM_OF_SFP_PORT 54 +#define MAX_PORT_PATH 64 + +#define SFP_PORT_FORMAT "/sys/bus/i2c/devices/%d-0050/%s" +#define SFP_PORT_DOM_FORMAT "/sys/bus/i2c/devices/%d-0051/%s" +#define SFP_BUS_INDEX(port) (port+33) + +/************************************************************ + * + * SFPI Entry Points + * + ***********************************************************/ +int +onlp_sfpi_init(void) +{ + /* Called at initialization time */ + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) +{ + /* + * Ports {0, 54} + */ + int p; + AIM_BITMAP_INIT(bmap, 64); + AIM_BITMAP_CLR_ALL(bmap); + + for(p = 0; p < NUM_OF_SFP_PORT; p++) { + AIM_BITMAP_SET(bmap, p); + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_is_present(int port) +{ + /* + * Return 1 if present. + * Return 0 if not present. + * Return < 0 if error. + */ + int present; + if (onlp_file_read_int(&present, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_is_present") < 0) { + AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return present; +} + +int +onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[7]; + char path[MAX_PORT_PATH] = {0}; + FILE* fp; + + sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_is_present_all"); + fp = fopen(path, "r"); + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + int count = fscanf(fp, "%x %x %x %x %x %x %x", + bytes+0, + bytes+1, + bytes+2, + bytes+3, + bytes+4, + bytes+5, + bytes+6 + ); + fclose(fp); + if(count != AIM_ARRAYSIZE(bytes)) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + + /* Mask out non-existant QSFP ports */ + bytes[6] &= 0x3F; + + /* Convert to 64 bit integer in port order */ + int i = 0; + uint64_t presence_all = 0 ; + for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { + presence_all <<= 8; + presence_all |= bytes[i]; + } + + /* Populate bitmap */ + for(i = 0; presence_all; i++) { + AIM_BITMAP_MOD(dst, i, (presence_all & 1)); + presence_all >>= 1; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + int size = 0; + if(onlp_file_read(data, 256, &size, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { + if(size == 256) { + return ONLP_STATUS_OK; + } + } + + return ONLP_STATUS_E_INTERNAL; +} + +int +onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + int size = 0; + if(onlp_file_read(data, 256, &size, SFP_PORT_DOM_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { + if(size == 256) { + return ONLP_STATUS_OK; + } + } + + return ONLP_STATUS_E_INTERNAL; +} + +int +onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[6]; + char path[MAX_PORT_PATH] = {0}; + FILE* fp; + + sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_rx_los_all"); + fp = fopen(path, "r"); + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + int count = fscanf(fp, "%x %x %x %x %x %x", + bytes+0, + bytes+1, + bytes+2, + bytes+3, + bytes+4, + bytes+5 + ); + fclose(fp); + if(count != 6) { + AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + + /* Convert to 64 bit integer in port order */ + int i = 0; + uint64_t rx_los_all = 0 ; + for(i = 5; 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_control_set(int port, onlp_sfp_control_t control, int value) +{ + int rv; + + switch(control) + { + case ONLP_SFP_CONTROL_TX_DISABLE: + { + if (onlp_file_write_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") != 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; + } + + 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; + + switch(control) + { + case ONLP_SFP_CONTROL_RX_LOS: + { + if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_rx_los") < 0) { + AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_FAULT: + { + if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_fault") < 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; + } + break; + } + + case ONLP_SFP_CONTROL_TX_DISABLE: + { + if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") < 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; + } + + 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/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sysi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sysi.c new file mode 100644 index 00000000..44bf47a1 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sysi.c @@ -0,0 +1,339 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2017 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include + +#include +#include +#include +#include +#include +#include +#include "platform_lib.h" + +#include "x86_64_accton_as5916_54x_int.h" +#include "x86_64_accton_as5916_54x_log.h" + +#define CPLD_VERSION_FORMAT "/sys/bus/i2c/devices/%s/version" +#define NUM_OF_CPLD 2 + +static char* cpld_path[NUM_OF_CPLD] = +{ + "11-0060", + "12-0062" +}; + +const char* +onlp_sysi_platform_get(void) +{ + return "x86-64-accton-as5916-54x-r1"; +} + +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)); + + /* 5 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}; + + for (i = 0; i < AIM_ARRAYSIZE(cpld_path); i++) { + v[i] = 0; + + if(onlp_file_read_int(v+i, CPLD_VERSION_FORMAT , cpld_path[i]) < 0) { + return ONLP_STATUS_E_INTERNAL; + } + } + + pi->cpld_versions = aim_fstrdup("%d.%d", v[0], v[1]); + return ONLP_STATUS_OK; +} + +void +onlp_sysi_platform_info_free(onlp_platform_info_t* pi) +{ + aim_free(pi->cpld_versions); +} + +#define FAN_DUTY_MAX (100) +#define FAN_DUTY_MID (69) +#define FAN_DUTY_MIN (38) + +#define FANCTRL_DIR_FACTOR (ONLP_FAN_STATUS_B2F) +#define FANCTRL_DIR_FACTOR_DUTY_ADDON (6) + +static int +sysi_fanctrl_fan_fault_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int i; + *adjusted = 0; + + /* Bring fan speed to FAN_DUTY_MAX if any fan is not operational */ + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + if (!(fi[i].status & ONLP_FAN_STATUS_FAILED)) { + continue; + } + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_fan_absent_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int i; + *adjusted = 0; + + /* Bring fan speed to FAN_DUTY_MAX if fan is not present */ + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + if (fi[i].status & ONLP_FAN_STATUS_PRESENT) { + continue; + } + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_fan_unknown_speed_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int fanduty; + int fanduty_min = FAN_DUTY_MIN; + int fanduty_mid = FAN_DUTY_MID; + + *adjusted = 0; + fanduty_min += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + + if (onlp_file_read_int(&fanduty, FAN_NODE(fan_duty_cycle_percentage)) < 0) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + /* Bring fan speed to max if current speed is not expected + */ + if (fanduty != fanduty_min && fanduty != fanduty_mid && fanduty != FAN_DUTY_MAX) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_single_thermal_sensor_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int i; + *adjusted = 0; + + /* When anyone higher than 50 degrees, all fans run with duty 100%. + */ + for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) { + if (ti[i-1].mcelsius < 50000) { + continue; + } + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + /* When anyone higher than 45 degrees, all fans run with duty 62.5%. + */ + for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) { + if (ti[i-1].mcelsius < 45000) { + continue; + } + + int fanduty_mid = FAN_DUTY_MID; + fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_mid); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_overall_thermal_sensor_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int fanduty_min = FAN_DUTY_MIN; + int fanduty_mid = FAN_DUTY_MID; + int i, num_of_sensor = 0, temp_avg = 0; + + *adjusted = 0; + fanduty_min += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + + for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) { + num_of_sensor++; + temp_avg += ti[i-1].mcelsius; + } + + temp_avg /= num_of_sensor; + + if (temp_avg >= 45000) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + else if (temp_avg >= 40000) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_mid); + } + else if (temp_avg < 35000) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_min); + } + + return ONLP_STATUS_OK; +} + +typedef int (*fan_control_policy)(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted); + +fan_control_policy fan_control_policies[] = { +sysi_fanctrl_fan_fault_policy, +sysi_fanctrl_fan_absent_policy, +sysi_fanctrl_fan_unknown_speed_policy, +sysi_fanctrl_single_thermal_sensor_policy, +sysi_fanctrl_overall_thermal_sensor_policy, +}; + +int +onlp_sysi_platform_manage_fans(void) +{ + int i, rc; + onlp_fan_info_t fi[CHASSIS_FAN_COUNT]; + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT]; + + memset(fi, 0, sizeof(fi)); + memset(ti, 0, sizeof(ti)); + + /* Get fan status + */ + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + rc = onlp_fani_info_get(ONLP_FAN_ID_CREATE(i+1), &fi[i]); + + if (rc != ONLP_STATUS_OK) { + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + return ONLP_STATUS_E_INTERNAL; + } + } + + /* Get thermal sensor status + */ + for (i = 0; i < CHASSIS_THERMAL_COUNT; i++) { + rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(i+1), &ti[i]); + + if (rc != ONLP_STATUS_OK) { + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + return ONLP_STATUS_E_INTERNAL; + } + } + + /* Apply thermal policy according the policy list, + * If fan duty is adjusted by one of the policies, skip the others + */ + for (i = 0; i < AIM_ARRAYSIZE(fan_control_policies); i++) { + int adjusted = 0; + + rc = fan_control_policies[i](fi, ti, &adjusted); + if (!adjusted) { + continue; + } + + return rc; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_platform_manage_leds(void) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/thermali.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/thermali.c new file mode 100644 index 00000000..742a4dd1 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/thermali.c @@ -0,0 +1,128 @@ +/************************************************************ + * + * + * 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 "platform_lib.h" + +#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/10-0048*temp1_input", + "/sys/bus/i2c/devices/10-0049*temp1_input", + "/sys/bus/i2c/devices/10-004a*temp1_input", + "/sys/bus/i2c/devices/10-004b*temp1_input", + "/sys/bus/i2c/devices/18-005b*psu_temp1_input", + "/sys/bus/i2c/devices/17-0058*psu_temp1_input", +}; + +static char* cpu_coretemp_files[] = + { + "/sys/devices/platform/coretemp.0*temp2_input", + "/sys/devices/platform/coretemp.0*temp3_input", + "/sys/devices/platform/coretemp.0*temp4_input", + "/sys/devices/platform/coretemp.0*temp5_input", + NULL, + }; + +/* Static values */ +static onlp_thermal_info_t linfo[] = { + { }, /* Not used */ + { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), "CPU Core", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-1-48", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "LM75-2-49", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "LM75-3-4A", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "LM75-3-4B", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 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, + ONLP_THERMAL_CAPS_ALL, 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, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + } +}; + +/* + * This will be called to intiialize the thermali subsystem. + */ +int +onlp_thermali_init(void) +{ + return ONLP_STATUS_OK; +} + +/* + * Retrieve the information structure for the given thermal OID. + * + * If the OID is invalid, return ONLP_E_STATUS_INVALID. + * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. + * Otherwise, return ONLP_STATUS_OK with the OID's information. + * + * Note -- it is expected that you fill out the information + * structure even if the sensor described by the OID is not present. + */ +int +onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) +{ + int tid; + VALIDATE(id); + + tid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[tid]; + + if(tid == THERMAL_CPU_CORE) { + int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files); + return rv; + } + + return onlp_file_read_int(&info->mcelsius, devfiles__[tid]); +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_config.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_config.c new file mode 100644 index 00000000..7f36f202 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_config.c @@ -0,0 +1,80 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* */ +#define __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(_x) __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(_x) +x86_64_accton_as5916_54x_config_settings_t x86_64_accton_as5916_54x_config_settings[] = +{ +#ifdef x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING) }, +#else +{ x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB) }, +#else +{ x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI) }, +#else +{ x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#else +{ x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE +#undef __x86_64_accton_as5916_54x_config_STRINGIFY_NAME + +const char* +x86_64_accton_as5916_54x_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_accton_as5916_54x_config_settings[i].name; i++) { + if(strcmp(x86_64_accton_as5916_54x_config_settings[i].name, setting)) { + return x86_64_accton_as5916_54x_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_accton_as5916_54x_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_accton_as5916_54x_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_accton_as5916_54x_config_settings[i].name, x86_64_accton_as5916_54x_config_settings[i].value); + } + return i; +} + +/* */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_enums.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_enums.c new file mode 100644 index 00000000..b2b98d07 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_enums.c @@ -0,0 +1,10 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_int.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_int.h new file mode 100644 index 00000000..4543ef58 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_int.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * x86_64_accton_as5916_54x Internal Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5916_54x_INT_H__ +#define __x86_64_accton_as5916_54x_INT_H__ + +#include + + +#endif /* __x86_64_accton_as5916_54x_INT_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.c new file mode 100644 index 00000000..99398f5a --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.c @@ -0,0 +1,18 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5916_54x_log.h" +/* + * x86_64_accton_as5916_54x log struct. + */ +AIM_LOG_STRUCT_DEFINE( + x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT, + x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.h new file mode 100644 index 00000000..5e6ad4d0 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5916_54x_LOG_H__ +#define __x86_64_accton_as5916_54x_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_accton_as5916_54x +#include + +#endif /* __x86_64_accton_as5916_54x_LOG_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_module.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_module.c new file mode 100644 index 00000000..efd313db --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_module.c @@ -0,0 +1,24 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5916_54x_log.h" + +static int +datatypes_init__(void) +{ +#define x86_64_accton_as5916_54x_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_as5916_54x_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_ucli.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_ucli.c new file mode 100644 index 00000000..fe6e423f --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_ucli.c @@ -0,0 +1,50 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#if x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_accton_as5916_54x_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as5916_54x) +} + +/* */ +/* */ + +static ucli_module_t +x86_64_accton_as5916_54x_ucli_module__ = + { + "x86_64_accton_as5916_54x_ucli", + NULL, + x86_64_accton_as5916_54x_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_accton_as5916_54x_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_accton_as5916_54x_ucli_module__); + n = ucli_node_create("x86_64_accton_as5916_54x", NULL, &x86_64_accton_as5916_54x_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as5916_54x")); + return n; +} + +#else +void* +x86_64_accton_as5916_54x_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/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/x86-64-accton-as5916-54x/platform-config/r1/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/PKG.yml new file mode 100644 index 00000000..caedb664 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as5916-54x REVISION=r1 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/lib/x86-64-accton-as5916-54x-r1.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/lib/x86-64-accton-as5916-54x-r1.yml new file mode 100644 index 00000000..42278b23 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/lib/x86-64-accton-as5916-54x-r1.yml @@ -0,0 +1,33 @@ +--- + +###################################################################### +# +# platform-config for AS5916 +# +###################################################################### + +x86-64-accton-as5916-54x-r1: + + grub: + + serial: >- + --port=0x3f8 + --speed=115200 + --word=8 + --parity=no + --stop=1 + + kernel: + <<: *kernel-3-16 + + args: >- + nopat + console=ttyS0,115200n8 + tg3.short_preamble=1 + tg3.bcm5718s_reset=1 + + ##network: + ## interfaces: + ## ma1: + ## name: ~ + ## syspath: pci0000:00/0000:00:1c.0/0000:0a:00.0 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/python/x86_64_accton_as5916_54x_r1/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/python/x86_64_accton_as5916_54x_r1/__init__.py new file mode 100644 index 00000000..171b3c20 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/python/x86_64_accton_as5916_54x_r1/__init__.py @@ -0,0 +1,72 @@ +from onl.platform.base import * +from onl.platform.accton import * + +class OnlPlatform_x86_64_accton_as5916_54x_r1(OnlPlatformAccton, + OnlPlatformPortConfig_48x10_6x40): + PLATFORM='x86-64-accton-as5916-54x-r1' + MODEL="AS5916-54X" + SYS_OBJECT_ID=".5916.54" + + def baseconfig(self): + self.insmod("accton_i2c_cpld") + self.insmod("ym2651y") + for m in [ "sfp", "psu", "fan", "leds" ]: + self.insmod("x86-64-accton-as5916-54x-%s" % m) + + ########### initialize I2C bus 0 ########### + self.new_i2c_devices( + [ + # initialize multiplexer (PCA9548) + ('pca9548', 0x77, 0), + ('pca9548', 0x76, 1), + + # initiate chassis fan + ('as5916_54x_fan', 0x66, 9), + + # inititate LM75 + ('lm75', 0x48, 10), + ('lm75', 0x49, 10), + ('lm75', 0x4a, 10), + ('lm75', 0x4b, 10), + + # initialize CPLDs + ('accton_i2c_cpld', 0x60, 11), + ('accton_i2c_cpld', 0x62, 12), + + # initialize multiplexer (PCA9548) + ('pca9548', 0x74, 2), + + # initiate PSU-1 AC Power + ('as5916_54x_psu1', 0x53, 18), + ('ym2651', 0x5b, 18), + + # initiate PSU-2 AC Power + ('as5916_54x_psu2', 0x50, 17), + ('ym2651', 0x58, 17), + + # initialize multiplexer (PCA9548) + ('pca9548', 0x72, 2), + ('pca9548', 0x75, 25), + ('pca9548', 0x75, 26), + ('pca9548', 0x75, 27), + ('pca9548', 0x75, 28), + ('pca9548', 0x75, 29), + ('pca9548', 0x75, 30), + ('pca9548', 0x75, 31), + + # initiate IDPROM + ('24c02', 0x54, 0), + ] + ) + + # initialize SFP devices + for port in range(1, 49): + self.new_i2c_device('as5916_54x_sfp%d' % port, 0x50, port+32) + self.new_i2c_device('as5916_54x_sfp%d' % port, 0x51, port+32) + + # initialize QSFP devices + for port in range(49, 55): + self.new_i2c_device('as5916_54x_sfp%d' % port, 0x50, port+32) + + return True + From d151fa4895d93b15d9ac7df43697ea6aa89ebce4 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 24 Aug 2017 14:01:17 +0000 Subject: [PATCH 38/67] Add stretch build options. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index b9a2b57a..c183f82e 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ $(foreach a,$(ALL_ARCHES),$(eval $(call build_arch_template,$(a)))) # Available build architectures based on the current suite BUILD_ARCHES_wheezy := amd64 powerpc BUILD_ARCHES_jessie := $(ALL_ARCHES) +BUILD_ARCHES_stretch := amd64 # Build available architectures by default. .DEFAULT_GOAL := all From 5c9eba88e4594c844444564fb171b6c583cc9f00 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 24 Aug 2017 14:32:57 +0000 Subject: [PATCH 39/67] Latest --- packages/platforms-closed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/platforms-closed b/packages/platforms-closed index c42683c1..194d6cef 160000 --- a/packages/platforms-closed +++ b/packages/platforms-closed @@ -1 +1 @@ -Subproject commit c42683c1317cf662331a34a2a84b5879144f8a56 +Subproject commit 194d6cef67bc5f67eecad95456c5085cd5ba47c3 From f243f7c8c2a809c358f31bc32bf297f883b37160 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Thu, 24 Aug 2017 17:30:31 -0700 Subject: [PATCH 40/67] Relax 'onlmounts' label parsing - previous checkin regressed this - re-enable e.g. 'boot' or 'BOOT' or 'ONL-BOOT' --- .../src/python/onl/mounts/__init__.py | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py b/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py index 6ddedbe5..bf591df6 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py @@ -225,6 +225,7 @@ class OnlMountManager(object): labels = labels + self.mdata['mounts'].keys() def _f(label): + """skip labels that do not resolve to a block device (ideally, optional ones)""" mpt = self.mdata['mounts'][label] dev = mpt.get('device', None) opt = mpt.get('optional', False) @@ -232,21 +233,24 @@ class OnlMountManager(object): if not opt: return True return False - labels = [x for x in labels if _f(x)] - # skip labels that do not resolve to a block device (ideally, optional ones) - rv = [] for l in list(set(labels)): - if self.__label_entry("ONL-%s" % l.upper(), False): - rv.append("ONL-%s" % l.upper()) - elif self.__label_entry(l.upper(), False): - rv.append(l.upper()) - elif self.__label_entry(l): - rv.append(l) - else: - pass - return rv; + lbl = "ONL-%s" % l.upper() + if self.__label_entry(lbl, False) and _f(lbl): + rv.append("ONL-%s" % l.upper()) + continue + + lbl = l.upper() + if self.__label_entry(lbl, False) and _f(lbl): + rv.append(l.upper()) + continue + + lbl = l + if self.__label_entry(lbl) and _f(lbl): + rv.append(l) + + return rv def fsck(self, labels, force=False): labels = self.validate_labels(labels) From 3e1654ee61aa091b9b05dba5e84849a54ae95d30 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Fri, 25 Aug 2017 07:19:15 +0000 Subject: [PATCH 41/67] [as5912-54xk] Modify source code to follow coding standards --- .../onlp/builds/src/module/src/debug.c | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/debug.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/debug.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/debug.c deleted file mode 100644 index d9d9ae6c..00000000 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/debug.c +++ /dev/null @@ -1,45 +0,0 @@ -#include "x86_64_accton_as5912_54xk_int.h" - -#if x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEBUG == 1 - -#include - -static char help__[] = - "Usage: debug [options]\n" - " -c CPLD Versions\n" - " -h Help\n" - ; - -int -x86_64_accton_as5912_54xk_debug_main(int argc, char* argv[]) -{ - int c = 0; - int help = 0; - int rv = 0; - - while( (c = getopt(argc, argv, "ch")) != -1) { - switch(c) - { - case 'c': c = 1; break; - case 'h': help = 1; rv = 0; break; - default: help = 1; rv = 1; break; - } - - } - - if(help || argc == 1) { - printf("%s", help__); - return rv; - } - - if(c) { - printf("Not implemented.\n"); - } - - - return 0; -} - -#endif - - From b4158e5ebf84383f72d4bb78e471b4939a2c6441 Mon Sep 17 00:00:00 2001 From: "sam.cc.chang" Date: Fri, 25 Aug 2017 00:32:20 -0700 Subject: [PATCH 42/67] Support ingrasys platform --- packages/platforms/ingrasys/Makefile | 1 + .../platforms/ingrasys/vendor-config/Makefile | 1 + .../platforms/ingrasys/vendor-config/PKG.yml | 1 + .../src/python/ingrasys/__init__.py | 7 + packages/platforms/ingrasys/x86-64/Makefile | 1 + .../ingrasys/x86-64/modules/Makefile | 1 + .../platforms/ingrasys/x86-64/modules/PKG.yml | 1 + .../ingrasys/x86-64/modules/builds/Makefile | 6 + .../x86-64/modules/builds/eeprom_mb.c | 212 ++ .../x86-64/x86-64-ingrasys-s9100/.gitignore | 1 + .../x86-64/x86-64-ingrasys-s9100/Makefile | 1 + .../x86-64-ingrasys-s9100/modules/Makefile | 1 + .../x86-64-ingrasys-s9100/modules/PKG.yml | 1 + .../modules/builds/Makefile | 6 + .../modules/builds/eeprom.c | 237 ++ .../modules/builds/w83795.c | 2287 +++++++++++++++++ .../x86-64-ingrasys-s9100/onlp/Makefile | 1 + .../x86-64/x86-64-ingrasys-s9100/onlp/PKG.yml | 1 + .../onlp/builds/Makefile | 2 + .../onlp/builds/lib/Makefile | 45 + .../onlp/builds/onlpdump/Makefile | 45 + .../src/x86_64_ingrasys_s9100/.gitignore | 2 + .../builds/src/x86_64_ingrasys_s9100/.module | 1 + .../builds/src/x86_64_ingrasys_s9100/Makefile | 10 + .../x86_64_ingrasys_s9100/module/auto/make.mk | 7 + .../module/auto/x86-64-ingrasys-s9100.yml | 47 + .../x86_64_ingrasys_s9100.x | 34 + .../x86_64_ingrasys_s9100_config.h | 162 ++ .../x86_64_ingrasys_s9100_dox.h | 26 + .../x86_64_ingrasys_s9100_porting.h | 106 + .../src/x86_64_ingrasys_s9100/module/make.mk | 29 + .../x86_64_ingrasys_s9100/module/src/Makefile | 30 + .../x86_64_ingrasys_s9100/module/src/fani.c | 283 ++ .../x86_64_ingrasys_s9100/module/src/ledi.c | 143 ++ .../x86_64_ingrasys_s9100/module/src/make.mk | 29 + .../module/src/platform_lib.c | 528 ++++ .../module/src/platform_lib.h | 248 ++ .../x86_64_ingrasys_s9100/module/src/psui.c | 150 ++ .../x86_64_ingrasys_s9100/module/src/sfpi.c | 159 ++ .../x86_64_ingrasys_s9100/module/src/sysi.c | 292 +++ .../module/src/thermali.c | 181 ++ .../module/src/x86_64_ingrasys_s9100_config.c | 101 + .../module/src/x86_64_ingrasys_s9100_enums.c | 30 + .../module/src/x86_64_ingrasys_s9100_int.h | 29 + .../module/src/x86_64_ingrasys_s9100_log.c | 38 + .../module/src/x86_64_ingrasys_s9100_log.h | 32 + .../module/src/x86_64_ingrasys_s9100_module.c | 44 + .../module/src/x86_64_ingrasys_s9100_ucli.c | 82 + .../platform-config/Makefile | 1 + .../platform-config/r0/Makefile | 1 + .../platform-config/r0/PKG.yml | 1 + .../r0/src/lib/x86-64-ingrasys-s9100-r0.yml | 30 + .../x86_64_ingrasys_s9100_r0/__init__.py | 496 ++++ 53 files changed, 6211 insertions(+) create mode 100755 packages/platforms/ingrasys/Makefile create mode 100755 packages/platforms/ingrasys/vendor-config/Makefile create mode 100755 packages/platforms/ingrasys/vendor-config/PKG.yml create mode 100755 packages/platforms/ingrasys/vendor-config/src/python/ingrasys/__init__.py create mode 100755 packages/platforms/ingrasys/x86-64/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/modules/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/modules/PKG.yml create mode 100755 packages/platforms/ingrasys/x86-64/modules/builds/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/modules/builds/eeprom_mb.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/.gitignore create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/PKG.yml create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/eeprom.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/w83795.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/PKG.yml create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/lib/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/onlpdump/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/.gitignore create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/.module create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/auto/make.mk create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/auto/x86-64-ingrasys-s9100.yml create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100.x create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_config.h create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_dox.h create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_porting.h create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/make.mk create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/fani.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/make.mk create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.h create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/psui.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sfpi.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sysi.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/thermali.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_config.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_enums.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_int.h create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.h create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_module.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_ucli.c create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/Makefile create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/PKG.yml create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/lib/x86-64-ingrasys-s9100-r0.yml create mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py diff --git a/packages/platforms/ingrasys/Makefile b/packages/platforms/ingrasys/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/ingrasys/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ingrasys/vendor-config/Makefile b/packages/platforms/ingrasys/vendor-config/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/ingrasys/vendor-config/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ingrasys/vendor-config/PKG.yml b/packages/platforms/ingrasys/vendor-config/PKG.yml new file mode 100755 index 00000000..e7d9d9e1 --- /dev/null +++ b/packages/platforms/ingrasys/vendor-config/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-vendor.yml VENDOR=ingrasys Vendor=ingrasys diff --git a/packages/platforms/ingrasys/vendor-config/src/python/ingrasys/__init__.py b/packages/platforms/ingrasys/vendor-config/src/python/ingrasys/__init__.py new file mode 100755 index 00000000..36f39285 --- /dev/null +++ b/packages/platforms/ingrasys/vendor-config/src/python/ingrasys/__init__.py @@ -0,0 +1,7 @@ +#!/usr/bin/python + +from onl.platform.base import * + +class OnlPlatformingrasys(OnlPlatformBase): + MANUFACTURER='Ingrasys' + PRIVATE_ENTERPRISE_NUMBER=2468 diff --git a/packages/platforms/ingrasys/x86-64/Makefile b/packages/platforms/ingrasys/x86-64/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/modules/Makefile b/packages/platforms/ingrasys/x86-64/modules/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/modules/PKG.yml b/packages/platforms/ingrasys/x86-64/modules/PKG.yml new file mode 100755 index 00000000..74f7e1b1 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/arch-vendor-modules.yml ARCH=amd64 VENDOR=ingrasys KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/modules/builds/Makefile b/packages/platforms/ingrasys/x86-64/modules/builds/Makefile new file mode 100755 index 00000000..f08898aa --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-3.16-lts-x86-64-all:amd64 +KMODULES := $(wildcard *.c) +VENDOR := ingrasys +BASENAME := common +ARCH := x86_64 +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/ingrasys/x86-64/modules/builds/eeprom_mb.c b/packages/platforms/ingrasys/x86-64/modules/builds/eeprom_mb.c new file mode 100755 index 00000000..ec4fe3d6 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/modules/builds/eeprom_mb.c @@ -0,0 +1,212 @@ +/* + * Copyright (C) 1998, 1999 Frodo Looijaard and + * Philip Edelbrock + * Copyright (C) 2003 Greg Kroah-Hartman + * Copyright (C) 2003 IBM Corp. + * Copyright (C) 2004 Jean Delvare + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { /* 0x50, 0x51, 0x52, 0x53, 0x54, + 0x55, 0x56, 0x57, */ I2C_CLIENT_END }; + + +/* Size of EEPROM in bytes */ +#define EEPROM_SIZE 256 + +#define SLICE_BITS (6) +#define SLICE_SIZE (1 << SLICE_BITS) +#define SLICE_NUM (EEPROM_SIZE/SLICE_SIZE) + +/* Each client has this additional data */ +struct eeprom_data { + struct mutex update_lock; + u8 valid; /* bitfield, bit!=0 if slice is valid */ + unsigned long last_updated[SLICE_NUM]; /* In jiffies, 8 slices */ + u8 data[EEPROM_SIZE]; /* Register values */ +}; + + +static void mb_eeprom_update_client(struct i2c_client *client, u8 slice) +{ + struct eeprom_data *data = i2c_get_clientdata(client); + int i, j; + int ret; + int addr; + + mutex_lock(&data->update_lock); + + if (!(data->valid & (1 << slice)) || + time_after(jiffies, data->last_updated[slice] + 300 * HZ)) { + dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); + + addr = slice << SLICE_BITS; + + ret = i2c_smbus_write_byte_data(client, ((u8)addr >> 8) & 0xFF, (u8)addr & 0xFF); + /* select the eeprom address */ + if (ret < 0) { + dev_err(&client->dev, "address set failed\n"); + goto exit; + } + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE)) { + goto exit; + } + + for (i = slice << SLICE_BITS; i < (slice + 1) << SLICE_BITS; i+= SLICE_SIZE) { + for (j = i; j < (i+SLICE_SIZE); j++) { + int res; + + res = i2c_smbus_read_byte(client); + if (res < 0) { + goto exit; + } + + data->data[j] = res & 0xFF; + } + } + + data->last_updated[slice] = jiffies; + data->valid |= (1 << slice); + } +exit: + mutex_unlock(&data->update_lock); +} + +static ssize_t mb_eeprom_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t off, size_t count) +{ + struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); + struct eeprom_data *data = i2c_get_clientdata(client); + u8 slice; + + if (off > EEPROM_SIZE) { + return 0; + } + if (off + count > EEPROM_SIZE) { + count = EEPROM_SIZE - off; + } + if (count == 0) { + return 0; + } + + /* Only refresh slices which contain requested bytes */ + for (slice = off >> SLICE_BITS; slice <= (off + count - 1) >> SLICE_BITS; slice++) { + mb_eeprom_update_client(client, slice); + } + + memcpy(buf, &data->data[off], count); + + return count; +} + +static struct bin_attribute mb_eeprom_attr = { + .attr = { + .name = "eeprom", + .mode = S_IRUGO, + }, + .size = EEPROM_SIZE, + .read = mb_eeprom_read, +}; + +/* Return 0 if detection is successful, -ENODEV otherwise */ +static int mb_eeprom_detect(struct i2c_client *client, struct i2c_board_info *info) +{ + struct i2c_adapter *adapter = client->adapter; + + /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all + addresses 0x50-0x57, but we only care about 0x50. So decline + attaching to addresses >= 0x51 on DDC buses */ + if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x51) { + return -ENODEV; + } + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE) + && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { + return -ENODEV; + } + + strlcpy(info->type, "eeprom", I2C_NAME_SIZE); + + return 0; +} + +static int mb_eeprom_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct eeprom_data *data; + int err; + + if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { + err = -ENOMEM; + goto exit; + } + + memset(data->data, 0xff, EEPROM_SIZE); + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + + /* create the sysfs eeprom file */ + err = sysfs_create_bin_file(&client->dev.kobj, &mb_eeprom_attr); + if (err) { + goto exit_kfree; + } + + return 0; + +exit_kfree: + kfree(data); +exit: + return err; +} + +static int mb_eeprom_remove(struct i2c_client *client) +{ + sysfs_remove_bin_file(&client->dev.kobj, &mb_eeprom_attr); + kfree(i2c_get_clientdata(client)); + + return 0; +} + +static const struct i2c_device_id mb_eeprom_id[] = { + { "mb_eeprom", 0 }, + { } +}; + +static struct i2c_driver mb_eeprom_driver = { + .driver = { + .name = "mb_eeprom", + }, + .probe = mb_eeprom_probe, + .remove = mb_eeprom_remove, + .id_table = mb_eeprom_id, + + .class = I2C_CLASS_DDC | I2C_CLASS_SPD, + .detect = mb_eeprom_detect, + .address_list = normal_i2c, +}; + +module_i2c_driver(mb_eeprom_driver); + +MODULE_AUTHOR("Wade "); +MODULE_DESCRIPTION("Ingrasys S9100 Mother Borad EEPROM driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/.gitignore b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/.gitignore new file mode 100755 index 00000000..9f7b1342 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/.gitignore @@ -0,0 +1 @@ +onlpdump.mk diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/PKG.yml b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/PKG.yml new file mode 100755 index 00000000..c99bf793 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml ARCH=amd64 VENDOR=ingrasys BASENAME=x86-64-ingrasys-s9100 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/Makefile new file mode 100755 index 00000000..f5d7b12f --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-3.16-lts-x86-64-all:amd64 +KMODULES := $(wildcard *.c) +VENDOR := ingrasys +BASENAME := x86-64-ingrasys-s9100 +ARCH := x86_64 +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/eeprom.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/eeprom.c new file mode 100755 index 00000000..33f8673d --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/eeprom.c @@ -0,0 +1,237 @@ +/* + * Copyright (C) 1998, 1999 Frodo Looijaard and + * Philip Edelbrock + * Copyright (C) 2003 Greg Kroah-Hartman + * Copyright (C) 2003 IBM Corp. + * Copyright (C) 2004 Jean Delvare + * + * 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. + */ + +#include +#include +#include +#include +#include +#include + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54, + 0x55, 0x56, 0x57, I2C_CLIENT_END }; + + +/* Size of EEPROM in bytes */ +#define EEPROM_SIZE 256 + +/* possible types of eeprom devices */ +enum eeprom_nature { + UNKNOWN, + VAIO, +}; + +/* Each client has this additional data */ +struct eeprom_data { + struct mutex update_lock; + u8 valid; /* bitfield, bit!=0 if slice is valid */ + unsigned long last_updated[8]; /* In jiffies, 8 slices */ + u8 data[EEPROM_SIZE]; /* Register values */ + enum eeprom_nature nature; +}; + + +static void eeprom_update_client(struct i2c_client *client, u8 slice) +{ + struct eeprom_data *data = i2c_get_clientdata(client); + int i; + + mutex_lock(&data->update_lock); + + if (!(data->valid & (1 << slice)) || + time_after(jiffies, data->last_updated[slice] + 300 * HZ)) { + dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); + + if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + for (i = slice << 5; i < (slice + 1) << 5; i += 32) + if (i2c_smbus_read_i2c_block_data(client, i, + 32, data->data + i) + != 32) + goto exit; + } else { + for (i = slice << 5; i < (slice + 1) << 5; i += 2) { + int word = i2c_smbus_read_word_data(client, i); + if (word < 0) + goto exit; + data->data[i] = word & 0xff; + data->data[i + 1] = word >> 8; + } + } + data->last_updated[slice] = jiffies; + data->valid |= (1 << slice); + } +exit: + mutex_unlock(&data->update_lock); +} + +static ssize_t eeprom_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t off, size_t count) +{ + struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); + struct eeprom_data *data = i2c_get_clientdata(client); + u8 slice; + + if (off > EEPROM_SIZE) + return 0; + if (off + count > EEPROM_SIZE) + count = EEPROM_SIZE - off; + + /* Only refresh slices which contain requested bytes */ + for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++) + eeprom_update_client(client, slice); + + /* Hide Vaio private settings to regular users: + - BIOS passwords: bytes 0x00 to 0x0f + - UUID: bytes 0x10 to 0x1f + - Serial number: 0xc0 to 0xdf */ + if (data->nature == VAIO && !capable(CAP_SYS_ADMIN)) { + int i; + + for (i = 0; i < count; i++) { + if ((off + i <= 0x1f) || + (off + i >= 0xc0 && off + i <= 0xdf)) + buf[i] = 0; + else + buf[i] = data->data[off + i]; + } + } else { + memcpy(buf, &data->data[off], count); + } + + return count; +} + +static struct bin_attribute eeprom_attr = { + .attr = { + .name = "eeprom", + .mode = S_IRUGO, + }, + .size = EEPROM_SIZE, + .read = eeprom_read, +}; + +/* Return 0 if detection is successful, -ENODEV otherwise */ +static int eeprom_detect(struct i2c_client *client, struct i2c_board_info *info) +{ + struct i2c_adapter *adapter = client->adapter; + + /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all + addresses 0x50-0x57, but we only care about 0x50. So decline + attaching to addresses >= 0x51 on DDC buses */ + if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x51) + return -ENODEV; + + /* There are four ways we can read the EEPROM data: + (1) I2C block reads (faster, but unsupported by most adapters) + (2) Word reads (128% overhead) + (3) Consecutive byte reads (88% overhead, unsafe) + (4) Regular byte data reads (265% overhead) + The third and fourth methods are not implemented by this driver + because all known adapters support one of the first two. */ + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA) + && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) + return -ENODEV; + + strlcpy(info->type, "eeprom", I2C_NAME_SIZE); + + return 0; +} + +static int eeprom_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adapter = client->adapter; + struct eeprom_data *data; + int err; + + if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { + err = -ENOMEM; + goto exit; + } + + memset(data->data, 0xff, EEPROM_SIZE); + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->nature = UNKNOWN; + + /* Detect the Vaio nature of EEPROMs. + We use the "PCG-" or "VGN-" prefix as the signature. */ + if (client->addr == 0x57 + && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { + char name[4]; + + name[0] = i2c_smbus_read_byte_data(client, 0x80); + name[1] = i2c_smbus_read_byte_data(client, 0x81); + name[2] = i2c_smbus_read_byte_data(client, 0x82); + name[3] = i2c_smbus_read_byte_data(client, 0x83); + + if (!memcmp(name, "PCG-", 4) || !memcmp(name, "VGN-", 4)) { + dev_info(&client->dev, "Vaio EEPROM detected, " + "enabling privacy protection\n"); + data->nature = VAIO; + } + } + + /* create the sysfs eeprom file */ + err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr); + if (err) + goto exit_kfree; + + return 0; + +exit_kfree: + kfree(data); +exit: + return err; +} + +static int eeprom_remove(struct i2c_client *client) +{ + sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr); + kfree(i2c_get_clientdata(client)); + + return 0; +} + +static const struct i2c_device_id eeprom_id[] = { + { "eeprom", 0 }, + { } +}; + +static struct i2c_driver eeprom_driver = { + .driver = { + .name = "eeprom", + }, + .probe = eeprom_probe, + .remove = eeprom_remove, + .id_table = eeprom_id, + + .class = I2C_CLASS_DDC | I2C_CLASS_SPD, + .detect = eeprom_detect, + .address_list = normal_i2c, +}; + +module_i2c_driver(eeprom_driver); + +MODULE_AUTHOR("Frodo Looijaard and " + "Philip Edelbrock and " + "Greg Kroah-Hartman "); +MODULE_DESCRIPTION("I2C EEPROM driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/w83795.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/w83795.c new file mode 100755 index 00000000..21894131 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/w83795.c @@ -0,0 +1,2287 @@ +/* + * w83795.c - Linux kernel driver for hardware monitoring + * Copyright (C) 2008 Nuvoton Technology Corp. + * Wei Song + * Copyright (C) 2010 Jean Delvare + * + * 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 - version 2. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + * + * Supports following chips: + * + * Chip #vin #fanin #pwm #temp #dts wchipid vendid i2c ISA + * w83795g 21 14 8 6 8 0x79 0x5ca3 yes no + * w83795adg 18 14 2 6 8 0x79 0x5ca3 yes no + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { + 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END +}; + + +static bool reset; +module_param(reset, bool, 0); +MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); + + +#define W83795_REG_BANKSEL 0x00 +#define W83795_REG_VENDORID 0xfd +#define W83795_REG_CHIPID 0xfe +#define W83795_REG_DEVICEID 0xfb +#define W83795_REG_DEVICEID_A 0xff + +#define W83795_REG_I2C_ADDR 0xfc +#define W83795_REG_CONFIG 0x01 +#define W83795_REG_CONFIG_CONFIG48 0x04 +#define W83795_REG_CONFIG_START 0x01 + +/* Multi-Function Pin Ctrl Registers */ +#define W83795_REG_VOLT_CTRL1 0x02 +#define W83795_REG_VOLT_CTRL2 0x03 +#define W83795_REG_TEMP_CTRL1 0x04 +#define W83795_REG_TEMP_CTRL2 0x05 +#define W83795_REG_FANIN_CTRL1 0x06 +#define W83795_REG_FANIN_CTRL2 0x07 +#define W83795_REG_VMIGB_CTRL 0x08 + +#define TEMP_READ 0 +#define TEMP_CRIT 1 +#define TEMP_CRIT_HYST 2 +#define TEMP_WARN 3 +#define TEMP_WARN_HYST 4 +/* + * only crit and crit_hyst affect real-time alarm status + * current crit crit_hyst warn warn_hyst + */ +static const u16 W83795_REG_TEMP[][5] = { + {0x21, 0x96, 0x97, 0x98, 0x99}, /* TD1/TR1 */ + {0x22, 0x9a, 0x9b, 0x9c, 0x9d}, /* TD2/TR2 */ + {0x23, 0x9e, 0x9f, 0xa0, 0xa1}, /* TD3/TR3 */ + {0x24, 0xa2, 0xa3, 0xa4, 0xa5}, /* TD4/TR4 */ + {0x1f, 0xa6, 0xa7, 0xa8, 0xa9}, /* TR5 */ + {0x20, 0xaa, 0xab, 0xac, 0xad}, /* TR6 */ +}; + +#define IN_READ 0 +#define IN_MAX 1 +#define IN_LOW 2 +static const u16 W83795_REG_IN[][3] = { + /* Current, HL, LL */ + {0x10, 0x70, 0x71}, /* VSEN1 */ + {0x11, 0x72, 0x73}, /* VSEN2 */ + {0x12, 0x74, 0x75}, /* VSEN3 */ + {0x13, 0x76, 0x77}, /* VSEN4 */ + {0x14, 0x78, 0x79}, /* VSEN5 */ + {0x15, 0x7a, 0x7b}, /* VSEN6 */ + {0x16, 0x7c, 0x7d}, /* VSEN7 */ + {0x17, 0x7e, 0x7f}, /* VSEN8 */ + {0x18, 0x80, 0x81}, /* VSEN9 */ + {0x19, 0x82, 0x83}, /* VSEN10 */ + {0x1A, 0x84, 0x85}, /* VSEN11 */ + {0x1B, 0x86, 0x87}, /* VTT */ + {0x1C, 0x88, 0x89}, /* 3VDD */ + {0x1D, 0x8a, 0x8b}, /* 3VSB */ + {0x1E, 0x8c, 0x8d}, /* VBAT */ + {0x1F, 0xa6, 0xa7}, /* VSEN12 */ + {0x20, 0xaa, 0xab}, /* VSEN13 */ + {0x21, 0x96, 0x97}, /* VSEN14 */ + {0x22, 0x9a, 0x9b}, /* VSEN15 */ + {0x23, 0x9e, 0x9f}, /* VSEN16 */ + {0x24, 0xa2, 0xa3}, /* VSEN17 */ +}; +#define W83795_REG_VRLSB 0x3C + +static const u8 W83795_REG_IN_HL_LSB[] = { + 0x8e, /* VSEN1-4 */ + 0x90, /* VSEN5-8 */ + 0x92, /* VSEN9-11 */ + 0x94, /* VTT, 3VDD, 3VSB, 3VBAT */ + 0xa8, /* VSEN12 */ + 0xac, /* VSEN13 */ + 0x98, /* VSEN14 */ + 0x9c, /* VSEN15 */ + 0xa0, /* VSEN16 */ + 0xa4, /* VSEN17 */ +}; + +#define IN_LSB_REG(index, type) \ + (((type) == 1) ? W83795_REG_IN_HL_LSB[(index)] \ + : (W83795_REG_IN_HL_LSB[(index)] + 1)) + +#define IN_LSB_SHIFT 0 +#define IN_LSB_IDX 1 +static const u8 IN_LSB_SHIFT_IDX[][2] = { + /* High/Low LSB shift, LSB No. */ + {0x00, 0x00}, /* VSEN1 */ + {0x02, 0x00}, /* VSEN2 */ + {0x04, 0x00}, /* VSEN3 */ + {0x06, 0x00}, /* VSEN4 */ + {0x00, 0x01}, /* VSEN5 */ + {0x02, 0x01}, /* VSEN6 */ + {0x04, 0x01}, /* VSEN7 */ + {0x06, 0x01}, /* VSEN8 */ + {0x00, 0x02}, /* VSEN9 */ + {0x02, 0x02}, /* VSEN10 */ + {0x04, 0x02}, /* VSEN11 */ + {0x00, 0x03}, /* VTT */ + {0x02, 0x03}, /* 3VDD */ + {0x04, 0x03}, /* 3VSB */ + {0x06, 0x03}, /* VBAT */ + {0x06, 0x04}, /* VSEN12 */ + {0x06, 0x05}, /* VSEN13 */ + {0x06, 0x06}, /* VSEN14 */ + {0x06, 0x07}, /* VSEN15 */ + {0x06, 0x08}, /* VSEN16 */ + {0x06, 0x09}, /* VSEN17 */ +}; + + +#define W83795_REG_FAN(index) (0x2E + (index)) +#define W83795_REG_FAN_MIN_HL(index) (0xB6 + (index)) +#define W83795_REG_FAN_MIN_LSB(index) (0xC4 + (index) / 2) +#define W83795_REG_FAN_MIN_LSB_SHIFT(index) \ + (((index) & 1) ? 4 : 0) + +#define W83795_REG_VID_CTRL 0x6A + +#define W83795_REG_ALARM_CTRL 0x40 +#define ALARM_CTRL_RTSACS (1 << 7) +#define W83795_REG_ALARM(index) (0x41 + (index)) +#define W83795_REG_CLR_CHASSIS 0x4D +#define W83795_REG_BEEP(index) (0x50 + (index)) + +#define W83795_REG_OVT_CFG 0x58 +#define OVT_CFG_SEL (1 << 7) + + +#define W83795_REG_FCMS1 0x201 +#define W83795_REG_FCMS2 0x208 +#define W83795_REG_TFMR(index) (0x202 + (index)) +#define W83795_REG_FOMC 0x20F + +#define W83795_REG_TSS(index) (0x209 + (index)) + +#define TSS_MAP_RESERVED 0xff +static const u8 tss_map[4][6] = { + { 0, 1, 2, 3, 4, 5}, + { 6, 7, 8, 9, 0, 1}, + {10, 11, 12, 13, 2, 3}, + { 4, 5, 4, 5, TSS_MAP_RESERVED, TSS_MAP_RESERVED}, +}; + +#define PWM_OUTPUT 0 +#define PWM_FREQ 1 +#define PWM_START 2 +#define PWM_NONSTOP 3 +#define PWM_STOP_TIME 4 +#define W83795_REG_PWM(index, nr) (0x210 + (nr) * 8 + (index)) + +#define W83795_REG_FTSH(index) (0x240 + (index) * 2) +#define W83795_REG_FTSL(index) (0x241 + (index) * 2) +#define W83795_REG_TFTS 0x250 + +#define TEMP_PWM_TTTI 0 +#define TEMP_PWM_CTFS 1 +#define TEMP_PWM_HCT 2 +#define TEMP_PWM_HOT 3 +#define W83795_REG_TTTI(index) (0x260 + (index)) +#define W83795_REG_CTFS(index) (0x268 + (index)) +#define W83795_REG_HT(index) (0x270 + (index)) + +#define SF4_TEMP 0 +#define SF4_PWM 1 +#define W83795_REG_SF4_TEMP(temp_num, index) \ + (0x280 + 0x10 * (temp_num) + (index)) +#define W83795_REG_SF4_PWM(temp_num, index) \ + (0x288 + 0x10 * (temp_num) + (index)) + +#define W83795_REG_DTSC 0x301 +#define W83795_REG_DTSE 0x302 +#define W83795_REG_DTS(index) (0x26 + (index)) +#define W83795_REG_PECI_TBASE(index) (0x320 + (index)) + +#define DTS_CRIT 0 +#define DTS_CRIT_HYST 1 +#define DTS_WARN 2 +#define DTS_WARN_HYST 3 +#define W83795_REG_DTS_EXT(index) (0xB2 + (index)) + +#define SETUP_PWM_DEFAULT 0 +#define SETUP_PWM_UPTIME 1 +#define SETUP_PWM_DOWNTIME 2 +#define W83795_REG_SETUP_PWM(index) (0x20C + (index)) + +static inline u16 in_from_reg(u8 index, u16 val) +{ + /* 3VDD, 3VSB and VBAT: 6 mV/bit; other inputs: 2 mV/bit */ + if (index >= 12 && index <= 14) + return val * 6; + else + return val * 2; +} + +static inline u16 in_to_reg(u8 index, u16 val) +{ + if (index >= 12 && index <= 14) + return val / 6; + else + return val / 2; +} + +static inline unsigned long fan_from_reg(u16 val) +{ + if ((val == 0xfff) || (val == 0)) + return 0; + return 1350000UL / val; +} + +static inline u16 fan_to_reg(long rpm) +{ + if (rpm <= 0) + return 0x0fff; + return clamp_val((1350000 + (rpm >> 1)) / rpm, 1, 0xffe); +} + +static inline unsigned long time_from_reg(u8 reg) +{ + return reg * 100; +} + +static inline u8 time_to_reg(unsigned long val) +{ + return clamp_val((val + 50) / 100, 0, 0xff); +} + +static inline long temp_from_reg(s8 reg) +{ + return reg * 1000; +} + +static inline s8 temp_to_reg(long val, s8 min, s8 max) +{ + return clamp_val(val / 1000, min, max); +} + +static const u16 pwm_freq_cksel0[16] = { + 1024, 512, 341, 256, 205, 171, 146, 128, + 85, 64, 32, 16, 8, 4, 2, 1 +}; + +static unsigned int pwm_freq_from_reg(u8 reg, u16 clkin) +{ + unsigned long base_clock; + + if (reg & 0x80) { + base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256); + return base_clock / ((reg & 0x7f) + 1); + } else + return pwm_freq_cksel0[reg & 0x0f]; +} + +static u8 pwm_freq_to_reg(unsigned long val, u16 clkin) +{ + unsigned long base_clock; + u8 reg0, reg1; + unsigned long best0, best1; + + /* Best fit for cksel = 0 */ + for (reg0 = 0; reg0 < ARRAY_SIZE(pwm_freq_cksel0) - 1; reg0++) { + if (val > (pwm_freq_cksel0[reg0] + + pwm_freq_cksel0[reg0 + 1]) / 2) + break; + } + if (val < 375) /* cksel = 1 can't beat this */ + return reg0; + best0 = pwm_freq_cksel0[reg0]; + + /* Best fit for cksel = 1 */ + base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256); + reg1 = clamp_val(DIV_ROUND_CLOSEST(base_clock, val), 1, 128); + best1 = base_clock / reg1; + reg1 = 0x80 | (reg1 - 1); + + /* Choose the closest one */ + if (abs(val - best0) > abs(val - best1)) + return reg1; + else + return reg0; +} + +enum chip_types {w83795g, w83795adg}; + +struct w83795_data { + struct device *hwmon_dev; + struct mutex update_lock; + unsigned long last_updated; /* In jiffies */ + enum chip_types chip_type; + + u8 bank; + + u32 has_in; /* Enable monitor VIN or not */ + u8 has_dyn_in; /* Only in2-0 can have this */ + u16 in[21][3]; /* Register value, read/high/low */ + u8 in_lsb[10][3]; /* LSB Register value, high/low */ + u8 has_gain; /* has gain: in17-20 * 8 */ + + u16 has_fan; /* Enable fan14-1 or not */ + u16 fan[14]; /* Register value combine */ + u16 fan_min[14]; /* Register value combine */ + + u8 has_temp; /* Enable monitor temp6-1 or not */ + s8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */ + u8 temp_read_vrlsb[6]; + u8 temp_mode; /* Bit vector, 0 = TR, 1 = TD */ + u8 temp_src[3]; /* Register value */ + + u8 enable_dts; /* + * Enable PECI and SB-TSI, + * bit 0: =1 enable, =0 disable, + * bit 1: =1 AMD SB-TSI, =0 Intel PECI + */ + u8 has_dts; /* Enable monitor DTS temp */ + s8 dts[8]; /* Register value */ + u8 dts_read_vrlsb[8]; /* Register value */ + s8 dts_ext[4]; /* Register value */ + + u8 has_pwm; /* + * 795g supports 8 pwm, 795adg only supports 2, + * no config register, only affected by chip + * type + */ + u8 pwm[8][5]; /* + * Register value, output, freq, start, + * non stop, stop time + */ + u16 clkin; /* CLKIN frequency in kHz */ + u8 pwm_fcms[2]; /* Register value */ + u8 pwm_tfmr[6]; /* Register value */ + u8 pwm_fomc; /* Register value */ + + u16 target_speed[8]; /* + * Register value, target speed for speed + * cruise + */ + u8 tol_speed; /* tolerance of target speed */ + u8 pwm_temp[6][4]; /* TTTI, CTFS, HCT, HOT */ + u8 sf4_reg[6][2][7]; /* 6 temp, temp/dcpwm, 7 registers */ + + u8 setup_pwm[3]; /* Register value */ + + u8 alarms[6]; /* Register value */ + u8 enable_beep; + u8 beeps[6]; /* Register value */ + + char valid; + char valid_limits; + char valid_pwm_config; +}; + +/* + * Hardware access + * We assume that nobdody can change the bank outside the driver. + */ + +/* Must be called with data->update_lock held, except during initialization */ +static int w83795_set_bank(struct i2c_client *client, u8 bank) +{ + struct w83795_data *data = i2c_get_clientdata(client); + int err; + + /* If the same bank is already set, nothing to do */ + if ((data->bank & 0x07) == bank) + return 0; + + /* Change to new bank, preserve all other bits */ + bank |= data->bank & ~0x07; + err = i2c_smbus_write_byte_data(client, W83795_REG_BANKSEL, bank); + if (err < 0) { + dev_err(&client->dev, + "Failed to set bank to %d, err %d\n", + (int)bank, err); + return err; + } + data->bank = bank; + + return 0; +} + +/* Must be called with data->update_lock held, except during initialization */ +static u8 w83795_read(struct i2c_client *client, u16 reg) +{ + int err; + + err = w83795_set_bank(client, reg >> 8); + if (err < 0) + return 0x00; /* Arbitrary */ + + err = i2c_smbus_read_byte_data(client, reg & 0xff); + if (err < 0) { + dev_err(&client->dev, + "Failed to read from register 0x%03x, err %d\n", + (int)reg, err); + return 0x00; /* Arbitrary */ + } + return err; +} + +/* Must be called with data->update_lock held, except during initialization */ +static int w83795_write(struct i2c_client *client, u16 reg, u8 value) +{ + int err; + + err = w83795_set_bank(client, reg >> 8); + if (err < 0) + return err; + + err = i2c_smbus_write_byte_data(client, reg & 0xff, value); + if (err < 0) + dev_err(&client->dev, + "Failed to write to register 0x%03x, err %d\n", + (int)reg, err); + return err; +} + +static void w83795_update_limits(struct i2c_client *client) +{ + struct w83795_data *data = i2c_get_clientdata(client); + int i, limit; + u8 lsb; + + /* Read the voltage limits */ + for (i = 0; i < ARRAY_SIZE(data->in); i++) { + if (!(data->has_in & (1 << i))) + continue; + data->in[i][IN_MAX] = + w83795_read(client, W83795_REG_IN[i][IN_MAX]); + data->in[i][IN_LOW] = + w83795_read(client, W83795_REG_IN[i][IN_LOW]); + } + for (i = 0; i < ARRAY_SIZE(data->in_lsb); i++) { + if ((i == 2 && data->chip_type == w83795adg) || + (i >= 4 && !(data->has_in & (1 << (i + 11))))) + continue; + data->in_lsb[i][IN_MAX] = + w83795_read(client, IN_LSB_REG(i, IN_MAX)); + data->in_lsb[i][IN_LOW] = + w83795_read(client, IN_LSB_REG(i, IN_LOW)); + } + + /* Read the fan limits */ + lsb = 0; /* Silent false gcc warning */ + for (i = 0; i < ARRAY_SIZE(data->fan); i++) { + /* + * Each register contains LSB for 2 fans, but we want to + * read it only once to save time + */ + if ((i & 1) == 0 && (data->has_fan & (3 << i))) + lsb = w83795_read(client, W83795_REG_FAN_MIN_LSB(i)); + + if (!(data->has_fan & (1 << i))) + continue; + data->fan_min[i] = + w83795_read(client, W83795_REG_FAN_MIN_HL(i)) << 4; + data->fan_min[i] |= + (lsb >> W83795_REG_FAN_MIN_LSB_SHIFT(i)) & 0x0F; + } + + /* Read the temperature limits */ + for (i = 0; i < ARRAY_SIZE(data->temp); i++) { + if (!(data->has_temp & (1 << i))) + continue; + for (limit = TEMP_CRIT; limit <= TEMP_WARN_HYST; limit++) + data->temp[i][limit] = + w83795_read(client, W83795_REG_TEMP[i][limit]); + } + + /* Read the DTS limits */ + if (data->enable_dts) { + for (limit = DTS_CRIT; limit <= DTS_WARN_HYST; limit++) + data->dts_ext[limit] = + w83795_read(client, W83795_REG_DTS_EXT(limit)); + } + + /* Read beep settings */ + if (data->enable_beep) { + for (i = 0; i < ARRAY_SIZE(data->beeps); i++) + data->beeps[i] = + w83795_read(client, W83795_REG_BEEP(i)); + } + + data->valid_limits = 1; +} + +static struct w83795_data *w83795_update_pwm_config(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + int i, tmp; + + mutex_lock(&data->update_lock); + + if (data->valid_pwm_config) + goto END; + + /* Read temperature source selection */ + for (i = 0; i < ARRAY_SIZE(data->temp_src); i++) + data->temp_src[i] = w83795_read(client, W83795_REG_TSS(i)); + + /* Read automatic fan speed control settings */ + data->pwm_fcms[0] = w83795_read(client, W83795_REG_FCMS1); + data->pwm_fcms[1] = w83795_read(client, W83795_REG_FCMS2); + for (i = 0; i < ARRAY_SIZE(data->pwm_tfmr); i++) + data->pwm_tfmr[i] = w83795_read(client, W83795_REG_TFMR(i)); + data->pwm_fomc = w83795_read(client, W83795_REG_FOMC); + for (i = 0; i < data->has_pwm; i++) { + for (tmp = PWM_FREQ; tmp <= PWM_STOP_TIME; tmp++) + data->pwm[i][tmp] = + w83795_read(client, W83795_REG_PWM(i, tmp)); + } + for (i = 0; i < ARRAY_SIZE(data->target_speed); i++) { + data->target_speed[i] = + w83795_read(client, W83795_REG_FTSH(i)) << 4; + data->target_speed[i] |= + w83795_read(client, W83795_REG_FTSL(i)) >> 4; + } + data->tol_speed = w83795_read(client, W83795_REG_TFTS) & 0x3f; + + for (i = 0; i < ARRAY_SIZE(data->pwm_temp); i++) { + data->pwm_temp[i][TEMP_PWM_TTTI] = + w83795_read(client, W83795_REG_TTTI(i)) & 0x7f; + data->pwm_temp[i][TEMP_PWM_CTFS] = + w83795_read(client, W83795_REG_CTFS(i)); + tmp = w83795_read(client, W83795_REG_HT(i)); + data->pwm_temp[i][TEMP_PWM_HCT] = tmp >> 4; + data->pwm_temp[i][TEMP_PWM_HOT] = tmp & 0x0f; + } + + /* Read SmartFanIV trip points */ + for (i = 0; i < ARRAY_SIZE(data->sf4_reg); i++) { + for (tmp = 0; tmp < 7; tmp++) { + data->sf4_reg[i][SF4_TEMP][tmp] = + w83795_read(client, + W83795_REG_SF4_TEMP(i, tmp)); + data->sf4_reg[i][SF4_PWM][tmp] = + w83795_read(client, W83795_REG_SF4_PWM(i, tmp)); + } + } + + /* Read setup PWM */ + for (i = 0; i < ARRAY_SIZE(data->setup_pwm); i++) + data->setup_pwm[i] = + w83795_read(client, W83795_REG_SETUP_PWM(i)); + + data->valid_pwm_config = 1; + +END: + mutex_unlock(&data->update_lock); + return data; +} + +static struct w83795_data *w83795_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + u16 tmp; + u8 intrusion; + int i; + + mutex_lock(&data->update_lock); + + if (!data->valid_limits) + w83795_update_limits(client); + + if (!(time_after(jiffies, data->last_updated + HZ * 2) + || !data->valid)) + goto END; + + /* Update the voltages value */ + for (i = 0; i < ARRAY_SIZE(data->in); i++) { + if (!(data->has_in & (1 << i))) + continue; + tmp = w83795_read(client, W83795_REG_IN[i][IN_READ]) << 2; + tmp |= w83795_read(client, W83795_REG_VRLSB) >> 6; + data->in[i][IN_READ] = tmp; + } + + /* in0-2 can have dynamic limits (W83795G only) */ + if (data->has_dyn_in) { + u8 lsb_max = w83795_read(client, IN_LSB_REG(0, IN_MAX)); + u8 lsb_low = w83795_read(client, IN_LSB_REG(0, IN_LOW)); + + for (i = 0; i < 3; i++) { + if (!(data->has_dyn_in & (1 << i))) + continue; + data->in[i][IN_MAX] = + w83795_read(client, W83795_REG_IN[i][IN_MAX]); + data->in[i][IN_LOW] = + w83795_read(client, W83795_REG_IN[i][IN_LOW]); + data->in_lsb[i][IN_MAX] = (lsb_max >> (2 * i)) & 0x03; + data->in_lsb[i][IN_LOW] = (lsb_low >> (2 * i)) & 0x03; + } + } + + /* Update fan */ + for (i = 0; i < ARRAY_SIZE(data->fan); i++) { + if (!(data->has_fan & (1 << i))) + continue; + data->fan[i] = w83795_read(client, W83795_REG_FAN(i)) << 4; + data->fan[i] |= w83795_read(client, W83795_REG_VRLSB) >> 4; + } + + /* Update temperature */ + for (i = 0; i < ARRAY_SIZE(data->temp); i++) { + data->temp[i][TEMP_READ] = + w83795_read(client, W83795_REG_TEMP[i][TEMP_READ]); + data->temp_read_vrlsb[i] = + w83795_read(client, W83795_REG_VRLSB); + } + + /* Update dts temperature */ + if (data->enable_dts) { + for (i = 0; i < ARRAY_SIZE(data->dts); i++) { + if (!(data->has_dts & (1 << i))) + continue; + data->dts[i] = + w83795_read(client, W83795_REG_DTS(i)); + data->dts_read_vrlsb[i] = + w83795_read(client, W83795_REG_VRLSB); + } + } + + /* Update pwm output */ + for (i = 0; i < data->has_pwm; i++) { + data->pwm[i][PWM_OUTPUT] = + w83795_read(client, W83795_REG_PWM(i, PWM_OUTPUT)); + } + + /* + * Update intrusion and alarms + * It is important to read intrusion first, because reading from + * register SMI STS6 clears the interrupt status temporarily. + */ + tmp = w83795_read(client, W83795_REG_ALARM_CTRL); + /* Switch to interrupt status for intrusion if needed */ + if (tmp & ALARM_CTRL_RTSACS) + w83795_write(client, W83795_REG_ALARM_CTRL, + tmp & ~ALARM_CTRL_RTSACS); + intrusion = w83795_read(client, W83795_REG_ALARM(5)) & (1 << 6); + /* Switch to real-time alarms */ + w83795_write(client, W83795_REG_ALARM_CTRL, tmp | ALARM_CTRL_RTSACS); + for (i = 0; i < ARRAY_SIZE(data->alarms); i++) + data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i)); + data->alarms[5] |= intrusion; + /* Restore original configuration if needed */ + if (!(tmp & ALARM_CTRL_RTSACS)) + w83795_write(client, W83795_REG_ALARM_CTRL, + tmp & ~ALARM_CTRL_RTSACS); + + data->last_updated = jiffies; + data->valid = 1; + +END: + mutex_unlock(&data->update_lock); + return data; +} + +/* + * Sysfs attributes + */ + +#define ALARM_STATUS 0 +#define BEEP_ENABLE 1 +static ssize_t +show_alarm_beep(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83795_data *data = w83795_update_device(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index >> 3; + int bit = sensor_attr->index & 0x07; + u8 val; + + if (nr == ALARM_STATUS) + val = (data->alarms[index] >> bit) & 1; + else /* BEEP_ENABLE */ + val = (data->beeps[index] >> bit) & 1; + + return sprintf(buf, "%u\n", val); +} + +static ssize_t +store_beep(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index >> 3; + int shift = sensor_attr->index & 0x07; + u8 beep_bit = 1 << shift; + unsigned long val; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + if (val != 0 && val != 1) + return -EINVAL; + + mutex_lock(&data->update_lock); + data->beeps[index] = w83795_read(client, W83795_REG_BEEP(index)); + data->beeps[index] &= ~beep_bit; + data->beeps[index] |= val << shift; + w83795_write(client, W83795_REG_BEEP(index), data->beeps[index]); + mutex_unlock(&data->update_lock); + + return count; +} + +/* Write 0 to clear chassis alarm */ +static ssize_t +store_chassis_clear(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + unsigned long val; + + if (kstrtoul(buf, 10, &val) < 0 || val != 0) + return -EINVAL; + + mutex_lock(&data->update_lock); + val = w83795_read(client, W83795_REG_CLR_CHASSIS); + val |= 0x80; + w83795_write(client, W83795_REG_CLR_CHASSIS, val); + + /* Clear status and force cache refresh */ + w83795_read(client, W83795_REG_ALARM(5)); + data->valid = 0; + mutex_unlock(&data->update_lock); + return count; +} + +#define FAN_INPUT 0 +#define FAN_MIN 1 +static ssize_t +show_fan(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + struct w83795_data *data = w83795_update_device(dev); + u16 val; + + if (nr == FAN_INPUT) + val = data->fan[index] & 0x0fff; + else + val = data->fan_min[index] & 0x0fff; + + return sprintf(buf, "%lu\n", fan_from_reg(val)); +} + +static ssize_t +store_fan_min(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index; + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + unsigned long val; + + if (kstrtoul(buf, 10, &val)) + return -EINVAL; + val = fan_to_reg(val); + + mutex_lock(&data->update_lock); + data->fan_min[index] = val; + w83795_write(client, W83795_REG_FAN_MIN_HL(index), (val >> 4) & 0xff); + val &= 0x0f; + if (index & 1) { + val <<= 4; + val |= w83795_read(client, W83795_REG_FAN_MIN_LSB(index)) + & 0x0f; + } else { + val |= w83795_read(client, W83795_REG_FAN_MIN_LSB(index)) + & 0xf0; + } + w83795_write(client, W83795_REG_FAN_MIN_LSB(index), val & 0xff); + mutex_unlock(&data->update_lock); + + return count; +} + +static ssize_t +show_pwm(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83795_data *data; + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + unsigned int val; + + data = nr == PWM_OUTPUT ? w83795_update_device(dev) + : w83795_update_pwm_config(dev); + + switch (nr) { + case PWM_STOP_TIME: + val = time_from_reg(data->pwm[index][nr]); + break; + case PWM_FREQ: + val = pwm_freq_from_reg(data->pwm[index][nr], data->clkin); + break; + default: + val = data->pwm[index][nr]; + break; + } + + return sprintf(buf, "%u\n", val); +} + +static ssize_t +store_pwm(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + unsigned long val; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + + mutex_lock(&data->update_lock); + switch (nr) { + case PWM_STOP_TIME: + val = time_to_reg(val); + break; + case PWM_FREQ: + val = pwm_freq_to_reg(val, data->clkin); + break; + default: + val = clamp_val(val, 0, 0xff); + break; + } + w83795_write(client, W83795_REG_PWM(index, nr), val); + data->pwm[index][nr] = val; + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t +show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + struct w83795_data *data = w83795_update_pwm_config(dev); + int index = sensor_attr->index; + u8 tmp; + + /* Speed cruise mode */ + if (data->pwm_fcms[0] & (1 << index)) { + tmp = 2; + goto out; + } + /* Thermal cruise or SmartFan IV mode */ + for (tmp = 0; tmp < 6; tmp++) { + if (data->pwm_tfmr[tmp] & (1 << index)) { + tmp = 3; + goto out; + } + } + /* Manual mode */ + tmp = 1; + +out: + return sprintf(buf, "%u\n", tmp); +} + +static ssize_t +store_pwm_enable(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = w83795_update_pwm_config(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index; + unsigned long val; + int i; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + if (val < 1 || val > 2) + return -EINVAL; + +#ifndef CONFIG_SENSORS_W83795_FANCTRL + if (val > 1) { + dev_warn(dev, "Automatic fan speed control support disabled\n"); + dev_warn(dev, "Build with CONFIG_SENSORS_W83795_FANCTRL=y if you want it\n"); + return -EOPNOTSUPP; + } +#endif + + mutex_lock(&data->update_lock); + switch (val) { + case 1: + /* Clear speed cruise mode bits */ + data->pwm_fcms[0] &= ~(1 << index); + w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]); + /* Clear thermal cruise mode bits */ + for (i = 0; i < 6; i++) { + data->pwm_tfmr[i] &= ~(1 << index); + w83795_write(client, W83795_REG_TFMR(i), + data->pwm_tfmr[i]); + } + break; + case 2: + data->pwm_fcms[0] |= (1 << index); + w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]); + break; + } + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t +show_pwm_mode(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83795_data *data = w83795_update_pwm_config(dev); + int index = to_sensor_dev_attr_2(attr)->index; + unsigned int mode; + + if (data->pwm_fomc & (1 << index)) + mode = 0; /* DC */ + else + mode = 1; /* PWM */ + + return sprintf(buf, "%u\n", mode); +} + +/* + * Check whether a given temperature source can ever be useful. + * Returns the number of selectable temperature channels which are + * enabled. + */ +static int w83795_tss_useful(const struct w83795_data *data, int tsrc) +{ + int useful = 0, i; + + for (i = 0; i < 4; i++) { + if (tss_map[i][tsrc] == TSS_MAP_RESERVED) + continue; + if (tss_map[i][tsrc] < 6) /* Analog */ + useful += (data->has_temp >> tss_map[i][tsrc]) & 1; + else /* Digital */ + useful += (data->has_dts >> (tss_map[i][tsrc] - 6)) & 1; + } + + return useful; +} + +static ssize_t +show_temp_src(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + struct w83795_data *data = w83795_update_pwm_config(dev); + int index = sensor_attr->index; + u8 tmp = data->temp_src[index / 2]; + + if (index & 1) + tmp >>= 4; /* Pick high nibble */ + else + tmp &= 0x0f; /* Pick low nibble */ + + /* Look-up the actual temperature channel number */ + if (tmp >= 4 || tss_map[tmp][index] == TSS_MAP_RESERVED) + return -EINVAL; /* Shouldn't happen */ + + return sprintf(buf, "%u\n", (unsigned int)tss_map[tmp][index] + 1); +} + +static ssize_t +store_temp_src(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = w83795_update_pwm_config(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index; + int tmp; + unsigned long channel; + u8 val = index / 2; + + if (kstrtoul(buf, 10, &channel) < 0 || + channel < 1 || channel > 14) + return -EINVAL; + + /* Check if request can be fulfilled */ + for (tmp = 0; tmp < 4; tmp++) { + if (tss_map[tmp][index] == channel - 1) + break; + } + if (tmp == 4) /* No match */ + return -EINVAL; + + mutex_lock(&data->update_lock); + if (index & 1) { + tmp <<= 4; + data->temp_src[val] &= 0x0f; + } else { + data->temp_src[val] &= 0xf0; + } + data->temp_src[val] |= tmp; + w83795_write(client, W83795_REG_TSS(val), data->temp_src[val]); + mutex_unlock(&data->update_lock); + + return count; +} + +#define TEMP_PWM_ENABLE 0 +#define TEMP_PWM_FAN_MAP 1 +static ssize_t +show_temp_pwm_enable(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct w83795_data *data = w83795_update_pwm_config(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + u8 tmp = 0xff; + + switch (nr) { + case TEMP_PWM_ENABLE: + tmp = (data->pwm_fcms[1] >> index) & 1; + if (tmp) + tmp = 4; + else + tmp = 3; + break; + case TEMP_PWM_FAN_MAP: + tmp = data->pwm_tfmr[index]; + break; + } + + return sprintf(buf, "%u\n", tmp); +} + +static ssize_t +store_temp_pwm_enable(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = w83795_update_pwm_config(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + unsigned long tmp; + + if (kstrtoul(buf, 10, &tmp) < 0) + return -EINVAL; + + switch (nr) { + case TEMP_PWM_ENABLE: + if (tmp != 3 && tmp != 4) + return -EINVAL; + tmp -= 3; + mutex_lock(&data->update_lock); + data->pwm_fcms[1] &= ~(1 << index); + data->pwm_fcms[1] |= tmp << index; + w83795_write(client, W83795_REG_FCMS2, data->pwm_fcms[1]); + mutex_unlock(&data->update_lock); + break; + case TEMP_PWM_FAN_MAP: + mutex_lock(&data->update_lock); + tmp = clamp_val(tmp, 0, 0xff); + w83795_write(client, W83795_REG_TFMR(index), tmp); + data->pwm_tfmr[index] = tmp; + mutex_unlock(&data->update_lock); + break; + } + return count; +} + +#define FANIN_TARGET 0 +#define FANIN_TOL 1 +static ssize_t +show_fanin(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83795_data *data = w83795_update_pwm_config(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + u16 tmp = 0; + + switch (nr) { + case FANIN_TARGET: + tmp = fan_from_reg(data->target_speed[index]); + break; + case FANIN_TOL: + tmp = data->tol_speed; + break; + } + + return sprintf(buf, "%u\n", tmp); +} + +static ssize_t +store_fanin(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + unsigned long val; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + + mutex_lock(&data->update_lock); + switch (nr) { + case FANIN_TARGET: + val = fan_to_reg(clamp_val(val, 0, 0xfff)); + w83795_write(client, W83795_REG_FTSH(index), val >> 4); + w83795_write(client, W83795_REG_FTSL(index), (val << 4) & 0xf0); + data->target_speed[index] = val; + break; + case FANIN_TOL: + val = clamp_val(val, 0, 0x3f); + w83795_write(client, W83795_REG_TFTS, val); + data->tol_speed = val; + break; + } + mutex_unlock(&data->update_lock); + + return count; +} + + +static ssize_t +show_temp_pwm(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83795_data *data = w83795_update_pwm_config(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + long tmp = temp_from_reg(data->pwm_temp[index][nr]); + + return sprintf(buf, "%ld\n", tmp); +} + +static ssize_t +store_temp_pwm(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + unsigned long val; + u8 tmp; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + val /= 1000; + + mutex_lock(&data->update_lock); + switch (nr) { + case TEMP_PWM_TTTI: + val = clamp_val(val, 0, 0x7f); + w83795_write(client, W83795_REG_TTTI(index), val); + break; + case TEMP_PWM_CTFS: + val = clamp_val(val, 0, 0x7f); + w83795_write(client, W83795_REG_CTFS(index), val); + break; + case TEMP_PWM_HCT: + val = clamp_val(val, 0, 0x0f); + tmp = w83795_read(client, W83795_REG_HT(index)); + tmp &= 0x0f; + tmp |= (val << 4) & 0xf0; + w83795_write(client, W83795_REG_HT(index), tmp); + break; + case TEMP_PWM_HOT: + val = clamp_val(val, 0, 0x0f); + tmp = w83795_read(client, W83795_REG_HT(index)); + tmp &= 0xf0; + tmp |= val & 0x0f; + w83795_write(client, W83795_REG_HT(index), tmp); + break; + } + data->pwm_temp[index][nr] = val; + mutex_unlock(&data->update_lock); + + return count; +} + +static ssize_t +show_sf4_pwm(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83795_data *data = w83795_update_pwm_config(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + + return sprintf(buf, "%u\n", data->sf4_reg[index][SF4_PWM][nr]); +} + +static ssize_t +store_sf4_pwm(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + unsigned long val; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + + mutex_lock(&data->update_lock); + w83795_write(client, W83795_REG_SF4_PWM(index, nr), val); + data->sf4_reg[index][SF4_PWM][nr] = val; + mutex_unlock(&data->update_lock); + + return count; +} + +static ssize_t +show_sf4_temp(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83795_data *data = w83795_update_pwm_config(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + + return sprintf(buf, "%u\n", + (data->sf4_reg[index][SF4_TEMP][nr]) * 1000); +} + +static ssize_t +store_sf4_temp(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + unsigned long val; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + val /= 1000; + + mutex_lock(&data->update_lock); + w83795_write(client, W83795_REG_SF4_TEMP(index, nr), val); + data->sf4_reg[index][SF4_TEMP][nr] = val; + mutex_unlock(&data->update_lock); + + return count; +} + + +static ssize_t +show_temp(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + struct w83795_data *data = w83795_update_device(dev); + long temp = temp_from_reg(data->temp[index][nr]); + + if (nr == TEMP_READ) + temp += (data->temp_read_vrlsb[index] >> 6) * 250; + return sprintf(buf, "%ld\n", temp); +} + +static ssize_t +store_temp(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + long tmp; + + if (kstrtol(buf, 10, &tmp) < 0) + return -EINVAL; + + mutex_lock(&data->update_lock); + data->temp[index][nr] = temp_to_reg(tmp, -128, 127); + w83795_write(client, W83795_REG_TEMP[index][nr], data->temp[index][nr]); + mutex_unlock(&data->update_lock); + return count; +} + + +static ssize_t +show_dts_mode(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83795_data *data = dev_get_drvdata(dev); + int tmp; + + if (data->enable_dts & 2) + tmp = 5; + else + tmp = 6; + + return sprintf(buf, "%d\n", tmp); +} + +static ssize_t +show_dts(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index; + struct w83795_data *data = w83795_update_device(dev); + long temp = temp_from_reg(data->dts[index]); + + temp += (data->dts_read_vrlsb[index] >> 6) * 250; + return sprintf(buf, "%ld\n", temp); +} + +static ssize_t +show_dts_ext(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + struct w83795_data *data = dev_get_drvdata(dev); + long temp = temp_from_reg(data->dts_ext[nr]); + + return sprintf(buf, "%ld\n", temp); +} + +static ssize_t +store_dts_ext(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + long tmp; + + if (kstrtol(buf, 10, &tmp) < 0) + return -EINVAL; + + mutex_lock(&data->update_lock); + data->dts_ext[nr] = temp_to_reg(tmp, -128, 127); + w83795_write(client, W83795_REG_DTS_EXT(nr), data->dts_ext[nr]); + mutex_unlock(&data->update_lock); + return count; +} + + +static ssize_t +show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w83795_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index; + int tmp; + + if (data->temp_mode & (1 << index)) + tmp = 3; /* Thermal diode */ + else + tmp = 4; /* Thermistor */ + + return sprintf(buf, "%d\n", tmp); +} + +/* Only for temp1-4 (temp5-6 can only be thermistor) */ +static ssize_t +store_temp_mode(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int index = sensor_attr->index; + int reg_shift; + unsigned long val; + u8 tmp; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + if ((val != 4) && (val != 3)) + return -EINVAL; + + mutex_lock(&data->update_lock); + if (val == 3) { + /* Thermal diode */ + val = 0x01; + data->temp_mode |= 1 << index; + } else if (val == 4) { + /* Thermistor */ + val = 0x03; + data->temp_mode &= ~(1 << index); + } + + reg_shift = 2 * index; + tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); + tmp &= ~(0x03 << reg_shift); + tmp |= val << reg_shift; + w83795_write(client, W83795_REG_TEMP_CTRL2, tmp); + + mutex_unlock(&data->update_lock); + return count; +} + + +/* show/store VIN */ +static ssize_t +show_in(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + struct w83795_data *data = w83795_update_device(dev); + u16 val = data->in[index][nr]; + u8 lsb_idx; + + switch (nr) { + case IN_READ: + /* calculate this value again by sensors as sensors3.conf */ + if ((index >= 17) && + !((data->has_gain >> (index - 17)) & 1)) + val *= 8; + break; + case IN_MAX: + case IN_LOW: + lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX]; + val <<= 2; + val |= (data->in_lsb[lsb_idx][nr] >> + IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]) & 0x03; + if ((index >= 17) && + !((data->has_gain >> (index - 17)) & 1)) + val *= 8; + break; + } + val = in_from_reg(index, val); + + return sprintf(buf, "%d\n", val); +} + +static ssize_t +store_in(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + int index = sensor_attr->index; + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + unsigned long val; + u8 tmp; + u8 lsb_idx; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + val = in_to_reg(index, val); + + if ((index >= 17) && + !((data->has_gain >> (index - 17)) & 1)) + val /= 8; + val = clamp_val(val, 0, 0x3FF); + mutex_lock(&data->update_lock); + + lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX]; + tmp = w83795_read(client, IN_LSB_REG(lsb_idx, nr)); + tmp &= ~(0x03 << IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]); + tmp |= (val & 0x03) << IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]; + w83795_write(client, IN_LSB_REG(lsb_idx, nr), tmp); + data->in_lsb[lsb_idx][nr] = tmp; + + tmp = (val >> 2) & 0xff; + w83795_write(client, W83795_REG_IN[index][nr], tmp); + data->in[index][nr] = tmp; + + mutex_unlock(&data->update_lock); + return count; +} + + +#ifdef CONFIG_SENSORS_W83795_FANCTRL +static ssize_t +show_sf_setup(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + struct w83795_data *data = w83795_update_pwm_config(dev); + u16 val = data->setup_pwm[nr]; + + switch (nr) { + case SETUP_PWM_UPTIME: + case SETUP_PWM_DOWNTIME: + val = time_from_reg(val); + break; + } + + return sprintf(buf, "%d\n", val); +} + +static ssize_t +store_sf_setup(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute_2 *sensor_attr = + to_sensor_dev_attr_2(attr); + int nr = sensor_attr->nr; + struct i2c_client *client = to_i2c_client(dev); + struct w83795_data *data = i2c_get_clientdata(client); + unsigned long val; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + + switch (nr) { + case SETUP_PWM_DEFAULT: + val = clamp_val(val, 0, 0xff); + break; + case SETUP_PWM_UPTIME: + case SETUP_PWM_DOWNTIME: + val = time_to_reg(val); + if (val == 0) + return -EINVAL; + break; + } + + mutex_lock(&data->update_lock); + data->setup_pwm[nr] = val; + w83795_write(client, W83795_REG_SETUP_PWM(nr), val); + mutex_unlock(&data->update_lock); + return count; +} +#endif + + +#define NOT_USED -1 + +/* + * Don't change the attribute order, _max, _min and _beep are accessed by index + * somewhere else in the code + */ +#define SENSOR_ATTR_IN(index) { \ + SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \ + IN_READ, index), \ + SENSOR_ATTR_2(in##index##_max, S_IRUGO | S_IWUSR, show_in, \ + store_in, IN_MAX, index), \ + SENSOR_ATTR_2(in##index##_min, S_IRUGO | S_IWUSR, show_in, \ + store_in, IN_LOW, index), \ + SENSOR_ATTR_2(in##index##_alarm, S_IRUGO, show_alarm_beep, \ + NULL, ALARM_STATUS, index + ((index > 14) ? 1 : 0)), \ + SENSOR_ATTR_2(in##index##_beep, S_IWUSR | S_IRUGO, \ + show_alarm_beep, store_beep, BEEP_ENABLE, \ + index + ((index > 14) ? 1 : 0)) } + +/* + * Don't change the attribute order, _beep is accessed by index + * somewhere else in the code + */ +#define SENSOR_ATTR_FAN(index) { \ + SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \ + NULL, FAN_INPUT, index - 1), \ + SENSOR_ATTR_2(fan##index##_min, S_IWUSR | S_IRUGO, \ + show_fan, store_fan_min, FAN_MIN, index - 1), \ + SENSOR_ATTR_2(fan##index##_alarm, S_IRUGO, show_alarm_beep, \ + NULL, ALARM_STATUS, index + 31), \ + SENSOR_ATTR_2(fan##index##_beep, S_IWUSR | S_IRUGO, \ + show_alarm_beep, store_beep, BEEP_ENABLE, index + 31) } + +#define SENSOR_ATTR_PWM(index) { \ + SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm, \ + store_pwm, PWM_OUTPUT, index - 1), \ + SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \ + show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \ + SENSOR_ATTR_2(pwm##index##_mode, S_IRUGO, \ + show_pwm_mode, NULL, NOT_USED, index - 1), \ + SENSOR_ATTR_2(pwm##index##_freq, S_IWUSR | S_IRUGO, \ + show_pwm, store_pwm, PWM_FREQ, index - 1), \ + SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO, \ + show_pwm, store_pwm, PWM_NONSTOP, index - 1), \ + SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO, \ + show_pwm, store_pwm, PWM_START, index - 1), \ + SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO, \ + show_pwm, store_pwm, PWM_STOP_TIME, index - 1), \ + SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \ + show_fanin, store_fanin, FANIN_TARGET, index - 1) } + +/* + * Don't change the attribute order, _beep is accessed by index + * somewhere else in the code + */ +#define SENSOR_ATTR_DTS(index) { \ + SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \ + show_dts_mode, NULL, NOT_USED, index - 7), \ + SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_dts, \ + NULL, NOT_USED, index - 7), \ + SENSOR_ATTR_2(temp##index##_crit, S_IRUGO | S_IWUSR, show_dts_ext, \ + store_dts_ext, DTS_CRIT, NOT_USED), \ + SENSOR_ATTR_2(temp##index##_crit_hyst, S_IRUGO | S_IWUSR, \ + show_dts_ext, store_dts_ext, DTS_CRIT_HYST, NOT_USED), \ + SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_dts_ext, \ + store_dts_ext, DTS_WARN, NOT_USED), \ + SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \ + show_dts_ext, store_dts_ext, DTS_WARN_HYST, NOT_USED), \ + SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \ + show_alarm_beep, NULL, ALARM_STATUS, index + 17), \ + SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ + show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } + +/* + * Don't change the attribute order, _beep is accessed by index + * somewhere else in the code + */ +#define SENSOR_ATTR_TEMP(index) { \ + SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \ + show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ + SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \ + NULL, TEMP_READ, index - 1), \ + SENSOR_ATTR_2(temp##index##_crit, S_IRUGO | S_IWUSR, show_temp, \ + store_temp, TEMP_CRIT, index - 1), \ + SENSOR_ATTR_2(temp##index##_crit_hyst, S_IRUGO | S_IWUSR, \ + show_temp, store_temp, TEMP_CRIT_HYST, index - 1), \ + SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_temp, \ + store_temp, TEMP_WARN, index - 1), \ + SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \ + show_temp, store_temp, TEMP_WARN_HYST, index - 1), \ + SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \ + show_alarm_beep, NULL, ALARM_STATUS, \ + index + (index > 4 ? 11 : 17)), \ + SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ + show_alarm_beep, store_beep, BEEP_ENABLE, \ + index + (index > 4 ? 11 : 17)), \ + SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ + show_temp_pwm_enable, store_temp_pwm_enable, \ + TEMP_PWM_ENABLE, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_channels_pwm, S_IWUSR | S_IRUGO, \ + show_temp_pwm_enable, store_temp_pwm_enable, \ + TEMP_PWM_FAN_MAP, index - 1), \ + SENSOR_ATTR_2(thermal_cruise##index, S_IWUSR | S_IRUGO, \ + show_temp_pwm, store_temp_pwm, TEMP_PWM_TTTI, index - 1), \ + SENSOR_ATTR_2(temp##index##_warn, S_IWUSR | S_IRUGO, \ + show_temp_pwm, store_temp_pwm, TEMP_PWM_CTFS, index - 1), \ + SENSOR_ATTR_2(temp##index##_warn_hyst, S_IWUSR | S_IRUGO, \ + show_temp_pwm, store_temp_pwm, TEMP_PWM_HCT, index - 1), \ + SENSOR_ATTR_2(temp##index##_operation_hyst, S_IWUSR | S_IRUGO, \ + show_temp_pwm, store_temp_pwm, TEMP_PWM_HOT, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point1_pwm, S_IRUGO | S_IWUSR, \ + show_sf4_pwm, store_sf4_pwm, 0, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point2_pwm, S_IRUGO | S_IWUSR, \ + show_sf4_pwm, store_sf4_pwm, 1, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point3_pwm, S_IRUGO | S_IWUSR, \ + show_sf4_pwm, store_sf4_pwm, 2, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point4_pwm, S_IRUGO | S_IWUSR, \ + show_sf4_pwm, store_sf4_pwm, 3, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point5_pwm, S_IRUGO | S_IWUSR, \ + show_sf4_pwm, store_sf4_pwm, 4, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point6_pwm, S_IRUGO | S_IWUSR, \ + show_sf4_pwm, store_sf4_pwm, 5, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point7_pwm, S_IRUGO | S_IWUSR, \ + show_sf4_pwm, store_sf4_pwm, 6, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point1_temp, S_IRUGO | S_IWUSR,\ + show_sf4_temp, store_sf4_temp, 0, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point2_temp, S_IRUGO | S_IWUSR,\ + show_sf4_temp, store_sf4_temp, 1, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point3_temp, S_IRUGO | S_IWUSR,\ + show_sf4_temp, store_sf4_temp, 2, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point4_temp, S_IRUGO | S_IWUSR,\ + show_sf4_temp, store_sf4_temp, 3, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point5_temp, S_IRUGO | S_IWUSR,\ + show_sf4_temp, store_sf4_temp, 4, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point6_temp, S_IRUGO | S_IWUSR,\ + show_sf4_temp, store_sf4_temp, 5, index - 1), \ + SENSOR_ATTR_2(temp##index##_auto_point7_temp, S_IRUGO | S_IWUSR,\ + show_sf4_temp, store_sf4_temp, 6, index - 1) } + + +static struct sensor_device_attribute_2 w83795_in[][5] = { + SENSOR_ATTR_IN(0), + SENSOR_ATTR_IN(1), + SENSOR_ATTR_IN(2), + SENSOR_ATTR_IN(3), + SENSOR_ATTR_IN(4), + SENSOR_ATTR_IN(5), + SENSOR_ATTR_IN(6), + SENSOR_ATTR_IN(7), + SENSOR_ATTR_IN(8), + SENSOR_ATTR_IN(9), + SENSOR_ATTR_IN(10), + SENSOR_ATTR_IN(11), + SENSOR_ATTR_IN(12), + SENSOR_ATTR_IN(13), + SENSOR_ATTR_IN(14), + SENSOR_ATTR_IN(15), + SENSOR_ATTR_IN(16), + SENSOR_ATTR_IN(17), + SENSOR_ATTR_IN(18), + SENSOR_ATTR_IN(19), + SENSOR_ATTR_IN(20), +}; + +static const struct sensor_device_attribute_2 w83795_fan[][4] = { + SENSOR_ATTR_FAN(1), + SENSOR_ATTR_FAN(2), + SENSOR_ATTR_FAN(3), + SENSOR_ATTR_FAN(4), + SENSOR_ATTR_FAN(5), + SENSOR_ATTR_FAN(6), + SENSOR_ATTR_FAN(7), + SENSOR_ATTR_FAN(8), + SENSOR_ATTR_FAN(9), + SENSOR_ATTR_FAN(10), + SENSOR_ATTR_FAN(11), + SENSOR_ATTR_FAN(12), + SENSOR_ATTR_FAN(13), + SENSOR_ATTR_FAN(14), +}; + +static const struct sensor_device_attribute_2 w83795_temp[][28] = { + SENSOR_ATTR_TEMP(1), + SENSOR_ATTR_TEMP(2), + SENSOR_ATTR_TEMP(3), + SENSOR_ATTR_TEMP(4), + SENSOR_ATTR_TEMP(5), + SENSOR_ATTR_TEMP(6), +}; + +static const struct sensor_device_attribute_2 w83795_dts[][8] = { + SENSOR_ATTR_DTS(7), + SENSOR_ATTR_DTS(8), + SENSOR_ATTR_DTS(9), + SENSOR_ATTR_DTS(10), + SENSOR_ATTR_DTS(11), + SENSOR_ATTR_DTS(12), + SENSOR_ATTR_DTS(13), + SENSOR_ATTR_DTS(14), +}; + +static const struct sensor_device_attribute_2 w83795_pwm[][8] = { + SENSOR_ATTR_PWM(1), + SENSOR_ATTR_PWM(2), + SENSOR_ATTR_PWM(3), + SENSOR_ATTR_PWM(4), + SENSOR_ATTR_PWM(5), + SENSOR_ATTR_PWM(6), + SENSOR_ATTR_PWM(7), + SENSOR_ATTR_PWM(8), +}; + +static const struct sensor_device_attribute_2 w83795_tss[6] = { + SENSOR_ATTR_2(temp1_source_sel, S_IWUSR | S_IRUGO, + show_temp_src, store_temp_src, NOT_USED, 0), + SENSOR_ATTR_2(temp2_source_sel, S_IWUSR | S_IRUGO, + show_temp_src, store_temp_src, NOT_USED, 1), + SENSOR_ATTR_2(temp3_source_sel, S_IWUSR | S_IRUGO, + show_temp_src, store_temp_src, NOT_USED, 2), + SENSOR_ATTR_2(temp4_source_sel, S_IWUSR | S_IRUGO, + show_temp_src, store_temp_src, NOT_USED, 3), + SENSOR_ATTR_2(temp5_source_sel, S_IWUSR | S_IRUGO, + show_temp_src, store_temp_src, NOT_USED, 4), + SENSOR_ATTR_2(temp6_source_sel, S_IWUSR | S_IRUGO, + show_temp_src, store_temp_src, NOT_USED, 5), +}; + +static const struct sensor_device_attribute_2 sda_single_files[] = { + SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep, + store_chassis_clear, ALARM_STATUS, 46), +#ifdef CONFIG_SENSORS_W83795_FANCTRL + SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin, + store_fanin, FANIN_TOL, NOT_USED), + SENSOR_ATTR_2(pwm_default, S_IWUSR | S_IRUGO, show_sf_setup, + store_sf_setup, SETUP_PWM_DEFAULT, NOT_USED), + SENSOR_ATTR_2(pwm_uptime, S_IWUSR | S_IRUGO, show_sf_setup, + store_sf_setup, SETUP_PWM_UPTIME, NOT_USED), + SENSOR_ATTR_2(pwm_downtime, S_IWUSR | S_IRUGO, show_sf_setup, + store_sf_setup, SETUP_PWM_DOWNTIME, NOT_USED), +#endif +}; + +static const struct sensor_device_attribute_2 sda_beep_files[] = { + SENSOR_ATTR_2(intrusion0_beep, S_IWUSR | S_IRUGO, show_alarm_beep, + store_beep, BEEP_ENABLE, 46), + SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep, + store_beep, BEEP_ENABLE, 47), +}; + +/* + * Driver interface + */ + +static void w83795_init_client(struct i2c_client *client) +{ + struct w83795_data *data = i2c_get_clientdata(client); + static const u16 clkin[4] = { /* in kHz */ + 14318, 24000, 33333, 48000 + }; + u8 config; + + if (reset) + w83795_write(client, W83795_REG_CONFIG, 0x80); + + /* Start monitoring if needed */ + config = w83795_read(client, W83795_REG_CONFIG); + if (!(config & W83795_REG_CONFIG_START)) { + dev_info(&client->dev, "Enabling monitoring operations\n"); + w83795_write(client, W83795_REG_CONFIG, + config | W83795_REG_CONFIG_START); + } + + data->clkin = clkin[(config >> 3) & 0x3]; + dev_dbg(&client->dev, "clkin = %u kHz\n", data->clkin); +} + +static int w83795_get_device_id(struct i2c_client *client) +{ + int device_id; + + device_id = i2c_smbus_read_byte_data(client, W83795_REG_DEVICEID); + + /* + * Special case for rev. A chips; can't be checked first because later + * revisions emulate this for compatibility + */ + if (device_id < 0 || (device_id & 0xf0) != 0x50) { + int alt_id; + + alt_id = i2c_smbus_read_byte_data(client, + W83795_REG_DEVICEID_A); + if (alt_id == 0x50) + device_id = alt_id; + } + + return device_id; +} + +/* Return 0 if detection is successful, -ENODEV otherwise */ +static int w83795_detect(struct i2c_client *client, + struct i2c_board_info *info) +{ + int bank, vendor_id, device_id, expected, i2c_addr, config; + struct i2c_adapter *adapter = client->adapter; + unsigned short address = client->addr; + const char *chip_name; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + return -ENODEV; + bank = i2c_smbus_read_byte_data(client, W83795_REG_BANKSEL); + if (bank < 0 || (bank & 0x7c)) { + dev_dbg(&adapter->dev, + "w83795: Detection failed at addr 0x%02hx, check %s\n", + address, "bank"); + return -ENODEV; + } + + /* Check Nuvoton vendor ID */ + vendor_id = i2c_smbus_read_byte_data(client, W83795_REG_VENDORID); + expected = bank & 0x80 ? 0x5c : 0xa3; + if (vendor_id != expected) { + dev_dbg(&adapter->dev, + "w83795: Detection failed at addr 0x%02hx, check %s\n", + address, "vendor id"); + return -ENODEV; + } + + /* Check device ID */ + device_id = w83795_get_device_id(client) | + (i2c_smbus_read_byte_data(client, W83795_REG_CHIPID) << 8); + if ((device_id >> 4) != 0x795) { + dev_dbg(&adapter->dev, + "w83795: Detection failed at addr 0x%02hx, check %s\n", + address, "device id\n"); + return -ENODEV; + } + + /* + * If Nuvoton chip, address of chip and W83795_REG_I2C_ADDR + * should match + */ + if ((bank & 0x07) == 0) { + i2c_addr = i2c_smbus_read_byte_data(client, + W83795_REG_I2C_ADDR); + if ((i2c_addr & 0x7f) != address) { + dev_dbg(&adapter->dev, + "w83795: Detection failed at addr 0x%02hx, " + "check %s\n", address, "i2c addr"); + return -ENODEV; + } + } + + /* + * Check 795 chip type: 795G or 795ADG + * Usually we don't write to chips during detection, but here we don't + * quite have the choice; hopefully it's OK, we are about to return + * success anyway + */ + if ((bank & 0x07) != 0) + i2c_smbus_write_byte_data(client, W83795_REG_BANKSEL, + bank & ~0x07); + config = i2c_smbus_read_byte_data(client, W83795_REG_CONFIG); + if (config & W83795_REG_CONFIG_CONFIG48) + chip_name = "w83795adg"; + else + chip_name = "w83795g"; + + strlcpy(info->type, chip_name, I2C_NAME_SIZE); + dev_info(&adapter->dev, "Found %s rev. %c at 0x%02hx\n", chip_name, + 'A' + (device_id & 0xf), address); + + return 0; +} + +#ifdef CONFIG_SENSORS_W83795_FANCTRL +#define NUM_PWM_ATTRIBUTES ARRAY_SIZE(w83795_pwm[0]) +#define NUM_TEMP_ATTRIBUTES ARRAY_SIZE(w83795_temp[0]) +#else +#define NUM_PWM_ATTRIBUTES 4 +#define NUM_TEMP_ATTRIBUTES 8 +#endif + +static int w83795_handle_files(struct device *dev, int (*fn)(struct device *, + const struct device_attribute *)) +{ + struct w83795_data *data = dev_get_drvdata(dev); + int err, i, j; + + for (i = 0; i < ARRAY_SIZE(w83795_in); i++) { + if (!(data->has_in & (1 << i))) + continue; + for (j = 0; j < ARRAY_SIZE(w83795_in[0]); j++) { + if (j == 4 && !data->enable_beep) + continue; + err = fn(dev, &w83795_in[i][j].dev_attr); + if (err) + return err; + } + } + + for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) { + if (!(data->has_fan & (1 << i))) + continue; + for (j = 0; j < ARRAY_SIZE(w83795_fan[0]); j++) { + if (j == 3 && !data->enable_beep) + continue; + err = fn(dev, &w83795_fan[i][j].dev_attr); + if (err) + return err; + } + } + + for (i = 0; i < ARRAY_SIZE(w83795_tss); i++) { + j = w83795_tss_useful(data, i); + if (!j) + continue; + err = fn(dev, &w83795_tss[i].dev_attr); + if (err) + return err; + } + + for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { + err = fn(dev, &sda_single_files[i].dev_attr); + if (err) + return err; + } + + if (data->enable_beep) { + for (i = 0; i < ARRAY_SIZE(sda_beep_files); i++) { + err = fn(dev, &sda_beep_files[i].dev_attr); + if (err) + return err; + } + } + + for (i = 0; i < data->has_pwm; i++) { + for (j = 0; j < NUM_PWM_ATTRIBUTES; j++) { + err = fn(dev, &w83795_pwm[i][j].dev_attr); + if (err) + return err; + } + } + + for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) { + if (!(data->has_temp & (1 << i))) + continue; + for (j = 0; j < NUM_TEMP_ATTRIBUTES; j++) { + if (j == 7 && !data->enable_beep) + continue; + err = fn(dev, &w83795_temp[i][j].dev_attr); + if (err) + return err; + } + } + + if (data->enable_dts) { + for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) { + if (!(data->has_dts & (1 << i))) + continue; + for (j = 0; j < ARRAY_SIZE(w83795_dts[0]); j++) { + if (j == 7 && !data->enable_beep) + continue; + err = fn(dev, &w83795_dts[i][j].dev_attr); + if (err) + return err; + } + } + } + + return 0; +} + +/* We need a wrapper that fits in w83795_handle_files */ +static int device_remove_file_wrapper(struct device *dev, + const struct device_attribute *attr) +{ + device_remove_file(dev, attr); + return 0; +} + +static void w83795_check_dynamic_in_limits(struct i2c_client *client) +{ + struct w83795_data *data = i2c_get_clientdata(client); + u8 vid_ctl; + int i, err_max, err_min; + + vid_ctl = w83795_read(client, W83795_REG_VID_CTRL); + + /* Return immediately if VRM isn't configured */ + if ((vid_ctl & 0x07) == 0x00 || (vid_ctl & 0x07) == 0x07) + return; + + data->has_dyn_in = (vid_ctl >> 3) & 0x07; + for (i = 0; i < 2; i++) { + if (!(data->has_dyn_in & (1 << i))) + continue; + + /* Voltage limits in dynamic mode, switch to read-only */ + err_max = sysfs_chmod_file(&client->dev.kobj, + &w83795_in[i][2].dev_attr.attr, + S_IRUGO); + err_min = sysfs_chmod_file(&client->dev.kobj, + &w83795_in[i][3].dev_attr.attr, + S_IRUGO); + if (err_max || err_min) + dev_warn(&client->dev, + "Failed to set in%d limits read-only (%d, %d)\n", + i, err_max, err_min); + else + dev_info(&client->dev, + "in%d limits set dynamically from VID\n", i); + } +} + +/* Check pins that can be used for either temperature or voltage monitoring */ +static void w83795_apply_temp_config(struct w83795_data *data, u8 config, + int temp_chan, int in_chan) +{ + /* config is a 2-bit value */ + switch (config) { + case 0x2: /* Voltage monitoring */ + data->has_in |= 1 << in_chan; + break; + case 0x1: /* Thermal diode */ + if (temp_chan >= 4) + break; + data->temp_mode |= 1 << temp_chan; + /* fall through */ + case 0x3: /* Thermistor */ + data->has_temp |= 1 << temp_chan; + break; + } +} + +static int w83795_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int i; + u8 tmp; + struct device *dev = &client->dev; + struct w83795_data *data; + int err; + + data = devm_kzalloc(dev, sizeof(struct w83795_data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + i2c_set_clientdata(client, data); + data->chip_type = id->driver_data; + data->bank = i2c_smbus_read_byte_data(client, W83795_REG_BANKSEL); + mutex_init(&data->update_lock); + + /* Initialize the chip */ + w83795_init_client(client); + + /* Check which voltages and fans are present */ + data->has_in = w83795_read(client, W83795_REG_VOLT_CTRL1) + | (w83795_read(client, W83795_REG_VOLT_CTRL2) << 8); + data->has_fan = w83795_read(client, W83795_REG_FANIN_CTRL1) + | (w83795_read(client, W83795_REG_FANIN_CTRL2) << 8); + + /* Check which analog temperatures and extra voltages are present */ + tmp = w83795_read(client, W83795_REG_TEMP_CTRL1); + if (tmp & 0x20) + data->enable_dts = 1; + w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 5, 16); + w83795_apply_temp_config(data, tmp & 0x3, 4, 15); + tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); + w83795_apply_temp_config(data, tmp >> 6, 3, 20); + w83795_apply_temp_config(data, (tmp >> 4) & 0x3, 2, 19); + w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 1, 18); + w83795_apply_temp_config(data, tmp & 0x3, 0, 17); + + /* Check DTS enable status */ + if (data->enable_dts) { + if (1 & w83795_read(client, W83795_REG_DTSC)) + data->enable_dts |= 2; + data->has_dts = w83795_read(client, W83795_REG_DTSE); + } + + /* Report PECI Tbase values */ + if (data->enable_dts == 1) { + for (i = 0; i < 8; i++) { + if (!(data->has_dts & (1 << i))) + continue; + tmp = w83795_read(client, W83795_REG_PECI_TBASE(i)); + dev_info(&client->dev, + "PECI agent %d Tbase temperature: %u\n", + i + 1, (unsigned int)tmp & 0x7f); + } + } + + data->has_gain = w83795_read(client, W83795_REG_VMIGB_CTRL) & 0x0f; + + /* pwm and smart fan */ + if (data->chip_type == w83795g) + data->has_pwm = 8; + else + data->has_pwm = 2; + + /* Check if BEEP pin is available */ + if (data->chip_type == w83795g) { + /* The W83795G has a dedicated BEEP pin */ + data->enable_beep = 1; + } else { + /* + * The W83795ADG has a shared pin for OVT# and BEEP, so you + * can't have both + */ + tmp = w83795_read(client, W83795_REG_OVT_CFG); + if ((tmp & OVT_CFG_SEL) == 0) + data->enable_beep = 1; + } + + err = w83795_handle_files(dev, device_create_file); + if (err) + goto exit_remove; + + if (data->chip_type == w83795g) + w83795_check_dynamic_in_limits(client); + + data->hwmon_dev = hwmon_device_register(dev); + if (IS_ERR(data->hwmon_dev)) { + err = PTR_ERR(data->hwmon_dev); + goto exit_remove; + } + + return 0; + +exit_remove: + w83795_handle_files(dev, device_remove_file_wrapper); + return err; +} + +static int w83795_remove(struct i2c_client *client) +{ + struct w83795_data *data = i2c_get_clientdata(client); + + hwmon_device_unregister(data->hwmon_dev); + w83795_handle_files(&client->dev, device_remove_file_wrapper); + + return 0; +} + + +static const struct i2c_device_id w83795_id[] = { + { "w83795g", w83795g }, + { "w83795adg", w83795adg }, + { } +}; +MODULE_DEVICE_TABLE(i2c, w83795_id); + +static struct i2c_driver w83795_driver = { + .driver = { + .name = "w83795", + }, + .probe = w83795_probe, + .remove = w83795_remove, + .id_table = w83795_id, + + .class = I2C_CLASS_HWMON, + .detect = w83795_detect, + .address_list = normal_i2c, +}; + +module_i2c_driver(w83795_driver); + +MODULE_AUTHOR("Wei Song, Jean Delvare "); +MODULE_DESCRIPTION("W83795G/ADG hardware monitoring driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/PKG.yml b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/PKG.yml new file mode 100755 index 00000000..59158725 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-ingrasys-s9100 ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/Makefile new file mode 100755 index 00000000..e7437cb2 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/lib/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/lib/Makefile new file mode 100755 index 00000000..644a9070 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/lib/Makefile @@ -0,0 +1,45 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +############################################################ +include $(ONL)/make/config.amd64.mk + +MODULE := libonlp-x86-64-ingrasys-s9100 +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF x86_64_ingrasys_s9100 onlplib +DEPENDMODULE_HEADERS := sff + +include $(BUILDER)/dependmodules.mk + +SHAREDLIB := libonlp-x86-64-ingrasys-s9100.so +$(SHAREDLIB)_TARGETS := $(ALL_TARGETS) +include $(BUILDER)/so.mk +.DEFAULT_GOAL := $(SHAREDLIB) + +GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -fPIC +GLOBAL_LINK_LIBS += -lpthread + +include $(BUILDER)/targets.mk + diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/onlpdump/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/onlpdump/Makefile new file mode 100755 index 00000000..da86108f --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/onlpdump/Makefile @@ -0,0 +1,45 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ +include $(ONL)/make/config.amd64.mk + +.DEFAULT_GOAL := onlpdump + +MODULE := onlpdump +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF onlp x86_64_ingrasys_s9100 onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS + +include $(BUILDER)/dependmodules.mk + +BINARY := onlpdump +$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS) +include $(BUILDER)/bin.mk + +GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1 +GLOBAL_LINK_LIBS += -lpthread -lm + +include $(BUILDER)/targets.mk diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/.gitignore b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/.gitignore new file mode 100755 index 00000000..d274ea3d --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/.gitignore @@ -0,0 +1,2 @@ +/x86_64_ingrasys_s9100.mk +/doc diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/.module b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/.module new file mode 100755 index 00000000..8958f013 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/.module @@ -0,0 +1 @@ +name: x86_64_ingrasys_s9100 diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/Makefile new file mode 100755 index 00000000..c9d9e890 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/Makefile @@ -0,0 +1,10 @@ +############################################################ +# +# +# +############################################################ +include $(ONL)/make/config.mk + +MODULE := x86_64_ingrasys_s9100 +AUTOMODULE := x86_64_ingrasys_s9100 +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/auto/make.mk b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/auto/make.mk new file mode 100755 index 00000000..f1a59d6e --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/auto/make.mk @@ -0,0 +1,7 @@ +# +# x86_64_ingrasys_s9100 Autogeneration +# +############################################################################### +x86-64-ingrasys-s9100_AUTO_DEFS := module/auto/x86-64-ingrasys-s9100.yml +x86-64-ingrasys-s9100_AUTO_DIRS := module/inc/x86-64-ingrasys-s9100 module/src +include $(BUILDER)/auto.mk diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/auto/x86-64-ingrasys-s9100.yml b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/auto/x86-64-ingrasys-s9100.yml new file mode 100755 index 00000000..03724760 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/auto/x86-64-ingrasys-s9100.yml @@ -0,0 +1,47 @@ +############################################################################### +# +# X86_64_INGRASYS_S9100 Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- X86_64_INGRASYS_S9100_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- X86_64_INGRASYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- X86_64_INGRASYS_S9100_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- X86_64_INGRASYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- X86_64_INGRASYS_S9100_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- X86_64_INGRASYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: X86_64_INGRASYS_S9100_CONFIG_PORTING_STDLIB +- X86_64_INGRASYS_S9100_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 + + +definitions: + cdefs: + X86_64_INGRASYS_S9100_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_ingrasys_s9100_config + + portingmacro: + X86_64_INGRASYS_S9100: + macros: + - malloc + - free + - memset + - memcpy + - strncpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100.x b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100.x new file mode 100755 index 00000000..d8db28cf --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100.x @@ -0,0 +1,34 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ + + diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_config.h b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_config.h new file mode 100755 index 00000000..1f3b3642 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_config.h @@ -0,0 +1,162 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +/**************************************************************************//** + * + * @file + * @brief x86_64_ingrasys_s9100 Configuration Header + * + * @addtogroup x86_64_ingrasys_s9100-config + * @{ + * + *****************************************************************************/ +#ifndef __INGRAYSYS_S9100_CONFIG_H__ +#define __INGRAYSYS_S9100_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef INGRAYSYS_S9100_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING +#define INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT +#define INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT +#define INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * INGRAYSYS_S9100_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef INGRAYSYS_S9100_CONFIG_PORTING_STDLIB +#define INGRAYSYS_S9100_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS INGRAYSYS_S9100_CONFIG_PORTING_STDLIB +#endif + +/** + * INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI +#define INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * INGRAYSYS_S9100_CONFIG_SFP_COUNT + * + * SFP Count. */ + + +#ifndef INGRAYSYS_S9100_CONFIG_SFP_COUNT +#define INGRAYSYS_S9100_CONFIG_SFP_COUNT 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct x86_64_ingrasys_s9100_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_ingrasys_s9100_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_ingrasys_s9100_config_settings table. */ +extern x86_64_ingrasys_s9100_config_settings_t x86_64_ingrasys_s9100_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_ingrasys_s9100_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_ingrasys_s9100_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_ingrasys_s9100_porting.h" + +#endif /* __INGRAYSYS_S9100_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_dox.h b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_dox.h new file mode 100755 index 00000000..c796e25b --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_ingrasys_s9100 Doxygen Header + * + *****************************************************************************/ +#ifndef __x86_64_ingrasys_s9100_DOX_H__ +#define __x86_64_ingrasys_s9100_DOX_H__ + +/** + * @defgroup x86_64_ingrasys_s9100 x86_64_ingrasys_s9100 - x86_64_ingrasys_s9100 Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_ingrasys_s9100-x86_64_ingrasys_s9100 Public Interface + * @defgroup x86_64_ingrasys_s9100-config Compile Time Configuration + * @defgroup x86_64_ingrasys_s9100-porting Porting Macros + * + * @} + * + */ + +#endif /* __x86_64_ingrasys_s9100_DOX_H__ */ diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_porting.h b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_porting.h new file mode 100755 index 00000000..58f68c04 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_porting.h @@ -0,0 +1,106 @@ +/********************************************************//** + * + * @file + * @brief x86_64_Ingrasys_s9100 Porting Macros. + * + * @addtogroup x86_64_Ingrasys_s9100-porting + * @{ + * + ***********************************************************/ +#ifndef __INGRAYSYS_S9100_PORTING_H__ +#define __INGRAYSYS_S9100_PORTING_H__ + +/* */ +#if INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef INGRAYSYS_S9100_MALLOC + #if defined(GLOBAL_MALLOC) + #define INGRAYSYS_S9100_MALLOC GLOBAL_MALLOC + #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define INGRAYSYS_S9100_MALLOC malloc + #else + #error The macro INGRAYSYS_S9100_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef INGRAYSYS_S9100_FREE + #if defined(GLOBAL_FREE) + #define INGRAYSYS_S9100_FREE GLOBAL_FREE + #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define INGRAYSYS_S9100_FREE free + #else + #error The macro INGRAYSYS_S9100_FREE is required but cannot be defined. + #endif +#endif + +#ifndef INGRAYSYS_S9100_MEMSET + #if defined(GLOBAL_MEMSET) + #define INGRAYSYS_S9100_MEMSET GLOBAL_MEMSET + #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define INGRAYSYS_S9100_MEMSET memset + #else + #error The macro INGRAYSYS_S9100_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef INGRAYSYS_S9100_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define INGRAYSYS_S9100_MEMCPY GLOBAL_MEMCPY + #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define INGRAYSYS_S9100_MEMCPY memcpy + #else + #error The macro INGRAYSYS_S9100_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef INGRAYSYS_S9100_STRNCPY + #if defined(GLOBAL_STRNCPY) + #define INGRAYSYS_S9100_STRNCPY GLOBAL_STRNCPY + #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define INGRAYSYS_S9100_STRNCPY strncpy + #else + #error The macro INGRAYSYS_S9100_STRNCPY is required but cannot be defined. + #endif +#endif + +#ifndef INGRAYSYS_S9100_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define INGRAYSYS_S9100_VSNPRINTF GLOBAL_VSNPRINTF + #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define INGRAYSYS_S9100_VSNPRINTF vsnprintf + #else + #error The macro INGRAYSYS_S9100_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef INGRAYSYS_S9100_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define INGRAYSYS_S9100_SNPRINTF GLOBAL_SNPRINTF + #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define INGRAYSYS_S9100_SNPRINTF snprintf + #else + #error The macro INGRAYSYS_S9100_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef INGRAYSYS_S9100_STRLEN + #if defined(GLOBAL_STRLEN) + #define INGRAYSYS_S9100_STRLEN GLOBAL_STRLEN + #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define INGRAYSYS_S9100_STRLEN strlen + #else + #error The macro INGRAYSYS_S9100_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __INGRAYSYS_S9100_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/make.mk b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/make.mk new file mode 100755 index 00000000..87e53be9 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/make.mk @@ -0,0 +1,29 @@ +############################################################ +# +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_ingrasys_s9100_INCLUDES := -I $(THIS_DIR)inc +x86_64_ingrasys_s9100_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_ingrasys_s9100_DEPENDMODULE_ENTRIES := init:x86_64_ingrasys_s9100 ucli:x86_64_ingrasys_s9100 + diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/Makefile new file mode 100755 index 00000000..5ccb9ac7 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/Makefile @@ -0,0 +1,30 @@ +############################################################ +# +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# Local source generation targets. +# +############################################################ + +include ../../../../init.mk + +ucli: + $(SUBMODULE_BIGCODE)/tools/uclihandlers.py x86_64_ingrasys_s9100_ucli.c + diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/fani.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/fani.c new file mode 100755 index 00000000..921b3ffa --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/fani.c @@ -0,0 +1,283 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Fan Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include "x86_64_ingrasys_s9100_int.h" +#include +#include "platform_lib.h" + +onlp_fan_info_t fan_info[] = { + { }, /* Not used */ + { + { FAN_OID_FAN1, "FANTRAY 1-A", 0 }, + ONLP_FAN_STATUS_PRESENT, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_FAN2, "FANTRAY 1-B", 0 }, + ONLP_FAN_STATUS_PRESENT, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_FAN3, "FANTRAY 2-A", 0 }, + ONLP_FAN_STATUS_PRESENT, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_FAN4, "FANTRAY 2-B", 0 }, + ONLP_FAN_STATUS_PRESENT, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_FAN5, "FANTRAY 3-A", 0 }, + ONLP_FAN_STATUS_PRESENT, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_FAN6, "FANTRAY 3-B", 0 }, + ONLP_FAN_STATUS_PRESENT, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_FAN7, "FANTRAY 4-A", 0 }, + ONLP_FAN_STATUS_PRESENT, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_FAN8, "FANTRAY 4-B", 0 }, + ONLP_FAN_STATUS_PRESENT, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_PSU_FAN1, "PSU-1 FAN", 0 }, + ONLP_FAN_STATUS_PRESENT, + }, + { + { FAN_OID_PSU_FAN2, "PSU-2 FAN", 0 }, + ONLP_FAN_STATUS_PRESENT, + } +}; +/* + * This function will be called prior to all of onlp_fani_* functions. + */ +int +onlp_fani_init(void) +{ + return ONLP_STATUS_OK; +} + +int +sys_fan_info_get(onlp_fan_info_t* info, int id) +{ + int rv, fan_status, fan_rpm, perc_val, percentage; + fan_status = 0; + fan_rpm = 0; + + rv = onlp_file_read_int(&fan_status, SYS_FAN_PREFIX "fan%d_alarm", id); + if (rv < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + /* fan status > 1, means failure */ + if (fan_status > 0) { + info->status |= ONLP_FAN_STATUS_FAILED; + return ONLP_STATUS_OK; + } + + rv = onlp_file_read_int(&fan_rpm, SYS_FAN_PREFIX "fan%d_input", id); + if (rv < 0) { + return ONLP_STATUS_E_INTERNAL; + } + info->rpm = fan_rpm; + + /* get speed percentage*/ + switch (id) + { + case FAN_ID_FAN1: + case FAN_ID_FAN2: + case FAN_ID_FAN3: + case FAN_ID_FAN4: + rv = onlp_file_read_int(&perc_val, SYS_FAN_PREFIX "pwm%d", FAN_CTRL_SET1); + break; + case FAN_ID_FAN5: + case FAN_ID_FAN6: + case FAN_ID_FAN7: + case FAN_ID_FAN8: + rv = onlp_file_read_int(&perc_val, SYS_FAN_PREFIX "pwm%d", FAN_CTRL_SET2); + break; + default: + return ONLP_STATUS_E_INVALID; + } + if (rv < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + /* + Get fan speed, converting driver value to percnet. + Value 128 is 50%. + Value 200 is 80%. + Value 255 is 100%. + */ + if (perc_val == 255) { + percentage = 100; + } else if (perc_val == 200) { + percentage = 80; + } else if (perc_val == 128) { + percentage = 50; + } else { + return ONLP_STATUS_E_INTERNAL; + } + info->percentage = percentage; + + return ONLP_STATUS_OK; +} + +int +sys_fan_rpm_percent_set(int perc) +{ + int rc; + rc = onlp_file_write_int(perc, SYS_FAN_PREFIX "pwm%d", FAN_CTRL_SET1); + + if (rc < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + rc = onlp_file_write_int(perc, SYS_FAN_PREFIX "pwm%d", FAN_CTRL_SET2); + if (rc < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_fani_rpm_set(onlp_oid_t id, int rpm) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function sets the fan speed of the given OID as a percentage. + * + * This will only be called if the OID has the PERCENTAGE_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int +onlp_fani_percentage_set(onlp_oid_t id, int percentage) +{ + int fid, perc_val, rc; + fid = ONLP_OID_ID_GET(id); + + /* Set fan speed + Driver accept value in range between 128 and 255. + Value 128 is 50%. + Value 200 is 80%. + Value 255 is 100%. + */ + if (percentage == 100) { + perc_val = 255; + } else if (percentage == 80) { + perc_val = 200; + } else if (percentage == 50) { + perc_val = 128; + } else { + return ONLP_STATUS_E_INVALID; + } + + switch (fid) + { + case FAN_ID_FAN1: + case FAN_ID_FAN2: + case FAN_ID_FAN3: + case FAN_ID_FAN4: + case FAN_ID_FAN5: + case FAN_ID_FAN6: + case FAN_ID_FAN7: + case FAN_ID_FAN8: + rc = sys_fan_rpm_percent_set(perc_val); + break; + default: + return ONLP_STATUS_E_INVALID; + } + return rc; +} + +int +onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* rv) +{ + int fan_id ,rc; + + fan_id = ONLP_OID_ID_GET(id); + *rv = fan_info[fan_id]; + rv->caps |= ONLP_FAN_CAPS_GET_RPM; + + switch (fan_id) { + case FAN_ID_FAN1: + case FAN_ID_FAN2: + case FAN_ID_FAN3: + case FAN_ID_FAN4: + case FAN_ID_FAN5: + case FAN_ID_FAN6: + case FAN_ID_FAN7: + case FAN_ID_FAN8: + rc = sys_fan_info_get(rv, fan_id); + break; + case FAN_ID_PSU_FAN1: + case FAN_ID_PSU_FAN2: + rc = psu_fan_info_get(rv, fan_id); + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + return rc; +} + \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c new file mode 100755 index 00000000..99a64628 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c @@ -0,0 +1,143 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include + +#include "platform_lib.h" + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t led_info[] = +{ + { }, /* Not used */ + { + { LED_OID_SYSTEM, "Chassis LED 1 (SYS LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN, + }, + { + { LED_OID_FAN, "Chassis LED 2 (FAN LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { LED_OID_PSU1, "Chassis LED 3 (PSU1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { LED_OID_PSU2, "Chassis LED 4 (PSU2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + } +}; + +/* + * This function will be called prior to any other onlp_ledi_* functions. + */ +int +onlp_ledi_init(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int led_id; + + led_id = ONLP_OID_ID_GET(id); + + *info = led_info[led_id]; + info->status |= ONLP_LED_STATUS_ON; + info->mode |= ONLP_LED_MODE_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) +{ + 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 led_id, rc; + + led_id = ONLP_OID_ID_GET(id); + switch (led_id) { + case LED_SYSTEM_LED: + rc = system_led_set(mode); + break; + case LED_FAN_LED: + rc = fan_led_set(mode); + break; + case LED_PSU1_LED: + rc = psu1_led_set(mode); + break; + case LED_PSU2_LED: + rc = psu2_led_set(mode); + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + return rc; +} + +/* + * Generic LED ioctl interface. + */ +int +onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/make.mk b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/make.mk new file mode 100755 index 00000000..d0885bbf --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/make.mk @@ -0,0 +1,29 @@ +############################################################ +# +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ + +LIBRARY := x86_64_ingrasys_s9100 +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +#$(LIBRARY)_LAST := 1 +include $(BUILDER)/lib.mk diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.c new file mode 100755 index 00000000..172b7f13 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.c @@ -0,0 +1,528 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "platform_lib.h" + +int +psu_thermal_get(onlp_thermal_info_t* info, int thermal_id) +{ + int pw_exist, pw_good, offset, i2c_bus, rc; + int value, buf, psu_mask; + unsigned int y_value = 0; + unsigned char n_value = 0; + unsigned int temp = 0; + char result[32]; + + if (thermal_id == THERMAL_ID_PSU1_1) { + i2c_bus = I2C_BUS_8; + offset = PSU_THERMAL1_OFFSET; + psu_mask = PSU1_MUX_MASK; + } else if (thermal_id == THERMAL_ID_PSU1_2) { + i2c_bus = I2C_BUS_8; + offset = PSU_THERMAL2_OFFSET; + psu_mask = PSU1_MUX_MASK; + } else if (thermal_id == THERMAL_ID_PSU2_1) { + i2c_bus = I2C_BUS_9; + offset = PSU_THERMAL1_OFFSET; + psu_mask = PSU2_MUX_MASK; + } else if (thermal_id == THERMAL_ID_PSU2_2) { + i2c_bus = I2C_BUS_9; + offset = PSU_THERMAL2_OFFSET; + psu_mask = PSU2_MUX_MASK; + } + + /* check psu status */ + if ((rc = psu_present_get(&pw_exist, I2C_BUS_0, psu_mask)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + if (pw_exist != PSU_STATUS_PRESENT) { + info->mcelsius = 0; + return ONLP_STATUS_OK; + } + + if ((rc = psu_pwgood_get(&pw_good, I2C_BUS_0, psu_mask)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + if (pw_good != PSU_STATUS_POWER_GOOD) { + info->mcelsius = 0; + return ONLP_STATUS_OK; + } + + value = onlp_i2c_readw(i2c_bus, PSU_REG, offset, ONLP_I2C_F_FORCE); + + y_value = (value & 0x07FF); + if ((value & 0x8000)&&(y_value)) { + n_value = 0xF0 + (((value) >> 11) & 0x0F); + n_value = (~n_value) +1; + temp = (unsigned int)(1<> 11) & 0x0F); + snprintf(result, sizeof(result), "%d", (y_value*(1<mcelsius = (int)(buf * 1000); + + return ONLP_STATUS_OK; +} + + +int +psu_fan_info_get(onlp_fan_info_t* info, int id) +{ + int pw_exist, pw_good, i2c_bus, psu_mask, rc; + unsigned int tmp_fan_rpm, fan_rpm; + + if (id == FAN_ID_PSU_FAN1) { + i2c_bus = I2C_BUS_8; + psu_mask = PSU1_MUX_MASK; + } else if (id == FAN_ID_PSU_FAN2) { + i2c_bus = I2C_BUS_9; + psu_mask = PSU2_MUX_MASK; + } else { + return ONLP_STATUS_E_INTERNAL; + } + + /* check psu status */ + if ((rc = psu_present_get(&pw_exist, I2C_BUS_0, psu_mask)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + if (pw_exist != PSU_STATUS_PRESENT) { + info->rpm = 0; + return ONLP_STATUS_OK; + } + + if ((rc = psu_pwgood_get(&pw_good, I2C_BUS_0, psu_mask)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + if (pw_good != PSU_STATUS_POWER_GOOD) { + info->rpm = 0; + return ONLP_STATUS_OK; + } + + tmp_fan_rpm = onlp_i2c_readw(i2c_bus, PSU_REG, PSU_FAN_RPM_OFFSET, ONLP_I2C_F_FORCE); + + fan_rpm = (unsigned int)tmp_fan_rpm; + fan_rpm = (fan_rpm & 0x07FF) * (1 << ((fan_rpm >> 11) & 0x1F)); + info->rpm = (int)fan_rpm; + + return ONLP_STATUS_OK; +} + +int +psu_vout_get(onlp_psu_info_t* info, int i2c_bus) +{ + int v_value = 0; + int n_value = 0; + unsigned int temp = 0; + char result[32]; + double dvalue; + memset(result, 0, sizeof(result)); + + n_value = onlp_i2c_readb(i2c_bus, PSU_REG, PSU_VOUT_OFFSET1, ONLP_I2C_F_FORCE); + if (n_value < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + v_value = onlp_i2c_readw(i2c_bus, PSU_REG, PSU_VOUT_OFFSET2, ONLP_I2C_F_FORCE); + if (v_value < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + if (n_value & 0x10) { + n_value = 0xF0 + (n_value & 0x0F); + n_value = (~n_value) +1; + temp = (unsigned int)(1< 0.0) { + info->caps |= ONLP_PSU_CAPS_VOUT; + info->mvout = (int)(dvalue * 1000); + } + + return ONLP_STATUS_OK; +} + +int +psu_iout_get(onlp_psu_info_t* info, int i2c_bus) +{ + int value; + unsigned int y_value = 0; + unsigned char n_value = 0; + unsigned int temp = 0; + char result[32]; + memset(result, 0, sizeof(result)); + double dvalue; + + value = onlp_i2c_readw(i2c_bus, PSU_REG, PSU_IOUT_OFFSET, ONLP_I2C_F_FORCE); + if (value < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + y_value = (value & 0x07FF); + if ((value & 0x8000)&&(y_value)) + { + n_value = 0xF0 + (((value) >> 11) & 0x0F); + n_value = (~n_value) +1; + temp = (unsigned int)(1<> 11) & 0x0F); + snprintf(result, sizeof(result), "%d", (y_value*(1< 0.0) { + info->caps |= ONLP_PSU_CAPS_IOUT; + info->miout = (int)(dvalue * 1000); + } + + return ONLP_STATUS_OK; +} + +int +psu_pout_get(onlp_psu_info_t* info, int i2c_bus) +{ + int value; + unsigned int y_value = 0; + unsigned char n_value = 0; + unsigned int temp = 0; + char result[32]; + memset(result, 0, sizeof(result)); + double dvalue; + + value = onlp_i2c_readw(i2c_bus, PSU_REG, PSU_POUT_OFFSET, ONLP_I2C_F_FORCE); + if (value < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + y_value = (value & 0x07FF); + if ((value & 0x8000)&&(y_value)) + { + n_value = 0xF0 + (((value) >> 11) & 0x0F); + n_value = (~n_value) +1; + temp = (unsigned int)(1<> 11) & 0x0F); + snprintf(result, sizeof(result), "%d", (y_value*(1< 0.0) { + info->caps |= ONLP_PSU_CAPS_POUT; + info->mpout = (int)(dvalue * 1000); + } + + return ONLP_STATUS_OK; +} + +int +psu_pin_get(onlp_psu_info_t* info, int i2c_bus) +{ + int value; + unsigned int y_value = 0; + unsigned char n_value = 0; + unsigned int temp = 0; + char result[32]; + memset(result, 0, sizeof(result)); + double dvalue; + + value = onlp_i2c_readw(i2c_bus, PSU_REG, PSU_PIN_OFFSET, ONLP_I2C_F_FORCE); + if (value < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + y_value = (value & 0x07FF); + if ((value & 0x8000)&&(y_value)) + { + n_value = 0xF0 + (((value) >> 11) & 0x0F); + n_value = (~n_value) +1; + temp = (unsigned int)(1<> 11) & 0x0F); + snprintf(result, sizeof(result), "%d", (y_value*(1< 0.0) { + info->caps |= ONLP_PSU_CAPS_PIN; + info->mpin = (int)(dvalue * 1000); + } + + return ONLP_STATUS_OK; +} + +int +psu_eeprom_get(onlp_psu_info_t* info, int id) +{ + uint8_t data[256]; + char eeprom_path[128]; + int data_len, i, rc; + memset(data, 0, sizeof(data)); + memset(eeprom_path, 0, sizeof(eeprom_path)); + + if (id == PSU_ID_PSU1) { + rc = onlp_file_read(data, sizeof(data), &data_len, PSU1_EEPROM_PATH); + } else { + rc = onlp_file_read(data, sizeof(data), &data_len, PSU2_EEPROM_PATH); + } + + if (rc == ONLP_STATUS_OK) + { + i = 11; + + /* Manufacturer Name */ + data_len = (data[i]&0x0f); + i++; + i += data_len; + + /* Product Name */ + data_len = (data[i]&0x0f); + i++; + memcpy(info->model, (char *) &(data[i]), data_len); + i += data_len; + + /* Product part,model number */ + data_len = (data[i]&0x0f); + i++; + i += data_len; + + /* Product Version */ + data_len = (data[i]&0x0f); + i++; + i += data_len; + + /* Product Serial Number */ + data_len = (data[i]&0x0f); + i++; + memcpy(info->serial, (char *) &(data[i]), data_len); + } else { + strcpy(info->model, "Missing"); + strcpy(info->serial, "Missing"); + } + + return ONLP_STATUS_OK; +} + + +int +psu_present_get(int *pw_exist, int i2c_bus, int psu_mask) +{ + int psu_pres; + + psu_pres = onlp_i2c_readb(i2c_bus, PSU_STATE_REG, PSU_PRESENT_OFFSET, ONLP_I2C_F_FORCE); + if (psu_pres < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + *pw_exist = ((psu_pres & psu_mask) ? 0 : 1); + return ONLP_STATUS_OK; +} + +int +psu_pwgood_get(int *pw_good, int i2c_bus, int psu_mask) +{ + int psu_pwgood; + + psu_pwgood = onlp_i2c_readb(i2c_bus, PSU_STATE_REG, PSU_PWGOOD_OFFSET, ONLP_I2C_F_FORCE); + if (psu_pwgood < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + *pw_good = (((psu_pwgood >> 3 ) & psu_mask) ? 1 : 0); + return ONLP_STATUS_OK; +} + +int +qsfp_present_get(int port, int *pres_val) +{ + int reg_addr, val, offset; + + if (port >= 1 && port <= 8) { + reg_addr = QSFP_PRES_REG1; + offset = QSFP_PRES_OFFSET1; + } else if (port >= 9 && port <= 16) { + reg_addr = QSFP_PRES_REG1; + offset = QSFP_PRES_OFFSET2; + } else if (port >= 17 && port <= 24) { + reg_addr = QSFP_PRES_REG2; + offset = QSFP_PRES_OFFSET1; + } else if (port >= 25 && port <= 32) { + reg_addr = QSFP_PRES_REG2; + offset = QSFP_PRES_OFFSET2; + } else { + return ONLP_STATUS_E_INTERNAL; + } + + val = onlp_i2c_readb(I2C_BUS_6, reg_addr, offset, ONLP_I2C_F_FORCE); + if (val < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + *pres_val = val; + + return ONLP_STATUS_OK; +} + + +int +system_led_set(onlp_led_mode_t mode) +{ + int rc; + if(mode == ONLP_LED_MODE_GREEN) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, LED_SYS_AND_MASK, + LED_SYS_GMASK, ONLP_I2C_F_FORCE); + } + else if(mode == ONLP_LED_MODE_ORANGE) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, LED_SYS_AND_MASK, + LED_SYS_YMASK, ONLP_I2C_F_FORCE); + } else { + return ONLP_STATUS_E_INTERNAL; + } + + if (rc < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +fan_led_set(onlp_led_mode_t mode) +{ + int rc; + if(mode == ONLP_LED_MODE_GREEN) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, LED_FAN_AND_MASK, + LED_FAN_GMASK, ONLP_I2C_F_FORCE); + } + else if(mode == ONLP_LED_MODE_ORANGE) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, LED_FAN_AND_MASK, + LED_FAN_YMASK, ONLP_I2C_F_FORCE); + } else { + return ONLP_STATUS_E_INTERNAL; + } + + if (rc < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +psu1_led_set(onlp_led_mode_t mode) +{ + int rc; + if(mode == ONLP_LED_MODE_GREEN) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, + LED_PSU1_AND_MASK, LED_PSU1_GMASK, + ONLP_I2C_F_FORCE); + } else if(mode == ONLP_LED_MODE_ORANGE) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, + LED_PSU1_AND_MASK, LED_PSU1_YMASK, + ONLP_I2C_F_FORCE); + } else { + return ONLP_STATUS_E_INTERNAL; + } + + if (rc < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +psu2_led_set(onlp_led_mode_t mode) +{ + int rc; + if(mode == ONLP_LED_MODE_GREEN) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, + LED_PSU2_AND_MASK, LED_PSU2_GMASK, + ONLP_I2C_F_FORCE); + } else if(mode == ONLP_LED_MODE_ORANGE) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, + LED_PSU2_AND_MASK, LED_PSU2_YMASK, + ONLP_I2C_F_FORCE); + } else { + return ONLP_STATUS_E_INTERNAL; + } + + + if (rc < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int cpld_release, cpld_version, cpld_rev; + + cpld_rev = onlp_i2c_readb(I2C_BUS_0, CPLD_REG, CPLD_VER_OFFSET, ONLP_I2C_F_FORCE); + if (cpld_rev < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + cpld_release = (((cpld_rev) >> 6 & 0x01)); + cpld_version = (((cpld_rev) & 0x3F)); + + pi->cpld_versions = aim_fstrdup( + "CPLD is %d version(0:RD 1:Release), Revision is 0x%02x\n", + cpld_release, cpld_version); + + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.h b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.h new file mode 100755 index 00000000..c06d2de9 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.h @@ -0,0 +1,248 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#ifndef __PLATFORM_LIB_H__ +#define __PLATFORM_LIB_H__ + +#include +#include +#include +#include +#include +#include "x86_64_ingrasys_s9100_int.h" +#include "x86_64_ingrasys_s9100_log.h" + +#include +#define SYS_HWMON_TEMP_PREFIX "/sys/class/hwmon/hwmon1/device/" +#define SYS_CORE_TEMP_PREFIX "/sys/class/hwmon/hwmon0/device/hwmon/hwmon0/" +#define SYS_FAN_PREFIX "/sys/class/hwmon/hwmon1/device/" +#define SYS_EEPROM_PATH "/sys/bus/i2c/devices/9-0054/eeprom" +#define PSU1_EEPROM_PATH "/sys/bus/i2c/devices/8-0050/eeprom" +#define PSU2_EEPROM_PATH "/sys/bus/i2c/devices/9-0050/eeprom" +#define PSU_STATUS_PRESENT 1 +#define PSU_STATUS_POWER_GOOD 1 +#define FAN_PRESENT 0 +#define FAN_CTRL_SET1 1 +#define FAN_CTRL_SET2 2 +#define MAX_SYS_FAN_NUM 8 +#define BOARD_THERMAL_NUM 6 +#define SYS_FAN_NUM 8 +#define QSFP_NUM 32 + +#define THERMAL_NUM 10 +#define LED_NUM 4 +#define FAN_NUM 10 + + + +#define THERMAL_SHUTDOWN_DEFAULT 105000 + +#define THERMAL_ERROR_DEFAULT 95000 +#define THERMAL_ERROR_FAN_PERC 100 + +#define THERMAL_WARNING_DEFAULT 77000 +#define THERMAL_WARNING_FAN_PERC 80 + +#define THERMAL_NORMAL_DEFAULT 72000 +#define THERMAL_NORMAL_FAN_PERC 50 + + +/* I2C bus */ +#define I2C_BUS_0 0 +#define I2C_BUS_1 1 +#define I2C_BUS_2 2 +#define I2C_BUS_3 3 +#define I2C_BUS_4 4 +#define I2C_BUS_5 5 +#define I2C_BUS_6 6 +#define I2C_BUS_7 7 +#define I2C_BUS_8 8 +#define I2C_BUS_9 9 + +/* PSU */ +#define PSU1_MUX_MASK 0x01 +#define PSU2_MUX_MASK 0x02 +#define PSU_THERMAL1_OFFSET 0x8D +#define PSU_THERMAL2_OFFSET 0x8E +#define PSU_THERMAL_REG 0x58 +#define PSU_FAN_RPM_REG 0x58 +#define PSU_FAN_RPM_OFFSET 0x90 +#define PSU_REG 0x58 +#define PSU_VOUT_OFFSET1 0x20 +#define PSU_VOUT_OFFSET2 0x8B +#define PSU_IOUT_OFFSET 0x8C +#define PSU_POUT_OFFSET 0x96 +#define PSU_PIN_OFFSET 0x97 +#define PSU_STATE_REG 0x33 +#define PSU_PRESENT_OFFSET 0x03 +#define PSU_PWGOOD_OFFSET 0x02 + +/* LED */ +#define LED_REG 0x22 +#define LED_OFFSET 0x02 +#define LED_SYS_AND_MASK 0x3F +#define LED_SYS_GMASK 0x40 +#define LED_SYS_YMASK 0x80 +#define LED_FAN_AND_MASK 0xF3 +#define LED_FAN_GMASK 0x04 +#define LED_FAN_YMASK 0x08 +#define LED_PSU1_AND_MASK 0xFC +#define LED_PSU1_GMASK 0x01 +#define LED_PSU1_YMASK 0x02 +#define LED_PSU2_AND_MASK 0xCF +#define LED_PSU2_GMASK 0x10 +#define LED_PSU2_YMASK 0x20 + +/* SYS */ +#define CPLD_REG 0x33 +#define CPLD_VER_OFFSET 0x01 + +/* QSFP */ +#define QSFP_PRES_REG1 0x20 +#define QSFP_PRES_REG2 0x21 +#define QSFP_PRES_OFFSET1 0x00 +#define QSFP_PRES_OFFSET2 0x01 + +/** led_oid */ +typedef enum led_oid_e { + LED_OID_SYSTEM = ONLP_LED_ID_CREATE(1), + LED_OID_FAN = ONLP_LED_ID_CREATE(2), + LED_OID_PSU1 = ONLP_LED_ID_CREATE(3), + LED_OID_PSU2 = ONLP_LED_ID_CREATE(4), +} led_oid_t; + +/** led_id */ +typedef enum led_id_e { + LED_SYSTEM_LED = 1, + LED_FAN_LED = 2, + LED_PSU1_LED = 3, + LED_PSU2_LED = 4, +} led_id_t; + +/** Thermal_oid */ +typedef enum thermal_oid_e { + THERMAL_OID_FRONT_MAC = ONLP_THERMAL_ID_CREATE(1), + THERMAL_OID_REAR_MAC = ONLP_THERMAL_ID_CREATE(2), + THERMAL_OID_CPU1 = ONLP_THERMAL_ID_CREATE(3), + THERMAL_OID_CPU2 = ONLP_THERMAL_ID_CREATE(4), + THERMAL_OID_CPU3 = ONLP_THERMAL_ID_CREATE(5), + THERMAL_OID_CPU4 = ONLP_THERMAL_ID_CREATE(6), + THERMAL_OID_PSU1_1 = ONLP_THERMAL_ID_CREATE(7), + THERMAL_OID_PSU1_2 = ONLP_THERMAL_ID_CREATE(8), + THERMAL_OID_PSU2_1 = ONLP_THERMAL_ID_CREATE(9), + THERMAL_OID_PSU2_2 = ONLP_THERMAL_ID_CREATE(10) +} thermal_oid_t; + +/** thermal_id */ +typedef enum thermal_id_e { + THERMAL_ID_FRONT_MAC = 1, + THERMAL_ID_REAR_MAC = 2, + THERMAL_ID_CPU1 = 3, + THERMAL_ID_CPU2 = 4, + THERMAL_ID_CPU3 = 5, + THERMAL_ID_CPU4 = 6, + THERMAL_ID_PSU1_1 = 7, + THERMAL_ID_PSU1_2 = 8, + THERMAL_ID_PSU2_1 = 9, + THERMAL_ID_PSU2_2 = 10, +} thermal_id_t; + +/* Shortcut for CPU thermal threshold value. */ +#define THERMAL_THRESHOLD_INIT_DEFAULTS \ + { THERMAL_WARNING_DEFAULT, \ + THERMAL_ERROR_DEFAULT, \ + THERMAL_SHUTDOWN_DEFAULT } + +/** Fan_oid */ +typedef enum fan_oid_e { + FAN_OID_FAN1 = ONLP_FAN_ID_CREATE(1), + FAN_OID_FAN2 = ONLP_FAN_ID_CREATE(2), + FAN_OID_FAN3 = ONLP_FAN_ID_CREATE(3), + FAN_OID_FAN4 = ONLP_FAN_ID_CREATE(4), + FAN_OID_FAN5 = ONLP_FAN_ID_CREATE(5), + FAN_OID_FAN6 = ONLP_FAN_ID_CREATE(6), + FAN_OID_FAN7 = ONLP_FAN_ID_CREATE(7), + FAN_OID_FAN8 = ONLP_FAN_ID_CREATE(8), + FAN_OID_PSU_FAN1 = ONLP_FAN_ID_CREATE(9), + FAN_OID_PSU_FAN2 = ONLP_FAN_ID_CREATE(10) +} fan_oid_t; + +/** fan_id */ +typedef enum fan_id_e { + FAN_ID_FAN1 = 1, + FAN_ID_FAN2 = 2, + FAN_ID_FAN3 = 3, + FAN_ID_FAN4 = 4, + FAN_ID_FAN5 = 5, + FAN_ID_FAN6 = 6, + FAN_ID_FAN7 = 7, + FAN_ID_FAN8 = 8, + FAN_ID_PSU_FAN1 = 9, + FAN_ID_PSU_FAN2 = 10 +} fan_id_t; + +/** led_oid */ +typedef enum psu_oid_e { + PSU_OID_PSU1 = ONLP_PSU_ID_CREATE(1), + PSU_OID_PSU2 = ONLP_PSU_ID_CREATE(2) +} psu_oid_t; + +/** fan_id */ +typedef enum psu_id_e { + PSU_ID_PSU1 = 1, + PSU_ID_PSU2 = 2 +} psu_id_t; + +int psu_thermal_get(onlp_thermal_info_t* info, int id); + +int psu_fan_info_get(onlp_fan_info_t* info, int id); + +int psu_vout_get(onlp_psu_info_t* info, int i2c_bus); + +int psu_iout_get(onlp_psu_info_t* info, int i2c_bus); + +int psu_pout_get(onlp_psu_info_t* info, int i2c_bus); + +int psu_pin_get(onlp_psu_info_t* info, int i2c_bus); + +int psu_eeprom_get(onlp_psu_info_t* info, int id); + +int psu_present_get(int *pw_exist, int i2c_bus, int psu_mask); + +int psu_pwgood_get(int *pw_good, int i2c_bus, int psu_mask); + +int psu2_led_set(onlp_led_mode_t mode); + +int psu1_led_set(onlp_led_mode_t mode); + +int fan_led_set(onlp_led_mode_t mode); + +int system_led_set(onlp_led_mode_t mode); + +int sysi_platform_info_get(onlp_platform_info_t* pi); + +int qsfp_present_get(int port, int *pres_val); + +#endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/psui.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/psui.c new file mode 100755 index 00000000..496bc1ea --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/psui.c @@ -0,0 +1,150 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include + +#include "platform_lib.h" + +static onlp_psu_info_t pinfo[] = +{ + { }, /* Not used */ + { + { + PSU_OID_PSU1, + "PSU-1", + 0, + { + FAN_OID_PSU_FAN1, + }, + } + }, + { + { + PSU_OID_PSU2, + "PSU-2", + 0, + { + FAN_OID_PSU_FAN2, + }, + } + } +}; + +int +onlp_psui_init(void) +{ + return ONLP_STATUS_OK; +} + +int +psu_status_info_get(int id, onlp_psu_info_t *info) +{ + int pw_exist, pw_good, rc, psu_mask, i2c_bus; + + if (id == PSU_ID_PSU1) { + i2c_bus = I2C_BUS_8; + psu_mask = PSU1_MUX_MASK; + } else if (id == PSU_ID_PSU2) { + i2c_bus = I2C_BUS_9; + psu_mask = PSU2_MUX_MASK; + } else { + return ONLP_STATUS_E_INTERNAL; + } + + /* Get power present status */ + if ((rc = psu_present_get(&pw_exist, 0, psu_mask)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + if (pw_exist != PSU_STATUS_PRESENT) { + info->status &= ~ONLP_PSU_STATUS_PRESENT; + info->status |= ONLP_PSU_STATUS_FAILED; + return ONLP_STATUS_OK; + } + info->status |= ONLP_PSU_STATUS_PRESENT; + + /* Get power good status */ + if ((rc = psu_pwgood_get(&pw_good, 0, psu_mask)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + if (pw_good != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + return ONLP_STATUS_OK; + } + + /* Get power eeprom status */ + if ((rc = psu_eeprom_get(info, id)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + /* Get power iout status */ + if ((rc = psu_iout_get(info, i2c_bus)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + /* Get power pout status */ + if ((rc = psu_pout_get(info, i2c_bus)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + /* Get power pin status */ + if ((rc = psu_pin_get(info, i2c_bus)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + /* Get power vout status */ + if ((rc = psu_vout_get(info, i2c_bus)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) +{ + int pid; + + pid = ONLP_OID_ID_GET(id); + memset(info, 0, sizeof(onlp_psu_info_t)); + + /* Set the onlp_oid_hdr_t */ + *info = pinfo[pid]; + + switch (pid) { + case PSU_ID_PSU1: + case PSU_ID_PSU2: + return psu_status_info_get(pid, info); + break; + default: + return ONLP_STATUS_E_UNSUPPORTED; + break; + } + + return ONLP_STATUS_OK; + + +} \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sfpi.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sfpi.c new file mode 100755 index 00000000..7a17a533 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sfpi.c @@ -0,0 +1,159 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include "x86_64_ingrasys_s9100_log.h" +#include "platform_lib.h" + +int +onlp_sfpi_init(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) +{ + int p; + for(p = 1; p <= QSFP_NUM; p++) { + AIM_BITMAP_SET(bmap, p); + } + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_is_present(int port) +{ + int status, presentchan, rc, pres_val; + + if ((rc = qsfp_present_get(port, &pres_val)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + presentchan = (( (port - 1) % 8 )); + presentchan = (( ((presentchan % 2)) == 1 ? presentchan - 1 : presentchan + 1 )); + + /* status: 0 -> Down, 1 -> Up */ + status=(( ((pres_val & ( 1 << presentchan))) != 0 ? 0 : 1 )); + + return status; +} + + +int +onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + int p = 1; + int rc = 0; + + for (p = 1; p <= QSFP_NUM; p++) { + rc = onlp_sfpi_is_present(p); + AIM_BITMAP_MOD(dst, p, (1 == rc) ? 1 : 0); + } + + return ONLP_STATUS_OK; +} + +/* + * This function reads the SFPs idrom and returns in + * in the data buffer provided. + */ +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + int eeprombusidx, eeprombus, eeprombusbase; + char eeprom_path[512], eeprom_addr[32]; + memset(eeprom_path, 0, sizeof(eeprom_path)); + memset(eeprom_addr, 0, sizeof(eeprom_addr)); + strncpy(eeprom_addr, "0050", sizeof(eeprom_addr)); + + memset(data, 0, 256); + + if (port >= 1 && port <= 8) { + eeprombusbase=10; + } else if (port >= 9 && port <= 16) { + eeprombusbase=18; + } else if (port >= 17 && port <= 24) { + eeprombusbase=26; + } else if (port >= 25 && port <= 32) { + eeprombusbase=34; + } else { + return 0; + } + + eeprombusidx = port % 8; + switch (eeprombusidx) { + case 1: + eeprombus = eeprombusbase + 1; + break; + case 2: + eeprombus = eeprombusbase + 0; + break; + case 3: + eeprombus = eeprombusbase + 3; + break; + case 4: + eeprombus = eeprombusbase + 2; + break; + case 5: + eeprombus = eeprombusbase + 5; + break; + case 6: + eeprombus = eeprombusbase + 4; + break; + case 7: + eeprombus = eeprombusbase + 7; + break; + case 0: + eeprombus = eeprombusbase + 6; + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + snprintf(eeprom_path, sizeof(eeprom_path), + "/sys/bus/i2c/devices/%d-%s/eeprom", eeprombus, eeprom_addr); + + if (onlplib_sfp_eeprom_read_file(eeprom_path, data) != 0) { + AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +/* + * De-initialize the SFPI subsystem. + */ +int +onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sysi.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sysi.c new file mode 100755 index 00000000..20c65b24 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sysi.c @@ -0,0 +1,292 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "platform_lib.h" + +const char* +onlp_sysi_platform_get(void) +{ + return "x86-64-ingrasys-s9100-r0"; +} + +int +onlp_sysi_init(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_sysi_onie_data_get(uint8_t** data, int* size) +{ + uint8_t* rdata = aim_zmalloc(256); + if(onlp_file_read(rdata, 256, size, SYS_EEPROM_PATH) == ONLP_STATUS_OK) { + if(*size == 256) { + AIM_LOG_INFO("read success\n"); + *data = rdata; + return ONLP_STATUS_OK; + } + } + + AIM_LOG_INFO("Unable to data get eeprom \n"); + aim_free(rdata); + *size = 0; + return ONLP_STATUS_E_INTERNAL; +} + +int +onlp_sysi_oids_get(onlp_oid_t* table, int max) +{ + onlp_oid_t* e = table; + memset(table, 0, max*sizeof(onlp_oid_t)); + int i; + + /* 2 PSUs */ + *e++ = ONLP_PSU_ID_CREATE(1); + *e++ = ONLP_PSU_ID_CREATE(2); + + /* LEDs Item */ + for (i=1; i<=LED_NUM; i++) { + *e++ = ONLP_LED_ID_CREATE(i); + } + + /* THERMALs Item */ + for (i=1; i<=THERMAL_NUM; i++) { + *e++ = ONLP_THERMAL_ID_CREATE(i); + } + + /* Fans Item */ + for (i=1; i<=FAN_NUM; i++) { + *e++ = ONLP_FAN_ID_CREATE(i); + } + + return ONLP_STATUS_OK; +} + +int +decide_fan_percentage(int is_up, int new_temp) +{ + int new_perc; + if (is_up) { + if (new_temp >= THERMAL_ERROR_DEFAULT) { + new_perc = THERMAL_ERROR_FAN_PERC; + } else if (new_temp >= THERMAL_WARNING_DEFAULT) { + new_perc = THERMAL_WARNING_FAN_PERC; + } else { + new_perc = THERMAL_NORMAL_FAN_PERC; + } + } else { + if (new_temp <= THERMAL_NORMAL_DEFAULT) { + new_perc = THERMAL_NORMAL_FAN_PERC; + } else if (new_temp <= THERMAL_WARNING_DEFAULT) { + new_perc = THERMAL_WARNING_FAN_PERC; + } else { + new_perc = THERMAL_ERROR_FAN_PERC; + } + } + + return new_perc; +} + +int +platform_thermal_temp_get(int *thermal_temp) +{ + int i, temp, max_temp, rc; + onlp_thermal_info_t thermal_info; + memset(&thermal_info, 0, sizeof(thermal_info)); + uint32_t thermal_arr[] = { THERMAL_OID_FRONT_MAC, + THERMAL_OID_REAR_MAC, + THERMAL_OID_CPU1, + THERMAL_OID_CPU2, + THERMAL_OID_CPU3, + THERMAL_OID_CPU4 }; + max_temp = 0; + + for (i=0; i max_temp) { + max_temp = temp; + } + } + *thermal_temp = max_temp; + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_platform_manage_fans(void) +{ + int rc, is_up ,new_temp, thermal_temp, diff; + static int new_perc = 0, ori_perc = 0; + static int ori_temp = 0; + onlp_thermal_info_t thermal_info; + memset(&thermal_info, 0, sizeof(thermal_info)); + + /* get new temperature */ + if ((rc = platform_thermal_temp_get(&thermal_temp)) != ONLP_STATUS_OK) { + goto _EXIT; + } + + new_temp = thermal_temp; + diff = new_temp - ori_temp; + + if (diff == 0) { + goto _EXIT; + } else { + is_up = (diff > 0 ? 1 : 0); + } + + new_perc = decide_fan_percentage(is_up, new_temp); + + if (ori_perc == new_perc) { + goto _EXIT; + } + + + AIM_LOG_INFO("Front Fan Speeds Percent are now at %d%%", new_perc); + + if ((rc = onlp_fani_percentage_set(THERMAL_OID_FRONT_MAC, new_perc)) != ONLP_STATUS_OK) { + goto _EXIT; + } + + /* update */ + ori_perc = new_perc; + ori_temp = new_temp; + +_EXIT : + return rc; +} + +int +onlp_sysi_platform_manage_leds(void) +{ + int psu1_status, psu2_status, rc, i, tmp_fan_status; + static int pre_psu1_status = 0, pre_psu2_status = 0, pre_fan_status = 0; + + onlp_psu_info_t psu_info; + onlp_fan_info_t fan_info; + memset(&psu_info, 0, sizeof(onlp_psu_info_t)); + memset(&fan_info, 0, sizeof(onlp_fan_info_t)); + uint32_t fan_arr[] = { FAN_OID_FAN1, + FAN_OID_FAN2, + FAN_OID_FAN3, + FAN_OID_FAN4, + FAN_OID_FAN5, + FAN_OID_FAN6, + FAN_OID_FAN7, + FAN_OID_FAN8, }; + + /* PSU LED CTRL */ + if ((rc = onlp_psui_info_get(PSU_OID_PSU1, &psu_info)) != ONLP_STATUS_OK) { + goto _EXIT; + } + + psu1_status = psu_info.status; + if (psu1_status != pre_psu1_status) { + if(psu1_status != ONLP_PSU_STATUS_PRESENT) { + rc = onlp_ledi_mode_set(LED_OID_PSU1, ONLP_LED_MODE_ORANGE); + } else { + rc = onlp_ledi_mode_set(LED_OID_PSU1, ONLP_LED_MODE_GREEN); + } + + if (rc != ONLP_STATUS_OK) { + goto _EXIT; + } + pre_psu1_status = psu1_status; + } + + if ((rc = onlp_psui_info_get(PSU_OID_PSU2, &psu_info)) != ONLP_STATUS_OK) { + goto _EXIT; + } + + psu2_status = psu_info.status; + if( psu2_status != pre_psu2_status) { + if(psu2_status != ONLP_PSU_STATUS_PRESENT) { + rc = onlp_ledi_mode_set(LED_OID_PSU2, ONLP_LED_MODE_ORANGE); + } else { + rc = onlp_ledi_mode_set(LED_OID_PSU2, ONLP_LED_MODE_GREEN); + } + + if (rc != ONLP_STATUS_OK) { + goto _EXIT; + } + pre_psu2_status = psu2_status; + } + + /* FAN LED CTRL */ + tmp_fan_status = ONLP_LED_STATUS_PRESENT; + for (i=0; i + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Thermal Sensor Platform Implementation. + * + ***********************************************************/ +#include +#include +#include "x86_64_ingrasys_s9100_log.h" +#include "platform_lib.h" + +static onlp_thermal_info_t thermal_info[] = { + { }, /* Not used */ + { { THERMAL_OID_FRONT_MAC, "Chassis Thermal (Front)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_REAR_MAC, "Chassis Thermal (Rear)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_CPU1, "CPU Thermal 1", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_CPU2, "CPU Thermal 2", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_CPU3, "CPU Thermal 3", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_CPU4, "CPU Thermal 4", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_PSU1_1, "PSU-1 Thermal 1", PSU_OID_PSU1}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_GET_TEMPERATURE, 0 + }, + { { THERMAL_OID_PSU1_2, "PSU-1 Thermal 2", PSU_OID_PSU1}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_GET_TEMPERATURE, 0 + }, + { { THERMAL_OID_PSU2_1, "PSU-2 Thermal 1", PSU_OID_PSU2}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_GET_TEMPERATURE, 0 + }, + { { THERMAL_OID_PSU2_2, "PSU-2 Thermal 2", PSU_OID_PSU2}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_GET_TEMPERATURE, 0 + } +}; + +/* + * This will be called to intiialize the thermali subsystem. + */ +int +onlp_thermali_init(void) +{ + return ONLP_STATUS_OK; +} + +static int +sys_thermal_info_get(onlp_thermal_info_t* info, int id) +{ + int rv; + + rv = onlp_file_read_int(&info->mcelsius, + SYS_FAN_PREFIX "/temp%d_input", id); + + if(rv == ONLP_STATUS_E_INTERNAL) { + return rv; + } + + if(rv == ONLP_STATUS_E_MISSING) { + info->status &= ~1; + return 0; + } + + return ONLP_STATUS_OK; +} + +static int +cpu_thermal_info_get(onlp_thermal_info_t* info, int id) +{ + int rv; + int offset; + offset = 1; + id = id - offset; + rv = onlp_file_read_int(&info->mcelsius, + SYS_CORE_TEMP_PREFIX "/temp%d_input", id); + + if(rv == ONLP_STATUS_E_INTERNAL) { + return rv; + } + + if(rv == ONLP_STATUS_E_MISSING) { + info->status &= ~1; + return 0; + } + + return ONLP_STATUS_OK; +} + + +int +psu_thermal_info_get(onlp_thermal_info_t* info, int id) +{ + int rv; + + rv = psu_thermal_get(info, id); + if(rv == ONLP_STATUS_E_INTERNAL) { + return rv; + } + + return ONLP_STATUS_OK; +} + +/* + * Retrieve the information structure for the given thermal OID. + * + * If the OID is invalid, return ONLP_E_STATUS_INVALID. + * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. + * Otherwise, return ONLP_STATUS_OK with the OID's information. + * + * Note -- it is expected that you fill out the information + * structure even if the sensor described by the OID is not present. + */ +int +onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) +{ + int sensor_id, rc; + sensor_id = ONLP_OID_ID_GET(id); + + *info = thermal_info[sensor_id]; + info->caps |= ONLP_THERMAL_CAPS_GET_TEMPERATURE; + + switch (sensor_id) { + case THERMAL_ID_FRONT_MAC: + case THERMAL_ID_REAR_MAC: + rc = sys_thermal_info_get(info, sensor_id); + break; + case THERMAL_ID_CPU1: + case THERMAL_ID_CPU2: + case THERMAL_ID_CPU3: + case THERMAL_ID_CPU4: + rc = cpu_thermal_info_get(info, sensor_id); + break; + case THERMAL_ID_PSU1_1: + case THERMAL_ID_PSU1_2: + case THERMAL_ID_PSU2_1: + case THERMAL_ID_PSU2_2: + rc = psu_thermal_info_get(info, sensor_id); + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + return rc; +} diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_config.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_config.c new file mode 100755 index 00000000..4325b6f5 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_config.c @@ -0,0 +1,101 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +/* */ +#define __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(_x) __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(_x) +x86_64_ingrasys_s9100_config_settings_t x86_64_ingrasys_s9100_config_settings[] = +{ +#ifdef INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING) }, +#else +{ INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef INGRAYSYS_S9100_CONFIG_PORTING_STDLIB + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_PORTING_STDLIB), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_PORTING_STDLIB) }, +#else +{ INGRAYSYS_S9100_CONFIG_PORTING_STDLIB(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI) }, +#else +{ INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef INGRAYSYS_S9100_CONFIG_SFP_COUNT + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_SFP_COUNT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_SFP_COUNT) }, +#else +{ INGRAYSYS_S9100_CONFIG_SFP_COUNT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE +#undef __x86_64_ingrasys_s9100_config_STRINGIFY_NAME + +const char* +x86_64_ingrasys_s9100_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_ingrasys_s9100_config_settings[i].name; i++) { + if(strcmp(x86_64_ingrasys_s9100_config_settings[i].name, setting)) { + return x86_64_ingrasys_s9100_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_ingrasys_s9100_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_ingrasys_s9100_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_ingrasys_s9100_config_settings[i].name, x86_64_ingrasys_s9100_config_settings[i].value); + } + return i; +} + +/* */ + diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_enums.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_enums.c new file mode 100755 index 00000000..6bbc233c --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_enums.c @@ -0,0 +1,30 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_int.h b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_int.h new file mode 100755 index 00000000..f1921224 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_int.h @@ -0,0 +1,29 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#ifndef __x86_64_ingrasys_s9100_INT_H__ +#define __x86_64_ingrasys_s9100_INT_H__ + +#endif /* __x86_64_ingrasys_s9100_INT_H__ */ diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.c new file mode 100755 index 00000000..07f60540 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.c @@ -0,0 +1,38 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +#include "x86_64_ingrasys_s9100_log.h" +/* + * x86_64_ingrasys_s9100 log struct. + */ +AIM_LOG_STRUCT_DEFINE( + INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT, + INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.h b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.h new file mode 100755 index 00000000..2c234703 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.h @@ -0,0 +1,32 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#ifndef __x86_64_ingrasys_s9100_LOG_H__ +#define __x86_64_ingrasys_s9100_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_ingrasys_s9100 +#include + +#endif /* __x86_64_ingrasys_s9100_LOG_H__ */ diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_module.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_module.c new file mode 100755 index 00000000..1a79380e --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_module.c @@ -0,0 +1,44 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +#include "x86_64_ingrasys_s9100_log.h" + +static int +datatypes_init__(void) +{ +#define INGRAYSYS_S9100_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#include + return 0; +} + +void __x86_64_ingrasys_s9100_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_ucli.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_ucli.c new file mode 100755 index 00000000..b359a04c --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_ucli.c @@ -0,0 +1,82 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +#if ONLPSIM_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_ingrasys_s9100_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_ingrasys_s9100) +} + +/* */ +/****************************************************************************** + * + * These handler table(s) were autogenerated from the symbols in this + * source file. + * + *****************************************************************************/ +static ucli_command_handler_f x86_64_ingrasys_s9100_ucli_ucli_handlers__[] = +{ + x86_64_ingrasys_s9100_ucli_ucli__config__, + NULL +}; +/******************************************************************************/ +/* */ + +static ucli_module_t +x86_64_ingrasys_s9100_ucli_module__ = + { + "x86_64_ingrasys_s9100_ucli", + NULL, + x86_64_ingrasys_s9100_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_ingrasys_s9100_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_ingrasys_s9100_ucli_module__); + n = ucli_node_create("x86_64_ingrasys_s9100", NULL, &x86_64_ingrasys_s9100_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_ingrasys_s9100")); + return n; +} + +#else +void* +x86_64_ingrasys_s9100_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/PKG.yml b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/PKG.yml new file mode 100755 index 00000000..afedc8f3 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=ingrasys BASENAME=x86-64-ingrasys-s9100 REVISION=r0 diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/lib/x86-64-ingrasys-s9100-r0.yml b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/lib/x86-64-ingrasys-s9100-r0.yml new file mode 100755 index 00000000..7d45ee0d --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/lib/x86-64-ingrasys-s9100-r0.yml @@ -0,0 +1,30 @@ +--- + +###################################################################### +# +# platform-config for x86-64-ingrasys-s9100 +# +###################################################################### + +x86-64-ingrasys-s9100-r0: + + grub: + + serial: >- + --port=0x2f8 + --speed=115200 + --word=8 + --parity=no + --stop=1 + + kernel: + <<: *kernel-3-16 + + args: >- + console=ttyS1,115200n8 + + ##network + ## interfaces: + ## ma1: + ## name: ~ + ## syspath: pci0000:00/0000:00:03.0 diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py new file mode 100755 index 00000000..86c4ba66 --- /dev/null +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py @@ -0,0 +1,496 @@ +from onl.platform.base import * +from onl.platform.ingrasys import * +import os + +class OnlPlatform_x86_64_ingrasys_s9100_r0(OnlPlatformingrasys): + PLATFORM='x86-64-ingrasys-s9100-r0' + MODEL="s9100" + SYS_OBJECT_ID=".8.1" + + def baseconfig(self): + + self.insmod("eeprom_mb") + self.insmod("w83795") + self.insmod("eeprom") + + ########### initialize I2C bus 1 ########### + self.new_i2c_device('pca9548', 0x70, 1) + + # initialize i2c + self.new_i2c_devices( + [ + ('pca9548', 0x71, 2), + ('pca9548', 0x72, 3), + ('pca9548', 0x73, 4), + ('pca9548', 0x74, 5), + ] + ) + + # initialize SMBUS0 IO Expander + os.system("i2cset -y 0 0x27 4 0x00") + os.system("i2cset -y 0 0x27 5 0x00") + os.system("i2cset -y 0 0x27 2 0x00") + os.system("i2cset -y 0 0x27 3 0x00") + os.system("i2cset -y 0 0x27 6 0xFF") + os.system("i2cset -y 0 0x27 7 0xFF") + + # initialize SMBUS1 ABS + os.system("i2cset -y 6 0x20 4 0x00") + os.system("i2cset -y 6 0x20 5 0x00") + os.system("i2cset -y 6 0x20 6 0xFF") + os.system("i2cset -y 6 0x20 7 0xFF") + + os.system("i2cset -y 6 0x21 4 0x00") + os.system("i2cset -y 6 0x21 5 0x00") + os.system("i2cset -y 6 0x21 6 0xFF") + os.system("i2cset -y 6 0x21 7 0xFF") + # initialize Transcevior INT + os.system("i2cset -y -r 6 0x22 4 0x00") + os.system("i2cset -y -r 6 0x22 5 0x00") + os.system("i2cset -y -r 6 0x22 6 0xFF") + os.system("i2cset -y -r 6 0x22 7 0xFF") + + os.system("i2cset -y -r 6 0x23 4 0x00") + os.system("i2cset -y -r 6 0x23 5 0x00") + os.system("i2cset -y -r 6 0x23 6 0xFF") + os.system("i2cset -y -r 6 0x23 7 0xFF") + + # initialize set ZQSFP LP_MODE = 0 + os.system("i2cset -y -r 7 0x20 4 0x00") + os.system("i2cset -y -r 7 0x20 5 0x00") + os.system("i2cset -y -r 7 0x20 2 0x00") + os.system("i2cset -y -r 7 0x20 3 0x00") + os.system("i2cset -y -r 7 0x20 6 0x00") + os.system("i2cset -y -r 7 0x20 7 0x00") + + os.system("i2cset -y -r 7 0x21 4 0x00") + os.system("i2cset -y -r 7 0x21 5 0x00") + os.system("i2cset -y -r 7 0x21 2 0x00") + os.system("i2cset -y -r 7 0x21 3 0x00") + os.system("i2cset -y -r 7 0x21 6 0x00") + os.system("i2cset -y -r 7 0x21 7 0x00") + + # initialize set ZQSFP RST = 1 + os.system("i2cset -y -r 7 0x22 4 0x00") + os.system("i2cset -y -r 7 0x22 5 0x00") + os.system("i2cset -y -r 7 0x22 2 0xFF") + os.system("i2cset -y -r 7 0x22 3 0xFF") + os.system("i2cset -y -r 7 0x22 6 0x00") + os.system("i2cset -y -r 7 0x22 7 0x00") + + os.system("i2cset -y -r 7 0x23 4 0x00") + os.system("i2cset -y -r 7 0x23 5 0x00") + os.system("i2cset -y -r 7 0x23 2 0xFF") + os.system("i2cset -y -r 7 0x23 3 0xFF") + os.system("i2cset -y -r 7 0x23 6 0x00") + os.system("i2cset -y -r 7 0x23 7 0x00") + + # initialize set ZQSFP mode + os.system("i2cset -y -r 7 0x24 4 0x00") + os.system("i2cset -y -r 7 0x24 5 0x00") + os.system("i2cset -y -r 7 0x24 2 0x00") + os.system("i2cset -y -r 7 0x24 3 0x00") + os.system("i2cset -y -r 7 0x24 6 0x00") + os.system("i2cset -y -r 7 0x24 7 0x00") + + os.system("i2cset -y -r 7 0x25 4 0x00") + os.system("i2cset -y -r 7 0x25 5 0x00") + os.system("i2cset -y -r 7 0x25 2 0x00") + os.system("i2cset -y -r 7 0x25 3 0x00") + os.system("i2cset -y -r 7 0x25 6 0x00") + os.system("i2cset -y -r 7 0x25 7 0x00") + + # initialize ZQSFP/SFP+/E-Card General + os.system("i2cset -y -r 8 0x20 4 0x00") + os.system("i2cset -y -r 8 0x20 5 0x00") + os.system("i2cset -y -r 8 0x20 6 0xFF") + os.system("i2cset -y -r 8 0x20 7 0xFF") + + # initialize LED board after PVT (S9100_IO_EXP_LED_ID) + os.system("i2cset -y -r 9 0x22 4 0x00") + os.system("i2cset -y -r 9 0x22 5 0x00") + os.system("i2cset -y -r 9 0x22 6 0x00") + os.system("i2cset -y -r 9 0x22 7 0x00") + + # initialize PSU I/O (S9100_IO_EXP_PSU_ID) + os.system("i2cset -y -r 8 0x23 4 0x00") + os.system("i2cset -y -r 8 0x23 5 0x00") + os.system("i2cset -y -r 8 0x23 2 0x00") + os.system("i2cset -y -r 8 0x23 3 0x00") + os.system("i2cset -y -r 8 0x23 6 0xBB") + os.system("i2cset -y -r 8 0x23 7 0xFF") + + # initialize ABS Port 0-15 + self.new_i2c_device('pca9535', 0x20, 6) + os.system("echo 496 > /sys/class/gpio/export") + os.system("echo 497 > /sys/class/gpio/export") + os.system("echo 498 > /sys/class/gpio/export") + os.system("echo 499 > /sys/class/gpio/export") + os.system("echo 500 > /sys/class/gpio/export") + os.system("echo 501 > /sys/class/gpio/export") + os.system("echo 502 > /sys/class/gpio/export") + os.system("echo 503 > /sys/class/gpio/export") + os.system("echo 504 > /sys/class/gpio/export") + os.system("echo 505 > /sys/class/gpio/export") + os.system("echo 506 > /sys/class/gpio/export") + os.system("echo 507 > /sys/class/gpio/export") + os.system("echo 508 > /sys/class/gpio/export") + os.system("echo 509 > /sys/class/gpio/export") + os.system("echo 510 > /sys/class/gpio/export") + os.system("echo 511 > /sys/class/gpio/export") + os.system("echo 1 > /sys/class/gpio/gpio496/active_low") + os.system("echo 1 > /sys/class/gpio/gpio497/active_low") + os.system("echo 1 > /sys/class/gpio/gpio498/active_low") + os.system("echo 1 > /sys/class/gpio/gpio499/active_low") + os.system("echo 1 > /sys/class/gpio/gpio500/active_low") + os.system("echo 1 > /sys/class/gpio/gpio501/active_low") + os.system("echo 1 > /sys/class/gpio/gpio502/active_low") + os.system("echo 1 > /sys/class/gpio/gpio503/active_low") + os.system("echo 1 > /sys/class/gpio/gpio504/active_low") + os.system("echo 1 > /sys/class/gpio/gpio505/active_low") + os.system("echo 1 > /sys/class/gpio/gpio506/active_low") + os.system("echo 1 > /sys/class/gpio/gpio507/active_low") + os.system("echo 1 > /sys/class/gpio/gpio508/active_low") + os.system("echo 1 > /sys/class/gpio/gpio509/active_low") + os.system("echo 1 > /sys/class/gpio/gpio510/active_low") + os.system("echo 1 > /sys/class/gpio/gpio511/active_low") + + # initialize ABS Port 16-31 + self.new_i2c_device('pca9535', 0x21, 6) + os.system("echo 480 > /sys/class/gpio/export") + os.system("echo 481 > /sys/class/gpio/export") + os.system("echo 482 > /sys/class/gpio/export") + os.system("echo 483 > /sys/class/gpio/export") + os.system("echo 484 > /sys/class/gpio/export") + os.system("echo 485 > /sys/class/gpio/export") + os.system("echo 486 > /sys/class/gpio/export") + os.system("echo 487 > /sys/class/gpio/export") + os.system("echo 488 > /sys/class/gpio/export") + os.system("echo 489 > /sys/class/gpio/export") + os.system("echo 490 > /sys/class/gpio/export") + os.system("echo 491 > /sys/class/gpio/export") + os.system("echo 492 > /sys/class/gpio/export") + os.system("echo 493 > /sys/class/gpio/export") + os.system("echo 494 > /sys/class/gpio/export") + os.system("echo 495 > /sys/class/gpio/export") + os.system("echo 1 > /sys/class/gpio/gpio480/active_low") + os.system("echo 1 > /sys/class/gpio/gpio481/active_low") + os.system("echo 1 > /sys/class/gpio/gpio482/active_low") + os.system("echo 1 > /sys/class/gpio/gpio483/active_low") + os.system("echo 1 > /sys/class/gpio/gpio484/active_low") + os.system("echo 1 > /sys/class/gpio/gpio485/active_low") + os.system("echo 1 > /sys/class/gpio/gpio486/active_low") + os.system("echo 1 > /sys/class/gpio/gpio487/active_low") + os.system("echo 1 > /sys/class/gpio/gpio488/active_low") + os.system("echo 1 > /sys/class/gpio/gpio489/active_low") + os.system("echo 1 > /sys/class/gpio/gpio490/active_low") + os.system("echo 1 > /sys/class/gpio/gpio491/active_low") + os.system("echo 1 > /sys/class/gpio/gpio492/active_low") + os.system("echo 1 > /sys/class/gpio/gpio493/active_low") + os.system("echo 1 > /sys/class/gpio/gpio494/active_low") + os.system("echo 1 > /sys/class/gpio/gpio495/active_low") + + # initialize INT Port 0-15 + self.new_i2c_device('pca9535', 0x22, 6) + os.system("echo 464 > /sys/class/gpio/export") + os.system("echo 465 > /sys/class/gpio/export") + os.system("echo 466 > /sys/class/gpio/export") + os.system("echo 467 > /sys/class/gpio/export") + os.system("echo 468 > /sys/class/gpio/export") + os.system("echo 469 > /sys/class/gpio/export") + os.system("echo 470 > /sys/class/gpio/export") + os.system("echo 471 > /sys/class/gpio/export") + os.system("echo 472 > /sys/class/gpio/export") + os.system("echo 473 > /sys/class/gpio/export") + os.system("echo 474 > /sys/class/gpio/export") + os.system("echo 475 > /sys/class/gpio/export") + os.system("echo 476 > /sys/class/gpio/export") + os.system("echo 477 > /sys/class/gpio/export") + os.system("echo 478 > /sys/class/gpio/export") + os.system("echo 479 > /sys/class/gpio/export") + os.system("echo 1 > /sys/class/gpio/gpio464/active_low") + os.system("echo 1 > /sys/class/gpio/gpio465/active_low") + os.system("echo 1 > /sys/class/gpio/gpio466/active_low") + os.system("echo 1 > /sys/class/gpio/gpio467/active_low") + os.system("echo 1 > /sys/class/gpio/gpio468/active_low") + os.system("echo 1 > /sys/class/gpio/gpio469/active_low") + os.system("echo 1 > /sys/class/gpio/gpio470/active_low") + os.system("echo 1 > /sys/class/gpio/gpio471/active_low") + os.system("echo 1 > /sys/class/gpio/gpio472/active_low") + os.system("echo 1 > /sys/class/gpio/gpio473/active_low") + os.system("echo 1 > /sys/class/gpio/gpio474/active_low") + os.system("echo 1 > /sys/class/gpio/gpio475/active_low") + os.system("echo 1 > /sys/class/gpio/gpio476/active_low") + os.system("echo 1 > /sys/class/gpio/gpio477/active_low") + os.system("echo 1 > /sys/class/gpio/gpio478/active_low") + os.system("echo 1 > /sys/class/gpio/gpio479/active_low") + + # initialize INT Port 16-31 + self.new_i2c_device('pca9535', 0x23, 6) + os.system("echo 448 > /sys/class/gpio/export") + os.system("echo 449 > /sys/class/gpio/export") + os.system("echo 450 > /sys/class/gpio/export") + os.system("echo 451 > /sys/class/gpio/export") + os.system("echo 452 > /sys/class/gpio/export") + os.system("echo 453 > /sys/class/gpio/export") + os.system("echo 454 > /sys/class/gpio/export") + os.system("echo 455 > /sys/class/gpio/export") + os.system("echo 456 > /sys/class/gpio/export") + os.system("echo 457 > /sys/class/gpio/export") + os.system("echo 458 > /sys/class/gpio/export") + os.system("echo 459 > /sys/class/gpio/export") + os.system("echo 460 > /sys/class/gpio/export") + os.system("echo 461 > /sys/class/gpio/export") + os.system("echo 462 > /sys/class/gpio/export") + os.system("echo 463 > /sys/class/gpio/export") + os.system("echo 1 > /sys/class/gpio/gpio448/active_low") + os.system("echo 1 > /sys/class/gpio/gpio449/active_low") + os.system("echo 1 > /sys/class/gpio/gpio450/active_low") + os.system("echo 1 > /sys/class/gpio/gpio451/active_low") + os.system("echo 1 > /sys/class/gpio/gpio452/active_low") + os.system("echo 1 > /sys/class/gpio/gpio453/active_low") + os.system("echo 1 > /sys/class/gpio/gpio454/active_low") + os.system("echo 1 > /sys/class/gpio/gpio455/active_low") + os.system("echo 1 > /sys/class/gpio/gpio456/active_low") + os.system("echo 1 > /sys/class/gpio/gpio457/active_low") + os.system("echo 1 > /sys/class/gpio/gpio458/active_low") + os.system("echo 1 > /sys/class/gpio/gpio459/active_low") + os.system("echo 1 > /sys/class/gpio/gpio460/active_low") + os.system("echo 1 > /sys/class/gpio/gpio461/active_low") + os.system("echo 1 > /sys/class/gpio/gpio462/active_low") + os.system("echo 1 > /sys/class/gpio/gpio463/active_low") + + # initialize LP Mode Port 0-15 + self.new_i2c_device('pca9535', 0x20, 7) + os.system("echo 432 > /sys/class/gpio/export") + os.system("echo 433 > /sys/class/gpio/export") + os.system("echo 434 > /sys/class/gpio/export") + os.system("echo 435 > /sys/class/gpio/export") + os.system("echo 436 > /sys/class/gpio/export") + os.system("echo 437 > /sys/class/gpio/export") + os.system("echo 438 > /sys/class/gpio/export") + os.system("echo 439 > /sys/class/gpio/export") + os.system("echo 440 > /sys/class/gpio/export") + os.system("echo 441 > /sys/class/gpio/export") + os.system("echo 442 > /sys/class/gpio/export") + os.system("echo 443 > /sys/class/gpio/export") + os.system("echo 444 > /sys/class/gpio/export") + os.system("echo 445 > /sys/class/gpio/export") + os.system("echo 446 > /sys/class/gpio/export") + os.system("echo 447 > /sys/class/gpio/export") + os.system("echo out > /sys/class/gpio/gpio432/direction") + os.system("echo out > /sys/class/gpio/gpio433/direction") + os.system("echo out > /sys/class/gpio/gpio434/direction") + os.system("echo out > /sys/class/gpio/gpio435/direction") + os.system("echo out > /sys/class/gpio/gpio436/direction") + os.system("echo out > /sys/class/gpio/gpio437/direction") + os.system("echo out > /sys/class/gpio/gpio438/direction") + os.system("echo out > /sys/class/gpio/gpio439/direction") + os.system("echo out > /sys/class/gpio/gpio440/direction") + os.system("echo out > /sys/class/gpio/gpio441/direction") + os.system("echo out > /sys/class/gpio/gpio442/direction") + os.system("echo out > /sys/class/gpio/gpio443/direction") + os.system("echo out > /sys/class/gpio/gpio444/direction") + os.system("echo out > /sys/class/gpio/gpio445/direction") + os.system("echo out > /sys/class/gpio/gpio446/direction") + os.system("echo out > /sys/class/gpio/gpio447/direction") + + # initialize LP Mode Port 16-31 + self.new_i2c_device('pca9535', 0x21, 7) + os.system("echo 416 > /sys/class/gpio/export") + os.system("echo 417 > /sys/class/gpio/export") + os.system("echo 418 > /sys/class/gpio/export") + os.system("echo 419 > /sys/class/gpio/export") + os.system("echo 420 > /sys/class/gpio/export") + os.system("echo 421 > /sys/class/gpio/export") + os.system("echo 422 > /sys/class/gpio/export") + os.system("echo 423 > /sys/class/gpio/export") + os.system("echo 424 > /sys/class/gpio/export") + os.system("echo 425 > /sys/class/gpio/export") + os.system("echo 426 > /sys/class/gpio/export") + os.system("echo 427 > /sys/class/gpio/export") + os.system("echo 428 > /sys/class/gpio/export") + os.system("echo 429 > /sys/class/gpio/export") + os.system("echo 430 > /sys/class/gpio/export") + os.system("echo 431 > /sys/class/gpio/export") + + os.system("echo out > /sys/class/gpio/gpio416/direction") + os.system("echo out > /sys/class/gpio/gpio417/direction") + os.system("echo out > /sys/class/gpio/gpio418/direction") + os.system("echo out > /sys/class/gpio/gpio419/direction") + os.system("echo out > /sys/class/gpio/gpio420/direction") + os.system("echo out > /sys/class/gpio/gpio421/direction") + os.system("echo out > /sys/class/gpio/gpio422/direction") + os.system("echo out > /sys/class/gpio/gpio423/direction") + os.system("echo out > /sys/class/gpio/gpio424/direction") + os.system("echo out > /sys/class/gpio/gpio425/direction") + os.system("echo out > /sys/class/gpio/gpio426/direction") + os.system("echo out > /sys/class/gpio/gpio427/direction") + os.system("echo out > /sys/class/gpio/gpio428/direction") + os.system("echo out > /sys/class/gpio/gpio429/direction") + os.system("echo out > /sys/class/gpio/gpio430/direction") + os.system("echo out > /sys/class/gpio/gpio431/direction") + + # initialize RST Port 0-15 + self.new_i2c_device('pca9535', 0x22, 7) + os.system("echo 400 > /sys/class/gpio/export") + os.system("echo 401 > /sys/class/gpio/export") + os.system("echo 402 > /sys/class/gpio/export") + os.system("echo 403 > /sys/class/gpio/export") + os.system("echo 404 > /sys/class/gpio/export") + os.system("echo 405 > /sys/class/gpio/export") + os.system("echo 406 > /sys/class/gpio/export") + os.system("echo 407 > /sys/class/gpio/export") + os.system("echo 408 > /sys/class/gpio/export") + os.system("echo 409 > /sys/class/gpio/export") + os.system("echo 410 > /sys/class/gpio/export") + os.system("echo 411 > /sys/class/gpio/export") + os.system("echo 412 > /sys/class/gpio/export") + os.system("echo 413 > /sys/class/gpio/export") + os.system("echo 414 > /sys/class/gpio/export") + os.system("echo 415 > /sys/class/gpio/export") + os.system("echo out > /sys/class/gpio/gpio400/direction") + os.system("echo out > /sys/class/gpio/gpio401/direction") + os.system("echo out > /sys/class/gpio/gpio402/direction") + os.system("echo out > /sys/class/gpio/gpio403/direction") + os.system("echo out > /sys/class/gpio/gpio404/direction") + os.system("echo out > /sys/class/gpio/gpio405/direction") + os.system("echo out > /sys/class/gpio/gpio406/direction") + os.system("echo out > /sys/class/gpio/gpio407/direction") + os.system("echo out > /sys/class/gpio/gpio408/direction") + os.system("echo out > /sys/class/gpio/gpio409/direction") + os.system("echo out > /sys/class/gpio/gpio410/direction") + os.system("echo out > /sys/class/gpio/gpio411/direction") + os.system("echo out > /sys/class/gpio/gpio412/direction") + os.system("echo out > /sys/class/gpio/gpio413/direction") + os.system("echo out > /sys/class/gpio/gpio414/direction") + os.system("echo out > /sys/class/gpio/gpio415/direction") + + # initialize RST Port 16-31 + self.new_i2c_device('pca9535', 0x23, 7) + os.system("echo 384 > /sys/class/gpio/export") + os.system("echo 385 > /sys/class/gpio/export") + os.system("echo 386 > /sys/class/gpio/export") + os.system("echo 387 > /sys/class/gpio/export") + os.system("echo 388 > /sys/class/gpio/export") + os.system("echo 389 > /sys/class/gpio/export") + os.system("echo 390 > /sys/class/gpio/export") + os.system("echo 391 > /sys/class/gpio/export") + os.system("echo 392 > /sys/class/gpio/export") + os.system("echo 393 > /sys/class/gpio/export") + os.system("echo 394 > /sys/class/gpio/export") + os.system("echo 395 > /sys/class/gpio/export") + os.system("echo 396 > /sys/class/gpio/export") + os.system("echo 397 > /sys/class/gpio/export") + os.system("echo 398 > /sys/class/gpio/export") + os.system("echo 399 > /sys/class/gpio/export") + os.system("echo out > /sys/class/gpio/gpio384/direction") + os.system("echo out > /sys/class/gpio/gpio385/direction") + os.system("echo out > /sys/class/gpio/gpio386/direction") + os.system("echo out > /sys/class/gpio/gpio387/direction") + os.system("echo out > /sys/class/gpio/gpio388/direction") + os.system("echo out > /sys/class/gpio/gpio389/direction") + os.system("echo out > /sys/class/gpio/gpio390/direction") + os.system("echo out > /sys/class/gpio/gpio391/direction") + os.system("echo out > /sys/class/gpio/gpio392/direction") + os.system("echo out > /sys/class/gpio/gpio393/direction") + os.system("echo out > /sys/class/gpio/gpio394/direction") + os.system("echo out > /sys/class/gpio/gpio395/direction") + os.system("echo out > /sys/class/gpio/gpio396/direction") + os.system("echo out > /sys/class/gpio/gpio397/direction") + os.system("echo out > /sys/class/gpio/gpio398/direction") + os.system("echo out > /sys/class/gpio/gpio399/direction") + + # initialize MODSEL Port 0-15 + self.new_i2c_device('pca9535', 0x24, 7) + os.system("echo 368 > /sys/class/gpio/export") + os.system("echo 369 > /sys/class/gpio/export") + os.system("echo 370 > /sys/class/gpio/export") + os.system("echo 371 > /sys/class/gpio/export") + os.system("echo 372 > /sys/class/gpio/export") + os.system("echo 373 > /sys/class/gpio/export") + os.system("echo 374 > /sys/class/gpio/export") + os.system("echo 375 > /sys/class/gpio/export") + os.system("echo 376 > /sys/class/gpio/export") + os.system("echo 377 > /sys/class/gpio/export") + os.system("echo 378 > /sys/class/gpio/export") + os.system("echo 379 > /sys/class/gpio/export") + os.system("echo 380 > /sys/class/gpio/export") + os.system("echo 381 > /sys/class/gpio/export") + os.system("echo 382 > /sys/class/gpio/export") + os.system("echo 383 > /sys/class/gpio/export") + os.system("echo out > /sys/class/gpio/gpio368/direction") + os.system("echo out > /sys/class/gpio/gpio369/direction") + os.system("echo out > /sys/class/gpio/gpio370/direction") + os.system("echo out > /sys/class/gpio/gpio371/direction") + os.system("echo out > /sys/class/gpio/gpio372/direction") + os.system("echo out > /sys/class/gpio/gpio373/direction") + os.system("echo out > /sys/class/gpio/gpio374/direction") + os.system("echo out > /sys/class/gpio/gpio375/direction") + os.system("echo out > /sys/class/gpio/gpio376/direction") + os.system("echo out > /sys/class/gpio/gpio377/direction") + os.system("echo out > /sys/class/gpio/gpio378/direction") + os.system("echo out > /sys/class/gpio/gpio379/direction") + os.system("echo out > /sys/class/gpio/gpio380/direction") + os.system("echo out > /sys/class/gpio/gpio381/direction") + os.system("echo out > /sys/class/gpio/gpio382/direction") + os.system("echo out > /sys/class/gpio/gpio383/direction") + + # initialize MODSEL Port 16-31 + self.new_i2c_device('pca9535', 0x25, 7) + os.system("echo 352 > /sys/class/gpio/export") + os.system("echo 353> /sys/class/gpio/export") + os.system("echo 354> /sys/class/gpio/export") + os.system("echo 355> /sys/class/gpio/export") + os.system("echo 356 > /sys/class/gpio/export") + os.system("echo 357 > /sys/class/gpio/export") + os.system("echo 358 > /sys/class/gpio/export") + os.system("echo 359 > /sys/class/gpio/export") + os.system("echo 360 > /sys/class/gpio/export") + os.system("echo 361 > /sys/class/gpio/export") + os.system("echo 362 > /sys/class/gpio/export") + os.system("echo 363 > /sys/class/gpio/export") + os.system("echo 364 > /sys/class/gpio/export") + os.system("echo 365 > /sys/class/gpio/export") + os.system("echo 366 > /sys/class/gpio/export") + os.system("echo 367 > /sys/class/gpio/export") + os.system("echo out > /sys/class/gpio/gpio352/direction") + os.system("echo out > /sys/class/gpio/gpio353/direction") + os.system("echo out > /sys/class/gpio/gpio354/direction") + os.system("echo out > /sys/class/gpio/gpio355/direction") + os.system("echo out > /sys/class/gpio/gpio356/direction") + os.system("echo out > /sys/class/gpio/gpio357/direction") + os.system("echo out > /sys/class/gpio/gpio358/direction") + os.system("echo out > /sys/class/gpio/gpio359/direction") + os.system("echo out > /sys/class/gpio/gpio360/direction") + os.system("echo out > /sys/class/gpio/gpio361/direction") + os.system("echo out > /sys/class/gpio/gpio362/direction") + os.system("echo out > /sys/class/gpio/gpio363/direction") + os.system("echo out > /sys/class/gpio/gpio364/direction") + os.system("echo out > /sys/class/gpio/gpio365/direction") + os.system("echo out > /sys/class/gpio/gpio366/direction") + os.system("echo out > /sys/class/gpio/gpio367/direction") + + # initialize qsfp eeprom + for port in range(1, 33): + self.new_i2c_device('sff8436', 0x50, port + 9) + + # initialize sys eeprom devices + self.new_i2c_device('mb_eeprom', 0x54, 9) + + # initialize temperature sensor + os.system("i2cset -y -r -f 0 0x2F 0x00 0x80") + os.system("i2cset -y -r -f 0 0x2F 0x05 0x7F") + os.system("i2cset -y -r -f 0 0x2F 0x04 0x0A") + + # initialize psu eeprom devices + self.new_i2c_device('eeprom', 0x50, 8) + self.new_i2c_device('eeprom', 0x50, 9) + + # initialize sys led + os.system("i2cset -m 0x40 -y -r 9 0x22 2 0xFF") + os.system("i2cset -m 0x80 -y -r 9 0x22 2 0x00") + + return True + + From 32a1e64c4be2529844948a929e57c3834419c3ac Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 25 Aug 2017 10:51:32 -0700 Subject: [PATCH 43/67] Move ESP to standard location --- builds/any/rootfs/jessie/common/overlay/etc/mtab.yml | 2 +- packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml b/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml index 17e0a6bc..e04f3666 100644 --- a/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml +++ b/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml @@ -21,7 +21,7 @@ mounts: # ESP (EFI system partition) EFI-BOOT: mount: ro - dir: /mnt/onl/efi-boot + dir: /boot/efi fsck: false label: EFI System optional: true diff --git a/packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml b/packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml index 17abb840..051105c7 100644 --- a/packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml +++ b/packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml @@ -22,7 +22,7 @@ mounts: # ESP (EFI system partition) EFI-BOOT: mount: ro - dir: /mnt/onl/efi-boot + dir: /boot/efi fsck: false label: EFI System optional: true From b0c8892e6600901a6234ecff218b2551479dc69e Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 25 Aug 2017 10:51:49 -0700 Subject: [PATCH 44/67] Port EFI support to stretch --- builds/any/rootfs/stretch/common/amd64-base-packages.yml | 2 ++ builds/any/rootfs/stretch/common/overlay/etc/mtab.yml | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/builds/any/rootfs/stretch/common/amd64-base-packages.yml b/builds/any/rootfs/stretch/common/amd64-base-packages.yml index a07863f3..efaf425b 100644 --- a/builds/any/rootfs/stretch/common/amd64-base-packages.yml +++ b/builds/any/rootfs/stretch/common/amd64-base-packages.yml @@ -11,3 +11,5 @@ - hw-management - sx-kernel - onl-kernel-3.16-lts-x86-64-all-modules +- efibootmgr +- gdisk diff --git a/builds/any/rootfs/stretch/common/overlay/etc/mtab.yml b/builds/any/rootfs/stretch/common/overlay/etc/mtab.yml index 598e4c69..e04f3666 100644 --- a/builds/any/rootfs/stretch/common/overlay/etc/mtab.yml +++ b/builds/any/rootfs/stretch/common/overlay/etc/mtab.yml @@ -17,3 +17,11 @@ mounts: mount: ro dir: /mnt/onl/boot fsck: false + + # ESP (EFI system partition) + EFI-BOOT: + mount: ro + dir: /boot/efi + fsck: false + label: EFI System + optional: true From 361412676650253755cff2cebc597540fc77be22 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 29 Aug 2017 22:00:06 +0000 Subject: [PATCH 45/67] Switch build-artifacts to public URL. --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 20df3fba..868f1568 100644 --- a/.gitmodules +++ b/.gitmodules @@ -18,4 +18,4 @@ url = git@github.com:opennetworklinux/platforms-closed [submodule "sm/build-artifacts"] path = sm/build-artifacts - url = git@github.com:opennetworklinux/build-artifacts + url = git://github.com/opennetworklinux/build-artifacts From fc13e7688759598aabf7bc8203d6160238002976 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Wed, 30 Aug 2017 17:14:54 -0700 Subject: [PATCH 46/67] Attempt to sync to upstream --- sm/infra | 1 + 1 file changed, 1 insertion(+) create mode 160000 sm/infra diff --git a/sm/infra b/sm/infra new file mode 160000 index 00000000..fd74bf9c --- /dev/null +++ b/sm/infra @@ -0,0 +1 @@ +Subproject commit fd74bf9c3fa31901ef3570a1b02e5a9621232fbe From 6dbd880959e1949d916cbf2ce8aceca5efc20df4 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Wed, 30 Aug 2017 17:07:18 -0700 Subject: [PATCH 47/67] Use gdisk recovery commands - recover from a corrupted/misplaced backup partition table --- .../vendor-config-onl/src/lib/install/lib.sh | 93 ++++++++++++++----- 1 file changed, 70 insertions(+), 23 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/lib/install/lib.sh b/packages/base/all/vendor-config-onl/src/lib/install/lib.sh index 72f6290f..0a5ea184 100644 --- a/packages/base/all/vendor-config-onl/src/lib/install/lib.sh +++ b/packages/base/all/vendor-config-onl/src/lib/install/lib.sh @@ -236,7 +236,7 @@ blkid_find_gpt_boot() { } installer_fixup_gpt() { - local buf dat sts dev + local buf dat sts dev do_recover buf=$(mktemp -u -t sgdisk-XXXXXX) @@ -264,32 +264,79 @@ installer_fixup_gpt() { fi test -b "$dev" || return 0 - # see if it's a clean GPT partition table - if sgdisk -p "$dev" > "$buf" 2>&1; then - sts=0 + do_recover= + + # simple validation using sgdisk + if test "$do_recover"; then + : else - sts=$? - fi - if test $sts -ne 0; then - cat "$buf" 1>&2 - rm -f "$buf" - installer_say "Cannot reliably get GPT partition table" - return 1 - fi + if sgdisk -p "$dev" > "$buf" 2>&1; then + sts=0 + else + sts=$? + fi + if test $sts -ne 0; then + cat "$buf" 1>&2 + rm -f "$buf" + installer_say "Cannot reliably get GPT partition table" + return 1 + fi - case $(cat "$buf") in - *Caution*|*Warning*) - cat $buf 1>&2 - installer_say "Found issues with the GPT partition table" - rm -f "$buf" - ;; - *) - installer_say "Found a clean GPT partition table" - rm -f "$buf" - return 0 + case $(cat "$buf") in + *Caution*|*Warning*) + cat $buf 1>&2 + installer_say "Found issues with the GPT partition table" + do_recover=1 + rm -f "$buf" ;; - esac + esac + fi + + # more thorough validation + if test "$do_recover"; then + : + else + + local inp + inp=$(mktemp -u -t sgdisk-XXXXXX) + cat > "$inp" <<-END + x + r + v + q + END + if gdisk "$dev" < "$inp" > "$buf" 2>&1; then + sts=0 + else + sts=$? + fi + rm -f "$inp" + if test $sts -ne 0; then + cat "$buf" 1>&2 + rm -f "$buf" + installer_say "Cannot reliably verify GPT partition table" + return 1 + fi + + case $(cat "$buf") in + *Caution*|*Warning*|*Problem:*) + cat $buf 1>&2 + installer_say "Found issues with the GPT partition table" + do_recover=1 + rm -f "$buf" + ;; + esac + + fi + + if test "$do_recover"; then + : + else + installer_say "Found a clean GPT partition table" + rm -f "$buf" + return 0 + fi installer_say "Attempting to correct the GPT partition table" # this is the simple method; gdisk/sfgdisk will correct From 4cde76b3f5924ddc1fab87ea9e4d095ef8d085ac Mon Sep 17 00:00:00 2001 From: Zi Zhou Date: Fri, 1 Sep 2017 18:35:41 -0700 Subject: [PATCH 48/67] Support 100G PSM4 optics --- packages/base/any/onlp/src/sff/module/auto/sff.yml | 2 ++ packages/base/any/onlp/src/sff/module/inc/sff/8636.h | 2 ++ packages/base/any/onlp/src/sff/module/inc/sff/sff.h | 2 ++ packages/base/any/onlp/src/sff/module/inc/sff/sff.x | 2 ++ packages/base/any/onlp/src/sff/module/src/sff.c | 8 ++++++++ packages/base/any/onlp/src/sff/module/src/sff_enums.c | 2 ++ packages/base/any/onlp/src/sff/sff.mk | 2 +- 7 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/base/any/onlp/src/sff/module/auto/sff.yml b/packages/base/any/onlp/src/sff/module/auto/sff.yml index 8977bcad..295fe6bf 100644 --- a/packages/base/any/onlp/src/sff/module/auto/sff.yml +++ b/packages/base/any/onlp/src/sff/module/auto/sff.yml @@ -53,6 +53,8 @@ sff_module_types: &sff_module_types desc: "100GBASE-LR4" - 100G_CWDM4: desc: "100G-CWDM4" +- 100G_PSM4: + desc: "100G-PSM4" - 40G_BASE_CR4: desc: "40GBASE-CR4" - 40G_BASE_SR4: diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/8636.h b/packages/base/any/onlp/src/sff/module/inc/sff/8636.h index e5ba6da4..4f87c170 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/8636.h +++ b/packages/base/any/onlp/src/sff/module/inc/sff/8636.h @@ -144,6 +144,8 @@ (idprom[192] == SFF8636_CC192_100GE_LR4) #define SFF8636_MEDIA_100GE_CWDM4(idprom) \ (idprom[192] == SFF8636_CC192_100GE_CWDM4) +#define SFF8636_MEDIA_100GE_PSM4(idprom) \ + (idprom[192] == SFF8636_CC192_100GE_PSM4) #define SFF8636_MEDIA_100GE_CR4(idprom) \ (idprom[192] == SFF8636_CC192_100GE_CR4) #define SFF8636_MEDIA_25GE_CR_S(idprom) \ diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/sff.h b/packages/base/any/onlp/src/sff/module/inc/sff/sff.h index 367b6c0e..be0d1725 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/sff.h +++ b/packages/base/any/onlp/src/sff/module/inc/sff/sff.h @@ -102,6 +102,7 @@ typedef enum sff_module_type_e { SFF_MODULE_TYPE_100G_BASE_SR4, SFF_MODULE_TYPE_100G_BASE_LR4, SFF_MODULE_TYPE_100G_CWDM4, + SFF_MODULE_TYPE_100G_PSM4, SFF_MODULE_TYPE_40G_BASE_CR4, SFF_MODULE_TYPE_40G_BASE_SR4, SFF_MODULE_TYPE_40G_BASE_LR4, @@ -141,6 +142,7 @@ typedef enum sff_module_type_e { "100G_BASE_SR4", \ "100G_BASE_LR4", \ "100G_CWDM4", \ + "100G_PSM4", \ "40G_BASE_CR4", \ "40G_BASE_SR4", \ "40G_BASE_LR4", \ diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/sff.x b/packages/base/any/onlp/src/sff/module/inc/sff/sff.x index 1efe7884..ba315949 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/sff.x +++ b/packages/base/any/onlp/src/sff/module/inc/sff/sff.x @@ -12,6 +12,7 @@ SFF_MEDIA_TYPE_ENTRY(100G_BASE_CR4, 100GBASE-CR4) SFF_MEDIA_TYPE_ENTRY(100G_BASE_SR4, 100GBASE-SR4) SFF_MEDIA_TYPE_ENTRY(100G_BASE_LR4, 100GBASE-LR4) SFF_MEDIA_TYPE_ENTRY(100G_CWDM4, 100G-CWDM4) +SFF_MEDIA_TYPE_ENTRY(100G_PSM4, 100G-PSM4) SFF_MEDIA_TYPE_ENTRY(40G_BASE_CR4, 40GBASE-CR4) SFF_MEDIA_TYPE_ENTRY(40G_BASE_SR4, 40GBASE-SR4) SFF_MEDIA_TYPE_ENTRY(40G_BASE_LR4, 40GBASE-LR4) @@ -57,6 +58,7 @@ SFF_MODULE_TYPE_ENTRY(100G_BASE_CR4, 100GBASE-CR4) SFF_MODULE_TYPE_ENTRY(100G_BASE_SR4, 100GBASE-SR4) SFF_MODULE_TYPE_ENTRY(100G_BASE_LR4, 100GBASE-LR4) SFF_MODULE_TYPE_ENTRY(100G_CWDM4, 100G-CWDM4) +SFF_MODULE_TYPE_ENTRY(100G_PSM4, 100G-PSM4) SFF_MODULE_TYPE_ENTRY(40G_BASE_CR4, 40GBASE-CR4) SFF_MODULE_TYPE_ENTRY(40G_BASE_SR4, 40GBASE-SR4) SFF_MODULE_TYPE_ENTRY(40G_BASE_LR4, 40GBASE-LR4) diff --git a/packages/base/any/onlp/src/sff/module/src/sff.c b/packages/base/any/onlp/src/sff/module/src/sff.c index 34a554a0..b866c741 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff.c +++ b/packages/base/any/onlp/src/sff/module/src/sff.c @@ -76,6 +76,11 @@ sff_module_type_get(const uint8_t* eeprom) && SFF8636_MEDIA_100GE_CWDM4(eeprom)) return SFF_MODULE_TYPE_100G_CWDM4; + if (SFF8636_MODULE_QSFP28(eeprom) + && SFF8636_MEDIA_EXTENDED(eeprom) + && SFF8636_MEDIA_100GE_PSM4(eeprom)) + return SFF_MODULE_TYPE_100G_PSM4; + if (SFF8436_MODULE_QSFP_PLUS_V2(eeprom) && SFF8436_MEDIA_40GE_CR4(eeprom)) return SFF_MODULE_TYPE_40G_BASE_CR4; @@ -241,6 +246,7 @@ sff_media_type_get(sff_module_type_t mt) case SFF_MODULE_TYPE_100G_BASE_SR4: case SFF_MODULE_TYPE_100G_BASE_LR4: case SFF_MODULE_TYPE_100G_CWDM4: + case SFF_MODULE_TYPE_100G_PSM4: case SFF_MODULE_TYPE_40G_BASE_SR4: case SFF_MODULE_TYPE_40G_BASE_LR4: case SFF_MODULE_TYPE_40G_BASE_LM4: @@ -286,6 +292,7 @@ sff_module_caps_get(sff_module_type_t mt, uint32_t *caps) case SFF_MODULE_TYPE_100G_BASE_LR4: case SFF_MODULE_TYPE_100G_BASE_CR4: case SFF_MODULE_TYPE_100G_CWDM4: + case SFF_MODULE_TYPE_100G_PSM4: *caps |= SFF_MODULE_CAPS_F_100G; return 0; @@ -677,6 +684,7 @@ sff_info_init(sff_info_t* info, sff_module_type_t mt, case SFF_MODULE_TYPE_100G_BASE_SR4: case SFF_MODULE_TYPE_100G_BASE_LR4: case SFF_MODULE_TYPE_100G_CWDM4: + case SFF_MODULE_TYPE_100G_PSM4: info->sfp_type = SFF_SFP_TYPE_QSFP28; info->media_type = SFF_MEDIA_TYPE_FIBER; info->caps = SFF_MODULE_CAPS_F_100G; diff --git a/packages/base/any/onlp/src/sff/module/src/sff_enums.c b/packages/base/any/onlp/src/sff/module/src/sff_enums.c index b2ce8fc3..29eb27b6 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff_enums.c +++ b/packages/base/any/onlp/src/sff/module/src/sff_enums.c @@ -136,6 +136,7 @@ aim_map_si_t sff_module_type_map[] = { "100G_BASE_SR4", SFF_MODULE_TYPE_100G_BASE_SR4 }, { "100G_BASE_LR4", SFF_MODULE_TYPE_100G_BASE_LR4 }, { "100G_CWDM4", SFF_MODULE_TYPE_100G_CWDM4 }, + { "100G_PSM4", SFF_MODULE_TYPE_100G_PSM4 }, { "40G_BASE_CR4", SFF_MODULE_TYPE_40G_BASE_CR4 }, { "40G_BASE_SR4", SFF_MODULE_TYPE_40G_BASE_SR4 }, { "40G_BASE_LR4", SFF_MODULE_TYPE_40G_BASE_LR4 }, @@ -172,6 +173,7 @@ aim_map_si_t sff_module_type_desc_map[] = { "100GBASE-SR4", SFF_MODULE_TYPE_100G_BASE_SR4 }, { "100GBASE-LR4", SFF_MODULE_TYPE_100G_BASE_LR4 }, { "100G-CWDM4", SFF_MODULE_TYPE_100G_CWDM4 }, + { "100G-PSM4", SFF_MODULE_TYPE_100G_PSM4 }, { "40GBASE-CR4", SFF_MODULE_TYPE_40G_BASE_CR4 }, { "40GBASE-SR4", SFF_MODULE_TYPE_40G_BASE_SR4 }, { "40GBASE-LR4", SFF_MODULE_TYPE_40G_BASE_LR4 }, diff --git a/packages/base/any/onlp/src/sff/sff.mk b/packages/base/any/onlp/src/sff/sff.mk index e982638c..b2002c58 100644 --- a/packages/base/any/onlp/src/sff/sff.mk +++ b/packages/base/any/onlp/src/sff/sff.mk @@ -3,7 +3,7 @@ # # Inclusive Makefile for the sff module. # -# Autogenerated 2017-08-22 22:14:08.507022 +# Autogenerated 2017-08-31 20:47:10.071123 # ############################################################################### sff_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) From 454180823c93fd4a84d51d20719fd6f2d5e45aa4 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 6 Sep 2017 16:30:14 -0700 Subject: [PATCH 49/67] Export defined architecture symbol for convenient use in makefiles. --- make/config.amd64.mk | 3 +-- make/config.arm64.mk | 1 + make/config.armel.mk | 1 + make/config.powerpc.mk | 3 +-- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/make/config.amd64.mk b/make/config.amd64.mk index 9c9850c5..df31cd5d 100644 --- a/make/config.amd64.mk +++ b/make/config.amd64.mk @@ -7,5 +7,4 @@ include $(ONL)/make/config.mk export TOOLCHAIN := x86_64-linux-gnu export ARCH := amd64 export UARCH := AMD64 - - +export __$(ARCH)__ := 1 diff --git a/make/config.arm64.mk b/make/config.arm64.mk index fa294082..27587349 100644 --- a/make/config.arm64.mk +++ b/make/config.arm64.mk @@ -7,3 +7,4 @@ include $(ONL)/make/config.mk export TOOLCHAIN := aarch64-linux-gnu export ARCH := arm64 export UARCH := ARM64 +export __$(ARCH)__ := 1 diff --git a/make/config.armel.mk b/make/config.armel.mk index e4dca860..fe6b8c4c 100644 --- a/make/config.armel.mk +++ b/make/config.armel.mk @@ -7,3 +7,4 @@ include $(ONL)/make/config.mk export TOOLCHAIN := arm-linux-gnueabi export ARCH := armel export UARCH := ARMEL +export __$(ARCH)__ := 1 diff --git a/make/config.powerpc.mk b/make/config.powerpc.mk index 2f2aa89c..e8aba400 100644 --- a/make/config.powerpc.mk +++ b/make/config.powerpc.mk @@ -7,5 +7,4 @@ include $(ONL)/make/config.mk export TOOLCHAIN := powerpc-linux-gnu export ARCH := powerpc export UARCH := PPC - - +export __$(ARCH)__ := 1 From 88ab3ed487d920cd3129723cff219f2a1e09f3ce Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 7 Sep 2017 00:08:26 +0000 Subject: [PATCH 50/67] Add PSM4 unit. --- .../base/any/onlp/src/sff/module/src/sff_db.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/base/any/onlp/src/sff/module/src/sff_db.c b/packages/base/any/onlp/src/sff/module/src/sff_db.c index 0318b1c3..f7129be1 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff_db.c +++ b/packages/base/any/onlp/src/sff/module/src/sff_db.c @@ -61,6 +61,10 @@ #define SFF_100G_CWDM4_PROPERTIES \ SFF_SFP_TYPE_QSFP28, "QSFP28", SFF_MODULE_TYPE_100G_CWDM4, "100G-CWDM4", SFF_MEDIA_TYPE_FIBER, "Fiber", SFF_MODULE_CAPS_F_100G +#define SFF_100G_PSM4_PROPERTIES \ + SFF_SFP_TYPE_QSFP28, "QSFP28", SFF_MODULE_TYPE_100G_PSM4, "100G-PSM4", SFF_MEDIA_TYPE_FIBER, "Fiber", SFF_MODULE_CAPS_F_100G + + static sff_db_entry_t sff_database__[] = { @@ -1413,6 +1417,35 @@ static sff_db_entry_t sff_database__[] = }, }, }, + { + { + .eeprom = { + 0x11, 0x07, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xb8, 0x00, 0x00, 0x85, 0x0b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x45, 0x26, 0x44, 0xf0, 0x45, 0x63, + 0x45, 0x3a, 0x1d, 0xee, 0x1d, 0x88, 0x23, 0x8a, 0x24, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x11, 0xcc, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x49, 0x4e, 0x4e, 0x4f, 0x4c, 0x49, 0x47, 0x48, 0x54, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x00, 0x44, 0x7c, 0x7f, 0x54, 0x52, 0x2d, 0x56, 0x43, 0x31, 0x33, 0x54, + 0x2d, 0x4e, 0x30, 0x30, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x66, 0x58, 0x07, 0xd0, 0x46, 0x33, + 0x07, 0x07, 0xff, 0xda, 0x49, 0x4e, 0x47, 0x41, 0x54, 0x36, 0x36, 0x35, 0x30, 0x30, 0x37, 0x39, + 0x20, 0x20, 0x20, 0x20, 0x31, 0x36, 0x30, 0x35, 0x31, 0x32, 0x31, 0x39, 0x0c, 0x00, 0x67, 0x57, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + }, + .info = { + "INNOLIGHT ", + "TR-VC13T-N00 ", + "INGAT6650079 ", + SFF_100G_PSM4_PROPERTIES, + -1, + }, + }, + }, #endif /** SFF_CONFIG_INCLUDE_DATABASE */ }; From 903873722898346c19a2409875f83e34ef05a51c Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Fri, 8 Sep 2017 15:20:40 +0000 Subject: [PATCH 51/67] Fix memory leaks on deinit. --- .../any/onlp/src/onlp/module/inc/onlp/onlp.h | 1 + .../base/any/onlp/src/onlp/module/src/onlp.c | 24 ++++++++++++++----- .../any/onlp/src/onlp/module/src/onlp_locks.c | 8 +++++-- .../any/onlp/src/onlp/module/src/onlp_locks.h | 1 + 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/base/any/onlp/src/onlp/module/inc/onlp/onlp.h b/packages/base/any/onlp/src/onlp/module/inc/onlp/onlp.h index 266bf3ee..55153d91 100644 --- a/packages/base/any/onlp/src/onlp/module/inc/onlp/onlp.h +++ b/packages/base/any/onlp/src/onlp/module/inc/onlp/onlp.h @@ -59,6 +59,7 @@ typedef enum onlp_status_e { */ int onlp_init(void); +int onlp_denit(void); /** * @brief Dump the current platform data. diff --git a/packages/base/any/onlp/src/onlp/module/src/onlp.c b/packages/base/any/onlp/src/onlp/module/src/onlp.c index 31d9999e..b6f7b77a 100644 --- a/packages/base/any/onlp/src/onlp/module/src/onlp.c +++ b/packages/base/any/onlp/src/onlp/module/src/onlp.c @@ -1,21 +1,21 @@ /************************************************************ * - * - * Copyright 2014, 2015 Big Switch Networks, Inc. - * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * * Licensed under the Eclipse Public License, Version 1.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.eclipse.org/legal/epl-v10.html - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. - * + * * ************************************************************ * @@ -62,3 +62,15 @@ onlp_init(void) onlp_thermal_init(); return 0; } + +int +onlp_denit(void) +{ +#if ONLP_CONFIG_INCLUDE_API_LOCK == 1 + onlp_api_lock_denit(); +#endif + + onlp_json_denit(); + + return 0; +} diff --git a/packages/base/any/onlp/src/onlp/module/src/onlp_locks.c b/packages/base/any/onlp/src/onlp/module/src/onlp_locks.c index 7e48c17d..d85ab83e 100644 --- a/packages/base/any/onlp/src/onlp/module/src/onlp_locks.c +++ b/packages/base/any/onlp/src/onlp/module/src/onlp_locks.c @@ -45,6 +45,12 @@ onlp_api_lock_init(void) api_sem__ = os_sem_create_flags(1, OS_SEM_CREATE_F_TRUE_RELATIVE_TIMEOUTS); } +void +onlp_api_lock_denit(void) +{ + os_sem_destroy(api_sem__); +} + void onlp_api_lock(const char* api) { @@ -119,5 +125,3 @@ onlp_api_lock_test(void) } #endif /* ONLP_CONFIG_INCLUDE_API_LOCK */ - - diff --git a/packages/base/any/onlp/src/onlp/module/src/onlp_locks.h b/packages/base/any/onlp/src/onlp/module/src/onlp_locks.h index 0ea6dc13..7a3c92e1 100644 --- a/packages/base/any/onlp/src/onlp/module/src/onlp_locks.h +++ b/packages/base/any/onlp/src/onlp/module/src/onlp_locks.h @@ -33,6 +33,7 @@ * @brief Initialize the ONLP API lock infrastructure. */ void onlp_api_lock_init(); +void onlp_api_lock_denit(); /** * @brief Take the ONLP API lock. From b89d5a1ce80560202958e3480f5981fa303d6eff Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Fri, 8 Sep 2017 22:46:15 +0000 Subject: [PATCH 52/67] Add global denit. --- packages/base/any/onlp/src/onlp/module/src/onlp_locks.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/base/any/onlp/src/onlp/module/src/onlp_locks.c b/packages/base/any/onlp/src/onlp/module/src/onlp_locks.c index d85ab83e..181a33b9 100644 --- a/packages/base/any/onlp/src/onlp/module/src/onlp_locks.c +++ b/packages/base/any/onlp/src/onlp/module/src/onlp_locks.c @@ -77,6 +77,12 @@ onlp_api_lock_init(void) onlp_shlock_global_init(); } +void +onlp_api_lock_denit(void) +{ + /* TODO */ +} + void onlp_api_lock(const char* api) { From e2573038e6efa7c21ebcf510f534be3bdbd4ca64 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Mon, 11 Sep 2017 09:26:26 +0800 Subject: [PATCH 53/67] [as5912-54xk] Modify source code to follow coding standards --- .../builds/x86-64-accton-as5912-54xk-leds.c | 49 ++++--- .../module/auto/x86_64_accton_as5912_54xk.yml | 20 +-- .../onlp/builds/src/module/src/fani.c | 35 ++--- .../onlp/builds/src/module/src/ledi.c | 77 ++++++----- .../onlp/builds/src/module/src/platform_lib.c | 120 +++--------------- .../onlp/builds/src/module/src/platform_lib.h | 35 +++-- .../onlp/builds/src/module/src/psui.c | 27 ++-- .../onlp/builds/src/module/src/sfpi.c | 116 ++++++----------- 8 files changed, 179 insertions(+), 300 deletions(-) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c index bfb0ec16..b81cef4d 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c @@ -57,12 +57,12 @@ static struct accton_as5912_54xk_led_data *ledctl = NULL; #define LED_TYPE_DIAG_REG_MASK (0x0C) #define LED_MODE_DIAG_GREEN_VALUE (0x04) -#define LED_MODE_DIAG_AMBER_VALUE (0x08) +#define LED_MODE_DIAG_ORANGE_VALUE (0x08) #define LED_MODE_DIAG_OFF_VALUE (0x0C) #define LED_TYPE_LOC_REG_MASK (0x10) -#define LED_MODE_LOC_AMBER_VALUE (0x00) +#define LED_MODE_LOC_ORANGE_VALUE (0x00) #define LED_MODE_LOC_OFF_VALUE (0x10) static const u8 led_reg[] = { @@ -80,17 +80,26 @@ enum led_type { /* FAN/PSU/DIAG/RELEASE led mode */ enum led_light_mode { - LED_MODE_OFF = 0, - LED_MODE_GREEN, - LED_MODE_GREEN_BLINK, - LED_MODE_AMBER, - LED_MODE_AMBER_BLINK, - LED_MODE_RED, - LED_MODE_RED_BLINK, - LED_MODE_BLUE, - LED_MODE_BLUE_BLINK, - LED_MODE_AUTO, - LED_MODE_UNKNOWN + LED_MODE_OFF, + LED_MODE_RED = 10, + LED_MODE_RED_BLINKING = 11, + LED_MODE_ORANGE = 12, + LED_MODE_ORANGE_BLINKING = 13, + LED_MODE_YELLOW = 14, + LED_MODE_YELLOW_BLINKING = 15, + LED_MODE_GREEN = 16, + LED_MODE_GREEN_BLINKING = 17, + LED_MODE_BLUE = 18, + LED_MODE_BLUE_BLINKING = 19, + LED_MODE_PURPLE = 20, + LED_MODE_PURPLE_BLINKING = 21, + LED_MODE_AUTO = 22, + LED_MODE_AUTO_BLINKING = 23, + LED_MODE_WHITE = 24, + LED_MODE_WHITE_BLINKING = 25, + LED_MODE_CYAN = 26, + LED_MODE_CYAN_BLINKING = 27, + LED_MODE_UNKNOWN = 99 }; struct led_type_mode { @@ -101,11 +110,11 @@ struct led_type_mode { }; static struct led_type_mode led_type_mode_data[] = { -{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE}, -{LED_TYPE_LOC, LED_MODE_AMBER, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_AMBER_VALUE}, -{LED_TYPE_DIAG, LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE}, -{LED_TYPE_DIAG, LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE}, -{LED_TYPE_DIAG, LED_MODE_AMBER, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_AMBER_VALUE}, +{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE}, +{LED_TYPE_LOC, LED_MODE_ORANGE, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_ORANGE_VALUE}, +{LED_TYPE_DIAG, LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE}, +{LED_TYPE_DIAG, LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE}, +{LED_TYPE_DIAG, LED_MODE_ORANGE, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_ORANGE_VALUE}, }; static int led_reg_val_to_light_mode(enum led_type type, u8 reg_val) { @@ -250,14 +259,14 @@ static struct led_classdev accton_as5912_54xk_leds[] = { .default_trigger = "unused", .brightness_set = accton_as5912_54xk_led_loc_set, .brightness_get = accton_as5912_54xk_led_loc_get, - .max_brightness = LED_MODE_AMBER, + .max_brightness = LED_MODE_ORANGE, }, [LED_TYPE_DIAG] = { .name = "accton_as5912_54xk_led::diag", .default_trigger = "unused", .brightness_set = accton_as5912_54xk_led_diag_set, .brightness_get = accton_as5912_54xk_led_diag_get, - .max_brightness = LED_MODE_AMBER, + .max_brightness = LED_MODE_GREEN, }, [LED_TYPE_PSU1] = { .name = "accton_as5912_54xk_led::psu1", diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/x86_64_accton_as5912_54xk.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/x86_64_accton_as5912_54xk.yml index 8898ff3d..aeb3583d 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/x86_64_accton_as5912_54xk.yml +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/auto/x86_64_accton_as5912_54xk.yml @@ -5,35 +5,35 @@ ############################################################################### cdefs: &cdefs -- x86_64_accton_as5912_54xk_CONFIG_INCLUDE_LOGGING: +- X86_64_ACCTON_AS5912_54XK_CONFIG_INCLUDE_LOGGING: doc: "Include or exclude logging." default: 1 -- x86_64_accton_as5912_54xk_CONFIG_LOG_OPTIONS_DEFAULT: +- X86_64_ACCTON_AS5912_54XK_CONFIG_LOG_OPTIONS_DEFAULT: doc: "Default enabled log options." default: AIM_LOG_OPTIONS_DEFAULT -- x86_64_accton_as5912_54xk_CONFIG_LOG_BITS_DEFAULT: +- X86_64_ACCTON_AS5912_54XK_CONFIG_LOG_BITS_DEFAULT: doc: "Default enabled log bits." default: AIM_LOG_BITS_DEFAULT -- x86_64_accton_as5912_54xk_CONFIG_LOG_CUSTOM_BITS_DEFAULT: +- X86_64_ACCTON_AS5912_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT: doc: "Default enabled custom log bits." default: 0 -- x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB: +- X86_64_ACCTON_AS5912_54XK_CONFIG_PORTING_STDLIB: doc: "Default all porting macros to use the C standard libraries." default: 1 -- x86_64_accton_as5912_54xk_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: +- X86_64_ACCTON_AS5912_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: doc: "Include standard library headers for stdlib porting macros." - default: x86_64_accton_as5912_54xk_CONFIG_PORTING_STDLIB -- x86_64_accton_as5912_54xk_CONFIG_INCLUDE_UCLI: + default: X86_64_ACCTON_AS5912_54XK_CONFIG_PORTING_STDLIB +- X86_64_ACCTON_AS5912_54XK_CONFIG_INCLUDE_UCLI: doc: "Include generic uCli support." default: 0 -- x86_64_accton_as5912_54xk_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION: +- X86_64_ACCTON_AS5912_54XK_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_as5912_54xk_CONFIG_HEADER: + X86_64_ACCTON_AS5912_54XK_CONFIG_HEADER: defs: *cdefs basename: x86_64_accton_as5912_54xk_config diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/fani.c index 9eb030ce..381a8b59 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/fani.c @@ -27,8 +27,6 @@ #include #include "platform_lib.h" -#define PSU_PREFIX_PATH "/sys/bus/i2c/devices/" - enum fan_id { FAN_1_ON_FAN_BOARD = 1, FAN_2_ON_FAN_BOARD, @@ -87,18 +85,17 @@ static int _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) { int value, ret; - char path[64] = {0}; /* get fan present status */ - ret = onlp_file_read_int(&value, "%s""fan%d_present", FAN_BOARD_PATH, fid); + ret = onlp_file_read_int(&value, "%s""fan%d_present", FAN_BOARD_PATH, fid); if (ret < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); return ONLP_STATUS_E_INTERNAL; } if (value == 0) { - return ONLP_STATUS_OK; + return ONLP_STATUS_OK; /* fan is not present */ } info->status |= ONLP_FAN_STATUS_PRESENT; @@ -107,7 +104,7 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) */ ret = onlp_file_read_int(&value, "%s""fan%d_fault", FAN_BOARD_PATH, fid); if (ret < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); return ONLP_STATUS_E_INTERNAL; } @@ -120,7 +117,7 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) */ ret = onlp_file_read_int(&value, "%s""fan%d_direction", FAN_BOARD_PATH, fid); if (ret < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); return ONLP_STATUS_E_INTERNAL; } @@ -131,16 +128,16 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) */ ret = onlp_file_read_int(&value, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid); if (ret < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); return ONLP_STATUS_E_INTERNAL; } info->rpm = value; /* get rear fan speed */ - ret = onlp_file_read_int(&value, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid); + ret = onlp_file_read_int(&value, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid); if (ret < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); return ONLP_STATUS_E_INTERNAL; } @@ -152,9 +149,9 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) /* get speed percentage from rpm */ - ret = onlp_file_read_int(&value, "%s""fan_max_speed_rpm", FAN_BOARD_PATH); + ret = onlp_file_read_int(&value, "%s""fan_max_speed_rpm", FAN_BOARD_PATH); if (ret < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); return ONLP_STATUS_E_INTERNAL; } @@ -201,17 +198,12 @@ _onlp_fani_info_get_fan_on_psu(int pid, onlp_fan_info_t* info) */ info->status |= _onlp_get_fan_direction_on_psu(); - /* get fan fault status - */ - if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_fault", &val) == ONLP_STATUS_OK) { - info->status |= (val > 0) ? ONLP_FAN_STATUS_FAILED : 0; - } - /* get fan speed */ if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == ONLP_STATUS_OK) { info->rpm = val; - info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED; + info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED; + info->status |= (val == 0) ? ONLP_FAN_STATUS_FAILED : 0; } return ONLP_STATUS_OK; @@ -315,7 +307,7 @@ onlp_fani_percentage_set(onlp_oid_t id, int p) return ONLP_STATUS_E_INVALID; } - if (onlp_file_write_integer(path, p) < 0) { + if (onlp_file_write_int(p, path) < 0) { AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; } @@ -360,4 +352,3 @@ onlp_fani_ioctl(onlp_oid_t id, va_list vargs) return ONLP_STATUS_E_UNSUPPORTED; } - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/ledi.c index b1523cb0..795cfd93 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/ledi.c @@ -27,6 +27,8 @@ #include #include "platform_lib.h" +#define LED_FORMAT "/sys/class/leds/accton_as5912_54xk_led::%s/brightness" + #define VALIDATE(_id) \ do { \ if(!ONLP_OID_IS_LED(_id)) { \ @@ -34,32 +36,40 @@ } \ } while(0) -#define LED_FORMAT "/sys/class/leds/accton_as5912_54xk_led::%s/brightness" - /* LED related data */ -enum led_light_mode { /*must be the same with the definition @ kernel driver */ - LED_MODE_OFF = 0, - LED_MODE_GREEN, - LED_MODE_GREEN_BLINK, - LED_MODE_AMBER, - LED_MODE_AMBER_BLINK, - LED_MODE_RED, - LED_MODE_RED_BLINK, - LED_MODE_BLUE, - LED_MODE_BLUE_BLINK, - LED_MODE_AUTO, - LED_MODE_UNKNOWN -}; - enum onlp_led_id { - LED_LOC = 1, + LED_RESERVED = 0, + LED_LOC, LED_DIAG, LED_PSU1, LED_PSU2, LED_FAN, }; + +enum led_light_mode { + LED_MODE_OFF, + LED_MODE_RED = 10, + LED_MODE_RED_BLINKING = 11, + LED_MODE_ORANGE = 12, + LED_MODE_ORANGE_BLINKING = 13, + LED_MODE_YELLOW = 14, + LED_MODE_YELLOW_BLINKING = 15, + LED_MODE_GREEN = 16, + LED_MODE_GREEN_BLINKING = 17, + LED_MODE_BLUE = 18, + LED_MODE_BLUE_BLINKING = 19, + LED_MODE_PURPLE = 20, + LED_MODE_PURPLE_BLINKING = 21, + LED_MODE_AUTO = 22, + LED_MODE_AUTO_BLINKING = 23, + LED_MODE_WHITE = 24, + LED_MODE_WHITE_BLINKING = 25, + LED_MODE_CYAN = 26, + LED_MODE_CYAN_BLINKING = 27, + LED_MODE_UNKNOWN = 99 +}; typedef struct led_light_mode_map { enum onlp_led_id id; @@ -68,14 +78,14 @@ typedef struct led_light_mode_map { } led_light_mode_map_t; led_light_mode_map_t led_map[] = { -{LED_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_LOC, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, -{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_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} +{LED_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_LOC, LED_MODE_ORANGE, ONLP_LED_MODE_ORANGE}, +{LED_DIAG, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_DIAG, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, +{LED_DIAG, LED_MODE_ORANGE, ONLP_LED_MODE_ORANGE}, +{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 *leds[] = /* must map with onlp_led_id */ @@ -160,8 +170,8 @@ onlp_ledi_init(void) /* * Turn off the LOCATION and DIAG LEDs at startup */ - onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_LOC), ONLP_LED_MODE_OFF); onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_DIAG), ONLP_LED_MODE_OFF); + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_LOC), ONLP_LED_MODE_OFF); return ONLP_STATUS_OK; } @@ -170,16 +180,17 @@ int onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) { int lid, value; + VALIDATE(id); lid = ONLP_OID_ID_GET(id); - /* Set the onlp_oid_hdr_t and capabilities */ + /* Set the onlp_oid_hdr_t and capabilities */ *info = linfo[ONLP_OID_ID_GET(id)]; /* Get LED mode */ if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) { - DEBUG_PRINT("Unable to read status from file (%s)", leds[lid]); + DEBUG_PRINT("Unable to read status from file "LED_FORMAT, leds[lid]); return ONLP_STATUS_E_INTERNAL; } @@ -223,15 +234,11 @@ onlp_ledi_set(onlp_oid_t id, int on_or_off) int onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) { - int lid; - char path[64] = {0}; - + int lid; VALIDATE(id); - - lid = ONLP_OID_ID_GET(id); - sprintf(path, LED_FORMAT, leds[lid]); - if (onlp_file_write_integer(path, onlp_to_driver_led_mode(lid , mode)) < 0) { + lid = ONLP_OID_ID_GET(id); + if (onlp_file_write_int(onlp_to_driver_led_mode(lid , mode), LED_FORMAT, leds[lid]) < 0) { return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.c index b14867bd..1837a772 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.c @@ -30,117 +30,39 @@ #include "platform_lib.h" #define PSU_NODE_MAX_PATH_LEN 64 - -int _onlp_file_write(char *filename, char *buffer, int buf_size, int data_len) -{ - int fd; - int len; - - if ((buffer == NULL) || (buf_size < 0)) { - return -1; - } - - if ((fd = open(filename, O_WRONLY, S_IWUSR)) == -1) { - return -1; - } - - if ((len = write(fd, buffer, buf_size)) < 0) { - close(fd); - return -1; - } - - if ((close(fd) == -1)) { - return -1; - } - - if ((len > buf_size) || (data_len != 0 && len != data_len)) { - return -1; - } - - return 0; -} - -int onlp_file_write_integer(char *filename, int value) -{ - char buf[8] = {0}; - sprintf(buf, "%d", value); - - return _onlp_file_write(filename, buf, (int)strlen(buf), 0); -} - -int onlp_file_read_binary(char *filename, char *buffer, int buf_size, int data_len) -{ - int fd; - int len; - - if ((buffer == NULL) || (buf_size < 0)) { - return -1; - } - - if ((fd = open(filename, O_RDONLY)) == -1) { - return -1; - } - - if ((len = read(fd, buffer, buf_size)) < 0) { - close(fd); - return -1; - } - - if ((close(fd) == -1)) { - return -1; - } - - if ((len > buf_size) || (data_len != 0 && len != data_len)) { - return -1; - } - - return 0; -} - -int onlp_file_read_string(char *filename, char *buffer, int buf_size, int data_len) -{ - int ret; - - if (data_len >= buf_size) { - return -1; - } - - ret = onlp_file_read_binary(filename, buffer, buf_size-1, data_len); - - if (ret == 0) { - buffer[buf_size-1] = '\0'; - } - - return ret; -} - -#define I2C_PSU_MODEL_NAME_LEN 9 -#define I2C_PSU_FAN_DIR_LEN 3 +#define PSU_MODEL_NAME_LEN 9 +#define PSU_FAN_DIR_LEN 3 psu_type_t get_psu_type(int id, char* modelname, int modelname_len) { - char *node = NULL; - char model_name[I2C_PSU_MODEL_NAME_LEN + 1] = {0}; - char fan_dir[I2C_PSU_FAN_DIR_LEN + 1] = {0}; - - /* Check AC model name */ - node = (id == PSU1_ID) ? PSU1_AC_HWMON_NODE(psu_model_name) : PSU2_AC_HWMON_NODE(psu_model_name); + int ret = 0, value = 0; + char model[PSU_MODEL_NAME_LEN + 1] = {0}; + char fan_dir[PSU_FAN_DIR_LEN + 1] = {0}; + char *path = NULL; - if (onlp_file_read_string(node, model_name, sizeof(model_name), 0) != 0) { + if (modelname && modelname_len < PSU_MODEL_NAME_LEN) { return PSU_TYPE_UNKNOWN; } + + /* Check AC model name */ + path = (id == PSU1_ID) ? PSU1_AC_EEPROM_NODE(psu_model_name) : PSU2_AC_EEPROM_NODE(psu_model_name); + ret = onlp_file_read((uint8_t*)model, PSU_MODEL_NAME_LEN, &value, path); + if (ret != ONLP_STATUS_OK || value != PSU_MODEL_NAME_LEN) { + return PSU_TYPE_UNKNOWN; + + } - if (strncmp(model_name, "YM-2651Y", strlen("YM-2651Y")) != 0) { + if (strncmp(model, "YM-2651Y", strlen("YM-2651Y")) != 0) { return PSU_TYPE_UNKNOWN; } if (modelname) { - strncpy(modelname, model_name, modelname_len-1); + strncpy(modelname, model, modelname_len-1); } - node = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_fan_dir) : PSU2_AC_PMBUS_NODE(psu_fan_dir); - - if (onlp_file_read_string(node, fan_dir, sizeof(fan_dir), 0) != 0) { + path = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_fan_dir) : PSU2_AC_PMBUS_NODE(psu_fan_dir); + ret = onlp_file_read((uint8_t*)fan_dir, sizeof(fan_dir), &value, path); + if (ret != ONLP_STATUS_OK) { return PSU_TYPE_UNKNOWN; } @@ -192,7 +114,7 @@ int psu_ym2651y_pmbus_info_set(int id, char *node, int value) return ONLP_STATUS_E_UNSUPPORTED; }; - if (onlp_file_write_integer(path, value) < 0) { + 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; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.h index b17bd084..4470faba 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/platform_lib.h @@ -30,8 +30,8 @@ #define CHASSIS_FAN_COUNT 6 #define CHASSIS_THERMAL_COUNT 5 -#define CHASSIS_PSU_COUNT 2 #define CHASSIS_LED_COUNT 5 +#define CHASSIS_PSU_COUNT 2 #define PSU1_ID 1 #define PSU2_ID 2 @@ -42,32 +42,17 @@ #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/11-0053/" -#define PSU2_AC_HWMON_PREFIX "/sys/bus/i2c/devices/10-0050/" +#define PSU1_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/11-0053/" +#define PSU2_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/10-0050/" -#define PSU1_AC_HWMON_NODE(node) PSU1_AC_HWMON_PREFIX#node -#define PSU2_AC_HWMON_NODE(node) PSU2_AC_HWMON_PREFIX#node +#define PSU1_AC_EEPROM_NODE(node) PSU1_AC_EEPROM_PREFIX#node +#define PSU2_AC_EEPROM_NODE(node) PSU2_AC_EEPROM_PREFIX#node #define FAN_BOARD_PATH "/sys/bus/i2c/devices/2-0066/" #define FAN_NODE(node) FAN_BOARD_PATH#node #define IDPROM_PATH "/sys/class/i2c-adapter/i2c-1/1-0057/eeprom" -int onlp_file_write_integer(char *filename, int value); -int onlp_file_read_binary(char *filename, char *buffer, int buf_size, int data_len); -int onlp_file_read_string(char *filename, char *buffer, int buf_size, int data_len); - -int psu_ym2651y_pmbus_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_F2B, - PSU_TYPE_AC_B2F -} psu_type_t; - -psu_type_t get_psu_type(int id, char* modelname, int modelname_len); - enum onlp_thermal_id { THERMAL_RESERVED = 0, @@ -80,6 +65,16 @@ enum onlp_thermal_id THERMAL_1_ON_PSU2, }; +typedef enum psu_type { + PSU_TYPE_UNKNOWN, + PSU_TYPE_AC_F2B, + PSU_TYPE_AC_B2F +} psu_type_t; + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len); +int psu_ym2651y_pmbus_info_get(int id, char *node, int *value); +int psu_ym2651y_pmbus_info_set(int id, char *node, int value); + #define DEBUG_MODE 0 #if (DEBUG_MODE == 1) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/psui.c index 6da5aa58..f7f64f0e 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/psui.c @@ -23,14 +23,12 @@ * * ***********************************************************/ -#include #include +#include #include "platform_lib.h" -#define PSU_STATUS_PRESENT 1 -#define PSU_STATUS_POWER_GOOD 1 - -#define PSU_NODE_MAX_INT_LEN 8 +#define PSU_STATUS_PRESENT 1 +#define PSU_STATUS_POWER_GOOD 1 #define PSU_NODE_MAX_PATH_LEN 64 #define VALIDATE(_id) \ @@ -43,24 +41,17 @@ static int psu_status_info_get(int id, char *node, int *value) { - int ret = 0; - char path[PSU_NODE_MAX_PATH_LEN] = {0}; - + char *prefix = NULL; + *value = 0; - if (PSU1_ID == id) { - ret = onlp_file_read_int(value, "%s%s", PSU1_AC_HWMON_PREFIX, node); - } - else if (PSU2_ID == id) { - ret = onlp_file_read_int(value, "%s%s", PSU2_AC_HWMON_PREFIX, node); - } - - if (ret < 0) { - AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + prefix = (id == PSU1_ID) ? PSU1_AC_EEPROM_PREFIX : PSU2_AC_EEPROM_PREFIX; + if (onlp_file_read_int(value, "%s%s", prefix, node) < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s%s)\r\n", prefix, node); return ONLP_STATUS_E_INTERNAL; } - return ret; + return 0; } int diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c index 7c80c419..fcfbbb36 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c @@ -2,7 +2,7 @@ * * * Copyright 2014 Big Switch Networks, Inc. - * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Accton Technology Corporation. * * Licensed under the Eclipse Public License, Version 1.0 (the * "License"); you may not use this file except in compliance @@ -30,23 +30,11 @@ #include "x86_64_accton_as5912_54xk_log.h" #define NUM_OF_SFP_PORT 54 -#define MAX_SFP_PATH 64 -static char sfp_node_path[MAX_SFP_PATH] = {0}; -#define FRONT_PORT_BUS_INDEX(port) (port+26) +#define MAX_PORT_PATH 64 -static char* -sfp_get_port_path_addr(int port, int addr, char *node_name) -{ - sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-00%d/%s", - FRONT_PORT_BUS_INDEX(port), addr, node_name); - return sfp_node_path; -} - -static char* -sfp_get_port_path(int port, char *node_name) -{ - return sfp_get_port_path_addr(port, 50, node_name); -} +#define SFP_PORT_FORMAT "/sys/bus/i2c/devices/%d-0050/%s" +#define SFP_PORT_DOM_FORMAT "/sys/bus/i2c/devices/%d-0051/%s" +#define SFP_BUS_INDEX(port) (port+26) /************************************************************ * @@ -86,9 +74,7 @@ onlp_sfpi_is_present(int port) * Return < 0 if error. */ int present; - char *path = sfp_get_port_path(port, "sfp_is_present"); - - if (onlp_file_read_int(&present, path) < 0) { + if (onlp_file_read_int(&present, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_is_present") < 0) { AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } @@ -100,12 +86,10 @@ int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { uint32_t bytes[7]; - char* path; + char path[MAX_PORT_PATH] = {0}; FILE* fp; - AIM_BITMAP_CLR_ALL(dst); - - path = sfp_get_port_path(0, "sfp_is_present_all"); + sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_is_present_all"); fp = fopen(path, "r"); if(fp == NULL) { @@ -148,14 +132,40 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) return ONLP_STATUS_OK; } +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + int size = 0; + if(onlp_file_read(data, 256, &size, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { + if(size == 256) { + return ONLP_STATUS_OK; + } + } + + return ONLP_STATUS_E_INTERNAL; +} + +int +onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + int size = 0; + if(onlp_file_read(data, 256, &size, SFP_PORT_DOM_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { + if(size == 256) { + return ONLP_STATUS_OK; + } + } + + return ONLP_STATUS_E_INTERNAL; +} + int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) { uint32_t bytes[6]; - char* path; + char path[MAX_PORT_PATH] = {0}; FILE* fp; - path = sfp_get_port_path(0, "sfp_rx_los_all"); + sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_rx_los_all"); fp = fopen(path, "r"); if(fp == NULL) { @@ -193,41 +203,6 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) return ONLP_STATUS_OK; } -int -onlp_sfpi_eeprom_read(int port, uint8_t data[256]) -{ - char* path = sfp_get_port_path(port, "sfp_eeprom"); - - /* - * Read the SFP eeprom into data[] - * - * Return MISSING if SFP is missing. - * Return OK if eeprom is read - */ - memset(data, 0, 256); - - if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) { - AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_dom_read(int port, uint8_t data[256]) -{ - char* path = sfp_get_port_path_addr(port, 51, "sfp_eeprom"); - memset(data, 0, 256); - - if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) { - AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { @@ -237,9 +212,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { case ONLP_SFP_CONTROL_TX_DISABLE: { - char* path = sfp_get_port_path(port, "sfp_tx_disable"); - - if (onlp_file_write_integer(path, value) != 0) { + if (onlp_file_write_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") != 0) { AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -261,15 +234,12 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { int rv; - char* path = NULL; switch(control) { case ONLP_SFP_CONTROL_RX_LOS: { - path = sfp_get_port_path(port, "sfp_rx_los"); - - if (onlp_file_read_int(value, path) < 0) { + if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_rx_los") < 0) { AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -281,9 +251,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_FAULT: { - path = sfp_get_port_path(port, "sfp_tx_fault"); - - if (onlp_file_read_int(value, path) < 0) { + if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_fault") < 0) { AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -295,9 +263,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_DISABLE: { - path = sfp_get_port_path(port, "sfp_tx_disable"); - - if (onlp_file_read_int(value, path) < 0) { + if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") < 0) { AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -321,5 +287,3 @@ onlp_sfpi_denit(void) return ONLP_STATUS_OK; } - - From 5c3e904b21b9f1b1f96b3ebfe43da6d745fe959a Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Mon, 11 Sep 2017 14:50:54 +0000 Subject: [PATCH 54/67] Latest --- packages/platforms-closed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/platforms-closed b/packages/platforms-closed index 194d6cef..392b22a7 160000 --- a/packages/platforms-closed +++ b/packages/platforms-closed @@ -1 +1 @@ -Subproject commit 194d6cef67bc5f67eecad95456c5085cd5ba47c3 +Subproject commit 392b22a7c7793fa709726f5e55d0fbf228c93205 From 2681870da4c9bdba87d1a56f5ed6534bdade0f06 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 12 Sep 2017 09:33:48 -0700 Subject: [PATCH 55/67] Python Enum Support - Define ONLP_SFP_CONTROL_FLAGS properly in terms of the shared control list. - Add a pyenum section. --- .../any/onlp/src/onlp/module/auto/onlp.yml | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/base/any/onlp/src/onlp/module/auto/onlp.yml b/packages/base/any/onlp/src/onlp/module/auto/onlp.yml index daaff3a3..f784e320 100644 --- a/packages/base/any/onlp/src/onlp/module/auto/onlp.yml +++ b/packages/base/any/onlp/src/onlp/module/auto/onlp.yml @@ -231,6 +231,17 @@ psu_caps: &psu_caps - PIN : (1 << 7) - POUT : (1 << 8) +# SFP Controls +sfp_controls: &sfp_controls +- RESET +- RESET_STATE +- RX_LOS +- TX_FAULT +- TX_DISABLE +- TX_DISABLE_CHANNEL +- LP_MODE +- POWER_OVERRIDE + definitions: cdefs: ONLP_CONFIG_HEADER: @@ -255,25 +266,13 @@ definitions: members: *thermal_threshold onlp_sfp_control: tag: sfp1 - members: - - RESET - - RESET_STATE - - RX_LOS - - TX_FAULT - - TX_DISABLE - - TX_DISABLE_CHANNEL - - LP_MODE - - POWER_OVERRIDE + members: *sfp_controls + onlp_sfp_control_flag: tag: sfp2 - members: - - RESET : (1 << ONLP_SFP_CONTROL_RESET) - - RESET_STATE : ( 1 << ONLP_SFP_CONTROL_RESET_STATE ) - - RX_LOS : ( 1 << ONLP_SFP_CONTROL_RX_LOS ) - - TX_FAULT : ( 1 << ONLP_SFP_CONTROL_TX_FAULT ) - - TX_DISABLE : ( 1 << ONLP_SFP_CONTROL_TX_DISABLE ) - - LP_MODE : ( 1 << ONLP_SFP_CONTROL_LP_MODE ) - - POWER_OVERRIDE : ( 1 << ONLP_SFP_CONTROL_POWER_OVERRIDE ) + members: *sfp_controls + flags: True + onlp_fan_mode: tag: fan members: *fan_modes @@ -302,6 +301,8 @@ definitions: tag: psu members: *psu_caps + pyenum: *enums + portingmacro: ONLP: macros: From a2ee36fa10feee762e68f479f0a8858720d17d6d Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 12 Sep 2017 09:35:37 -0700 Subject: [PATCH 56/67] SFP flags regenerated. --- .../base/any/onlp/src/onlp/module/inc/onlp/sfp.h | 15 ++++++++------- .../any/onlp/src/onlp/module/src/onlp_enums.c | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/base/any/onlp/src/onlp/module/inc/onlp/sfp.h b/packages/base/any/onlp/src/onlp/module/inc/onlp/sfp.h index 173a38ae..3913e9af 100644 --- a/packages/base/any/onlp/src/onlp/module/inc/onlp/sfp.h +++ b/packages/base/any/onlp/src/onlp/module/inc/onlp/sfp.h @@ -51,13 +51,14 @@ typedef enum onlp_sfp_control_e { /* */ /** onlp_sfp_control_flag */ typedef enum onlp_sfp_control_flag_e { - ONLP_SFP_CONTROL_FLAG_RESET = (1 << ONLP_SFP_CONTROL_RESET), - ONLP_SFP_CONTROL_FLAG_RESET_STATE = ( 1 << ONLP_SFP_CONTROL_RESET_STATE ), - ONLP_SFP_CONTROL_FLAG_RX_LOS = ( 1 << ONLP_SFP_CONTROL_RX_LOS ), - ONLP_SFP_CONTROL_FLAG_TX_FAULT = ( 1 << ONLP_SFP_CONTROL_TX_FAULT ), - ONLP_SFP_CONTROL_FLAG_TX_DISABLE = ( 1 << ONLP_SFP_CONTROL_TX_DISABLE ), - ONLP_SFP_CONTROL_FLAG_LP_MODE = ( 1 << ONLP_SFP_CONTROL_LP_MODE ), - ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE = ( 1 << ONLP_SFP_CONTROL_POWER_OVERRIDE ), + ONLP_SFP_CONTROL_FLAG_RESET = (1 << 0), + ONLP_SFP_CONTROL_FLAG_RESET_STATE = (1 << 1), + ONLP_SFP_CONTROL_FLAG_RX_LOS = (1 << 2), + ONLP_SFP_CONTROL_FLAG_TX_FAULT = (1 << 3), + ONLP_SFP_CONTROL_FLAG_TX_DISABLE = (1 << 4), + ONLP_SFP_CONTROL_FLAG_TX_DISABLE_CHANNEL = (1 << 5), + ONLP_SFP_CONTROL_FLAG_LP_MODE = (1 << 6), + ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE = (1 << 7), } onlp_sfp_control_flag_t; /* */ diff --git a/packages/base/any/onlp/src/onlp/module/src/onlp_enums.c b/packages/base/any/onlp/src/onlp/module/src/onlp_enums.c index 44d268e4..67ebd6f7 100644 --- a/packages/base/any/onlp/src/onlp/module/src/onlp_enums.c +++ b/packages/base/any/onlp/src/onlp/module/src/onlp_enums.c @@ -798,6 +798,7 @@ aim_map_si_t onlp_sfp_control_flag_map[] = { "RX_LOS", ONLP_SFP_CONTROL_FLAG_RX_LOS }, { "TX_FAULT", ONLP_SFP_CONTROL_FLAG_TX_FAULT }, { "TX_DISABLE", ONLP_SFP_CONTROL_FLAG_TX_DISABLE }, + { "TX_DISABLE_CHANNEL", ONLP_SFP_CONTROL_FLAG_TX_DISABLE_CHANNEL }, { "LP_MODE", ONLP_SFP_CONTROL_FLAG_LP_MODE }, { "POWER_OVERRIDE", ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE }, { NULL, 0 } @@ -810,6 +811,7 @@ aim_map_si_t onlp_sfp_control_flag_desc_map[] = { "None", ONLP_SFP_CONTROL_FLAG_RX_LOS }, { "None", ONLP_SFP_CONTROL_FLAG_TX_FAULT }, { "None", ONLP_SFP_CONTROL_FLAG_TX_DISABLE }, + { "None", ONLP_SFP_CONTROL_FLAG_TX_DISABLE_CHANNEL }, { "None", ONLP_SFP_CONTROL_FLAG_LP_MODE }, { "None", ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE }, { NULL, 0 } From d120a9f1d4c446cc42a49993b802de671e546581 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 12 Sep 2017 16:39:41 +0000 Subject: [PATCH 57/67] Initial python enums. --- .../any/onlp/src/onlp/module/auto/make.mk | 15 +- .../base/any/onlp/src/onlp/module/py/enums.py | 169 ++++++++++++++++++ 2 files changed, 176 insertions(+), 8 deletions(-) create mode 100644 packages/base/any/onlp/src/onlp/module/py/enums.py diff --git a/packages/base/any/onlp/src/onlp/module/auto/make.mk b/packages/base/any/onlp/src/onlp/module/auto/make.mk index 1e68bdb8..95a06896 100644 --- a/packages/base/any/onlp/src/onlp/module/auto/make.mk +++ b/packages/base/any/onlp/src/onlp/module/auto/make.mk @@ -1,21 +1,21 @@ ############################################################ # -# -# Copyright 2014, 2015 Big Switch Networks, Inc. -# +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# # Licensed under the Eclipse Public License, Version 1.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.eclipse.org/legal/epl-v10.html -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, # either express or implied. See the License for the specific # language governing permissions and limitations under the # License. -# +# # ############################################################ # @@ -24,6 +24,5 @@ ############################################################ onlp_AUTO_DEFS := module/auto/onlp.yml -onlp_AUTO_DIRS := module/inc/onlp module/src +onlp_AUTO_DIRS := module/inc/onlp module/src module/py include $(BUILDER)/auto.mk - diff --git a/packages/base/any/onlp/src/onlp/module/py/enums.py b/packages/base/any/onlp/src/onlp/module/py/enums.py new file mode 100644 index 00000000..65cd75ec --- /dev/null +++ b/packages/base/any/onlp/src/onlp/module/py/enums.py @@ -0,0 +1,169 @@ +#!/usr/bin/python +############################################################ +# +# These are all ONLP Enumeration values +# for use with the Python API. +# +############################################################ +class Enumeration(object): + @classmethod + def name(klass, value): + for (k, v) in klass.__dict__.iteritems(): + if v == value: + return k + return None + +# +class ONLP_FAN_CAPS(Enumeration): + B2F = (1 << 0) + F2B = (1 << 1) + SET_RPM = (1 << 2) + SET_PERCENTAGE = (1 << 3) + GET_RPM = (1 << 4) + GET_PERCENTAGE = (1 << 5) + + +class ONLP_FAN_DIR(Enumeration): + B2F = 0 + F2B = 1 + + +class ONLP_FAN_MODE(Enumeration): + OFF = 0 + SLOW = 1 + NORMAL = 2 + FAST = 3 + MAX = 4 + + +class ONLP_FAN_STATUS(Enumeration): + PRESENT = (1 << 0) + FAILED = (1 << 1) + B2F = (1 << 2) + F2B = (1 << 3) + + +class ONLP_LED_CAPS(Enumeration): + ON_OFF = (1 << 0) + CHAR = (1 << 1) + RED = (1 << 10) + RED_BLINKING = (1 << 11) + ORANGE = (1 << 12) + ORANGE_BLINKING = (1 << 13) + YELLOW = (1 << 14) + YELLOW_BLINKING = (1 << 15) + GREEN = (1 << 16) + GREEN_BLINKING = (1 << 17) + BLUE = (1 << 18) + BLUE_BLINKING = (1 << 19) + PURPLE = (1 << 20) + PURPLE_BLINKING = (1 << 21) + AUTO = (1 << 22) + AUTO_BLINKING = (1 << 23) + + +class ONLP_LED_MODE(Enumeration): + OFF = 0 + ON = 1 + BLINKING = 2 + RED = 10 + RED_BLINKING = 11 + ORANGE = 12 + ORANGE_BLINKING = 13 + YELLOW = 14 + YELLOW_BLINKING = 15 + GREEN = 16 + GREEN_BLINKING = 17 + BLUE = 18 + BLUE_BLINKING = 19 + PURPLE = 20 + PURPLE_BLINKING = 21 + AUTO = 22 + AUTO_BLINKING = 23 + + +class ONLP_LED_STATUS(Enumeration): + PRESENT = (1 << 0) + FAILED = (1 << 1) + ON = (1 << 2) + + +class ONLP_OID_TYPE(Enumeration): + SYS = 1 + THERMAL = 2 + FAN = 3 + PSU = 4 + LED = 5 + MODULE = 6 + RTC = 7 + + +class ONLP_PSU_CAPS(Enumeration): + AC = (1 << 0) + DC12 = (1 << 1) + DC48 = (1 << 2) + VIN = (1 << 3) + VOUT = (1 << 4) + IIN = (1 << 5) + IOUT = (1 << 6) + PIN = (1 << 7) + POUT = (1 << 8) + + +class ONLP_PSU_STATUS(Enumeration): + PRESENT = (1 << 0) + FAILED = (1 << 1) + UNPLUGGED = (1 << 2) + + +class ONLP_SFP_CONTROL(Enumeration): + RESET = 0 + RESET_STATE = 1 + RX_LOS = 2 + TX_FAULT = 3 + TX_DISABLE = 4 + TX_DISABLE_CHANNEL = 5 + LP_MODE = 6 + POWER_OVERRIDE = 7 + + +class ONLP_SFP_CONTROL_FLAG(Enumeration): + RESET = (1 << 0) + RESET_STATE = (1 << 1) + RX_LOS = (1 << 2) + TX_FAULT = (1 << 3) + TX_DISABLE = (1 << 4) + TX_DISABLE_CHANNEL = (1 << 5) + LP_MODE = (1 << 6) + POWER_OVERRIDE = (1 << 7) + + +class ONLP_STATUS(Enumeration): + OK = 0 + E_GENERIC = -1 + E_UNSUPPORTED = -10 + E_MISSING = -11 + E_INVALID = -12 + E_INTERNAL = -13 + E_PARAM = -14 + E_I2C = -15 + + +class ONLP_THERMAL_CAPS(Enumeration): + GET_TEMPERATURE = (1 << 0) + GET_WARNING_THRESHOLD = (1 << 1) + GET_ERROR_THRESHOLD = (1 << 2) + GET_SHUTDOWN_THRESHOLD = (1 << 3) + + +class ONLP_THERMAL_STATUS(Enumeration): + PRESENT = (1 << 0) + FAILED = (1 << 1) + + +class ONLP_THERMAL_THRESHOLD(Enumeration): + WARNING_DEFAULT = 45000 + ERROR_DEFAULT = 55000 + SHUTDOWN_DEFAULT = 60000 + +# From e71d683cf547fe643edbf8ff5aa750afc483ab51 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 12 Sep 2017 16:39:55 +0000 Subject: [PATCH 58/67] Latest --- sm/infra | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sm/infra b/sm/infra index fd74bf9c..36947a54 160000 --- a/sm/infra +++ b/sm/infra @@ -1 +1 @@ -Subproject commit fd74bf9c3fa31901ef3570a1b02e5a9621232fbe +Subproject commit 36947a5451e7d4fb4e9008aa346786fffc6fc82a From f40f9ee48be48fefdda2a58085c26ef7fc8679ea Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 12 Sep 2017 15:19:36 -0700 Subject: [PATCH 59/67] Latesst --- packages/platforms-closed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/platforms-closed b/packages/platforms-closed index 392b22a7..84fffe45 160000 --- a/packages/platforms-closed +++ b/packages/platforms-closed @@ -1 +1 @@ -Subproject commit 392b22a7c7793fa709726f5e55d0fbf228c93205 +Subproject commit 84fffe4502faabac0891b7e80fe3eea9a02df099 From 49ae98db1c928a62b59e10a15198bf3cee4f0605 Mon Sep 17 00:00:00 2001 From: Zi Zhou Date: Fri, 15 Sep 2017 10:57:14 -0700 Subject: [PATCH 60/67] support SFP28 SR --- packages/base/any/onlp/src/sff/module/auto/sff.yml | 2 ++ .../base/any/onlp/src/sff/module/inc/sff/8472.h | 14 ++++++++++++++ .../base/any/onlp/src/sff/module/inc/sff/sff.h | 2 ++ .../base/any/onlp/src/sff/module/inc/sff/sff.x | 2 ++ packages/base/any/onlp/src/sff/module/src/sff.c | 13 +++++++++++++ .../base/any/onlp/src/sff/module/src/sff_enums.c | 2 ++ packages/base/any/onlp/src/sff/sff.mk | 2 +- 7 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/base/any/onlp/src/sff/module/auto/sff.yml b/packages/base/any/onlp/src/sff/module/auto/sff.yml index 295fe6bf..ed2b8bb5 100644 --- a/packages/base/any/onlp/src/sff/module/auto/sff.yml +++ b/packages/base/any/onlp/src/sff/module/auto/sff.yml @@ -75,6 +75,8 @@ sff_module_types: &sff_module_types desc: "40GBASE-ER4" - 25G_BASE_CR: desc: "25GBASE-CR" +- 25G_BASE_SR: + desc: "25GBASE-SR" - 10G_BASE_SR: desc: "10GBASE-SR" - 10G_BASE_LR: diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/8472.h b/packages/base/any/onlp/src/sff/module/inc/sff/8472.h index fa7b1ddc..6b7a1161 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/8472.h +++ b/packages/base/any/onlp/src/sff/module/inc/sff/8472.h @@ -148,6 +148,7 @@ #define SFF8472_CC36_XGE_UNALLOCATED 0x01 #define SFF8472_CC36_UNALLOCATED1 0xF7 +#define SFF8472_CC36_100G_25G_SR 0x02 #define SFF8471_CC60_FC_PI_4_LIMITING 0x08 #define SFF8471_CC60_SFF8431_LIMITING 0x04 @@ -973,4 +974,17 @@ _sff8472_media_sfp28_cr(const uint8_t* idprom) return 0; } + +static inline int +_sff8472_media_sfp28_sr(const uint8_t* idprom) +{ + /* module should be sfp */ + if (!SFF8472_MODULE_SFP(idprom)) return 0; + + if (idprom[12] != 0xFF) return 0; + if (idprom[36] == SFF8472_CC36_100G_25G_SR) return 1; + + return 0; +} + #endif diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/sff.h b/packages/base/any/onlp/src/sff/module/inc/sff/sff.h index be0d1725..d146bba2 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/sff.h +++ b/packages/base/any/onlp/src/sff/module/inc/sff/sff.h @@ -113,6 +113,7 @@ typedef enum sff_module_type_e { SFF_MODULE_TYPE_40G_BASE_SM4, SFF_MODULE_TYPE_40G_BASE_ER4, SFF_MODULE_TYPE_25G_BASE_CR, + SFF_MODULE_TYPE_25G_BASE_SR, SFF_MODULE_TYPE_10G_BASE_SR, SFF_MODULE_TYPE_10G_BASE_LR, SFF_MODULE_TYPE_10G_BASE_LRM, @@ -153,6 +154,7 @@ typedef enum sff_module_type_e { "40G_BASE_SM4", \ "40G_BASE_ER4", \ "25G_BASE_CR", \ + "25G_BASE_SR", \ "10G_BASE_SR", \ "10G_BASE_LR", \ "10G_BASE_LRM", \ diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/sff.x b/packages/base/any/onlp/src/sff/module/inc/sff/sff.x index ba315949..d02e1840 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/sff.x +++ b/packages/base/any/onlp/src/sff/module/inc/sff/sff.x @@ -23,6 +23,7 @@ SFF_MEDIA_TYPE_ENTRY(40G_BASE_SR2, 40GBASE-SR2) SFF_MEDIA_TYPE_ENTRY(40G_BASE_SM4, 40GBASE-SM4) SFF_MEDIA_TYPE_ENTRY(40G_BASE_ER4, 40GBASE-ER4) SFF_MEDIA_TYPE_ENTRY(25G_BASE_CR, 25GBASE-CR) +SFF_MEDIA_TYPE_ENTRY(25G_BASE_SR, 25GBASE-SR) SFF_MEDIA_TYPE_ENTRY(10G_BASE_SR, 10GBASE-SR) SFF_MEDIA_TYPE_ENTRY(10G_BASE_LR, 10GBASE-LR) SFF_MEDIA_TYPE_ENTRY(10G_BASE_LRM, 10GBASE-LRM) @@ -69,6 +70,7 @@ SFF_MODULE_TYPE_ENTRY(40G_BASE_SR2, 40GBASE-SR2) SFF_MODULE_TYPE_ENTRY(40G_BASE_SM4, 40GBASE-SM4) SFF_MODULE_TYPE_ENTRY(40G_BASE_ER4, 40GBASE-ER4) SFF_MODULE_TYPE_ENTRY(25G_BASE_CR, 25GBASE-CR) +SFF_MODULE_TYPE_ENTRY(25G_BASE_SR, 25GBASE-SR) SFF_MODULE_TYPE_ENTRY(10G_BASE_SR, 10GBASE-SR) SFF_MODULE_TYPE_ENTRY(10G_BASE_LR, 10GBASE-LR) SFF_MODULE_TYPE_ENTRY(10G_BASE_LRM, 10GBASE-LRM) diff --git a/packages/base/any/onlp/src/sff/module/src/sff.c b/packages/base/any/onlp/src/sff/module/src/sff.c index b866c741..c142b6a4 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff.c +++ b/packages/base/any/onlp/src/sff/module/src/sff.c @@ -187,6 +187,11 @@ sff_module_type_get(const uint8_t* eeprom) return SFF_MODULE_TYPE_25G_BASE_CR; } + if (SFF8472_MODULE_SFP(eeprom) + && _sff8472_media_sfp28_sr(eeprom)) { + return SFF_MODULE_TYPE_25G_BASE_SR; + } + if (SFF8472_MODULE_SFP(eeprom) && SFF8472_MEDIA_GBE_SX(eeprom)) return SFF_MODULE_TYPE_1G_BASE_SX; @@ -254,6 +259,7 @@ sff_media_type_get(sff_module_type_t mt) case SFF_MODULE_TYPE_40G_BASE_SR2: case SFF_MODULE_TYPE_40G_BASE_SM4: case SFF_MODULE_TYPE_40G_BASE_ER4: + case SFF_MODULE_TYPE_25G_BASE_SR: case SFF_MODULE_TYPE_10G_BASE_SR: case SFF_MODULE_TYPE_10G_BASE_LR: case SFF_MODULE_TYPE_10G_BASE_LRM: @@ -309,6 +315,7 @@ sff_module_caps_get(sff_module_type_t mt, uint32_t *caps) return 0; case SFF_MODULE_TYPE_25G_BASE_CR: + case SFF_MODULE_TYPE_25G_BASE_SR: *caps |= SFF_MODULE_CAPS_F_25G; return 0; @@ -722,6 +729,12 @@ sff_info_init(sff_info_t* info, sff_module_type_t mt, info->caps = SFF_MODULE_CAPS_F_25G; break; + case SFF_MODULE_TYPE_25G_BASE_SR: + info->sfp_type = SFF_SFP_TYPE_SFP; + info->media_type = SFF_MEDIA_TYPE_FIBER; + info->caps = SFF_MODULE_CAPS_F_25G; + break; + case SFF_MODULE_TYPE_10G_BASE_CR: info->sfp_type = SFF_SFP_TYPE_SFP; info->media_type = SFF_MEDIA_TYPE_COPPER; diff --git a/packages/base/any/onlp/src/sff/module/src/sff_enums.c b/packages/base/any/onlp/src/sff/module/src/sff_enums.c index 29eb27b6..876c01e8 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff_enums.c +++ b/packages/base/any/onlp/src/sff/module/src/sff_enums.c @@ -147,6 +147,7 @@ aim_map_si_t sff_module_type_map[] = { "40G_BASE_SM4", SFF_MODULE_TYPE_40G_BASE_SM4 }, { "40G_BASE_ER4", SFF_MODULE_TYPE_40G_BASE_ER4 }, { "25G_BASE_CR", SFF_MODULE_TYPE_25G_BASE_CR }, + { "25G_BASE_SR", SFF_MODULE_TYPE_25G_BASE_SR }, { "10G_BASE_SR", SFF_MODULE_TYPE_10G_BASE_SR }, { "10G_BASE_LR", SFF_MODULE_TYPE_10G_BASE_LR }, { "10G_BASE_LRM", SFF_MODULE_TYPE_10G_BASE_LRM }, @@ -184,6 +185,7 @@ aim_map_si_t sff_module_type_desc_map[] = { "40GBASE-SM4", SFF_MODULE_TYPE_40G_BASE_SM4 }, { "40GBASE-ER4", SFF_MODULE_TYPE_40G_BASE_ER4 }, { "25GBASE-CR", SFF_MODULE_TYPE_25G_BASE_CR }, + { "25GBASE-SR", SFF_MODULE_TYPE_25G_BASE_SR }, { "10GBASE-SR", SFF_MODULE_TYPE_10G_BASE_SR }, { "10GBASE-LR", SFF_MODULE_TYPE_10G_BASE_LR }, { "10GBASE-LRM", SFF_MODULE_TYPE_10G_BASE_LRM }, diff --git a/packages/base/any/onlp/src/sff/sff.mk b/packages/base/any/onlp/src/sff/sff.mk index b2002c58..b2b5922f 100644 --- a/packages/base/any/onlp/src/sff/sff.mk +++ b/packages/base/any/onlp/src/sff/sff.mk @@ -3,7 +3,7 @@ # # Inclusive Makefile for the sff module. # -# Autogenerated 2017-08-31 20:47:10.071123 +# Autogenerated 2017-09-14 23:57:29.895708 # ############################################################################### sff_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) From cbec0570076a05c27454aa58fd3f670ad7e4db52 Mon Sep 17 00:00:00 2001 From: "joy.yw.chang" Date: Tue, 19 Sep 2017 22:38:28 -0700 Subject: [PATCH 61/67] Remove w83795 and eeprom modules, Modify platform name in config file --- .../configs/x86_64-all/x86_64-all.config | 5 +- .../platforms/ingrasys/vendor-config/PKG.yml | 2 +- .../src/python/ingrasys/__init__.py | 2 +- .../x86-64-ingrasys-s9100/modules/PKG.yml | 2 +- .../modules/builds/Makefile | 6 - .../modules/builds/eeprom.c | 237 -- .../modules/builds/w83795.c | 2287 ----------------- .../x86_64_ingrasys_s9100_config.h | 60 +- .../x86_64_ingrasys_s9100_porting.h | 88 +- .../x86_64_ingrasys_s9100/module/src/ledi.c | 3 - .../module/src/x86_64_ingrasys_s9100_config.c | 52 +- .../module/src/x86_64_ingrasys_s9100_log.c | 6 +- .../x86_64_ingrasys_s9100_r0/__init__.py | 6 +- 13 files changed, 112 insertions(+), 2644 deletions(-) delete mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/Makefile delete mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/eeprom.c delete mode 100755 packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/w83795.c diff --git a/packages/base/any/kernels/3.16-lts/configs/x86_64-all/x86_64-all.config b/packages/base/any/kernels/3.16-lts/configs/x86_64-all/x86_64-all.config index 90f68706..a7f0259f 100644 --- a/packages/base/any/kernels/3.16-lts/configs/x86_64-all/x86_64-all.config +++ b/packages/base/any/kernels/3.16-lts/configs/x86_64-all/x86_64-all.config @@ -1203,7 +1203,7 @@ CONFIG_EDA_DEF_ALIGN=0x00100000 # CONFIG_EEPROM_AT24=y CONFIG_EEPROM_AT25=y -# CONFIG_EEPROM_LEGACY is not set +CONFIG_EEPROM_LEGACY=m # CONFIG_EEPROM_MAX6875 is not set CONFIG_EEPROM_93CX6=y # CONFIG_EEPROM_93XX46 is not set @@ -2208,7 +2208,8 @@ CONFIG_SENSORS_W83781D=y # CONFIG_SENSORS_W83791D is not set # CONFIG_SENSORS_W83792D is not set # CONFIG_SENSORS_W83793 is not set -# CONFIG_SENSORS_W83795 is not set +CONFIG_SENSORS_W83795=m +CONFIG_SENSORS_W83795_FANCTRL=y # CONFIG_SENSORS_W83L785TS is not set # CONFIG_SENSORS_W83L786NG is not set # CONFIG_SENSORS_W83627HF is not set diff --git a/packages/platforms/ingrasys/vendor-config/PKG.yml b/packages/platforms/ingrasys/vendor-config/PKG.yml index e7d9d9e1..3c21bbc5 100755 --- a/packages/platforms/ingrasys/vendor-config/PKG.yml +++ b/packages/platforms/ingrasys/vendor-config/PKG.yml @@ -1 +1 @@ -!include $ONL_TEMPLATES/platform-config-vendor.yml VENDOR=ingrasys Vendor=ingrasys +!include $ONL_TEMPLATES/platform-config-vendor.yml VENDOR=ingrasys Vendor=Ingrasys diff --git a/packages/platforms/ingrasys/vendor-config/src/python/ingrasys/__init__.py b/packages/platforms/ingrasys/vendor-config/src/python/ingrasys/__init__.py index 36f39285..d18f6329 100755 --- a/packages/platforms/ingrasys/vendor-config/src/python/ingrasys/__init__.py +++ b/packages/platforms/ingrasys/vendor-config/src/python/ingrasys/__init__.py @@ -2,6 +2,6 @@ from onl.platform.base import * -class OnlPlatformingrasys(OnlPlatformBase): +class OnlPlatformIngrasys(OnlPlatformBase): MANUFACTURER='Ingrasys' PRIVATE_ENTERPRISE_NUMBER=2468 diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/PKG.yml b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/PKG.yml index c99bf793..9005a6f4 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/PKG.yml +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/PKG.yml @@ -1 +1 @@ -!include $ONL_TEMPLATES/platform-modules.yml ARCH=amd64 VENDOR=ingrasys BASENAME=x86-64-ingrasys-s9100 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" +!include $ONL_TEMPLATES/no-platform-modules.yml ARCH=amd64 VENDOR=ingrasys BASENAME=x86-64-ingrasys-s9100 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/Makefile b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/Makefile deleted file mode 100755 index f5d7b12f..00000000 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -KERNELS := onl-kernel-3.16-lts-x86-64-all:amd64 -KMODULES := $(wildcard *.c) -VENDOR := ingrasys -BASENAME := x86-64-ingrasys-s9100 -ARCH := x86_64 -include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/eeprom.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/eeprom.c deleted file mode 100755 index 33f8673d..00000000 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/eeprom.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (C) 1998, 1999 Frodo Looijaard and - * Philip Edelbrock - * Copyright (C) 2003 Greg Kroah-Hartman - * Copyright (C) 2003 IBM Corp. - * Copyright (C) 2004 Jean Delvare - * - * 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. - */ - -#include -#include -#include -#include -#include -#include - -/* Addresses to scan */ -static const unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54, - 0x55, 0x56, 0x57, I2C_CLIENT_END }; - - -/* Size of EEPROM in bytes */ -#define EEPROM_SIZE 256 - -/* possible types of eeprom devices */ -enum eeprom_nature { - UNKNOWN, - VAIO, -}; - -/* Each client has this additional data */ -struct eeprom_data { - struct mutex update_lock; - u8 valid; /* bitfield, bit!=0 if slice is valid */ - unsigned long last_updated[8]; /* In jiffies, 8 slices */ - u8 data[EEPROM_SIZE]; /* Register values */ - enum eeprom_nature nature; -}; - - -static void eeprom_update_client(struct i2c_client *client, u8 slice) -{ - struct eeprom_data *data = i2c_get_clientdata(client); - int i; - - mutex_lock(&data->update_lock); - - if (!(data->valid & (1 << slice)) || - time_after(jiffies, data->last_updated[slice] + 300 * HZ)) { - dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); - - if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { - for (i = slice << 5; i < (slice + 1) << 5; i += 32) - if (i2c_smbus_read_i2c_block_data(client, i, - 32, data->data + i) - != 32) - goto exit; - } else { - for (i = slice << 5; i < (slice + 1) << 5; i += 2) { - int word = i2c_smbus_read_word_data(client, i); - if (word < 0) - goto exit; - data->data[i] = word & 0xff; - data->data[i + 1] = word >> 8; - } - } - data->last_updated[slice] = jiffies; - data->valid |= (1 << slice); - } -exit: - mutex_unlock(&data->update_lock); -} - -static ssize_t eeprom_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) -{ - struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); - struct eeprom_data *data = i2c_get_clientdata(client); - u8 slice; - - if (off > EEPROM_SIZE) - return 0; - if (off + count > EEPROM_SIZE) - count = EEPROM_SIZE - off; - - /* Only refresh slices which contain requested bytes */ - for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++) - eeprom_update_client(client, slice); - - /* Hide Vaio private settings to regular users: - - BIOS passwords: bytes 0x00 to 0x0f - - UUID: bytes 0x10 to 0x1f - - Serial number: 0xc0 to 0xdf */ - if (data->nature == VAIO && !capable(CAP_SYS_ADMIN)) { - int i; - - for (i = 0; i < count; i++) { - if ((off + i <= 0x1f) || - (off + i >= 0xc0 && off + i <= 0xdf)) - buf[i] = 0; - else - buf[i] = data->data[off + i]; - } - } else { - memcpy(buf, &data->data[off], count); - } - - return count; -} - -static struct bin_attribute eeprom_attr = { - .attr = { - .name = "eeprom", - .mode = S_IRUGO, - }, - .size = EEPROM_SIZE, - .read = eeprom_read, -}; - -/* Return 0 if detection is successful, -ENODEV otherwise */ -static int eeprom_detect(struct i2c_client *client, struct i2c_board_info *info) -{ - struct i2c_adapter *adapter = client->adapter; - - /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all - addresses 0x50-0x57, but we only care about 0x50. So decline - attaching to addresses >= 0x51 on DDC buses */ - if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x51) - return -ENODEV; - - /* There are four ways we can read the EEPROM data: - (1) I2C block reads (faster, but unsupported by most adapters) - (2) Word reads (128% overhead) - (3) Consecutive byte reads (88% overhead, unsafe) - (4) Regular byte data reads (265% overhead) - The third and fourth methods are not implemented by this driver - because all known adapters support one of the first two. */ - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA) - && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) - return -ENODEV; - - strlcpy(info->type, "eeprom", I2C_NAME_SIZE); - - return 0; -} - -static int eeprom_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct i2c_adapter *adapter = client->adapter; - struct eeprom_data *data; - int err; - - if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { - err = -ENOMEM; - goto exit; - } - - memset(data->data, 0xff, EEPROM_SIZE); - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->nature = UNKNOWN; - - /* Detect the Vaio nature of EEPROMs. - We use the "PCG-" or "VGN-" prefix as the signature. */ - if (client->addr == 0x57 - && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { - char name[4]; - - name[0] = i2c_smbus_read_byte_data(client, 0x80); - name[1] = i2c_smbus_read_byte_data(client, 0x81); - name[2] = i2c_smbus_read_byte_data(client, 0x82); - name[3] = i2c_smbus_read_byte_data(client, 0x83); - - if (!memcmp(name, "PCG-", 4) || !memcmp(name, "VGN-", 4)) { - dev_info(&client->dev, "Vaio EEPROM detected, " - "enabling privacy protection\n"); - data->nature = VAIO; - } - } - - /* create the sysfs eeprom file */ - err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr); - if (err) - goto exit_kfree; - - return 0; - -exit_kfree: - kfree(data); -exit: - return err; -} - -static int eeprom_remove(struct i2c_client *client) -{ - sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr); - kfree(i2c_get_clientdata(client)); - - return 0; -} - -static const struct i2c_device_id eeprom_id[] = { - { "eeprom", 0 }, - { } -}; - -static struct i2c_driver eeprom_driver = { - .driver = { - .name = "eeprom", - }, - .probe = eeprom_probe, - .remove = eeprom_remove, - .id_table = eeprom_id, - - .class = I2C_CLASS_DDC | I2C_CLASS_SPD, - .detect = eeprom_detect, - .address_list = normal_i2c, -}; - -module_i2c_driver(eeprom_driver); - -MODULE_AUTHOR("Frodo Looijaard and " - "Philip Edelbrock and " - "Greg Kroah-Hartman "); -MODULE_DESCRIPTION("I2C EEPROM driver"); -MODULE_LICENSE("GPL"); diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/w83795.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/w83795.c deleted file mode 100755 index 21894131..00000000 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/modules/builds/w83795.c +++ /dev/null @@ -1,2287 +0,0 @@ -/* - * w83795.c - Linux kernel driver for hardware monitoring - * Copyright (C) 2008 Nuvoton Technology Corp. - * Wei Song - * Copyright (C) 2010 Jean Delvare - * - * 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 - version 2. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA. - * - * Supports following chips: - * - * Chip #vin #fanin #pwm #temp #dts wchipid vendid i2c ISA - * w83795g 21 14 8 6 8 0x79 0x5ca3 yes no - * w83795adg 18 14 2 6 8 0x79 0x5ca3 yes no - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Addresses to scan */ -static const unsigned short normal_i2c[] = { - 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END -}; - - -static bool reset; -module_param(reset, bool, 0); -MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); - - -#define W83795_REG_BANKSEL 0x00 -#define W83795_REG_VENDORID 0xfd -#define W83795_REG_CHIPID 0xfe -#define W83795_REG_DEVICEID 0xfb -#define W83795_REG_DEVICEID_A 0xff - -#define W83795_REG_I2C_ADDR 0xfc -#define W83795_REG_CONFIG 0x01 -#define W83795_REG_CONFIG_CONFIG48 0x04 -#define W83795_REG_CONFIG_START 0x01 - -/* Multi-Function Pin Ctrl Registers */ -#define W83795_REG_VOLT_CTRL1 0x02 -#define W83795_REG_VOLT_CTRL2 0x03 -#define W83795_REG_TEMP_CTRL1 0x04 -#define W83795_REG_TEMP_CTRL2 0x05 -#define W83795_REG_FANIN_CTRL1 0x06 -#define W83795_REG_FANIN_CTRL2 0x07 -#define W83795_REG_VMIGB_CTRL 0x08 - -#define TEMP_READ 0 -#define TEMP_CRIT 1 -#define TEMP_CRIT_HYST 2 -#define TEMP_WARN 3 -#define TEMP_WARN_HYST 4 -/* - * only crit and crit_hyst affect real-time alarm status - * current crit crit_hyst warn warn_hyst - */ -static const u16 W83795_REG_TEMP[][5] = { - {0x21, 0x96, 0x97, 0x98, 0x99}, /* TD1/TR1 */ - {0x22, 0x9a, 0x9b, 0x9c, 0x9d}, /* TD2/TR2 */ - {0x23, 0x9e, 0x9f, 0xa0, 0xa1}, /* TD3/TR3 */ - {0x24, 0xa2, 0xa3, 0xa4, 0xa5}, /* TD4/TR4 */ - {0x1f, 0xa6, 0xa7, 0xa8, 0xa9}, /* TR5 */ - {0x20, 0xaa, 0xab, 0xac, 0xad}, /* TR6 */ -}; - -#define IN_READ 0 -#define IN_MAX 1 -#define IN_LOW 2 -static const u16 W83795_REG_IN[][3] = { - /* Current, HL, LL */ - {0x10, 0x70, 0x71}, /* VSEN1 */ - {0x11, 0x72, 0x73}, /* VSEN2 */ - {0x12, 0x74, 0x75}, /* VSEN3 */ - {0x13, 0x76, 0x77}, /* VSEN4 */ - {0x14, 0x78, 0x79}, /* VSEN5 */ - {0x15, 0x7a, 0x7b}, /* VSEN6 */ - {0x16, 0x7c, 0x7d}, /* VSEN7 */ - {0x17, 0x7e, 0x7f}, /* VSEN8 */ - {0x18, 0x80, 0x81}, /* VSEN9 */ - {0x19, 0x82, 0x83}, /* VSEN10 */ - {0x1A, 0x84, 0x85}, /* VSEN11 */ - {0x1B, 0x86, 0x87}, /* VTT */ - {0x1C, 0x88, 0x89}, /* 3VDD */ - {0x1D, 0x8a, 0x8b}, /* 3VSB */ - {0x1E, 0x8c, 0x8d}, /* VBAT */ - {0x1F, 0xa6, 0xa7}, /* VSEN12 */ - {0x20, 0xaa, 0xab}, /* VSEN13 */ - {0x21, 0x96, 0x97}, /* VSEN14 */ - {0x22, 0x9a, 0x9b}, /* VSEN15 */ - {0x23, 0x9e, 0x9f}, /* VSEN16 */ - {0x24, 0xa2, 0xa3}, /* VSEN17 */ -}; -#define W83795_REG_VRLSB 0x3C - -static const u8 W83795_REG_IN_HL_LSB[] = { - 0x8e, /* VSEN1-4 */ - 0x90, /* VSEN5-8 */ - 0x92, /* VSEN9-11 */ - 0x94, /* VTT, 3VDD, 3VSB, 3VBAT */ - 0xa8, /* VSEN12 */ - 0xac, /* VSEN13 */ - 0x98, /* VSEN14 */ - 0x9c, /* VSEN15 */ - 0xa0, /* VSEN16 */ - 0xa4, /* VSEN17 */ -}; - -#define IN_LSB_REG(index, type) \ - (((type) == 1) ? W83795_REG_IN_HL_LSB[(index)] \ - : (W83795_REG_IN_HL_LSB[(index)] + 1)) - -#define IN_LSB_SHIFT 0 -#define IN_LSB_IDX 1 -static const u8 IN_LSB_SHIFT_IDX[][2] = { - /* High/Low LSB shift, LSB No. */ - {0x00, 0x00}, /* VSEN1 */ - {0x02, 0x00}, /* VSEN2 */ - {0x04, 0x00}, /* VSEN3 */ - {0x06, 0x00}, /* VSEN4 */ - {0x00, 0x01}, /* VSEN5 */ - {0x02, 0x01}, /* VSEN6 */ - {0x04, 0x01}, /* VSEN7 */ - {0x06, 0x01}, /* VSEN8 */ - {0x00, 0x02}, /* VSEN9 */ - {0x02, 0x02}, /* VSEN10 */ - {0x04, 0x02}, /* VSEN11 */ - {0x00, 0x03}, /* VTT */ - {0x02, 0x03}, /* 3VDD */ - {0x04, 0x03}, /* 3VSB */ - {0x06, 0x03}, /* VBAT */ - {0x06, 0x04}, /* VSEN12 */ - {0x06, 0x05}, /* VSEN13 */ - {0x06, 0x06}, /* VSEN14 */ - {0x06, 0x07}, /* VSEN15 */ - {0x06, 0x08}, /* VSEN16 */ - {0x06, 0x09}, /* VSEN17 */ -}; - - -#define W83795_REG_FAN(index) (0x2E + (index)) -#define W83795_REG_FAN_MIN_HL(index) (0xB6 + (index)) -#define W83795_REG_FAN_MIN_LSB(index) (0xC4 + (index) / 2) -#define W83795_REG_FAN_MIN_LSB_SHIFT(index) \ - (((index) & 1) ? 4 : 0) - -#define W83795_REG_VID_CTRL 0x6A - -#define W83795_REG_ALARM_CTRL 0x40 -#define ALARM_CTRL_RTSACS (1 << 7) -#define W83795_REG_ALARM(index) (0x41 + (index)) -#define W83795_REG_CLR_CHASSIS 0x4D -#define W83795_REG_BEEP(index) (0x50 + (index)) - -#define W83795_REG_OVT_CFG 0x58 -#define OVT_CFG_SEL (1 << 7) - - -#define W83795_REG_FCMS1 0x201 -#define W83795_REG_FCMS2 0x208 -#define W83795_REG_TFMR(index) (0x202 + (index)) -#define W83795_REG_FOMC 0x20F - -#define W83795_REG_TSS(index) (0x209 + (index)) - -#define TSS_MAP_RESERVED 0xff -static const u8 tss_map[4][6] = { - { 0, 1, 2, 3, 4, 5}, - { 6, 7, 8, 9, 0, 1}, - {10, 11, 12, 13, 2, 3}, - { 4, 5, 4, 5, TSS_MAP_RESERVED, TSS_MAP_RESERVED}, -}; - -#define PWM_OUTPUT 0 -#define PWM_FREQ 1 -#define PWM_START 2 -#define PWM_NONSTOP 3 -#define PWM_STOP_TIME 4 -#define W83795_REG_PWM(index, nr) (0x210 + (nr) * 8 + (index)) - -#define W83795_REG_FTSH(index) (0x240 + (index) * 2) -#define W83795_REG_FTSL(index) (0x241 + (index) * 2) -#define W83795_REG_TFTS 0x250 - -#define TEMP_PWM_TTTI 0 -#define TEMP_PWM_CTFS 1 -#define TEMP_PWM_HCT 2 -#define TEMP_PWM_HOT 3 -#define W83795_REG_TTTI(index) (0x260 + (index)) -#define W83795_REG_CTFS(index) (0x268 + (index)) -#define W83795_REG_HT(index) (0x270 + (index)) - -#define SF4_TEMP 0 -#define SF4_PWM 1 -#define W83795_REG_SF4_TEMP(temp_num, index) \ - (0x280 + 0x10 * (temp_num) + (index)) -#define W83795_REG_SF4_PWM(temp_num, index) \ - (0x288 + 0x10 * (temp_num) + (index)) - -#define W83795_REG_DTSC 0x301 -#define W83795_REG_DTSE 0x302 -#define W83795_REG_DTS(index) (0x26 + (index)) -#define W83795_REG_PECI_TBASE(index) (0x320 + (index)) - -#define DTS_CRIT 0 -#define DTS_CRIT_HYST 1 -#define DTS_WARN 2 -#define DTS_WARN_HYST 3 -#define W83795_REG_DTS_EXT(index) (0xB2 + (index)) - -#define SETUP_PWM_DEFAULT 0 -#define SETUP_PWM_UPTIME 1 -#define SETUP_PWM_DOWNTIME 2 -#define W83795_REG_SETUP_PWM(index) (0x20C + (index)) - -static inline u16 in_from_reg(u8 index, u16 val) -{ - /* 3VDD, 3VSB and VBAT: 6 mV/bit; other inputs: 2 mV/bit */ - if (index >= 12 && index <= 14) - return val * 6; - else - return val * 2; -} - -static inline u16 in_to_reg(u8 index, u16 val) -{ - if (index >= 12 && index <= 14) - return val / 6; - else - return val / 2; -} - -static inline unsigned long fan_from_reg(u16 val) -{ - if ((val == 0xfff) || (val == 0)) - return 0; - return 1350000UL / val; -} - -static inline u16 fan_to_reg(long rpm) -{ - if (rpm <= 0) - return 0x0fff; - return clamp_val((1350000 + (rpm >> 1)) / rpm, 1, 0xffe); -} - -static inline unsigned long time_from_reg(u8 reg) -{ - return reg * 100; -} - -static inline u8 time_to_reg(unsigned long val) -{ - return clamp_val((val + 50) / 100, 0, 0xff); -} - -static inline long temp_from_reg(s8 reg) -{ - return reg * 1000; -} - -static inline s8 temp_to_reg(long val, s8 min, s8 max) -{ - return clamp_val(val / 1000, min, max); -} - -static const u16 pwm_freq_cksel0[16] = { - 1024, 512, 341, 256, 205, 171, 146, 128, - 85, 64, 32, 16, 8, 4, 2, 1 -}; - -static unsigned int pwm_freq_from_reg(u8 reg, u16 clkin) -{ - unsigned long base_clock; - - if (reg & 0x80) { - base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256); - return base_clock / ((reg & 0x7f) + 1); - } else - return pwm_freq_cksel0[reg & 0x0f]; -} - -static u8 pwm_freq_to_reg(unsigned long val, u16 clkin) -{ - unsigned long base_clock; - u8 reg0, reg1; - unsigned long best0, best1; - - /* Best fit for cksel = 0 */ - for (reg0 = 0; reg0 < ARRAY_SIZE(pwm_freq_cksel0) - 1; reg0++) { - if (val > (pwm_freq_cksel0[reg0] + - pwm_freq_cksel0[reg0 + 1]) / 2) - break; - } - if (val < 375) /* cksel = 1 can't beat this */ - return reg0; - best0 = pwm_freq_cksel0[reg0]; - - /* Best fit for cksel = 1 */ - base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256); - reg1 = clamp_val(DIV_ROUND_CLOSEST(base_clock, val), 1, 128); - best1 = base_clock / reg1; - reg1 = 0x80 | (reg1 - 1); - - /* Choose the closest one */ - if (abs(val - best0) > abs(val - best1)) - return reg1; - else - return reg0; -} - -enum chip_types {w83795g, w83795adg}; - -struct w83795_data { - struct device *hwmon_dev; - struct mutex update_lock; - unsigned long last_updated; /* In jiffies */ - enum chip_types chip_type; - - u8 bank; - - u32 has_in; /* Enable monitor VIN or not */ - u8 has_dyn_in; /* Only in2-0 can have this */ - u16 in[21][3]; /* Register value, read/high/low */ - u8 in_lsb[10][3]; /* LSB Register value, high/low */ - u8 has_gain; /* has gain: in17-20 * 8 */ - - u16 has_fan; /* Enable fan14-1 or not */ - u16 fan[14]; /* Register value combine */ - u16 fan_min[14]; /* Register value combine */ - - u8 has_temp; /* Enable monitor temp6-1 or not */ - s8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */ - u8 temp_read_vrlsb[6]; - u8 temp_mode; /* Bit vector, 0 = TR, 1 = TD */ - u8 temp_src[3]; /* Register value */ - - u8 enable_dts; /* - * Enable PECI and SB-TSI, - * bit 0: =1 enable, =0 disable, - * bit 1: =1 AMD SB-TSI, =0 Intel PECI - */ - u8 has_dts; /* Enable monitor DTS temp */ - s8 dts[8]; /* Register value */ - u8 dts_read_vrlsb[8]; /* Register value */ - s8 dts_ext[4]; /* Register value */ - - u8 has_pwm; /* - * 795g supports 8 pwm, 795adg only supports 2, - * no config register, only affected by chip - * type - */ - u8 pwm[8][5]; /* - * Register value, output, freq, start, - * non stop, stop time - */ - u16 clkin; /* CLKIN frequency in kHz */ - u8 pwm_fcms[2]; /* Register value */ - u8 pwm_tfmr[6]; /* Register value */ - u8 pwm_fomc; /* Register value */ - - u16 target_speed[8]; /* - * Register value, target speed for speed - * cruise - */ - u8 tol_speed; /* tolerance of target speed */ - u8 pwm_temp[6][4]; /* TTTI, CTFS, HCT, HOT */ - u8 sf4_reg[6][2][7]; /* 6 temp, temp/dcpwm, 7 registers */ - - u8 setup_pwm[3]; /* Register value */ - - u8 alarms[6]; /* Register value */ - u8 enable_beep; - u8 beeps[6]; /* Register value */ - - char valid; - char valid_limits; - char valid_pwm_config; -}; - -/* - * Hardware access - * We assume that nobdody can change the bank outside the driver. - */ - -/* Must be called with data->update_lock held, except during initialization */ -static int w83795_set_bank(struct i2c_client *client, u8 bank) -{ - struct w83795_data *data = i2c_get_clientdata(client); - int err; - - /* If the same bank is already set, nothing to do */ - if ((data->bank & 0x07) == bank) - return 0; - - /* Change to new bank, preserve all other bits */ - bank |= data->bank & ~0x07; - err = i2c_smbus_write_byte_data(client, W83795_REG_BANKSEL, bank); - if (err < 0) { - dev_err(&client->dev, - "Failed to set bank to %d, err %d\n", - (int)bank, err); - return err; - } - data->bank = bank; - - return 0; -} - -/* Must be called with data->update_lock held, except during initialization */ -static u8 w83795_read(struct i2c_client *client, u16 reg) -{ - int err; - - err = w83795_set_bank(client, reg >> 8); - if (err < 0) - return 0x00; /* Arbitrary */ - - err = i2c_smbus_read_byte_data(client, reg & 0xff); - if (err < 0) { - dev_err(&client->dev, - "Failed to read from register 0x%03x, err %d\n", - (int)reg, err); - return 0x00; /* Arbitrary */ - } - return err; -} - -/* Must be called with data->update_lock held, except during initialization */ -static int w83795_write(struct i2c_client *client, u16 reg, u8 value) -{ - int err; - - err = w83795_set_bank(client, reg >> 8); - if (err < 0) - return err; - - err = i2c_smbus_write_byte_data(client, reg & 0xff, value); - if (err < 0) - dev_err(&client->dev, - "Failed to write to register 0x%03x, err %d\n", - (int)reg, err); - return err; -} - -static void w83795_update_limits(struct i2c_client *client) -{ - struct w83795_data *data = i2c_get_clientdata(client); - int i, limit; - u8 lsb; - - /* Read the voltage limits */ - for (i = 0; i < ARRAY_SIZE(data->in); i++) { - if (!(data->has_in & (1 << i))) - continue; - data->in[i][IN_MAX] = - w83795_read(client, W83795_REG_IN[i][IN_MAX]); - data->in[i][IN_LOW] = - w83795_read(client, W83795_REG_IN[i][IN_LOW]); - } - for (i = 0; i < ARRAY_SIZE(data->in_lsb); i++) { - if ((i == 2 && data->chip_type == w83795adg) || - (i >= 4 && !(data->has_in & (1 << (i + 11))))) - continue; - data->in_lsb[i][IN_MAX] = - w83795_read(client, IN_LSB_REG(i, IN_MAX)); - data->in_lsb[i][IN_LOW] = - w83795_read(client, IN_LSB_REG(i, IN_LOW)); - } - - /* Read the fan limits */ - lsb = 0; /* Silent false gcc warning */ - for (i = 0; i < ARRAY_SIZE(data->fan); i++) { - /* - * Each register contains LSB for 2 fans, but we want to - * read it only once to save time - */ - if ((i & 1) == 0 && (data->has_fan & (3 << i))) - lsb = w83795_read(client, W83795_REG_FAN_MIN_LSB(i)); - - if (!(data->has_fan & (1 << i))) - continue; - data->fan_min[i] = - w83795_read(client, W83795_REG_FAN_MIN_HL(i)) << 4; - data->fan_min[i] |= - (lsb >> W83795_REG_FAN_MIN_LSB_SHIFT(i)) & 0x0F; - } - - /* Read the temperature limits */ - for (i = 0; i < ARRAY_SIZE(data->temp); i++) { - if (!(data->has_temp & (1 << i))) - continue; - for (limit = TEMP_CRIT; limit <= TEMP_WARN_HYST; limit++) - data->temp[i][limit] = - w83795_read(client, W83795_REG_TEMP[i][limit]); - } - - /* Read the DTS limits */ - if (data->enable_dts) { - for (limit = DTS_CRIT; limit <= DTS_WARN_HYST; limit++) - data->dts_ext[limit] = - w83795_read(client, W83795_REG_DTS_EXT(limit)); - } - - /* Read beep settings */ - if (data->enable_beep) { - for (i = 0; i < ARRAY_SIZE(data->beeps); i++) - data->beeps[i] = - w83795_read(client, W83795_REG_BEEP(i)); - } - - data->valid_limits = 1; -} - -static struct w83795_data *w83795_update_pwm_config(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - int i, tmp; - - mutex_lock(&data->update_lock); - - if (data->valid_pwm_config) - goto END; - - /* Read temperature source selection */ - for (i = 0; i < ARRAY_SIZE(data->temp_src); i++) - data->temp_src[i] = w83795_read(client, W83795_REG_TSS(i)); - - /* Read automatic fan speed control settings */ - data->pwm_fcms[0] = w83795_read(client, W83795_REG_FCMS1); - data->pwm_fcms[1] = w83795_read(client, W83795_REG_FCMS2); - for (i = 0; i < ARRAY_SIZE(data->pwm_tfmr); i++) - data->pwm_tfmr[i] = w83795_read(client, W83795_REG_TFMR(i)); - data->pwm_fomc = w83795_read(client, W83795_REG_FOMC); - for (i = 0; i < data->has_pwm; i++) { - for (tmp = PWM_FREQ; tmp <= PWM_STOP_TIME; tmp++) - data->pwm[i][tmp] = - w83795_read(client, W83795_REG_PWM(i, tmp)); - } - for (i = 0; i < ARRAY_SIZE(data->target_speed); i++) { - data->target_speed[i] = - w83795_read(client, W83795_REG_FTSH(i)) << 4; - data->target_speed[i] |= - w83795_read(client, W83795_REG_FTSL(i)) >> 4; - } - data->tol_speed = w83795_read(client, W83795_REG_TFTS) & 0x3f; - - for (i = 0; i < ARRAY_SIZE(data->pwm_temp); i++) { - data->pwm_temp[i][TEMP_PWM_TTTI] = - w83795_read(client, W83795_REG_TTTI(i)) & 0x7f; - data->pwm_temp[i][TEMP_PWM_CTFS] = - w83795_read(client, W83795_REG_CTFS(i)); - tmp = w83795_read(client, W83795_REG_HT(i)); - data->pwm_temp[i][TEMP_PWM_HCT] = tmp >> 4; - data->pwm_temp[i][TEMP_PWM_HOT] = tmp & 0x0f; - } - - /* Read SmartFanIV trip points */ - for (i = 0; i < ARRAY_SIZE(data->sf4_reg); i++) { - for (tmp = 0; tmp < 7; tmp++) { - data->sf4_reg[i][SF4_TEMP][tmp] = - w83795_read(client, - W83795_REG_SF4_TEMP(i, tmp)); - data->sf4_reg[i][SF4_PWM][tmp] = - w83795_read(client, W83795_REG_SF4_PWM(i, tmp)); - } - } - - /* Read setup PWM */ - for (i = 0; i < ARRAY_SIZE(data->setup_pwm); i++) - data->setup_pwm[i] = - w83795_read(client, W83795_REG_SETUP_PWM(i)); - - data->valid_pwm_config = 1; - -END: - mutex_unlock(&data->update_lock); - return data; -} - -static struct w83795_data *w83795_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - u16 tmp; - u8 intrusion; - int i; - - mutex_lock(&data->update_lock); - - if (!data->valid_limits) - w83795_update_limits(client); - - if (!(time_after(jiffies, data->last_updated + HZ * 2) - || !data->valid)) - goto END; - - /* Update the voltages value */ - for (i = 0; i < ARRAY_SIZE(data->in); i++) { - if (!(data->has_in & (1 << i))) - continue; - tmp = w83795_read(client, W83795_REG_IN[i][IN_READ]) << 2; - tmp |= w83795_read(client, W83795_REG_VRLSB) >> 6; - data->in[i][IN_READ] = tmp; - } - - /* in0-2 can have dynamic limits (W83795G only) */ - if (data->has_dyn_in) { - u8 lsb_max = w83795_read(client, IN_LSB_REG(0, IN_MAX)); - u8 lsb_low = w83795_read(client, IN_LSB_REG(0, IN_LOW)); - - for (i = 0; i < 3; i++) { - if (!(data->has_dyn_in & (1 << i))) - continue; - data->in[i][IN_MAX] = - w83795_read(client, W83795_REG_IN[i][IN_MAX]); - data->in[i][IN_LOW] = - w83795_read(client, W83795_REG_IN[i][IN_LOW]); - data->in_lsb[i][IN_MAX] = (lsb_max >> (2 * i)) & 0x03; - data->in_lsb[i][IN_LOW] = (lsb_low >> (2 * i)) & 0x03; - } - } - - /* Update fan */ - for (i = 0; i < ARRAY_SIZE(data->fan); i++) { - if (!(data->has_fan & (1 << i))) - continue; - data->fan[i] = w83795_read(client, W83795_REG_FAN(i)) << 4; - data->fan[i] |= w83795_read(client, W83795_REG_VRLSB) >> 4; - } - - /* Update temperature */ - for (i = 0; i < ARRAY_SIZE(data->temp); i++) { - data->temp[i][TEMP_READ] = - w83795_read(client, W83795_REG_TEMP[i][TEMP_READ]); - data->temp_read_vrlsb[i] = - w83795_read(client, W83795_REG_VRLSB); - } - - /* Update dts temperature */ - if (data->enable_dts) { - for (i = 0; i < ARRAY_SIZE(data->dts); i++) { - if (!(data->has_dts & (1 << i))) - continue; - data->dts[i] = - w83795_read(client, W83795_REG_DTS(i)); - data->dts_read_vrlsb[i] = - w83795_read(client, W83795_REG_VRLSB); - } - } - - /* Update pwm output */ - for (i = 0; i < data->has_pwm; i++) { - data->pwm[i][PWM_OUTPUT] = - w83795_read(client, W83795_REG_PWM(i, PWM_OUTPUT)); - } - - /* - * Update intrusion and alarms - * It is important to read intrusion first, because reading from - * register SMI STS6 clears the interrupt status temporarily. - */ - tmp = w83795_read(client, W83795_REG_ALARM_CTRL); - /* Switch to interrupt status for intrusion if needed */ - if (tmp & ALARM_CTRL_RTSACS) - w83795_write(client, W83795_REG_ALARM_CTRL, - tmp & ~ALARM_CTRL_RTSACS); - intrusion = w83795_read(client, W83795_REG_ALARM(5)) & (1 << 6); - /* Switch to real-time alarms */ - w83795_write(client, W83795_REG_ALARM_CTRL, tmp | ALARM_CTRL_RTSACS); - for (i = 0; i < ARRAY_SIZE(data->alarms); i++) - data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i)); - data->alarms[5] |= intrusion; - /* Restore original configuration if needed */ - if (!(tmp & ALARM_CTRL_RTSACS)) - w83795_write(client, W83795_REG_ALARM_CTRL, - tmp & ~ALARM_CTRL_RTSACS); - - data->last_updated = jiffies; - data->valid = 1; - -END: - mutex_unlock(&data->update_lock); - return data; -} - -/* - * Sysfs attributes - */ - -#define ALARM_STATUS 0 -#define BEEP_ENABLE 1 -static ssize_t -show_alarm_beep(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w83795_data *data = w83795_update_device(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index >> 3; - int bit = sensor_attr->index & 0x07; - u8 val; - - if (nr == ALARM_STATUS) - val = (data->alarms[index] >> bit) & 1; - else /* BEEP_ENABLE */ - val = (data->beeps[index] >> bit) & 1; - - return sprintf(buf, "%u\n", val); -} - -static ssize_t -store_beep(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int index = sensor_attr->index >> 3; - int shift = sensor_attr->index & 0x07; - u8 beep_bit = 1 << shift; - unsigned long val; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - if (val != 0 && val != 1) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->beeps[index] = w83795_read(client, W83795_REG_BEEP(index)); - data->beeps[index] &= ~beep_bit; - data->beeps[index] |= val << shift; - w83795_write(client, W83795_REG_BEEP(index), data->beeps[index]); - mutex_unlock(&data->update_lock); - - return count; -} - -/* Write 0 to clear chassis alarm */ -static ssize_t -store_chassis_clear(struct device *dev, - struct device_attribute *attr, const char *buf, - size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - unsigned long val; - - if (kstrtoul(buf, 10, &val) < 0 || val != 0) - return -EINVAL; - - mutex_lock(&data->update_lock); - val = w83795_read(client, W83795_REG_CLR_CHASSIS); - val |= 0x80; - w83795_write(client, W83795_REG_CLR_CHASSIS, val); - - /* Clear status and force cache refresh */ - w83795_read(client, W83795_REG_ALARM(5)); - data->valid = 0; - mutex_unlock(&data->update_lock); - return count; -} - -#define FAN_INPUT 0 -#define FAN_MIN 1 -static ssize_t -show_fan(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - struct w83795_data *data = w83795_update_device(dev); - u16 val; - - if (nr == FAN_INPUT) - val = data->fan[index] & 0x0fff; - else - val = data->fan_min[index] & 0x0fff; - - return sprintf(buf, "%lu\n", fan_from_reg(val)); -} - -static ssize_t -store_fan_min(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int index = sensor_attr->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - unsigned long val; - - if (kstrtoul(buf, 10, &val)) - return -EINVAL; - val = fan_to_reg(val); - - mutex_lock(&data->update_lock); - data->fan_min[index] = val; - w83795_write(client, W83795_REG_FAN_MIN_HL(index), (val >> 4) & 0xff); - val &= 0x0f; - if (index & 1) { - val <<= 4; - val |= w83795_read(client, W83795_REG_FAN_MIN_LSB(index)) - & 0x0f; - } else { - val |= w83795_read(client, W83795_REG_FAN_MIN_LSB(index)) - & 0xf0; - } - w83795_write(client, W83795_REG_FAN_MIN_LSB(index), val & 0xff); - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t -show_pwm(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w83795_data *data; - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - unsigned int val; - - data = nr == PWM_OUTPUT ? w83795_update_device(dev) - : w83795_update_pwm_config(dev); - - switch (nr) { - case PWM_STOP_TIME: - val = time_from_reg(data->pwm[index][nr]); - break; - case PWM_FREQ: - val = pwm_freq_from_reg(data->pwm[index][nr], data->clkin); - break; - default: - val = data->pwm[index][nr]; - break; - } - - return sprintf(buf, "%u\n", val); -} - -static ssize_t -store_pwm(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - unsigned long val; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - - mutex_lock(&data->update_lock); - switch (nr) { - case PWM_STOP_TIME: - val = time_to_reg(val); - break; - case PWM_FREQ: - val = pwm_freq_to_reg(val, data->clkin); - break; - default: - val = clamp_val(val, 0, 0xff); - break; - } - w83795_write(client, W83795_REG_PWM(index, nr), val); - data->pwm[index][nr] = val; - mutex_unlock(&data->update_lock); - return count; -} - -static ssize_t -show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - struct w83795_data *data = w83795_update_pwm_config(dev); - int index = sensor_attr->index; - u8 tmp; - - /* Speed cruise mode */ - if (data->pwm_fcms[0] & (1 << index)) { - tmp = 2; - goto out; - } - /* Thermal cruise or SmartFan IV mode */ - for (tmp = 0; tmp < 6; tmp++) { - if (data->pwm_tfmr[tmp] & (1 << index)) { - tmp = 3; - goto out; - } - } - /* Manual mode */ - tmp = 1; - -out: - return sprintf(buf, "%u\n", tmp); -} - -static ssize_t -store_pwm_enable(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = w83795_update_pwm_config(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int index = sensor_attr->index; - unsigned long val; - int i; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - if (val < 1 || val > 2) - return -EINVAL; - -#ifndef CONFIG_SENSORS_W83795_FANCTRL - if (val > 1) { - dev_warn(dev, "Automatic fan speed control support disabled\n"); - dev_warn(dev, "Build with CONFIG_SENSORS_W83795_FANCTRL=y if you want it\n"); - return -EOPNOTSUPP; - } -#endif - - mutex_lock(&data->update_lock); - switch (val) { - case 1: - /* Clear speed cruise mode bits */ - data->pwm_fcms[0] &= ~(1 << index); - w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]); - /* Clear thermal cruise mode bits */ - for (i = 0; i < 6; i++) { - data->pwm_tfmr[i] &= ~(1 << index); - w83795_write(client, W83795_REG_TFMR(i), - data->pwm_tfmr[i]); - } - break; - case 2: - data->pwm_fcms[0] |= (1 << index); - w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]); - break; - } - mutex_unlock(&data->update_lock); - return count; -} - -static ssize_t -show_pwm_mode(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w83795_data *data = w83795_update_pwm_config(dev); - int index = to_sensor_dev_attr_2(attr)->index; - unsigned int mode; - - if (data->pwm_fomc & (1 << index)) - mode = 0; /* DC */ - else - mode = 1; /* PWM */ - - return sprintf(buf, "%u\n", mode); -} - -/* - * Check whether a given temperature source can ever be useful. - * Returns the number of selectable temperature channels which are - * enabled. - */ -static int w83795_tss_useful(const struct w83795_data *data, int tsrc) -{ - int useful = 0, i; - - for (i = 0; i < 4; i++) { - if (tss_map[i][tsrc] == TSS_MAP_RESERVED) - continue; - if (tss_map[i][tsrc] < 6) /* Analog */ - useful += (data->has_temp >> tss_map[i][tsrc]) & 1; - else /* Digital */ - useful += (data->has_dts >> (tss_map[i][tsrc] - 6)) & 1; - } - - return useful; -} - -static ssize_t -show_temp_src(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - struct w83795_data *data = w83795_update_pwm_config(dev); - int index = sensor_attr->index; - u8 tmp = data->temp_src[index / 2]; - - if (index & 1) - tmp >>= 4; /* Pick high nibble */ - else - tmp &= 0x0f; /* Pick low nibble */ - - /* Look-up the actual temperature channel number */ - if (tmp >= 4 || tss_map[tmp][index] == TSS_MAP_RESERVED) - return -EINVAL; /* Shouldn't happen */ - - return sprintf(buf, "%u\n", (unsigned int)tss_map[tmp][index] + 1); -} - -static ssize_t -store_temp_src(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = w83795_update_pwm_config(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int index = sensor_attr->index; - int tmp; - unsigned long channel; - u8 val = index / 2; - - if (kstrtoul(buf, 10, &channel) < 0 || - channel < 1 || channel > 14) - return -EINVAL; - - /* Check if request can be fulfilled */ - for (tmp = 0; tmp < 4; tmp++) { - if (tss_map[tmp][index] == channel - 1) - break; - } - if (tmp == 4) /* No match */ - return -EINVAL; - - mutex_lock(&data->update_lock); - if (index & 1) { - tmp <<= 4; - data->temp_src[val] &= 0x0f; - } else { - data->temp_src[val] &= 0xf0; - } - data->temp_src[val] |= tmp; - w83795_write(client, W83795_REG_TSS(val), data->temp_src[val]); - mutex_unlock(&data->update_lock); - - return count; -} - -#define TEMP_PWM_ENABLE 0 -#define TEMP_PWM_FAN_MAP 1 -static ssize_t -show_temp_pwm_enable(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct w83795_data *data = w83795_update_pwm_config(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - u8 tmp = 0xff; - - switch (nr) { - case TEMP_PWM_ENABLE: - tmp = (data->pwm_fcms[1] >> index) & 1; - if (tmp) - tmp = 4; - else - tmp = 3; - break; - case TEMP_PWM_FAN_MAP: - tmp = data->pwm_tfmr[index]; - break; - } - - return sprintf(buf, "%u\n", tmp); -} - -static ssize_t -store_temp_pwm_enable(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = w83795_update_pwm_config(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - unsigned long tmp; - - if (kstrtoul(buf, 10, &tmp) < 0) - return -EINVAL; - - switch (nr) { - case TEMP_PWM_ENABLE: - if (tmp != 3 && tmp != 4) - return -EINVAL; - tmp -= 3; - mutex_lock(&data->update_lock); - data->pwm_fcms[1] &= ~(1 << index); - data->pwm_fcms[1] |= tmp << index; - w83795_write(client, W83795_REG_FCMS2, data->pwm_fcms[1]); - mutex_unlock(&data->update_lock); - break; - case TEMP_PWM_FAN_MAP: - mutex_lock(&data->update_lock); - tmp = clamp_val(tmp, 0, 0xff); - w83795_write(client, W83795_REG_TFMR(index), tmp); - data->pwm_tfmr[index] = tmp; - mutex_unlock(&data->update_lock); - break; - } - return count; -} - -#define FANIN_TARGET 0 -#define FANIN_TOL 1 -static ssize_t -show_fanin(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w83795_data *data = w83795_update_pwm_config(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - u16 tmp = 0; - - switch (nr) { - case FANIN_TARGET: - tmp = fan_from_reg(data->target_speed[index]); - break; - case FANIN_TOL: - tmp = data->tol_speed; - break; - } - - return sprintf(buf, "%u\n", tmp); -} - -static ssize_t -store_fanin(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - unsigned long val; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - - mutex_lock(&data->update_lock); - switch (nr) { - case FANIN_TARGET: - val = fan_to_reg(clamp_val(val, 0, 0xfff)); - w83795_write(client, W83795_REG_FTSH(index), val >> 4); - w83795_write(client, W83795_REG_FTSL(index), (val << 4) & 0xf0); - data->target_speed[index] = val; - break; - case FANIN_TOL: - val = clamp_val(val, 0, 0x3f); - w83795_write(client, W83795_REG_TFTS, val); - data->tol_speed = val; - break; - } - mutex_unlock(&data->update_lock); - - return count; -} - - -static ssize_t -show_temp_pwm(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w83795_data *data = w83795_update_pwm_config(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - long tmp = temp_from_reg(data->pwm_temp[index][nr]); - - return sprintf(buf, "%ld\n", tmp); -} - -static ssize_t -store_temp_pwm(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - unsigned long val; - u8 tmp; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - val /= 1000; - - mutex_lock(&data->update_lock); - switch (nr) { - case TEMP_PWM_TTTI: - val = clamp_val(val, 0, 0x7f); - w83795_write(client, W83795_REG_TTTI(index), val); - break; - case TEMP_PWM_CTFS: - val = clamp_val(val, 0, 0x7f); - w83795_write(client, W83795_REG_CTFS(index), val); - break; - case TEMP_PWM_HCT: - val = clamp_val(val, 0, 0x0f); - tmp = w83795_read(client, W83795_REG_HT(index)); - tmp &= 0x0f; - tmp |= (val << 4) & 0xf0; - w83795_write(client, W83795_REG_HT(index), tmp); - break; - case TEMP_PWM_HOT: - val = clamp_val(val, 0, 0x0f); - tmp = w83795_read(client, W83795_REG_HT(index)); - tmp &= 0xf0; - tmp |= val & 0x0f; - w83795_write(client, W83795_REG_HT(index), tmp); - break; - } - data->pwm_temp[index][nr] = val; - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t -show_sf4_pwm(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w83795_data *data = w83795_update_pwm_config(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - - return sprintf(buf, "%u\n", data->sf4_reg[index][SF4_PWM][nr]); -} - -static ssize_t -store_sf4_pwm(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - unsigned long val; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - - mutex_lock(&data->update_lock); - w83795_write(client, W83795_REG_SF4_PWM(index, nr), val); - data->sf4_reg[index][SF4_PWM][nr] = val; - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t -show_sf4_temp(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w83795_data *data = w83795_update_pwm_config(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - - return sprintf(buf, "%u\n", - (data->sf4_reg[index][SF4_TEMP][nr]) * 1000); -} - -static ssize_t -store_sf4_temp(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - unsigned long val; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - val /= 1000; - - mutex_lock(&data->update_lock); - w83795_write(client, W83795_REG_SF4_TEMP(index, nr), val); - data->sf4_reg[index][SF4_TEMP][nr] = val; - mutex_unlock(&data->update_lock); - - return count; -} - - -static ssize_t -show_temp(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - struct w83795_data *data = w83795_update_device(dev); - long temp = temp_from_reg(data->temp[index][nr]); - - if (nr == TEMP_READ) - temp += (data->temp_read_vrlsb[index] >> 6) * 250; - return sprintf(buf, "%ld\n", temp); -} - -static ssize_t -store_temp(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - long tmp; - - if (kstrtol(buf, 10, &tmp) < 0) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->temp[index][nr] = temp_to_reg(tmp, -128, 127); - w83795_write(client, W83795_REG_TEMP[index][nr], data->temp[index][nr]); - mutex_unlock(&data->update_lock); - return count; -} - - -static ssize_t -show_dts_mode(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w83795_data *data = dev_get_drvdata(dev); - int tmp; - - if (data->enable_dts & 2) - tmp = 5; - else - tmp = 6; - - return sprintf(buf, "%d\n", tmp); -} - -static ssize_t -show_dts(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int index = sensor_attr->index; - struct w83795_data *data = w83795_update_device(dev); - long temp = temp_from_reg(data->dts[index]); - - temp += (data->dts_read_vrlsb[index] >> 6) * 250; - return sprintf(buf, "%ld\n", temp); -} - -static ssize_t -show_dts_ext(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - struct w83795_data *data = dev_get_drvdata(dev); - long temp = temp_from_reg(data->dts_ext[nr]); - - return sprintf(buf, "%ld\n", temp); -} - -static ssize_t -store_dts_ext(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - long tmp; - - if (kstrtol(buf, 10, &tmp) < 0) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->dts_ext[nr] = temp_to_reg(tmp, -128, 127); - w83795_write(client, W83795_REG_DTS_EXT(nr), data->dts_ext[nr]); - mutex_unlock(&data->update_lock); - return count; -} - - -static ssize_t -show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w83795_data *data = dev_get_drvdata(dev); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int index = sensor_attr->index; - int tmp; - - if (data->temp_mode & (1 << index)) - tmp = 3; /* Thermal diode */ - else - tmp = 4; /* Thermistor */ - - return sprintf(buf, "%d\n", tmp); -} - -/* Only for temp1-4 (temp5-6 can only be thermistor) */ -static ssize_t -store_temp_mode(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int index = sensor_attr->index; - int reg_shift; - unsigned long val; - u8 tmp; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - if ((val != 4) && (val != 3)) - return -EINVAL; - - mutex_lock(&data->update_lock); - if (val == 3) { - /* Thermal diode */ - val = 0x01; - data->temp_mode |= 1 << index; - } else if (val == 4) { - /* Thermistor */ - val = 0x03; - data->temp_mode &= ~(1 << index); - } - - reg_shift = 2 * index; - tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); - tmp &= ~(0x03 << reg_shift); - tmp |= val << reg_shift; - w83795_write(client, W83795_REG_TEMP_CTRL2, tmp); - - mutex_unlock(&data->update_lock); - return count; -} - - -/* show/store VIN */ -static ssize_t -show_in(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - struct w83795_data *data = w83795_update_device(dev); - u16 val = data->in[index][nr]; - u8 lsb_idx; - - switch (nr) { - case IN_READ: - /* calculate this value again by sensors as sensors3.conf */ - if ((index >= 17) && - !((data->has_gain >> (index - 17)) & 1)) - val *= 8; - break; - case IN_MAX: - case IN_LOW: - lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX]; - val <<= 2; - val |= (data->in_lsb[lsb_idx][nr] >> - IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]) & 0x03; - if ((index >= 17) && - !((data->has_gain >> (index - 17)) & 1)) - val *= 8; - break; - } - val = in_from_reg(index, val); - - return sprintf(buf, "%d\n", val); -} - -static ssize_t -store_in(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - int index = sensor_attr->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - unsigned long val; - u8 tmp; - u8 lsb_idx; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - val = in_to_reg(index, val); - - if ((index >= 17) && - !((data->has_gain >> (index - 17)) & 1)) - val /= 8; - val = clamp_val(val, 0, 0x3FF); - mutex_lock(&data->update_lock); - - lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX]; - tmp = w83795_read(client, IN_LSB_REG(lsb_idx, nr)); - tmp &= ~(0x03 << IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]); - tmp |= (val & 0x03) << IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]; - w83795_write(client, IN_LSB_REG(lsb_idx, nr), tmp); - data->in_lsb[lsb_idx][nr] = tmp; - - tmp = (val >> 2) & 0xff; - w83795_write(client, W83795_REG_IN[index][nr], tmp); - data->in[index][nr] = tmp; - - mutex_unlock(&data->update_lock); - return count; -} - - -#ifdef CONFIG_SENSORS_W83795_FANCTRL -static ssize_t -show_sf_setup(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - struct w83795_data *data = w83795_update_pwm_config(dev); - u16 val = data->setup_pwm[nr]; - - switch (nr) { - case SETUP_PWM_UPTIME: - case SETUP_PWM_DOWNTIME: - val = time_from_reg(val); - break; - } - - return sprintf(buf, "%d\n", val); -} - -static ssize_t -store_sf_setup(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct sensor_device_attribute_2 *sensor_attr = - to_sensor_dev_attr_2(attr); - int nr = sensor_attr->nr; - struct i2c_client *client = to_i2c_client(dev); - struct w83795_data *data = i2c_get_clientdata(client); - unsigned long val; - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - - switch (nr) { - case SETUP_PWM_DEFAULT: - val = clamp_val(val, 0, 0xff); - break; - case SETUP_PWM_UPTIME: - case SETUP_PWM_DOWNTIME: - val = time_to_reg(val); - if (val == 0) - return -EINVAL; - break; - } - - mutex_lock(&data->update_lock); - data->setup_pwm[nr] = val; - w83795_write(client, W83795_REG_SETUP_PWM(nr), val); - mutex_unlock(&data->update_lock); - return count; -} -#endif - - -#define NOT_USED -1 - -/* - * Don't change the attribute order, _max, _min and _beep are accessed by index - * somewhere else in the code - */ -#define SENSOR_ATTR_IN(index) { \ - SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \ - IN_READ, index), \ - SENSOR_ATTR_2(in##index##_max, S_IRUGO | S_IWUSR, show_in, \ - store_in, IN_MAX, index), \ - SENSOR_ATTR_2(in##index##_min, S_IRUGO | S_IWUSR, show_in, \ - store_in, IN_LOW, index), \ - SENSOR_ATTR_2(in##index##_alarm, S_IRUGO, show_alarm_beep, \ - NULL, ALARM_STATUS, index + ((index > 14) ? 1 : 0)), \ - SENSOR_ATTR_2(in##index##_beep, S_IWUSR | S_IRUGO, \ - show_alarm_beep, store_beep, BEEP_ENABLE, \ - index + ((index > 14) ? 1 : 0)) } - -/* - * Don't change the attribute order, _beep is accessed by index - * somewhere else in the code - */ -#define SENSOR_ATTR_FAN(index) { \ - SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \ - NULL, FAN_INPUT, index - 1), \ - SENSOR_ATTR_2(fan##index##_min, S_IWUSR | S_IRUGO, \ - show_fan, store_fan_min, FAN_MIN, index - 1), \ - SENSOR_ATTR_2(fan##index##_alarm, S_IRUGO, show_alarm_beep, \ - NULL, ALARM_STATUS, index + 31), \ - SENSOR_ATTR_2(fan##index##_beep, S_IWUSR | S_IRUGO, \ - show_alarm_beep, store_beep, BEEP_ENABLE, index + 31) } - -#define SENSOR_ATTR_PWM(index) { \ - SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm, \ - store_pwm, PWM_OUTPUT, index - 1), \ - SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \ - show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \ - SENSOR_ATTR_2(pwm##index##_mode, S_IRUGO, \ - show_pwm_mode, NULL, NOT_USED, index - 1), \ - SENSOR_ATTR_2(pwm##index##_freq, S_IWUSR | S_IRUGO, \ - show_pwm, store_pwm, PWM_FREQ, index - 1), \ - SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO, \ - show_pwm, store_pwm, PWM_NONSTOP, index - 1), \ - SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO, \ - show_pwm, store_pwm, PWM_START, index - 1), \ - SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO, \ - show_pwm, store_pwm, PWM_STOP_TIME, index - 1), \ - SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \ - show_fanin, store_fanin, FANIN_TARGET, index - 1) } - -/* - * Don't change the attribute order, _beep is accessed by index - * somewhere else in the code - */ -#define SENSOR_ATTR_DTS(index) { \ - SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \ - show_dts_mode, NULL, NOT_USED, index - 7), \ - SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_dts, \ - NULL, NOT_USED, index - 7), \ - SENSOR_ATTR_2(temp##index##_crit, S_IRUGO | S_IWUSR, show_dts_ext, \ - store_dts_ext, DTS_CRIT, NOT_USED), \ - SENSOR_ATTR_2(temp##index##_crit_hyst, S_IRUGO | S_IWUSR, \ - show_dts_ext, store_dts_ext, DTS_CRIT_HYST, NOT_USED), \ - SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_dts_ext, \ - store_dts_ext, DTS_WARN, NOT_USED), \ - SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \ - show_dts_ext, store_dts_ext, DTS_WARN_HYST, NOT_USED), \ - SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \ - show_alarm_beep, NULL, ALARM_STATUS, index + 17), \ - SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ - show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } - -/* - * Don't change the attribute order, _beep is accessed by index - * somewhere else in the code - */ -#define SENSOR_ATTR_TEMP(index) { \ - SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \ - show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ - SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \ - NULL, TEMP_READ, index - 1), \ - SENSOR_ATTR_2(temp##index##_crit, S_IRUGO | S_IWUSR, show_temp, \ - store_temp, TEMP_CRIT, index - 1), \ - SENSOR_ATTR_2(temp##index##_crit_hyst, S_IRUGO | S_IWUSR, \ - show_temp, store_temp, TEMP_CRIT_HYST, index - 1), \ - SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_temp, \ - store_temp, TEMP_WARN, index - 1), \ - SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \ - show_temp, store_temp, TEMP_WARN_HYST, index - 1), \ - SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \ - show_alarm_beep, NULL, ALARM_STATUS, \ - index + (index > 4 ? 11 : 17)), \ - SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ - show_alarm_beep, store_beep, BEEP_ENABLE, \ - index + (index > 4 ? 11 : 17)), \ - SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ - show_temp_pwm_enable, store_temp_pwm_enable, \ - TEMP_PWM_ENABLE, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_channels_pwm, S_IWUSR | S_IRUGO, \ - show_temp_pwm_enable, store_temp_pwm_enable, \ - TEMP_PWM_FAN_MAP, index - 1), \ - SENSOR_ATTR_2(thermal_cruise##index, S_IWUSR | S_IRUGO, \ - show_temp_pwm, store_temp_pwm, TEMP_PWM_TTTI, index - 1), \ - SENSOR_ATTR_2(temp##index##_warn, S_IWUSR | S_IRUGO, \ - show_temp_pwm, store_temp_pwm, TEMP_PWM_CTFS, index - 1), \ - SENSOR_ATTR_2(temp##index##_warn_hyst, S_IWUSR | S_IRUGO, \ - show_temp_pwm, store_temp_pwm, TEMP_PWM_HCT, index - 1), \ - SENSOR_ATTR_2(temp##index##_operation_hyst, S_IWUSR | S_IRUGO, \ - show_temp_pwm, store_temp_pwm, TEMP_PWM_HOT, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point1_pwm, S_IRUGO | S_IWUSR, \ - show_sf4_pwm, store_sf4_pwm, 0, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point2_pwm, S_IRUGO | S_IWUSR, \ - show_sf4_pwm, store_sf4_pwm, 1, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point3_pwm, S_IRUGO | S_IWUSR, \ - show_sf4_pwm, store_sf4_pwm, 2, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point4_pwm, S_IRUGO | S_IWUSR, \ - show_sf4_pwm, store_sf4_pwm, 3, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point5_pwm, S_IRUGO | S_IWUSR, \ - show_sf4_pwm, store_sf4_pwm, 4, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point6_pwm, S_IRUGO | S_IWUSR, \ - show_sf4_pwm, store_sf4_pwm, 5, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point7_pwm, S_IRUGO | S_IWUSR, \ - show_sf4_pwm, store_sf4_pwm, 6, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point1_temp, S_IRUGO | S_IWUSR,\ - show_sf4_temp, store_sf4_temp, 0, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point2_temp, S_IRUGO | S_IWUSR,\ - show_sf4_temp, store_sf4_temp, 1, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point3_temp, S_IRUGO | S_IWUSR,\ - show_sf4_temp, store_sf4_temp, 2, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point4_temp, S_IRUGO | S_IWUSR,\ - show_sf4_temp, store_sf4_temp, 3, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point5_temp, S_IRUGO | S_IWUSR,\ - show_sf4_temp, store_sf4_temp, 4, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point6_temp, S_IRUGO | S_IWUSR,\ - show_sf4_temp, store_sf4_temp, 5, index - 1), \ - SENSOR_ATTR_2(temp##index##_auto_point7_temp, S_IRUGO | S_IWUSR,\ - show_sf4_temp, store_sf4_temp, 6, index - 1) } - - -static struct sensor_device_attribute_2 w83795_in[][5] = { - SENSOR_ATTR_IN(0), - SENSOR_ATTR_IN(1), - SENSOR_ATTR_IN(2), - SENSOR_ATTR_IN(3), - SENSOR_ATTR_IN(4), - SENSOR_ATTR_IN(5), - SENSOR_ATTR_IN(6), - SENSOR_ATTR_IN(7), - SENSOR_ATTR_IN(8), - SENSOR_ATTR_IN(9), - SENSOR_ATTR_IN(10), - SENSOR_ATTR_IN(11), - SENSOR_ATTR_IN(12), - SENSOR_ATTR_IN(13), - SENSOR_ATTR_IN(14), - SENSOR_ATTR_IN(15), - SENSOR_ATTR_IN(16), - SENSOR_ATTR_IN(17), - SENSOR_ATTR_IN(18), - SENSOR_ATTR_IN(19), - SENSOR_ATTR_IN(20), -}; - -static const struct sensor_device_attribute_2 w83795_fan[][4] = { - SENSOR_ATTR_FAN(1), - SENSOR_ATTR_FAN(2), - SENSOR_ATTR_FAN(3), - SENSOR_ATTR_FAN(4), - SENSOR_ATTR_FAN(5), - SENSOR_ATTR_FAN(6), - SENSOR_ATTR_FAN(7), - SENSOR_ATTR_FAN(8), - SENSOR_ATTR_FAN(9), - SENSOR_ATTR_FAN(10), - SENSOR_ATTR_FAN(11), - SENSOR_ATTR_FAN(12), - SENSOR_ATTR_FAN(13), - SENSOR_ATTR_FAN(14), -}; - -static const struct sensor_device_attribute_2 w83795_temp[][28] = { - SENSOR_ATTR_TEMP(1), - SENSOR_ATTR_TEMP(2), - SENSOR_ATTR_TEMP(3), - SENSOR_ATTR_TEMP(4), - SENSOR_ATTR_TEMP(5), - SENSOR_ATTR_TEMP(6), -}; - -static const struct sensor_device_attribute_2 w83795_dts[][8] = { - SENSOR_ATTR_DTS(7), - SENSOR_ATTR_DTS(8), - SENSOR_ATTR_DTS(9), - SENSOR_ATTR_DTS(10), - SENSOR_ATTR_DTS(11), - SENSOR_ATTR_DTS(12), - SENSOR_ATTR_DTS(13), - SENSOR_ATTR_DTS(14), -}; - -static const struct sensor_device_attribute_2 w83795_pwm[][8] = { - SENSOR_ATTR_PWM(1), - SENSOR_ATTR_PWM(2), - SENSOR_ATTR_PWM(3), - SENSOR_ATTR_PWM(4), - SENSOR_ATTR_PWM(5), - SENSOR_ATTR_PWM(6), - SENSOR_ATTR_PWM(7), - SENSOR_ATTR_PWM(8), -}; - -static const struct sensor_device_attribute_2 w83795_tss[6] = { - SENSOR_ATTR_2(temp1_source_sel, S_IWUSR | S_IRUGO, - show_temp_src, store_temp_src, NOT_USED, 0), - SENSOR_ATTR_2(temp2_source_sel, S_IWUSR | S_IRUGO, - show_temp_src, store_temp_src, NOT_USED, 1), - SENSOR_ATTR_2(temp3_source_sel, S_IWUSR | S_IRUGO, - show_temp_src, store_temp_src, NOT_USED, 2), - SENSOR_ATTR_2(temp4_source_sel, S_IWUSR | S_IRUGO, - show_temp_src, store_temp_src, NOT_USED, 3), - SENSOR_ATTR_2(temp5_source_sel, S_IWUSR | S_IRUGO, - show_temp_src, store_temp_src, NOT_USED, 4), - SENSOR_ATTR_2(temp6_source_sel, S_IWUSR | S_IRUGO, - show_temp_src, store_temp_src, NOT_USED, 5), -}; - -static const struct sensor_device_attribute_2 sda_single_files[] = { - SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep, - store_chassis_clear, ALARM_STATUS, 46), -#ifdef CONFIG_SENSORS_W83795_FANCTRL - SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin, - store_fanin, FANIN_TOL, NOT_USED), - SENSOR_ATTR_2(pwm_default, S_IWUSR | S_IRUGO, show_sf_setup, - store_sf_setup, SETUP_PWM_DEFAULT, NOT_USED), - SENSOR_ATTR_2(pwm_uptime, S_IWUSR | S_IRUGO, show_sf_setup, - store_sf_setup, SETUP_PWM_UPTIME, NOT_USED), - SENSOR_ATTR_2(pwm_downtime, S_IWUSR | S_IRUGO, show_sf_setup, - store_sf_setup, SETUP_PWM_DOWNTIME, NOT_USED), -#endif -}; - -static const struct sensor_device_attribute_2 sda_beep_files[] = { - SENSOR_ATTR_2(intrusion0_beep, S_IWUSR | S_IRUGO, show_alarm_beep, - store_beep, BEEP_ENABLE, 46), - SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep, - store_beep, BEEP_ENABLE, 47), -}; - -/* - * Driver interface - */ - -static void w83795_init_client(struct i2c_client *client) -{ - struct w83795_data *data = i2c_get_clientdata(client); - static const u16 clkin[4] = { /* in kHz */ - 14318, 24000, 33333, 48000 - }; - u8 config; - - if (reset) - w83795_write(client, W83795_REG_CONFIG, 0x80); - - /* Start monitoring if needed */ - config = w83795_read(client, W83795_REG_CONFIG); - if (!(config & W83795_REG_CONFIG_START)) { - dev_info(&client->dev, "Enabling monitoring operations\n"); - w83795_write(client, W83795_REG_CONFIG, - config | W83795_REG_CONFIG_START); - } - - data->clkin = clkin[(config >> 3) & 0x3]; - dev_dbg(&client->dev, "clkin = %u kHz\n", data->clkin); -} - -static int w83795_get_device_id(struct i2c_client *client) -{ - int device_id; - - device_id = i2c_smbus_read_byte_data(client, W83795_REG_DEVICEID); - - /* - * Special case for rev. A chips; can't be checked first because later - * revisions emulate this for compatibility - */ - if (device_id < 0 || (device_id & 0xf0) != 0x50) { - int alt_id; - - alt_id = i2c_smbus_read_byte_data(client, - W83795_REG_DEVICEID_A); - if (alt_id == 0x50) - device_id = alt_id; - } - - return device_id; -} - -/* Return 0 if detection is successful, -ENODEV otherwise */ -static int w83795_detect(struct i2c_client *client, - struct i2c_board_info *info) -{ - int bank, vendor_id, device_id, expected, i2c_addr, config; - struct i2c_adapter *adapter = client->adapter; - unsigned short address = client->addr; - const char *chip_name; - - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) - return -ENODEV; - bank = i2c_smbus_read_byte_data(client, W83795_REG_BANKSEL); - if (bank < 0 || (bank & 0x7c)) { - dev_dbg(&adapter->dev, - "w83795: Detection failed at addr 0x%02hx, check %s\n", - address, "bank"); - return -ENODEV; - } - - /* Check Nuvoton vendor ID */ - vendor_id = i2c_smbus_read_byte_data(client, W83795_REG_VENDORID); - expected = bank & 0x80 ? 0x5c : 0xa3; - if (vendor_id != expected) { - dev_dbg(&adapter->dev, - "w83795: Detection failed at addr 0x%02hx, check %s\n", - address, "vendor id"); - return -ENODEV; - } - - /* Check device ID */ - device_id = w83795_get_device_id(client) | - (i2c_smbus_read_byte_data(client, W83795_REG_CHIPID) << 8); - if ((device_id >> 4) != 0x795) { - dev_dbg(&adapter->dev, - "w83795: Detection failed at addr 0x%02hx, check %s\n", - address, "device id\n"); - return -ENODEV; - } - - /* - * If Nuvoton chip, address of chip and W83795_REG_I2C_ADDR - * should match - */ - if ((bank & 0x07) == 0) { - i2c_addr = i2c_smbus_read_byte_data(client, - W83795_REG_I2C_ADDR); - if ((i2c_addr & 0x7f) != address) { - dev_dbg(&adapter->dev, - "w83795: Detection failed at addr 0x%02hx, " - "check %s\n", address, "i2c addr"); - return -ENODEV; - } - } - - /* - * Check 795 chip type: 795G or 795ADG - * Usually we don't write to chips during detection, but here we don't - * quite have the choice; hopefully it's OK, we are about to return - * success anyway - */ - if ((bank & 0x07) != 0) - i2c_smbus_write_byte_data(client, W83795_REG_BANKSEL, - bank & ~0x07); - config = i2c_smbus_read_byte_data(client, W83795_REG_CONFIG); - if (config & W83795_REG_CONFIG_CONFIG48) - chip_name = "w83795adg"; - else - chip_name = "w83795g"; - - strlcpy(info->type, chip_name, I2C_NAME_SIZE); - dev_info(&adapter->dev, "Found %s rev. %c at 0x%02hx\n", chip_name, - 'A' + (device_id & 0xf), address); - - return 0; -} - -#ifdef CONFIG_SENSORS_W83795_FANCTRL -#define NUM_PWM_ATTRIBUTES ARRAY_SIZE(w83795_pwm[0]) -#define NUM_TEMP_ATTRIBUTES ARRAY_SIZE(w83795_temp[0]) -#else -#define NUM_PWM_ATTRIBUTES 4 -#define NUM_TEMP_ATTRIBUTES 8 -#endif - -static int w83795_handle_files(struct device *dev, int (*fn)(struct device *, - const struct device_attribute *)) -{ - struct w83795_data *data = dev_get_drvdata(dev); - int err, i, j; - - for (i = 0; i < ARRAY_SIZE(w83795_in); i++) { - if (!(data->has_in & (1 << i))) - continue; - for (j = 0; j < ARRAY_SIZE(w83795_in[0]); j++) { - if (j == 4 && !data->enable_beep) - continue; - err = fn(dev, &w83795_in[i][j].dev_attr); - if (err) - return err; - } - } - - for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) { - if (!(data->has_fan & (1 << i))) - continue; - for (j = 0; j < ARRAY_SIZE(w83795_fan[0]); j++) { - if (j == 3 && !data->enable_beep) - continue; - err = fn(dev, &w83795_fan[i][j].dev_attr); - if (err) - return err; - } - } - - for (i = 0; i < ARRAY_SIZE(w83795_tss); i++) { - j = w83795_tss_useful(data, i); - if (!j) - continue; - err = fn(dev, &w83795_tss[i].dev_attr); - if (err) - return err; - } - - for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { - err = fn(dev, &sda_single_files[i].dev_attr); - if (err) - return err; - } - - if (data->enable_beep) { - for (i = 0; i < ARRAY_SIZE(sda_beep_files); i++) { - err = fn(dev, &sda_beep_files[i].dev_attr); - if (err) - return err; - } - } - - for (i = 0; i < data->has_pwm; i++) { - for (j = 0; j < NUM_PWM_ATTRIBUTES; j++) { - err = fn(dev, &w83795_pwm[i][j].dev_attr); - if (err) - return err; - } - } - - for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) { - if (!(data->has_temp & (1 << i))) - continue; - for (j = 0; j < NUM_TEMP_ATTRIBUTES; j++) { - if (j == 7 && !data->enable_beep) - continue; - err = fn(dev, &w83795_temp[i][j].dev_attr); - if (err) - return err; - } - } - - if (data->enable_dts) { - for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) { - if (!(data->has_dts & (1 << i))) - continue; - for (j = 0; j < ARRAY_SIZE(w83795_dts[0]); j++) { - if (j == 7 && !data->enable_beep) - continue; - err = fn(dev, &w83795_dts[i][j].dev_attr); - if (err) - return err; - } - } - } - - return 0; -} - -/* We need a wrapper that fits in w83795_handle_files */ -static int device_remove_file_wrapper(struct device *dev, - const struct device_attribute *attr) -{ - device_remove_file(dev, attr); - return 0; -} - -static void w83795_check_dynamic_in_limits(struct i2c_client *client) -{ - struct w83795_data *data = i2c_get_clientdata(client); - u8 vid_ctl; - int i, err_max, err_min; - - vid_ctl = w83795_read(client, W83795_REG_VID_CTRL); - - /* Return immediately if VRM isn't configured */ - if ((vid_ctl & 0x07) == 0x00 || (vid_ctl & 0x07) == 0x07) - return; - - data->has_dyn_in = (vid_ctl >> 3) & 0x07; - for (i = 0; i < 2; i++) { - if (!(data->has_dyn_in & (1 << i))) - continue; - - /* Voltage limits in dynamic mode, switch to read-only */ - err_max = sysfs_chmod_file(&client->dev.kobj, - &w83795_in[i][2].dev_attr.attr, - S_IRUGO); - err_min = sysfs_chmod_file(&client->dev.kobj, - &w83795_in[i][3].dev_attr.attr, - S_IRUGO); - if (err_max || err_min) - dev_warn(&client->dev, - "Failed to set in%d limits read-only (%d, %d)\n", - i, err_max, err_min); - else - dev_info(&client->dev, - "in%d limits set dynamically from VID\n", i); - } -} - -/* Check pins that can be used for either temperature or voltage monitoring */ -static void w83795_apply_temp_config(struct w83795_data *data, u8 config, - int temp_chan, int in_chan) -{ - /* config is a 2-bit value */ - switch (config) { - case 0x2: /* Voltage monitoring */ - data->has_in |= 1 << in_chan; - break; - case 0x1: /* Thermal diode */ - if (temp_chan >= 4) - break; - data->temp_mode |= 1 << temp_chan; - /* fall through */ - case 0x3: /* Thermistor */ - data->has_temp |= 1 << temp_chan; - break; - } -} - -static int w83795_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - int i; - u8 tmp; - struct device *dev = &client->dev; - struct w83795_data *data; - int err; - - data = devm_kzalloc(dev, sizeof(struct w83795_data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - i2c_set_clientdata(client, data); - data->chip_type = id->driver_data; - data->bank = i2c_smbus_read_byte_data(client, W83795_REG_BANKSEL); - mutex_init(&data->update_lock); - - /* Initialize the chip */ - w83795_init_client(client); - - /* Check which voltages and fans are present */ - data->has_in = w83795_read(client, W83795_REG_VOLT_CTRL1) - | (w83795_read(client, W83795_REG_VOLT_CTRL2) << 8); - data->has_fan = w83795_read(client, W83795_REG_FANIN_CTRL1) - | (w83795_read(client, W83795_REG_FANIN_CTRL2) << 8); - - /* Check which analog temperatures and extra voltages are present */ - tmp = w83795_read(client, W83795_REG_TEMP_CTRL1); - if (tmp & 0x20) - data->enable_dts = 1; - w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 5, 16); - w83795_apply_temp_config(data, tmp & 0x3, 4, 15); - tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); - w83795_apply_temp_config(data, tmp >> 6, 3, 20); - w83795_apply_temp_config(data, (tmp >> 4) & 0x3, 2, 19); - w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 1, 18); - w83795_apply_temp_config(data, tmp & 0x3, 0, 17); - - /* Check DTS enable status */ - if (data->enable_dts) { - if (1 & w83795_read(client, W83795_REG_DTSC)) - data->enable_dts |= 2; - data->has_dts = w83795_read(client, W83795_REG_DTSE); - } - - /* Report PECI Tbase values */ - if (data->enable_dts == 1) { - for (i = 0; i < 8; i++) { - if (!(data->has_dts & (1 << i))) - continue; - tmp = w83795_read(client, W83795_REG_PECI_TBASE(i)); - dev_info(&client->dev, - "PECI agent %d Tbase temperature: %u\n", - i + 1, (unsigned int)tmp & 0x7f); - } - } - - data->has_gain = w83795_read(client, W83795_REG_VMIGB_CTRL) & 0x0f; - - /* pwm and smart fan */ - if (data->chip_type == w83795g) - data->has_pwm = 8; - else - data->has_pwm = 2; - - /* Check if BEEP pin is available */ - if (data->chip_type == w83795g) { - /* The W83795G has a dedicated BEEP pin */ - data->enable_beep = 1; - } else { - /* - * The W83795ADG has a shared pin for OVT# and BEEP, so you - * can't have both - */ - tmp = w83795_read(client, W83795_REG_OVT_CFG); - if ((tmp & OVT_CFG_SEL) == 0) - data->enable_beep = 1; - } - - err = w83795_handle_files(dev, device_create_file); - if (err) - goto exit_remove; - - if (data->chip_type == w83795g) - w83795_check_dynamic_in_limits(client); - - data->hwmon_dev = hwmon_device_register(dev); - if (IS_ERR(data->hwmon_dev)) { - err = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - return 0; - -exit_remove: - w83795_handle_files(dev, device_remove_file_wrapper); - return err; -} - -static int w83795_remove(struct i2c_client *client) -{ - struct w83795_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - w83795_handle_files(&client->dev, device_remove_file_wrapper); - - return 0; -} - - -static const struct i2c_device_id w83795_id[] = { - { "w83795g", w83795g }, - { "w83795adg", w83795adg }, - { } -}; -MODULE_DEVICE_TABLE(i2c, w83795_id); - -static struct i2c_driver w83795_driver = { - .driver = { - .name = "w83795", - }, - .probe = w83795_probe, - .remove = w83795_remove, - .id_table = w83795_id, - - .class = I2C_CLASS_HWMON, - .detect = w83795_detect, - .address_list = normal_i2c, -}; - -module_i2c_driver(w83795_driver); - -MODULE_AUTHOR("Wei Song, Jean Delvare "); -MODULE_DESCRIPTION("W83795G/ADG hardware monitoring driver"); -MODULE_LICENSE("GPL"); diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_config.h b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_config.h index 1f3b3642..c479e961 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_config.h +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_config.h @@ -32,96 +32,96 @@ * @{ * *****************************************************************************/ -#ifndef __INGRAYSYS_S9100_CONFIG_H__ -#define __INGRAYSYS_S9100_CONFIG_H__ +#ifndef __X86_64_INGRAYSYS_S9100_CONFIG_H__ +#define __X86_64_INGRAYSYS_S9100_CONFIG_H__ #ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG #include #endif -#ifdef INGRAYSYS_S9100_INCLUDE_CUSTOM_CONFIG +#ifdef X86_64_INGRAYSYS_S9100_INCLUDE_CUSTOM_CONFIG #include #endif -/* */ +/* */ #include /** - * INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING + * X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING * * Include or exclude logging. */ -#ifndef INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING -#define INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING 1 +#ifndef X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING +#define X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING 1 #endif /** - * INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT + * X86_64_INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT * * Default enabled log options. */ -#ifndef INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT -#define INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#ifndef X86_64_INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT +#define X86_64_INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT #endif /** - * INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT + * X86_64_INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT * * Default enabled log bits. */ -#ifndef INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT -#define INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#ifndef X86_64_INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT +#define X86_64_INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT #endif /** - * INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * X86_64_INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT * * Default enabled custom log bits. */ -#ifndef INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT -#define INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#ifndef X86_64_INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define X86_64_INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 #endif /** - * INGRAYSYS_S9100_CONFIG_PORTING_STDLIB + * X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB * * Default all porting macros to use the C standard libraries. */ -#ifndef INGRAYSYS_S9100_CONFIG_PORTING_STDLIB -#define INGRAYSYS_S9100_CONFIG_PORTING_STDLIB 1 +#ifndef X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB +#define X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB 1 #endif /** - * INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * X86_64_INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS * * Include standard library headers for stdlib porting macros. */ -#ifndef INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS -#define INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS INGRAYSYS_S9100_CONFIG_PORTING_STDLIB +#ifndef X86_64_INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define X86_64_INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB #endif /** - * INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI + * X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI * * Include generic uCli support. */ -#ifndef INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI -#define INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI 0 +#ifndef X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI +#define X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI 0 #endif /** - * INGRAYSYS_S9100_CONFIG_SFP_COUNT + * X86_64_INGRAYSYS_S9100_CONFIG_SFP_COUNT * * SFP Count. */ -#ifndef INGRAYSYS_S9100_CONFIG_SFP_COUNT -#define INGRAYSYS_S9100_CONFIG_SFP_COUNT 0 +#ifndef X86_64_INGRAYSYS_S9100_CONFIG_SFP_COUNT +#define X86_64_INGRAYSYS_S9100_CONFIG_SFP_COUNT 0 #endif @@ -154,9 +154,9 @@ const char* x86_64_ingrasys_s9100_config_lookup(const char* setting); */ int x86_64_ingrasys_s9100_config_show(struct aim_pvs_s* pvs); -/* */ +/* */ #include "x86_64_ingrasys_s9100_porting.h" -#endif /* __INGRAYSYS_S9100_CONFIG_H__ */ +#endif /* __X86_64_INGRAYSYS_S9100_CONFIG_H__ */ /* @} */ diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_porting.h b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_porting.h index 58f68c04..fb311e97 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_porting.h +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/inc/x86_64_ingrasys_s9100/x86_64_ingrasys_s9100_porting.h @@ -7,11 +7,11 @@ * @{ * ***********************************************************/ -#ifndef __INGRAYSYS_S9100_PORTING_H__ -#define __INGRAYSYS_S9100_PORTING_H__ +#ifndef __X86_64_INGRAYSYS_S9100_PORTING_H__ +#define __X86_64_INGRAYSYS_S9100_PORTING_H__ /* */ -#if INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#if X86_64_INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 #include #include #include @@ -19,88 +19,88 @@ #include #endif -#ifndef INGRAYSYS_S9100_MALLOC +#ifndef X86_64_INGRAYSYS_S9100_MALLOC #if defined(GLOBAL_MALLOC) - #define INGRAYSYS_S9100_MALLOC GLOBAL_MALLOC - #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 - #define INGRAYSYS_S9100_MALLOC malloc + #define X86_64_INGRAYSYS_S9100_MALLOC GLOBAL_MALLOC + #elif X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define X86_64_INGRAYSYS_S9100_MALLOC malloc #else - #error The macro INGRAYSYS_S9100_MALLOC is required but cannot be defined. + #error The macro X86_64_INGRAYSYS_S9100_MALLOC is required but cannot be defined. #endif #endif -#ifndef INGRAYSYS_S9100_FREE +#ifndef X86_64_INGRAYSYS_S9100_FREE #if defined(GLOBAL_FREE) - #define INGRAYSYS_S9100_FREE GLOBAL_FREE - #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 - #define INGRAYSYS_S9100_FREE free + #define X86_64_INGRAYSYS_S9100_FREE GLOBAL_FREE + #elif X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define X86_64_INGRAYSYS_S9100_FREE free #else - #error The macro INGRAYSYS_S9100_FREE is required but cannot be defined. + #error The macro X86_64_INGRAYSYS_S9100_FREE is required but cannot be defined. #endif #endif -#ifndef INGRAYSYS_S9100_MEMSET +#ifndef X86_64_INGRAYSYS_S9100_MEMSET #if defined(GLOBAL_MEMSET) - #define INGRAYSYS_S9100_MEMSET GLOBAL_MEMSET - #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 - #define INGRAYSYS_S9100_MEMSET memset + #define X86_64_INGRAYSYS_S9100_MEMSET GLOBAL_MEMSET + #elif X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define X86_64_INGRAYSYS_S9100_MEMSET memset #else - #error The macro INGRAYSYS_S9100_MEMSET is required but cannot be defined. + #error The macro X86_64_INGRAYSYS_S9100_MEMSET is required but cannot be defined. #endif #endif -#ifndef INGRAYSYS_S9100_MEMCPY +#ifndef X86_64_INGRAYSYS_S9100_MEMCPY #if defined(GLOBAL_MEMCPY) - #define INGRAYSYS_S9100_MEMCPY GLOBAL_MEMCPY - #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 - #define INGRAYSYS_S9100_MEMCPY memcpy + #define X86_64_INGRAYSYS_S9100_MEMCPY GLOBAL_MEMCPY + #elif X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define X86_64_INGRAYSYS_S9100_MEMCPY memcpy #else - #error The macro INGRAYSYS_S9100_MEMCPY is required but cannot be defined. + #error The macro X86_64_INGRAYSYS_S9100_MEMCPY is required but cannot be defined. #endif #endif -#ifndef INGRAYSYS_S9100_STRNCPY +#ifndef X86_64_INGRAYSYS_S9100_STRNCPY #if defined(GLOBAL_STRNCPY) - #define INGRAYSYS_S9100_STRNCPY GLOBAL_STRNCPY - #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 - #define INGRAYSYS_S9100_STRNCPY strncpy + #define X86_64_INGRAYSYS_S9100_STRNCPY GLOBAL_STRNCPY + #elif X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define X86_64_INGRAYSYS_S9100_STRNCPY strncpy #else - #error The macro INGRAYSYS_S9100_STRNCPY is required but cannot be defined. + #error The macro X86_64_INGRAYSYS_S9100_STRNCPY is required but cannot be defined. #endif #endif -#ifndef INGRAYSYS_S9100_VSNPRINTF +#ifndef X86_64_INGRAYSYS_S9100_VSNPRINTF #if defined(GLOBAL_VSNPRINTF) - #define INGRAYSYS_S9100_VSNPRINTF GLOBAL_VSNPRINTF - #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 - #define INGRAYSYS_S9100_VSNPRINTF vsnprintf + #define X86_64_INGRAYSYS_S9100_VSNPRINTF GLOBAL_VSNPRINTF + #elif X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define X86_64_INGRAYSYS_S9100_VSNPRINTF vsnprintf #else - #error The macro INGRAYSYS_S9100_VSNPRINTF is required but cannot be defined. + #error The macro X86_64_INGRAYSYS_S9100_VSNPRINTF is required but cannot be defined. #endif #endif -#ifndef INGRAYSYS_S9100_SNPRINTF +#ifndef X86_64_INGRAYSYS_S9100_SNPRINTF #if defined(GLOBAL_SNPRINTF) - #define INGRAYSYS_S9100_SNPRINTF GLOBAL_SNPRINTF - #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 - #define INGRAYSYS_S9100_SNPRINTF snprintf + #define X86_64_INGRAYSYS_S9100_SNPRINTF GLOBAL_SNPRINTF + #elif X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define X86_64_INGRAYSYS_S9100_SNPRINTF snprintf #else - #error The macro INGRAYSYS_S9100_SNPRINTF is required but cannot be defined. + #error The macro X86_64_INGRAYSYS_S9100_SNPRINTF is required but cannot be defined. #endif #endif -#ifndef INGRAYSYS_S9100_STRLEN +#ifndef X86_64_INGRAYSYS_S9100_STRLEN #if defined(GLOBAL_STRLEN) - #define INGRAYSYS_S9100_STRLEN GLOBAL_STRLEN - #elif INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 - #define INGRAYSYS_S9100_STRLEN strlen + #define X86_64_INGRAYSYS_S9100_STRLEN GLOBAL_STRLEN + #elif X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB == 1 + #define X86_64_INGRAYSYS_S9100_STRLEN strlen #else - #error The macro INGRAYSYS_S9100_STRLEN is required but cannot be defined. + #error The macro X86_64_INGRAYSYS_S9100_STRLEN is required but cannot be defined. #endif #endif /* */ -#endif /* __INGRAYSYS_S9100_PORTING_H__ */ +#endif /* __X86_64_INGRAYSYS_S9100_PORTING_H__ */ /* @} */ diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c index 99a64628..306ab37b 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c @@ -133,9 +133,6 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) return rc; } -/* - * Generic LED ioctl interface. - */ int onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) { diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_config.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_config.c index 4325b6f5..e24562cf 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_config.c +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_config.c @@ -25,50 +25,50 @@ #include -/* */ +/* */ #define __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(_x) #_x #define __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(_x) __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(_x) x86_64_ingrasys_s9100_config_settings_t x86_64_ingrasys_s9100_config_settings[] = { -#ifdef INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING - { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING) }, +#ifdef X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING) }, #else -{ INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_LOGGING(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT - { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT) }, +#ifdef X86_64_INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(X86_64_INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(X86_64_INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT) }, #else -{ INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT - { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT) }, +#ifdef X86_64_INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(X86_64_INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(X86_64_INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT) }, #else -{ INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT - { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#ifdef X86_64_INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(X86_64_INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(X86_64_INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, #else -{ INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef INGRAYSYS_S9100_CONFIG_PORTING_STDLIB - { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_PORTING_STDLIB), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_PORTING_STDLIB) }, +#ifdef X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB) }, #else -{ INGRAYSYS_S9100_CONFIG_PORTING_STDLIB(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_INGRAYSYS_S9100_CONFIG_PORTING_STDLIB(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS - { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#ifdef X86_64_INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(X86_64_INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(X86_64_INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, #else -{ INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_INGRAYSYS_S9100_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI - { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI) }, +#ifdef X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI) }, #else -{ INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_INGRAYSYS_S9100_CONFIG_INCLUDE_UCLI(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef INGRAYSYS_S9100_CONFIG_SFP_COUNT - { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(INGRAYSYS_S9100_CONFIG_SFP_COUNT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(INGRAYSYS_S9100_CONFIG_SFP_COUNT) }, +#ifdef X86_64_INGRAYSYS_S9100_CONFIG_SFP_COUNT + { __x86_64_ingrasys_s9100_config_STRINGIFY_NAME(X86_64_INGRAYSYS_S9100_CONFIG_SFP_COUNT), __x86_64_ingrasys_s9100_config_STRINGIFY_VALUE(X86_64_INGRAYSYS_S9100_CONFIG_SFP_COUNT) }, #else -{ INGRAYSYS_S9100_CONFIG_SFP_COUNT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_INGRAYSYS_S9100_CONFIG_SFP_COUNT(__x86_64_ingrasys_s9100_config_STRINGIFY_NAME), "__undefined__" }, #endif { NULL, NULL } }; @@ -97,5 +97,5 @@ x86_64_ingrasys_s9100_config_show(struct aim_pvs_s* pvs) return i; } -/* */ +/* */ diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.c index 07f60540..e837eeca 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.c +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/x86_64_ingrasys_s9100_log.c @@ -30,9 +30,9 @@ * x86_64_ingrasys_s9100 log struct. */ AIM_LOG_STRUCT_DEFINE( - INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT, - INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT, + X86_64_INGRAYSYS_S9100_CONFIG_LOG_OPTIONS_DEFAULT, + X86_64_INGRAYSYS_S9100_CONFIG_LOG_BITS_DEFAULT, NULL, /* Custom log map */ - INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT + X86_64_INGRAYSYS_S9100_CONFIG_LOG_CUSTOM_BITS_DEFAULT ); diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py index 86c4ba66..cba0b0fe 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py @@ -2,7 +2,7 @@ from onl.platform.base import * from onl.platform.ingrasys import * import os -class OnlPlatform_x86_64_ingrasys_s9100_r0(OnlPlatformingrasys): +class OnlPlatform_x86_64_ingrasys_s9100_r0(OnlPlatformIngrasys): PLATFORM='x86-64-ingrasys-s9100-r0' MODEL="s9100" SYS_OBJECT_ID=".8.1" @@ -10,8 +10,8 @@ class OnlPlatform_x86_64_ingrasys_s9100_r0(OnlPlatformingrasys): def baseconfig(self): self.insmod("eeprom_mb") - self.insmod("w83795") - self.insmod("eeprom") + os.system("modprobe w83795") + os.system("modprobe eeprom") ########### initialize I2C bus 1 ########### self.new_i2c_device('pca9548', 0x70, 1) From e3b4724d8dd8101d3def5e6cbcea6d02113557cc Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Wed, 20 Sep 2017 15:13:56 +0800 Subject: [PATCH 62/67] [as5916-54x] Modify source code to follow coding standards --- .../x86_64_accton_as5916_54x_config.h | 60 +++++++++---------- .../x86_64_accton_as5916_54x_dox.h | 6 +- .../x86_64_accton_as5916_54x_porting.h | 24 ++++---- .../onlp/builds/src/module/src/fani.c | 51 ---------------- .../onlp/builds/src/module/src/ledi.c | 9 --- .../src/x86_64_accton_as5916_54x_config.c | 48 +++++++-------- .../module/src/x86_64_accton_as5916_54x_log.c | 6 +- 7 files changed, 72 insertions(+), 132 deletions(-) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_config.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_config.h index 15a5af00..43572880 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_config.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_config.h @@ -7,96 +7,96 @@ * @{ * *****************************************************************************/ -#ifndef __x86_64_accton_as5916_54x_CONFIG_H__ -#define __x86_64_accton_as5916_54x_CONFIG_H__ +#ifndef __X86_64_ACCTON_AS5916_54X_CONFIG_H__ +#define __X86_64_ACCTON_AS5916_54X_CONFIG_H__ #ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG #include #endif -#ifdef x86_64_accton_as5916_54x_INCLUDE_CUSTOM_CONFIG +#ifdef X86_64_ACCTON_AS5916_54X_INCLUDE_CUSTOM_CONFIG #include #endif -/* */ +/* */ #include /** - * x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING + * X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING * * Include or exclude logging. */ -#ifndef x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING -#define x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING 1 +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING +#define X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING 1 #endif /** - * x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT + * X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT * * Default enabled log options. */ -#ifndef x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT -#define x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT +#define X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT #endif /** - * x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT + * X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT * * Default enabled log bits. */ -#ifndef x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT -#define x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT +#define X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT #endif /** - * x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT * * Default enabled custom log bits. */ -#ifndef x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT -#define x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 #endif /** - * x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB + * X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB * * Default all porting macros to use the C standard libraries. */ -#ifndef x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB -#define x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB 1 +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB +#define X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB 1 #endif /** - * x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS * * Include standard library headers for stdlib porting macros. */ -#ifndef x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS -#define x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB #endif /** - * x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI + * X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI * * Include generic uCli support. */ -#ifndef x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI -#define x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI 0 +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI +#define X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI 0 #endif /** - * x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION * * Assume chassis fan direction is the same as the PSU fan direction. */ -#ifndef x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION -#define x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 #endif @@ -129,9 +129,9 @@ const char* x86_64_accton_as5916_54x_config_lookup(const char* setting); */ int x86_64_accton_as5916_54x_config_show(struct aim_pvs_s* pvs); -/* */ +/* */ #include "x86_64_accton_as5916_54x_porting.h" -#endif /* __x86_64_accton_as5916_54x_CONFIG_H__ */ +#endif /* __X86_64_ACCTON_AS5916_54X_CONFIG_H__ */ /* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_dox.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_dox.h index 85d980e3..67e69645 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_dox.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_dox.h @@ -3,8 +3,8 @@ * x86_64_accton_as5916_54x Doxygen Header * *****************************************************************************/ -#ifndef __x86_64_accton_as5916_54x_DOX_H__ -#define __x86_64_accton_as5916_54x_DOX_H__ +#ifndef __X86_64_ACCTON_AS5916_54X_DOX_H__ +#define __X86_64_ACCTON_AS5916_54X_DOX_H__ /** * @defgroup x86_64_accton_as5916_54x x86_64_accton_as5916_54x - x86_64_accton_as5916_54x Description @@ -23,4 +23,4 @@ The documentation overview for this module should go here. * */ -#endif /* __x86_64_accton_as5916_54x_DOX_H__ */ +#endif /* __X86_64_ACCTON_AS5916_54X_DOX_H__ */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_porting.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_porting.h index adf4e952..e7dcddc8 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_porting.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/inc/x86_64_accton_as5916_54x/x86_64_accton_as5916_54x_porting.h @@ -7,12 +7,12 @@ * @{ * *****************************************************************************/ -#ifndef __x86_64_accton_as5916_54x_PORTING_H__ -#define __x86_64_accton_as5916_54x_PORTING_H__ +#ifndef __X86_64_ACCTON_AS5916_54X_PORTING_H__ +#define __X86_64_ACCTON_AS5916_54X_PORTING_H__ /* */ -#if x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#if X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 #include #include #include @@ -23,7 +23,7 @@ #ifndef x86_64_accton_as5916_54x_MALLOC #if defined(GLOBAL_MALLOC) #define x86_64_accton_as5916_54x_MALLOC GLOBAL_MALLOC - #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 #define x86_64_accton_as5916_54x_MALLOC malloc #else #error The macro x86_64_accton_as5916_54x_MALLOC is required but cannot be defined. @@ -33,7 +33,7 @@ #ifndef x86_64_accton_as5916_54x_FREE #if defined(GLOBAL_FREE) #define x86_64_accton_as5916_54x_FREE GLOBAL_FREE - #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 #define x86_64_accton_as5916_54x_FREE free #else #error The macro x86_64_accton_as5916_54x_FREE is required but cannot be defined. @@ -43,7 +43,7 @@ #ifndef x86_64_accton_as5916_54x_MEMSET #if defined(GLOBAL_MEMSET) #define x86_64_accton_as5916_54x_MEMSET GLOBAL_MEMSET - #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 #define x86_64_accton_as5916_54x_MEMSET memset #else #error The macro x86_64_accton_as5916_54x_MEMSET is required but cannot be defined. @@ -53,7 +53,7 @@ #ifndef x86_64_accton_as5916_54x_MEMCPY #if defined(GLOBAL_MEMCPY) #define x86_64_accton_as5916_54x_MEMCPY GLOBAL_MEMCPY - #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 #define x86_64_accton_as5916_54x_MEMCPY memcpy #else #error The macro x86_64_accton_as5916_54x_MEMCPY is required but cannot be defined. @@ -63,7 +63,7 @@ #ifndef x86_64_accton_as5916_54x_STRNCPY #if defined(GLOBAL_STRNCPY) #define x86_64_accton_as5916_54x_STRNCPY GLOBAL_STRNCPY - #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 #define x86_64_accton_as5916_54x_STRNCPY strncpy #else #error The macro x86_64_accton_as5916_54x_STRNCPY is required but cannot be defined. @@ -73,7 +73,7 @@ #ifndef x86_64_accton_as5916_54x_VSNPRINTF #if defined(GLOBAL_VSNPRINTF) #define x86_64_accton_as5916_54x_VSNPRINTF GLOBAL_VSNPRINTF - #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 #define x86_64_accton_as5916_54x_VSNPRINTF vsnprintf #else #error The macro x86_64_accton_as5916_54x_VSNPRINTF is required but cannot be defined. @@ -83,7 +83,7 @@ #ifndef x86_64_accton_as5916_54x_SNPRINTF #if defined(GLOBAL_SNPRINTF) #define x86_64_accton_as5916_54x_SNPRINTF GLOBAL_SNPRINTF - #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 #define x86_64_accton_as5916_54x_SNPRINTF snprintf #else #error The macro x86_64_accton_as5916_54x_SNPRINTF is required but cannot be defined. @@ -93,7 +93,7 @@ #ifndef x86_64_accton_as5916_54x_STRLEN #if defined(GLOBAL_STRLEN) #define x86_64_accton_as5916_54x_STRLEN GLOBAL_STRLEN - #elif x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB == 1 + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 #define x86_64_accton_as5916_54x_STRLEN strlen #else #error The macro x86_64_accton_as5916_54x_STRLEN is required but cannot be defined. @@ -103,5 +103,5 @@ /* */ -#endif /* __x86_64_accton_as5916_54x_PORTING_H__ */ +#endif /* __X86_64_ACCTON_AS5916_54X_PORTING_H__ */ /* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/fani.c index d8319a0d..6e990cfd 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/fani.c @@ -252,20 +252,6 @@ onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) return rc; } -/* - * This function sets the speed of the given fan in RPM. - * - * This function will only be called if the fan supprots the RPM_SET - * capability. - * - * It is optional if you have no fans at all with this feature. - */ -int -onlp_fani_rpm_set(onlp_oid_t id, int rpm) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - /* * This function sets the fan speed of the given OID as a percentage. * @@ -315,40 +301,3 @@ onlp_fani_percentage_set(onlp_oid_t id, int p) return ONLP_STATUS_OK; } - -/* - * This function sets the fan speed of the given OID as per - * the predefined ONLP fan speed modes: off, slow, normal, fast, max. - * - * Interpretation of these modes is up to the platform. - * - */ -int -onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -/* - * This function sets the fan direction of the given OID. - * - * This function is only relevant if the fan OID supports both direction - * capabilities. - * - * This function is optional unless the functionality is available. - */ -int -onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -/* - * Generic fan ioctl. Optional. - */ -int -onlp_fani_ioctl(onlp_oid_t id, va_list vargs) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/ledi.c index 31a17cc1..4cb41893 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/ledi.c @@ -245,12 +245,3 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) 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/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_config.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_config.c index 7f36f202..3579a89f 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_config.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_config.c @@ -10,45 +10,45 @@ #define __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(_x) __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(_x) x86_64_accton_as5916_54x_config_settings_t x86_64_accton_as5916_54x_config_settings[] = { -#ifdef x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING) }, +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING) }, #else -{ x86_64_accton_as5916_54x_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT) }, +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT) }, #else -{ x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT) }, +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT) }, #else -{ x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, #else -{ x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB) }, +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB) }, #else -{ x86_64_accton_as5916_54x_CONFIG_PORTING_STDLIB(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, #else -{ x86_64_accton_as5916_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI) }, +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI) }, #else -{ x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, #else -{ x86_64_accton_as5916_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, #endif { NULL, NULL } }; diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.c index 99398f5a..1537e358 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/x86_64_accton_as5916_54x_log.c @@ -10,9 +10,9 @@ * x86_64_accton_as5916_54x log struct. */ AIM_LOG_STRUCT_DEFINE( - x86_64_accton_as5916_54x_CONFIG_LOG_OPTIONS_DEFAULT, - x86_64_accton_as5916_54x_CONFIG_LOG_BITS_DEFAULT, + X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT, + X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT, NULL, /* Custom log map */ - x86_64_accton_as5916_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT + X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT ); From 5f72f71303f7ca6280770919cd346e915528aa37 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Fri, 22 Sep 2017 09:03:33 +0800 Subject: [PATCH 63/67] [as5916-54x] Remove r0 revision support --- .../accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml index facee58f..0987b043 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml @@ -1,6 +1,5 @@ variables: platformbase: x86-64-accton-as5916-54x - r0_install: /lib/platform-config/${platformbase}-r0/onl r1_install: /lib/platform-config/${platformbase}-r1/onl common: @@ -12,13 +11,6 @@ common: changelog: Change changes changes., packages: - - name: onlp-${platformbase}-r0 - summary: ONLP Package for the ${platformbase}-r0 platform. - - files: - builds/lib/$BUILD_DIR/x86_64-linux-gnu/bin/libonlp-${platformbase}.so : ${r0_install}/lib/libonlp-${platformbase}.so - builds/onlpdump/$BUILD_DIR/x86_64-linux-gnu/bin/onlpdump : ${r0_install}/bin/ - - name: onlp-${platformbase}-r1 summary: ONLP Package for the ${platformbase}-r1 platform. From 1a0f22a36e3579f03983108c966cdbb4884a865c Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Mon, 25 Sep 2017 16:28:03 +0000 Subject: [PATCH 64/67] Allow the default ONLP platform package templates to take a revision other than r0. --- .../base/any/templates/onlp-platform-any.yml | 26 +---------------- .../any/templates/onlp-platform-revision.yml | 28 +++++++++++++++++++ .../x86-64-accton-as5916-54x/onlp/PKG.yml | 20 +------------ 3 files changed, 30 insertions(+), 44 deletions(-) create mode 100644 packages/base/any/templates/onlp-platform-revision.yml diff --git a/packages/base/any/templates/onlp-platform-any.yml b/packages/base/any/templates/onlp-platform-any.yml index e9580aae..bdf719cd 100644 --- a/packages/base/any/templates/onlp-platform-any.yml +++ b/packages/base/any/templates/onlp-platform-any.yml @@ -6,28 +6,4 @@ # Assumes revision r0 # ############################################################ - -variables: - install: /lib/platform-config/${PLATFORM}-r0/onl - -common: - version: 1.0.0 - arch: $ARCH - copyright: Copyright 2013, 2014, 2015 Big Switch Networks - maintainer: support@bigswitch.com - support: opennetworklinux@googlegroups.com - -packages: - - name: onlp-${PLATFORM}-r0 - summary: ONLP Package for the ${PLATFORM}-r0 platform. - platform-config: True - - files: - builds/lib/$BUILD_DIR/$TOOLCHAIN/bin/libonlp-${PLATFORM}.so : ${install}/lib/ - builds/onlpdump/$BUILD_DIR/$TOOLCHAIN/bin/onlpdump : ${install}/bin/ - - changelog: Change changes changes., - - - - +!include $ONL/packages/base/any/templates/onlp-platform-revision.yml REVISION=r0 diff --git a/packages/base/any/templates/onlp-platform-revision.yml b/packages/base/any/templates/onlp-platform-revision.yml new file mode 100644 index 00000000..90a419e4 --- /dev/null +++ b/packages/base/any/templates/onlp-platform-revision.yml @@ -0,0 +1,28 @@ +############################################################ +# +# ONLP Platform Package Template +# +# Requires: PLATFORM, ARCH, REVISION +# +############################################################ + +variables: + install: /lib/platform-config/${PLATFORM}-${REVISION}/onl + +common: + version: 1.0.0 + arch: $ARCH + copyright: Copyright 2013, 2014, 2015 Big Switch Networks + maintainer: support@bigswitch.com + support: opennetworklinux@googlegroups.com + +packages: + - name: onlp-${PLATFORM}-${REVISION} + summary: ONLP Package for the ${PLATFORM}-${REVISION} platform. + platform-config: True + + files: + builds/lib/$BUILD_DIR/$TOOLCHAIN/bin/libonlp-${PLATFORM}.so : ${install}/lib/ + builds/onlpdump/$BUILD_DIR/$TOOLCHAIN/bin/onlpdump : ${install}/bin/ + + changelog: Change changes changes., diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml index 0987b043..ee1812ff 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/PKG.yml @@ -1,19 +1 @@ -variables: - platformbase: x86-64-accton-as5916-54x - r1_install: /lib/platform-config/${platformbase}-r1/onl - -common: - version: 1.0.0 - arch: amd64 - copyright: Copyright 2013, 2014, 2015 Big Switch Networks - maintainer: support@bigswitch.com - support: opennetworklinux@googlegroups.com - changelog: Change changes changes., - -packages: - - name: onlp-${platformbase}-r1 - summary: ONLP Package for the ${platformbase}-r1 platform. - - files: - builds/lib/$BUILD_DIR/x86_64-linux-gnu/bin/libonlp-${platformbase}.so : ${r1_install}/lib/libonlp-${platformbase}.so - builds/onlpdump/$BUILD_DIR/x86_64-linux-gnu/bin/onlpdump : ${r1_install}/bin/ \ No newline at end of file +!include $ONL_TEMPLATES/onlp-platform-revision.yml PLATFORM=x86-64-accton-as5916-54x ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu REVISION=r1 From 161bcc91af6a79cb488419a838f1d3864aabb047 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Mon, 25 Sep 2017 18:30:00 +0000 Subject: [PATCH 65/67] Add SFP28. --- .../base/any/onlp/src/sff/module/auto/sff.yml | 2 ++ .../any/onlp/src/sff/module/inc/sff/sff.h | 6 ++-- .../any/onlp/src/sff/module/inc/sff/sff.x | 1 + .../base/any/onlp/src/sff/module/src/sff.c | 4 +-- .../base/any/onlp/src/sff/module/src/sff_db.c | 32 +++++++++++++++++++ .../any/onlp/src/sff/module/src/sff_enums.c | 2 ++ packages/base/any/onlp/src/sff/sff.mk | 4 +-- 7 files changed, 45 insertions(+), 6 deletions(-) diff --git a/packages/base/any/onlp/src/sff/module/auto/sff.yml b/packages/base/any/onlp/src/sff/module/auto/sff.yml index ed2b8bb5..5f3c057c 100644 --- a/packages/base/any/onlp/src/sff/module/auto/sff.yml +++ b/packages/base/any/onlp/src/sff/module/auto/sff.yml @@ -127,6 +127,8 @@ sff_sfp_types: &sff_sfp_types desc: "QSFP+" - QSFP28: desc: "QSFP28" +- SFP28: + desc: "SFP28" definitions: cdefs: diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/sff.h b/packages/base/any/onlp/src/sff/module/inc/sff/sff.h index d146bba2..d011a5da 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/sff.h +++ b/packages/base/any/onlp/src/sff/module/inc/sff/sff.h @@ -196,7 +196,8 @@ typedef enum sff_sfp_type_e { SFF_SFP_TYPE_QSFP, SFF_SFP_TYPE_QSFP_PLUS, SFF_SFP_TYPE_QSFP28, - SFF_SFP_TYPE_LAST = SFF_SFP_TYPE_QSFP28, + SFF_SFP_TYPE_SFP28, + SFF_SFP_TYPE_LAST = SFF_SFP_TYPE_SFP28, SFF_SFP_TYPE_COUNT, SFF_SFP_TYPE_INVALID = -1, } sff_sfp_type_t; @@ -208,6 +209,7 @@ typedef enum sff_sfp_type_e { "QSFP", \ "QSFP_PLUS", \ "QSFP28", \ + "SFP28", \ } /** Enum names. */ const char* sff_sfp_type_name(sff_sfp_type_t e); @@ -220,7 +222,7 @@ const char* sff_sfp_type_desc(sff_sfp_type_t e); /** validator */ #define SFF_SFP_TYPE_VALID(_e) \ - ( (0 <= (_e)) && ((_e) <= SFF_SFP_TYPE_QSFP28)) + ( (0 <= (_e)) && ((_e) <= SFF_SFP_TYPE_SFP28)) /** sff_sfp_type_map table. */ extern aim_map_si_t sff_sfp_type_map[]; diff --git a/packages/base/any/onlp/src/sff/module/inc/sff/sff.x b/packages/base/any/onlp/src/sff/module/inc/sff/sff.x index d02e1840..82ec6c09 100644 --- a/packages/base/any/onlp/src/sff/module/inc/sff/sff.x +++ b/packages/base/any/onlp/src/sff/module/inc/sff/sff.x @@ -95,6 +95,7 @@ SFF_SFP_TYPE_ENTRY(SFP, SFP) SFF_SFP_TYPE_ENTRY(QSFP, QSFP) SFF_SFP_TYPE_ENTRY(QSFP_PLUS, QSFP+) SFF_SFP_TYPE_ENTRY(QSFP28, QSFP28) +SFF_SFP_TYPE_ENTRY(SFP28, SFP28) #undef SFF_SFP_TYPE_ENTRY #endif /* */ diff --git a/packages/base/any/onlp/src/sff/module/src/sff.c b/packages/base/any/onlp/src/sff/module/src/sff.c index c142b6a4..52279a43 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff.c +++ b/packages/base/any/onlp/src/sff/module/src/sff.c @@ -724,13 +724,13 @@ sff_info_init(sff_info_t* info, sff_module_type_t mt, break; case SFF_MODULE_TYPE_25G_BASE_CR: - info->sfp_type = SFF_SFP_TYPE_SFP; + info->sfp_type = SFF_SFP_TYPE_SFP28; info->media_type = SFF_MEDIA_TYPE_COPPER; info->caps = SFF_MODULE_CAPS_F_25G; break; case SFF_MODULE_TYPE_25G_BASE_SR: - info->sfp_type = SFF_SFP_TYPE_SFP; + info->sfp_type = SFF_SFP_TYPE_SFP28; info->media_type = SFF_MEDIA_TYPE_FIBER; info->caps = SFF_MODULE_CAPS_F_25G; break; diff --git a/packages/base/any/onlp/src/sff/module/src/sff_db.c b/packages/base/any/onlp/src/sff/module/src/sff_db.c index f7129be1..30a7c2b2 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff_db.c +++ b/packages/base/any/onlp/src/sff/module/src/sff_db.c @@ -28,6 +28,9 @@ #define SFF_10G_BASE_SRL_PROPERTIES \ SFF_SFP_TYPE_SFP, "SFP", SFF_MODULE_TYPE_10G_BASE_SRL, "1GBASE-SRL", SFF_MEDIA_TYPE_FIBER, "Fiber", SFF_MODULE_CAPS_F_10G +#define SFF_25G_BASE_SR_PROPERTIES \ + SFF_SFP_TYPE_SFP28, "SFP28", SFF_MODULE_TYPE_25G_BASE_SR, "25GBASE-SR", SFF_MEDIA_TYPE_FIBER, "Fiber",SFF_MODULE_CAPS_F_25G + #define SFF_40G_BASE_SR4_PROPERTIES \ SFF_SFP_TYPE_QSFP_PLUS, "QSFP+", SFF_MODULE_TYPE_40G_BASE_SR4, "40GBASE-SR4", SFF_MEDIA_TYPE_FIBER, "Fiber", SFF_MODULE_CAPS_F_40G @@ -1417,6 +1420,35 @@ static sff_db_entry_t sff_database__[] = }, }, }, + { + { + .eeprom = { + 0x03, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xff, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x0a, 0x07, 0x46, 0x49, 0x4e, 0x49, 0x53, 0x41, 0x52, 0x20, 0x43, 0x4f, 0x52, 0x50, + 0x2e, 0x20, 0x20, 0x20, 0x02, 0x00, 0x90, 0x65, 0x46, 0x54, 0x4c, 0x46, 0x38, 0x35, 0x33, 0x36, + 0x50, 0x34, 0x42, 0x43, 0x4c, 0x20, 0x20, 0x20, 0x41, 0x20, 0x20, 0x20, 0x03, 0x52, 0x00, 0xb8, + 0x08, 0x1a, 0x70, 0x00, 0x55, 0x57, 0x42, 0x30, 0x34, 0x56, 0x59, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x31, 0x36, 0x31, 0x32, 0x32, 0x35, 0x20, 0x20, 0x68, 0xf0, 0x08, 0x84, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + .info = { + "FINISAR CORP. ", + "FTLF8536P4BCL ", + "UWB04VY ", + SFF_25G_BASE_SR_PROPERTIES, + -1, + } + } + }, { { .eeprom = { diff --git a/packages/base/any/onlp/src/sff/module/src/sff_enums.c b/packages/base/any/onlp/src/sff/module/src/sff_enums.c index 876c01e8..8d8e62b9 100644 --- a/packages/base/any/onlp/src/sff/module/src/sff_enums.c +++ b/packages/base/any/onlp/src/sff/module/src/sff_enums.c @@ -251,6 +251,7 @@ aim_map_si_t sff_sfp_type_map[] = { "QSFP", SFF_SFP_TYPE_QSFP }, { "QSFP_PLUS", SFF_SFP_TYPE_QSFP_PLUS }, { "QSFP28", SFF_SFP_TYPE_QSFP28 }, + { "SFP28", SFF_SFP_TYPE_SFP28 }, { NULL, 0 } }; @@ -260,6 +261,7 @@ aim_map_si_t sff_sfp_type_desc_map[] = { "QSFP", SFF_SFP_TYPE_QSFP }, { "QSFP+", SFF_SFP_TYPE_QSFP_PLUS }, { "QSFP28", SFF_SFP_TYPE_QSFP28 }, + { "SFP28", SFF_SFP_TYPE_SFP28 }, { NULL, 0 } }; diff --git a/packages/base/any/onlp/src/sff/sff.mk b/packages/base/any/onlp/src/sff/sff.mk index b2b5922f..3760cec8 100644 --- a/packages/base/any/onlp/src/sff/sff.mk +++ b/packages/base/any/onlp/src/sff/sff.mk @@ -3,12 +3,12 @@ # # Inclusive Makefile for the sff module. # -# Autogenerated 2017-09-14 23:57:29.895708 +# Autogenerated 2017-09-25 18:15:50.901582 # ############################################################################### sff_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) include $(sff_BASEDIR)module/make.mk -include $(sff_BASEDIR)module/src/make.mk include $(sff_BASEDIR)module/auto/make.mk +include $(sff_BASEDIR)module/src/make.mk include $(sff_BASEDIR)utest/_make.mk From edc98e74367a90bc0215f844c5a1ce7c8633d647 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 26 Sep 2017 17:43:33 +0000 Subject: [PATCH 66/67] Add option to output utilization only. --- .../base/any/onlp-snmpd/bin/onl-snmp-mpstat | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/base/any/onlp-snmpd/bin/onl-snmp-mpstat b/packages/base/any/onlp-snmpd/bin/onl-snmp-mpstat index d7247f94..12ed7883 100755 --- a/packages/base/any/onlp-snmpd/bin/onl-snmp-mpstat +++ b/packages/base/any/onlp-snmpd/bin/onl-snmp-mpstat @@ -14,6 +14,11 @@ Average: all 5.17 0.00 2.07 0.00 0.00 0.00 0.00 0.00 import subprocess import json +import argparse + +ap = argparse.ArgumentParser("onl-snmp-mpstat") +ap.add_argument("-u", required=False, help="Output current utilization only.", action='store_true') +ops = ap.parse_args() stats = {} @@ -30,5 +35,13 @@ for line in out.split('\n'): vals = line.split()[1:] stats[vals[0]] = { k:int(round(100*float(v))) \ for (k,v) in zip(keys[1:],vals[1:]) } - -print json.dumps(stats) +if ops.u: + u = 0; + try: + idle = stats['all']['%idle'] + u = 10000 - idle + except: + pass + print u +else: + print json.dumps(stats) From 86df0e7c8d39f1839c8bbd4d10d7e2bea967cda9 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 26 Sep 2017 22:19:09 +0000 Subject: [PATCH 67/67] Latest --- packages/platforms-closed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/platforms-closed b/packages/platforms-closed index 84fffe45..5336dac8 160000 --- a/packages/platforms-closed +++ b/packages/platforms-closed @@ -1 +1 @@ -Subproject commit 84fffe4502faabac0891b7e80fe3eea9a02df099 +Subproject commit 5336dac8f6fb1a602061256d2e0c76e5065d975e