Exemplo n.º 1
0
def bench():

    # Parameters
    AXIS_PCIE_DATA_WIDTH = 512
    AXIS_PCIE_KEEP_WIDTH = (AXIS_PCIE_DATA_WIDTH/32)
    AXIS_PCIE_RC_USER_WIDTH = 161
    AXIS_PCIE_RQ_USER_WIDTH = 137
    AXIS_PCIE_CQ_USER_WIDTH = 183
    AXIS_PCIE_CC_USER_WIDTH = 81
    RQ_SEQ_NUM_WIDTH = 6
    BAR0_APERTURE = 24
    AXIS_ETH_DATA_WIDTH = 512
    AXIS_ETH_KEEP_WIDTH = AXIS_ETH_DATA_WIDTH/8

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    clk_250mhz = Signal(bool(0))
    rst_250mhz = Signal(bool(0))
    user_sw = Signal(intbv(0)[2:])
    m_axis_rq_tready = Signal(bool(0))
    s_axis_rc_tdata = Signal(intbv(0)[AXIS_PCIE_DATA_WIDTH:])
    s_axis_rc_tkeep = Signal(intbv(0)[AXIS_PCIE_KEEP_WIDTH:])
    s_axis_rc_tlast = Signal(bool(0))
    s_axis_rc_tuser = Signal(intbv(0)[AXIS_PCIE_RC_USER_WIDTH:])
    s_axis_rc_tvalid = Signal(bool(0))
    s_axis_cq_tdata = Signal(intbv(0)[AXIS_PCIE_DATA_WIDTH:])
    s_axis_cq_tkeep = Signal(intbv(0)[AXIS_PCIE_KEEP_WIDTH:])
    s_axis_cq_tlast = Signal(bool(0))
    s_axis_cq_tuser = Signal(intbv(0)[AXIS_PCIE_CQ_USER_WIDTH:])
    s_axis_cq_tvalid = Signal(bool(0))
    m_axis_cc_tready = Signal(bool(0))
    s_axis_rq_seq_num_0 = Signal(intbv(0)[RQ_SEQ_NUM_WIDTH:])
    s_axis_rq_seq_num_valid_0 = Signal(bool(0))
    s_axis_rq_seq_num_1 = Signal(intbv(0)[RQ_SEQ_NUM_WIDTH:])
    s_axis_rq_seq_num_valid_1 = Signal(bool(0))
    pcie_tfc_nph_av = Signal(intbv(15)[4:])
    pcie_tfc_npd_av = Signal(intbv(15)[4:])
    cfg_max_payload = Signal(intbv(0)[2:])
    cfg_max_read_req = Signal(intbv(0)[3:])
    cfg_mgmt_read_data = Signal(intbv(0)[32:])
    cfg_mgmt_read_write_done = Signal(bool(0))
    cfg_fc_ph = Signal(intbv(0)[8:])
    cfg_fc_pd = Signal(intbv(0)[12:])
    cfg_fc_nph = Signal(intbv(0)[8:])
    cfg_fc_npd = Signal(intbv(0)[12:])
    cfg_fc_cplh = Signal(intbv(0)[8:])
    cfg_fc_cpld = Signal(intbv(0)[12:])
    cfg_interrupt_msi_enable = Signal(intbv(0)[4:])
    cfg_interrupt_msi_mmenable = Signal(intbv(0)[12:])
    cfg_interrupt_msi_mask_update = Signal(bool(0))
    cfg_interrupt_msi_data = Signal(intbv(0)[32:])
    cfg_interrupt_msi_sent = Signal(bool(0))
    cfg_interrupt_msi_fail = Signal(bool(0))
    qsfp_0_tx_clk = Signal(bool(0))
    qsfp_0_tx_rst = Signal(bool(0))
    qsfp_0_rx_clk = Signal(bool(0))
    qsfp_0_rx_rst = Signal(bool(0))
    qsfp_0_tx_axis_tready = Signal(bool(0))
    qsfp_0_rx_axis_tdata = Signal(intbv(0)[AXIS_ETH_DATA_WIDTH:])
    qsfp_0_rx_axis_tkeep = Signal(intbv(0)[AXIS_ETH_KEEP_WIDTH:])
    qsfp_0_rx_axis_tvalid = Signal(bool(0))
    qsfp_0_rx_axis_tlast = Signal(bool(0))
    qsfp_0_rx_axis_tuser = Signal(bool(0))
    qsfp_0_modprs_l = Signal(bool(0))
    qsfp_1_tx_clk = Signal(bool(0))
    qsfp_1_tx_rst = Signal(bool(0))
    qsfp_1_rx_clk = Signal(bool(0))
    qsfp_1_rx_rst = Signal(bool(0))
    qsfp_1_tx_axis_tready = Signal(bool(0))
    qsfp_1_rx_axis_tdata = Signal(intbv(0)[AXIS_ETH_DATA_WIDTH:])
    qsfp_1_rx_axis_tkeep = Signal(intbv(0)[AXIS_ETH_KEEP_WIDTH:])
    qsfp_1_rx_axis_tvalid = Signal(bool(0))
    qsfp_1_rx_axis_tlast = Signal(bool(0))
    qsfp_1_rx_axis_tuser = Signal(bool(0))
    qsfp_1_modprs_l = Signal(bool(0))
    qsfp_int_l = Signal(bool(0))
    qsfp_i2c_scl_i = Signal(bool(1))
    qsfp_i2c_sda_i = Signal(bool(1))
    eeprom_i2c_scl_i = Signal(bool(1))
    eeprom_i2c_sda_i = Signal(bool(1))
    qspi_0_dq_i = Signal(intbv(0)[4:])
    qspi_1_dq_i = Signal(intbv(0)[4:])

    # Outputs
    user_led_g = Signal(intbv(0)[2:])
    user_led_r = Signal(bool(0))
    front_led = Signal(intbv(0)[2:])
    m_axis_rq_tdata = Signal(intbv(0)[AXIS_PCIE_DATA_WIDTH:])
    m_axis_rq_tkeep = Signal(intbv(0)[AXIS_PCIE_KEEP_WIDTH:])
    m_axis_rq_tlast = Signal(bool(0))
    m_axis_rq_tuser = Signal(intbv(0)[AXIS_PCIE_RQ_USER_WIDTH:])
    m_axis_rq_tvalid = Signal(bool(0))
    s_axis_rc_tready = Signal(bool(0))
    s_axis_cq_tready = Signal(bool(0))
    m_axis_cc_tdata = Signal(intbv(0)[AXIS_PCIE_DATA_WIDTH:])
    m_axis_cc_tkeep = Signal(intbv(0)[AXIS_PCIE_KEEP_WIDTH:])
    m_axis_cc_tlast = Signal(bool(0))
    m_axis_cc_tuser = Signal(intbv(0)[AXIS_PCIE_CC_USER_WIDTH:])
    m_axis_cc_tvalid = Signal(bool(0))
    status_error_cor = Signal(bool(0))
    status_error_uncor = Signal(bool(0))
    cfg_mgmt_addr = Signal(intbv(0)[10:])
    cfg_mgmt_function_number = Signal(intbv(0)[8:])
    cfg_mgmt_write = Signal(bool(0))
    cfg_mgmt_write_data = Signal(intbv(0)[32:])
    cfg_mgmt_byte_enable = Signal(intbv(0)[4:])
    cfg_mgmt_read = Signal(bool(0))
    cfg_fc_sel = Signal(intbv(4)[3:])
    cfg_interrupt_msi_int = Signal(intbv(0)[32:])
    cfg_interrupt_msi_pending_status = Signal(intbv(0)[32:])
    cfg_interrupt_msi_select = Signal(intbv(0)[2:])
    cfg_interrupt_msi_pending_status_function_num = Signal(intbv(0)[2:])
    cfg_interrupt_msi_pending_status_data_enable = Signal(bool(0))
    cfg_interrupt_msi_attr = Signal(intbv(0)[3:])
    cfg_interrupt_msi_tph_present = Signal(bool(0))
    cfg_interrupt_msi_tph_type = Signal(intbv(0)[2:])
    cfg_interrupt_msi_tph_st_tag = Signal(intbv(0)[8:])
    cfg_interrupt_msi_function_number = Signal(intbv(0)[8:])
    qsfp_0_tx_axis_tdata = Signal(intbv(0)[AXIS_ETH_DATA_WIDTH:])
    qsfp_0_tx_axis_tkeep = Signal(intbv(0)[AXIS_ETH_KEEP_WIDTH:])
    qsfp_0_tx_axis_tvalid = Signal(bool(0))
    qsfp_0_tx_axis_tlast = Signal(bool(0))
    qsfp_0_tx_axis_tuser = Signal(bool(0))
    qsfp_0_sel_l = Signal(bool(1))
    qsfp_1_tx_axis_tdata = Signal(intbv(0)[AXIS_ETH_DATA_WIDTH:])
    qsfp_1_tx_axis_tkeep = Signal(intbv(0)[AXIS_ETH_KEEP_WIDTH:])
    qsfp_1_tx_axis_tvalid = Signal(bool(0))
    qsfp_1_tx_axis_tlast = Signal(bool(0))
    qsfp_1_tx_axis_tuser = Signal(bool(0))
    qsfp_1_sel_l = Signal(bool(1))
    qsfp_reset_l = Signal(bool(1))
    qsfp_i2c_scl_o = Signal(bool(1))
    qsfp_i2c_scl_t = Signal(bool(1))
    qsfp_i2c_sda_o = Signal(bool(1))
    qsfp_i2c_sda_t = Signal(bool(1))
    eeprom_i2c_scl_o = Signal(bool(1))
    eeprom_i2c_scl_t = Signal(bool(1))
    eeprom_i2c_sda_o = Signal(bool(1))
    eeprom_i2c_sda_t = Signal(bool(1))
    eeprom_wp = Signal(bool(1))
    fpga_boot = Signal(bool(0))
    qspi_clk = Signal(bool(0))
    qspi_0_dq_o = Signal(intbv(0)[4:])
    qspi_0_dq_oe = Signal(intbv(0)[4:])
    qspi_0_cs = Signal(bool(1))
    qspi_1_dq_o = Signal(intbv(0)[4:])
    qspi_1_dq_oe = Signal(intbv(0)[4:])
    qspi_1_cs = Signal(bool(1))

    # sources and sinks
    qsfp_0_source = axis_ep.AXIStreamSource()
    qsfp_0_source_pause = Signal(bool(False))

    qsfp_0_source_logic = qsfp_0_source.create_logic(
        qsfp_0_rx_clk,
        qsfp_0_rx_rst,
        tdata=qsfp_0_rx_axis_tdata,
        tkeep=qsfp_0_rx_axis_tkeep,
        tvalid=qsfp_0_rx_axis_tvalid,
        tlast=qsfp_0_rx_axis_tlast,
        tuser=qsfp_0_rx_axis_tuser,
        pause=qsfp_0_source_pause,
        name='qsfp_0_source'
    )

    qsfp_0_sink = axis_ep.AXIStreamSink()
    qsfp_0_sink_pause = Signal(bool(False))

    qsfp_0_sink_logic = qsfp_0_sink.create_logic(
        qsfp_0_tx_clk,
        qsfp_0_tx_rst,
        tdata=qsfp_0_tx_axis_tdata,
        tkeep=qsfp_0_tx_axis_tkeep,
        tvalid=qsfp_0_tx_axis_tvalid,
        tready=qsfp_0_tx_axis_tready,
        tlast=qsfp_0_tx_axis_tlast,
        tuser=qsfp_0_tx_axis_tuser,
        pause=qsfp_0_sink_pause,
        name='qsfp_0_sink'
    )

    qsfp_1_source = axis_ep.AXIStreamSource()
    qsfp_1_source_pause = Signal(bool(False))

    qsfp_1_source_logic = qsfp_1_source.create_logic(
        qsfp_1_rx_clk,
        qsfp_1_rx_rst,
        tdata=qsfp_1_rx_axis_tdata,
        tkeep=qsfp_1_rx_axis_tkeep,
        tvalid=qsfp_1_rx_axis_tvalid,
        tlast=qsfp_1_rx_axis_tlast,
        tuser=qsfp_1_rx_axis_tuser,
        pause=qsfp_1_source_pause,
        name='qsfp_1_source'
    )

    qsfp_1_sink = axis_ep.AXIStreamSink()
    qsfp_1_sink_pause = Signal(bool(False))

    qsfp_1_sink_logic = qsfp_1_sink.create_logic(
        qsfp_1_tx_clk,
        qsfp_1_tx_rst,
        tdata=qsfp_1_tx_axis_tdata,
        tkeep=qsfp_1_tx_axis_tkeep,
        tvalid=qsfp_1_tx_axis_tvalid,
        tready=qsfp_1_tx_axis_tready,
        tlast=qsfp_1_tx_axis_tlast,
        tuser=qsfp_1_tx_axis_tuser,
        pause=qsfp_1_sink_pause,
        name='qsfp_1_sink'
    )

    # Clock and Reset Interface
    user_clk=Signal(bool(0))
    user_reset=Signal(bool(0))
    sys_clk=Signal(bool(0))
    sys_reset=Signal(bool(0))

    # PCIe devices
    rc = pcie.RootComplex()

    rc.max_payload_size = 0x1 # 256 bytes
    rc.max_read_request_size = 0x5 # 4096 bytes

    driver = mqnic.Driver(rc)

    dev = pcie_usp.UltrascalePlusPCIe()

    dev.pcie_generation = 3
    dev.pcie_link_width = 16
    dev.user_clk_frequency = 250e6

    dev.functions[0].msi_multiple_message_capable = 5

    dev.functions[0].configure_bar(0, 2**BAR0_APERTURE, ext=True, prefetch=True)

    rc.make_port().connect(dev)

    cq_pause = Signal(bool(0))
    cc_pause = Signal(bool(0))
    rq_pause = Signal(bool(0))
    rc_pause = Signal(bool(0))

    pcie_logic = dev.create_logic(
        # Completer reQuest Interface
        m_axis_cq_tdata=s_axis_cq_tdata,
        m_axis_cq_tuser=s_axis_cq_tuser,
        m_axis_cq_tlast=s_axis_cq_tlast,
        m_axis_cq_tkeep=s_axis_cq_tkeep,
        m_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cq_tready=s_axis_cq_tready,
        #pcie_cq_np_req=pcie_cq_np_req,
        pcie_cq_np_req=Signal(intbv(3)[2:]),
        #pcie_cq_np_req_count=pcie_cq_np_req_count,

        # Completer Completion Interface
        s_axis_cc_tdata=m_axis_cc_tdata,
        s_axis_cc_tuser=m_axis_cc_tuser,
        s_axis_cc_tlast=m_axis_cc_tlast,
        s_axis_cc_tkeep=m_axis_cc_tkeep,
        s_axis_cc_tvalid=m_axis_cc_tvalid,
        s_axis_cc_tready=m_axis_cc_tready,

        # Requester reQuest Interface
        s_axis_rq_tdata=m_axis_rq_tdata,
        s_axis_rq_tuser=m_axis_rq_tuser,
        s_axis_rq_tlast=m_axis_rq_tlast,
        s_axis_rq_tkeep=m_axis_rq_tkeep,
        s_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rq_tready=m_axis_rq_tready,
        pcie_rq_seq_num0=s_axis_rq_seq_num_0,
        pcie_rq_seq_num_vld0=s_axis_rq_seq_num_valid_0,
        pcie_rq_seq_num1=s_axis_rq_seq_num_1,
        pcie_rq_seq_num_vld1=s_axis_rq_seq_num_valid_1,
        #pcie_rq_tag0=pcie_rq_tag0,
        #pcie_rq_tag1=pcie_rq_tag1,
        #pcie_rq_tag_av=pcie_rq_tag_av,
        #pcie_rq_tag_vld0=pcie_rq_tag_vld0,
        #pcie_rq_tag_vld1=pcie_rq_tag_vld1,

        # Requester Completion Interface
        m_axis_rc_tdata=s_axis_rc_tdata,
        m_axis_rc_tuser=s_axis_rc_tuser,
        m_axis_rc_tlast=s_axis_rc_tlast,
        m_axis_rc_tkeep=s_axis_rc_tkeep,
        m_axis_rc_tvalid=s_axis_rc_tvalid,
        m_axis_rc_tready=s_axis_rc_tready,

        # Transmit Flow Control Interface
        #pcie_tfc_nph_av=pcie_tfc_nph_av,
        #pcie_tfc_npd_av=pcie_tfc_npd_av,

        # Configuration Management Interface
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_function_number=cfg_mgmt_function_number,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        #cfg_mgmt_debug_access=cfg_mgmt_debug_access,

        # Configuration Status Interface
        #cfg_phy_link_down=cfg_phy_link_down,
        #cfg_phy_link_status=cfg_phy_link_status,
        #cfg_negotiated_width=cfg_negotiated_width,
        #cfg_current_speed=cfg_current_speed,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        #cfg_function_status=cfg_function_status,
        #cfg_vf_status=cfg_vf_status,
        #cfg_function_power_state=cfg_function_power_state,
        #cfg_vf_power_state=cfg_vf_power_state,
        #cfg_link_power_state=cfg_link_power_state,
        #cfg_err_cor_out=cfg_err_cor_out,
        #cfg_err_nonfatal_out=cfg_err_nonfatal_out,
        #cfg_err_fatal_out=cfg_err_fatal_out,
        #cfg_local_err_out=cfg_local_err_out,
        #cfg_local_err_valid=cfg_local_err_valid,
        #cfg_rx_pm_state=cfg_rx_pm_state,
        #cfg_tx_pm_state=cfg_tx_pm_state,
        #cfg_ltssm_state=cfg_ltssm_state,
        #cfg_rcb_status=cfg_rcb_status,
        #cfg_obff_enable=cfg_obff_enable,
        #cfg_pl_status_change=cfg_pl_status_change,
        #cfg_tph_requester_enable=cfg_tph_requester_enable,
        #cfg_tph_st_mode=cfg_tph_st_mode,
        #cfg_vf_tph_requester_enable=cfg_vf_tph_requester_enable,
        #cfg_vf_tph_st_mode=cfg_vf_tph_st_mode,

        # Configuration Received Message Interface
        #cfg_msg_received=cfg_msg_received,
        #cfg_msg_received_data=cfg_msg_received_data,
        #cfg_msg_received_type=cfg_msg_received_type,

        # Configuration Transmit Message Interface
        #cfg_msg_transmit=cfg_msg_transmit,
        #cfg_msg_transmit_type=cfg_msg_transmit_type,
        #cfg_msg_transmit_data=cfg_msg_transmit_data,
        #cfg_msg_transmit_done=cfg_msg_transmit_done,

        # Configuration Flow Control Interface
        cfg_fc_ph=cfg_fc_ph,
        cfg_fc_pd=cfg_fc_pd,
        cfg_fc_nph=cfg_fc_nph,
        cfg_fc_npd=cfg_fc_npd,
        cfg_fc_cplh=cfg_fc_cplh,
        cfg_fc_cpld=cfg_fc_cpld,
        cfg_fc_sel=cfg_fc_sel,

        # Configuration Control Interface
        #cfg_hot_reset_in=cfg_hot_reset_in,
        #cfg_hot_reset_out=cfg_hot_reset_out,
        #cfg_config_space_enable=cfg_config_space_enable,
        #cfg_dsn=cfg_dsn,
        #cfg_ds_port_number=cfg_ds_port_number,
        #cfg_ds_bus_number=cfg_ds_bus_number,
        #cfg_ds_device_number=cfg_ds_device_number,
        #cfg_ds_function_number=cfg_ds_function_number,
        #cfg_power_state_change_ack=cfg_power_state_change_ack,
        #cfg_power_state_change_interrupt=cfg_power_state_change_interrupt,
        cfg_err_cor_in=status_error_cor,
        cfg_err_uncor_in=status_error_uncor,
        #cfg_flr_done=cfg_flr_done,
        #cfg_vf_flr_done=cfg_vf_flr_done,
        #cfg_flr_in_process=cfg_flr_in_process,
        #cfg_vf_flr_in_process=cfg_vf_flr_in_process,
        #cfg_req_pm_transition_l23_ready=cfg_req_pm_transition_l23_ready,
        #cfg_link_training_enable=cfg_link_training_enable,

        # Configuration Interrupt Controller Interface
        #cfg_interrupt_int=cfg_interrupt_int,
        #cfg_interrupt_sent=cfg_interrupt_sent,
        #cfg_interrupt_pending=cfg_interrupt_pending,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_pending_status_data_enable=cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_pending_status_function_num=cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        #cfg_interrupt_msix_enable=cfg_interrupt_msix_enable,
        #cfg_interrupt_msix_mask=cfg_interrupt_msix_mask,
        #cfg_interrupt_msix_vf_enable=cfg_interrupt_msix_vf_enable,
        #cfg_interrupt_msix_vf_mask=cfg_interrupt_msix_vf_mask,
        #cfg_interrupt_msix_address=cfg_interrupt_msix_address,
        #cfg_interrupt_msix_data=cfg_interrupt_msix_data,
        #cfg_interrupt_msix_int=cfg_interrupt_msix_int,
        #cfg_interrupt_msix_vec_pending=cfg_interrupt_msix_vec_pending,
        #cfg_interrupt_msix_vec_pending_status=cfg_interrupt_msix_vec_pending_status,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,

        # Configuration Extend Interface
        #cfg_ext_read_received=cfg_ext_read_received,
        #cfg_ext_write_received=cfg_ext_write_received,
        #cfg_ext_register_number=cfg_ext_register_number,
        #cfg_ext_function_number=cfg_ext_function_number,
        #cfg_ext_write_data=cfg_ext_write_data,
        #cfg_ext_write_byte_enable=cfg_ext_write_byte_enable,
        #cfg_ext_read_data=cfg_ext_read_data,
        #cfg_ext_read_data_valid=cfg_ext_read_data_valid,

        # Clock and Reset Interface
        user_clk=user_clk,
        user_reset=user_reset,
        sys_clk=sys_clk,
        sys_clk_gt=sys_clk,
        sys_reset=sys_reset,
        #phy_rdy_out=phy_rdy_out,

        cq_pause=cq_pause,
        cc_pause=cc_pause,
        rq_pause=rq_pause,
        rc_pause=rc_pause
    )

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation(
        "vvp -m myhdl %s.vvp -lxt2" % testbench,
        clk=clk,
        rst=rst,
        current_test=current_test,
        clk_250mhz=user_clk,
        rst_250mhz=user_reset,
        user_led_g=user_led_g,
        user_led_r=user_led_r,
        front_led=front_led,
        user_sw=user_sw,
        m_axis_rq_tdata=m_axis_rq_tdata,
        m_axis_rq_tkeep=m_axis_rq_tkeep,
        m_axis_rq_tlast=m_axis_rq_tlast,
        m_axis_rq_tready=m_axis_rq_tready,
        m_axis_rq_tuser=m_axis_rq_tuser,
        m_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rc_tdata=s_axis_rc_tdata,
        s_axis_rc_tkeep=s_axis_rc_tkeep,
        s_axis_rc_tlast=s_axis_rc_tlast,
        s_axis_rc_tready=s_axis_rc_tready,
        s_axis_rc_tuser=s_axis_rc_tuser,
        s_axis_rc_tvalid=s_axis_rc_tvalid,
        s_axis_cq_tdata=s_axis_cq_tdata,
        s_axis_cq_tkeep=s_axis_cq_tkeep,
        s_axis_cq_tlast=s_axis_cq_tlast,
        s_axis_cq_tready=s_axis_cq_tready,
        s_axis_cq_tuser=s_axis_cq_tuser,
        s_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cc_tdata=m_axis_cc_tdata,
        m_axis_cc_tkeep=m_axis_cc_tkeep,
        m_axis_cc_tlast=m_axis_cc_tlast,
        m_axis_cc_tready=m_axis_cc_tready,
        m_axis_cc_tuser=m_axis_cc_tuser,
        m_axis_cc_tvalid=m_axis_cc_tvalid,
        s_axis_rq_seq_num_0=s_axis_rq_seq_num_0,
        s_axis_rq_seq_num_valid_0=s_axis_rq_seq_num_valid_0,
        s_axis_rq_seq_num_1=s_axis_rq_seq_num_1,
        s_axis_rq_seq_num_valid_1=s_axis_rq_seq_num_valid_1,
        pcie_tfc_nph_av=pcie_tfc_nph_av,
        pcie_tfc_npd_av=pcie_tfc_npd_av,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_function_number=cfg_mgmt_function_number,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        cfg_fc_ph=cfg_fc_ph,
        cfg_fc_pd=cfg_fc_pd,
        cfg_fc_nph=cfg_fc_nph,
        cfg_fc_npd=cfg_fc_npd,
        cfg_fc_cplh=cfg_fc_cplh,
        cfg_fc_cpld=cfg_fc_cpld,
        cfg_fc_sel=cfg_fc_sel,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_pending_status_function_num=cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_pending_status_data_enable=cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,
        status_error_cor=status_error_cor,
        status_error_uncor=status_error_uncor,
        qsfp_0_tx_clk=qsfp_0_tx_clk,
        qsfp_0_tx_rst=qsfp_0_tx_rst,
        qsfp_0_tx_axis_tdata=qsfp_0_tx_axis_tdata,
        qsfp_0_tx_axis_tkeep=qsfp_0_tx_axis_tkeep,
        qsfp_0_tx_axis_tvalid=qsfp_0_tx_axis_tvalid,
        qsfp_0_tx_axis_tready=qsfp_0_tx_axis_tready,
        qsfp_0_tx_axis_tlast=qsfp_0_tx_axis_tlast,
        qsfp_0_tx_axis_tuser=qsfp_0_tx_axis_tuser,
        qsfp_0_rx_clk=qsfp_0_rx_clk,
        qsfp_0_rx_rst=qsfp_0_rx_rst,
        qsfp_0_rx_axis_tdata=qsfp_0_rx_axis_tdata,
        qsfp_0_rx_axis_tkeep=qsfp_0_rx_axis_tkeep,
        qsfp_0_rx_axis_tvalid=qsfp_0_rx_axis_tvalid,
        qsfp_0_rx_axis_tlast=qsfp_0_rx_axis_tlast,
        qsfp_0_rx_axis_tuser=qsfp_0_rx_axis_tuser,
        qsfp_0_modprs_l=qsfp_0_modprs_l,
        qsfp_0_sel_l=qsfp_0_sel_l,
        qsfp_1_tx_clk=qsfp_1_tx_clk,
        qsfp_1_tx_rst=qsfp_1_tx_rst,
        qsfp_1_tx_axis_tdata=qsfp_1_tx_axis_tdata,
        qsfp_1_tx_axis_tkeep=qsfp_1_tx_axis_tkeep,
        qsfp_1_tx_axis_tvalid=qsfp_1_tx_axis_tvalid,
        qsfp_1_tx_axis_tready=qsfp_1_tx_axis_tready,
        qsfp_1_tx_axis_tlast=qsfp_1_tx_axis_tlast,
        qsfp_1_tx_axis_tuser=qsfp_1_tx_axis_tuser,
        qsfp_1_rx_clk=qsfp_1_rx_clk,
        qsfp_1_rx_rst=qsfp_1_rx_rst,
        qsfp_1_rx_axis_tdata=qsfp_1_rx_axis_tdata,
        qsfp_1_rx_axis_tkeep=qsfp_1_rx_axis_tkeep,
        qsfp_1_rx_axis_tvalid=qsfp_1_rx_axis_tvalid,
        qsfp_1_rx_axis_tlast=qsfp_1_rx_axis_tlast,
        qsfp_1_rx_axis_tuser=qsfp_1_rx_axis_tuser,
        qsfp_1_modprs_l=qsfp_1_modprs_l,
        qsfp_1_sel_l=qsfp_1_sel_l,
        qsfp_reset_l=qsfp_reset_l,
        qsfp_int_l=qsfp_int_l,
        qsfp_i2c_scl_i=qsfp_i2c_scl_i,
        qsfp_i2c_scl_o=qsfp_i2c_scl_o,
        qsfp_i2c_scl_t=qsfp_i2c_scl_t,
        qsfp_i2c_sda_i=qsfp_i2c_sda_i,
        qsfp_i2c_sda_o=qsfp_i2c_sda_o,
        qsfp_i2c_sda_t=qsfp_i2c_sda_t,
        eeprom_i2c_scl_i=eeprom_i2c_scl_i,
        eeprom_i2c_scl_o=eeprom_i2c_scl_o,
        eeprom_i2c_scl_t=eeprom_i2c_scl_t,
        eeprom_i2c_sda_i=eeprom_i2c_sda_i,
        eeprom_i2c_sda_o=eeprom_i2c_sda_o,
        eeprom_i2c_sda_t=eeprom_i2c_sda_t,
        eeprom_wp=eeprom_wp,
        fpga_boot=fpga_boot,
        qspi_clk=qspi_clk,
        qspi_0_dq_i=qspi_0_dq_i,
        qspi_0_dq_o=qspi_0_dq_o,
        qspi_0_dq_oe=qspi_0_dq_oe,
        qspi_0_cs=qspi_0_cs,
        qspi_1_dq_i=qspi_1_dq_i,
        qspi_1_dq_o=qspi_1_dq_o,
        qspi_1_dq_oe=qspi_1_dq_oe,
        qspi_1_cs=qspi_1_cs
    )

    @always(delay(5))
    def clkgen():
        clk.next = not clk

    @always(delay(2))
    def qsfp_clkgen():
        qsfp_0_tx_clk.next = not qsfp_0_tx_clk
        qsfp_0_rx_clk.next = not qsfp_0_rx_clk
        qsfp_1_tx_clk.next = not qsfp_1_tx_clk
        qsfp_1_rx_clk.next = not qsfp_1_rx_clk

    @always_comb
    def clk_logic():
        sys_clk.next = clk
        sys_reset.next = not rst

    loopback_enable = Signal(bool(0))

    @instance
    def loopback():
        while True:

            yield clk.posedge

            if loopback_enable:
                if not qsfp_0_sink.empty():
                    pkt = qsfp_0_sink.recv()
                    qsfp_0_source.send(pkt)
                if not qsfp_1_sink.empty():
                    pkt = qsfp_1_sink.recv()
                    qsfp_1_source.send(pkt)

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        qsfp_0_tx_rst.next = 1
        qsfp_0_rx_rst.next = 1
        qsfp_1_tx_rst.next = 1
        qsfp_1_rx_rst.next = 1
        yield clk.posedge
        yield delay(100)
        rst.next = 0
        qsfp_0_tx_rst.next = 0
        qsfp_0_rx_rst.next = 0
        qsfp_1_tx_rst.next = 0
        qsfp_1_rx_rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # testbench stimulus

        current_tag = 1

        yield clk.posedge
        print("test 1: enumeration")
        current_test.next = 1

        yield rc.enumerate(enable_bus_mastering=True, configure_msi=True)

        yield delay(100)

        yield clk.posedge
        print("test 2: init NIC")
        current_test.next = 2

        yield from driver.init_dev(dev.functions[0].get_id())
        yield from driver.interfaces[0].open()
        #yield from driver.interfaces[1].open()

        # enable queues
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].hw_addr+mqnic.MQNIC_PORT_REG_SCHED_ENABLE, 0x00000001)
        for k in range(driver.interfaces[0].tx_queue_count):
            yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+4*k, 0x00000003)

        yield from rc.mem_read(driver.hw_addr, 4) # wait for all writes to complete

        yield delay(100)

        yield clk.posedge
        print("test 3: send and receive a packet")
        current_test.next = 3

        # test bad packet
        #qsfp_0_source.send(b'\x55\x55\x55\x55\x55\xd5'+bytearray(range(128)))

        data = bytearray([x%256 for x in range(1024)])

        yield from driver.interfaces[0].start_xmit(data, 0)

        yield qsfp_0_sink.wait()

        pkt = qsfp_0_sink.recv()
        print(pkt)

        qsfp_0_source.send(pkt)

        yield driver.interfaces[0].wait()

        pkt = driver.interfaces[0].recv()

        print(pkt)
        assert frame_checksum(pkt.data) == pkt.rx_checksum

        # yield from driver.interfaces[1].start_xmit(data, 0)

        # yield qsfp_1_sink.wait()

        # pkt = qsfp_1_sink.recv()
        # print(pkt)

        # qsfp_1_source.send(pkt)

        # yield driver.interfaces[1].wait()

        # pkt = driver.interfaces[1].recv()

        # print(pkt)
        # assert frame_checksum(pkt.data) == pkt.rx_checksum

        yield delay(100)

        yield clk.posedge
        print("test 4: checksum tests")
        current_test.next = 4

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80164
        test_frame.ip_dest_ip = 0xc0a80165
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray((x%256 for x in range(256)))

        test_frame.set_udp_pseudo_header_checksum()

        axis_frame = test_frame.build_axis()

        yield from driver.interfaces[0].start_xmit(axis_frame.data, 0, 34, 6)

        yield qsfp_0_sink.wait()

        pkt = qsfp_0_sink.recv()
        print(pkt)

        qsfp_0_source.send(pkt)

        yield driver.interfaces[0].wait()

        pkt = driver.interfaces[0].recv()

        print(pkt)

        assert pkt.rx_checksum == frame_checksum(pkt.data)

        check_frame = udp_ep.UDPFrame()
        check_frame.parse_axis(pkt.data)

        assert check_frame.verify_checksums()

        yield delay(100)

        yield clk.posedge
        print("test 5: multiple small packets")
        current_test.next = 5

        count = 64

        pkts = [bytearray([(x+k)%256 for x in range(64)]) for k in range(count)]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        yield clk.posedge
        print("test 6: multiple large packets")
        current_test.next = 6

        count = 64

        pkts = [bytearray([(x+k)%256 for x in range(1514)]) for k in range(count)]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        yield clk.posedge
        print("test 7: jumbo frames")
        current_test.next = 7

        count = 64

        pkts = [bytearray([(x+k)%256 for x in range(9014)]) for k in range(count)]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        raise StopSimulation

    return instances()
