Merge pull request #460 from roylee123/add_platform_as5916-54xl

[platform] add new platform as5916-54xl.
This commit is contained in:
Jeffrey Townsend
2018-11-27 13:15:29 -08:00
committed by GitHub
49 changed files with 6121 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
*x86*64*accton*as5916*54xl*.mk
onlpdump.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as5916-54xl ARCH=amd64 KERNELS="onl-kernel-4.14-lts-x86-64-all:amd64"

View File

@@ -0,0 +1 @@
lib

View File

@@ -0,0 +1,6 @@
KERNELS := onl-kernel-4.14-lts-x86-64-all:amd64
KMODULES := $(wildcard *.c)
VENDOR := accton
BASENAME := x86-64-accton-as5916-54xl
ARCH := x86_64
include $(ONL)/make/kmodule.mk

View File

@@ -0,0 +1,460 @@
/*
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
*
*
* Based on:
* pca954x.c from Kumar Gala <galak@kernel.crashing.org>
* Copyright (C) 2006
*
* Based on:
* pca954x.c from Ken Harrenstien
* Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
*
* Based on:
* i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
* and
* pca9540.c from Jean Delvare <khali@linux-fr.org>.
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/version.h>
#include <linux/stat.h>
#include <linux/sysfs.h>
#include <linux/hwmon-sysfs.h>
#include <linux/ipmi.h>
#include <linux/ipmi_smi.h>
#include <linux/platform_device.h>
#define DRVNAME "as5916_54xl_fan"
#define ACCTON_IPMI_NETFN 0x34
#define IPMI_FAN_READ_CMD 0x14
#define IPMI_FAN_WRITE_CMD 0x15
#define IPMI_TIMEOUT (20 * HZ)
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
static ssize_t set_fan(struct device *dev, struct device_attribute *da,
const char *buf, size_t count);
static ssize_t show_fan(struct device *dev, struct device_attribute *attr, char *buf);
static int as5916_54xl_fan_probe(struct platform_device *pdev);
static int as5916_54xl_fan_remove(struct platform_device *pdev);
enum fan_id {
FAN_1,
FAN_2,
FAN_3,
FAN_4,
FAN_5,
FAN_6,
NUM_OF_FAN
};
enum fan_data_index {
FAN_PRESENT,
FAN_PWM,
FAN_SPEED0,
FAN_SPEED1,
FAN_DATA_COUNT
};
struct ipmi_data {
struct completion read_complete;
struct ipmi_addr address;
ipmi_user_t user;
int interface;
struct kernel_ipmi_msg tx_message;
long tx_msgid;
void *rx_msg_data;
unsigned short rx_msg_len;
unsigned char rx_result;
int rx_recv_type;
struct ipmi_user_hndl ipmi_hndlrs;
};
struct as5916_54xl_fan_data {
struct platform_device *pdev;
struct mutex update_lock;
char valid; /* != 0 if registers are valid */
unsigned long last_updated; /* In jiffies */
unsigned char ipmi_resp[24];
struct ipmi_data ipmi;
unsigned char ipmi_tx_data[3]; /* 0: FAN id, 1: 0x02, 2: PWM */
};
struct as5916_54xl_fan_data *data = NULL;
static struct platform_driver as5916_54xl_fan_driver = {
.probe = as5916_54xl_fan_probe,
.remove = as5916_54xl_fan_remove,
.driver = {
.name = DRVNAME,
.owner = THIS_MODULE,
},
};
#define FAN_PRESENT_ATTR_ID(index) FAN##index##_PRESENT
#define FAN_PWM_ATTR_ID(index) FAN##index##_PWM
#define FAN_RPM_ATTR_ID(index) FAN##index##_INPUT
#define FAN_ATTR(fan_id) \
FAN_PRESENT_ATTR_ID(fan_id), \
FAN_PWM_ATTR_ID(fan_id), \
FAN_RPM_ATTR_ID(fan_id)
enum as5916_54x_fan_sysfs_attrs {
FAN_ATTR(1),
FAN_ATTR(2),
FAN_ATTR(3),
FAN_ATTR(4),
FAN_ATTR(5),
FAN_ATTR(6),
NUM_OF_FAN_ATTR,
NUM_OF_PER_FAN_ATTR = (NUM_OF_FAN_ATTR/NUM_OF_FAN)
};
/* fan attributes */
#define DECLARE_FAN_SENSOR_DEVICE_ATTR(index) \
static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, show_fan, NULL, FAN##index##_PRESENT); \
static SENSOR_DEVICE_ATTR(fan##index##_pwm, S_IWUSR | S_IRUGO, show_fan, set_fan, FAN##index##_PWM); \
static SENSOR_DEVICE_ATTR(fan##index##_input, S_IRUGO, show_fan, NULL, FAN##index##_INPUT)
#define DECLARE_FAN_ATTR(index) \
&sensor_dev_attr_fan##index##_present.dev_attr.attr, \
&sensor_dev_attr_fan##index##_pwm.dev_attr.attr, \
&sensor_dev_attr_fan##index##_input.dev_attr.attr
DECLARE_FAN_SENSOR_DEVICE_ATTR(1);
DECLARE_FAN_SENSOR_DEVICE_ATTR(2);
DECLARE_FAN_SENSOR_DEVICE_ATTR(3);
DECLARE_FAN_SENSOR_DEVICE_ATTR(4);
DECLARE_FAN_SENSOR_DEVICE_ATTR(5);
DECLARE_FAN_SENSOR_DEVICE_ATTR(6);
static struct attribute *as5916_54xl_fan_attributes[] = {
/* fan attributes */
DECLARE_FAN_ATTR(1),
DECLARE_FAN_ATTR(2),
DECLARE_FAN_ATTR(3),
DECLARE_FAN_ATTR(4),
DECLARE_FAN_ATTR(5),
DECLARE_FAN_ATTR(6),
NULL
};
static const struct attribute_group as5916_54xl_fan_group = {
.attrs = as5916_54xl_fan_attributes,
};
/* Functions to talk to the IPMI layer */
/* Initialize IPMI address, message buffers and user data */
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
struct device *dev)
{
int err;
init_completion(&ipmi->read_complete);
/* Initialize IPMI address */
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
ipmi->address.channel = IPMI_BMC_CHANNEL;
ipmi->address.data[0] = 0;
ipmi->interface = iface;
/* Initialize message buffers */
ipmi->tx_msgid = 0;
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
/* Create IPMI messaging interface user */
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
ipmi, &ipmi->user);
if (err < 0) {
dev_err(dev, "Unable to register user with IPMI "
"interface %d\n", ipmi->interface);
return -EACCES;
}
return 0;
}
/* Send an IPMI command */
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
unsigned char *tx_data, unsigned short tx_len,
unsigned char *rx_data, unsigned short rx_len)
{
int err;
ipmi->tx_message.cmd = cmd;
ipmi->tx_message.data = tx_data;
ipmi->tx_message.data_len = tx_len;
ipmi->rx_msg_data = rx_data;
ipmi->rx_msg_len = rx_len;
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
if (err)
goto addr_err;
ipmi->tx_msgid++;
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
&ipmi->tx_message, ipmi, 0, 0, 0);
if (err)
goto ipmi_req_err;
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
if (!err)
goto ipmi_timeout_err;
return 0;
ipmi_timeout_err:
err = -ETIMEDOUT;
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
return err;
ipmi_req_err:
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
return err;
addr_err:
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
return err;
}
/* Dispatch IPMI messages to callers */
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
{
unsigned short rx_len;
struct ipmi_data *ipmi = user_msg_data;
if (msg->msgid != ipmi->tx_msgid) {
dev_err(&data->pdev->dev, "Mismatch between received msgid "
"(%02x) and transmitted msgid (%02x)!\n",
(int)msg->msgid,
(int)ipmi->tx_msgid);
ipmi_free_recv_msg(msg);
return;
}
ipmi->rx_recv_type = msg->recv_type;
if (msg->msg.data_len > 0)
ipmi->rx_result = msg->msg.data[0];
else
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
if (msg->msg.data_len > 1) {
rx_len = msg->msg.data_len - 1;
if (ipmi->rx_msg_len < rx_len)
rx_len = ipmi->rx_msg_len;
ipmi->rx_msg_len = rx_len;
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
} else
ipmi->rx_msg_len = 0;
ipmi_free_recv_msg(msg);
complete(&ipmi->read_complete);
}
static struct as5916_54xl_fan_data *as5916_54xl_fan_update_device(void)
{
int status = 0;
if (time_before(jiffies, data->last_updated + HZ * 5) && data->valid) {
return data;
}
mutex_lock(&data->update_lock);
data->valid = 0;
status = ipmi_send_message(&data->ipmi, IPMI_FAN_READ_CMD, NULL, 0,
data->ipmi_resp, sizeof(data->ipmi_resp));
if (unlikely(status != 0)) {
goto exit;
}
if (unlikely(data->ipmi.rx_result != 0)) {
status = -EIO;
goto exit;
}
data->last_updated = jiffies;
data->valid = 1;
exit:
mutex_unlock(&data->update_lock);
return data;
}
static ssize_t show_fan(struct device *dev, struct device_attribute *da, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
unsigned char fid = attr->index / NUM_OF_PER_FAN_ATTR;
struct as5916_54xl_fan_data *data = NULL;
int value = 0;
int index = 0;
int present = 0;
data = as5916_54xl_fan_update_device();
if (!data->valid) {
return -EIO;
}
index = fid * FAN_DATA_COUNT; /* base index */
present = !data->ipmi_resp[index + FAN_PRESENT];
switch (attr->index) {
case FAN1_PRESENT:
case FAN2_PRESENT:
case FAN3_PRESENT:
case FAN4_PRESENT:
case FAN5_PRESENT:
case FAN6_PRESENT:
value = !data->ipmi_resp[index + FAN_PRESENT];
break;
case FAN1_PWM:
case FAN2_PWM:
case FAN3_PWM:
case FAN4_PWM:
case FAN5_PWM:
case FAN6_PWM:
value = (data->ipmi_resp[index + FAN_PWM] + 1) * 625 / 100;
break;
case FAN1_INPUT:
case FAN2_INPUT:
case FAN3_INPUT:
case FAN4_INPUT:
case FAN5_INPUT:
case FAN6_INPUT:
value = (int)data->ipmi_resp[index + FAN_SPEED0] |
(int)data->ipmi_resp[index + FAN_SPEED1] << 8;
break;
default:
return -EINVAL;
}
return sprintf(buf, "%d\n", present ? value : 0);
}
static ssize_t set_fan(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
long pwm;
int status;
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
unsigned char fid = attr->index / NUM_OF_PER_FAN_ATTR;
status = kstrtol(buf, 10, &pwm);
if (status) {
return status;
}
pwm = (pwm * 100) / 625 - 1; /* Convert pwm to register value */
/* Send IPMI write command */
data->ipmi_tx_data[0] = 1; /* All FANs share the same PWM register, ALWAYS set 1 for each fan */
data->ipmi_tx_data[1] = 0x02;
data->ipmi_tx_data[2] = pwm;
status = ipmi_send_message(&data->ipmi, IPMI_FAN_WRITE_CMD,
data->ipmi_tx_data, sizeof(data->ipmi_tx_data), NULL, 0);
if (unlikely(status != 0)) {
return status;
}
if (unlikely(data->ipmi.rx_result != 0)) {
return -EIO;
}
/* Update pwm to ipmi_resp buffer to prevent from the impact of lazy update */
data->ipmi_resp[fid * FAN_DATA_COUNT + FAN_PWM] = pwm;
return count;
}
static int as5916_54xl_fan_probe(struct platform_device *pdev)
{
int status = -1;
/* Register sysfs hooks */
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xl_fan_group);
if (status) {
goto exit;
}
dev_info(&pdev->dev, "device created\n");
return 0;
exit:
return status;
}
static int as5916_54xl_fan_remove(struct platform_device *pdev)
{
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xl_fan_group);
return 0;
}
static int __init as5916_54xl_fan_init(void)
{
int ret;
data = kzalloc(sizeof(struct as5916_54xl_fan_data), GFP_KERNEL);
if (!data) {
ret = -ENOMEM;
goto alloc_err;
}
mutex_init(&data->update_lock);
data->valid = 0;
ret = platform_driver_register(&as5916_54xl_fan_driver);
if (ret < 0) {
goto dri_reg_err;
}
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
if (IS_ERR(data->pdev)) {
ret = PTR_ERR(data->pdev);
goto dev_reg_err;
}
/* Set up IPMI interface */
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
if (ret)
goto ipmi_err;
return 0;
ipmi_err:
platform_device_unregister(data->pdev);
dev_reg_err:
platform_driver_unregister(&as5916_54xl_fan_driver);
dri_reg_err:
kfree(data);
alloc_err:
return ret;
}
static void __exit as5916_54xl_fan_exit(void)
{
ipmi_destroy_user(data->ipmi.user);
platform_device_unregister(data->pdev);
platform_driver_unregister(&as5916_54xl_fan_driver);
kfree(data);
}
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("as5916_54xl fan driver");
MODULE_LICENSE("GPL");
module_init(as5916_54xl_fan_init);
module_exit(as5916_54xl_fan_exit);

View File

