class ROVUtility: def __init__(self): log = Logger(__name__) self.logger = log.getLogger() self.cpld = CPLD() self.rov_controller = ROVController() def platform_check(self): # NCP 1-1 beta (JR2 B1) and later #0x2[9abcdefABCDEF]) board_info = self.cpld.get_board_info() if board_info["hw_rev"] >= 2: return True else: return False def get_j2_rov(self): try: if not self.platform_check(): self.logger.error("Not supported") return {} j2_rov_stamp = self.cpld.get_j2_rov_stamp() rov_controller_config = self.rov_controller.get_rov_config() rov_controller_output = self.rov_controller.get_rov_output() return { "j2_rov_stamp": j2_rov_stamp, "rov_controller_config": "0x{:02X}".format(rov_controller_config), "rov_controller_config_volt": self.rov_controller._vid_to_volt_str(rov_controller_config), "rov_controller_output": "0x{:02X}".format(rov_controller_output), "rov_controller_output_volt": self.rov_controller._vid_to_volt_str(rov_controller_output) } except Exception as e: self.logger.error("get_j2_rov failed, error: {0}".format(e)) def set_j2_rov(self): try: if not self.platform_check(): self.logger.error("Not supported") return j2_rov_stamp = self.cpld.get_j2_rov_stamp() self.rov_controller.set_rov_config(j2_rov_stamp) except Exception as e: self.logger.error("set_j2_rov failed, error: {}".format(e))
class CPLDUtility: def __init__(self): log = Logger(__name__) self.logger = log.getLogger() self.cpld = CPLD() def _check_cpld_num(self, cpld_num): if cpld_num not in range(CPLDConst.CPLD_MAX): raise ValueError("CPLD number({0}) is out of range (0-{1})".format( cpld_num, CPLDConst.CPLD_MAX - 1)) def _check_dev_type(self, devType): if devType not in range(DevType.DEV_MAX): raise ValueError("Dev Type({}) is out of range (0-{})".format( devType, DevType.DEV_MAX)) board_info = self.cpld.get_board_info() if board_info["hw_rev"] == 0: if devType != DevType.J2: raise ValueError( "Dev Type({}) Reset is not supported ".format(devType)) ''' else: if devType not in range(DevType.RETIMER+1): raise ValueError("Dev Type({}) Reset is not supported ".format(devType)) ''' def _version_h(self, version): return "{}.{:02d}".format(version >> 6, version & 0b00111111) def get_board_info(self): try: board_info = self.cpld.get_board_info() return board_info except Exception as e: self.logger.error("get_board_info failed, error: {0}".format(e)) def get_cpld_version(self, target): try: if target == CPLDSource.CPU: cpld_version = self.cpld.get_cpu_board_cpld_version() return { "version": "X.%02x" % cpld_version, "version_h": self._version_h(cpld_version) } elif target == CPLDSource.MB: result = [] result_h = [] cpld_versions = self.cpld.get_main_board_cpld_version() for i in range(len(cpld_versions)): result.append("X.%02x" % cpld_versions[i]) result_h.append(self._version_h(cpld_versions[i])) return {"version": result, "version_h": result_h} else: raise ValueError("target(" + str(target) + ") is out of range") except Exception as e: self.logger.error( "get_cpld_version failed, target={0}, error: {1}".format( target, e)) def get_cpld_id(self): try: result = [] cpld_ids = self.cpld.get_main_board_cpld_id() for i in range(len(cpld_ids)): result.append("X.%02x" % cpld_ids[i]) return {"id": result} except Exception as e: self.logger.error("get_cpld_id failed, error: {0}".format(e)) def get_cpld_port_interrupt(self, cpld_num): try: self._check_cpld_num(cpld_num) result = self.cpld.get_port_interrupt(cpld_num) if result == PortStatus.INTERRUPTED: ret_val = {"interrupt_status": "interrupted"} else: ret_val = {"interrupt_status": "no interrupt"} return ret_val except Exception as e: self.logger.error( "get_cpld_port_interrupt failed, error: {0}".format(e)) def reset_dev(self, devType): try: self._check_dev_type(devType) self.cpld.reset_dev(devType) except Exception as e: self.logger.error("reset_dev {} failed, error: {}".format( devType, e)) def get_reset_ctrl(self, devType): try: result = self.cpld.get_reset_ctrl(devType) if result == ResetStatus.RESET: ret_val = {"reset": "true"} elif result == ResetStatus.UNSET: ret_val = {"reset": "false"} else: ret_val = {"reset": "not supported"} return ret_val except Exception as e: self.logger.error("get_reset_ctrl {} failed, error: {}".format( devType, e)) def set_reset_ctrl(self, devType, reset_status): try: result = self.cpld.set_reset_ctrl(devType, reset_status) if result == False: self.logger.error( "reset_ctrl failed, devType={}, reset_status={}".format( devType, reset_status)) except Exception as e: self.logger.error("set_reset_ctrl {} failed, error: {}".format( devType, e))
class SFPUtility: def __init__(self): log = Logger(__name__) self.logger = log.getLogger() self.ioexp = IOExpander() self.cpld = CPLD() def _check_sfp_port(self, port): if port not in range(SFP.MAX_PORT): raise ValueError("Port number({0}) is out of range (0-{1})".format( port, SFP.MAX_PORT - 1)) def get_presence(self, port_num): try: #get hw_rev board_info = self.cpld.get_board_info() #not proto board if board_info["hw_rev"] != 0b00: ret_val = {"presence": "not supported"} return ret_val self._check_sfp_port(port_num) result = self.cpld.sfp_get_presence(port_num) if result == PortStatus.PORT_ABSENCE: ret_val = {"presence": "absence"} else: ret_val = {"presence": "presence"} return ret_val except Exception as e: self.logger.error( "get_presence failed, port_num={0}, error: {1}".format( port_num, e)) def get_rx_los(self, port_num): try: self._check_sfp_port(port_num) result = self.cpld.sfp_get_rx_los(port_num) if result == SFP.DETECTED: ret_val = {"rx_los": "detected"} else: ret_val = {"rx_los": "undetected"} return ret_val except Exception as e: self.logger.error( "get_rx_los failed, port_num={0}, error: {1}".format( port_num, e)) def get_tx_fault(self, port_num): try: self._check_sfp_port(port_num) result = self.cpld.sfp_get_tx_fault(port_num) if result == SFP.DETECTED: ret_val = {"tx_flt": "detected"} else: ret_val = {"tx_flt": "undetected"} return ret_val except Exception as e: self.logger.error( "get_tx_fault failed, port_num={0}, error: {1}".format( port_num, e)) def set_tx_disable(self, port_num, tx_disable): try: self._check_sfp_port(port_num) if tx_disable not in range(SFP.DISABLED + 1): raise ValueError( "tx_disable ({0}) is out of range (0-{1})".format( tx_disable, SFP.DISABLED)) self.cpld.sfp_set_tx_disable(port_num, tx_disable) except Exception as e: self.logger.error( "set_tx_disable failed, port_num={0}, tx_disable={1}, error: {2}" .format(port_num, tx_disable, e)) def get_tx_disable(self, port_num): try: self._check_sfp_port(port_num) result = self.cpld.sfp_get_tx_disable(port_num) if result == PortStatus.ENABLED: ret_val = {"tx_disable": "enabled"} else: ret_val = {"tx_disable": "disabled"} return ret_val except Exception as e: self.logger.error( "get_tx_disable failed, port_num={0}, error: {1}".format( port_num, e))