Exemplo n.º 2
0
def bench():

    # Parameters
    AXIS_PCIE_DATA_WIDTH = 256
    AXIS_PCIE_KEEP_WIDTH = (AXIS_PCIE_DATA_WIDTH / 32)
    AXIS_PCIE_RC_USER_WIDTH = 75
    AXIS_PCIE_RQ_USER_WIDTH = 60
    AXIS_PCIE_CQ_USER_WIDTH = 85
    AXIS_PCIE_CC_USER_WIDTH = 33
    RQ_SEQ_NUM_WIDTH = 4
    BAR0_APERTURE = 24

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    clk_250mhz = Signal(bool(0))
    rst_250mhz = Signal(bool(0))
    btnu = Signal(bool(0))
    btnl = Signal(bool(0))
    btnd = Signal(bool(0))
    btnr = Signal(bool(0))
    btnc = Signal(bool(0))
    sw = Signal(intbv(0)[4:])
    i2c_scl_i = Signal(bool(1))
    i2c_sda_i = Signal(bool(1))
    m_axis_rq_tready = Signal(bool(0))
    s_axis_rc_tdata = Signal(intbv(0)[AXIS_PCIE_DATA_WIDTH:])
    s_axis_rc_tkeep = Signal(intbv(0)[AXIS_PCIE_KEEP_WIDTH:])
    s_axis_rc_tlast = Signal(bool(0))
    s_axis_rc_tuser = Signal(intbv(0)[AXIS_PCIE_RC_USER_WIDTH:])
    s_axis_rc_tvalid = Signal(bool(0))
    s_axis_cq_tdata = Signal(intbv(0)[AXIS_PCIE_DATA_WIDTH:])
    s_axis_cq_tkeep = Signal(intbv(0)[AXIS_PCIE_KEEP_WIDTH:])
    s_axis_cq_tlast = Signal(bool(0))
    s_axis_cq_tuser = Signal(intbv(0)[AXIS_PCIE_CQ_USER_WIDTH:])
    s_axis_cq_tvalid = Signal(bool(0))
    m_axis_cc_tready = Signal(bool(0))
    s_axis_rq_seq_num = Signal(intbv(0)[RQ_SEQ_NUM_WIDTH:])
    s_axis_rq_seq_num_valid = Signal(bool(0))
    pcie_tfc_nph_av = Signal(intbv(0)[2:])
    pcie_tfc_npd_av = Signal(intbv(0)[2:])
    cfg_max_payload = Signal(intbv(0)[3:])
    cfg_max_read_req = Signal(intbv(0)[3:])
    cfg_mgmt_read_data = Signal(intbv(0)[32:])
    cfg_mgmt_read_write_done = Signal(bool(0))
    cfg_fc_ph = Signal(intbv(0)[8:])
    cfg_fc_pd = Signal(intbv(0)[12:])
    cfg_fc_nph = Signal(intbv(0)[8:])
    cfg_fc_npd = Signal(intbv(0)[12:])
    cfg_fc_cplh = Signal(intbv(0)[8:])
    cfg_fc_cpld = Signal(intbv(0)[12:])
    cfg_interrupt_msi_enable = Signal(intbv(0)[4:])
    cfg_interrupt_msi_vf_enable = Signal(intbv(0)[8:])
    cfg_interrupt_msi_mmenable = Signal(intbv(0)[12:])
    cfg_interrupt_msi_mask_update = Signal(bool(0))
    cfg_interrupt_msi_data = Signal(intbv(0)[32:])
    cfg_interrupt_msi_sent = Signal(bool(0))
    cfg_interrupt_msi_fail = Signal(bool(0))
    qsfp_tx_clk_1 = Signal(bool(0))
    qsfp_tx_rst_1 = Signal(bool(0))
    qsfp_rx_clk_1 = Signal(bool(0))
    qsfp_rx_rst_1 = Signal(bool(0))
    qsfp_rxd_1 = Signal(intbv(0)[64:])
    qsfp_rxc_1 = Signal(intbv(0)[8:])
    qsfp_tx_clk_2 = Signal(bool(0))
    qsfp_tx_rst_2 = Signal(bool(0))
    qsfp_rx_clk_2 = Signal(bool(0))
    qsfp_rx_rst_2 = Signal(bool(0))
    qsfp_rxd_2 = Signal(intbv(0)[64:])
    qsfp_rxc_2 = Signal(intbv(0)[8:])
    qsfp_tx_clk_3 = Signal(bool(0))
    qsfp_tx_rst_3 = Signal(bool(0))
    qsfp_rx_clk_3 = Signal(bool(0))
    qsfp_rx_rst_3 = Signal(bool(0))
    qsfp_rxd_3 = Signal(intbv(0)[64:])
    qsfp_rxc_3 = Signal(intbv(0)[8:])
    qsfp_tx_clk_4 = Signal(bool(0))
    qsfp_tx_rst_4 = Signal(bool(0))
    qsfp_rx_clk_4 = Signal(bool(0))
    qsfp_rx_rst_4 = Signal(bool(0))
    qsfp_rxd_4 = Signal(intbv(0)[64:])
    qsfp_rxc_4 = Signal(intbv(0)[8:])
    qsfp_modprsl = Signal(bool(1))
    qsfp_intl = Signal(bool(1))
    flash_dq_i = Signal(intbv(0)[16:])

    # Outputs
    led = Signal(intbv(0)[8:])
    i2c_scl_o = Signal(bool(1))
    i2c_scl_t = Signal(bool(1))
    i2c_sda_o = Signal(bool(1))
    i2c_sda_t = Signal(bool(1))
    m_axis_rq_tdata = Signal(intbv(0)[AXIS_PCIE_DATA_WIDTH:])
    m_axis_rq_tkeep = Signal(intbv(0)[AXIS_PCIE_KEEP_WIDTH:])
    m_axis_rq_tlast = Signal(bool(0))
    m_axis_rq_tuser = Signal(intbv(0)[AXIS_PCIE_RQ_USER_WIDTH:])
    m_axis_rq_tvalid = Signal(bool(0))
    s_axis_rc_tready = Signal(bool(0))
    s_axis_cq_tready = Signal(bool(0))
    m_axis_cc_tdata = Signal(intbv(0)[AXIS_PCIE_DATA_WIDTH:])
    m_axis_cc_tkeep = Signal(intbv(0)[AXIS_PCIE_KEEP_WIDTH:])
    m_axis_cc_tlast = Signal(bool(0))
    m_axis_cc_tuser = Signal(intbv(0)[AXIS_PCIE_CC_USER_WIDTH:])
    m_axis_cc_tvalid = Signal(bool(0))
    status_error_cor = Signal(bool(0))
    status_error_uncor = Signal(bool(0))
    cfg_mgmt_addr = Signal(intbv(0)[19:])
    cfg_mgmt_write = Signal(bool(0))
    cfg_mgmt_write_data = Signal(intbv(0)[32:])
    cfg_mgmt_byte_enable = Signal(intbv(0)[4:])
    cfg_mgmt_read = Signal(bool(0))
    cfg_fc_sel = Signal(intbv(4)[3:])
    cfg_interrupt_msi_int = Signal(intbv(0)[32:])
    cfg_interrupt_msi_pending_status = Signal(intbv(0)[32:])
    cfg_interrupt_msi_select = Signal(intbv(0)[4:])
    cfg_interrupt_msi_pending_status_function_num = Signal(intbv(0)[4:])
    cfg_interrupt_msi_pending_status_data_enable = Signal(bool(0))
    cfg_interrupt_msi_attr = Signal(intbv(0)[3:])
    cfg_interrupt_msi_tph_present = Signal(bool(0))
    cfg_interrupt_msi_tph_type = Signal(intbv(0)[2:])
    cfg_interrupt_msi_tph_st_tag = Signal(intbv(0)[9:])
    cfg_interrupt_msi_function_number = Signal(intbv(0)[4:])
    qsfp_txd_1 = Signal(intbv(0)[64:])
    qsfp_txc_1 = Signal(intbv(0)[8:])
    qsfp_txd_2 = Signal(intbv(0)[64:])
    qsfp_txc_2 = Signal(intbv(0)[8:])
    qsfp_txd_3 = Signal(intbv(0)[64:])
    qsfp_txc_3 = Signal(intbv(0)[8:])
    qsfp_txd_4 = Signal(intbv(0)[64:])
    qsfp_txc_4 = Signal(intbv(0)[8:])
    qsfp_modsell = Signal(bool(0))
    qsfp_resetl = Signal(bool(1))
    qsfp_lpmode = Signal(bool(0))
    flash_dq_o = Signal(intbv(0)[16:])
    flash_dq_oe = Signal(bool(0))
    flash_addr = Signal(intbv(0)[23:])
    flash_region = Signal(bool(0))
    flash_region_oe = Signal(bool(0))
    flash_ce_n = Signal(bool(1))
    flash_oe_n = Signal(bool(1))
    flash_we_n = Signal(bool(1))
    flash_adv_n = Signal(bool(1))

    # sources and sinks
    qsfp_1_source = xgmii_ep.XGMIISource()
    qsfp_1_source_logic = qsfp_1_source.create_logic(qsfp_rx_clk_1,
                                                     qsfp_rx_rst_1,
                                                     txd=qsfp_rxd_1,
                                                     txc=qsfp_rxc_1,
                                                     name='qsfp_1_source')

    qsfp_1_sink = xgmii_ep.XGMIISink()
    qsfp_1_sink_logic = qsfp_1_sink.create_logic(qsfp_tx_clk_1,
                                                 qsfp_tx_rst_1,
                                                 rxd=qsfp_txd_1,
                                                 rxc=qsfp_txc_1,
                                                 name='qsfp_1_sink')

    qsfp_2_source = xgmii_ep.XGMIISource()
    qsfp_2_source_logic = qsfp_2_source.create_logic(qsfp_rx_clk_2,
                                                     qsfp_rx_rst_2,
                                                     txd=qsfp_rxd_2,
                                                     txc=qsfp_rxc_2,
                                                     name='qsfp_2_source')

    qsfp_2_sink = xgmii_ep.XGMIISink()
    qsfp_2_sink_logic = qsfp_2_sink.create_logic(qsfp_tx_clk_2,
                                                 qsfp_tx_rst_2,
                                                 rxd=qsfp_txd_2,
                                                 rxc=qsfp_txc_2,
                                                 name='qsfp_2_sink')

    qsfp_3_source = xgmii_ep.XGMIISource()
    qsfp_3_source_logic = qsfp_3_source.create_logic(qsfp_rx_clk_3,
                                                     qsfp_rx_rst_3,
                                                     txd=qsfp_rxd_3,
                                                     txc=qsfp_rxc_3,
                                                     name='qsfp_3_source')

    qsfp_3_sink = xgmii_ep.XGMIISink()
    qsfp_3_sink_logic = qsfp_3_sink.create_logic(qsfp_tx_clk_3,
                                                 qsfp_tx_rst_3,
                                                 rxd=qsfp_txd_3,
                                                 rxc=qsfp_txc_3,
                                                 name='qsfp_3_sink')

    qsfp_4_source = xgmii_ep.XGMIISource()
    qsfp_4_source_logic = qsfp_4_source.create_logic(qsfp_rx_clk_4,
                                                     qsfp_rx_rst_4,
                                                     txd=qsfp_rxd_4,
                                                     txc=qsfp_rxc_4,
                                                     name='qsfp_4_source')

    qsfp_4_sink = xgmii_ep.XGMIISink()
    qsfp_4_sink_logic = qsfp_4_sink.create_logic(qsfp_tx_clk_4,
                                                 qsfp_tx_rst_4,
                                                 rxd=qsfp_txd_4,
                                                 rxc=qsfp_txc_4,
                                                 name='qsfp_4_sink')

    # Clock and Reset Interface
    user_clk = Signal(bool(0))
    user_reset = Signal(bool(0))
    sys_clk = Signal(bool(0))
    sys_reset = Signal(bool(0))

    # PCIe devices
    rc = pcie.RootComplex()

    rc.max_payload_size = 0x1  # 256 bytes
    rc.max_read_request_size = 0x5  # 4096 bytes

    driver = mqnic.Driver(rc)

    dev = pcie_us.UltrascalePCIe()

    dev.pcie_generation = 3
    dev.pcie_link_width = 8
    dev.user_clock_frequency = 256e6

    dev.functions[0].msi_multiple_message_capable = 5

    dev.functions[0].configure_bar(0,
                                   2**BAR0_APERTURE,
                                   ext=True,
                                   prefetch=True)

    rc.make_port().connect(dev)

    pcie_logic = dev.create_logic(
        # Completer reQuest Interface
        m_axis_cq_tdata=s_axis_cq_tdata,
        m_axis_cq_tuser=s_axis_cq_tuser,
        m_axis_cq_tlast=s_axis_cq_tlast,
        m_axis_cq_tkeep=s_axis_cq_tkeep,
        m_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cq_tready=s_axis_cq_tready,
        #pcie_cq_np_req=pcie_cq_np_req,
        pcie_cq_np_req=Signal(bool(1)),
        #pcie_cq_np_req_count=pcie_cq_np_req_count,

        # Completer Completion Interface
        s_axis_cc_tdata=m_axis_cc_tdata,
        s_axis_cc_tuser=m_axis_cc_tuser,
        s_axis_cc_tlast=m_axis_cc_tlast,
        s_axis_cc_tkeep=m_axis_cc_tkeep,
        s_axis_cc_tvalid=m_axis_cc_tvalid,
        s_axis_cc_tready=m_axis_cc_tready,

        # Requester reQuest Interface
        s_axis_rq_tdata=m_axis_rq_tdata,
        s_axis_rq_tuser=m_axis_rq_tuser,
        s_axis_rq_tlast=m_axis_rq_tlast,
        s_axis_rq_tkeep=m_axis_rq_tkeep,
        s_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rq_tready=m_axis_rq_tready,
        pcie_rq_seq_num=s_axis_rq_seq_num,
        pcie_rq_seq_num_vld=s_axis_rq_seq_num_valid,
        #pcie_rq_tag=pcie_rq_tag,
        #pcie_rq_tag_vld=pcie_rq_tag_vld,

        # Requester Completion Interface
        m_axis_rc_tdata=s_axis_rc_tdata,
        m_axis_rc_tuser=s_axis_rc_tuser,
        m_axis_rc_tlast=s_axis_rc_tlast,
        m_axis_rc_tkeep=s_axis_rc_tkeep,
        m_axis_rc_tvalid=s_axis_rc_tvalid,
        m_axis_rc_tready=s_axis_rc_tready,

        # Transmit Flow Control Interface
        pcie_tfc_nph_av=pcie_tfc_nph_av,
        pcie_tfc_npd_av=pcie_tfc_npd_av,

        # Configuration Management Interface
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        #cfg_mgmt_type1_cfg_reg_access=cfg_mgmt_type1_cfg_reg_access,

        # Configuration Status Interface
        #cfg_phy_link_down=cfg_phy_link_down,
        #cfg_phy_link_status=cfg_phy_link_status,
        #cfg_negotiated_width=cfg_negotiated_width,
        #cfg_current_speed=cfg_current_speed,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        #cfg_function_status=cfg_function_status,
        #cfg_vf_status=cfg_vf_status,
        #cfg_function_power_state=cfg_function_power_state,
        #cfg_vf_power_state=cfg_vf_power_state,
        #cfg_link_power_state=cfg_link_power_state,
        #cfg_err_cor_out=cfg_err_cor_out,
        #cfg_err_nonfatal_out=cfg_err_nonfatal_out,
        #cfg_err_fatal_out=cfg_err_fatal_out,
        #cfg_ltr_enable=cfg_ltr_enable,
        #cfg_ltssm_state=cfg_ltssm_state,
        #cfg_rcb_status=cfg_rcb_status,
        #cfg_dpa_substate_change=cfg_dpa_substate_change,
        #cfg_obff_enable=cfg_obff_enable,
        #cfg_pl_status_change=cfg_pl_status_change,
        #cfg_tph_requester_enable=cfg_tph_requester_enable,
        #cfg_tph_st_mode=cfg_tph_st_mode,
        #cfg_vf_tph_requester_enable=cfg_vf_tph_requester_enable,
        #cfg_vf_tph_st_mode=cfg_vf_tph_st_mode,

        # Configuration Received Message Interface
        #cfg_msg_received=cfg_msg_received,
        #cfg_msg_received_data=cfg_msg_received_data,
        #cfg_msg_received_type=cfg_msg_received_type,

        # Configuration Transmit Message Interface
        #cfg_msg_transmit=cfg_msg_transmit,
        #cfg_msg_transmit_type=cfg_msg_transmit_type,
        #cfg_msg_transmit_data=cfg_msg_transmit_data,
        #cfg_msg_transmit_done=cfg_msg_transmit_done,

        # Configuration Flow Control Interface
        cfg_fc_ph=cfg_fc_ph,
        cfg_fc_pd=cfg_fc_pd,
        cfg_fc_nph=cfg_fc_nph,
        cfg_fc_npd=cfg_fc_npd,
        cfg_fc_cplh=cfg_fc_cplh,
        cfg_fc_cpld=cfg_fc_cpld,
        cfg_fc_sel=cfg_fc_sel,

        # Per-Function Status Interface
        #cfg_per_func_status_control=cfg_per_func_status_control,
        #cfg_per_func_status_data=cfg_per_func_status_data,

        # Configuration Control Interface
        #cfg_hot_reset_in=cfg_hot_reset_in,
        #cfg_hot_reset_out=cfg_hot_reset_out,
        #cfg_config_space_enable=cfg_config_space_enable,
        #cfg_per_function_update_done=cfg_per_function_update_done,
        #cfg_per_function_number=cfg_per_function_number,
        #cfg_per_function_output_request=cfg_per_function_output_request,
        #cfg_dsn=cfg_dsn,
        #cfg_ds_bus_number=cfg_ds_bus_number,
        #cfg_ds_device_number=cfg_ds_device_number,
        #cfg_ds_function_number=cfg_ds_function_number,
        #cfg_power_state_change_ack=cfg_power_state_change_ack,
        #cfg_power_state_change_interrupt=cfg_power_state_change_interrupt,
        cfg_err_cor_in=status_error_cor,
        cfg_err_uncor_in=status_error_uncor,
        #cfg_flr_done=cfg_flr_done,
        #cfg_vf_flr_done=cfg_vf_flr_done,
        #cfg_flr_in_process=cfg_flr_in_process,
        #cfg_vf_flr_in_process=cfg_vf_flr_in_process,
        #cfg_req_pm_transition_l23_ready=cfg_req_pm_transition_l23_ready,
        #cfg_link_training_enable=cfg_link_training_enable,

        # Configuration Interrupt Controller Interface
        #cfg_interrupt_int=cfg_interrupt_int,
        #cfg_interrupt_sent=cfg_interrupt_sent,
        #cfg_interrupt_pending=cfg_interrupt_pending,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_vf_enable=cfg_interrupt_msi_vf_enable,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_pending_status_data_enable=
        cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_pending_status_function_num=
        cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        #cfg_interrupt_msix_enable=cfg_interrupt_msix_enable,
        #cfg_interrupt_msix_mask=cfg_interrupt_msix_mask,
        #cfg_interrupt_msix_vf_enable=cfg_interrupt_msix_vf_enable,
        #cfg_interrupt_msix_vf_mask=cfg_interrupt_msix_vf_mask,
        #cfg_interrupt_msix_address=cfg_interrupt_msix_address,
        #cfg_interrupt_msix_data=cfg_interrupt_msix_data,
        #cfg_interrupt_msix_int=cfg_interrupt_msix_int,
        #cfg_interrupt_msix_sent=cfg_interrupt_msix_sent,
        #cfg_interrupt_msix_fail=cfg_interrupt_msix_fail,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,

        # Configuration Extend Interface
        #cfg_ext_read_received=cfg_ext_read_received,
        #cfg_ext_write_received=cfg_ext_write_received,
        #cfg_ext_register_number=cfg_ext_register_number,
        #cfg_ext_function_number=cfg_ext_function_number,
        #cfg_ext_write_data=cfg_ext_write_data,
        #cfg_ext_write_byte_enable=cfg_ext_write_byte_enable,
        #cfg_ext_read_data=cfg_ext_read_data,
        #cfg_ext_read_data_valid=cfg_ext_read_data_valid,

        # Clock and Reset Interface
        user_clk=user_clk,
        user_reset=user_reset,
        sys_clk=sys_clk,
        sys_clk_gt=sys_clk,
        sys_reset=sys_reset,
        #pcie_perstn0_out=pcie_perstn0_out,
        #pcie_perstn1_in=pcie_perstn1_in,
        #pcie_perstn1_out=pcie_perstn1_out
    )

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation(
        "vvp -m myhdl %s.vvp -lxt2" % testbench,
        clk=clk,
        rst=rst,
        current_test=current_test,
        clk_250mhz=user_clk,
        rst_250mhz=user_reset,
        btnu=btnu,
        btnl=btnl,
        btnd=btnd,
        btnr=btnr,
        btnc=btnc,
        sw=sw,
        led=led,
        i2c_scl_i=i2c_scl_i,
        i2c_scl_o=i2c_scl_o,
        i2c_scl_t=i2c_scl_t,
        i2c_sda_i=i2c_sda_i,
        i2c_sda_o=i2c_sda_o,
        i2c_sda_t=i2c_sda_t,
        m_axis_rq_tdata=m_axis_rq_tdata,
        m_axis_rq_tkeep=m_axis_rq_tkeep,
        m_axis_rq_tlast=m_axis_rq_tlast,
        m_axis_rq_tready=m_axis_rq_tready,
        m_axis_rq_tuser=m_axis_rq_tuser,
        m_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rc_tdata=s_axis_rc_tdata,
        s_axis_rc_tkeep=s_axis_rc_tkeep,
        s_axis_rc_tlast=s_axis_rc_tlast,
        s_axis_rc_tready=s_axis_rc_tready,
        s_axis_rc_tuser=s_axis_rc_tuser,
        s_axis_rc_tvalid=s_axis_rc_tvalid,
        s_axis_cq_tdata=s_axis_cq_tdata,
        s_axis_cq_tkeep=s_axis_cq_tkeep,
        s_axis_cq_tlast=s_axis_cq_tlast,
        s_axis_cq_tready=s_axis_cq_tready,
        s_axis_cq_tuser=s_axis_cq_tuser,
        s_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cc_tdata=m_axis_cc_tdata,
        m_axis_cc_tkeep=m_axis_cc_tkeep,
        m_axis_cc_tlast=m_axis_cc_tlast,
        m_axis_cc_tready=m_axis_cc_tready,
        m_axis_cc_tuser=m_axis_cc_tuser,
        m_axis_cc_tvalid=m_axis_cc_tvalid,
        s_axis_rq_seq_num=s_axis_rq_seq_num,
        s_axis_rq_seq_num_valid=s_axis_rq_seq_num_valid,
        pcie_tfc_nph_av=pcie_tfc_nph_av,
        pcie_tfc_npd_av=pcie_tfc_npd_av,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        cfg_fc_ph=cfg_fc_ph,
        cfg_fc_pd=cfg_fc_pd,
        cfg_fc_nph=cfg_fc_nph,
        cfg_fc_npd=cfg_fc_npd,
        cfg_fc_cplh=cfg_fc_cplh,
        cfg_fc_cpld=cfg_fc_cpld,
        cfg_fc_sel=cfg_fc_sel,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_vf_enable=cfg_interrupt_msi_vf_enable,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_pending_status_function_num=
        cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_pending_status_data_enable=
        cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,
        status_error_cor=status_error_cor,
        status_error_uncor=status_error_uncor,
        qsfp_tx_clk_1=qsfp_tx_clk_1,
        qsfp_tx_rst_1=qsfp_tx_rst_1,
        qsfp_txd_1=qsfp_txd_1,
        qsfp_txc_1=qsfp_txc_1,
        qsfp_rx_clk_1=qsfp_rx_clk_1,
        qsfp_rx_rst_1=qsfp_rx_rst_1,
        qsfp_rxd_1=qsfp_rxd_1,
        qsfp_rxc_1=qsfp_rxc_1,
        qsfp_tx_clk_2=qsfp_tx_clk_2,
        qsfp_tx_rst_2=qsfp_tx_rst_2,
        qsfp_txd_2=qsfp_txd_2,
        qsfp_txc_2=qsfp_txc_2,
        qsfp_rx_clk_2=qsfp_rx_clk_2,
        qsfp_rx_rst_2=qsfp_rx_rst_2,
        qsfp_rxd_2=qsfp_rxd_2,
        qsfp_rxc_2=qsfp_rxc_2,
        qsfp_tx_clk_3=qsfp_tx_clk_3,
        qsfp_tx_rst_3=qsfp_tx_rst_3,
        qsfp_txd_3=qsfp_txd_3,
        qsfp_txc_3=qsfp_txc_3,
        qsfp_rx_clk_3=qsfp_rx_clk_3,
        qsfp_rx_rst_3=qsfp_rx_rst_3,
        qsfp_rxd_3=qsfp_rxd_3,
        qsfp_rxc_3=qsfp_rxc_3,
        qsfp_tx_clk_4=qsfp_tx_clk_4,
        qsfp_tx_rst_4=qsfp_tx_rst_4,
        qsfp_txd_4=qsfp_txd_4,
        qsfp_txc_4=qsfp_txc_4,
        qsfp_rx_clk_4=qsfp_rx_clk_4,
        qsfp_rx_rst_4=qsfp_rx_rst_4,
        qsfp_rxd_4=qsfp_rxd_4,
        qsfp_rxc_4=qsfp_rxc_4,
        qsfp_modsell=qsfp_modsell,
        qsfp_resetl=qsfp_resetl,
        qsfp_modprsl=qsfp_modprsl,
        qsfp_intl=qsfp_intl,
        qsfp_lpmode=qsfp_lpmode,
        flash_dq_i=flash_dq_i,
        flash_dq_o=flash_dq_o,
        flash_dq_oe=flash_dq_oe,
        flash_addr=flash_addr,
        flash_region=flash_region,
        flash_region_oe=flash_region_oe,
        flash_ce_n=flash_ce_n,
        flash_oe_n=flash_oe_n,
        flash_we_n=flash_we_n,
        flash_adv_n=flash_adv_n)

    @always(delay(5))
    def clkgen():
        clk.next = not clk

    @always(delay(3))
    def clkgen2():
        qsfp_tx_clk_1.next = not qsfp_tx_clk_1
        qsfp_rx_clk_1.next = not qsfp_rx_clk_1
        qsfp_tx_clk_2.next = not qsfp_tx_clk_2
        qsfp_rx_clk_2.next = not qsfp_rx_clk_2
        qsfp_tx_clk_3.next = not qsfp_tx_clk_3
        qsfp_rx_clk_3.next = not qsfp_rx_clk_3
        qsfp_tx_clk_4.next = not qsfp_tx_clk_4
        qsfp_rx_clk_4.next = not qsfp_rx_clk_4

    @always_comb
    def clk_logic():
        sys_clk.next = clk
        sys_reset.next = not rst

    loopback_enable = Signal(bool(0))

    @instance
    def loopback():
        while True:

            yield clk.posedge

            if loopback_enable:
                if not qsfp_1_sink.empty():
                    pkt = qsfp_1_sink.recv()
                    qsfp_1_source.send(pkt)
                if not qsfp_2_sink.empty():
                    pkt = qsfp_2_sink.recv()
                    qsfp_2_source.send(pkt)
                if not qsfp_3_sink.empty():
                    pkt = qsfp_3_sink.recv()
                    qsfp_3_source.send(pkt)
                if not qsfp_4_sink.empty():
                    pkt = qsfp_4_sink.recv()
                    qsfp_4_source.send(pkt)

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        qsfp_tx_rst_1.next = 1
        qsfp_rx_rst_1.next = 1
        qsfp_tx_rst_2.next = 1
        qsfp_rx_rst_2.next = 1
        qsfp_tx_rst_3.next = 1
        qsfp_rx_rst_3.next = 1
        qsfp_tx_rst_4.next = 1
        qsfp_rx_rst_4.next = 1
        yield clk.posedge
        rst.next = 0
        qsfp_tx_rst_1.next = 0
        qsfp_rx_rst_1.next = 0
        qsfp_tx_rst_2.next = 0
        qsfp_rx_rst_2.next = 0
        qsfp_tx_rst_3.next = 0
        qsfp_rx_rst_3.next = 0
        qsfp_tx_rst_4.next = 0
        qsfp_rx_rst_4.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # testbench stimulus

        current_tag = 1

        yield clk.posedge
        print("test 1: enumeration")
        current_test.next = 1

        yield rc.enumerate(enable_bus_mastering=True, configure_msi=True)

        yield delay(100)

        yield clk.posedge
        print("test 2: init NIC")
        current_test.next = 2

        yield from driver.init_dev(dev.functions[0].get_id())
        yield from driver.interfaces[0].open()

        # enable queues
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].hw_addr +
            mqnic.MQNIC_PORT_REG_SCHED_ENABLE, 0x00000001)
        for k in range(driver.interfaces[0].tx_queue_count):
            yield from rc.mem_write_dword(
                driver.interfaces[0].ports[0].schedulers[0].hw_addr + 4 * k,
                0x00000003)

        yield from rc.mem_read(driver.hw_addr,
                               4)  # wait for all writes to complete

        yield delay(100)

        yield clk.posedge
        print("test 3: send and receive a packet")
        current_test.next = 3

        data = bytearray([x % 256 for x in range(1024)])

        yield from driver.interfaces[0].start_xmit(data, 0)

        yield qsfp_1_sink.wait()

        pkt = qsfp_1_sink.recv()
        print(pkt)

        qsfp_1_source.send(pkt)

        yield driver.interfaces[0].wait()

        pkt = driver.interfaces[0].recv()

        print(pkt)

        yield delay(100)

        yield clk.posedge
        print("test 4: checksum tests")
        current_test.next = 4

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80164
        test_frame.ip_dest_ip = 0xc0a80165
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray((x % 256 for x in range(256)))

        test_frame.set_udp_pseudo_header_checksum()

        axis_frame = test_frame.build_axis()

        yield from driver.interfaces[0].start_xmit(axis_frame.data, 0, 34, 6)

        yield qsfp_1_sink.wait()

        pkt = qsfp_1_sink.recv()
        print(pkt)

        qsfp_1_source.send(pkt)

        yield driver.interfaces[0].wait()

        pkt = driver.interfaces[0].recv()

        print(pkt)

        assert pkt.rx_checksum == frame_checksum(pkt.data)

        check_frame = udp_ep.UDPFrame()
        check_frame.parse_axis(pkt.data)

        assert check_frame.verify_checksums()

        yield delay(100)

        yield clk.posedge
        print("test 5: multiple small packets")
        current_test.next = 5

        count = 64

        pkts = [
            bytearray([(x + k) % 256 for x in range(64)]) for k in range(count)
        ]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        yield clk.posedge
        print("test 6: multiple large packets")
        current_test.next = 6

        count = 64

        pkts = [
            bytearray([(x + k) % 256 for x in range(1514)])
            for k in range(count)
        ]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        raise StopSimulation

    return instances()