@@ -0,0 +1,455 @@
/*
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
*
* Based on:
* pca954x.c from Kumar Gala <galak@kernel.crashing.org>
* Copyright (C) 2006
*
* Based on:
* pca954x.c from Ken Harrenstien
* Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
*
* Based on:
* i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
* and
* pca9540.c from Jean Delvare <khali@linux-fr.org>.
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/version.h>
#include <linux/stat.h>
#include <linux/sysfs.h>
#include <linux/hwmon-sysfs.h>
#include <linux/ipmi.h>
#include <linux/ipmi_smi.h>
#include <linux/platform_device.h>
#define DRVNAME "as5916_54xl_led"
#define ACCTON_IPMI_NETFN 0x34
#define IPMI_LED_READ_CMD 0x1A
#define IPMI_LED_WRITE_CMD 0x1B
#define IPMI_TIMEOUT (20 * HZ)
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
static ssize_t set_led(struct device *dev, struct device_attribute *da,
const char *buf, size_t count);
static ssize_t show_led(struct device *dev, struct device_attribute *attr, char *buf);
static int as5916_54xl_led_probe(struct platform_device *pdev);
static int as5916_54xl_led_remove(struct platform_device *pdev);
enum led_data_index {
LOC_INDEX,
DIAG_RED_INDEX,
DIAG_GREEN_INDEX
};
struct ipmi_data {
struct completion read_complete;
struct ipmi_addr address;
ipmi_user_t user;
int interface;
struct kernel_ipmi_msg tx_message;
long tx_msgid;
void *rx_msg_data;
unsigned short rx_msg_len;
unsigned char rx_result;
int rx_recv_type;
struct ipmi_user_hndl ipmi_hndlrs;
};
struct as5916_54xl_led_data {
struct platform_device *pdev;
struct mutex update_lock;
char valid; /* != 0 if registers are valid */
unsigned long last_updated; /* In jiffies */
unsigned char ipmi_resp[3]; /* 0: LOC LED, 1: DIAG Red LED, 2: DIAG Green LED */
struct ipmi_data ipmi;
};
struct as5916_54xl_led_data *data = NULL;
static struct platform_driver as5916_54xl_led_driver = {
.probe = as5916_54xl_led_probe,
.remove = as5916_54xl_led_remove,
.driver = {
.name = DRVNAME,
.owner = THIS_MODULE,
},
};
enum led_light_mode {
LED_MODE_OFF,
LED_MODE_RED = 10,
LED_MODE_RED_BLINKING = 11,
LED_MODE_ORANGE = 12,
LED_MODE_ORANGE_BLINKING = 13,
LED_MODE_YELLOW = 14,
LED_MODE_YELLOW_BLINKING = 15,
LED_MODE_GREEN = 16,
LED_MODE_GREEN_BLINKING = 17,
LED_MODE_BLUE = 18,
LED_MODE_BLUE_BLINKING = 19,
LED_MODE_PURPLE = 20,
LED_MODE_PURPLE_BLINKING = 21,
LED_MODE_AUTO = 22,
LED_MODE_AUTO_BLINKING = 23,
LED_MODE_WHITE = 24,
LED_MODE_WHITE_BLINKING = 25,
LED_MODE_CYAN = 26,
LED_MODE_CYAN_BLINKING = 27,
LED_MODE_UNKNOWN = 99
};
enum as5916_54x_led_sysfs_attrs {
LED_LOC,
LED_DIAG,
LED_PSU1,
LED_PSU2,
LED_FAN
};
static SENSOR_DEVICE_ATTR(led_loc, S_IWUSR | S_IRUGO, show_led, set_led, LED_LOC);
static SENSOR_DEVICE_ATTR(led_diag, S_IWUSR | S_IRUGO, show_led, set_led, LED_DIAG);
static SENSOR_DEVICE_ATTR(led_psu1, S_IWUSR | S_IRUGO, show_led, set_led, LED_PSU1);
static SENSOR_DEVICE_ATTR(led_psu2, S_IWUSR | S_IRUGO, show_led, set_led, LED_PSU2);
static SENSOR_DEVICE_ATTR(led_fan, S_IWUSR | S_IRUGO, show_led, set_led, LED_FAN);
static struct attribute *as5916_54xl_led_attributes[] = {
&sensor_dev_attr_led_loc.dev_attr.attr,
&sensor_dev_attr_led_diag.dev_attr.attr,
&sensor_dev_attr_led_psu1.dev_attr.attr,
&sensor_dev_attr_led_psu2.dev_attr.attr,
&sensor_dev_attr_led_fan.dev_attr.attr,
NULL
};
static const struct attribute_group as5916_54xl_led_group = {
.attrs = as5916_54xl_led_attributes,
};
/* Functions to talk to the IPMI layer */
/* Initialize IPMI address, message buffers and user data */
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
struct device *dev)
{
int err;
init_completion(&ipmi->read_complete);
/* Initialize IPMI address */
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
ipmi->address.channel = IPMI_BMC_CHANNEL;
ipmi->address.data[0] = 0;
ipmi->interface = iface;
/* Initialize message buffers */
ipmi->tx_msgid = 0;
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
/* Create IPMI messaging interface user */
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
ipmi, &ipmi->user);
if (err < 0) {
dev_err(dev, "Unable to register user with IPMI "
"interface %d\n", ipmi->interface);
return -EACCES;
}
return 0;
}
/* Send an IPMI command */
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
unsigned char *tx_data, unsigned short tx_len,
unsigned char *rx_data, unsigned short rx_len)
{
int err;
ipmi->tx_message.cmd = cmd;
ipmi->tx_message.data = tx_data;
ipmi->tx_message.data_len = tx_len;
ipmi->rx_msg_data = rx_data;
ipmi->rx_msg_len = rx_len;
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
if (err)
goto addr_err;
ipmi->tx_msgid++;
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
&ipmi->tx_message, ipmi, 0, 0, 0);
if (err)
goto ipmi_req_err;
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
if (!err)
goto ipmi_timeout_err;
return 0;
ipmi_timeout_err:
err = -ETIMEDOUT;
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
return err;
ipmi_req_err:
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
return err;
addr_err:
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
return err;
}
/* Dispatch IPMI messages to callers */
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
{
unsigned short rx_len;
struct ipmi_data *ipmi = user_msg_data;
if (msg->msgid != ipmi->tx_msgid) {
dev_err(&data->pdev->dev, "Mismatch between received msgid "
"(%02x) and transmitted msgid (%02x)!\n",
(int)msg->msgid,
(int)ipmi->tx_msgid);
ipmi_free_recv_msg(msg);
return;
}
ipmi->rx_recv_type = msg->recv_type;
if (msg->msg.data_len > 0)
ipmi->rx_result = msg->msg.data[0];
else
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
if (msg->msg.data_len > 1) {
rx_len = msg->msg.data_len - 1;
if (ipmi->rx_msg_len < rx_len)
rx_len = ipmi->rx_msg_len;
ipmi->rx_msg_len = rx_len;
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
} else
ipmi->rx_msg_len = 0;
ipmi_free_recv_msg(msg);
complete(&ipmi->read_complete);
}
static struct as5916_54xl_led_data *as5916_54xl_led_update_device(void)
{
int status = 0;
if (time_before(jiffies, data->last_updated + HZ * 5) && data->valid) {
return data;
}
mutex_lock(&data->update_lock);
data->valid = 0;
status = ipmi_send_message(&data->ipmi, IPMI_LED_READ_CMD, NULL, 0,
data->ipmi_resp, sizeof(data->ipmi_resp));
if (unlikely(status != 0)) {
goto exit;
}
if (unlikely(data->ipmi.rx_result != 0)) {
status = -EIO;
goto exit;
}
data->last_updated = jiffies;
data->valid = 1;
exit:
mutex_unlock(&data->update_lock);
return data;
}
static ssize_t show_led(struct device *dev, struct device_attribute *da, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct as5916_54xl_led_data *data = NULL;
int value = 0;
data = as5916_54xl_led_update_device();
if (!data->valid) {
return -EIO;
}
switch (attr->index) {
case LED_LOC:
value = data->ipmi_resp[LOC_INDEX] ? LED_MODE_ORANGE_BLINKING : LED_MODE_OFF;
break;
case LED_DIAG:
{
if (!data->ipmi_resp[DIAG_GREEN_INDEX] && !data->ipmi_resp[DIAG_RED_INDEX])
value = LED_MODE_OFF;
else if (data->ipmi_resp[DIAG_GREEN_INDEX] && data->ipmi_resp[DIAG_RED_INDEX])
value = LED_MODE_OFF;
else if (data->ipmi_resp[DIAG_RED_INDEX])
value = LED_MODE_ORANGE;
else if (data->ipmi_resp[DIAG_GREEN_INDEX])
value = LED_MODE_GREEN;
break;
}
case LED_PSU1:
case LED_PSU2:
case LED_FAN:
value = LED_MODE_AUTO;
break;
default:
return -EINVAL;
}
return sprintf(buf, "%d\n", value);
}
static ssize_t set_led(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
long mode;
int status;
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct as5916_54xl_led_data *data = NULL;
status = kstrtol(buf, 10, &mode);
if (status) {
return status;
}
data = as5916_54xl_led_update_device();
if (!data->valid) {
return -EIO;
}
switch (attr->index) {
case LED_LOC:
data->ipmi_resp[LOC_INDEX] = !!mode;
break;
case LED_DIAG:
{
if (mode == LED_MODE_GREEN) {
data->ipmi_resp[DIAG_GREEN_INDEX] = 1;
data->ipmi_resp[DIAG_RED_INDEX] = 0;
}
else if (mode == LED_MODE_ORANGE) {
data->ipmi_resp[DIAG_GREEN_INDEX] = 0;
data->ipmi_resp[DIAG_RED_INDEX] = 1;
}
else { /* OFF */
data->ipmi_resp[DIAG_GREEN_INDEX] = 0;
data->ipmi_resp[DIAG_RED_INDEX] = 0;
}
break;
}
default:
return -EINVAL;
}
/* Send IPMI write command */
status = ipmi_send_message(&data->ipmi, IPMI_LED_WRITE_CMD,
data->ipmi_resp, sizeof(data->ipmi_resp), NULL, 0);
if (unlikely(status != 0)) {
return status;
}
if (unlikely(data->ipmi.rx_result != 0)) {
return -EIO;
}
return count;
}
static int as5916_54xl_led_probe(struct platform_device *pdev)
{
int status = -1;
/* Register sysfs hooks */
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xl_led_group);
if (status) {
goto exit;
}
dev_info(&pdev->dev, "device created\n");
return 0;
exit:
return status;
}
static int as5916_54xl_led_remove(struct platform_device *pdev)
{
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xl_led_group);
return 0;
}
static int __init as5916_54xl_led_init(void)
{
int ret;
data = kzalloc(sizeof(struct as5916_54xl_led_data), GFP_KERNEL);
if (!data) {
ret = -ENOMEM;
goto alloc_err;
}
mutex_init(&data->update_lock);
data->valid = 0;
ret = platform_driver_register(&as5916_54xl_led_driver);
if (ret < 0) {
goto dri_reg_err;
}
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
if (IS_ERR(data->pdev)) {
ret = PTR_ERR(data->pdev);
goto dev_reg_err;
}
/* Set up IPMI interface */
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
if (ret)
goto ipmi_err;
return 0;
ipmi_err:
platform_device_unregister(data->pdev);
dev_reg_err:
platform_driver_unregister(&as5916_54xl_led_driver);
dri_reg_err:
kfree(data);
alloc_err:
return ret;
}
static void __exit as5916_54xl_led_exit(void)
{
ipmi_destroy_user(data->ipmi.user);
platform_device_unregister(data->pdev);
platform_driver_unregister(&as5916_54xl_led_driver);
kfree(data);
}
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("AS5916 54XL led driver");
MODULE_LICENSE("GPL");
module_init(as5916_54xl_led_init);
module_exit(as5916_54xl_led_exit);

View File

