OpenCores
URL https://opencores.org/ocsvn/openhmc/openhmc/trunk

Subversion Repositories openhmc

[/] [openhmc/] [trunk/] [openHMC/] [rtl/] [hmc_controller/] [rx/] [rx_link.v] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 juko
/*
2
 *                              .--------------. .----------------. .------------.
3
 *                             | .------------. | .--------------. | .----------. |
4
 *                             | | ____  ____ | | | ____    ____ | | |   ______ | |
5
 *                             | ||_   ||   _|| | ||_   \  /   _|| | | .' ___  || |
6
 *       ___  _ __   ___ _ __  | |  | |__| |  | | |  |   \/   |  | | |/ .'   \_|| |
7
 *      / _ \| '_ \ / _ \ '_ \ | |  |  __  |  | | |  | |\  /| |  | | || |       | |
8
 *       (_) | |_) |  __/ | | || | _| |  | |_ | | | _| |_\/_| |_ | | |\ `.___.'\| |
9
 *      \___/| .__/ \___|_| |_|| ||____||____|| | ||_____||_____|| | | `._____.'| |
10
 *           | |               | |            | | |              | | |          | |
11
 *           |_|               | '------------' | '--------------' | '----------' |
12
 *                              '--------------' '----------------' '------------'
13
 *
14
 *  openHMC - An Open Source Hybrid Memory Cube Controller
15
 *  (C) Copyright 2014 Computer Architecture Group - University of Heidelberg
16
 *  www.ziti.uni-heidelberg.de
17
 *  B6, 26
18
 *  68159 Mannheim
19
 *  Germany
20
 *
21
 *  Contact: openhmc@ziti.uni-heidelberg.de
22
 *  http://ra.ziti.uni-heidelberg.de/openhmc
23
 *
24
 *   This source file is free software: you can redistribute it and/or modify
25
 *   it under the terms of the GNU Lesser General Public License as published by
26
 *   the Free Software Foundation, either version 3 of the License, or
27
 *   (at your option) any later version.
28
 *
29
 *   This source file is distributed in the hope that it will be useful,
30
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
 *   GNU Lesser General Public License for more details.
33
 *
34
 *   You should have received a copy of the GNU Lesser General Public License
35
 *   along with this source file.  If not, see <http://www.gnu.org/licenses/>.
36
 *
37
 *
38
 *  Module name: rx_link
39
 *
40
 */
41
 
42
`default_nettype none
43
 
44
module rx_link #(
45 15 juko
    parameter LOG_FPW              = 2,
46
    parameter FPW                  = 4,
47
    parameter DWIDTH               = FPW*128,
48
    parameter LOG_NUM_LANES        = 3,
49
    parameter NUM_LANES            = 2**LOG_NUM_LANES,
50
    parameter HMC_PTR_SIZE         = 8,
51
    parameter RF_COUNTER_SIZE      = 64,
52
    //Set Token Related
53
    parameter LOG_MAX_RX_TOKENS    = 8,
54
    parameter MAX_RTC_RET_LOG      = 8,
55
    //Control
56
    parameter XIL_CNT_PIPELINED    = 0,
57
    parameter CTRL_LANE_POLARITY   = 1,
58
    parameter RX_RELAX_INIT_TIMING = 1,
59
    parameter RX_BIT_SLIP_CNT_LOG  = 5,
60
    parameter DETECT_LANE_POLARITY = 1,
61
    parameter CTRL_LANE_REVERSAL   = 1,
62
    parameter BITSLIP_SHIFT_RIGHT  = 1,
63
    parameter OPEN_RSP_MODE        = 0
64 11 juko
) (
65
 
66
    //----------------------------------
67
    //----SYSTEM INTERFACE
68
    //----------------------------------
69
    input   wire                        clk,
70
    input   wire                        res_n,
71 15 juko
    input   wire                        run_rx,
72 11 juko
 
73
    //----------------------------------
74
    //----TO HMC PHY
75
    //----------------------------------
76 15 juko
    input   wire  [DWIDTH-1:0]          phy_scrambled_data_in,
77
    output  reg   [NUM_LANES-1:0]       phy_bit_slip,
78 11 juko
 
79
    //----------------------------------
80
    //----TO RX HTAX FIFO
81
    //----------------------------------
82 15 juko
    output  wire   [DWIDTH-1:0]         d_out_fifo_data,
83 11 juko
    input   wire                        d_out_fifo_a_full,
84 15 juko
    output  wire                        d_out_fifo_shift_in,
85
    output  wire   [4*FPW-1:0]          d_out_fifo_ctrl,
86 11 juko
 
87
    //----------------------------------
88
    //----TO TX Block
89
    //----------------------------------
90
    output  reg                         tx_link_retry,
91
    output  reg                         tx_error_abort_mode,
92
    output  reg                         tx_error_abort_mode_cleared,
93 15 juko
    output  reg   [7:0]                 tx_hmc_frp,
94
    output  reg   [7:0]                 tx_rrp,
95
    output  reg   [MAX_RTC_RET_LOG-1:0] tx_returned_tokens,
96
    output  wire  [LOG_FPW:0]           tx_hmc_tokens_to_return,
97
    output  wire  [LOG_FPW:0]           tx_hmc_poisoned_tokens_to_return,
98 11 juko
 
99
    //----------------------------------
100
    //----RF
101
    //----------------------------------
102
    //Monitoring    1-cycle set to increment
103 15 juko
    output  wire  [RF_COUNTER_SIZE-1:0] rf_cnt_poisoned,
104
    output  wire  [RF_COUNTER_SIZE-1:0] rf_cnt_rsp,
105 11 juko
    //Status
106 15 juko
    output  reg                         rf_link_up,
107
    output  reg   [2:0]                 rf_rx_init_status,
108 11 juko
    input   wire                        rf_hmc_sleep,
109
    //Init Status
110 15 juko
    output  wire  [NUM_LANES-1:0]       rf_descrambler_part_aligned,
111
    output  wire  [NUM_LANES-1:0]       rf_descrambler_aligned,
112 11 juko
    output  wire                        rf_all_descramblers_aligned,
113
    //Control
114 15 juko
    output  wire  [NUM_LANES-1:0]       rf_lane_polarity,
115 11 juko
    input   wire                        rf_scrambler_disable,
116 15 juko
    output  wire                        rf_lane_reversal_detected,
117
    output  reg   [NUM_LANES-1:0]       rf_descramblers_locked,
118
    input   wire  [4:0]                 rf_irtry_received_threshold
119 11 juko
 
120
);
121
`include "hmc_field_functions.h"
122
 
123
//=====================================================================================================
124
//-----------------------------------------------------------------------------------------------------
125
//---------WIRING AND SIGNAL STUFF---------------------------------------------------------------------
126
//-----------------------------------------------------------------------------------------------------
127
//=====================================================================================================
128
 
129
//------------------------------------------------------------------------------------Some general things
130 15 juko
//Link state -- Most likely will be encoded as one-hot FSM
131
localparam              HMC_DOWN            = 3'b000;
132
localparam              HMC_WAIT_FOR_NULL   = 3'b001;
133
localparam              HMC_NULL            = 3'b010;
134
localparam              HMC_TS1_PART_ALIGN  = 3'b011;
135
localparam              HMC_TS1_FIND_REF    = 3'b100;
136
localparam              HMC_TS1_ALIGN       = 3'b101;
137
localparam              HMC_NULL_NEXT       = 3'b110;
138
localparam              HMC_UP              = 3'b111;
139 11 juko
 
140
//Commands
141 15 juko
localparam              CMD_IRTRY           = 6'b000011;
142
localparam              CMD_RSP_ERROR       = 6'b111110;
143 11 juko
 
144
//Other helpful defines
145
localparam              WIDTH_PER_LANE          = (DWIDTH/NUM_LANES);
146
 
147
//16 bits is a ts1, so the init seq number is incremented according to the lane size
148
localparam              INIT_SEQ_INC_PER_CYCLE  = WIDTH_PER_LANE/16;
149
 
150
//MISC
151
integer i_f;    //counts to FPW
152
integer i_l;    //counts to NUM_LANES
153
integer i_c;    //counts to CYCLES_TO_COMPLETE_FULL_PACKET
154
 
155
genvar f;   //Counts to FPW
156
genvar n;   //Counts to NUM_LANES
157
genvar w;   //Counts to WIDTH_PER_LANE
158
 
159
//------------------------------------------------------------------------------------DESCRAMBLER AND DATA ORDERING
160
reg [NUM_LANES-1:0]     init_descrambler_part_aligned;
161
reg [NUM_LANES-1:0]     init_descrambler_aligned;
162
assign                  rf_descrambler_part_aligned = init_descrambler_part_aligned;
163
assign                  rf_descrambler_aligned      = init_descrambler_aligned;
164
 
165
//DATA and REORDERING
166
wire [128-1:0]              init_d_in_flit              [FPW-1:0];
167
wire [WIDTH_PER_LANE-1:0]   descrambled_data_per_lane   [NUM_LANES-1:0];
168 15 juko
reg  [WIDTH_PER_LANE-1:0]   descrambled_data_per_lane_dly   [NUM_LANES-1:0];
169 11 juko
wire [DWIDTH-1:0]           d_in;
170 15 juko
wire [DWIDTH-1:0]           d_in_dly;
171 11 juko
wire [128-1:0]              d_in_flit                   [FPW-1:0];
172
 
173
//Valid FLIT sources. A FLIT is valid when it is not NULL
174 15 juko
wire [FPW-1:0]              valid_flit_src;         //bit0 = flit0, ...
175
wire [FPW-1:0]              init_valid_flit_src;    //bit0 = flit0, ...
176 11 juko
 
177
generate
178
 
179
    //-- Apply lane reversal if detected
180
    for(n = 0; n < NUM_LANES; n = n + 1) begin : apply_lane_reversal
181
        for(w = 0; w < WIDTH_PER_LANE; w = w + 1) begin
182
            if(CTRL_LANE_REVERSAL==1)begin