Exemplo n.º 3
0
    def __init__(self, dut):
        self.dut = dut

        self.BAR0_APERTURE = int(os.getenv("PARAM_BAR0_APERTURE"))

        self.log = SimLog("cocotb.tb")
        self.log.setLevel(logging.DEBUG)

        # PCIe
        self.rc = RootComplex()

        self.rc.max_payload_size = 0x1  # 256 bytes
        self.rc.max_read_request_size = 0x2  # 512 bytes

        self.dev = UltraScalePlusPcieDevice(
            # configuration options
            pcie_generation=3,
            pcie_link_width=4,
            user_clk_frequency=250e6,
            alignment="dword",
            cq_cc_straddle=False,
            rq_rc_straddle=False,
            rc_4tlp_straddle=False,
            enable_pf1=False,
            enable_client_tag=True,
            enable_extended_tag=True,
            enable_parity=False,
            enable_rx_msg_interface=False,
            enable_sriov=False,
            enable_extended_configuration=False,
            enable_pf0_msi=True,
            enable_pf1_msi=False,

            # signals
            # Clock and Reset Interface
            user_clk=dut.clk_250mhz,
            user_reset=dut.rst_250mhz,
            # user_lnk_up
            # sys_clk
            # sys_clk_gt
            # sys_reset
            # phy_rdy_out

            # Requester reQuest Interface
            rq_entity=dut,
            rq_name="m_axis_rq",
            pcie_rq_seq_num0=dut.s_axis_rq_seq_num_0,
            pcie_rq_seq_num_vld0=dut.s_axis_rq_seq_num_valid_0,
            pcie_rq_seq_num1=dut.s_axis_rq_seq_num_1,
            pcie_rq_seq_num_vld1=dut.s_axis_rq_seq_num_valid_1,
            # pcie_rq_tag0
            # pcie_rq_tag1
            # pcie_rq_tag_av
            # pcie_rq_tag_vld0
            # pcie_rq_tag_vld1

            # Requester Completion Interface
            rc_entity=dut,
            rc_name="s_axis_rc",

            # Completer reQuest Interface
            cq_entity=dut,
            cq_name="s_axis_cq",
            # pcie_cq_np_req
            # pcie_cq_np_req_count

            # Completer Completion Interface
            cc_entity=dut,
            cc_name="m_axis_cc",

            # Transmit Flow Control Interface
            # pcie_tfc_nph_av=dut.pcie_tfc_nph_av,
            # pcie_tfc_npd_av=dut.pcie_tfc_npd_av,

            # Configuration Management Interface
            cfg_mgmt_addr=dut.cfg_mgmt_addr,
            cfg_mgmt_function_number=dut.cfg_mgmt_function_number,
            cfg_mgmt_write=dut.cfg_mgmt_write,
            cfg_mgmt_write_data=dut.cfg_mgmt_write_data,
            cfg_mgmt_byte_enable=dut.cfg_mgmt_byte_enable,
            cfg_mgmt_read=dut.cfg_mgmt_read,
            cfg_mgmt_read_data=dut.cfg_mgmt_read_data,
            cfg_mgmt_read_write_done=dut.cfg_mgmt_read_write_done,
            # cfg_mgmt_debug_access

            # Configuration Status Interface
            # cfg_phy_link_down
            # cfg_phy_link_status
            # cfg_negotiated_width
            # cfg_current_speed
            cfg_max_payload=dut.cfg_max_payload,
            cfg_max_read_req=dut.cfg_max_read_req,
            # cfg_function_status
            # cfg_vf_status
            # cfg_function_power_state
            # cfg_vf_power_state
            # cfg_link_power_state
            # cfg_err_cor_out
            # cfg_err_nonfatal_out
            # cfg_err_fatal_out
            # cfg_local_error_out
            # cfg_local_error_valid
            # cfg_rx_pm_state
            # cfg_tx_pm_state
            # cfg_ltssm_state
            # cfg_rcb_status
            # cfg_obff_enable
            # cfg_pl_status_change
            # cfg_tph_requester_enable
            # cfg_tph_st_mode
            # cfg_vf_tph_requester_enable
            # cfg_vf_tph_st_mode

            # Configuration Received Message Interface
            # cfg_msg_received
            # cfg_msg_received_data
            # cfg_msg_received_type

            # Configuration Transmit Message Interface
            # cfg_msg_transmit
            # cfg_msg_transmit_type
            # cfg_msg_transmit_data
            # cfg_msg_transmit_done

            # Configuration Flow Control Interface
            cfg_fc_ph=dut.cfg_fc_ph,
            cfg_fc_pd=dut.cfg_fc_pd,
            cfg_fc_nph=dut.cfg_fc_nph,
            cfg_fc_npd=dut.cfg_fc_npd,
            cfg_fc_cplh=dut.cfg_fc_cplh,
            cfg_fc_cpld=dut.cfg_fc_cpld,
            cfg_fc_sel=dut.cfg_fc_sel,

            # Configuration Control Interface
            # cfg_hot_reset_in
            # cfg_hot_reset_out
            # cfg_config_space_enable
            # cfg_dsn
            # cfg_bus_number
            # cfg_ds_port_number
            # cfg_ds_bus_number
            # cfg_ds_device_number
            # cfg_ds_function_number
            # cfg_power_state_change_ack
            # cfg_power_state_change_interrupt
            cfg_err_cor_in=dut.status_error_cor,
            cfg_err_uncor_in=dut.status_error_uncor,
            # cfg_flr_in_process
            # cfg_flr_done
            # cfg_vf_flr_in_process
            # cfg_vf_flr_func_num
            # cfg_vf_flr_done
            # cfg_pm_aspm_l1_entry_reject
            # cfg_pm_aspm_tx_l0s_entry_disable
            # cfg_req_pm_transition_l23_ready
            # cfg_link_training_enable

            # Configuration Interrupt Controller Interface
            # cfg_interrupt_int
            # cfg_interrupt_sent
            # cfg_interrupt_pending
            cfg_interrupt_msi_enable=dut.cfg_interrupt_msi_enable,
            cfg_interrupt_msi_mmenable=dut.cfg_interrupt_msi_mmenable,
            cfg_interrupt_msi_mask_update=dut.cfg_interrupt_msi_mask_update,
            cfg_interrupt_msi_data=dut.cfg_interrupt_msi_data,
            # cfg_interrupt_msi_select=dut.cfg_interrupt_msi_select,
            cfg_interrupt_msi_int=dut.cfg_interrupt_msi_int,
            cfg_interrupt_msi_pending_status=dut.
            cfg_interrupt_msi_pending_status,
            cfg_interrupt_msi_pending_status_data_enable=dut.
            cfg_interrupt_msi_pending_status_data_enable,
            # cfg_interrupt_msi_pending_status_function_num=dut.cfg_interrupt_msi_pending_status_function_num,
            cfg_interrupt_msi_sent=dut.cfg_interrupt_msi_sent,
            cfg_interrupt_msi_fail=dut.cfg_interrupt_msi_fail,
            # cfg_interrupt_msix_enable
            # cfg_interrupt_msix_mask
            # cfg_interrupt_msix_vf_enable
            # cfg_interrupt_msix_vf_mask
            # cfg_interrupt_msix_address
            # cfg_interrupt_msix_data
            # cfg_interrupt_msix_int
            # cfg_interrupt_msix_vec_pending
            # cfg_interrupt_msix_vec_pending_status
            cfg_interrupt_msi_attr=dut.cfg_interrupt_msi_attr,
            cfg_interrupt_msi_tph_present=dut.cfg_interrupt_msi_tph_present,
            cfg_interrupt_msi_tph_type=dut.cfg_interrupt_msi_tph_type,
            # cfg_interrupt_msi_tph_st_tag=dut.cfg_interrupt_msi_tph_st_tag,
            # cfg_interrupt_msi_function_number=dut.cfg_interrupt_msi_function_number,

            # Configuration Extend Interface
            # cfg_ext_read_received
            # cfg_ext_write_received
            # cfg_ext_register_number
            # cfg_ext_function_number
            # cfg_ext_write_data
            # cfg_ext_write_byte_enable
            # cfg_ext_read_data
            # cfg_ext_read_data_valid
        )

        # self.dev.log.setLevel(logging.DEBUG)

        self.rc.make_port().connect(self.dev)

        self.driver = mqnic.Driver(self.rc)

        self.dev.functions[0].msi_multiple_message_capable = 5

        self.dev.functions[0].configure_bar(0,
                                            2**self.BAR0_APERTURE,
                                            ext=True,
                                            prefetch=True)

        # Ethernet
        cocotb.fork(Clock(dut.sfp0_rx_clk, 6.4, units="ns").start())
        self.sfp0_source = XgmiiSource(dut.sfp0_rxd, dut.sfp0_rxc,
                                       dut.sfp0_rx_clk, dut.sfp0_rx_rst)
        cocotb.fork(Clock(dut.sfp0_tx_clk, 6.4, units="ns").start())
        self.sfp0_sink = XgmiiSink(dut.sfp0_txd, dut.sfp0_txc, dut.sfp0_tx_clk,
                                   dut.sfp0_tx_rst)

        cocotb.fork(Clock(dut.sfp1_rx_clk, 6.4, units="ns").start())
        self.sfp1_source = XgmiiSource(dut.sfp1_rxd, dut.sfp1_rxc,
                                       dut.sfp1_rx_clk, dut.sfp1_rx_rst)
        cocotb.fork(Clock(dut.sfp1_tx_clk, 6.4, units="ns").start())
        self.sfp1_sink = XgmiiSink(dut.sfp1_txd, dut.sfp1_txc, dut.sfp1_tx_clk,
                                   dut.sfp1_tx_rst)

        dut.btnu.setimmediatevalue(0)
        dut.btnl.setimmediatevalue(0)
        dut.btnd.setimmediatevalue(0)
        dut.btnr.setimmediatevalue(0)
        dut.btnc.setimmediatevalue(0)
        dut.sw.setimmediatevalue(0)

        dut.i2c_scl_i.setimmediatevalue(1)
        dut.i2c_sda_i.setimmediatevalue(1)

        self.loopback_enable = False
        cocotb.fork(self._run_loopback())