@@ -0,0 +1,531 @@
/*
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
* Based on:
* pca954x.c from Kumar Gala <galak@kernel.crashing.org>
* Copyright (C) 2006
*
* Based on:
* pca954x.c from Ken Harrenstien
* Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
*
* Based on:
* i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
* and
* pca9540.c from Jean Delvare <khali@linux-fr.org>.
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/version.h>
#include <linux/stat.h>
#include <linux/sysfs.h>
#include <linux/hwmon-sysfs.h>
#include <linux/ipmi.h>
#include <linux/ipmi_smi.h>
#include <linux/platform_device.h>
#define DRVNAME "as5916_54xl_psu"
#define ACCTON_IPMI_NETFN 0x34
#define IPMI_PSU_READ_CMD 0x16
#define IPMI_PSU_MODEL_NAME_CMD 0x10
#define IPMI_PSU_SERIAL_NUM_CMD 0x11
#define IPMI_TIMEOUT (20 * HZ)
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
static ssize_t show_psu(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t show_string(struct device *dev, struct device_attribute *attr, char *buf);
static int as5916_54xl_psu_probe(struct platform_device *pdev);
static int as5916_54xl_psu_remove(struct platform_device *pdev);
enum psu_id {
PSU_1,
PSU_2,
NUM_OF_PSU
};
enum psu_data_index {
PSU_PRESENT = 0,
PSU_TEMP_FAULT,
PSU_POWER_GOOD_CPLD,
PSU_POWER_GOOD_PMBUS,
PSU_OVER_VOLTAGE,
PSU_OVER_CURRENT,
PSU_POWER_ON,
PSU_VIN0,
PSU_VIN1,
PSU_VOUT0,
PSU_VOUT1,
PSU_IOUT0,
PSU_IOUT1,
PSU_TEMP0,
PSU_TEMP1,
PSU_FAN0,
PSU_FAN1,
PSU_POUT0,
PSU_POUT1,
PSU_STATUS_COUNT,
PSU_MODEL = 0,
PSU_SERIAL = 0
};
struct ipmi_data {
struct completion read_complete;
struct ipmi_addr address;
ipmi_user_t user;
int interface;
struct kernel_ipmi_msg tx_message;
long tx_msgid;
void *rx_msg_data;
unsigned short rx_msg_len;
unsigned char rx_result;
int rx_recv_type;
struct ipmi_user_hndl ipmi_hndlrs;
};
struct ipmi_psu_resp_data {
unsigned char status[19];
char serial[19];
char model[9];
};
struct as5916_54xl_psu_data {
struct platform_device *pdev;
struct mutex update_lock;
char valid[2]; /* != 0 if registers are valid, 0: PSU1, 1: PSU2 */
unsigned long last_updated[2]; /* In jiffies, 0: PSU1, 1: PSU2 */
struct ipmi_data ipmi;
struct ipmi_psu_resp_data ipmi_resp[2]; /* 0: PSU1, 1: PSU2 */
unsigned char ipmi_tx_data[2];
};
struct as5916_54xl_psu_data *data = NULL;
static struct platform_driver as5916_54xl_psu_driver = {
.probe = as5916_54xl_psu_probe,
.remove = as5916_54xl_psu_remove,
.driver = {
.name = DRVNAME,
.owner = THIS_MODULE,
},
};
#define PSU_PRESENT_ATTR_ID(index) PSU##index##_PRESENT
#define PSU_POWERGOOD_ATTR_ID(index) PSU##index##_POWER_GOOD
#define PSU_VOUT_ATTR_ID(index) PSU##index##_VOUT
#define PSU_IOUT_ATTR_ID(index) PSU##index##_IOUT
#define PSU_POUT_ATTR_ID(index) PSU##index##_POUT
#define PSU_MODEL_ATTR_ID(index) PSU##index##_MODEL
#define PSU_SERIAL_ATTR_ID(index) PSU##index##_SERIAL
#define PSU_TEMP_INPUT_ATTR_ID(index) PSU##index##_TEMP_INPUT
#define PSU_FAN_INPUT_ATTR_ID(index) PSU##index##_FAN_INPUT
#define PSU_ATTR(psu_id) \
PSU_PRESENT_ATTR_ID(psu_id), \
PSU_POWERGOOD_ATTR_ID(psu_id), \
PSU_VOUT_ATTR_ID(psu_id), \
PSU_IOUT_ATTR_ID(psu_id), \
PSU_POUT_ATTR_ID(psu_id), \
PSU_MODEL_ATTR_ID(psu_id), \
PSU_SERIAL_ATTR_ID(psu_id), \
PSU_TEMP_INPUT_ATTR_ID(psu_id), \
PSU_FAN_INPUT_ATTR_ID(psu_id)
enum as5916_54x_psu_sysfs_attrs {
/* psu attributes */
PSU_ATTR(1),
PSU_ATTR(2),
NUM_OF_PSU_ATTR,
NUM_OF_PER_PSU_ATTR = (NUM_OF_PSU_ATTR/NUM_OF_PSU)
};
/* psu attributes */
#define DECLARE_PSU_SENSOR_DEVICE_ATTR(index) \
static SENSOR_DEVICE_ATTR(psu##index##_present, S_IRUGO, show_psu, NULL, PSU##index##_PRESENT); \
static SENSOR_DEVICE_ATTR(psu##index##_power_good, S_IRUGO, show_psu, NULL, PSU##index##_POWER_GOOD); \
static SENSOR_DEVICE_ATTR(psu##index##_vout, S_IRUGO, show_psu, NULL, PSU##index##_VOUT); \
static SENSOR_DEVICE_ATTR(psu##index##_iout, S_IRUGO, show_psu, NULL, PSU##index##_IOUT); \
static SENSOR_DEVICE_ATTR(psu##index##_pout, S_IRUGO, show_psu, NULL, PSU##index##_POUT); \
static SENSOR_DEVICE_ATTR(psu##index##_model, S_IRUGO, show_string, NULL, PSU##index##_MODEL); \
static SENSOR_DEVICE_ATTR(psu##index##_serial, S_IRUGO, show_string, NULL, PSU##index##_SERIAL);\
static SENSOR_DEVICE_ATTR(psu##index##_temp1_input, S_IRUGO, show_psu, NULL, PSU##index##_TEMP_INPUT); \
static SENSOR_DEVICE_ATTR(psu##index##_fan1_input, S_IRUGO, show_psu, NULL, PSU##index##_FAN_INPUT)
#define DECLARE_PSU_ATTR(index) \
&sensor_dev_attr_psu##index##_present.dev_attr.attr, \
&sensor_dev_attr_psu##index##_power_good.dev_attr.attr, \
&sensor_dev_attr_psu##index##_vout.dev_attr.attr, \
&sensor_dev_attr_psu##index##_iout.dev_attr.attr, \
&sensor_dev_attr_psu##index##_pout.dev_attr.attr, \
&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##_fan1_input.dev_attr.attr
DECLARE_PSU_SENSOR_DEVICE_ATTR(1);
DECLARE_PSU_SENSOR_DEVICE_ATTR(2);
static struct attribute *as5916_54xl_psu_attributes[] = {
/* psu attributes */
DECLARE_PSU_ATTR(1),
DECLARE_PSU_ATTR(2),
NULL
};
static const struct attribute_group as5916_54xl_psu_group = {
.attrs = as5916_54xl_psu_attributes,
};
/* Functions to talk to the IPMI layer */
/* Initialize IPMI address, message buffers and user data */
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
struct device *dev)
{
int err;
init_completion(&ipmi->read_complete);
/* Initialize IPMI address */
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
ipmi->address.channel = IPMI_BMC_CHANNEL;
ipmi->address.data[0] = 0;
ipmi->interface = iface;
/* Initialize message buffers */
ipmi->tx_msgid = 0;
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
/* Create IPMI messaging interface user */
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
ipmi, &ipmi->user);
if (err < 0) {
dev_err(dev, "Unable to register user with IPMI "
"interface %d\n", ipmi->interface);
return -EACCES;
}
return 0;
}
/* Send an IPMI command */
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
unsigned char *tx_data, unsigned short tx_len,
unsigned char *rx_data, unsigned short rx_len)
{
int err;
ipmi->tx_message.cmd = cmd;
ipmi->tx_message.data = tx_data;
ipmi->tx_message.data_len = tx_len;
ipmi->rx_msg_data = rx_data;
ipmi->rx_msg_len = rx_len;
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
if (err)
goto addr_err;
ipmi->tx_msgid++;
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
&ipmi->tx_message, ipmi, 0, 0, 0);
if (err)
goto ipmi_req_err;
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
if (!err)
goto ipmi_timeout_err;
return 0;
ipmi_timeout_err:
err = -ETIMEDOUT;
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
return err;
ipmi_req_err:
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
return err;
addr_err:
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
return err;
}
/* Dispatch IPMI messages to callers */
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
{
unsigned short rx_len;
struct ipmi_data *ipmi = user_msg_data;
if (msg->msgid != ipmi->tx_msgid) {
dev_err(&data->pdev->dev, "Mismatch between received msgid "
"(%02x) and transmitted msgid (%02x)!\n",
(int)msg->msgid,
(int)ipmi->tx_msgid);
ipmi_free_recv_msg(msg);
return;
}
ipmi->rx_recv_type = msg->recv_type;
if (msg->msg.data_len > 0)
ipmi->rx_result = msg->msg.data[0];
else
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
if (msg->msg.data_len > 1) {
rx_len = msg->msg.data_len - 1;
if (ipmi->rx_msg_len < rx_len)
rx_len = ipmi->rx_msg_len;
ipmi->rx_msg_len = rx_len;
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
} else
ipmi->rx_msg_len = 0;
ipmi_free_recv_msg(msg);
complete(&ipmi->read_complete);
}
static struct as5916_54xl_psu_data *as5916_54xl_psu_update_device(struct device_attribute *da)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
unsigned char pid = attr->index / NUM_OF_PER_PSU_ATTR;
int status = 0;
if (time_before(jiffies, data->last_updated[pid] + HZ * 5) && data->valid[pid]) {
return data;
}
mutex_lock(&data->update_lock);
data->valid[pid] = 0;
/* Get status from ipmi */
data->ipmi_tx_data[0] = pid + 1; /* PSU ID base id for ipmi start from 1 */
status = ipmi_send_message(&data->ipmi, IPMI_PSU_READ_CMD, data->ipmi_tx_data, 1,
data->ipmi_resp[pid].status, sizeof(data->ipmi_resp[pid].status));
if (unlikely(status != 0)) {
goto exit;
}
if (unlikely(data->ipmi.rx_result != 0)) {
status = -EIO;
goto exit;
}
/* Get model name from ipmi */
data->ipmi_tx_data[1] = 0x10;
status = ipmi_send_message(&data->ipmi, IPMI_PSU_READ_CMD, data->ipmi_tx_data, 2,
data->ipmi_resp[pid].model, sizeof(data->ipmi_resp[pid].model) - 1);
if (unlikely(status != 0)) {
goto exit;
}
if (unlikely(data->ipmi.rx_result != 0)) {
status = -EIO;
goto exit;
}
/* Get serial number from ipmi */
data->ipmi_tx_data[1] = 0x11;
status = ipmi_send_message(&data->ipmi, IPMI_PSU_READ_CMD, data->ipmi_tx_data, 2,
data->ipmi_resp[pid].serial, sizeof(data->ipmi_resp[pid].serial) - 1);
if (unlikely(status != 0)) {
goto exit;
}
if (unlikely(data->ipmi.rx_result != 0)) {
status = -EIO;
goto exit;
}
data->last_updated[pid] = jiffies;
data->valid[pid] = 1;
exit:
mutex_unlock(&data->update_lock);
return data;
}
#define VALIDATE_PRESENT_RETURN(id) \
{ \
if (data->ipmi_resp[id].status[PSU_PRESENT] != 0) { \
return -ENXIO; \
} \
}
static ssize_t show_psu(struct device *dev, struct device_attribute *da, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
unsigned char pid = attr->index / NUM_OF_PER_PSU_ATTR;
struct as5916_54xl_psu_data *data = NULL;
int value = 0;
data = as5916_54xl_psu_update_device(da);
if (!data->valid[pid]) {
return -EIO;
}
switch (attr->index) {
case PSU1_PRESENT:
case PSU2_PRESENT:
value = !(data->ipmi_resp[pid].status[PSU_PRESENT]);
break;
case PSU1_POWER_GOOD:
case PSU2_POWER_GOOD:
VALIDATE_PRESENT_RETURN(pid);
value = data->ipmi_resp[pid].status[PSU_POWER_GOOD_CPLD];
break;
case PSU1_VOUT:
case PSU2_VOUT:
VALIDATE_PRESENT_RETURN(pid);
value = ((int)data->ipmi_resp[pid].status[PSU_VOUT0] |
(int)data->ipmi_resp[pid].status[PSU_VOUT1] << 8) * 1000;
break;
case PSU1_IOUT:
case PSU2_IOUT:
VALIDATE_PRESENT_RETURN(pid);
value = ((int)data->ipmi_resp[pid].status[PSU_IOUT0] |
(int)data->ipmi_resp[pid].status[PSU_IOUT1] << 8) * 1000;
break;
case PSU1_POUT:
case PSU2_POUT:
VALIDATE_PRESENT_RETURN(pid);
value = ((int)data->ipmi_resp[pid].status[PSU_POUT0] |
(int)data->ipmi_resp[pid].status[PSU_POUT1] << 8) * 1000;
break;
case PSU1_TEMP_INPUT:
case PSU2_TEMP_INPUT:
VALIDATE_PRESENT_RETURN(pid);
value = ((int)data->ipmi_resp[pid].status[PSU_TEMP0] |
(int)data->ipmi_resp[pid].status[PSU_TEMP1] << 8) * 1000;
break;
case PSU1_FAN_INPUT:
case PSU2_FAN_INPUT:
VALIDATE_PRESENT_RETURN(pid);
value = ((int)data->ipmi_resp[pid].status[PSU_FAN0] |
(int)data->ipmi_resp[pid].status[PSU_FAN1] << 8);
break;
default:
return -EINVAL;
}
return sprintf(buf, "%d\n", value);
}
static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
unsigned char pid = attr->index / NUM_OF_PER_PSU_ATTR;
struct as5916_54xl_psu_data *data;
char *str = NULL;
data = as5916_54xl_psu_update_device(da);
if (!data->valid[pid]) {
return -EIO;
}
switch (attr->index) {
case PSU1_MODEL:
case PSU2_MODEL:
VALIDATE_PRESENT_RETURN(pid);
str = data->ipmi_resp[pid].model;
break;
case PSU1_SERIAL:
case PSU2_SERIAL:
VALIDATE_PRESENT_RETURN(pid);
str = data->ipmi_resp[pid].serial;
break;
default:
return -EINVAL;
}
return sprintf(buf, "%s\n", str);
}
static int as5916_54xl_psu_probe(struct platform_device *pdev)
{
int status = -1;
/* Register sysfs hooks */
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xl_psu_group);
if (status) {
goto exit;
}
dev_info(&pdev->dev, "device created\n");
return 0;
exit:
return status;
}
static int as5916_54xl_psu_remove(struct platform_device *pdev)
{
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xl_psu_group);
return 0;
}
static int __init as5916_54xl_psu_init(void)
{
int ret;
data = kzalloc(sizeof(struct as5916_54xl_psu_data), GFP_KERNEL);
if (!data) {
ret = -ENOMEM;
goto alloc_err;
}
mutex_init(&data->update_lock);
ret = platform_driver_register(&as5916_54xl_psu_driver);
if (ret < 0) {
goto dri_reg_err;
}
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
if (IS_ERR(data->pdev)) {
ret = PTR_ERR(data->pdev);
goto dev_reg_err;
}
/* Set up IPMI interface */
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
if (ret)
goto ipmi_err;
return 0;
ipmi_err:
platform_device_unregister(data->pdev);
dev_reg_err:
platform_driver_unregister(&as5916_54xl_psu_driver);
dri_reg_err:
kfree(data);
alloc_err:
return ret;
}
static void __exit as5916_54xl_psu_exit(void)
{
ipmi_destroy_user(data->ipmi.user);
platform_device_unregister(data->pdev);
platform_driver_unregister(&as5916_54xl_psu_driver);
kfree(data);
}
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("AS5916 54XL PSU driver");
MODULE_LICENSE("GPL");
module_init(as5916_54xl_psu_init);
module_exit(as5916_54xl_psu_exit);

View File

@@ -0,0 +1,686 @@
/*
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
*
* Based on:
* pca954x.c from Kumar Gala <galak@kernel.crashing.org>
* Copyright (C) 2006
*
* Based on:
* pca954x.c from Ken Harrenstien
* Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
*
* Based on:
* i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
* and
* pca9540.c from Jean Delvare <khali@linux-fr.org>.
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/version.h>
#include <linux/stat.h>
#include <linux/sysfs.h>
#include <linux/hwmon-sysfs.h>
#include <linux/ipmi.h>
#include <linux/ipmi_smi.h>
#include <linux/platform_device.h>
#define DRVNAME "as5916_54xl_sys"
#define ACCTON_IPMI_NETFN 0x34
#define IPMI_TCAM_READ_CMD 0x1E
#define IPMI_TCAM_WRITE_CMD 0x1F
#define IPMI_TCAM_RESET_SUBCMD 1
#define IPMI_TCAM_INT_SUMCMD 2
#define IPMI_TCAM_INT_MASK_SUBCMD 3
#define IPMI_SYSEEPROM_READ_CMD 0x18
#define IPMI_TIMEOUT (20 * HZ)
#define IPMI_READ_MAX_LEN 128
#define EEPROM_NAME "eeprom"
#define EEPROM_SIZE 512 /* 512 byte eeprom */
#define IPMI_GET_CPLD_VER_CMD 0x20
#define MAINBOARD_CPLD1_ADDR 0x60
#define MAINBOARD_CPLD2_ADDR 0x62
#define CPU_CPLD_ADDR 0x65
#define FAN_CPLD_ADDR 0x66
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
static int as5916_54xl_sys_probe(struct platform_device *pdev);
static int as5916_54xl_sys_remove(struct platform_device *pdev);
static ssize_t show_sys_reset_6(struct device *dev, struct device_attribute *da, char *buf);
static ssize_t set_sys_reset_6(struct device *dev, struct device_attribute *da,
const char *buf, size_t count);
static ssize_t show_interrupt_status_6(struct device *dev, struct device_attribute *da, char *buf);
static ssize_t set_interrupt_status_6_mask(struct device *dev, struct device_attribute *da,
const char *buf, size_t count);
static ssize_t show_cpld_version(struct device *dev, struct device_attribute *da, char *buf);
struct ipmi_data {
struct completion read_complete;
struct ipmi_addr address;
ipmi_user_t user;
int interface;
struct kernel_ipmi_msg tx_message;
long tx_msgid;
void *rx_msg_data;
unsigned short rx_msg_len;
unsigned char rx_result;
int rx_recv_type;
struct ipmi_user_hndl ipmi_hndlrs;
};
struct as5916_54xl_sys_data {
struct platform_device *pdev;
struct mutex update_lock;
char valid; /* != 0 if registers are valid */
unsigned long last_updated; /* In jiffies */
struct ipmi_data ipmi;
unsigned char ipmi_resp_eeprom[EEPROM_SIZE];
unsigned char ipmi_resp_tcam; /* tcam reset: (CPLD register 0x51)
Bit0/1: Reserved
Bit 2 : CPU_JTAG_RST
Bit 3 : RESET_SYS_CPLD
Bit 4 : RESET_MAC
Bit 5 : CPLD1_TCAM_SRST_L
Bit 6 : CPLD1_TCAM_PERST_L
Bit 7 : CPLD1_TCAM_CRST_L
tcam interrupt (CPLD register 0x62)
tcam interrupt mask (CPLD register 0x63)
Bit 0 : TCAM_CPLD1_GIO_L_1
Bit 1 : TCAM_CPLD1_GIO_L_0 */
unsigned char ipmi_resp_cpld;
unsigned char ipmi_tx_data[3];
struct bin_attribute eeprom; /* eeprom data */
};
struct as5916_54xl_sys_data *data = NULL;
static struct platform_driver as5916_54xl_sys_driver = {
.probe = as5916_54xl_sys_probe,
.remove = as5916_54xl_sys_remove,
.driver = {
.name = DRVNAME,
.owner = THIS_MODULE,
},
};
enum as5916_54xl_sys_sysfs_attrs {
SYS_RESET_6_BIT0, /* Not Used */
SYS_RESET_6_BIT1, /* Not Used */
CPU_JTAG_RST,
RESET_SYS_CPLD,
RESET_MAC,
TCAM_SRST_L,
TCAM_PERST_L,
TCAM_CRST_L,
TCAM_RST_ALL,
SYS_RESET_6_ALL,
TCAM_CPLD1_GIO_L,
TCAM_CPLD1_GIO_L_MASK,
MB_CPLD1_VER, /* mainboard cpld1 version */
MB_CPLD2_VER, /* mainboard cpld2 version */
CPU_CPLD_VER, /* CPU board CPLD version */
FAN_CPLD_VER, /* FAN CPLD version */
};
static SENSOR_DEVICE_ATTR(tcam_rst_c, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, TCAM_CRST_L);
static SENSOR_DEVICE_ATTR(tcam_rst_pe, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, TCAM_PERST_L);
static SENSOR_DEVICE_ATTR(tcam_rst_s, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, TCAM_SRST_L);
static SENSOR_DEVICE_ATTR(tcam_rst_all, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, TCAM_RST_ALL);
static SENSOR_DEVICE_ATTR(sys_rst_6, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, SYS_RESET_6_ALL);
static SENSOR_DEVICE_ATTR(tcam_int, S_IRUGO, show_interrupt_status_6, NULL, TCAM_CPLD1_GIO_L);
static SENSOR_DEVICE_ATTR(tcam_int_msk, S_IWUSR | S_IRUGO, show_interrupt_status_6, set_interrupt_status_6_mask, TCAM_CPLD1_GIO_L_MASK);
static SENSOR_DEVICE_ATTR(mb_cpld1_ver, S_IRUGO, show_cpld_version, NULL, MB_CPLD1_VER);
static SENSOR_DEVICE_ATTR(mb_cpld2_ver, S_IRUGO, show_cpld_version, NULL, MB_CPLD2_VER);
static SENSOR_DEVICE_ATTR(cpu_cpld_ver, S_IRUGO, show_cpld_version, NULL, CPU_CPLD_VER);
static SENSOR_DEVICE_ATTR(fan_cpld_ver, S_IRUGO, show_cpld_version, NULL, FAN_CPLD_VER);
static struct attribute *as5916_54xl_sys_attributes[] = {
&sensor_dev_attr_tcam_rst_c.dev_attr.attr,
&sensor_dev_attr_tcam_rst_pe.dev_attr.attr,
&sensor_dev_attr_tcam_rst_s.dev_attr.attr,
&sensor_dev_attr_tcam_rst_all.dev_attr.attr,
&sensor_dev_attr_sys_rst_6.dev_attr.attr,
&sensor_dev_attr_tcam_int.dev_attr.attr,
&sensor_dev_attr_tcam_int_msk.dev_attr.attr,
&sensor_dev_attr_mb_cpld1_ver.dev_attr.attr,
&sensor_dev_attr_mb_cpld2_ver.dev_attr.attr,
&sensor_dev_attr_cpu_cpld_ver.dev_attr.attr,
&sensor_dev_attr_fan_cpld_ver.dev_attr.attr,
NULL
};
static const struct attribute_group as5916_54xl_sys_group = {
.attrs = as5916_54xl_sys_attributes,
};
/* Functions to talk to the IPMI layer */
/* Initialize IPMI address, message buffers and user data */
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
struct device *dev)
{
int err;
init_completion(&ipmi->read_complete);
/* Initialize IPMI address */
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
ipmi->address.channel = IPMI_BMC_CHANNEL;
ipmi->address.data[0] = 0;
ipmi->interface = iface;
/* Initialize message buffers */
ipmi->tx_msgid = 0;
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
/* Create IPMI messaging interface user */
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
ipmi, &ipmi->user);
if (err < 0) {
dev_err(dev, "Unable to register user with IPMI "
"interface %d\n", ipmi->interface);
return -EACCES;
}
return 0;
}
/* Send an IPMI command */
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
unsigned char *tx_data, unsigned short tx_len,
unsigned char *rx_data, unsigned short rx_len)
{
int err;
ipmi->tx_message.cmd = cmd;
ipmi->tx_message.data = tx_data;
ipmi->tx_message.data_len = tx_len;
ipmi->rx_msg_data = rx_data;
ipmi->rx_msg_len = rx_len;
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
if (err)
goto addr_err;
ipmi->tx_msgid++;
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
&ipmi->tx_message, ipmi, 0, 0, 0);
if (err)
goto ipmi_req_err;
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
if (!err)
goto ipmi_timeout_err;
return 0;
ipmi_timeout_err:
err = -ETIMEDOUT;
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
return err;
ipmi_req_err:
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
return err;
addr_err:
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
return err;
}
/* Dispatch IPMI messages to callers */
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
{
unsigned short rx_len;
struct ipmi_data *ipmi = user_msg_data;
if (msg->msgid != ipmi->tx_msgid) {
dev_err(&data->pdev->dev, "Mismatch between received msgid "
"(%02x) and transmitted msgid (%02x)!\n",
(int)msg->msgid,
(int)ipmi->tx_msgid);
ipmi_free_recv_msg(msg);
return;
}
ipmi->rx_recv_type = msg->recv_type;
if (msg->msg.data_len > 0)
ipmi->rx_result = msg->msg.data[0];
else
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
if (msg->msg.data_len > 1) {
rx_len = msg->msg.data_len - 1;
if (ipmi->rx_msg_len < rx_len)
rx_len = ipmi->rx_msg_len;
ipmi->rx_msg_len = rx_len;
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
} else
ipmi->rx_msg_len = 0;
ipmi_free_recv_msg(msg);
complete(&ipmi->read_complete);
}
static ssize_t sys_eeprom_read(loff_t off, char *buf, size_t count)
{
int status = 0;
unsigned char length = 0;
if ((off + count) > EEPROM_SIZE) {
return -EINVAL;
}
length = (count >= IPMI_READ_MAX_LEN) ? IPMI_READ_MAX_LEN : count;
data->ipmi_tx_data[0] = off;
data->ipmi_tx_data[1] = length;
status = ipmi_send_message(&data->ipmi, IPMI_SYSEEPROM_READ_CMD,
data->ipmi_tx_data, 2,
data->ipmi_resp_eeprom + off, length);
if (unlikely(status != 0)) {
goto exit;
}
if (unlikely(data->ipmi.rx_result != 0)) {
status = -EIO;
goto exit;
}
status = length; /* Read length */
memcpy(buf, data->ipmi_resp_eeprom + off, length);
exit:
return status;
}
static ssize_t sysfs_bin_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
ssize_t retval = 0;
if (unlikely(!count)) {
return count;
}
/*
* Read data from chip, protecting against concurrent updates
* from this host
*/
mutex_lock(&data->update_lock);
while (count) {
ssize_t status;
status = sys_eeprom_read(off, buf, count);
if (status <= 0) {
if (retval == 0) {
retval = status;
}
break;
}
buf += status;
off += status;
count -= status;
retval += status;
}
mutex_unlock(&data->update_lock);
return retval;
}
static int sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom)
{
sysfs_bin_attr_init(eeprom);
eeprom->attr.name = EEPROM_NAME;
eeprom->attr.mode = S_IRUGO;
eeprom->read = sysfs_bin_read;
eeprom->write = NULL;
eeprom->size = EEPROM_SIZE;
/* Create eeprom file */
return sysfs_create_bin_file(kobj, eeprom);
}
static int sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom)
{
sysfs_remove_bin_file(kobj, eeprom);
return 0;
}
static struct as5916_54xl_sys_data *as5916_54xl_sys_update_tcam(unsigned char subcmd)
{
int status = 0;
mutex_lock(&data->update_lock);
data->valid = 0;
data->ipmi_tx_data[0] = subcmd;
status = ipmi_send_message(&data->ipmi, IPMI_TCAM_READ_CMD, data->ipmi_tx_data, 1,
&data->ipmi_resp_tcam, sizeof(data->ipmi_resp_tcam));
if (unlikely(status != 0)) {
goto exit;
}
if (unlikely(data->ipmi.rx_result != 0)) {
status = -EIO;
goto exit;
}
data->last_updated = jiffies;
data->valid = 1;
exit:
mutex_unlock(&data->update_lock);
return data;
}
static ssize_t set_sys_reset_6(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
long reset; /* reset value to be set */
int status;
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct as5916_54xl_sys_data *data = NULL;
status = kstrtol(buf, 10, &reset);
if (status) {
return status;
}
data = as5916_54xl_sys_update_tcam(IPMI_TCAM_RESET_SUBCMD);
if (!data->valid) {
return -EIO;
}
switch (attr->index) {
case SYS_RESET_6_BIT0:
case SYS_RESET_6_BIT1:
case CPU_JTAG_RST:
case RESET_SYS_CPLD:
case RESET_MAC:
case TCAM_SRST_L:
case TCAM_PERST_L:
case TCAM_CRST_L:
data->ipmi_tx_data[1] = reset ? (data->ipmi_resp_tcam | (1 << attr->index)):
(data->ipmi_resp_tcam & ~(1 << attr->index));
break;
case TCAM_RST_ALL:
data->ipmi_tx_data[1] = (data->ipmi_resp_tcam & 0x1f) | (reset << TCAM_SRST_L);
break;
case SYS_RESET_6_ALL:
data->ipmi_tx_data[1] = reset;
break;
default:
return -EINVAL;
}
/* Send IPMI write command */
data->ipmi_tx_data[0] = IPMI_TCAM_RESET_SUBCMD;
status = ipmi_send_message(&data->ipmi, IPMI_TCAM_WRITE_CMD,
data->ipmi_tx_data, 2, NULL, 0);
if (unlikely(status != 0)) {
return status;
}
if (unlikely(data->ipmi.rx_result != 0)) {
return -EIO;
}
return count;
}
static ssize_t show_sys_reset_6(struct device *dev, struct device_attribute *da, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct as5916_54xl_sys_data *data = NULL;
int value = 0;
data = as5916_54xl_sys_update_tcam(IPMI_TCAM_RESET_SUBCMD);
if (!data->valid) {
return -EIO;
}
switch (attr->index) {
case SYS_RESET_6_BIT0:
case SYS_RESET_6_BIT1:
case CPU_JTAG_RST:
case RESET_SYS_CPLD:
case RESET_MAC:
case TCAM_SRST_L:
case TCAM_PERST_L:
case TCAM_CRST_L:
value = !!(data->ipmi_resp_tcam & (1 << attr->index));
break;
case TCAM_RST_ALL:
value = (data->ipmi_resp_tcam >> 5) & 0x7;
break;
case SYS_RESET_6_ALL:
value = data->ipmi_resp_tcam & 0xff;
break;
default:
return -EINVAL;
}
return sprintf(buf, "%d\n", value);
}
static ssize_t show_interrupt_status_6(struct device *dev, struct device_attribute *da, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct as5916_54xl_sys_data *data = NULL;
unsigned char subcmd = 0;
int value = 0;
switch (attr->index) {
case TCAM_CPLD1_GIO_L:
subcmd = IPMI_TCAM_INT_SUMCMD;
break;
case TCAM_CPLD1_GIO_L_MASK:
subcmd = IPMI_TCAM_INT_MASK_SUBCMD;
break;
default:
return -EINVAL;
}
data = as5916_54xl_sys_update_tcam(subcmd);
if (!data->valid) {
return -EIO;
}
value = data->ipmi_resp_tcam & 0x3;
return sprintf(buf, "%d\n", value);
}
static ssize_t set_interrupt_status_6_mask(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
long mask = 0; /* mask value to be set */
int status;
struct as5916_54xl_sys_data *data = NULL;
status = kstrtol(buf, 10, &mask);
if (status) {
return status;
}
data = as5916_54xl_sys_update_tcam(IPMI_TCAM_INT_MASK_SUBCMD);
if (!data->valid) {
return -EIO;
}
/* Send IPMI write command */
data->ipmi_tx_data[0] = IPMI_TCAM_INT_MASK_SUBCMD;
data->ipmi_tx_data[1] = (data->ipmi_resp_tcam & 0xfc) | (mask & 0x3);
status = ipmi_send_message(&data->ipmi, IPMI_TCAM_WRITE_CMD,
data->ipmi_tx_data, 2, NULL, 0);
if (unlikely(status != 0)) {
return status;
}
if (unlikely(data->ipmi.rx_result != 0)) {
return -EIO;
}
return count;
}
static struct as5916_54xl_sys_data *as5916_54xl_sys_update_cpld_ver(unsigned char cpld_addr)
{
int status = 0;
mutex_lock(&data->update_lock);
data->valid = 0;
data->ipmi_tx_data[0] = cpld_addr;
status = ipmi_send_message(&data->ipmi, IPMI_GET_CPLD_VER_CMD, data->ipmi_tx_data, 1,
&data->ipmi_resp_cpld, sizeof(data->ipmi_resp_cpld));
if (unlikely(status != 0)) {
goto exit;
}
if (unlikely(data->ipmi.rx_result != 0)) {
status = -EIO;
goto exit;
}
data->last_updated = jiffies;
data->valid = 1;
exit:
mutex_unlock(&data->update_lock);
return data;
}
static ssize_t show_cpld_version(struct device *dev, struct device_attribute *da, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct as5916_54xl_sys_data *data = NULL;
unsigned char cpld_addr = 0;
switch (attr->index) {
case MB_CPLD1_VER:
cpld_addr = MAINBOARD_CPLD1_ADDR;
break;
case MB_CPLD2_VER:
cpld_addr = MAINBOARD_CPLD2_ADDR;
break;
case CPU_CPLD_VER:
cpld_addr = CPU_CPLD_ADDR;
break;
case FAN_CPLD_VER:
cpld_addr = FAN_CPLD_ADDR;
break;
default:
return -EINVAL;
}
data = as5916_54xl_sys_update_cpld_ver(cpld_addr);
if (!data->valid) {
return -EIO;
}
return sprintf(buf, "%d\n", data->ipmi_resp_cpld);
}
static int as5916_54xl_sys_probe(struct platform_device *pdev)
{
int status = -1;
/* Register sysfs hooks */
status = sysfs_eeprom_init(&pdev->dev.kobj, &data->eeprom);
if (status) {
goto exit;
}
/* Register sysfs hooks */
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xl_sys_group);
if (status) {
goto exit;
}
dev_info(&pdev->dev, "device created\n");
return 0;
exit:
return status;
}
static int as5916_54xl_sys_remove(struct platform_device *pdev)
{
sysfs_eeprom_cleanup(&pdev->dev.kobj, &data->eeprom);
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xl_sys_group);
return 0;
}
static int __init as5916_54xl_sys_init(void)
{
int ret;
data = kzalloc(sizeof(struct as5916_54xl_sys_data), GFP_KERNEL);
if (!data) {
ret = -ENOMEM;
goto alloc_err;
}
mutex_init(&data->update_lock);
ret = platform_driver_register(&as5916_54xl_sys_driver);
if (ret < 0) {
goto dri_reg_err;
}
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
if (IS_ERR(data->pdev)) {
ret = PTR_ERR(data->pdev);
goto dev_reg_err;
}
/* Set up IPMI interface */
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
if (ret)
goto ipmi_err;
return 0;
ipmi_err:
platform_device_unregister(data->pdev);
dev_reg_err:
platform_driver_unregister(&as5916_54xl_sys_driver);
dri_reg_err:
kfree(data);
alloc_err:
return ret;
}
static void __exit as5916_54xl_sys_exit(void)
{
ipmi_destroy_user(data->ipmi.user);
platform_device_unregister(data->pdev);
platform_driver_unregister(&as5916_54xl_sys_driver);
kfree(data);
}
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("AS5916-54XL System driver");
MODULE_LICENSE("GPL");
module_init(as5916_54xl_sys_init);
module_exit(as5916_54xl_sys_exit);

