コード例 #1
0
ファイル: fpgastats.py プロジェクト: jiapei100/opae-sdk
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()
コード例 #2
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('--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()
コード例 #3
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.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', 3)
    if args.debug:
        for g in args.eth_grps:
            print('ethernet group device: {}'.format(g))
    lp = FPGAMAC(args)
    lp.start()
コード例 #4
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')
    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()
コード例 #5
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('--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()
コード例 #6
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('--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')
コード例 #7
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('--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.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', 3)
    if args.debug:
        for g in args.eth_grps:
            print('ethernet group device: {}'.format(g))

    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')