Exemplo n.º 4
0
def bench():

    # Parameters


    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    clk_156mhz = Signal(bool(0))
    rst_156mhz = Signal(bool(0))
    clk_250mhz = Signal(bool(0))
    rst_250mhz = Signal(bool(0))
    m_axis_rq_tready = Signal(bool(0))
    s_axis_rc_tdata = Signal(intbv(0)[256:])
    s_axis_rc_tkeep = Signal(intbv(0)[8:])
    s_axis_rc_tlast = Signal(bool(0))
    s_axis_rc_tuser = Signal(intbv(0)[75:])
    s_axis_rc_tvalid = Signal(bool(0))
    s_axis_cq_tdata = Signal(intbv(0)[256:])
    s_axis_cq_tkeep = Signal(intbv(0)[8:])
    s_axis_cq_tlast = Signal(bool(0))
    s_axis_cq_tuser = Signal(intbv(0)[85:])
    s_axis_cq_tvalid = Signal(bool(0))
    m_axis_cc_tready = Signal(bool(0))
    pcie_tfc_nph_av = Signal(intbv(0)[2:])
    pcie_tfc_npd_av = Signal(intbv(0)[2:])
    cfg_max_payload = Signal(intbv(0)[3:])
    cfg_max_read_req = Signal(intbv(0)[3:])
    cfg_mgmt_read_data = Signal(intbv(0)[32:])
    cfg_mgmt_read_write_done = Signal(bool(0))
    cfg_interrupt_msi_enable = Signal(intbv(0)[4:])
    cfg_interrupt_msi_vf_enable = Signal(intbv(0)[8:])
    cfg_interrupt_msi_mmenable = Signal(intbv(0)[12:])
    cfg_interrupt_msi_mask_update = Signal(bool(0))
    cfg_interrupt_msi_data = Signal(intbv(0)[32:])
    cfg_interrupt_msi_sent = Signal(bool(0))
    cfg_interrupt_msi_fail = Signal(bool(0))
    sfp_1_tx_clk = Signal(bool(0))
    sfp_1_tx_rst = Signal(bool(0))
    sfp_1_rx_clk = Signal(bool(0))
    sfp_1_rx_rst = Signal(bool(0))
    sfp_1_rxd = Signal(intbv(0)[64:])
    sfp_1_rxc = Signal(intbv(0)[8:])
    sfp_2_tx_clk = Signal(bool(0))
    sfp_2_tx_rst = Signal(bool(0))
    sfp_2_rx_clk = Signal(bool(0))
    sfp_2_rx_rst = Signal(bool(0))
    sfp_2_rxd = Signal(intbv(0)[64:])
    sfp_2_rxc = Signal(intbv(0)[8:])
    sfp_i2c_scl_i = Signal(bool(1))
    sfp_1_i2c_sda_i = Signal(bool(1))
    sfp_2_i2c_sda_i = Signal(bool(1))
    eeprom_i2c_scl_i = Signal(bool(1))
    eeprom_i2c_sda_i = Signal(bool(1))
    flash_dq_i = Signal(intbv(0)[16:])

    # Outputs
    sfp_1_led = Signal(intbv(0)[2:])
    sfp_2_led = Signal(intbv(0)[2:])
    sma_led = Signal(intbv(0)[2:])
    m_axis_rq_tdata = Signal(intbv(0)[256:])
    m_axis_rq_tkeep = Signal(intbv(0)[8:])
    m_axis_rq_tlast = Signal(bool(0))
    m_axis_rq_tuser = Signal(intbv(0)[60:])
    m_axis_rq_tvalid = Signal(bool(0))
    s_axis_rc_tready = Signal(bool(0))
    s_axis_cq_tready = Signal(bool(0))
    m_axis_cc_tdata = Signal(intbv(0)[256:])
    m_axis_cc_tkeep = Signal(intbv(0)[8:])
    m_axis_cc_tlast = Signal(bool(0))
    m_axis_cc_tuser = Signal(intbv(0)[33:])
    m_axis_cc_tvalid = Signal(bool(0))
    status_error_cor = Signal(bool(0))
    status_error_uncor = Signal(bool(0))
    cfg_mgmt_addr = Signal(intbv(0)[19:])
    cfg_mgmt_write = Signal(bool(0))
    cfg_mgmt_write_data = Signal(intbv(0)[32:])
    cfg_mgmt_byte_enable = Signal(intbv(0)[4:])
    cfg_mgmt_read = Signal(bool(0))
    cfg_interrupt_msi_int = Signal(intbv(0)[32:])
    cfg_interrupt_msi_pending_status = Signal(intbv(0)[32:])
    cfg_interrupt_msi_select = Signal(intbv(0)[4:])
    cfg_interrupt_msi_pending_status_function_num = Signal(intbv(0)[4:])
    cfg_interrupt_msi_pending_status_data_enable = Signal(bool(0))
    cfg_interrupt_msi_attr = Signal(intbv(0)[3:])
    cfg_interrupt_msi_tph_present = Signal(bool(0))
    cfg_interrupt_msi_tph_type = Signal(intbv(0)[2:])
    cfg_interrupt_msi_tph_st_tag = Signal(intbv(0)[9:])
    cfg_interrupt_msi_function_number = Signal(intbv(0)[4:])
    sfp_1_txd = Signal(intbv(0)[64:])
    sfp_1_txc = Signal(intbv(0)[8:])
    sfp_2_txd = Signal(intbv(0)[64:])
    sfp_2_txc = Signal(intbv(0)[8:])
    sfp_i2c_scl_o = Signal(bool(1))
    sfp_i2c_scl_t = Signal(bool(1))
    sfp_1_i2c_sda_o = Signal(bool(1))
    sfp_1_i2c_sda_t = Signal(bool(1))
    sfp_2_i2c_sda_o = Signal(bool(1))
    sfp_2_i2c_sda_t = Signal(bool(1))
    eeprom_i2c_scl_o = Signal(bool(1))
    eeprom_i2c_scl_t = Signal(bool(1))
    eeprom_i2c_sda_o = Signal(bool(1))
    eeprom_i2c_sda_t = Signal(bool(1))
    flash_dq_o = Signal(intbv(0)[16:])
    flash_dq_oe = Signal(bool(0))
    flash_addr = Signal(intbv(0)[23:])
    flash_region = Signal(bool(0))
    flash_region_oe = Signal(bool(0))
    flash_ce_n = Signal(bool(1))
    flash_oe_n = Signal(bool(1))
    flash_we_n = Signal(bool(1))
    flash_adv_n = Signal(bool(1))

    # sources and sinks
    sfp_1_source = xgmii_ep.XGMIISource()
    sfp_1_source_logic = sfp_1_source.create_logic(sfp_1_rx_clk, sfp_1_rx_rst, txd=sfp_1_rxd, txc=sfp_1_rxc, name='sfp_1_source')

    sfp_1_sink = xgmii_ep.XGMIISink()
    sfp_1_sink_logic = sfp_1_sink.create_logic(sfp_1_tx_clk, sfp_1_tx_rst, rxd=sfp_1_txd, rxc=sfp_1_txc, name='sfp_1_sink')

    sfp_2_source = xgmii_ep.XGMIISource()
    sfp_2_source_logic = sfp_2_source.create_logic(sfp_2_rx_clk, sfp_2_rx_rst, txd=sfp_2_rxd, txc=sfp_2_rxc, name='sfp_2_source')

    sfp_2_sink = xgmii_ep.XGMIISink()
    sfp_2_sink_logic = sfp_2_sink.create_logic(sfp_2_tx_clk, sfp_2_tx_rst, rxd=sfp_2_txd, rxc=sfp_2_txc, name='sfp_2_sink')

    # Clock and Reset Interface
    user_clk=Signal(bool(0))
    user_reset=Signal(bool(0))
    sys_clk=Signal(bool(0))
    sys_reset=Signal(bool(0))

    # PCIe devices
    rc = pcie.RootComplex()

    rc.max_payload_size = 0x1 # 256 bytes
    rc.max_read_request_size = 0x5 # 4096 bytes

    driver = mqnic.Driver(rc)

    dev = pcie_us.UltrascalePCIe()

    dev.pcie_generation = 3
    dev.pcie_link_width = 8
    dev.user_clock_frequency = 256e6

    dev.functions[0].msi_multiple_message_capable = 5

    dev.functions[0].configure_bar(0, 16*1024*1024)
    dev.functions[0].configure_bar(1, 16*1024*1024)

    rc.make_port().connect(dev)

    pcie_logic = dev.create_logic(
        # Completer reQuest Interface
        m_axis_cq_tdata=s_axis_cq_tdata,
        m_axis_cq_tuser=s_axis_cq_tuser,
        m_axis_cq_tlast=s_axis_cq_tlast,
        m_axis_cq_tkeep=s_axis_cq_tkeep,
        m_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cq_tready=s_axis_cq_tready,
        #pcie_cq_np_req=pcie_cq_np_req,
        pcie_cq_np_req=Signal(bool(1)),
        #pcie_cq_np_req_count=pcie_cq_np_req_count,

        # Completer Completion Interface
        s_axis_cc_tdata=m_axis_cc_tdata,
        s_axis_cc_tuser=m_axis_cc_tuser,
        s_axis_cc_tlast=m_axis_cc_tlast,
        s_axis_cc_tkeep=m_axis_cc_tkeep,
        s_axis_cc_tvalid=m_axis_cc_tvalid,
        s_axis_cc_tready=m_axis_cc_tready,

        # Requester reQuest Interface
        s_axis_rq_tdata=m_axis_rq_tdata,
        s_axis_rq_tuser=m_axis_rq_tuser,
        s_axis_rq_tlast=m_axis_rq_tlast,
        s_axis_rq_tkeep=m_axis_rq_tkeep,
        s_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rq_tready=m_axis_rq_tready,
        #pcie_rq_seq_num=pcie_rq_seq_num,
        #pcie_rq_seq_num_vld=pcie_rq_seq_num_vld,
        #pcie_rq_tag=pcie_rq_tag,
        #pcie_rq_tag_vld=pcie_rq_tag_vld,

        # Requester Completion Interface
        m_axis_rc_tdata=s_axis_rc_tdata,
        m_axis_rc_tuser=s_axis_rc_tuser,
        m_axis_rc_tlast=s_axis_rc_tlast,
        m_axis_rc_tkeep=s_axis_rc_tkeep,
        m_axis_rc_tvalid=s_axis_rc_tvalid,
        m_axis_rc_tready=s_axis_rc_tready,

        # Transmit Flow Control Interface
        pcie_tfc_nph_av=pcie_tfc_nph_av,
        pcie_tfc_npd_av=pcie_tfc_npd_av,

        # Configuration Management Interface
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        #cfg_mgmt_type1_cfg_reg_access=cfg_mgmt_type1_cfg_reg_access,

        # Configuration Status Interface
        #cfg_phy_link_down=cfg_phy_link_down,
        #cfg_phy_link_status=cfg_phy_link_status,
        #cfg_negotiated_width=cfg_negotiated_width,
        #cfg_current_speed=cfg_current_speed,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        #cfg_function_status=cfg_function_status,
        #cfg_vf_status=cfg_vf_status,
        #cfg_function_power_state=cfg_function_power_state,
        #cfg_vf_power_state=cfg_vf_power_state,
        #cfg_link_power_state=cfg_link_power_state,
        #cfg_err_cor_out=cfg_err_cor_out,
        #cfg_err_nonfatal_out=cfg_err_nonfatal_out,
        #cfg_err_fatal_out=cfg_err_fatal_out,
        #cfg_ltr_enable=cfg_ltr_enable,
        #cfg_ltssm_state=cfg_ltssm_state,
        #cfg_rcb_status=cfg_rcb_status,
        #cfg_dpa_substate_change=cfg_dpa_substate_change,
        #cfg_obff_enable=cfg_obff_enable,
        #cfg_pl_status_change=cfg_pl_status_change,
        #cfg_tph_requester_enable=cfg_tph_requester_enable,
        #cfg_tph_st_mode=cfg_tph_st_mode,
        #cfg_vf_tph_requester_enable=cfg_vf_tph_requester_enable,
        #cfg_vf_tph_st_mode=cfg_vf_tph_st_mode,

        # Configuration Received Message Interface
        #cfg_msg_received=cfg_msg_received,
        #cfg_msg_received_data=cfg_msg_received_data,
        #cfg_msg_received_type=cfg_msg_received_type,

        # Configuration Transmit Message Interface
        #cfg_msg_transmit=cfg_msg_transmit,
        #cfg_msg_transmit_type=cfg_msg_transmit_type,
        #cfg_msg_transmit_data=cfg_msg_transmit_data,
        #cfg_msg_transmit_done=cfg_msg_transmit_done,

        # Configuration Flow Control Interface
        #cfg_fc_ph=cfg_fc_ph,
        #cfg_fc_pd=cfg_fc_pd,
        #cfg_fc_nph=cfg_fc_nph,
        #cfg_fc_npd=cfg_fc_npd,
        #cfg_fc_cplh=cfg_fc_cplh,
        #cfg_fc_cpld=cfg_fc_cpld,
        #cfg_fc_sel=cfg_fc_sel,

        # Per-Function Status Interface
        #cfg_per_func_status_control=cfg_per_func_status_control,
        #cfg_per_func_status_data=cfg_per_func_status_data,

        # Configuration Control Interface
        #cfg_hot_reset_in=cfg_hot_reset_in,
        #cfg_hot_reset_out=cfg_hot_reset_out,
        #cfg_config_space_enable=cfg_config_space_enable,
        #cfg_per_function_update_done=cfg_per_function_update_done,
        #cfg_per_function_number=cfg_per_function_number,
        #cfg_per_function_output_request=cfg_per_function_output_request,
        #cfg_dsn=cfg_dsn,
        #cfg_ds_bus_number=cfg_ds_bus_number,
        #cfg_ds_device_number=cfg_ds_device_number,
        #cfg_ds_function_number=cfg_ds_function_number,
        #cfg_power_state_change_ack=cfg_power_state_change_ack,
        #cfg_power_state_change_interrupt=cfg_power_state_change_interrupt,
        cfg_err_cor_in=status_error_cor,
        cfg_err_uncor_in=status_error_uncor,
        #cfg_flr_done=cfg_flr_done,
        #cfg_vf_flr_done=cfg_vf_flr_done,
        #cfg_flr_in_process=cfg_flr_in_process,
        #cfg_vf_flr_in_process=cfg_vf_flr_in_process,
        #cfg_req_pm_transition_l23_ready=cfg_req_pm_transition_l23_ready,
        #cfg_link_training_enable=cfg_link_training_enable,

        # Configuration Interrupt Controller Interface
        #cfg_interrupt_int=cfg_interrupt_int,
        #cfg_interrupt_sent=cfg_interrupt_sent,
        #cfg_interrupt_pending=cfg_interrupt_pending,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_vf_enable=cfg_interrupt_msi_vf_enable,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_pending_status_data_enable=cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_pending_status_function_num=cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        #cfg_interrupt_msix_enable=cfg_interrupt_msix_enable,
        #cfg_interrupt_msix_mask=cfg_interrupt_msix_mask,
        #cfg_interrupt_msix_vf_enable=cfg_interrupt_msix_vf_enable,
        #cfg_interrupt_msix_vf_mask=cfg_interrupt_msix_vf_mask,
        #cfg_interrupt_msix_address=cfg_interrupt_msix_address,
        #cfg_interrupt_msix_data=cfg_interrupt_msix_data,
        #cfg_interrupt_msix_int=cfg_interrupt_msix_int,
        #cfg_interrupt_msix_sent=cfg_interrupt_msix_sent,
        #cfg_interrupt_msix_fail=cfg_interrupt_msix_fail,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,

        # Configuration Extend Interface
        #cfg_ext_read_received=cfg_ext_read_received,
        #cfg_ext_write_received=cfg_ext_write_received,
        #cfg_ext_register_number=cfg_ext_register_number,
        #cfg_ext_function_number=cfg_ext_function_number,
        #cfg_ext_write_data=cfg_ext_write_data,
        #cfg_ext_write_byte_enable=cfg_ext_write_byte_enable,
        #cfg_ext_read_data=cfg_ext_read_data,
        #cfg_ext_read_data_valid=cfg_ext_read_data_valid,

        # Clock and Reset Interface
        user_clk=user_clk,
        user_reset=user_reset,
        sys_clk=sys_clk,
        sys_clk_gt=sys_clk,
        sys_reset=sys_reset,
        #pcie_perstn0_out=pcie_perstn0_out,
        #pcie_perstn1_in=pcie_perstn1_in,
        #pcie_perstn1_out=pcie_perstn1_out
    )

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation(
        "vvp -m myhdl %s.vvp -lxt2" % testbench,
        clk=clk,
        rst=rst,
        current_test=current_test,
        clk_156mhz=clk_156mhz,
        rst_156mhz=rst_156mhz,
        clk_250mhz=user_clk,
        rst_250mhz=user_reset,
        sfp_1_led=sfp_1_led,
        sfp_2_led=sfp_2_led,
        sma_led=sma_led,
        m_axis_rq_tdata=m_axis_rq_tdata,
        m_axis_rq_tkeep=m_axis_rq_tkeep,
        m_axis_rq_tlast=m_axis_rq_tlast,
        m_axis_rq_tready=m_axis_rq_tready,
        m_axis_rq_tuser=m_axis_rq_tuser,
        m_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rc_tdata=s_axis_rc_tdata,
        s_axis_rc_tkeep=s_axis_rc_tkeep,
        s_axis_rc_tlast=s_axis_rc_tlast,
        s_axis_rc_tready=s_axis_rc_tready,
        s_axis_rc_tuser=s_axis_rc_tuser,
        s_axis_rc_tvalid=s_axis_rc_tvalid,
        s_axis_cq_tdata=s_axis_cq_tdata,
        s_axis_cq_tkeep=s_axis_cq_tkeep,
        s_axis_cq_tlast=s_axis_cq_tlast,
        s_axis_cq_tready=s_axis_cq_tready,
        s_axis_cq_tuser=s_axis_cq_tuser,
        s_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cc_tdata=m_axis_cc_tdata,
        m_axis_cc_tkeep=m_axis_cc_tkeep,
        m_axis_cc_tlast=m_axis_cc_tlast,
        m_axis_cc_tready=m_axis_cc_tready,
        m_axis_cc_tuser=m_axis_cc_tuser,
        m_axis_cc_tvalid=m_axis_cc_tvalid,
        pcie_tfc_nph_av=pcie_tfc_nph_av,
        pcie_tfc_npd_av=pcie_tfc_npd_av,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_vf_enable=cfg_interrupt_msi_vf_enable,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_pending_status_function_num=cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_pending_status_data_enable=cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,
        status_error_cor=status_error_cor,
        status_error_uncor=status_error_uncor,
        sfp_1_tx_clk=sfp_1_tx_clk,
        sfp_1_tx_rst=sfp_1_tx_rst,
        sfp_1_txd=sfp_1_txd,
        sfp_1_txc=sfp_1_txc,
        sfp_1_rx_clk=sfp_1_rx_clk,
        sfp_1_rx_rst=sfp_1_rx_rst,
        sfp_1_rxd=sfp_1_rxd,
        sfp_1_rxc=sfp_1_rxc,
        sfp_2_tx_clk=sfp_2_tx_clk,
        sfp_2_tx_rst=sfp_2_tx_rst,
        sfp_2_txd=sfp_2_txd,
        sfp_2_txc=sfp_2_txc,
        sfp_2_rx_clk=sfp_2_rx_clk,
        sfp_2_rx_rst=sfp_2_rx_rst,
        sfp_2_rxd=sfp_2_rxd,
        sfp_2_rxc=sfp_2_rxc,
        sfp_i2c_scl_i=sfp_i2c_scl_i,
        sfp_i2c_scl_o=sfp_i2c_scl_o,
        sfp_i2c_scl_t=sfp_i2c_scl_t,
        sfp_1_i2c_sda_i=sfp_1_i2c_sda_i,
        sfp_1_i2c_sda_o=sfp_1_i2c_sda_o,
        sfp_1_i2c_sda_t=sfp_1_i2c_sda_t,
        sfp_2_i2c_sda_i=sfp_2_i2c_sda_i,
        sfp_2_i2c_sda_o=sfp_2_i2c_sda_o,
        sfp_2_i2c_sda_t=sfp_2_i2c_sda_t,
        eeprom_i2c_scl_i=eeprom_i2c_scl_i,
        eeprom_i2c_scl_o=eeprom_i2c_scl_o,
        eeprom_i2c_scl_t=eeprom_i2c_scl_t,
        eeprom_i2c_sda_i=eeprom_i2c_sda_i,
        eeprom_i2c_sda_o=eeprom_i2c_sda_o,
        eeprom_i2c_sda_t=eeprom_i2c_sda_t,
        flash_dq_i=flash_dq_i,
        flash_dq_o=flash_dq_o,
        flash_dq_oe=flash_dq_oe,
        flash_addr=flash_addr,
        flash_region=flash_region,
        flash_region_oe=flash_region_oe,
        flash_ce_n=flash_ce_n,
        flash_oe_n=flash_oe_n,
        flash_we_n=flash_we_n,
        flash_adv_n=flash_adv_n
    )

    @always(delay(5))
    def clkgen():
        clk.next = not clk

    @always_comb
    def clk_logic():
        sys_clk.next = clk
        sys_reset.next = not rst

        sfp_1_tx_clk.next = clk
        sfp_1_tx_rst.next = rst
        sfp_1_rx_clk.next = clk
        sfp_1_rx_rst.next = rst
        sfp_2_tx_clk.next = clk
        sfp_2_tx_rst.next = rst
        sfp_2_rx_clk.next = clk
        sfp_2_rx_rst.next = rst

    loopback_enable = Signal(bool(0))

    @instance
    def loopback():
        while True:

            yield clk.posedge

            if loopback_enable:
                if not sfp_1_sink.empty():
                    pkt = sfp_1_sink.recv()
                    sfp_1_source.send(pkt)
                if not sfp_2_sink.empty():
                    pkt = sfp_2_sink.recv()
                    sfp_2_source.send(pkt)

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # testbench stimulus

        current_tag = 1

        yield clk.posedge
        print("test 1: enumeration")
        current_test.next = 1

        yield rc.enumerate(enable_bus_mastering=True, configure_msi=True)

        dev_pf0_bar0 = dev.functions[0].bar[0] & 0xfffffffc
        dev_pf0_bar1 = dev.functions[0].bar[1] & 0xfffffffc

        yield from rc.mem_write_dword(dev_pf0_bar0+0x270, 0);
        yield from rc.mem_write_dword(dev_pf0_bar0+0x274, 0);
        yield from rc.mem_write_dword(dev_pf0_bar0+0x278, 0);
        yield from rc.mem_write_dword(dev_pf0_bar0+0x27C, 0);

        yield from rc.mem_write_dword(dev_pf0_bar0+0x290, 0);
        yield from rc.mem_write_dword(dev_pf0_bar0+0x294, 1000);
        yield from rc.mem_write_dword(dev_pf0_bar0+0x298, 0);
        yield from rc.mem_write_dword(dev_pf0_bar0+0x29C, 0);

        yield from rc.mem_write_dword(dev_pf0_bar0+0x280, 0);
        yield from rc.mem_write_dword(dev_pf0_bar0+0x284, 2000);
        yield from rc.mem_write_dword(dev_pf0_bar0+0x288, 0);
        yield from rc.mem_write_dword(dev_pf0_bar0+0x28C, 0);

        yield delay(100)

        yield clk.posedge
        print("test 2: init NIC")
        current_test.next = 2

        yield from driver.init_dev(dev.functions[0].get_id())
        yield from driver.interfaces[0].open()

        # enable queues
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x0200, 0xffffffff)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x0300, 0xffffffff)

        yield from rc.mem_read(driver.hw_addr, 4) # wait for all writes to complete

        yield delay(100)

        yield clk.posedge
        print("test 3: send and receive a packet")
        current_test.next = 3

        data = bytearray([x%256 for x in range(1024)])

        yield from driver.interfaces[0].start_xmit(data, 0)

        yield sfp_1_sink.wait()

        pkt = sfp_1_sink.recv()
        print(pkt)

        sfp_1_source.send(pkt)

        yield driver.interfaces[0].wait()

        pkt = driver.interfaces[0].recv()

        print(pkt)

        yield delay(100)

        yield clk.posedge
        print("test 4: multiple small packets")
        current_test.next = 4

        count = 64

        pkts = [bytearray([(x+k)%256 for x in range(64)]) for k in range(count)]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        yield clk.posedge
        print("test 5: multiple large packets")
        current_test.next = 5

        count = 64

        pkts = [bytearray([(x+k)%256 for x in range(1514)]) for k in range(count)]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(1000)

        yield clk.posedge
        print("test 6: TDMA")
        current_test.next = 6

        count = 16

        pkts = [bytearray([(x+k)%256 for x in range(1514)]) for k in range(count)]

        loopback_enable.next = True

        # configure TDMA

        # configure TDMA scheduler
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00120, 0) # schedule period fns
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00124, 40000) # schedule period ns
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00128, 0) # schedule period sec (low)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x0012c, 0) # schedule period sec (high)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00130, 0) # timeslot period fns
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00134, 10000) # timeslot period ns
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00138, 0) # timeslot period sec (low)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x0013c, 0) # timeslot period sec (high)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00140, 0) # active period fns
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00144, 5000) # active period ns
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00148, 0) # active period sec (low)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x0014c, 0) # active period sec (high)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00110, 0) # schedule start fns
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00114, 200000) # schedule start ns
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00118, 0) # schedule start sec (low)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x0011c, 0) # schedule start sec (high)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00100, 0x00000001)

        # enable queues
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00200, 0xffffffff)
        # disable global enable
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x00300, 0x00000000)

        # configure slots
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x10000, 0x00000001)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x10100, 0x00000002)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x10200, 0x00000004)
        yield from rc.mem_write_dword(driver.interfaces[0].ports[0].schedulers[0].hw_addr+0x10300, 0x00000008)

        yield from rc.mem_read(driver.hw_addr, 4) # wait for all writes to complete

        # send packets
        for k in range(count):
            yield from driver.interfaces[0].start_xmit(pkts[k], k%4)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            #assert pkt.data == pkts[k]
            #assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        raise StopSimulation

    return instances()
Exemplo n.º 5
0
    def __init__(self, dut):
        self.dut = dut

        self.log = SimLog("cocotb.tb")
        self.log.setLevel(logging.DEBUG)

        # PCIe
        self.rc = RootComplex()

        self.rc.max_payload_size = 0x1  # 256 bytes
        self.rc.max_read_request_size = 0x2  # 512 bytes

        self.dev = UltraScalePlusPcieDevice(
            # configuration options
            pcie_generation=3,
            pcie_link_width=16,
            user_clk_frequency=250e6,
            alignment="dword",
            cq_cc_straddle=False,
            rq_rc_straddle=False,
            rc_4tlp_straddle=False,
            enable_pf1=False,
            enable_client_tag=True,
            enable_extended_tag=True,
            enable_parity=False,
            enable_rx_msg_interface=False,
            enable_sriov=False,
            enable_extended_configuration=False,
            enable_pf0_msi=True,
            enable_pf1_msi=False,

            # signals
            # Clock and Reset Interface
            user_clk=dut.clk_250mhz,
            user_reset=dut.rst_250mhz,
            # user_lnk_up
            # sys_clk
            # sys_clk_gt
            # sys_reset
            # phy_rdy_out

            # Requester reQuest Interface
            rq_bus=AxiStreamBus.from_prefix(dut, "m_axis_rq"),
            pcie_rq_seq_num0=dut.s_axis_rq_seq_num_0,
            pcie_rq_seq_num_vld0=dut.s_axis_rq_seq_num_valid_0,
            pcie_rq_seq_num1=dut.s_axis_rq_seq_num_1,
            pcie_rq_seq_num_vld1=dut.s_axis_rq_seq_num_valid_1,
            # pcie_rq_tag0
            # pcie_rq_tag1
            # pcie_rq_tag_av
            # pcie_rq_tag_vld0
            # pcie_rq_tag_vld1

            # Requester Completion Interface
            rc_bus=AxiStreamBus.from_prefix(dut, "s_axis_rc"),

            # Completer reQuest Interface
            cq_bus=AxiStreamBus.from_prefix(dut, "s_axis_cq"),
            # pcie_cq_np_req
            # pcie_cq_np_req_count

            # Completer Completion Interface
            cc_bus=AxiStreamBus.from_prefix(dut, "m_axis_cc"),

            # Transmit Flow Control Interface
            # pcie_tfc_nph_av=dut.pcie_tfc_nph_av,
            # pcie_tfc_npd_av=dut.pcie_tfc_npd_av,

            # Configuration Management Interface
            cfg_mgmt_addr=dut.cfg_mgmt_addr,
            cfg_mgmt_function_number=dut.cfg_mgmt_function_number,
            cfg_mgmt_write=dut.cfg_mgmt_write,
            cfg_mgmt_write_data=dut.cfg_mgmt_write_data,
            cfg_mgmt_byte_enable=dut.cfg_mgmt_byte_enable,
            cfg_mgmt_read=dut.cfg_mgmt_read,
            cfg_mgmt_read_data=dut.cfg_mgmt_read_data,
            cfg_mgmt_read_write_done=dut.cfg_mgmt_read_write_done,
            # cfg_mgmt_debug_access

            # Configuration Status Interface
            # cfg_phy_link_down
            # cfg_phy_link_status
            # cfg_negotiated_width
            # cfg_current_speed
            cfg_max_payload=dut.cfg_max_payload,
            cfg_max_read_req=dut.cfg_max_read_req,
            # cfg_function_status
            # cfg_vf_status
            # cfg_function_power_state
            # cfg_vf_power_state
            # cfg_link_power_state
            # cfg_err_cor_out
            # cfg_err_nonfatal_out
            # cfg_err_fatal_out
            # cfg_local_error_out
            # cfg_local_error_valid
            # cfg_rx_pm_state
            # cfg_tx_pm_state
            # cfg_ltssm_state
            # cfg_rcb_status
            # cfg_obff_enable
            # cfg_pl_status_change
            # cfg_tph_requester_enable
            # cfg_tph_st_mode
            # cfg_vf_tph_requester_enable
            # cfg_vf_tph_st_mode

            # Configuration Received Message Interface
            # cfg_msg_received
            # cfg_msg_received_data
            # cfg_msg_received_type

            # Configuration Transmit Message Interface
            # cfg_msg_transmit
            # cfg_msg_transmit_type
            # cfg_msg_transmit_data
            # cfg_msg_transmit_done

            # Configuration Flow Control Interface
            cfg_fc_ph=dut.cfg_fc_ph,
            cfg_fc_pd=dut.cfg_fc_pd,
            cfg_fc_nph=dut.cfg_fc_nph,
            cfg_fc_npd=dut.cfg_fc_npd,
            cfg_fc_cplh=dut.cfg_fc_cplh,
            cfg_fc_cpld=dut.cfg_fc_cpld,
            cfg_fc_sel=dut.cfg_fc_sel,

            # Configuration Control Interface
            # cfg_hot_reset_in
            # cfg_hot_reset_out
            # cfg_config_space_enable
            # cfg_dsn
            # cfg_bus_number
            # cfg_ds_port_number
            # cfg_ds_bus_number
            # cfg_ds_device_number
            # cfg_ds_function_number
            # cfg_power_state_change_ack
            # cfg_power_state_change_interrupt
            cfg_err_cor_in=dut.status_error_cor,
            cfg_err_uncor_in=dut.status_error_uncor,
            # cfg_flr_in_process
            # cfg_flr_done
            # cfg_vf_flr_in_process
            # cfg_vf_flr_func_num
            # cfg_vf_flr_done
            # cfg_pm_aspm_l1_entry_reject
            # cfg_pm_aspm_tx_l0s_entry_disable
            # cfg_req_pm_transition_l23_ready
            # cfg_link_training_enable

            # Configuration Interrupt Controller Interface
            # cfg_interrupt_int
            # cfg_interrupt_sent
            # cfg_interrupt_pending
            cfg_interrupt_msi_enable=dut.cfg_interrupt_msi_enable,
            cfg_interrupt_msi_mmenable=dut.cfg_interrupt_msi_mmenable,
            cfg_interrupt_msi_mask_update=dut.cfg_interrupt_msi_mask_update,
            cfg_interrupt_msi_data=dut.cfg_interrupt_msi_data,
            # cfg_interrupt_msi_select=dut.cfg_interrupt_msi_select,
            cfg_interrupt_msi_int=dut.cfg_interrupt_msi_int,
            cfg_interrupt_msi_pending_status=dut.
            cfg_interrupt_msi_pending_status,
            cfg_interrupt_msi_pending_status_data_enable=dut.
            cfg_interrupt_msi_pending_status_data_enable,
            # cfg_interrupt_msi_pending_status_function_num=dut.cfg_interrupt_msi_pending_status_function_num,
            cfg_interrupt_msi_sent=dut.cfg_interrupt_msi_sent,
            cfg_interrupt_msi_fail=dut.cfg_interrupt_msi_fail,
            # cfg_interrupt_msix_enable
            # cfg_interrupt_msix_mask
            # cfg_interrupt_msix_vf_enable
            # cfg_interrupt_msix_vf_mask
            # cfg_interrupt_msix_address
            # cfg_interrupt_msix_data
            # cfg_interrupt_msix_int
            # cfg_interrupt_msix_vec_pending
            # cfg_interrupt_msix_vec_pending_status
            cfg_interrupt_msi_attr=dut.cfg_interrupt_msi_attr,
            cfg_interrupt_msi_tph_present=dut.cfg_interrupt_msi_tph_present,
            cfg_interrupt_msi_tph_type=dut.cfg_interrupt_msi_tph_type,
            # cfg_interrupt_msi_tph_st_tag=dut.cfg_interrupt_msi_tph_st_tag,
            # cfg_interrupt_msi_function_number=dut.cfg_interrupt_msi_function_number,

            # Configuration Extend Interface
            # cfg_ext_read_received
            # cfg_ext_write_received
            # cfg_ext_register_number
            # cfg_ext_function_number
            # cfg_ext_write_data
            # cfg_ext_write_byte_enable
            # cfg_ext_read_data
            # cfg_ext_read_data_valid
        )

        # self.dev.log.setLevel(logging.DEBUG)

        self.rc.make_port().connect(self.dev)

        self.driver = mqnic.Driver()

        self.dev.functions[0].msi_cap.msi_multiple_message_capable = 5

        self.dev.functions[0].configure_bar(
            0,
            2**len(dut.core_inst.core_pcie_inst.axil_ctrl_araddr),
            ext=True,
            prefetch=True)
        if hasattr(dut.core_inst.core_pcie_inst, 'pcie_app_ctrl'):
            self.dev.functions[0].configure_bar(
                2,
                2**len(dut.core_inst.core_pcie_inst.axil_app_ctrl_araddr),
                ext=True,
                prefetch=True)

        # Ethernet
        cocotb.start_soon(Clock(dut.qsfp_rx_clk, 3.102, units="ns").start())
        cocotb.start_soon(Clock(dut.qsfp_tx_clk, 3.102, units="ns").start())

        self.qsfp_mac = EthMac(
            tx_clk=dut.qsfp_tx_clk,
            tx_rst=dut.qsfp_tx_rst,
            tx_bus=AxiStreamBus.from_prefix(dut, "qsfp_tx_axis"),
            tx_ptp_time=dut.qsfp_tx_ptp_time,
            tx_ptp_ts=dut.qsfp_tx_ptp_ts,
            tx_ptp_ts_tag=dut.qsfp_tx_ptp_ts_tag,
            tx_ptp_ts_valid=dut.qsfp_tx_ptp_ts_valid,
            rx_clk=dut.qsfp_rx_clk,
            rx_rst=dut.qsfp_rx_rst,
            rx_bus=AxiStreamBus.from_prefix(dut, "qsfp_rx_axis"),
            rx_ptp_time=dut.qsfp_rx_ptp_time,
            ifg=12,
            speed=100e9)

        dut.qspi_dq_i.setimmediatevalue(0)

        self.cms_ram = AxiLiteRam(AxiLiteBus.from_prefix(dut, "m_axil_cms"),
                                  dut.m_axil_cms_clk,
                                  dut.m_axil_cms_rst,
                                  size=256 * 1024)

        self.loopback_enable = False
        cocotb.start_soon(self._run_loopback())