View File

@@ -0,0 +1,347 @@
/*
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
*
* Based on:
* pca954x.c from Kumar Gala <galak@kernel.crashing.org>
* Copyright (C) 2006
*
* Based on:
* pca954x.c from Ken Harrenstien
* Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
*
* Based on:
* i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
* and
* pca9540.c from Jean Delvare <khali@linux-fr.org>.
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/version.h>
#include <linux/stat.h>
#include <linux/sysfs.h>
#include <linux/hwmon-sysfs.h>
#include <linux/ipmi.h>
#include <linux/ipmi_smi.h>
#include <linux/platform_device.h>
#define DRVNAME "as5916_54xl_thermal"
#define ACCTON_IPMI_NETFN 0x34
#define IPMI_THERMAL_READ_CMD 0x12
#define IPMI_TIMEOUT (20 * HZ)
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf);
static int as5916_54xl_thermal_probe(struct platform_device *pdev);
static int as5916_54xl_thermal_remove(struct platform_device *pdev);
enum temp_data_index {
TEMP_ADDR,
TEMP_FAULT,
TEMP_INPUT,
TEMP_DATA_COUNT
};
struct ipmi_data {
struct completion read_complete;
struct ipmi_addr address;
ipmi_user_t user;
int interface;
struct kernel_ipmi_msg tx_message;
long tx_msgid;
void *rx_msg_data;
unsigned short rx_msg_len;
unsigned char rx_result;
int rx_recv_type;
struct ipmi_user_hndl ipmi_hndlrs;
};
struct as5916_54xl_thermal_data {
struct platform_device *pdev;
struct mutex update_lock;
char valid; /* != 0 if registers are valid */
unsigned long last_updated; /* In jiffies */
char ipmi_resp[12]; /* 3 bytes for each thermal */
struct ipmi_data ipmi;
};
struct as5916_54xl_thermal_data *data = NULL;
static struct platform_driver as5916_54xl_thermal_driver = {
.probe = as5916_54xl_thermal_probe,
.remove = as5916_54xl_thermal_remove,
.driver = {
.name = DRVNAME,
.owner = THIS_MODULE,
},
};
enum as5916_54x_thermal_sysfs_attrs {
TEMP1_INPUT,
TEMP2_INPUT,
TEMP3_INPUT,
TEMP4_INPUT,
};
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, TEMP1_INPUT);
static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, TEMP2_INPUT);
static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, TEMP3_INPUT);
static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, TEMP4_INPUT);
static struct attribute *as5916_54xl_thermal_attributes[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr,
&sensor_dev_attr_temp2_input.dev_attr.attr,
&sensor_dev_attr_temp3_input.dev_attr.attr,
&sensor_dev_attr_temp4_input.dev_attr.attr,
NULL
};
static const struct attribute_group as5916_54xl_thermal_group = {
.attrs = as5916_54xl_thermal_attributes,
};
/* Functions to talk to the IPMI layer */
/* Initialize IPMI address, message buffers and user data */
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
struct device *dev)
{
int err;
init_completion(&ipmi->read_complete);
/* Initialize IPMI address */
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
ipmi->address.channel = IPMI_BMC_CHANNEL;
ipmi->address.data[0] = 0;
ipmi->interface = iface;
/* Initialize message buffers */
ipmi->tx_msgid = 0;
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
/* Create IPMI messaging interface user */
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
ipmi, &ipmi->user);
if (err < 0) {
dev_err(dev, "Unable to register user with IPMI "
"interface %d\n", ipmi->interface);
return -EACCES;
}
return 0;
}
/* Send an IPMI command */
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
unsigned char *tx_data, unsigned short tx_len,
unsigned char *rx_data, unsigned short rx_len)
{
int err;
ipmi->tx_message.cmd = cmd;
ipmi->tx_message.data = tx_data;
ipmi->tx_message.data_len = tx_len;
ipmi->rx_msg_data = rx_data;
ipmi->rx_msg_len = rx_len;
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
if (err)
goto addr_err;
ipmi->tx_msgid++;
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
&ipmi->tx_message, ipmi, 0, 0, 0);
if (err)
goto ipmi_req_err;
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
if (!err)
goto ipmi_timeout_err;
return 0;
ipmi_timeout_err:
err = -ETIMEDOUT;
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
return err;
ipmi_req_err:
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
return err;
addr_err:
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
return err;
}
/* Dispatch IPMI messages to callers */
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
{
unsigned short rx_len;
struct ipmi_data *ipmi = user_msg_data;
if (msg->msgid != ipmi->tx_msgid) {
dev_err(&data->pdev->dev, "Mismatch between received msgid "
"(%02x) and transmitted msgid (%02x)!\n",
(int)msg->msgid,
(int)ipmi->tx_msgid);
ipmi_free_recv_msg(msg);
return;
}
ipmi->rx_recv_type = msg->recv_type;
if (msg->msg.data_len > 0)
ipmi->rx_result = msg->msg.data[0];
else
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
if (msg->msg.data_len > 1) {
rx_len = msg->msg.data_len - 1;
if (ipmi->rx_msg_len < rx_len)
rx_len = ipmi->rx_msg_len;
ipmi->rx_msg_len = rx_len;
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
} else
ipmi->rx_msg_len = 0;
ipmi_free_recv_msg(msg);
complete(&ipmi->read_complete);
}
static ssize_t show_temp(struct device *dev, struct device_attribute *da, char *buf)
{
int status = 0;
int index = 0;
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ * 5) || !data->valid) {
data->valid = 0;
status = ipmi_send_message(&data->ipmi, IPMI_THERMAL_READ_CMD, NULL, 0,
data->ipmi_resp, sizeof(data->ipmi_resp));
if (unlikely(status != 0)) {
goto exit;
}
if (unlikely(data->ipmi.rx_result != 0)) {
status = -EIO;
goto exit;
}
data->last_updated = jiffies;
data->valid = 1;
}
mutex_unlock(&data->update_lock);
/* Get temp fault status */
index = attr->index * TEMP_DATA_COUNT + TEMP_FAULT;
if (unlikely(data->ipmi_resp[index] == 0)) {
status = -EIO;
goto exit;
}
/* Get temperature in degree celsius */
index = attr->index * TEMP_DATA_COUNT + TEMP_INPUT;
status = data->ipmi_resp[index] * 1000;
return sprintf(buf, "%d\n", status);
exit:
mutex_unlock(&data->update_lock);
return status;
}
static int as5916_54xl_thermal_probe(struct platform_device *pdev)
{
int status = -1;
/* Register sysfs hooks */
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xl_thermal_group);
if (status) {
goto exit;
}
dev_info(&pdev->dev, "device created\n");
return 0;
exit:
return status;
}
static int as5916_54xl_thermal_remove(struct platform_device *pdev)
{
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xl_thermal_group);
return 0;
}
static int __init as5916_54xl_thermal_init(void)
{
int ret;
data = kzalloc(sizeof(struct as5916_54xl_thermal_data), GFP_KERNEL);
if (!data) {
ret = -ENOMEM;
goto alloc_err;
}
mutex_init(&data->update_lock);
data->valid = 0;
ret = platform_driver_register(&as5916_54xl_thermal_driver);
if (ret < 0) {
goto dri_reg_err;
}
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
if (IS_ERR(data->pdev)) {
ret = PTR_ERR(data->pdev);
goto dev_reg_err;
}
/* Set up IPMI interface */
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
if (ret)
goto ipmi_err;
return 0;
ipmi_err:
platform_device_unregister(data->pdev);
dev_reg_err:
platform_driver_unregister(&as5916_54xl_thermal_driver);
dri_reg_err:
kfree(data);
alloc_err:
return ret;
}
static void __exit as5916_54xl_thermal_exit(void)
{
ipmi_destroy_user(data->ipmi.user);
platform_device_unregister(data->pdev);
platform_driver_unregister(&as5916_54xl_thermal_driver);
kfree(data);
}
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("AS5916 54XL Thermal driver");
MODULE_LICENSE("GPL");
module_init(as5916_54xl_thermal_init);
module_exit(as5916_54xl_thermal_exit);

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
!include $ONL_TEMPLATES/onlp-platform-revision.yml PLATFORM=x86-64-accton-as5916-54xl ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu REVISION=r0

