Merge pull request #300 from brandonchuang/as5912_54x

[as5912-54x] Add support for OOM driver
This commit is contained in:
Jeffrey Townsend
2018-02-20 13:15:23 -08:00
committed by GitHub
6 changed files with 1239 additions and 1978 deletions

View File

@@ -38,8 +38,8 @@
#define DEBUG_PRINT(fmt, args...)
#endif
extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
extern int as5912_54x_cpld_read(unsigned short cpld_addr, u8 reg);
extern int as5912_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
struct accton_as5912_54x_led_data {
struct platform_device *pdev;
@@ -148,12 +148,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type,
static int accton_as5912_54x_led_read_value(u8 reg)
{
return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg);
return as5912_54x_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg);
}
static int accton_as5912_54x_led_write_value(u8 reg, u8 value)
{
return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value);
return as5912_54x_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value);
}
static void accton_as5912_54x_led_update(void)

View File

@@ -37,7 +37,7 @@
static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf);
static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf);
static int as5912_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len);
extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int as5912_54x_cpld_read(unsigned short cpld_addr, u8 reg);
/* Addresses scanned
*/
@@ -234,7 +234,7 @@ static struct as5912_54x_psu_data *as5912_54x_psu_update_device(struct device *d
dev_dbg(&client->dev, "Starting as5912_54x update\n");
/* Read psu status */
status = accton_i2c_cpld_read(0x60, 0x2);
status = as5912_54x_cpld_read(0x60, 0x2);
if (status < 0) {
dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status);

View File

@@ -24,29 +24,21 @@
*
***********************************************************/
#include <onlp/platformi/sfpi.h>
#include <onlplib/i2c.h>
#include <onlplib/file.h>
#include "platform_lib.h"
#include "x86_64_accton_as5912_54x_int.h"
#include "x86_64_accton_as5912_54x_log.h"
#define NUM_OF_SFP_PORT 54
#define MAX_SFP_PATH 64
static char sfp_node_path[MAX_SFP_PATH] = {0};
#define FRONT_PORT_BUS_INDEX(port) (port+26)
#define PORT_BUS_INDEX(port) (port+26)
static char*
sfp_get_port_path_addr(int port, int addr, char *node_name)
{
sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-00%d/%s",
FRONT_PORT_BUS_INDEX(port), addr, node_name);
return sfp_node_path;
}
static char*
sfp_get_port_path(int port, char *node_name)
{
return sfp_get_port_path_addr(port, 50, node_name);
}
#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom"
#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_present_%d"
#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_rx_los_%d"
#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_fault_%d"
#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_disable_%d"
#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/%d-00%d/module_present_all"
#define MODULE_RXLOS_ALL_ATTR_CPLD1 "/sys/bus/i2c/devices/4-0060/module_rx_los_all"
#define MODULE_RXLOS_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/5-0062/module_rx_los_all"
/************************************************************
*
@@ -67,8 +59,8 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap)
* Ports {0, 54}
*/
int p;
for(p = 0; p < NUM_OF_SFP_PORT; p++) {
for(p = 0; p < 54; p++) {
AIM_BITMAP_SET(bmap, p);
}
@@ -84,9 +76,12 @@ onlp_sfpi_is_present(int port)
* Return < 0 if error.
*/
int present;
char *path = sfp_get_port_path(port, "sfp_is_present");
int bus, addr;
if (onlp_file_read_int(&present, path) < 0) {
addr = (port < 24) ? 60 : 62;
bus = (addr == 60) ? 4 : 5;
if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
@@ -97,33 +92,45 @@ onlp_sfpi_is_present(int port)
int
onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
{
uint32_t bytes[7];
char* path;
uint32_t bytes[7], *ptr = NULL;
FILE* fp;
int addr;
AIM_BITMAP_CLR_ALL(dst);
ptr = bytes;
path = sfp_get_port_path(0, "sfp_is_present_all");
fp = fopen(path, "r");
for (addr = 60; addr <= 62; addr+=2) {
/* Read present status of port 0~53 */
int count = 0;
char file[64] = {0};
int bus = (addr == 60) ? 4 : 5;
sprintf(file, MODULE_PRESENT_ALL_ATTR, bus, addr);
fp = fopen(file, "r");
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD(0x%d).", addr);
return ONLP_STATUS_E_INTERNAL;
}
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file.");
return ONLP_STATUS_E_INTERNAL;
}
int count = fscanf(fp, "%x %x %x %x %x %x %x",
bytes+0,
bytes+1,
bytes+2,
bytes+3,
bytes+4,
bytes+5,
bytes+6
);
fclose(fp);
if(count != AIM_ARRAYSIZE(bytes)) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file.");
return ONLP_STATUS_E_INTERNAL;
if (addr == 60) { /* CPLD1 */
count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2);
fclose(fp);
if(count != 3) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr);
return ONLP_STATUS_E_INTERNAL;
}
}
else { /* CPLD2 */
count = fscanf(fp, "%x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3);
fclose(fp);
if(count != 4) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr);
return ONLP_STATUS_E_INTERNAL;
}
}
ptr += count;
}
/* Mask out non-existant QSFP ports */
@@ -150,34 +157,40 @@ int
onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
{
uint32_t bytes[6];
char* path;
uint32_t *ptr = bytes;
FILE* fp;
path = sfp_get_port_path(0, "sfp_rx_los_all");
fp = fopen(path, "r");
/* Read present status of port 0~23 */
int addr, i = 0;
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file.");
return ONLP_STATUS_E_INTERNAL;
}
int count = fscanf(fp, "%x %x %x %x %x %x",
bytes+0,
bytes+1,
bytes+2,
bytes+3,
bytes+4,
bytes+5
);
fclose(fp);
if(count != 6) {
AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file.");
return ONLP_STATUS_E_INTERNAL;
for (addr = 60; addr <= 62; addr+=2) {
if (addr == 60) {
fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD1, "r");
}
else {
fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r");
}
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr);
return ONLP_STATUS_E_INTERNAL;
}
int count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2);
fclose(fp);
if(count != 3) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr);
return ONLP_STATUS_E_INTERNAL;
}
ptr += count;
}
/* Convert to 64 bit integer in port order */
int i = 0;
i = 0;
uint64_t rx_los_all = 0 ;
for(i = 5; i >= 0; i--) {
for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
rx_los_all <<= 8;
rx_los_all |= bytes[i];
}
@@ -194,32 +207,51 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
int
onlp_sfpi_eeprom_read(int port, uint8_t data[256])
{
char* path = sfp_get_port_path(port, "sfp_eeprom");
/*
* Read the SFP eeprom into data[]
*
* Return MISSING if SFP is missing.
* Return OK if eeprom is read
*/
int size = 0;
memset(data, 0, 256);
if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) {
if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != 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_dom_read(int port, uint8_t data[256])
{
char* path = sfp_get_port_path_addr(port, 51, "sfp_eeprom");
memset(data, 0, 256);
FILE* fp;
char file[64] = {0};
sprintf(file, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port));
fp = fopen(file, "r");
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port);
return ONLP_STATUS_E_INTERNAL;
}
if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) {
AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port);
if (fseek(fp, 256, SEEK_CUR) != 0) {
fclose(fp);
AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port);
return ONLP_STATUS_E_INTERNAL;
}
int ret = fread(data, 1, 256, fp);
fclose(fp);
if (ret != 256) {
AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port);
return ONLP_STATUS_E_INTERNAL;
}
@@ -231,13 +263,18 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
{
int rv;
if (port < 0 || port >= 48) {
return ONLP_STATUS_E_UNSUPPORTED;
}
int addr = (port < 24) ? 60 : 62;
int bus = (addr == 60) ? 4 : 5;
switch(control)
{
case ONLP_SFP_CONTROL_TX_DISABLE:
{
char* path = sfp_get_port_path(port, "sfp_tx_disable");
if (onlp_file_write_integer(path, value) != 0) {
if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
@@ -259,16 +296,20 @@ int
onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
{
int rv;
char* path = NULL;
if (port < 0 || port >= 48) {
return ONLP_STATUS_E_UNSUPPORTED;
}
int addr = (port < 24) ? 60 : 62;
int bus = (addr == 60) ? 4 : 5;
switch(control)
{
case ONLP_SFP_CONTROL_RX_LOS:
{
path = sfp_get_port_path(port, "sfp_rx_los");
if (onlp_file_read_int(value, path) < 0) {
AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port);
if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
else {
@@ -279,9 +320,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
case ONLP_SFP_CONTROL_TX_FAULT:
{
path = sfp_get_port_path(port, "sfp_tx_fault");
if (onlp_file_read_int(value, path) < 0) {
if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
@@ -293,9 +332,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
case ONLP_SFP_CONTROL_TX_DISABLE:
{
path = sfp_get_port_path(port, "sfp_tx_disable");
if (onlp_file_read_int(value, path) < 0) {
if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
@@ -312,12 +349,9 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
return rv;
}
int
onlp_sfpi_denit(void)
{
return ONLP_STATUS_OK;
}

View File

@@ -8,9 +8,9 @@ class OnlPlatform_x86_64_accton_as5912_54x_r0(OnlPlatformAccton,
SYS_OBJECT_ID=".5912.54"
def baseconfig(self):
self.insmod("accton_i2c_cpld")
self.insmod('optoe')
self.insmod("ym2651y")
for m in [ "sfp", "psu", "fan", "leds" ]:
for m in [ "cpld", "psu", "fan", "leds" ]:
self.insmod("x86-64-accton-as5912-54x-%s" % m)
########### initialize I2C bus 0 ###########
@@ -29,8 +29,8 @@ class OnlPlatform_x86_64_accton_as5912_54x_r0(OnlPlatformAccton,
('lm75', 0x4b, 3),
# initialize CPLDs
('accton_i2c_cpld', 0x60, 4),
('accton_i2c_cpld', 0x62, 5),
('as5912_54x_cpld1', 0x60, 4),
('as5912_54x_cpld2', 0x62, 5),
]
)
@@ -69,11 +69,14 @@ class OnlPlatform_x86_64_accton_as5912_54x_r0(OnlPlatformAccton,
# initialize SFP devices
for port in range(1, 49):
self.new_i2c_device('as5912_54x_port%d' % port, 0x50, port+25)
self.new_i2c_device('optoe2', 0x50, port+25)
# initialize QSFP devices
for port in range(49, 55):
self.new_i2c_device('as5912_54x_port%d' % port, 0x50, port+25)
self.new_i2c_device('optoe1', 0x50, port+25)
for port in range(1, 55):
subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+25), shell=True)
return True