Exemplo n.º 6
0
def bench():

    # Parameters

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    clk_156mhz = Signal(bool(0))
    rst_156mhz = Signal(bool(0))
    clk_250mhz = Signal(bool(0))
    rst_250mhz = Signal(bool(0))
    user_sw = Signal(intbv(0)[2:])
    m_axis_rq_tready = Signal(bool(0))
    s_axis_rc_tdata = Signal(intbv(0)[256:])
    s_axis_rc_tkeep = Signal(intbv(0)[8:])
    s_axis_rc_tlast = Signal(bool(0))
    s_axis_rc_tuser = Signal(intbv(0)[75:])
    s_axis_rc_tvalid = Signal(bool(0))
    s_axis_cq_tdata = Signal(intbv(0)[256:])
    s_axis_cq_tkeep = Signal(intbv(0)[8:])
    s_axis_cq_tlast = Signal(bool(0))
    s_axis_cq_tuser = Signal(intbv(0)[88:])
    s_axis_cq_tvalid = Signal(bool(0))
    m_axis_cc_tready = Signal(bool(0))
    pcie_tfc_nph_av = Signal(intbv(15)[4:])
    pcie_tfc_npd_av = Signal(intbv(15)[4:])
    cfg_max_payload = Signal(intbv(0)[2:])
    cfg_max_read_req = Signal(intbv(0)[3:])
    cfg_mgmt_read_data = Signal(intbv(0)[32:])
    cfg_mgmt_read_write_done = Signal(bool(0))
    cfg_interrupt_msi_enable = Signal(intbv(0)[4:])
    cfg_interrupt_msi_mmenable = Signal(intbv(0)[12:])
    cfg_interrupt_msi_mask_update = Signal(bool(0))
    cfg_interrupt_msi_data = Signal(intbv(0)[32:])
    cfg_interrupt_msi_sent = Signal(bool(0))
    cfg_interrupt_msi_fail = Signal(bool(0))
    qsfp_0_tx_clk_0 = Signal(bool(0))
    qsfp_0_tx_rst_0 = Signal(bool(0))
    qsfp_0_rx_clk_0 = Signal(bool(0))
    qsfp_0_rx_rst_0 = Signal(bool(0))
    qsfp_0_rxd_0 = Signal(intbv(0)[64:])
    qsfp_0_rxc_0 = Signal(intbv(0)[8:])
    qsfp_0_tx_clk_1 = Signal(bool(0))
    qsfp_0_tx_rst_1 = Signal(bool(0))
    qsfp_0_rx_clk_1 = Signal(bool(0))
    qsfp_0_rx_rst_1 = Signal(bool(0))
    qsfp_0_rxd_1 = Signal(intbv(0)[64:])
    qsfp_0_rxc_1 = Signal(intbv(0)[8:])
    qsfp_0_tx_clk_2 = Signal(bool(0))
    qsfp_0_tx_rst_2 = Signal(bool(0))
    qsfp_0_rx_clk_2 = Signal(bool(0))
    qsfp_0_rx_rst_2 = Signal(bool(0))
    qsfp_0_rxd_2 = Signal(intbv(0)[64:])
    qsfp_0_rxc_2 = Signal(intbv(0)[8:])
    qsfp_0_tx_clk_3 = Signal(bool(0))
    qsfp_0_tx_rst_3 = Signal(bool(0))
    qsfp_0_rx_clk_3 = Signal(bool(0))
    qsfp_0_rx_rst_3 = Signal(bool(0))
    qsfp_0_rxd_3 = Signal(intbv(0)[64:])
    qsfp_0_rxc_3 = Signal(intbv(0)[8:])
    qsfp_0_modprs_l = Signal(bool(0))
    qsfp_1_tx_clk_0 = Signal(bool(0))
    qsfp_1_tx_rst_0 = Signal(bool(0))
    qsfp_1_rx_clk_0 = Signal(bool(0))
    qsfp_1_rx_rst_0 = Signal(bool(0))
    qsfp_1_rxd_0 = Signal(intbv(0)[64:])
    qsfp_1_rxc_0 = Signal(intbv(0)[8:])
    qsfp_1_tx_clk_1 = Signal(bool(0))
    qsfp_1_tx_rst_1 = Signal(bool(0))
    qsfp_1_rx_clk_1 = Signal(bool(0))
    qsfp_1_rx_rst_1 = Signal(bool(0))
    qsfp_1_rxd_1 = Signal(intbv(0)[64:])
    qsfp_1_rxc_1 = Signal(intbv(0)[8:])
    qsfp_1_tx_clk_2 = Signal(bool(0))
    qsfp_1_tx_rst_2 = Signal(bool(0))
    qsfp_1_rx_clk_2 = Signal(bool(0))
    qsfp_1_rx_rst_2 = Signal(bool(0))
    qsfp_1_rxd_2 = Signal(intbv(0)[64:])
    qsfp_1_rxc_2 = Signal(intbv(0)[8:])
    qsfp_1_tx_clk_3 = Signal(bool(0))
    qsfp_1_tx_rst_3 = Signal(bool(0))
    qsfp_1_rx_clk_3 = Signal(bool(0))
    qsfp_1_rx_rst_3 = Signal(bool(0))
    qsfp_1_rxd_3 = Signal(intbv(0)[64:])
    qsfp_1_rxc_3 = Signal(intbv(0)[8:])
    qsfp_1_modprs_l = Signal(bool(0))
    qsfp_int_l = Signal(bool(0))
    qsfp_i2c_scl_i = Signal(bool(1))
    qsfp_i2c_sda_i = Signal(bool(1))
    eeprom_i2c_scl_i = Signal(bool(1))
    eeprom_i2c_sda_i = Signal(bool(1))

    # Outputs
    user_led_g = Signal(intbv(0)[2:])
    user_led_r = Signal(bool(0))
    front_led = Signal(intbv(0)[2:])
    m_axis_rq_tdata = Signal(intbv(0)[256:])
    m_axis_rq_tkeep = Signal(intbv(0)[8:])
    m_axis_rq_tlast = Signal(bool(0))
    m_axis_rq_tuser = Signal(intbv(0)[62:])
    m_axis_rq_tvalid = Signal(bool(0))
    s_axis_rc_tready = Signal(bool(0))
    s_axis_cq_tready = Signal(bool(0))
    m_axis_cc_tdata = Signal(intbv(0)[256:])
    m_axis_cc_tkeep = Signal(intbv(0)[8:])
    m_axis_cc_tlast = Signal(bool(0))
    m_axis_cc_tuser = Signal(intbv(0)[33:])
    m_axis_cc_tvalid = Signal(bool(0))
    status_error_cor = Signal(bool(0))
    status_error_uncor = Signal(bool(0))
    cfg_mgmt_addr = Signal(intbv(0)[10:])
    cfg_mgmt_function_number = Signal(intbv(0)[8:])
    cfg_mgmt_write = Signal(bool(0))
    cfg_mgmt_write_data = Signal(intbv(0)[32:])
    cfg_mgmt_byte_enable = Signal(intbv(0)[4:])
    cfg_mgmt_read = Signal(bool(0))
    cfg_interrupt_msi_int = Signal(intbv(0)[32:])
    cfg_interrupt_msi_pending_status = Signal(intbv(0)[32:])
    cfg_interrupt_msi_select = Signal(intbv(0)[2:])
    cfg_interrupt_msi_pending_status_function_num = Signal(intbv(0)[2:])
    cfg_interrupt_msi_pending_status_data_enable = Signal(bool(0))
    cfg_interrupt_msi_attr = Signal(intbv(0)[3:])
    cfg_interrupt_msi_tph_present = Signal(bool(0))
    cfg_interrupt_msi_tph_type = Signal(intbv(0)[2:])
    cfg_interrupt_msi_tph_st_tag = Signal(intbv(0)[8:])
    cfg_interrupt_msi_function_number = Signal(intbv(0)[8:])
    qsfp_0_txd_0 = Signal(intbv(0)[64:])
    qsfp_0_txc_0 = Signal(intbv(0)[8:])
    qsfp_0_txd_1 = Signal(intbv(0)[64:])
    qsfp_0_txc_1 = Signal(intbv(0)[8:])
    qsfp_0_txd_2 = Signal(intbv(0)[64:])
    qsfp_0_txc_2 = Signal(intbv(0)[8:])
    qsfp_0_txd_3 = Signal(intbv(0)[64:])
    qsfp_0_txc_3 = Signal(intbv(0)[8:])
    qsfp_0_sel_l = Signal(bool(1))
    qsfp_1_txd_0 = Signal(intbv(0)[64:])
    qsfp_1_txc_0 = Signal(intbv(0)[8:])
    qsfp_1_txd_1 = Signal(intbv(0)[64:])
    qsfp_1_txc_1 = Signal(intbv(0)[8:])
    qsfp_1_txd_2 = Signal(intbv(0)[64:])
    qsfp_1_txc_2 = Signal(intbv(0)[8:])
    qsfp_1_txd_3 = Signal(intbv(0)[64:])
    qsfp_1_txc_3 = Signal(intbv(0)[8:])
    qsfp_1_sel_l = Signal(bool(1))
    qsfp_reset_l = Signal(bool(1))
    qsfp_i2c_scl_o = Signal(bool(1))
    qsfp_i2c_scl_t = Signal(bool(1))
    qsfp_i2c_sda_o = Signal(bool(1))
    qsfp_i2c_sda_t = Signal(bool(1))
    eeprom_i2c_scl_o = Signal(bool(1))
    eeprom_i2c_scl_t = Signal(bool(1))
    eeprom_i2c_sda_o = Signal(bool(1))
    eeprom_i2c_sda_t = Signal(bool(1))
    eeprom_wp = Signal(bool(1))

    # sources and sinks
    qsfp_0_0_source = xgmii_ep.XGMIISource()
    qsfp_0_0_source_logic = qsfp_0_0_source.create_logic(
        qsfp_0_rx_clk_0,
        qsfp_0_rx_rst_0,
        txd=qsfp_0_rxd_0,
        txc=qsfp_0_rxc_0,
        name='qsfp_0_0_source')

    qsfp_0_0_sink = xgmii_ep.XGMIISink()
    qsfp_0_0_sink_logic = qsfp_0_0_sink.create_logic(qsfp_0_tx_clk_0,
                                                     qsfp_0_tx_rst_0,
                                                     rxd=qsfp_0_txd_0,
                                                     rxc=qsfp_0_txc_0,
                                                     name='qsfp_0_0_sink')

    qsfp_0_1_source = xgmii_ep.XGMIISource()
    qsfp_0_1_source_logic = qsfp_0_1_source.create_logic(
        qsfp_0_rx_clk_1,
        qsfp_0_rx_rst_1,
        txd=qsfp_0_rxd_1,
        txc=qsfp_0_rxc_1,
        name='qsfp_0_1_source')

    qsfp_0_1_sink = xgmii_ep.XGMIISink()
    qsfp_0_1_sink_logic = qsfp_0_1_sink.create_logic(qsfp_0_tx_clk_1,
                                                     qsfp_0_tx_rst_1,
                                                     rxd=qsfp_0_txd_1,
                                                     rxc=qsfp_0_txc_1,
                                                     name='qsfp_0_1_sink')

    qsfp_0_2_source = xgmii_ep.XGMIISource()
    qsfp_0_2_source_logic = qsfp_0_2_source.create_logic(
        qsfp_0_rx_clk_2,
        qsfp_0_rx_rst_2,
        txd=qsfp_0_rxd_2,
        txc=qsfp_0_rxc_2,
        name='qsfp_0_2_source')

    qsfp_0_2_sink = xgmii_ep.XGMIISink()
    qsfp_0_2_sink_logic = qsfp_0_2_sink.create_logic(qsfp_0_tx_clk_2,
                                                     qsfp_0_tx_rst_2,
                                                     rxd=qsfp_0_txd_2,
                                                     rxc=qsfp_0_txc_2,
                                                     name='qsfp_0_2_sink')

    qsfp_0_3_source = xgmii_ep.XGMIISource()
    qsfp_0_3_source_logic = qsfp_0_3_source.create_logic(
        qsfp_0_rx_clk_3,
        qsfp_0_rx_rst_3,
        txd=qsfp_0_rxd_3,
        txc=qsfp_0_rxc_3,
        name='qsfp_0_3_source')

    qsfp_0_3_sink = xgmii_ep.XGMIISink()
    qsfp_0_3_sink_logic = qsfp_0_3_sink.create_logic(qsfp_0_tx_clk_3,
                                                     qsfp_0_tx_rst_3,
                                                     rxd=qsfp_0_txd_3,
                                                     rxc=qsfp_0_txc_3,
                                                     name='qsfp_0_3_sink')

    qsfp_1_0_source = xgmii_ep.XGMIISource()
    qsfp_1_0_source_logic = qsfp_1_0_source.create_logic(
        qsfp_1_rx_clk_0,
        qsfp_1_rx_rst_0,
        txd=qsfp_1_rxd_0,
        txc=qsfp_1_rxc_0,
        name='qsfp_1_0_source')

    qsfp_1_0_sink = xgmii_ep.XGMIISink()
    qsfp_1_0_sink_logic = qsfp_1_0_sink.create_logic(qsfp_1_tx_clk_0,
                                                     qsfp_1_tx_rst_0,
                                                     rxd=qsfp_1_txd_0,
                                                     rxc=qsfp_1_txc_0,
                                                     name='qsfp_1_0_sink')

    qsfp_1_1_source = xgmii_ep.XGMIISource()
    qsfp_1_1_source_logic = qsfp_1_1_source.create_logic(
        qsfp_1_rx_clk_1,
        qsfp_1_rx_rst_1,
        txd=qsfp_1_rxd_1,
        txc=qsfp_1_rxc_1,
        name='qsfp_1_1_source')

    qsfp_1_1_sink = xgmii_ep.XGMIISink()
    qsfp_1_1_sink_logic = qsfp_1_1_sink.create_logic(qsfp_1_tx_clk_1,
                                                     qsfp_1_tx_rst_1,
                                                     rxd=qsfp_1_txd_1,
                                                     rxc=qsfp_1_txc_1,
                                                     name='qsfp_1_1_sink')

    qsfp_1_2_source = xgmii_ep.XGMIISource()
    qsfp_1_2_source_logic = qsfp_1_2_source.create_logic(
        qsfp_1_rx_clk_2,
        qsfp_1_rx_rst_2,
        txd=qsfp_1_rxd_2,
        txc=qsfp_1_rxc_2,
        name='qsfp_1_2_source')

    qsfp_1_2_sink = xgmii_ep.XGMIISink()
    qsfp_1_2_sink_logic = qsfp_1_2_sink.create_logic(qsfp_1_tx_clk_2,
                                                     qsfp_1_tx_rst_2,
                                                     rxd=qsfp_1_txd_2,
                                                     rxc=qsfp_1_txc_2,
                                                     name='qsfp_1_2_sink')

    qsfp_1_3_source = xgmii_ep.XGMIISource()
    qsfp_1_3_source_logic = qsfp_1_3_source.create_logic(
        qsfp_1_rx_clk_3,
        qsfp_1_rx_rst_3,
        txd=qsfp_1_rxd_3,
        txc=qsfp_1_rxc_3,
        name='qsfp_1_3_source')

    qsfp_1_3_sink = xgmii_ep.XGMIISink()
    qsfp_1_3_sink_logic = qsfp_1_3_sink.create_logic(qsfp_1_tx_clk_3,
                                                     qsfp_1_tx_rst_3,
                                                     rxd=qsfp_1_txd_3,
                                                     rxc=qsfp_1_txc_3,
                                                     name='qsfp_1_3_sink')

    # Clock and Reset Interface
    user_clk = Signal(bool(0))
    user_reset = Signal(bool(0))
    sys_clk = Signal(bool(0))
    sys_reset = Signal(bool(0))

    # PCIe devices
    rc = pcie.RootComplex()

    rc.max_payload_size = 0x1  # 256 bytes
    rc.max_read_request_size = 0x5  # 4096 bytes

    driver = mqnic.Driver(rc)

    dev = pcie_usp.UltrascalePlusPCIe()

    dev.pcie_generation = 3
    dev.pcie_link_width = 8
    dev.user_clock_frequency = 256e6

    dev.functions[0].msi_multiple_message_capable = 5

    dev.functions[0].configure_bar(0, 16 * 1024 * 1024)
    dev.functions[0].configure_bar(1, 16 * 1024 * 1024)

    rc.make_port().connect(dev)

    cq_pause = Signal(bool(0))
    cc_pause = Signal(bool(0))
    rq_pause = Signal(bool(0))
    rc_pause = Signal(bool(0))

    pcie_logic = dev.create_logic(
        # Completer reQuest Interface
        m_axis_cq_tdata=s_axis_cq_tdata,
        m_axis_cq_tuser=s_axis_cq_tuser,
        m_axis_cq_tlast=s_axis_cq_tlast,
        m_axis_cq_tkeep=s_axis_cq_tkeep,
        m_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cq_tready=s_axis_cq_tready,
        #pcie_cq_np_req=pcie_cq_np_req,
        pcie_cq_np_req=Signal(intbv(3)[2:]),
        #pcie_cq_np_req_count=pcie_cq_np_req_count,

        # Completer Completion Interface
        s_axis_cc_tdata=m_axis_cc_tdata,
        s_axis_cc_tuser=m_axis_cc_tuser,
        s_axis_cc_tlast=m_axis_cc_tlast,
        s_axis_cc_tkeep=m_axis_cc_tkeep,
        s_axis_cc_tvalid=m_axis_cc_tvalid,
        s_axis_cc_tready=m_axis_cc_tready,

        # Requester reQuest Interface
        s_axis_rq_tdata=m_axis_rq_tdata,
        s_axis_rq_tuser=m_axis_rq_tuser,
        s_axis_rq_tlast=m_axis_rq_tlast,
        s_axis_rq_tkeep=m_axis_rq_tkeep,
        s_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rq_tready=m_axis_rq_tready,
        #pcie_rq_seq_num0=pcie_rq_seq_num0,
        #pcie_rq_seq_num_vld0=pcie_rq_seq_num_vld0,
        #pcie_rq_seq_num1=pcie_rq_seq_num1,
        #pcie_rq_seq_num_vld1=pcie_rq_seq_num_vld1,
        #pcie_rq_tag0=pcie_rq_tag0,
        #pcie_rq_tag1=pcie_rq_tag1,
        #pcie_rq_tag_av=pcie_rq_tag_av,
        #pcie_rq_tag_vld0=pcie_rq_tag_vld0,
        #pcie_rq_tag_vld1=pcie_rq_tag_vld1,

        # Requester Completion Interface
        m_axis_rc_tdata=s_axis_rc_tdata,
        m_axis_rc_tuser=s_axis_rc_tuser,
        m_axis_rc_tlast=s_axis_rc_tlast,
        m_axis_rc_tkeep=s_axis_rc_tkeep,
        m_axis_rc_tvalid=s_axis_rc_tvalid,
        m_axis_rc_tready=s_axis_rc_tready,

        # Transmit Flow Control Interface
        #pcie_tfc_nph_av=pcie_tfc_nph_av,
        #pcie_tfc_npd_av=pcie_tfc_npd_av,

        # Configuration Management Interface
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_function_number=cfg_mgmt_function_number,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        #cfg_mgmt_debug_access=cfg_mgmt_debug_access,

        # Configuration Status Interface
        #cfg_phy_link_down=cfg_phy_link_down,
        #cfg_phy_link_status=cfg_phy_link_status,
        #cfg_negotiated_width=cfg_negotiated_width,
        #cfg_current_speed=cfg_current_speed,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        #cfg_function_status=cfg_function_status,
        #cfg_vf_status=cfg_vf_status,
        #cfg_function_power_state=cfg_function_power_state,
        #cfg_vf_power_state=cfg_vf_power_state,
        #cfg_link_power_state=cfg_link_power_state,
        #cfg_err_cor_out=cfg_err_cor_out,
        #cfg_err_nonfatal_out=cfg_err_nonfatal_out,
        #cfg_err_fatal_out=cfg_err_fatal_out,
        #cfg_local_err_out=cfg_local_err_out,
        #cfg_local_err_valid=cfg_local_err_valid,
        #cfg_rx_pm_state=cfg_rx_pm_state,
        #cfg_tx_pm_state=cfg_tx_pm_state,
        #cfg_ltssm_state=cfg_ltssm_state,
        #cfg_rcb_status=cfg_rcb_status,
        #cfg_obff_enable=cfg_obff_enable,
        #cfg_pl_status_change=cfg_pl_status_change,
        #cfg_tph_requester_enable=cfg_tph_requester_enable,
        #cfg_tph_st_mode=cfg_tph_st_mode,
        #cfg_vf_tph_requester_enable=cfg_vf_tph_requester_enable,
        #cfg_vf_tph_st_mode=cfg_vf_tph_st_mode,

        # Configuration Received Message Interface
        #cfg_msg_received=cfg_msg_received,
        #cfg_msg_received_data=cfg_msg_received_data,
        #cfg_msg_received_type=cfg_msg_received_type,

        # Configuration Transmit Message Interface
        #cfg_msg_transmit=cfg_msg_transmit,
        #cfg_msg_transmit_type=cfg_msg_transmit_type,
        #cfg_msg_transmit_data=cfg_msg_transmit_data,
        #cfg_msg_transmit_done=cfg_msg_transmit_done,

        # Configuration Flow Control Interface
        #cfg_fc_ph=cfg_fc_ph,
        #cfg_fc_pd=cfg_fc_pd,
        #cfg_fc_nph=cfg_fc_nph,
        #cfg_fc_npd=cfg_fc_npd,
        #cfg_fc_cplh=cfg_fc_cplh,
        #cfg_fc_cpld=cfg_fc_cpld,
        #cfg_fc_sel=cfg_fc_sel,

        # Configuration Control Interface
        #cfg_hot_reset_in=cfg_hot_reset_in,
        #cfg_hot_reset_out=cfg_hot_reset_out,
        #cfg_config_space_enable=cfg_config_space_enable,
        #cfg_dsn=cfg_dsn,
        #cfg_ds_port_number=cfg_ds_port_number,
        #cfg_ds_bus_number=cfg_ds_bus_number,
        #cfg_ds_device_number=cfg_ds_device_number,
        #cfg_ds_function_number=cfg_ds_function_number,
        #cfg_power_state_change_ack=cfg_power_state_change_ack,
        #cfg_power_state_change_interrupt=cfg_power_state_change_interrupt,
        cfg_err_cor_in=status_error_cor,
        cfg_err_uncor_in=status_error_uncor,
        #cfg_flr_done=cfg_flr_done,
        #cfg_vf_flr_done=cfg_vf_flr_done,
        #cfg_flr_in_process=cfg_flr_in_process,
        #cfg_vf_flr_in_process=cfg_vf_flr_in_process,
        #cfg_req_pm_transition_l23_ready=cfg_req_pm_transition_l23_ready,
        #cfg_link_training_enable=cfg_link_training_enable,

        # Configuration Interrupt Controller Interface
        #cfg_interrupt_int=cfg_interrupt_int,
        #cfg_interrupt_sent=cfg_interrupt_sent,
        #cfg_interrupt_pending=cfg_interrupt_pending,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_pending_status_data_enable=
        cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_pending_status_function_num=
        cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        #cfg_interrupt_msix_enable=cfg_interrupt_msix_enable,
        #cfg_interrupt_msix_mask=cfg_interrupt_msix_mask,
        #cfg_interrupt_msix_vf_enable=cfg_interrupt_msix_vf_enable,
        #cfg_interrupt_msix_vf_mask=cfg_interrupt_msix_vf_mask,
        #cfg_interrupt_msix_address=cfg_interrupt_msix_address,
        #cfg_interrupt_msix_data=cfg_interrupt_msix_data,
        #cfg_interrupt_msix_int=cfg_interrupt_msix_int,
        #cfg_interrupt_msix_vec_pending=cfg_interrupt_msix_vec_pending,
        #cfg_interrupt_msix_vec_pending_status=cfg_interrupt_msix_vec_pending_status,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,

        # Configuration Extend Interface
        #cfg_ext_read_received=cfg_ext_read_received,
        #cfg_ext_write_received=cfg_ext_write_received,
        #cfg_ext_register_number=cfg_ext_register_number,
        #cfg_ext_function_number=cfg_ext_function_number,
        #cfg_ext_write_data=cfg_ext_write_data,
        #cfg_ext_write_byte_enable=cfg_ext_write_byte_enable,
        #cfg_ext_read_data=cfg_ext_read_data,
        #cfg_ext_read_data_valid=cfg_ext_read_data_valid,

        # Clock and Reset Interface
        user_clk=user_clk,
        user_reset=user_reset,
        sys_clk=sys_clk,
        sys_clk_gt=sys_clk,
        sys_reset=sys_reset,
        #phy_rdy_out=phy_rdy_out,
        cq_pause=cq_pause,
        cc_pause=cc_pause,
        rq_pause=rq_pause,
        rc_pause=rc_pause)

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation(
        "vvp -m myhdl %s.vvp -lxt2" % testbench,
        clk=clk,
        rst=rst,
        current_test=current_test,
        clk_156mhz=clk_156mhz,
        rst_156mhz=rst_156mhz,
        clk_250mhz=user_clk,
        rst_250mhz=user_reset,
        user_led_g=user_led_g,
        user_led_r=user_led_r,
        front_led=front_led,
        user_sw=user_sw,
        m_axis_rq_tdata=m_axis_rq_tdata,
        m_axis_rq_tkeep=m_axis_rq_tkeep,
        m_axis_rq_tlast=m_axis_rq_tlast,
        m_axis_rq_tready=m_axis_rq_tready,
        m_axis_rq_tuser=m_axis_rq_tuser,
        m_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rc_tdata=s_axis_rc_tdata,
        s_axis_rc_tkeep=s_axis_rc_tkeep,
        s_axis_rc_tlast=s_axis_rc_tlast,
        s_axis_rc_tready=s_axis_rc_tready,
        s_axis_rc_tuser=s_axis_rc_tuser,
        s_axis_rc_tvalid=s_axis_rc_tvalid,
        s_axis_cq_tdata=s_axis_cq_tdata,
        s_axis_cq_tkeep=s_axis_cq_tkeep,
        s_axis_cq_tlast=s_axis_cq_tlast,
        s_axis_cq_tready=s_axis_cq_tready,
        s_axis_cq_tuser=s_axis_cq_tuser,
        s_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cc_tdata=m_axis_cc_tdata,
        m_axis_cc_tkeep=m_axis_cc_tkeep,
        m_axis_cc_tlast=m_axis_cc_tlast,
        m_axis_cc_tready=m_axis_cc_tready,
        m_axis_cc_tuser=m_axis_cc_tuser,
        m_axis_cc_tvalid=m_axis_cc_tvalid,
        pcie_tfc_nph_av=pcie_tfc_nph_av,
        pcie_tfc_npd_av=pcie_tfc_npd_av,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_function_number=cfg_mgmt_function_number,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_pending_status_function_num=
        cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_pending_status_data_enable=
        cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,
        status_error_cor=status_error_cor,
        status_error_uncor=status_error_uncor,
        qsfp_0_tx_clk_0=qsfp_0_tx_clk_0,
        qsfp_0_tx_rst_0=qsfp_0_tx_rst_0,
        qsfp_0_txd_0=qsfp_0_txd_0,
        qsfp_0_txc_0=qsfp_0_txc_0,
        qsfp_0_rx_clk_0=qsfp_0_rx_clk_0,
        qsfp_0_rx_rst_0=qsfp_0_rx_rst_0,
        qsfp_0_rxd_0=qsfp_0_rxd_0,
        qsfp_0_rxc_0=qsfp_0_rxc_0,
        qsfp_0_tx_clk_1=qsfp_0_tx_clk_1,
        qsfp_0_tx_rst_1=qsfp_0_tx_rst_1,
        qsfp_0_txd_1=qsfp_0_txd_1,
        qsfp_0_txc_1=qsfp_0_txc_1,
        qsfp_0_rx_clk_1=qsfp_0_rx_clk_1,
        qsfp_0_rx_rst_1=qsfp_0_rx_rst_1,
        qsfp_0_rxd_1=qsfp_0_rxd_1,
        qsfp_0_rxc_1=qsfp_0_rxc_1,
        qsfp_0_tx_clk_2=qsfp_0_tx_clk_2,
        qsfp_0_tx_rst_2=qsfp_0_tx_rst_2,
        qsfp_0_txd_2=qsfp_0_txd_2,
        qsfp_0_txc_2=qsfp_0_txc_2,
        qsfp_0_rx_clk_2=qsfp_0_rx_clk_2,
        qsfp_0_rx_rst_2=qsfp_0_rx_rst_2,
        qsfp_0_rxd_2=qsfp_0_rxd_2,
        qsfp_0_rxc_2=qsfp_0_rxc_2,
        qsfp_0_tx_clk_3=qsfp_0_tx_clk_3,
        qsfp_0_tx_rst_3=qsfp_0_tx_rst_3,
        qsfp_0_txd_3=qsfp_0_txd_3,
        qsfp_0_txc_3=qsfp_0_txc_3,
        qsfp_0_rx_clk_3=qsfp_0_rx_clk_3,
        qsfp_0_rx_rst_3=qsfp_0_rx_rst_3,
        qsfp_0_rxd_3=qsfp_0_rxd_3,
        qsfp_0_rxc_3=qsfp_0_rxc_3,
        qsfp_0_modprs_l=qsfp_0_modprs_l,
        qsfp_0_sel_l=qsfp_0_sel_l,
        qsfp_1_tx_clk_0=qsfp_1_tx_clk_0,
        qsfp_1_tx_rst_0=qsfp_1_tx_rst_0,
        qsfp_1_txd_0=qsfp_1_txd_0,
        qsfp_1_txc_0=qsfp_1_txc_0,
        qsfp_1_rx_clk_0=qsfp_1_rx_clk_0,
        qsfp_1_rx_rst_0=qsfp_1_rx_rst_0,
        qsfp_1_rxd_0=qsfp_1_rxd_0,
        qsfp_1_rxc_0=qsfp_1_rxc_0,
        qsfp_1_tx_clk_1=qsfp_1_tx_clk_1,
        qsfp_1_tx_rst_1=qsfp_1_tx_rst_1,
        qsfp_1_txd_1=qsfp_1_txd_1,
        qsfp_1_txc_1=qsfp_1_txc_1,
        qsfp_1_rx_clk_1=qsfp_1_rx_clk_1,
        qsfp_1_rx_rst_1=qsfp_1_rx_rst_1,
        qsfp_1_rxd_1=qsfp_1_rxd_1,
        qsfp_1_rxc_1=qsfp_1_rxc_1,
        qsfp_1_tx_clk_2=qsfp_1_tx_clk_2,
        qsfp_1_tx_rst_2=qsfp_1_tx_rst_2,
        qsfp_1_txd_2=qsfp_1_txd_2,
        qsfp_1_txc_2=qsfp_1_txc_2,
        qsfp_1_rx_clk_2=qsfp_1_rx_clk_2,
        qsfp_1_rx_rst_2=qsfp_1_rx_rst_2,
        qsfp_1_rxd_2=qsfp_1_rxd_2,
        qsfp_1_rxc_2=qsfp_1_rxc_2,
        qsfp_1_tx_clk_3=qsfp_1_tx_clk_3,
        qsfp_1_tx_rst_3=qsfp_1_tx_rst_3,
        qsfp_1_txd_3=qsfp_1_txd_3,
        qsfp_1_txc_3=qsfp_1_txc_3,
        qsfp_1_rx_clk_3=qsfp_1_rx_clk_3,
        qsfp_1_rx_rst_3=qsfp_1_rx_rst_3,
        qsfp_1_rxd_3=qsfp_1_rxd_3,
        qsfp_1_rxc_3=qsfp_1_rxc_3,
        qsfp_1_modprs_l=qsfp_1_modprs_l,
        qsfp_1_sel_l=qsfp_1_sel_l,
        qsfp_reset_l=qsfp_reset_l,
        qsfp_int_l=qsfp_int_l,
        qsfp_i2c_scl_i=qsfp_i2c_scl_i,
        qsfp_i2c_scl_o=qsfp_i2c_scl_o,
        qsfp_i2c_scl_t=qsfp_i2c_scl_t,
        qsfp_i2c_sda_i=qsfp_i2c_sda_i,
        qsfp_i2c_sda_o=qsfp_i2c_sda_o,
        qsfp_i2c_sda_t=qsfp_i2c_sda_t,
        eeprom_i2c_scl_i=eeprom_i2c_scl_i,
        eeprom_i2c_scl_o=eeprom_i2c_scl_o,
        eeprom_i2c_scl_t=eeprom_i2c_scl_t,
        eeprom_i2c_sda_i=eeprom_i2c_sda_i,
        eeprom_i2c_sda_o=eeprom_i2c_sda_o,
        eeprom_i2c_sda_t=eeprom_i2c_sda_t,
        eeprom_wp=eeprom_wp)

    @always(delay(5))
    def clkgen():
        clk.next = not clk

    @always(delay(3))
    def qsfp_clkgen():
        qsfp_0_tx_clk_0.next = not qsfp_0_tx_clk_0
        qsfp_0_rx_clk_0.next = not qsfp_0_rx_clk_0
        qsfp_0_tx_clk_1.next = not qsfp_0_tx_clk_1
        qsfp_0_rx_clk_1.next = not qsfp_0_rx_clk_1
        qsfp_0_tx_clk_2.next = not qsfp_0_tx_clk_2
        qsfp_0_rx_clk_2.next = not qsfp_0_rx_clk_2
        qsfp_0_tx_clk_3.next = not qsfp_0_tx_clk_3
        qsfp_0_rx_clk_3.next = not qsfp_0_rx_clk_3
        qsfp_1_tx_clk_0.next = not qsfp_1_tx_clk_0
        qsfp_1_rx_clk_0.next = not qsfp_1_rx_clk_0
        qsfp_1_tx_clk_1.next = not qsfp_1_tx_clk_1
        qsfp_1_rx_clk_1.next = not qsfp_1_rx_clk_1
        qsfp_1_tx_clk_2.next = not qsfp_1_tx_clk_2
        qsfp_1_rx_clk_2.next = not qsfp_1_rx_clk_2
        qsfp_1_tx_clk_3.next = not qsfp_1_tx_clk_3
        qsfp_1_rx_clk_3.next = not qsfp_1_rx_clk_3

    @always_comb
    def clk_logic():
        sys_clk.next = clk
        sys_reset.next = not rst

    loopback_enable = Signal(bool(0))

    @instance
    def loopback():
        while True:

            yield clk.posedge

            if loopback_enable:
                if not qsfp_0_0_sink.empty():
                    pkt = qsfp_0_0_sink.recv()
                    qsfp_0_0_source.send(pkt)
                if not qsfp_0_1_sink.empty():
                    pkt = qsfp_0_1_sink.recv()
                    qsfp_0_1_source.send(pkt)
                if not qsfp_0_2_sink.empty():
                    pkt = qsfp_0_2_sink.recv()
                    qsfp_0_2_source.send(pkt)
                if not qsfp_0_3_sink.empty():
                    pkt = qsfp_0_3_sink.recv()
                    qsfp_0_3_source.send(pkt)
                if not qsfp_1_0_sink.empty():
                    pkt = qsfp_1_0_sink.recv()
                    qsfp_1_0_source.send(pkt)
                if not qsfp_1_1_sink.empty():
                    pkt = qsfp_1_1_sink.recv()
                    qsfp_1_1_source.send(pkt)
                if not qsfp_1_2_sink.empty():
                    pkt = qsfp_1_2_sink.recv()
                    qsfp_1_2_source.send(pkt)
                if not qsfp_1_3_sink.empty():
                    pkt = qsfp_1_3_sink.recv()
                    qsfp_1_3_source.send(pkt)

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        qsfp_0_tx_rst_0.next = 1
        qsfp_0_rx_rst_0.next = 1
        qsfp_0_tx_rst_1.next = 1
        qsfp_0_rx_rst_1.next = 1
        qsfp_0_tx_rst_2.next = 1
        qsfp_0_rx_rst_2.next = 1
        qsfp_0_tx_rst_3.next = 1
        qsfp_0_rx_rst_3.next = 1
        qsfp_1_tx_rst_0.next = 1
        qsfp_1_rx_rst_0.next = 1
        qsfp_1_tx_rst_1.next = 1
        qsfp_1_rx_rst_1.next = 1
        qsfp_1_tx_rst_2.next = 1
        qsfp_1_rx_rst_2.next = 1
        qsfp_1_tx_rst_3.next = 1
        qsfp_1_rx_rst_3.next = 1
        yield clk.posedge
        yield delay(100)
        rst.next = 0
        qsfp_0_tx_rst_0.next = 0
        qsfp_0_rx_rst_0.next = 0
        qsfp_0_tx_rst_1.next = 0
        qsfp_0_rx_rst_1.next = 0
        qsfp_0_tx_rst_2.next = 0
        qsfp_0_rx_rst_2.next = 0
        qsfp_0_tx_rst_3.next = 0
        qsfp_0_rx_rst_3.next = 0
        qsfp_1_tx_rst_0.next = 0
        qsfp_1_rx_rst_0.next = 0
        qsfp_1_tx_rst_1.next = 0
        qsfp_1_rx_rst_1.next = 0
        qsfp_1_tx_rst_2.next = 0
        qsfp_1_rx_rst_2.next = 0
        qsfp_1_tx_rst_3.next = 0
        qsfp_1_rx_rst_3.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # testbench stimulus

        current_tag = 1

        yield clk.posedge
        print("test 1: enumeration")
        current_test.next = 1

        yield rc.enumerate(enable_bus_mastering=True, configure_msi=True)

        dev_pf0_bar0 = dev.functions[0].bar[0] & 0xfffffffc
        dev_pf0_bar1 = dev.functions[0].bar[1] & 0xfffffffc

        yield delay(100)

        yield clk.posedge
        print("test 2: init NIC")
        current_test.next = 2

        #data = yield from rc.mem_read(dev_pf0_bar0+0x20000+0x10, 4);
        #print(data)

        #yield delay(1000)

        #raise StopSimulation

        yield from driver.init_dev(dev.functions[0].get_id())
        yield from driver.interfaces[0].open()
        #yield from driver.interfaces[1].open()

        # enable queues
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x0200,
            0xffffffff)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x0300,
            0xffffffff)

        yield from rc.mem_read(driver.hw_addr,
                               4)  # wait for all writes to complete

        yield delay(100)

        yield clk.posedge
        print("test 3: send and receive a packet")
        current_test.next = 3

        # test bad packet
        #qsfp_0_0_source.send(b'\x55\x55\x55\x55\x55\xd5'+bytearray(range(128)))

        data = bytearray([x % 256 for x in range(1024)])

        yield from driver.interfaces[0].start_xmit(data, 0)

        yield qsfp_0_0_sink.wait()

        pkt = qsfp_0_0_sink.recv()
        print(pkt)

        qsfp_0_0_source.send(pkt)

        yield driver.interfaces[0].wait()

        pkt = driver.interfaces[0].recv()

        print(pkt)
        assert frame_checksum(pkt.data) == pkt.rx_checksum

        # yield from driver.interfaces[1].start_xmit(data, 0)

        # yield qsfp_1_0_sink.wait()

        # pkt = qsfp_1_0_sink.recv()
        # print(pkt)

        # qsfp_1_0_source.send(pkt)

        # yield driver.interfaces[1].wait()

        # pkt = driver.interfaces[1].recv()

        # print(pkt)
        # assert frame_checksum(pkt.data) == pkt.rx_checksum

        yield delay(100)

        yield clk.posedge
        print("test 4: checksum tests")
        current_test.next = 4

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80164
        test_frame.ip_dest_ip = 0xc0a80165
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray((x % 256 for x in range(256)))

        test_frame.set_udp_pseudo_header_checksum()

        axis_frame = test_frame.build_axis()

        yield from driver.interfaces[0].start_xmit(axis_frame.data, 0, 34, 6)

        yield qsfp_0_0_sink.wait()

        pkt = qsfp_0_0_sink.recv()
        print(pkt)

        qsfp_0_0_source.send(pkt)

        yield driver.interfaces[0].wait()

        pkt = driver.interfaces[0].recv()

        print(pkt)

        assert pkt.rx_checksum == frame_checksum(pkt.data)

        check_frame = udp_ep.UDPFrame()
        check_frame.parse_axis(pkt.data)

        assert check_frame.verify_checksums()

        yield delay(100)

        yield clk.posedge
        print("test 5: multiple small packets")
        current_test.next = 5

        count = 64

        pkts = [
            bytearray([(x + k) % 256 for x in range(64)]) for k in range(count)
        ]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        yield clk.posedge
        print("test 6: multiple large packets")
        current_test.next = 6

        count = 64

        pkts = [
            bytearray([(x + k) % 256 for x in range(1514)])
            for k in range(count)
        ]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(1000)

        yield clk.posedge
        print("test 7: TDMA")
        current_test.next = 7

        count = 16

        pkts = [
            bytearray([(x + k) % 256 for x in range(1514)])
            for k in range(count)
        ]

        loopback_enable.next = True

        # configure TDMA

        # configure TDMA scheduler
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00120,
            0)  # schedule period fns
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00124,
            40000)  # schedule period ns
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00128,
            0)  # schedule period sec (low)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x0012c,
            0)  # schedule period sec (high)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00130,
            0)  # timeslot period fns
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00134,
            10000)  # timeslot period ns
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00138,
            0)  # timeslot period sec (low)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x0013c,
            0)  # timeslot period sec (high)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00140,
            0)  # active period fns
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00144,
            5000)  # active period ns
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00148,
            0)  # active period sec (low)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x0014c,
            0)  # active period sec (high)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00110,
            0)  # schedule start fns
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00114,
            200000)  # schedule start ns
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00118,
            0)  # schedule start sec (low)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x0011c,
            0)  # schedule start sec (high)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00100,
            0x00000001)

        # enable queues
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00200,
            0xffffffff)
        # disable global enable
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x00300,
            0x00000000)

        # configure slots
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x10000,
            0x00000001)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x10100,
            0x00000002)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x10200,
            0x00000004)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].schedulers[0].hw_addr + 0x10300,
            0x00000008)

        yield from rc.mem_read(driver.hw_addr,
                               4)  # wait for all writes to complete

        # send packets
        for k in range(count):
            yield from driver.interfaces[0].start_xmit(pkts[k], k % 4)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            #assert pkt.data == pkts[k]
            #assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        raise StopSimulation

    return instances()