View File

@@ -0,0 +1,2 @@
FILTER=src
include $(ONL)/make/subdirs.mk

View File

@@ -0,0 +1,45 @@
############################################################
# <bsn.cl fy=2014 v=onl>
#
# 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.
#
# </bsn.cl>
############################################################
#
#
############################################################
include $(ONL)/make/config.amd64.mk
MODULE := libonlp-x86-64-accton-as5916-54xl
include $(BUILDER)/standardinit.mk
DEPENDMODULES := AIM IOF x86_64_accton_as5916_54xl onlplib
DEPENDMODULE_HEADERS := sff
include $(BUILDER)/dependmodules.mk
SHAREDLIB := libonlp-x86-64-accton-as5916-54xl.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

View File

@@ -0,0 +1,46 @@
############################################################
# <bsn.cl fy=2014 v=onl>
#
# 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.
#
# </bsn.cl>
############################################################
#
#
#
############################################################
include $(ONL)/make/config.amd64.mk
.DEFAULT_GOAL := onlpdump
MODULE := onlpdump
include $(BUILDER)/standardinit.mk
DEPENDMODULES := AIM IOF onlp x86_64_accton_as5916_54xl 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

View File

@@ -0,0 +1 @@
name: x86_64_accton_as5916_54xl

View File

@@ -0,0 +1,9 @@
###############################################################################
#
#
#
###############################################################################
include $(ONL)/make/config.mk
MODULE := x86_64_accton_as5916_54xl
AUTOMODULE := x86_64_accton_as5916_54xl
include $(BUILDER)/definemodule.mk

View File

@@ -0,0 +1,6 @@
###############################################################################
#
# x86_64_accton_as5916_54xl README
#
###############################################################################

View File

@@ -0,0 +1,9 @@
###############################################################################
#
# x86_64_accton_as5916_54xl Autogeneration
#
###############################################################################
x86_64_accton_as5916_54xl_AUTO_DEFS := module/auto/x86_64_accton_as5916_54xl.yml
x86_64_accton_as5916_54xl_AUTO_DIRS := module/inc/x86_64_accton_as5916_54xl module/src
include $(BUILDER)/auto.mk

View File

@@ -0,0 +1,50 @@
###############################################################################
#
# x86_64_accton_as5916_54xl Autogeneration Definitions.
#
###############################################################################
cdefs: &cdefs
- X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_LOGGING:
doc: "Include or exclude logging."
default: 1
- X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_OPTIONS_DEFAULT:
doc: "Default enabled log options."
default: AIM_LOG_OPTIONS_DEFAULT
- X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_BITS_DEFAULT:
doc: "Default enabled log bits."
default: AIM_LOG_BITS_DEFAULT
- X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_CUSTOM_BITS_DEFAULT:
doc: "Default enabled custom log bits."
default: 0
- X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB:
doc: "Default all porting macros to use the C standard libraries."
default: 1
- X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS:
doc: "Include standard library headers for stdlib porting macros."
default: X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB
- X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_UCLI:
doc: "Include generic uCli support."
default: 0
- X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION:
doc: "Assume chassis fan direction is the same as the PSU fan direction."
default: 0
definitions:
cdefs:
X86_64_ACCTON_AS5916_54XL_CONFIG_HEADER:
defs: *cdefs
basename: x86_64_accton_as5916_54xl_config
portingmacro:
x86_64_accton_as5916_54xl:
macros:
- malloc
- free
- memset
- memcpy
- strncpy
- vsnprintf
- snprintf
- strlen

View File

@@ -0,0 +1,14 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_accton_as5916_54xl/x86_64_accton_as5916_54xl_config.h>
/* <--auto.start.xmacro(ALL).define> */
/* <auto.end.xmacro(ALL).define> */
/* <--auto.start.xenum(ALL).define> */
/* <auto.end.xenum(ALL).define> */

View File

