def setFEC(self, enable): """ set FEC configuration """ # get back data first data = self.mdio.cfp_adaptor_read(DEVICE_1, FEC_CONTROL) # only set the configuration if it has changed value = (data | bit(3)) if enable else (data & invert(bit(3))) self.mdio.cfp_adaptor_write(DEVICE_1, FEC_CONTROL, value) time.sleep(0.5) return ""
def setAN(self, enable): """ set AN configuration """ # select lane 0 self.mdio.cfp_adaptor_write(DEVICE_7, SLICE_REGISTER, 0x3b80) # set lane0 for AN DME self.mdio.cfp_adaptor_write(DEVICE_1, LOGIC_TO_PHY_LANE0_MAP, 0x203) if enable: # AN Adv3 bit14=1 FEC Ability self.mdio.cfp_adaptor_write(DEVICE_7, AN_ADVERTISEMENT_3, 0x4000) # AN Adv2 bit13=1 100G-CR4 self.mdio.cfp_adaptor_write(DEVICE_7, AN_ADVERTISEMENT_2, 0x2000) # AN Adv1 self.mdio.cfp_adaptor_write(DEVICE_7, AN_ADVERTISEMENT_1, 0x1) # Enable/Restart AN process self.mdio.cfp_adaptor_write(DEVICE_7, AN_CONTROL, 0x1200) # PHY= Front Panel self.mdio.cfp_adaptor_write(DEVICE_1, FRONT_PANEL, 0x1) # trigger FW changes self.mdio.cfp_adaptor_write(DEVICE_1, AN_TRIGGER, 0x1) data = 0xffff read_count = 0 while (data & bit(0) != 0x0) and read_count < MAX_FW_READ_COUNT: data = self.mdio.cfp_adaptor_read(DEVICE_1, AN_TRIGGER) read_count += 1 time.sleep(1) else: # reset and disable AN self.mdio.cfp_adaptor_write(DEVICE_7, AN_CONTROL, 0x8000) # trigger changes self.mdio.cfp_adaptor_write(DEVICE_1, AN_TRIGGER, 0x1) while (data & bit(0) != 0x0) and read_count < MAX_FW_READ_COUNT: data = self.mdio.cfp_adaptor_read(DEVICE_1, AN_TRIGGER) read_count += 1 time.sleep(0.01) # disable AN self.mdio.cfp_adaptor_write(DEVICE_7, AN_CONTROL, 0x0) # trigger changes self.mdio.cfp_adaptor_write(DEVICE_1, AN_TRIGGER, 0x1) while (data & bit(0) != 0x0) and read_count < MAX_FW_READ_COUNT: data = self.mdio.cfp_adaptor_read(DEVICE_1, AN_TRIGGER) read_count += 1 time.sleep(0.2) return ""
def wait_done(self): """ Wait for the ready bit """ doneBit = bit(31) for attempt in xrange(10): time.sleep(0.01) data = self.spam.read(self.cmd_reg) if data & doneBit: return # if the done bit does not get set raise an Exception print "MDIO Failure"
""" port module for proteus """ import portColossus import time from pci import Pci from Mdio import Mdio from I2c import I2c from l1constants import bit, invert GEARBOX_PORT_ADDR = 0x7 DEVICE_1 = 0x1 DEVICE_7 = 0x7 MODE_CONTROL_0 = 0xa101 FEC_ENABLE = bit(13) SLICE_REGISTER = 0x8000 class Proteus(Pci): """ port class implementation """ def __init__(self, bar, port): Pci.__init__(self, '174a:0a0f', bar, port) class MdioAccess(portColossus.MdioAccess): """ Proteus Mdio implementation """ def __init__(self, port, bar=0): self.mdio = Mdio(port, bar, portColossus.MDIO_CMD_REG, portColossus.MDIO_DATA_REG)
Port Colossus Module """ import time from pci import Pci from Mdio import Mdio from I2c import I2c from l1constants import bit, invert # Bar 0 Registers MDIO_CMD_REG = 0x0078 MDIO_DATA_REG = 0x007c I2C_CMD_REG = 0x0044 # Bar 1 Registers FRAMER_PCS_PMA = 0x204 LOCAL_FAULT = bit(0) REMOTE_FAULT = bit(1) RX_GTH_RESET = bit(11) RX_CORE_RESET = bit(12) STICKY_REGISTER = 0x208 HSEC_ERROR = bit(2) # MDIO and I2C Constants CFP_PORT_ADDR = 0x1 GEARBOX_PORT_ADDR = 0x0 CFP_ADAPTOR_PORT_ADDR = 0xe DEVICE_1 = 0x1 DEVICE_7 = 0x7 FEC_CONTROL = 0x8a05 GEARBOX_LOOPBACK = 0xf457 GEARBOX_COMMON_CTRL1 = 0xf402
""" I2c base module """ import time import getHwHandle from l1constants import bit i2cDoneBit = bit(31) i2cErrorBit = bit(29) i2cDoneMask = i2cDoneBit | i2cErrorBit READ_WRITE_BIT = bit(30) class I2c(): """ I2c base class implementation """ def __init__(self, port, bar, cmd_reg): """ Initialization of I2c class """ self.port = port if bar: self.spam = getHwHandle.getBar1Handle(self.port) else: self.spam = getHwHandle.getBar0Handle(self.port) self.cmd_reg = cmd_reg def buildReadCmd(self, devAddr, regAddr, busSel): """ helper function to build i2c read cmd """
""" Mdio Base module """ import time import getHwHandle from l1constants import bit READ_WRITE_BIT = bit(30) PORT_ADDR_MASK = 0x1f PORT_ADDR_SHIFT = 21 DEV_ADDR_MASK = 0x1f DEV_ADDR_SHIFT = 16 REG_ADDR_MASK = 0xffff DATA_MASK = 0x1ffff mdioDoneBit = bit(31) mdioWriteBit = bit(16) class Mdio(): """ Mdio base class implementation """ def __init__(self, port, bar, cmd_reg, data_reg): """ initialization of MDIO class """ self.port = port if bar: self.spam = getHwHandle.getBar1Handle(self.port) else: self.spam = getHwHandle.getBar0Handle(self.port)