diff --git a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py index d3aa2b6cd24e..9729aeed8073 100644 --- a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py @@ -9,11 +9,12 @@ ############################################################################# try: - import sys - import re + import json import os + import re + import sys import subprocess - import json + import time from sonic_platform_base.chassis_base import ChassisBase from helper import APIHelper except ImportError as e: @@ -25,6 +26,12 @@ NUM_THERMAL = 11 NUM_SFP = 56 NUM_COMPONENT = 7 + +SFP_PORT_START = 1 +SFP_PORT_END = 48 +QSFP_PORT_START = 49 +QSFP_PORT_END = 56 + REBOOT_CAUSE_REG = "0xA106" TLV_EEPROM_I2C_BUS = 0 TLV_EEPROM_I2C_ADDR = 56 @@ -32,6 +39,11 @@ BASE_CPLD_PLATFORM = "questone2bd.cpldb" BASE_GETREG_PATH = "/sys/devices/platform/{}/getreg".format(BASE_CPLD_PLATFORM) +SWITCH_BRD_PLATFORM = "questone2bd.switchboard" +PORT_INFO_PATH = "/sys/devices/platform/{}/SFF".format(SWITCH_BRD_PLATFORM) +PATH_INT_SYSFS = "{0}/{port_name}/{type_prefix}_isr_flags" +PATH_INTMASK_SYSFS = "{0}/{port_name}/{type_prefix}_isr_mask" +PATH_PRS_SYSFS = "{0}/{port_name}/{prs_file_name}" class Chassis(ChassisBase): """Platform-specific Chassis class""" @@ -40,12 +52,14 @@ def __init__(self): ChassisBase.__init__(self) self._api_helper = APIHelper() self.sfp_module_initialized = False + self.POLL_INTERVAL = 1 if not self._api_helper.is_host(): self.__initialize_fan() self.__initialize_psu() self.__initialize_eeprom() self.__initialize_thermals() + self.__initialize_interrupts() else: self.__initialize_components() @@ -85,6 +99,46 @@ def __initialize_components(self): component = Component(index) self._component_list.append(component) + def __initialize_interrupts(self): + # Initial Interrupt MASK for QSFP, SFP + sfp_info_obj = {} + + present_en = 0x10 + Rxlos_IntL_en = 0x01 + event_mask = present_en + + for index in range(NUM_SFP): + port_num = index + 1 + if port_num in range(SFP_PORT_START, SFP_PORT_END+1): + port_name = "SFP{}".format(str(port_num - SFP_PORT_START + 1)) + port_type = "sfp" + sysfs_prs_file = "{}_modabs".format(port_type) + elif port_num in range(QSFP_PORT_START, QSFP_PORT_END+1): + port_name = "QSFP{}".format(str(port_num - QSFP_PORT_START + 1)) + port_type = "qsfp" + sysfs_prs_file = "{}_modprs".format(port_type) + + sfp_info_obj[index] = {} + sfp_info_obj[index]['intmask_sysfs'] = PATH_INTMASK_SYSFS.format( + PORT_INFO_PATH, + port_name = port_name, + type_prefix = port_type) + + sfp_info_obj[index]['int_sysfs'] = PATH_INT_SYSFS.format( + PORT_INFO_PATH, + port_name = port_name, + type_prefix = port_type) + + sfp_info_obj[index]['prs_sysfs'] = PATH_PRS_SYSFS.format( + PORT_INFO_PATH, + port_name = port_name, + prs_file_name = sysfs_prs_file) + + self._api_helper.write_file( + sfp_info_obj[index]["intmask_sysfs"], hex(event_mask)) + + self.sfp_info_obj = sfp_info_obj + def get_base_mac(self): """ Retrieves the base MAC address for the chassis @@ -260,3 +314,83 @@ def get_status(self): A boolean value, True if device is operating properly, False if not """ return True + + ############################################################## + ###################### Event methods ######################### + ############################################################## + + def __is_port_device_present(self, port_idx): + prs_path = self.sfp_info_obj[port_idx]["prs_sysfs"] + is_present = 1 - int(self._api_helper.read_txt_file(prs_path)) + return is_present + + def __update_port_event_object(self, interrup_devices): + port_dict = {} + event_obj = {'sfp':port_dict} + for port_idx in interrup_devices: + device_id = str(port_idx + 1) + port_dict[device_id] = str(self.__is_port_device_present(port_idx)) + + if len(port_dict): + event_obj['sfp'] = port_dict + + return event_obj + + def __check_all_port_interrupt_event(self): + interrupt_devices = {} + for i in range(NUM_SFP): + int_sysfs = self.sfp_info_obj[i]["int_sysfs"] + interrupt_flags = self._api_helper.read_txt_file(int_sysfs) + if interrupt_flags != '0x00': + interrupt_devices[i] = 1 + return interrupt_devices + + def get_change_event(self, timeout=0): + """ + Returns a nested dictionary containing all devices which have + experienced a change at chassis level + Args: + timeout: Timeout in milliseconds (optional). If timeout == 0, + this method will block until a change is detected. + Returns: + (bool, dict): + - True if call successful, False if not; + - A nested dictionary where key is a device type, + value is a dictionary with key:value pairs in the + format of {'device_id':'device_event'}, + where device_id is the device ID for this device and + device_event, + status='1' represents device inserted, + status='0' represents device removed. + Ex. {'fan':{'0':'0', '2':'1'}, 'sfp':{'11':'0'}} + indicates that fan 0 has been removed, fan 2 + has been inserted and sfp 11 has been removed. + """ + if timeout == 0: + timer = self.POLL_INTERVAL + while True: + interrupt_devices = self.__check_all_port_interrupt_event() + if len(interrupt_devices): + break + else: + time.sleep(timer) + events_dict = self.__update_port_event_object(interrupt_devices) + return (True, events_dict) + else: + timeout = timeout / float(1000) + timer = min(timeout, self.POLL_INTERVAL) + + while True: + start_time = time.time() + interrupt_devices = self.__check_all_port_interrupt_event() + if len(interrupt_devices): + break + + if timeout <= 0: + break + else: + time.sleep(timer) + elasped_time = time.time() - start_time + timeout = round(timeout - elasped_time, 3) + events_dict = self.__update_port_event_object(interrupt_devices) + return (True, events_dict) diff --git a/platform/broadcom/sonic-platform-modules-cel/questone2bd/modules/switchboard_fpga.c b/platform/broadcom/sonic-platform-modules-cel/questone2bd/modules/switchboard_fpga.c index 82c5dcc049cc..8dbf68f077fa 100644 --- a/platform/broadcom/sonic-platform-modules-cel/questone2bd/modules/switchboard_fpga.c +++ b/platform/broadcom/sonic-platform-modules-cel/questone2bd/modules/switchboard_fpga.c @@ -25,7 +25,7 @@ */ #ifndef TEST_MODE -#define MOD_VERSION "0.5.4" +#define MOD_VERSION "0.5.5" #else #define MOD_VERSION "TEST" #endif @@ -867,6 +867,20 @@ static ssize_t qsfp_modprs_show(struct device *dev, struct device_attribute *att } DEVICE_ATTR_RO(qsfp_modprs); +static ssize_t qsfp_isr_flags_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + u8 data; + int err; + struct sff_device_data *dev_data = dev_get_drvdata(dev); + unsigned int portid = dev_data->portid; + err = i2c_xcvr_access(I2C_XCVR_INRT,portid,&data,I2C_SMBUS_READ); + if(err < 0){ + return err; + } + return sprintf(buf, "0x%2.2x\n", data); +} +DEVICE_ATTR_RO(qsfp_isr_flags); + static ssize_t sfp_txfault_show(struct device *dev, struct device_attribute *attr, char *buf) { u8 data; @@ -909,6 +923,20 @@ static ssize_t sfp_modabs_show(struct device *dev, struct device_attribute *attr } DEVICE_ATTR_RO(sfp_modabs); +static ssize_t sfp_isr_flags_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + u8 data; + int err; + struct sff_device_data *dev_data = dev_get_drvdata(dev); + unsigned int portid = dev_data->portid; + err = i2c_xcvr_access(I2C_XCVR_INRT,portid,&data,I2C_SMBUS_READ); + if(err < 0){ + return err; + } + return sprintf(buf, "0x%2.2x\n", data); +} +DEVICE_ATTR_RO(sfp_isr_flags); + static ssize_t qsfp_modsel_show(struct device *dev, struct device_attribute *attr, char *buf) { u8 data; @@ -980,6 +1008,35 @@ static ssize_t qsfp_reset_store(struct device *dev, struct device_attribute *att } DEVICE_ATTR_RW(qsfp_reset); +static ssize_t qsfp_isr_mask_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + u8 data; + int err; + struct sff_device_data *dev_data = dev_get_drvdata(dev); + unsigned int portid = dev_data->portid; + err = i2c_xcvr_access(I2C_XCVR_MASK,portid,&data,I2C_SMBUS_READ); + if(err < 0){ + return err; + } + return sprintf(buf, "0x%2.2x\n", data); +} + +static ssize_t qsfp_isr_mask_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) +{ + ssize_t status; + u8 data; + struct sff_device_data *dev_data = dev_get_drvdata(dev); + unsigned int portid = dev_data->portid; + + status = kstrtou8(buf, 0, &data); + if (status == 0) { + i2c_xcvr_access(I2C_XCVR_MASK,portid,&data,I2C_SMBUS_WRITE); + status = size; + } + return status; +} +DEVICE_ATTR_RW(qsfp_isr_mask); + static ssize_t sfp_txdisable_show(struct device *dev, struct device_attribute *attr, char *buf) { u8 data; @@ -1017,15 +1074,48 @@ static ssize_t sfp_txdisable_store(struct device *dev, struct device_attribute * } DEVICE_ATTR_RW(sfp_txdisable); +static ssize_t sfp_isr_mask_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + u8 data; + int err; + struct sff_device_data *dev_data = dev_get_drvdata(dev); + unsigned int portid = dev_data->portid; + err = i2c_xcvr_access(I2C_XCVR_MASK,portid,&data,I2C_SMBUS_READ); + if(err < 0){ + return err; + } + return sprintf(buf, "0x%2.2x\n", data); +} + +static ssize_t sfp_isr_mask_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) +{ + ssize_t status; + u8 data; + struct sff_device_data *dev_data = dev_get_drvdata(dev); + unsigned int portid = dev_data->portid; + + status = kstrtou8(buf, 0, &data); + if (status == 0) { + i2c_xcvr_access(I2C_XCVR_MASK,portid,&data,I2C_SMBUS_WRITE); + status = size; + } + return status; +} +DEVICE_ATTR_RW(sfp_isr_mask); + static struct attribute *sff_attrs[] = { &dev_attr_qsfp_modirq.attr, &dev_attr_qsfp_modprs.attr, &dev_attr_qsfp_modsel.attr, &dev_attr_qsfp_reset.attr, + &dev_attr_qsfp_isr_flags.attr, + &dev_attr_qsfp_isr_mask.attr, &dev_attr_sfp_txfault.attr, &dev_attr_sfp_rxlos.attr, &dev_attr_sfp_modabs.attr, &dev_attr_sfp_txdisable.attr, + &dev_attr_sfp_isr_flags.attr, + &dev_attr_sfp_isr_mask.attr, NULL, }; @@ -2413,7 +2503,6 @@ static long fpgafw_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned switch (status_reg) { case 0x0000 : status_reg = 0x8000; break; - case 0x8080 : status_reg = 0x80C0; break; case 0x80C0 : status_reg = 0x80F0;