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 25

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 25 antanguay
        datamask <= 8'b0;
254
 
255 2 antanguay
    end
256
    else begin
257
 
258 24 antanguay
        rxsfifo_wen <= 1'b0;
259
        rxsfifo_wdata <= curr_byte_cnt + {11'b0, frame_end_bytes};
260
 
261 2 antanguay
        //---
262
        // Link status RC layer
263
        // Look for local/remote messages on lower 4 lanes and upper
264
        // 4 lanes. This is a 64-bit interface but look at each 32-bit
265
        // independantly.
266 21 antanguay
 
267 2 antanguay
        local_fault_msg_det[1] <= (xgmii_rxd[63:32] ==
268
                                   {`LOCAL_FAULT, 8'h0, 8'h0, `SEQUENCE} &&
269
                                   xgmii_rxc[7:4] == 4'b0001);
270
 
271
        local_fault_msg_det[0] <= (xgmii_rxd[31:0] ==
272
                                   {`LOCAL_FAULT, 8'h0, 8'h0, `SEQUENCE} &&
273
                                   xgmii_rxc[3:0] == 4'b0001);
274
 
275
        remote_fault_msg_det[1] <= (xgmii_rxd[63:32] ==
276
                                    {`REMOTE_FAULT, 8'h0, 8'h0, `SEQUENCE} &&
277
                                    xgmii_rxc[7:4] == 4'b0001);
278
 
279
        remote_fault_msg_det[0] <= (xgmii_rxd[31:0] ==
280
                                    {`REMOTE_FAULT, 8'h0, 8'h0, `SEQUENCE} &&
281
                                    xgmii_rxc[3:0] == 4'b0001);
282
 
283
 
284
        //---
285
        // Rotating barrel. This function allow us to always align the start of
286
        // a frame with LANE0. If frame starts in LANE4, it will be shifted 4 bytes
287
        // to LANE0, thus reducing the amount of logic needed at the next stage.
288
 
289
        xgmii_rxd_d1[63:32] <= xgmii_rxd[63:32];
290
        xgmii_rxc_d1[7:4] <= xgmii_rxc[7:4];
291
 
292
        if (xgmii_rxd[`LANE0] == `START && xgmii_rxc[0]) begin
293 21 antanguay
 
294 2 antanguay
            xgxs_rxd_barrel <= xgmii_rxd;
295
            xgxs_rxc_barrel <= xgmii_rxc;
296
 
297
            barrel_shift <= 1'b0;
298
 
299
        end
300
        else if (xgmii_rxd[`LANE4] == `START && xgmii_rxc[4]) begin
301
 
302
            xgxs_rxd_barrel <= {xgmii_rxd[31:0], xgmii_rxd_d1[63:32]};
303
            xgxs_rxc_barrel <= {xgmii_rxc[3:0], xgmii_rxc_d1[7:4]};
304
 
305
            barrel_shift <= 1'b1;
306
 
307
        end
308
        else if (barrel_shift) begin
309
 
310
            xgxs_rxd_barrel <= {xgmii_rxd[31:0], xgmii_rxd_d1[63:32]};
311
            xgxs_rxc_barrel <= {xgmii_rxc[3:0], xgmii_rxc_d1[7:4]};
312
 
313
        end
314
        else begin
315
 
316
            xgxs_rxd_barrel <= xgmii_rxd;
317
            xgxs_rxc_barrel <= xgmii_rxc;
318
 
319
        end
320
 
321
        xgxs_rxd_barrel_d1 <= xgxs_rxd_barrel;
322
        xgxs_rxc_barrel_d1 <= xgxs_rxc_barrel;
323
 
324 25 antanguay
        //---
325
        // Mask for end-of-frame
326 2 antanguay
 
327 25 antanguay
        datamask[0] <= addmask[0];
328
        datamask[1] <= &addmask[1:0];
329
        datamask[2] <= &addmask[2:0];
330
        datamask[3] <= &addmask[3:0];
331
        datamask[4] <= &addmask[4:0];
332
        datamask[5] <= &addmask[5:0];
333
        datamask[6] <= &addmask[6:0];
334
        datamask[7] <= &addmask[7:0];
335
 
336 2 antanguay
        //---
337
        // When final CRC calculation begins we capture info relevant to
338
        // current frame CRC claculation continues while next frame is
339
        // being received.
340
 
341
        if (crc_start_8b) begin
342
 
343
            pause_frame_hold <= pause_frame;
344
 
345
        end
346
 
347
        //---
348
        // CRC Checking
349
 
350
        crc_rx <= next_crc_rx;
351
 
352
        if (crc_clear) begin
353
 
354
            // CRC is cleared at the beginning of the frame, calculate
355
            // 64-bit at a time otherwise
356
 
357
            crc32_d64 <= 32'hffffffff;
358
 
359
        end
360
        else begin
361
 
362
            crc32_d64 <= nextCRC32_D64(reverse_64b(xgxs_rxd_barrel_d1), crc32_d64);
363
 
364
        end
365
 
366
        if (crc_bytes != 4'b0) begin
367
 
368
            // When reaching the end of the frame we switch from 64-bit mode
369
            // to 8-bit mode to accomodate odd number of bytes in the frame.
370
            // crc_bytes indicated the number of remaining payload byte to
371
            // compute CRC on. Calculate and decrement until it reaches 0.
372
 
373
            if (crc_bytes == 4'b1) begin
374
                crc_done <= 1'b1;
375
            end
376
 
377
            crc32_d8 <= nextCRC32_D8(reverse_8b(crc_shift_data[7:0]), crc32_d8);
378
            crc_shift_data <= {8'h00, crc_shift_data[63:8]};
379
            crc_bytes <= crc_bytes - 4'b1;
380
 
381
        end
382
        else if (crc_bytes == 4'b0) begin
383
 
384
            // Per Clause 46. Control code during data must be reported
385
            // as a CRC error. Indicated here by coding_error. Corrupt CRC
386
            // if coding error is detected.
387 21 antanguay
 
388 2 antanguay
            if (coding_error || next_coding_error) begin
389
                crc32_d8 <= ~crc32_d64;
390
            end
391
            else begin
392
                crc32_d8 <= crc32_d64;
393
            end
394
 
395
            crc_done <= 1'b0;
396
 
397
            crc_shift_data <= xgxs_rxd_barrel_d1;
398
            crc_bytes <= next_crc_bytes;
399
 
400
        end
401
 
402
        //---
403
        // Error detection
404
 
405
        if (crc_done && !crc_good) begin
406
            status_crc_error_tog <= ~status_crc_error_tog;
407
        end
408
 
409
        if (fragment_error) begin
410
            status_fragment_error_tog <= ~status_fragment_error_tog;
411
        end
412
 
413
        if (rxd_ovflow_error) begin
414
            status_rxdfifo_ovflow_tog <= ~status_rxdfifo_ovflow_tog;
415
        end
416
 
417
        //---
418
        // Frame receive indication
419
 
420
        if (good_pause_frame) begin
421
            status_pause_frame_rx_tog <= ~status_pause_frame_rx_tog;
422
        end
423
 
424 23 antanguay
        if (frame_end_flag) begin
425 24 antanguay
            rxsfifo_wen <= 1'b1;
426 23 antanguay
        end
427
 
428 2 antanguay
    end
429
 
430
end
431
 
432
 
433
always @(/*AS*/crc32_d8 or crc_done or crc_rx or pause_frame_hold) begin
434
 
435
 
436
    crc_good = 1'b0;
437
    good_pause_frame = 1'b0;
438
 
439
    if (crc_done) begin
440
 
441
        // Check CRC. If this is a pause frame, report it to cpu.
442
 
443
        if (crc_rx == ~reverse_32b(crc32_d8)) begin
444
            crc_good = 1'b1;
445
            good_pause_frame = pause_frame_hold;
446
        end
447
 
448
    end
449
 
450
end
451 21 antanguay
 
452 2 antanguay
always @(posedge clk_xgmii_rx or negedge reset_xgmii_rx_n) begin
453
 
454
    if (reset_xgmii_rx_n == 1'b0) begin
455
 
456
        curr_state <= SM_IDLE;
457
        curr_byte_cnt <= 14'b0;
458 23 antanguay
        frame_end_flag <= 1'b0;
459
        frame_end_bytes <= 3'b0;
460 2 antanguay
        coding_error <= 1'b0;
461
        pause_frame <= 1'b0;
462
 
463
    end
464
    else begin
465
 
466
        curr_state <= next_state;
467
        curr_byte_cnt <= next_byte_cnt;
468 23 antanguay
        frame_end_flag <= next_frame_end_flag;
469
        frame_end_bytes <= next_frame_end_bytes;
470 2 antanguay
        coding_error <= next_coding_error;
471
        pause_frame <= next_pause_frame;
472
 
473
    end
474
 
475
end
476
 
477
 
478
always @(/*AS*/coding_error or crc_rx or curr_byte_cnt or curr_state
479 25 antanguay
         or datamask or pause_frame or xgxs_rxc_barrel
480
         or xgxs_rxc_barrel_d1 or xgxs_rxd_barrel
481
         or xgxs_rxd_barrel_d1) begin
482 2 antanguay
 
483
    next_state = curr_state;
484
 
485
    rxhfifo_wdata = xgxs_rxd_barrel_d1;
486 6 antanguay
    rxhfifo_wstatus = `RXSTATUS_NONE;
487 2 antanguay
    rxhfifo_wen = 1'b0;
488
 
489
    next_crc_bytes = 4'b0;
490
    next_crc_rx = crc_rx;
491
    crc_start_8b = 1'b0;
492
    crc_clear = 1'b0;
493
 
494
    next_byte_cnt = curr_byte_cnt;
495 23 antanguay
    next_frame_end_flag = 1'b0;
496
    next_frame_end_bytes = 3'b0;
497 2 antanguay
 
498
    fragment_error = 1'b0;
499
 
500
    next_coding_error = coding_error;
501
    next_pause_frame = pause_frame;
502
 
503 25 antanguay
    addmask[0] = !(xgxs_rxd_barrel[`LANE0] == `TERMINATE && xgxs_rxc_barrel[0]);
504
    addmask[1] = !(xgxs_rxd_barrel[`LANE1] == `TERMINATE && xgxs_rxc_barrel[1]);
505
    addmask[2] = !(xgxs_rxd_barrel[`LANE2] == `TERMINATE && xgxs_rxc_barrel[2]);
506
    addmask[3] = !(xgxs_rxd_barrel[`LANE3] == `TERMINATE && xgxs_rxc_barrel[3]);
507
    addmask[4] = !(xgxs_rxd_barrel[`LANE4] == `TERMINATE && xgxs_rxc_barrel[4]);
508
    addmask[5] = !(xgxs_rxd_barrel[`LANE5] == `TERMINATE && xgxs_rxc_barrel[5]);
509
    addmask[6] = !(xgxs_rxd_barrel[`LANE6] == `TERMINATE && xgxs_rxc_barrel[6]);
510
    addmask[7] = !(xgxs_rxd_barrel[`LANE7] == `TERMINATE && xgxs_rxc_barrel[7]);
511
 
512 2 antanguay
    case (curr_state)
513
 
514
        SM_IDLE:
515
          begin
516
 
517
              next_byte_cnt = 14'b0;
518
              crc_clear = 1'b1;
519
              next_coding_error = 1'b0;
520
              next_pause_frame = 1'b0;
521
 
522 21 antanguay
 
523 2 antanguay
              // Detect the start of a frame
524 21 antanguay
 
525 2 antanguay
              if (xgxs_rxd_barrel_d1[`LANE0] == `START && xgxs_rxc_barrel_d1[0] &&
526
                  xgxs_rxd_barrel_d1[`LANE1] == `PREAMBLE && !xgxs_rxc_barrel_d1[1] &&
527
                  xgxs_rxd_barrel_d1[`LANE2] == `PREAMBLE && !xgxs_rxc_barrel_d1[2] &&
528
                  xgxs_rxd_barrel_d1[`LANE3] == `PREAMBLE && !xgxs_rxc_barrel_d1[3] &&
529
                  xgxs_rxd_barrel_d1[`LANE4] == `PREAMBLE && !xgxs_rxc_barrel_d1[4] &&
530
                  xgxs_rxd_barrel_d1[`LANE5] == `PREAMBLE && !xgxs_rxc_barrel_d1[5] &&
531
                  xgxs_rxd_barrel_d1[`LANE6] == `PREAMBLE && !xgxs_rxc_barrel_d1[6] &&
532
                  xgxs_rxd_barrel_d1[`LANE7] == `SFD && !xgxs_rxc_barrel_d1[7]) begin
533
 
534
                  next_state = SM_RX;
535
              end
536
 
537
          end
538
 
539
        SM_RX:
540
          begin
541
 
542
              // Pause frames are filtered
543 21 antanguay
 
544 2 antanguay
              rxhfifo_wen = !pause_frame;
545
 
546
 
547
              if (xgxs_rxd_barrel_d1[`LANE0] == `START && xgxs_rxc_barrel_d1[0] &&
548
                  xgxs_rxd_barrel_d1[`LANE7] == `SFD && !xgxs_rxc_barrel_d1[7]) begin
549
 
550
                  // Fragment received, if we are still at SOP stage don't store
551
                  // the frame. If not, write a fake EOP and flag frame as bad.
552
 
553
                  next_byte_cnt = 14'b0;
554
                  crc_clear = 1'b1;
555
                  next_coding_error = 1'b0;
556
 
557
                  fragment_error = 1'b1;
558 6 antanguay
                  rxhfifo_wstatus[`RXSTATUS_ERR] = 1'b1;
559 2 antanguay
 
560
                  if (curr_byte_cnt == 14'b0) begin
561
                      rxhfifo_wen = 1'b0;
562
                  end
563
                  else begin
564 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
565 2 antanguay
                  end
566
 
567
              end
568
              else if (curr_byte_cnt > 14'd9900) begin
569
 
570
                  // Frame too long, TERMMINATE must have been corrupted.
571
                  // Abort transfer, write a fake EOP, report as fragment.
572
 
573
                  fragment_error = 1'b1;
574 6 antanguay
                  rxhfifo_wstatus[`RXSTATUS_ERR] = 1'b1;
575 2 antanguay
 
576 6 antanguay
                  rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
577 2 antanguay
                  next_state = SM_IDLE;
578
 
579
              end
580
              else begin
581
 
582
                  // Pause frame receive, these frame will be filtered
583
 
584
                  if (curr_byte_cnt == 14'd0 &&
585
                      xgxs_rxd_barrel_d1[47:0] == `PAUSE_FRAME) begin
586
 
587
                      rxhfifo_wen = 1'b0;
588
                      next_pause_frame = 1'b1;
589
                  end
590
 
591
 
592
                  // Control character during data phase, force CRC error
593 21 antanguay
 
594 2 antanguay
                  if (|(xgxs_rxc_barrel_d1 & datamask)) begin
595
 
596
                      next_coding_error = 1'b1;
597
                  end
598
 
599
 
600
                  // Write SOP to status bits during first byte
601
 
602
                  if (curr_byte_cnt == 14'b0) begin
603 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_SOP] = 1'b1;
604 2 antanguay
                  end
605
 
606
                  /* verilator lint_off WIDTH */
607 21 antanguay
                  //next_byte_cnt = curr_byte_cnt +
608
                  //                addmask[0] + addmask[1] + addmask[2] + addmask[3] +
609
                  //                addmask[4] + addmask[5] + addmask[6] + addmask[7];
610 2 antanguay
                  /* verilator lint_on WIDTH */
611 21 antanguay
                  // don't infer a chain of adders
612 23 antanguay
                  next_byte_cnt = curr_byte_cnt + {10'b0, bit_cnt8(datamask[7:0])};
613 2 antanguay
 
614
 
615
                  // We will not write to the fifo if all is left
616
                  // are four or less bytes of crc. We also strip off the
617
                  // crc, which requires looking one cycle ahead
618 21 antanguay
                  // wstatus:
619 6 antanguay
                  //   [2:0] modulus of packet length
620 2 antanguay
 
621
                  // Look one cycle ahead for TERMINATE in lanes 0 to 4
622
 
623
                  if (xgxs_rxd_barrel[`LANE4] == `TERMINATE && xgxs_rxc_barrel[4]) begin
624 21 antanguay
 
625 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
626
                      rxhfifo_wstatus[2:0] = 3'd0;
627 2 antanguay
 
628
                      crc_start_8b = 1'b1;
629
                      next_crc_bytes = 4'd8;
630
                      next_crc_rx = xgxs_rxd_barrel[31:0];
631
 
632 23 antanguay
                      next_frame_end_flag = 1'b1;
633
                      next_frame_end_bytes = 3'd4;
634
 
635 2 antanguay
                      next_state = SM_IDLE;
636
 
637
                  end
638
 
639
                  if (xgxs_rxd_barrel[`LANE3] == `TERMINATE && xgxs_rxc_barrel[3]) begin
640
 
641 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
642
                      rxhfifo_wstatus[2:0] = 3'd7;
643 2 antanguay
 
644
                      crc_start_8b = 1'b1;
645
                      next_crc_bytes = 4'd7;
646
                      next_crc_rx = {xgxs_rxd_barrel[23:0], xgxs_rxd_barrel_d1[63:56]};
647 21 antanguay
 
648 23 antanguay
                      next_frame_end_flag = 1'b1;
649
                      next_frame_end_bytes = 3'd3;
650
 
651 2 antanguay
                      next_state = SM_IDLE;
652
 
653
                  end
654 21 antanguay
 
655 2 antanguay
                  if (xgxs_rxd_barrel[`LANE2] == `TERMINATE && xgxs_rxc_barrel[2]) begin
656
 
657 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
658
                      rxhfifo_wstatus[2:0] = 3'd6;
659 2 antanguay
 
660
                      crc_start_8b = 1'b1;
661
                      next_crc_bytes = 4'd6;
662
                      next_crc_rx = {xgxs_rxd_barrel[15:0], xgxs_rxd_barrel_d1[63:48]};
663
 
664 23 antanguay
                      next_frame_end_flag = 1'b1;
665
                      next_frame_end_bytes = 3'd2;
666
 
667 2 antanguay
                      next_state = SM_IDLE;
668
 
669
                  end
670
 
671
                  if (xgxs_rxd_barrel[`LANE1] == `TERMINATE && xgxs_rxc_barrel[1]) begin
672
 
673 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
674
                      rxhfifo_wstatus[2:0] = 3'd5;
675 2 antanguay
 
676
                      crc_start_8b = 1'b1;
677
                      next_crc_bytes = 4'd5;
678
                      next_crc_rx = {xgxs_rxd_barrel[7:0], xgxs_rxd_barrel_d1[63:40]};
679
 
680 23 antanguay
                      next_frame_end_flag = 1'b1;
681
                      next_frame_end_bytes = 3'd1;
682
 
683 2 antanguay
                      next_state = SM_IDLE;
684
 
685
                  end
686 21 antanguay
 
687 2 antanguay
                  if (xgxs_rxd_barrel[`LANE0] == `TERMINATE && xgxs_rxc_barrel[0]) begin
688
 
689 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
690
                      rxhfifo_wstatus[2:0] = 3'd4;
691 2 antanguay
 
692
                      crc_start_8b = 1'b1;
693
                      next_crc_bytes = 4'd4;
694
                      next_crc_rx = xgxs_rxd_barrel_d1[63:32];
695
 
696 23 antanguay
                      next_frame_end_flag = 1'b1;
697
 
698 2 antanguay
                      next_state = SM_IDLE;
699
 
700
                  end
701
 
702
                  // Look at current cycle for TERMINATE in lanes 5 to 7
703
 
704
                  if (xgxs_rxd_barrel_d1[`LANE7] == `TERMINATE &&
705
                      xgxs_rxc_barrel_d1[7]) begin
706
 
707 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
708
                      rxhfifo_wstatus[2:0] = 3'd3;
709 2 antanguay
 
710
                      crc_start_8b = 1'b1;
711
                      next_crc_bytes = 4'd3;
712
                      next_crc_rx = xgxs_rxd_barrel_d1[55:24];
713
 
714 23 antanguay
                      next_frame_end_flag = 1'b1;
715
 
716 2 antanguay
                      next_state = SM_IDLE;
717
 
718
                  end
719 21 antanguay
 
720 2 antanguay
                  if (xgxs_rxd_barrel_d1[`LANE6] == `TERMINATE &&
721
                      xgxs_rxc_barrel_d1[6]) begin
722
 
723 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
724
                      rxhfifo_wstatus[2:0] = 3'd2;
725 2 antanguay
 
726
                      crc_start_8b = 1'b1;
727
                      next_crc_bytes = 4'd2;
728
                      next_crc_rx = xgxs_rxd_barrel_d1[47:16];
729
 
730 23 antanguay
                      next_frame_end_flag = 1'b1;
731
 
732 2 antanguay
                      next_state = SM_IDLE;
733
 
734
                  end
735 21 antanguay
 
736 2 antanguay
                  if (xgxs_rxd_barrel_d1[`LANE5] == `TERMINATE &&
737
                      xgxs_rxc_barrel_d1[5]) begin
738
 
739 6 antanguay
                      rxhfifo_wstatus[`RXSTATUS_EOP] = 1'b1;
740
                      rxhfifo_wstatus[2:0] = 3'd1;
741 2 antanguay
 
742
                      crc_start_8b = 1'b1;
743
                      next_crc_bytes = 4'd1;
744
                      next_crc_rx = xgxs_rxd_barrel_d1[39:8];
745
 
746 23 antanguay
                      next_frame_end_flag = 1'b1;
747
 
748 2 antanguay
                      next_state = SM_IDLE;
749
 
750
                  end
751
              end
752
          end
753
 
754
        default:
755
          begin
756
              next_state = SM_IDLE;
757
          end
758
 
759
    endcase
760
 
761
end
762
 
763
 
764
always @(posedge clk_xgmii_rx or negedge reset_xgmii_rx_n) begin
765
 
766
    if (reset_xgmii_rx_n == 1'b0) begin
767
 
768
        rxhfifo_ralmost_empty_d1 <= 1'b1;
769
 
770
        drop_data <= 1'b0;
771
 
772
        pkt_pending <= 1'b0;
773
 
774 6 antanguay
        rxhfifo_ren_d1 <= 1'b0;
775
 
776 2 antanguay
    end
777
    else begin
778
 
779
        rxhfifo_ralmost_empty_d1 <= rxhfifo_ralmost_empty;
780
 
781
        drop_data <= next_drop_data;
782
 
783 6 antanguay
        pkt_pending <= rxhfifo_ren;
784 2 antanguay
 
785 6 antanguay
        rxhfifo_ren_d1 <= rxhfifo_ren;
786
 
787 2 antanguay
    end
788
 
789
end
790
 
791
always @(/*AS*/crc_done or crc_good or drop_data or pkt_pending
792
         or rxdfifo_wfull or rxhfifo_ralmost_empty_d1 or rxhfifo_rdata
793 6 antanguay
         or rxhfifo_ren_d1 or rxhfifo_rstatus) begin
794 2 antanguay
 
795
    rxd_ovflow_error = 1'b0;
796
 
797
    rxdfifo_wdata = rxhfifo_rdata;
798
    rxdfifo_wstatus = rxhfifo_rstatus;
799
 
800
    next_drop_data = drop_data;
801
 
802
 
803
    // There must be at least 8 words in holding FIFO before we start reading.
804
    // This provides enough time for CRC calculation.
805
 
806 6 antanguay
    rxhfifo_ren = !rxhfifo_ralmost_empty_d1 ||
807
                  (pkt_pending && !rxhfifo_rstatus[`RXSTATUS_EOP]);
808 2 antanguay
 
809 21 antanguay
 
810 6 antanguay
    if (rxhfifo_ren_d1 && rxhfifo_rstatus[`RXSTATUS_SOP]) begin
811 2 antanguay
 
812
        // Reset drop flag on SOP
813 21 antanguay
 
814 2 antanguay
        next_drop_data = 1'b0;
815
 
816
    end
817
 
818 6 antanguay
    if (rxhfifo_ren_d1 && rxdfifo_wfull && !next_drop_data) begin
819 2 antanguay
 
820
        // FIFO overflow, abort transfer. The rest of the frame
821
        // will be dropped. Since we can't put an EOP indication
822
        // in a fifo already full, there will be no EOP and receive
823
        // side will need to sync on next SOP.
824
 
825
        rxd_ovflow_error = 1'b1;
826
        next_drop_data = 1'b1;
827
 
828
    end
829
 
830
 
831 6 antanguay
    rxdfifo_wen = rxhfifo_ren_d1 && !next_drop_data;
832 2 antanguay
 
833
 
834
 
835
    if (crc_done && !crc_good) begin
836
 
837
        // Flag packet with error when CRC error is detected
838 21 antanguay
 
839 6 antanguay
        rxdfifo_wstatus[`RXSTATUS_ERR] = 1'b1;
840 2 antanguay
 
841
    end
842
 
843
end
844
 
845
endmodule

powered by: WebSVN 2.1.0

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