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

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [rtl/] [verilog/] [rx_enqueue.v] - Blame information for rev 24

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 antanguay
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "rx_enqueue.v"                                    ////
4
////                                                              ////
5
////  This file is part of the "10GE MAC" project                 ////
6
////  http://www.opencores.org/cores/xge_mac/                     ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - A. Tanguay (antanguay@opencores.org)                  ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2008 AUTHORS. All rights reserved.             ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
 
39
`include "defines.v"
40
 
41
module rx_enqueue(/*AUTOARG*/
42
  // Outputs
43 12 antanguay
  rxdfifo_wdata, rxdfifo_wstatus, rxdfifo_wen, rxhfifo_ren,
44
  rxhfifo_wdata, rxhfifo_wstatus, rxhfifo_wen, local_fault_msg_det,
45
  remote_fault_msg_det, status_crc_error_tog,
46
  status_fragment_error_tog, status_rxdfifo_ovflow_tog,
47 24 antanguay
  status_pause_frame_rx_tog, rxsfifo_wen, rxsfifo_wdata,
48 2 antanguay
  // Inputs
49 12 antanguay
  clk_xgmii_rx, reset_xgmii_rx_n, xgmii_rxd, xgmii_rxc, rxdfifo_wfull,
50
  rxhfifo_rdata, rxhfifo_rstatus, rxhfifo_rempty,
51 2 antanguay
  rxhfifo_ralmost_empty
52
  );
53
 
54
`include "CRC32_D64.v"
55
`include "CRC32_D8.v"
56
`include "utils.v"
57
 
58
input         clk_xgmii_rx;
59
input         reset_xgmii_rx_n;
60 21 antanguay
 
61 2 antanguay
input  [63:0] xgmii_rxd;
62
input  [7:0]  xgmii_rxc;
63
 
64
input         rxdfifo_wfull;
65 21 antanguay
 
66 2 antanguay
input  [63:0] rxhfifo_rdata;
67
input  [7:0]  rxhfifo_rstatus;
68
input         rxhfifo_rempty;
69
input         rxhfifo_ralmost_empty;
70
 
71
output [63:0] rxdfifo_wdata;
72
output [7:0]  rxdfifo_wstatus;
73 21 antanguay
output        rxdfifo_wen;
74 2 antanguay
 
75
output        rxhfifo_ren;
76
 
77
output [63:0] rxhfifo_wdata;
78
output [7:0]  rxhfifo_wstatus;
79
output        rxhfifo_wen;
80
 
81
output [1:0]  local_fault_msg_det;
82
output [1:0]  remote_fault_msg_det;
83
 
84
output        status_crc_error_tog;
85
output        status_fragment_error_tog;
86
output        status_rxdfifo_ovflow_tog;
87
 
88
output        status_pause_frame_rx_tog;
89
 
90 24 antanguay
output        rxsfifo_wen;
91
output [13:0] rxsfifo_wdata;
92 2 antanguay
 
93
 
94
 
95
/*AUTOREG*/
96
// Beginning of automatic regs (for this module's undeclared outputs)
97
reg [1:0]               local_fault_msg_det;
98
reg [1:0]               remote_fault_msg_det;
99
reg [63:0]              rxdfifo_wdata;
100
reg                     rxdfifo_wen;
101
reg [7:0]               rxdfifo_wstatus;
102
reg                     rxhfifo_ren;
103
reg [63:0]              rxhfifo_wdata;
104
reg                     rxhfifo_wen;
105
reg [7:0]               rxhfifo_wstatus;
106 24 antanguay
reg [13:0]              rxsfifo_wdata;
107
reg                     rxsfifo_wen;
108 2 antanguay
reg                     status_crc_error_tog;
109
reg                     status_fragment_error_tog;
110
reg                     status_pause_frame_rx_tog;
111
reg                     status_rxdfifo_ovflow_tog;
112
// End of automatics
113
 
114
/*AUTOWIRE*/
115
 
116
 
117
reg [63:32]   xgmii_rxd_d1;
118
reg [7:4]     xgmii_rxc_d1;
119
 
120
reg [63:0]    xgxs_rxd_barrel;
121
reg [7:0]     xgxs_rxc_barrel;
122
 
123
reg [63:0]    xgxs_rxd_barrel_d1;
124
reg [7:0]     xgxs_rxc_barrel_d1;
125
 
