diff --git a/packages/platforms/accton/common/inc/log_ctrl.h b/packages/platforms/accton/common/inc/log_ctrl.h new file mode 100644 index 000000000..aad5b89c4 --- /dev/null +++ b/packages/platforms/accton/common/inc/log_ctrl.h @@ -0,0 +1,106 @@ +/************************************************************ + * + * + * Copyright 2026 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0. + * + * + ************************************************************ + * + * Per-key syslog rate limiting shared by Accton ONLP driver + * modules (sfpi.c, fani.c, sysi.c, ...). + * + * Generic primitive: + * struct log_ctrl { int should_log; }; + * void syslog_ctrl(struct log_ctrl *arr, int reason, + * const char *fmt, ...); + * void reset_log_ctrl(struct log_ctrl *arr, int count); + * + * Each domain (SFP, fan, ...) defines its own reason enum plus a + * bookkeeping struct bundling a last-known state value with a + * per-reason log_ctrl[] array. The SFP domain lives in this header + * to avoid an extra include; new domains (fan, PSU, ...) should be + * appended below in the same style. + * + * Typical driver-side declaration (SFP example): + * + * 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 } + * } + * } + * }; + * + * syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + * "fmt %d", arg); + * reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + * + ***********************************************************/ +#ifndef __ACCTON_COMMON_LOG_CTRL_H__ +#define __ACCTON_COMMON_LOG_CTRL_H__ + +/* --------------------------------------------------------------- + * Generic throttling primitive + * --------------------------------------------------------------- */ + +struct log_ctrl { + int should_log; +}; + +/* + * Emit one syslog(LOG_ERR, ...) line for arr[reason] if its + * should_log flag is set, then clear the flag. Subsequent calls + * with the same (arr, reason) key are silent until reset_log_ctrl() + * re-arms them. + * + * The caller owns the array and must guarantee 0 <= reason < count, + * where count is the size passed to reset_log_ctrl() below. + */ +void syslog_ctrl(struct log_ctrl *arr, int reason, const char *fmt, ...) + __attribute__((format(printf, 3, 4))); + +/* + * Re-arm every entry in arr[0..count-1] so the next syslog_ctrl() + * for each reason is emitted again. + */ +void reset_log_ctrl(struct log_ctrl *arr, int count); + +/* --------------------------------------------------------------- + * SFP domain + * --------------------------------------------------------------- */ + +enum sfp_log_reason { + SFP_PRESENT_UNABLE_TO_GET_STATUS, + SFP_EEPROM_UNABLE_TO_GET_DATA, + SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + SFP_TX_DIS_UNABLE_TO_SET_STATUS, + SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + SFP_TX_DIS_UNABLE_TO_SET_BANK, + SFP_TX_DIS_UNABLE_TO_GET_STATUS, + SFP_LP_MODE_UNABLE_TO_GET_IDENTIFIER, + SFP_LP_MODE_UNABLE_TO_SET_STATUS, + SFP_LP_MODE_UNABLE_TO_GET_STATUS, + SFP_RESET_UNABLE_TO_SET_STATUS, + SFP_RESET_UNABLE_TO_GET_STATUS, + SFP_RX_LOS_UNABLE_TO_GET_STATUS, + SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + SFP_MULTIRATE_UNABLE_TO_SET_STATUS, + + SFP_LOG_REASON_COUNT, +}; + +struct sfp_log_mgmt { + int present_rec; + struct log_ctrl log_ctrl[SFP_LOG_REASON_COUNT]; +}; + +#endif /* __ACCTON_COMMON_LOG_CTRL_H__ */ diff --git a/packages/platforms/accton/common/src/log_ctrl.c b/packages/platforms/accton/common/src/log_ctrl.c new file mode 100644 index 000000000..5ce3e19a8 --- /dev/null +++ b/packages/platforms/accton/common/src/log_ctrl.c @@ -0,0 +1,40 @@ +/************************************************************ + * + * + * Copyright 2026 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0. + * + * + ***********************************************************/ +#include +#include +#include + +#include "log_ctrl.h" + +void +syslog_ctrl(struct log_ctrl *arr, int reason, const char *fmt, ...) +{ + char buf[256]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + + if (arr[reason].should_log) { + syslog(LOG_ERR, "%s", buf); + arr[reason].should_log = 0; + } +} + +void +reset_log_ctrl(struct log_ctrl *arr, int count) +{ + int i; + + for (i = 0; i < count; i++) { + arr[i].should_log = 1; + } +} diff --git a/packages/platforms/accton/common/src/make.mk b/packages/platforms/accton/common/src/make.mk new file mode 100644 index 000000000..47f9039ac --- /dev/null +++ b/packages/platforms/accton/common/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# Common library shared by Accton platform ONLP modules. +# +############################################################################### + +LIBRARY := accton_common +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/accton/x86-64/as4625-54t/onlp/builds/x86_64_accton_as4625_54t/module/make.mk b/packages/platforms/accton/x86-64/as4625-54t/onlp/builds/x86_64_accton_as4625_54t/module/make.mk index d68eb57cb..875367868 100644 --- a/packages/platforms/accton/x86-64/as4625-54t/onlp/builds/x86_64_accton_as4625_54t/module/make.mk +++ b/packages/platforms/accton/x86-64/as4625-54t/onlp/builds/x86_64_accton_as4625_54t/module/make.mk @@ -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 +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 diff --git a/packages/platforms/accton/x86-64/as4625-54t/onlp/builds/x86_64_accton_as4625_54t/module/src/sfpi.c b/packages/platforms/accton/x86-64/as4625-54t/onlp/builds/x86_64_accton_as4625_54t/module/src/sfpi.c index eae66474b..6be05ab6d 100644 --- a/packages/platforms/accton/x86-64/as4625-54t/onlp/builds/x86_64_accton_as4625_54t/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as4625-54t/onlp/builds/x86_64_accton_as4625_54t/module/src/sfpi.c @@ -28,6 +28,8 @@ #include #include "x86_64_accton_as4625_54t_int.h" #include "x86_64_accton_as4625_54t_log.h" +#include +#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" @@ -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 } + } + } +}; /************************************************************ * @@ -93,12 +105,22 @@ 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); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -115,7 +137,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; } } @@ -125,7 +147,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; } @@ -166,7 +188,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; } } @@ -176,7 +198,7 @@ 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; } @@ -184,7 +206,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) 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; } } @@ -194,7 +216,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 */ @@ -230,12 +252,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_UNABLE_TO_GET_DATA, + "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_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!" , port); return ONLP_STATUS_E_INTERNAL; } @@ -254,14 +278,16 @@ 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_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "Unable to set the file position indicator of port(%d)" , port); return ONLP_STATUS_E_INTERNAL; } @@ -269,7 +295,8 @@ onlp_sfpi_dom_read(int port, uint8_t data[256]) 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_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)" , port); return ONLP_STATUS_E_INTERNAL; } @@ -292,7 +319,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_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to set tx_disable status to port(%d)" , port); return ONLP_STATUS_E_INTERNAL; } @@ -325,7 +353,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_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)" , port); return ONLP_STATUS_E_INTERNAL; } @@ -340,7 +369,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_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)" , port); return ONLP_STATUS_E_INTERNAL; } @@ -358,7 +388,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_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)" , port); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/as4630-54pe/onlp/builds/x86_64_accton_as4630_54pe/module/make.mk b/packages/platforms/accton/x86-64/as4630-54pe/onlp/builds/x86_64_accton_as4630_54pe/module/make.mk index fedb9a555..447e12fbc 100755 --- a/packages/platforms/accton/x86-64/as4630-54pe/onlp/builds/x86_64_accton_as4630_54pe/module/make.mk +++ b/packages/platforms/accton/x86-64/as4630-54pe/onlp/builds/x86_64_accton_as4630_54pe/module/make.mk @@ -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 +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 diff --git a/packages/platforms/accton/x86-64/as4630-54pe/onlp/builds/x86_64_accton_as4630_54pe/module/src/sfpi.c b/packages/platforms/accton/x86-64/as4630-54pe/onlp/builds/x86_64_accton_as4630_54pe/module/src/sfpi.c index 5ad86e3ad..d458c5b8a 100755 --- a/packages/platforms/accton/x86-64/as4630-54pe/onlp/builds/x86_64_accton_as4630_54pe/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as4630-54pe/onlp/builds/x86_64_accton_as4630_54pe/module/src/sfpi.c @@ -28,6 +28,10 @@ #include #include "x86_64_accton_as4630_54pe_int.h" #include "x86_64_accton_as4630_54pe_log.h" +#include +#include "log_ctrl.h" + +#define MAX_PORT 53 #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" @@ -63,6 +67,15 @@ int port_bus_index[] ={18, 19, 20, 21, 22, 23}; 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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -108,10 +121,21 @@ onlp_sfpi_is_present(int port) bus = 3; 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); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -161,12 +185,13 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 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_UNABLE_TO_GET_DATA, "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -183,20 +208,23 @@ 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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -249,7 +277,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if (port>=48 && port<=51) { if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -257,7 +286,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } else { /* txdis valid bit(bit0-bit3), xxxx 1111 */ if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, (value & 0xf)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -270,7 +300,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { if(port>=52 && port<=53) { if (onlp_file_write_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -281,7 +312,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { if(port>=52 && port<=53) { if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write lpmode status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write lpmode status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -309,7 +341,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { if(port>=48 && port<=51) { 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -321,7 +354,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { if(port>=48 && port<=51) { 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -338,7 +372,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { if (port>=48 && port<=51) { 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -346,7 +381,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } else { /* txdis valid bit(bit0-bit3), xxxx 1111 */ if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS)) < 0) { - AIM_LOG_ERROR("Unable to read tx_disable status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } *value = (tx_dis & 0xf); @@ -360,7 +396,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { if(port>=52 && port<=53) { if (onlp_file_read_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -373,7 +410,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { if(port>=52 && port<=53) { if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read lpmode status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read lpmode status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; diff --git a/packages/platforms/accton/x86-64/as4630-54te/onlp/builds/x86_64_accton_as4630_54pe/module/make.mk b/packages/platforms/accton/x86-64/as4630-54te/onlp/builds/x86_64_accton_as4630_54pe/module/make.mk index d9b448b38..b42b31dd9 100644 --- a/packages/platforms/accton/x86-64/as4630-54te/onlp/builds/x86_64_accton_as4630_54pe/module/make.mk +++ b/packages/platforms/accton/x86-64/as4630-54te/onlp/builds/x86_64_accton_as4630_54pe/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as4630_54te_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as4630_54te_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as4630_54te_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as4630_54te_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as4630_54te_DEPENDMODULE_ENTRIES := init:x86_64_accton_as4630_54te ucli:x86_64_accton_as4630_54te +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as4630_54te_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as4630-54te/onlp/builds/x86_64_accton_as4630_54pe/module/src/sfpi.c b/packages/platforms/accton/x86-64/as4630-54te/onlp/builds/x86_64_accton_as4630_54pe/module/src/sfpi.c index 8b4443861..493f3ccc9 100644 --- a/packages/platforms/accton/x86-64/as4630-54te/onlp/builds/x86_64_accton_as4630_54pe/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as4630-54te/onlp/builds/x86_64_accton_as4630_54pe/module/src/sfpi.c @@ -28,6 +28,10 @@ #include #include "x86_64_accton_as4630_54te_int.h" #include "x86_64_accton_as4630_54te_log.h" +#include +#include "log_ctrl.h" + +#define MAX_PORT 53 #define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" #define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/3-0060/module_present_%d" @@ -65,6 +69,15 @@ int port_bus_index[] = { 18, 19, 20, 21, 22, 23 }; 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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -104,10 +117,21 @@ onlp_sfpi_is_present(int port) VALIDATE(port); 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); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -122,7 +146,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) fp = fopen(MODULE_PRESENT_ALL_ATTR, "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; } @@ -131,7 +155,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; } @@ -164,7 +188,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) fp = fopen(MODULE_RXLOS_ALL_ATTR, "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; } @@ -173,7 +197,7 @@ 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; } @@ -211,12 +235,13 @@ 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_UNABLE_TO_GET_DATA, "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -233,20 +258,23 @@ 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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -295,7 +323,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if (port >= 48 && port < 52) { if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -303,7 +332,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } else { /* txdis valid bit(bit0-bit3), xxxx 1111 */ if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, (value & 0xf)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -316,7 +346,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -326,7 +357,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write lpmode status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write lpmode status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -350,7 +382,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -360,7 +393,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_FAULT: { VALIDATE_SFP(port); 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -375,7 +409,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { if (port >= 48 && port < 52) { 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -383,7 +418,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } else { /* txdis valid bit(bit0-bit3), xxxx 1111 */ if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS)) < 0) { - AIM_LOG_ERROR("Unable to read tx_disable status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } *value = (tx_dis & 0xf); @@ -397,7 +433,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -407,7 +444,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read lpmode status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read lpmode status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/make.mk b/packages/platforms/accton/x86-64/as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/make.mk index 7fb74e039..ff124090b 100644 --- a/packages/platforms/accton/x86-64/as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/make.mk +++ b/packages/platforms/accton/x86-64/as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as5835_54t_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as5835_54t_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as5835_54t_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as5835_54t_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as5835_54t_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5835_54t ucli:x86_64_accton_as5835_54t +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as5835_54t_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/src/sfpi.c b/packages/platforms/accton/x86-64/as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/src/sfpi.c index 95ad770ee..47e2c754b 100644 --- a/packages/platforms/accton/x86-64/as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/src/sfpi.c @@ -28,11 +28,14 @@ #include #include "x86_64_accton_as5835_54t_int.h" #include "x86_64_accton_as5835_54t_log.h" +#include +#include "log_ctrl.h" int sfp_map[] = {28,29,26,30,31,27}; #define QSFP_PORT_MIN 48 #define QSFP_PORT_MAX 53 +#define MAX_PORT 53 #define VALIDATE_QSFP(_port) \ do { \ if (_port < QSFP_PORT_MIN || _port > QSFP_PORT_MAX ) \ @@ -51,6 +54,15 @@ int sfp_map[] = {28,29,26,30,31,27}; #define PORT_EEPROM_DEVADDR 0x50 #define QSFP_EEPROM_OFFSET_TXDIS 0x56 +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -89,10 +101,21 @@ onlp_sfpi_is_present(int port) 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); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -110,7 +133,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) sprintf(file, MODULE_PRESENT_ALL_ATTR); fp = fopen(file, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to open the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -119,7 +142,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) if(count != length) { /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -156,12 +179,13 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 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_UNABLE_TO_GET_DATA, "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -177,20 +201,23 @@ 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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -244,7 +271,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ value = value & 0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d): write eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -261,7 +289,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) case ONLP_SFP_CONTROL_RESET: { if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -273,7 +302,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) case ONLP_SFP_CONTROL_LP_MODE: { if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write LP mode status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -310,7 +340,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) tx_dis_val = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_dis_val < 0) { - AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -327,7 +358,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_RESET: { if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -339,7 +371,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_LP_MODE: { if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read LP mode status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { diff --git a/packages/platforms/accton/x86-64/as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/make.mk b/packages/platforms/accton/x86-64/as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/make.mk index 5718f964c..6d17e5e32 100644 --- a/packages/platforms/accton/x86-64/as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/make.mk +++ b/packages/platforms/accton/x86-64/as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as5835_54x_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as5835_54x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as5835_54x_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as5835_54x_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as5835_54x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5835_54x ucli:x86_64_accton_as5835_54x +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as5835_54x_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/src/sfpi.c index 69d0d5ee8..fa10eed8e 100644 --- a/packages/platforms/accton/x86-64/as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/src/sfpi.c @@ -28,6 +28,8 @@ #include #include "x86_64_accton_as5835_54x_int.h" #include "x86_64_accton_as5835_54x_log.h" +#include +#include "log_ctrl.h" int sfp_map[] = { 42,43,44,45,46,47,48,49,50,51, @@ -80,6 +82,15 @@ int sfp_map[] = { #define PORT_EEPROM_DEVADDR 0x50 #define QSFP_EEPROM_OFFSET_TXDIS 0x56 +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -119,10 +130,21 @@ onlp_sfpi_is_present(int port) int addr = (port < 38) ? 61 : 62; if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, 3, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -144,7 +166,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) sprintf(file, MODULE_PRESENT_ALL_ATTR, 3, addr); fp = fopen(file, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to open the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -159,7 +181,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) if(count != length) { /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -215,7 +237,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) } if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); + syslog(LOG_ERR, "Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); return ONLP_STATUS_E_INTERNAL; } @@ -224,7 +246,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) fclose(fp); if(count != 5) { /* 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); + syslog(LOG_ERR, "Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); return ONLP_STATUS_E_INTERNAL; } } @@ -233,7 +255,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) fclose(fp); if(count != 2) { /* 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); + syslog(LOG_ERR, "Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); return ONLP_STATUS_E_INTERNAL; } } @@ -281,12 +303,14 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 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_UNABLE_TO_GET_DATA, + "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -302,20 +326,23 @@ 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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -368,7 +395,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if(present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, 3, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -379,7 +407,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ value = value & 0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d): write eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -397,7 +426,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, 3, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -410,7 +440,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, 3, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write LP mode status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -443,7 +474,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, 3, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -456,7 +488,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, 3, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -472,7 +505,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if(present == 1){ if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, 3, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -483,7 +517,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ tx_dis_val = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_dis_val < 0) { - AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -502,7 +537,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, 3, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -515,7 +551,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, 3, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read LP mode status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { diff --git a/packages/platforms/accton/x86-64/as5915-18x/onlp/builds/x86_64_accton_as5915_18x/module/make.mk b/packages/platforms/accton/x86-64/as5915-18x/onlp/builds/x86_64_accton_as5915_18x/module/make.mk index d1d99f3e6..b0461a307 100644 --- a/packages/platforms/accton/x86-64/as5915-18x/onlp/builds/x86_64_accton_as5915_18x/module/make.mk +++ b/packages/platforms/accton/x86-64/as5915-18x/onlp/builds/x86_64_accton_as5915_18x/module/make.mk @@ -1,10 +1,16 @@ ############################################################################### # -# +# # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as5915_18x_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as5915_18x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +# module -> x86_64_accton_as5915_18x -> builds -> onlp -> as5915-18x -> x86-64 -> accton +ACCTON_COMMON := $(THIS_DIR)../../../../../../common + +x86_64_accton_as5915_18x_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as5915_18x_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as5915_18x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5915_18x ucli:x86_64_accton_as5915_18x +# Pull in the shared accton helper library (log throttling, ...). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as5915_18x_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as5915-18x/onlp/builds/x86_64_accton_as5915_18x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as5915-18x/onlp/builds/x86_64_accton_as5915_18x/module/src/sfpi.c index 6ab3eafe1..ced41a887 100644 --- a/packages/platforms/accton/x86-64/as5915-18x/onlp/builds/x86_64_accton_as5915_18x/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as5915-18x/onlp/builds/x86_64_accton_as5915_18x/module/src/sfpi.c @@ -28,6 +28,10 @@ #include #include "x86_64_accton_as5915_18x_int.h" #include "x86_64_accton_as5915_18x_log.h" +#include +#include "log_ctrl.h" + +#define MAX_PORT 13 #define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" #define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/32-0063/module_present_%d" @@ -44,6 +48,15 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { #define PORT_BUS_INDEX(port) (port_bus_index[port]) +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -82,10 +95,21 @@ onlp_sfpi_is_present(int port) 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); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -100,7 +124,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) fp = fopen(MODULE_PRESENT_ALL_ATTR, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to open the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -109,7 +133,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) if(count != 2) { /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -145,7 +169,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x63)"); + syslog(LOG_ERR, "Unable to open the module_rx_los_all device file of CPLD(0x63)"); return ONLP_STATUS_E_INTERNAL; } @@ -153,7 +177,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) fclose(fp); if(count != 2) { /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x62)"); + syslog(LOG_ERR, "Unable to read all fields from the module_rx_los_all device file of CPLD(0x62)"); return ONLP_STATUS_E_INTERNAL; } @@ -191,12 +215,13 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 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_UNABLE_TO_GET_DATA, "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -212,20 +237,23 @@ 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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -274,7 +302,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to set tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -304,7 +333,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_RX_LOS: { 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -316,7 +346,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_FAULT: { 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -328,7 +359,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { diff --git a/packages/platforms/accton/x86-64/as5916-54x/onlp/builds/x86_64_accton_as5916_54x/module/make.mk b/packages/platforms/accton/x86-64/as5916-54x/onlp/builds/x86_64_accton_as5916_54x/module/make.mk index 568066a47..3c3b0f434 100644 --- a/packages/platforms/accton/x86-64/as5916-54x/onlp/builds/x86_64_accton_as5916_54x/module/make.mk +++ b/packages/platforms/accton/x86-64/as5916-54x/onlp/builds/x86_64_accton_as5916_54x/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as5916_54x_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as5916_54x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as5916_54x_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as5916_54x_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as5916_54x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5916_54x ucli:x86_64_accton_as5916_54x +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as5916_54x_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as5916-54x/onlp/builds/x86_64_accton_as5916_54x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as5916-54x/onlp/builds/x86_64_accton_as5916_54x/module/src/sfpi.c index b1e34e795..a91640894 100644 --- a/packages/platforms/accton/x86-64/as5916-54x/onlp/builds/x86_64_accton_as5916_54x/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as5916-54x/onlp/builds/x86_64_accton_as5916_54x/module/src/sfpi.c @@ -28,6 +28,8 @@ #include #include "x86_64_accton_as5916_54x_int.h" #include "x86_64_accton_as5916_54x_log.h" +#include +#include "log_ctrl.h" #define SFP_PORT_MIN 0 #define SFP_PORT_MAX 47 @@ -71,6 +73,15 @@ #define PORT_EEPROM_DEVADDR 0x50 #define QSFP_EEPROM_OFFSET_TXDIS 0x56 +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -109,14 +120,27 @@ onlp_sfpi_is_present(int port) int present; int bus, addr; + VALIDATE_PORT(port); + addr = (port < 24) ? 60 : 62; bus = (addr == 60) ? 11 : 12; 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); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -138,7 +162,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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); + syslog(LOG_ERR, "Unable to open the module_present_all device file of CPLD(0x%d).", addr); return ONLP_STATUS_E_INTERNAL; } @@ -147,7 +171,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr); return ONLP_STATUS_E_INTERNAL; } } @@ -156,7 +180,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr); return ONLP_STATUS_E_INTERNAL; } } @@ -203,7 +227,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) } if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); + syslog(LOG_ERR, "Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); return ONLP_STATUS_E_INTERNAL; } @@ -211,7 +235,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) 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); + syslog(LOG_ERR, "Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); return ONLP_STATUS_E_INTERNAL; } @@ -248,12 +272,13 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 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_UNABLE_TO_GET_DATA, "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -269,20 +294,23 @@ 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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -336,7 +364,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if(present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -347,7 +376,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ value = value & 0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d): write eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -365,7 +395,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -378,7 +409,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write LP mode status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -411,7 +443,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -424,7 +457,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(port); 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -440,7 +474,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if(present == 1){ if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -451,7 +486,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ tx_dis_val = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_dis_val < 0) { - AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -470,7 +506,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -483,7 +520,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read LP mode status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { diff --git a/packages/platforms/accton/x86-64/as5916-54xks/onlp/builds/x86_64_accton_as5916_54xks/module/make.mk b/packages/platforms/accton/x86-64/as5916-54xks/onlp/builds/x86_64_accton_as5916_54xks/module/make.mk index 3f0fcdad7..f87f40a57 100755 --- a/packages/platforms/accton/x86-64/as5916-54xks/onlp/builds/x86_64_accton_as5916_54xks/module/make.mk +++ b/packages/platforms/accton/x86-64/as5916-54xks/onlp/builds/x86_64_accton_as5916_54xks/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as5916_54xks_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as5916_54xks_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as5916_54xks_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as5916_54xks_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as5916_54xks_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5916_54xks ucli:x86_64_accton_as5916_54xks +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as5916_54xks_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as5916-54xks/onlp/builds/x86_64_accton_as5916_54xks/module/src/sfpi.c b/packages/platforms/accton/x86-64/as5916-54xks/onlp/builds/x86_64_accton_as5916_54xks/module/src/sfpi.c index 1a9c848c1..3f2dd8857 100755 --- a/packages/platforms/accton/x86-64/as5916-54xks/onlp/builds/x86_64_accton_as5916_54xks/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as5916-54xks/onlp/builds/x86_64_accton_as5916_54xks/module/src/sfpi.c @@ -28,6 +28,8 @@ #include #include "x86_64_accton_as5916_54xks_int.h" #include "x86_64_accton_as5916_54xks_log.h" +#include +#include "log_ctrl.h" #define PORT_EEPROM_FORMAT "/sys/devices/platform/as5916_54xks_sfp/module_eeprom_%d" #define MODULE_PRESENT_FORMAT "/sys/devices/platform/as5916_54xks_sfp/module_present_%d" @@ -66,6 +68,16 @@ /*QSFP tx_disable*/ #define QSFP_EEPROM_OFFSET_TXDIS 0x56 + +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -104,10 +116,21 @@ onlp_sfpi_is_present(int port) 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); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -122,7 +145,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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); + syslog(LOG_ERR, "Unable to open the module_present_all device file from (%s).", MODULE_PRESENT_ALL_ATTR); return ONLP_STATUS_E_INTERNAL; } @@ -131,7 +154,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file from(%s).", MODULE_PRESENT_ALL_ATTR); return ONLP_STATUS_E_INTERNAL; } @@ -166,7 +189,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) 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); + syslog(LOG_ERR, "Unable to open the module_rxlos_all device file from (%s).", MODULE_RXLOS_ALL_ATTR); return ONLP_STATUS_E_INTERNAL; } @@ -175,7 +198,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) 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); + syslog(LOG_ERR, "Unable to read all fields the module_rxlos_all device file from(%s).", MODULE_RXLOS_ALL_ATTR); return ONLP_STATUS_E_INTERNAL; } @@ -209,12 +232,14 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, + "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -314,7 +339,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -325,8 +351,9 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ value = value & 0xf; if (onlp_sfpi_eeprom_writeb(port, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d): write TX disable to eeprom fail\r\n", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -345,7 +372,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -359,7 +387,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write LP mode status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -392,7 +421,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -406,7 +436,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -422,7 +453,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if(present == 1){ if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -433,8 +465,9 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ tx_disable = onlp_sfpi_eeprom_readb(port, QSFP_EEPROM_OFFSET_TXDIS); if (tx_disable < 0) { - AIM_LOG_ERROR("Unable to read tx_disable status from port(%d): read TX disable from eeprom fail\r\n", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -455,7 +488,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -469,7 +503,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read LP mode status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -541,7 +576,8 @@ static int onlp_sfpi_dev_read_write(int port, uint8_t devaddr, uint8_t addr, uin sprintf(file, PORT_EEPROM_FORMAT, (port+1)); fp = fopen(file, "r+"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "Unable to open the eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -552,21 +588,24 @@ static int onlp_sfpi_dev_read_write(int port, uint8_t devaddr, uint8_t addr, uin seek_off = (port <= SFP_PORT_IDX_END) ? SFP_PAGE_OFFSET : QSFP_PAGE_OFFSET; if (fseek(fp, seek_off, SEEK_SET) != 0) { fclose(fp); - AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "Unable to set the file position indicator of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } int ret = fread(&page, 1, 1, fp); if (ret != 1) { fclose(fp); - AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } seek_off = onlp_sfpi_dev_get_sysfs_off(port, devaddr, addr, page); if (fseek(fp, seek_off, SEEK_SET) != 0) { fclose(fp); - AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "Unable to set the file position indicator of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -575,7 +614,8 @@ static int onlp_sfpi_dev_read_write(int port, uint8_t devaddr, uint8_t addr, uin fclose(fp); if (ret != size) { - AIM_LOG_ERROR("Unable to write the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to write the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } @@ -584,7 +624,8 @@ static int onlp_sfpi_dev_read_write(int port, uint8_t devaddr, uint8_t addr, uin fclose(fp); if (ret != size) { - AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } diff --git a/packages/platforms/accton/x86-64/as5916-54xl/onlp/builds/x86_64_accton_as5916_54xl/module/make.mk b/packages/platforms/accton/x86-64/as5916-54xl/onlp/builds/x86_64_accton_as5916_54xl/module/make.mk index 9b80644e3..a91b5c65d 100755 --- a/packages/platforms/accton/x86-64/as5916-54xl/onlp/builds/x86_64_accton_as5916_54xl/module/make.mk +++ b/packages/platforms/accton/x86-64/as5916-54xl/onlp/builds/x86_64_accton_as5916_54xl/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### 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 +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as5916_54xl_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as5916_54xl_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as5916_54xl_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5916_54xl ucli:x86_64_accton_as5916_54xl +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as5916_54xl_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as5916-54xl/onlp/builds/x86_64_accton_as5916_54xl/module/src/sfpi.c b/packages/platforms/accton/x86-64/as5916-54xl/onlp/builds/x86_64_accton_as5916_54xl/module/src/sfpi.c index a7d5d633e..9be217a05 100755 --- a/packages/platforms/accton/x86-64/as5916-54xl/onlp/builds/x86_64_accton_as5916_54xl/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as5916-54xl/onlp/builds/x86_64_accton_as5916_54xl/module/src/sfpi.c @@ -1,706 +1,745 @@ -/************************************************************ - * - * - * 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. - * - * - ************************************************************ - * - * - * - ***********************************************************/ -#include -#include -#include -#include "x86_64_accton_as5916_54xl_int.h" -#include "x86_64_accton_as5916_54xl_log.h" - -#define SFP_PORT_MIN 0 -#define SFP_PORT_MAX 47 -#define QSFP_PORT_MIN 48 -#define QSFP_PORT_MAX 53 -#define MIN_PORT SFP_PORT_MIN -#define MAX_PORT QSFP_PORT_MAX - -#define VALIDATE_SFP(_port) \ - do { \ - if (_port < SFP_PORT_MIN || _port > SFP_PORT_MAX) \ - return ONLP_STATUS_E_UNSUPPORTED; \ - } while(0) - -#define VALIDATE_QSFP(_port) \ - do { \ - if (_port < QSFP_PORT_MIN || _port > QSFP_PORT_MAX) \ - return ONLP_STATUS_E_UNSUPPORTED; \ - } while(0) - -#define VALIDATE_PORT(_port) \ - do { \ - if (_port < MIN_PORT || _port > MAX_PORT ) \ - return ONLP_STATUS_E_UNSUPPORTED; \ - } while(0) - -#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_LPMODE_FORMAT "/sys/devices/platform/as5916_54xl_sfp/module_lpmode_%d" -#define MODULE_RESET_FORMAT "/sys/devices/platform/as5916_54xl_sfp/module_reset_%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" - -/*QSFP tx_disable*/ -#define QSFP_EEPROM_OFFSET_TXDIS 0x56 - -/************************************************************ - * - * 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; -} - -static int read_byte(int offset, const char *fmt, ...) -{ - FILE *f; - uint8_t value = 0; - char path[100]; - va_list args; - va_start(args, fmt); - vsnprintf(path, sizeof(path), fmt, args); - va_end(args); - - f = fopen(path, "rb"); - if (!f) - return -1; - - if (fseek(f, offset, SEEK_SET) != 0) { - fclose(f); - return -1; - } - - if (fread(&value, 1, 1, f) != 1) { - fclose(f); - return -1; - } - - fclose(f); - return value; -} - -static int write_byte(int offset, uint8_t value, const char *fmt, ...) -{ - FILE *f; - char path[100]; - va_list args; - va_start(args, fmt); - vsnprintf(path, sizeof(path), fmt, args); - va_end(args); - - f = fopen(path, "r+b"); - if (!f) - return -1; - - if (fseek(f, offset, SEEK_SET) != 0) { - fclose(f); - return -1; - } - - if (fwrite(&value, 1, 1, f) != 1) { - fclose(f); - return -1; - } - - fclose(f); - return 0; -} - -int onlp_sfpi_eeprom_readb(int port, uint8_t addr) -{ - /* Validate port */ - if (port < 0) { - return ONLP_STATUS_E_PARAM; - } - - return read_byte(addr, PORT_EEPROM_FORMAT, (port+1)); -} - -int onlp_sfpi_eeprom_writeb(int port, uint8_t addr, uint8_t value) -{ - /* Validate port */ - if (port < 0) { - return ONLP_STATUS_E_PARAM; - } - - return write_byte(addr, value, PORT_EEPROM_FORMAT, (port+1)); -} - -int -onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) -{ - int rv = ONLP_STATUS_E_INTERNAL; - int present = 0; - - VALIDATE_PORT(port); - - switch(control) - { - case ONLP_SFP_CONTROL_TX_DISABLE: - case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: - { - present = onlp_sfpi_is_present(port); - if(present == 1) - { - if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP - if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - } - else { //QSFP - /* txdis valid bit(bit0-bit3), xxxx 1111 */ - value = value & 0xf; - if (onlp_sfpi_eeprom_writeb(port, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d): write TX disable to eeprom fail\r\n", - port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - } - } - else { - rv = ONLP_STATUS_E_INTERNAL; - } - break; - } - - case ONLP_SFP_CONTROL_RESET: - { - VALIDATE_QSFP(port); - - if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - break; - } - - case ONLP_SFP_CONTROL_LP_MODE: - { - VALIDATE_QSFP(port); - - if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write LP mode 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 = ONLP_STATUS_E_INTERNAL; - int present = 0; - int tx_disable; - - VALIDATE_PORT(port); - - switch(control) - { - case ONLP_SFP_CONTROL_RX_LOS: - { - VALIDATE_SFP(port); - - 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: - { - VALIDATE_SFP(port); - - 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: - case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: - { - present = onlp_sfpi_is_present(port); - if(present == 1){ - if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP - 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; - } - } - else { //QSFP - /* txdis valid bit(bit0-bit3), xxxx 1111 */ - tx_disable = onlp_sfpi_eeprom_readb(port, QSFP_EEPROM_OFFSET_TXDIS); - if (tx_disable < 0) { - AIM_LOG_ERROR("Unable to read tx_disable status from port(%d): read TX disable from eeprom fail\r\n", - port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - *value = tx_disable; - rv = ONLP_STATUS_OK; - } - } - } - else { - rv = ONLP_STATUS_E_INTERNAL; - } - break; - } - - case ONLP_SFP_CONTROL_RESET: - { - VALIDATE_QSFP(port); - - if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - break; - } - - case ONLP_SFP_CONTROL_LP_MODE: - { - VALIDATE_QSFP(port); - - if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read LP mode 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; -} - -#define SFP_PAGE_OFFSET 383 -#define QSFP_PAGE_OFFSET 127 -#define SFF_A0_ADDR 0x50 -#define SFF_A2_ADDR 0x51 -#define SFF_A0_DATA_SIZE 256 -#define SFF_A2_NON_PAGE_SIZE 128 -#define SFF_PAGE_DATA_SIZE 128 -#define SFP_PORT_IDX_END 47 -#define QSFP_PORT_IDX_BEGIN 48 -#define QSFP_PORT_IDX_END 53 - -static int onlp_sfpi_dev_get_sysfs_off(int port, uint8_t devaddr, uint8_t addr, uint8_t page) -{ - if (port <= SFP_PORT_IDX_END) { - if (devaddr == SFF_A0_ADDR) { - return addr; - } - - // SFF_A2_ADDR - if (addr < SFF_A2_NON_PAGE_SIZE) { - return SFF_A0_DATA_SIZE + addr; - } - - return SFF_A0_DATA_SIZE + (page * SFF_PAGE_DATA_SIZE) + addr; - } - - // QSFP - return (addr < SFF_A2_NON_PAGE_SIZE) ? (addr) : (page * SFF_PAGE_DATA_SIZE) + addr; -} - -static int onlp_sfpi_dev_read_write(int port, uint8_t devaddr, uint8_t addr, uint8_t* data, int size, int write_access) -{ - FILE* fp; - char file[64] = {0}; - int seek_off = 0; - uint8_t page = 0; - - if (port < 0 || port > QSFP_PORT_IDX_END) { - return ONLP_STATUS_E_PARAM; - } - - if ((port <= SFP_PORT_IDX_END) && (devaddr != 0x50 && devaddr != 0x51)) { - return ONLP_STATUS_E_PARAM; - } - - if ((port >= QSFP_PORT_IDX_BEGIN) && (devaddr != 0x50)) { - return ONLP_STATUS_E_PARAM; - } - - if ((addr + size) > 256) { - return ONLP_STATUS_E_PARAM; - } - - sprintf(file, PORT_EEPROM_FORMAT, (port+1)); - 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; - } - - // Disable buffering - setvbuf(fp, NULL, _IONBF, 0); - - // Read out current page to decide the target offset - seek_off = (port <= SFP_PORT_IDX_END) ? SFP_PAGE_OFFSET : QSFP_PAGE_OFFSET; - if (fseek(fp, seek_off, SEEK_SET) != 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(&page, 1, 1, fp); - if (ret != 1) { - fclose(fp); - AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); - return ONLP_STATUS_E_INTERNAL; - } - - seek_off = onlp_sfpi_dev_get_sysfs_off(port, devaddr, addr, page); - if (fseek(fp, seek_off, SEEK_SET) != 0) { - fclose(fp); - AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); - return ONLP_STATUS_E_INTERNAL; - } - - if (write_access) { - int ret = fwrite(data, 1, size, fp); - - fclose(fp); - if (ret != size) { - AIM_LOG_ERROR("Unable to write the module_eeprom device file of port(%d)", port); - return ONLP_STATUS_E_INTERNAL; - } - } - else { - int ret = fread(data, 1, size, fp); - - fclose(fp); - if (ret != size) { - 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) -{ - uint8_t data; - int ret = onlp_sfpi_dev_read_write(port, devaddr, addr, &data, 1, 0); - return (ret < 0) ? ret : data; -} - -int onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) -{ - return onlp_sfpi_dev_read_write(port, devaddr, addr, &value, 1, 1); -} - -int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) -{ - uint8_t data[2]; - int ret = 0; - - // Split into two byte operation if data cross the boundary - if (addr == 0x7F) { - int i = 0; - - for (i = 0; i < 2; i++) { - ret = onlp_sfpi_dev_readb(port, devaddr, addr+i); - if (ret < 0) { - break; - } - - data[i] = ret; - } - } - else { - ret = onlp_sfpi_dev_read_write(port, devaddr, addr, data, 2, 0); - } - - return (ret < 0) ? ret : (data[0] | (data[1] << 8)); -} - -int onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) -{ - int ret = 0; - uint8_t data[2] = {value & 0xFF, (value >> 8) & 0xFF}; - - // Split into two byte operation if data cross the boundary - if (addr == 0x7F) { - int i = 0; - - for (i = 0; i < 2; i++) { - ret = onlp_sfpi_dev_writeb(port, devaddr, addr+i, data[i]); - if (ret < 0) { - break; - } - } - } - else { - ret = onlp_sfpi_dev_read_write(port, devaddr, addr, data, 2, 0); - } - - return ret; -} - -int onlp_sfpi_dev_read(int port, uint8_t devaddr, uint8_t addr, uint8_t* rdata, int size) -{ - int ret = 0; - - // Split into two byte operation if data cross the boundary - if ((addr+size) > SFF_PAGE_DATA_SIZE) { - ret = onlp_sfpi_dev_read_write(port, devaddr, addr, rdata, SFF_PAGE_DATA_SIZE-addr, 0); - if (ret < 0) { - return ret; - } - - ret = onlp_sfpi_dev_read_write(port, devaddr, SFF_PAGE_DATA_SIZE, rdata + (SFF_PAGE_DATA_SIZE-addr), (addr+size-SFF_PAGE_DATA_SIZE), 0); - if (ret < 0) { - return ret; - } - } - else { - ret = onlp_sfpi_dev_read_write(port, devaddr, addr, rdata, size, 0); - } - - return ret; -} - -int onlp_sfpi_dev_write(int port, uint8_t devaddr, uint8_t addr, uint8_t* data, int size) -{ - int ret = 0; - - // Split into two byte operation if data cross the boundary - if ((addr+size) > SFF_PAGE_DATA_SIZE) { - ret = onlp_sfpi_dev_read_write(port, devaddr, addr, data, SFF_PAGE_DATA_SIZE-addr, 1); - if (ret < 0) { - return ret; - } - - ret = onlp_sfpi_dev_read_write(port, devaddr, SFF_PAGE_DATA_SIZE, data + (SFF_PAGE_DATA_SIZE-addr), (addr+size-SFF_PAGE_DATA_SIZE), 1); - if (ret < 0) { - return ret; - } - } - else { - ret = onlp_sfpi_dev_read_write(port, devaddr, addr, data, size, 1); - } - - return ret; -} - -int -onlp_sfpi_denit(void) -{ - return ONLP_STATUS_OK; -} - +/************************************************************ + * + * + * 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. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include "x86_64_accton_as5916_54xl_int.h" +#include "x86_64_accton_as5916_54xl_log.h" +#include +#include "log_ctrl.h" + +#define SFP_PORT_MIN 0 +#define SFP_PORT_MAX 47 +#define QSFP_PORT_MIN 48 +#define QSFP_PORT_MAX 53 +#define MIN_PORT SFP_PORT_MIN +#define MAX_PORT QSFP_PORT_MAX + +#define VALIDATE_SFP(_port) \ + do { \ + if (_port < SFP_PORT_MIN || _port > SFP_PORT_MAX) \ + return ONLP_STATUS_E_UNSUPPORTED; \ + } while(0) + +#define VALIDATE_QSFP(_port) \ + do { \ + if (_port < QSFP_PORT_MIN || _port > QSFP_PORT_MAX) \ + return ONLP_STATUS_E_UNSUPPORTED; \ + } while(0) + +#define VALIDATE_PORT(_port) \ + do { \ + if (_port < MIN_PORT || _port > MAX_PORT ) \ + return ONLP_STATUS_E_UNSUPPORTED; \ + } while(0) + +#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_LPMODE_FORMAT "/sys/devices/platform/as5916_54xl_sfp/module_lpmode_%d" +#define MODULE_RESET_FORMAT "/sys/devices/platform/as5916_54xl_sfp/module_reset_%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" + +/*QSFP tx_disable*/ +#define QSFP_EEPROM_OFFSET_TXDIS 0x56 + +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 } + } + } +}; + +/************************************************************ + * + * 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) { + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; +} + +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) { + syslog(LOG_ERR, "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. */ + syslog(LOG_ERR, "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) { + syslog(LOG_ERR, "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. */ + syslog(LOG_ERR, "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) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, "Unable to read eeprom from port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (size != 256) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +static int read_byte(int offset, const char *fmt, ...) +{ + FILE *f; + uint8_t value = 0; + char path[100]; + va_list args; + va_start(args, fmt); + vsnprintf(path, sizeof(path), fmt, args); + va_end(args); + + f = fopen(path, "rb"); + if (!f) + return -1; + + if (fseek(f, offset, SEEK_SET) != 0) { + fclose(f); + return -1; + } + + if (fread(&value, 1, 1, f) != 1) { + fclose(f); + return -1; + } + + fclose(f); + return value; +} + +static int write_byte(int offset, uint8_t value, const char *fmt, ...) +{ + FILE *f; + char path[100]; + va_list args; + va_start(args, fmt); + vsnprintf(path, sizeof(path), fmt, args); + va_end(args); + + f = fopen(path, "r+b"); + if (!f) + return -1; + + if (fseek(f, offset, SEEK_SET) != 0) { + fclose(f); + return -1; + } + + if (fwrite(&value, 1, 1, f) != 1) { + fclose(f); + return -1; + } + + fclose(f); + return 0; +} + +int onlp_sfpi_eeprom_readb(int port, uint8_t addr) +{ + /* Validate port */ + if (port < 0) { + return ONLP_STATUS_E_PARAM; + } + + return read_byte(addr, PORT_EEPROM_FORMAT, (port+1)); +} + +int onlp_sfpi_eeprom_writeb(int port, uint8_t addr, uint8_t value) +{ + /* Validate port */ + if (port < 0) { + return ONLP_STATUS_E_PARAM; + } + + return write_byte(addr, value, PORT_EEPROM_FORMAT, (port+1)); +} + +int +onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) +{ + int rv = ONLP_STATUS_E_INTERNAL; + int present = 0; + + VALIDATE_PORT(port); + + switch(control) + { + case ONLP_SFP_CONTROL_TX_DISABLE: + case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: + { + present = onlp_sfpi_is_present(port); + if(present == 1) + { + if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + } + else { //QSFP + /* txdis valid bit(bit0-bit3), xxxx 1111 */ + value = value & 0xf; + if (onlp_sfpi_eeprom_writeb(port, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + } + } + else { + rv = ONLP_STATUS_E_INTERNAL; + } + break; + } + + case ONLP_SFP_CONTROL_RESET: + { + VALIDATE_QSFP(port); + + if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_LP_MODE: + { + VALIDATE_QSFP(port); + + if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d)", 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 = ONLP_STATUS_E_INTERNAL; + int present = 0; + int tx_disable; + + VALIDATE_PORT(port); + + switch(control) + { + case ONLP_SFP_CONTROL_RX_LOS: + { + VALIDATE_SFP(port); + + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_FAULT: + { + VALIDATE_SFP(port); + + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_DISABLE: + case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: + { + present = onlp_sfpi_is_present(port); + if(present == 1){ + if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + } + else { //QSFP + /* txdis valid bit(bit0-bit3), xxxx 1111 */ + tx_disable = onlp_sfpi_eeprom_readb(port, QSFP_EEPROM_OFFSET_TXDIS); + if (tx_disable < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + *value = tx_disable; + rv = ONLP_STATUS_OK; + } + } + } + else { + rv = ONLP_STATUS_E_INTERNAL; + } + break; + } + + case ONLP_SFP_CONTROL_RESET: + { + VALIDATE_QSFP(port); + + if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_LP_MODE: + { + VALIDATE_QSFP(port); + + if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + default: + rv = ONLP_STATUS_E_UNSUPPORTED; + } + + return rv; +} + +#define SFP_PAGE_OFFSET 383 +#define QSFP_PAGE_OFFSET 127 +#define SFF_A0_ADDR 0x50 +#define SFF_A2_ADDR 0x51 +#define SFF_A0_DATA_SIZE 256 +#define SFF_A2_NON_PAGE_SIZE 128 +#define SFF_PAGE_DATA_SIZE 128 +#define SFP_PORT_IDX_END 47 +#define QSFP_PORT_IDX_BEGIN 48 +#define QSFP_PORT_IDX_END 53 + +static int onlp_sfpi_dev_get_sysfs_off(int port, uint8_t devaddr, uint8_t addr, uint8_t page) +{ + if (port <= SFP_PORT_IDX_END) { + if (devaddr == SFF_A0_ADDR) { + return addr; + } + + // SFF_A2_ADDR + if (addr < SFF_A2_NON_PAGE_SIZE) { + return SFF_A0_DATA_SIZE + addr; + } + + return SFF_A0_DATA_SIZE + (page * SFF_PAGE_DATA_SIZE) + addr; + } + + // QSFP + return (addr < SFF_A2_NON_PAGE_SIZE) ? (addr) : (page * SFF_PAGE_DATA_SIZE) + addr; +} + +static int onlp_sfpi_dev_read_write(int port, uint8_t devaddr, uint8_t addr, uint8_t* data, int size, int write_access) +{ + FILE* fp; + char file[64] = {0}; + int seek_off = 0; + uint8_t page = 0; + + if (port < 0 || port > QSFP_PORT_IDX_END) { + return ONLP_STATUS_E_PARAM; + } + + if ((port <= SFP_PORT_IDX_END) && (devaddr != 0x50 && devaddr != 0x51)) { + return ONLP_STATUS_E_PARAM; + } + + if ((port >= QSFP_PORT_IDX_BEGIN) && (devaddr != 0x50)) { + return ONLP_STATUS_E_PARAM; + } + + if ((addr + size) > 256) { + return ONLP_STATUS_E_PARAM; + } + + sprintf(file, PORT_EEPROM_FORMAT, (port+1)); + fp = fopen(file, "r+"); + if(fp == NULL) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "Unable to open the eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + // Disable buffering + setvbuf(fp, NULL, _IONBF, 0); + + // Read out current page to decide the target offset + seek_off = (port <= SFP_PORT_IDX_END) ? SFP_PAGE_OFFSET : QSFP_PAGE_OFFSET; + if (fseek(fp, seek_off, SEEK_SET) != 0) { + fclose(fp); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "Unable to set the file position indicator of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + int ret = fread(&page, 1, 1, fp); + if (ret != 1) { + fclose(fp); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + seek_off = onlp_sfpi_dev_get_sysfs_off(port, devaddr, addr, page); + if (fseek(fp, seek_off, SEEK_SET) != 0) { + fclose(fp); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "Unable to set the file position indicator of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (write_access) { + int ret = fwrite(data, 1, size, fp); + + fclose(fp); + if (ret != size) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to write the module_eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + } + else { + int ret = fread(data, 1, size, fp); + + fclose(fp); + if (ret != size) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "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) +{ + uint8_t data; + int ret = onlp_sfpi_dev_read_write(port, devaddr, addr, &data, 1, 0); + return (ret < 0) ? ret : data; +} + +int onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) +{ + return onlp_sfpi_dev_read_write(port, devaddr, addr, &value, 1, 1); +} + +int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) +{ + uint8_t data[2]; + int ret = 0; + + // Split into two byte operation if data cross the boundary + if (addr == 0x7F) { + int i = 0; + + for (i = 0; i < 2; i++) { + ret = onlp_sfpi_dev_readb(port, devaddr, addr+i); + if (ret < 0) { + break; + } + + data[i] = ret; + } + } + else { + ret = onlp_sfpi_dev_read_write(port, devaddr, addr, data, 2, 0); + } + + return (ret < 0) ? ret : (data[0] | (data[1] << 8)); +} + +int onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) +{ + int ret = 0; + uint8_t data[2] = {value & 0xFF, (value >> 8) & 0xFF}; + + // Split into two byte operation if data cross the boundary + if (addr == 0x7F) { + int i = 0; + + for (i = 0; i < 2; i++) { + ret = onlp_sfpi_dev_writeb(port, devaddr, addr+i, data[i]); + if (ret < 0) { + break; + } + } + } + else { + ret = onlp_sfpi_dev_read_write(port, devaddr, addr, data, 2, 0); + } + + return ret; +} + +int onlp_sfpi_dev_read(int port, uint8_t devaddr, uint8_t addr, uint8_t* rdata, int size) +{ + int ret = 0; + + // Split into two byte operation if data cross the boundary + if ((addr+size) > SFF_PAGE_DATA_SIZE) { + ret = onlp_sfpi_dev_read_write(port, devaddr, addr, rdata, SFF_PAGE_DATA_SIZE-addr, 0); + if (ret < 0) { + return ret; + } + + ret = onlp_sfpi_dev_read_write(port, devaddr, SFF_PAGE_DATA_SIZE, rdata + (SFF_PAGE_DATA_SIZE-addr), (addr+size-SFF_PAGE_DATA_SIZE), 0); + if (ret < 0) { + return ret; + } + } + else { + ret = onlp_sfpi_dev_read_write(port, devaddr, addr, rdata, size, 0); + } + + return ret; +} + +int onlp_sfpi_dev_write(int port, uint8_t devaddr, uint8_t addr, uint8_t* data, int size) +{ + int ret = 0; + + // Split into two byte operation if data cross the boundary + if ((addr+size) > SFF_PAGE_DATA_SIZE) { + ret = onlp_sfpi_dev_read_write(port, devaddr, addr, data, SFF_PAGE_DATA_SIZE-addr, 1); + if (ret < 0) { + return ret; + } + + ret = onlp_sfpi_dev_read_write(port, devaddr, SFF_PAGE_DATA_SIZE, data + (SFF_PAGE_DATA_SIZE-addr), (addr+size-SFF_PAGE_DATA_SIZE), 1); + if (ret < 0) { + return ret; + } + } + else { + ret = onlp_sfpi_dev_read_write(port, devaddr, addr, data, size, 1); + } + + return ret; +} + +int +onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/accton/x86-64/as7326-56x/onlp/builds/x86_64_accton_as7326_56x/module/make.mk b/packages/platforms/accton/x86-64/as7326-56x/onlp/builds/x86_64_accton_as7326_56x/module/make.mk index b7aa99d1b..6ec9754cc 100644 --- a/packages/platforms/accton/x86-64/as7326-56x/onlp/builds/x86_64_accton_as7326_56x/module/make.mk +++ b/packages/platforms/accton/x86-64/as7326-56x/onlp/builds/x86_64_accton_as7326_56x/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as7326_56x_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as7326_56x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as7326_56x_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as7326_56x_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as7326_56x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as7326_56x ucli:x86_64_accton_as7326_56x +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as7326_56x_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as7326-56x/onlp/builds/x86_64_accton_as7326_56x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as7326-56x/onlp/builds/x86_64_accton_as7326_56x/module/src/sfpi.c index 784011376..dc5714c16 100644 --- a/packages/platforms/accton/x86-64/as7326-56x/onlp/builds/x86_64_accton_as7326_56x/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as7326-56x/onlp/builds/x86_64_accton_as7326_56x/module/src/sfpi.c @@ -28,6 +28,8 @@ #include #include "x86_64_accton_as7326_56x_int.h" #include "x86_64_accton_as7326_56x_log.h" +#include +#include "log_ctrl.h" #define SFP_PORT_RANGE1_MIN 0 #define SFP_PORT_RANGE1_MAX 47 @@ -86,6 +88,14 @@ const int sfp_map[] = { 25,26,27,28,29,30,31,32, /*port 49~56 QSFP*/ 22,23}; /*port 57~58 SFP+ from CPU NIF.*/ +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 } + } + } +}; /************************************************************ * @@ -125,14 +135,27 @@ onlp_sfpi_is_present(int port) int present; int bus, addr; + VALIDATE_PORT(port); + addr = (port < 30) ? 62 : 60; bus = (addr == 62) ? 12 : 18; - 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); + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -154,7 +177,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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."); + syslog(LOG_ERR, "Unable to open the module_present_all device file of CPLD3."); return ONLP_STATUS_E_INTERNAL; } @@ -162,7 +185,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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."); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file of CPLD3."); return ONLP_STATUS_E_INTERNAL; } @@ -208,7 +231,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) } if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); + syslog(LOG_ERR, "Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); return ONLP_STATUS_E_INTERNAL; } @@ -216,7 +239,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) 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); + syslog(LOG_ERR, "Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); return ONLP_STATUS_E_INTERNAL; } @@ -253,12 +276,13 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 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_UNABLE_TO_GET_DATA, "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -274,20 +298,23 @@ 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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -347,7 +374,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ value = value & 0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -357,7 +385,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) else { if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -377,7 +406,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -394,7 +424,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - AIM_LOG_ERROR("Unable to write LP mode status to port(%d):read LP mode value fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d):read LP mode value fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -405,7 +436,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE, lpmode_value) < 0){ - AIM_LOG_ERROR("Unable to write LP mode status to port(%d):write eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d):write eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -448,7 +480,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -462,7 +495,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -482,7 +516,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_dis < 0) { - AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -494,7 +529,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -513,7 +549,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -530,7 +567,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0) { - AIM_LOG_ERROR("Unable to read LP mode status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { diff --git a/packages/platforms/accton/x86-64/as7515-24x/onlp/builds/x86_64_accton_as7515_24x/module/make.mk b/packages/platforms/accton/x86-64/as7515-24x/onlp/builds/x86_64_accton_as7515_24x/module/make.mk index 5f1f189be..71c5ef4ea 100644 --- a/packages/platforms/accton/x86-64/as7515-24x/onlp/builds/x86_64_accton_as7515_24x/module/make.mk +++ b/packages/platforms/accton/x86-64/as7515-24x/onlp/builds/x86_64_accton_as7515_24x/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as7515_24x_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as7515_24x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as7515_24x_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as7515_24x_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as7515_24x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as7515_24x ucli:x86_64_accton_as7515_24x +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as7515_24x_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as7515-24x/onlp/builds/x86_64_accton_as7515_24x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as7515-24x/onlp/builds/x86_64_accton_as7515_24x/module/src/sfpi.c index 8174a6928..d87b3abe5 100644 --- a/packages/platforms/accton/x86-64/as7515-24x/onlp/builds/x86_64_accton_as7515_24x/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as7515-24x/onlp/builds/x86_64_accton_as7515_24x/module/src/sfpi.c @@ -29,6 +29,8 @@ #include "x86_64_accton_as7515_24x_int.h" #include "x86_64_accton_as7515_24x_log.h" #include "platform_lib.h" +#include +#include "log_ctrl.h" #define VALIDATE(_port) \ do { \ @@ -71,6 +73,17 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { #define PORT_BUS_INDEX(port) (port_bus_index[port]) +#define MAX_PORT (NUM_OF_SFP_PORT - 1) + +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -110,10 +123,21 @@ onlp_sfpi_is_present(int port) VALIDATE(port); 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+1); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "Unable to read present status from port(%d)", port+1); 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; } @@ -128,7 +152,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) /* Read present status of each port */ fp = fopen(MODULE_PRESENT_ALL_ATTR, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to open the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -137,7 +161,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) if(count != 3) { /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -169,7 +193,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) /* Read present status of each port */ fp = fopen(MODULE_PRESENT_ALL_ATTR, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to open the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -178,7 +202,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) if(count != 3) { /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD."); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -193,7 +217,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) /* Read rx los status of each port */ fp = fopen(MODULE_RXLOS_ALL_ATTR, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD."); + syslog(LOG_ERR, "Unable to open the module_rx_los_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -202,7 +226,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) if(count != 3) { /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields the module_rx_los_all device file of CPLD."); + syslog(LOG_ERR, "Unable to read all fields the module_rx_los_all device file of CPLD."); return ONLP_STATUS_E_INTERNAL; } @@ -240,12 +264,14 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 256); if(onlp_file_read(data, 256, &size, MODULE_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_UNABLE_TO_GET_DATA, + "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -262,20 +288,23 @@ onlp_sfpi_dom_read(int port, uint8_t data[256]) sprintf(file, MODULE_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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -325,13 +354,15 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (port >= 0 && port < 4) { /* txdis valid bit(bit0-bit3), xxxx 1111 */ if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, (value & 0xf)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; } else { if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, port+1) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -344,7 +375,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, port+1) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -354,7 +386,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, port+1) < 0) { - AIM_LOG_ERROR("Unable to write lpmode status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write lpmode status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -380,7 +413,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -391,7 +425,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -406,14 +441,16 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { if (port >= 0 && port < 4) { if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS)) < 0) { - AIM_LOG_ERROR("Unable to read tx_disable status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } *value = (tx_dis & 0xf); return ONLP_STATUS_OK; } else { 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -426,7 +463,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, port+1) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -436,7 +474,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, port+1) < 0) { - AIM_LOG_ERROR("Unable to read lpmode status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read lpmode status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/as7535-28xb/onlp/builds/x86_64_accton_as7535_28xb/module/make.mk b/packages/platforms/accton/x86-64/as7535-28xb/onlp/builds/x86_64_accton_as7535_28xb/module/make.mk index a6373b185..19c2aadc2 100644 --- a/packages/platforms/accton/x86-64/as7535-28xb/onlp/builds/x86_64_accton_as7535_28xb/module/make.mk +++ b/packages/platforms/accton/x86-64/as7535-28xb/onlp/builds/x86_64_accton_as7535_28xb/module/make.mk @@ -4,6 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as7535_28xb_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as7535_28xb_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as7535_28xb_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as7535_28xb_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as7535_28xb_DEPENDMODULE_ENTRIES := init:x86_64_accton_as7535_28xb ucli:x86_64_accton_as7535_28xb + +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as7535_28xb_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as7535-28xb/onlp/builds/x86_64_accton_as7535_28xb/module/src/sfpi.c b/packages/platforms/accton/x86-64/as7535-28xb/onlp/builds/x86_64_accton_as7535_28xb/module/src/sfpi.c index fdd48a5be..4a1205ea7 100644 --- a/packages/platforms/accton/x86-64/as7535-28xb/onlp/builds/x86_64_accton_as7535_28xb/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as7535-28xb/onlp/builds/x86_64_accton_as7535_28xb/module/src/sfpi.c @@ -29,6 +29,7 @@ #include "x86_64_accton_as7535_28xb_int.h" #include "x86_64_accton_as7535_28xb_log.h" #include +#include "log_ctrl.h" #define VALIDATE(_port) \ do { \ @@ -91,6 +92,7 @@ #define QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX 0x82 #define NUM_OF_SFP_PORT 28 +#define MAX_PORT (NUM_OF_SFP_PORT - 1) static const int port_bus_index[NUM_OF_SFP_PORT] = { 23, 21, 24, 22, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, @@ -99,6 +101,15 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { #define PORT_BUS_INDEX(port) (port_bus_index[port]) +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -138,10 +149,21 @@ onlp_sfpi_is_present(int port) VALIDATE(port); if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -246,12 +268,14 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 256); if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, + "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d), size is different!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -268,20 +292,23 @@ 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) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -336,40 +363,47 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if (port >= 0 && port <= 3) { if ((identifier = onlp_sfpi_dev_readb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER)) < 0 ) { - syslog(LOG_ERR, "Failed to read Identifier, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Failed to read Identifier, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (identifier == QSFP_DD_IDENTIFIER) { /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_DD_P01H_OFFSET_CONTROL_1)) < 0 ) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } if (support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Failed to set Bank 0, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Failed to set Bank 0, unable to write tx_disable status to port(%d)", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0 ) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Failed to write tx_disable value(0x%02x) to Lane Control register on port(%d)", value, port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Failed to write tx_disable value(0x%02x) to Lane Control register on port(%d)", value, port); goto restore; } } else { @@ -380,7 +414,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if ((onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO)) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { return (rv == ONLP_STATUS_E_UNSUPPORTED) ? rv : ONLP_STATUS_E_INTERNAL; @@ -391,14 +426,16 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } else { /* QSFP */ /* txdis valid bit(bit0-bit3), xxxx 1111 */ if (onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, (value & 0xf)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; } } else { if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -411,7 +448,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write reset status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -420,7 +458,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } else { @@ -438,7 +477,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (value == 0x0) { mbit_value = RESET_RATE_SELECT_BIT(mbit_value,3); if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, MULTIRATE_OFFSET, mbit_value) < 0){ - syslog(LOG_ERR, "Unable to write multirate status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_MULTIRATE_UNABLE_TO_SET_STATUS, + "Unable to write multirate status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -446,7 +486,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) else if(value == 0x1) { mbit_value = SET_RATE_SELECT_BIT(mbit_value,3); if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, MULTIRATE_OFFSET, mbit_value) < 0){ - syslog(LOG_ERR, "Unable to write multirate status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_MULTIRATE_UNABLE_TO_SET_STATUS, + "Unable to write multirate status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -458,7 +499,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } } else { - syslog(LOG_ERR, "Unable to write multirate status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_MULTIRATE_UNABLE_TO_SET_STATUS, + "Unable to write multirate status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } @@ -486,7 +528,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -497,7 +540,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_fault status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -512,40 +556,47 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { if (port >= 0 && port <= 3) { if ((identifier = onlp_sfpi_dev_readb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER)) < 0) { - syslog(LOG_ERR, "Failed to read Identifier, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Failed to read Identifier, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (identifier == QSFP_DD_IDENTIFIER) { /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_DD_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } if (support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Failed to set Bank 0, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Failed to set Bank 0, unable to read tx_disable status from port(%d)", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((tx_dis = onlp_sfpi_dev_readb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Failed to read TX_DISABLE value from Lane Control register on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Failed to read TX_DISABLE value from Lane Control register on port(%d)", port); rv = tx_dis; goto restore; } @@ -557,7 +608,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) restore: if ((onlp_sfpi_dev_writeb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO)) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -567,7 +619,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) return ONLP_STATUS_OK; } else { /* QSFP */ if ((tx_dis = onlp_sfpi_dev_readb(port, XCVR_PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } *value = (tx_dis & 0xf); @@ -575,7 +628,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } } else { /* SFP */ if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -588,7 +642,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -598,7 +653,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/as7712-32x/onlp/builds/x86_64_accton_as7712_32x/module/make.mk b/packages/platforms/accton/x86-64/as7712-32x/onlp/builds/x86_64_accton_as7712_32x/module/make.mk index 3e09eade4..9913ddcbc 100644 --- a/packages/platforms/accton/x86-64/as7712-32x/onlp/builds/x86_64_accton_as7712_32x/module/make.mk +++ b/packages/platforms/accton/x86-64/as7712-32x/onlp/builds/x86_64_accton_as7712_32x/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as7712_32x_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as7712_32x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as7712_32x_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as7712_32x_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as7712_32x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as7712_32x ucli:x86_64_accton_as7712_32x +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as7712_32x_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as7712-32x/onlp/builds/x86_64_accton_as7712_32x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as7712-32x/onlp/builds/x86_64_accton_as7712_32x/module/src/sfpi.c index 5845ecceb..27932102d 100644 --- a/packages/platforms/accton/x86-64/as7712-32x/onlp/builds/x86_64_accton_as7712_32x/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as7712-32x/onlp/builds/x86_64_accton_as7712_32x/module/src/sfpi.c @@ -28,9 +28,12 @@ #include #include #include "platform_lib.h" +#include +#include "log_ctrl.h" #define QSFP_PORT_MIN 0 #define QSFP_PORT_MAX 31 +#define MAX_PORT QSFP_PORT_MAX #define VALIDATE_QSFP(_port) \ do { \ @@ -64,6 +67,15 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { /*QSFP Specific*/ #define QSFP_LPMODE 0x3 +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -102,11 +114,22 @@ onlp_sfpi_is_present(int port) */ 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); + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, (port+1)) < 0) { + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -119,7 +142,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) fp = fopen(MODULE_PRESENT_ALL_ATTR, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); + syslog(LOG_ERR, "Unable to open the sfp_is_present_all device file."); return ONLP_STATUS_E_INTERNAL; } int count = fscanf(fp, "%x %x %x %x", @@ -131,7 +154,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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."); + syslog(LOG_ERR, "Unable to read all fields from the sfp_is_present_all device file."); return ONLP_STATUS_E_INTERNAL; } @@ -165,7 +188,8 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 256); if(onlp_file_read(data, 256, &size, PORT_FORMAT, PORT_BUS_INDEX(port), "eeprom") != 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_UNABLE_TO_GET_DATA, + "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -219,7 +243,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ value = value & 0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -235,7 +260,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) case ONLP_SFP_CONTROL_RESET: { if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } else { @@ -251,7 +277,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - AIM_LOG_ERROR("Unable to write LP mode status to port(%d):read LP mode value fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d):read LP mode value fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -262,7 +289,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE, lpmode_value) < 0){ - AIM_LOG_ERROR("Unable to write LP mode status to port(%d):write eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d):write eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -305,7 +333,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_dis < 0) { - AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -323,7 +352,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_RESET: { if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -339,7 +369,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0) { - AIM_LOG_ERROR("Unable to read LP mode status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { diff --git a/packages/platforms/accton/x86-64/as7726-32x/onlp/builds/x86_64_accton_as7726_32x/module/make.mk b/packages/platforms/accton/x86-64/as7726-32x/onlp/builds/x86_64_accton_as7726_32x/module/make.mk index 7dd2df7a9..89a504dfe 100644 --- a/packages/platforms/accton/x86-64/as7726-32x/onlp/builds/x86_64_accton_as7726_32x/module/make.mk +++ b/packages/platforms/accton/x86-64/as7726-32x/onlp/builds/x86_64_accton_as7726_32x/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as7726_32x_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as7726_32x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as7726_32x_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as7726_32x_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as7726_32x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as7726_32x ucli:x86_64_accton_as7726_32x +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as7726_32x_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as7726-32x/onlp/builds/x86_64_accton_as7726_32x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as7726-32x/onlp/builds/x86_64_accton_as7726_32x/module/src/sfpi.c index 397282280..eb6331a88 100755 --- a/packages/platforms/accton/x86-64/as7726-32x/onlp/builds/x86_64_accton_as7726_32x/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as7726-32x/onlp/builds/x86_64_accton_as7726_32x/module/src/sfpi.c @@ -28,7 +28,8 @@ #include #include "x86_64_accton_as7726_32x_int.h" #include "x86_64_accton_as7726_32x_log.h" - +#include +#include "log_ctrl.h" #define SFP_PORT_MIN 32 #define SFP_PORT_MAX 33 @@ -83,6 +84,15 @@ int sfp_map_bus[] ={21, 22, 23, 24, 26, 25, 28, 27, 37, 38, 39, 40, 41, 42, 43, 44, 15, 16}; +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -136,10 +146,21 @@ onlp_sfpi_is_present(int port) bus = 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); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -157,7 +178,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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."); + syslog(LOG_ERR, "Unable to open the module_present_all device file of CPLD3."); return ONLP_STATUS_E_INTERNAL; } @@ -165,7 +186,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) fclose(fp); if(count != 5) { /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD3."); + syslog(LOG_ERR, "Unable to read all fields the module_present_all device file of CPLD3."); return ONLP_STATUS_E_INTERNAL; } @@ -197,7 +218,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); + syslog(LOG_ERR, "Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); return ONLP_STATUS_E_INTERNAL; } @@ -205,7 +226,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) fclose(fp); if(count != 5) { /* 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); + syslog(LOG_ERR, "Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); return ONLP_STATUS_E_INTERNAL; } @@ -240,12 +261,13 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 256); if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, onlp_sfpi_map_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_UNABLE_TO_GET_DATA, "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", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -261,20 +283,23 @@ onlp_sfpi_dom_read(int port, uint8_t data[256]) sprintf(file, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)); fp = fopen(file, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -334,7 +359,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ value = value & 0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -344,7 +370,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) else { if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write tx_disable status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -363,7 +390,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -380,7 +408,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - AIM_LOG_ERROR("Unable to write LP mode status to port(%d):read LP mode value fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d):read LP mode value fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -391,7 +420,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE, lpmode_value) < 0){ - AIM_LOG_ERROR("Unable to write LP mode status to port(%d):write eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d):write eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -432,7 +462,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -445,7 +476,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(port); 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -465,7 +497,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_dis < 0) { - AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -476,7 +509,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { 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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -495,7 +529,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -512,7 +547,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0) { - AIM_LOG_ERROR("Unable to read LP mode status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { diff --git a/packages/platforms/accton/x86-64/as7816-64x/onlp/builds/x86_64_accton_as7816_64x/module/make.mk b/packages/platforms/accton/x86-64/as7816-64x/onlp/builds/x86_64_accton_as7816_64x/module/make.mk index cbf5a4d3e..1ba1a91a7 100644 --- a/packages/platforms/accton/x86-64/as7816-64x/onlp/builds/x86_64_accton_as7816_64x/module/make.mk +++ b/packages/platforms/accton/x86-64/as7816-64x/onlp/builds/x86_64_accton_as7816_64x/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as7816_64x_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as7816_64x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as7816_64x_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as7816_64x_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as7816_64x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as7816_64x ucli:x86_64_accton_as7816_64x +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as7816_64x_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as7816-64x/onlp/builds/x86_64_accton_as7816_64x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as7816-64x/onlp/builds/x86_64_accton_as7816_64x/module/src/sfpi.c index cbdf3b171..03c14221f 100644 --- a/packages/platforms/accton/x86-64/as7816-64x/onlp/builds/x86_64_accton_as7816_64x/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as7816-64x/onlp/builds/x86_64_accton_as7816_64x/module/src/sfpi.c @@ -27,9 +27,13 @@ #include #include #include "platform_lib.h" +#include +#include "log_ctrl.h" #define QSFP_PORT_MIN 0 #define QSFP_PORT_MAX 63 +#define MIN_PORT QSFP_PORT_MIN +#define MAX_PORT QSFP_PORT_MAX #define VALIDATE_QSFP(_port) \ do { \ if (_port < QSFP_PORT_MIN || _port > QSFP_PORT_MAX ) \ @@ -64,6 +68,16 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { /*QSFP Specific*/ #define QSFP_LPMODE 0x3 + +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -103,10 +117,21 @@ onlp_sfpi_is_present(int port) 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); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -119,7 +144,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) fp = fopen(MODULE_PRESENT_ALL_ATTR, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); + syslog(LOG_ERR, "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 %x", @@ -128,7 +153,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) 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."); + syslog(LOG_ERR, "Unable to read all fields from the sfp_is_present_all device file."); return ONLP_STATUS_E_INTERNAL; } @@ -161,7 +186,7 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) int size = 0; if(onlp_file_read(data, 256, &size, PORT_FORMAT, PORT_BUS_INDEX(port), "eeprom") != 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_UNABLE_TO_GET_DATA, "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -222,7 +247,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) value = value&0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0){ - AIM_LOG_ERROR("Unable to write tx_disabled status to port(%d): write eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disabled status to port(%d): write eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -239,7 +265,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) case ONLP_SFP_CONTROL_RESET: { if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -255,7 +282,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - AIM_LOG_ERROR("Unable to write LP mode status to port(%d):read LP mode value fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d):read LP mode value fail", port); rv = ONLP_STATUS_E_INTERNAL; } else{ @@ -266,7 +294,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE, lpmode_value) < 0){ - AIM_LOG_ERROR("Unable to write LP mode status to port(%d):write eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d):write eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -309,7 +338,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { tx_disable = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_disable < 0){ - AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else{ @@ -328,7 +358,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_RESET: { if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) { - AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -344,7 +375,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - AIM_LOG_ERROR("Unable to read LP mode status from port(%d): read eeprom fail\r\n", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else{ diff --git a/packages/platforms/accton/x86-64/as7926-40xfb/onlp/builds/x86_64_accton_as7926_40xfb/module/make.mk b/packages/platforms/accton/x86-64/as7926-40xfb/onlp/builds/x86_64_accton_as7926_40xfb/module/make.mk index 0a1eeeca2..e6075a542 100644 --- a/packages/platforms/accton/x86-64/as7926-40xfb/onlp/builds/x86_64_accton_as7926_40xfb/module/make.mk +++ b/packages/platforms/accton/x86-64/as7926-40xfb/onlp/builds/x86_64_accton_as7926_40xfb/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as7926_40xfb_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as7926_40xfb_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as7926_40xfb_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as7926_40xfb_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as7926_40xfb_DEPENDMODULE_ENTRIES := init:x86_64_accton_as7926_40xfb ucli:x86_64_accton_as7926_40xfb +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as7926_40xfb_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as7926-40xfb/onlp/builds/x86_64_accton_as7926_40xfb/module/src/sfpi.c b/packages/platforms/accton/x86-64/as7926-40xfb/onlp/builds/x86_64_accton_as7926_40xfb/module/src/sfpi.c index 291e75f18..a2eb9a0eb 100644 --- a/packages/platforms/accton/x86-64/as7926-40xfb/onlp/builds/x86_64_accton_as7926_40xfb/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as7926-40xfb/onlp/builds/x86_64_accton_as7926_40xfb/module/src/sfpi.c @@ -28,6 +28,7 @@ #include #include "platform_lib.h" #include +#include "log_ctrl.h" #define NUM_OF_SFP_PORT 55 @@ -108,6 +109,15 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { /* OSFP IDENTIFIER Specific*/ #define QSFP_DD_IDENTIFIER 0x18 +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -165,10 +175,21 @@ onlp_sfpi_is_present(int port) } if (onlp_file_read_int(&present, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -214,12 +235,12 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) } if (onlp_file_read(data, 256, &size, PORT_FORMAT, PORT_BUS_INDEX(port), "eeprom") != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Invalid file size(%d)", size); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, "Invalid file size(%d)", size); return ONLP_STATUS_E_INTERNAL; } @@ -276,7 +297,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -286,14 +307,14 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) else{ identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /*QSFP DD*/ /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; break; } @@ -302,29 +323,29 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) break; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); goto restore; } if ((eeprom_control = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read control from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, "Unable to write tx_disable status to port(%d): read control from eeprom fail", port); rv = eeprom_control; goto restore; } if (eeprom_control & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write bank to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, "Unable to write tx_disable status to port(%d): write bank to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); goto restore; } @@ -335,7 +356,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -348,7 +369,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) value = value&0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0 ){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -384,7 +405,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } if (onlp_file_write_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to reset port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, "Unable to reset port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -400,14 +421,14 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read identifier from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_IDENTIFIER, "Unable to write LP mode status to port(%d): read identifier from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /*QSFP DD*/ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -417,7 +438,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) else lpmode_value &= ~QSFP_DD_LPMODE; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW, lpmode_value) < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -429,7 +450,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -441,7 +462,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE, lpmode_value)< 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -484,7 +505,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -505,7 +526,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if(present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -515,14 +536,14 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) {/* QSFP DD */ /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; break; } @@ -531,11 +552,11 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } @@ -544,17 +565,17 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): write bank to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, "Unable to read tx_disable status from port(%d): write bank to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", port); rv = tx_dis; goto restore; @@ -562,7 +583,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -575,7 +596,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { /* QSFP 28 or QSFP+ */ tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_dis < 0){ - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -612,7 +633,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } if (onlp_file_read_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -627,7 +648,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read identifier from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_IDENTIFIER, "Unable to read LP mode status from port(%d): read identifier from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -635,7 +656,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* lpmode valid bit(bit4):Low power requset sw */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): set LP mode value to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, "Unable to read LP mode status from port(%d): set LP mode value to eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -647,7 +668,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): set LP mode value to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, "Unable to read LP mode status from port(%d): set LP mode value to eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/as7946-30xb/onlp/builds/x86_64_accton_as7946_30xb/module/make.mk b/packages/platforms/accton/x86-64/as7946-30xb/onlp/builds/x86_64_accton_as7946_30xb/module/make.mk index b49d29b76..d49299751 100644 --- a/packages/platforms/accton/x86-64/as7946-30xb/onlp/builds/x86_64_accton_as7946_30xb/module/make.mk +++ b/packages/platforms/accton/x86-64/as7946-30xb/onlp/builds/x86_64_accton_as7946_30xb/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as7946_30xb_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as7946_30xb_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as7946_30xb_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as7946_30xb_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as7946_30xb_DEPENDMODULE_ENTRIES := init:x86_64_accton_as7946_30xb ucli:x86_64_accton_as7946_30xb +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as7946_30xb_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as7946-30xb/onlp/builds/x86_64_accton_as7946_30xb/module/src/sfpi.c b/packages/platforms/accton/x86-64/as7946-30xb/onlp/builds/x86_64_accton_as7946_30xb/module/src/sfpi.c index cd86f89a4..abe6a29fb 100644 --- a/packages/platforms/accton/x86-64/as7946-30xb/onlp/builds/x86_64_accton_as7946_30xb/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as7946-30xb/onlp/builds/x86_64_accton_as7946_30xb/module/src/sfpi.c @@ -28,8 +28,10 @@ #include #include "platform_lib.h" #include +#include "log_ctrl.h" #define NUM_OF_SFP_PORT 30 +#define MAX_PORT (NUM_OF_SFP_PORT - 1) /* QSFP device address of eeprom */ #define PORT_EEPROM_DEVADDR 0x50 @@ -89,6 +91,14 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { #define MODULE_TXDISABLE_MAIN_BOARD_CPLD1_FORMAT "/sys/bus/i2c/devices/12-0061/module_tx_disable_%d" #define MODULE_TXDISABLE_MAIN_BOARD_CPLD2_FORMAT "/sys/bus/i2c/devices/13-0062/module_tx_disable_%d" +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 } + } + } +}; /************************************************************ * @@ -143,10 +153,21 @@ onlp_sfpi_is_present(int port) } if (onlp_file_read_int(&present, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -200,12 +221,12 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) VALIDATE(port); if (onlp_file_read(data, 256, &size, PORT_FORMAT, PORT_BUS_INDEX(port), "eeprom") != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Invalid file size(%d)", size); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, "Invalid file size(%d)", size); return ONLP_STATUS_E_INTERNAL; } @@ -222,20 +243,20 @@ 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) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -290,40 +311,40 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if(port >= 0 && port <= 25) { if ((identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER)) < 0) { - syslog(LOG_ERR, "Failed to read Identifier, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, "Failed to read Identifier, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (identifier == QSFP_DD_IDENTIFIER) { /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } if (support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Failed to set Bank 0, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, "Failed to set Bank 0, unable to write tx_disable status to port(%d)", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Failed to write tx_disable value(0x%02x) to Lane Control register on port(%d)", value, port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, "Failed to write tx_disable value(0x%02x) to Lane Control register on port(%d)", value, port); goto restore; } } else { @@ -334,7 +355,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if ((onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO)) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -345,7 +366,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } else { /* QSFP */ /* txdis valid bit(bit0-bit3), xxxx 1111 */ if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, (value & 0xf)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -354,7 +375,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } else { path = MODULE_TXDISABLE_MAIN_BOARD_CPLD2_FORMAT; if (onlp_file_write_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to set tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, "Unable to set tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -379,7 +400,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) break; } if (onlp_file_write_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write reset status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; @@ -399,7 +420,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) break; } if (onlp_file_write_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, "Unable to write LP mode status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; @@ -442,7 +463,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if (onlp_file_read_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; @@ -457,40 +478,40 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { if (port >= 0 && port <= 25) { if ((identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER)) < 0) { - syslog(LOG_ERR, "Failed to read Identifier, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, "Failed to read Identifier, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (identifier == QSFP_DD_IDENTIFIER) { /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } if (support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Failed to set Bank 0, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, "Failed to set Bank 0, unable to read tx_disable status from port(%d)", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Failed to read TX_DISABLE value from Lane Control register on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, "Failed to read TX_DISABLE value from Lane Control register on port(%d)", port); rv = tx_dis; goto restore; } @@ -502,7 +523,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) restore: if ((onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO)) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -513,7 +534,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } } else { /* QSFP */ if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, "Unable to read tx_disable status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { *value = (tx_dis & 0xf); @@ -523,7 +544,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } else { /* SFP */ path = MODULE_TXDISABLE_MAIN_BOARD_CPLD2_FORMAT; if (onlp_file_read_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -548,7 +569,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if (onlp_file_read_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; @@ -567,7 +588,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if (onlp_file_read_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, "Unable to read LP mode status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; diff --git a/packages/platforms/accton/x86-64/as7946-74xkb/onlp/builds/x86_64_accton_as7946_74xkb/module/make.mk b/packages/platforms/accton/x86-64/as7946-74xkb/onlp/builds/x86_64_accton_as7946_74xkb/module/make.mk index 5e1d5c8ca..92e746189 100644 --- a/packages/platforms/accton/x86-64/as7946-74xkb/onlp/builds/x86_64_accton_as7946_74xkb/module/make.mk +++ b/packages/platforms/accton/x86-64/as7946-74xkb/onlp/builds/x86_64_accton_as7946_74xkb/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as7946_74xkb_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as7946_74xkb_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as7946_74xkb_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as7946_74xkb_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as7946_74xkb_DEPENDMODULE_ENTRIES := init:x86_64_accton_as7946_74xkb ucli:x86_64_accton_as7946_74xkb +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as7946_74xkb_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as7946-74xkb/onlp/builds/x86_64_accton_as7946_74xkb/module/src/sfpi.c b/packages/platforms/accton/x86-64/as7946-74xkb/onlp/builds/x86_64_accton_as7946_74xkb/module/src/sfpi.c index 1ccbdcd36..84c3cd4c7 100644 --- a/packages/platforms/accton/x86-64/as7946-74xkb/onlp/builds/x86_64_accton_as7946_74xkb/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as7946-74xkb/onlp/builds/x86_64_accton_as7946_74xkb/module/src/sfpi.c @@ -28,8 +28,10 @@ #include #include "platform_lib.h" #include +#include "log_ctrl.h" #define NUM_OF_SFP_PORT 74 +#define MAX_PORT (NUM_OF_SFP_PORT - 1) /* QSFP device address of eeprom */ #define PORT_EEPROM_DEVADDR 0x50 @@ -97,6 +99,15 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { #define MODULE_TXDISABLE_MAIN_BOARD_CPLD2_FORMAT "/sys/bus/i2c/devices/13-0062/module_tx_disable_%d" #define MODULE_TXDISABLE_MAIN_BOARD_CPLD3_FORMAT "/sys/bus/i2c/devices/16-0063/module_tx_disable_%d" +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -153,10 +164,21 @@ onlp_sfpi_is_present(int port) } if (onlp_file_read_int(&present, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -213,12 +235,12 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) VALIDATE(port); if (onlp_file_read(data, 256, &size, PORT_FORMAT, PORT_BUS_INDEX(port), "eeprom") != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Invalid file size(%d)", size); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, "Invalid file size(%d)", size); return ONLP_STATUS_E_INTERNAL; } @@ -235,20 +257,20 @@ 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) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -303,40 +325,40 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if(port >= 0 && port <= 9) { if ((identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER)) < 0) { - syslog(LOG_ERR, "Failed to read Identifier, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, "Failed to read Identifier, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (identifier == QSFP_DD_IDENTIFIER) { /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } if (support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Failed to set Bank 0, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, "Failed to set Bank 0, unable to write tx_disable status to port(%d)", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Failed to write tx_disable value(0x%02x) to Lane Control register on port(%d)", value, port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, "Failed to write tx_disable value(0x%02x) to Lane Control register on port(%d)", value, port); goto restore; } } else { @@ -347,7 +369,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if ((onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO)) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { rv = (rv == ONLP_STATUS_E_UNSUPPORTED) ? rv : ONLP_STATUS_E_INTERNAL; @@ -357,7 +379,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } else { /* QSFP */ /* txdis valid bit(bit0-bit3), xxxx 1111 */ if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, (value & 0xf)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -378,7 +400,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) break; } if (onlp_file_write_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to set tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, "Unable to set tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -406,7 +428,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) break; } if (onlp_file_write_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write reset status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; @@ -423,7 +445,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) break; } if (onlp_file_write_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, "Unable to write LP mode status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; @@ -468,7 +490,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if (onlp_file_read_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; @@ -483,40 +505,40 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { if (port >= 0 && port <= 9) { if ((identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER)) < 0) { - syslog(LOG_ERR, "Failed to read Identifier, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, "Failed to read Identifier, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (identifier == QSFP_DD_IDENTIFIER) { /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } if (support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Failed to set Bank 0, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, "Failed to set Bank 0, unable to read tx_disable status from port(%d)", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Failed to read TX_DISABLE value from Lane Control register on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, "Failed to read TX_DISABLE value from Lane Control register on port(%d)", port); rv = tx_dis; goto restore; } @@ -528,7 +550,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) restore: if ((onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO)) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -539,7 +561,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } } else { /* QSFP */ if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, "Unable to read tx_disable status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { *value = (tx_dis & 0xf); @@ -561,7 +583,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if (onlp_file_read_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -589,7 +611,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if (onlp_file_read_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; @@ -607,7 +629,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } if (onlp_file_read_int(value, path, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, "Unable to read LP mode status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } break; diff --git a/packages/platforms/accton/x86-64/as9716_32d/onlp/builds/x86_64_accton_as9716_32d/module/make.mk b/packages/platforms/accton/x86-64/as9716_32d/onlp/builds/x86_64_accton_as9716_32d/module/make.mk index 2a274b718..9f25bfb04 100755 --- a/packages/platforms/accton/x86-64/as9716_32d/onlp/builds/x86_64_accton_as9716_32d/module/make.mk +++ b/packages/platforms/accton/x86-64/as9716_32d/onlp/builds/x86_64_accton_as9716_32d/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as9716_32d_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as9716_32d_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as9716_32d_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as9716_32d_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as9716_32d_DEPENDMODULE_ENTRIES := init:x86_64_accton_as9716_32d ucli:x86_64_accton_as9716_32d +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as9716_32d_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as9716_32d/onlp/builds/x86_64_accton_as9716_32d/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9716_32d/onlp/builds/x86_64_accton_as9716_32d/module/src/sfpi.c old mode 100755 new mode 100644 index a617dbf5d..15632f415 --- a/packages/platforms/accton/x86-64/as9716_32d/onlp/builds/x86_64_accton_as9716_32d/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as9716_32d/onlp/builds/x86_64_accton_as9716_32d/module/src/sfpi.c @@ -29,6 +29,7 @@ #include "x86_64_accton_as9716_32d_int.h" #include "x86_64_accton_as9716_32d_log.h" #include +#include "log_ctrl.h" #define SFP_PORT_MIN 32 #define SFP_PORT_MAX 33 @@ -100,6 +101,15 @@ int sfp_map_bus[] ={25, 26, 27, 28, 29, 30, 31, 32, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58}; +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -159,18 +169,28 @@ onlp_sfpi_is_present(int port) bus = 21; } - if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", port); + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { - return ONLP_STATUS_E_UNSUPPORTED; } @@ -180,7 +200,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) uint32_t bytes[5]; int i = 0; uint64_t rx_los_all = 0; - + bytes[0]=bytes[1]=bytes[2]=bytes[3]=0x0; bytes[4]=0x03; for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { @@ -211,13 +231,14 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 256); - if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)) != ONLP_STATUS_OK) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d), size is different!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -233,20 +254,23 @@ onlp_sfpi_dom_read(int port, uint8_t data[256]) sprintf(file, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)); fp = fopen(file, "r"); if(fp == NULL) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -312,7 +336,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -323,14 +348,16 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /*QSFP DD*/ /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; break; } @@ -339,30 +366,35 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) break; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", + port); goto restore; } if ((eeprom_control = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read control from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to write tx_disable status to port(%d): read control from eeprom fail", + port); rv = eeprom_control; goto restore; } if (eeprom_control & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write bank to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to write tx_disable status to port(%d): write bank to eeprom fail", + port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", + port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + port); goto restore; } } else { @@ -372,7 +404,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -385,8 +418,9 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) value = value&0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0 ){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -394,7 +428,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } } } - } + } else { rv = ONLP_STATUS_E_INTERNAL; } @@ -404,7 +438,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write reset status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -419,15 +454,17 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_IDENTIFIER, + "Unable to write LP mode status to port(%d): read identifier from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /*QSFP DD*/ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -437,7 +474,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) else lpmode_value &= ~QSFP_DD_LPMODE; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW, lpmode_value) < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -451,7 +489,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -463,7 +502,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE, lpmode_value)< 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -509,7 +549,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } else{ addr=62; - bus=21; + bus=21; } switch(control) @@ -518,7 +558,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -531,7 +572,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_fault status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -548,7 +590,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if(present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -558,14 +601,16 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) {/* QSFP DD */ /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; break; } @@ -574,11 +619,13 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } @@ -587,17 +634,20 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): write bank to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to read tx_disable status from port(%d): write bank to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", port); rv = tx_dis; goto restore; @@ -605,7 +655,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -618,7 +669,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { /* QSFP 28 or QSFP+ */ tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_dis < 0){ - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -639,7 +691,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to get reset status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to get reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -655,15 +708,17 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_IDENTIFIER, + "Unable to read LP mode status from port(%d): read identifier from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ /* lpmode valid bit(bit4):Low power requset sw */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -675,7 +730,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", port); rv = ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/make.mk b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/make.mk index 95477e155..dfd0d0bfe 100644 --- a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/make.mk +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as9726_32d_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as9726_32d_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as9726_32d_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as9726_32d_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as9726_32d_DEPENDMODULE_ENTRIES := init:x86_64_accton_as9726_32d ucli:x86_64_accton_as9726_32d +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as9726_32d_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sfpi.c index b50d7d63b..132ea893e 100644 --- a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sfpi.c @@ -24,6 +24,7 @@ * ***********************************************************/ #include +#include "log_ctrl.h" #include #include @@ -31,6 +32,8 @@ #include "x86_64_accton_as9726_32d_int.h" #include "x86_64_accton_as9726_32d_log.h" +#define MAX_PORT 33 + #define VALIDATE(_port) \ do { \ if (_port < 0 || _port > 33) { \ @@ -96,6 +99,15 @@ int sfp_map_bus[] = {17, 18, 19, 20, 21, 22, 23, 24, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50}; +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -145,8 +157,13 @@ int onlp_sfpi_is_present(int port) if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)" - , port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "Unable to read present status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } else { @@ -155,12 +172,22 @@ int onlp_sfpi_is_present(int port) if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)" - , port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -279,13 +306,14 @@ int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) if (onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, + "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d), size is different!", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -301,23 +329,23 @@ int onlp_sfpi_dom_read(int port, uint8_t data[256]) sprintf(file, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)); fp = fopen(file, "r"); if (fp == NULL) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -370,40 +398,47 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if(port >= 0 && port <= 31) { if ((identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER)) < 0) { - syslog(LOG_ERR, "Failed to read Identifier, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Failed to read Identifier, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (identifier == QSFP_DD_IDENTIFIER) { /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } if (support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Failed to set Bank 0, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Failed to set Bank 0, unable to write tx_disable status to port(%d)", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", - QSFP_DD_PAGE_LANE_CTRL, port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Failed to write tx_disable value(0x%02x) to Lane Control register on port(%d)", value, port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Failed to write tx_disable value(0x%02x) to Lane Control register on port(%d)", value, port); goto restore; } } else { @@ -414,7 +449,8 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if ((onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO)) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -425,7 +461,8 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } else { /* QSFP */ /* txdis valid bit(bit0-bit3), xxxx 1111 */ if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, (value & 0xf)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -435,8 +472,8 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) addr = 62; if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to set tx_disable status to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to set tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -454,8 +491,8 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (onlp_file_write_int(value, MODULE_RESET_FORMAT, bus, addr, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to set reset status to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to set reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -469,8 +506,8 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, bus, addr, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to set LP mode to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to set LP mode to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -506,8 +543,8 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -521,8 +558,8 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_fault status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -536,40 +573,47 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { if (port >= 0 && port <= 31) { if ((identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER)) < 0) { - syslog(LOG_ERR, "Failed to read Identifier, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Failed to read Identifier, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (identifier == QSFP_DD_IDENTIFIER) { /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } if (support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Failed to set Bank 0, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Failed to set Bank 0, unable to read tx_disable status from port(%d)", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", - QSFP_DD_PAGE_LANE_CTRL, port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Failed to read TX_DISABLE value from Lane Control register on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Failed to read TX_DISABLE value from Lane Control register on port(%d)", port); rv = tx_dis; goto restore; } @@ -581,7 +625,8 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) restore: if ((onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO)) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -592,7 +637,8 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } } else { /* QSFP */ if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { *value = (tx_dis & 0xf); @@ -603,8 +649,8 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) addr = 62; if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -622,8 +668,8 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (onlp_file_read_int(value, MODULE_RESET_FORMAT, bus, addr, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to get reset status to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to get reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; @@ -637,8 +683,8 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, bus, addr, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to get LP mode to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to get LP mode from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { rv = ONLP_STATUS_OK; diff --git a/packages/platforms/accton/x86-64/as9736-64d/onlp/builds/x86_64_accton_as9736_64d/module/make.mk b/packages/platforms/accton/x86-64/as9736-64d/onlp/builds/x86_64_accton_as9736_64d/module/make.mk index 7f23fb8a0..0d204d15e 100644 --- a/packages/platforms/accton/x86-64/as9736-64d/onlp/builds/x86_64_accton_as9736_64d/module/make.mk +++ b/packages/platforms/accton/x86-64/as9736-64d/onlp/builds/x86_64_accton_as9736_64d/module/make.mk @@ -1,10 +1,16 @@ ############################################################################### # -# +# # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as9736_64d_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as9736_64d_INTERNAL_INCLUDES := -I $(THIS_DIR)src +# module -> x86_64_accton_as9736_64d -> builds -> onlp -> as9736-64d -> x86-64 -> accton +ACCTON_COMMON := $(THIS_DIR)../../../../../../common + +x86_64_accton_as9736_64d_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as9736_64d_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as9736_64d_DEPENDMODULE_ENTRIES := init:x86_64_accton_as9736_64d ucli:x86_64_accton_as9736_64d +# Pull in the shared accton helper library (log throttling, ...). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as9736_64d_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as9736-64d/onlp/builds/x86_64_accton_as9736_64d/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9736-64d/onlp/builds/x86_64_accton_as9736_64d/module/src/sfpi.c index 58d244918..c18455555 100644 --- a/packages/platforms/accton/x86-64/as9736-64d/onlp/builds/x86_64_accton_as9736_64d/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as9736-64d/onlp/builds/x86_64_accton_as9736_64d/module/src/sfpi.c @@ -30,6 +30,7 @@ #include "x86_64_accton_as9736_64d_log.h" #include "platform_lib.h" #include +#include "log_ctrl.h" #define SFP_PORT_MIN 64 #define SFP_PORT_MAX 65 @@ -111,6 +112,15 @@ int sfp_map_bus[] = {17, 18, 19, 20, 21, 22, 23, 24, 49, 50}; #endif +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -158,11 +168,21 @@ int onlp_sfpi_is_present(int port) VALIDATE_PORT(port); if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)" - , port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -262,21 +282,24 @@ int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) if (port <= 31) { if (onlp_file_read(data, 256, &size, UDB_PORT_EEPROM_FORMAT, port) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, + "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } else { if (onlp_file_read(data, 256, &size, LDB_PORT_EEPROM_FORMAT, port-32) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, + "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } if (size != 256) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d), size is different!", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", + port); return ONLP_STATUS_E_INTERNAL; } @@ -292,23 +315,23 @@ int onlp_sfpi_dom_read(int port, uint8_t data[256]) sprintf(file, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)); fp = fopen(file, "r"); if (fp == NULL) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } #endif @@ -435,8 +458,9 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -446,14 +470,16 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) else { //QSFP identifier = onlp_sfpi_eeprom_readb(port, QSFP_EEPROM_OFFSET_IDENTIFIER); if (identifier < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_eeprom_readb(port, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; break; } @@ -462,30 +488,35 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) break; } if ((rv = onlp_sfpi_eeprom_writeb(port, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", + port); goto restore; } if ((eeprom_control = onlp_sfpi_eeprom_readb(port, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read control from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to write tx_disable status to port(%d): read control from eeprom fail", + port); rv = eeprom_control; goto restore; } if (eeprom_control & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_eeprom_writeb(port, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write bank to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to write tx_disable status to port(%d): write bank to eeprom fail", + port); goto restore; } if ((rv = onlp_sfpi_eeprom_writeb(port, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", + port); goto restore; } if ((rv = onlp_sfpi_eeprom_writeb(port, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + port); goto restore; } } else { @@ -495,7 +526,8 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if (onlp_sfpi_eeprom_writeb(port, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -508,8 +540,9 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) value = value & 0xf; if (onlp_sfpi_eeprom_writeb(port, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -528,8 +561,9 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to write reset status to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -542,8 +576,9 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d)", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -575,8 +610,9 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -588,8 +624,9 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_fault status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -604,8 +641,9 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -615,14 +653,16 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { identifier = onlp_sfpi_eeprom_readb(port, QSFP_EEPROM_OFFSET_IDENTIFIER); if (identifier < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_eeprom_readb(port, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; break; } @@ -631,11 +671,13 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if ((rv = onlp_sfpi_eeprom_writeb(port, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Failed to switch to Advertising Page on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Advertising Page on port(%d)", port); goto restore; } if ((support_ctrls = onlp_sfpi_eeprom_readb(port, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Failed to read Support Control on port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Failed to read Support Control on port(%d)", port); rv = support_ctrls; goto restore; } @@ -644,25 +686,29 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) goto restore; } if ((rv = onlp_sfpi_eeprom_writeb(port, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): write bank to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to read tx_disable status from port(%d): write bank to eeprom fail", + port); goto restore; } if ((rv = onlp_sfpi_eeprom_writeb(port, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", - QSFP_DD_PAGE_LANE_CTRL, port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to switch to Lane Control Page (Page 0x%02x) on port(%d)", + QSFP_DD_PAGE_LANE_CTRL, port); goto restore; } if ((tx_dis = onlp_sfpi_eeprom_readb(port, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + port); rv = tx_dis; goto restore; } restore: if (onlp_sfpi_eeprom_writeb(port, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -675,8 +721,9 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { /* QSFP 28 or QSFP+ */ tx_dis = onlp_sfpi_eeprom_readb(port, QSFP_EEPROM_OFFSET_TXDIS); if (tx_dis < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -696,8 +743,9 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -710,8 +758,9 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, (port + 1)) < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", + port); rv = ONLP_STATUS_E_INTERNAL; } else { diff --git a/packages/platforms/accton/x86-64/as9737-32db/onlp/builds/x86_64_accton_as9737_32db/module/make.mk b/packages/platforms/accton/x86-64/as9737-32db/onlp/builds/x86_64_accton_as9737_32db/module/make.mk index 1a8eba730..ee7ab50ad 100644 --- a/packages/platforms/accton/x86-64/as9737-32db/onlp/builds/x86_64_accton_as9737_32db/module/make.mk +++ b/packages/platforms/accton/x86-64/as9737-32db/onlp/builds/x86_64_accton_as9737_32db/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as9737_32db_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as9737_32db_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as9737_32db_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as9737_32db_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as9737_32db_DEPENDMODULE_ENTRIES := init:x86_64_accton_as9737_32db ucli:x86_64_accton_as9737_32db +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as9737_32db_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as9737-32db/onlp/builds/x86_64_accton_as9737_32db/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9737-32db/onlp/builds/x86_64_accton_as9737_32db/module/src/sfpi.c index 7d1b07a56..5a10f94c8 100644 --- a/packages/platforms/accton/x86-64/as9737-32db/onlp/builds/x86_64_accton_as9737_32db/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as9737-32db/onlp/builds/x86_64_accton_as9737_32db/module/src/sfpi.c @@ -29,6 +29,7 @@ #include "x86_64_accton_as9737_32db_int.h" #include "x86_64_accton_as9737_32db_log.h" #include +#include "log_ctrl.h" #define SFP_PORT_MIN 33 #define SFP_PORT_MAX 34 @@ -101,6 +102,14 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { /*QSFP Specific*/ #define QSFP_DD_IDENTIFIER 0x18 +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 } + } + } +}; /************************************************************ * @@ -152,12 +161,21 @@ onlp_sfpi_is_present(int port) } if (onlp_file_read_int(&present, path, port) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", - port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -175,13 +193,14 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) if(onlp_file_read(data, 256, &size, MODULE_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, + "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d), size is different!", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -197,23 +216,23 @@ onlp_sfpi_dom_read(int port, uint8_t data[256]) sprintf(file, MODULE_EEPROM_FORMAT, PORT_BUS_INDEX(port)); fp = fopen(file, "r"); if(fp == NULL) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -268,8 +287,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } @@ -277,41 +296,46 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", port); return ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ int rv = ONLP_STATUS_OK; /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); goto restore; } if ((eeprom_control = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read control from eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to write tx_disable status to port(%d): read control from eeprom fail", port); rv = eeprom_control; goto restore; } if (eeprom_control & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write bank to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to write tx_disable status to port(%d): write bank to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); goto restore; } } else { @@ -321,7 +345,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -335,8 +360,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ value = value&0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) <0 ){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); return ONLP_STATUS_E_INTERNAL; } @@ -356,8 +381,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) : MODULE_RESET_CPLD3_FORMAT; if (onlp_file_write_int(value, path, port) < 0) { - syslog(LOG_ERR, "Unable to write reset status to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -370,8 +395,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) : MODULE_LPMODE_CPLD3_FORMAT; if (onlp_file_write_int(value, path, port) < 0) { - syslog(LOG_ERR, "Unable to write LP mode to port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -401,8 +426,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) *value = 0; if (port >= 33 && port <= 34) { if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } @@ -414,8 +439,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read tx_fault status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -430,36 +455,37 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if(present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } else { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to read tx_disabled status from port(%d) : read identifier from eeprom fail", port); return ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ int rv = ONLP_STATUS_OK; /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disabled status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to read tx_disabled status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read support control from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to read tx_disabled status from port(%d) : read support control from eeprom fail", port); rv = support_ctrls; goto restore; } @@ -468,25 +494,26 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : write bank to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to read tx_disabled status from port(%d) : write bank to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", port); goto restore; } if ((tx_disable = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", port); rv = tx_disable; goto restore; } restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -500,8 +527,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { /* QSFP 28 or QSFP+ */ tx_disable = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_disable < 0){ - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", port); return ONLP_STATUS_E_INTERNAL; } *value = (tx_disable & 0xf); @@ -521,8 +548,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) : MODULE_RESET_CPLD3_FORMAT; if (onlp_file_read_int(value, path, port) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -535,8 +562,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) : MODULE_LPMODE_CPLD3_FORMAT; if (onlp_file_read_int(value, path, port) < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d)", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/as9817-64-nb/src/x86_64_accton_as9817_64_nb/module/make.mk b/packages/platforms/accton/x86-64/as9817-64-nb/src/x86_64_accton_as9817_64_nb/module/make.mk index 132db709d..fe4b8ee4c 100644 --- a/packages/platforms/accton/x86-64/as9817-64-nb/src/x86_64_accton_as9817_64_nb/module/make.mk +++ b/packages/platforms/accton/x86-64/as9817-64-nb/src/x86_64_accton_as9817_64_nb/module/make.mk @@ -4,6 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as9817_64_nb_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as9817_64_nb_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../common +x86_64_accton_as9817_64_nb_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as9817_64_nb_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as9817_64_nb_DEPENDMODULE_ENTRIES := init:x86_64_accton_as9817_64_nb ucli:x86_64_accton_as9817_64_nb + +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as9817_64_nb_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as9817-64-nb/src/x86_64_accton_as9817_64_nb/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9817-64-nb/src/x86_64_accton_as9817_64_nb/module/src/sfpi.c index a3cfc9577..d57d81c6a 100644 --- a/packages/platforms/accton/x86-64/as9817-64-nb/src/x86_64_accton_as9817_64_nb/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as9817-64-nb/src/x86_64_accton_as9817_64_nb/module/src/sfpi.c @@ -29,6 +29,7 @@ #include "x86_64_accton_as9817_64_nb_int.h" #include "x86_64_accton_as9817_64_nb_log.h" #include +#include "log_ctrl.h" #define SFP_PORT_MIN 65 #define SFP_PORT_MAX 66 @@ -103,6 +104,15 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { #define PORT_BUS_INDEX(port) (port_bus_index[port-1]) +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -141,10 +151,21 @@ onlp_sfpi_is_present(int port) int present; if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -161,12 +182,13 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 256); if(onlp_file_read(data, 256, &size, MODULE_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d), size is different!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -182,20 +204,23 @@ onlp_sfpi_dom_read(int port, uint8_t data[256]) sprintf(file, MODULE_EEPROM_FORMAT, PORT_BUS_INDEX(port)); fp = fopen(file, "r"); if(fp == NULL) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -247,14 +272,16 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } else { //QSFP identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", port); return ONLP_STATUS_E_INTERNAL; } else { @@ -264,32 +291,38 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) int rv = ONLP_STATUS_OK; /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); goto restore; } if ((eeprom_control = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read control from eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to write tx_disable status to port(%d): read control from eeprom fail", port); rv = eeprom_control; goto restore; } if (eeprom_control & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write bank to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to write tx_disable status to port(%d): write bank to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); goto restore; } } else { @@ -299,7 +332,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -313,7 +347,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) case QSFP_PLUS_IDENTIFIER:{ value = value&0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) <0 ){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); return ONLP_STATUS_E_INTERNAL; } break; @@ -332,7 +367,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) case ONLP_SFP_CONTROL_RESET_STATE: { VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to write reset status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -340,7 +376,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) case ONLP_SFP_CONTROL_LP_MODE: { VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -368,7 +405,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) *value = 0; if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } @@ -377,7 +415,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_FAULT: { VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read tx_fault status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -388,14 +427,16 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if(present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } else { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read identifier from eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to read tx_disabled status from port(%d) : read identifier from eeprom fail", port); return ONLP_STATUS_E_INTERNAL; } else { @@ -405,18 +446,21 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) int rv = ONLP_STATUS_OK; /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read control from eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to read tx_disabled status from port(%d) : read control from eeprom fail", port); rv = support_ctrls; goto restore; } @@ -425,22 +469,26 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : write bank to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to read tx_disabled status from port(%d) : write bank to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", port); goto restore; } if ((tx_disable = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", port); rv = tx_disable; goto restore; } restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -455,7 +503,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case QSFP_PLUS_IDENTIFIER:{ tx_disable = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_disable < 0){ - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", port); return ONLP_STATUS_E_INTERNAL; } *value = (tx_disable & 0xf); @@ -475,7 +524,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_RESET_STATE: { VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; @@ -483,7 +533,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_LP_MODE: { VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; diff --git a/packages/platforms/accton/x86-64/as9817-64/src/x86_64_accton_as9817_64/module/make.mk b/packages/platforms/accton/x86-64/as9817-64/src/x86_64_accton_as9817_64/module/make.mk index a353a86a4..a3f63b8ba 100644 --- a/packages/platforms/accton/x86-64/as9817-64/src/x86_64_accton_as9817_64/module/make.mk +++ b/packages/platforms/accton/x86-64/as9817-64/src/x86_64_accton_as9817_64/module/make.mk @@ -4,6 +4,13 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as9817_64_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as9817_64_INTERNAL_INCLUDES := -I $(THIS_DIR)src +# module -> x86_64_accton_as9817_64 -> src -> as9817-64 -> x86-64 -> accton +ACCTON_COMMON := $(THIS_DIR)../../../../../common + +x86_64_accton_as9817_64_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as9817_64_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as9817_64_DEPENDMODULE_ENTRIES := init:x86_64_accton_as9817_64 ucli:x86_64_accton_as9817_64 + +# Pull in the shared accton helper library (log throttling, ...). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as9817_64_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as9817-64/src/x86_64_accton_as9817_64/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9817-64/src/x86_64_accton_as9817_64/module/src/sfpi.c index b78e759d0..aa91e2cea 100644 --- a/packages/platforms/accton/x86-64/as9817-64/src/x86_64_accton_as9817_64/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as9817-64/src/x86_64_accton_as9817_64/module/src/sfpi.c @@ -29,6 +29,7 @@ #include "x86_64_accton_as9817_64_int.h" #include "x86_64_accton_as9817_64_log.h" #include +#include "log_ctrl.h" #define SFP_PORT_MIN 65 #define SFP_PORT_MAX 66 @@ -105,6 +106,15 @@ static const int port_bus_index[NUM_OF_SFP_PORT] = { #define OSFP_IDENTIFIER 0x19 +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -143,10 +153,21 @@ onlp_sfpi_is_present(int port) int present; if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -163,12 +184,14 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 256); if(onlp_file_read(data, 256, &size, MODULE_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, + "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d), size is different!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -184,20 +207,23 @@ onlp_sfpi_dom_read(int port, uint8_t data[256]) sprintf(file, MODULE_EEPROM_FORMAT, PORT_BUS_INDEX(port)); fp = fopen(file, "r"); if(fp == NULL) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -249,15 +275,17 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } else { //QSFP identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", + port); return ONLP_STATUS_E_INTERNAL; } else { @@ -267,33 +295,39 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) int rv = ONLP_STATUS_OK; /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to write tx_disable status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", + port); goto restore; } if ((eeprom_control = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read control from eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to write tx_disable status to port(%d): read control from eeprom fail", port); rv = eeprom_control; goto restore; } if (eeprom_control & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write bank to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to write tx_disable status to port(%d): write bank to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); goto restore; } } else { @@ -303,7 +337,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -318,8 +353,9 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* txdis valid bit(bit0-bit3), xxxx 1111 */ value = value&0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) <0 ){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + port); return ONLP_STATUS_E_INTERNAL; } break; @@ -341,7 +377,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_RESET_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to write reset status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -351,7 +388,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) VALIDATE_QSFP(port); if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -380,7 +418,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) *value = 0; if (port >= 65 && port <= 66) { if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } @@ -392,7 +431,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read tx_fault status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -407,15 +447,17 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if(present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } } else { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to read tx_disabled status from port(%d) : read identifier from eeprom fail", + port); return ONLP_STATUS_E_INTERNAL; } else { @@ -425,20 +467,23 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) int rv = ONLP_STATUS_OK; /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Failed to read Status byte, unable to read tx_disable status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (status_byte & QSFP_DD_FLAT_MEM) { return ONLP_STATUS_E_UNSUPPORTED; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read control from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to read tx_disabled status from port(%d) : read control from eeprom fail", + port); rv = support_ctrls; goto restore; } @@ -447,25 +492,29 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : write bank to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to read tx_disabled status from port(%d) : write bank to eeprom fail", port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disabled status from port(%d) : write page to eeprom fail", port); goto restore; } if ((tx_disable = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", + port); rv = tx_disable; goto restore; } restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -480,8 +529,9 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case QSFP_PLUS_IDENTIFIER:{ //for as9817-64D tx_disable = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_disable < 0){ - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d) : read TX disable from eeprom fail", + port); return ONLP_STATUS_E_INTERNAL; } *value = (tx_disable & 0xf); @@ -505,7 +555,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_RESET_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -515,7 +566,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) VALIDATE_QSFP(port); if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, port) < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/as9926-24d/onlp/builds/x86_64_accton_as9926_24d/module/make.mk b/packages/platforms/accton/x86-64/as9926-24d/onlp/builds/x86_64_accton_as9926_24d/module/make.mk index 2356e8fe7..586637610 100644 --- a/packages/platforms/accton/x86-64/as9926-24d/onlp/builds/x86_64_accton_as9926_24d/module/make.mk +++ b/packages/platforms/accton/x86-64/as9926-24d/onlp/builds/x86_64_accton_as9926_24d/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as9926_24d_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as9926_24d_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as9926_24d_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as9926_24d_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as9926_24d_DEPENDMODULE_ENTRIES := init:x86_64_accton_as9926_24d ucli:x86_64_accton_as9926_24d +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as9926_24d_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as9926-24d/onlp/builds/x86_64_accton_as9926_24d/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9926-24d/onlp/builds/x86_64_accton_as9926_24d/module/src/sfpi.c index e4ab7fb8e..1043915e1 100644 --- a/packages/platforms/accton/x86-64/as9926-24d/onlp/builds/x86_64_accton_as9926_24d/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as9926-24d/onlp/builds/x86_64_accton_as9926_24d/module/src/sfpi.c @@ -29,6 +29,7 @@ #include "x86_64_accton_as9926_24d_int.h" #include "x86_64_accton_as9926_24d_log.h" #include +#include "log_ctrl.h" #define SFP_PORT_MIN 24 #define SFP_PORT_MAX 25 @@ -98,6 +99,15 @@ /* OSFP IDENTIFIER Specific*/ #define QSFP_DD_IDENTIFIER 0x18 +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 } + } + } +}; + /************************************************************ * * SFPI Entry Points @@ -138,10 +148,21 @@ onlp_sfpi_is_present(int port) int bus = (port < 16) ? 20 : 21; if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", port); + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; } @@ -250,12 +271,14 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) memset(data, 0, 256); if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, + "Unable to read eeprom from port(%d)", port); return ONLP_STATUS_E_INTERNAL; } if (size != 256) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d), size is different!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); return ONLP_STATUS_E_INTERNAL; } @@ -271,20 +294,23 @@ 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) { - syslog(LOG_ERR, "Unable to open the eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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); - syslog(LOG_ERR, "Unable to set the file position indicator of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -341,7 +367,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { //SFP if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, 21, 62, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -352,15 +379,17 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /*QSFP DD*/ /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read status byte from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Unable to write tx_disable status to port(%d): read status byte from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; break; } @@ -369,30 +398,35 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) break; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", + port); goto restore; } if ((eeprom_control = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read control from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to write tx_disable status to port(%d): read control from eeprom fail", + port); rv = eeprom_control; goto restore; } if (eeprom_control & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write bank to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to write tx_disable status to port(%d): write bank to eeprom fail", + port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", + port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + port); goto restore; } } else { @@ -402,7 +436,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -415,8 +450,9 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) value = value&0xf; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0 ){ - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -438,7 +474,8 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) int bus = (port < 16) ? 20 : 21; if (onlp_file_write_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write reset status to port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to write reset status to port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -455,16 +492,18 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) if (present == 1) { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_IDENTIFIER, + "Unable to write LP mode status to port(%d): read identifier from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /*QSFP DD*/ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else{ @@ -473,8 +512,9 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) else lpmode_value &= ~QSFP_DD_LPMODE; if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW, lpmode_value) < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -487,8 +527,9 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else{ @@ -499,8 +540,9 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } if(onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE, lpmode_value)< 0){ - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -543,7 +585,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, 21, 62, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -556,7 +599,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { VALIDATE_SFP(port); if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, 21, 62, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_fault status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -573,7 +617,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if(present == 1) { if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, 21, 62, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -583,15 +628,17 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) {/* QSFP DD */ /* Flat-memory CMIS modules do not implement page 01h/10h */ if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read status byte from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Unable to read tx_disable status from port(%d): read status byte from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; break; } @@ -600,13 +647,15 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) break; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disable status from port(%d): write page to eeprom fail", + port); goto restore; } if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read support control from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to read tx_disable status from port(%d): read support control from eeprom fail", + port); rv = support_ctrls; goto restore; } @@ -615,25 +664,29 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): write bank to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to read tx_disable status from port(%d): write bank to eeprom fail", + port); goto restore; } if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): write page to eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disable status from port(%d): write page to eeprom fail", + port); goto restore; } if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + port); rv = tx_dis; goto restore; } restore: if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); } if (rv < 0) { @@ -646,8 +699,9 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) else { /* QSFP 28 or QSFP+ */ tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); if(tx_dis < 0){ - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -671,7 +725,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) int bus = (port < 16) ? 20 : 21; if (onlp_file_read_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -688,16 +743,18 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (present == 1) { identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); if(identifier < 0){ - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read identifier from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_IDENTIFIER, + "Unable to read LP mode status from port(%d): read identifier from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ /* lpmode valid bit(bit4):Low power requset sw */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -708,8 +765,9 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); if(lpmode_value < 0){ - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", - port); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", + port); rv = ONLP_STATUS_E_INTERNAL; } else { diff --git a/packages/platforms/accton/x86-64/as9926-24db/onlp/builds/x86_64_accton_as9926_24db/module/make.mk b/packages/platforms/accton/x86-64/as9926-24db/onlp/builds/x86_64_accton_as9926_24db/module/make.mk index e4dbf4969..dbfe1d879 100644 --- a/packages/platforms/accton/x86-64/as9926-24db/onlp/builds/x86_64_accton_as9926_24db/module/make.mk +++ b/packages/platforms/accton/x86-64/as9926-24db/onlp/builds/x86_64_accton_as9926_24db/module/make.mk @@ -4,7 +4,11 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as9926_24db_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as9926_24db_INTERNAL_INCLUDES := -I $(THIS_DIR)src +ACCTON_COMMON := $(THIS_DIR)../../../../../../common +x86_64_accton_as9926_24db_INCLUDES := -I $(THIS_DIR)inc -I $(ACCTON_COMMON)/inc +x86_64_accton_as9926_24db_INTERNAL_INCLUDES := -I $(THIS_DIR)src -I $(ACCTON_COMMON)/inc x86_64_accton_as9926_24db_DEPENDMODULE_ENTRIES := init:x86_64_accton_as9926_24db ucli:x86_64_accton_as9926_24db +# Pull in the shared accton helper library (log throttling). +include $(ACCTON_COMMON)/src/make.mk +x86_64_accton_as9926_24db_LIBRARIES := accton_common diff --git a/packages/platforms/accton/x86-64/as9926-24db/onlp/builds/x86_64_accton_as9926_24db/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9926-24db/onlp/builds/x86_64_accton_as9926_24db/module/src/sfpi.c index a0e614017..c9c1f6717 100644 --- a/packages/platforms/accton/x86-64/as9926-24db/onlp/builds/x86_64_accton_as9926_24db/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as9926-24db/onlp/builds/x86_64_accton_as9926_24db/module/src/sfpi.c @@ -1,716 +1,769 @@ -/************************************************************ - * - * - * 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. - * - * - ************************************************************ - * - * - * - ***********************************************************/ -#include -#include -#include -#include "x86_64_accton_as9926_24db_int.h" -#include "x86_64_accton_as9926_24db_log.h" -#include - -#define PORT_BUS_INDEX(port) (port+9) - -#define SFP_PORT_MIN 24 -#define SFP_PORT_MAX 25 -#define QSFP_PORT_MIN 0 -#define QSFP_PORT_MAX 23 -#define MIN_PORT QSFP_PORT_MIN -#define MAX_PORT SFP_PORT_MAX - -#define VALIDATE_SFP(_port) \ - do { \ - if (_port < SFP_PORT_MIN || _port > SFP_PORT_MAX) \ - return ONLP_STATUS_E_UNSUPPORTED; \ - } while(0) - -#define VALIDATE_QSFP(_port) \ - do { \ - if (_port < QSFP_PORT_MIN || _port > QSFP_PORT_MAX) \ - return ONLP_STATUS_E_UNSUPPORTED; \ - } while(0) - -#define VALIDATE_PORT(_port) \ - do { \ - if (_port < MIN_PORT || _port > MAX_PORT) \ - return ONLP_STATUS_E_UNSUPPORTED; \ - } while(0) - -/* QSFP device address of eeprom */ -#define PORT_EEPROM_DEVADDR 0x50 - -/*QSFP identify offsets*/ -#define QSFP_EEPROM_OFFSET_IDENTIFIER 0x0 - -/* QSFP eeprom offsets*/ -#define QSFP_EEPROM_OFFSET_TXDIS 0x56 - -/* QSFP DD eeprom offsets*/ -#define QSFP_DD_EEPROM_OFFSET_BANK_SELECT 0x7E -#define QSFP_DD_EEPROM_OFFSET_PAGE_SELECT 0x7F -#define QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1 0x9B -#define QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX 0x82 -#define QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW 0x1A - -/*QSFP Specific*/ -#define QSFP_EEPROM_OFFSET_LPMODE 0x5D -#define QSFP_LPMODE 0x3 - -/* QSFP DD Specific*/ -#define QSFP_DD_PAGE_ADMIN_INFO 0x0 -#define QSFP_DD_PAGE_ADVERTISING 0x1 -#define QSFP_DD_PAGE_LANE_CTRL 0x10 -#define QSFP_DD_LOWER_OFFSET_STATUS 0x02 -#define QSFP_DD_FLAT_MEM 0x80 /* byte 0x02 bit 7 */ -#define QSFP_DD_P01H_TX_DISABLE_SUPPORT 0x2 -#define QSFP_DD_LPMODE 0x10 - -/* OSFP IDENTIFIER Specific*/ -#define QSFP_DD_IDENTIFIER 0x18 - -#define PORT_EEPROM_FORMAT \ - "/sys/bus/i2c/devices/%d-0050/eeprom" -#define MODULE_PRESENT_FORMAT \ - "/sys/devices/platform/as9926_24db_sfp/module_present_%d" -#define MODULE_RESET_FORMAT \ - "/sys/devices/platform/as9926_24db_sfp/module_reset_%d" -#define MODULE_RXLOS_FORMAT \ - "/sys/devices/platform/as9926_24db_sfp/module_rx_los_%d" -#define MODULE_TXFAULT_FORMAT \ - "/sys/devices/platform/as9926_24db_sfp/module_tx_fault_%d" -#define MODULE_TXDISABLE_FORMAT \ - "/sys/devices/platform/as9926_24db_sfp/module_tx_disable_%d" -#define MODULE_PRESENT_ALL_ATTR \ - "/sys/devices/platform/as9926_24db_sfp/module_present_all" -#define MODULE_RXLOS_ALL_ATTR \ - "/sys/devices/platform/as9926_24db_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, 26} - */ - int p; - - for(p = 0; p < 26; 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) { - syslog(LOG_ERR, "Unable to read present status from port(%d)", - port); - return ONLP_STATUS_E_INTERNAL; - } - - return present; -} - -int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) -{ - uint32_t bytes[4]; - FILE* fp; - - /* Read present status of port 0~25 */ - int count = 0; - - fp = fopen(MODULE_PRESENT_ALL_ATTR, "r"); - if(fp == NULL) { - syslog(LOG_ERR, "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", bytes+0, bytes+1, bytes+2, - bytes+3); - - fclose(fp); - - if(count != 4) { - /* Likely a CPLD read timeout. */ - syslog(LOG_ERR, "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 SFP ports */ - bytes[3] &= 0x3; - - /* Convert to 64 bit integer in port order */ - int i = 0; - uint64_t presence_all = 0 ; - AIM_BITMAP_CLR_ALL(dst); - - 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[4]; - FILE* fp; - - /* Read present status of port 0~25 */ - int count = 0; - - - bytes[0] = bytes[1] = bytes[2] = bytes[3] = 0; - fp = fopen(MODULE_RXLOS_ALL_ATTR, "r"); - - if(fp == NULL) { - syslog(LOG_ERR, "Unable to open the module_rxlos_all \ - device file from (%s).", - MODULE_RXLOS_ALL_ATTR); - - return ONLP_STATUS_E_INTERNAL; - } - - count = fscanf(fp, "%x", bytes+3); - - fclose(fp); - - if(count != 1) { - /* Likely a CPLD read timeout. */ - syslog(LOG_ERR, "Unable to read all fields the module_rxlos_all \ - device file from(%s).", MODULE_RXLOS_ALL_ATTR); - - return ONLP_STATUS_E_INTERNAL; - } - - /* Mask out non-existant SFP ports */ - bytes[3] &= 0x3; - - /* Convert to 64 bit integer in port order */ - int i = 0; - uint64_t rx_los_all = 0 ; - AIM_BITMAP_CLR_ALL(dst); - - 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_BUS_INDEX(port)) != ONLP_STATUS_OK) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d)", port); - return ONLP_STATUS_E_INTERNAL; - } - - if (size != 256) { - syslog(LOG_ERR, "Unable to read eeprom from port(%d), size is \ - different!", port); - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - -int onlp_sfpi_dom_read(int port, uint8_t data[256]) -{ - FILE* fp; - char file[64] = {0}; - - sprintf(file, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)); - fp = fopen(file, "r"); - if(fp == NULL) { - syslog(LOG_ERR, "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); - syslog(LOG_ERR, "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) { - syslog(LOG_ERR, "Unable to read the module_eeprom device file of \ - port(%d)", 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 = ONLP_STATUS_E_INTERNAL; - int present = 0; - int lpmode_value = 0; - int identifier = 0; - int status_byte = 0; - int eeprom_control; - - VALIDATE_PORT(port); - - switch(control) - { - case ONLP_SFP_CONTROL_TX_DISABLE: - case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: - { - present = onlp_sfpi_is_present(port); - if (present == 1) { - if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { /* SFP */ - if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, - (port+1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d)", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - } - else { /* QSFP */ - identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); - if (identifier < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ - /* Flat-memory CMIS modules do not implement page 01h/10h */ - if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read status byte from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - break; - } - if (status_byte & QSFP_DD_FLAT_MEM) { - rv = ONLP_STATUS_E_UNSUPPORTED; - break; - } - if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); - goto restore; - } - if ((eeprom_control = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): read control from eeprom fail", port); - rv = eeprom_control; - goto restore; - } - if (eeprom_control & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { - if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write bank to eeprom fail", port); - goto restore; - } - if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); - goto restore; - } - if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); - goto restore; - } - } else { - rv = ONLP_STATUS_E_UNSUPPORTED; - goto restore; - } - -restore: - if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); - } - - if (rv < 0) { - rv = (rv == ONLP_STATUS_E_UNSUPPORTED) ? rv : ONLP_STATUS_E_INTERNAL; - } else { - rv = ONLP_STATUS_OK; - } - } else { /* QSFP 28 or QSFP+ */ - value = value & 0xf; - if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { - syslog(LOG_ERR, "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - } - } - } - else { - rv = ONLP_STATUS_E_INTERNAL; - } - break; - } - - case ONLP_SFP_CONTROL_RESET: - { - VALIDATE_QSFP(port); - if (onlp_file_write_int(value, MODULE_RESET_FORMAT, - (port+1)) < 0) { - syslog(LOG_ERR, "Unable to set reset to port(%d)", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - break; - } - - case ONLP_SFP_CONTROL_LP_MODE: - { - VALIDATE_QSFP(port); - present = onlp_sfpi_is_present(port); - if (present == 1) { - identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); - if (identifier < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read identifier from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ - lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); - if (lpmode_value < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - if (value) - lpmode_value |= QSFP_DD_LPMODE; - else - lpmode_value &= ~QSFP_DD_LPMODE; - if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW, lpmode_value) < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - } - } else { /* QSFP 28 or QSFP+ */ - lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); - if (lpmode_value < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - if (value) - lpmode_value |= QSFP_LPMODE; - else - lpmode_value &= ~QSFP_LPMODE; - if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE, lpmode_value) < 0) { - syslog(LOG_ERR, "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - } - } - } - else { - rv = ONLP_STATUS_E_INTERNAL; - } - break; - } - - default: - rv = ONLP_STATUS_E_UNSUPPORTED; - break; - } - - return rv; -} - -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_get(int port, onlp_sfp_control_t control, int* value) -{ - int rv = ONLP_STATUS_E_INTERNAL; - int present = 0; - int lpmode_value = 0; - int identifier = 0; - int status_byte = 0; - int support_ctrls = 0; - int tx_dis = 0; - - VALIDATE_PORT(port); - - switch(control) - { - case ONLP_SFP_CONTROL_RESET: - { - VALIDATE_QSFP(port); - if (onlp_file_read_int(value, MODULE_RESET_FORMAT, - (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read reset status from port(%d)", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - break; - } - case ONLP_SFP_CONTROL_RX_LOS: - { - VALIDATE_SFP(port); - if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, - (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read rx_loss status from port(%d)", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - break; - } - - case ONLP_SFP_CONTROL_TX_FAULT: - { - VALIDATE_SFP(port); - if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, - (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_fault status from port(%d)", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - break; - } - - case ONLP_SFP_CONTROL_TX_DISABLE: - case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: - { - present = onlp_sfpi_is_present(port); - if (present == 1) { - if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { /* SFP */ - if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, - (port+1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d)", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - rv = ONLP_STATUS_OK; - } - } - else { /* QSFP */ - identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); - if (identifier < 0) { - syslog(LOG_ERR, "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ - /* Flat-memory CMIS modules do not implement page 01h/10h */ - if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read status byte from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - break; - } - if (status_byte & QSFP_DD_FLAT_MEM) { - rv = ONLP_STATUS_E_UNSUPPORTED; - break; - } - if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): write page to eeprom fail", port); - goto restore; - } - if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read support control from eeprom fail", port); - rv = support_ctrls; - goto restore; - } - if (!(support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT)) { - rv = ONLP_STATUS_E_UNSUPPORTED; - goto restore; - } - if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): write bank to eeprom fail", port); - goto restore; - } - if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): write page to eeprom fail", port); - goto restore; - } - if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", port); - rv = tx_dis; - goto restore; - } - -restore: - if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { - syslog(LOG_ERR, "Failed to restore Page Select to Admin Info on port(%d)!", port); - } - - if (rv < 0) { - rv = (rv == ONLP_STATUS_E_UNSUPPORTED) ? rv : ONLP_STATUS_E_INTERNAL; - } else { - *value = (tx_dis & 0xff); - rv = ONLP_STATUS_OK; - } - } - else { /* QSFP 28 or QSFP+ */ - tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); - if (tx_dis < 0) { - syslog(LOG_ERR, "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - *value = (tx_dis & 0xf); - rv = ONLP_STATUS_OK; - } - } - } - } - else { - rv = ONLP_STATUS_E_INTERNAL; - } - break; - } - - case ONLP_SFP_CONTROL_LP_MODE: - { - VALIDATE_QSFP(port); - present = onlp_sfpi_is_present(port); - if (present == 1) { - identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); - if (identifier < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read identifier from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ - /* lpmode valid bit(bit4): Low power request sw */ - lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); - if (lpmode_value < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - *value = !!(lpmode_value & QSFP_DD_LPMODE); - rv = ONLP_STATUS_OK; - } - } else { /* QSFP 28 or QSFP+ */ - /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ - lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); - if (lpmode_value < 0) { - syslog(LOG_ERR, "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", port); - rv = ONLP_STATUS_E_INTERNAL; - } - else { - *value = ((lpmode_value & QSFP_LPMODE) == QSFP_LPMODE); - rv = ONLP_STATUS_OK; - } - } - } - else { - rv = ONLP_STATUS_E_INTERNAL; - } - break; - } - - default: - rv = ONLP_STATUS_E_UNSUPPORTED; - } - - return rv; -} - -int onlp_sfpi_denit(void) -{ - return ONLP_STATUS_OK; -} +/************************************************************ + * + * + * 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. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include "x86_64_accton_as9926_24db_int.h" +#include "x86_64_accton_as9926_24db_log.h" +#include +#include "log_ctrl.h" + +#define PORT_BUS_INDEX(port) (port+9) + +#define SFP_PORT_MIN 24 +#define SFP_PORT_MAX 25 +#define QSFP_PORT_MIN 0 +#define QSFP_PORT_MAX 23 +#define MIN_PORT QSFP_PORT_MIN +#define MAX_PORT SFP_PORT_MAX + +#define VALIDATE_SFP(_port) \ + do { \ + if (_port < SFP_PORT_MIN || _port > SFP_PORT_MAX) \ + return ONLP_STATUS_E_UNSUPPORTED; \ + } while(0) + +#define VALIDATE_QSFP(_port) \ + do { \ + if (_port < QSFP_PORT_MIN || _port > QSFP_PORT_MAX) \ + return ONLP_STATUS_E_UNSUPPORTED; \ + } while(0) + +#define VALIDATE_PORT(_port) \ + do { \ + if (_port < MIN_PORT || _port > MAX_PORT) \ + return ONLP_STATUS_E_UNSUPPORTED; \ + } while(0) + +/* QSFP device address of eeprom */ +#define PORT_EEPROM_DEVADDR 0x50 + +/*QSFP identify offsets*/ +#define QSFP_EEPROM_OFFSET_IDENTIFIER 0x0 + +/* QSFP eeprom offsets*/ +#define QSFP_EEPROM_OFFSET_TXDIS 0x56 + +/* QSFP DD eeprom offsets*/ +#define QSFP_DD_EEPROM_OFFSET_BANK_SELECT 0x7E +#define QSFP_DD_EEPROM_OFFSET_PAGE_SELECT 0x7F +#define QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1 0x9B +#define QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX 0x82 +#define QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW 0x1A + +/*QSFP Specific*/ +#define QSFP_EEPROM_OFFSET_LPMODE 0x5D +#define QSFP_LPMODE 0x3 + +/* QSFP DD Specific*/ +#define QSFP_DD_PAGE_ADMIN_INFO 0x0 +#define QSFP_DD_PAGE_ADVERTISING 0x1 +#define QSFP_DD_PAGE_LANE_CTRL 0x10 +#define QSFP_DD_LOWER_OFFSET_STATUS 0x02 +#define QSFP_DD_FLAT_MEM 0x80 /* byte 0x02 bit 7 */ +#define QSFP_DD_P01H_TX_DISABLE_SUPPORT 0x2 +#define QSFP_DD_LPMODE 0x10 + +/* OSFP IDENTIFIER Specific*/ +#define QSFP_DD_IDENTIFIER 0x18 + +#define PORT_EEPROM_FORMAT \ + "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT \ + "/sys/devices/platform/as9926_24db_sfp/module_present_%d" +#define MODULE_RESET_FORMAT \ + "/sys/devices/platform/as9926_24db_sfp/module_reset_%d" +#define MODULE_RXLOS_FORMAT \ + "/sys/devices/platform/as9926_24db_sfp/module_rx_los_%d" +#define MODULE_TXFAULT_FORMAT \ + "/sys/devices/platform/as9926_24db_sfp/module_tx_fault_%d" +#define MODULE_TXDISABLE_FORMAT \ + "/sys/devices/platform/as9926_24db_sfp/module_tx_disable_%d" +#define MODULE_PRESENT_ALL_ATTR \ + "/sys/devices/platform/as9926_24db_sfp/module_present_all" +#define MODULE_RXLOS_ALL_ATTR \ + "/sys/devices/platform/as9926_24db_sfp/module_rxlos_all" + +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 } + } + } +}; + +/************************************************************ + * + * 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, 26} + */ + int p; + + for(p = 0; p < 26; 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) { + if (log_mgmt[port].present_rec != ONLP_STATUS_E_INTERNAL) { + reset_log_ctrl(log_mgmt[port].log_ctrl, SFP_LOG_REASON_COUNT); + } + log_mgmt[port].present_rec = ONLP_STATUS_E_INTERNAL; + + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_PRESENT_UNABLE_TO_GET_STATUS, + "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; +} + +int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[4]; + FILE* fp; + + /* Read present status of port 0~25 */ + int count = 0; + + fp = fopen(MODULE_PRESENT_ALL_ATTR, "r"); + if(fp == NULL) { + syslog(LOG_ERR, "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", bytes+0, bytes+1, bytes+2, + bytes+3); + + fclose(fp); + + if(count != 4) { + /* Likely a CPLD read timeout. */ + syslog(LOG_ERR, "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 SFP ports */ + bytes[3] &= 0x3; + + /* Convert to 64 bit integer in port order */ + int i = 0; + uint64_t presence_all = 0 ; + AIM_BITMAP_CLR_ALL(dst); + + 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[4]; + FILE* fp; + + /* Read present status of port 0~25 */ + int count = 0; + + + bytes[0] = bytes[1] = bytes[2] = bytes[3] = 0; + fp = fopen(MODULE_RXLOS_ALL_ATTR, "r"); + + if(fp == NULL) { + syslog(LOG_ERR, "Unable to open the module_rxlos_all \ + device file from (%s).", + MODULE_RXLOS_ALL_ATTR); + + return ONLP_STATUS_E_INTERNAL; + } + + count = fscanf(fp, "%x", bytes+3); + + fclose(fp); + + if(count != 1) { + /* Likely a CPLD read timeout. */ + syslog(LOG_ERR, "Unable to read all fields the module_rxlos_all \ + device file from(%s).", MODULE_RXLOS_ALL_ATTR); + + return ONLP_STATUS_E_INTERNAL; + } + + /* Mask out non-existant SFP ports */ + bytes[3] &= 0x3; + + /* Convert to 64 bit integer in port order */ + int i = 0; + uint64_t rx_los_all = 0 ; + AIM_BITMAP_CLR_ALL(dst); + + 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_BUS_INDEX(port)) != ONLP_STATUS_OK) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA, + "Unable to read eeprom from port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (size != 256) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_EEPROM_UNABLE_TO_GET_DATA_SIZE_DIFF, + "Unable to read eeprom from port(%d), size is different!", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + FILE* fp; + char file[64] = {0}; + + sprintf(file, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)); + fp = fopen(file, "r"); + if(fp == NULL) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_OPEN_EEPROM_FILE, + "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); + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_SET_FILE_POS_INDICATOR, + "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) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_DOM_UNABLE_TO_GET_EEPROM_DATA, + "Unable to read the module_eeprom device file of port(%d)", 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 = ONLP_STATUS_E_INTERNAL; + int present = 0; + int lpmode_value = 0; + int identifier = 0; + int status_byte = 0; + int eeprom_control; + + VALIDATE_PORT(port); + + switch(control) + { + case ONLP_SFP_CONTROL_TX_DISABLE: + case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: + { + present = onlp_sfpi_is_present(port); + if (present == 1) { + if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { /* SFP */ + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, + (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + } + else { /* QSFP */ + identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); + if (identifier < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to write tx_disable status to port(%d): read identifier from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ + /* Flat-memory CMIS modules do not implement page 01h/10h */ + if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Unable to write tx_disable status to port(%d): read status byte from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + break; + } + if (status_byte & QSFP_DD_FLAT_MEM) { + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); + goto restore; + } + if ((eeprom_control = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to write tx_disable status to port(%d): read control from eeprom fail", port); + rv = eeprom_control; + goto restore; + } + if (eeprom_control & QSFP_DD_P01H_TX_DISABLE_SUPPORT) { + if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to write tx_disable status to port(%d): write bank to eeprom fail", port); + goto restore; + } + if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to write tx_disable status to port(%d): write page to eeprom fail", port); + goto restore; + } + if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX, (value & 0xff))) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); + goto restore; + } + } else { + rv = ONLP_STATUS_E_UNSUPPORTED; + goto restore; + } + +restore: + if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); + } + + if (rv < 0) { + rv = (rv == ONLP_STATUS_E_UNSUPPORTED) ? rv : ONLP_STATUS_E_INTERNAL; + } else { + rv = ONLP_STATUS_OK; + } + } else { /* QSFP 28 or QSFP+ */ + value = value & 0xf; + if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_STATUS, + "Unable to write tx_disable status to port(%d): write TX disable to eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + } + } + } + else { + rv = ONLP_STATUS_E_INTERNAL; + } + break; + } + + case ONLP_SFP_CONTROL_RESET: + { + VALIDATE_QSFP(port); + if (onlp_file_write_int(value, MODULE_RESET_FORMAT, + (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_SET_STATUS, + "Unable to set reset to port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_LP_MODE: + { + VALIDATE_QSFP(port); + present = onlp_sfpi_is_present(port); + if (present == 1) { + identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); + if (identifier < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_IDENTIFIER, + "Unable to write LP mode status to port(%d): read identifier from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ + lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); + if (lpmode_value < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + if (value) + lpmode_value |= QSFP_DD_LPMODE; + else + lpmode_value &= ~QSFP_DD_LPMODE; + if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW, lpmode_value) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + } + } else { /* QSFP 28 or QSFP+ */ + lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); + if (lpmode_value < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to write LP mode status to port(%d): read LP mode value from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + if (value) + lpmode_value |= QSFP_LPMODE; + else + lpmode_value &= ~QSFP_LPMODE; + if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE, lpmode_value) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_SET_STATUS, + "Unable to write LP mode status to port(%d): write LP mode value to eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + } + } + } + else { + rv = ONLP_STATUS_E_INTERNAL; + } + break; + } + + default: + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + return rv; +} + +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_get(int port, onlp_sfp_control_t control, int* value) +{ + int rv = ONLP_STATUS_E_INTERNAL; + int present = 0; + int lpmode_value = 0; + int identifier = 0; + int status_byte = 0; + int support_ctrls = 0; + int tx_dis = 0; + + VALIDATE_PORT(port); + + switch(control) + { + case ONLP_SFP_CONTROL_RESET: + { + VALIDATE_QSFP(port); + if (onlp_file_read_int(value, MODULE_RESET_FORMAT, + (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RESET_UNABLE_TO_GET_STATUS, + "Unable to read reset status from port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + case ONLP_SFP_CONTROL_RX_LOS: + { + VALIDATE_SFP(port); + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, + (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_RX_LOS_UNABLE_TO_GET_STATUS, + "Unable to read rx_loss status from port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_FAULT: + { + VALIDATE_SFP(port); + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, + (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_FAULT_UNABLE_TO_GET_STATUS, + "Unable to read tx_fault status from port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_DISABLE: + case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: + { + present = onlp_sfpi_is_present(port); + if (present == 1) { + if (port >= SFP_PORT_MIN && port <= SFP_PORT_MAX) { /* SFP */ + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, + (port+1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disabled status from port(%d)", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + } + else { /* QSFP */ + identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); + if (identifier < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_IDENTIFIER, + "Unable to read tx_disabled status from port(%d): read identifier from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ + /* Flat-memory CMIS modules do not implement page 01h/10h */ + if ((status_byte = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_LOWER_OFFSET_STATUS)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_MEM_MODEL, + "Unable to read tx_disable status from port(%d): read status byte from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + break; + } + if (status_byte & QSFP_DD_FLAT_MEM) { + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disable status from port(%d): write page to eeprom fail", port); + goto restore; + } + if ((support_ctrls = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P01H_OFFSET_CONTROL_1)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_CONTROL, + "Unable to read tx_disable status from port(%d): read support control from eeprom fail", port); + rv = support_ctrls; + goto restore; + } + if (!(support_ctrls & QSFP_DD_P01H_TX_DISABLE_SUPPORT)) { + rv = ONLP_STATUS_E_UNSUPPORTED; + goto restore; + } + if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_BANK_SELECT, 0)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_BANK, + "Unable to read tx_disable status from port(%d): write bank to eeprom fail", port); + goto restore; + } + if ((rv = onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Unable to read tx_disable status from port(%d): write page to eeprom fail", port); + goto restore; + } + if ((tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_P10H_OFFSET_OUTPUT_DISABLE_TX)) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", port); + rv = tx_dis; + goto restore; + } + +restore: + if (onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO) < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_SET_EEPROM_PAGE, + "Failed to restore Page Select to Admin Info on port(%d)!", port); + } + + if (rv < 0) { + rv = (rv == ONLP_STATUS_E_UNSUPPORTED) ? rv : ONLP_STATUS_E_INTERNAL; + } else { + *value = (tx_dis & 0xff); + rv = ONLP_STATUS_OK; + } + } + else { /* QSFP 28 or QSFP+ */ + tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); + if (tx_dis < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_TX_DIS_UNABLE_TO_GET_STATUS, + "Unable to read tx_disable status from port(%d): read TX disable from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + *value = (tx_dis & 0xf); + rv = ONLP_STATUS_OK; + } + } + } + } + else { + rv = ONLP_STATUS_E_INTERNAL; + } + break; + } + + case ONLP_SFP_CONTROL_LP_MODE: + { + VALIDATE_QSFP(port); + present = onlp_sfpi_is_present(port); + if (present == 1) { + identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); + if (identifier < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_IDENTIFIER, + "Unable to read LP mode status from port(%d): read identifier from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else if (identifier == QSFP_DD_IDENTIFIER) { /* QSFP DD */ + /* lpmode valid bit(bit4): Low power request sw */ + lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_EEPROM_OFFSET_LOWPWR_REQUEST_SW); + if (lpmode_value < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + *value = !!(lpmode_value & QSFP_DD_LPMODE); + rv = ONLP_STATUS_OK; + } + } else { /* QSFP 28 or QSFP+ */ + /* lpmode valid bit(bit0):set LP/txdis mode bit(bit1):set low/high power mode */ + lpmode_value = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_LPMODE); + if (lpmode_value < 0) { + syslog_ctrl(log_mgmt[port].log_ctrl, SFP_LP_MODE_UNABLE_TO_GET_STATUS, + "Unable to read LP mode status from port(%d): read LP mode value from eeprom fail", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + *value = ((lpmode_value & QSFP_LPMODE) == QSFP_LPMODE); + rv = ONLP_STATUS_OK; + } + } + } + else { + rv = ONLP_STATUS_E_INTERNAL; + } + break; + } + + default: + rv = ONLP_STATUS_E_UNSUPPORTED; + } + + return rv; +} + +int onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +}