Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#
###############################################################################
THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
x86_64_accton_as4625_54t_INCLUDES := -I $(THIS_DIR)inc
x86_64_accton_as4625_54t_INTERNAL_INCLUDES := -I $(THIS_DIR)src
ACCTON_COMMON := $(THIS_DIR)../../../../../common_lib/onlp_lib
x86_64_accton_as4625_54t_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc
x86_64_accton_as4625_54t_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc
x86_64_accton_as4625_54t_DEPENDMODULE_ENTRIES := init:x86_64_accton_as4625_54t ucli:x86_64_accton_as4625_54t

# Pull in the shared accton helper library (log throttling).
include $(ACCTON_COMMON)/src/make.mk
x86_64_accton_as4625_54t_LIBRARIES := accton_common
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <onlplib/file.h>
#include "x86_64_accton_as4625_54t_int.h"
#include "x86_64_accton_as4625_54t_log.h"
#include <syslog.h>
#include "log_ctrl.h"

#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom"
#define MODULE_PRESENT_FORMAT_0 "/sys/bus/i2c/devices/0-0064/module_present_%d"
Expand All @@ -46,12 +48,22 @@
int port_bus_index[] = { 10, 11, 12, 13, 14, 15 };
#define PORT_BUS_INDEX(port) (port_bus_index[port-48])

#define MAX_PORT 53

#define VALIDATE_SFP(_port) \
do { \
if (_port < 48 || _port > 53) \
return ONLP_STATUS_E_UNSUPPORTED; \
} while(0)

static struct sfp_log_mgmt log_mgmt[MAX_PORT+1] = {
[0 ... MAX_PORT] = {
.present_rec = ONLP_STATUS_E_INTERNAL,
.log_ctrl = {
[0 ... SFP_LOG_REASON_COUNT - 1] = { .should_log = 1 }
}
}
};

/************************************************************
*
Expand Down Expand Up @@ -93,12 +105,19 @@ onlp_sfpi_is_present(int port)

if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT_0, port+1) < 0) {
if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT_1, port+1) < 0) {
AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n",
port);
log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL;

syslog_ctrl(log_mgmt[port].log_ctrl, SFP_SYSFS_READ_FAIL,
"Unable to read present status from port(%d)", port);
return ONLP_STATUS_E_INTERNAL;
}
}

if (present == 1 && present != log_mgmt[port].present_rec) {
reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT);
}
log_mgmt[port].present_rec = present;

return present;
}

Expand All @@ -115,7 +134,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
if(fp == NULL) {
fp = fopen(MODULE_PRESENT_ALL_ATTR_1, "r");
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the module_present_all device file");
syslog(LOG_ERR, "Unable to open the module_present_all device file");
return ONLP_STATUS_E_INTERNAL;
}
}
Expand All @@ -125,7 +144,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)

if(count != 1) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read the module_present_all device file");
syslog(LOG_ERR, "Unable to read the module_present_all device file");
return ONLP_STATUS_E_INTERNAL;
}

Expand Down Expand Up @@ -166,7 +185,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
if(fp == NULL) {
fp = fopen(MODULE_RXLOS_ALL_ATTR_1, "r");
if(fp == NULL){
AIM_LOG_ERROR("Unable to open the module_rx_los_all device file");
syslog(LOG_ERR, "Unable to open the module_rx_los_all device file");
return ONLP_STATUS_E_INTERNAL;
}
}
Expand All @@ -176,15 +195,15 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)

if(count != 1) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read the module_rx_los_all device file");
syslog(LOG_ERR, "Unable to read the module_rx_los_all device file");
return ONLP_STATUS_E_INTERNAL;
}

fp1 = fopen(MODULE_PRESENT_ALL_ATTR_0, "r");
if(fp1 == NULL) {
fp1 = fopen(MODULE_PRESENT_ALL_ATTR_1, "r");
if(fp1 == NULL) {
AIM_LOG_ERROR("Unable to open the module_present_all device file");
syslog(LOG_ERR, "Unable to open the module_present_all device file");
return ONLP_STATUS_E_INTERNAL;
}
}
Expand All @@ -194,7 +213,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)

if(count1 != 1) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read the module_present_all device file");
syslog(LOG_ERR, "Unable to read the module_present_all device file");
return ONLP_STATUS_E_INTERNAL;
}
/* Mask out non-existant SFP ports */
Expand Down Expand Up @@ -230,12 +249,14 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256])

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);
syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_READ_FAIL,
"Unable to read eeprom from port(%d)", port);
return ONLP_STATUS_E_INTERNAL;
}

if (size != 256) {
AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n"
syslog_ctrl(log_mgmt[port].log_ctrl, SFP_INVALID_DATA_SIZE,
"Unable to read eeprom from port(%d), size is different!"
, port);
return ONLP_STATUS_E_INTERNAL;
}
Expand All @@ -254,22 +275,25 @@ onlp_sfpi_dom_read(int port, uint8_t data[256])
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)"
syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_READ_FAIL,
"Unable to open the eeprom device file of port(%d)"
, port);
return ONLP_STATUS_E_INTERNAL;
}

if (fseek(fp, 256, SEEK_CUR) != 0) {
fclose(fp);
AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)"
syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_READ_FAIL,
"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)"
syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_READ_FAIL,
"Unable to read the module_eeprom device file of port(%d)"
, port);
return ONLP_STATUS_E_INTERNAL;
}
Expand All @@ -292,7 +316,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
, (port+1)) < 0) {
if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT_1
, (port+1)) < 0) {
AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n"
syslog_ctrl(log_mgmt[port].log_ctrl, SFP_SYSFS_WRITE_FAIL,
"Unable to set tx_disable status to port(%d)"
, port);
return ONLP_STATUS_E_INTERNAL;
}
Expand Down Expand Up @@ -325,7 +350,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
< 0) {
if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT_1, (port+1))
< 0) {
AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n"
syslog_ctrl(log_mgmt[port].log_ctrl, SFP_SYSFS_READ_FAIL,
"Unable to read rx_loss status from port(%d)"
, port);
return ONLP_STATUS_E_INTERNAL;
}
Expand All @@ -340,7 +366,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
< 0) {
if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT_1, (port+1))
< 0) {
AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n"
syslog_ctrl(log_mgmt[port].log_ctrl, SFP_SYSFS_READ_FAIL,
"Unable to read tx_fault status from port(%d)"
, port);
return ONLP_STATUS_E_INTERNAL;
}
Expand All @@ -358,7 +385,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
(port+1)) < 0) {
if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT_1,
(port+1)) < 0) {
AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n"
syslog_ctrl(log_mgmt[port].log_ctrl, SFP_SYSFS_READ_FAIL,
"Unable to read tx_disabled status from port(%d)"
, port);
return ONLP_STATUS_E_INTERNAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#
###############################################################################
THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
x86_64_accton_as4630_54pe_INCLUDES := -I $(THIS_DIR)inc
x86_64_accton_as4630_54pe_INTERNAL_INCLUDES := -I $(THIS_DIR)src
ACCTON_COMMON := $(THIS_DIR)../../../../../common_lib/onlp_lib
x86_64_accton_as4630_54pe_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc
x86_64_accton_as4630_54pe_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc
x86_64_accton_as4630_54pe_DEPENDMODULE_ENTRIES := init:x86_64_accton_as4630_54pe ucli:x86_64_accton_as4630_54pe

# Pull in the shared accton helper library (log throttling).
include $(ACCTON_COMMON)/src/make.mk
x86_64_accton_as4630_54pe_LIBRARIES := accton_common
Loading