126
reg           barrel_shift;
127
 
128
reg [31:0]    crc32_d64;
129
reg [31:0]    crc32_d8;
130
 
131
reg [3:0]     crc_bytes;
132
reg [3:0]     next_crc_bytes;
133
 
134
reg [63:0]    crc_shift_data;
135
reg           crc_start_8b;
136
reg           crc_done;
137
reg           crc_good;
138
reg           crc_clear;
139
 
140
reg [31:0]    crc_rx;
141
reg [31:0]    next_crc_rx;
142
 
143
reg [2:0]     curr_state;
144
reg [2:0]     next_state;
145
 
146
reg [13:0]    curr_byte_cnt;
147
reg [13:0]    next_byte_cnt;
148
 
149 23 antanguay
reg           frame_end_flag;
150
reg           next_frame_end_flag;
151
 
152
reg [2:0]     frame_end_bytes;
153
reg [2:0]     next_frame_end_bytes;
154
 
155 2 antanguay
reg           fragment_error;
156
reg           rxd_ovflow_error;
157
 
158
reg           coding_error;
159
reg           next_coding_error;
160
 
161
reg [7:0]     addmask;
162
reg [7:0]     datamask;
163
 
164
reg           pause_frame;
165
reg           next_pause_frame;
166
reg           pause_frame_hold;
167
 
168
reg           good_pause_frame;
169
 
170
reg           drop_data;
171
reg           next_drop_data;
172
 
173
reg           pkt_pending;
174
 
175 6 antanguay
reg           rxhfifo_ren_d1;
176
 
177 2 antanguay
reg           rxhfifo_ralmost_empty_d1;
178
 
179
 
180
parameter [2:0]
181
             SM_IDLE = 3'd0,
182
             SM_RX = 3'd1;
183
 
184 21 antanguay
// count the number of set bits in a nibble
185
function [2:0] bit_cnt4;
186
input   [3:0]   bits;
187
    begin
188
    case (bits)
189
    0:  bit_cnt4 = 0;
190
    1:  bit_cnt4 = 1;
191
    2:  bit_cnt4 = 1;
192
    3:  bit_cnt4 = 2;
193
    4:  bit_cnt4 = 1;
194
    5:  bit_cnt4 = 2;
195
    6:  bit_cnt4 = 2;
196
    7:  bit_cnt4 = 3;
197
    8:  bit_cnt4 = 1;
198
    9:  bit_cnt4 = 2;
199
    10: bit_cnt4 = 2;
200
    11: bit_cnt4 = 3;
201
    12: bit_cnt4 = 2;
202
    13: bit_cnt4 = 3;
203
    14: bit_cnt4 = 3;
204
    15: bit_cnt4 = 4;
205
    endcase
206
    end
207
endfunction
208
 
209
function [3:0] bit_cnt8;
210
input   [7:0]   bits;
211
    begin
212
    bit_cnt8 = bit_cnt4(bits[3:0]) + bit_cnt4(bits[7:4]);
213
    end
214
endfunction
215
 
216 2 antanguay
always @(posedge clk_xgmii_rx or negedge reset_xgmii_rx_n) begin
217
 
218
    if (reset_xgmii_rx_n == 1'b0) begin
219
 
220
        xgmii_rxd_d1 <= 32'b0;
221
        xgmii_rxc_d1 <= 4'b0;
222
 
223
        xgxs_rxd_barrel <= 64'b0;
224
        xgxs_rxc_barrel <= 8'b0;
225
 
226
        xgxs_rxd_barrel_d1 <= 64'b0;
227
        xgxs_rxc_barrel_d1 <= 8'b0;
228
 
229
        barrel_shift <= 1'b0;
230
 
231
        local_fault_msg_det <= 2'b0;
232
        remote_fault_msg_det <= 2'b0;
233
 
234
        crc32_d64 <= 32'b0;
235
        crc32_d8 <= 32'b0;
236
        crc_bytes <= 4'b0;
237
 
238
        crc_shift_data <= 64'b0;
239
        crc_done <= 1'b0;
240
        crc_rx <= 32'b0;
241
 
242
        pause_frame_hold <= 1'b0;
243
 
244
        status_crc_error_tog <= 1'b0;
245
        status_fragment_error_tog <= 1'b0;
246
        status_rxdfifo_ovflow_tog <= 1'b0;
247
 
248
        status_pause_frame_rx_tog <= 1'b0;
249
 
250 24 antanguay
        rxsfifo_wen <= 1'b0;
251
        rxsfifo_wdata <= 14'b0;
252 23 antanguay
 
253 2 antanguay
    end
254
    else begin
255
 
256 24 antanguay
        rxsfifo_wen <= 1'b0;
257
        rxsfifo_wdata <= curr_byte_cnt + {11'b0, frame_end_bytes};
258
 
259 2 antanguay
        //---
260
        // Link status RC layer
261
        // Look for local/remote messages on lower 4 lanes and upper
262
        // 4 lanes. This is a 64-bit interface but look at each 32-bit
263
        // independantly.
264 21 antanguay
 
265 2 antanguay
        local_fault_msg_det[1] <= (xgmii_rxd[63:32] ==
266
                                   {`LOCAL_FAULT, 8'h0, 8'h0, `SEQUENCE} &&
267
                                   xgmii_rxc[7:4] == 4'b0001);
268
 
269
        local_fault_msg_det[0] <= (xgmii_rxd[31:0] ==
270
                                   {`LOCAL_FAULT, 8'h0, 8'h0, `SEQUENCE} &&
271
                                   xgmii_rxc[3:0] == 4'b0001);
272
 
273
        remote_fault_msg_det[1] <= (xgmii_rxd[63:32] ==
274
                                    {`REMOTE_FAULT, 8'h0, 8'h0, `SEQUENCE} &&
275
                                    xgmii_rxc[7:4] == 4'b0001);
276
 
277
        remote_fault_msg_det[0] <= (xgmii_rxd[31:0] ==
278
                                    {`REMOTE_FAULT, 8'h0, 8'h0, `SEQUENCE} &&
279
                                    xgmii_rxc[3:0] == 4'b0001);
280
 
281
 
282
        //---
283
        // Rotating barrel. This function allow us to always align the start of
284
        // a frame with LANE0. If frame starts in LANE4, it will be shifted 4 bytes
285
        // to LANE0, thus reducing the amount of logic needed at the next stage.
286
 
287
        xgmii_rxd_d1[63:32] <= xgmii_rxd[63:32];
288
        xgmii_rxc_d1[7:4] <= xgmii_rxc[7:4];
289
 
290
        if (xgmii_rxd[`LANE0] == `START && xgmii_rxc[0]) begin
291 21 antanguay
 
292 2 antanguay
            xgxs_rxd_barrel <= xgmii_rxd;
293
            xgxs_rxc_barrel <= xgmii_rxc;
294
 
295
            barrel_shift <= 1'b0;
296
 
297
        end
298
        else if (xgmii_rxd[`LANE4] == `START && xgmii_rxc[4]) begin
299
 
300
            xgxs_rxd_barrel <= {xgmii_rxd[31:0], xgmii_rxd_d1[63:32]};
301
            xgxs_rxc_barrel <= {xgmii_rxc[3:0], xgmii_rxc_d1[7:4]};
302
 
303
            barrel_shift <= 1'b1;
304
 
305
        end
306
        else if (barrel_shift) begin
307
 
308
            xgxs_rxd_barrel <= {xgmii_rxd[31:0], xgmii_rxd_d1[63:32]};
309
            xgxs_rxc_barrel <= {xgmii_rxc[3:0], xgmii_rxc_d1[7:4]};
310
 
311
        end
312
        else begin
313
 
314
            xgxs_rxd_barrel <= xgmii_rxd;
315
            xgxs_rxc_barrel <= xgmii_rxc;
316
 
317
        end
318
 
319
        xgxs_rxd_barrel_d1 <= xgxs_rxd_barrel;
320
        xgxs_rxc_barrel_d1 <= xgxs_rxc_barrel;
321
 
322
 
323
        //---
324
        // When final CRC calculation begins we capture info relevant to
325
        // current frame CRC claculation continues while next frame is
326
        // being received.
327
 
328
        if (crc_start_8b) begin
329
 
330
            pause_frame_hold <= pause_frame;
331
 
332
        end
333
 
334
        //---
335
        // CRC Checking
336
 
337
        crc_rx <= next_crc_rx;
338
 
339
        if (crc_clear) begin
340
 
341
            // CRC is cleared at the beginning of the frame, calculate
342
            // 64-bit at a time otherwise
343
 
344
            crc32_d64 <= 32'hffffffff;
345
 
346
        end
347
        else begin
348
 
349
            crc32_d64 <= nextCRC32_D64(reverse_64b(xgxs_rxd_barrel_d1), crc32_d64);
350
 
351
        end
352
 
353
        if (crc_bytes != 4'b0) begin
354
 
355
            // When reaching the end of the frame we switch from 64-bit mode
356
            // to 8-bit mode to accomodate odd number of bytes in the frame.
357
            // crc_bytes indicated the number of remaining payload byte to
358
            // compute CRC on. Calculate and decrement until it reaches 0.
359
 
360
            if (crc_bytes == 4'b1) begin
361
                crc_done <= 1'b1;
362
            end
363
 
364
            crc32_d8 <= nextCRC32_D8(reverse_8b(crc_shift_data[7:0]), crc32_d8);
365
            crc_shift_data <= {8'h00, crc_shift_data[63:8]};
366
            crc_bytes <= crc_bytes - 4'b1;
367
 
368
        end
369
        else if (crc_bytes == 4'b0) begin
370
 
371
            // Per Clause 46. Control code during data must be reported
372
            // as a CRC error. Indicated here by coding_error. Corrupt CRC
373
            // if coding error is detected.
374 21 antanguay
 
375 2 antanguay
            if (coding_error || next_coding_error) begin
376
                crc32_d8 <= ~crc32_d64;
377
            end
378
            else begin
379
                crc32_d8 <= crc32_d64;
380
            end
381
 
382
            crc_done <= 1'b0;
383
 
384
            crc_shift_data <= xgxs_rxd_barrel_d1;
385
            crc_bytes <= next_crc_bytes;
386
 
387
        end
388
 
389
        //---
390
        // Error detection
391
 
392
        if (crc_done && !crc_good) begin
393
            status_crc_error_tog <= ~status_crc_error_tog;
394
        end
395
 
396
        if (fragment_error) begin
397
            status_fragment_error_tog <= ~status_fragment_error_tog;
398
        end
399
 
400
        if (rxd_ovflow_error) begin
401
            status_rxdfifo_ovflow_tog <= ~status_rxdfifo_ovflow_tog;
402
        end
403
 
404
        //---
405
        // Frame receive indication
406
 
407
        if (good_pause_frame) begin
408
            status_pause_frame_rx_tog <= ~status_pause_frame_rx_tog;
409
        end
410
 
411 23 antanguay
        if (frame_end_flag) begin
412 24 antanguay
            rxsfifo_wen <= 1'b1;
413 23 antanguay
        end
414
 
415 2 antanguay
    end
416
 
417
end
418
 
419
 
420
always @(/*AS*/crc32_d8 or crc_done or crc_rx or pause_frame_hold) begin
421
 
422
 
423
    crc_good = 1'b0;
424
    good_pause_frame = 1'b0;
425
 
426
    if (crc_done) begin
427
 
428
        // Check CRC. If this is a pause frame, report it to cpu.
429
 
430
        if (crc_rx == ~reverse_32b(crc32_d8)) begin
431
            crc_good = 1'b1;
432
            good_pause_frame = pause_frame_hold;
433
        end
434
 
435
    end
436
 
437
end
438 21 antanguay
 
439 2 antanguay
always @(posedge clk_xgmii_rx or negedge reset_xgmii_rx_n) begin
440
 
441
    if (reset_xgmii_rx_n == 1'b0) begin
442
 
443
        curr_state <= SM_IDLE;
444
        curr_byte_cnt <= 14'b0;
445 23 antanguay
        frame_end_flag <= 1'b0;
446
        frame_end_bytes <= 3'b0;
447 2 antanguay
        coding_error <= 1'b0;
448
        pause_frame <= 1'b0;
449
 
450
    end
451
    else begin
452
 
453
        curr_state <= next_state;
454
        curr_byte_cnt <= next_byte_cnt;
455 23 antanguay
        frame_end_flag <= next_frame_end_flag;
456
        frame_end_bytes <= next_frame_end_bytes;
457 2 antanguay
        coding_error <= next_coding_error;
458
        pause_frame <= next_pause_frame;
459
 
460
    end
461
 
462
end
463
 
464
 
465
always @(/*AS*/coding_error or crc_rx or curr_byte_cnt or curr_state
466
         or pause_frame or xgxs_rxc_barrel or xgxs_rxc_barrel_d1
467
         or xgxs_rxd_barrel or xgxs_rxd_barrel_d1) begin
468
 
469
    next_state = curr_state;
470
 
471
    rxhfifo_wdata = xgxs_rxd_barrel_d1;
472 6 antanguay
    rxhfifo_wstatus = `RXSTATUS_NONE;
473 2 antanguay
    rxhfifo_wen = 1'b0;
474
 
475
    addmask[0] = !(xgxs_rxd_barrel_d1[`LANE0] == `TERMINATE && xgxs_rxc_barrel_d1[0]);
476
    addmask[1] = !(xgxs_rxd_barrel_d1[`LANE1] == `TERMINATE && xgxs_rxc_barrel_d1[1]);
477
    addmask[2] = !(xgxs_rxd_barrel_d1[`LANE2] == `TERMINATE && xgxs_rxc_barrel_d1[2]);
478
    addmask[3] = !(xgxs_rxd_barrel_d1[`LANE3] == `TERMINATE && xgxs_rxc_barrel_d1[3]);
479
    addmask[4] = !(xgxs_rxd_barrel_d1[`LANE4] == `TERMINATE && xgxs_rxc_barrel_d1[4]);
480
    addmask[5] = !(xgxs_rxd_barrel_d1[`LANE5] == `TERMINATE && xgxs_rxc_barrel_d1[5]);
481
    addmask[6] = !(xgxs_rxd_barrel_d1[`LANE6] == `TERMINATE && xgxs_rxc_barrel_d1[6]);
482
    addmask[7] = !(xgxs_rxd_barrel_d1[`LANE7] == `TERMINATE && xgxs_rxc_barrel_d1[7]);
483
 
484
    datamask[0] = addmask[0];
485
    datamask[1] = &addmask[1:0];
486
    datamask[2] = &addmask[2:0];
487
    datamask[3] = &addmask[3:0];
488
    datamask[4] = &addmask[4:0];
489
    datamask[5] = &addmask[5:0];
490
    datamask[6] = &addmask[6:0];
491
    datamask[7] = &addmask[7:0];
492
 
493
    next_crc_bytes = 4'b0;
494
    next_crc_rx = crc_rx;
495
    crc_start_8b = 1'b0;
496
    crc_clear = 1'b0;
497
 
498
    next_byte_cnt = curr_byte_cnt;
499 23 antanguay
    next_frame_end_flag = 1'b0;
500
    next_frame_end_bytes = 3'b0;
501 2 antanguay
 
502
    fragment_error = 1'b0;
503
 
504
    next_coding_error = coding_error;
505
    next_pause_frame = pause_frame;
506
 
507
    case (curr_state)
508
 
509
        SM_IDLE:
510
          begin
511
 
512
              next_byte_cnt = 14'b0;
513
              crc_clear = 1'b1;
514
              next_coding_error = 1'b0;
515
              next_pause_frame = 1'b0;
516
 
517 21 antanguay
 
518 2 antanguay
              // Detect the start of a frame
519 21 antanguay
 
520 2 antanguay
              if (xgxs_rxd_barrel_d1[`LANE0] == `START && xgxs_rxc_barrel_d1[0] &&
521
                  xgxs_rxd_barrel_d1[`LANE1] == `PREAMBLE && !xgxs_rxc_barrel_d1[1] &&
522
                  xgxs_rxd_barrel_d1[`LANE2] == `PREAMBLE && !xgxs_rxc_barrel_d1[2] &&
523
                  xgxs_rxd_barrel_d1[`LANE3] == `PREAMBLE && !xgxs_rxc_barrel_d1[3] &&
524
                  xgxs_rxd_barrel_d1[`LANE4] == `PREAMBLE && !xgxs_rxc_barrel_d1[4] &&
525
                  xgxs_rxd_barrel_d1[`LANE5] == `PREAMBLE && !xgxs_rxc_barrel_d1[5] &&
526
                  xgxs_rxd_barrel_d1[`LANE6] == `PREAMBLE && !xgxs_rxc_barrel_d1[6] &&
527
                  xgxs_rxd_barrel_d1[`LANE7] == `SFD && !xgxs_rxc_barrel_d1[7]) begin
528
 
529
                  next_state = SM_RX;
530
              end
531
 
532
          end
533
 
534
        SM_RX:
535
          begin
536
 
537
              // Pause frames are filtered
538 21 antanguay
 
539 2 antanguay
              rxhfifo_wen = !pause_frame;
540
 
541
 
542
              if (xgxs_rxd_barrel_d1[`LANE0] == `START && xgxs_rxc_barrel_d1[0] &&
543
                  xgxs_rxd_barrel_d1[`LANE7] == `SFD && !xgxs_rxc_barrel_d1[7]) begin
544
 
545
                  // Fragment received, if we are still at SOP stage don't store
546
                  // the frame. If not, write a fake EOP and flag frame as bad.
547
 
548
                  next_byte_cnt = 14'b0;
549
                  crc_clear = 1'b1;
550
                  next_coding_error = 1'b0;
551
 
552
                  fragment_error = 1'b1;
553 6 antanguay
                  rxhfifo_wstatus[`RXSTATUS_ERR] = 1'b1;