@@ -0,0 +1,137 @@
/**************************************************************************//**
*
* @file
* @brief x86_64_accton_as5916_54xl Configuration Header
*
* @addtogroup x86_64_accton_as5916_54xl-config
* @{
*
*****************************************************************************/
#ifndef __X86_64_ACCTON_AS5916_54XL_CONFIG_H__
#define __X86_64_ACCTON_AS5916_54XL_CONFIG_H__
#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG
#include <global_custom_config.h>
#endif
#ifdef X86_64_ACCTON_AS5916_54XL_INCLUDE_CUSTOM_CONFIG
#include <x86_64_accton_as5916_54xl_custom_config.h>
#endif
/* <auto.start.cdefs(X86_64_ACCTON_AS5916_54XL_CONFIG_HEADER).header> */
#include <AIM/aim.h>
/**
* X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_LOGGING
*
* Include or exclude logging. */
#ifndef X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_LOGGING
#define X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_LOGGING 1
#endif
/**
* X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_OPTIONS_DEFAULT
*
* Default enabled log options. */
#ifndef X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_OPTIONS_DEFAULT
#define X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT
#endif
/**
* X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_BITS_DEFAULT
*
* Default enabled log bits. */
#ifndef X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_BITS_DEFAULT
#define X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT
#endif
/**
* X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_CUSTOM_BITS_DEFAULT
*
* Default enabled custom log bits. */
#ifndef X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_CUSTOM_BITS_DEFAULT
#define X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0
#endif
/**
* X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB
*
* Default all porting macros to use the C standard libraries. */
#ifndef X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB
#define X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB 1
#endif
/**
* X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
*
* Include standard library headers for stdlib porting macros. */
#ifndef X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
#define X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB
#endif
/**
* X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_UCLI
*
* Include generic uCli support. */
#ifndef X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_UCLI
#define X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_UCLI 0
#endif
/**
* X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION
*
* Assume chassis fan direction is the same as the PSU fan direction. */
#ifndef X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION
#define X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0
#endif
/**
* All compile time options can be queried or displayed
*/
/** Configuration settings structure. */
typedef struct x86_64_accton_as5916_54xl_config_settings_s {
/** name */
const char* name;
/** value */
const char* value;
} x86_64_accton_as5916_54xl_config_settings_t;
/** Configuration settings table. */
/** x86_64_accton_as5916_54xl_config_settings table. */
extern x86_64_accton_as5916_54xl_config_settings_t x86_64_accton_as5916_54xl_config_settings[];
/**
* @brief Lookup a configuration setting.
* @param setting The name of the configuration option to lookup.
*/
const char* x86_64_accton_as5916_54xl_config_lookup(const char* setting);
/**
* @brief Show the compile-time configuration.
* @param pvs The output stream.
*/
int x86_64_accton_as5916_54xl_config_show(struct aim_pvs_s* pvs);
/* <auto.end.cdefs(X86_64_ACCTON_AS5916_54XL_CONFIG_HEADER).header> */
#include "x86_64_accton_as5916_54xl_porting.h"
#endif /* __X86_64_ACCTON_AS5916_54XL_CONFIG_H__ */
/* @} */

View File

@@ -0,0 +1,26 @@
/**************************************************************************//**
*
* x86_64_accton_as5916_54xl Doxygen Header
*
*****************************************************************************/
#ifndef __X86_64_ACCTON_AS5916_54XL_DOX_H__
#define __X86_64_ACCTON_AS5916_54XL_DOX_H__
/**
* @defgroup x86_64_accton_as5916_54xl x86_64_accton_as5916_54xl - x86_64_accton_as5916_54xl Description
*
The documentation overview for this module should go here.
*
* @{
*
* @defgroup x86_64_accton_as5916_54xl-x86_64_accton_as5916_54xl Public Interface
* @defgroup x86_64_accton_as5916_54xl-config Compile Time Configuration
* @defgroup x86_64_accton_as5916_54xl-porting Porting Macros
*
* @}
*
*/
#endif /* __X86_64_ACCTON_AS5916_54XL_DOX_H__ */

View File

@@ -0,0 +1,107 @@
/**************************************************************************//**
*
* @file
* @brief x86_64_accton_as5916_54xl Porting Macros.
*
* @addtogroup x86_64_accton_as5916_54xl-porting
* @{
*
*****************************************************************************/
#ifndef __X86_64_ACCTON_AS5916_54XL_PORTING_H__
#define __X86_64_ACCTON_AS5916_54XL_PORTING_H__
/* <auto.start.portingmacro(ALL).define> */
#if X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <memory.h>
#endif
#ifndef X86_64_ACCTON_AS5916_54XL_MALLOC
#if defined(GLOBAL_MALLOC)
#define X86_64_ACCTON_AS5916_54XL_MALLOC GLOBAL_MALLOC
#elif X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB == 1
#define X86_64_ACCTON_AS5916_54XL_MALLOC malloc
#else
#error The macro X86_64_ACCTON_AS5916_54XL_MALLOC is required but cannot be defined.
#endif
#endif
#ifndef X86_64_ACCTON_AS5916_54XL_FREE
#if defined(GLOBAL_FREE)
#define X86_64_ACCTON_AS5916_54XL_FREE GLOBAL_FREE
#elif X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB == 1
#define X86_64_ACCTON_AS5916_54XL_FREE free
#else
#error The macro X86_64_ACCTON_AS5916_54XL_FREE is required but cannot be defined.
#endif
#endif
#ifndef X86_64_ACCTON_AS5916_54XL_MEMSET
#if defined(GLOBAL_MEMSET)
#define X86_64_ACCTON_AS5916_54XL_MEMSET GLOBAL_MEMSET
#elif X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB == 1
#define X86_64_ACCTON_AS5916_54XL_MEMSET memset
#else
#error The macro X86_64_ACCTON_AS5916_54XL_MEMSET is required but cannot be defined.
#endif
#endif
#ifndef X86_64_ACCTON_AS5916_54XL_MEMCPY
#if defined(GLOBAL_MEMCPY)
#define X86_64_ACCTON_AS5916_54XL_MEMCPY GLOBAL_MEMCPY
#elif X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB == 1
#define X86_64_ACCTON_AS5916_54XL_MEMCPY memcpy
#else
#error The macro X86_64_ACCTON_AS5916_54XL_MEMCPY is required but cannot be defined.
#endif
#endif
#ifndef X86_64_ACCTON_AS5916_54XL_STRNCPY
#if defined(GLOBAL_STRNCPY)
#define X86_64_ACCTON_AS5916_54XL_STRNCPY GLOBAL_STRNCPY
#elif X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB == 1
#define X86_64_ACCTON_AS5916_54XL_STRNCPY strncpy
#else
#error The macro X86_64_ACCTON_AS5916_54XL_STRNCPY is required but cannot be defined.
#endif
#endif
#ifndef X86_64_ACCTON_AS5916_54XL_VSNPRINTF
#if defined(GLOBAL_VSNPRINTF)
#define X86_64_ACCTON_AS5916_54XL_VSNPRINTF GLOBAL_VSNPRINTF
#elif X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB == 1
#define X86_64_ACCTON_AS5916_54XL_VSNPRINTF vsnprintf
#else
#error The macro X86_64_ACCTON_AS5916_54XL_VSNPRINTF is required but cannot be defined.
#endif
#endif
#ifndef X86_64_ACCTON_AS5916_54XL_SNPRINTF
#if defined(GLOBAL_SNPRINTF)
#define X86_64_ACCTON_AS5916_54XL_SNPRINTF GLOBAL_SNPRINTF
#elif X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB == 1
#define X86_64_ACCTON_AS5916_54XL_SNPRINTF snprintf
#else
#error The macro X86_64_ACCTON_AS5916_54XL_SNPRINTF is required but cannot be defined.
#endif
#endif
#ifndef X86_64_ACCTON_AS5916_54XL_STRLEN
#if defined(GLOBAL_STRLEN)
#define X86_64_ACCTON_AS5916_54XL_STRLEN GLOBAL_STRLEN
#elif X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB == 1
#define X86_64_ACCTON_AS5916_54XL_STRLEN strlen
#else
#error The macro X86_64_ACCTON_AS5916_54XL_STRLEN is required but cannot be defined.
#endif
#endif
/* <auto.end.portingmacro(ALL).define> */
#endif /* __X86_64_ACCTON_AS5916_54XL_PORTING_H__ */
/* @} */

View File

@@ -0,0 +1,10 @@
###############################################################################
#
#
#
###############################################################################
THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
x86_64_accton_as5916_54xl_INCLUDES := -I $(THIS_DIR)inc
x86_64_accton_as5916_54xl_INTERNAL_INCLUDES := -I $(THIS_DIR)src
x86_64_accton_as5916_54xl_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5916_54xl ucli:x86_64_accton_as5916_54xl

View File

@@ -0,0 +1,9 @@
###############################################################################
#
# Local source generation targets.
#
###############################################################################
ucli:
@../../../../tools/uclihandlers.py x86_64_accton_as5916_54xl_ucli.c

View File

@@ -0,0 +1,235 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2014 Accton Technology Corporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
* Fan Platform Implementation Defaults.
*
***********************************************************/
#include <onlplib/file.h>
#include <onlp/platformi/fani.h>
#include "platform_lib.h"
enum fan_id {
FAN_1_ON_FAN_BOARD = 1,
FAN_2_ON_FAN_BOARD,
FAN_3_ON_FAN_BOARD,
FAN_4_ON_FAN_BOARD,
FAN_5_ON_FAN_BOARD,
FAN_6_ON_FAN_BOARD,
FAN_1_ON_PSU_1,
FAN_1_ON_PSU_2,
};
#define MAX_FAN_SPEED 25500
#define MAX_PSU_FAN_SPEED 25500
#define CHASSIS_FAN_INFO(fid) \
{ \
{ ONLP_FAN_ID_CREATE(FAN_##fid##_ON_FAN_BOARD), "Chassis Fan - "#fid, 0 },\
0x0,\
ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\
0,\
0,\
ONLP_FAN_MODE_INVALID,\
}
#define PSU_FAN_INFO(pid, fid) \
{ \
{ ONLP_FAN_ID_CREATE(FAN_##fid##_ON_PSU_##pid), "PSU "#pid" - Fan "#fid, 0 },\
0x0,\
ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\
0,\
0,\
ONLP_FAN_MODE_INVALID,\
}
/* Static fan information */
onlp_fan_info_t finfo[] = {
{ }, /* Not used */
CHASSIS_FAN_INFO(1),
CHASSIS_FAN_INFO(2),
CHASSIS_FAN_INFO(3),
CHASSIS_FAN_INFO(4),
CHASSIS_FAN_INFO(5),
CHASSIS_FAN_INFO(6),
PSU_FAN_INFO(1, 1),
PSU_FAN_INFO(2, 1)
};
#define VALIDATE(_id) \
do { \
if(!ONLP_OID_IS_FAN(_id)) { \
return ONLP_STATUS_E_INVALID; \
} \
} while(0)
static int
_onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)
{
int value, ret;
/* get fan present status
*/
ret = onlp_file_read_int(&value, "%s""fan%d_present", FAN_BOARD_PATH, fid);
if (ret < 0) {
AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH);
return ONLP_STATUS_E_INTERNAL;
}
if (value == 0) {
return ONLP_STATUS_OK; /* fan is not present */
}
info->status |= ONLP_FAN_STATUS_PRESENT;
/* get fan direction
*/
info->status |= ONLP_FAN_STATUS_F2B;
/* get fan speed
*/
ret = onlp_file_read_int(&value, "%s""fan%d_input", FAN_BOARD_PATH, fid);
if (ret < 0) {
AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH);
return ONLP_STATUS_E_INTERNAL;
}
info->rpm = value;
info->percentage = (info->rpm * 100)/MAX_FAN_SPEED;
/* get fan fault status
*/
if (!info->rpm) {
info->status |= ONLP_FAN_STATUS_FAILED;
}
return ONLP_STATUS_OK;
}
static int
_onlp_fani_info_get_fan_on_psu(int pid, onlp_fan_info_t* info)
{
int value, ret;
info->status |= ONLP_FAN_STATUS_PRESENT;
/* get fan direction
*/
info->status |= ONLP_FAN_STATUS_F2B;
/* get fan speed
*/
ret = onlp_file_read_int(&value, "%s""psu%d_fan1_input", PSU_SYSFS_PATH, pid);
if (ret < 0) {
AIM_LOG_ERROR("Unable to read status from (%s)\r\n", PSU_SYSFS_PATH);
return ONLP_STATUS_E_INTERNAL;
}
info->rpm = value;
info->percentage = (info->rpm * 100)/MAX_PSU_FAN_SPEED;
/* get fan fault status
*/
if (!info->rpm) {
info->status |= ONLP_FAN_STATUS_FAILED;
}
return ONLP_STATUS_OK;
}
/*
* This function will be called prior to all of onlp_fani_* functions.
*/
int
onlp_fani_init(void)
{
return ONLP_STATUS_OK;
}
int
onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info)
{
int rc = 0;
int fid;
VALIDATE(id);
fid = ONLP_OID_ID_GET(id);
*info = finfo[fid];
switch (fid)
{
case FAN_1_ON_PSU_1:
rc = _onlp_fani_info_get_fan_on_psu(PSU1_ID, info);
break;
case FAN_1_ON_PSU_2:
rc = _onlp_fani_info_get_fan_on_psu(PSU2_ID, info);
break;
case FAN_1_ON_FAN_BOARD:
case FAN_2_ON_FAN_BOARD:
case FAN_3_ON_FAN_BOARD:
case FAN_4_ON_FAN_BOARD:
case FAN_5_ON_FAN_BOARD:
case FAN_6_ON_FAN_BOARD:
rc =_onlp_fani_info_get_fan(fid, info);
break;
default:
rc = ONLP_STATUS_E_INVALID;
break;
}
return rc;
}
/*
* This function sets the fan speed of the given OID as a percentage.
*
* This will only be called if the OID has the PERCENTAGE_SET
* capability.
*
* It is optional if you have no fans at all with this feature.
*/
int
onlp_fani_percentage_set(onlp_oid_t id, int p)
{
int fid;
VALIDATE(id);
fid = ONLP_OID_ID_GET(id);
/* reject p=0 (p=0, stop fan) */
if (p == 0){
return ONLP_STATUS_E_INVALID;
}
if (fid < FAN_1_ON_FAN_BOARD || fid > FAN_6_ON_FAN_BOARD) {
return ONLP_STATUS_E_INVALID;
}
if (onlp_file_write_int(p, "%s""fan%d_pwm", FAN_BOARD_PATH, fid) < 0) {
AIM_LOG_ERROR("Unable to write data to file %s""fan%d_pwm", FAN_BOARD_PATH, fid);
return ONLP_STATUS_E_INTERNAL;
}
return ONLP_STATUS_OK;
}

View File