Exemplo n.º 7
0
def bench():

    # Parameters

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    clk_156mhz = Signal(bool(0))
    rst_156mhz = Signal(bool(0))
    clk_250mhz = Signal(bool(0))
    rst_250mhz = Signal(bool(0))
    btnu = Signal(bool(0))
    btnl = Signal(bool(0))
    btnd = Signal(bool(0))
    btnr = Signal(bool(0))
    btnc = Signal(bool(0))
    sw = Signal(intbv(0)[4:])
    i2c_scl_i = Signal(bool(1))
    i2c_sda_i = Signal(bool(1))
    m_axis_rq_tready = Signal(bool(0))
    s_axis_rc_tdata = Signal(intbv(0)[256:])
    s_axis_rc_tkeep = Signal(intbv(0)[8:])
    s_axis_rc_tlast = Signal(bool(0))
    s_axis_rc_tuser = Signal(intbv(0)[75:])
    s_axis_rc_tvalid = Signal(bool(0))
    s_axis_cq_tdata = Signal(intbv(0)[256:])
    s_axis_cq_tkeep = Signal(intbv(0)[8:])
    s_axis_cq_tlast = Signal(bool(0))
    s_axis_cq_tuser = Signal(intbv(0)[88:])
    s_axis_cq_tvalid = Signal(bool(0))
    m_axis_cc_tready = Signal(bool(0))
    pcie_tfc_nph_av = Signal(intbv(15)[4:])
    pcie_tfc_npd_av = Signal(intbv(15)[4:])
    cfg_max_payload = Signal(intbv(0)[2:])
    cfg_max_read_req = Signal(intbv(0)[3:])
    cfg_mgmt_read_data = Signal(intbv(0)[32:])
    cfg_mgmt_read_write_done = Signal(bool(0))
    cfg_interrupt_msi_enable = Signal(intbv(0)[4:])
    cfg_interrupt_msi_mmenable = Signal(intbv(0)[12:])
    cfg_interrupt_msi_mask_update = Signal(bool(0))
    cfg_interrupt_msi_data = Signal(intbv(0)[32:])
    cfg_interrupt_msi_sent = Signal(bool(0))
    cfg_interrupt_msi_fail = Signal(bool(0))
    qsfp1_tx_clk_1 = Signal(bool(0))
    qsfp1_tx_rst_1 = Signal(bool(0))
    qsfp1_rx_clk_1 = Signal(bool(0))
    qsfp1_rx_rst_1 = Signal(bool(0))
    qsfp1_rxd_1 = Signal(intbv(0)[64:])
    qsfp1_rxc_1 = Signal(intbv(0)[8:])
    qsfp1_tx_clk_2 = Signal(bool(0))
    qsfp1_tx_rst_2 = Signal(bool(0))
    qsfp1_rx_clk_2 = Signal(bool(0))
    qsfp1_rx_rst_2 = Signal(bool(0))
    qsfp1_rxd_2 = Signal(intbv(0)[64:])
    qsfp1_rxc_2 = Signal(intbv(0)[8:])
    qsfp1_tx_clk_3 = Signal(bool(0))
    qsfp1_tx_rst_3 = Signal(bool(0))
    qsfp1_rx_clk_3 = Signal(bool(0))
    qsfp1_rx_rst_3 = Signal(bool(0))
    qsfp1_rxd_3 = Signal(intbv(0)[64:])
    qsfp1_rxc_3 = Signal(intbv(0)[8:])
    qsfp1_tx_clk_4 = Signal(bool(0))
    qsfp1_tx_rst_4 = Signal(bool(0))
    qsfp1_rx_clk_4 = Signal(bool(0))
    qsfp1_rx_rst_4 = Signal(bool(0))
    qsfp1_rxd_4 = Signal(intbv(0)[64:])
    qsfp1_rxc_4 = Signal(intbv(0)[8:])
    qsfp1_modprsl = Signal(bool(1))
    qsfp1_intl = Signal(bool(1))
    qsfp2_tx_clk_1 = Signal(bool(0))
    qsfp2_tx_rst_1 = Signal(bool(0))
    qsfp2_rx_clk_1 = Signal(bool(0))
    qsfp2_rx_rst_1 = Signal(bool(0))
    qsfp2_rxd_1 = Signal(intbv(0)[64:])
    qsfp2_rxc_1 = Signal(intbv(0)[8:])
    qsfp2_tx_clk_2 = Signal(bool(0))
    qsfp2_tx_rst_2 = Signal(bool(0))
    qsfp2_rx_clk_2 = Signal(bool(0))
    qsfp2_rx_rst_2 = Signal(bool(0))
    qsfp2_rxd_2 = Signal(intbv(0)[64:])
    qsfp2_rxc_2 = Signal(intbv(0)[8:])
    qsfp2_tx_clk_3 = Signal(bool(0))
    qsfp2_tx_rst_3 = Signal(bool(0))
    qsfp2_rx_clk_3 = Signal(bool(0))
    qsfp2_rx_rst_3 = Signal(bool(0))
    qsfp2_rxd_3 = Signal(intbv(0)[64:])
    qsfp2_rxc_3 = Signal(intbv(0)[8:])
    qsfp2_tx_clk_4 = Signal(bool(0))
    qsfp2_tx_rst_4 = Signal(bool(0))
    qsfp2_rx_clk_4 = Signal(bool(0))
    qsfp2_rx_rst_4 = Signal(bool(0))
    qsfp2_rxd_4 = Signal(intbv(0)[64:])
    qsfp2_rxc_4 = Signal(intbv(0)[8:])
    qsfp2_modprsl = Signal(bool(1))
    qsfp2_intl = Signal(bool(1))

    # Outputs
    led = Signal(intbv(0)[8:])
    i2c_scl_o = Signal(bool(1))
    i2c_scl_t = Signal(bool(1))
    i2c_sda_o = Signal(bool(1))
    i2c_sda_t = Signal(bool(1))
    m_axis_rq_tdata = Signal(intbv(0)[256:])
    m_axis_rq_tkeep = Signal(intbv(0)[8:])
    m_axis_rq_tlast = Signal(bool(0))
    m_axis_rq_tuser = Signal(intbv(0)[62:])
    m_axis_rq_tvalid = Signal(bool(0))
    s_axis_rc_tready = Signal(bool(0))
    s_axis_cq_tready = Signal(bool(0))
    m_axis_cc_tdata = Signal(intbv(0)[256:])
    m_axis_cc_tkeep = Signal(intbv(0)[8:])
    m_axis_cc_tlast = Signal(bool(0))
    m_axis_cc_tuser = Signal(intbv(0)[33:])
    m_axis_cc_tvalid = Signal(bool(0))
    status_error_cor = Signal(bool(0))
    status_error_uncor = Signal(bool(0))
    cfg_mgmt_addr = Signal(intbv(0)[10:])
    cfg_mgmt_function_number = Signal(intbv(0)[8:])
    cfg_mgmt_write = Signal(bool(0))
    cfg_mgmt_write_data = Signal(intbv(0)[32:])
    cfg_mgmt_byte_enable = Signal(intbv(0)[4:])
    cfg_mgmt_read = Signal(bool(0))
    cfg_interrupt_msi_int = Signal(intbv(0)[32:])
    cfg_interrupt_msi_pending_status = Signal(intbv(0)[32:])
    cfg_interrupt_msi_select = Signal(intbv(0)[2:])
    cfg_interrupt_msi_pending_status_function_num = Signal(intbv(0)[2:])
    cfg_interrupt_msi_pending_status_data_enable = Signal(bool(0))
    cfg_interrupt_msi_attr = Signal(intbv(0)[3:])
    cfg_interrupt_msi_tph_present = Signal(bool(0))
    cfg_interrupt_msi_tph_type = Signal(intbv(0)[2:])
    cfg_interrupt_msi_tph_st_tag = Signal(intbv(0)[8:])
    cfg_interrupt_msi_function_number = Signal(intbv(0)[8:])
    qsfp1_txd_1 = Signal(intbv(0)[64:])
    qsfp1_txc_1 = Signal(intbv(0)[8:])
    qsfp1_txd_2 = Signal(intbv(0)[64:])
    qsfp1_txc_2 = Signal(intbv(0)[8:])
    qsfp1_txd_3 = Signal(intbv(0)[64:])
    qsfp1_txc_3 = Signal(intbv(0)[8:])
    qsfp1_txd_4 = Signal(intbv(0)[64:])
    qsfp1_txc_4 = Signal(intbv(0)[8:])
    qsfp1_modsell = Signal(bool(0))
    qsfp1_resetl = Signal(bool(0))
    qsfp1_lpmode = Signal(bool(0))
    qsfp2_txd_1 = Signal(intbv(0)[64:])
    qsfp2_txc_1 = Signal(intbv(0)[8:])
    qsfp2_txd_2 = Signal(intbv(0)[64:])
    qsfp2_txc_2 = Signal(intbv(0)[8:])
    qsfp2_txd_3 = Signal(intbv(0)[64:])
    qsfp2_txc_3 = Signal(intbv(0)[8:])
    qsfp2_txd_4 = Signal(intbv(0)[64:])
    qsfp2_txc_4 = Signal(intbv(0)[8:])
    qsfp2_modsell = Signal(bool(0))
    qsfp2_resetl = Signal(bool(0))
    qsfp2_lpmode = Signal(bool(0))

    # sources and sinks
    qsfp1_1_source = xgmii_ep.XGMIISource()
    qsfp1_1_source_logic = qsfp1_1_source.create_logic(qsfp1_rx_clk_1,
                                                       qsfp1_rx_rst_1,
                                                       txd=qsfp1_rxd_1,
                                                       txc=qsfp1_rxc_1,
                                                       name='qsfp1_1_source')

    qsfp1_1_sink = xgmii_ep.XGMIISink()
    qsfp1_1_sink_logic = qsfp1_1_sink.create_logic(qsfp1_tx_clk_1,
                                                   qsfp1_tx_rst_1,
                                                   rxd=qsfp1_txd_1,
                                                   rxc=qsfp1_txc_1,
                                                   name='qsfp1_1_sink')

    qsfp1_2_source = xgmii_ep.XGMIISource()
    qsfp1_2_source_logic = qsfp1_2_source.create_logic(qsfp1_rx_clk_2,
                                                       qsfp1_rx_rst_2,
                                                       txd=qsfp1_rxd_2,
                                                       txc=qsfp1_rxc_2,
                                                       name='qsfp1_2_source')

    qsfp1_2_sink = xgmii_ep.XGMIISink()
    qsfp1_2_sink_logic = qsfp1_2_sink.create_logic(qsfp1_tx_clk_2,
                                                   qsfp1_tx_rst_2,
                                                   rxd=qsfp1_txd_2,
                                                   rxc=qsfp1_txc_2,
                                                   name='qsfp1_2_sink')

    qsfp1_3_source = xgmii_ep.XGMIISource()
    qsfp1_3_source_logic = qsfp1_3_source.create_logic(qsfp1_rx_clk_3,
                                                       qsfp1_rx_rst_3,
                                                       txd=qsfp1_rxd_3,
                                                       txc=qsfp1_rxc_3,
                                                       name='qsfp1_3_source')

    qsfp1_3_sink = xgmii_ep.XGMIISink()
    qsfp1_3_sink_logic = qsfp1_3_sink.create_logic(qsfp1_tx_clk_3,
                                                   qsfp1_tx_rst_3,
                                                   rxd=qsfp1_txd_3,
                                                   rxc=qsfp1_txc_3,
                                                   name='qsfp1_3_sink')

    qsfp1_4_source = xgmii_ep.XGMIISource()
    qsfp1_4_source_logic = qsfp1_4_source.create_logic(qsfp1_rx_clk_4,
                                                       qsfp1_rx_rst_4,
                                                       txd=qsfp1_rxd_4,
                                                       txc=qsfp1_rxc_4,
                                                       name='qsfp1_4_source')

    qsfp1_4_sink = xgmii_ep.XGMIISink()
    qsfp1_4_sink_logic = qsfp1_4_sink.create_logic(qsfp1_tx_clk_4,
                                                   qsfp1_tx_rst_4,
                                                   rxd=qsfp1_txd_4,
                                                   rxc=qsfp1_txc_4,
                                                   name='qsfp1_4_sink')

    qsfp2_1_source = xgmii_ep.XGMIISource()
    qsfp2_1_source_logic = qsfp2_1_source.create_logic(qsfp2_rx_clk_1,
                                                       qsfp2_rx_rst_1,
                                                       txd=qsfp2_rxd_1,
                                                       txc=qsfp2_rxc_1,
                                                       name='qsfp2_1_source')

    qsfp2_1_sink = xgmii_ep.XGMIISink()
    qsfp2_1_sink_logic = qsfp2_1_sink.create_logic(qsfp2_tx_clk_1,
                                                   qsfp2_tx_rst_1,
                                                   rxd=qsfp2_txd_1,
                                                   rxc=qsfp2_txc_1,
                                                   name='qsfp2_1_sink')

    qsfp2_2_source = xgmii_ep.XGMIISource()
    qsfp2_2_source_logic = qsfp2_2_source.create_logic(qsfp2_rx_clk_2,
                                                       qsfp2_rx_rst_2,
                                                       txd=qsfp2_rxd_2,
                                                       txc=qsfp2_rxc_2,
                                                       name='qsfp2_2_source')

    qsfp2_2_sink = xgmii_ep.XGMIISink()
    qsfp2_2_sink_logic = qsfp2_2_sink.create_logic(qsfp2_tx_clk_2,
                                                   qsfp2_tx_rst_2,
                                                   rxd=qsfp2_txd_2,
                                                   rxc=qsfp2_txc_2,
                                                   name='qsfp2_2_sink')

    qsfp2_3_source = xgmii_ep.XGMIISource()
    qsfp2_3_source_logic = qsfp2_3_source.create_logic(qsfp2_rx_clk_3,
                                                       qsfp2_rx_rst_3,
                                                       txd=qsfp2_rxd_3,
                                                       txc=qsfp2_rxc_3,
                                                       name='qsfp2_3_source')

    qsfp2_3_sink = xgmii_ep.XGMIISink()
    qsfp2_3_sink_logic = qsfp2_3_sink.create_logic(qsfp2_tx_clk_3,
                                                   qsfp2_tx_rst_3,
                                                   rxd=qsfp2_txd_3,
                                                   rxc=qsfp2_txc_3,
                                                   name='qsfp2_3_sink')

    qsfp2_4_source = xgmii_ep.XGMIISource()
    qsfp2_4_source_logic = qsfp2_4_source.create_logic(qsfp2_rx_clk_4,
                                                       qsfp2_rx_rst_4,
                                                       txd=qsfp2_rxd_4,
                                                       txc=qsfp2_rxc_4,
                                                       name='qsfp2_4_source')

    qsfp2_4_sink = xgmii_ep.XGMIISink()
    qsfp2_4_sink_logic = qsfp2_4_sink.create_logic(qsfp2_tx_clk_4,
                                                   qsfp2_tx_rst_4,
                                                   rxd=qsfp2_txd_4,
                                                   rxc=qsfp2_txc_4,
                                                   name='qsfp2_4_sink')

    # Clock and Reset Interface
    user_clk = Signal(bool(0))
    user_reset = Signal(bool(0))
    sys_clk = Signal(bool(0))
    sys_reset = Signal(bool(0))

    # PCIe devices
    rc = pcie.RootComplex()

    rc.max_payload_size = 0x1  # 256 bytes
    rc.max_read_request_size = 0x5  # 4096 bytes

    driver = mqnic.Driver(rc)

    dev = pcie_usp.UltrascalePlusPCIe()

    dev.pcie_generation = 3
    dev.pcie_link_width = 8
    dev.user_clock_frequency = 256e6

    dev.functions[0].msi_multiple_message_capable = 5

    dev.functions[0].configure_bar(0, 16 * 1024 * 1024)
    dev.functions[0].configure_bar(1, 16 * 1024 * 1024)

    rc.make_port().connect(dev)

    cq_pause = Signal(bool(0))
    cc_pause = Signal(bool(0))
    rq_pause = Signal(bool(0))
    rc_pause = Signal(bool(0))

    pcie_logic = dev.create_logic(
        # Completer reQuest Interface
        m_axis_cq_tdata=s_axis_cq_tdata,
        m_axis_cq_tuser=s_axis_cq_tuser,
        m_axis_cq_tlast=s_axis_cq_tlast,
        m_axis_cq_tkeep=s_axis_cq_tkeep,
        m_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cq_tready=s_axis_cq_tready,
        #pcie_cq_np_req=pcie_cq_np_req,
        pcie_cq_np_req=Signal(intbv(3)[2:]),
        #pcie_cq_np_req_count=pcie_cq_np_req_count,

        # Completer Completion Interface
        s_axis_cc_tdata=m_axis_cc_tdata,
        s_axis_cc_tuser=m_axis_cc_tuser,
        s_axis_cc_tlast=m_axis_cc_tlast,
        s_axis_cc_tkeep=m_axis_cc_tkeep,
        s_axis_cc_tvalid=m_axis_cc_tvalid,
        s_axis_cc_tready=m_axis_cc_tready,

        # Requester reQuest Interface
        s_axis_rq_tdata=m_axis_rq_tdata,
        s_axis_rq_tuser=m_axis_rq_tuser,
        s_axis_rq_tlast=m_axis_rq_tlast,
        s_axis_rq_tkeep=m_axis_rq_tkeep,
        s_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rq_tready=m_axis_rq_tready,
        #pcie_rq_seq_num0=pcie_rq_seq_num0,
        #pcie_rq_seq_num_vld0=pcie_rq_seq_num_vld0,
        #pcie_rq_seq_num1=pcie_rq_seq_num1,
        #pcie_rq_seq_num_vld1=pcie_rq_seq_num_vld1,
        #pcie_rq_tag0=pcie_rq_tag0,
        #pcie_rq_tag1=pcie_rq_tag1,
        #pcie_rq_tag_av=pcie_rq_tag_av,
        #pcie_rq_tag_vld0=pcie_rq_tag_vld0,
        #pcie_rq_tag_vld1=pcie_rq_tag_vld1,

        # Requester Completion Interface
        m_axis_rc_tdata=s_axis_rc_tdata,
        m_axis_rc_tuser=s_axis_rc_tuser,
        m_axis_rc_tlast=s_axis_rc_tlast,
        m_axis_rc_tkeep=s_axis_rc_tkeep,
        m_axis_rc_tvalid=s_axis_rc_tvalid,
        m_axis_rc_tready=s_axis_rc_tready,

        # Transmit Flow Control Interface
        #pcie_tfc_nph_av=pcie_tfc_nph_av,
        #pcie_tfc_npd_av=pcie_tfc_npd_av,

        # Configuration Management Interface
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_function_number=cfg_mgmt_function_number,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        #cfg_mgmt_debug_access=cfg_mgmt_debug_access,

        # Configuration Status Interface
        #cfg_phy_link_down=cfg_phy_link_down,
        #cfg_phy_link_status=cfg_phy_link_status,
        #cfg_negotiated_width=cfg_negotiated_width,
        #cfg_current_speed=cfg_current_speed,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        #cfg_function_status=cfg_function_status,
        #cfg_vf_status=cfg_vf_status,
        #cfg_function_power_state=cfg_function_power_state,
        #cfg_vf_power_state=cfg_vf_power_state,
        #cfg_link_power_state=cfg_link_power_state,
        #cfg_err_cor_out=cfg_err_cor_out,
        #cfg_err_nonfatal_out=cfg_err_nonfatal_out,
        #cfg_err_fatal_out=cfg_err_fatal_out,
        #cfg_local_err_out=cfg_local_err_out,
        #cfg_local_err_valid=cfg_local_err_valid,
        #cfg_rx_pm_state=cfg_rx_pm_state,
        #cfg_tx_pm_state=cfg_tx_pm_state,
        #cfg_ltssm_state=cfg_ltssm_state,
        #cfg_rcb_status=cfg_rcb_status,
        #cfg_obff_enable=cfg_obff_enable,
        #cfg_pl_status_change=cfg_pl_status_change,
        #cfg_tph_requester_enable=cfg_tph_requester_enable,
        #cfg_tph_st_mode=cfg_tph_st_mode,
        #cfg_vf_tph_requester_enable=cfg_vf_tph_requester_enable,
        #cfg_vf_tph_st_mode=cfg_vf_tph_st_mode,

        # Configuration Received Message Interface
        #cfg_msg_received=cfg_msg_received,
        #cfg_msg_received_data=cfg_msg_received_data,
        #cfg_msg_received_type=cfg_msg_received_type,

        # Configuration Transmit Message Interface
        #cfg_msg_transmit=cfg_msg_transmit,
        #cfg_msg_transmit_type=cfg_msg_transmit_type,
        #cfg_msg_transmit_data=cfg_msg_transmit_data,
        #cfg_msg_transmit_done=cfg_msg_transmit_done,

        # Configuration Flow Control Interface
        #cfg_fc_ph=cfg_fc_ph,
        #cfg_fc_pd=cfg_fc_pd,
        #cfg_fc_nph=cfg_fc_nph,
        #cfg_fc_npd=cfg_fc_npd,
        #cfg_fc_cplh=cfg_fc_cplh,
        #cfg_fc_cpld=cfg_fc_cpld,
        #cfg_fc_sel=cfg_fc_sel,

        # Configuration Control Interface
        #cfg_hot_reset_in=cfg_hot_reset_in,
        #cfg_hot_reset_out=cfg_hot_reset_out,
        #cfg_config_space_enable=cfg_config_space_enable,
        #cfg_dsn=cfg_dsn,
        #cfg_ds_port_number=cfg_ds_port_number,
        #cfg_ds_bus_number=cfg_ds_bus_number,
        #cfg_ds_device_number=cfg_ds_device_number,
        #cfg_ds_function_number=cfg_ds_function_number,
        #cfg_power_state_change_ack=cfg_power_state_change_ack,
        #cfg_power_state_change_interrupt=cfg_power_state_change_interrupt,
        cfg_err_cor_in=status_error_cor,
        cfg_err_uncor_in=status_error_uncor,
        #cfg_flr_done=cfg_flr_done,
        #cfg_vf_flr_done=cfg_vf_flr_done,
        #cfg_flr_in_process=cfg_flr_in_process,
        #cfg_vf_flr_in_process=cfg_vf_flr_in_process,
        #cfg_req_pm_transition_l23_ready=cfg_req_pm_transition_l23_ready,
        #cfg_link_training_enable=cfg_link_training_enable,

        # Configuration Interrupt Controller Interface
        #cfg_interrupt_int=cfg_interrupt_int,
        #cfg_interrupt_sent=cfg_interrupt_sent,
        #cfg_interrupt_pending=cfg_interrupt_pending,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_pending_status_data_enable=
        cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_pending_status_function_num=
        cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        #cfg_interrupt_msix_enable=cfg_interrupt_msix_enable,
        #cfg_interrupt_msix_mask=cfg_interrupt_msix_mask,
        #cfg_interrupt_msix_vf_enable=cfg_interrupt_msix_vf_enable,
        #cfg_interrupt_msix_vf_mask=cfg_interrupt_msix_vf_mask,
        #cfg_interrupt_msix_address=cfg_interrupt_msix_address,
        #cfg_interrupt_msix_data=cfg_interrupt_msix_data,
        #cfg_interrupt_msix_int=cfg_interrupt_msix_int,
        #cfg_interrupt_msix_vec_pending=cfg_interrupt_msix_vec_pending,
        #cfg_interrupt_msix_vec_pending_status=cfg_interrupt_msix_vec_pending_status,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,

        # Configuration Extend Interface
        #cfg_ext_read_received=cfg_ext_read_received,
        #cfg_ext_write_received=cfg_ext_write_received,
        #cfg_ext_register_number=cfg_ext_register_number,
        #cfg_ext_function_number=cfg_ext_function_number,
        #cfg_ext_write_data=cfg_ext_write_data,
        #cfg_ext_write_byte_enable=cfg_ext_write_byte_enable,
        #cfg_ext_read_data=cfg_ext_read_data,
        #cfg_ext_read_data_valid=cfg_ext_read_data_valid,

        # Clock and Reset Interface
        user_clk=user_clk,
        user_reset=user_reset,
        sys_clk=sys_clk,
        sys_clk_gt=sys_clk,
        sys_reset=sys_reset,
        #phy_rdy_out=phy_rdy_out,
        cq_pause=cq_pause,
        cc_pause=cc_pause,
        rq_pause=rq_pause,
        rc_pause=rc_pause)

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation(
        "vvp -m myhdl %s.vvp -lxt2" % testbench,
        clk=clk,
        rst=rst,
        current_test=current_test,
        clk_156mhz=clk_156mhz,
        rst_156mhz=rst_156mhz,
        clk_250mhz=user_clk,
        rst_250mhz=user_reset,
        btnu=btnu,
        btnl=btnl,
        btnd=btnd,
        btnr=btnr,
        btnc=btnc,
        sw=sw,
        led=led,
        i2c_scl_i=i2c_scl_i,
        i2c_scl_o=i2c_scl_o,
        i2c_scl_t=i2c_scl_t,
        i2c_sda_i=i2c_sda_i,
        i2c_sda_o=i2c_sda_o,
        i2c_sda_t=i2c_sda_t,
        m_axis_rq_tdata=m_axis_rq_tdata,
        m_axis_rq_tkeep=m_axis_rq_tkeep,
        m_axis_rq_tlast=m_axis_rq_tlast,
        m_axis_rq_tready=m_axis_rq_tready,
        m_axis_rq_tuser=m_axis_rq_tuser,
        m_axis_rq_tvalid=m_axis_rq_tvalid,
        s_axis_rc_tdata=s_axis_rc_tdata,
        s_axis_rc_tkeep=s_axis_rc_tkeep,
        s_axis_rc_tlast=s_axis_rc_tlast,
        s_axis_rc_tready=s_axis_rc_tready,
        s_axis_rc_tuser=s_axis_rc_tuser,
        s_axis_rc_tvalid=s_axis_rc_tvalid,
        s_axis_cq_tdata=s_axis_cq_tdata,
        s_axis_cq_tkeep=s_axis_cq_tkeep,
        s_axis_cq_tlast=s_axis_cq_tlast,
        s_axis_cq_tready=s_axis_cq_tready,
        s_axis_cq_tuser=s_axis_cq_tuser,
        s_axis_cq_tvalid=s_axis_cq_tvalid,
        m_axis_cc_tdata=m_axis_cc_tdata,
        m_axis_cc_tkeep=m_axis_cc_tkeep,
        m_axis_cc_tlast=m_axis_cc_tlast,
        m_axis_cc_tready=m_axis_cc_tready,
        m_axis_cc_tuser=m_axis_cc_tuser,
        m_axis_cc_tvalid=m_axis_cc_tvalid,
        pcie_tfc_nph_av=pcie_tfc_nph_av,
        pcie_tfc_npd_av=pcie_tfc_npd_av,
        cfg_max_payload=cfg_max_payload,
        cfg_max_read_req=cfg_max_read_req,
        cfg_mgmt_addr=cfg_mgmt_addr,
        cfg_mgmt_function_number=cfg_mgmt_function_number,
        cfg_mgmt_write=cfg_mgmt_write,
        cfg_mgmt_write_data=cfg_mgmt_write_data,
        cfg_mgmt_byte_enable=cfg_mgmt_byte_enable,
        cfg_mgmt_read=cfg_mgmt_read,
        cfg_mgmt_read_data=cfg_mgmt_read_data,
        cfg_mgmt_read_write_done=cfg_mgmt_read_write_done,
        cfg_interrupt_msi_enable=cfg_interrupt_msi_enable,
        cfg_interrupt_msi_int=cfg_interrupt_msi_int,
        cfg_interrupt_msi_sent=cfg_interrupt_msi_sent,
        cfg_interrupt_msi_fail=cfg_interrupt_msi_fail,
        cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable,
        cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status,
        cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update,
        cfg_interrupt_msi_select=cfg_interrupt_msi_select,
        cfg_interrupt_msi_data=cfg_interrupt_msi_data,
        cfg_interrupt_msi_pending_status_function_num=
        cfg_interrupt_msi_pending_status_function_num,
        cfg_interrupt_msi_pending_status_data_enable=
        cfg_interrupt_msi_pending_status_data_enable,
        cfg_interrupt_msi_attr=cfg_interrupt_msi_attr,
        cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present,
        cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type,
        cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag,
        cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number,
        status_error_cor=status_error_cor,
        status_error_uncor=status_error_uncor,
        qsfp1_tx_clk_1=qsfp1_tx_clk_1,
        qsfp1_tx_rst_1=qsfp1_tx_rst_1,
        qsfp1_txd_1=qsfp1_txd_1,
        qsfp1_txc_1=qsfp1_txc_1,
        qsfp1_rx_clk_1=qsfp1_rx_clk_1,
        qsfp1_rx_rst_1=qsfp1_rx_rst_1,
        qsfp1_rxd_1=qsfp1_rxd_1,
        qsfp1_rxc_1=qsfp1_rxc_1,
        qsfp1_tx_clk_2=qsfp1_tx_clk_2,
        qsfp1_tx_rst_2=qsfp1_tx_rst_2,
        qsfp1_txd_2=qsfp1_txd_2,
        qsfp1_txc_2=qsfp1_txc_2,
        qsfp1_rx_clk_2=qsfp1_rx_clk_2,
        qsfp1_rx_rst_2=qsfp1_rx_rst_2,
        qsfp1_rxd_2=qsfp1_rxd_2,
        qsfp1_rxc_2=qsfp1_rxc_2,
        qsfp1_tx_clk_3=qsfp1_tx_clk_3,
        qsfp1_tx_rst_3=qsfp1_tx_rst_3,
        qsfp1_txd_3=qsfp1_txd_3,
        qsfp1_txc_3=qsfp1_txc_3,
        qsfp1_rx_clk_3=qsfp1_rx_clk_3,
        qsfp1_rx_rst_3=qsfp1_rx_rst_3,
        qsfp1_rxd_3=qsfp1_rxd_3,
        qsfp1_rxc_3=qsfp1_rxc_3,
        qsfp1_tx_clk_4=qsfp1_tx_clk_4,
        qsfp1_tx_rst_4=qsfp1_tx_rst_4,
        qsfp1_txd_4=qsfp1_txd_4,
        qsfp1_txc_4=qsfp1_txc_4,
        qsfp1_rx_clk_4=qsfp1_rx_clk_4,
        qsfp1_rx_rst_4=qsfp1_rx_rst_4,
        qsfp1_rxd_4=qsfp1_rxd_4,
        qsfp1_rxc_4=qsfp1_rxc_4,
        qsfp1_modprsl=qsfp1_modprsl,
        qsfp1_modsell=qsfp1_modsell,
        qsfp1_resetl=qsfp1_resetl,
        qsfp1_intl=qsfp1_intl,
        qsfp1_lpmode=qsfp1_lpmode,
        qsfp2_tx_clk_1=qsfp2_tx_clk_1,
        qsfp2_tx_rst_1=qsfp2_tx_rst_1,
        qsfp2_txd_1=qsfp2_txd_1,
        qsfp2_txc_1=qsfp2_txc_1,
        qsfp2_rx_clk_1=qsfp2_rx_clk_1,
        qsfp2_rx_rst_1=qsfp2_rx_rst_1,
        qsfp2_rxd_1=qsfp2_rxd_1,
        qsfp2_rxc_1=qsfp2_rxc_1,
        qsfp2_tx_clk_2=qsfp2_tx_clk_2,
        qsfp2_tx_rst_2=qsfp2_tx_rst_2,
        qsfp2_txd_2=qsfp2_txd_2,
        qsfp2_txc_2=qsfp2_txc_2,
        qsfp2_rx_clk_2=qsfp2_rx_clk_2,
        qsfp2_rx_rst_2=qsfp2_rx_rst_2,
        qsfp2_rxd_2=qsfp2_rxd_2,
        qsfp2_rxc_2=qsfp2_rxc_2,
        qsfp2_tx_clk_3=qsfp2_tx_clk_3,
        qsfp2_tx_rst_3=qsfp2_tx_rst_3,
        qsfp2_txd_3=qsfp2_txd_3,
        qsfp2_txc_3=qsfp2_txc_3,
        qsfp2_rx_clk_3=qsfp2_rx_clk_3,
        qsfp2_rx_rst_3=qsfp2_rx_rst_3,
        qsfp2_rxd_3=qsfp2_rxd_3,
        qsfp2_rxc_3=qsfp2_rxc_3,
        qsfp2_tx_clk_4=qsfp2_tx_clk_4,
        qsfp2_tx_rst_4=qsfp2_tx_rst_4,
        qsfp2_txd_4=qsfp2_txd_4,
        qsfp2_txc_4=qsfp2_txc_4,
        qsfp2_rx_clk_4=qsfp2_rx_clk_4,
        qsfp2_rx_rst_4=qsfp2_rx_rst_4,
        qsfp2_rxd_4=qsfp2_rxd_4,
        qsfp2_rxc_4=qsfp2_rxc_4,
        qsfp2_modprsl=qsfp2_modprsl,
        qsfp2_modsell=qsfp2_modsell,
        qsfp2_resetl=qsfp2_resetl,
        qsfp2_intl=qsfp2_intl,
        qsfp2_lpmode=qsfp2_lpmode)

    @always(delay(5))
    def clkgen():
        clk.next = not clk

    @always(delay(3))
    def qsfp_clkgen():
        qsfp1_tx_clk_1.next = not qsfp1_tx_clk_1
        qsfp1_rx_clk_1.next = not qsfp1_rx_clk_1
        qsfp1_tx_clk_2.next = not qsfp1_tx_clk_2
        qsfp1_rx_clk_2.next = not qsfp1_rx_clk_2
        qsfp1_tx_clk_3.next = not qsfp1_tx_clk_3
        qsfp1_rx_clk_3.next = not qsfp1_rx_clk_3
        qsfp1_tx_clk_4.next = not qsfp1_tx_clk_4
        qsfp1_rx_clk_4.next = not qsfp1_rx_clk_4
        qsfp2_tx_clk_1.next = not qsfp2_tx_clk_1
        qsfp2_rx_clk_1.next = not qsfp2_rx_clk_1
        qsfp2_tx_clk_2.next = not qsfp2_tx_clk_2
        qsfp2_rx_clk_2.next = not qsfp2_rx_clk_2
        qsfp2_tx_clk_3.next = not qsfp2_tx_clk_3
        qsfp2_rx_clk_3.next = not qsfp2_rx_clk_3
        qsfp2_tx_clk_4.next = not qsfp2_tx_clk_4
        qsfp2_rx_clk_4.next = not qsfp2_rx_clk_4

    @always_comb
    def clk_logic():
        sys_clk.next = clk
        sys_reset.next = not rst

    loopback_enable = Signal(bool(0))

    @instance
    def loopback():
        while True:

            yield clk.posedge

            if loopback_enable:
                if not qsfp1_1_sink.empty():
                    pkt = qsfp1_1_sink.recv()
                    qsfp1_1_source.send(pkt)
                if not qsfp1_2_sink.empty():
                    pkt = qsfp1_2_sink.recv()
                    qsfp1_2_source.send(pkt)
                if not qsfp1_3_sink.empty():
                    pkt = qsfp1_3_sink.recv()
                    qsfp1_3_source.send(pkt)
                if not qsfp1_4_sink.empty():
                    pkt = qsfp1_4_sink.recv()
                    qsfp1_4_source.send(pkt)
                if not qsfp2_1_sink.empty():
                    pkt = qsfp2_1_sink.recv()
                    qsfp2_1_source.send(pkt)
                if not qsfp2_2_sink.empty():
                    pkt = qsfp2_2_sink.recv()
                    qsfp2_2_source.send(pkt)
                if not qsfp2_3_sink.empty():
                    pkt = qsfp2_3_sink.recv()
                    qsfp2_3_source.send(pkt)
                if not qsfp2_4_sink.empty():
                    pkt = qsfp2_4_sink.recv()
                    qsfp2_4_source.send(pkt)

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        qsfp1_tx_rst_1.next = 1
        qsfp1_rx_rst_1.next = 1
        qsfp1_tx_rst_2.next = 1
        qsfp1_rx_rst_2.next = 1
        qsfp1_tx_rst_3.next = 1
        qsfp1_rx_rst_3.next = 1
        qsfp1_tx_rst_4.next = 1
        qsfp1_rx_rst_4.next = 1
        qsfp2_tx_rst_1.next = 1
        qsfp2_rx_rst_1.next = 1
        qsfp2_tx_rst_2.next = 1
        qsfp2_rx_rst_2.next = 1
        qsfp2_tx_rst_3.next = 1
        qsfp2_rx_rst_3.next = 1
        qsfp2_tx_rst_4.next = 1
        qsfp2_rx_rst_4.next = 1
        yield clk.posedge
        yield delay(100)
        rst.next = 0
        qsfp1_tx_rst_1.next = 0
        qsfp1_rx_rst_1.next = 0
        qsfp1_tx_rst_2.next = 0
        qsfp1_rx_rst_2.next = 0
        qsfp1_tx_rst_3.next = 0
        qsfp1_rx_rst_3.next = 0
        qsfp1_tx_rst_4.next = 0
        qsfp1_rx_rst_4.next = 0
        qsfp2_tx_rst_1.next = 0
        qsfp2_rx_rst_1.next = 0
        qsfp2_tx_rst_2.next = 0
        qsfp2_rx_rst_2.next = 0
        qsfp2_tx_rst_3.next = 0
        qsfp2_rx_rst_3.next = 0
        qsfp2_tx_rst_4.next = 0
        qsfp2_rx_rst_4.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # testbench stimulus

        current_tag = 1

        yield clk.posedge
        print("test 1: enumeration")
        current_test.next = 1

        yield rc.enumerate(enable_bus_mastering=True, configure_msi=True)

        dev_pf0_bar0 = dev.functions[0].bar[0] & 0xfffffffc
        dev_pf0_bar1 = dev.functions[0].bar[1] & 0xfffffffc

        yield delay(100)

        yield clk.posedge
        print("test 2: init NIC")
        current_test.next = 2

        #data = yield from rc.mem_read(dev_pf0_bar0+0x20000+0x10, 4);
        #print(data)

        #yield delay(1000)

        #raise StopSimulation

        yield from driver.init_dev(dev.functions[0].get_id())
        yield from driver.interfaces[0].open()
        #yield from driver.interfaces[1].open()

        # enable queues
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].hw_addr + 0x0200, 0xffffffff)
        yield from rc.mem_write_dword(
            driver.interfaces[0].ports[0].hw_addr + 0x0300, 0xffffffff)

        yield from rc.mem_read(driver.hw_addr,
                               4)  # wait for all writes to complete

        yield delay(100)

        yield clk.posedge
        print("test 3: send and receive a packet")
        current_test.next = 3

        # test bad packet
        #qsfp1_1_source.send(b'\x55\x55\x55\x55\x55\xd5'+bytearray(range(128)))

        data = bytearray([x % 256 for x in range(1024)])

        yield from driver.interfaces[0].start_xmit(data, 0)

        yield qsfp1_1_sink.wait()

        pkt = qsfp1_1_sink.recv()
        print(pkt)

        qsfp1_1_source.send(pkt)

        yield driver.interfaces[0].wait()

        pkt = driver.interfaces[0].recv()

        print(pkt)
        assert frame_checksum(pkt.data) == pkt.rx_checksum

        # yield from driver.interfaces[1].start_xmit(data, 0)

        # yield qsfp1_1_sink.wait()

        # pkt = qsfp1_1_sink.recv()
        # print(pkt)

        # qsfp1_1_source.send(pkt)

        # yield driver.interfaces[1].wait()

        # pkt = driver.interfaces[1].recv()

        # print(pkt)
        # assert frame_checksum(pkt.data) == pkt.rx_checksum

        yield delay(100)

        yield clk.posedge
        print("test 4: multiple small packets")
        current_test.next = 4

        count = 64

        pkts = [
            bytearray([(x + k) % 256 for x in range(64)]) for k in range(count)
        ]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        yield clk.posedge
        print("test 5: multiple large packets")
        current_test.next = 5

        count = 64

        pkts = [
            bytearray([(x + k) % 256 for x in range(1514)])
            for k in range(count)
        ]

        loopback_enable.next = True

        for p in pkts:
            yield from driver.interfaces[0].start_xmit(p, 0)

        for k in range(count):
            pkt = driver.interfaces[0].recv()

            if not pkt:
                yield driver.interfaces[0].wait()
                pkt = driver.interfaces[0].recv()

            print(pkt)
            assert pkt.data == pkts[k]
            assert frame_checksum(pkt.data) == pkt.rx_checksum

        loopback_enable.next = False

        yield delay(100)

        raise StopSimulation

    return instances()
