Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ enum psu_data_index {
PSU_POUT3,
PSU_TEMP1_0,
PSU_TEMP1_1,
PSU_TEMP2_0,
PSU_TEMP2_1,
PSU_TEMP3_0,
PSU_TEMP3_1,
PSU_FAN0,
PSU_FAN1,
PSU_VOUT_MODE,
Expand Down Expand Up @@ -153,8 +149,6 @@ static struct platform_driver as7946_30xb_psu_driver = {
#define PSU_MODEL_ATTR_ID(index) PSU##index##_MODEL
#define PSU_SERIAL_ATTR_ID(index) PSU##index##_SERIAL
#define PSU_TEMP1_INPUT_ATTR_ID(index) PSU##index##_TEMP1_INPUT
#define PSU_TEMP2_INPUT_ATTR_ID(index) PSU##index##_TEMP2_INPUT
#define PSU_TEMP3_INPUT_ATTR_ID(index) PSU##index##_TEMP3_INPUT
#define PSU_FAN_INPUT_ATTR_ID(index) PSU##index##_FAN_INPUT
#define PSU_FAN_DIR_ATTR_ID(index) PSU##index##_FAN_DIR

Expand All @@ -170,8 +164,6 @@ static struct platform_driver as7946_30xb_psu_driver = {
PSU_MODEL_ATTR_ID(psu_id), \
PSU_SERIAL_ATTR_ID(psu_id), \
PSU_TEMP1_INPUT_ATTR_ID(psu_id), \
PSU_TEMP2_INPUT_ATTR_ID(psu_id), \
PSU_TEMP3_INPUT_ATTR_ID(psu_id), \
PSU_FAN_INPUT_ATTR_ID(psu_id), \
PSU_FAN_DIR_ATTR_ID(psu_id)

Expand Down Expand Up @@ -207,10 +199,6 @@ enum as7946_30xb_psu_sysfs_attrs {
PSU##index##_SERIAL);\
static SENSOR_DEVICE_ATTR(psu##index##_temp1_input, S_IRUGO, show_psu, NULL,\
PSU##index##_TEMP1_INPUT); \
static SENSOR_DEVICE_ATTR(psu##index##_temp2_input, S_IRUGO, show_psu, NULL,\
PSU##index##_TEMP2_INPUT); \
static SENSOR_DEVICE_ATTR(psu##index##_temp3_input, S_IRUGO, show_psu, NULL,\
PSU##index##_TEMP3_INPUT); \
static SENSOR_DEVICE_ATTR(psu##index##_fan1_input, S_IRUGO, show_psu, NULL,\
PSU##index##_FAN_INPUT); \
static SENSOR_DEVICE_ATTR(psu##index##_fan_dir, S_IRUGO, show_string, NULL,\
Expand All @@ -228,8 +216,6 @@ enum as7946_30xb_psu_sysfs_attrs {
&sensor_dev_attr_psu##index##_model.dev_attr.attr, \
&sensor_dev_attr_psu##index##_serial.dev_attr.attr,\
&sensor_dev_attr_psu##index##_temp1_input.dev_attr.attr, \
&sensor_dev_attr_psu##index##_temp2_input.dev_attr.attr, \
&sensor_dev_attr_psu##index##_temp3_input.dev_attr.attr, \
&sensor_dev_attr_psu##index##_fan1_input.dev_attr.attr, \
&sensor_dev_attr_psu##index##_fan_dir.dev_attr.attr

Expand Down Expand Up @@ -549,18 +535,6 @@ static ssize_t show_psu(struct device *dev, struct device_attribute *da,
value = ((u32)data->ipmi_resp[pid].status[PSU_TEMP1_0] |
(u32)data->ipmi_resp[pid].status[PSU_TEMP1_1] << 8);
break;
case PSU1_TEMP2_INPUT:
case PSU2_TEMP2_INPUT:
VALIDATE_PRESENT_RETURN(pid);
value = ((u32)data->ipmi_resp[pid].status[PSU_TEMP2_0] |
(u32)data->ipmi_resp[pid].status[PSU_TEMP2_1] << 8);
break;
case PSU1_TEMP3_INPUT:
case PSU2_TEMP3_INPUT:
VALIDATE_PRESENT_RETURN(pid);
value = ((u32)data->ipmi_resp[pid].status[PSU_TEMP3_0] |
(u32)data->ipmi_resp[pid].status[PSU_TEMP3_1] << 8);
break;
case PSU1_FAN_INPUT:
case PSU2_FAN_INPUT:
VALIDATE_PRESENT_RETURN(pid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ enum fan_id {
{ 0 },\
}

#define AIM_FREE_IF_PTR(p) \
do \
{ \
if (p) { \
aim_free(p); \
p = NULL; \
} \
} while (0)

/* Static fan information */
onlp_fan_info_t finfo[] = {
{ }, /* Not used */
Expand Down Expand Up @@ -169,39 +160,33 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)
static int
_onlp_fani_info_get_fan_on_psu(int pid, onlp_fan_info_t* info)
{
char *fandir = NULL;
int len = 0;
int val = 0;
int ret = 0;

info->status |= ONLP_FAN_STATUS_PRESENT;

/* Get power good status */
if (psu_status_info_get(pid, "power_good", &val) == ONLP_STATUS_OK) {
info->status |= (val != PSU_STATUS_POWER_GOOD) ? ONLP_FAN_STATUS_FAILED : 0;
}

/* get fan direction
*/
len = onlp_file_read_str(&fandir, "%s""psu%d_fan_dir", PSU_SYSFS_PATH, pid);
if (fandir && len) {
if (strncmp(fandir, "B2F", strlen("B2F")) == 0) {
if (psu_status_info_get(pid, "fan_dir", &val) == ONLP_STATUS_OK) {
if (val == PSU_FAN_B2F)
info->status |= ONLP_FAN_STATUS_B2F;
}
else {
else if (val == PSU_FAN_F2B)
info->status |= ONLP_FAN_STATUS_F2B;
}
}
AIM_FREE_IF_PTR(fandir);

/* get fan speed
*/
ret = onlp_file_read_int(&val, "%s""psu%d_fan1_input", PSU_SYSFS_PATH, pid);
if (ret < 0) {
AIM_LOG_ERROR("Unable to read status from (%s""psu%d_fan1_input)\r\n", PSU_SYSFS_PATH, pid);
return ONLP_STATUS_E_INTERNAL;
if (psu_status_info_get(pid, "fan1_input", &val) == ONLP_STATUS_OK) {
/* get speed percentage from rpm
*/
info->rpm = val;
info->percentage = (info->rpm * 100)/MAX_PSU_FAN_SPEED;
}

/* get speed percentage from rpm
*/
info->rpm = val;
info->percentage = (info->rpm * 100)/MAX_PSU_FAN_SPEED;

return ONLP_STATUS_OK;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
* Platform Library
*
***********************************************************/
#include <unistd.h>
#include <onlp/onlp.h>
#include <onlplib/file.h>
#include "platform_lib.h"

int psu_status_info_get(int id, char *node, int *value)
{
int ret = 0;
int len = 0;
char path[PSU_NODE_MAX_PATH_LEN] = {0};
char *fandir = NULL;

*value = 0;

sprintf(path, "%spsu%d_%s", PSU_SYSFS_PATH, id, node);

if (strncmp(node, "fan_dir", strlen("fan_dir")) == 0) {
len = onlp_file_read_str(&fandir, "%s", path);

if (fandir && len) {
if (strncmp(fandir, "B2F", strlen("B2F")) == 0)
*value = PSU_FAN_B2F;
else if (strncmp(fandir, "F2B", strlen("F2B")) == 0)
*value = PSU_FAN_F2B;

} else {
AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path);
return ONLP_STATUS_E_INTERNAL;
}
AIM_FREE_IF_PTR(fandir);
} else {
if (onlp_file_read_int(value, path) < 0) {
AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path);
return ONLP_STATUS_E_INTERNAL;
}
}

return ret;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,31 @@

#define CHASSIS_FAN_COUNT 5
#define CHASSIS_THERMAL_COUNT 10
#define CHASSIS_PSU_THERMAL_COUNT 3
#define CHASSIS_PSU_THERMAL_COUNT 1
#define CHASSIS_LED_COUNT 5
#define CHASSIS_PSU_COUNT 2

#define PSU1_ID 1
#define PSU2_ID 2

#define PSU_NODE_MAX_PATH_LEN 64
#define PSU_STATUS_POWER_GOOD 1

#define PSU_SYSFS_PATH "/sys/devices/platform/as7946_30xb_psu/"
#define FAN_BOARD_PATH "/sys/devices/platform/as7946_30xb_fan/"
#define IDPROM_PATH "/sys/devices/platform/as7946_30xb_sys/eeprom"

int psu_status_info_get(int id, char *node, int *value);

#define AIM_FREE_IF_PTR(p) \
do \
{ \
if (p) { \
aim_free(p); \
p = NULL; \
} \
} while (0)

enum onlp_led_id {
LED_LOC = 1,
LED_DIAG,
Expand All @@ -50,6 +64,12 @@ enum onlp_led_id {
LED_FAN,
};

enum onlp_psu_fan_dir {
PSU_FAN_RESERVED = 0,
PSU_FAN_F2B,
PSU_FAN_B2F,
};

enum onlp_thermal_id {
THERMAL_RESERVED = 0,
THERMAL_CPU_CORE,
Expand All @@ -63,11 +83,7 @@ enum onlp_thermal_id {
THERMAL_1_ON_FANCPLD, /* FAN_4D Temp */
THERMAL_2_ON_FANCPLD, /* FAN_4E Temp */
THERMAL_1_ON_PSU1,
THERMAL_2_ON_PSU1,
THERMAL_3_ON_PSU1,
THERMAL_1_ON_PSU2,
THERMAL_2_ON_PSU2,
THERMAL_3_ON_PSU2,
};

#endif /* __PLATFORM_LIB_H__ */
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@
} \
} while(0)

#define AIM_FREE_IF_PTR(p) \
do \
{ \
if (p) { \
aim_free(p); \
p = NULL; \
} \
} while (0)

int
onlp_psui_init(void)
{
Expand Down Expand Up @@ -109,20 +100,9 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
}
info->status |= ONLP_PSU_STATUS_PRESENT;

/* Get power good status */
ret = onlp_file_read_int(&val, "%s""psu%d_power_good", PSU_SYSFS_PATH, pid);
if (ret < 0) {
AIM_LOG_ERROR("Unable to read status from (%s""psu%d_power_good)\r\n", PSU_SYSFS_PATH, pid);
return ONLP_STATUS_E_INTERNAL;
}

if (val != PSU_STATUS_POWER_GOOD) {
info->status |= ONLP_PSU_STATUS_FAILED;
}

if (info->status & ONLP_PSU_STATUS_FAILED) {
return ONLP_STATUS_OK;
}
/* Set the associated oid_table */
info->hdr.coids[0] = ONLP_FAN_ID_CREATE(pid + CHASSIS_FAN_COUNT);
info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(((pid-1) * CHASSIS_PSU_THERMAL_COUNT) + THERMAL_1_ON_PSU1);

/* Read voltage, current and power */
val = 0;
Expand Down Expand Up @@ -161,26 +141,6 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
info->caps |= ONLP_PSU_CAPS_POUT;
}

/* Set the associated oid_table */
val = 0;
if (onlp_file_read_int(&val, "%s""psu%d_fan1_input", PSU_SYSFS_PATH, pid) == 0 && val) {
info->hdr.coids[0] = ONLP_FAN_ID_CREATE(pid + CHASSIS_FAN_COUNT);
}

val = 0;
if (onlp_file_read_int(&val, "%s""psu%d_temp1_input", PSU_SYSFS_PATH, pid) == 0 && val) {
info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(((pid-1) * CHASSIS_PSU_THERMAL_COUNT) + THERMAL_1_ON_PSU1);
}

val = 0;
if (onlp_file_read_int(&val, "%s""psu%d_temp2_input", PSU_SYSFS_PATH, pid) == 0 && val) {
info->hdr.coids[2] = ONLP_THERMAL_ID_CREATE(((pid-1) * CHASSIS_PSU_THERMAL_COUNT) + THERMAL_2_ON_PSU1);
}

val = 0;
if (onlp_file_read_int(&val, "%s""psu%d_temp3_input", PSU_SYSFS_PATH, pid) == 0 && val) {
info->hdr.coids[3] = ONLP_THERMAL_ID_CREATE(((pid-1) * CHASSIS_PSU_THERMAL_COUNT) + THERMAL_3_ON_PSU1);
}
/* Read model */
char *string = NULL;
int len = onlp_file_read_str(&string, "%s""psu%d_model", PSU_SYSFS_PATH, pid);
Expand All @@ -190,6 +150,9 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
}
AIM_FREE_IF_PTR(string);

/* Set capability */
info->caps |= get_DCorAC_cap(info->model);

/* Read serial */
len = onlp_file_read_str(&string, "%s""psu%d_serial", PSU_SYSFS_PATH, pid);
if (string && len) {
Expand All @@ -198,8 +161,17 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
}
AIM_FREE_IF_PTR(string);

/* Set capability */
info->caps |= get_DCorAC_cap(info->model);
/* Get power good status */
ret = onlp_file_read_int(&val, "%s""psu%d_power_good", PSU_SYSFS_PATH, pid);
if (ret < 0) {
AIM_LOG_ERROR("Unable to read status from (%s""psu%d_power_good)\r\n", PSU_SYSFS_PATH, pid);
return ONLP_STATUS_E_INTERNAL;
}

if (val != PSU_STATUS_POWER_GOOD) {
info->status |= ONLP_PSU_STATUS_UNPLUGGED;
info->caps = 0;
}

return ret;
}
Loading