@@ -0,0 +1,247 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2013 Accton Technology Corporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
*
*
***********************************************************/
#include <onlplib/file.h>
#include <onlp/platformi/ledi.h>
#include "platform_lib.h"
#define LED_FORMAT "/sys/devices/platform/as5916_54xl_led/%s"
#define VALIDATE(_id) \
do { \
if(!ONLP_OID_IS_LED(_id)) { \
return ONLP_STATUS_E_INVALID; \
} \
} while(0)
/* LED related data
*/
enum onlp_led_id
{
LED_RESERVED = 0,
LED_LOC,
LED_DIAG,
LED_PSU1,
LED_PSU2,
LED_FAN,
};
enum led_light_mode {
LED_MODE_OFF,
LED_MODE_RED = 10,
LED_MODE_RED_BLINKING = 11,
LED_MODE_ORANGE = 12,
LED_MODE_ORANGE_BLINKING = 13,
LED_MODE_YELLOW = 14,
LED_MODE_YELLOW_BLINKING = 15,
LED_MODE_GREEN = 16,
LED_MODE_GREEN_BLINKING = 17,
LED_MODE_BLUE = 18,
LED_MODE_BLUE_BLINKING = 19,
LED_MODE_PURPLE = 20,
LED_MODE_PURPLE_BLINKING = 21,
LED_MODE_AUTO = 22,
LED_MODE_AUTO_BLINKING = 23,
LED_MODE_WHITE = 24,
LED_MODE_WHITE_BLINKING = 25,
LED_MODE_CYAN = 26,
LED_MODE_CYAN_BLINKING = 27,
LED_MODE_UNKNOWN = 99
};
typedef struct led_light_mode_map {
enum onlp_led_id id;
enum led_light_mode driver_led_mode;
enum onlp_led_mode_e onlp_led_mode;
} led_light_mode_map_t;
led_light_mode_map_t led_map[] = {
{LED_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF},
{LED_LOC, LED_MODE_ORANGE_BLINKING, ONLP_LED_MODE_ORANGE_BLINKING},
{LED_DIAG, LED_MODE_OFF, ONLP_LED_MODE_OFF},
{LED_DIAG, LED_MODE_GREEN, ONLP_LED_MODE_GREEN},
{LED_DIAG, LED_MODE_ORANGE, ONLP_LED_MODE_ORANGE},
{LED_FAN, LED_MODE_AUTO, ONLP_LED_MODE_AUTO},
{LED_PSU1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO},
{LED_PSU2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}
};
static char *leds[] = /* must map with onlp_led_id */
{
NULL,
"led_loc",
"led_diag",
"led_psu1",
"led_psu2",
"led_fan"
};
/*
* Get the information for the given LED OID.
*/
static onlp_led_info_t linfo[] =
{
{ }, /* Not used */
{
{ ONLP_LED_ID_CREATE(LED_LOC), "Chassis LED 1 (LOC LED)", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_DIAG), "Chassis LED 2 (DIAG LED)", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE,
},
{
{ ONLP_LED_ID_CREATE(LED_PSU1), "Chassis LED 3 (PSU1 LED)", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO,
},
{
{ ONLP_LED_ID_CREATE(LED_PSU2), "Chassis LED 4 (PSU2 LED)", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO,
},
{
{ ONLP_LED_ID_CREATE(LED_FAN), "Chassis LED 5 (FAN LED)", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO,
},
};
static int driver_to_onlp_led_mode(enum onlp_led_id id, enum led_light_mode driver_led_mode)
{
int i, nsize = sizeof(led_map)/sizeof(led_map[0]);
for (i = 0; i < nsize; i++)
{
if (id == led_map[i].id && driver_led_mode == led_map[i].driver_led_mode)
{
return led_map[i].onlp_led_mode;
}
}
return 0;
}
static int onlp_to_driver_led_mode(enum onlp_led_id id, onlp_led_mode_t onlp_led_mode)
{
int i, nsize = sizeof(led_map)/sizeof(led_map[0]);
for(i = 0; i < nsize; i++)
{
if (id == led_map[i].id && onlp_led_mode == led_map[i].onlp_led_mode)
{
return led_map[i].driver_led_mode;
}
}
return 0;
}
/*
* This function will be called prior to any other onlp_ledi_* functions.
*/
int
onlp_ledi_init(void)
{
/*
* Turn off the LOCATION and DIAG LEDs at startup
*/
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_DIAG), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_LOC), ONLP_LED_MODE_OFF);
return ONLP_STATUS_OK;
}
int
onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
{
int lid, value;
VALIDATE(id);
lid = ONLP_OID_ID_GET(id);
/* Set the onlp_oid_hdr_t and capabilities */
*info = linfo[ONLP_OID_ID_GET(id)];
/* Get LED mode */
if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) {
DEBUG_PRINT("Unable to read status from file "LED_FORMAT, leds[lid]);
return ONLP_STATUS_E_INTERNAL;
}
info->mode = driver_to_onlp_led_mode(lid, value);
/* Set the on/off status */
if (info->mode != ONLP_LED_MODE_OFF && info->mode != ONLP_LED_MODE_AUTO) {
info->status |= ONLP_LED_STATUS_ON;
}
return ONLP_STATUS_OK;
}
/*
* Turn an LED on or off.
*
* This function will only be called if the LED OID supports the ONOFF
* capability.
*
* What 'on' means in terms of colors or modes for multimode LEDs is
* up to the platform to decide. This is intended as baseline toggle mechanism.
*/
int
onlp_ledi_set(onlp_oid_t id, int on_or_off)
{
VALIDATE(id);
if (!on_or_off) {
return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF);
}
return ONLP_STATUS_E_UNSUPPORTED;
}
/*
* This function puts the LED into the given mode. It is a more functional
* interface for multimode LEDs.
*
* Only modes reported in the LED's capabilities will be attempted.
*/
int
onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode)
{
int lid;
VALIDATE(id);
lid = ONLP_OID_ID_GET(id);
if (onlp_file_write_int(onlp_to_driver_led_mode(lid , mode), LED_FORMAT, leds[lid]) < 0) {
return ONLP_STATUS_E_INTERNAL;
}
return ONLP_STATUS_OK;
}

View File

@@ -0,0 +1,9 @@
###############################################################################
#
#
#
###############################################################################
LIBRARY := x86_64_accton_as5916_54xl
$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(BUILDER)/lib.mk

View File

@@ -0,0 +1,65 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2014 Accton Technology Corporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
*
*
***********************************************************/
#ifndef __PLATFORM_LIB_H__
#define __PLATFORM_LIB_H__
#include "x86_64_accton_as5916_54xl_log.h"
#define CHASSIS_FAN_COUNT 6
#define CHASSIS_THERMAL_COUNT 5
#define CHASSIS_LED_COUNT 5
#define CHASSIS_PSU_COUNT 2
#define PSU1_ID 1
#define PSU2_ID 2
#define PSU_SYSFS_PATH "/sys/devices/platform/as5916_54xl_psu/"
#define FAN_BOARD_PATH "/sys/devices/platform/as5916_54xl_fan/"
#define IDPROM_PATH "/sys/devices/platform/as5916_54xl_sys/eeprom"
enum onlp_thermal_id
{
THERMAL_RESERVED = 0,
THERMAL_CPU_CORE,
THERMAL_1_ON_MAIN_BROAD,
THERMAL_2_ON_MAIN_BROAD,
THERMAL_3_ON_MAIN_BROAD,
THERMAL_4_ON_MAIN_BROAD,
THERMAL_1_ON_PSU1,
THERMAL_1_ON_PSU2,
};
#define DEBUG_MODE 0
#if (DEBUG_MODE == 1)
#define DEBUG_PRINT(fmt, args...) \
printf("%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args)
#else
#define DEBUG_PRINT(fmt, args...)
#endif
#endif /* __PLATFORM_LIB_H__ */

View File

@@ -0,0 +1,154 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2014 Accton Technology Corporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
*
*
***********************************************************/
#include <onlp/platformi/psui.h>
#include <onlplib/file.h>
#include "platform_lib.h"
#define PSU_STATUS_PRESENT 1
#define PSU_STATUS_POWER_GOOD 1
#define VALIDATE(_id) \
do { \
if(!ONLP_OID_IS_PSU(_id)) { \
return ONLP_STATUS_E_INVALID; \
} \
} while(0)
int
onlp_psui_init(void)
{
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 pid = ONLP_OID_ID_GET(id);
VALIDATE(id);
memset(info, 0, sizeof(onlp_psu_info_t));
*info = pinfo[pid]; /* Set the onlp_oid_hdr_t */
/* Get the present state */
ret = onlp_file_read_int(&val, "%s""psu%d_present", PSU_SYSFS_PATH, pid);
if (ret < 0) {
AIM_LOG_ERROR("Unable to read status from (%s""psu%d_present)\r\n", PSU_SYSFS_PATH, pid);
return ONLP_STATUS_E_INTERNAL;
}
if (val != PSU_STATUS_PRESENT) {
info->status &= ~ONLP_PSU_STATUS_PRESENT;
return ONLP_STATUS_OK;
}
info->status |= ONLP_PSU_STATUS_PRESENT;
/* Get power good status */
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;
}
/* Read voltage, current and power */
val = 0;
if (onlp_file_read_int(&val, "%s""psu%d_vin", PSU_SYSFS_PATH, pid) == 0 && val) {
info->mvin = val;
info->caps |= ONLP_PSU_CAPS_VIN;
}
val = 0;
if (onlp_file_read_int(&val, "%s""psu%d_vout", PSU_SYSFS_PATH, pid) == 0 && val) {
info->mvout = val;
info->caps |= ONLP_PSU_CAPS_VOUT;
}
val = 0;
if (onlp_file_read_int(&val, "%s""psu%d_iout", PSU_SYSFS_PATH, pid) == 0 && val) {
info->miout = val;
info->caps |= ONLP_PSU_CAPS_IOUT;
}
val = 0;
if (onlp_file_read_int(&val, "%s""psu%d_pout", PSU_SYSFS_PATH, pid) == 0 && val) {
info->mpout = val;
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 + CHASSIS_THERMAL_COUNT);
}
/* Read model */
char *string = NULL;
int len = onlp_file_read_str(&string, "%s""psu%d_model", PSU_SYSFS_PATH, pid);
if (string && len) {
strncpy(info->model, string, len);
aim_free(string);
}
/* Read serial */
len = onlp_file_read_str(&string, "%s""psu%d_serial", PSU_SYSFS_PATH, pid);
if (string && len) {
strncpy(info->serial, string, len);
aim_free(string);
}
return ret;
}

View File