183
                assign d_in[w*NUM_LANES+n]      = rf_lane_reversal_detected ? descrambled_data_per_lane[NUM_LANES-1-n][w] : descrambled_data_per_lane[n][w];
184 15 juko
                assign d_in_dly[w*NUM_LANES+n]  = rf_lane_reversal_detected ? descrambled_data_per_lane_dly[NUM_LANES-1-n][w] : descrambled_data_per_lane_dly[n][w];
185 11 juko
            end else begin
186
                assign d_in[w*NUM_LANES+n]      = descrambled_data_per_lane[n][w];
187 15 juko
                assign d_in_dly[w*NUM_LANES+n]  = descrambled_data_per_lane_dly[n][w];
188 11 juko
            end
189
        end
190
    end
191
 
192
 
193
    for(f = 0; f < FPW; f = f + 1) begin : reorder_input_data
194
        //-- Reorder the descrambled data to FLITs
195
        assign d_in_flit[f]       = d_in[128-1+(f*128):f*128];
196 15 juko
        assign init_d_in_flit[f]  = d_in_dly[128-1+(f*128):f*128];
197
        //-- Generate valid flit positions
198
        assign valid_flit_src[f]        = |d_in_flit[f][5:0];
199
        assign init_valid_flit_src[f]   = |init_d_in_flit[f];
200 11 juko
    end
201
 
202
endgenerate
203
 
204
 
205
//------------------------------------------------------------------------------------INIT
206 15 juko
localparam                  LINK_DOWN   = 1'b0;
207
localparam                  LINK_UP     = 1'b1;
208 11 juko
 
209 15 juko
reg [NUM_LANES-1:0]         init_bit_slip;
210
reg [NUM_LANES-1:0]         init_bit_slip_part;
211
reg [RX_BIT_SLIP_CNT_LOG-1:0]init_bit_slip_cnt;
212
wire[NUM_LANES-1:0]         init_descrambler_locked;           //locked from the descrambler
213
reg [3:0]                   init_tmp_seq;
214 11 juko
 
215
assign                      rf_all_descramblers_aligned = &init_descrambler_aligned;
216
 
217
//--------------TS1 recognition
218 15 juko
localparam                  TS1_INDEPENDENT_PORTION = {4'hF,4'h0};
219
localparam                  TS1_LANE0_PORTION       = 4'h3;         //Not used if RX_RELAX_INIT_TIMING==1
220
localparam                  TS1_LANEX_PORTION       = 4'h5;         //Not used if RX_RELAX_INIT_TIMING==1
221
localparam                  TS1_LANE7OR15_PORTION   = 4'hc;
222 11 juko
 
223 15 juko
localparam                  TS1_SEQS_PER_CYCLE_AND_LANE = DWIDTH/NUM_LANES/16;
224 11 juko
 
225 15 juko
wire    [NUM_LANES-1:0]                  init_lane_has_correct_ts1;
226
wire    [TS1_SEQS_PER_CYCLE_AND_LANE-1:0]init_lane_has_correct_ts1_vec   [NUM_LANES-1:0];
227 11 juko
 
228
genvar t;
229
generate
230
    //Make sure that the lanes have valid ts1 sequences throughout the entire data stream
231
    for(n=0;n<NUM_LANES;n=n+1) begin : lane_has_correct_ts1_gen
232
        assign init_lane_has_correct_ts1[n] = &init_lane_has_correct_ts1_vec[n];
233 15 juko
    end
234 11 juko
 
235 15 juko
    for(t=0;t<TS1_SEQS_PER_CYCLE_AND_LANE;t=t+1) begin : ts1_recognition_gen
236
        if(RX_RELAX_INIT_TIMING==1) begin
237
            for(n=0;n<NUM_LANES;n=n+1) begin
238
                assign init_lane_has_correct_ts1_vec[n][t] = (descrambled_data_per_lane[n][(t*16)+8+:8] == {TS1_INDEPENDENT_PORTION});
239
            end
240
        end else begin
241
            for(n=1;n<NUM_LANES-1;n=n+1) begin
242
                assign init_lane_has_correct_ts1_vec[n][t] = (descrambled_data_per_lane[n][(t*16)+4+:12] == {TS1_INDEPENDENT_PORTION,TS1_LANEX_PORTION});
243 11 juko
            end
244 15 juko
            assign init_lane_has_correct_ts1_vec[0][t] = (descrambled_data_per_lane[0][(t*16)+4+:12] == {TS1_INDEPENDENT_PORTION,TS1_LANE0_PORTION})||
245
                (CTRL_LANE_REVERSAL==1 ? descrambled_data_per_lane[0][(t*16)+4+:12] == {TS1_INDEPENDENT_PORTION,TS1_LANE7OR15_PORTION} : 0);
246
            assign init_lane_has_correct_ts1_vec[NUM_LANES-1][t] = (descrambled_data_per_lane[NUM_LANES-1][(t*16)+4+:12] == {TS1_INDEPENDENT_PORTION,TS1_LANE7OR15_PORTION})||
247
                (CTRL_LANE_REVERSAL==1 ? descrambled_data_per_lane[NUM_LANES-1][(t*16)+4+:12] == {TS1_INDEPENDENT_PORTION,TS1_LANE0_PORTION} : 0);
248 11 juko
        end
249
    end
250
endgenerate
251
 
252
//--------------Align the lanes, scan for the ts1 seq
253 15 juko
wire [LOG_NUM_LANES-1:0] init_lane_cnt;
254
assign                   init_lane_cnt = init_bit_slip_cnt[LOG_NUM_LANES-1:0];
255
wire [3:0]               init_seq_diff;
256 11 juko
 
257
//If one of the descramblers is already partially aligned search for other lanes with their ts1 sequence number close this lane. 
258 15 juko
assign                   init_seq_diff = (BITSLIP_SHIFT_RIGHT==1 ? (descrambled_data_per_lane[init_lane_cnt][3:0] - init_tmp_seq)
259
                                         : init_tmp_seq - descrambled_data_per_lane[init_lane_cnt][3:0]);
260 11 juko
 
261
//------------------------------------------------------------------------------------Input Stage: Scan for Packets, Headers, Tails ...
262
reg  [FPW-1:0]          data2crc_hdr;
263
reg  [FPW-1:0]          data2crc_tail;
264
reg  [FPW-1:0]          data2crc_valid;
265
wire [(FPW*4)-1:0]      data2crc_lng;
266
reg  [3:0]              data2crc_lng_per_flit [FPW-1:0];
267
reg  [3:0]              data2crc_payload_remain;
268
 
269
reg  [FPW-1:0]          data2crc_hdr_comb;
270
reg  [FPW-1:0]          data2crc_tail_comb;
271
reg  [FPW-1:0]          data2crc_valid_comb;
272
reg  [3:0]              data2crc_lng_per_flit_comb [FPW-1:0];
273
reg  [3:0]              data2crc_payload_remain_comb;
274
 
275
generate
276 15 juko
        for(f = 0; f < (FPW); f = f + 1) begin : reorder_crc_input
277
            assign data2crc_lng[(f*4)+:4] = data2crc_lng_per_flit[f];
278 11 juko
        end
279
endgenerate
280
 
281
//------------------------------------------------------------------------------------CRC
282
wire [DWIDTH-1:0]       crc_d_out_data;
283
wire [128-1:0]          crc_d_out_flit              [FPW-1:0];
284
wire [FPW-1:0]          crc_d_out_flit_is_hdr;
285
wire [FPW-1:0]          crc_d_out_flit_is_tail;
286
wire [FPW-1:0]          crc_d_out_flit_is_valid;
287
wire [FPW-1:0]          crc_d_out_flit_is_error;
288
wire [FPW-1:0]          crc_d_out_flit_is_poisoned;
289
wire [FPW-1:0]          crc_d_out_flit_has_rtc;
290
wire [FPW-1:0]          crc_d_out_flit_is_flow;
291
 
292
generate
293
        for(f=0;f<FPW;f=f+1) begin : reorder_crc_output
294
            assign crc_d_out_flit[f] = crc_d_out_data[128-1+(f*128):f*128];
295
        end
296
endgenerate
297
 
298
//------------------------------------------------------------------------------------Start TX retry Stage
299 15 juko
reg     [128-1:0]       flit_after_irtry_stage                   [FPW-1:0];
300
reg     [FPW-1:0]       flit_after_irtry_stage_is_hdr;
301
reg     [FPW-1:0]       flit_after_irtry_stage_is_tail;
302
reg     [FPW-1:0]       flit_after_irtry_stage_is_valid;
303
reg     [FPW-1:0]       flit_after_irtry_stage_is_error;
304
reg     [FPW-1:0]       flit_after_irtry_stage_is_poisoned;
305
reg     [FPW-1:0]       flit_after_irtry_stage_has_rtc;
306
reg     [FPW-1:0]       flit_after_irtry_stage_is_start_retry;
307
reg     [FPW-1:0]       flit_after_irtry_stage_is_clear_error;
308
reg     [FPW-1:0]       flit_after_irtry_stage_is_start_retry_comb;
309
reg     [FPW-1:0]       flit_after_irtry_stage_is_clear_error_comb;
310 11 juko
 
311
//------------------------------------------------------------------------------------SeqStage and Seqnum
312
reg     [128-1:0]       flit_after_seq_check                   [FPW-1:0];
313
reg     [FPW-1:0]       flit_after_seq_check_is_hdr;
314
reg     [FPW-1:0]       flit_after_seq_check_is_tail;
315
reg     [FPW-1:0]       flit_after_seq_check_is_valid;
316
reg     [FPW-1:0]       flit_after_seq_check_is_error;
317
reg     [FPW-1:0]       flit_after_seq_check_is_error_comb;
318
reg     [FPW-1:0]       flit_after_seq_check_is_poisoned;
319
reg     [FPW-1:0]       flit_after_seq_check_has_rtc;
320
reg     [FPW-1:0]       flit_after_seq_check_is_start_retry;
321 15 juko
reg     [FPW-1:0]       flit_after_seq_check_is_clear_error;
322 11 juko
 
