From 8b566a62246f41f5d683ac1f32dddcd076c4e324 Mon Sep 17 00:00:00 2001 From: Eugene Dementyev Date: Thu, 7 Apr 2016 17:07:36 +0600 Subject: [PATCH 01/10] Update sfpi.c Fix wrong value of qsf-qdb (ports 69,70) --- .../builds/src/x86_64_quanta_ly8_rangeley/module/src/sfpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/sfpi.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/sfpi.c index ecab4d29..e58f0dce 100644 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/sfpi.c +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/sfpi.c @@ -99,8 +99,8 @@ static sfpmap_t sfpmap__[] = { 50, QSFP_GPIO_PRSNT_50_N /* 430 */, "/sys/class/gpio/gpio428/value", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-21/i2c-81/81-0050/eeprom", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-21/i2c-81/81-0051/eeprom" }, { 51, QSFP_GPIO_PRSNT_51_N /* 434 */, "/sys/class/gpio/gpio432/value", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-21/i2c-82/82-0050/eeprom", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-21/i2c-82/82-0051/eeprom" }, { 52, QSFP_GPIO_PRSNT_52_N /* 438 */, "/sys/class/gpio/gpio436/value", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-21/i2c-83/83-0050/eeprom", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-21/i2c-83/83-0051/eeprom" }, - { 69, QSFP_QDB_GPIO_PRSNT_69_N /* 442 */, "/sys/class/gpio/gpio432/value", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-88/88-0050/eeprom", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-88/88-0051/eeprom" }, - { 70, QSFP_QDB_GPIO_PRSNT_70_N /* 446 */, "/sys/class/gpio/gpio436/value", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-89/89-0050/eeprom", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-89/89-0051/eeprom" }, + { 69, QSFP_QDB_GPIO_PRSNT_69_N /* 442 */, "/sys/class/gpio/gpio442/value", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-88/88-0050/eeprom", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-88/88-0051/eeprom" }, + { 70, QSFP_QDB_GPIO_PRSNT_70_N /* 446 */, "/sys/class/gpio/gpio446/value", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-89/89-0050/eeprom", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-89/89-0051/eeprom" }, }; int From 173e9d2e37385ca7066945d788b2a101ae584d46 Mon Sep 17 00:00:00 2001 From: brandonchuang Date: Tue, 12 Apr 2016 11:54:51 +0800 Subject: [PATCH 02/10] [as5512-54x] Add onlp for 5512 --- .../configs/x86_64-all/x86_64-all.config | 4 + ...orm-accton-as5512_54x-device-drivers.patch | 2608 +++++++++++++++++ .../kernels/3.2.65-1+deb7u2/patches/series | 1 + .../x86-64-accton-as5512-54x/.gitignore | 2 + .../x86-64/x86-64-accton-as5512-54x/Makefile | 1 + .../x86-64-accton-as5512-54x/onlp/Makefile | 1 + .../x86-64-accton-as5512-54x/onlp/PKG.yml | 1 + .../onlp/builds/Makefile | 2 + .../onlp/builds/lib/Makefile | 45 + .../onlp/builds/onlpdump/Makefile | 46 + .../onlp/builds/src/Makefile | 9 + .../onlp/builds/src/README | 6 + .../onlp/builds/src/module/auto/make.mk | 9 + .../module/auto/x86_64_accton_as5512_54x.yml | 50 + .../x86_64_accton_as5512_54x.x | 14 + .../x86_64_accton_as5512_54x_config.h | 137 + .../x86_64_accton_as5512_54x_dox.h | 26 + .../x86_64_accton_as5512_54x_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 | 420 +++ .../onlp/builds/src/module/src/ledi.c | 313 ++ .../onlp/builds/src/module/src/make.mk | 9 + .../onlp/builds/src/module/src/platform_lib.c | 169 ++ .../onlp/builds/src/module/src/platform_lib.h | 66 + .../onlp/builds/src/module/src/psui.c | 247 ++ .../onlp/builds/src/module/src/sfpi.c | 356 +++ .../onlp/builds/src/module/src/sysi.c | 276 ++ .../onlp/builds/src/module/src/thermali.c | 175 ++ .../src/x86_64_accton_as5512_54x_config.c | 80 + .../src/x86_64_accton_as5512_54x_enums.c | 10 + .../module/src/x86_64_accton_as5512_54x_int.h | 12 + .../module/src/x86_64_accton_as5512_54x_log.c | 18 + .../module/src/x86_64_accton_as5512_54x_log.h | 12 + .../src/x86_64_accton_as5512_54x_module.c | 24 + .../src/x86_64_accton_as5512_54x_ucli.c | 50 + .../platform-config/Makefile | 1 + .../platform-config/r0/Makefile | 1 + .../platform-config/r0/PKG.yml | 1 + .../platform-config/r0/src/lib/boot/grub.cfg | 21 + .../src/lib/boot/x86-64-accton-as5512-54x-r0 | 7 + .../install/x86-64-accton-as5512-54x-r0.sh | 15 + .../x86_64_accton_as5512_54x_r0/__init__.py | 78 + 44 files changed, 5494 insertions(+) create mode 100644 packages/base/any/kernels/3.2.65-1+deb7u2/patches/platform-accton-as5512_54x-device-drivers.patch create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/.gitignore create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/lib/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/onlpdump/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/README create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/auto/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/auto/x86_64_accton_as5512_54x.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x.x create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_config.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_dox.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_porting.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/debug.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/fani.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/ledi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/platform_lib.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/platform_lib.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/psui.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/sfpi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/sysi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/thermali.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_config.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_enums.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_int.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_log.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_log.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_module.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_ucli.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/boot/grub.cfg create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/boot/x86-64-accton-as5512-54x-r0 create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/install/x86-64-accton-as5512-54x-r0.sh create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/python/x86_64_accton_as5512_54x_r0/__init__.py diff --git a/packages/base/any/kernels/3.2.65-1+deb7u2/configs/x86_64-all/x86_64-all.config b/packages/base/any/kernels/3.2.65-1+deb7u2/configs/x86_64-all/x86_64-all.config index 49879a00..968dfaec 100644 --- a/packages/base/any/kernels/3.2.65-1+deb7u2/configs/x86_64-all/x86_64-all.config +++ b/packages/base/any/kernels/3.2.65-1+deb7u2/configs/x86_64-all/x86_64-all.config @@ -1047,6 +1047,7 @@ CONFIG_EEPROM_AT24=y CONFIG_EEPROM_AT25=y # CONFIG_EEPROM_LEGACY is not set # CONFIG_EEPROM_MAX6875 is not set +CONFIG_EEPROM_ACCTON_AS5512_54X_SFP=y CONFIG_EEPROM_ACCTON_AS5712_54x_SFP=y CONFIG_EEPROM_ACCTON_AS6712_32x_SFP=y CONFIG_EEPROM_ACCTON_AS7512_32x_SFP=y @@ -1911,6 +1912,8 @@ CONFIG_SENSORS_W83781D=y # CONFIG_SENSORS_APPLESMC is not set # CONFIG_SENSORS_QUANTA_LY_HWMON is not set CONFIG_SENSORS_CPR_4011_4MXX=y +CONFIG_SENSORS_ACCTON_AS5512_54X_PSU=y +CONFIG_SENSORS_ACCTON_AS5512_54X_FAN=y CONFIG_SENSORS_ACCTON_AS5712_54x_FAN=y CONFIG_SENSORS_ACCTON_AS5712_54x_PSU=y CONFIG_SENSORS_ACCTON_AS6712_32x_FAN=y @@ -2299,6 +2302,7 @@ CONFIG_LEDS_CLASS=y # # LED drivers # +CONFIG_LEDS_ACCTON_AS5512_54X=y CONFIG_LEDS_ACCTON_AS5712_54x=y CONFIG_LEDS_ACCTON_AS6712_32x=y CONFIG_LEDS_ACCTON_AS7512_32x=y diff --git a/packages/base/any/kernels/3.2.65-1+deb7u2/patches/platform-accton-as5512_54x-device-drivers.patch b/packages/base/any/kernels/3.2.65-1+deb7u2/patches/platform-accton-as5512_54x-device-drivers.patch new file mode 100644 index 00000000..d20e89ce --- /dev/null +++ b/packages/base/any/kernels/3.2.65-1+deb7u2/patches/platform-accton-as5512_54x-device-drivers.patch @@ -0,0 +1,2608 @@ +Device driver patches for accton as5512 (fan/psu/cpld/led/sfp) + +diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig +index 89c619d..968bd5f 100644 +--- a/drivers/hwmon/Kconfig ++++ b/drivers/hwmon/Kconfig +@@ -1574,6 +1574,24 @@ config SENSORS_ACCTON_AS5812_54t_PSU + This driver can also be built as a module. If so, the module will + be called accton_as5812_54t_psu. + ++config SENSORS_ACCTON_AS5512_54X_PSU ++ tristate "Accton as5512 54x psu" ++ depends on I2C && SENSORS_ACCTON_I2C_CPLD ++ help ++ If you say yes here you get support for Accton as5512 54x psu. ++ ++ This driver can also be built as a module. If so, the module will ++ be called accton_as5512_54x_psu. ++ ++config SENSORS_ACCTON_AS5512_54X_FAN ++ tristate "Accton as5512 54x fan" ++ depends on I2C && SENSORS_ACCTON_I2C_CPLD ++ help ++ If you say yes here you get support for Accton as5512 54x fan. ++ ++ This driver can also be built as a module. If so, the module will ++ be called accton_as5512_54x_fan. ++ + if ACPI + + comment "ACPI drivers" +diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile +index de922bc..b8ee7b0 100644 +--- a/drivers/hwmon/Makefile ++++ b/drivers/hwmon/Makefile +@@ -36,6 +36,8 @@ obj-$(CONFIG_SENSORS_ACCTON_AS6812_32x_FAN) += accton_as6812_32x_fan.o + obj-$(CONFIG_SENSORS_ACCTON_AS6812_32x_PSU) += accton_as6812_32x_psu.o + obj-$(CONFIG_SENSORS_ACCTON_AS5812_54t_FAN) += accton_as5812_54t_fan.o + obj-$(CONFIG_SENSORS_ACCTON_AS5812_54t_PSU) += accton_as5812_54t_psu.o ++obj-$(CONFIG_SENSORS_ACCTON_AS5512_54X_PSU) += accton_as5512_54x_psu.o ++obj-$(CONFIG_SENSORS_ACCTON_AS5512_54X_FAN) += accton_as5512_54x_fan.o + obj-$(CONFIG_SENSORS_AD7314) += ad7314.o + obj-$(CONFIG_SENSORS_AD7414) += ad7414.o + obj-$(CONFIG_SENSORS_AD7418) += ad7418.o +diff --git a/drivers/hwmon/accton_as5512_54x_fan.c b/drivers/hwmon/accton_as5512_54x_fan.c +new file mode 100644 +index 0000000..67e3dd6 +--- /dev/null ++++ b/drivers/hwmon/accton_as5512_54x_fan.c +@@ -0,0 +1,454 @@ ++/* ++ * A hwmon driver for the Accton as5512 54x fan control ++ * ++ * Copyright (C) 2015 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 ++#include ++#include ++#include ++ ++#define FAN_MAX_NUMBER 5 ++#define FAN_SPEED_CPLD_TO_RPM_STEP 150 ++#define FAN_SPEED_PRECENT_TO_CPLD_STEP 5 ++#define FAN_DUTY_CYCLE_MIN 0 ++#define FAN_DUTY_CYCLE_MAX 100 /* 100% */ ++ ++#define CPLD_REG_FAN_STATUS_OFFSET 0x0C ++#define CPLD_REG_FANR_STATUS_OFFSET 0x1E ++#define CPLD_REG_FAN_DIRECTION_OFFSET 0x1D ++ ++#define CPLD_FAN1_REG_SPEED_OFFSET 0x10 ++#define CPLD_FAN2_REG_SPEED_OFFSET 0x11 ++#define CPLD_FAN3_REG_SPEED_OFFSET 0x12 ++#define CPLD_FAN4_REG_SPEED_OFFSET 0x13 ++#define CPLD_FAN5_REG_SPEED_OFFSET 0x14 ++ ++#define CPLD_FANR1_REG_SPEED_OFFSET 0x18 ++#define CPLD_FANR2_REG_SPEED_OFFSET 0x19 ++#define CPLD_FANR3_REG_SPEED_OFFSET 0x1A ++#define CPLD_FANR4_REG_SPEED_OFFSET 0x1B ++#define CPLD_FANR5_REG_SPEED_OFFSET 0x1C ++ ++#define CPLD_REG_FAN_PWM_CYCLE_OFFSET 0x0D ++ ++#define CPLD_FAN1_INFO_BIT_MASK 0x01 ++#define CPLD_FAN2_INFO_BIT_MASK 0x02 ++#define CPLD_FAN3_INFO_BIT_MASK 0x04 ++#define CPLD_FAN4_INFO_BIT_MASK 0x08 ++#define CPLD_FAN5_INFO_BIT_MASK 0x10 ++ ++#define PROJECT_NAME ++ ++#define LOCAL_DEBUG 0 ++ ++static struct accton_as5512_54x_fan *fan_data = NULL; ++ ++struct accton_as5512_54x_fan { ++ struct platform_device *pdev; ++ struct device *hwmon_dev; ++ struct mutex update_lock; ++ char valid; /* != 0 if registers are valid */ ++ unsigned long last_updated; /* In jiffies */ ++ u8 status[FAN_MAX_NUMBER]; /* inner first fan status */ ++ u32 speed[FAN_MAX_NUMBER]; /* inner first fan speed */ ++ u8 direction[FAN_MAX_NUMBER]; /* reconrd the direction of inner first and second fans */ ++ u32 duty_cycle[FAN_MAX_NUMBER]; /* control the speed of inner first and second fans */ ++ u8 r_status[FAN_MAX_NUMBER]; /* inner second fan status */ ++ u32 r_speed[FAN_MAX_NUMBER]; /* inner second fan speed */ ++}; ++ ++/*******************/ ++#define MAKE_FAN_MASK_OR_REG(name,type) \ ++ CPLD_FAN##type##1_##name, \ ++ CPLD_FAN##type##2_##name, \ ++ CPLD_FAN##type##3_##name, \ ++ CPLD_FAN##type##4_##name, \ ++ CPLD_FAN##type##5_##name, ++ ++/* fan related data ++ */ ++static const u8 fan_info_mask[] = { ++ MAKE_FAN_MASK_OR_REG(INFO_BIT_MASK,) ++}; ++ ++static const u8 fan_speed_reg[] = { ++ MAKE_FAN_MASK_OR_REG(REG_SPEED_OFFSET,) ++}; ++ ++static const u8 fanr_speed_reg[] = { ++ MAKE_FAN_MASK_OR_REG(REG_SPEED_OFFSET,R) ++}; ++ ++/*******************/ ++#define DEF_FAN_SET(id) \ ++ FAN##id##_FAULT, \ ++ FAN##id##_SPEED, \ ++ FAN##id##_DUTY_CYCLE, \ ++ FAN##id##_DIRECTION, \ ++ FANR##id##_FAULT, \ ++ FANR##id##_SPEED, ++ ++enum sysfs_fan_attributes { ++ DEF_FAN_SET(1) ++ DEF_FAN_SET(2) ++ DEF_FAN_SET(3) ++ DEF_FAN_SET(4) ++ DEF_FAN_SET(5) ++}; ++/*******************/ ++static void accton_as5512_54x_fan_update_device(struct device *dev); ++static int accton_as5512_54x_fan_read_value(u8 reg); ++static int accton_as5512_54x_fan_write_value(u8 reg, u8 value); ++ ++static ssize_t fan_set_duty_cycle(struct device *dev, ++ struct device_attribute *da,const char *buf, size_t count); ++static ssize_t fan_show_value(struct device *dev, ++ struct device_attribute *da, char *buf); ++ ++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); ++ ++ ++/*******************/ ++#define _MAKE_SENSOR_DEVICE_ATTR(prj, id) \ ++ static SENSOR_DEVICE_ATTR(prj##fan##id##_fault, S_IRUGO, fan_show_value, NULL, FAN##id##_FAULT); \ ++ static SENSOR_DEVICE_ATTR(prj##fan##id##_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##id##_SPEED); \ ++ static SENSOR_DEVICE_ATTR(prj##fan##id##_direction, S_IRUGO, fan_show_value, NULL, FAN##id##_DIRECTION); \ ++ static SENSOR_DEVICE_ATTR(prj##fanr##id##_fault, S_IRUGO, fan_show_value, NULL, FANR##id##_FAULT); \ ++ static SENSOR_DEVICE_ATTR(prj##fanr##id##_speed_rpm, S_IRUGO, fan_show_value, NULL, FANR##id##_SPEED); ++ ++#define MAKE_SENSOR_DEVICE_ATTR(prj,id) _MAKE_SENSOR_DEVICE_ATTR(prj,id) ++ ++#define _MAKE_SENSOR_DEVICE_ATTR_FAN_DUTY(prj,id) \ ++ static SENSOR_DEVICE_ATTR(prj##fan##id##_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, \ ++ fan_set_duty_cycle, FAN1_DUTY_CYCLE); ++ ++#define MAKE_SENSOR_DEVICE_ATTR_FAN_DUTY(prj,id) _MAKE_SENSOR_DEVICE_ATTR_FAN_DUTY(prj,id) ++ ++ ++MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 1) ++MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 2) ++MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 3) ++MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 4) ++MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 5) ++MAKE_SENSOR_DEVICE_ATTR_FAN_DUTY(PROJECT_NAME,) ++/*******************/ ++ ++#define _MAKE_FAN_ATTR(prj, id) \ ++ &sensor_dev_attr_##prj##fan##id##_fault.dev_attr.attr, \ ++ &sensor_dev_attr_##prj##fan##id##_speed_rpm.dev_attr.attr, \ ++ &sensor_dev_attr_##prj##fan##id##_direction.dev_attr.attr, \ ++ &sensor_dev_attr_##prj##fanr##id##_fault.dev_attr.attr, \ ++ &sensor_dev_attr_##prj##fanr##id##_speed_rpm.dev_attr.attr, ++ ++#define MAKE_FAN_ATTR(prj, id) _MAKE_FAN_ATTR(prj, id) ++ ++#define _MAKE_FAN_DUTY_ATTR(prj, id) \ ++ &sensor_dev_attr_##prj##fan##id##_duty_cycle_percentage.dev_attr.attr, ++ ++#define MAKE_FAN_DUTY_ATTR(prj, id) _MAKE_FAN_DUTY_ATTR(prj, id) ++ ++static struct attribute *accton_as5512_54x_fan_attributes[] = { ++ /* fan related attributes */ ++ MAKE_FAN_ATTR(PROJECT_NAME,1) ++ MAKE_FAN_ATTR(PROJECT_NAME,2) ++ MAKE_FAN_ATTR(PROJECT_NAME,3) ++ MAKE_FAN_ATTR(PROJECT_NAME,4) ++ MAKE_FAN_ATTR(PROJECT_NAME,5) ++ MAKE_FAN_DUTY_ATTR(PROJECT_NAME,) ++ NULL ++}; ++/*******************/ ++ ++/* fan related functions ++ */ ++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); ++ ssize_t ret = 0; ++ int data_index, type_index; ++ ++ accton_as5512_54x_fan_update_device(dev); ++ ++ if (fan_data->valid == 0) { ++ return ret; ++ } ++ ++ type_index = attr->index%FAN2_FAULT; ++ data_index = attr->index/FAN2_FAULT; ++ ++ switch (type_index) { ++ case FAN1_FAULT: ++ ret = sprintf(buf, "%d\n", fan_data->status[data_index]); ++ if (LOCAL_DEBUG) ++ printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); ++ break; ++ case FAN1_SPEED: ++ ret = sprintf(buf, "%d\n", fan_data->speed[data_index]); ++ if (LOCAL_DEBUG) ++ printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); ++ break; ++ case FAN1_DUTY_CYCLE: ++ ret = sprintf(buf, "%d\n", fan_data->duty_cycle[data_index]); ++ if (LOCAL_DEBUG) ++ printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); ++ break; ++ case FAN1_DIRECTION: ++ ret = sprintf(buf, "%d\n", fan_data->direction[data_index]); /* presnet, need to modify*/ ++ if (LOCAL_DEBUG) ++ printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); ++ break; ++ case FANR1_FAULT: ++ ret = sprintf(buf, "%d\n", fan_data->r_status[data_index]); ++ if (LOCAL_DEBUG) ++ printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); ++ break; ++ case FANR1_SPEED: ++ ret = sprintf(buf, "%d\n", fan_data->r_speed[data_index]); ++ if (LOCAL_DEBUG) ++ printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); ++ break; ++ default: ++ if (LOCAL_DEBUG) ++ printk ("[Check !!][%s][%d] \n", __FUNCTION__, __LINE__); ++ break; ++ } ++ ++ return ret; ++} ++/*******************/ ++static ssize_t fan_set_duty_cycle(struct device *dev, struct device_attribute *da, ++ const char *buf, size_t count) { ++ ++ int error, value; ++ ++ error = kstrtoint(buf, 10, &value); ++ if (error) ++ return error; ++ ++ if (value < FAN_DUTY_CYCLE_MIN || value > FAN_DUTY_CYCLE_MAX) ++ return -EINVAL; ++ ++ accton_as5512_54x_fan_write_value(CPLD_REG_FAN_PWM_CYCLE_OFFSET, value/FAN_SPEED_PRECENT_TO_CPLD_STEP); ++ ++ fan_data->valid = 0; ++ ++ return count; ++} ++ ++static const struct attribute_group accton_as5512_54x_fan_group = { ++ .attrs = accton_as5512_54x_fan_attributes, ++}; ++ ++static int accton_as5512_54x_fan_read_value(u8 reg) ++{ ++ return accton_i2c_cpld_read(0x60, reg); ++} ++ ++static int accton_as5512_54x_fan_write_value(u8 reg, u8 value) ++{ ++ return accton_i2c_cpld_write(0x60, reg, value); ++} ++ ++static void accton_as5512_54x_fan_update_device(struct device *dev) ++{ ++ int speed, r_speed, fault, r_fault, ctrl_speed, direction; ++ int i; ++ ++ mutex_lock(&fan_data->update_lock); ++ ++ if (LOCAL_DEBUG) ++ printk ("Starting accton_as5512_54x_fan update \n"); ++ ++ if (!(time_after(jiffies, fan_data->last_updated + HZ + HZ / 2) || !fan_data->valid)) { ++ /* do nothing */ ++ goto _exit; ++ } ++ ++ fan_data->valid = 0; ++ ++ if (LOCAL_DEBUG) ++ printk ("Starting accton_as5512_54x_fan update 2 \n"); ++ ++ fault = accton_as5512_54x_fan_read_value(CPLD_REG_FAN_STATUS_OFFSET); ++ r_fault = accton_as5512_54x_fan_read_value(CPLD_REG_FANR_STATUS_OFFSET); ++ direction = accton_as5512_54x_fan_read_value(CPLD_REG_FAN_DIRECTION_OFFSET); ++ ctrl_speed = accton_as5512_54x_fan_read_value(CPLD_REG_FAN_PWM_CYCLE_OFFSET); ++ ++ if ( (fault < 0) || (r_fault < 0) || (direction < 0) || (ctrl_speed < 0) ) ++ { ++ if (LOCAL_DEBUG) ++ printk ("[Error!!][%s][%d] \n", __FUNCTION__, __LINE__); ++ goto _exit; /* error */ ++ } ++ ++ if (LOCAL_DEBUG) ++ printk ("[fan:] fault:%d, r_fault=%d, direction=%d, ctrl_speed=%d \n",fault, r_fault, direction, ctrl_speed); ++ ++ for (i=0; istatus[i] = (fault & fan_info_mask[i]) >> i; ++ if (LOCAL_DEBUG) ++ printk ("[fan%d:] fail=%d \n",i, fan_data->status[i]); ++ ++ fan_data->r_status[i] = (r_fault & fan_info_mask[i]) >> i; ++ fan_data->direction[i] = (direction & fan_info_mask[i]) >> i; ++ fan_data->duty_cycle[i] = ctrl_speed * FAN_SPEED_PRECENT_TO_CPLD_STEP; ++ ++ /* fan speed ++ */ ++ speed = accton_as5512_54x_fan_read_value(fan_speed_reg[i]); ++ r_speed = accton_as5512_54x_fan_read_value(fanr_speed_reg[i]); ++ if ( (speed < 0) || (r_speed < 0) ) ++ { ++ if (LOCAL_DEBUG) ++ printk ("[Error!!][%s][%d] \n", __FUNCTION__, __LINE__); ++ goto _exit; /* error */ ++ } ++ ++ if (LOCAL_DEBUG) ++ printk ("[fan%d:] speed:%d, r_speed=%d \n", i, speed, r_speed); ++ ++ fan_data->speed[i] = speed * FAN_SPEED_CPLD_TO_RPM_STEP; ++ fan_data->r_speed[i] = r_speed * FAN_SPEED_CPLD_TO_RPM_STEP; ++ } ++ ++ /* finish to update */ ++ fan_data->last_updated = jiffies; ++ fan_data->valid = 1; ++ ++_exit: ++ mutex_unlock(&fan_data->update_lock); ++} ++ ++static int accton_as5512_54x_fan_probe(struct platform_device *pdev) ++{ ++ int status = -1; ++ ++ /* Register sysfs hooks */ ++ status = sysfs_create_group(&pdev->dev.kobj, &accton_as5512_54x_fan_group); ++ if (status) { ++ goto exit; ++ ++ } ++ ++ fan_data->hwmon_dev = hwmon_device_register(&pdev->dev); ++ if (IS_ERR(fan_data->hwmon_dev)) { ++ status = PTR_ERR(fan_data->hwmon_dev); ++ goto exit_remove; ++ } ++ ++ dev_info(&pdev->dev, "accton_as5512_54x_fan\n"); ++ ++ return 0; ++ ++exit_remove: ++ sysfs_remove_group(&pdev->dev.kobj, &accton_as5512_54x_fan_group); ++exit: ++ return status; ++} ++ ++static int accton_as5512_54x_fan_remove(struct platform_device *pdev) ++{ ++ hwmon_device_unregister(fan_data->hwmon_dev); ++ sysfs_remove_group(&fan_data->pdev->dev.kobj, &accton_as5512_54x_fan_group); ++ ++ return 0; ++} ++ ++#define DRVNAME "as5512_54x_fan" ++ ++static struct platform_driver accton_as5512_54x_fan_driver = { ++ .probe = accton_as5512_54x_fan_probe, ++ .remove = accton_as5512_54x_fan_remove, ++ .driver = { ++ .name = DRVNAME, ++ .owner = THIS_MODULE, ++ }, ++}; ++ ++static int __init accton_as5512_54x_fan_init(void) ++{ ++ int ret; ++ ++ extern int platform_accton_as5512_54x(void); ++ if(!platform_accton_as5512_54x()) { ++ return -ENODEV; ++ } ++ ++ ret = platform_driver_register(&accton_as5512_54x_fan_driver); ++ if (ret < 0) { ++ goto exit; ++ } ++ ++ fan_data = kzalloc(sizeof(struct accton_as5512_54x_fan), GFP_KERNEL); ++ if (!fan_data) { ++ ret = -ENOMEM; ++ platform_driver_unregister(&accton_as5512_54x_fan_driver); ++ goto exit; ++ } ++ ++ mutex_init(&fan_data->update_lock); ++ fan_data->valid = 0; ++ ++ fan_data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); ++ if (IS_ERR(fan_data->pdev)) { ++ ret = PTR_ERR(fan_data->pdev); ++ platform_driver_unregister(&accton_as5512_54x_fan_driver); ++ kfree(fan_data); ++ goto exit; ++ } ++ ++exit: ++ return ret; ++} ++ ++static void __exit accton_as5512_54x_fan_exit(void) ++{ ++ platform_device_unregister(fan_data->pdev); ++ platform_driver_unregister(&accton_as5512_54x_fan_driver); ++ kfree(fan_data); ++} ++ ++MODULE_AUTHOR("Brandon Chuang "); ++MODULE_DESCRIPTION("accton_as5512_54x_fan driver"); ++MODULE_LICENSE("GPL"); ++ ++module_init(accton_as5512_54x_fan_init); ++module_exit(accton_as5512_54x_fan_exit); ++ ++ +diff --git a/drivers/hwmon/accton_as5512_54x_psu.c b/drivers/hwmon/accton_as5512_54x_psu.c +new file mode 100644 +index 0000000..66d61f3 +--- /dev/null ++++ b/drivers/hwmon/accton_as5512_54x_psu.c +@@ -0,0 +1,295 @@ ++/* ++ * An hwmon driver for accton as5512_54x Power Module ++ * ++ * Copyright (C) 2015 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 ++ ++static ssize_t show_index(struct device *dev, struct device_attribute *da, char *buf); ++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 as5512_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[] = { 0x38, 0x3b, 0x50, 0x53, I2C_CLIENT_END }; ++ ++/* Each client has this additional data ++ */ ++struct as5512_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[14]; /* Model name, read from eeprom */ ++}; ++ ++static struct as5512_54x_psu_data *as5512_54x_psu_update_device(struct device *dev); ++ ++enum as5512_54x_psu_sysfs_attributes { ++ PSU_INDEX, ++ PSU_PRESENT, ++ PSU_MODEL_NAME, ++ PSU_POWER_GOOD ++}; ++ ++/* sysfs attributes for hwmon ++ */ ++static SENSOR_DEVICE_ATTR(psu_index, S_IRUGO, show_index, NULL, PSU_INDEX); ++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 *as5512_54x_psu_attributes[] = { ++ &sensor_dev_attr_psu_index.dev_attr.attr, ++ &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_index(struct device *dev, struct device_attribute *da, ++ char *buf) ++{ ++ struct i2c_client *client = to_i2c_client(dev); ++ struct as5512_54x_psu_data *data = i2c_get_clientdata(client); ++ ++ return sprintf(buf, "%d\n", data->index); ++} ++ ++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 as5512_54x_psu_data *data = as5512_54x_psu_update_device(dev); ++ u8 status = 0; ++ ++ if (attr->index == PSU_PRESENT) { ++ status = !(data->status >> ((data->index - 1) * 4) & 0x1); ++ } ++ else { /* PSU_POWER_GOOD */ ++ status = data->status >> ((data->index - 1) * 4 + 1) & 0x1; ++ } ++ ++ return sprintf(buf, "%d\n", status); ++} ++ ++static ssize_t show_model_name(struct device *dev, struct device_attribute *da, ++ char *buf) ++{ ++ struct as5512_54x_psu_data *data = as5512_54x_psu_update_device(dev); ++ ++ return sprintf(buf, "%s", data->model_name); ++} ++ ++static const struct attribute_group as5512_54x_psu_group = { ++ .attrs = as5512_54x_psu_attributes, ++}; ++ ++static int as5512_54x_psu_probe(struct i2c_client *client, ++ const struct i2c_device_id *dev_id) ++{ ++ struct as5512_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 as5512_54x_psu_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, &as5512_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; ++ } ++ ++ /* Update PSU index */ ++ if (client->addr == 0x38 || client->addr == 0x50) { ++ data->index = 1; ++ } ++ else if (client->addr == 0x3b || client->addr == 0x53) { ++ data->index = 2; ++ } ++ ++ 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, &as5512_54x_psu_group); ++exit_free: ++ kfree(data); ++exit: ++ ++ return status; ++} ++ ++static int as5512_54x_psu_remove(struct i2c_client *client) ++{ ++ struct as5512_54x_psu_data *data = i2c_get_clientdata(client); ++ ++ hwmon_device_unregister(data->hwmon_dev); ++ sysfs_remove_group(&client->dev.kobj, &as5512_54x_psu_group); ++ kfree(data); ++ ++ return 0; ++} ++ ++static const struct i2c_device_id as5512_54x_psu_id[] = { ++ { "as5512_54x_psu", 0 }, ++ {} ++}; ++MODULE_DEVICE_TABLE(i2c, as5512_54x_psu_id); ++ ++static struct i2c_driver as5512_54x_psu_driver = { ++ .class = I2C_CLASS_HWMON, ++ .driver = { ++ .name = "as5512_54x_psu", ++ }, ++ .probe = as5512_54x_psu_probe, ++ .remove = as5512_54x_psu_remove, ++ .id_table = as5512_54x_psu_id, ++ .address_list = normal_i2c, ++}; ++ ++static int as5512_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data, ++ int data_len) ++{ ++ int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); ++ ++ if (unlikely(result < 0)) ++ goto abort; ++ if (unlikely(result != data_len)) { ++ result = -EIO; ++ goto abort; ++ } ++ ++ result = 0; ++ ++abort: ++ return result; ++} ++ ++static struct as5512_54x_psu_data *as5512_54x_psu_update_device(struct device *dev) ++{ ++ struct i2c_client *client = to_i2c_client(dev); ++ struct as5512_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 = -1; ++ ++ dev_dbg(&client->dev, "Starting as5512_54x update\n"); ++ ++ /* Read model name */ ++ if (client->addr == 0x38 || client->addr == 0x3b) { ++ /* AC power */ ++ status = as5512_54x_psu_read_block(client, 0x26, data->model_name, ++ ARRAY_SIZE(data->model_name)-1); ++ } ++ else { ++ /* DC power */ ++ status = as5512_54x_psu_read_block(client, 0x50, 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'; ++ } ++ ++ /* 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; ++ } ++ ++ data->last_updated = jiffies; ++ data->valid = 1; ++ } ++ ++ mutex_unlock(&data->update_lock); ++ ++ return data; ++} ++ ++static int __init as5512_54x_psu_init(void) ++{ ++ extern int platform_accton_as5512_54x(void); ++ if(!platform_accton_as5512_54x()) { ++ return -ENODEV; ++ } ++ ++ return i2c_add_driver(&as5512_54x_psu_driver); ++} ++ ++static void __exit as5512_54x_psu_exit(void) ++{ ++ i2c_del_driver(&as5512_54x_psu_driver); ++} ++ ++MODULE_AUTHOR("Brandon Chuang "); ++MODULE_DESCRIPTION("accton as5512_54x_psu driver"); ++MODULE_LICENSE("GPL"); ++ ++module_init(as5512_54x_psu_init); ++module_exit(as5512_54x_psu_exit); ++ +diff --git a/drivers/hwmon/accton_i2c_cpld.c b/drivers/hwmon/accton_i2c_cpld.c +index acf88c9..e50c599 100644 +--- a/drivers/hwmon/accton_i2c_cpld.c ++++ b/drivers/hwmon/accton_i2c_cpld.c +@@ -255,6 +255,22 @@ int platform_accton_as5812_54t(void) + } + EXPORT_SYMBOL(platform_accton_as5812_54t); + ++static struct dmi_system_id as5512_54x_dmi_table[] = { ++ { ++ .ident = "Accton AS5512", ++ .matches = { ++ DMI_MATCH(DMI_SYS_VENDOR, "Accton"), ++ DMI_MATCH(DMI_PRODUCT_NAME, "AS5512"), ++ }, ++ } ++}; ++ ++int platform_accton_as5512_54x(void) ++{ ++ return dmi_check_system(as5512_54x_dmi_table); ++} ++EXPORT_SYMBOL(platform_accton_as5512_54x); ++ + MODULE_AUTHOR("Brandon Chuang "); + MODULE_DESCRIPTION("accton_i2c_cpld driver"); + MODULE_LICENSE("GPL"); +diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig +index 599b97b..9ba4a1b 100644 +--- a/drivers/leds/Kconfig ++++ b/drivers/leds/Kconfig +@@ -88,7 +88,14 @@ config LEDS_ACCTON_AS5812_54t + help + This option enables support for the LEDs on the Accton as5812 54t. + Say Y to enable LEDs on the Accton as5812 54t. +- ++ ++config LEDS_ACCTON_AS5512_54X ++ tristate "LED support for the Accton as5512 54x" ++ depends on LEDS_CLASS && SENSORS_ACCTON_I2C_CPLD ++ help ++ This option enables support for the LEDs on the Accton as5512 54x. ++ Say Y to enable LEDs on the Accton as5512 54x. ++ + config LEDS_LM3530 + tristate "LCD Backlight driver for LM3530" + depends on LEDS_CLASS +diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile +index bd20baa..ff3be6c 100644 +--- a/drivers/leds/Makefile ++++ b/drivers/leds/Makefile +@@ -50,6 +50,7 @@ obj-$(CONFIG_LEDS_ACCTON_AS7712_32x) += leds-accton_as7712_32x.o + obj-$(CONFIG_LEDS_ACCTON_AS5812_54x) += leds-accton_as5812_54x.o + obj-$(CONFIG_LEDS_ACCTON_AS6812_32x) += leds-accton_as6812_32x.o + obj-$(CONFIG_LEDS_ACCTON_AS5812_54t) += leds-accton_as5812_54t.o ++obj-$(CONFIG_LEDS_ACCTON_AS5512_54X) += leds-accton_as5512_54x.o + + # LED SPI Drivers + obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o +diff --git a/drivers/leds/leds-accton_as5512_54x.c b/drivers/leds/leds-accton_as5512_54x.c +new file mode 100644 +index 0000000..761483a +--- /dev/null ++++ b/drivers/leds/leds-accton_as5512_54x.c +@@ -0,0 +1,463 @@ ++/* ++ * A LED driver for the accton_as5512_54x_led ++ * ++ * Copyright (C) 2015 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. ++ */ ++ ++/*#define DEBUG*/ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++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); ++ ++extern void led_classdev_unregister(struct led_classdev *led_cdev); ++extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); ++extern void led_classdev_resume(struct led_classdev *led_cdev); ++extern void led_classdev_suspend(struct led_classdev *led_cdev); ++ ++#define DRVNAME "as5512_54x_led" ++ ++struct accton_as5512_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 = LOC/DIAG/FAN LED ++ 1 = PSU1/PSU2 LED */ ++}; ++ ++static struct accton_as5512_54x_led_data *ledctl = NULL; ++ ++/* LED related data ++ */ ++#define LED_TYPE_PSU1_REG_MASK 0x03 ++#define LED_MODE_PSU1_GREEN_MASK 0x02 ++#define LED_MODE_PSU1_AMBER_MASK 0x01 ++#define LED_MODE_PSU1_OFF_MASK 0x03 ++#define LED_MODE_PSU1_AUTO_MASK 0x00 ++ ++#define LED_TYPE_PSU2_REG_MASK 0x0C ++#define LED_MODE_PSU2_GREEN_MASK 0x08 ++#define LED_MODE_PSU2_AMBER_MASK 0x04 ++#define LED_MODE_PSU2_OFF_MASK 0x0C ++#define LED_MODE_PSU2_AUTO_MASK 0x00 ++ ++#define LED_TYPE_DIAG_REG_MASK 0x0C ++#define LED_MODE_DIAG_GREEN_MASK 0x08 ++#define LED_MODE_DIAG_AMBER_MASK 0x04 ++#define LED_MODE_DIAG_OFF_MASK 0x0C ++ ++#define LED_TYPE_FAN_REG_MASK 0x03 ++#define LED_MODE_FAN_GREEN_MASK 0x02 ++#define LED_MODE_FAN_AMBER_MASK 0x01 ++#define LED_MODE_FAN_OFF_MASK 0x03 ++#define LED_MODE_FAN_AUTO_MASK 0x00 ++ ++#define LED_TYPE_LOC_REG_MASK 0x30 ++#define LED_MODE_LOC_ON_MASK 0x00 ++#define LED_MODE_LOC_OFF_MASK 0x10 ++#define LED_MODE_LOC_BLINK_MASK 0x20 ++ ++static const u8 led_reg[] = { ++ 0xA, /* LOC/DIAG/FAN LED*/ ++ 0xB, /* PSU1/PSU2 LED */ ++}; ++ ++enum led_type { ++ LED_TYPE_PSU1, ++ LED_TYPE_PSU2, ++ LED_TYPE_DIAG, ++ LED_TYPE_FAN, ++ LED_TYPE_LOC ++}; ++ ++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; ++ int type_mask; ++ enum led_light_mode mode; ++ int mode_mask; ++}; ++ ++static struct led_type_mode led_type_mode_data[] = { ++{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_GREEN, LED_MODE_PSU1_GREEN_MASK}, ++{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_AMBER, LED_MODE_PSU1_AMBER_MASK}, ++{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_AUTO, LED_MODE_PSU1_AUTO_MASK}, ++{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_OFF, LED_MODE_PSU1_OFF_MASK}, ++{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_GREEN, LED_MODE_PSU2_GREEN_MASK}, ++{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_AMBER, LED_MODE_PSU2_AMBER_MASK}, ++{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_AUTO, LED_MODE_PSU2_AUTO_MASK}, ++{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_OFF, LED_MODE_PSU2_OFF_MASK}, ++{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_GREEN, LED_MODE_FAN_GREEN_MASK}, ++{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_AMBER, LED_MODE_FAN_AMBER_MASK}, ++{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_AUTO, LED_MODE_FAN_AUTO_MASK}, ++{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_OFF, LED_MODE_FAN_OFF_MASK}, ++{LED_TYPE_DIAG, LED_TYPE_DIAG_REG_MASK, LED_MODE_GREEN, LED_MODE_DIAG_GREEN_MASK}, ++{LED_TYPE_DIAG, LED_TYPE_DIAG_REG_MASK, LED_MODE_AMBER, LED_MODE_DIAG_AMBER_MASK}, ++{LED_TYPE_DIAG, LED_TYPE_DIAG_REG_MASK, LED_MODE_OFF, LED_MODE_DIAG_OFF_MASK}, ++{LED_TYPE_LOC, LED_TYPE_LOC_REG_MASK, LED_MODE_AMBER, LED_MODE_LOC_ON_MASK}, ++{LED_TYPE_LOC, LED_TYPE_LOC_REG_MASK, LED_MODE_OFF, LED_MODE_LOC_OFF_MASK}, ++{LED_TYPE_LOC, LED_TYPE_LOC_REG_MASK, LED_MODE_AMBER_BLINK, LED_MODE_LOC_BLINK_MASK} ++}; ++ ++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_mask) ++ { ++ return led_type_mode_data[i].mode; ++ } ++ } ++ ++ return 0; ++} ++ ++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++) { ++ if (type != led_type_mode_data[i].type) ++ continue; ++ ++ if (mode != led_type_mode_data[i].mode) ++ continue; ++ ++ reg_val = led_type_mode_data[i].mode_mask | ++ (reg_val & (~led_type_mode_data[i].type_mask)); ++ } ++ ++ return reg_val; ++} ++ ++static int accton_as5512_54x_led_read_value(u8 reg) ++{ ++ return accton_i2c_cpld_read(0x60, reg); ++} ++ ++static int accton_as5512_54x_led_write_value(u8 reg, u8 value) ++{ ++ return accton_i2c_cpld_write(0x60, reg, value); ++} ++ ++static void accton_as5512_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_as5512_54x_led update\n"); ++ ++ /* Update LED data ++ */ ++ for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { ++ int status = accton_as5512_54x_led_read_value(led_reg[i]); ++ ++ if (status < 0) { ++ ledctl->valid = 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_as5512_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_as5512_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_as5512_54x_led_write_value(reg, reg_val); ++ ++ /* to prevent the slow-update issue */ ++ ledctl->valid = 0; ++ ++exit: ++ mutex_unlock(&ledctl->update_lock); ++} ++ ++static void accton_as5512_54x_led_psu_1_set(struct led_classdev *led_cdev, ++ enum led_brightness led_light_mode) ++{ ++ accton_as5512_54x_led_set(led_cdev, led_light_mode, led_reg[1], LED_TYPE_PSU1); ++} ++ ++static enum led_brightness accton_as5512_54x_led_psu_1_get(struct led_classdev *cdev) ++{ ++ accton_as5512_54x_led_update(); ++ return led_reg_val_to_light_mode(LED_TYPE_PSU1, ledctl->reg_val[1]); ++} ++ ++static void accton_as5512_54x_led_psu_2_set(struct led_classdev *led_cdev, ++ enum led_brightness led_light_mode) ++{ ++ accton_as5512_54x_led_set(led_cdev, led_light_mode, led_reg[1], LED_TYPE_PSU2); ++} ++ ++static enum led_brightness accton_as5512_54x_led_psu_2_get(struct led_classdev *cdev) ++{ ++ accton_as5512_54x_led_update(); ++ return led_reg_val_to_light_mode(LED_TYPE_PSU2, ledctl->reg_val[1]); ++} ++ ++static void accton_as5512_54x_led_fan_set(struct led_classdev *led_cdev, ++ enum led_brightness led_light_mode) ++{ ++ accton_as5512_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_FAN); ++} ++ ++static enum led_brightness accton_as5512_54x_led_fan_get(struct led_classdev *cdev) ++{ ++ accton_as5512_54x_led_update(); ++ return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[0]); ++} ++ ++static void accton_as5512_54x_led_diag_set(struct led_classdev *led_cdev, ++ enum led_brightness led_light_mode) ++{ ++ accton_as5512_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG); ++} ++ ++static enum led_brightness accton_as5512_54x_led_diag_get(struct led_classdev *cdev) ++{ ++ accton_as5512_54x_led_update(); ++ return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); ++} ++ ++static void accton_as5512_54x_led_loc_set(struct led_classdev *led_cdev, ++ enum led_brightness led_light_mode) ++{ ++ accton_as5512_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC); ++} ++ ++static enum led_brightness accton_as5512_54x_led_loc_get(struct led_classdev *cdev) ++{ ++ accton_as5512_54x_led_update(); ++ return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); ++} ++ ++static struct led_classdev accton_as5512_54x_leds[] = { ++ [LED_TYPE_PSU1] = { ++ .name = "accton_as5512_54x_led::psu1", ++ .default_trigger = "unused", ++ .brightness_set = accton_as5512_54x_led_psu_1_set, ++ .brightness_get = accton_as5512_54x_led_psu_1_get, ++ .flags = LED_CORE_SUSPENDRESUME, ++ .max_brightness = LED_MODE_AUTO, ++ }, ++ [LED_TYPE_PSU2] = { ++ .name = "accton_as5512_54x_led::psu2", ++ .default_trigger = "unused", ++ .brightness_set = accton_as5512_54x_led_psu_2_set, ++ .brightness_get = accton_as5512_54x_led_psu_2_get, ++ .flags = LED_CORE_SUSPENDRESUME, ++ .max_brightness = LED_MODE_AUTO, ++ }, ++ [LED_TYPE_FAN] = { ++ .name = "accton_as5512_54x_led::fan", ++ .default_trigger = "unused", ++ .brightness_set = accton_as5512_54x_led_fan_set, ++ .brightness_get = accton_as5512_54x_led_fan_get, ++ .flags = LED_CORE_SUSPENDRESUME, ++ .max_brightness = LED_MODE_AUTO, ++ }, ++ [LED_TYPE_DIAG] = { ++ .name = "accton_as5512_54x_led::diag", ++ .default_trigger = "unused", ++ .brightness_set = accton_as5512_54x_led_diag_set, ++ .brightness_get = accton_as5512_54x_led_diag_get, ++ .flags = LED_CORE_SUSPENDRESUME, ++ .max_brightness = LED_MODE_AUTO, ++ }, ++ [LED_TYPE_LOC] = { ++ .name = "accton_as5512_54x_led::loc", ++ .default_trigger = "unused", ++ .brightness_set = accton_as5512_54x_led_loc_set, ++ .brightness_get = accton_as5512_54x_led_loc_get, ++ .flags = LED_CORE_SUSPENDRESUME, ++ .max_brightness = LED_MODE_AUTO, ++ }, ++}; ++ ++static int accton_as5512_54x_led_suspend(struct platform_device *dev, ++ pm_message_t state) ++{ ++ int i = 0; ++ ++ for (i = 0; i < ARRAY_SIZE(accton_as5512_54x_leds); i++) { ++ led_classdev_suspend(&accton_as5512_54x_leds[i]); ++ } ++ ++ return 0; ++} ++ ++static int accton_as5512_54x_led_resume(struct platform_device *dev) ++{ ++ int i = 0; ++ ++ for (i = 0; i < ARRAY_SIZE(accton_as5512_54x_leds); i++) { ++ led_classdev_resume(&accton_as5512_54x_leds[i]); ++ } ++ ++ return 0; ++} ++ ++static int accton_as5512_54x_led_probe(struct platform_device *pdev) ++{ ++ int ret, i; ++ ++ for (i = 0; i < ARRAY_SIZE(accton_as5512_54x_leds); i++) { ++ ret = led_classdev_register(&pdev->dev, &accton_as5512_54x_leds[i]); ++ ++ if (ret < 0) ++ break; ++ } ++ ++ /* Check if all LEDs were successfully registered */ ++ if (i != ARRAY_SIZE(accton_as5512_54x_leds)){ ++ int j; ++ ++ /* only unregister the LEDs that were successfully registered */ ++ for (j = 0; j < i; j++) { ++ led_classdev_unregister(&accton_as5512_54x_leds[i]); ++ } ++ } ++ ++ return ret; ++} ++ ++static int accton_as5512_54x_led_remove(struct platform_device *pdev) ++{ ++ int i; ++ ++ for (i = 0; i < ARRAY_SIZE(accton_as5512_54x_leds); i++) { ++ led_classdev_unregister(&accton_as5512_54x_leds[i]); ++ } ++ ++ return 0; ++} ++ ++static struct platform_driver accton_as5512_54x_led_driver = { ++ .probe = accton_as5512_54x_led_probe, ++ .remove = accton_as5512_54x_led_remove, ++ .suspend = accton_as5512_54x_led_suspend, ++ .resume = accton_as5512_54x_led_resume, ++ .driver = { ++ .name = DRVNAME, ++ .owner = THIS_MODULE, ++ }, ++}; ++ ++static int __init accton_as5512_54x_led_init(void) ++{ ++ int ret; ++ ++ extern int platform_accton_as5512_54x(void); ++ if(!platform_accton_as5512_54x()) { ++ return -ENODEV; ++ } ++ ++ ret = platform_driver_register(&accton_as5512_54x_led_driver); ++ if (ret < 0) { ++ goto exit; ++ } ++ ++ ledctl = kzalloc(sizeof(struct accton_as5512_54x_led_data), GFP_KERNEL); ++ if (!ledctl) { ++ ret = -ENOMEM; ++ platform_driver_unregister(&accton_as5512_54x_led_driver); ++ goto exit; ++ } ++ ++ mutex_init(&ledctl->update_lock); ++ ++ ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); ++ if (IS_ERR(ledctl->pdev)) { ++ ret = PTR_ERR(ledctl->pdev); ++ platform_driver_unregister(&accton_as5512_54x_led_driver); ++ kfree(ledctl); ++ goto exit; ++ } ++ ++exit: ++ return ret; ++} ++ ++static void __exit accton_as5512_54x_led_exit(void) ++{ ++ platform_device_unregister(ledctl->pdev); ++ platform_driver_unregister(&accton_as5512_54x_led_driver); ++ kfree(ledctl); ++} ++ ++module_init(accton_as5512_54x_led_init); ++module_exit(accton_as5512_54x_led_exit); ++ ++MODULE_AUTHOR("Brandon Chuang "); ++MODULE_DESCRIPTION("accton_as5512_54x_led driver"); ++MODULE_LICENSE("GPL"); ++ +diff --git a/drivers/misc/eeprom/Kconfig b/drivers/misc/eeprom/Kconfig +index c75227b..d90ebe2 100644 +--- a/drivers/misc/eeprom/Kconfig ++++ b/drivers/misc/eeprom/Kconfig +@@ -135,7 +135,16 @@ config EEPROM_ACCTON_AS5812_54t_SFP + + This driver can also be built as a module. If so, the module will + be called accton_as5812_54t_sfp. +- ++ ++config EEPROM_ACCTON_AS5512_54X_SFP ++ tristate "Accton as5512_54x sfp" ++ depends on I2C && SENSORS_ACCTON_I2C_CPLD ++ help ++ If you say yes here you get support for Accton 5512_54x sfp. ++ ++ This driver can also be built as a module. If so, the module will ++ be called accton_5512_54x_sfp. ++ + config EEPROM_93CX6 + tristate "EEPROM 93CX6 support" + help +diff --git a/drivers/misc/eeprom/Makefile b/drivers/misc/eeprom/Makefile +index 152a8bc..907f836 100644 +--- a/drivers/misc/eeprom/Makefile ++++ b/drivers/misc/eeprom/Makefile +@@ -13,4 +13,5 @@ obj-$(CONFIG_EEPROM_ACCTON_AS7712_32x_SFP) += accton_as7712_32x_sfp.o + obj-$(CONFIG_EEPROM_ACCTON_AS5812_54x_SFP) += accton_as5812_54x_sfp.o + obj-$(CONFIG_EEPROM_ACCTON_AS6812_32x_SFP) += accton_as6812_32x_sfp.o + obj-$(CONFIG_EEPROM_ACCTON_AS5812_54t_SFP) += accton_as5812_54t_sfp.o ++obj-$(CONFIG_EEPROM_ACCTON_AS5512_54X_SFP) += accton_as5512_54x_sfp.o + obj-$(CONFIG_EEPROM_SFF_8436) += sff_8436_eeprom.o +diff --git a/drivers/misc/eeprom/accton_as5512_54x_sfp.c b/drivers/misc/eeprom/accton_as5512_54x_sfp.c +new file mode 100644 +index 0000000..d89e71d +--- /dev/null ++++ b/drivers/misc/eeprom/accton_as5512_54x_sfp.c +@@ -0,0 +1,1237 @@ ++/* ++ * SFP driver for accton as5512_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 "as5512_54x_sfp" ++ ++#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 ++#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 ++ ++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); ++ ++/* Addresses scanned ++ */ ++static const unsigned short normal_i2c[] = { SFP_EEPROM_A0_I2C_ADDR, SFP_EEPROM_A2_I2C_ADDR, I2C_CLIENT_END }; ++ ++#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) ++ ++enum port_numbers { ++sfp1, sfp2, sfp3, sfp4, sfp5, sfp6, sfp7, sfp8, ++sfp9, sfp10, sfp11, sfp12, sfp13, sfp14, sfp15, sfp16, ++sfp17, sfp18, sfp19, sfp20, sfp21, sfp22, sfp23, sfp24, ++sfp25, sfp26, sfp27, sfp28, sfp29, sfp30, sfp31, sfp32, ++sfp33, sfp34, sfp35, sfp36, sfp37, sfp38, sfp39, sfp40, ++sfp41, sfp42, sfp43, sfp44, sfp45, sfp46, sfp47, sfp48, ++sfp49, sfp50, sfp51, sfp52, sfp53, sfp54 ++}; ++ ++static const struct i2c_device_id sfp_device_id[] = { ++{ "sfp1", sfp1 }, { "sfp2", sfp2 }, { "sfp3", sfp3 }, { "sfp4", sfp4 }, ++{ "sfp5", sfp5 }, { "sfp6", sfp6 }, { "sfp7", sfp7 }, { "sfp8", sfp8 }, ++{ "sfp9", sfp9 }, { "sfp10", sfp10 }, { "sfp11", sfp11 }, { "sfp12", sfp12 }, ++{ "sfp13", sfp13 }, { "sfp14", sfp14 }, { "sfp15", sfp15 }, { "sfp16", sfp16 }, ++{ "sfp17", sfp17 }, { "sfp18", sfp18 }, { "sfp19", sfp19 }, { "sfp20", sfp20 }, ++{ "sfp21", sfp21 }, { "sfp22", sfp22 }, { "sfp23", sfp23 }, { "sfp24", sfp24 }, ++{ "sfp25", sfp25 }, { "sfp26", sfp26 }, { "sfp27", sfp27 }, { "sfp28", sfp28 }, ++{ "sfp29", sfp29 }, { "sfp30", sfp30 }, { "sfp31", sfp31 }, { "sfp32", sfp32 }, ++{ "sfp33", sfp33 }, { "sfp34", sfp34 }, { "sfp35", sfp35 }, { "sfp36", sfp36 }, ++{ "sfp37", sfp37 }, { "sfp38", sfp38 }, { "sfp39", sfp39 }, { "sfp40", sfp40 }, ++{ "sfp41", sfp41 }, { "sfp42", sfp42 }, { "sfp43", sfp43 }, { "sfp44", sfp44 }, ++{ "sfp45", sfp45 }, { "sfp46", sfp46 }, { "sfp47", sfp47 }, { "sfp48", sfp48 }, ++{ "sfp49", sfp49 }, { "sfp50", sfp50 }, { "sfp51", sfp51 }, { "sfp52", sfp52 }, ++{ "sfp53", sfp53 }, { "sfp54", sfp54 }, ++{ /* LIST END */ } ++}; ++MODULE_DEVICE_TABLE(i2c, sfp_device_id); ++ ++/* ++ * 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; ++}; ++ ++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 ++}; ++ ++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)); ++} ++ ++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 = 0x61+i; ++ reg = 0x6+j; ++ status = accton_i2c_cpld_read(cpld_addr, reg); ++ ++ if (unlikely(status < 0)) { ++ data = ERR_PTR(status); ++ 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-54(QSFP port) */ ++ cpld_addr = 0x62; ++ reg = 0x14; ++ status = accton_i2c_cpld_read(cpld_addr, reg); ++ ++ if (unlikely(status < 0)) { ++ data = ERR_PTR(status); ++ dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); ++ goto exit; ++ } ++ else { ++ data->present |= (u64)status << 48; ++ } ++ ++ DEBUG_PRINT("Present status = 0x%lx", data->present); ++exit: ++ mutex_unlock(&data->update_lock); ++ return 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; ++ ++ if (time_before(jiffies, data->msa->last_updated + HZ + HZ / 2) && data->msa->valid) { ++ return data; ++ } ++ ++ DEBUG_PRINT("Starting as5512_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 < 9; j++) { ++ u8 reg; ++ unsigned short cpld_addr; ++ reg = 0x9+j; ++ cpld_addr = 0x61+i; ++ ++ status = accton_i2c_cpld_read(cpld_addr, reg); ++ if (unlikely(status < 0)) { ++ data = ERR_PTR(status); ++ dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, 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 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; ++ ++ error = kstrtol(buf, 10, &disable); ++ if (error) { ++ return error; ++ } ++ ++ mutex_lock(&data->update_lock); ++ ++ if(data->port < 24) { ++ cpld_addr = 0x61; ++ cpld_reg = 0xC + data->port / 8; ++ cpld_bit = 1 << (data->port % 8); ++ } ++ else { /* port 24 ~ 48 */ ++ cpld_addr = 0x62; ++ cpld_reg = 0xC + (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)) ? 0 : 1; ++} ++ ++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); ++ } ++} ++ ++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)) { ++ data = ERR_PTR(status); ++ 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)) { ++ data = ERR_PTR(status); ++ 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 data; ++} ++ ++static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, ++ char *buf) ++{ ++ int status; ++ 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); ++ ++ status = sfp_is_port_present(client, data->port); ++ if (IS_ERR_VALUE(status)) { ++ return status; ++ } ++ ++ data = qsfp_update_tx_rx_status(dev); ++ if (IS_ERR(data)) { ++ return PTR_ERR(data); ++ } ++ ++ switch (attr->index) { ++ case TX_FAULT1: ++ case TX_FAULT2: ++ case TX_FAULT3: ++ case TX_FAULT4: ++ val = (data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)) ? 1 : 0; ++ break; ++ case TX_DISABLE1: ++ case TX_DISABLE2: ++ case TX_DISABLE3: ++ case TX_DISABLE4: ++ val = (data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)) ? 1 : 0; ++ break; ++ case RX_LOS1: ++ case RX_LOS2: ++ case RX_LOS3: ++ case RX_LOS4: ++ val = (data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)) ? 1 : 0; ++ 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 sfp_port_data *data = NULL; ++ ++ 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 (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; ++ } ++ ++ 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) ? 1 : 0); ++} ++ ++static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, ++ char *buf) ++{ ++ u8 val = 0, index = 0; ++ struct sensor_device_attribute *attr = to_sensor_dev_attr(da); ++ struct sfp_port_data *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: ++ break; ++ } ++ ++ val = (data->msa->status[index] & BIT_INDEX(data->port)) ? 1 : 0; ++ return sprintf(buf, "%d\n", val); ++} ++ ++/* 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); ++ ++/* 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_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_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_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, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); ++static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS_ALL); ++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); ++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 ++}; ++ ++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) ++{ ++ 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)); ++ 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, result); ++ 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) ++{ ++ struct sfp_port_data *data; ++ DEBUG_PRINT("offset = (%d), count = (%d)", off, count); ++ data = dev_get_drvdata(container_of(kobj, struct device, kobj)); ++ 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; ++ } ++ ++ /* Bring QSFPs out of reset */ ++ accton_i2c_cpld_write(0x62, 0x15, 0x3F); ++ ++ *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; ++} ++ ++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 >= sfp1 && dev_id->driver_data <= 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 { /* sfp49 ~ 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; ++} ++ ++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; ++} ++ ++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) ++{ ++ extern int platform_accton_as5512_54x(void); ++ if(!platform_accton_as5512_54x()) { ++ return -ENODEV; ++ } ++ ++ return i2c_add_driver(&sfp_driver); ++} ++ ++static void __exit sfp_exit(void) ++{ ++ i2c_del_driver(&sfp_driver); ++} ++ ++MODULE_AUTHOR("Brandon Chuang "); ++MODULE_DESCRIPTION("accton as5512_54x_sfp driver"); ++MODULE_LICENSE("GPL"); ++ ++module_init(sfp_init); ++module_exit(sfp_exit); ++ ++ diff --git a/packages/base/any/kernels/3.2.65-1+deb7u2/patches/series b/packages/base/any/kernels/3.2.65-1+deb7u2/patches/series index f958b6b7..d909661b 100644 --- a/packages/base/any/kernels/3.2.65-1+deb7u2/patches/series +++ b/packages/base/any/kernels/3.2.65-1+deb7u2/patches/series @@ -246,3 +246,4 @@ platform-accton-as6812_32x-device-drivers.patch platform-accton-as5812_54t-device-drivers.patch driver-mfd-lpc-ich.patch driver-watchdog-itco-wd.patch +platform-accton-as5512_54x-device-drivers.patch diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/.gitignore b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/.gitignore new file mode 100644 index 00000000..f32d9065 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/.gitignore @@ -0,0 +1,2 @@ +*x86*64*accton*as5512*54x*.mk +onlpdump.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-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-as5512-54x/onlp/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-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-as5512-54x/onlp/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/PKG.yml new file mode 100644 index 00000000..121096e1 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-accton-as5512-54x ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/Makefile new file mode 100644 index 00000000..e7437cb2 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-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-as5512-54x/onlp/builds/lib/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/lib/Makefile new file mode 100644 index 00000000..983ad76c --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-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-as5512-54x +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF x86_64_accton_as5512_54x onlplib +DEPENDMODULE_HEADERS := sff + +include $(BUILDER)/dependmodules.mk + +SHAREDLIB := libonlp-x86-64-accton-as5512-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-as5512-54x/onlp/builds/onlpdump/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/onlpdump/Makefile new file mode 100644 index 00000000..68f2a998 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-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_as5512_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-as5512-54x/onlp/builds/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/Makefile new file mode 100644 index 00000000..2b9cbb03 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +include ../../init.mk +MODULE := x86_64_accton_as5512_54x +AUTOMODULE := x86_64_accton_as5512_54x +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/README b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/README new file mode 100644 index 00000000..504c2aa2 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/README @@ -0,0 +1,6 @@ +############################################################################### +# +# x86_64_accton_as5512_54x README +# +############################################################################### + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/auto/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/auto/make.mk new file mode 100644 index 00000000..f2c96993 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/auto/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# x86_64_accton_as5512_54x Autogeneration +# +############################################################################### +x86_64_accton_as5512_54x_AUTO_DEFS := module/auto/x86_64_accton_as5512_54x.yml +x86_64_accton_as5512_54x_AUTO_DIRS := module/inc/x86_64_accton_as5512_54x module/src +include $(BUILDER)/auto.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/auto/x86_64_accton_as5512_54x.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/auto/x86_64_accton_as5512_54x.yml new file mode 100644 index 00000000..d11f560c --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/auto/x86_64_accton_as5512_54x.yml @@ -0,0 +1,50 @@ +############################################################################### +# +# x86_64_accton_as5512_54x Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- x86_64_accton_as5512_54x_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- x86_64_accton_as5512_54x_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- x86_64_accton_as5512_54x_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- x86_64_accton_as5512_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- x86_64_accton_as5512_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB +- x86_64_accton_as5512_54x_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 +- x86_64_accton_as5512_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_as5512_54x_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_accton_as5512_54x_config + + portingmacro: + x86_64_accton_as5512_54x: + macros: + - malloc + - free + - memset + - memcpy + - strncpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x.x b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x.x new file mode 100644 index 00000000..608b597e --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_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-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_config.h b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_config.h new file mode 100644 index 00000000..84435002 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_config.h @@ -0,0 +1,137 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5512_54x Configuration Header + * + * @addtogroup x86_64_accton_as5512_54x-config + * @{ + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5512_54x_CONFIG_H__ +#define __x86_64_accton_as5512_54x_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef x86_64_accton_as5512_54x_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * x86_64_accton_as5512_54x_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef x86_64_accton_as5512_54x_CONFIG_INCLUDE_LOGGING +#define x86_64_accton_as5512_54x_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * x86_64_accton_as5512_54x_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef x86_64_accton_as5512_54x_CONFIG_LOG_OPTIONS_DEFAULT +#define x86_64_accton_as5512_54x_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * x86_64_accton_as5512_54x_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef x86_64_accton_as5512_54x_CONFIG_LOG_BITS_DEFAULT +#define x86_64_accton_as5512_54x_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * x86_64_accton_as5512_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef x86_64_accton_as5512_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define x86_64_accton_as5512_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB +#define x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * x86_64_accton_as5512_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef x86_64_accton_as5512_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define x86_64_accton_as5512_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB +#endif + +/** + * x86_64_accton_as5512_54x_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef x86_64_accton_as5512_54x_CONFIG_INCLUDE_UCLI +#define x86_64_accton_as5512_54x_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * x86_64_accton_as5512_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * + * Assume chassis fan direction is the same as the PSU fan direction. */ + + +#ifndef x86_64_accton_as5512_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define x86_64_accton_as5512_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_as5512_54x_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_accton_as5512_54x_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_accton_as5512_54x_config_settings table. */ +extern x86_64_accton_as5512_54x_config_settings_t x86_64_accton_as5512_54x_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_accton_as5512_54x_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_accton_as5512_54x_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_accton_as5512_54x_porting.h" + +#endif /* __x86_64_accton_as5512_54x_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_dox.h b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_dox.h new file mode 100644 index 00000000..f3edba45 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_accton_as5512_54x Doxygen Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5512_54x_DOX_H__ +#define __x86_64_accton_as5512_54x_DOX_H__ + +/** + * @defgroup x86_64_accton_as5512_54x x86_64_accton_as5512_54x - x86_64_accton_as5512_54x Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_accton_as5512_54x-x86_64_accton_as5512_54x Public Interface + * @defgroup x86_64_accton_as5512_54x-config Compile Time Configuration + * @defgroup x86_64_accton_as5512_54x-porting Porting Macros + * + * @} + * + */ + +#endif /* __x86_64_accton_as5512_54x_DOX_H__ */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_porting.h b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_porting.h new file mode 100644 index 00000000..ab37ffd8 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/inc/x86_64_accton_as5512_54x/x86_64_accton_as5512_54x_porting.h @@ -0,0 +1,107 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5512_54x Porting Macros. + * + * @addtogroup x86_64_accton_as5512_54x-porting + * @{ + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5512_54x_PORTING_H__ +#define __x86_64_accton_as5512_54x_PORTING_H__ + + +/* */ +#if x86_64_accton_as5512_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef x86_64_accton_as5512_54x_MALLOC + #if defined(GLOBAL_MALLOC) + #define x86_64_accton_as5512_54x_MALLOC GLOBAL_MALLOC + #elif x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5512_54x_MALLOC malloc + #else + #error The macro x86_64_accton_as5512_54x_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5512_54x_FREE + #if defined(GLOBAL_FREE) + #define x86_64_accton_as5512_54x_FREE GLOBAL_FREE + #elif x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5512_54x_FREE free + #else + #error The macro x86_64_accton_as5512_54x_FREE is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5512_54x_MEMSET + #if defined(GLOBAL_MEMSET) + #define x86_64_accton_as5512_54x_MEMSET GLOBAL_MEMSET + #elif x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5512_54x_MEMSET memset + #else + #error The macro x86_64_accton_as5512_54x_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5512_54x_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define x86_64_accton_as5512_54x_MEMCPY GLOBAL_MEMCPY + #elif x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5512_54x_MEMCPY memcpy + #else + #error The macro x86_64_accton_as5512_54x_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5512_54x_STRNCPY + #if defined(GLOBAL_STRNCPY) + #define x86_64_accton_as5512_54x_STRNCPY GLOBAL_STRNCPY + #elif x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5512_54x_STRNCPY strncpy + #else + #error The macro x86_64_accton_as5512_54x_STRNCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5512_54x_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define x86_64_accton_as5512_54x_VSNPRINTF GLOBAL_VSNPRINTF + #elif x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5512_54x_VSNPRINTF vsnprintf + #else + #error The macro x86_64_accton_as5512_54x_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5512_54x_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define x86_64_accton_as5512_54x_SNPRINTF GLOBAL_SNPRINTF + #elif x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5512_54x_SNPRINTF snprintf + #else + #error The macro x86_64_accton_as5512_54x_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5512_54x_STRLEN + #if defined(GLOBAL_STRLEN) + #define x86_64_accton_as5512_54x_STRLEN GLOBAL_STRLEN + #elif x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5512_54x_STRLEN strlen + #else + #error The macro x86_64_accton_as5512_54x_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __x86_64_accton_as5512_54x_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/make.mk new file mode 100644 index 00000000..44223a1f --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/make.mk @@ -0,0 +1,10 @@ +############################################################################### +# +# +# +############################################################################### +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_accton_as5512_54x_INCLUDES := -I $(THIS_DIR)inc +x86_64_accton_as5512_54x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_accton_as5512_54x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5512_54x ucli:x86_64_accton_as5512_54x + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/Makefile new file mode 100644 index 00000000..e087254c --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# Local source generation targets. +# +############################################################################### + +ucli: + @../../../../tools/uclihandlers.py x86_64_accton_as5512_54x_ucli.c + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/debug.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/debug.c new file mode 100644 index 00000000..4d02c832 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/debug.c @@ -0,0 +1,45 @@ +#include "x86_64_accton_as5512_54x_int.h" + +#if X86_64_ACCTON_AS5512_54X_CONFIG_INCLUDE_DEBUG == 1 + +#include + +static char help__[] = + "Usage: debug [options]\n" + " -c CPLD Versions\n" + " -h Help\n" + ; + +int +x86_64_accton_as5512_54x_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-as5512-54x/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/fani.c new file mode 100644 index 00000000..c8004c0c --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/fani.c @@ -0,0 +1,420 @@ +/************************************************************ + * + * + * 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. + * + * + ************************************************************ + * + * Fan Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include +#include +#include "platform_lib.h" + +#define PREFIX_PATH_ON_MAIN_BOARD "/sys/devices/platform/as5512_54x_fan/" +#define PREFIX_PATH_ON_PSU "/sys/bus/i2c/devices/" +#define LOCAL_DEBUG 0 + + +#define FAN_RESERVED 0 +#define FAN_1_ON_MAIN_BOARD 1 +#define FAN_2_ON_MAIN_BOARD 2 +#define FAN_3_ON_MAIN_BOARD 3 +#define FAN_4_ON_MAIN_BOARD 4 +#define FAN_5_ON_MAIN_BOARD 5 +#define FAN_1_ON_PSU1 6 +#define FAN_1_ON_PSU2 7 + +#define PROJECT_NAME + +#define LEN_FILE_NAME 50 + +typedef struct last_path_S +{ + char status[LEN_FILE_NAME]; + char speed[LEN_FILE_NAME]; + char direction[LEN_FILE_NAME]; + char ctrl_speed[LEN_FILE_NAME]; + char r_status[LEN_FILE_NAME]; + char r_speed[LEN_FILE_NAME]; +}last_path_T; + +#define _MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(prj,id) \ + { #prj"fan"#id"_fault", #prj"fan"#id"_speed_rpm", #prj"fan"#id"_direction",\ + #prj"fan_duty_cycle_percentage", #prj"fanr"#id"_fault", #prj"fanr"#id"_speed_rpm" } + +#define MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(prj,id) _MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(prj,id) + + +#define MAKE_FAN_LAST_PATH_ON_PSU(folder) \ + {#folder"/psu_fan1_fault", #folder"/psu_fan1_speed_rpm", "",\ + #folder"/psu_fan1_duty_cycle_percentage", "", "" } + +static last_path_T last_path[] = /* must map with onlp_fan_id */ +{ + MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_RESERVED), + MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_1_ON_MAIN_BOARD), + MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_2_ON_MAIN_BOARD), + MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_3_ON_MAIN_BOARD), + MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_4_ON_MAIN_BOARD), + MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_5_ON_MAIN_BOARD), + + MAKE_FAN_LAST_PATH_ON_PSU(59-003c), + MAKE_FAN_LAST_PATH_ON_PSU(60-003f), +}; + +#define MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(id) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##id##_ON_MAIN_BOARD), "Chassis Fan "#id, 0 }, \ + 0x0, \ + ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, \ + 0, \ + 0, \ + ONLP_FAN_MODE_INVALID, \ + } + +#define MAKE_FAN_INFO_NODE_ON_PSU(psu_id, fan_id) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##fan_id##_ON_PSU##psu_id), "Chassis PSU-"#psu_id " Fan "#fan_id, 0 }, \ + 0x0, \ + 0, \ + 0, \ + 0, \ + ONLP_FAN_MODE_INVALID, \ + } + + +/* Static fan information */ +onlp_fan_info_t linfo[] = { + { }, /* Not used */ + MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(1), + MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(2), + MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(3), + MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(4), + MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(5), + MAKE_FAN_INFO_NODE_ON_PSU(1,1), + MAKE_FAN_INFO_NODE_ON_PSU(2,1), +}; + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_FAN(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +#define OPEN_READ_FILE(fd,fullpath,data,nbytes,len) \ + if (LOCAL_DEBUG) \ + printf("[Debug][%s][%d][openfile: %s]\n", __FUNCTION__, __LINE__, fullpath); \ + if ((fd = open(fullpath, O_RDONLY)) == -1) \ + return ONLP_STATUS_E_INTERNAL; \ + if ((len = read(fd, r_data, nbytes)) <= 0){ \ + close(fd); \ + return ONLP_STATUS_E_INTERNAL;} \ + if (LOCAL_DEBUG) \ + printf("[Debug][%s][%d][read data: %s]\n", __FUNCTION__, __LINE__, r_data); \ + if (close(fd) == -1) \ + return ONLP_STATUS_E_INTERNAL + + +/* PSU relative marco */ +#define SET_PSU_TYPE_CPR_4011_F2B_FAN(info) \ + info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B); \ + info->caps |= ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE + +#define SET_PSU_TYPE_CPR_4011_B2F_FAN(info) \ + info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F); \ + info->caps |= ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE + +#define SET_PSU_TYPE_UM400D_F2B_FAN(info) \ + info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B) + +#define SET_PSU_TYPE_UM400D_B2F_FAN(info) \ + info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F) + + +static int +_onlp_fani_info_get_fan(int local_id, onlp_fan_info_t* info) +{ + int fd, len, nbytes = 10; + char r_data[10] = {0}; + char fullpath[65] = {0}; + + /* get fan/fanr fault status (turn on when any one fails) + */ + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].status); + OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); + if (atoi(r_data) > 0) + info->status |= ONLP_FAN_STATUS_FAILED; + + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_status); + OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); + if (atoi(r_data) > 0) + info->status |= ONLP_FAN_STATUS_FAILED; + + /* get fan/fanr direction (both : the same) + */ + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].direction); + OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); + + if (atoi(r_data) == 0) /*F2B*/ + info->status |= ONLP_FAN_STATUS_F2B; + else + info->status |= ONLP_FAN_STATUS_B2F; + + /* get fan/fanr speed (take the average of two speeds) + */ + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].speed); + OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); + info->rpm = atoi(r_data); + + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_speed); + OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); + info->rpm = (info->rpm + atoi(r_data))/2; + + /* get speed percentage from rpm */ + info->percentage = (info->rpm * 100)/16800; + + /* check present */ + if (info->rpm > 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + + return ONLP_STATUS_OK; +} + +static int +_onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) +{ + int psu_id, is_ac=0; + int fd, len, nbytes = 10; + char r_data[10] = {0}; + char fullpath[50] = {0}; + psu_type_t psu_type; + + /* get fan other cap status according to psu type + */ + psu_id = (local_id-FAN_1_ON_PSU1) + 1; + + if (LOCAL_DEBUG) + printf("[Debug][%s][%d][psu_id: %d]\n", __FUNCTION__, __LINE__, psu_id); + + psu_type = get_psu_type(psu_id, NULL, 0); /* psu_id = 1 , present PSU1. pus_id =2 , present PSU2 */ + + if (LOCAL_DEBUG) + printf("[Debug][%s][%d][psu_type: %d]\n", __FUNCTION__, __LINE__, psu_type); + + + switch (psu_type) { + case PSU_TYPE_AC_F2B: + SET_PSU_TYPE_CPR_4011_F2B_FAN(info); + is_ac = 1; + break; + case PSU_TYPE_AC_B2F: + SET_PSU_TYPE_CPR_4011_B2F_FAN(info); + is_ac = 1; + break; + case PSU_TYPE_DC_48V_F2B: + SET_PSU_TYPE_UM400D_F2B_FAN(info); + break; + case PSU_TYPE_DC_48V_B2F: + SET_PSU_TYPE_UM400D_B2F_FAN(info); + break; + default: + if (LOCAL_DEBUG) + printf("[Debug][%s][%d][psu_type=%d]\n", __FUNCTION__, __LINE__, psu_type); + + break; + } + + if (1 == is_ac) + { + /* get fan fault status + */ + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].status); + OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); + if (atoi(r_data) > 0) + info->status |= ONLP_FAN_STATUS_FAILED; + + /* get fan speed + */ + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].speed); + OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); + info->rpm = atoi(r_data); + + /* get speed percentage from rpm */ + info->percentage = (info->rpm * 100)/19328; + + } + + 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 local_id; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + *info = linfo[local_id]; + + if (LOCAL_DEBUG) + printf("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id); + + switch (local_id) + { + case FAN_1_ON_PSU1: + case FAN_1_ON_PSU2: + rc = _onlp_fani_info_get_fan_on_psu(local_id, info); + break; + + default: + rc =_onlp_fani_info_get_fan(local_id, info); + 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 fd, len, nbytes=10, local_id; + char data[10] = {0}; + char fullpath[70] = {0}; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + /* reject p=0 (p=0, stop fan) */ + if (p == 0){ + return ONLP_STATUS_E_INVALID; + } + + /* get fullpath */ + switch (local_id) + { + case FAN_1_ON_PSU1: + case FAN_1_ON_PSU2: + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].ctrl_speed); + break; + default: + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].ctrl_speed); + break; + } + + sprintf(data, "%d", p); + + if (LOCAL_DEBUG) + printf("[Debug][%s][%d][openfile: %s][data=%s]\n", __FUNCTION__, __LINE__, fullpath, data); + + /* Create output file descriptor */ + fd = open(fullpath, O_WRONLY, 0644); + if(fd == -1){ + return ONLP_STATUS_E_INTERNAL; + } + + len = write (fd, data, (ssize_t) nbytes); + if(len != nbytes){ + close(fd); + return ONLP_STATUS_E_INTERNAL; + } + + close(fd); + 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-as5512-54x/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/ledi.c new file mode 100644 index 00000000..79399200 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/ledi.c @@ -0,0 +1,313 @@ +/************************************************************ + * + * + * 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 + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_LED(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +/* 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 +}; + +int led_light_map_mode[][2] = +{ + {LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, + {LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_MODE_AMBER_BLINK, ONLP_LED_MODE_ORANGE_BLINKING}, + {LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, +}; + + +#define prefix_path "/sys/class/leds/accton_as5512_54x_led::" +#define filename "brightness" + +enum onlp_led_id +{ + LED_RESERVED = 0, + LED_DIAG, + LED_FAN, + LED_LOC, + LED_PSU1, + LED_PSU2, + LED_FAN1, + LED_FAN2, + LED_FAN3, + LED_FAN4, + LED_FAN5, +}; + +static char last_path[][10] = /* must map with onlp_led_id */ +{ + "reserved", + "diag", + "fan", + "loc", + "psu1", + "psu2", + "fan1", + "fan2", + "fan3", + "fan4", + "fan5", +}; + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t linfo[] = +{ + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_DIAG), "Chassis LED 1 (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_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, + }, + { + { ONLP_LED_ID_CREATE(LED_LOC), "Chassis LED 3 (LOC LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU1), "Chassis LED 4 (PSU1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU2), "Chassis LED 5 (PSU2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN1), "Chassis LED 6 (FAN1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, 0, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN2), "Chassis LED 7 (FAN2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, 0, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN3), "Chassis LED 8 (FAN3 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, 0, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN4), "Chassis LED 9 (FAN4 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, 0, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN5), "Chassis LED 10 (FAN5 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, 0, + }, +}; + + +static int conver_led_light_mode_to_onl(int led_ligth_mode) +{ + int i, nsize = sizeof(led_light_map_mode)/sizeof(led_light_map_mode[0]); + for (i = 0; i < nsize; i++) { + if (led_ligth_mode == led_light_map_mode[i][0]) { + return led_light_map_mode[i][1]; + } + } + return 0; +} + + +static int conver_led_light_mode_to_driver(int led_ligth_mode) +{ + int i, nsize = sizeof(led_light_map_mode)/sizeof(led_light_map_mode[0]); + for (i = 0; i < nsize; i++) { + if (led_ligth_mode == led_light_map_mode[i][1]) { + return led_light_map_mode[i][0]; + } + } + 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 fd, len, nbytes=1, local_id; + char data[2] = {0}; + char fullpath[50] = {0}; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + /* get fullpath */ + if (strchr(last_path[local_id], '/') != NULL) { + sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]); + } + else { + sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename); + } + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[ONLP_OID_ID_GET(id)]; + + /* Set current mode */ + if ((fd = open(fullpath, O_RDONLY)) == -1) { + return ONLP_STATUS_E_INTERNAL; + } + + if ((len = read(fd, data, nbytes)) <= 0) { + close(fd); + return ONLP_STATUS_E_INTERNAL; + } + + /* If the read byte count is less, the format is different and calc will be wrong*/ + if (close(fd) == -1) { + return ONLP_STATUS_E_INTERNAL; + } + + info->mode = conver_led_light_mode_to_onl(atoi(data)); + + /* Set the on/off status */ + if (info->mode != ONLP_LED_MODE_OFF) { + info->status |= ONLP_LED_STATUS_ON; + } + + return ONLP_STATUS_OK; +} + +/* + * Turn an LED on or off. + * + * This function will only be called if the LED OID supports the ONOFF + * capability. + * + * What 'on' means in terms of colors or modes for multimode LEDs is + * up to the platform to decide. This is intended as baseline toggle mechanism. + */ +int +onlp_ledi_set(onlp_oid_t id, int on_or_off) +{ + VALIDATE(id); + + if (!on_or_off) { + 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 fd, len, driver_mode, nbytes=1, local_id; + char data[2] = {0}; + char fullpath[50] = {0}; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + /* get fullpath */ + if (strchr(last_path[local_id], '/') != NULL) { + sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]); + } + else { + sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename); + } + + driver_mode = conver_led_light_mode_to_driver(mode); + sprintf(data, "%d", driver_mode); + + /* Create output file descriptor */ + fd = open(fullpath, O_WRONLY, 0644); + if(fd == -1){ + return ONLP_STATUS_E_INTERNAL; + } + + len = write (fd, data, (ssize_t) nbytes); + if(len != nbytes){ + close(fd); + return ONLP_STATUS_E_INTERNAL; + } + + close(fd); + 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-as5512-54x/onlp/builds/src/module/src/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/make.mk new file mode 100644 index 00000000..00ab17bd --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### + +LIBRARY := x86_64_accton_as5512_54x +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/platform_lib.c new file mode 100644 index 00000000..74b785f1 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/platform_lib.c @@ -0,0 +1,169 @@ +/************************************************************ + * + * + * 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 "platform_lib.h" + +int deviceNodeWrite(char *filename, char *buffer, int buf_size, int data_len) +{ + int fd; + int len; + + if ((buffer == NULL) || (buf_size < 0)) { + return -1; + } + + if ((fd = open(filename, O_WRONLY, S_IWUSR)) == -1) { + return -1; + } + + if ((len = write(fd, buffer, buf_size)) < 0) { + close(fd); + return -1; + } + + if ((close(fd) == -1)) { + return -1; + } + + if ((len > buf_size) || (data_len != 0 && len != data_len)) { + return -1; + } + + return 0; +} + +int deviceNodeWriteInt(char *filename, int value, int data_len) +{ + char buf[8] = {0}; + sprintf(buf, "%d", value); + + return deviceNodeWrite(filename, buf, sizeof(buf)-1, data_len); +} + +int deviceNodeReadBinary(char *filename, char *buffer, int buf_size, int data_len) + { + int fd; + int len; + + if ((buffer == NULL) || (buf_size < 0)) { + return -1; + } + + if ((fd = open(filename, O_RDONLY)) == -1) { + return -1; + } + + if ((len = read(fd, buffer, buf_size)) < 0) { + close(fd); + return -1; + } + + if ((close(fd) == -1)) { + return -1; + } + + if ((len > buf_size) || (data_len != 0 && len != data_len)) { + return -1; + } + + return 0; +} + +int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_len) +{ + int ret; + + if (data_len >= buf_size || data_len < 0) { + return -1; + } + + ret = deviceNodeReadBinary(filename, buffer, buf_size-1, data_len); + + if (ret == 0) { + if (data_len) { + buffer[data_len] = '\0'; + } + else { + buffer[buf_size-1] = '\0'; + } + } + + return ret; +} + +#define I2C_PSU_MODEL_NAME_LEN 13 + +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}; + + /* Check AC model name */ + node = (id == PSU1_ID) ? PSU1_AC_HWMON_NODE(psu_model_name) : PSU2_AC_HWMON_NODE(psu_model_name); + + if (deviceNodeReadString(node, model_name, sizeof(model_name), 0) == 0) { + if (strncmp(model_name, "CPR-4011-4M11", strlen("CPR-4011-4M11")) == 0) { + if (modelname) { + strncpy(modelname, model_name, modelname_len-1); + } + return PSU_TYPE_AC_F2B; + } + else if (strncmp(model_name, "CPR-4011-4M21", strlen("CPR-4011-4M21")) == 0) { + if (modelname) { + strncpy(modelname, model_name, modelname_len-1); + } + return PSU_TYPE_AC_B2F; + } + } + + /* Check DC model name */ + memset(model_name, 0, sizeof(model_name)); + node = (id == PSU1_ID) ? PSU1_DC_HWMON_NODE(psu_model_name) : PSU2_DC_HWMON_NODE(psu_model_name); + + if (deviceNodeReadString(node, model_name, sizeof(model_name), 0) == 0) { + if (strncmp(model_name, "um400d01G", strlen("um400d01G")) == 0) { + if (modelname) { + strncpy(modelname, model_name, modelname_len-1); + } + return PSU_TYPE_DC_48V_B2F; + } + else if (strncmp(model_name, "um400d01-01G", strlen("um400d01-01G")) == 0) { + if (modelname) { + strncpy(modelname, model_name, modelname_len-1); + } + return PSU_TYPE_DC_48V_F2B; + } + } + + return PSU_TYPE_UNKNOWN; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/platform_lib.h new file mode 100644 index 00000000..8367e2cd --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/platform_lib.h @@ -0,0 +1,66 @@ +/************************************************************ + * + * + * 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 "x86_64_accton_as5512_54x_log.h" + +#define PSU1_ID 1 +#define PSU2_ID 2 + +#define CHASSIS_FAN_COUNT 5 +#define CHASSIS_THERMAL_COUNT 4 + +#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/59-003c/" +#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/60-003f/" + +#define PSU1_AC_HWMON_PREFIX "/sys/bus/i2c/devices/59-0038/" +#define PSU1_DC_HWMON_PREFIX "/sys/bus/i2c/devices/59-0050/" +#define PSU2_AC_HWMON_PREFIX "/sys/bus/i2c/devices/60-003b/" +#define PSU2_DC_HWMON_PREFIX "/sys/bus/i2c/devices/60-0053/" + +#define PSU1_AC_HWMON_NODE(node) PSU1_AC_HWMON_PREFIX#node +#define PSU1_DC_HWMON_NODE(node) PSU1_DC_HWMON_PREFIX#node +#define PSU2_AC_HWMON_NODE(node) PSU2_AC_HWMON_PREFIX#node +#define PSU2_DC_HWMON_NODE(node) PSU2_DC_HWMON_PREFIX#node + +#define IDPROM_PATH "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/1-0057/eeprom" + +int deviceNodeWriteInt(char *filename, int value, int data_len); +int deviceNodeReadBinary(char *filename, char *buffer, int buf_size, int data_len); +int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_len); + +typedef enum psu_type { + PSU_TYPE_UNKNOWN, + PSU_TYPE_AC_F2B, + PSU_TYPE_AC_B2F, + PSU_TYPE_DC_48V_F2B, + PSU_TYPE_DC_48V_B2F +} psu_type_t; + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len); + +#endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/psui.c new file mode 100644 index 00000000..f9334399 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/psui.c @@ -0,0 +1,247 @@ +/************************************************************ + * + * + * 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_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, int is_ac, char *node, int *value) +{ + int ret = 0; + char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; + char node_path[PSU_NODE_MAX_PATH_LEN] = {0}; + + *value = 0; + + if (PSU1_ID == id) { + sprintf(node_path, "%s%s", is_ac ? PSU1_AC_HWMON_PREFIX : PSU1_DC_HWMON_PREFIX, node); + } + else if (PSU2_ID == id) { + sprintf(node_path, "%s%s", is_ac ? PSU2_AC_HWMON_PREFIX : PSU2_DC_HWMON_PREFIX, node); + } + + ret = deviceNodeReadString(node_path, buf, sizeof(buf), 0); + + if (ret == 0) { + *value = atoi(buf); + } + + return ret; +} + +static int +psu_cpr_4011_pmbus_info_get(int id, char *node, int *value) +{ + int ret = 0; + char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; + char node_path[PSU_NODE_MAX_PATH_LEN] = {0}; + + *value = 0; + + if (PSU1_ID == id) { + sprintf(node_path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + } + else { + sprintf(node_path, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + } + + ret = deviceNodeReadString(node_path, buf, sizeof(buf), 0); + + if (ret == 0) { + *value = atoi(buf); + } + + return ret; +} + +int +onlp_psui_init(void) +{ + return ONLP_STATUS_OK; +} + +static int +psu_cpr_4011_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_cpr_4011_pmbus_info_get(index, "psu_v_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_cpr_4011_pmbus_info_get(index, "psu_v_in", &val) == 0) { + info->mvin = val; + info->caps |= ONLP_PSU_CAPS_VIN; + } + + if (psu_cpr_4011_pmbus_info_get(index, "psu_i_out", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (psu_cpr_4011_pmbus_info_get(index, "psu_i_in", &val) == 0) { + info->miin = val; + info->caps |= ONLP_PSU_CAPS_IIN; + } + + if (psu_cpr_4011_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + if (psu_cpr_4011_pmbus_info_get(index, "psu_p_in", &val) == 0) { + info->mpin = val; + info->caps |= ONLP_PSU_CAPS_PIN; + } + + return ONLP_STATUS_OK; +} + +int +psu_um400d_info_get(onlp_psu_info_t* info) +{ + int index = ONLP_OID_ID_GET(info->hdr.id); + + /* Set capability + */ + info->caps = ONLP_PSU_CAPS_DC48; + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Set the associated oid_table */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + + return ONLP_STATUS_OK; +} + +/* + * Get all information about the given PSU oid. + */ +static onlp_psu_info_t pinfo[] = +{ + { }, /* Not used */ + { + { 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, 1, "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, 1, "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_cpr_4011_info_get(info); + break; + case PSU_TYPE_DC_48V_F2B: + case PSU_TYPE_DC_48V_B2F: + ret = psu_um400d_info_get(info); + break; + default: + ret = ONLP_STATUS_E_UNSUPPORTED; + 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-as5512-54x/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/sfpi.c new file mode 100644 index 00000000..141b8645 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/sfpi.c @@ -0,0 +1,356 @@ +/************************************************************ + * + * + * 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 /* For O_RDWR && open */ +#include +#include +#include +#include + +#include "platform_lib.h" + +#define MAX_SFP_PATH 64 +static char sfp_node_path[MAX_SFP_PATH] = {0}; + +#define MUX_START_INDEX 2 +#define NUM_OF_SFP_PORT 54 +static const int sfp_mux_index[NUM_OF_SFP_PORT] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, +16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, +52, 50, 48, 53, 51, 49 +}; + +#define FRONT_PORT_TO_MUX_INDEX(port) (sfp_mux_index[port]+MUX_START_INDEX) + +static int +sfp_node_read_int(char *node_path, int *value, int data_len) +{ + int ret = 0; + char buf[8] = {0}; + *value = 0; + + ret = deviceNodeReadString(node_path, buf, sizeof(buf), data_len); + + if (ret == 0) { + *value = atoi(buf); + } + + return ret; +} + +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_TO_MUX_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; + + for(p = 0; p < 54; 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 (sfp_node_read_int(path, &present, 0) != 0) { + AIM_LOG_INFO("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; + + 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[7]; + 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 (deviceNodeReadBinary(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_dom_read(int port, uint8_t data[256]) +{ + char* path = sfp_get_port_path_addr(port, 51, "sfp_eeprom"); + memset(data, 0, 256); + + if (deviceNodeReadBinary(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; + + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + switch(control) + { + case ONLP_SFP_CONTROL_TX_DISABLE: + { + char* path = sfp_get_port_path(port, "sfp_tx_disable"); + + if (deviceNodeWriteInt(path, value, 0) != 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; + + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + switch(control) + { + case ONLP_SFP_CONTROL_RX_LOS: + { + path = sfp_get_port_path(port, "sfp_rx_los"); + + if (sfp_node_read_int(path, value, 0) != 0) { + AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_FAULT: + { + path = sfp_get_port_path(port, "sfp_tx_fault"); + + if (sfp_node_read_int(path, value, 0) != 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 (sfp_node_read_int(path, value, 0) != 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-as5512-54x/onlp/builds/src/module/src/sysi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/sysi.c new file mode 100644 index 00000000..662189b8 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/sysi.c @@ -0,0 +1,276 @@ +/************************************************************ + * + * + * 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 "x86_64_accton_as5512_54x_int.h" +#include "x86_64_accton_as5512_54x_log.h" +#include "platform_lib.h" +#include +#include + +#define LOCAL_DEBUG 0 + +#define OPEN_READ_FILE(fd,fullpath,data,nbytes,len) \ + if (LOCAL_DEBUG) \ + printf("[Debug][%s][%d][openfile: %s]\n", __FUNCTION__, __LINE__, fullpath); \ + if ((fd = open(fullpath, O_RDONLY)) == -1) \ + return ONLP_STATUS_E_INTERNAL; \ + if ((len = read(fd, r_data, nbytes)) <= 0){ \ + close(fd); \ + return ONLP_STATUS_E_INTERNAL;} \ + if (LOCAL_DEBUG) \ + printf("[Debug][%s][%d][read data: %s][len:%d]\n", __FUNCTION__, __LINE__, r_data, len); \ + if (close(fd) == -1) \ + return ONLP_STATUS_E_INTERNAL + + +#define PREFIX_PATH_ON_CPLD_DEV "/sys/bus/i2c/devices/" +#define NUM_OF_CPLD 3 +static char arr_cplddev_name[NUM_OF_CPLD][10] = +{ + "0-0060", + "0-0061", + "0-0062" +}; + +const char* +onlp_sysi_platform_get(void) +{ + return "x86-64-accton-as5512-54x-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_platform_info_get(onlp_platform_info_t* pi) +{ + int i, siz=NUM_OF_CPLD, v[NUM_OF_CPLD]={0}; + int fd, len, nbytes = 10; + char r_data[10] = {0}; + char fullpath[65] = {0}; + + for (i=0; icpld_versions = aim_fstrdup("%d.%d.%d", v[0], v[1], v[2]); + else + printf("This CPLD numbers are wrong !! \n"); + + return 0; +} + +void +onlp_sysi_platform_info_free(onlp_platform_info_t* pi) +{ + aim_free(pi->cpld_versions); +} + +int +onlp_sysi_oids_get(onlp_oid_t* table, int max) +{ + onlp_oid_t* e = table; + memset(table, 0, max*sizeof(onlp_oid_t)); + int i; + int n_led=5, n_thermal=4, n_fan=5; + + //assert(max > (n_led+n_thermal+n_fan)); + + /* 2 PSUs */ + *e++ = ONLP_PSU_ID_CREATE(1); + *e++ = ONLP_PSU_ID_CREATE(2); + + /* LEDs Item */ + for (i=1; i<=n_led; i++) + { + *e++ = ONLP_LED_ID_CREATE(i); + } + + /* THERMALs Item */ + for (i=1; i<=n_thermal; i++) + { + *e++ = ONLP_THERMAL_ID_CREATE(i); + } + + /* Fans Item */ + for (i=1; i<=n_fan; i++) + { + *e++ = ONLP_FAN_ID_CREATE(i); + } + + return 0; +} + +/* + * 1. If any FAN failed, set all the other fans as full speed (100%) + * 2. When (LM75-1 + LM75-2)/2 >= 49.5 C, set fan speed from 40% to 65%. + * 3. When (LM75-1 + LM75-2)/2 >= 53C, set fan speed from 65% to 80% + * 4. When (LM75-1 + LM75-2)/2 >= 57.7C, set fan speed from 80% to 100% + + * 5. When (LM75-1 + LM75-2)/2 <= 52.7C, set fan speed from 100% to 80% + * 6. When (LM75-1 + LM75-2)/2 <= 47.7C, set fan speed from 80% to 65% + * 7. When (LM75-1 + LM75-2)/2 <= 42.7C, set fan speed from 65% to 40% + * 8. The default FAN speed is 40% + */ +int +onlp_sysi_platform_manage_fans(void) +{ +#define LEV1_UP_TEMP 57500 /*temperature*/ +#define LEV1_DOWN_TEMP NULL /* unused */ +#define LEV1_SPEED_PERC 100 /*percentage*/ + +#define LEV2_UP_TEMP 53000 +#define LEV2_DOWN_TEMP 52700 +#define LEV2_SPEED_PERC 80 + +#define LEV3_UP_TEMP 49500 +#define LEV3_DOWN_TEMP 47700 +#define LEV3_SPEED_PERC 65 + +#define LEV4_UP_TEMP NULL /* unused */ +#define LEV4_DOWN_TEMP 42700 +#define LEV4_SPEED_PERC 40 + +#define FAN_NUM_ON_MAIN_BROAD 5 + + int rc, i; + int is_up; + int new_temp, temp1, temp2, diff; + static int new_perc = 0, ori_perc = 0; + static int ori_temp = 0; + onlp_thermal_info_t thermal_info; + onlp_fan_info_t fan_info; + + /* get new temperature */ + if ((rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(2), &thermal_info)) != ONLP_STATUS_OK) + goto _EXIT; + + temp1 = thermal_info.mcelsius; + + if ((rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(3), &thermal_info)) != ONLP_STATUS_OK) + goto _EXIT; + + temp2 = thermal_info.mcelsius; + + new_temp = (temp1+temp2)/2; + + /* check fan status */ + for (i=1; i<=FAN_NUM_ON_MAIN_BROAD; i++) + { + if ((rc = onlp_fani_info_get(ONLP_FAN_ID_CREATE(i), &fan_info)) != ONLP_STATUS_OK) + goto _EXIT; + + if (fan_info.status & ONLP_FAN_STATUS_FAILED) + { + new_perc = LEV1_SPEED_PERC; + goto _CTRL; + } + } + + diff = new_temp - ori_temp; + + if (diff == 0) + goto _EXIT; + else + is_up = (diff > 0 ? 1 : 0); + + if (is_up) + { + if (new_temp >= LEV1_UP_TEMP) + new_perc = LEV1_SPEED_PERC; + else if (new_temp >= LEV2_UP_TEMP) + new_perc = LEV2_SPEED_PERC; + else if (new_temp >= LEV3_UP_TEMP) + new_perc = LEV3_SPEED_PERC; + else + new_perc = LEV4_SPEED_PERC; + } + else + { + if (new_temp <= LEV4_DOWN_TEMP) + new_perc = LEV4_SPEED_PERC; + else if (new_temp <= LEV3_DOWN_TEMP) + new_perc = LEV3_SPEED_PERC; + else if (new_temp <= LEV2_DOWN_TEMP) + new_perc = LEV2_SPEED_PERC; + else + new_perc = LEV1_SPEED_PERC; + } + +_CTRL : + + if (LOCAL_DEBUG) + printf("\n[DEBUG][%s][%d]{ori:temp=%d, perc=%d} {new:temp=%d, perc=%d}\n", __FUNCTION__, __LINE__, + ori_temp, ori_perc, new_temp, new_perc); + + if (ori_perc == new_perc) + goto _EXIT; + + /* ctrl fans */ + AIM_LOG_INFO("Fan Speeds are now at %d%%", new_perc); + + if ((rc = onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), new_perc)) != ONLP_STATUS_OK) + goto _EXIT; + + /* update om */ + ori_perc = new_perc; + ori_temp = new_temp; + +_EXIT : + + return rc; +} + +int +onlp_sysi_platform_manage_leds(void) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/thermali.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/thermali.c new file mode 100644 index 00000000..63345a7b --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/thermali.c @@ -0,0 +1,175 @@ +/************************************************************ + * + * + * 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. + * + * + ************************************************************ + * + * Thermal Sensor Platform Implementation. + * + ***********************************************************/ +#include +#include +#include +#include +#include + +#define prefix_path "/sys/bus/i2c/devices/" +#define filename "temp1_input" +#define LOCAL_DEBUG 0 + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_THERMAL(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + + +#define OPEN_READ_FILE(fd,fullpath,data,nbytes,len) \ + if (LOCAL_DEBUG) \ + printf("[Debug][%s][%d][openfile: %s]\n", __FUNCTION__, __LINE__, fullpath); \ + if ((fd = open(fullpath, O_RDONLY)) == -1) \ + return ONLP_STATUS_E_INTERNAL; \ + if ((len = read(fd, r_data, nbytes)) <= 0){ \ + close(fd); \ + return ONLP_STATUS_E_INTERNAL;} \ + if (LOCAL_DEBUG) \ + printf("[Debug][%s][%d][read data: %s]\n", __FUNCTION__, __LINE__, r_data); \ + if (close(fd) == -1) \ + return ONLP_STATUS_E_INTERNAL + + +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_1_ON_PSU1, + THERMAL_1_ON_PSU2, +}; + +static char* last_path[] = /* must map with onlp_thermal_id */ +{ + "reserved", + NULL, /* CPU_CORE files */ + "63-0048/", + "64-0049/", + "65-004a/", + "59-003c/psu_", + "60-003f/psu_", +}; + +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), "Chassis Thermal Sensor 1 (Front middle)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "Chassis Thermal Sensor 2 (Rear right)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "Chassis Thermal Sensor 3 (Front right)", 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(1)}, + 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(2)}, + 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 fd, len, nbytes = 10, temp_base=1, local_id; + char r_data[10] = {0}; + char fullpath[50] = {0}; + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + if (LOCAL_DEBUG) + printf("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[local_id]; + + if(local_id == THERMAL_CPU_CORE) { + int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files); + return rv; + } + + /* get fullpath */ + sprintf(fullpath, "%s%s%s", prefix_path, last_path[local_id], filename); + + OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); + + info->mcelsius = atoi(r_data)/temp_base; + + if (LOCAL_DEBUG) + printf("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius); + + return ONLP_STATUS_OK; +} + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_config.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_config.c new file mode 100644 index 00000000..d4f9aca0 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_config.c @@ -0,0 +1,80 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* */ +#define __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE(_x) __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(_x) +x86_64_accton_as5512_54x_config_settings_t x86_64_accton_as5512_54x_config_settings[] = +{ +#ifdef x86_64_accton_as5512_54x_CONFIG_INCLUDE_LOGGING + { __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(x86_64_accton_as5512_54x_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE(x86_64_accton_as5512_54x_CONFIG_INCLUDE_LOGGING) }, +#else +{ x86_64_accton_as5512_54x_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5512_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5512_54x_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(x86_64_accton_as5512_54x_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE(x86_64_accton_as5512_54x_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ x86_64_accton_as5512_54x_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5512_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5512_54x_CONFIG_LOG_BITS_DEFAULT + { __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(x86_64_accton_as5512_54x_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE(x86_64_accton_as5512_54x_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ x86_64_accton_as5512_54x_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5512_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5512_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(x86_64_accton_as5512_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE(x86_64_accton_as5512_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ x86_64_accton_as5512_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5512_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB + { __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB), __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE(x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB) }, +#else +{ x86_64_accton_as5512_54x_CONFIG_PORTING_STDLIB(__x86_64_accton_as5512_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5512_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(x86_64_accton_as5512_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE(x86_64_accton_as5512_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ x86_64_accton_as5512_54x_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5512_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5512_54x_CONFIG_INCLUDE_UCLI + { __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(x86_64_accton_as5512_54x_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE(x86_64_accton_as5512_54x_CONFIG_INCLUDE_UCLI) }, +#else +{ x86_64_accton_as5512_54x_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5512_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef x86_64_accton_as5512_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_accton_as5512_54x_config_STRINGIFY_NAME(x86_64_accton_as5512_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE(x86_64_accton_as5512_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#else +{ x86_64_accton_as5512_54x_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5512_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_accton_as5512_54x_config_STRINGIFY_VALUE +#undef __x86_64_accton_as5512_54x_config_STRINGIFY_NAME + +const char* +x86_64_accton_as5512_54x_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_accton_as5512_54x_config_settings[i].name; i++) { + if(strcmp(x86_64_accton_as5512_54x_config_settings[i].name, setting)) { + return x86_64_accton_as5512_54x_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_accton_as5512_54x_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_accton_as5512_54x_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_accton_as5512_54x_config_settings[i].name, x86_64_accton_as5512_54x_config_settings[i].value); + } + return i; +} + +/* */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_enums.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_enums.c new file mode 100644 index 00000000..d6a1f0d1 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_enums.c @@ -0,0 +1,10 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_int.h b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_int.h new file mode 100644 index 00000000..8310a341 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_int.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * x86_64_accton_as5512_54x Internal Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5512_54x_INT_H__ +#define __x86_64_accton_as5512_54x_INT_H__ + +#include + + +#endif /* __x86_64_accton_as5512_54x_INT_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_log.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_log.c new file mode 100644 index 00000000..2d75aaf7 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_log.c @@ -0,0 +1,18 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5512_54x_log.h" +/* + * x86_64_accton_as5512_54x log struct. + */ +AIM_LOG_STRUCT_DEFINE( + x86_64_accton_as5512_54x_CONFIG_LOG_OPTIONS_DEFAULT, + x86_64_accton_as5512_54x_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + x86_64_accton_as5512_54x_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_log.h b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_log.h new file mode 100644 index 00000000..1f6ade5a --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_log.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5512_54x_LOG_H__ +#define __x86_64_accton_as5512_54x_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_accton_as5512_54x +#include + +#endif /* __x86_64_accton_as5512_54x_LOG_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_module.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_module.c new file mode 100644 index 00000000..7303e141 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_module.c @@ -0,0 +1,24 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5512_54x_log.h" + +static int +datatypes_init__(void) +{ +#define x86_64_accton_as5512_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_as5512_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-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_ucli.c b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_ucli.c new file mode 100644 index 00000000..6dc694d4 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/onlp/builds/src/module/src/x86_64_accton_as5512_54x_ucli.c @@ -0,0 +1,50 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#if x86_64_accton_as5512_54x_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_accton_as5512_54x_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as5512_54x) +} + +/* */ +/* */ + +static ucli_module_t +x86_64_accton_as5512_54x_ucli_module__ = + { + "x86_64_accton_as5512_54x_ucli", + NULL, + x86_64_accton_as5512_54x_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_accton_as5512_54x_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_accton_as5512_54x_ucli_module__); + n = ucli_node_create("x86_64_accton_as5512_54x", NULL, &x86_64_accton_as5512_54x_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as5512_54x")); + return n; +} + +#else +void* +x86_64_accton_as5512_54x_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-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-as5512-54x/platform-config/r0/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/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-as5512-54x/platform-config/r0/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/PKG.yml new file mode 100644 index 00000000..e13eaf29 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton PLATFORM=x86-64-accton-as5512-54x-r0 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/boot/grub.cfg b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/boot/grub.cfg new file mode 100644 index 00000000..40105eaf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/boot/grub.cfg @@ -0,0 +1,21 @@ +serial --port=0x2f8 --speed=115200 --word=8 --parity=no --stop=1 +terminal_input serial +terminal_output serial +set timeout=5 + +# boot switch light +menuentry OpenNetworkLinux { + search --no-floppy --label --set=root ONL-BOOT + echo 'Loading Open Network Linux ...' + insmod gzio + insmod part_msdos + linux /kernel-3.2-deb7-x86_64-all nopat console=ttyS1,115200n8 onl_platform=x86-64-accton-as5512-54x-r0 + initrd /initrd-amd64 +} + +# Menu entry to chainload ONIE +menuentry ONIE { + search --no-floppy --label --set=root ONIE-BOOT + echo 'Loading ONIE ...' + chainloader +1 +} diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/boot/x86-64-accton-as5512-54x-r0 b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/boot/x86-64-accton-as5512-54x-r0 new file mode 100644 index 00000000..1d035c23 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/boot/x86-64-accton-as5512-54x-r0 @@ -0,0 +1,7 @@ +echo "pci0000:00/0000:00:14.0 ma1" >/etc/onl/net + +echo "LABEL=FLASH * flash" > /etc/onl/mounts +echo "LABEL=FLASH2 * flash2" >> /etc/onl/mounts + + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/install/x86-64-accton-as5512-54x-r0.sh b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/install/x86-64-accton-as5512-54x-r0.sh new file mode 100644 index 00000000..e62ede0a --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/lib/install/x86-64-accton-as5512-54x-r0.sh @@ -0,0 +1,15 @@ +############################################################ +# +# +# Copyright 2013, 2014 BigSwitch Networks, Inc. +# +# +# +# +############################################################ +# Platform data goes here. + +platform_installer() { + # Standard isntallation to an available GPT partition + installer_standard_gpt_install /dev/sda +} diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/python/x86_64_accton_as5512_54x_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/python/x86_64_accton_as5512_54x_r0/__init__.py new file mode 100644 index 00000000..de3685dd --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5512-54x/platform-config/r0/src/python/x86_64_accton_as5512_54x_r0/__init__.py @@ -0,0 +1,78 @@ +from onl.platform.base import * +from onl.platform.accton import * + +class OnlPlatform_x86_64_accton_as5512_54x_r0(OnlPlatformAccton): + + + def model(self): + return "AS5512-54X" + + def platform(self): + return "x86-64-accton-as5512-54x-r0" + + def sys_init(self): + pass + + def sys_oid_platform(self): + return ".5512.54.1" + + def baseconfig(self): + ########### initialize I2C bus 0 ########### + + # initialize multiplexer (PCA9548) + self.new_i2c_devices( + [ + ('pca9548', 0x71, 0), + ('pca9548', 0x72, 0), + ('pca9548', 0x73, 0), + ('pca9548', 0x74, 0), + ('pca9548', 0x75, 0), + ('pca9548', 0x76, 0), + ('pca9548', 0x77, 0), + ] + ) + # initialize CPLDs + self.new_i2c_devices( + [ + ('accton_i2c_cpld', 0x60, 0), + ('accton_i2c_cpld', 0x61, 0), + ('accton_i2c_cpld', 0x62, 0), + ] + ) + # initialize SFP devices + for port in range(1, 49): + self.new_i2c_device('sfp%d' % port, 0x50, port+1) + self.new_i2c_device('sfp%d' % port, 0x51, port+1) + + # Initialize QSFP devices + self.new_i2c_device('sfp51', 0x50, 50) + self.new_i2c_device('sfp54', 0x50, 51) + self.new_i2c_device('sfp50', 0x50, 52) + self.new_i2c_device('sfp53', 0x50, 53) + self.new_i2c_device('sfp49', 0x50, 54) + self.new_i2c_device('sfp52', 0x50, 55) + + ########### initialize I2C bus 1 ########### + self.new_i2c_devices( + [ + # initiate multiplexer (PCA9548) + ('pca9548', 0x70, 1), + + # initiate PSU-1 AC Power + ('as5512_54x_psu', 0x38, 59), + ('cpr_4011_4mxx', 0x3c, 59), + + # initiate PSU-2 AC Power + ('as5512_54x_psu', 0x3b, 60), + ('cpr_4011_4mxx', 0x3f, 60), + + # initiate lm75 + ('lm75', 0x48, 63), + ('lm75', 0x49, 64), + ('lm75', 0x4a, 65), + + # initiate IDPROM + ('24c02', 0x57, 1), + ] + ) + return True From 1d97e2e54b5f9d4dd7e1e8e4ce58717c0c96ddc5 Mon Sep 17 00:00:00 2001 From: Steven Noble Date: Tue, 19 Apr 2016 12:37:18 -0700 Subject: [PATCH 03/10] moved default buildroot mirror from github to opencompute server --- setup.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.env b/setup.env index 6418a522..ed0ae4a9 100755 --- a/setup.env +++ b/setup.env @@ -31,7 +31,7 @@ export ONLPM_OPTION_INCLUDE_ENV_JSON="$ONL/make/version-onl.json" # # buildroot download mirror. We suggest you setup a local repository containing these contents for faster local builds. # -export BUILDROOTMIRROR=${BUILDROOTMIRROR:-"https://raw.githubusercontent.com/opennetworklinux/buildroot-download-cache/master/dl"} +export BUILDROOTMIRROR=${BUILDROOTMIRROR:-"http://buildroot.opennetlinux.org/dl"} # These submodules are required for almost everything. $ONL/tools/submodules.py $ONL sm/infra From 90f0218b57e82dd043ebda171abd44a7f60c25c7 Mon Sep 17 00:00:00 2001 From: Steven Noble Date: Tue, 19 Apr 2016 14:53:58 -0700 Subject: [PATCH 04/10] Update REPO directories to match standard APT names binary-arch --- REPO/jessie/packages/{all => binary-all}/Makefile | 0 REPO/jessie/packages/{amd64 => binary-amd64}/Makefile | 0 REPO/jessie/packages/{armel => binary-armel}/Makefile | 0 REPO/jessie/packages/{powerpc => binary-powerpc}/Makefile | 0 REPO/wheezy/packages/{all => binary-all}/Makefile | 0 REPO/wheezy/packages/{amd64 => binary-amd64}/Makefile | 0 REPO/wheezy/packages/{powerpc => binary-powerpc}/Makefile | 0 builds/any/rootfs/jessie/standard/standard.yml | 4 ++-- builds/any/rootfs/wheezy/standard/standard.yml | 4 ++-- tools/onlpm.py | 6 +++--- 10 files changed, 7 insertions(+), 7 deletions(-) rename REPO/jessie/packages/{all => binary-all}/Makefile (100%) rename REPO/jessie/packages/{amd64 => binary-amd64}/Makefile (100%) rename REPO/jessie/packages/{armel => binary-armel}/Makefile (100%) rename REPO/jessie/packages/{powerpc => binary-powerpc}/Makefile (100%) rename REPO/wheezy/packages/{all => binary-all}/Makefile (100%) rename REPO/wheezy/packages/{amd64 => binary-amd64}/Makefile (100%) rename REPO/wheezy/packages/{powerpc => binary-powerpc}/Makefile (100%) diff --git a/REPO/jessie/packages/all/Makefile b/REPO/jessie/packages/binary-all/Makefile similarity index 100% rename from REPO/jessie/packages/all/Makefile rename to REPO/jessie/packages/binary-all/Makefile diff --git a/REPO/jessie/packages/amd64/Makefile b/REPO/jessie/packages/binary-amd64/Makefile similarity index 100% rename from REPO/jessie/packages/amd64/Makefile rename to REPO/jessie/packages/binary-amd64/Makefile diff --git a/REPO/jessie/packages/armel/Makefile b/REPO/jessie/packages/binary-armel/Makefile similarity index 100% rename from REPO/jessie/packages/armel/Makefile rename to REPO/jessie/packages/binary-armel/Makefile diff --git a/REPO/jessie/packages/powerpc/Makefile b/REPO/jessie/packages/binary-powerpc/Makefile similarity index 100% rename from REPO/jessie/packages/powerpc/Makefile rename to REPO/jessie/packages/binary-powerpc/Makefile diff --git a/REPO/wheezy/packages/all/Makefile b/REPO/wheezy/packages/binary-all/Makefile similarity index 100% rename from REPO/wheezy/packages/all/Makefile rename to REPO/wheezy/packages/binary-all/Makefile diff --git a/REPO/wheezy/packages/amd64/Makefile b/REPO/wheezy/packages/binary-amd64/Makefile similarity index 100% rename from REPO/wheezy/packages/amd64/Makefile rename to REPO/wheezy/packages/binary-amd64/Makefile diff --git a/REPO/wheezy/packages/powerpc/Makefile b/REPO/wheezy/packages/binary-powerpc/Makefile similarity index 100% rename from REPO/wheezy/packages/powerpc/Makefile rename to REPO/wheezy/packages/binary-powerpc/Makefile diff --git a/builds/any/rootfs/jessie/standard/standard.yml b/builds/any/rootfs/jessie/standard/standard.yml index 071dc193..4586c93f 100644 --- a/builds/any/rootfs/jessie/standard/standard.yml +++ b/builds/any/rootfs/jessie/standard/standard.yml @@ -43,11 +43,11 @@ Multistrap: omitdebsrc: true Local-All: - source: ${ONL}/REPO/${ONL_DEBIAN_SUITE}/packages/all + source: ${ONL}/REPO/${ONL_DEBIAN_SUITE}/packages/binary-all omitdebsrc: true Local-Arch: - source: ${ONL}/REPO/${ONL_DEBIAN_SUITE}/packages/${ARCH} + source: ${ONL}/REPO/${ONL_DEBIAN_SUITE}/packages/binary-${ARCH} omitdebsrc: true Configure: diff --git a/builds/any/rootfs/wheezy/standard/standard.yml b/builds/any/rootfs/wheezy/standard/standard.yml index fe72a3b8..2ec2902d 100644 --- a/builds/any/rootfs/wheezy/standard/standard.yml +++ b/builds/any/rootfs/wheezy/standard/standard.yml @@ -43,11 +43,11 @@ Multistrap: omitdebsrc: true Local-All: - source: ${ONL}/REPO/${ONL_DEBIAN_SUITE}/packages/all + source: ${ONL}/REPO/${ONL_DEBIAN_SUITE}/packages/binary-all omitdebsrc: true Local-Arch: - source: ${ONL}/REPO/${ONL_DEBIAN_SUITE}/packages/${ARCH} + source: ${ONL}/REPO/${ONL_DEBIAN_SUITE}/packages/binary-${ARCH} omitdebsrc: true Configure: diff --git a/tools/onlpm.py b/tools/onlpm.py index 62aff9c8..552f4f1f 100755 --- a/tools/onlpm.py +++ b/tools/onlpm.py @@ -605,8 +605,8 @@ class OnlPackageRepo(object): package = os.path.split(underscores[0])[1] # Architecture is the last entry (.deb) arch = underscores[-1].split('.')[0] - logger.debug("+ /bin/cp %s %s/%s", p, self.repo, arch) - dstdir = os.path.join(self.repo, arch) + logger.debug("+ /bin/cp %s %s/%s", p, self.repo, "binary-" + arch) + dstdir = os.path.join(self.repo, "binary-" + arch) if not os.path.exists(dstdir): os.makedirs(dstdir) logger.info("dstdir=%s"% dstdir) @@ -637,7 +637,7 @@ class OnlPackageRepo(object): with self.lock: rv = [] (name, arch) = OnlPackage.idparse(pkg) - dirname = os.path.join(self.repo, arch) + dirname = os.path.join(self.repo, "binary-" + arch) if os.path.exists(dirname): manifest = os.listdir(dirname) rv = [ os.path.join(dirname, x) for x in manifest if arch in x and "%s_" % name in x ] From 8491981e35569d125e6b0fb645bc3262357ac7d1 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 21 Apr 2016 00:56:46 +0000 Subject: [PATCH 05/10] The ONL-CONFIG partition should not be mounted by default. --- builds/any/rootfs/jessie/common/overlay/etc/mtab.yml | 2 +- builds/any/rootfs/wheezy/common/overlay/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 f29f2a11..e6c3ab22 100644 --- a/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml +++ b/builds/any/rootfs/jessie/common/overlay/etc/mtab.yml @@ -9,7 +9,7 @@ mounts: dir: /mnt/onl/data ONL-CONFIG: - mount: r + mount: false dir: /mnt/onl/config fsck: true diff --git a/builds/any/rootfs/wheezy/common/overlay/etc/mtab.yml b/builds/any/rootfs/wheezy/common/overlay/etc/mtab.yml index f29f2a11..e6c3ab22 100644 --- a/builds/any/rootfs/wheezy/common/overlay/etc/mtab.yml +++ b/builds/any/rootfs/wheezy/common/overlay/etc/mtab.yml @@ -9,7 +9,7 @@ mounts: dir: /mnt/onl/data ONL-CONFIG: - mount: r + mount: false dir: /mnt/onl/config fsck: true From 177ea065e7e04e8a718bea0a4850270a205edde9 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 21 Apr 2016 00:57:51 +0000 Subject: [PATCH 06/10] Add openssl. --- builds/any/rootfs/jessie/common/common-packages.yml | 1 + builds/any/rootfs/wheezy/common/common-packages.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/builds/any/rootfs/jessie/common/common-packages.yml b/builds/any/rootfs/jessie/common/common-packages.yml index 1b399128..3b6c00df 100644 --- a/builds/any/rootfs/jessie/common/common-packages.yml +++ b/builds/any/rootfs/jessie/common/common-packages.yml @@ -70,3 +70,4 @@ - onlp-snmpd - oom-shim - onl-mibs +- openssl diff --git a/builds/any/rootfs/wheezy/common/common-packages.yml b/builds/any/rootfs/wheezy/common/common-packages.yml index c60d3f33..17aae016 100644 --- a/builds/any/rootfs/wheezy/common/common-packages.yml +++ b/builds/any/rootfs/wheezy/common/common-packages.yml @@ -69,4 +69,4 @@ - onlp-snmpd - oom-shim - onl-mibs - +- openssl From 889d8d7282fa8a702a772437d8fbb11185dc4f5a Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 21 Apr 2016 00:58:05 +0000 Subject: [PATCH 07/10] The ONL-CONFIG partition should not be mounted. --- packages/base/all/initrds/loader-initrd-files/src/etc/mtab.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 291e1996..00f64685 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 @@ -9,7 +9,7 @@ mounts: dir: /mnt/onl/data ONL-CONFIG: - mount: r + mount: false dir: /mnt/onl/config fsck: true From 16284d277f43a89d2a2390a5fd0c812c5ff5b981 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 21 Apr 2016 00:58:55 +0000 Subject: [PATCH 08/10] Run pki --init --- packages/base/all/initrds/loader-initrd-files/src/bin/sysinit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 6c255b85..968d4a92 100755 --- a/packages/base/all/initrds/loader-initrd-files/src/bin/sysinit +++ b/packages/base/all/initrds/loader-initrd-files/src/bin/sysinit @@ -84,8 +84,8 @@ fi # # Initialize PKI # -if [ -f /sbin/init-pki ]; then - /sbin/init-pki +if [ -f /sbin/pki ]; then + /sbin/pki --init fi From 2640aec6d872cd73134653bc7a426ac61c3c7755 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 21 Apr 2016 01:00:04 +0000 Subject: [PATCH 09/10] ONL-CONFIG datastore and PKI infrastructure. --- packages/base/all/boot.d/src/51.pki | 6 + .../src/etc/onl/config/csr.yml | 7 + packages/base/all/vendor-config-onl/PKG.yml | 1 + .../base/all/vendor-config-onl/src/bin/pki | 3 + .../src/python/onl/mounts/__init__.py | 156 +++++++++++++++++- .../src/python/onl/pki/__init__.py | 129 +++++++++++++++ 6 files changed, 301 insertions(+), 1 deletion(-) create mode 100755 packages/base/all/boot.d/src/51.pki create mode 100644 packages/base/all/initrds/loader-initrd-files/src/etc/onl/config/csr.yml create mode 100755 packages/base/all/vendor-config-onl/src/bin/pki create mode 100755 packages/base/all/vendor-config-onl/src/python/onl/pki/__init__.py diff --git a/packages/base/all/boot.d/src/51.pki b/packages/base/all/boot.d/src/51.pki new file mode 100755 index 00000000..5752d4e9 --- /dev/null +++ b/packages/base/all/boot.d/src/51.pki @@ -0,0 +1,6 @@ +#!/bin/sh +if [ -f /usr/bin/pki ]; then + /usr/bin/pki --init +fi + + diff --git a/packages/base/all/initrds/loader-initrd-files/src/etc/onl/config/csr.yml b/packages/base/all/initrds/loader-initrd-files/src/etc/onl/config/csr.yml new file mode 100644 index 00000000..c64b4847 --- /dev/null +++ b/packages/base/all/initrds/loader-initrd-files/src/etc/onl/config/csr.yml @@ -0,0 +1,7 @@ +C: US +ST: CA +O: Open Compute Project +localityName: Santa Clara +commonName: Networking +organizationalUnitName: Open Network Linux +emailAddress: support@bigswitch.com diff --git a/packages/base/all/vendor-config-onl/PKG.yml b/packages/base/all/vendor-config-onl/PKG.yml index 794948a1..5e5a397a 100644 --- a/packages/base/all/vendor-config-onl/PKG.yml +++ b/packages/base/all/vendor-config-onl/PKG.yml @@ -25,5 +25,6 @@ packages: files: src/python/onl : /usr/lib/python2.7/onl src/bin/initmounts : /bin/initmounts + src/bin/pki : /sbin/pki changelog: Changes diff --git a/packages/base/all/vendor-config-onl/src/bin/pki b/packages/base/all/vendor-config-onl/src/bin/pki new file mode 100755 index 00000000..eb5105a8 --- /dev/null +++ b/packages/base/all/vendor-config-onl/src/bin/pki @@ -0,0 +1,3 @@ +#!/usr/bin/python +from onl.pki import OnlPKI +OnlPKI.main() 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 eaaea1ff..e5d8c9d0 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 @@ -7,6 +7,8 @@ import logging import time import json import yaml +import tempfile +import shutil class OnlMountManager(object): def __init__(self, mdata, logger): @@ -88,7 +90,7 @@ class OnlMountManager(object): out = subprocess.check_output("umount %s" % v['device'], shell=True) self.logger.info("%s now unmounted." % (k)) except subprocess.CalledProcessError,e: - self.logger.error("Could not unmount %s @ %s: " % (k, v['device'], e.output)) + self.logger.error("Could not unmount %s @ %s: %s" % (k, v['device'], e.output)) continue # # FS Checks @@ -151,3 +153,155 @@ class OnlMountManager(object): mm.mountall(all_=True, fsck=False) else: mm.mountall() + + + +############################################################ +# +# Fix this stuff +# +############################################################ +class ServiceMixin(object): + + def _execute(self, cmd, root=False, ex=True): + self.logger.debug("Executing: %s" % cmd) + if root is True and os.getuid() != 0: + cmd = "sudo " + cmd + try: + subprocess.check_call(cmd, shell=True) + except Exception, e: + if ex: + self.logger.error("Command failed: %s" % e) + raise + else: + return e.returncode + + def _raise(self, msg, klass): + self.logger.critical(msg) + raise klass(msg) + +class DataMount(ServiceMixin): + + def __init__(self, partition, logger=None): + self.partition = partition + self.logger = logger + + self.mountpoint = None + self.mounted = False + + if os.path.isabs(partition) and not os.path.exists(partition): + # Implicitly a bind mount. It may not exist yet, so create it + os.makedirs(partition) + + if os.path.exists(partition): + # Bind mount + self.device = None + else: + self.device = subprocess.check_output("blkid | grep %s | awk '{print $1}' | tr -d ':'" % self.partition, shell=True).strip() + if self.device is None or len(self.device) is 0: + self._raise("Data partition %s does not exist." % self.partition, + RuntimeError) + self.logger.debug("device is %s" % self.device) + + def _mount(self): + if self.device: + self._execute("mount %s %s" % (self.device, self.mountdir()), root=True) + else: + self._execute("mount --bind %s %s" % (self.partition, + self.mountdir()), root=True) + self.mounted = True + + def _umount(self): + mounted, self.mounted = self.mounted, False + if mounted: + self._execute("umount %s" % self.mountpoint, root=True) + mountpoint, self.mountpoint = self.mountpoint, None + if mountpoint and os.path.exists(mountpoint): + self.logger.debug("+ /bin/rmdir %s", mountpoint) + os.rmdir(mountpoint) + + def __enter__(self): + self._mount() + return self + + def __exit__(self, type_, value, traceback): + self._umount() + + def mountdir(self): + if self.mountpoint is None: + self.mountpoint = tempfile.mkdtemp(prefix="pki-", suffix=".d") + self.logger.debug("mountpoint is %s" % self.mountpoint) + return self.mountpoint + + +class OnlDataStore(ServiceMixin): + + # Data partition containing the persistant store + DATA_PARTITION='ONL-CONFIG' + + # Persistant directory on DATA_PARTITION + P_DIR=None + + # Runtime directory in the root filesystem + R_DIR=None + + def __init__(self, logger=None): + + if logger is None: + logging.basicConfig() + logger = logging.getLogger(str(self.__class__)) + logger.setLevel(logging.WARN) + + self.logger = logger + + self.mount = DataMount(self.DATA_PARTITION, logger=self.logger) + + if self.P_DIR is None: + raise AttributeError("P_DIR must be set in the derived class.") + + if self.R_DIR is None: + raise ValueError("R_DIR must be set in the derived class.") + + # The R_DIR is accessed here + self.r_dir = self.R_DIR + + self.logger.debug("persistant dir: %s" % self.p_dir) + self.logger.debug(" runtime dir: %s" % self.r_dir) + + @property + def p_dir(self): + return os.path.join(self.mount.mountdir(), self.P_DIR) + + def _sync_dir(self, src, dst): + self.logger.debug("Syncing store from %s -> %s" % (src, dst)) + if os.path.exists(dst): + shutil.rmtree(dst) + + if not os.path.exists(src): + os.makedirs(src) + + shutil.copytree(src, dst) + + def init_runtime(self): + with self.mount: + self._sync_dir(self.p_dir, self.r_dir) + + def commit_runtime(self): + with self.mount: + self._sync_dir(self.r_dir, self.p_dir) + + def diff(self): + with self.mount: + rv = self._execute("diff -rNq %s %s" % (self.p_dir, self.r_dir), ex=False) + return rv == 0 + + def ls(self): + with self.mount: + self._execute("cd %s && find ." % (self.p_dir)) + + def rm(self, filename): + with self.mount: + os.unlink(os.path.join(self.p_dir, filename)) + os.unlink(os.path.join(r_dir, filename)) + + diff --git a/packages/base/all/vendor-config-onl/src/python/onl/pki/__init__.py b/packages/base/all/vendor-config-onl/src/python/onl/pki/__init__.py new file mode 100755 index 00000000..2f8dd157 --- /dev/null +++ b/packages/base/all/vendor-config-onl/src/python/onl/pki/__init__.py @@ -0,0 +1,129 @@ +#!/usr/bin/python +############################################################ +# +# ONL PKI Management +# +############################################################ +import sys +import os +import argparse +import logging +import tempfile +import shutil +import subprocess +import tempfile +import yaml + +from onl.mounts import OnlDataStore + +class OnlPKI(OnlDataStore): + P_DIR='private' + R_DIR='/private' + + PRIVATE_KEY='key.pem' + CERTIFICATE='certificate' + + KLEN=2048 + CDAYS=3650 + + CSR_FILE='/etc/onl/config/csr.yml' + + def __init__(self, logger=None): + OnlDataStore.__init__(self, logger) + self.kpath = os.path.join(self.R_DIR, self.PRIVATE_KEY) + self.cpath = os.path.join(self.R_DIR, self.CERTIFICATE) + + def init_cert(self, force=False): + if not os.path.exists(self.cpath) or force: + self.logger.info("Generating self-signed certificate...") + + # + # The csr.yml file allows the system integrator to customize + # the fields for the certificate. + # + fdict = {} + try: + fdict = yaml.load(open(self.CSR_FILE)) + except Exception, e: + self.logger.error(e); + + csr = tempfile.NamedTemporaryFile(prefix="pki-", suffix=".csr", delete=False) + csr.close() + + fields = [ "%s=%s" % (k, v) for k,v in fdict.iteritems() ] + subject = "/" + "/".join(fields) + self.logger.debug("Subject: '%s'", subject) + self.logger.debug("CSR: %s", csr.name) + self._execute("""openssl req -new -batch -subj "%s" -key %s -out %s""" % ( + subject, self.kpath, csr.name)) + self._execute("""openssl x509 -req -days %s -in %s -signkey %s -out %s""" % ( + self.CDAYS, + csr.name, self.kpath, self.cpath)) + os.unlink(csr.name) + else: + self.logger.info("Using existing certificate.") + + def init_key(self, force=False): + if not os.path.exists(self.kpath) or force: + self.logger.info("Generating private key...") + cmd = "openssl genrsa -out %s %s" % (self.kpath, self.KLEN) + self._execute(cmd) + self.init_cert(force=True) + else: + self.logger.info("Using existing private key.") + + def init(self, force=False): + self.init_key(force=force) + self.init_cert(force=force) + self.commit_runtime() + + + @staticmethod + def main(): + ap = argparse.ArgumentParser(description="ONL PKI Management") + ap.add_argument("--init", action='store_true', help="Initialize /private and PKI files if necessary.") + ap.add_argument("--regen-cert", action='store_true', help="Regenerate certificate.") + ap.add_argument("--force", "-f", action='store_true', help="Force regeneration of the key and certificate during initialization (--init)") + ap.add_argument("--commit", action='store_true', help="Commit the runtime /private directory to the persistant storage.") + ap.add_argument("--ls", action='store_true', help="List contents of the peristant directory.") + ap.add_argument("--quiet", "-q", action='store_true', help="Quiet output.") + ap.add_argument("--verbose", "-v", action='store_true', help="Verbose output.") + ap.add_argument("--part", help='Override Data Partition (testing only).') + ap.add_argument("--rd", help='Override /private runtime directory (testing only)') + + ops = ap.parse_args() + + logging.basicConfig() + logger = logging.getLogger("PKI") + + if ops.verbose: + logger.setLevel(logging.DEBUG) + elif ops.quiet: + logger.setLevel(logging.WARNING) + else: + logger.setLevel(logging.INFO) + + if ops.part: + OnlPKI.DATA_PARTITION=ops.part + + if ops.rd: + OnlPKI.R_DIR=ops.rd + + pki = OnlPKI(logger) + + if ops.init: + pki.init_runtime() + pki.init_key(force=ops.force) + pki.init_cert(force=ops.force) + pki.commit_runtime() + + elif ops.regen_cert: + pki.init_cert(force=True) + pki.commit_runtime() + + elif ops.commit: + pki.commit_runtime() + elif ops.ls: + pki.ls() + else: + pki.diff() From 429cbf0ad1c84074dd562274a79ec8905a0bd575 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 21 Apr 2016 01:03:27 +0000 Subject: [PATCH 10/10] Add default CSR configuration. --- .../rootfs/jessie/common/overlay/etc/onl/config/csr.yml | 7 +++++++ .../rootfs/wheezy/common/overlay/etc/onl/config/csr.yml | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 builds/any/rootfs/jessie/common/overlay/etc/onl/config/csr.yml create mode 100644 builds/any/rootfs/wheezy/common/overlay/etc/onl/config/csr.yml diff --git a/builds/any/rootfs/jessie/common/overlay/etc/onl/config/csr.yml b/builds/any/rootfs/jessie/common/overlay/etc/onl/config/csr.yml new file mode 100644 index 00000000..c64b4847 --- /dev/null +++ b/builds/any/rootfs/jessie/common/overlay/etc/onl/config/csr.yml @@ -0,0 +1,7 @@ +C: US +ST: CA +O: Open Compute Project +localityName: Santa Clara +commonName: Networking +organizationalUnitName: Open Network Linux +emailAddress: support@bigswitch.com diff --git a/builds/any/rootfs/wheezy/common/overlay/etc/onl/config/csr.yml b/builds/any/rootfs/wheezy/common/overlay/etc/onl/config/csr.yml new file mode 100644 index 00000000..c64b4847 --- /dev/null +++ b/builds/any/rootfs/wheezy/common/overlay/etc/onl/config/csr.yml @@ -0,0 +1,7 @@ +C: US +ST: CA +O: Open Compute Project +localityName: Santa Clara +commonName: Networking +organizationalUnitName: Open Network Linux +emailAddress: support@bigswitch.com