From 4f2d904412a8f42b52693488a4074f16bcff1d77 Mon Sep 17 00:00:00 2001 From: brandon_chuang Date: Thu, 7 Mar 2019 17:13:22 +0800 Subject: [PATCH] [as7816-64x] Update onlp/drivers for different CPLD firmware --- .../builds/x86-64-accton-as7816-64x-cpld1.c | 35 +++++++ .../onlp/builds/src/module/src/platform_lib.c | 93 +++++++++++-------- .../onlp/builds/src/module/src/platform_lib.h | 2 +- .../onlp/builds/src/module/src/thermali.c | 4 + 4 files changed, 92 insertions(+), 42 deletions(-) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-cpld1.c b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-cpld1.c index 16474804..57b4862c 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-cpld1.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-cpld1.c @@ -55,6 +55,7 @@ static ssize_t access(struct device *dev, struct device_attribute *da, const char *buf, size_t count); static ssize_t show_version(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_id(struct device *dev, struct device_attribute *da, char *buf); static int as7816_64x_cpld_read_internal(struct i2c_client *client, u8 reg); static int as7816_64x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); @@ -74,6 +75,7 @@ static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; enum as7816_64x_cpld_sysfs_attributes { CPLD_VERSION, ACCESS, + CPLD_ID, MODULE_PRESENT_ALL, /* transceiver attributes */ TRANSCEIVER_PRESENT_ATTR_ID(1), @@ -166,6 +168,8 @@ enum as7816_64x_cpld_sysfs_attributes { static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); +static SENSOR_DEVICE_ATTR(cpld_id, S_IRUGO, show_id, NULL, CPLD_ID); + /* transceiver attributes */ static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); @@ -240,6 +244,7 @@ DECLARE_PSU_SENSOR_DEVICE_ATTR(2); static struct attribute *as7816_64x_cpld_attributes[] = { &sensor_dev_attr_version.dev_attr.attr, &sensor_dev_attr_access.dev_attr.attr, + &sensor_dev_attr_cpld_id.dev_attr.attr, /* transceiver attributes */ &sensor_dev_attr_module_present_all.dev_attr.attr, DECLARE_TRANSCEIVER_ATTR(1), @@ -507,6 +512,36 @@ exit: return status; } +static ssize_t show_id(struct device *dev, struct device_attribute *da, char *buf) +{ + int i = 0; + u8 cpld_id[3] = {0}; + struct i2c_client *client = to_i2c_client(dev); + struct as7816_64x_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + + mutex_lock(&data->update_lock); + for (i = 0; i < 2; i++) { + status = as7816_64x_cpld_read_internal(client, 0xfd+i); + if (unlikely(status < 0)) { + goto exit; + } + + cpld_id[i] = status; + } + mutex_unlock(&data->update_lock); + + if (cpld_id[0] == 0xff && cpld_id[1] == 0xff) { + return sprintf(buf, "NULL\n"); + } + + return sprintf(buf, "%s\n", cpld_id); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + static int as7816_64x_cpld_read_internal(struct i2c_client *client, u8 reg) { int status = 0, retry = I2C_RW_RETRY_COUNT; diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.c index 209193b7..a148b00a 100755 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.c @@ -34,18 +34,55 @@ #define PSU_NODE_MAX_PATH_LEN 64 #define PSU_FAN_DIR_LEN 3 +#define CPLD1_ATTR_PREFIX "/sys/bus/i2c/devices/19-0060/" + +char* psu_pmbus_path(int pid) +{ + int version = 0; + char *path = NULL; + int ret = ONLP_STATUS_OK; + int size = 0; + char cpld_id[5] = {0}; + + /* Get CPLD1 version + */ + ret = onlp_file_read_int(&version, "%s%s", CPLD1_ATTR_PREFIX, "version"); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read cpld version from (%s%s)\r\n", CPLD1_ATTR_PREFIX, "version"); + return ""; + } + + /* Get CPLD1 ID + */ + ret = onlp_file_read((uint8_t*)cpld_id, sizeof(cpld_id)-1, &size, "%s%s", CPLD1_ATTR_PREFIX, "cpld_id"); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read cpld id from (%s%s)\r\n", CPLD1_ATTR_PREFIX, "cpld_id"); + return ""; + } + + if (strncmp(cpld_id, "AT", strlen("AT")) == 0) { + path = (pid == PSU1_ID) ? PSU2_AC_PMBUS_PREFIX : PSU1_AC_PMBUS_PREFIX; + return path; + } + else if ((version == 0x5) && (strncmp(cpld_id, "NULL", strlen("NULL")) == 0)) { + path = (pid == PSU1_ID) ? PSU2_AC_PMBUS_PREFIX : PSU1_AC_PMBUS_PREFIX; + return path; + } + + path = (pid == PSU1_ID) ? PSU1_AC_PMBUS_PREFIX : PSU2_AC_PMBUS_PREFIX; + return path; +} int psu_serial_number_get(int id, char *serial, int serial_len) { int size = 0; - int ret = ONLP_STATUS_OK; - char *path = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_mfr_serial) : - PSU2_AC_PMBUS_NODE(psu_mfr_serial) ; + int ret = ONLP_STATUS_OK; + char *prefix = psu_pmbus_path(id); if (serial == NULL || serial_len < PSU_SERIAL_NUMBER_LEN) { return ONLP_STATUS_E_PARAM; } - ret = onlp_file_read((uint8_t*)serial, PSU_SERIAL_NUMBER_LEN, &size, path); + ret = onlp_file_read((uint8_t*)serial, PSU_SERIAL_NUMBER_LEN, &size, "%s%s", prefix, "psu_mfr_serial"); if (ret != ONLP_STATUS_OK || size != PSU_SERIAL_NUMBER_LEN) { return ONLP_STATUS_E_INTERNAL; @@ -60,7 +97,7 @@ psu_type_t psu_type_get(int id, char* modelname, int modelname_len) int value = 0; int ret = ONLP_STATUS_OK; char model[PSU_MODEL_NAME_LEN + 1] = {0}; - char *prefix = NULL; + char *prefix = psu_pmbus_path(id); char fan_dir[PSU_FAN_DIR_LEN + 1] = {0}; if (modelname && modelname_len < PSU_MODEL_NAME_LEN) { @@ -70,7 +107,7 @@ psu_type_t psu_type_get(int id, char* modelname, int modelname_len) /* Check if the psu is power good */ if (onlp_file_read_int(&value, PSU_POWERGOOD_FORMAT, id) < 0) { - AIM_LOG_ERROR("Unable to read present status from PSU(%d)\r\n", index); + AIM_LOG_ERROR("Unable to read power good status from PSU(%d)\r\n", index); return ONLP_STATUS_E_INTERNAL; } @@ -79,7 +116,6 @@ psu_type_t psu_type_get(int id, char* modelname, int modelname_len) } /* Read mode name */ - prefix = (id == PSU1_ID) ? PSU1_AC_PMBUS_PREFIX : PSU2_AC_PMBUS_PREFIX; ret = onlp_file_read((uint8_t*)model, PSU_MODEL_NAME_LEN, &value, "%s%s", prefix, "psu_mfr_model"); if (ret != ONLP_STATUS_OK || value != PSU_MODEL_NAME_LEN) { return PSU_TYPE_UNKNOWN; @@ -91,51 +127,30 @@ psu_type_t psu_type_get(int id, char* modelname, int modelname_len) } if (strncmp(model, "DPS-850A", strlen("DPS-850A")) == 0) { - prefix = (id == PSU1_ID) ? PSU1_AC_PMBUS_PREFIX : PSU2_AC_PMBUS_PREFIX; ret = onlp_file_read((uint8_t*)fan_dir, PSU_FAN_DIR_LEN, &value, "%s%s", prefix, "psu_fan_dir"); - if (ret != ONLP_STATUS_OK || value != PSU_FAN_DIR_LEN) { - return PSU_TYPE_UNKNOWN; - } - - if (strncmp(fan_dir, "F2B", strlen("F2B")) == 0) { - return PSU_TYPE_AC_DPS850_F2B; - } - if (strncmp(fan_dir, "B2F", strlen("B2F")) == 0) { return PSU_TYPE_AC_DPS850_B2F; } + return PSU_TYPE_AC_DPS850_F2B; } if (strncmp(model, "YM-2851F", strlen("YM-2851F")) == 0) { - prefix = (id == PSU1_ID) ? PSU1_AC_PMBUS_PREFIX : PSU2_AC_PMBUS_PREFIX; ret = onlp_file_read((uint8_t*)fan_dir, PSU_FAN_DIR_LEN, &value, "%s%s", prefix, "psu_fan_dir"); - if (ret != ONLP_STATUS_OK || value != PSU_FAN_DIR_LEN) { - return PSU_TYPE_UNKNOWN; - } - - if (strncmp(fan_dir, "F2B", strlen("F2B")) == 0) { - return PSU_TYPE_AC_YM2851_F2B; - } - if (strncmp(fan_dir, "B2F", strlen("B2F")) == 0) { return PSU_TYPE_AC_YM2851_B2F; } + + return PSU_TYPE_AC_YM2851_F2B; } if (strncmp(model, "YM-2851J", strlen("YM-2851J")) == 0) { - prefix = (id == PSU1_ID) ? PSU1_AC_PMBUS_PREFIX : PSU2_AC_PMBUS_PREFIX; ret = onlp_file_read((uint8_t*)fan_dir, PSU_FAN_DIR_LEN, &value, "%s%s", prefix, "psu_fan_dir"); - if (ret != ONLP_STATUS_OK || value != PSU_FAN_DIR_LEN) { - return PSU_TYPE_UNKNOWN; - } - - if (strncmp(fan_dir, "F2B", strlen("F2B")) == 0) { - return PSU_TYPE_AC_YM2851_F2B; - } - if (strncmp(fan_dir, "B2F", strlen("B2F")) == 0) { return PSU_TYPE_AC_YM2851_B2F; } + + + return PSU_TYPE_AC_YM2851_F2B; } return PSU_TYPE_UNKNOWN; @@ -143,10 +158,9 @@ psu_type_t psu_type_get(int id, char* modelname, int modelname_len) int psu_ym2651y_pmbus_info_get(int id, char *node, int *value) { - char *prefix = NULL; + char *prefix = psu_pmbus_path(id); *value = 0; - prefix = (id == PSU1_ID) ? PSU1_AC_PMBUS_PREFIX : PSU2_AC_PMBUS_PREFIX; if (onlp_file_read_int(value, "%s%s", prefix, node) < 0) { AIM_LOG_ERROR("Unable to read status from file(%s%s)\r\n", prefix, node); return ONLP_STATUS_E_INTERNAL; @@ -157,9 +171,8 @@ int psu_ym2651y_pmbus_info_get(int id, char *node, int *value) int psu_ym2651y_pmbus_info_set(int id, char *node, int value) { - char *prefix = NULL; + char *prefix = psu_pmbus_path(id); - prefix = (id == PSU1_ID) ? PSU1_AC_PMBUS_PREFIX : PSU2_AC_PMBUS_PREFIX; if (onlp_file_write_int(value, "%s%s", prefix, node) < 0) { AIM_LOG_ERROR("Unable to write data to file (%s%s)\r\n", prefix, node); return ONLP_STATUS_E_INTERNAL; @@ -170,11 +183,9 @@ int psu_ym2651y_pmbus_info_set(int id, char *node, int value) int psu_dps850_pmbus_info_get(int id, char *node, int *value) { - char *prefix = NULL; - + char *prefix = psu_pmbus_path(id); *value = 0; - prefix = (id == PSU1_ID) ? PSU1_AC_PMBUS_PREFIX : PSU2_AC_PMBUS_PREFIX; if (onlp_file_read_int(value, "%s%s", prefix, node) < 0) { AIM_LOG_ERROR("Unable to read status from file(%s%s)\r\n", prefix, node); return ONLP_STATUS_E_INTERNAL; diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.h index 1aacc5ad..2db22ca7 100755 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.h @@ -87,7 +87,7 @@ int psu_serial_number_get(int id, char *serial, int serial_len); int psu_ym2651y_pmbus_info_get(int id, char *node, int *value); int psu_ym2651y_pmbus_info_set(int id, char *node, int value); int psu_dps850_pmbus_info_get(int id, char *node, int *value); - +char* psu_pmbus_path(int pid); #define DEBUG_MODE 0 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/thermali.c b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/thermali.c index 31cf3a27..6a8747dc 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/thermali.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/thermali.c @@ -133,6 +133,10 @@ onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files); return rv; } + else if (tid == THERMAL_1_ON_PSU1 || tid == THERMAL_1_ON_PSU2) { + int pid = tid - THERMAL_1_ON_PSU1 + 1; + return onlp_file_read_int(&info->mcelsius, "%s%s", psu_pmbus_path(pid), "psu_temp1_input"); + } return onlp_file_read_int(&info->mcelsius, devfiles__[tid]); }