Merge pull request #348 from brandonchuang/as5822_54x

[as5822-54x] Add support for OOM
This commit is contained in:
Jeffrey Townsend
2018-04-04 10:58:00 -07:00
committed by GitHub
7 changed files with 1346 additions and 1498 deletions

View File

@@ -39,8 +39,8 @@ static struct as5822_54x_fan_data *as5822_54x_fan_update_device(struct device *d
static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf);
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
const char *buf, size_t count);
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 as5822_54x_cpld_read(unsigned short cpld_addr, u8 reg);
extern int as5822_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
/* fan related data, the index should match sysfs_fan_attributes
*/
@@ -199,12 +199,12 @@ static struct attribute *as5822_54x_fan_attributes[] = {
static int as5822_54x_fan_read_value(u8 reg)
{
return accton_i2c_cpld_read(FAN_STATUS_I2C_ADDR, reg);
return as5822_54x_cpld_read(FAN_STATUS_I2C_ADDR, reg);
}
static int as5822_54x_fan_write_value(u8 reg, u8 value)
{
return accton_i2c_cpld_write(FAN_STATUS_I2C_ADDR, reg, value);
return as5822_54x_cpld_write(FAN_STATUS_I2C_ADDR, reg, value);
}
/* fan utility functions

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 as5822_54x_cpld_read(unsigned short cpld_addr, u8 reg);
extern int as5822_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
struct accton_as5822_54x_led_data {
struct platform_device *pdev;
@@ -147,12 +147,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type,
static int accton_as5822_54x_led_read_value(u8 reg)
{
return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg);
return as5822_54x_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg);
}
static int accton_as5822_54x_led_write_value(u8 reg, u8 value)
{
return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value);
return as5822_54x_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value);
}
static void accton_as5822_54x_led_update(void)

View File

@@ -50,7 +50,7 @@
static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf);
static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf);
static int as5822_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 as5822_54x_cpld_read(unsigned short cpld_addr, u8 reg);
/* Addresses scanned
*/
@@ -317,7 +317,7 @@ static struct as5822_54x_psu_data *as5822_54x_psu_update_device(struct device *d
data->valid = 0;
/* Read psu status */
status = accton_i2c_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET);
status = as5822_54x_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET);
if (status < 0) {
dev_dbg(&client->dev, "cpld reg (0x%x) err %d\n", PSU_STATUS_I2C_ADDR, status);
@@ -372,18 +372,7 @@ exit:
return data;
}
static int __init as5822_54x_psu_init(void)
{
return i2c_add_driver(&as5822_54x_psu_driver);
}
static void __exit as5822_54x_psu_exit(void)
{
i2c_del_driver(&as5822_54x_psu_driver);
}
module_init(as5822_54x_psu_init);
module_exit(as5822_54x_psu_exit);
module_i2c_driver(as5822_54x_psu_driver);
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("as5822_54x_psu driver");

View File

@@ -2,7 +2,7 @@
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2016 Accton Technology Corporation.
* 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
@@ -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_as5822_54x_int.h"
#include "x86_64_accton_as5822_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+18)
#define PORT_BUS_INDEX(port) (port+18)
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_CPLD2 "/sys/bus/i2c/devices/10-0061/module_rx_los_all"
#define MODULE_RXLOS_ALL_ATTR_CPLD3 "/sys/bus/i2c/devices/11-0062/module_rx_los_all"
/************************************************************
*
@@ -68,7 +60,7 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap)
*/
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 < 29) ? 61 : 62;
bus = (addr == 61) ? 10 : 11;
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,42 +92,51 @@ 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[8], *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 = 61; addr <= 62; addr++) {
/* Read present status of port 0~53 */
char file[64] = {0};
int bus = (addr == 61) ? 10 : 11;
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.");
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;
int 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.");
return ONLP_STATUS_E_INTERNAL;
}
ptr += count;
}
/* Mask out non-existant QSFP ports */
bytes[6] &= 0x3F;
bytes[3] &= 0x1F;
bytes[7] &= 0x1;
/* 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--) {
for(i = 7; i >= 4; i--) {
presence_all <<= 8;
presence_all |= bytes[i];
}
presence_all <<= 5;
presence_all |= bytes[3];
for(i = 2; i >= 0; i--) {
presence_all <<= 8;
presence_all |= bytes[i];
}
@@ -149,39 +153,68 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
int
onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
{
uint32_t bytes[6];
char* path;
uint32_t bytes[7];
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 = 61; addr <= 62; addr++) {
int count;
if (addr == 61) {
fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r");
}
else {
fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD3, "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;
}
if (addr == 61) {
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 from the module_rx_los_all device file of CPLD(0x%d)", addr);
return ONLP_STATUS_E_INTERNAL;
}
}
else {
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;
uint64_t rx_los_all = 0 ;
for(i = 5; i >= 0; i--) {
bytes[3] &= 0x1F;
bytes[6] &= 0x7;
for(i = 6; i >= 4; i--) {
rx_los_all <<= 8;
rx_los_all |= bytes[i];
}
rx_los_all <<= 5;
rx_los_all |= bytes[3];
for(i = 2; 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));
@@ -194,50 +227,102 @@ 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;
}
return ONLP_STATUS_OK;
}
int
onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr)
{
int bus = PORT_BUS_INDEX(port);
return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE);
}
int
onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value)
{
int bus = PORT_BUS_INDEX(port);
return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE);
}
int
onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr)
{
int bus = PORT_BUS_INDEX(port);
return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE);
}
int
onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value)
{
int bus = PORT_BUS_INDEX(port);
return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE);
}
int
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 < 29) ? 61 : 62;
int bus = (addr == 61) ? 10 : 11;
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 +344,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 < 29) ? 61 : 62;
int bus = (addr == 61) ? 10 : 11;
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 +368,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 +380,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,9 +397,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_as5822_54x_r0(OnlPlatformAccton,
SYS_OBJECT_ID=".5822.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', 'fan', 'psu', 'leds' ]:
self.insmod("x86-64-accton-as5822-54x-%s" % m)
########### initialize I2C bus 0 ###########
@@ -20,7 +20,7 @@ class OnlPlatform_x86_64_accton_as5822_54x_r0(OnlPlatformAccton,
('pca9548', 0x72, 0),
# initialize CPLD
('accton_i2c_cpld', 0x60, 6),
('as5822_54x_cpld1', 0x60, 6),
# initiate PSU-1 AC Power
('as5822_54x_psu1', 0x50, 3),
@@ -45,8 +45,8 @@ class OnlPlatform_x86_64_accton_as5822_54x_r0(OnlPlatformAccton,
('pca9548', 0x70, 1),
# initialize CPLD
('accton_i2c_cpld', 0x61, 10),
('accton_i2c_cpld', 0x62, 11),
('as5822_54x_cpld2', 0x61, 10),
('as5822_54x_cpld3', 0x62, 11),
# initialize multiplexer (PCA9548)
('pca9548', 0x71, 12),
@@ -64,11 +64,13 @@ class OnlPlatform_x86_64_accton_as5822_54x_r0(OnlPlatformAccton,
# initialize SFP devices
for port in range(1, 49):
self.new_i2c_device('as5822_54x_sfp%d' % port, 0x50, port+17)
self.new_i2c_device('as5822_54x_sfp%d' % port, 0x51, port+17)
self.new_i2c_device('optoe2', 0x50, port+17)
# initialize QSFP devices
for port in range(49, 55):
self.new_i2c_device('as5822_54x_sfp%d' % port, 0x50, port+17)
self.new_i2c_device('optoe1', 0x50, port+17)
for port in range(1, 55):
subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+17), shell=True)
return True