Exemplo n.º 8
0
    def __init__(self, dut):
        self.dut = dut

        self.log = SimLog("cocotb.tb")
        self.log.setLevel(logging.DEBUG)

        # PCIe
        self.rc = RootComplex()

        self.rc.max_payload_size = 0x1  # 256 bytes
        self.rc.max_read_request_size = 0x2  # 512 bytes

        self.dev = S10PcieDevice(
            # configuration options
            pcie_generation=3,
            # pcie_link_width=2,
            # pld_clk_frequency=250e6,
            l_tile=False,

            # signals
            # Clock and reset
            # npor=dut.npor,
            # pin_perst=dut.pin_perst,
            # ninit_done=dut.ninit_done,
            # pld_clk_inuse=dut.pld_clk_inuse,
            # pld_core_ready=dut.pld_core_ready,
            reset_status=dut.rst,
            # clr_st=dut.clr_st,
            # refclk=dut.refclk,
            coreclkout_hip=dut.clk,

            # RX interface
            rx_bus=S10RxBus.from_prefix(dut, "rx_st"),

            # TX interface
            tx_bus=S10TxBus.from_prefix(dut, "tx_st"),

            # TX flow control
            tx_ph_cdts=dut.tx_ph_cdts,
            tx_pd_cdts=dut.tx_pd_cdts,
            tx_nph_cdts=dut.tx_nph_cdts,
            tx_npd_cdts=dut.tx_npd_cdts,
            tx_cplh_cdts=dut.tx_cplh_cdts,
            tx_cpld_cdts=dut.tx_cpld_cdts,
            tx_hdr_cdts_consumed=dut.tx_hdr_cdts_consumed,
            tx_data_cdts_consumed=dut.tx_data_cdts_consumed,
            tx_cdts_type=dut.tx_cdts_type,
            tx_cdts_data_value=dut.tx_cdts_data_value,

            # Hard IP status
            # int_status=dut.int_status,
            # int_status_common=dut.int_status_common,
            # derr_cor_ext_rpl=dut.derr_cor_ext_rpl,
            # derr_rpl=dut.derr_rpl,
            # derr_cor_ext_rcv=dut.derr_cor_ext_rcv,
            # derr_uncor_ext_rcv=dut.derr_uncor_ext_rcv,
            # rx_par_err=dut.rx_par_err,
            # tx_par_err=dut.tx_par_err,
            # ltssmstate=dut.ltssmstate,
            # link_up=dut.link_up,
            # lane_act=dut.lane_act,
            # currentspeed=dut.currentspeed,

            # Power management
            # pm_linkst_in_l1=dut.pm_linkst_in_l1,
            # pm_linkst_in_l0s=dut.pm_linkst_in_l0s,
            # pm_state=dut.pm_state,
            # pm_dstate=dut.pm_dstate,
            # apps_pm_xmt_pme=dut.apps_pm_xmt_pme,
            # apps_ready_entr_l23=dut.apps_ready_entr_l23,
            # apps_pm_xmt_turnoff=dut.apps_pm_xmt_turnoff,
            # app_init_rst=dut.app_init_rst,
            # app_xfer_pending=dut.app_xfer_pending,

            # Interrupt interface
            app_msi_req=dut.app_msi_req,
            app_msi_ack=dut.app_msi_ack,
            app_msi_tc=dut.app_msi_tc,
            app_msi_num=dut.app_msi_num,
            app_msi_func_num=dut.app_msi_func_num,
            # app_int_sts=dut.app_int_sts,

            # Error interface
            # serr_out=dut.serr_out,
            # hip_enter_err_mode=dut.hip_enter_err_mode,
            # app_err_valid=dut.app_err_valid,
            # app_err_hdr=dut.app_err_hdr,
            # app_err_info=dut.app_err_info,
            # app_err_func_num=dut.app_err_func_num,

            # Configuration output
            tl_cfg_func=dut.tl_cfg_func,
            tl_cfg_add=dut.tl_cfg_add,
            tl_cfg_ctl=dut.tl_cfg_ctl,

            # Configuration extension bus
            # ceb_req=dut.ceb_req,
            # ceb_ack=dut.ceb_ack,
            # ceb_addr=dut.ceb_addr,
            # ceb_din=dut.ceb_din,
            # ceb_dout=dut.ceb_dout,
            # ceb_wr=dut.ceb_wr,
            # ceb_cdm_convert_data=dut.ceb_cdm_convert_data,
            # ceb_func_num=dut.ceb_func_num,
            # ceb_vf_num=dut.ceb_vf_num,
            # ceb_vf_active=dut.ceb_vf_active,

            # Hard IP reconfiguration interface
            # hip_reconfig_clk=dut.hip_reconfig_clk,
            # hip_reconfig_address=dut.hip_reconfig_address,
            # hip_reconfig_read=dut.hip_reconfig_read,
            # hip_reconfig_readdata=dut.hip_reconfig_readdata,
            # hip_reconfig_readdatavalid=dut.hip_reconfig_readdatavalid,
            # hip_reconfig_write=dut.hip_reconfig_write,
            # hip_reconfig_writedata=dut.hip_reconfig_writedata,
            # hip_reconfig_waitrequest=dut.hip_reconfig_waitrequest,
        )

        # self.dev.log.setLevel(logging.DEBUG)

        self.rc.make_port().connect(self.dev)

        self.driver = mqnic.Driver()

        self.dev.functions[0].msi_cap.msi_multiple_message_capable = 5

        self.dev.functions[0].configure_bar(
            0,
            2**len(dut.core_pcie_inst.axil_ctrl_araddr),
            ext=True,
            prefetch=True)
        if hasattr(dut.core_pcie_inst, 'pcie_app_ctrl'):
            self.dev.functions[0].configure_bar(
                2,
                2**len(dut.core_pcie_inst.axil_app_ctrl_araddr),
                ext=True,
                prefetch=True)

        # Ethernet
        self.port_mac = []

        eth_int_if_width = len(dut.core_pcie_inst.core_inst.iface[0].port[0].
                               rx_async_fifo_inst.m_axis_tdata)
        eth_clock_period = 6.4
        eth_speed = 10e9

        if eth_int_if_width == 64:
            # 10G
            eth_clock_period = 6.4
            eth_speed = 10e9
        elif eth_int_if_width == 128:
            # 25G
            eth_clock_period = 2.56
            eth_speed = 25e9
        elif eth_int_if_width == 512:
            # 100G
            eth_clock_period = 3.102
            eth_speed = 100e9

        for iface in dut.core_pcie_inst.core_inst.iface:
            for port in iface.port:
                cocotb.start_soon(
                    Clock(port.port_rx_clk, eth_clock_period,
                          units="ns").start())
                cocotb.start_soon(
                    Clock(port.port_tx_clk, eth_clock_period,
                          units="ns").start())

                port.port_rx_rst.setimmediatevalue(0)
                port.port_tx_rst.setimmediatevalue(0)

                mac = EthMac(tx_clk=port.port_tx_clk,
                             tx_rst=port.port_tx_rst,
                             tx_bus=AxiStreamBus.from_prefix(port, "axis_tx"),
                             tx_ptp_time=port.ptp.tx_ptp_cdc_inst.output_ts,
                             tx_ptp_ts=port.ptp.axis_tx_ptp_ts,
                             tx_ptp_ts_tag=port.ptp.axis_tx_ptp_ts_tag,
                             tx_ptp_ts_valid=port.ptp.axis_tx_ptp_ts_valid,
                             rx_clk=port.port_rx_clk,
                             rx_rst=port.port_rx_rst,
                             rx_bus=AxiStreamBus.from_prefix(port, "axis_rx"),
                             rx_ptp_time=port.ptp.rx_ptp_cdc_inst.output_ts,
                             ifg=12,
                             speed=eth_speed)

                self.port_mac.append(mac)

        dut.ctrl_reg_wr_wait.setimmediatevalue(0)
        dut.ctrl_reg_wr_ack.setimmediatevalue(0)
        dut.ctrl_reg_rd_data.setimmediatevalue(0)
        dut.ctrl_reg_rd_wait.setimmediatevalue(0)
        dut.ctrl_reg_rd_ack.setimmediatevalue(0)

        dut.ptp_sample_clk.setimmediatevalue(0)

        dut.s_axis_stat_tdata.setimmediatevalue(0)
        dut.s_axis_stat_tid.setimmediatevalue(0)
        dut.s_axis_stat_tvalid.setimmediatevalue(0)

        self.loopback_enable = False
        cocotb.start_soon(self._run_loopback())