554 2 antanguay
 
555
                  if (curr_byte_cnt == 14'b0) begin
556
                      rxhfifo_wen = 1'b0;
557
                  end
558
                  else begin
559 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
560 2 antanguay
                  end
561
 
562
              end
563
              else if (curr_byte_cnt > 14'd9900) begin
564
 
565
                  // Frame too long, TERMMINATE must have been corrupted.
566
                  // Abort transfer, write a fake EOP, report as fragment.
567
 
568
                  fragment_error = 1'b1;
569 6 antanguay
                  rxhfifo_wstatus[`RXSTATUS_ERR] = 1'b1;
570 2 antanguay
 
571 6 antanguay
                  rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
572 2 antanguay
                  next_state = SM_IDLE;
573
 
574
              end
575
              else begin
576
 
577
                  // Pause frame receive, these frame will be filtered
578
 
579
                  if (curr_byte_cnt == 14'd0 &&
580
                      xgxs_rxd_barrel_d1[47:0] == `PAUSE_FRAME) begin
581
 
582
                      rxhfifo_wen = 1'b0;
583
                      next_pause_frame = 1'b1;
584
                  end
585
 
586
 
587
                  // Control character during data phase, force CRC error
588 21 antanguay
 
589 2 antanguay
                  if (|(xgxs_rxc_barrel_d1 & datamask)) begin
590
 
591
                      next_coding_error = 1'b1;
592
                  end
593
 
594
 
595
                  // Write SOP to status bits during first byte
596
 
597
                  if (curr_byte_cnt == 14'b0) begin
598 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_SOP] = 1'b1;
599 2 antanguay
                  end
600
 
601
                  /* verilator lint_off WIDTH */
602 21 antanguay
                  //next_byte_cnt = curr_byte_cnt +
603
                  //                addmask[0] + addmask[1] + addmask[2] + addmask[3] +
604
                  //                addmask[4] + addmask[5] + addmask[6] + addmask[7];
605 2 antanguay
                  /* verilator lint_on WIDTH */
606 21 antanguay
                  // don't infer a chain of adders
607 23 antanguay
                  next_byte_cnt = curr_byte_cnt + {10'b0, bit_cnt8(datamask[7:0])};
608 2 antanguay
 
609
 
610
                  // We will not write to the fifo if all is left
611
                  // are four or less bytes of crc. We also strip off the
612
                  // crc, which requires looking one cycle ahead
613 21 antanguay
                  // wstatus:
614 6 antanguay
                  //   [2:0] modulus of packet length
615 2 antanguay
 
616
                  // Look one cycle ahead for TERMINATE in lanes 0 to 4
617
 
618
                  if (xgxs_rxd_barrel[`LANE4] == `TERMINATE && xgxs_rxc_barrel[4]) begin
619 21 antanguay
 
620 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
621
                      rxhfifo_wstatus[2:0] = 3'd0;
622 2 antanguay
 
623
                      crc_start_8b = 1'b1;
624
                      next_crc_bytes = 4'd8;
625
                      next_crc_rx = xgxs_rxd_barrel[31:0];
626
 
627 23 antanguay
                      next_frame_end_flag = 1'b1;
628
                      next_frame_end_bytes = 3'd4;
629
 
630 2 antanguay
                      next_state = SM_IDLE;
631
 
632
                  end
633
 
634
                  if (xgxs_rxd_barrel[`LANE3] == `TERMINATE && xgxs_rxc_barrel[3]) begin
635
 
636 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
637
                      rxhfifo_wstatus[2:0] = 3'd7;
638 2 antanguay
 
639
                      crc_start_8b = 1'b1;
640
                      next_crc_bytes = 4'd7;
641
                      next_crc_rx = {xgxs_rxd_barrel[23:0], xgxs_rxd_barrel_d1[63:56]};
642 21 antanguay
 
643 23 antanguay
                      next_frame_end_flag = 1'b1;
644
                      next_frame_end_bytes = 3'd3;
645
 
646 2 antanguay
                      next_state = SM_IDLE;
647
 
648
                  end
649 21 antanguay
 
650 2 antanguay
                  if (xgxs_rxd_barrel[`LANE2] == `TERMINATE && xgxs_rxc_barrel[2]) begin
651
 
652 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
653
                      rxhfifo_wstatus[2:0] = 3'd6;
654 2 antanguay
 
655
                      crc_start_8b = 1'b1;
656
                      next_crc_bytes = 4'd6;
657
                      next_crc_rx = {xgxs_rxd_barrel[15:0], xgxs_rxd_barrel_d1[63:48]};
658
 
659 23 antanguay
                      next_frame_end_flag = 1'b1;
660
                      next_frame_end_bytes = 3'd2;
661
 
662 2 antanguay
                      next_state = SM_IDLE;
663
 
664
                  end
665
 
666
                  if (xgxs_rxd_barrel[`LANE1] == `TERMINATE && xgxs_rxc_barrel[1]) begin
667
 
668 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
669
                      rxhfifo_wstatus[2:0] = 3'd5;
670 2 antanguay
 
671
                      crc_start_8b = 1'b1;
672
                      next_crc_bytes = 4'd5;
673
                      next_crc_rx = {xgxs_rxd_barrel[7:0], xgxs_rxd_barrel_d1[63:40]};
674
 
675 23 antanguay
                      next_frame_end_flag = 1'b1;
676
                      next_frame_end_bytes = 3'd1;
677
 
678 2 antanguay
                      next_state = SM_IDLE;
679
 
680
                  end
681 21 antanguay
 
682 2 antanguay
                  if (xgxs_rxd_barrel[`LANE0] == `TERMINATE && xgxs_rxc_barrel[0]) begin
683
 
684 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
685
                      rxhfifo_wstatus[2:0] = 3'd4;
686 2 antanguay
 
687
                      crc_start_8b = 1'b1;
688
                      next_crc_bytes = 4'd4;
689
                      next_crc_rx = xgxs_rxd_barrel_d1[63:32];
690
 
691 23 antanguay
                      next_frame_end_flag = 1'b1;
692
 
693 2 antanguay
                      next_state = SM_IDLE;
694
 
695
                  end
696
 
697
                  // Look at current cycle for TERMINATE in lanes 5 to 7
698
 
699
                  if (xgxs_rxd_barrel_d1[`LANE7] == `TERMINATE &&
700
                      xgxs_rxc_barrel_d1[7]) begin
701
 
702 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
703
                      rxhfifo_wstatus[2:0] = 3'd3;
704 2 antanguay
 
705
                      crc_start_8b = 1'b1;
706
                      next_crc_bytes = 4'd3;
707
                      next_crc_rx = xgxs_rxd_barrel_d1[55:24];
708
 
709 23 antanguay
                      next_frame_end_flag = 1'b1;
710
 
711 2 antanguay
                      next_state = SM_IDLE;
712
 
713
                  end
714 21 antanguay
 
715 2 antanguay
                  if (xgxs_rxd_barrel_d1[`LANE6] == `TERMINATE &&
716
                      xgxs_rxc_barrel_d1[6]) begin
717
 
718 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
719
                      rxhfifo_wstatus[2:0] = 3'd2;
720 2 antanguay
 
721
                      crc_start_8b = 1'b1;
722
                      next_crc_bytes = 4'd2;
723
                      next_crc_rx = xgxs_rxd_barrel_d1[47:16];
724
 
725 23 antanguay
                      next_frame_end_flag = 1'b1;
726
 
727 2 antanguay
                      next_state = SM_IDLE;
728
 
729
                  end
730 21 antanguay
 
731 2 antanguay
                  if (xgxs_rxd_barrel_d1[`LANE5] == `TERMINATE &&
732
                      xgxs_rxc_barrel_d1[5]) begin
733
 
734 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
735
                      rxhfifo_wstatus[2:0] = 3'd1;
736 2 antanguay
 
737
                      crc_start_8b = 1'b1;
738
                      next_crc_bytes = 4'd1;
739
                      next_crc_rx = xgxs_rxd_barrel_d1[39:8];
740
 
741 23 antanguay
                      next_frame_end_flag = 1'b1;
742
 
743 2 antanguay
                      next_state = SM_IDLE;
744
 
745
                  end
746
              end
747
          end
748
 
749
        default:
750
          begin
751
              next_state = SM_IDLE;
752
          end
753
 
754
    endcase
755
 
756
end
757
 
758
 
759
always @(posedge clk_xgmii_rx or negedge reset_xgmii_rx_n) begin
760
 
761
    if (reset_xgmii_rx_n == 1'b0) begin
762
 
763
        rxhfifo_ralmost_empty_d1 <= 1'b1;
764
 
765
        drop_data <= 1'b0;
766
 
767
        pkt_pending <= 1'b0;
768
 
769 6 antanguay
        rxhfifo_ren_d1 <= 1'b0;
770
 
771 2 antanguay
    end
772
    else begin
773
 
774
        rxhfifo_ralmost_empty_d1 <= rxhfifo_ralmost_empty;
775
 
776
        drop_data <= next_drop_data;
777
 
778 6 antanguay
        pkt_pending <= rxhfifo_ren;
779 2 antanguay
 
780 6 antanguay
        rxhfifo_ren_d1 <= rxhfifo_ren;
781
 
782 2 antanguay
    end
783
 
784
end
785
 
786
always @(/*AS*/crc_done or crc_good or drop_data or pkt_pending
787
         or rxdfifo_wfull or rxhfifo_ralmost_empty_d1 or rxhfifo_rdata
788 6 antanguay
         or rxhfifo_ren_d1 or rxhfifo_rstatus) begin
789 2 antanguay
 
790
    rxd_ovflow_error = 1'b0;
791
 
792
    rxdfifo_wdata = rxhfifo_rdata;
793
    rxdfifo_wstatus = rxhfifo_rstatus;
794
 
795
    next_drop_data = drop_data;
796
 
797
 
798
    // There must be at least 8 words in holding FIFO before we start reading.
799
    // This provides enough time for CRC calculation.
800
 
801 6 antanguay
    rxhfifo_ren = !rxhfifo_ralmost_empty_d1 ||
802
                  (pkt_pending && !rxhfifo_rstatus[`RXSTATUS_EOP]);
803 2 antanguay
 
804 21 antanguay
 
805 6 antanguay
    if (rxhfifo_ren_d1 && rxhfifo_rstatus[`RXSTATUS_SOP]) begin
806 2 antanguay
 
807
        // Reset drop flag on SOP
808 21 antanguay
 
809 2 antanguay
        next_drop_data = 1'b0;
810
 
811
    end
812
 
813 6 antanguay
    if (rxhfifo_ren_d1 && rxdfifo_wfull && !next_drop_data) begin
814 2 antanguay
 
815
        // FIFO overflow, abort transfer. The rest of the frame
816
        // will be dropped. Since we can't put an EOP indication
817
        // in a fifo already full, there will be no EOP and receive
818
        // side will need to sync on next SOP.
819
 
820
        rxd_ovflow_error = 1'b1;
821
        next_drop_data = 1'b1;
822
 
823
    end
824
 
825
 
826 6 antanguay
    rxdfifo_wen = rxhfifo_ren_d1 && !next_drop_data;
827 2 antanguay
 
828
 
829
 
830
    if (crc_done && !crc_good) begin
831
 
832
        // Flag packet with error when CRC error is detected
833 21 antanguay
 
834 6 antanguay
        rxdfifo_wstatus[`RXSTATUS_ERR] = 1'b1;
835 2 antanguay
 
836
    end
837
 
838
end
839
 
840
endmodule

powered by: WebSVN 2.1.0

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