From 8232d13bb491d020c081d4bb2da6009264d153ed Mon Sep 17 00:00:00 2001 From: hans Date: Fri, 28 Apr 2017 10:34:35 +0800 Subject: [PATCH 1/2] Release the first edition of ag5648 Signed-off-by: hans --- .../x86-64/x86-64-delta-ag5648/.gitignore | 3 + .../delta/x86-64/x86-64-delta-ag5648/Makefile | 1 + .../x86-64-delta-ag5648/modules/Makefile | 1 + .../x86-64-delta-ag5648/modules/PKG.yml | 1 + .../modules/builds/.gitignore | 1 + .../modules/builds/Makefile | 6 + .../modules/builds/dni_ag5648_psu.c | 501 +++++++++++++ .../modules/builds/dni_ag5648_sfp.c | 696 ++++++++++++++++++ .../modules/builds/dni_emc2305.c | 362 +++++++++ .../x86-64/x86-64-delta-ag5648/onlp/Makefile | 1 + .../x86-64/x86-64-delta-ag5648/onlp/PKG.yml | 1 + .../x86-64-delta-ag5648/onlp/builds/Makefile | 2 + .../onlp/builds/lib/Makefile | 45 ++ .../builds/lib/libonlp-x86-64-delta-ag5648.mk | 10 + .../onlp/builds/onlpdump/Makefile | 47 ++ .../onlp/builds/src/.module | 1 + .../onlp/builds/src/Makefile | 9 + .../onlp/builds/src/README | 6 + .../onlp/builds/src/module/auto/make.mk | 9 + .../src/module/auto/x86_64_delta_ag5648.yml | 50 ++ .../x86_64_delta_ag5648/x86_64_delta_ag5648.x | 14 + .../x86_64_delta_ag5648_config.h | 137 ++++ .../x86_64_delta_ag5648_dox.h | 26 + .../x86_64_delta_ag5648_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 | 357 +++++++++ .../onlp/builds/src/module/src/ledi.c | 429 +++++++++++ .../onlp/builds/src/module/src/make.mk | 9 + .../onlp/builds/src/module/src/platform_lib.c | 280 +++++++ .../onlp/builds/src/module/src/platform_lib.h | 224 ++++++ .../onlp/builds/src/module/src/psui.c | 229 ++++++ .../onlp/builds/src/module/src/sfpi.c | 473 ++++++++++++ .../onlp/builds/src/module/src/sysi.c | 310 ++++++++ .../onlp/builds/src/module/src/thermali.c | 160 ++++ .../module/src/x86_64_delta_ag5648_config.c | 81 ++ .../module/src/x86_64_delta_ag5648_enums.c | 10 + .../src/module/src/x86_64_delta_ag5648_int.h | 12 + .../src/module/src/x86_64_delta_ag5648_log.c | 18 + .../src/module/src/x86_64_delta_ag5648_log.h | 12 + .../module/src/x86_64_delta_ag5648_module.c | 24 + .../src/module/src/x86_64_delta_ag5648_ucli.c | 50 ++ .../platform-config/Makefile | 1 + .../platform-config/r0/Makefile | 1 + .../platform-config/r0/PKG.yml | 1 + .../r0/src/lib/x86-64-delta-ag5648-r0.yml | 30 + .../python/x86_64_delta_ag5648_r0/__init__.py | 53 ++ 48 files changed, 4865 insertions(+) create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/.gitignore create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/PKG.yml create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/.gitignore create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/Makefile create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_ag5648_psu.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_ag5648_sfp.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_emc2305.c create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/PKG.yml create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/lib/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/lib/libonlp-x86-64-delta-ag5648.mk create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/onlpdump/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/.module create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/README create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/auto/make.mk create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/auto/x86_64_delta_ag5648.yml create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648.x create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_config.h create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_dox.h create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_porting.h create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/make.mk create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/debug.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/fani.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/ledi.c create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/make.mk create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/platform_lib.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/platform_lib.h create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/psui.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/sfpi.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/sysi.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/thermali.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_config.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_enums.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_int.h create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_log.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_log.h create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_module.c create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_ucli.c create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/Makefile create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/PKG.yml create mode 100644 packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/src/lib/x86-64-delta-ag5648-r0.yml create mode 100755 packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/src/python/x86_64_delta_ag5648_r0/__init__.py diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/.gitignore b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/.gitignore new file mode 100644 index 00000000..76483140 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/.gitignore @@ -0,0 +1,3 @@ +*x86*64*delta_agc7648a*.mk +onlpdump.mk + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/PKG.yml b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/PKG.yml new file mode 100644 index 00000000..b178f5d8 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml VENDOR=delta BASENAME=x86-64-delta-ag5648 ARCH=amd64 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/.gitignore b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/.gitignore new file mode 100644 index 00000000..a65b4177 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/Makefile new file mode 100644 index 00000000..cac437cc --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-3.16-lts-x86-64-all:amd64 +KMODULES := $(wildcard *.c) +VENDOR := delta +BASENAME := x86-64-delta-ag5648 +ARCH := x86_64 +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_ag5648_psu.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_ag5648_psu.c new file mode 100755 index 00000000..6c7a1fa1 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_ag5648_psu.c @@ -0,0 +1,501 @@ +/* + * An hwmon driver for delta AG9032v1 PSU + * dps_800ab_16_d.c - Support for DPS-800AB-16 D Power Supply Module + * + * Copyright (C) 2017 Delta Networks, Inc. + * + * Aries Lin + * + * Based on ym2651y.c + * Based on ad7414.c + * + * 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 MAX_FAN_DUTY_CYCLE 100 + +/* Address scanned */ +static const unsigned short normal_i2c[] = { 0x58, I2C_CLIENT_END }; + +/* This is additional data */ +struct dps_800ab_16_d_data { + struct device *hwmon_dev; + struct mutex update_lock; + char valid; + unsigned long last_updated; /* In jiffies */ + + /* Registers value */ + u8 vout_mode; + u16 v_in; + u16 v_out; + u16 i_in; + u16 i_out; + u16 p_in; + u16 p_out; + u16 temp_input[2]; + u8 fan_fault; + u16 fan_duty_cycle[2]; + u16 fan_speed[2]; + u8 mfr_model[16]; + u8 mfr_serial[16]; +}; + +static int two_complement_to_int(u16 data, u8 valid_bit, int mask); +static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute \ + *dev_attr, const char *buf, size_t count); +static ssize_t for_linear_data(struct device *dev, struct device_attribute \ + *dev_attr, char *buf); +static ssize_t for_fan_fault(struct device *dev, struct device_attribute \ + *dev_attr, char *buf); +static ssize_t for_vout_data(struct device *dev, struct device_attribute \ + *dev_attr, char *buf); +static int dps_800ab_16_d_read_byte(struct i2c_client *client, u8 reg); +static int dps_800ab_16_d_read_word(struct i2c_client *client, u8 reg); +static int dps_800ab_16_d_write_word(struct i2c_client *client, u8 reg, \ + u16 value); +static int dps_800ab_16_d_read_block(struct i2c_client *client, u8 command, \ + u8 *data, int data_len); +static struct dps_800ab_16_d_data *dps_800ab_16_d_update_device( \ + struct device *dev); +static ssize_t for_ascii(struct device *dev, struct device_attribute \ + *dev_attr, char *buf); + +enum dps_800ab_16_d_sysfs_attributes { + PSU_V_IN, + PSU_V_OUT, + PSU_I_IN, + PSU_I_OUT, + PSU_P_IN, + PSU_P_OUT, + PSU_TEMP1_INPUT, + PSU_FAN1_FAULT, + PSU_FAN1_DUTY_CYCLE, + PSU_FAN1_SPEED, + PSU_MFR_MODEL, + PSU_MFR_SERIAL, +}; + +static int two_complement_to_int(u16 data, u8 valid_bit, int mask) +{ + u16 valid_data = data & mask; + bool is_negative = valid_data >> (valid_bit - 1); + + return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; +} + +static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute \ + *dev_attr, const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct i2c_client *client = to_i2c_client(dev); + struct dps_800ab_16_d_data *data = i2c_get_clientdata(client); + int nr = (attr->index == PSU_FAN1_DUTY_CYCLE) ? 0 : 1; + long speed; + int error; + + error = kstrtol(buf, 10, &speed); + if (error) + return error; + + if (speed < 0 || speed > MAX_FAN_DUTY_CYCLE) + return -EINVAL; + + + mutex_lock(&data->update_lock); + data->fan_duty_cycle[nr] = speed; + dps_800ab_16_d_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); + mutex_unlock(&data->update_lock); + + return count; +} + +static ssize_t for_linear_data(struct device *dev, struct device_attribute \ + *dev_attr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct dps_800ab_16_d_data *data = dps_800ab_16_d_update_device(dev); + + u16 value = 0; + int exponent, mantissa; + int multiplier = 1000; + + switch (attr->index) { + case PSU_V_IN: + value = data->v_in; + break; + case PSU_I_IN: + value = data->i_in; + break; + case PSU_I_OUT: + value = data->i_out; + break; + case PSU_P_IN: + value = data->p_in; + break; + case PSU_P_OUT: + value = data->p_out; + break; + case PSU_TEMP1_INPUT: + value = data->temp_input[0]; + break; + case PSU_FAN1_DUTY_CYCLE: + multiplier = 1; + value = data->fan_duty_cycle[0]; + break; + case PSU_FAN1_SPEED: + multiplier = 1; + value = data->fan_speed[0]; + break; + default: + break; + } + + exponent = two_complement_to_int(value >> 11, 5, 0x1f); + mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff); + + return (exponent >= 0) ? sprintf(buf, "%d\n", \ + (mantissa << exponent) * multiplier) : \ + sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); +} + +static ssize_t for_fan_fault(struct device *dev, struct device_attribute \ + *dev_attr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct dps_800ab_16_d_data *data = dps_800ab_16_d_update_device(dev); + + u8 shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; + + return sprintf(buf, "%d\n", data->fan_fault >> shift); +} + +static ssize_t for_vout_data(struct device *dev, struct device_attribute \ + *dev_attr, char *buf) +{ + struct dps_800ab_16_d_data *data = dps_800ab_16_d_update_device(dev); + int exponent, mantissa; + int multiplier = 1000; + + exponent = two_complement_to_int(data->vout_mode, 5, 0x1f); + mantissa = data->v_out; + + return (exponent > 0) ? sprintf(buf, "%d\n", \ + (mantissa << exponent) * multiplier) : \ + sprintf(buf, "%d\n", (mantissa << exponent) / (1 << -exponent)); + +} + +static ssize_t for_ascii(struct device *dev, struct device_attribute \ + *dev_attr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + struct dps_800ab_16_d_data *data = dps_800ab_16_d_update_device(dev); + u8 *ptr = NULL; + + if (!data->valid) + return 0; + + switch (attr->index) { + case PSU_MFR_MODEL: + ptr = data->mfr_model + 1; + break; + case PSU_MFR_SERIAL: + ptr = data->mfr_serial + 1; + break; + default: + return 0; + } + return sprintf(buf, "%s\n", ptr); +} +static int dps_800ab_16_d_read_byte(struct i2c_client *client, u8 reg) +{ + return i2c_smbus_read_byte_data(client, reg); +} + +static int dps_800ab_16_d_read_word(struct i2c_client *client, u8 reg) +{ + return i2c_smbus_read_word_data(client, reg); +} + +static int dps_800ab_16_d_write_word(struct i2c_client *client, u8 reg, \ + u16 value) +{ + union i2c_smbus_data data; + data.word = value; + return i2c_smbus_xfer(client->adapter, client->addr, + client->flags |= I2C_CLIENT_PEC, + I2C_SMBUS_WRITE, reg, + I2C_SMBUS_WORD_DATA, &data); + +} + +static int dps_800ab_16_d_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; + +} + +struct reg_data_byte { + u8 reg; + u8 *value; +}; + +struct reg_data_word { + u8 reg; + u16 *value; +}; + +static struct dps_800ab_16_d_data *dps_800ab_16_d_update_device( \ + struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct dps_800ab_16_d_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + + if (time_after(jiffies, data->last_updated)) { + int i, status; + u8 command; + struct reg_data_byte regs_byte[] = { + {0x20, &data->vout_mode}, + {0x81, &data->fan_fault} + }; + struct reg_data_word regs_word[] = { + {0x88, &data->v_in}, + {0x8b, &data->v_out}, + {0x89, &data->i_in}, + {0x8c, &data->i_out}, + {0x96, &data->p_out}, + {0x97, &data->p_in}, + {0x8d, &(data->temp_input[0])}, + {0x8e, &(data->temp_input[1])}, + {0x3b, &(data->fan_duty_cycle[0])}, + {0x90, &(data->fan_speed[0])}, + }; + + dev_dbg(&client->dev, "start data update\n"); + + /* one milliseconds from now */ + data->last_updated = jiffies + HZ / 1000; + + for (i = 0; i < ARRAY_SIZE(regs_byte); i++) { + status = dps_800ab_16_d_read_byte(client, + regs_byte[i].reg); + if (status < 0) { + dev_dbg(&client->dev, "reg %d, err %d\n", + regs_byte[i].reg, status); + } else { + *(regs_byte[i].value) = status; + } + } + + for (i = 0; i < ARRAY_SIZE(regs_word); i++) { + status = dps_800ab_16_d_read_word(client, + regs_word[i].reg); + if (status < 0) { + dev_dbg(&client->dev, "reg %d, err %d\n", + regs_word[i].reg, status); + } else { + *(regs_word[i].value) = status; + } + } + + command = 0x9a; /* PSU mfr_model */ + status = dps_800ab_16_d_read_block(client, command, + data->mfr_model, ARRAY_SIZE(data->mfr_model) - 1); + data->mfr_model[ARRAY_SIZE(data->mfr_model) - 1] = '\0'; + if (status < 0) { + dev_dbg(&client->dev, "reg %d, err %d\n", command, + status); + } + + command = 0x9e; /* PSU mfr_serial */ + status = dps_800ab_16_d_read_block(client, command, + data->mfr_serial, ARRAY_SIZE(data->mfr_serial) - 1); + data->mfr_serial[ARRAY_SIZE(data->mfr_serial) - 1] = '\0'; + if (status < 0) { + dev_dbg(&client->dev, "reg %d, err %d\n", command, + status); + } + + data->valid = 1; + } + + mutex_unlock(&data->update_lock); + + return data; + +} + +/* sysfs attributes for hwmon */ +static SENSOR_DEVICE_ATTR(psu_v_in, S_IRUGO, for_linear_data, NULL, PSU_V_IN); +static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, for_vout_data, NULL, PSU_V_OUT); +static SENSOR_DEVICE_ATTR(psu_i_in, S_IRUGO, for_linear_data, NULL, PSU_I_IN); +static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, for_linear_data, NULL, PSU_I_OUT); +static SENSOR_DEVICE_ATTR(psu_p_in, S_IRUGO, for_linear_data, NULL, PSU_P_IN); +static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, for_linear_data, NULL, PSU_P_OUT); +static SENSOR_DEVICE_ATTR(psu_temp1_input, \ + S_IRUGO, for_linear_data, NULL, PSU_TEMP1_INPUT); +static SENSOR_DEVICE_ATTR(psu_fan1_fault, \ + S_IRUGO, for_fan_fault, NULL, PSU_FAN1_FAULT); +static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUGO | S_IRUGO, \ + for_linear_data, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE); +static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, \ + S_IRUGO, for_linear_data, NULL, PSU_FAN1_SPEED); +static SENSOR_DEVICE_ATTR(psu_mfr_model, \ + S_IRUGO, for_ascii, NULL, PSU_MFR_MODEL); +static SENSOR_DEVICE_ATTR(psu_mfr_serial, \ + S_IRUGO, for_ascii, NULL, PSU_MFR_SERIAL); + +static struct attribute *dps_800ab_16_d_attributes[] = { + &sensor_dev_attr_psu_v_in.dev_attr.attr, + &sensor_dev_attr_psu_v_out.dev_attr.attr, + &sensor_dev_attr_psu_i_in.dev_attr.attr, + &sensor_dev_attr_psu_i_out.dev_attr.attr, + &sensor_dev_attr_psu_p_in.dev_attr.attr, + &sensor_dev_attr_psu_p_out.dev_attr.attr, + &sensor_dev_attr_psu_temp1_input.dev_attr.attr, + &sensor_dev_attr_psu_fan1_fault.dev_attr.attr, + &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, + &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, + &sensor_dev_attr_psu_mfr_model.dev_attr.attr, + &sensor_dev_attr_psu_mfr_serial.dev_attr.attr, + NULL +}; + +static const struct attribute_group dps_800ab_16_d_group = { + .attrs = dps_800ab_16_d_attributes, +}; + +static int dps_800ab_16_d_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct dps_800ab_16_d_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(*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, "new chip found\n"); + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &dps_800ab_16_d_group); + if (status) + goto exit_sysfs_create_group; + + data->hwmon_dev = hwmon_device_register(&client->dev); + if (IS_ERR(data->hwmon_dev)) { + status = PTR_ERR(data->hwmon_dev); + goto exit_hwmon_device_register; + } + + return 0; + +exit_hwmon_device_register: + sysfs_remove_group(&client->dev.kobj, &dps_800ab_16_d_group); +exit_sysfs_create_group: + kfree(data); +exit: + return status; +} + +static int dps_800ab_16_d_remove(struct i2c_client *client) +{ + struct dps_800ab_16_d_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &dps_800ab_16_d_group); + kfree(data); + + return 0; +} + +enum id_name { + dni_ag5648_psu, + dps_800ab_16_d +}; + +static const struct i2c_device_id dps_800ab_16_d_id[] = { + { "dni_ag5648_psu", dni_ag5648_psu }, + { "dps_800ab_16_d", dps_800ab_16_d }, + {} +}; +MODULE_DEVICE_TABLE(i2c, dps_800ab_16_d_id); + +/* This is the driver that will be inserted */ +static struct i2c_driver dps_800ab_16_d_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "dps_800ab_16_d", + }, + .probe = dps_800ab_16_d_probe, + .remove = dps_800ab_16_d_remove, + .id_table = dps_800ab_16_d_id, + .address_list = normal_i2c, +}; + +static int __init dps_800ab_16_d_init(void) +{ + return i2c_add_driver(&dps_800ab_16_d_driver); +} + +static void __exit dps_800ab_16_d_exit(void) +{ + i2c_del_driver(&dps_800ab_16_d_driver); +} + + +MODULE_AUTHOR("Aries Lin "); +MODULE_DESCRIPTION("DPS_800AB_16_D Driver"); +MODULE_LICENSE("GPL"); + +module_init(dps_800ab_16_d_init); +module_exit(dps_800ab_16_d_exit); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_ag5648_sfp.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_ag5648_sfp.c new file mode 100755 index 00000000..a0459f37 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_ag5648_sfp.c @@ -0,0 +1,696 @@ +/* + * An hwmon driver for agema ag5648 qsfp + * + * Copyright (C) 2017 Delta Networks, Inc. + * + * DNI + * + * Based on ad7414.c + * + * 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 I2C_BUS_2 2 +#define MASTER_CPLD 0x35 +#define SLAVE_CPLD 0x39 + +#define SFP_PRESENCE_1 0x08 +#define SFP_PRESENCE_2 0x09 +#define SFP_PRESENCE_3 0x0a +#define SFP_PRESENCE_4 0x0b +#define SFP_PRESENCE_5 0x0c +#define SFP_PRESENCE_6 0x08 +#define SFP_PRESENCE_7 0x09 +#define QSFP_PRESENCE_1 0x12 +#define QSFP_LP_MODE_1 0x11 +#define QSFP_RESET_1 0x13 + +#define DEFAULT_DISABLE 0x00 +#define QSFP_SFP_SEL_I2C_MUX 0x18 + + +/* Check cpld read results */ +#define VALIDATED_READ(_buf, _rv, _read, _invert) \ + do { \ + _rv = _read; \ + if (_rv < 0) { \ + return sprintf(_buf, "READ ERROR\n"); \ + } \ + if (_invert) { \ + _rv = ~_rv; \ + } \ + _rv &= 0xFF; \ + } while(0) \ + + +long sfp_port_data = 0; + +static const u8 cpld_to_port_table[] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36 }; + +/* Addresses scanned */ +static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END }; + +/* Each client has this additional data */ +struct ag5648_sfp_data +{ + struct device *hwmon_dev; + struct mutex update_lock; + char valid; + unsigned long last_updated; + int port; + char eeprom[256]; +}; + +static ssize_t for_eeprom(struct device *dev, struct device_attribute *dev_attr,char *buf); +static int ag5648_sfp_read_block(struct i2c_client *client, u8 command,u8 *data, int data_len); +static struct ag5648_sfp_data *ag5648_sfp_update_device(struct device *dev); +static ssize_t for_status(struct device *dev, struct device_attribute *dev_attr, char *buf); +static ssize_t set_w_port_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count); +static ssize_t for_r_port_data(struct device *dev, struct device_attribute *dev_attr, char *buf); +static ssize_t set_w_lp_mode_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count); +static ssize_t set_w_reset_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count); + +extern int i2c_cpld_read(int bus, unsigned short cpld_addr, u8 reg); +extern int i2c_cpld_write(int bus, unsigned short cpld_addr, u8 reg, u8 value); + +enum ag5648_sfp_sysfs_attributes +{ + SFP_EEPROM, + SFP_SELECT_PORT, + SFP_IS_PRESENT, + SFP_IS_PRESENT_ALL, + SFP_LP_MODE, + SFP_RESET +}; + +static ssize_t set_w_port_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) +{ + long data; + int error; + long port_t = 0; + u8 reg_t = 0x00; + + error = kstrtol(buf, 10, &data); + if(error) + return error; + + port_t = data; + + if(port_t > 0 && port_t < 9) + { /* SFP Port 1-8 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 8 && port_t < 17) + { /* SFP Port 9-16 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 16 && port_t < 25) + { /* SFP Port 17-24 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 24 && port_t < 33) + { /* SFP Port 25-32 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 32 && port_t < 37) + { /* SFP Port 33-36 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 36 && port_t < 45) + { /* SFP Port 37-44 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 44 && port_t < 49) + { /* SFP Port 45-48 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 48 && port_t < 55) + { /* QSFP Port 49-54 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else + { + + /* Disable QSFP SFP channel */ + if (i2c_cpld_write(I2C_BUS_2, MASTER_CPLD, QSFP_SFP_SEL_I2C_MUX, DEFAULT_DISABLE) < 0) + { + return -EIO; + } + + goto exit; + } + + /* Disable QSFP SFP channel */ + if (i2c_cpld_write(I2C_BUS_2, MASTER_CPLD, QSFP_SFP_SEL_I2C_MUX, DEFAULT_DISABLE) < 0) + { + return -EIO; + } + + /* Select SFP or QSFP port channel */ + if (i2c_cpld_write(I2C_BUS_2, MASTER_CPLD, reg_t, cpld_to_port_table[port_t]) < 0) + { + return -EIO; + } + +exit: + sfp_port_data = data; + return count; +} + +static ssize_t for_r_port_data(struct device *dev, struct device_attribute *dev_attr, char *buf) +{ + + if (sfp_port_data == DEFAULT_DISABLE) + { + /* Disable QSFP SFP channel */ + if (i2c_cpld_write(I2C_BUS_2, MASTER_CPLD, QSFP_SFP_SEL_I2C_MUX, DEFAULT_DISABLE) < 0) + { + return -EIO; + } + } + + return sprintf(buf, "%d\n", sfp_port_data); +} + +static ssize_t set_w_lp_mode_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) +{ + long data; + int error; + long port_t = 0; + int bit_t = 0x00; + int values = 0x00; + + error = kstrtol(buf, 10, &data); + if (error) + return error; + + port_t = sfp_port_data; + + if (port_t > 48 && port_t < 55) + { /* QSFP Port 48-53 */ + values = i2c_cpld_read(I2C_BUS_2, MASTER_CPLD, QSFP_LP_MODE_1); + if (values < 0) + return -EIO; + + /* Indicate the module is in LP mode or not + * 0 = Disable + * 1 = Enable + */ + if (data == 0) + { + bit_t = ~(1 << ((port_t - 1) % 8)); + values = values & bit_t; + } + else if (data == 1) + { + bit_t = 1 << ((port_t - 1) % 8); + values = values | bit_t; + } + else + { + return -EINVAL; + } + + if (i2c_cpld_write(I2C_BUS_2, MASTER_CPLD, QSFP_LP_MODE_1, + values) < 0) + { + return -EIO; + } + } + + return count; +} + +static ssize_t set_w_reset_data(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) +{ + long data; + int error; + long port_t = 0; + int bit_t = 0x00; + int values = 0x00; + + error = kstrtol(buf, 10, &data); + if (error) + return error; + + port_t = sfp_port_data; + + if (port_t > 48 && port_t < 55) + { /* QSFP Port 48-53 */ + values = i2c_cpld_read(I2C_BUS_2, MASTER_CPLD, QSFP_RESET_1); + if (values < 0) + return -EIO; + + /* Indicate the module Reset or not + * 0 = Reset + * 1 = Normal + */ + if (data == 0) + { + bit_t = ~(1 << ((port_t - 1) % 8)); + values = values & bit_t; + } + else if (data == 1) + { + bit_t = 1 << ((port_t - 1) % 8); + values = values | bit_t; + } + else + { + return -EINVAL; + } + + if (i2c_cpld_write(I2C_BUS_2, MASTER_CPLD, QSFP_RESET_1, + values) < 0) + { + return -EIO; + } + } + + return count; +} + +static ssize_t for_status(struct device *dev, struct device_attribute *dev_attr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + long port_t = 0; + u8 reg_t = 0x00; + u8 cpld_addr_t = 0x00; + int values[8] = {'\0'}; + int bit_t = 0x00; + + switch (attr->index) + { + case SFP_IS_PRESENT: + port_t = sfp_port_data; + + if (port_t > 0 && port_t < 9) + { /* SFP Port 1-8 */ + cpld_addr_t = SLAVE_CPLD; + reg_t = SFP_PRESENCE_1; + } + else if (port_t > 8 && port_t < 17) + { /* SFP Port 9-16 */ + cpld_addr_t = SLAVE_CPLD; + reg_t = SFP_PRESENCE_2; + } + else if (port_t > 16 && port_t < 25) + { /* SFP Port 17-24 */ + cpld_addr_t = SLAVE_CPLD; + reg_t = SFP_PRESENCE_3; + } + else if (port_t > 24 && port_t < 33) + { /* SFP Port 25-32 */ + cpld_addr_t = SLAVE_CPLD; + reg_t = SFP_PRESENCE_4; + } + else if (port_t > 32 && port_t < 37) + { /* SFP Port 33-36 */ + cpld_addr_t = SLAVE_CPLD; + reg_t = SFP_PRESENCE_5; + } + else if (port_t > 36 && port_t < 45) + { /* SFP Port 37-44 */ + cpld_addr_t = MASTER_CPLD; + reg_t = SFP_PRESENCE_6; + } + else if (port_t > 44 && port_t < 49) + { /* SFP Port 45-48 */ + cpld_addr_t = MASTER_CPLD; + reg_t = SFP_PRESENCE_7; + } + else if (port_t > 48 && port_t < 55) + { /* QSFP Port 49-54 */ + cpld_addr_t = MASTER_CPLD; + reg_t = QSFP_PRESENCE_1; + } + else + { + values[0] = 1; /* return 1, module NOT present */ + return sprintf(buf, "%d\n", values[0]); + } + + VALIDATED_READ(buf, values[0], i2c_cpld_read(I2C_BUS_2, + cpld_addr_t, reg_t), 0); + + /* SWPLD QSFP module respond */ + bit_t = 1 << ((port_t - 1) % 8); + values[0] = values[0] & bit_t; + values[0] = values[0] / bit_t; + + /* sfp_is_present value + * return 0 is module present + * return 1 is module NOT present*/ + return sprintf(buf, "%d\n", values[0]); + + case SFP_IS_PRESENT_ALL: + /* + * Report the SFP ALL PRESENCE status + * This data information form CPLD. + */ + + /* SFP_PRESENT Ports 1-8 */ + VALIDATED_READ(buf, values[0],i2c_cpld_read(I2C_BUS_2, SLAVE_CPLD, SFP_PRESENCE_1), 0); + /* SFP_PRESENT Ports 9-16 */ + VALIDATED_READ(buf, values[1],i2c_cpld_read(I2C_BUS_2, SLAVE_CPLD, SFP_PRESENCE_2), 0); + /* SFP_PRESENT Ports 17-24 */ + VALIDATED_READ(buf, values[2],i2c_cpld_read(I2C_BUS_2, SLAVE_CPLD, SFP_PRESENCE_3), 0); + /* SFP_PRESENT Ports 25-32 */ + VALIDATED_READ(buf, values[3],i2c_cpld_read(I2C_BUS_2, SLAVE_CPLD, SFP_PRESENCE_4), 0); + /* SFP_PRESENT Ports 33-40 */ + VALIDATED_READ(buf, values[4],i2c_cpld_read(I2C_BUS_2, SLAVE_CPLD, SFP_PRESENCE_5), 0); + /* SFP_PRESENT Ports 41-48 */ + VALIDATED_READ(buf, values[5],i2c_cpld_read(I2C_BUS_2, MASTER_CPLD, SFP_PRESENCE_6), 0); + /* SFP_PRESENT Ports 41-48 */ + VALIDATED_READ(buf, values[6],i2c_cpld_read(I2C_BUS_2, MASTER_CPLD, SFP_PRESENCE_7), 0); + /* QSFP_PRESENT Ports 49-54 */ + VALIDATED_READ(buf, values[7],i2c_cpld_read(I2C_BUS_2, MASTER_CPLD, QSFP_PRESENCE_1), 0); + + + /* sfp_is_present_all value + * return 0 is module present + * return 1 is module NOT present + */ + return sprintf(buf, "%02X %02X %02X %02X %02X %02X %02X %02X\n",values[0], values[1], values[2],values[3], values[4], values[5],values[6], values[7]); + + case SFP_LP_MODE: + port_t = sfp_port_data; + if (port_t > 48 && port_t < 55) + { /* QSFP Port 49-54 */ + VALIDATED_READ(buf, values[0], i2c_cpld_read(I2C_BUS_2,MASTER_CPLD, QSFP_LP_MODE_1), 0); + } + else + { + /* In AG5648 only QSFP support control LP MODE */ + values[0] = 0; + return sprintf(buf, "%d\n", values[0]); + } + + /* SWPLD QSFP module respond */ + bit_t = 1 << ((port_t - 1) % 8); + values[0] = values[0] & bit_t; + values[0] = values[0] / bit_t; + + /* sfp_lp_mode value + * return 0 is module NOT in LP mode + * return 1 is module in LP mode + */ + return sprintf(buf, "%d\n", values[0]); + + case SFP_RESET: + port_t = sfp_port_data; + if (port_t > 48 && port_t < 55) + { /* QSFP Port 49-54 */ + VALIDATED_READ(buf, values[0], i2c_cpld_read(I2C_BUS_2,MASTER_CPLD, QSFP_RESET_1), 0); + } + else + { + /* In AG5648 only QSFP support control RESET MODE */ + values[0] = 1; + return sprintf(buf, "%d\n", values[0]); + } + + /* SWPLD QSFP module respond */ + bit_t = 1 << ((port_t - 1) % 8); + values[0] = values[0] & bit_t; + values[0] = values[0] / bit_t; + + /* sfp_reset value + * return 0 is module Reset + * return 1 is module Normal*/ + return sprintf(buf, "%d\n", values[0]); + + default: + return (attr->index); + } +} + +static ssize_t for_eeprom(struct device *dev, struct device_attribute *dev_attr,char *buf) +{ + struct ag5648_sfp_data *data = ag5648_sfp_update_device(dev); + if (!data->valid) + { + return 0; + } + memcpy(buf, data->eeprom, sizeof(data->eeprom)); + return sizeof(data->eeprom); +} + +static int ag5648_sfp_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 ag5648_sfp_data *ag5648_sfp_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct ag5648_sfp_data *data = i2c_get_clientdata(client); + long port_t = 0; + u8 reg_t = 0x00; + + port_t = sfp_port_data; + + memset(data->eeprom, 0, sizeof(data->eeprom)); + + if (port_t > 0 && port_t < 9) + { /* SFP Port 1-8 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 8 && port_t < 17) + { /* SFP Port 9-16 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 16 && port_t < 25) + { /* SFP Port 17-24 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 24 && port_t < 33) + { /* SFP Port 25-32 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 32 && port_t < 37) + { /* SFP Port 33-36 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 36 && port_t < 45) + { /* SFP Port 37-44 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 44 && port_t < 49) + { /* SFP Port 45-48 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else if (port_t > 48 && port_t < 55) + { /* QSFP Port 49-54 */ + reg_t = QSFP_SFP_SEL_I2C_MUX; + } + else + { + memset(data->eeprom, 0, sizeof(data->eeprom)); + + /* Disable QSFP SFP channel */ + if (i2c_cpld_write(I2C_BUS_2, MASTER_CPLD, QSFP_SFP_SEL_I2C_MUX,DEFAULT_DISABLE) < 0) + { + goto exit; + } + + goto exit; + } + + /* Disable QSFP SFP channel */ + if (i2c_cpld_write(I2C_BUS_2, MASTER_CPLD, QSFP_SFP_SEL_I2C_MUX,DEFAULT_DISABLE) < 0) { + memset(data->eeprom, 0, sizeof(data->eeprom)); + goto exit; + } + + /* Select SFP or QSFP port channel */ + if (i2c_cpld_write(I2C_BUS_2, MASTER_CPLD, reg_t,cpld_to_port_table[port_t]) < 0) + { + memset(data->eeprom, 0, sizeof(data->eeprom)); + goto exit; + } + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated) || !data->valid) + { + int status = -1; + int i = 0; + data->valid = 0; + memset(data->eeprom, 0, sizeof(data->eeprom)); + + for (i = 0; i < sizeof(data->eeprom)/I2C_SMBUS_BLOCK_MAX; i++) + { + status = ag5648_sfp_read_block(client,i * I2C_SMBUS_BLOCK_MAX,data->eeprom + (i * I2C_SMBUS_BLOCK_MAX),I2C_SMBUS_BLOCK_MAX); + if (status < 0) + { + printk(KERN_INFO "status = %d\n", status); + dev_dbg(&client->dev,"unable to read eeprom from port(%d)\n", data->port); + + goto exit; + } + } + data->last_updated = jiffies; + data->valid = 1; + } + + exit: + mutex_unlock(&data->update_lock); + return data; +} + +/* sysfs attributes for hwmon */ +static SENSOR_DEVICE_ATTR(sfp_eeprom,S_IRUGO, for_eeprom, NULL,SFP_EEPROM); +static SENSOR_DEVICE_ATTR(sfp_select_port, S_IWUSR | S_IRUGO, for_r_port_data, set_w_port_data, SFP_SELECT_PORT); +static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, for_status, NULL, SFP_IS_PRESENT); +static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, for_status, NULL, SFP_IS_PRESENT_ALL); +static SENSOR_DEVICE_ATTR(sfp_lp_mode,S_IWUSR | S_IRUGO, for_status, set_w_lp_mode_data, SFP_LP_MODE); +static SENSOR_DEVICE_ATTR(sfp_reset, S_IWUSR | S_IRUGO, for_status, set_w_reset_data, SFP_RESET); + +static struct attribute *ag5648_sfp_attributes[] = { + &sensor_dev_attr_sfp_eeprom.dev_attr.attr, + &sensor_dev_attr_sfp_select_port.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_lp_mode.dev_attr.attr, + &sensor_dev_attr_sfp_reset.dev_attr.attr, + NULL +}; + +static const struct attribute_group ag5648_sfp_group = { + .attrs = ag5648_sfp_attributes, +}; + +static int ag5648_sfp_probe(struct i2c_client *client, const struct i2c_device_id *id) +{ + struct ag5648_sfp_data *data; + int status; + + if (!i2c_check_functionality(client->adapter,I2C_FUNC_SMBUS_I2C_BLOCK)) + { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct ag5648_sfp_data), GFP_KERNEL); + if (!data) { + status = -ENOMEM; + goto exit; + } + + mutex_init(&data->update_lock); + data->port = id->driver_data; + i2c_set_clientdata(client, data); + + dev_info(&client->dev, "chip found\n"); + + status = sysfs_create_group(&client->dev.kobj, &ag5648_sfp_group); + if (status) + goto exit_sysfs_create_group; + + data->hwmon_dev = hwmon_device_register(&client->dev); + if (IS_ERR(data->hwmon_dev)) + { + status = PTR_ERR(data->hwmon_dev); + goto exit_hwmon_device_register; + } + + dev_info(&client->dev, "%s: sfp '%s'\n", dev_name(data->hwmon_dev),client->name); + + return 0; + + exit_hwmon_device_register: + sysfs_remove_group(&client->dev.kobj, &ag5648_sfp_group); + exit_sysfs_create_group: + kfree(data); + exit: + return status; +} + +static int ag5648_sfp_remove(struct i2c_client *client) +{ + struct ag5648_sfp_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &ag5648_sfp_group); + kfree(data); + return 0; +} + +enum id_name +{ + dni_ag5648_sfp +}; + +static const struct i2c_device_id ag5648_sfp_id[] = { + { "dni_ag5648_sfp", dni_ag5648_sfp }, + {} +}; +MODULE_DEVICE_TABLE(i2c, ag5648_sfp_id); + + +static struct i2c_driver ag5648_sfp_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "dni_ag5648_sfp", + }, + .probe = ag5648_sfp_probe, + .remove = ag5648_sfp_remove, + .id_table = ag5648_sfp_id, + .address_list = normal_i2c, +}; + +static int __init ag5648_sfp_init(void) +{ + return i2c_add_driver(&ag5648_sfp_driver); +} + +static void __exit ag5648_sfp_exit(void) +{ + i2c_del_driver(&ag5648_sfp_driver); +} + +MODULE_AUTHOR("Aries Lin "); +MODULE_DESCRIPTION("ag5648 SFP Driver"); +MODULE_LICENSE("GPL"); + +module_init(ag5648_sfp_init); +module_exit(ag5648_sfp_exit); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_emc2305.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_emc2305.c new file mode 100755 index 00000000..00ed5ebe --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/modules/builds/dni_emc2305.c @@ -0,0 +1,362 @@ +/* + * + * + * Copyright (C) 2017 Delta Networks, Inc. + * + * This program is free software; you can redistribute it + * and/or modify it under the terms ofthe GNU General Public License as + * published by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * + * + * + * + * A hwmon driver for the SMSC EMC2305 fan controller + * Complete datasheet is available (6/2013) at: + * http://www.smsc.com/media/Downloads_Public/Data_Sheets/2305.pdf + */ + +#include +#include +#include +#include +#include + +extern int i2c_cpld_read(int bus, unsigned short cpld_addr, u8 reg); +extern int i2c_cpld_write(int bus, unsigned short cpld_addr, u8 reg, u8 value); + +static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count); +static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, + char *buf); +static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, + char *buf); +static ssize_t set_fan(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count); +static ssize_t set_fan_percentage(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count); +static const unsigned short normal_i2c[] = { 0x2C, 0x2D, 0x2E, 0x2F, 0x4C, + 0x4D, I2C_CLIENT_END + }; + + +#define EMC2305_REG_DEVICE 0xFD +#define EMC2305_REG_VENDOR 0xFE + +//#define FAN_MINIMUN 0x33 /*20%*/ +#define FAN_MINIMUN 0x0 /*0%*/ +#define FAN_RPM_BASED 0xAB + +#define EMC2305_REG_FAN_DRIVE(n) (0x30 + 0x10 * n) +#define EMC2305_REG_FAN_MIN_DRIVE(n) (0x38 + 0x10 * n) +#define EMC2305_REG_FAN_TACH(n) (0x3E + 0x10 * n) +#define EMC2305_REG_FAN_CONF(n) (0x32 + 0x10 * n) +#define EMC2305_REG_FAN_REAR_H_RPM(n) (0x3D + 0x10 * n) +#define EMC2305_REG_FAN_REAR_L_RPM(n) (0x3C + 0x10 * n) + +#define EMC2305_DEVICE 0x34 +#define EMC2305_VENDOR 0x5D + +struct emc2305_data +{ + struct device *hwmon_dev; + struct attribute_group attrs; + struct mutex lock; +}; + +static int emc2305_probe(struct i2c_client *client, + const struct i2c_device_id *id); +static int emc2305_detect(struct i2c_client *client, + struct i2c_board_info *info); +static int emc2305_remove(struct i2c_client *client); + +static const struct i2c_device_id emc2305_id[] = +{ + { "emc2305", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, emc2305_id); + +static struct i2c_driver emc2305_driver = +{ + .class = I2C_CLASS_HWMON, + .driver = { + .name = "emc2305", + }, + .probe = emc2305_probe, + .remove = emc2305_remove, + .id_table = emc2305_id, + .detect = emc2305_detect, + .address_list = normal_i2c, +}; + +static SENSOR_DEVICE_ATTR(fan1_input, S_IWUSR | S_IRUGO, show_fan, set_fan, 0); +static SENSOR_DEVICE_ATTR(fan2_input, S_IWUSR | S_IRUGO, show_fan, set_fan, 1); +static SENSOR_DEVICE_ATTR(fan3_input, S_IWUSR | S_IRUGO, show_fan, set_fan, 2); +static SENSOR_DEVICE_ATTR(fan4_input, S_IWUSR | S_IRUGO, show_fan, set_fan, 3); +static SENSOR_DEVICE_ATTR(fan5_input, S_IWUSR | S_IRUGO, show_fan, set_fan, 4); +static SENSOR_DEVICE_ATTR(fan1_input_percentage, S_IWUSR | S_IRUGO, show_fan, set_fan_percentage, 0); +static SENSOR_DEVICE_ATTR(fan2_input_percentage, S_IWUSR | S_IRUGO, show_fan, set_fan_percentage, 1); +static SENSOR_DEVICE_ATTR(fan3_input_percentage, S_IWUSR | S_IRUGO, show_fan, set_fan_percentage, 2); +static SENSOR_DEVICE_ATTR(fan4_input_percentage, S_IWUSR | S_IRUGO, show_fan, set_fan_percentage, 3); +static SENSOR_DEVICE_ATTR(fan5_input_percentage, S_IWUSR | S_IRUGO, show_fan, set_fan_percentage, 4); +static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0); +static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1); +static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2); +static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 3); +static SENSOR_DEVICE_ATTR(pwm5, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 4); + +static struct attribute *emc2305_attr[] = +{ + &sensor_dev_attr_fan1_input.dev_attr.attr, + &sensor_dev_attr_fan2_input.dev_attr.attr, + &sensor_dev_attr_fan3_input.dev_attr.attr, + &sensor_dev_attr_fan4_input.dev_attr.attr, + &sensor_dev_attr_fan5_input.dev_attr.attr, + &sensor_dev_attr_fan1_input_percentage.dev_attr.attr, + &sensor_dev_attr_fan2_input_percentage.dev_attr.attr, + &sensor_dev_attr_fan3_input_percentage.dev_attr.attr, + &sensor_dev_attr_fan4_input_percentage.dev_attr.attr, + &sensor_dev_attr_fan5_input_percentage.dev_attr.attr, + &sensor_dev_attr_pwm1.dev_attr.attr, + &sensor_dev_attr_pwm2.dev_attr.attr, + &sensor_dev_attr_pwm3.dev_attr.attr, + &sensor_dev_attr_pwm4.dev_attr.attr, + &sensor_dev_attr_pwm5.dev_attr.attr, + NULL +}; + + +static ssize_t set_fan_percentage(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct emc2305_data *data = i2c_get_clientdata(client); + unsigned long hsb, lsb; + unsigned long tech; + unsigned long val; + int ret; + + ret = kstrtoul(buf, 10, &val); + if (ret) + { + return ret; + } + if (val > 100) + { + return -EINVAL; + } + + if (val <= 5) + { + hsb = 0xff; /*high bit*/ + lsb = 0xe0; /*low bit*/ + } + else + { + val = val * 230; + tech = (3932160 * 2) / (val > 0 ? val : 1); + hsb = (uint8_t)(((tech << 3) >> 8) & 0x0ff); + lsb = (uint8_t)((tech << 3) & 0x0f8); + } + + mutex_lock(&data->lock); + i2c_smbus_write_byte_data(client, EMC2305_REG_FAN_REAR_H_RPM(attr->index), hsb); + i2c_smbus_write_byte_data(client, EMC2305_REG_FAN_REAR_L_RPM(attr->index), lsb); + mutex_unlock(&data->lock); + return count; +} + + +static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct emc2305_data *data = i2c_get_clientdata(client); + int val; + + + mutex_lock(&data->lock); + val = i2c_smbus_read_word_swapped(client, + EMC2305_REG_FAN_TACH(attr->index)); + mutex_unlock(&data->lock); + /* Left shift 3 bits for showing correct RPM */ + val = val >> 3; + return sprintf(buf, "%d\n", 3932160 * 2 / (val > 0 ? val : 1)); +} + +static ssize_t set_fan(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct emc2305_data *data = i2c_get_clientdata(client); + unsigned long hsb, lsb; + unsigned long tech; + unsigned long val; + int ret; + + ret = kstrtoul(buf, 10, &val); + if (ret) + { + return ret; + } + if (val > 23000) + { + return -EINVAL; + } + + if (val <= 960) + { + hsb = 0xff; /*high bit*/ + lsb = 0xe0; /*low bit*/ + } + else + { + tech = (3932160 * 2) / (val > 0 ? val : 1); + hsb = (uint8_t)(((tech << 3) >> 8) & 0x0ff); + lsb = (uint8_t)((tech << 3) & 0x0f8); + } + + mutex_lock(&data->lock); + i2c_smbus_write_byte_data(client, EMC2305_REG_FAN_REAR_H_RPM(attr->index), hsb); + i2c_smbus_write_byte_data(client, EMC2305_REG_FAN_REAR_L_RPM(attr->index), lsb); + mutex_unlock(&data->lock); + return count; +} + +static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct emc2305_data *data = i2c_get_clientdata(client); + int val; + + mutex_lock(&data->lock); + val = i2c_smbus_read_byte_data(client, + EMC2305_REG_FAN_DRIVE(attr->index)); + mutex_unlock(&data->lock); + return sprintf(buf, "%d\n", val); +} + +static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct i2c_client *client = to_i2c_client(dev); + struct emc2305_data *data = i2c_get_clientdata(client); + unsigned long val; + int ret; + + ret = kstrtoul(buf, 10, &val); + if (ret) + { + return ret; + } + if (val > 255) + { + return -EINVAL; + } + + mutex_lock(&data->lock); + i2c_smbus_write_byte_data(client, + EMC2305_REG_FAN_DRIVE(attr->index), + val); + mutex_unlock(&data->lock); + return count; +} + +static int emc2305_detect(struct i2c_client *client, + struct i2c_board_info *info) +{ + struct i2c_adapter *adapter = client->adapter; + int vendor, device; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WORD_DATA)) + { + return -ENODEV; + } + + vendor = i2c_smbus_read_byte_data(client, EMC2305_REG_VENDOR); + if (vendor != EMC2305_VENDOR) + { + return -ENODEV; + } + + device = i2c_smbus_read_byte_data(client, EMC2305_REG_DEVICE); + if (device != EMC2305_DEVICE) + { + return -ENODEV; + } + + strlcpy(info->type, "emc2305", I2C_NAME_SIZE); + + return 0; +} + +static int emc2305_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct emc2305_data *data; + int err; + int i; + + data = devm_kzalloc(&client->dev, sizeof(struct emc2305_data), + GFP_KERNEL); + if (!data) + { + return -ENOMEM; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->lock); + + dev_info(&client->dev, "%s chip found\n", client->name); + + data->attrs.attrs = emc2305_attr; + err = sysfs_create_group(&client->dev.kobj, &data->attrs); + if (err) + { + return err; + } + + data->hwmon_dev = hwmon_device_register(&client->dev); + if (IS_ERR(data->hwmon_dev)) + { + err = PTR_ERR(data->hwmon_dev); + goto exit_remove; + } + + for (i = 0; i < 5; i++) + { + /* set minimum drive to 0% */ + i2c_smbus_write_byte_data(client, EMC2305_REG_FAN_MIN_DRIVE(i), FAN_MINIMUN); + i2c_smbus_write_byte_data(client, EMC2305_REG_FAN_CONF(i), FAN_RPM_BASED); + } + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &data->attrs); + return err; +} + +static int emc2305_remove(struct i2c_client *client) +{ + struct emc2305_data *data = i2c_get_clientdata(client); + + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &data->attrs); + return 0; +} + +module_i2c_driver(emc2305_driver); + +MODULE_AUTHOR("Neal Tai"); +MODULE_DESCRIPTION("SMSC EMC2305 fan controller driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/PKG.yml b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/PKG.yml new file mode 100644 index 00000000..67b0a462 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-delta-ag5648 ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/Makefile new file mode 100644 index 00000000..e7437cb2 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/lib/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/lib/Makefile new file mode 100644 index 00000000..bec767b5 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/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-delta-ag5648 +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF x86_64_delta_ag5648 onlplib +DEPENDMODULE_HEADERS := sff + +include $(BUILDER)/dependmodules.mk + +SHAREDLIB := libonlp-x86-64-delta-ag5648.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/delta/x86-64/x86-64-delta-ag5648/onlp/builds/lib/libonlp-x86-64-delta-ag5648.mk b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/lib/libonlp-x86-64-delta-ag5648.mk new file mode 100644 index 00000000..dc74c4a3 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/lib/libonlp-x86-64-delta-ag5648.mk @@ -0,0 +1,10 @@ + +############################################################################### +# +# Inclusive Makefile for the libonlp-x86-64-delta-ag5648 module. +# +# Autogenerated 2017-03-15 04:06:44.303111 +# +############################################################################### +libonlp-x86-64-delta-ag5648_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/onlpdump/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/onlpdump/Makefile new file mode 100644 index 00000000..69f7730b --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/onlpdump/Makefile @@ -0,0 +1,47 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# Copyright (C) 2017 Delta Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# 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_delta_ag5648 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/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/.module b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/.module new file mode 100644 index 00000000..964bcf3f --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/.module @@ -0,0 +1 @@ +name: x86_64_delta_ag5648 diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/Makefile new file mode 100644 index 00000000..d7cc3764 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +include ../../init.mk +MODULE := x86_64_delta_ag5648 +AUTOMODULE := x86_64_delta_ag5648 +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/README b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/README new file mode 100644 index 00000000..f4bee216 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/README @@ -0,0 +1,6 @@ +############################################################################### +# +# x86_64_delta_ag5648 README +# +############################################################################### + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/auto/make.mk b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/auto/make.mk new file mode 100644 index 00000000..71e91a55 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/auto/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# x86_64_delta_ag5648 Autogeneration +# +############################################################################### +x86_64_delta_ag5648_AUTO_DEFS := module/auto/x86_64_delta_ag5648.yml +x86_64_delta_ag5648_AUTO_DIRS := module/inc/x86_64_delta_ag5648 module/src +include $(BUILDER)/auto.mk + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/auto/x86_64_delta_ag5648.yml b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/auto/x86_64_delta_ag5648.yml new file mode 100644 index 00000000..71c8479c --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/auto/x86_64_delta_ag5648.yml @@ -0,0 +1,50 @@ +############################################################################### +# +# x86_64_delta_ag5648 Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- X86_64_DELTA_AG5648_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- X86_64_DELTA_AG5648_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- X86_64_DELTA_AG5648_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- X86_64_DELTA_AG5648_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- X86_64_DELTA_AG5648_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: x86_64_delta_ag5648_CONFIG_PORTING_STDLIB +- X86_64_DELTA_AG5648_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 +- X86_64_DELTA_AG5648_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION: + doc: "Assume chassis fan direction is the same as the PSU fan direction." + default: 0 + + +definitions: + cdefs: + X86_64_DELTA_AG5648_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_delta_ag5648_config + + portingmacro: + x86_64_delta_ag5648: + macros: + - malloc + - free + - memset + - memcpy + - strncpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648.x b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648.x new file mode 100644 index 00000000..33bb5af0 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648.x @@ -0,0 +1,14 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ + + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_config.h b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_config.h new file mode 100644 index 00000000..dd1200bd --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_config.h @@ -0,0 +1,137 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_delta_ag5648 Configuration Header + * + * @addtogroup x86_64_delta_ag5648-config + * @{ + * + *****************************************************************************/ +#ifndef __X86_64_DELTA_AG5648_CONFIG_H__ +#define __X86_64_DELTA_AG5648_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef X86_64_DELTA_AG5648_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * X86_64_DELTA_AG5648_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef X86_64_DELTA_AG5648_CONFIG_INCLUDE_LOGGING +#define X86_64_DELTA_AG5648_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * X86_64_DELTA_AG5648_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef X86_64_DELTA_AG5648_CONFIG_LOG_OPTIONS_DEFAULT +#define X86_64_DELTA_AG5648_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * X86_64_DELTA_AG5648_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef X86_64_DELTA_AG5648_CONFIG_LOG_BITS_DEFAULT +#define X86_64_DELTA_AG5648_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * X86_64_DELTA_AG5648_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef X86_64_DELTA_AG5648_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define X86_64_DELTA_AG5648_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB +#define X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * X86_64_DELTA_AG5648_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef X86_64_DELTA_AG5648_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define X86_64_DELTA_AG5648_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB +#endif + +/** + * X86_64_DELTA_AG5648_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef X86_64_DELTA_AG5648_CONFIG_INCLUDE_UCLI +#define X86_64_DELTA_AG5648_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * X86_64_DELTA_AG5648_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * + * Assume chassis fan direction is the same as the PSU fan direction. */ + + +#ifndef X86_64_DELTA_AG5648_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define X86_64_DELTA_AG5648_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct x86_64_delta_ag5648_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_delta_ag5648_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_delta_ag5648_config_settings table. */ +extern x86_64_delta_ag5648_config_settings_t x86_64_delta_ag5648_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_delta_ag5648_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_delta_ag5648_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_delta_ag5648_porting.h" + +#endif /* __X86_64_DELTA_AG5648_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_dox.h b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_dox.h new file mode 100644 index 00000000..08d73372 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_delta_ag5648 Doxygen Header + * + *****************************************************************************/ +#ifndef __X86_64_DELTA_AG5648_DOX_H__ +#define __X86_64_DELTA_AG5648_DOX_H__ + +/** + * @defgroup x86_64_delta_ag5648 x86_64_delta_ag5648 - x86_64_delta_ag5648 Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_delta_ag5648-x86_64_delta_ag5648 Public Interface + * @defgroup x86_64_delta_ag5648-config Compile Time Configuration + * @defgroup x86_64_delta_ag5648-porting Porting Macros + * + * @} + * + */ + +#endif /* __X86_64_DELTA_AG5648_DOX_H__ */ diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_porting.h b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_porting.h new file mode 100644 index 00000000..2512d3d7 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/inc/x86_64_delta_ag5648/x86_64_delta_ag5648_porting.h @@ -0,0 +1,107 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_delta_ag5648 Porting Macros. + * + * @addtogroup x86_64_delta_ag5648-porting + * @{ + * + *****************************************************************************/ +#ifndef __X86_64_DELTA_AG5648_PORTING_H__ +#define __X86_64_DELTA_AG5648_PORTING_H__ + + +/* */ +#if X86_64_DELTA_AG5648_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef x86_64_delta_ag5648_MALLOC + #if defined(GLOBAL_MALLOC) + #define x86_64_delta_ag5648_MALLOC GLOBAL_MALLOC + #elif X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB == 1 + #define x86_64_delta_ag5648_MALLOC malloc + #else + #error The macro x86_64_delta_ag5648_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_delta_ag5648_FREE + #if defined(GLOBAL_FREE) + #define x86_64_delta_ag5648_FREE GLOBAL_FREE + #elif X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB == 1 + #define x86_64_delta_ag5648_FREE free + #else + #error The macro x86_64_delta_ag5648_FREE is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_delta_ag5648_MEMSET + #if defined(GLOBAL_MEMSET) + #define x86_64_delta_ag5648_MEMSET GLOBAL_MEMSET + #elif X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB == 1 + #define x86_64_delta_ag5648_MEMSET memset + #else + #error The macro x86_64_delta_ag5648_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_delta_ag5648_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define x86_64_delta_ag5648_MEMCPY GLOBAL_MEMCPY + #elif X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB == 1 + #define x86_64_delta_ag5648_MEMCPY memcpy + #else + #error The macro x86_64_delta_ag5648_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_delta_ag5648_STRNCPY + #if defined(GLOBAL_STRNCPY) + #define x86_64_delta_ag5648_STRNCPY GLOBAL_STRNCPY + #elif X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB == 1 + #define x86_64_delta_ag5648_STRNCPY strncpy + #else + #error The macro x86_64_delta_ag5648_STRNCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_delta_ag5648_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define x86_64_delta_ag5648_VSNPRINTF GLOBAL_VSNPRINTF + #elif X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB == 1 + #define x86_64_delta_ag5648_VSNPRINTF vsnprintf + #else + #error The macro x86_64_delta_ag5648_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_delta_ag5648_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define x86_64_delta_ag5648_SNPRINTF GLOBAL_SNPRINTF + #elif X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB == 1 + #define x86_64_delta_ag5648_SNPRINTF snprintf + #else + #error The macro x86_64_delta_ag5648_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_delta_ag5648_STRLEN + #if defined(GLOBAL_STRLEN) + #define x86_64_delta_ag5648_STRLEN GLOBAL_STRLEN + #elif X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB == 1 + #define x86_64_delta_ag5648_STRLEN strlen + #else + #error The macro x86_64_delta_ag5648_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* _X86_64_DELTA_AG5648_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/make.mk b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/make.mk new file mode 100644 index 00000000..1cf9cbcc --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/make.mk @@ -0,0 +1,10 @@ +############################################################################### +# +# +# +############################################################################### +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_delta_ag5648_INCLUDES := -I $(THIS_DIR)inc +x86_64_delta_ag5648_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_delta_ag5648_DEPENDMODULE_ENTRIES := init:x86_64_delta_ag5648 ucli:x86_64_delta_ag5648 + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/Makefile new file mode 100644 index 00000000..fe12520a --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# Local source generation targets. +# +############################################################################### + +ucli: + @../../../../tools/uclihandlers.py x86_64_delta_ag5648_ucli.c + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/debug.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/debug.c new file mode 100644 index 00000000..4228e6f3 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/debug.c @@ -0,0 +1,45 @@ +#include "x86_64_delta_ag5648_int.h" + +#if X86_64_DELTA_AG5648_CONFIG_INCLUDE_DEBUG == 1 + +#include + +static char help__[] = + "Usage: debug [options]\n" + " -c CPLD Versions\n" + " -h Help\n" + ; + +int +x86_64_delta_ag5648_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/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/fani.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/fani.c new file mode 100755 index 00000000..3c3014e0 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/fani.c @@ -0,0 +1,357 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright (C) 2017 Delta Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * 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" +#include + +typedef struct fan_path_S +{ + char *status; + char *speed; + char *ctrl_speed; +}fan_path_T; + +static fan_path_T fan_path[] = /* must map with onlp_fan_id */ +{ + { NULL, NULL, NULL }, + { "/3-004d/fan1_fault", "/3-004d/fan1_input", "/3-004d/fan1_input" }, + { "/3-004d/fan2_fault", "/3-004d/fan2_input", "/3-004d/fan2_input" }, + { "/3-004d/fan3_fault", "/3-004d/fan3_input", "/3-004d/fan3_input" }, + { "/3-004d/fan4_fault", "/3-004d/fan4_input", "/3-004d/fan4_input" }, + { "/5-004d/fan1_fault", "/5-004d/fan1_input", "/5-004d/fan1_input" }, + { "/5-004d/fan2_fault", "/5-004d/fan2_input", "/5-004d/fan2_input" }, + { "/5-004d/fan3_fault", "/5-004d/fan3_input", "/5-004d/fan3_input" }, + { "/5-004d/fan4_fault", "/5-004d/fan4_input", "/5-004d/fan4_input" }, + { "/6-0059/psu_fan1_fault", "/6-0059/psu_fan1_speed_rpm", "/6-0059/psu_fan1_duty_cycle_percentage" }, + { "/6-0058/psu_fan1_fault", "/6-0058/psu_fan1_speed_rpm", "/6-0058/psu_fan1_duty_cycle_percentage" } +}; + +#define MAKE_FAN_INFO_NODE_ON_FAN_BOARD(id) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##id##_ON_FAN_BOARD), "Chassis Fan "#id, 0 }, \ + 0x0, \ + (ONLP_FAN_CAPS_SET_RPM | ONLP_FAN_CAPS_GET_RPM), \ + 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, \ + (ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE), \ + 0, \ + 0, \ + ONLP_FAN_MODE_INVALID, \ + } + +/* Static fan information */ +onlp_fan_info_t linfo[] = { + { }, /* Not used */ + MAKE_FAN_INFO_NODE_ON_FAN_BOARD(1), + MAKE_FAN_INFO_NODE_ON_FAN_BOARD(2), + MAKE_FAN_INFO_NODE_ON_FAN_BOARD(3), + MAKE_FAN_INFO_NODE_ON_FAN_BOARD(4), + MAKE_FAN_INFO_NODE_ON_FAN_BOARD(5), + MAKE_FAN_INFO_NODE_ON_FAN_BOARD(6), + MAKE_FAN_INFO_NODE_ON_FAN_BOARD(7), + MAKE_FAN_INFO_NODE_ON_FAN_BOARD(8), + 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) + +static int +dni_fani_info_get_fan(int local_id, onlp_fan_info_t* info) +{ + int rpm = 0; + char fullpath[100] = {0}; + uint8_t present_bit=0x00, bit=0x00; + + sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].speed); + rpm = dni_i2c_lock_read_attribute(NULL, fullpath); + info->rpm = rpm; + + if(info->rpm == FAN_ZERO_RPM) + info->rpm = 0; + + /* get speed percentage from rpm */ + if( local_id < ALL_FAN_TRAY_EXIST ){ + info->percentage = (info->rpm * 100)/MAX_FRONT_FAN_SPEED; + } + else{ + info->percentage = (info->rpm * 100)/MAX_REAR_FAN_SPEED; + } + present_bit = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_STATUS_REG); + + switch(local_id) + { + case FAN_1_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + if((present_bit & (bit+1)) == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + case FAN_2_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + if((present_bit & ((bit+1)<<1)) == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + case FAN_3_ON_FAN_BOARD: + case FAN_7_ON_FAN_BOARD: + if((present_bit & ((bit+1)<<2)) == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + case FAN_4_ON_FAN_BOARD: + case FAN_8_ON_FAN_BOARD: + if((present_bit & ((bit+1)<<3)) == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + } + return ONLP_STATUS_OK; +} + + +static int +dni_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) +{ + int r_data = 0; + char fullpath[80] = {0}; + + dev_info_t dev_info; + /* Select PSU member */ + switch (local_id) { + case FAN_1_ON_PSU1: + dev_info.addr = PSU1_EEPROM; + break; + case FAN_1_ON_PSU2: + dev_info.addr = PSU2_EEPROM; + break; + default: + return ONLP_STATUS_E_INVALID; + } + + dev_info.bus = I2C_BUS_6; + dev_info.offset = 0x00; /* In EEPROM address 0x00 */ + dev_info.flags = DEFAULT_FLAG; + + /* Check PSU is PRESENT or not + * Read PSU EEPROM 1 byte from adress 0x00 + * if not present, return Negative value. + */ + if(dni_i2c_lock_read(NULL, &dev_info) >= 0) { + info->status |= ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F; + } + + /* Check PSU FAN is fault or not + * Read PSU FAN Fault from psu_fan1_fault + * Return 1 is PSU fan fault + */ + sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].status); + r_data = dni_i2c_lock_read_attribute(NULL, fullpath); + + if (r_data == 1) { + info->status |= ONLP_FAN_STATUS_FAILED; + } + + /* Read PSU FAN speed from psu_fan1_speed_rpm */ + sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].speed); + r_data = dni_i2c_lock_read_attribute(NULL, fullpath); + info->rpm = r_data; + + /* get speed percentage from rpm */ + info->percentage = ((info->rpm) * 100) / MAX_PSU_FAN_SPEED; + return ONLP_STATUS_OK; +} + +/* + * This function will be called prior to all of onlp_fani_* functions. + */ +int +onlp_fani_init(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) +{ + int rc = 0; + int local_id; + VALIDATE(id); + local_id = ONLP_OID_ID_GET(id); + *info = linfo[local_id]; + + switch (local_id) + { + case FAN_1_ON_PSU1: + case FAN_1_ON_PSU2: + rc = dni_fani_info_get_fan_on_psu(local_id, info); + break; + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + case FAN_4_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + case FAN_7_ON_FAN_BOARD: + case FAN_8_ON_FAN_BOARD: + rc = dni_fani_info_get_fan(local_id, info); + break; + default: + rc = ONLP_STATUS_E_INVALID; + break; + } + + return rc; +} + + +/* + * This function sets the speed of the given fan in RPM. + * + * This function will only be called if the fan supprots the RPM_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int +onlp_fani_rpm_set(onlp_oid_t id, int rpm) +{ + int local_id; + char data[10] = {0}; + char fullpath[70] = {0}; + VALIDATE(id); + local_id = ONLP_OID_ID_GET(id); + + /* get fullpath */ + switch (local_id) + { + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + case FAN_4_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + case FAN_7_ON_FAN_BOARD: + case FAN_8_ON_FAN_BOARD: + sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].ctrl_speed); + break; + default: + return ONLP_STATUS_E_INVALID; + } + sprintf(data, "%d", rpm); + dni_i2c_lock_write_attribute(NULL, data, fullpath); + return ONLP_STATUS_OK; +} + +/* + * This function sets the fan speed of the given OID as a percentage. + * + * This will only be called if the OID has the PERCENTAGE_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int +onlp_fani_percentage_set(onlp_oid_t id, int percentage) +{ + int local_id; + char data[10] = {0}; + char fullpath[70] = {0}; + VALIDATE(id); + local_id = ONLP_OID_ID_GET(id); + + /* Select PSU member */ + switch (local_id) { + case FAN_1_ON_PSU1: + case FAN_1_ON_PSU2: + break; + default: + return ONLP_STATUS_E_INVALID; + } + sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].ctrl_speed); + + /* Write percentage to psu_fan1_duty_cycle_percentage */ + sprintf(data, "%d", percentage); + dni_i2c_lock_write_attribute(NULL, data, fullpath); + + 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/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/ledi.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/ledi.c new file mode 100755 index 00000000..e697dce4 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/ledi.c @@ -0,0 +1,429 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright (C) 2017 Delta Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include "platform_lib.h" + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_LED(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t linfo[] = +{ + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_FRONT_FAN), "FRONT LED (FAN LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_FRONT_SYS), "FRONT LED (SYS LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_FRONT_PWR), "FRONT LED (PWR LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING, + }, + { + { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1), "FAN TRAY 1 LED", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2), "FAN TRAY 2 LED", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3), "FAN TRAY 3 LED", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4), "FAN TRAY 4 LED", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_RED | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, +}; +/* + * This function will be called prior to any other onlp_ledi_* functions. + */ +int +onlp_ledi_init(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int r_data = 0, fantray_present = -1; + VALIDATE(id); + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[ONLP_OID_ID_GET(id)]; + + dev_info_t dev_info; + dev_info.bus = I2C_BUS_3; + dev_info.offset = 0x00; + dev_info.flags = DEFAULT_FLAG; + + /* Set front panel's mode of leds */ + r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,LED_REG); + int local_id = ONLP_OID_ID_GET(id); + switch(local_id) + { + case LED_FRONT_FAN: + if((r_data & 0xc0) == 0x80) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0xc0) == 0x40) + info->mode = ONLP_LED_MODE_ORANGE; + else if((r_data & 0xc0) == 0xc0) + info->mode = ONLP_LED_MODE_ORANGE_BLINKING; + else + info->mode = ONLP_LED_MODE_OFF; + break; + case LED_FRONT_SYS: + if((r_data & 0x30) == 0x10) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x30) == 0x20) + info->mode = ONLP_LED_MODE_ORANGE; + else if((r_data & 0x30) == 0x00) + info->mode = ONLP_LED_MODE_GREEN_BLINKING; + else + return ONLP_STATUS_E_INTERNAL; + break; + case LED_FRONT_PWR: + if((r_data & 0x06) == 0x04) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x06) == 0x02) + info->mode = ONLP_LED_MODE_ORANGE; + else if((r_data & 0x06) == 0x06) + info->mode = ONLP_LED_MODE_ORANGE_BLINKING; + else + info->mode = ONLP_LED_MODE_OFF; + break; + case LED_REAR_FAN_TRAY_1: + dev_info.addr = FAN_TRAY_1; + r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG); + fantray_present = dni_i2c_lock_read(NULL, &dev_info); + if(fantray_present >= 0) + { + if((r_data & 0x01) == 0x01) + info->mode = ONLP_LED_MODE_GREEN; + else + info->mode = ONLP_LED_MODE_ORANGE; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + case LED_REAR_FAN_TRAY_2: + dev_info.addr = FAN_TRAY_2; + r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG); + fantray_present = dni_i2c_lock_read(NULL, &dev_info); + if(fantray_present >= 0) + { + if((r_data & 0x04) == 0x04) + info->mode = ONLP_LED_MODE_GREEN; + else + info->mode = ONLP_LED_MODE_ORANGE; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + case LED_REAR_FAN_TRAY_3: + dev_info.addr = FAN_TRAY_3; + r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG); + fantray_present = dni_i2c_lock_read(NULL, &dev_info); + if(fantray_present >= 0) + { + if((r_data & 0x10) == 0x10) + info->mode = ONLP_LED_MODE_GREEN; + else + info->mode = ONLP_LED_MODE_ORANGE; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + case LED_REAR_FAN_TRAY_4: + dev_info.addr = FAN_TRAY_4; + r_data = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG); + fantray_present = dni_i2c_lock_read(NULL, &dev_info); + if(fantray_present >= 0) + { + if((r_data & 0x40) == 0x40) + info->mode = ONLP_LED_MODE_GREEN; + else + info->mode = ONLP_LED_MODE_ORANGE; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + default: + break; + } + /* Set the on/off status */ + if (info->mode == ONLP_LED_MODE_OFF) + info->status |= ONLP_LED_STATUS_FAILED; + else + info->status |=ONLP_LED_STATUS_PRESENT; + 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 == 0) + onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF); + else + onlp_ledi_mode_set(id,ONLP_LED_MODE_AUTO); + return ONLP_STATUS_OK; +} + +/* + * 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) +{ + VALIDATE(id); + int local_id = ONLP_OID_ID_GET(id); + int i = 0, count = 0 ,fan_board_not_present_count = 0 , fan_stat2_reg_mask = 0 , fan_stat1_reg_mask = 0 ; + int fantray_present = -1, rpm = 0, rpm1 = 0; + uint8_t front_panel_led_value, power_state,fan_tray_led_reg_value, fan_led_status_value, fan_tray_pres_value; + uint8_t psu1_state, psu2_state, alarm_reg_value, fan_tray_interface_detected_value; + dev_info_t dev_info; + dev_info.bus = I2C_BUS_3; + dev_info.offset = 0x00; + dev_info.flags = DEFAULT_FLAG; + + front_panel_led_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,LED_REG); + fan_tray_led_reg_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG); + fan_led_status_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_STAT1_REG); + fan_tray_pres_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_STAT2_REG); + alarm_reg_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,ALARM_REG); + + switch(local_id) + { + case LED_FRONT_FAN: + /* Clean the bit 7,6 */ + front_panel_led_value &= ~0xC0; + fan_board_not_present_count = 0; + /* Read cpld fan status to check present. Fan tray 1-4 */ + for(i = 0; i < 4; i++) + { + fan_stat2_reg_mask = 0x01 << i; + fan_stat1_reg_mask = 0x01 << (i * 2); + if((fan_tray_pres_value & fan_stat2_reg_mask) == fan_stat2_reg_mask) + fan_board_not_present_count++; + else if((fan_led_status_value & fan_stat1_reg_mask) == fan_stat1_reg_mask) + count++; + } + /* Set front light of FAN */ + if(count == ALL_FAN_TRAY_EXIST) + { + front_panel_led_value |= 0x80;/*Solid green, FAN operates normally.*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } + else if (fan_board_not_present_count > 0) + { + front_panel_led_value |= 0xc0;/*Blinking Yellow , FAN is failed */ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } + else + { + front_panel_led_value |= 0x40;/*Solid Amber FAN operating is NOT present */ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } + + break; + + case LED_FRONT_PWR: + /* Clean bit 2,1 */ + front_panel_led_value &= ~0x06; + /* switch CPLD to PSU 1 */ + dev_info.bus = I2C_BUS_6; + dev_info.addr = PSU1_EEPROM; + psu1_state = dni_i2c_lock_read(NULL, &dev_info); + /* switch CPLD to PSU 2 */ + dev_info.addr = PSU2_EEPROM; + psu2_state = dni_i2c_lock_read(NULL, &dev_info); + + if(psu1_state == 1 && psu2_state == 1) + { + power_state = dni_lock_cpld_read_attribute(MASTER_CPLD_PATH,PSU_STAT_REG); + + if((power_state & 0x40) == 0x40 || (power_state & 0x04) == 0x04) + { + front_panel_led_value |= 0x06; /*Blinking Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } + else + { + front_panel_led_value |= 0x04; /*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + } + } + else + front_panel_led_value |= 0x02; /*Solid Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,LED_REG, front_panel_led_value); + break; + + case LED_FRONT_SYS: + /* Clean bit 4,5 */ + front_panel_led_value &= ~0x30; + fan_board_not_present_count = 0; + /* Read fan eeprom to check present */ + for(i = 0;i < 4; i++) + { + fan_stat2_reg_mask = 0x01 << i; + if((fan_tray_pres_value & fan_stat2_reg_mask) == fan_stat2_reg_mask) + fan_board_not_present_count++; + } + if(fan_board_not_present_count > 0 || (alarm_reg_value & 0xff) == 0xff) + { + fan_tray_interface_detected_value = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,INTERRUPT_REG); + if(fan_tray_interface_detected_value == 0xfe || (alarm_reg_value & 0xff) == 0xff) + { + front_panel_led_value |= 0x20; + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH, LED_REG, front_panel_led_value); + } + } + else + { + front_panel_led_value |= 0x10; + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH, LED_REG, front_panel_led_value); + } + break; + + case LED_REAR_FAN_TRAY_1: + dev_info.addr = FAN_TRAY_1; + fantray_present = dni_i2c_lock_read(NULL, &dev_info); + rpm = dni_i2c_lock_read_attribute(NULL, FAN1_FRONT); + rpm1 = dni_i2c_lock_read_attribute(NULL, FAN1_REAR); + fan_tray_led_reg_value &= ~0x03; + if(fantray_present >= 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) + { + fan_tray_led_reg_value |= 0x01;/*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } + else + { + fan_tray_led_reg_value |= 0x02;/*Solid Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } + break; + + case LED_REAR_FAN_TRAY_2: + dev_info.addr = FAN_TRAY_2; + fantray_present = dni_i2c_lock_read(NULL, &dev_info); + rpm = dni_i2c_lock_read_attribute(NULL, FAN2_FRONT); + rpm1 = dni_i2c_lock_read_attribute(NULL, FAN2_REAR); + fan_tray_led_reg_value &= ~0x0c; + + if(fantray_present >= 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) + { + fan_tray_led_reg_value |= 0x04;/*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } + else + { + fan_tray_led_reg_value |= 0x08;/*Solid Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } + break; + + case LED_REAR_FAN_TRAY_3: + dev_info.addr = FAN_TRAY_3; + fantray_present = dni_i2c_lock_read(NULL, &dev_info); + fan_tray_led_reg_value &= ~0x30; + rpm = dni_i2c_lock_read_attribute(NULL, FAN3_FRONT); + rpm1 = dni_i2c_lock_read_attribute(NULL, FAN3_REAR); + if(fantray_present >= 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) + { + fan_tray_led_reg_value |= 0x10;/*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } + else + { + fan_tray_led_reg_value |= 0x20;/*Solid Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } + break; + + case LED_REAR_FAN_TRAY_4: + dev_info.addr = FAN_TRAY_4; + fantray_present = dni_i2c_lock_read(NULL, &dev_info); + fan_tray_led_reg_value &= ~0xc0; + rpm = dni_i2c_lock_read_attribute(NULL, FAN4_FRONT); + rpm1 = dni_i2c_lock_read_attribute(NULL, FAN4_REAR); + if(fantray_present >= 0 && rpm != FAN_ZERO_RPM && rpm !=0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) + { + fan_tray_led_reg_value |= 0x40; /*Solid Green*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } + else + { + fan_tray_led_reg_value |= 0x80;/*Solid Amber*/ + dni_lock_cpld_write_attribute(SLAVE_CPLD_PATH,FAN_TRAY_LED_REG, fan_tray_led_reg_value); + } + } + 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/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/make.mk b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/make.mk new file mode 100644 index 00000000..7eaf61f9 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### + +LIBRARY := x86_64_delta_ag5648 +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/platform_lib.c new file mode 100755 index 00000000..648296d3 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/platform_lib.c @@ -0,0 +1,280 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright (C) 2017 Delta Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include "platform_lib.h" +#include +#include +#include + +int dni_i2c_read_attribute_binary(char *filename, char *buffer, int buf_size, int data_len) +{ + int fd; + int len; + + if ((buffer == NULL) || (buf_size < 0)) { + return -1; + } + + if ((fd = open(filename, O_RDONLY)) == -1) { + return -1; + } + + if ((len = read(fd, buffer, buf_size)) < 0) { + close(fd); + return -1; + } + + if ((close(fd) == -1)) { + return -1; + } + + if ((len > buf_size) || (data_len != 0 && len != data_len)) { + return -1; + } + + return 0; +} + +int dni_i2c_read_attribute_string(char *filename, char *buffer, int buf_size, int data_len) +{ + int ret; + + if (data_len >= buf_size) { + return -1; + } + + ret = dni_i2c_read_attribute_binary(filename, buffer, buf_size-1, data_len); + + if (ret == 0) { + buffer[buf_size-1] = '\0'; + } + + return ret; +} + +/* Lock function */ +int dni_i2c_lock_read( mux_info_t * mux_info, dev_info_t * dev_info) +{ + int r_data=0; + + pthread_mutex_lock(&mutex); + if(mux_info != NULL) + { + char cpld_path[100] = {0}; + sprintf(cpld_path, "%s/%d-%04x", PREFIX_PATH, mux_info->bus, mux_info->addr); + dni_lock_cpld_write_attribute(cpld_path, mux_info->offset, mux_info->channel); + } + if(dev_info->size == 1) + r_data = onlp_i2c_readb(dev_info->bus, dev_info->addr, dev_info->offset, dev_info->flags); + else + r_data = onlp_i2c_readw(dev_info->bus, dev_info->addr, dev_info->offset, dev_info->flags); + + pthread_mutex_unlock(&mutex); + return r_data; +} + +int dni_i2c_lock_write( mux_info_t * mux_info, dev_info_t * dev_info) +{ + pthread_mutex_lock(&mutex); + if(mux_info != NULL) + { + char cpld_path[100] = {0}; + sprintf(cpld_path, "%s/%d-%04x", PREFIX_PATH, mux_info->bus, mux_info->addr); + dni_lock_cpld_write_attribute(cpld_path, mux_info->offset, mux_info->channel); + } + /* Write size */ + if(dev_info->size == 1) + onlp_i2c_write(dev_info->bus, dev_info->addr, dev_info->offset, 1, &dev_info->data_8, dev_info->flags); + else + onlp_i2c_writew(dev_info->bus, dev_info->addr, dev_info->offset, dev_info->data_16, dev_info->flags); + + pthread_mutex_unlock(&mutex); + return 0; +} + +int dni_i2c_lock_read_attribute(mux_info_t * mux_info, char * fullpath) +{ + int fd, len, nbytes = 10; + char r_data[10] = {0}; + + pthread_mutex_lock(&mutex); + if(mux_info != NULL) + { + char cpld_path[100] = {0}; + sprintf(cpld_path, "%s/%d-%04x", PREFIX_PATH, mux_info->bus, mux_info->addr); + dni_lock_cpld_write_attribute(cpld_path, mux_info->offset, mux_info->channel); + } + if ((fd = open(fullpath, O_RDONLY)) == -1) + { + goto ERROR; + } + if ((len = read(fd, r_data, nbytes)) <= 0) + { + goto ERROR; + } + close(fd); + pthread_mutex_unlock(&mutex); + return atoi(r_data); +ERROR: + close(fd); + pthread_mutex_unlock(&mutex); + return -1; +} + +int dni_i2c_lock_write_attribute(mux_info_t * mux_info, char * data,char * fullpath) +{ + int fd, len, nbytes = 10; + pthread_mutex_lock(&mutex); + if(mux_info!=NULL) + { + char cpld_path[100] = {0}; + sprintf(cpld_path, "%s/%d-%04x", PREFIX_PATH, mux_info->bus, mux_info->addr); + dni_lock_cpld_write_attribute(cpld_path, mux_info->offset, mux_info->channel); + } + /* Create output file descriptor */ + fd = open(fullpath, O_WRONLY, 0644); + if (fd == -1) + { + goto ERROR; + } + len = write (fd, data, (ssize_t) nbytes); + if (len != nbytes) + { + goto ERROR; + } + close(fd); + pthread_mutex_unlock(&mutex); + return 0; +ERROR: + close(fd); + pthread_mutex_unlock(&mutex); + return -1; +} + +/* Use this function to select MUX and read data on CPLD */ +int dni_lock_cpld_read_attribute(char *cpld_path, int addr) +{ + int fd, len, nbytes = 10,data = 0; + char r_data[10] = {0}; + char address[10] = {0}; + char cpld_data_path[100] = {0}; + char cpld_addr_path[100] = {0}; + + sprintf(cpld_data_path, "%s/data", cpld_path); + sprintf(cpld_addr_path, "%s/addr", cpld_path); + sprintf(address, "%02x", addr); + + pthread_mutex_lock(&mutex1); + /* Create output file descriptor */ + fd = open(cpld_addr_path, O_WRONLY, 0644); + if (fd == -1) + { + goto ERR_HANDLE; + } + + len = write (fd, address, 2); + if (len <= 0) + { + goto ERR_HANDLE; + } + close(fd); + + if ((fd = open(cpld_data_path, O_RDONLY)) == -1) + { + goto ERR_HANDLE; + } + + if ((len = read(fd, r_data, nbytes)) <= 0) + { + goto ERR_HANDLE; + } + close(fd); + pthread_mutex_unlock(&mutex1); + + sscanf(r_data, "%x", &data); + return data; + + ERR_HANDLE: + close(fd); + pthread_mutex_unlock(&mutex1); + return -1; +} + +/* Use this function to select MUX and write data on CPLD */ +int dni_lock_cpld_write_attribute(char *cpld_path, int addr, int data) +{ + int fd, len; + char address[10] = {0}; + char cpld_data_path[100] = {0}; + char cpld_addr_path[100] = {0}; + + sprintf(cpld_data_path, "%s/data", cpld_path); + sprintf(cpld_addr_path, "%s/addr", cpld_path); + sprintf(address, "%02x", addr); + + pthread_mutex_lock(&mutex1); + /* Create output file descriptor */ + fd = open(cpld_addr_path, O_WRONLY, 0644); + if (fd == -1) + { + goto ERR_HANDLE; + } + len = write(fd, address, 2); + if(len <= 0) + { + goto ERR_HANDLE; + } + close(fd); + + fd = open(cpld_data_path, O_WRONLY, 0644); + if (fd == -1) + { + goto ERR_HANDLE; + } + sprintf(address, "%02x", data); + len = write (fd, address, 2); + if(len <= 0) + { + goto ERR_HANDLE; + } + close(fd); + pthread_mutex_unlock(&mutex1); + + return 0; + + ERR_HANDLE: + close(fd); + pthread_mutex_unlock(&mutex1); + return -1; +} + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/platform_lib.h new file mode 100755 index 00000000..8e617859 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/platform_lib.h @@ -0,0 +1,224 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright (C) 2017 Delta Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * 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_delta_ag5648_log.h" + +/* CPLD numbrt & peripherals */ +#define NUM_OF_THERMAL_ON_BOARDS 9 +#define NUM_OF_FAN_ON_FAN_BOARD 8 +#define NUM_OF_PSU_ON_PSU_BOARD 2 +#define NUM_OF_LED_ON_BOARDS 7 +#define NUM_OF_CPLD 3 +#define CHASSIS_FAN_COUNT 8 +#define CHASSIS_THERMAL_COUNT 7 + +#define MAX_REAR_FAN_SPEED 20500 +#define MAX_FRONT_FAN_SPEED 23000 +#define MAX_PSU_FAN_SPEED 19000 + +#define NUM_OF_SFP 48 +#define NUM_OF_QSFP 6 +#define NUM_OF_PORT NUM_OF_SFP + NUM_OF_QSFP + +#define PREFIX_PATH "/sys/bus/i2c/devices" +#define SYS_CPLD_PATH PREFIX_PATH "/2-0031" +#define MASTER_CPLD_PATH PREFIX_PATH "/2-0035" +#define SLAVE_CPLD_PATH PREFIX_PATH "/2-0039" +#define MASTER_CPLD_ADDR_PATH PREFIX_PATH "/2-0035/addr" +#define MASTER_CPLD_DATA_PATH PREFIX_PATH "/2-0035/data" +#define SLAVE_CPLD_ADDR_PATH PREFIX_PATH "/2-0039/addr" +#define SLAVE_CPLD_DATA_PATH PREFIX_PATH "/2-0039/data" + +#define PSU1_AC_PMBUS_PREFIX PREFIX_PATH "/6-0059/" +#define PSU2_AC_PMBUS_PREFIX PREFIX_PATH "/6-0058/" +#define PSU1_SELECT_MEMBER_PATH PREFIX_PATH "/6-0059/psu_select_member" +#define PSU2_SELECT_MEMBER_PATH PREFIX_PATH "/6-0058/psu_select_member" +#define PSU1_AC_PMBUS_NODE(node) PSU1_AC_PMBUS_PREFIX#node +#define PSU2_AC_PMBUS_NODE(node) PSU2_AC_PMBUS_PREFIX#node + +#define FAN1_FRONT PREFIX_PATH "/3-004d/fan1_input" +#define FAN1_REAR PREFIX_PATH "/5-004d/fan1_input" +#define FAN2_FRONT PREFIX_PATH "/3-004d/fan2_input" +#define FAN2_REAR PREFIX_PATH "/5-004d/fan2_input" +#define FAN3_FRONT PREFIX_PATH "/3-004d/fan3_input" +#define FAN3_REAR PREFIX_PATH "/5-004d/fan3_input" +#define FAN4_FRONT PREFIX_PATH "/3-004d/fan4_input" +#define FAN4_REAR PREFIX_PATH "/5-004d/fan4_input" +#define IDPROM_PATH "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" + +#define SFP_SELECT_PORT_PATH PREFIX_PATH "/4-0050/sfp_select_port" +#define SFP_IS_PRESENT_PATH PREFIX_PATH "/4-0050/sfp_is_present" +#define SFP_IS_PRESENT_ALL_PATH PREFIX_PATH "/4-0050/sfp_is_present_all" +#define SFP_EEPROM_PATH PREFIX_PATH "/4-0050/sfp_eeprom" +#define SFP_RESET_PATH PREFIX_PATH "/4-0050/sfp_reset" +#define SFP_LP_MODE_PATH PREFIX_PATH "/4-0050/sfp_lp_mode" + +/* BUS define */ +#define I2C_BUS_0 (0) +#define I2C_BUS_1 (1) +#define I2C_BUS_2 (2) +#define I2C_BUS_3 (3) +#define I2C_BUS_4 (4) +#define I2C_BUS_5 (5) +#define I2C_BUS_6 (6) +#define I2C_BUS_7 (7) +#define I2C_BUS_8 (8) +#define I2C_BUS_9 (9) +#define PSU1_ID (1) +#define PSU2_ID (2) +#define TURN_OFF (0) +#define TURN_ON (1) +#define ALL_FAN_TRAY_EXIST (4) +#define PSU_STATUS_PRESENT (1) +#define PSU_NODE_MAX_PATH_LEN (64) +#define FAN_ZERO_RPM (960) +#define SPEED_100_PERCENTAGE (100) + + +/* REG define*/ +#define DEFAULT_FLAG (0x00) +#define QSFP_RESPOND_REG (0x10) +#define SYS_CPLD_VERSION_ADDR (0x08) +#define MASTER_CPLD_VERSION_ADDR (0x17) +#define SLAVE_CPLD_VERSION_ADDR (0x01) +#define SYS_CPLD (0x31) +#define MASTER_CPLD (0x35) +#define SLAVE_CPLD (0x39) +#define SYS_VERSION_REG (0x08) +#define MASTER_VERSION_REG (0x17) +#define SLAVE_VERSION_REG (0x01) +#define LED_REG (0x04) +#define PSU1_EEPROM (0x51) +#define PSU2_EEPROM (0x50) +#define EMC2305_FRONT_FAN (0x4D) +#define EMC2305_REAR_FAN (0x4D) +#define FAN_STATUS_REG (0x06) +#define FAN_TRAY_1 (0x51) +#define FAN_TRAY_2 (0x52) +#define FAN_TRAY_3 (0x53) +#define FAN_TRAY_4 (0x54) +#define FAN_TRAY_5 (0x55) +#define FAN_TRAY_LED_REG (0x05) +#define PSU_I2C_SEL_PSU1_EEPROM (0xB2) +#define PSU_I2C_SEL_PSU2_EEPROM (0xB0) +#define SFP_I2C_MUX_REG (0x18) +#define SFP_LP_MODE (0x11) +#define SFP_RESET (0x13) +#define QSFP_MODE_SEL_REG (0x10) +#define FAN_STAT1_REG (0x05) +#define FAN_STAT2_REG (0x06) +#define PSU_STAT_REG (0x03) +#define ALARM_REG (0x06) +#define INTERRUPT_REG (0x02) +#define PORT_ADDR (0x50) + + +int dni_i2c_read_attribute_binary(char *filename, char *buffer, int buf_size, int data_len); +int dni_i2c_read_attribute_string(char *filename, char *buffer, int buf_size, int data_len); + +typedef struct dev_info_s +{ + int bus; + int size; + uint8_t addr; + uint8_t data_8; + uint16_t data_16; + uint8_t offset; + uint32_t flags; +}dev_info_t; + +typedef struct mux_info_s +{ + int bus; + uint8_t addr; + uint8_t offset; + uint8_t channel; + char dev_data[10]; + uint32_t flags; +}mux_info_t; + +pthread_mutex_t mutex; +pthread_mutex_t mutex1; +int dni_i2c_lock_read(mux_info_t * mux_info, dev_info_t * dev_info); +int dni_i2c_lock_write(mux_info_t * mux_info, dev_info_t * dev_info); +int dni_i2c_lock_read_attribute(mux_info_t * mux_info, char * fullpath); +int dni_i2c_lock_write_attribute(mux_info_t * mux_info, char * data,char * fullpath); +int dni_lock_cpld_write_attribute(char *cpld_path, int addr, int data); +int dni_lock_cpld_read_attribute(char *cpld_path, int addr); + +#define DEBUG_MODE 0 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(format, ...) printf(format, __VA_ARGS__) +#else + #define DEBUG_PRINT(format, ...) +#endif + +typedef enum +{ + THERMAL_RESERVED = 0, + THERMAL_CPU_CORE, + THERMAL_1_ON_CPU_BOARD, + THERMAL_2_ON_FAN_BOARD, + THERMAL_3_ON_MAIN_BOARD, + THERMAL_4_ON_MAIN_BOARD, + THERMAL_5_ON_MAIN_BOARD, + THERMAL_6_ON_MAIN_BOARD, + THERMAL_1_ON_PSU1, + THERMAL_1_ON_PSU2, +} onlp_thermal_id; + +typedef enum +{ + FAN_RESERVED = 0, + FAN_1_ON_FAN_BOARD, + FAN_2_ON_FAN_BOARD, + FAN_3_ON_FAN_BOARD, + FAN_4_ON_FAN_BOARD, + FAN_5_ON_FAN_BOARD, + FAN_6_ON_FAN_BOARD, + FAN_7_ON_FAN_BOARD, + FAN_8_ON_FAN_BOARD, + FAN_1_ON_PSU1, + FAN_1_ON_PSU2 +} onlp_fan_id; + +typedef enum +{ + LED_RESERVED = 0, + LED_FRONT_FAN, + LED_FRONT_SYS, + LED_FRONT_PWR, + LED_REAR_FAN_TRAY_1, + LED_REAR_FAN_TRAY_2, + LED_REAR_FAN_TRAY_3, + LED_REAR_FAN_TRAY_4 +}onlp_led_id; + +#endif /* __PLATFORM_LIB_H__ */ + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/psui.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/psui.c new file mode 100755 index 00000000..4e64b5a8 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/psui.c @@ -0,0 +1,229 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright (C) 2017 Delta Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * 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" +#include + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_PSU(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static int +dni_psu_pmbus_info_get(int id, char *node, int *value) +{ + int ret = 0; + char node_path[PSU_NODE_MAX_PATH_LEN] = {0}; + *value = 0; + + switch (id) { + case PSU1_ID: + sprintf(node_path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + break; + case PSU2_ID: + sprintf(node_path, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + break; + default: + break; + } + + /* Read attribute value */ + *value = dni_i2c_lock_read_attribute(NULL, node_path); + + return ret; +} + +int +onlp_psui_init(void) +{ + return ONLP_STATUS_OK; +} + +static int +dni_psu_info_get(onlp_psu_info_t* info) +{ + int val = 0; + int index = ONLP_OID_ID_GET(info->hdr.id); + char val_char_mod[11] = {'\0'}; + char val_char_sel[11] = {'\0'}; + char node_path[PSU_NODE_MAX_PATH_LEN] = {'\0'}; + + /* Set capability */ + info->caps |= ONLP_PSU_CAPS_AC; + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Set the associated oid_table + * Set PSU's fan and thermal to child OID + */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); + + switch (index) { + case PSU1_ID: + /* Read PSU module name from attribute */ + sprintf(node_path, "%s%s", PSU1_AC_PMBUS_PREFIX, "psu_mfr_model"); + dni_i2c_read_attribute_string(node_path, val_char_mod, sizeof(val_char_mod), 0); + strcpy(info->model, val_char_mod); + + /* Read PSU serial number from attribute */ + sprintf(node_path, "%s%s", PSU1_AC_PMBUS_PREFIX, "psu_mfr_serial"); + dni_i2c_read_attribute_string(node_path, val_char_sel, sizeof(val_char_sel), 0); + strcpy(info->serial, val_char_sel); + + break; + case PSU2_ID: + /* Read PSU module name from attribute */ + sprintf(node_path, "%s%s", PSU2_AC_PMBUS_PREFIX, "psu_mfr_model"); + dni_i2c_read_attribute_string(node_path, val_char_mod, sizeof(val_char_mod), 0); + strcpy(info->model, val_char_mod); + + /* Read PSU serial number from attribute */ + sprintf(node_path, "%s%s", PSU2_AC_PMBUS_PREFIX, "psu_mfr_serial"); + dni_i2c_read_attribute_string(node_path, val_char_sel, sizeof(val_char_sel), 0); + strcpy(info->serial, val_char_sel); + break; + default: + break; + } + + /* Read voltage, current and power */ + if (dni_psu_pmbus_info_get(index, "psu_v_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (dni_psu_pmbus_info_get(index, "psu_v_in", &val) == 0) { + info->mvin = val; + info->caps |= ONLP_PSU_CAPS_VIN; + } + + if (dni_psu_pmbus_info_get(index, "psu_i_out", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (dni_psu_pmbus_info_get(index, "psu_i_in", &val) == 0) { + info->miin = val; + info->caps |= ONLP_PSU_CAPS_IIN; + } + + if (dni_psu_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + if (dni_psu_pmbus_info_get(index, "psu_p_in", &val) == 0) { + info->mpin = val; + info->caps |= ONLP_PSU_CAPS_PIN; + } + 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); + + dev_info_t dev_info; + + VALIDATE(id); + + /* Set the onlp_oid_hdr_t */ + memset(info, 0, sizeof(onlp_psu_info_t)); + *info = pinfo[index]; + + switch (index) { + case PSU1_ID: + dev_info.addr = PSU1_EEPROM; + break; + case PSU2_ID: + dev_info.addr = PSU2_EEPROM; + break; + default: + break; + } + + dev_info.bus = I2C_BUS_6; + dev_info.offset = 0x00; /* In EEPROM address 0x00 */ + dev_info.flags = DEFAULT_FLAG; + + /* Check PSU is PRESENT or not + * Read PSU EEPROM 1 byte from adress 0x00 + * if not present, return Negative value. + */ + if(dni_i2c_lock_read(NULL, &dev_info) < 0) { + /* Unable to read PSU(%d) node(psu_present) */ + return ONLP_STATUS_OK; + } + else { + info->status |= ONLP_PSU_STATUS_PRESENT; + } + + + /* Check PSU have voltage input or not */ + dni_psu_pmbus_info_get(index, "psu_v_in", &val); + if (val == 0) { + + /* Unable to read PSU(%d) node(psu_power_good) */ + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + return ONLP_STATUS_OK; + } + + ret = dni_psu_info_get(info); + + return ret; +} + +int +onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/sfpi.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/sfpi.c new file mode 100755 index 00000000..7234d966 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/sfpi.c @@ -0,0 +1,473 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright (C) 2017 Delta Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * 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 +#include +#include "platform_lib.h" +/******************* Utility Function *****************************************/ + +int +ag5648_get_respond_val(int port) +{ + int respond_default = 0xff; + int value = 0x00; + if(port > NUM_OF_SFP && port <= (NUM_OF_SFP + NUM_OF_QSFP)) + { + value = respond_default & (~(1 << ((port % 8)-1))); + return value; + } + else + { + return respond_default; + } + +} +int +ag5648_get_respond_reg(int port) +{ + return QSFP_RESPOND_REG; +} + +/************************************************************ + * + * 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 {1, 54}*/ + int p; + AIM_BITMAP_CLR_ALL(bmap); + + for(p = 1; p <= NUM_OF_PORT; p++) { + AIM_BITMAP_SET(bmap, p); + } + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_is_present(int port) +{ + char port_data[2]; + int present, present_bit; + + /* Select QSFP port */ + sprintf(port_data, "%d", port ); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH); + + /* Read SFP/QSFP MODULE is present or not */ + present_bit = dni_i2c_lock_read_attribute(NULL, SFP_IS_PRESENT_PATH); + + /* From sfp_is_present value, + * return 0 = The module is preset + * return 1 = The module is NOT present + */ + if(present_bit == 0) { + present = 1; + } else if (present_bit == 1) { + present = 0; + AIM_LOG_ERROR("Unble to present status from port(%d)\r\n", port); + } else { + /* Port range over 1-54, return -1 */ + AIM_LOG_ERROR("Error to present status from port(%d)\r\n", port); + present = -1; + } + return present; +} + +int +onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + char present_all_data[24] = {0}; + uint32_t bytes[8]; + /* Read presence bitmap from CPLD SFP28/QSFP28 Presence Register + * if only port 0 is present, return 7F FF FF FF FF FF FF FF + * if only port 0 and 1 present, return 3F FF FF FF FF FF FF FF + */ + if(dni_i2c_read_attribute_string(SFP_IS_PRESENT_ALL_PATH, present_all_data, + sizeof(present_all_data), 0) < 0) { + return -1; + } + int count = sscanf(present_all_data, "%x %x %x %x %x %x %x %x", + bytes+0, + bytes+1, + bytes+2, + bytes+3, + bytes+4, + bytes+5, + bytes+6, + bytes+7 + ); + + 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 SFP/QSFP ports */ + bytes[4] &= 0xF; + bytes[6] >>= 4; + + /* Convert to 64 bit integer in port order */ + uint64_t presence_all = 0 ; + int i = 0; + for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { + if( i == 4 || i == 6) { + presence_all <<= 4; + presence_all |= bytes[i]; + } + else { + presence_all <<= 8; + presence_all |= bytes[i]; + } + } + + /* Populate bitmap */ + for(i = 0; i < NUM_OF_PORT; i++) { + AIM_BITMAP_MOD(dst, i+1, !(presence_all & 1)); + presence_all >>= 1; + } + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + char port_data[2]; + int sfp_respond_reg; + int sfp_respond_val; + + + /* Get respond register if port have it */ + sfp_respond_reg = ag5648_get_respond_reg(port); + + /* Set respond val */ + sfp_respond_val = ag5648_get_respond_val(port); + dni_lock_cpld_write_attribute(MASTER_CPLD_PATH, sfp_respond_reg, sfp_respond_val); + + + /* Select port */ + sprintf(port_data, "%d", port ); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH); + + memset(data, 0 ,256); + + /* Read eeprom information into data[] */ + if (dni_i2c_read_attribute_binary(SFP_EEPROM_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_port_map(int port, int* rport) +{ + *rport = port; + return ONLP_STATUS_OK; +} + + +int +onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) +{ + int value_t; + char port_data[2]; + /* Select QSFP port */ + sprintf(port_data, "%d", port ); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH); + + switch (control) { + case ONLP_SFP_CONTROL_RESET_STATE: + *value = dni_i2c_lock_read_attribute(NULL, SFP_RESET_PATH); + /* From sfp_reset value, + * return 0 = The module is in Reset + * return 1 = The module is NOT in Reset + */ + if (*value == 0) + { + *value = 1; + } + else if (*value == 1) + { + *value = 0; + } + value_t = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_RX_LOS: + *value = 0; + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + case ONLP_SFP_CONTROL_TX_DISABLE: + *value = 0; + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + case ONLP_SFP_CONTROL_LP_MODE: + /* From sfp_lp_mode value, + * return 0 = The module is NOT in LP mode + * return 1 = The moduel is in LP mode + */ + *value = dni_i2c_lock_read_attribute(NULL, SFP_LP_MODE_PATH); + value_t = ONLP_STATUS_OK; + break; + default: + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + } + return value_t; +} + +int +onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) +{ + int value_t; + char port_data[2]; + sprintf(port_data, "%d", port); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH); + + switch (control) { + case ONLP_SFP_CONTROL_RESET_STATE: + sprintf(port_data, "%d", value); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_RESET_PATH); + value_t = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_RX_LOS: + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + case ONLP_SFP_CONTROL_TX_DISABLE: + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + case ONLP_SFP_CONTROL_LP_MODE: + sprintf(port_data, "%d", value); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_LP_MODE_PATH); + value_t = ONLP_STATUS_OK; + break; + default: + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + } + return value_t; +} + +int +onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) +{ + char port_data[2]; + int sfp_respond_reg, sfp_respond_val; + dev_info_t dev_info; + + /* Get respond register if port have it */ + sfp_respond_reg = ag5648_get_respond_reg(port); + + /* Set respond val */ + sfp_respond_val = ag5648_get_respond_val(port); + dni_lock_cpld_write_attribute(MASTER_CPLD_PATH, sfp_respond_reg, sfp_respond_val); + + /* Select port */ + sprintf(port_data, "%d", port); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH); + + dev_info.bus = I2C_BUS_4; + dev_info.addr = PORT_ADDR; + dev_info.offset = addr; + dev_info.flags = ONLP_I2C_F_FORCE; + dev_info.size = 1; /* Read 1 byte */ + + return dni_i2c_lock_read(NULL, &dev_info); +} + +int +onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) +{ + char port_data[2]; + int sfp_respond_reg, sfp_respond_val; + dev_info_t dev_info; + + /* Get respond register if port have it */ + sfp_respond_reg = ag5648_get_respond_reg(port); + + /* Set respond val */ + sfp_respond_val = ag5648_get_respond_val(port); + dni_lock_cpld_write_attribute(MASTER_CPLD_PATH, sfp_respond_reg, sfp_respond_val); + + /* Select port */ + sprintf(port_data, "%d", port); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH); + + dev_info.bus = I2C_BUS_4; + dev_info.addr = PORT_ADDR; + dev_info.offset = addr; + dev_info.flags = ONLP_I2C_F_FORCE; + dev_info.size = 1; /* Write 1 byte */ + dev_info.data_8 = value; + + return dni_i2c_lock_write(NULL, &dev_info); +} + +int +onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) +{ + char port_data[2]; + int sfp_respond_reg, sfp_respond_val; + dev_info_t dev_info; + + /* Get respond register if port have it */ + sfp_respond_reg = ag5648_get_respond_reg(port); + + /* Set respond val */ + sfp_respond_val = ag5648_get_respond_val(port); + dni_lock_cpld_write_attribute(MASTER_CPLD_PATH, sfp_respond_reg, sfp_respond_val); + + /* Select port */ + sprintf(port_data, "%d", port); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH); + + dev_info.bus = I2C_BUS_4; + dev_info.addr = PORT_ADDR; + dev_info.offset = addr; + dev_info.flags = ONLP_I2C_F_FORCE; + dev_info.size = 2; /* Read 1 byte */ + + return dni_i2c_lock_read(NULL, &dev_info); +} + +int +onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) +{ + char port_data[2]; + int sfp_respond_reg, sfp_respond_val; + dev_info_t dev_info; + + /* Get respond register if port have it */ + sfp_respond_reg = ag5648_get_respond_reg(port); + + /* Set respond val */ + sfp_respond_val = ag5648_get_respond_val(port); + dni_lock_cpld_write_attribute(MASTER_CPLD_PATH, sfp_respond_reg, sfp_respond_val); + + /* Select port */ + sprintf(port_data, "%d", port); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH); + + dev_info.bus = I2C_BUS_4; + dev_info.addr = PORT_ADDR; + dev_info.offset = addr; + dev_info.flags = ONLP_I2C_F_FORCE; + dev_info.size = 2; /* Write 2 byte */ + dev_info.data_16 = value; + + return dni_i2c_lock_write(NULL, &dev_info); +} + +int +onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv) +{ + char port_data[2] ; + /* Select QSFP port */ + sprintf(port_data, "%d", port ); + dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH); + switch (control) { + case ONLP_SFP_CONTROL_RESET_STATE: + if(port > NUM_OF_SFP && port <= (NUM_OF_SFP +NUM_OF_QSFP)){ + *rv = 1; + } + else{ + *rv = 0; + } + break; + case ONLP_SFP_CONTROL_RX_LOS: + *rv = 0; + break; + case ONLP_SFP_CONTROL_TX_DISABLE: + *rv = 0; + break; + case ONLP_SFP_CONTROL_LP_MODE: + if(port > NUM_OF_SFP && port <= (NUM_OF_SFP +NUM_OF_QSFP)){ + *rv = 1; + } + else{ + *rv = 0; + } + break; + default: + break; + } + return ONLP_STATUS_OK; +} + + + +int +onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_sfpi_post_insert(int port, sff_info_t* info) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +void +onlp_sfpi_debug(int port, aim_pvs_t* pvs) +{ +} + +int +onlp_sfpi_ioctl(int port, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/sysi.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/sysi.c new file mode 100755 index 00000000..f5e6204b --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/sysi.c @@ -0,0 +1,310 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright (C) 2017 Delta Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "x86_64_delta_ag5648_int.h" +#include "x86_64_delta_ag5648_log.h" +#include "platform_lib.h" + +const char* +onlp_sysi_platform_get(void) +{ + return "x86-64-delta-ag5648-r0"; +} + +int +onlp_sysi_init(void) +{ + return ONLP_STATUS_OK; +} + +/******************* Utility Function *****************************************/ +int +decide_percentage(int *percentage, int temper) +{ + int level; + + if(temper <= 50) + { + *percentage = 40; + level = 1; + } + else if(temper > 50 && temper <= 55) + { + *percentage = 60; + level = 2; + } + else if(temper > 55 && temper <= 60) + { + *percentage = 80; + level = 3; + } + else if(temper > 60 && temper <= 65) + { + *percentage = 90; + level = 4; + } + else if(temper > 65) + { + *percentage = 100; + level = 5; + } + else + { + *percentage = 100; + level = 6; + } + + + return level; +} +/******************************************************************************/ + + +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_UNSUPPORTED; +} + +void +onlp_sysi_onie_data_free(uint8_t* data) +{ + aim_free(data); +} + +int +onlp_sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int sys_cpld_version = 0 , master_cpld_version = 0 ,slave_cpld_version = 0 ; + + sys_cpld_version = dni_lock_cpld_read_attribute(SYS_CPLD_PATH,SYS_VERSION_REG); + master_cpld_version = dni_lock_cpld_read_attribute(MASTER_CPLD_PATH,MASTER_VERSION_REG); + slave_cpld_version = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,SLAVE_VERSION_REG); + + pi->cpld_versions = aim_fstrdup("SYSTEM-CPLD = %d, MASTER-CPLD = %d, SLAVE-CPLD = %d", sys_cpld_version, master_cpld_version, slave_cpld_version); + + return ONLP_STATUS_OK; +} + +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) +{ + int i; + onlp_oid_t* e = table; + memset(table, 0, max*sizeof(onlp_oid_t)); + + /* 9 Thermal sensors on the chassis */ + for (i = 1; i <= NUM_OF_THERMAL_ON_BOARDS; i++) + { + *e++ = ONLP_THERMAL_ID_CREATE(i); + } + + /* 7 LEDs on the chassis */ + for (i = 1; i <= NUM_OF_LED_ON_BOARDS; i++) + { + *e++ = ONLP_LED_ID_CREATE(i); + } + + /* 8 Fans on the chassis */ + for (i = 1; i <= NUM_OF_FAN_ON_FAN_BOARD; i++) + { + *e++ = ONLP_FAN_ID_CREATE(i); + } + + /* 2 PSUs on the chassis */ + for (i = 1; i <= NUM_OF_PSU_ON_PSU_BOARD; i++) + { + *e++ = ONLP_PSU_ID_CREATE(i); + } + + return 0; +} + +int +onlp_sysi_platform_manage_fans(void) +{ + int i = 0; + int new_percentage; + int highest_temp = 0; + onlp_thermal_info_t thermal[NUM_OF_THERMAL_ON_BOARDS]; + /* Get current temperature */ + if (onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), &thermal[0]) != ONLP_STATUS_OK || + onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_CPU_BOARD), &thermal[1]) != ONLP_STATUS_OK || + onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_FAN_BOARD), &thermal[2]) != ONLP_STATUS_OK || + onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BOARD), &thermal[3]) != ONLP_STATUS_OK || + onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BOARD), &thermal[4]) != ONLP_STATUS_OK || + onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(THERMAL_5_ON_MAIN_BOARD), &thermal[5]) != ONLP_STATUS_OK || + onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(THERMAL_6_ON_MAIN_BOARD), &thermal[6]) != ONLP_STATUS_OK || + onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU1), &thermal[7]) != ONLP_STATUS_OK || + onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU2), &thermal[8]) != ONLP_STATUS_OK + ) + { + /* Setting all fans speed to maximum */ + new_percentage = SPEED_100_PERCENTAGE; + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_1_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_2_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_3_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_4_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_5_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_6_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_7_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_8_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1_ON_PSU1) , new_percentage); + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1_ON_PSU2) , new_percentage); + + AIM_LOG_ERROR("Unable to read thermal status"); + return ONLP_STATUS_E_INTERNAL; + } + for (i = 0; i < NUM_OF_THERMAL_ON_BOARDS; i++) + { + if (thermal[i].mcelsius > highest_temp) + { + highest_temp = thermal[i].mcelsius; + } + } + + highest_temp = highest_temp/1000; + decide_percentage(&new_percentage, highest_temp); + + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_1_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_2_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_3_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_4_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_5_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_6_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_7_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_8_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1_ON_PSU1) , new_percentage); + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1_ON_PSU2) , new_percentage); + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_platform_manage_leds(void) +{ + /* Set front lights: fan, power supply 1, 2*/ + uint8_t addr, present_bit = 0x00; + + addr = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,LED_REG); + /* Turn the fan led on or off */ + if((addr & 0xc0) == 0 ) + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FRONT_FAN), TURN_OFF); + } + else + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FRONT_FAN), TURN_ON); + } + /* Set front light of SYS */ + addr = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,LED_REG); + + if((addr & 0x30) == 0x30) + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FRONT_SYS), TURN_OFF); + } + else + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FRONT_SYS), TURN_ON); + } + + /* Set front light of PSU */ + addr = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,LED_REG); + + if((addr & 0x06) == 0x00) + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FRONT_PWR), TURN_OFF); + } + else + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FRONT_PWR), TURN_ON); + } + + /* Turn on or off the FAN tray leds */ + present_bit = dni_lock_cpld_read_attribute(SLAVE_CPLD_PATH,FAN_STAT2_REG); + if((present_bit & 0x01) == 0x00) + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1), TURN_OFF); + } + else + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1), TURN_ON); + } + if((present_bit & 0x02) == 0x00) + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2), TURN_OFF); + } + else + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2), TURN_ON); + } + if((present_bit & 0x04) == 0x00) + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3), TURN_OFF); + } + else + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3), TURN_ON); + } + if((present_bit & 0x08) == 0x00) + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4), TURN_OFF); + } + else + { + onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4), TURN_ON); + } + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/thermali.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/thermali.c new file mode 100755 index 00000000..8f0b5353 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/thermali.c @@ -0,0 +1,160 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright (C) 2017 Delta Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Thermal Sensor Platform Implementation. + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include "platform_lib.h" +#include + +#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) \ + DEBUG_PRINT("[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;} \ + DEBUG_PRINT("[Debug][%s][%d][read data: %s]\n", __FUNCTION__, __LINE__, r_data); \ + if (close(fd) == -1) \ + return ONLP_STATUS_E_INTERNAL + +static char* last_path[] = /* must map with onlp_thermal_id */ +{ + "reserved", + NULL, /* CPU Core */ + "/2-004d/hwmon/hwmon5/temp1_input", + "/3-0049/hwmon/hwmon6/temp1_input", + "/3-004b/hwmon/hwmon7/temp1_input", + "/3-004c/hwmon/hwmon8/temp1_input", + "/3-004e/hwmon/hwmon9/temp1_input", + "/3-004f/hwmon/hwmon10/temp1_input", + "/6-0059/psu_temp1_input", + "/6-0058/psu_temp1_input", +}; + +static char* cpu_coretemp_files[] = +{ + "/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp2_input", + "/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp3_input", + "/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp4_input", + "/sys/devices/platform/coretemp.0/hwmon/hwmon0/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_CPU_BOARD), "Thermal sensor near CPU (U57, middle)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_FAN_BOARD), "Thermal sensor near Middle of front vents (U291, Middle)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BOARD), "Thermal sensor near Left of front vents (U290, Left)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BOARD), "Thermal sensor near MAC (U288, Middle)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_5_ON_MAIN_BOARD), "Thermal sensor near Right of front vents (U289, right)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_6_ON_MAIN_BOARD), "Thermal sensor near DC fan (U334, Middle)", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU1), "PSU-1 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU1_ID)}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU2), "PSU-2 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU2_ID)}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + } +}; + +/* + * This will be called to intiialize the thermali subsystem. + */ +int +onlp_thermali_init(void) +{ + return ONLP_STATUS_OK; +} + +/* + * Retrieve the information structure for the given thermal OID. + * + * If the OID is invalid, return ONLP_E_STATUS_INVALID. + * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. + * Otherwise, return ONLP_STATUS_OK with the OID's information. + * + * Note -- it is expected that you fill out the information + * structure even if the sensor described by the OID is not present. + */ +int +onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) +{ + int temp_base = 1; + int local_id, r_data; + char fullpath[256] = {0}; + VALIDATE(id); + local_id = ONLP_OID_ID_GET(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; + } + + sprintf(fullpath, "%s%s", PREFIX_PATH, last_path[local_id]); + r_data = dni_i2c_lock_read_attribute(NULL, fullpath); + + /* Current temperature in milli-celsius */ + info->mcelsius = r_data / temp_base; + + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_config.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_config.c new file mode 100755 index 00000000..51a71397 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_config.c @@ -0,0 +1,81 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* */ +#define __x86_64_delta_ag5648_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_delta_ag5648_config_STRINGIFY_VALUE(_x) __x86_64_delta_ag5648_config_STRINGIFY_NAME(_x) +x86_64_delta_ag5648_config_settings_t x86_64_delta_ag5648_config_settings[] = +{ +#ifdef X86_64_DELTA_AG5648_CONFIG_INCLUDE_LOGGING + { __x86_64_delta_ag5648_config_STRINGIFY_NAME(X86_64_DELTA_AG5648_CONFIG_INCLUDE_LOGGING), __x86_64_delta_ag5648_config_STRINGIFY_VALUE(X86_64_DELTA_AG5648_CONFIG_INCLUDE_LOGGING) }, +#else +{ X86_64_DELTA_AG5648_CONFIG_INCLUDE_LOGGING(__x86_64_delta_ag5648_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_DELTA_AG5648_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_delta_ag5648_config_STRINGIFY_NAME(X86_64_DELTA_AG5648_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_delta_ag5648_config_STRINGIFY_VALUE(X86_64_DELTA_AG5648_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ X86_64_DELTA_AG5648_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_delta_ag5648_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_DELTA_AG5648_CONFIG_LOG_BITS_DEFAULT + { __x86_64_delta_ag5648_config_STRINGIFY_NAME(X86_64_DELTA_AG5648_CONFIG_LOG_BITS_DEFAULT), __x86_64_delta_ag5648_config_STRINGIFY_VALUE(X86_64_DELTA_AG5648_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ X86_64_DELTA_AG5648_CONFIG_LOG_BITS_DEFAULT(__x86_64_delta_ag5648_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_DELTA_AG5648_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_delta_ag5648_config_STRINGIFY_NAME(X86_64_DELTA_AG5648_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_delta_ag5648_config_STRINGIFY_VALUE(X86_64_DELTA_AG5648_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ X86_64_DELTA_AG5648_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_delta_ag5648_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB + { __x86_64_delta_ag5648_config_STRINGIFY_NAME(X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB), __x86_64_delta_ag5648_config_STRINGIFY_VALUE(X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB) }, +#else +{ X86_64_DELTA_AG5648_CONFIG_PORTING_STDLIB(__x86_64_delta_ag5648_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_DELTA_AG5648_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_delta_ag5648_config_STRINGIFY_NAME(X86_64_DELTA_AG5648_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_delta_ag5648_config_STRINGIFY_VALUE(X86_64_DELTA_AG5648_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ X86_64_DELTA_AG5648_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_delta_ag5648_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_DELTA_AG5648_CONFIG_INCLUDE_UCLI + { __x86_64_delta_ag5648_config_STRINGIFY_NAME(X86_64_DELTA_AG5648_CONFIG_INCLUDE_UCLI), __x86_64_delta_ag5648_config_STRINGIFY_VALUE(X86_64_DELTA_AG5648_CONFIG_INCLUDE_UCLI) }, +#else +{ X86_64_DELTA_AG5648_CONFIG_INCLUDE_UCLI(__x86_64_delta_ag5648_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_DELTA_AG5648_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_delta_ag5648_config_STRINGIFY_NAME(X86_64_DELTA_AG5648_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_delta_ag5648_config_STRINGIFY_VALUE(X86_64_DELTA_AG5648_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#else +{ X86_64_DELTA_AG5648_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_delta_ag5648_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_delta_ag5648_config_STRINGIFY_VALUE +#undef __x86_64_delta_ag5648_config_STRINGIFY_NAME + +const char* +x86_64_delta_ag5648_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_delta_ag5648_config_settings[i].name; i++) { + if(strcmp(x86_64_delta_ag5648_config_settings[i].name, setting)) { + return x86_64_delta_ag5648_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_delta_ag5648_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_delta_ag5648_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_delta_ag5648_config_settings[i].name, x86_64_delta_ag5648_config_settings[i].value); + } + return i; +} + +/* */ + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_enums.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_enums.c new file mode 100755 index 00000000..083ec2be --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_enums.c @@ -0,0 +1,10 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_int.h b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_int.h new file mode 100755 index 00000000..f6e5bfff --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_int.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * x86_64_delta_ag5648 Internal Header + * + *****************************************************************************/ +#ifndef __x86_64_delta_ag5648_INT_H__ +#define __x86_64_delta_ag5648_INT_H__ + +#include + + +#endif /* __x86_64_delta_ag5648_INT_H__ */ diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_log.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_log.c new file mode 100755 index 00000000..e3dfe415 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_log.c @@ -0,0 +1,18 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_delta_ag5648_log.h" +/* + * x86_64_delta_ag5648 log struct. + */ +AIM_LOG_STRUCT_DEFINE( + X86_64_DELTA_AG5648_CONFIG_LOG_OPTIONS_DEFAULT, + X86_64_DELTA_AG5648_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + X86_64_DELTA_AG5648_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_log.h b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_log.h new file mode 100755 index 00000000..043c3426 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_log.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#ifndef __x86_64_delta_ag5648_LOG_H__ +#define __x86_64_delta_ag5648_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_delta_ag5648 +#include + +#endif /* __x86_64_delta_ag5648_LOG_H__ */ diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_module.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_module.c new file mode 100755 index 00000000..eceed5c3 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_module.c @@ -0,0 +1,24 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_delta_ag5648_log.h" + +static int +datatypes_init__(void) +{ +#define x86_64_delta_ag5648_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#include + return 0; +} + +void __x86_64_delta_ag5648_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_ucli.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_ucli.c new file mode 100755 index 00000000..3c7484f8 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/x86_64_delta_ag5648_ucli.c @@ -0,0 +1,50 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#if X86_64_DELTA_AG5648_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_delta_ag5648_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_delta_ag5648) +} + +/* */ +/* */ + +static ucli_module_t +x86_64_delta_ag5648_ucli_module__ = + { + "x86_64_delta_ag5648_ucli", + NULL, + x86_64_delta_ag5648_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_delta_ag5648_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_delta_ag5648_ucli_module__); + n = ucli_node_create("x86_64_delta_ag5648", NULL, &x86_64_delta_ag5648_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_delta_ag5648")); + return n; +} + +#else +void* +x86_64_delta_ag5648_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/Makefile b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/PKG.yml b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/PKG.yml new file mode 100644 index 00000000..51ecaae4 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=delta BASENAME=x86-64-delta-ag5648 REVISION=r0 diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/src/lib/x86-64-delta-ag5648-r0.yml b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/src/lib/x86-64-delta-ag5648-r0.yml new file mode 100644 index 00000000..78708c18 --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/src/lib/x86-64-delta-ag5648-r0.yml @@ -0,0 +1,30 @@ +--- + +###################################################################### +# +# platform-config for AG5648 +# +###################################################################### + +x86-64-delta-ag5648-r0: + grub: + + serial: >- + --port=0x3f8 + --speed=115200 + --word=8 + --parity=no + --stop=1 + + kernel: + <<: *kernel-3-16 + + args: >- + nopat + console=ttyS0,115200n8 + + ##network + ## interfaces: + ## ma1: + ## name: ~ + ## syspath: pci0000:00/0000:00:14.0 diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/src/python/x86_64_delta_ag5648_r0/__init__.py b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/src/python/x86_64_delta_ag5648_r0/__init__.py new file mode 100755 index 00000000..490bc6bf --- /dev/null +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/platform-config/r0/src/python/x86_64_delta_ag5648_r0/__init__.py @@ -0,0 +1,53 @@ +from onl.platform.base import * +from onl.platform.delta import * + +class OnlPlatform_x86_64_delta_ag5648_r0(OnlPlatformDelta, + OnlPlatformPortConfig_32x100): + PLATFORM='x86-64-delta-ag5648-r0' + MODEL="AG5648" + SYS_OBJECT_ID=".5648" + + + def baseconfig(self): + #PCA9548 modulize + self.new_i2c_device('pca9548', 0x70, 1) + + #Insert cpld module + self.insmod('i2c_cpld') + self.new_i2c_device('cpld', 0x31, 2) + self.new_i2c_device('cpld', 0x35, 2) + self.new_i2c_device('cpld', 0x39, 2) + + #IDEEPROM modulize + self.new_i2c_device('24c02', 0x53, 2) + + #Insert psu module + self.insmod('dni_ag5648_psu') + self.new_i2c_device('dni_ag5648_psu', 0x58, 6) + self.new_i2c_device('dni_ag5648_psu', 0x59, 6) + + #insert fan module + self.insmod('dni_emc2305') + self.new_i2c_device('emc2305', 0x4d, 3) + self.new_i2c_device('emc2305', 0x4d, 5) + + #Insert temperature modules + self.new_i2c_device('tmp75', 0x4d, 2) + self.new_i2c_device('tmp75', 0x49, 3) + self.new_i2c_device('tmp75', 0x4b, 3) + self.new_i2c_device('tmp75', 0x4c, 3) + self.new_i2c_device('tmp75', 0x4e, 3) + self.new_i2c_device('tmp75', 0x4f, 3) + + #Insert sfp module + self.insmod('dni_ag5648_sfp') + os.system("echo 0x18 > /sys/bus/i2c/devices/2-0035/data") + self.new_i2c_device('dni_ag5648_sfp', 0x50, 4) + + #set front panel sys light + os.system("echo 0x04 > /sys/bus/i2c/devices/2-0039/addr") + os.system("echo 0x10 > /sys/bus/i2c/devices/2-0039/data") + + return True + + From a4bc672c8f7eb326d6fa98a2309ff56a31a8f0e7 Mon Sep 17 00:00:00 2001 From: hans Date: Tue, 2 May 2017 12:38:51 +0800 Subject: [PATCH 2/2] remove the unused function Signed-off-by: hans --- .../onlp/builds/src/module/src/thermali.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/thermali.c b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/thermali.c index 8f0b5353..7545b743 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/thermali.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-ag5648/onlp/builds/src/module/src/thermali.c @@ -38,17 +38,6 @@ } \ } while(0) -#define OPEN_READ_FILE(fd,fullpath,data,nbytes,len) \ - DEBUG_PRINT("[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;} \ - DEBUG_PRINT("[Debug][%s][%d][read data: %s]\n", __FUNCTION__, __LINE__, r_data); \ - if (close(fd) == -1) \ - return ONLP_STATUS_E_INTERNAL - static char* last_path[] = /* must map with onlp_thermal_id */ { "reserved",