323
reg     [2:0]           next_seqnum;
324 15 juko
reg     [2:0]           next_seqnum_comb; //can be reduced to [1:0] for 2FLIT config
325 11 juko
reg     [2:0]           first_seq_after_error;
326
 
327 15 juko
//------------------------------------------------------------------------------------IRTRY packet count stage
328
reg     [128-1:0]       flit_after_mask_stage                   [FPW-1:0];
329
reg     [FPW-1:0]       flit_after_mask_stage_is_hdr;
330
reg     [FPW-1:0]       flit_after_mask_stage_is_tail;
331
reg     [FPW-1:0]       flit_after_mask_stage_is_valid;
332
reg     [FPW-1:0]       flit_after_mask_stage_is_valid_mask_lsb;
333
reg     [FPW-1:0]       flit_after_mask_stage_is_valid_mask_msb;
334
reg     [FPW-1:0]       flit_after_mask_stage_is_error;
335
reg     [FPW-1:0]       flit_after_mask_stage_is_poisoned;
336
reg     [FPW-1:0]       flit_after_mask_stage_is_start_retry;
337
reg     [FPW-1:0]       flit_after_mask_stage_has_rtc;
338
 
339
 
340
//Assign FLITs to word, necessary for the invalidation stage pipeline
341
wire   [DWIDTH-1:0]            flit_after_mask_stage_word;
342
generate
343
        for(f = 0; f < (FPW); f = f + 1) begin : reorder_flits_to_word
344
            assign flit_after_mask_stage_word[(f*128)+128-1:(f*128)] = flit_after_mask_stage[f];
345
        end
346
endgenerate
347
 
348 11 juko
//------------------------------------------------------------------------------------Invalidation Stage
349 15 juko
//Assuming Max Pkt size = 9 FLITs
350 11 juko
localparam CYCLES_TO_COMPLETE_FULL_PACKET   =   (FPW == 2) ? 5 :
351 15 juko
                                                (FPW == 4) ? 3 :
352 11 juko
                                                (FPW == 6) ? 3 :
353 15 juko
                                                2;
354 11 juko
 
355
//Regs to retrieve the pkt length, assign the length to correspoding tail. The packet will be invalidated then
356
reg     [3:0]        lng_per_tail      [FPW-1:0] ;
357
reg     [3:0]        lng_per_tail_comb [FPW-1:0] ;
358
reg     [3:0]        lng_temp;
359
reg     [3:0]        lng_comb;
360 15 juko
//Signal that an error was detected. Invalidate all FLITs after
361
reg                  error;
362 11 juko
 
363
reg     [DWIDTH-1:0]    flit_in_invalidation_data          [CYCLES_TO_COMPLETE_FULL_PACKET-1:0];
364
reg     [FPW-1:0]       flit_in_invalidation_is_hdr        [CYCLES_TO_COMPLETE_FULL_PACKET-1:0];
365
reg     [FPW-1:0]       flit_in_invalidation_is_tail       [CYCLES_TO_COMPLETE_FULL_PACKET-1:0];
366
reg     [FPW-1:0]       flit_in_invalidation_is_valid      [CYCLES_TO_COMPLETE_FULL_PACKET-1:0];
367
reg     [FPW-1:0]       flit_in_invalidation_mask_error;
368
reg     [FPW-1:0]       flit_in_invalidation_is_poisoned   [CYCLES_TO_COMPLETE_FULL_PACKET-1:0];
369
reg     [FPW-1:0]       flit_in_invalidation0_is_poisoned_comb;
370
 
371
//------------------------------------------------------------------------------------Checked FLITs
372
wire     [128-1:0]      checked_flit             [FPW-1:0];
373
wire     [FPW-1:0]      checked_flit_is_poisoned;
374
wire     [FPW-1:0]      checked_flit_is_valid;
375
wire     [FPW-1:0]      checked_flit_is_hdr;
376
wire     [FPW-1:0]      checked_flit_is_tail;
377
 
378
assign checked_flit_is_hdr         = flit_in_invalidation_is_hdr       [CYCLES_TO_COMPLETE_FULL_PACKET-1] & flit_in_invalidation_is_valid     [CYCLES_TO_COMPLETE_FULL_PACKET-1];
379
assign checked_flit_is_tail        = flit_in_invalidation_is_tail      [CYCLES_TO_COMPLETE_FULL_PACKET-1] & flit_in_invalidation_is_valid     [CYCLES_TO_COMPLETE_FULL_PACKET-1];
380
assign checked_flit_is_valid       = flit_in_invalidation_is_valid     [CYCLES_TO_COMPLETE_FULL_PACKET-1] ;
381
assign checked_flit_is_poisoned    = flit_in_invalidation_is_poisoned  [CYCLES_TO_COMPLETE_FULL_PACKET-1] & flit_in_invalidation_is_valid     [CYCLES_TO_COMPLETE_FULL_PACKET-1];
382
 
383
generate
384
        for(f = 0; f < (FPW); f = f + 1) begin : reorder_invalidation_word_back_to_flits
385
            assign checked_flit[f] = flit_in_invalidation_data[CYCLES_TO_COMPLETE_FULL_PACKET-1][128-1+(f*128):f*128];
386
        end
387
endgenerate
388
 
389
//------------------------------------------------------------------------------------Counter
390 15 juko
reg [LOG_FPW:0]             rf_cnt_poisoned_comb;
391
reg [LOG_FPW:0]             rf_cnt_rsp_comb;
392 11 juko
 
393
//------------------------------------------------------------------------------------Input Buffer
394 15 juko
reg     [MAX_RTC_RET_LOG-1:0]rtc_sum_comb; //for 8 FLIT config, maximum 8*31 tokens will be returned per cycle
395 11 juko
 
396
reg     [128-1:0]            input_buffer_d_in_flit    [FPW-1:0];
397 15 juko
reg     [FPW-1:0]            input_buffer_is_valid;
398 11 juko
reg     [FPW-1:0]            input_buffer_is_hdr;
399
reg     [FPW-1:0]            input_buffer_is_tail;
400
reg     [FPW-1:0]            input_buffer_is_error_rsp;
401
wire    [DWIDTH+(4*FPW)-1:0] input_buffer_d_in;
402
wire    [DWIDTH+(4*FPW)-1:0] input_buffer_d_out;
403
wire                         input_buffer_empty;
404 15 juko
wire                         input_buffer_shift_in;
405 11 juko
wire                         input_buffer_shift_out;
406
assign                       input_buffer_shift_out    =   ~(input_buffer_empty || d_out_fifo_a_full);
407
 
408
generate
409
        for(f = 0; f < (FPW); f = f + 1) begin : assign_flits_to_input_buffer_to_a_single_reg
410
            assign input_buffer_d_in[f*128+128-1:f*128] = input_buffer_d_in_flit[f];
411 15 juko
            assign input_buffer_d_in[DWIDTH+f]          = input_buffer_is_valid[f];
412 11 juko
            assign input_buffer_d_in[DWIDTH+f+FPW]      = input_buffer_is_hdr[f];
413
            assign input_buffer_d_in[DWIDTH+f+(2*FPW)]  = input_buffer_is_tail[f];
414
            assign input_buffer_d_in[DWIDTH+f+(3*FPW)]  = input_buffer_is_error_rsp[f];
415
        end
416
endgenerate
417
 
418
//------------------------------------------------------------------------------------LINK RETRY
419 15 juko
reg  [4:0]     irtry_start_retry_cnt;
420
reg  [4:0]     irtry_clear_error_cnt;
421
reg  [4:0]     irtry_start_retry_cnt_comb;
422
reg  [4:0]     irtry_clear_error_cnt_comb;
423 11 juko
reg            irtry_clear_trig;
424
 
425
//=====================================================================================================
426
//-----------------------------------------------------------------------------------------------------
427
//---------ACTUAL LOGIC STARTS HERE--------------------------------------------------------------------
428
//-----------------------------------------------------------------------------------------------------
429
//=====================================================================================================
430
 
431
//========================================================================================================================================
432
//------------------------------------------------------------------INIT
433
//========================================================================================================================================
434 15 juko
 
435
generate
436
    if(CTRL_LANE_REVERSAL==1) begin : control_lane_reversal
437
        reg    init_lane_reversal_detected;
438
        assign rf_lane_reversal_detected = init_lane_reversal_detected;
439
 
440
        `ifdef ASYNC_RES
441
        always @(posedge clk or negedge res_n)  begin `else
442
        always @(posedge clk)  begin `endif
443
            if(!res_n) begin
444
                init_lane_reversal_detected   <= 1'b0;
445
            end else begin
446
                if(rf_rx_init_status==HMC_DOWN) begin
447
                    init_lane_reversal_detected   <= 1'b0;
448
                end
449
                if(rf_rx_init_status==HMC_TS1_ALIGN && rf_all_descramblers_aligned && (descrambled_data_per_lane[0][7:4] ==  TS1_LANE7OR15_PORTION)) begin
450
                    //lane reversal detected, reverse the input stream lane by lane
451
                    init_lane_reversal_detected   <= 1'b1;
452
                end
453
            end
454
        end
455
    end else begin
456
        assign rf_lane_reversal_detected = 1'b0;
457 11 juko
    end
458
 
459 15 juko
    if(DETECT_LANE_POLARITY==1) begin : detect_lane_reversal
460
        reg [NUM_LANES-1:0] init_lane_polarity;
461
        assign rf_lane_polarity = init_lane_polarity;
462
        `ifdef ASYNC_RES
463
        always @(posedge clk or negedge res_n)  begin `else
464
        always @(posedge clk)  begin `endif
465
            if(!res_n) begin
