def indir_rw_data(*args): addr = ((args[1] << 17) | args[2]) << 32 rdata = 0 if len(args) == 3: # read cmd = 0x4 << 60 rw_data(args[0], 0x0, INDIRECT_CTRL_REG, cmd | addr, 0) while (rdata >> 32) != 0x1: # waiting for read valid rdata = rw_data(args[0], 0x0, INDIRECT_DATA_REG) # rdata valid return rdata & 0xffffffff elif len(args) == 5: # write cmd = 0x8 << 60 rw_data(args[0], 0x0, INDIRECT_CTRL_REG, cmd | addr | args[3], 0) while (rdata >> 32) != 0x1: # waiting for write complete rdata = rw_data(args[0], 0x0, INDIRECT_DATA_REG) # rdata valid rdata = 0 if args[4]: cmd = 0x4 << 60 rw_data(args[0], 0x0, INDIRECT_CTRL_REG, cmd | addr, 0) while (rdata >> 32) != 0x1: # waiting for read valid rdata = rw_data(args[0], 0x0, INDIRECT_DATA_REG) # rdata valid if args[3] != (rdata & 0xffffffff): print('{:#x} {:#x}'.format(args[3], rdata)) exception_quit("Error: failed comparison of wrote data", 8) else: exception_quit("Error: Bad arguments number", 7)
def read_mac_info(self): mac = 0 byte_offset = [40, 32, 24, 16, 8, 0] if self.args.mac_addr and self.args.mac_cnt: location = 'sysfs' with open(self.args.mac_addr, 'r') as f: mac_addr = f.read().strip() with open(self.args.mac_cnt, 'r') as f: cnt = f.read().strip() mac_number = int(cnt) m = mac_addr.split(':') if len(m) != 6: exception_quit('MAC address {} is invalid'.format(mac_addr)) for i, x in enumerate(byte_offset): mac |= int(m[i], 16) << x else: location = 'NVMEM' with open(self.args.nvmem, 'rb') as f: f.seek(self.args.offset, 0) for x in byte_offset: mac |= self.str2hex(f.read(1)) << x mac_number = self.str2hex(f.read(1)) print('Read {} mac addresses from {}:'.format(mac_number, location)) vendor = '{:06x}'.format(mac >> 24) for i in range(mac_number): mac_str = '{}{:06x}'.format(vendor, (mac & 0xffffff)) fmt_str = ':'.join([mac_str[x:x + 2] for x in range(0, len(mac_str), 2)]) self.mac.append(fmt_str) mac += 1 for m in self.mac: print(' {}'.format(m)) print(DIVIDE)
def clear_stats(f, info, args): global VC_INFO if args.clear: print('Clearing statistics of MACs ...') vc_mode = VC_INFO.get('mode', None) if vc_mode is None: exception_quit("FPGA is not in bypass mode", 5) offset = VC_INFO.get('demux_offset', 0x100) for w in info: _, mac_total, _, node = info[w] with open(node, 'r') as fd: for i in args.ports: if vc_mode == VC_MODE_8x10G: f.fpga_eth_reg_write(fd, 'mac', i, 0x140, 0x1) f.fpga_eth_reg_write(fd, 'mac', i, 0x1C0, 0x1) else: f.fpga_eth_reg_write(fd, 'mac', i, 0x845, 0x1) f.fpga_eth_reg_write(fd, 'mac', i, 0x945, 0x1) reg = 0x1 + i * 8 f.fpga_eth_reg_write(fd, 'eth', 0, reg, 0x0) f.fpga_eth_reg_write(fd, 'eth', 0, offset + reg, 0x0) time.sleep(0.1)
def fpga_loopback_en(self, en): with open(self.phy_group_dev, 'rw') as f: if self.speed == 10: if self.type == 'serial': for i in self.ports: self.fpga_phy_reg_set_field( f, i, FPGA_PHY_REG_RX_SERIALLPBKEN, 0, 1, en) elif self.type == 'precdr': for i in self.ports: self.fpga_phy_reg_set_field(f, i, 0x137, 7, 1, en) self.fpga_phy_reg_set_field(f, i, 0x13c, 7, 1, 0) self.fpga_phy_reg_set_field(f, i, 0x132, 4, 2, 0) self.fpga_phy_reg_set_field(f, i, 0x142, 4, 1, en) self.fpga_phy_reg_set_field(f, i, 0x11d, 0, 1, en) elif self.type == 'postcdr': for i in self.ports: self.fpga_phy_reg_set_field(f, i, 0x137, 7, 1, 0) self.fpga_phy_reg_set_field(f, i, 0x13c, 7, 1, en) self.fpga_phy_reg_set_field(f, i, 0x132, 4, 2, en) self.fpga_phy_reg_set_field(f, i, 0x142, 4, 1, 0) self.fpga_phy_reg_set_field(f, i, 0x11d, 0, 1, 0) elif self.speed == 25: for i in self.ports: self.fpga_eth_reg_set_field(f, 'mac', i, 0x313, 0, 4, en) elif self.speed == 40: for i in self.ports: v = 0xf if en else en self.fpga_eth_reg_set_field(f, 'mac', i, 0x313, 0, 4, v) else: exception_quit('unsupport speed mode {}'.format(self.speed))
def get_sbdf_upl_mapping(sbdf): global VC_INFO pci_dev_path = '/sys/bus/pci/devices/{}/resource2'.format(sbdf) addr = 0 while True: header = pci_read(pci_dev_path, addr) feature_type = (header >> DFH_TYPE_SHIFT) & DFH_TYPE_MASK feature_id = (header >> DFH_ID_SHIFT) & DFH_ID_MASK if feature_type == DFH_TYPE_AFU and feature_id == DFH_ID_UPL: uuid_l = pci_read(pci_dev_path, addr+UUID_L_OFFSET_REG) uuid_h = pci_read(pci_dev_path, addr+UUID_H_OFFSET_REG) if uuid_l == UPL_UUID_L and uuid_h == UPL_UUID_H: VC_INFO['upl_base'] = addr break else: msg = "FPGA {} has no packet generator for test".format(sbdf) exception_quit(msg, 6) if feature_type in [DFH_TYPE_AFU, DFH_TYPE_FIU]: next_afu_offset = pci_read(pci_dev_path, addr+NEXT_AFU_OFFSET_REG) next_afu_offset &= NEXT_AFU_OFFSET_MASK if next_afu_offset == 0: exception_quit("Error: UPL not found in FPGA {}".format(sbdf), 6) else: addr += next_afu_offset next_afu_offset = 0
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('--mtu', nargs='?', const='', help='maximum allowable ethernet frame length') parser.add_argument('--port', nargs='*', default='all', help='select specific port (default: %(default)s)') parser.add_argument('--direction', choices=['tx', 'rx', 'both'], default='both', help='select direction of port (default: %(default)s)') parser.add_argument('--side', choices=['line', 'host'], default='host', help='select mac on which side (default: %(default)s)') parser.add_argument('--debug', '-d', action='store_true', help='Output debug information') args, left = parser.parse_known_args() f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() if args.debug: for d in devs: s = 'bdf: {segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d) print(s) if len(devs) > 1: s = '{} FPGAs are found\nplease choose one FPGA'.format(len(devs)) exception_quit(s, 1) if not devs: sys.exit(2) args.fpga_root = devs[0].get('path') args.eth_grps = f.find_eth_group(args.fpga_root) print("args.eth_grps", args.eth_grps) if len(args.eth_grps) == 0: exception_quit("Invalid Eth group MDEV") lp = FPGAMAC(args) lp.eth_group_start()
def rw_data(*args): upl_base = VC_INFO.get('upl_base', None) if upl_base is None: exception_quit("Error: UPL not found in FPGA {}".format(args[0]), 6) pci_dev_path = '/sys/bus/pci/devices/{}/resource2'.format(args[0]) addr = upl_base | (args[1] << 12) | (args[2] << 3) if len(args) == 3: # read return pci_read(pci_dev_path, addr) elif len(args) == 5: # write pci_write(pci_dev_path, addr, args[3]) else: exception_quit("Error: Bad arguments number", 7)
def __init__(self, args): try: if args.mtu is None or args.mtu == '': self.mtu = args.mtu else: self.mtu = int(args.mtu, 0) except ValueError as e: exception_quit('invalid mtu value {}'.format(args.mtu), 4) self.side = args.side self.argport = args.port self.direction = args.direction self.eth_grps = args.eth_grps
def get_if_and_mac_list(self): pci_root = self.get_pci_common_root_path(self.args.fpga_root) ifs = os.listdir(SYSF_IF) for i in ifs: root = self.get_pci_common_root_path(os.path.join(SYSF_IF, i)) if pci_root == root: with open(os.path.join(SYSF_IF, i, 'address')) as f: self.ethif[i] = f.read().strip() if self.ethif: print('Found {} ethernet interfaces:'.format(len(self.ethif))) ethifs = sorted(self.ethif.items()) for i in ethifs: print(' {:<20} {}'.format(*i)) print(DIVIDE) else: exception_quit('No ethernet interface found!')
def clear_stats(f, info, args): global VC_INFO if args.clear: print('Clearing statistics of MACs ...') vc_mode = VC_INFO.get('mode', None) if vc_mode is None: exception_quit("FPGA is not in bypass mode", 5) offset = VC_INFO.get('demux_offset', 0x100) for w in info: _, mac_total, _ = info[w] for keys, values in args.items(): eth_group_inst = eth_group() ret = eth_group_inst.eth_group_open(int(values[0]), values[1]) if ret != 0: return None for i in args.ports: if vc_mode == VC_MODE_8x10G: eth_group_inst.eth_group_reg_write(eth_group_inst, 'mac', i, 0x140, 0x1) eth_group_inst.eth_group_reg_write(eth_group_inst, 'mac', i, 0x1C0, 0x1) else: eth_group_inst.eth_group_reg_write(eth_group_inst, 'mac', i, 0x845, 0x1) eth_group_inst.eth_group_reg_write(eth_group_inst, 'mac', i, 0x945, 0x1) reg = 0x1 + i * 8 eth_group_inst.eth_group_reg_write(eth_group_inst, 'eth', 0, reg, 0x0) eth_group_inst.eth_group_reg_write(eth_group_inst, 'eth', 0, offset + reg, 0x0) time.sleep(0.1) eth_group_inst.eth_group_close()
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('--offset', default='0', type=hexint, help='read mac address from a offset address') args, left = parser.parse_known_args() f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() for d in devs: print('bdf: {segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d)) if len(devs) > 1: exception_quit('{} FPGAs are found\nplease choose ' 'one FPGA to do mactest'.format(len(devs))) if not devs: exception_quit('no FPGA found') args.fpga_root = devs[0].get('path') nvmem_path = f.find_node(devs[0].get('path'), 'nvmem', depth=7) if not nvmem_path: nvmem_path = f.find_node(devs[0].get('path'), 'eeprom', depth=7) if not nvmem_path: exception_quit('No nvmem found at {}'.format(devs[0].get('path'))) args.nvmem = nvmem_path[0] if len(nvmem_path) > 1: print('multi nvmem found, ' 'select {} to do mactest'.format(args.nvmem)) args.eth_grps = f.find_node(devs[0].get('path'), 'eth_group*/dev', depth=3) if not args.eth_grps: exception_quit('No ethernet group found') for g in args.eth_grps: print('ethernet group device: {}'.format(g)) m = MacromCompare(args) m.start()
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('--clear', '-c', action='store_true', help='Clear statistics') parser.add_argument('--debug', '-d', action='store_true', help='Output debug information') args, left = parser.parse_known_args() f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() for d in devs: if args.debug: s = 'bdf: {segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d) print(s) if len(devs) > 1: exception_quit('{} FPGAs are found\nplease choose ' 'one FPGA'.format(len(devs))) if not devs: exception_quit('no FPGA found') args.sbdf = '{segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**devs[0]) bitstream_id_path = f.find_node(devs[0].get('path'), 'intel-fpga-fme.*/bitstream_id', depth=1) with open(bitstream_id_path[0], 'r') as fd: bitstream_id = fd.read().strip() args.build_flags = (int(bitstream_id, 16) >> 24) & 0xff args.eth_grps = f.find_node(devs[0].get('path'), 'eth_group*/dev', depth=4) if not args.eth_grps: exception_quit('No ethernet group found') for g in args.eth_grps: if args.debug: print('ethernet group device: {}'.format(g)) f = FPGASTATS(args) if args.clear: f.clear_stats() else: f.start()
def check_args(self): if isinstance(self.mtu, int) and (self.mtu < 1 or self.mtu > 65535): s = 'mtu size {} is out of range 1~65535'.format(self.mtu) exception_quit(s, 5) if self.mac_group_dev == '': exception_quit('{} side mac not found'.format(self.side), 6) if self.speed not in MTU_REG_OFFSET: exception_quit('unknown speed {}'.format(self.speed), 6)
def get_sbdf_mode_mapping(sbdf, args): global VC_INFO sysfs_path = glob.glob(os.path.join('/sys/bus/pci/devices', sbdf, 'fpga_region', 'region*', 'dfl-fme*', 'bitstream_id')) if len(sysfs_path) == 0: exception_quit("Error: bitstream_id not found", 4) with open(sysfs_path[0], 'r') as f: bitstream_id = f.read().strip() build_flags = (int(bitstream_id, 16) >> 24) & 0xff if (build_flags & 0x01) == 0x00: exception_quit("FPGA {} does not support bypass mode".format(sbdf), 5) VC_INFO['mode'] = (int(bitstream_id, 16) >> 32) & 0xf print('Mode: {}'.format(VC_MODE_NAME.get(VC_INFO['mode'], 'unknown'))) if VC_INFO['mode'] == VC_MODE_8x10G: VC_INFO['total_mac'] = 8 VC_INFO['demux_offset'] = 0x100 elif VC_INFO['mode'] == VC_MODE_2x1x25G: VC_INFO['total_mac'] = 2 VC_INFO['demux_offset'] = 0x40 elif VC_INFO['mode'] == VC_MODE_2x2x25G: VC_INFO['total_mac'] = 4 VC_INFO['demux_offset'] = 0x80 else: exception_quit("FPGA {} not support bypass mode".format(sbdf), 5) c = COMMON() args.ports = c.get_port_list(args.port, VC_INFO.get('total_mac')) sysfs_path = glob.glob(os.path.join('/sys/bus/pci/devices', sbdf, 'fpga_region', 'region*', 'dfl-fme*', 'bitstream_metadata')) if len(sysfs_path) == 0: exception_quit("Error: bitstream_id not found", 4) with open(sysfs_path[0], 'r') as f: bitstream_md = int(f.read().strip(), 16) seed = (bitstream_md >> 4) & 0xfff print("Seed: {:#x}".format(seed))
def check_args(self): type_dict = { 10: { 'line': { 'local': ['serial'], 'remote': ['precdr', 'postcdr'] }, 'host': { 'remote': ['serial'], 'local': ['precdr', 'postcdr'] } }, 25: { 'line': { 'local': ['serial'], 'remote': [] }, 'host': { 'local': [], 'remote': [] } }, 40: { 'line': { 'local': [], 'remote': [] }, 'host': { 'local': [], 'remote': ['serial'] } } } if self.speed not in type_dict: exception_quit('unknown speed {}'.format(self.speed)) support_type = type_dict[self.speed][self.side][self.direction] if not support_type: exception_quit('fpga NOT support loopback at side [{}] ' 'in the direction [{}]'.format(self.side, self.direction)) if self.type not in support_type: prompt_msg = ('fpga support loopback type {} at side [{}] ' 'in the direction [{}]'.format(support_type, self.side, self.direction)) exception_quit('{}\n{} is given!'.format(prompt_msg, self.type))
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') args, left = parser.parse_known_args() f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() for d in devs: print('bdf: {segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d)) if len(devs) > 1: exception_quit('{} FPGAs are found\nplease choose ' 'one FPGA'.format(len(devs))) if not devs: exception_quit('no FPGA found') args.eth_grps = f.find_node(devs[0].get('path'), 'eth_group*/dev', depth=3) if not args.eth_grps: exception_quit('No ethernet group found') for g in args.eth_grps: print('ethernet group device: {}'.format(g)) f = FPGASTATS(args) f.start()
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('--offset', default='0', type=hexint, help='read mac address from a offset address') parser.add_argument('--debug', '-d', action='store_true', help='Output debug information') args, left = parser.parse_known_args() f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() for d in devs: if args.debug: s = 'bdf: {segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d) print(s) if len(devs) > 1: exception_quit('{} FPGAs are found\nplease choose ' 'one FPGA to do mactest'.format(len(devs))) if not devs: exception_quit('no FPGA found') args.fpga_root = devs[0].get('path') args.bitstream_id = f.find_node(devs[0].get('path'), 'bitstream_id', depth=3) mac_addrs = glob.glob(os.path.join(devs[0].get('path'), 'intel-fpga-fme.*', 'spi-altera*', 'spi_master', 'spi*', 'spi*', 'mac_address')) args.mac_addr = None if len(mac_addrs) > 0: args.mac_addr = mac_addrs[0] mac_cnts = glob.glob(os.path.join(devs[0].get('path'), 'intel-fpga-fme.*', 'spi-altera*', 'spi_master', 'spi*', 'spi*', 'mac_count')) args.mac_cnt = None if len(mac_cnts) > 0: args.mac_cnt = mac_cnts[0] if args.mac_addr is None or args.mac_cnt is None: nvmem_path = f.find_node(devs[0].get('path'), 'nvmem', depth=7) if not nvmem_path: nvmem_path = f.find_node(devs[0].get('path'), 'eeprom', depth=7) if not nvmem_path: exception_quit('No nvmem found at {}'.format(devs[0].get('path'))) args.nvmem = None if len(nvmem_path) > 0: args.nvmem = nvmem_path[0] if len(nvmem_path) > 1 and args.debug: s = 'multi nvmem found, select {} to do mactest'.format(args.nvmem) print(s) args.eth_grps = f.find_node(devs[0].get('path'), 'eth_group*/dev', depth=4) if not args.eth_grps: exception_quit('No ethernet group found') for g in args.eth_grps: if args.debug: print('ethernet group device: {}'.format(g)) m = MacromCompare(args) m.start()
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('--number', '-n', default=DEFAULT_TEST_PKT_NUM, help='Number of the test packets to send per MAC') parser.add_argument('--length', '-s', default=DEFAULT_TEST_PKT_LEN, help='Length of each test packet') parser.add_argument('--loopback', '-l', action='store_true', help='Configure loopback automatically.' 'Loopback is not configured by default.') parser.add_argument('--clear', '-c', action='store_true', help='Clear statistics automatically.' 'Statistics are not cleared by default.') parser.add_argument('--port', '-p', nargs='*', default='all', help='Test on selected MACs') parser.add_argument('--debug', '-d', action='store_true', help='Output debug information') args, left = parser.parse_known_args() setattr(args, 'number', int(getattr(args, 'number'))) if args.number < MIN_TEST_PKT_NUM or args.number > MAX_TEST_PKT_NUM: setattr(args, 'number', DEFAULT_TEST_PKT_NUM) print(('The number of test packets is out of range ({}~{})' ', use {} instead'.format(MIN_TEST_PKT_NUM, MAX_TEST_PKT_NUM, DEFAULT_TEST_PKT_NUM))) setattr(args, 'length', int(getattr(args, 'length'))) if args.length < MIN_TEST_PKT_LEN or args.length > MAX_TEST_PKT_LEN: setattr(args, 'length', DEFAULT_TEST_PKT_LEN) print(('The length of test packet is out of range ({}~{})' ', use {} instead'.format(MIN_TEST_PKT_LEN, MAX_TEST_PKT_LEN, DEFAULT_TEST_PKT_LEN))) f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() for d in devs: sbdf = '{segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d) print('DUT: {}'.format(sbdf)) if len(devs) > 1: exception_quit('{} FPGAs are found\n' 'please choose one FPGA'.format(len(devs)), 1) if not devs: exception_quit('no FPGA found', 2) args.fpga_root = devs[0].get('path') args.eth_grps = f.find_eth_group(args.fpga_root) print("args.eth_grps", args.eth_grps) if len(args.eth_grps) == 0: exception_quit("Invalid Eth group MDEV") get_sbdf_mode_mapping(sbdf, args) lock_file = '/tmp/DUT{}'.format(sbdf) if os.path.exists(lock_file): exception_quit("FPGA {} is already in test".format(sbdf), 0) try: with open(lock_file, 'w') as fd: fd.write(sbdf) enable_loopback(args) fvl_bypass_mode_test(sbdf, args) finally: disable_loopback(args) if os.path.exists(lock_file): os.remove(lock_file) print('Done')
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('mode', choices=['no', 'kr', 'rs'], nargs='?', default=None, help='Choose fec mode to configure') parser.add_argument('--rsu', '-r', action='store_true', help='Reboot card') parser.add_argument('--debug', '-d', action='store_true', help='Output debug information') args, left = parser.parse_known_args() f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() for d in devs: sbdf = '{segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d) if len(devs) > 1: exception_quit( '{} FPGAs are found\n' 'please choose one FPGA'.format(len(devs)), 1) if not devs: exception_quit('no FPGA found', 2) if args.mode is None: if args.rsu: bdf = do_rsu(sbdf, args.debug) if bdf is None: ret = 1 else: ret = 0 else: ret = show_fec_mode(sbdf) sys.exit(ret) if fec_is_fixed(sbdf, args.debug): print('fec mode is not configurable in card {}'.format(sbdf)) sys.exit(2) with open(CONF_FILE, 'w') as f: option_line = OPTION_LINE + '"{}"'.format(args.mode) if args.debug: print("write '{}' to file {}".format(option_line, CONF_FILE)) f.write(option_line + '\n') ret = reload_driver(args.mode, args.debug) if ret == 0: bdf = do_rsu(sbdf, args.debug) if bdf is not None: if args.debug and bdf != sbdf: print("BDF of FPGA changed to {}".format(bdf)) ret = check_fec_mode(bdf, args.mode, args.debug) else: ret = 1 if ret == 0: print("done") else: print("please power cycle system or reboot card to make the fec mode " "effective") sys.exit(ret)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('--direction', required=True, choices=['local', 'remote'], help='choose loopback direction from chip view') parser.add_argument('--enable', action='store_const', dest='en', const=1, help='loopback enable') parser.add_argument('--disable', action='store_const', dest='en', const=0, help='loopback disable') parser.add_argument('--type', choices=['serial', 'precdr', 'postcdr'], help='choose loopback type') parser.add_argument('--port', nargs='*', default='all', help='enable/disable loopback on specific port') parser.add_argument('--side', required=True, choices=['line', 'host'], help='choose loopback on which side') args, left = parser.parse_known_args() if args.en is None: exception_quit('please specify --enable/--disable loopback!') else: op = 'enable' if args.en else 'disable' print('{} fpga loopback'.format(op)) if not args.type: if ((args.side == 'line' and args.direction == 'local') or (args.side == 'host' and args.direction == 'remote')): args.type = 'serial' else: exception_quit( 'missing argument --type [serial | precdr | postcdr]') f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() for d in devs: print('bdf: {segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d)) if len(devs) > 1: exception_quit('{} FPGAs are found\nplease choose ' 'one FPGA'.format(len(devs))) if not devs: exception_quit('no FPGA found') args.eth_grps = f.find_node(devs[0].get('path'), 'eth_group*/dev', depth=3) if not args.eth_grps: exception_quit('No ethernet group found') for g in args.eth_grps: print('ethernet group device: {}'.format(g)) lp = FPGALPBK(args) lp.start() print('Done')