1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
//////////////////////////////////////////////////////////////////////
//// ////
//// File name "fault_sm.v" ////
//// ////
//// This file is part of the "10GE MAC" project ////
//// http://www.opencores.org/cores/xge_mac/ ////
//// ////
//// Author(s): ////
//// - A. Tanguay (antanguay@opencores.org) ////
//// ////
//////////////////////////////////////////////////////////////////////
//// ////
//// Copyright (C) 2008 AUTHORS. All rights reserved. ////
//// ////
//// This source file may be used and distributed without ////
//// restriction provided that this copyright statement is not ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer. ////
//// ////
//// This source file is free software; you can redistribute it ////
//// and/or modify it under the terms of the GNU Lesser General ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any ////
//// later version. ////
//// ////
//// This source is distributed in the hope that it will be ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
//// PURPOSE. See the GNU Lesser General Public License for more ////
//// details. ////
//// ////
//// You should have received a copy of the GNU Lesser General ////
//// Public License along with this source; if not, download it ////
//// from http://www.opencores.org/lgpl.shtml ////
//// ////
//////////////////////////////////////////////////////////////////////
`include "defines.v"
module fault_sm(/*AUTOARG*/
// Outputs
status_local_fault_crx, status_remote_fault_crx,
// Inputs
clk_xgmii_rx, reset_xgmii_rx_n, local_fault_msg_det,
remote_fault_msg_det
);
input clk_xgmii_rx;
input reset_xgmii_rx_n;
input [1:0] local_fault_msg_det;
input [1:0] remote_fault_msg_det;
output status_local_fault_crx;
output status_remote_fault_crx;
/*AUTOREG*/
// Beginning of automatic regs (for this module's undeclared outputs)
reg status_local_fault_crx;
reg status_remote_fault_crx;
// End of automatics
reg [1:0] curr_state;
reg [7:0] col_cnt;
reg [1:0] fault_sequence;
reg [1:0] last_seq_type;
reg [1:0] link_fault;
reg [2:0] seq_cnt;
reg [1:0] seq_type;
reg [1:0] seq_add;
/*AUTOWIRE*/
parameter [1:0]
SM_INIT = 2'd0,
SM_COUNT = 2'd1,
SM_FAULT = 2'd2,
SM_NEW_FAULT = 2'd3;
always @(/*AS*/local_fault_msg_det or remote_fault_msg_det) begin
//---
// Fault indication. Indicate remote or local fault
fault_sequence = local_fault_msg_det | remote_fault_msg_det;
//---
// Sequence type, local, remote, or ok
if (|local_fault_msg_det) begin
seq_type = `LINK_FAULT_LOCAL;
end
else if (|remote_fault_msg_det) begin
seq_type = `LINK_FAULT_REMOTE;
end
else begin
seq_type = `LINK_FAULT_OK;
end
//---
// Adder for number of faults, if detected in lower 4 lanes and
// upper 4 lanes, add 2. That's because we process 64-bit at a time
// instead of typically 32-bit xgmii.
if (|remote_fault_msg_det) begin
seq_add = remote_fault_msg_det[1] + remote_fault_msg_det[0];
end
else begin
seq_add = local_fault_msg_det[1] + local_fault_msg_det[0];
end
end
always @(posedge clk_xgmii_rx or negedge reset_xgmii_rx_n) begin
if (reset_xgmii_rx_n == 1'b0) begin
status_local_fault_crx <= 1'b0;
status_remote_fault_crx <= 1'b0;
end
else begin
//---
// Status signal to generate local/remote fault interrupts
status_local_fault_crx <= curr_state == SM_FAULT &&
link_fault == `LINK_FAULT_LOCAL;
status_remote_fault_crx <= curr_state == SM_FAULT &&
link_fault == `LINK_FAULT_REMOTE;
end
end
always @(posedge clk_xgmii_rx or negedge reset_xgmii_rx_n) begin
if (reset_xgmii_rx_n == 1'b0) begin
curr_state <= SM_INIT;
col_cnt <= 8'b0;
last_seq_type <= `LINK_FAULT_OK;
link_fault <= `LINK_FAULT_OK;
seq_cnt <= 3'b0;
end
else begin
case (curr_state)
SM_INIT:
begin
last_seq_type <= seq_type;
if (|fault_sequence) begin
// If a fault is detected, capture the type of
// fault and start column counter. We need 4 fault
// messages in 128 columns to accept the fault.
if (fault_sequence[0]) begin
col_cnt <= 8'd2;
end
else begin
col_cnt <= 8'd1;
end
seq_cnt <= {1'b0, seq_add};
curr_state <= SM_COUNT;
end
else begin
// If no faults, stay in INIT and clear counters
col_cnt <= 8'b0;
seq_cnt <= 3'b0;
end
end
SM_COUNT:
begin
col_cnt <= col_cnt + 8'd2;
seq_cnt <= seq_cnt + {1'b0, seq_add};
if (!fault_sequence[0] && col_cnt >= 8'd127) begin
// No new fault in lower lanes and almost
// reached the 128 columns count, abort fault.
curr_state <= SM_INIT;
end
else if (col_cnt > 8'd127) begin
// Reached the 128 columns count, abort fault.
curr_state <= SM_INIT;
end
else if (|fault_sequence) begin
// If fault type has changed, move to NEW_FAULT.
// If not, after detecting 4 fault messages move to
// FAULT state.
if (seq_type != last_seq_type) begin
curr_state <= SM_NEW_FAULT;
end
else begin
if ((seq_cnt + {1'b0, seq_add}) > 3'd3) begin
col_cnt <= 8'b0;
link_fault <= seq_type;
curr_state <= SM_FAULT;
end
end
end
end
SM_FAULT:
begin
col_cnt <= col_cnt + 8'd2;
if (!fault_sequence[0] && col_cnt >= 8'd127) begin
// No new fault in lower lanes and almost
// reached the 128 columns count, abort fault.
curr_state <= SM_INIT;
end
else if (col_cnt > 8'd127) begin
// Reached the 128 columns count, abort fault.
curr_state <= SM_INIT;
end
else if (|fault_sequence) begin
// Clear the column count each time we see a fault,
// if fault changes, go no next state.
col_cnt <= 8'd0;
if (seq_type != last_seq_type) begin
curr_state <= SM_NEW_FAULT;
end
end
end
SM_NEW_FAULT:
begin
// Capture new fault type. Start counters.
col_cnt <= 8'b0;
last_seq_type <= seq_type;
seq_cnt <= {1'b0, seq_add};
curr_state <= SM_COUNT;
end
endcase
end
end
endmodule
|