L- and H-tile Avalon® Streaming and Single Root I/O Virtualization (SR-IOV) Intel® FPGA IP for PCI Express* User Guide

ID 683111
Date 3/07/2022

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

B. TX Credit Adjustment Sample Code

This sample Verilog HDL code computes the available credits for non-posted TLPs. It provides the updated credit information from the remote device on the tx_nph_cdts and tx_npd_cdts buses. The tx_nph_cdts and tx_npd_cdts buses drive the actual available credit space in the link partner's RX buffer. The credit information contained in these buses is difficult to use because, due to the EMIB (Embedded Multi-die Interconnect Bridge) latency, the values that you can observe on these buses are not real-time values.

The following Verilog RTL restores the credit limit for non-posted TLPs that can be used by application logic before it sends a TLP.

module nph_credit_limit_gen (
    input          clk,
    input          rst_n,
    input  [7:0]   tx_nph_cdts,
    input          tx_hdr_cdts_consumed,
    input  [1:0]   tx_cdts_type,
    output [7:0]   tx_nph_cdts_limit
    reg        tx_nph_credit_consume_1r;
    reg        tx_nph_credit_consume_2r;
    reg  [7:0] tx_nph_credit_consume_count_hip_3r;
    always @(posedge clk) begin
        if (!rst_n) begin
            tx_nph_credit_consume_1r        <= 1'b0;
            tx_nph_credit_consume_2r        <= 1'b0;
            tx_nph_credit_consume_count_hip <= 8'h0;

        end else begin
            tx_nph_credit_consume_1r <= (tx_cdts_type == 2'b01) ? 
                tx_hdr_cdts_consumed : 1'b0;
            tx_nph_credit_consume_2r <= tx_nph_credit_consume_1r;
            tx_nph_credit_consume_count_hip_3r <= 
                tx_nph_credit_consume_count_hip_3r + tx_nph_credit_consume_2r;
    assign tx_nph_cdts_limit = tx_nph_cdts + tx_nph_credit_consume_count_hip_3r;

The following pseudo-code explains the Verilog RTL above.

// reset credit_consume_count initially
tx_nph_credit_consume_count      = 0; 
tx_nph_credit_consume_count_hip  = 0;

if  (tx_nph_credit_limit_count – (tx_nph_credit_consume_count + tx_nph_credit_required) <= (2^8)/2) { 
  send NPH packet 
  tx_nph_credit_consume_count += tx_nph_credit_required;

tx_nph_credit_required: the number of credits required to send given NP TLP. For NP, tx_nph_credit_required is 1.
tx_nph_credit_consume_count_hip += (tx_cdts_type == "01") ? tx_hdr_cdts_consumed : 1'b0;
tx_nph_credit_consume_count_hip_delayed : three pld_clk cycle delayed tx_nph_credit_consume_count_hip
tx_nph_credit_limit_count = tx_nph_cdts + tx_nph_credit_consume_count_hip_delayed;