[as7312-54x] Add support for OOM driver

This commit is contained in:
Brandon Chuang
2018-01-18 13:51:23 +08:00
parent 9cd087dcb7
commit 2a0c85cc3a
7 changed files with 1263 additions and 2268 deletions

View File

@@ -36,8 +36,6 @@ static struct as7312_54x_fan_data *as7312_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 as7312_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int as7312_54x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
/* fan related data, the index should match sysfs_fan_attributes
*/
@@ -467,23 +465,7 @@ static struct i2c_driver as7312_54x_fan_driver = {
.address_list = normal_i2c,
};
static int __init as7312_54x_fan_init(void)
{
extern int platform_accton_as7312_54x(void);
if (!platform_accton_as7312_54x()) {
return -ENODEV;
}
return i2c_add_driver(&as7312_54x_fan_driver);
}
static void __exit as7312_54x_fan_exit(void)
{
i2c_del_driver(&as7312_54x_fan_driver);
}
module_init(as7312_54x_fan_init);
module_exit(as7312_54x_fan_exit);
module_i2c_driver(as7312_54x_fan_driver);
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("as7312_54x_fan driver");

View File

@@ -30,8 +30,8 @@
#include <linux/slab.h>
#include <linux/dmi.h>
extern int as7312_54x_i2c_cpld_read (unsigned short cpld_addr, u8 reg);
extern int as7312_54x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
extern int as7312_54x_cpld_read (unsigned short cpld_addr, u8 reg);
extern int as7312_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
extern void led_classdev_unregister(struct led_classdev *led_cdev);
extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev);
@@ -175,12 +175,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type,
static int accton_as7312_54x_led_read_value(u8 reg)
{
return as7312_54x_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg);
return as7312_54x_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg);
}
static int accton_as7312_54x_led_write_value(u8 reg, u8 value)
{
return as7312_54x_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value);
return as7312_54x_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value);
}
static void accton_as7312_54x_led_update(void)
@@ -397,11 +397,6 @@ static int __init accton_as7312_54x_led_init(void)
{
int ret;
extern int platform_accton_as7312_54x(void);
if (!platform_accton_as7312_54x()) {
return -ENODEV;
}
ret = platform_driver_register(&accton_as7312_54x_led_driver);
if (ret < 0) {
goto exit;

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 as7312_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len);
extern int as7312_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int as7312_54x_cpld_read(unsigned short cpld_addr, u8 reg);
/* Addresses scanned
*/
@@ -234,7 +234,7 @@ static struct as7312_54x_psu_data *as7312_54x_psu_update_device(struct device *d
dev_dbg(&client->dev, "Starting as7312_54x update\n");
/* Read psu status */
status = as7312_54x_i2c_cpld_read(0x60, 0x2);
status = as7312_54x_cpld_read(0x60, 0x2);
if (status < 0) {
dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status);
@@ -269,23 +269,7 @@ static struct as7312_54x_psu_data *as7312_54x_psu_update_device(struct device *d
return data;
}
static int __init as7312_54x_psu_init(void)
{
extern int platform_accton_as7312_54x(void);
if (!platform_accton_as7312_54x()) {
return -ENODEV;
}
return i2c_add_driver(&as7312_54x_psu_driver);
}
static void __exit as7312_54x_psu_exit(void)
{
i2c_del_driver(&as7312_54x_psu_driver);
}
module_init(as7312_54x_psu_init);
module_exit(as7312_54x_psu_exit);
module_i2c_driver(as7312_54x_psu_driver);
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("as7312_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,30 +24,21 @@
*
***********************************************************/
#include <onlp/platformi/sfpi.h>
#include <fcntl.h>
#include <unistd.h>
#include "platform_lib.h"
#include <onlplib/i2c.h>
#include <onlplib/file.h>
#include "x86_64_accton_as7312_54x_int.h"
#include "x86_64_accton_as7312_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/5-0062/module_rx_los_all"
#define MODULE_RXLOS_ALL_ATTR_CPLD3 "/sys/bus/i2c/devices/6-0064/module_rx_los_all"
/************************************************************
*
@@ -57,7 +48,7 @@ sfp_get_port_path(int port, char *node_name)
int
onlp_sfpi_init(void)
{
/* Called at initialization time */
/* Called at initialization time */
return ONLP_STATUS_OK;
}
@@ -68,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);
}
@@ -85,55 +76,68 @@ 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 || (port >= 48 && port <= 51)) ? 62 : 64;
bus = (addr == 62) ? 5 : 6;
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;
}
return present;
}
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 = 62; addr <= 64; addr+=2) {
/* Read present status of port 0~53 */
char file[64] = {0};
int bus = (addr == 62) ? 5 : 6;
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 CPLD3.");
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 CPLD3.");
return ONLP_STATUS_E_INTERNAL;
}
ptr += count;
}
/* Mask out non-existant QSFP ports */
bytes[6] &= 0x3F;
bytes[3] &= 0xF;
bytes[7] &= 0x3;
/* 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 |= bytes[7];
presence_all <<= 4;
presence_all |= bytes[3];
for(i = 6; i >= 4; i--) {
presence_all <<= 8;
presence_all |= bytes[i];
}
for(i = 2; i >= 0; i--) {
presence_all <<= 8;
presence_all |= bytes[i];
}
@@ -151,32 +155,38 @@ 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 = 62; addr <= 64; addr+=2) {
if (addr == 62) {
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;
}
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--) {
rx_los_all <<= 8;
@@ -195,50 +205,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 < 24) ? 62 : 64;
int bus = (addr == 62) ? 5 : 6;
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;
}
@@ -260,16 +322,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) ? 62 : 64;
int bus = (addr == 62) ? 5 : 6;
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 {
@@ -280,9 +346,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;
}
@@ -294,9 +358,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;
}
@@ -313,11 +375,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

@@ -9,8 +9,9 @@ class OnlPlatform_x86_64_accton_as7312_54x_r0(OnlPlatformAccton,
SYS_OBJECT_ID=".7312.54"
def baseconfig(self):
self.insmod('optoe')
self.insmod('ym2651y')
for m in [ 'cpld', 'fan', 'psu', 'leds', 'sfp' ]:
for m in [ 'cpld', 'fan', 'psu', 'leds' ]:
self.insmod("x86-64-accton-as7312-54x-%s.ko" % m)
########### initialize I2C bus 0 ###########
@@ -31,9 +32,9 @@ class OnlPlatform_x86_64_accton_as7312_54x_r0(OnlPlatformAccton,
self.new_i2c_devices([
# initialize CPLD
('accton_i2c_cpld', 0x60, 4),
('accton_i2c_cpld', 0x62, 5),
('accton_i2c_cpld', 0x64, 6),
('as7312_54x_cpld1', 0x60, 4),
('as7312_54x_cpld2', 0x62, 5),
('as7312_54x_cpld3', 0x64, 6),
])
self.new_i2c_device('pca9548', 0x71, 0)
@@ -67,63 +68,14 @@ class OnlPlatform_x86_64_accton_as7312_54x_r0(OnlPlatformAccton,
)
# initialize QSFP port 1~54
self.new_i2c_devices(
[
('as7312_54x_port1', 0x50, 18),
('as7312_54x_port2', 0x50, 19),
('as7312_54x_port3', 0x50, 20),
('as7312_54x_port4', 0x50, 21),
('as7312_54x_port5', 0x50, 22),
('as7312_54x_port6', 0x50, 23),
('as7312_54x_port7', 0x50, 24),
('as7312_54x_port8', 0x50, 25),
('as7312_54x_port9', 0x50, 26),
('as7312_54x_port10', 0x50, 27),
('as7312_54x_port11', 0x50, 28),
('as7312_54x_port12', 0x50, 29),
('as7312_54x_port13', 0x50, 30),
('as7312_54x_port14', 0x50, 31),
('as7312_54x_port15', 0x50, 32),
('as7312_54x_port16', 0x50, 33),
('as7312_54x_port17', 0x50, 34),
('as7312_54x_port18', 0x50, 35),
('as7312_54x_port19', 0x50, 36),
('as7312_54x_port20', 0x50, 37),
('as7312_54x_port21', 0x50, 38),
('as7312_54x_port22', 0x50, 39),
('as7312_54x_port23', 0x50, 40),
('as7312_54x_port24', 0x50, 41),
('as7312_54x_port25', 0x50, 42),
('as7312_54x_port26', 0x50, 43),
('as7312_54x_port27', 0x50, 44),
('as7312_54x_port28', 0x50, 45),
('as7312_54x_port29', 0x50, 46),
('as7312_54x_port30', 0x50, 47),
('as7312_54x_port31', 0x50, 48),
('as7312_54x_port32', 0x50, 49),
('as7312_54x_port33', 0x50, 50),
('as7312_54x_port34', 0x50, 51),
('as7312_54x_port35', 0x50, 52),
('as7312_54x_port36', 0x50, 53),
('as7312_54x_port37', 0x50, 54),
('as7312_54x_port38', 0x50, 55),
('as7312_54x_port39', 0x50, 56),
('as7312_54x_port40', 0x50, 57),
('as7312_54x_port41', 0x50, 58),
('as7312_54x_port42', 0x50, 59),
('as7312_54x_port43', 0x50, 60),
('as7312_54x_port44', 0x50, 61),
('as7312_54x_port45', 0x50, 62),
('as7312_54x_port46', 0x50, 63),
('as7312_54x_port47', 0x50, 64),
('as7312_54x_port48', 0x50, 65),
('as7312_54x_port49', 0x50, 66),
('as7312_54x_port50', 0x50, 67),
('as7312_54x_port51', 0x50, 68),
('as7312_54x_port52', 0x50, 69),
('as7312_54x_port53', 0x50, 70),
('as7312_54x_port54', 0x50, 71),
]
)
for port in range(1, 49):
self.new_i2c_device('optoe2', 0x50, port+17)
for port in range(49, 55):
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)
self.new_i2c_device('24c02', 0x57, 1)
return True