@@ -0,0 +1,289 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2017 Accton Technology Corporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
*
*
***********************************************************/
#include <onlp/platformi/sfpi.h>
#include <onlplib/i2c.h>
#include <onlplib/file.h>
#include "x86_64_accton_as5916_54xl_int.h"
#include "x86_64_accton_as5916_54xl_log.h"
#define PORT_EEPROM_FORMAT "/sys/devices/platform/as5916_54xl_sfp/module_eeprom_%d"
#define MODULE_PRESENT_FORMAT "/sys/devices/platform/as5916_54xl_sfp/module_present_%d"
#define MODULE_RXLOS_FORMAT "/sys/devices/platform/as5916_54xl_sfp/module_rx_los_%d"
#define MODULE_TXFAULT_FORMAT "/sys/devices/platform/as5916_54xl_sfp/module_tx_fault_%d"
#define MODULE_TXDISABLE_FORMAT "/sys/devices/platform/as5916_54xl_sfp/module_tx_disable_%d"
#define MODULE_PRESENT_ALL_ATTR "/sys/devices/platform/as5916_54xl_sfp/module_present_all"
#define MODULE_RXLOS_ALL_ATTR "/sys/devices/platform/as5916_54xl_sfp/module_rxlos_all"
/************************************************************
*
* SFPI Entry Points
*
***********************************************************/
int
onlp_sfpi_init(void)
{
/* Called at initialization time */
return ONLP_STATUS_OK;
}
int
onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap)
{
/*
* Ports {0, 54}
*/
int p;
for(p = 0; p < 54; p++) {
AIM_BITMAP_SET(bmap, p);
}
return ONLP_STATUS_OK;
}
int
onlp_sfpi_is_present(int port)
{
/*
* Return 1 if present.
* Return 0 if not present.
* Return < 0 if error.
*/
int present;
if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
return present;
}
int
onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
{
uint32_t bytes[7];
FILE* fp;
/* Read present status of port 0~54 */
int count = 0;
fp = fopen(MODULE_PRESENT_ALL_ATTR, "r");
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the module_present_all device file from (%s).", MODULE_PRESENT_ALL_ATTR);
return ONLP_STATUS_E_INTERNAL;
}
count = fscanf(fp, "%x %x %x %x %x %x %x", bytes+0, bytes+1, bytes+2, bytes+3,
bytes+4, bytes+5, bytes+6);
fclose(fp);
if(count != 7) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read all fields the module_present_all device file from(%s).", MODULE_PRESENT_ALL_ATTR);
return ONLP_STATUS_E_INTERNAL;
}
/* Mask out non-existant QSFP ports */
bytes[6] &= 0x3F;
/* Convert to 64 bit integer in port order */
int i = 0;
uint64_t presence_all = 0 ;
for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
presence_all <<= 8;
presence_all |= bytes[i];
}
/* Populate bitmap */
for(i = 0; presence_all; i++) {
AIM_BITMAP_MOD(dst, i, (presence_all & 1));
presence_all >>= 1;
}
return ONLP_STATUS_OK;
}
int
onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
{
uint32_t bytes[6];
FILE* fp;
/* Read present status of port 0~25 */
int count = 0;
fp = fopen(MODULE_RXLOS_ALL_ATTR, "r");
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the module_rxlos_all device file from (%s).", MODULE_RXLOS_ALL_ATTR);
return ONLP_STATUS_E_INTERNAL;
}
count = fscanf(fp, "%x %x %x %x %x %x", bytes+0, bytes+1, bytes+2,
bytes+3, bytes+4, bytes+5);
fclose(fp);
if(count != 6) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read all fields the module_rxlos_all device file from(%s).", MODULE_RXLOS_ALL_ATTR);
return ONLP_STATUS_E_INTERNAL;
}
/* Convert to 64 bit integer in port order */
int i = 0;
uint64_t rx_los_all = 0 ;
for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
rx_los_all <<= 8;
rx_los_all |= bytes[i];
}
/* Populate bitmap */
for(i = 0; rx_los_all; i++) {
AIM_BITMAP_MOD(dst, i, (rx_los_all & 1));
rx_los_all >>= 1;
}
return ONLP_STATUS_OK;
}
int
onlp_sfpi_eeprom_read(int port, uint8_t data[256])
{
/*
* Read the SFP eeprom into data[]
*
* Return MISSING if SFP is missing.
* Return OK if eeprom is read
*/
int size = 0;
memset(data, 0, 256);
if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, (port+1)) != ONLP_STATUS_OK) {
AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
if (size != 256) {
AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
return ONLP_STATUS_OK;
}
int
onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
{
int rv;
switch(control)
{
case ONLP_SFP_CONTROL_TX_DISABLE:
{
if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
else {
rv = ONLP_STATUS_OK;
}
break;
}
default:
rv = ONLP_STATUS_E_UNSUPPORTED;
break;
}
return rv;
}
int
onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
{
int rv;
if (port < 0) {
return ONLP_STATUS_E_UNSUPPORTED;
}
switch(control)
{
case ONLP_SFP_CONTROL_RX_LOS:
{
if (port >= 48) {
return ONLP_STATUS_E_UNSUPPORTED;
}
if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
else {
rv = ONLP_STATUS_OK;
}
break;
}
case ONLP_SFP_CONTROL_TX_FAULT:
{
if (port >= 48) {
return ONLP_STATUS_E_UNSUPPORTED;
}
if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
else {
rv = ONLP_STATUS_OK;
}
break;
}
case ONLP_SFP_CONTROL_TX_DISABLE:
{
if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
else {
rv = ONLP_STATUS_OK;
}
break;
}
default:
rv = ONLP_STATUS_E_UNSUPPORTED;
}
return rv;
}
int
onlp_sfpi_denit(void)
{
return ONLP_STATUS_OK;
}

View File

@@ -0,0 +1,132 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2017 Accton Technology Corporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
*
*
***********************************************************/
#include <unistd.h>
#include <fcntl.h>
#include <onlplib/file.h>
#include <onlp/platformi/sysi.h>
#include <onlp/platformi/ledi.h>
#include <onlp/platformi/thermali.h>
#include <onlp/platformi/fani.h>
#include <onlp/platformi/psui.h>
#include "platform_lib.h"
#include "x86_64_accton_as5916_54xl_int.h"
#include "x86_64_accton_as5916_54xl_log.h"
const char*
onlp_sysi_platform_get(void)
{
return "x86-64-accton-as5916-54xl-r0";
}
int
onlp_sysi_onie_data_get(uint8_t** data, int* size)
{
uint8_t* rdata = aim_zmalloc(256);
if(onlp_file_read(rdata, 256, size, IDPROM_PATH) == ONLP_STATUS_OK) {
if(*size == 256) {
*data = rdata;
return ONLP_STATUS_OK;
}
}
aim_free(rdata);
*size = 0;
return ONLP_STATUS_E_INTERNAL;
}
int
onlp_sysi_oids_get(onlp_oid_t* table, int max)
{
int i;
onlp_oid_t* e = table;
memset(table, 0, max*sizeof(onlp_oid_t));
/* 5 Thermal sensors on the chassis */
for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) {
*e++ = ONLP_THERMAL_ID_CREATE(i);
}
/* 5 LEDs on the chassis */
for (i = 1; i <= CHASSIS_LED_COUNT; i++) {
*e++ = ONLP_LED_ID_CREATE(i);
}
/* 2 PSUs on the chassis */
for (i = 1; i <= CHASSIS_PSU_COUNT; i++) {
*e++ = ONLP_PSU_ID_CREATE(i);
}
/* 6 Fans on the chassis */
for (i = 1; i <= CHASSIS_FAN_COUNT; i++) {
*e++ = ONLP_FAN_ID_CREATE(i);
}
return 0;
}
#define CPLD_VERSION_FORMAT "/sys/devices/platform/as5916_54xl_sys/%s"
typedef struct cpld_version {
char *attr_name;
int version;
char *description;
} cpld_version_t;
int
onlp_sysi_platform_info_get(onlp_platform_info_t* pi)
{
int i, ret;
cpld_version_t cplds[] = { { "mb_cpld1_ver", 0, "Mainboard-CPLD#1"},
{ "mb_cpld2_ver", 0, "Mainboard-CPLD#2"},
{ "cpu_cpld_ver", 0, "CPU-CPLD"},
{ "fan_cpld_ver", 0, "FAN-CPLD"} };
/* Read CPLD version
*/
for (i = 0; i < AIM_ARRAYSIZE(cplds); i++) {
ret = onlp_file_read_int(&cplds[i].version, CPLD_VERSION_FORMAT, cplds[i].attr_name);
if (ret < 0) {
AIM_LOG_ERROR("Unable to read version from CPLD(%s)\r\n", cplds[i].attr_name);
return ONLP_STATUS_E_INTERNAL;
}
}
pi->cpld_versions = aim_fstrdup("%s:%d, %s:%d, %s:%d, %s:%d",
cplds[0].description, cplds[0].version,
cplds[1].description, cplds[1].version,
cplds[2].description, cplds[2].version,
cplds[3].description, cplds[3].version);
return ONLP_STATUS_OK;
}
void
onlp_sysi_platform_info_free(onlp_platform_info_t* pi)
{
aim_free(pi->cpld_versions);
}

View File

@@ -0,0 +1,129 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2014 Accton Technology Corporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
* Thermal Sensor Platform Implementation.
*
***********************************************************/
#include <onlplib/file.h>
#include <onlp/platformi/thermali.h>
#include "platform_lib.h"
#define VALIDATE(_id) \
do { \
if(!ONLP_OID_IS_THERMAL(_id)) { \
return ONLP_STATUS_E_INVALID; \
} \
} while(0)
static char* ipmi_devfiles__[] = /* must map with onlp_thermal_id */
{
NULL,
NULL, /* CPU_CORE files */
"/sys/devices/platform/as5916_54xl_thermal/temp1_input",
"/sys/devices/platform/as5916_54xl_thermal/temp2_input",
"/sys/devices/platform/as5916_54xl_thermal/temp3_input",
"/sys/devices/platform/as5916_54xl_thermal/temp4_input",
"/sys/devices/platform/as5916_54xl_psu/psu1_temp1_input",
"/sys/devices/platform/as5916_54xl_psu/psu2_temp1_input",
};
static char* cpu_coretemp_files[] =
{
"/sys/devices/platform/coretemp.0*temp2_input",
"/sys/devices/platform/coretemp.0*temp3_input",
"/sys/devices/platform/coretemp.0*temp4_input",
"/sys/devices/platform/coretemp.0*temp5_input",
NULL,
};
/* Static values */
static onlp_thermal_info_t linfo[] = {
{ }, /* Not used */
{ { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), "CPU Core", 0},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
},
{ { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-1", 0},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
},
{ { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "LM75-2", 0},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
},
{ { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "LM75-3", 0},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
},
{ { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "LM75-4", 0},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
},
{ { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU1), "PSU-1 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU1_ID)},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
},
{ { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU2), "PSU-2 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU2_ID)},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
}
};
/*
* This will be called to intiialize the thermali subsystem.
*/
int
onlp_thermali_init(void)
{
return ONLP_STATUS_OK;
}
/*
* Retrieve the information structure for the given thermal OID.
*
* If the OID is invalid, return ONLP_E_STATUS_INVALID.
* If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
* Otherwise, return ONLP_STATUS_OK with the OID's information.
*
* Note -- it is expected that you fill out the information
* structure even if the sensor described by the OID is not present.
*/
int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
{
int tid;
VALIDATE(id);
tid = ONLP_OID_ID_GET(id);
/* Set the onlp_oid_hdr_t and capabilities */
*info = linfo[tid];
if(tid == THERMAL_CPU_CORE) {
int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
return rv;
}
return onlp_file_read_int(&info->mcelsius, ipmi_devfiles__[tid]);
}

View File

@@ -0,0 +1,80 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_accton_as5916_54xl/x86_64_accton_as5916_54xl_config.h>
/* <auto.start.cdefs(X86_64_ACCTON_AS5916_54XL_CONFIG_HEADER).source> */
#define __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(_x) #_x
#define __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE(_x) __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(_x)
x86_64_accton_as5916_54xl_config_settings_t x86_64_accton_as5916_54xl_config_settings[] =
{
#ifdef X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_LOGGING
{ __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_LOGGING) },
#else
{ X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5916_54xl_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_OPTIONS_DEFAULT
{ __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_OPTIONS_DEFAULT) },
#else
{ X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5916_54xl_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_BITS_DEFAULT
{ __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_BITS_DEFAULT) },
#else
{ X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5916_54xl_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_CUSTOM_BITS_DEFAULT
{ __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_CUSTOM_BITS_DEFAULT) },
#else
{ X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5916_54xl_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB
{ __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB), __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB) },
#else
{ X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_STDLIB(__x86_64_accton_as5916_54xl_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
{ __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) },
#else
{ X86_64_ACCTON_AS5916_54XL_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5916_54xl_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_UCLI
{ __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_UCLI) },
#else
{ X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5916_54xl_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION
{ __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) },
#else
{ X86_64_ACCTON_AS5916_54XL_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5916_54xl_config_STRINGIFY_NAME), "__undefined__" },
#endif
{ NULL, NULL }
};
#undef __x86_64_accton_as5916_54xl_config_STRINGIFY_VALUE
#undef __x86_64_accton_as5916_54xl_config_STRINGIFY_NAME
const char*
x86_64_accton_as5916_54xl_config_lookup(const char* setting)
{
int i;
for(i = 0; x86_64_accton_as5916_54xl_config_settings[i].name; i++) {
if(!strcmp(x86_64_accton_as5916_54xl_config_settings[i].name, setting)) {
return x86_64_accton_as5916_54xl_config_settings[i].value;
}
}
return NULL;
}
int
x86_64_accton_as5916_54xl_config_show(struct aim_pvs_s* pvs)
{
int i;
for(i = 0; x86_64_accton_as5916_54xl_config_settings[i].name; i++) {
aim_printf(pvs, "%s = %s\n", x86_64_accton_as5916_54xl_config_settings[i].name, x86_64_accton_as5916_54xl_config_settings[i].value);
}
return i;
}
/* <auto.end.cdefs(X86_64_ACCTON_AS5916_54XL_CONFIG_HEADER).source> */

View File

@@ -0,0 +1,10 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_accton_as5916_54xl/x86_64_accton_as5916_54xl_config.h>
/* <--auto.start.enum(ALL).source> */
/* <auto.end.enum(ALL).source> */

View File

@@ -0,0 +1,12 @@
/**************************************************************************//**
*
* x86_64_accton_as5916_54xl Internal Header
*
*****************************************************************************/
#ifndef __x86_64_accton_as5916_54xl_INT_H__
#define __x86_64_accton_as5916_54xl_INT_H__
#include <x86_64_accton_as5916_54xl/x86_64_accton_as5916_54xl_config.h>
#endif /* __x86_64_accton_as5916_54xl_INT_H__ */

View File

@@ -0,0 +1,18 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_accton_as5916_54xl/x86_64_accton_as5916_54xl_config.h>
#include "x86_64_accton_as5916_54xl_log.h"
/*
* x86_64_accton_as5916_54xl log struct.
*/
AIM_LOG_STRUCT_DEFINE(
X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_OPTIONS_DEFAULT,
X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_BITS_DEFAULT,
NULL, /* Custom log map */
X86_64_ACCTON_AS5916_54XL_CONFIG_LOG_CUSTOM_BITS_DEFAULT
);

View File

@@ -0,0 +1,12 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#ifndef __x86_64_accton_as5916_54xl_LOG_H__
#define __x86_64_accton_as5916_54xl_LOG_H__
#define AIM_LOG_MODULE_NAME x86_64_accton_as5916_54xl
#include <AIM/aim_log.h>
#endif /* __x86_64_accton_as5916_54xl_LOG_H__ */

View File

@@ -0,0 +1,24 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_accton_as5916_54xl/x86_64_accton_as5916_54xl_config.h>
#include "x86_64_accton_as5916_54xl_log.h"
static int
datatypes_init__(void)
{
#define x86_64_accton_as5916_54xl_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL);
#include <x86_64_accton_as5916_54xl/x86_64_accton_as5916_54xl.x>
return 0;
}
void __x86_64_accton_as5916_54xl_module_init__(void)
{
AIM_LOG_STRUCT_REGISTER();
datatypes_init__();
}
int __onlp_platform_version__ = 1;

View File

@@ -0,0 +1,50 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_accton_as5916_54xl/x86_64_accton_as5916_54xl_config.h>
#if x86_64_accton_as5916_54xl_CONFIG_INCLUDE_UCLI == 1
#include <uCli/ucli.h>
#include <uCli/ucli_argparse.h>
#include <uCli/ucli_handler_macros.h>
static ucli_status_t
x86_64_accton_as5916_54xl_ucli_ucli__config__(ucli_context_t* uc)
{
UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as5916_54xl)
}
/* <auto.ucli.handlers.start> */
/* <auto.ucli.handlers.end> */
static ucli_module_t
x86_64_accton_as5916_54xl_ucli_module__ =
{
"x86_64_accton_as5916_54xl_ucli",
NULL,
x86_64_accton_as5916_54xl_ucli_ucli_handlers__,
NULL,
NULL,
};
ucli_node_t*
x86_64_accton_as5916_54xl_ucli_node_create(void)
{
ucli_node_t* n;
ucli_module_init(&x86_64_accton_as5916_54xl_ucli_module__);
n = ucli_node_create("x86_64_accton_as5916_54xl", NULL, &x86_64_accton_as5916_54xl_ucli_module__);
ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as5916_54xl"));
return n;
}
#else
void*
x86_64_accton_as5916_54xl_ucli_node_create(void)
{
return NULL;
}
#endif

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as5916-54xl REVISION=r0

View File

@@ -0,0 +1,33 @@
---
######################################################################
#
# platform-config for AS5916
#
######################################################################
x86-64-accton-as5916-54xl-r0:
grub:
serial: >-
--port=0x3f8
--speed=115200
--word=8
--parity=no
--stop=1
kernel:
<<: *kernel-4-14
args: >-
nopat
console=ttyS0,115200n8
tg3.short_preamble=1
tg3.bcm5718s_reset=1
##network:
## interfaces:
## ma1:
## name: ~
## syspath: pci0000:00/0000:00:1c.0/0000:0a:00.0

View File

@@ -0,0 +1,15 @@
from onl.platform.base import *
from onl.platform.accton import *
class OnlPlatform_x86_64_accton_as5916_54xl_r0(OnlPlatformAccton,
OnlPlatformPortConfig_48x10_6x100):
PLATFORM='x86-64-accton-as5916-54xl-r0'
MODEL="AS5916-54XL"
SYS_OBJECT_ID=".5916.54"
def baseconfig(self):
for m in [ 'fan', 'psu', 'leds', 'sfp', 'sys', 'thermal' ]:
self.insmod("x86-64-accton-as5916-54xl-%s.ko" % m)
return True