Exemplo n.º 9
0
    def __init__(self, dut):
        self.dut = dut

        self.log = SimLog("cocotb.tb")
        self.log.setLevel(logging.DEBUG)

        # PCIe
        self.rc = RootComplex()

        self.rc.max_payload_size = 0x1  # 256 bytes
        self.rc.max_read_request_size = 0x2  # 512 bytes

        self.dev = S10PcieDevice(
            # configuration options
            pcie_generation=3,
            # pcie_link_width=8,
            # pld_clk_frequency=250e6,
            l_tile=False,

            # signals
            # Clock and reset
            # npor=dut.npor,
            # pin_perst=dut.pin_perst,
            # ninit_done=dut.ninit_done,
            # pld_clk_inuse=dut.pld_clk_inuse,
            # pld_core_ready=dut.pld_core_ready,
            reset_status=dut.rst_250mhz,
            # clr_st=dut.clr_st,
            # refclk=dut.refclk,
            coreclkout_hip=dut.clk_250mhz,

            # RX interface
            rx_bus=S10RxBus.from_prefix(dut, "rx_st"),

            # TX interface
            tx_bus=S10TxBus.from_prefix(dut, "tx_st"),

            # TX flow control
            tx_ph_cdts=dut.tx_ph_cdts,
            tx_pd_cdts=dut.tx_pd_cdts,
            tx_nph_cdts=dut.tx_nph_cdts,
            tx_npd_cdts=dut.tx_npd_cdts,
            tx_cplh_cdts=dut.tx_cplh_cdts,
            tx_cpld_cdts=dut.tx_cpld_cdts,
            tx_hdr_cdts_consumed=dut.tx_hdr_cdts_consumed,
            tx_data_cdts_consumed=dut.tx_data_cdts_consumed,
            tx_cdts_type=dut.tx_cdts_type,
            tx_cdts_data_value=dut.tx_cdts_data_value,

            # Hard IP status
            # int_status=dut.int_status,
            # int_status_common=dut.int_status_common,
            # derr_cor_ext_rpl=dut.derr_cor_ext_rpl,
            # derr_rpl=dut.derr_rpl,
            # derr_cor_ext_rcv=dut.derr_cor_ext_rcv,
            # derr_uncor_ext_rcv=dut.derr_uncor_ext_rcv,
            # rx_par_err=dut.rx_par_err,
            # tx_par_err=dut.tx_par_err,
            # ltssmstate=dut.ltssmstate,
            # link_up=dut.link_up,
            # lane_act=dut.lane_act,
            # currentspeed=dut.currentspeed,

            # Power management
            # pm_linkst_in_l1=dut.pm_linkst_in_l1,
            # pm_linkst_in_l0s=dut.pm_linkst_in_l0s,
            # pm_state=dut.pm_state,
            # pm_dstate=dut.pm_dstate,
            # apps_pm_xmt_pme=dut.apps_pm_xmt_pme,
            # apps_ready_entr_l23=dut.apps_ready_entr_l23,
            # apps_pm_xmt_turnoff=dut.apps_pm_xmt_turnoff,
            # app_init_rst=dut.app_init_rst,
            # app_xfer_pending=dut.app_xfer_pending,

            # Interrupt interface
            app_msi_req=dut.app_msi_req,
            app_msi_ack=dut.app_msi_ack,
            app_msi_tc=dut.app_msi_tc,
            app_msi_num=dut.app_msi_num,
            app_msi_func_num=dut.app_msi_func_num,
            # app_int_sts=dut.app_int_sts,

            # Error interface
            # app_err_valid=dut.app_err_valid,
            # app_err_hdr=dut.app_err_hdr,
            # app_err_info=dut.app_err_info,
            # app_err_func_num=dut.app_err_func_num,

            # Configuration output
            tl_cfg_func=dut.tl_cfg_func,
            tl_cfg_add=dut.tl_cfg_add,
            tl_cfg_ctl=dut.tl_cfg_ctl,

            # Configuration extension bus
            # ceb_req=dut.ceb_req,
            # ceb_ack=dut.ceb_ack,
            # ceb_addr=dut.ceb_addr,
            # ceb_din=dut.ceb_din,
            # ceb_dout=dut.ceb_dout,
            # ceb_wr=dut.ceb_wr,
            # ceb_cdm_convert_data=dut.ceb_cdm_convert_data,
            # ceb_func_num=dut.ceb_func_num,
            # ceb_vf_num=dut.ceb_vf_num,
            # ceb_vf_active=dut.ceb_vf_active,

            # Hard IP reconfiguration interface
            # hip_reconfig_clk=dut.hip_reconfig_clk,
            # hip_reconfig_address=dut.hip_reconfig_address,
            # hip_reconfig_read=dut.hip_reconfig_read,
            # hip_reconfig_readdata=dut.hip_reconfig_readdata,
            # hip_reconfig_readdatavalid=dut.hip_reconfig_readdatavalid,
            # hip_reconfig_write=dut.hip_reconfig_write,
            # hip_reconfig_writedata=dut.hip_reconfig_writedata,
            # hip_reconfig_waitrequest=dut.hip_reconfig_waitrequest,
        )

        # self.dev.log.setLevel(logging.DEBUG)

        self.rc.make_port().connect(self.dev)

        self.driver = mqnic.Driver()

        self.dev.functions[0].msi_cap.msi_multiple_message_capable = 5

        self.dev.functions[0].configure_bar(
            0,
            2**len(dut.core_inst.core_pcie_inst.axil_ctrl_araddr),
            ext=True,
            prefetch=True)
        if hasattr(dut.core_inst.core_pcie_inst, 'pcie_app_ctrl'):
            self.dev.functions[0].configure_bar(
                2,
                2**len(dut.core_inst.core_pcie_inst.axil_app_ctrl_araddr),
                ext=True,
                prefetch=True)

        # Ethernet
        cocotb.start_soon(Clock(dut.qsfp0_rx_clk_1, 6.4, units="ns").start())
        self.qsfp0_1_source = XgmiiSource(dut.qsfp0_rxd_1, dut.qsfp0_rxc_1,
                                          dut.qsfp0_rx_clk_1,
                                          dut.qsfp0_rx_rst_1)
        cocotb.start_soon(Clock(dut.qsfp0_tx_clk_1, 6.4, units="ns").start())
        self.qsfp0_1_sink = XgmiiSink(dut.qsfp0_txd_1, dut.qsfp0_txc_1,
                                      dut.qsfp0_tx_clk_1, dut.qsfp0_tx_rst_1)

        cocotb.start_soon(Clock(dut.qsfp0_rx_clk_2, 6.4, units="ns").start())
        self.qsfp0_2_source = XgmiiSource(dut.qsfp0_rxd_2, dut.qsfp0_rxc_2,
                                          dut.qsfp0_rx_clk_2,
                                          dut.qsfp0_rx_rst_2)
        cocotb.start_soon(Clock(dut.qsfp0_tx_clk_2, 6.4, units="ns").start())
        self.qsfp0_2_sink = XgmiiSink(dut.qsfp0_txd_2, dut.qsfp0_txc_2,
                                      dut.qsfp0_tx_clk_2, dut.qsfp0_tx_rst_2)

        cocotb.start_soon(Clock(dut.qsfp0_rx_clk_3, 6.4, units="ns").start())
        self.qsfp0_3_source = XgmiiSource(dut.qsfp0_rxd_3, dut.qsfp0_rxc_3,
                                          dut.qsfp0_rx_clk_3,
                                          dut.qsfp0_rx_rst_3)
        cocotb.start_soon(Clock(dut.qsfp0_tx_clk_3, 6.4, units="ns").start())
        self.qsfp0_3_sink = XgmiiSink(dut.qsfp0_txd_3, dut.qsfp0_txc_3,
                                      dut.qsfp0_tx_clk_3, dut.qsfp0_tx_rst_3)

        cocotb.start_soon(Clock(dut.qsfp0_rx_clk_4, 6.4, units="ns").start())
        self.qsfp0_4_source = XgmiiSource(dut.qsfp0_rxd_4, dut.qsfp0_rxc_4,
                                          dut.qsfp0_rx_clk_4,
                                          dut.qsfp0_rx_rst_4)
        cocotb.start_soon(Clock(dut.qsfp0_tx_clk_4, 6.4, units="ns").start())
        self.qsfp0_4_sink = XgmiiSink(dut.qsfp0_txd_4, dut.qsfp0_txc_4,
                                      dut.qsfp0_tx_clk_4, dut.qsfp0_tx_rst_4)

        cocotb.start_soon(Clock(dut.qsfp1_rx_clk_1, 6.4, units="ns").start())
        self.qsfp1_1_source = XgmiiSource(dut.qsfp1_rxd_1, dut.qsfp1_rxc_1,
                                          dut.qsfp1_rx_clk_1,
                                          dut.qsfp1_rx_rst_1)
        cocotb.start_soon(Clock(dut.qsfp1_tx_clk_1, 6.4, units="ns").start())
        self.qsfp1_1_sink = XgmiiSink(dut.qsfp1_txd_1, dut.qsfp1_txc_1,
                                      dut.qsfp1_tx_clk_1, dut.qsfp1_tx_rst_1)

        cocotb.start_soon(Clock(dut.qsfp1_rx_clk_2, 6.4, units="ns").start())
        self.qsfp1_2_source = XgmiiSource(dut.qsfp1_rxd_2, dut.qsfp1_rxc_2,
                                          dut.qsfp1_rx_clk_2,
                                          dut.qsfp1_rx_rst_2)
        cocotb.start_soon(Clock(dut.qsfp1_tx_clk_2, 6.4, units="ns").start())
        self.qsfp1_2_sink = XgmiiSink(dut.qsfp1_txd_2, dut.qsfp1_txc_2,
                                      dut.qsfp1_tx_clk_2, dut.qsfp1_tx_rst_2)

        cocotb.start_soon(Clock(dut.qsfp1_rx_clk_3, 6.4, units="ns").start())
        self.qsfp1_3_source = XgmiiSource(dut.qsfp1_rxd_3, dut.qsfp1_rxc_3,
                                          dut.qsfp1_rx_clk_3,
                                          dut.qsfp1_rx_rst_3)
        cocotb.start_soon(Clock(dut.qsfp1_tx_clk_3, 6.4, units="ns").start())
        self.qsfp1_3_sink = XgmiiSink(dut.qsfp1_txd_3, dut.qsfp1_txc_3,
                                      dut.qsfp1_tx_clk_3, dut.qsfp1_tx_rst_3)

        cocotb.start_soon(Clock(dut.qsfp1_rx_clk_4, 6.4, units="ns").start())
        self.qsfp1_4_source = XgmiiSource(dut.qsfp1_rxd_4, dut.qsfp1_rxc_4,
                                          dut.qsfp1_rx_clk_4,
                                          dut.qsfp1_rx_rst_4)
        cocotb.start_soon(Clock(dut.qsfp1_tx_clk_4, 6.4, units="ns").start())
        self.qsfp1_4_sink = XgmiiSink(dut.qsfp1_txd_4, dut.qsfp1_txc_4,
                                      dut.qsfp1_tx_clk_4, dut.qsfp1_tx_rst_4)

        # dut.qsfp0_i2c_scl_i.setimmediatevalue(1)
        # dut.qsfp0_i2c_sda_i.setimmediatevalue(1)
        # dut.qsfp0_intr_n.setimmediatevalue(1)
        # dut.qsfp0_mod_prsnt_n.setimmediatevalue(0)

        # dut.qsfp0_rx_error_count_0.setimmediatevalue(0)
        # dut.qsfp0_rx_error_count_1.setimmediatevalue(0)
        # dut.qsfp0_rx_error_count_2.setimmediatevalue(0)
        # dut.qsfp0_rx_error_count_3.setimmediatevalue(0)

        # dut.qsfp1_i2c_scl_i.setimmediatevalue(1)
        # dut.qsfp1_i2c_sda_i.setimmediatevalue(1)
        # dut.qsfp1_intr_n.setimmediatevalue(1)
        # dut.qsfp1_mod_prsnt_n.setimmediatevalue(0)

        # dut.qsfp1_rx_error_count_0.setimmediatevalue(0)
        # dut.qsfp1_rx_error_count_1.setimmediatevalue(0)
        # dut.qsfp1_rx_error_count_2.setimmediatevalue(0)
        # dut.qsfp1_rx_error_count_3.setimmediatevalue(0)

        # dut.qspi_dq_i.setimmediatevalue(0)

        self.loopback_enable = False
        cocotb.start_soon(self._run_loopback())
Exemplo n.º 10
0
    def __init__(self, dut):
        self.dut = dut

        self.log = SimLog("cocotb.tb")
        self.log.setLevel(logging.DEBUG)

        cocotb.start_soon(Clock(dut.clk, 4, units="ns").start())

        # AXI
        self.address_space = AddressSpace()
        self.pool = self.address_space.create_pool(0, 0x8000_0000)

        self.axil_master = AxiLiteMaster(
            AxiLiteBus.from_prefix(dut, "s_axil_ctrl"), dut.clk, dut.rst)
        self.address_space.register_region(self.axil_master, 0x10_0000_0000)
        self.hw_regs = self.address_space.create_window(
            0x10_0000_0000, self.axil_master.size)

        self.axi_slave = AxiSlave(AxiBus.from_prefix(dut, "m_axi"), dut.clk,
                                  dut.rst, self.address_space)

        self.driver = mqnic.Driver()

        # Ethernet
        self.port_mac = []

        eth_int_if_width = len(
            dut.core_inst.iface[0].port[0].rx_async_fifo_inst.m_axis_tdata)
        eth_clock_period = 6.4
        eth_speed = 10e9

        if eth_int_if_width == 64:
            # 10G
            eth_clock_period = 6.4
            eth_speed = 10e9
        elif eth_int_if_width == 128:
            # 25G
            eth_clock_period = 2.56
            eth_speed = 25e9
        elif eth_int_if_width == 512:
            # 100G
            eth_clock_period = 3.102
            eth_speed = 100e9

        for iface in dut.core_inst.iface:
            for port in iface.port:
                cocotb.start_soon(
                    Clock(port.port_rx_clk, eth_clock_period,
                          units="ns").start())
                cocotb.start_soon(
                    Clock(port.port_tx_clk, eth_clock_period,
                          units="ns").start())

                port.port_rx_rst.setimmediatevalue(0)
                port.port_tx_rst.setimmediatevalue(0)

                mac = EthMac(tx_clk=port.port_tx_clk,
                             tx_rst=port.port_tx_rst,
                             tx_bus=AxiStreamBus.from_prefix(port, "axis_tx"),
                             tx_ptp_time=port.ptp.tx_ptp_cdc_inst.output_ts,
                             tx_ptp_ts=port.ptp.axis_tx_ptp_ts,
                             tx_ptp_ts_tag=port.ptp.axis_tx_ptp_ts_tag,
                             tx_ptp_ts_valid=port.ptp.axis_tx_ptp_ts_valid,
                             rx_clk=port.port_rx_clk,
                             rx_rst=port.port_rx_rst,
                             rx_bus=AxiStreamBus.from_prefix(port, "axis_rx"),
                             rx_ptp_time=port.ptp.rx_ptp_cdc_inst.output_ts,
                             ifg=12,
                             speed=eth_speed)

                self.port_mac.append(mac)

        dut.ctrl_reg_wr_wait.setimmediatevalue(0)
        dut.ctrl_reg_wr_ack.setimmediatevalue(0)
        dut.ctrl_reg_rd_data.setimmediatevalue(0)
        dut.ctrl_reg_rd_wait.setimmediatevalue(0)
        dut.ctrl_reg_rd_ack.setimmediatevalue(0)

        dut.ptp_sample_clk.setimmediatevalue(0)

        dut.s_axis_stat_tdata.setimmediatevalue(0)
        dut.s_axis_stat_tid.setimmediatevalue(0)
        dut.s_axis_stat_tvalid.setimmediatevalue(0)

        self.loopback_enable = False
        cocotb.start_soon(self._run_loopback())