466
                init_lane_polarity        <= {NUM_LANES{1'b0}};
467
            end else begin
468
                if(rf_rx_init_status==HMC_DOWN) begin
469
                    init_lane_polarity    <= {NUM_LANES{1'b0}};
470
                end
471
                //Detect Lane polarity when HMC is sending first NULLs
472
                if(rf_rx_init_status==HMC_WAIT_FOR_NULL) begin
473
                    for(i_l = 0;i_l<NUM_LANES;i_l=i_l+1)begin
474
                        if(descrambled_data_per_lane[i_l] == {WIDTH_PER_LANE{1'b1}})begin
475
                            init_lane_polarity[i_l] <=  1'b1;
476
                        end
477
                    end
478
                end
479
            end
480
        end
481
    end else begin
482
        assign rf_lane_polarity = {NUM_LANES{1'b0}};
483
    end
484
endgenerate
485
 
486 11 juko
`ifdef ASYNC_RES
487
always @(posedge clk or negedge res_n)  begin `else
488
always @(posedge clk)  begin `endif
489 15 juko
 
490
    for(i_l = 0;i_l<NUM_LANES;i_l=i_l+1)begin
491
        `ifdef RESET_ALL
492
            if(!res_n) descrambled_data_per_lane_dly[i_l] <= {WIDTH_PER_LANE{1'b0}};
493
            else
494
        `endif
495
        descrambled_data_per_lane_dly[i_l] <= descrambled_data_per_lane[i_l];
496
    end
497
 
498 11 juko
if(!res_n) begin
499
    //----Misc
500 15 juko
    init_descrambler_aligned        <= {NUM_LANES{1'b0}};
501
    init_descrambler_part_aligned   <= {NUM_LANES{1'b0}};
502
    phy_bit_slip                    <= {NUM_LANES{1'b0}};
503
    init_bit_slip                   <= {NUM_LANES{1'b0}};
504
    init_bit_slip_part              <= {NUM_LANES{1'b0}};
505
    init_bit_slip_cnt               <= {RX_BIT_SLIP_CNT_LOG{1'b0}};
506
    init_tmp_seq                    <= 4'h0;
507
    rf_rx_init_status               <= HMC_DOWN;
508
    rf_link_up                      <= LINK_DOWN;
509
    rf_descramblers_locked          <= {NUM_LANES{1'b0}};
510
 
511 11 juko
end
512
else begin
513
 
514 15 juko
    rf_descramblers_locked  <= run_rx ? init_descrambler_locked : {NUM_LANES{1'b0}};
515 11 juko
    init_bit_slip           <= {NUM_LANES{1'b0}};
516 15 juko
    init_bit_slip_part      <= {NUM_LANES{1'b0}};
517
    phy_bit_slip            <= init_bit_slip | init_bit_slip_part;
518
    init_tmp_seq            <= init_tmp_seq + INIT_SEQ_INC_PER_CYCLE;
519 11 juko
 
520 15 juko
    init_bit_slip_cnt   <= init_bit_slip_cnt +1;
521 11 juko
 
522 15 juko
    case (rf_rx_init_status)
523
        HMC_DOWN: begin
524
            init_descrambler_aligned         <= {NUM_LANES{1'b0}};
525
            init_descrambler_part_aligned    <= {NUM_LANES{1'b0}};
526
            if(&rf_descramblers_locked) begin
527
                rf_rx_init_status <= HMC_WAIT_FOR_NULL;
528 11 juko
            end
529
        end
530 15 juko
        HMC_WAIT_FOR_NULL: begin
531
            if(|init_valid_flit_src == 1'b0) begin
532
                rf_rx_init_status <= HMC_NULL;
533
            end
534
        end
535
        HMC_NULL: begin
536
            if(&init_valid_flit_src) begin
537
                rf_rx_init_status      <= HMC_TS1_PART_ALIGN;
538
            end
539
        end
540
        HMC_TS1_PART_ALIGN: begin
541
            if(|init_bit_slip_cnt[RX_BIT_SLIP_CNT_LOG-1:LOG_NUM_LANES] == 1'b0)begin
542
                init_bit_slip_part[init_lane_cnt]                <= ~init_lane_has_correct_ts1[init_lane_cnt];
543
                init_descrambler_part_aligned[init_lane_cnt]     <= init_lane_has_correct_ts1[init_lane_cnt];
544
            end
545
            if(&init_descrambler_part_aligned/*=={NUM_LANES{1'b1}}*/) begin
546
                rf_rx_init_status   <= HMC_TS1_FIND_REF;
547
                init_tmp_seq        <= descrambled_data_per_lane[0][3:0] + INIT_SEQ_INC_PER_CYCLE;
548
                init_bit_slip_cnt   <= {RX_BIT_SLIP_CNT_LOG{1'b0}};
549
            end
550
        end
551
        HMC_TS1_FIND_REF: begin
552
            if(init_seq_diff < 2)
553
                init_tmp_seq <= descrambled_data_per_lane[init_lane_cnt][3:0] + INIT_SEQ_INC_PER_CYCLE;
554
 
555
            if(&init_bit_slip_cnt==1'b1)
556
                rf_rx_init_status   <= HMC_TS1_ALIGN;
557 11 juko
 
558
        end
559 15 juko
        HMC_TS1_ALIGN: begin
560
 
561
            if(|init_bit_slip_cnt[RX_BIT_SLIP_CNT_LOG-1:LOG_NUM_LANES] == 1'b0)begin
562
                if(|init_seq_diff==1'b0 && init_lane_has_correct_ts1[init_lane_cnt])begin
563
                    init_descrambler_aligned[init_lane_cnt] <= 1'b1;
564 11 juko
                end else begin
565 15 juko
                    init_bit_slip[init_lane_cnt] <= 1'b1;
566 11 juko
                end
567
            end
568
 
569 15 juko
            if(rf_all_descramblers_aligned) begin
570
                rf_rx_init_status  <= HMC_NULL_NEXT;
571
            end
572
        end
573
        HMC_NULL_NEXT: begin
574
             if(|init_valid_flit_src == 1'b0) begin
575
                rf_rx_init_status   <= HMC_UP;
576
                rf_link_up          <= LINK_UP;
577
            end
578
        end
579 11 juko
 
580 15 juko
        HMC_UP: begin
581
            if(rf_hmc_sleep || !run_rx) begin
582
                rf_rx_init_status   <= HMC_DOWN;
583
                rf_link_up          <= LINK_DOWN;
584 11 juko
            end
585
        end
586 15 juko
    endcase
587 11 juko
end
588
end
589
 
590
//========================================================================================================================================
591
//------------------------------------------------------------------Packet Processing
592
//========================================================================================================================================
593
//==================================================================================
594
//---------------------------------Detect HDR,Tail,Valid Flits and provide to CRC logic
595
//==================================================================================
596
always @(*)  begin
597
    //Use the remaining payload from last cycle
598
    data2crc_payload_remain_comb = data2crc_payload_remain;
599
 
600
    data2crc_hdr_comb    = {FPW{1'b0}};
601
    data2crc_tail_comb   = {FPW{1'b0}};
602
    data2crc_valid_comb  = {FPW{1'b0}};
603
 
604
    for(i_f=0;i_f<FPW;i_f=i_f+1) begin
605
 
606 15 juko
        data2crc_lng_per_flit_comb[i_f] = 4'h0;
607 11 juko
 
608 15 juko
 
609
        case (data2crc_payload_remain_comb)
610
        4'h1: begin
611
            data2crc_tail_comb[i_f]      = 1'b1;
612
            data2crc_valid_comb[i_f]     = 1'b1;
613
            data2crc_payload_remain_comb = 4'h0;
614 11 juko
        end
615 15 juko
        4'h0: begin
616
            if(valid_flit_src[i_f])begin
617
                data2crc_hdr_comb[i_f]   = 1'b1;
618
                data2crc_valid_comb[i_f] = 1'b1;
619
                if(lng(d_in_flit[i_f])<2 || lng(d_in_flit[i_f])>9 || !lng_dln_equal(d_in_flit[i_f]))begin
620
                    data2crc_lng_per_flit_comb[i_f] = 4'h1;
621
                    data2crc_tail_comb[i_f]         = 1'b1;
622
                    data2crc_payload_remain_comb    = 4'h0;
623
                end else begin
624
                    data2crc_payload_remain_comb    = lng(d_in_flit[i_f]) -1;
625
                    data2crc_lng_per_flit_comb[i_f] = lng(d_in_flit[i_f]);
626
                end
627
            end
628
        end
629
        default: begin
630 11 juko
            data2crc_valid_comb[i_f]     = 1'b1;
631
            data2crc_payload_remain_comb = data2crc_payload_remain_comb - 1;
632
        end
633 15 juko
        endcase
634 11 juko
    end
635
end
636
 
637
//Register the combinational logic from previous stage
638
`ifdef ASYNC_RES
639
always @(posedge clk or negedge res_n)  begin `else
640
always @(posedge clk)  begin `endif
641
if(!res_n) begin
642
 
643 15 juko
    data2crc_hdr             <= {FPW{1'b0}};
644
    data2crc_tail            <= {FPW{1'b0}};
645
    data2crc_valid           <= {FPW{1'b0}};
646
    data2crc_payload_remain  <= 4'h0;
647 11 juko
 
648
    for(i_f=0;i_f<FPW;i_f=i_f+1) begin
649 15 juko
        data2crc_lng_per_flit[i_f] <= 4'h0;
650 11 juko
    end
651
 
652
end else begin
653 15 juko
    if(rf_link_up) begin
654 11 juko
        data2crc_valid  <= data2crc_valid_comb;
655
    end
656 15 juko
 
657
    data2crc_hdr            <= data2crc_hdr_comb;
658
    data2crc_tail           <= data2crc_tail_comb;
659
    data2crc_payload_remain <= data2crc_payload_remain_comb;
660 11 juko
 
661
    for(i_f=0;i_f<FPW;i_f=i_f+1) begin
662
        data2crc_lng_per_flit[i_f] <= data2crc_lng_per_flit_comb[i_f];
663
    end
664
end
665
end
666
 
667
//====================================================================
668 15 juko
//---------------------------------IRTRY Stage
669 11 juko
//====================================================================
670
//-- Count all types of IRTRY packets
671
always @(*)  begin
672
 
673 15 juko
    flit_after_irtry_stage_is_start_retry_comb = {FPW{1'b0}};
674
    flit_after_irtry_stage_is_clear_error_comb = {FPW{1'b0}};
675 11 juko
 
676
    irtry_clear_error_cnt_comb = irtry_clear_error_cnt;
677
    irtry_start_retry_cnt_comb = irtry_start_retry_cnt;
678
 
679
 
680 15 juko
    for(i_f=0;i_f<(FPW);i_f=i_f+1) begin
681 11 juko
 
682 15 juko
        if( crc_d_out_flit_is_flow[i_f] &&
683
            cmd(crc_d_out_flit[i_f]) == {CMD_IRTRY} &&
684
            !crc_d_out_flit_is_error[i_f]
685 11 juko
        ) begin
686
 
687 15 juko
            if(irtry_start_retry_flag(crc_d_out_flit[i_f])) begin
688 11 juko
                //it's a start tx retry pkt
689 15 juko
                irtry_start_retry_cnt_comb   = irtry_start_retry_cnt_comb + 5'h1;
690
                irtry_clear_error_cnt_comb   = 5'h0;
691 11 juko
            end else begin
692
                //must be clear error pkt
693 15 juko
                irtry_clear_error_cnt_comb   = irtry_clear_error_cnt_comb + 5'h1;
694
                irtry_start_retry_cnt_comb   = 5'h0;
695 11 juko
            end
696
 
697
            if(irtry_start_retry_cnt_comb == rf_irtry_received_threshold) begin
698
                //The start retry packet that reaches the trehold is treated as valid and will trigger tx retry
699 15 juko
                flit_after_irtry_stage_is_start_retry_comb[i_f] = 1'b1;
700 11 juko
            end
701
 
702
            //Clear error abort when threshold reached, allow following FLITs to be valid
703
            if(irtry_clear_error_cnt_comb == rf_irtry_received_threshold) begin
704 15 juko
                flit_after_irtry_stage_is_clear_error_comb[i_f] = 1'b1;
705 11 juko
            end
706
 
707
        end else begin
708
            //Reset both counters when received a non-irtry packet
709 15 juko
            irtry_start_retry_cnt_comb = 5'h0;
710
            irtry_clear_error_cnt_comb = 5'h0;
711 11 juko
        end
712
    end
713
end
714
 
715
//Save the temporary counts to be re-used in the next cycle and register the clear trigger
716
`ifdef ASYNC_RES
717
always @(posedge clk or negedge res_n)  begin `else
718
always @(posedge clk)  begin `endif
719
if(!res_n) begin
720
    irtry_clear_trig      <= 1'b0;
721
 
722 15 juko
    irtry_clear_error_cnt <= {5{1'b0}};
723
    irtry_start_retry_cnt <= {5{1'b0}};
724 11 juko
 
725
end else begin
726 15 juko
    irtry_clear_trig      <= |flit_after_irtry_stage_is_clear_error_comb;
727 11 juko
 
728
    irtry_clear_error_cnt <= irtry_clear_error_cnt_comb;
729
    irtry_start_retry_cnt <= irtry_start_retry_cnt_comb;
730
end
731
end
732
 
733
//Propagate data and apply the valid masks
734
`ifdef ASYNC_RES
735
always @(posedge clk or negedge res_n)  begin `else
736
always @(posedge clk)  begin `endif
737 15 juko
 
738 11 juko
    for(i_f = 0;i_f<(FPW);i_f=i_f+1) begin
739 15 juko
        `ifdef RESET_ALL
740
        if(!res_n) flit_after_irtry_stage[i_f]  <= {128{1'b0}};
741
        else
742
        `endif
743
        flit_after_irtry_stage[i_f] <= crc_d_out_flit[i_f];
744 11 juko
    end
745 15 juko
 
746
if(!res_n) begin
747
    `ifdef RESET_ALL
748
        flit_after_irtry_stage_is_hdr         <= {FPW{1'b0}};
749
        flit_after_irtry_stage_is_tail        <= {FPW{1'b0}};
750
        flit_after_irtry_stage_is_poisoned    <= {FPW{1'b0}};
751
        flit_after_irtry_stage_has_rtc        <= {FPW{1'b0}};
752
        flit_after_irtry_stage_is_error       <= {FPW{1'b0}};
753
        flit_after_irtry_stage_is_valid       <= {FPW{1'b0}};
754
    `endif
755
    flit_after_irtry_stage_is_start_retry <= {FPW{1'b0}};
756
    flit_after_irtry_stage_is_clear_error <= {FPW{1'b0}};
757 11 juko
end else begin
758
 
759 15 juko
    flit_after_irtry_stage_is_start_retry <= flit_after_irtry_stage_is_start_retry_comb;
760
    flit_after_irtry_stage_is_clear_error <= flit_after_irtry_stage_is_clear_error_comb;
761 11 juko
end
762 15 juko
    flit_after_irtry_stage_is_hdr         <= crc_d_out_flit_is_hdr;
763
    flit_after_irtry_stage_is_tail        <= crc_d_out_flit_is_tail;
764
    flit_after_irtry_stage_is_poisoned    <= crc_d_out_flit_is_poisoned;
765
    flit_after_irtry_stage_has_rtc        <= crc_d_out_flit_has_rtc;
766
    flit_after_irtry_stage_is_error       <= crc_d_out_flit_is_error;
767
    flit_after_irtry_stage_is_valid       <= crc_d_out_flit_is_valid;
768 11 juko
end
769
 
770
//-------------------------------------------Error abort mode
771
`ifdef ASYNC_RES
772
always @(posedge clk or negedge res_n)  begin `else
773
always @(posedge clk)  begin `endif
774
if(!res_n) begin
775
 
776
    //TX signaling
777
    tx_error_abort_mode             <= 1'b0;
778
    tx_error_abort_mode_cleared     <= 1'b0;
779
 
780
end else begin
781
 
782
    tx_error_abort_mode_cleared <= 1'b0;
783
 
784
    if(irtry_clear_trig) begin
785
        tx_error_abort_mode         <= 1'b0;
786
        tx_error_abort_mode_cleared <= 1'b1;
787
    end
788
 
789
    //Set error abort mode again if error detected
790 15 juko
    if(|crc_d_out_flit_is_error || flit_after_seq_check_is_error)begin
791 11 juko
        tx_error_abort_mode <= 1'b1;
792
    end
793
 
794
end
795
end
796
 
797
//==================================================================================
798
//---------------------------------SEQ check
799
//==================================================================================
800
//Check the seqnum FLIT by FLIT. Assign the last received seqnum when error abort mode is cleared
801
//!Lots of logic levels for 8FLIT config
802
always @(*)  begin
803
 
804
    next_seqnum_comb                    = 3'h0;
805
    flit_after_seq_check_is_error_comb  = {FPW{1'b0}};
806
 
807 15 juko
    for(i_f=0;i_f<(FPW);i_f=i_f+1) begin
808
        if(flit_after_irtry_stage_has_rtc[i_f]) begin
809 11 juko
        //All packets that have an RTC also have a valid seqnum
810 15 juko
            next_seqnum_comb = next_seqnum_comb + 3'h1;
811
            if(seq(flit_after_irtry_stage[i_f]) != (next_seqnum + next_seqnum_comb)) begin
812 11 juko
                flit_after_seq_check_is_error_comb[i_f]  = 1'b1;
813
            end
814
        end
815
    end
816
end
817
 
818
`ifdef ASYNC_RES
819
always @(posedge clk or negedge res_n)  begin `else
820
always @(posedge clk)  begin `endif
821 15 juko
 
822
    for(i_f = 0;i_f<(FPW);i_f=i_f+1) begin
823
        `ifdef RESET_ALL
824
        if(!res_n) flit_after_seq_check[i_f]  <= {128{1'b0}};
825
        else
826
        `endif
827
        flit_after_seq_check[i_f] <= flit_after_irtry_stage[i_f];
828
    end
829
 
830 11 juko
if(!res_n) begin
831
 
832 15 juko
    next_seqnum                         <= 3'h0;
833 11 juko
 
834 15 juko
    `ifdef RESET_ALL
835
        flit_after_seq_check_is_hdr         <= {FPW{1'b0}};
836
        flit_after_seq_check_is_tail        <= {FPW{1'b0}};
837
        flit_after_seq_check_is_valid       <= {FPW{1'b0}};
838
        flit_after_seq_check_is_poisoned    <= {FPW{1'b0}};
839
        flit_after_seq_check_has_rtc        <= {FPW{1'b0}};
840
        flit_after_seq_check_is_start_retry <= {FPW{1'b0}};
841
        flit_after_seq_check_is_clear_error <= {FPW{1'b0}};
842
    `endif
843 11 juko
    flit_after_seq_check_is_error       <= {FPW{1'b0}};
844
end else begin
845
 
846
    //Set the expected sequence number to the first one after error abort mode was cleared
847
    //otherwise apply the last seqnum + combinatioanl offset
848 15 juko
    if(|flit_after_irtry_stage_is_clear_error_comb) begin
849 11 juko
        next_seqnum     <= first_seq_after_error + next_seqnum_comb;
850
    end else begin
851
        next_seqnum     <= next_seqnum + next_seqnum_comb;
852
    end
853
 
854
    //propage data to next stage and include any error bits that were detected during sequence number check
855 15 juko
    flit_after_seq_check_is_error       <= flit_after_irtry_stage_is_error |
856 11 juko
                                           flit_after_seq_check_is_error_comb;
857 15 juko
 
858
end
859
    flit_after_seq_check_is_hdr         <= flit_after_irtry_stage_is_hdr;
860
    flit_after_seq_check_is_tail        <= flit_after_irtry_stage_is_tail;
861
    flit_after_seq_check_is_valid       <= flit_after_irtry_stage_is_valid;
862
    flit_after_seq_check_is_poisoned    <= flit_after_irtry_stage_is_poisoned;
863
    flit_after_seq_check_has_rtc        <= flit_after_irtry_stage_has_rtc;
864
    flit_after_seq_check_is_start_retry <= flit_after_irtry_stage_is_start_retry;
865
    flit_after_seq_check_is_clear_error <= flit_after_irtry_stage_is_clear_error;
866
end
867
 
868
//==================================================================================
869
//---------------------------------Valid Mask - Remove valid bits for invalid FLITs
870
//==================================================================================
871
always@(*) begin
872
    flit_after_mask_stage_is_valid_mask_lsb = {FPW{1'b0}};
873
    flit_after_mask_stage_is_valid_mask_msb = {FPW{1'b0}};
874
    for(i_f = FPW-1; i_f >=0; i_f = i_f - 1) begin
875
        if(flit_after_seq_check_is_clear_error[i_f]) begin
876
            flit_after_mask_stage_is_valid_mask_msb       = {{FPW-1{1'b1}},1'b0} << i_f;
877
        end
878
        if(flit_after_seq_check_is_error[i_f]) begin
879
            flit_after_mask_stage_is_valid_mask_lsb       = {FPW{1'b1}} >> (FPW-i_f);
880
        end
881 11 juko
    end
882
 
883
end
884 15 juko
 
885
`ifdef ASYNC_RES
886
always @(posedge clk or negedge res_n)  begin `else
887
always @(posedge clk)  begin `endif
888
 
889
    for(i_f = 0;i_f<(FPW);i_f=i_f+1) begin
890
        flit_after_mask_stage[i_f] <= flit_after_seq_check[i_f];
891
    end
892
 
893
if(!res_n) begin
894
 
895
    `ifdef RESET_ALL
896
        flit_after_mask_stage_is_hdr         <= {FPW{1'b0}};
897
        flit_after_mask_stage_is_tail        <= {FPW{1'b0}};
898
        flit_after_mask_stage_is_poisoned    <= {FPW{1'b0}};
899
        flit_after_mask_stage_has_rtc        <= {FPW{1'b0}};
900
        flit_after_mask_stage_is_error       <= {FPW{1'b0}};
901
        flit_after_mask_stage_is_start_retry <= 1'b0;
902
    `endif
903
    flit_after_mask_stage_is_valid  <= {FPW{1'b0}};
904
    error                           <= 1'b0;
905
end else begin
906
 
907
    if(|flit_after_seq_check_is_clear_error)
908
        error <= 1'b0;
909
 
910
    if(|flit_after_seq_check_is_error)
911
        error <= 1'b1;
912
 
913
    casex({error,|flit_after_seq_check_is_clear_error,|flit_after_seq_check_is_error})
914
        3'b000: begin
915
            flit_after_mask_stage_is_valid <= flit_after_seq_check_is_valid;
916
        end
917
        3'b001: begin
918
            flit_after_mask_stage_is_valid <= flit_after_seq_check_is_valid & flit_after_mask_stage_is_valid_mask_lsb;
919
        end
920
        3'bx10: begin
921
            flit_after_mask_stage_is_valid <= flit_after_seq_check_is_valid & flit_after_mask_stage_is_valid_mask_msb;
922
        end
923
        3'bx11: begin
924
            flit_after_mask_stage_is_valid <= flit_after_seq_check_is_valid & flit_after_mask_stage_is_valid_mask_msb & flit_after_mask_stage_is_valid_mask_lsb;
925
        end
926
        default: begin
927
            flit_after_mask_stage_is_valid <= {FPW{1'b0}};
928
        end
929
    endcase
930
 
931
    //propage data to next stage and include any error bits that were detected
932
 
933 11 juko
end
934 15 juko
    flit_after_mask_stage_is_hdr         <= flit_after_seq_check_is_hdr;
935
    flit_after_mask_stage_is_tail        <= flit_after_seq_check_is_tail;
936
    flit_after_mask_stage_is_poisoned    <= flit_after_seq_check_is_poisoned;
937
    flit_after_mask_stage_has_rtc        <= flit_after_seq_check_has_rtc;
938
    flit_after_mask_stage_is_error       <= flit_after_seq_check_is_error & flit_after_seq_check_is_tail;
939
    flit_after_mask_stage_is_start_retry <= flit_after_seq_check_is_start_retry;
940
end
941 11 juko
 
942
//==================================================================================
943 15 juko
//---------------------------------Tokens/Pointers/Sequence numbers
944 11 juko
//==================================================================================
945 15 juko
//Count Tokens that were returned
946 11 juko
always @(*)  begin
947 15 juko
    rtc_sum_comb                  = {MAX_RTC_RET_LOG{1'b0}};
948
    for(i_f=0;i_f<(FPW);i_f=i_f+1) begin
949
        if(flit_after_mask_stage_has_rtc[i_f] && flit_after_mask_stage_is_valid[i_f])begin
950
            rtc_sum_comb                  =  rtc_sum_comb + rtc(flit_after_mask_stage[i_f]);
951
        end
952
    end
953
end
954
 
955
//Extract FRP/RRP + last seq (which is necessary to check packets after error_abort_mode is cleared)
956
`ifdef ASYNC_RES
957
always @(posedge clk or negedge res_n)  begin `else
958
always @(posedge clk)  begin `endif
959
if(!res_n) begin
960
 
961
    tx_hmc_frp                      <= {8{1'b0}};
962
    tx_rrp                          <= {8{1'b0}};
963
    tx_returned_tokens              <= {MAX_RTC_RET_LOG{1'b0}};
964
    first_seq_after_error           <= 3'h0;
965
    tx_link_retry                   <= 1'b0;
966
 
967
end else begin
968
    //Return tokens
969
    tx_returned_tokens              <= rtc_sum_comb;
970
 
971
    //Process FLITs and extract frp/seq/rrp if applicable
972
    for(i_f=0;i_f<(FPW);i_f=i_f+1) begin
973
 
974
        if((flit_after_mask_stage_is_tail[i_f] && flit_after_mask_stage_is_valid[i_f]) || flit_after_mask_stage_is_start_retry[i_f]) begin
975
            tx_rrp                  <=  rrp(flit_after_mask_stage[i_f]);
976
        end
977
 
978
        if(flit_after_mask_stage_has_rtc[i_f] && flit_after_mask_stage_is_valid[i_f])begin
979
            tx_hmc_frp                      <= frp(flit_after_mask_stage[i_f]);
980
            first_seq_after_error           <= seq(flit_after_mask_stage[i_f]);
981
        end
982
    end
983
 
984
    //-------------------------------------------TX retry
985
    tx_link_retry   <= 1'b0;
986
 
987
    if(|flit_after_mask_stage_is_start_retry)begin
988
        tx_link_retry              <= 1'b1;
989
    end
990
 
991
end
992
end
993
 
994
//==================================================================================
995
//---------------------------------Retrieve the lengths to invalidate FLITs
996
//==================================================================================
997
always @(*)  begin
998 11 juko
//Retrieve the length from the header and assign it to the tail. This information will be used in the
999
//invalidation stage to mask out FLITs that belong to the faulty packet
1000
 
1001
    lng_comb = lng_temp;
1002
 
1003 15 juko
    for(i_f=0;i_f<(FPW);i_f=i_f+1) begin
1004 11 juko
 
1005 15 juko
        if(flit_after_seq_check_is_hdr[i_f]) begin
1006
            if(flit_after_seq_check_is_error[i_f]) begin
1007
                lng_comb = 4'h1;
1008 11 juko
            end else begin
1009 15 juko
                lng_comb = lng(flit_after_seq_check[i_f]);
1010 11 juko
            end
1011
        end
1012
 
1013 15 juko
        if(flit_after_seq_check_is_tail[i_f]) begin
1014 11 juko
            lng_per_tail_comb[i_f] = lng_comb;
1015
        end else begin
1016 15 juko
            lng_per_tail_comb[i_f] = 4'h0;
1017 11 juko
        end
1018
 
1019
    end
1020
end
1021
 
1022
//Register combinational values
1023
`ifdef ASYNC_RES
1024
always @(posedge clk or negedge res_n)  begin `else
1025
always @(posedge clk)  begin `endif
1026
if(!res_n) begin
1027 15 juko
    for(i_f=0;i_f<(FPW);i_f=i_f+1) begin
1028 11 juko
        lng_per_tail[i_f] <= 0;
1029
    end
1030 15 juko
    lng_temp    <= 4'h0;
1031 11 juko
end else begin
1032 15 juko
    for(i_f=0;i_f<(FPW);i_f=i_f+1) begin
1033 11 juko
        lng_per_tail[i_f] <= lng_per_tail_comb[i_f];
1034
    end
1035
    lng_temp    <= lng_comb;
1036
end
1037
end
1038
 
1039
//==================================================================================
1040
//---------------------------------FLIT Invalidation Stage
1041
//==================================================================================
1042
//Constant propagation for some parts of the invalidation stage
1043
`ifdef ASYNC_RES
1044
always @(posedge clk or negedge res_n)  begin `else
1045
always @(posedge clk)  begin `endif
1046
 
1047 15 juko
    `ifdef RESET_ALL
1048
    if(!res_n) begin
1049
        flit_in_invalidation_data[0]            <= {DWIDTH{1'b0}};
1050
 
1051
        for(i_c=0; i_c<(CYCLES_TO_COMPLETE_FULL_PACKET-1); i_c=i_c+1) begin
1052
            flit_in_invalidation_data[i_c+1]    <= {DWIDTH{1'b0}};
1053
        end
1054
    end else
1055
    `endif
1056
    begin
1057
        flit_in_invalidation_data[0]            <= flit_after_mask_stage_word;
1058
 
1059
        for(i_c=0; i_c<(CYCLES_TO_COMPLETE_FULL_PACKET-1); i_c=i_c+1) begin
1060
            flit_in_invalidation_data[i_c+1]        <= flit_in_invalidation_data[i_c];
1061
        end
1062 11 juko
    end
1063
 
1064 15 juko
    flit_in_invalidation_is_hdr[0]          <= flit_after_mask_stage_is_hdr;
1065
    flit_in_invalidation_is_tail[0]         <= flit_after_mask_stage_is_tail;
1066
 
1067 11 juko
    for(i_c=0; i_c<(CYCLES_TO_COMPLETE_FULL_PACKET-1); i_c=i_c+1) begin
1068
        flit_in_invalidation_is_hdr[i_c+1]          <= flit_in_invalidation_is_hdr[i_c];
1069
        flit_in_invalidation_is_tail[i_c+1]         <= flit_in_invalidation_is_tail[i_c];
1070
    end
1071
end
1072
 
1073
//Mark all poisoned FLITs
1074
always @(*)  begin
1075
    flit_in_invalidation0_is_poisoned_comb  = {FPW{1'b0}};
1076
    for(i_f = FPW-1; i_f>=0; i_f = i_f-1) begin
1077 15 juko
        if(flit_after_mask_stage_is_poisoned[i_f])begin
1078 11 juko
            flit_in_invalidation0_is_poisoned_comb =flit_in_invalidation0_is_poisoned_comb |
1079
                                                    (({FPW{1'b1}} >> (FPW-i_f-1)) & ~({FPW{1'b1}} >> lng_per_tail[i_f]+(FPW-i_f-1)));
1080
        end
1081
    end
1082
end
1083
`ifdef ASYNC_RES
1084
always @(posedge clk or negedge res_n)  begin `else
1085
always @(posedge clk)  begin `endif
1086
if(!res_n) begin
1087
 
1088
    for(i_c = 0; i_c < (CYCLES_TO_COMPLETE_FULL_PACKET); i_c = i_c + 1) begin
1089 15 juko
        flit_in_invalidation_is_poisoned[i_c]  <= {FPW{1'b0}};
1090 11 juko
    end
1091
 
1092
end else begin
1093
    flit_in_invalidation_is_poisoned[0]     <= flit_in_invalidation0_is_poisoned_comb;
1094
 
1095
    for(i_c = 0; i_c < (CYCLES_TO_COMPLETE_FULL_PACKET-1); i_c = i_c + 1) begin
1096
        flit_in_invalidation_is_poisoned[i_c+1] <= flit_in_invalidation_is_poisoned[i_c];
1097
    end
1098
 
1099
    //If there is a poisoned packet mark all FLITs as such
1100
    for(i_f = FPW-1; i_f>=0; i_f = i_f-1) begin
1101 15 juko
        if(flit_after_mask_stage_is_poisoned[i_f]) begin
1102 11 juko
 
1103
            for(i_c = 0; i_c < (CYCLES_TO_COMPLETE_FULL_PACKET-1); i_c = i_c + 1) begin
1104
                if(lng_per_tail[i_f] > ((i_c)*FPW)+i_f+1) begin
1105
                    flit_in_invalidation_is_poisoned[i_c+1] <= flit_in_invalidation_is_poisoned[i_c] | ~({FPW{1'b1}} >> lng_per_tail[i_f]-(i_c*FPW)-i_f-1);
1106
                end
1107
            end
1108
 
1109
        end
1110
    end
1111
end
1112
end
1113
 
1114
 
1115
//Invalidate FLITs that belong to errorenous packets
1116
`ifdef ASYNC_RES
1117
always @(posedge clk or negedge res_n)  begin `else
1118
always @(posedge clk)  begin `endif
1119
if(!res_n) begin
1120
 
1121
    for(i_c = 0; i_c < (CYCLES_TO_COMPLETE_FULL_PACKET); i_c = i_c + 1) begin
1122 15 juko
        flit_in_invalidation_is_valid[i_c]     <= {FPW{1'b0}};
1123 11 juko
    end
1124 15 juko
    flit_in_invalidation_mask_error <= {FPW{1'b0}};
1125 11 juko
 
1126
end else begin
1127
 
1128
    //Reset the masks for invalidation stages
1129
    flit_in_invalidation_mask_error         <= {FPW{1'b1}};
1130
 
1131
    //Propate invalidation stages but apply error and poisoned masks to the second stage
1132
    for(i_c = 1; i_c < (CYCLES_TO_COMPLETE_FULL_PACKET-1); i_c = i_c + 1) begin
1133
        flit_in_invalidation_is_valid[i_c+1] <= flit_in_invalidation_is_valid[i_c];
1134
    end
1135
    flit_in_invalidation_is_valid[1] <= flit_in_invalidation_is_valid[0] & flit_in_invalidation_mask_error;
1136
 
1137 15 juko
    //First apply valids from previous stage
1138
    flit_in_invalidation_is_valid[0] <= flit_after_mask_stage_is_valid;
1139 11 juko
 
1140 15 juko
    //At least one FLIT contained an error in its tail. Leave all FLITs before the error untouched
1141
    for(i_f = FPW-1; i_f>=0; i_f = i_f-1) begin
1142
        if(flit_after_mask_stage_is_error[i_f]) begin
1143
            flit_in_invalidation_mask_error <= {FPW{1'b1}} >> (FPW-i_f-1+lng_per_tail[i_f]);
1144 11 juko
        end
1145
 
1146 15 juko
    //Now use the length of the packet to invalidate FLITs that may reside in the next stages already
1147
        if(flit_after_mask_stage_is_error[i_f] && &flit_in_invalidation_mask_error) begin
1148
            for(i_c = 0; i_c < (CYCLES_TO_COMPLETE_FULL_PACKET-1); i_c = i_c + 1) begin
1149
                if(lng_per_tail[i_f] > ((i_c)*FPW)+i_f+1) begin
1150
                    flit_in_invalidation_is_valid[i_c+1] <= flit_in_invalidation_is_valid[i_c] &
1151
                                                            ({FPW{1'b1}} >> lng_per_tail[i_f]-(i_c*FPW)-i_f-1);
1152 11 juko
                end
1153
            end
1154
        end
1155
    end
1156
 
1157
end
1158
end
1159
 
1160
//==================================================================================
1161
//---------------------------------Fill the input buffer with all response packets
1162
//==================================================================================
1163
`ifdef ASYNC_RES
1164
always @(posedge clk or negedge res_n)  begin `else
1165
always @(posedge clk)  begin `endif
1166
 
1167 15 juko
    for(i_f=0;i_f<(FPW);i_f=i_f+1) begin
1168
        `ifdef RESET_ALL
1169
        if(!res_n) input_buffer_d_in_flit[i_f] <= {128{1'b0}};
1170
        else
1171
        `endif
1172
        input_buffer_d_in_flit[i_f]           <= checked_flit[i_f];
1173 11 juko
    end
1174
 
1175 15 juko
    for(i_f=0;i_f<FPW;i_f=i_f+1) begin
1176
        input_buffer_is_error_rsp[i_f]  <= checked_flit_is_hdr[i_f]     && cmd(checked_flit[i_f])==CMD_RSP_ERROR;
1177
        input_buffer_is_hdr[i_f]        <= checked_flit_is_hdr[i_f]     && !checked_flit_is_poisoned[i_f] && !is_rsp_flow(checked_flit[i_f]);
1178
        input_buffer_is_valid[i_f]      <= checked_flit_is_valid[i_f]   && !checked_flit_is_poisoned[i_f] && !(is_rsp_flow(checked_flit[i_f]) && checked_flit_is_hdr[i_f]);
1179
        input_buffer_is_tail[i_f]       <= checked_flit_is_tail[i_f]    && !checked_flit_is_poisoned[i_f] && !(is_rsp_flow(checked_flit[i_f]) && checked_flit_is_hdr[i_f]);
1180 11 juko
    end
1181
 
1182
end
1183 15 juko
assign input_buffer_shift_in = |input_buffer_is_valid;
1184 11 juko
 
1185
//==================================================================================
1186
//---------------------------------Count responses and poisoned packets
1187
//==================================================================================
1188
always @(*)  begin
1189
    rf_cnt_poisoned_comb = {LOG_FPW+1{1'b0}};
1190
    rf_cnt_rsp_comb      = {LOG_FPW+1{1'b0}};
1191
 
1192 15 juko
    for(i_f=0;i_f<(FPW);i_f=i_f+1) begin
1193 11 juko
        if(checked_flit_is_poisoned[i_f] && checked_flit_is_hdr[i_f])begin
1194
            rf_cnt_poisoned_comb = rf_cnt_poisoned_comb + {{LOG_FPW{1'b0}},1'b1};
1195
        end
1196
        if(input_buffer_is_tail[i_f] && !input_buffer_is_error_rsp[i_f])begin
1197
            //if its a tail but not error response
1198
            rf_cnt_rsp_comb = rf_cnt_rsp_comb + {{LOG_FPW{1'b0}},1'b1};
1199
        end
1200
    end
1201
end
1202
 
1203 15 juko
`ifdef XILINX
1204
    //Use the openhmc_counter48_wrapper_xilinx in building_blocks/counter to directly instantiate DSP48
1205
    openhmc_counter48_wrapper_xilinx #(
1206
        .INC_SIZE(LOG_FPW+1),
1207
        .PIPELINED(XIL_CNT_PIPELINED)
1208
    )cnt_poisoned (
1209
        .clk(clk),
1210
        .res_n(res_n),
1211
        .inc_value(rf_cnt_poisoned_comb),
1212
        .value(rf_cnt_poisoned)
1213
    );
1214 11 juko
 
1215 15 juko
    openhmc_counter48_wrapper_xilinx #(
1216
        .INC_SIZE(LOG_FPW+1),
1217
        .PIPELINED(XIL_CNT_PIPELINED)
1218
    )cnt_rsp (
1219
        .clk(clk),
1220
        .res_n(res_n),
1221
        .inc_value(rf_cnt_rsp_comb),
1222
        .value(rf_cnt_rsp)
1223
    );
1224
 
1225
`else
1226
    reg [RF_COUNTER_SIZE-1:0]   rf_cnt_poisoned_temp;
1227
    reg [RF_COUNTER_SIZE-1:0]   rf_cnt_rsp_temp;
1228
    assign rf_cnt_poisoned      = rf_cnt_poisoned_temp;
1229
    assign rf_cnt_rsp           = rf_cnt_rsp_temp;
1230
 
1231
    `ifdef ASYNC_RES
1232
    always @(posedge clk or negedge res_n)  begin `else
1233
    always @(posedge clk)  begin `endif
1234
    if(!res_n) begin
1235
        rf_cnt_poisoned_temp <= {RF_COUNTER_SIZE{1'b0}};
1236
        rf_cnt_rsp_temp      <= {RF_COUNTER_SIZE{1'b0}};
1237
    end else begin
1238
        rf_cnt_poisoned_temp <= rf_cnt_poisoned_temp + {{RF_COUNTER_SIZE-LOG_FPW-1{1'b0}},rf_cnt_poisoned_comb};
1239
        rf_cnt_rsp_temp      <= rf_cnt_rsp_temp + {{RF_COUNTER_SIZE-LOG_FPW-1{1'b0}},rf_cnt_rsp_comb};
1240
    end
1241
    end
1242
`endif
1243
 
1244
 
1245 11 juko
//==================================================================================
1246 15 juko
//---------------------------------Return the tokens
1247 11 juko
//==================================================================================
1248 15 juko
generate
1249
    if(OPEN_RSP_MODE==0) begin : return_tokens
1250 11 juko
 
1251 15 juko
    reg   [MAX_RTC_RET_LOG-1:0] rtc_returned_tokens;
1252
    reg   [MAX_RTC_RET_LOG-1:0] rtc_poisoned_tokens_to_return;
1253
    reg   [LOG_FPW:0]           tokens_out_of_fifo_sum_comb;
1254
    reg   [LOG_FPW:0]           tokens_poisoned;
1255
 
1256
    assign tx_hmc_tokens_to_return          = rtc_returned_tokens;
1257
    assign tx_hmc_poisoned_tokens_to_return = rtc_poisoned_tokens_to_return;
1258
 
1259
        //Poisoned tokens will be returned before they enter the input buffer
1260
        always @(*)  begin
1261
            tokens_poisoned          = {LOG_FPW+1{1'b0}};
1262
 
1263
            for(i_f=0; i_f<FPW; i_f=i_f+1) begin
1264
                tokens_poisoned  =   tokens_poisoned + checked_flit_is_poisoned[i_f];
1265
            end
1266 11 juko
        end
1267 15 juko
 
1268
        //All other tokens will be returned as they leave the input buffer
1269
        always @(*)  begin
1270
            tokens_out_of_fifo_sum_comb          = {LOG_FPW+1{1'b0}};
1271
 
1272
            if(input_buffer_shift_out)begin
1273
                for(i_f=0; i_f<FPW; i_f=i_f+1) begin
1274
                    tokens_out_of_fifo_sum_comb  =   tokens_out_of_fifo_sum_comb +
1275
                                                     (input_buffer_d_out[DWIDTH+i_f] &&
1276
                                                     !input_buffer_d_out[DWIDTH+i_f+(3*FPW)]);    //increment if there's a valid FLIT, but not an error response
1277
                end
1278
            end
1279
        end
1280
 
1281
        `ifdef ASYNC_RES
1282
        always @(posedge clk or negedge res_n)  begin `else
1283
            always @(posedge clk)  begin `endif
1284
            if(!res_n) begin
1285
                rtc_returned_tokens            <= {LOG_FPW+1{1'b0}};
1286
                rtc_poisoned_tokens_to_return  <= {LOG_FPW+1{1'b0}};
1287
            end else begin
1288
                rtc_returned_tokens            <= tokens_out_of_fifo_sum_comb;
1289
                rtc_poisoned_tokens_to_return  <= tokens_poisoned;
1290
            end
1291
        end
1292
 
1293
    end else begin
1294
        //no input buffer, and no tokens will be returned
1295
        assign tx_hmc_tokens_to_return          = {LOG_FPW+1{1'b0}};
1296
        assign tx_hmc_poisoned_tokens_to_return = {LOG_FPW+1{1'b0}};
1297 11 juko
    end
1298 15 juko
endgenerate
1299 11 juko
 
1300
 
1301
 
1302 15 juko
//==================================================================================
1303
//---------------------------------Shift response packets into the output fifo
1304
//==================================================================================
1305
generate
1306
    if(OPEN_RSP_MODE==0) begin : assign_output_data
1307 11 juko
 
1308 15 juko
    reg   [DWIDTH-1:0]          out_data;
1309
    reg                         out_shift_in;
1310
    reg   [4*FPW-1:0]           out_ctrl;
1311 11 juko
 
1312 15 juko
    assign d_out_fifo_data      = out_data;
1313
    assign d_out_fifo_shift_in  = out_shift_in;
1314
    assign d_out_fifo_ctrl      = out_ctrl;
1315
 
1316
        `ifdef ASYNC_RES
1317
        always @(posedge clk or negedge res_n)  begin `else
1318
        always @(posedge clk)  begin `endif
1319
            if(!res_n) begin
1320
                //----FIFO
1321
                out_shift_in          <= 1'b0;
1322
                out_ctrl              <= {4*FPW{1'b0}};
1323
                out_data              <= {DWIDTH{1'b0}};
1324
            end else begin
1325
                if(input_buffer_shift_out)begin
1326
                    out_shift_in         <= 1'b1;
1327
                    out_ctrl             <= input_buffer_d_out[DWIDTH+(4*FPW)-1:DWIDTH];
1328
                    out_data             <= input_buffer_d_out[DWIDTH-1:0];
1329
                end else begin
1330
                    out_shift_in          <= 1'b0;
1331
                end
1332
            end
1333
        end
1334
    end else begin  //Open Response Mode
1335
 
1336
    assign d_out_fifo_data      = input_buffer_d_in[DWIDTH-1:0];
1337
    assign d_out_fifo_shift_in  = input_buffer_shift_in;
1338
    assign d_out_fifo_ctrl      = input_buffer_d_in[DWIDTH+(4*FPW)-1:DWIDTH];
1339
 
1340 11 juko
    end
1341 15 juko
endgenerate
1342 11 juko
 
1343
 
1344
 
1345
//=====================================================================================================
1346
//-----------------------------------------------------------------------------------------------------
1347
//---------INSTANTIATIONS HERE-------------------------------------------------------------------------
1348
//-----------------------------------------------------------------------------------------------------
1349
//=====================================================================================================
1350
 
1351 15 juko
wire   lanes_can_lock;
1352
assign lanes_can_lock = (rf_hmc_sleep || !run_rx) ? 1'b0 : 1'b1;
1353
// 
1354 11 juko
//Lane Init
1355
genvar i;
1356
generate
1357
for(i=0;i<NUM_LANES;i=i+1)begin : lane_gen
1358
    rx_lane_logic #(
1359
        .DWIDTH(DWIDTH),
1360
        .NUM_LANES(NUM_LANES),
1361
        .CTRL_LANE_POLARITY(CTRL_LANE_POLARITY),
1362
        .BITSLIP_SHIFT_RIGHT(BITSLIP_SHIFT_RIGHT)
1363
    ) rx_lane_I (
1364
        .clk(clk),
1365 15 juko
        .res_n(res_n),
1366
        .can_lock(lanes_can_lock),
1367
        .bit_slip(phy_bit_slip[i]),
1368 11 juko
        .descrambler_locked(init_descrambler_locked[i]),
1369
        .descrambler_disable(rf_scrambler_disable),
1370
        .lane_polarity(rf_lane_polarity[i]),
1371
        .scrambled_data_in(phy_scrambled_data_in[i*WIDTH_PER_LANE+WIDTH_PER_LANE-1:i*WIDTH_PER_LANE]),
1372
        .descrambled_data_out(descrambled_data_per_lane[i])
1373
    );
1374
end
1375
endgenerate
1376
 
1377
//HMC CRC Logic
1378
rx_crc_compare #(
1379
    .DWIDTH(DWIDTH),
1380
    .FPW(FPW),
1381
    .LOG_FPW(LOG_FPW)
1382
)
1383
rx_crc_compare
1384
(
1385
    .clk(clk),
1386
    .res_n(res_n),
1387
    //input
1388 15 juko
    .d_in_data(d_in_dly),
1389 11 juko
    .d_in_hdr(data2crc_hdr),
1390
    .d_in_tail(data2crc_tail),
1391
    .d_in_valid(data2crc_valid),
1392 15 juko
    // .d_in_error(data2crc_error),
1393 11 juko
    .d_in_lng(data2crc_lng),
1394
    //output
1395
    .d_out_data(crc_d_out_data),
1396
    .d_out_hdr(crc_d_out_flit_is_hdr),
1397
    .d_out_tail(crc_d_out_flit_is_tail),
1398
    .d_out_valid(crc_d_out_flit_is_valid),
1399
    .d_out_error(crc_d_out_flit_is_error),
1400
    .d_out_poisoned(crc_d_out_flit_is_poisoned),
1401
    .d_out_rtc(crc_d_out_flit_has_rtc),
1402
    .d_out_flow(crc_d_out_flit_is_flow)
1403
);
1404
 
1405 15 juko
generate
1406
    if(OPEN_RSP_MODE==0) begin : use_input_buffer
1407
        //Buffer Fifo - Depth = Max Tokens
1408
        openhmc_sync_fifo #(
1409
                .DATASIZE(DWIDTH+(4*FPW)),   //+4*FPW for header/tail/valid/error response information -> AXI-4 TUSER signal
1410
                .ADDRSIZE(LOG_MAX_RX_TOKENS)
1411
            ) input_buffer_I(
1412
                .clk(clk),
1413
                .res_n(res_n),
1414
                .d_in(input_buffer_d_in),
1415
                .shift_in(input_buffer_shift_in),
1416
                .d_out(input_buffer_d_out),
1417
                .shift_out(input_buffer_shift_out),
1418
                .empty(input_buffer_empty)
1419
            );
1420
    end
1421
endgenerate
1422 11 juko
 
1423
endmodule
1424
`default_nettype wire

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.