1 |
2 |
acastong |
//link_l2_tb.h
|
2 |
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
3 |
|
|
* Version: MPL 1.1
|
4 |
|
|
*
|
5 |
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
6 |
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
7 |
|
|
* the License. You may obtain a copy of the License at
|
8 |
|
|
* http://www.mozilla.org/MPL/
|
9 |
|
|
*
|
10 |
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
11 |
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
12 |
|
|
* for the specific language governing rights and limitations under the
|
13 |
|
|
* License.
|
14 |
|
|
*
|
15 |
|
|
* The Original Code is HyperTransport Tunnel IP Core.
|
16 |
|
|
*
|
17 |
|
|
* The Initial Developer of the Original Code is
|
18 |
|
|
* Ecole Polytechnique de Montreal.
|
19 |
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
20 |
|
|
* the Initial Developer. All Rights Reserved.
|
21 |
|
|
*
|
22 |
|
|
* Contributor(s):
|
23 |
|
|
* Ami Castonguay <acastong@grm.polymtl.ca>
|
24 |
|
|
*
|
25 |
|
|
* Alternatively, the contents of this file may be used under the terms
|
26 |
|
|
* of the Polytechnique HyperTransport Tunnel IP Core Source Code License
|
27 |
|
|
* (the "PHTICSCL License", see the file PHTICSCL.txt), in which case the
|
28 |
|
|
* provisions of PHTICSCL License are applicable instead of those
|
29 |
|
|
* above. If you wish to allow use of your version of this file only
|
30 |
|
|
* under the terms of the PHTICSCL License and not to allow others to use
|
31 |
|
|
* your version of this file under the MPL, indicate your decision by
|
32 |
|
|
* deleting the provisions above and replace them with the notice and
|
33 |
|
|
* other provisions required by the PHTICSCL License. If you do not delete
|
34 |
|
|
* the provisions above, a recipient may use your version of this file
|
35 |
|
|
* under either the MPL or the PHTICSCL License."
|
36 |
|
|
*
|
37 |
|
|
* ***** END LICENSE BLOCK ***** */
|
38 |
|
|
|
39 |
|
|
#ifndef LINK_L2_TB_H
|
40 |
|
|
#define LINK_L2_TB_H
|
41 |
|
|
|
42 |
|
|
#include <queue>
|
43 |
|
|
#include "../../../rtl/systemc/core_synth/synth_datatypes.h"
|
44 |
|
|
#include "../../../rtl/systemc/core_synth/constants.h"
|
45 |
|
|
|
46 |
|
|
const int poly = 0x04C11DB7; /* The HT periodic CRC polynomial */
|
47 |
|
|
|
48 |
|
|
/** struct regrouping a dword, it's LCTL and HCTL values and
|
49 |
|
|
if there is a ctl transition error during the transmission*/
|
50 |
|
|
struct LinkTransmission{
|
51 |
|
|
sc_bv<32> dword;
|
52 |
|
|
bool lctl;
|
53 |
|
|
bool hctl;
|
54 |
|
|
bool error;
|
55 |
|
|
};
|
56 |
|
|
|
57 |
|
|
//Forward decleration
|
58 |
|
|
class link_rx_transmitter;
|
59 |
|
|
class link_tx_validator;
|
60 |
|
|
|
61 |
|
|
///Testbench for the link_l2 module
|
62 |
|
|
/**
|
63 |
|
|
@class link_l2_tb
|
64 |
|
|
@author Ami Castonguay
|
65 |
|
|
@description This is a module to test the link module in it's
|
66 |
|
|
whole. It will test for the different retry and ldtstop
|
67 |
|
|
sequences, for periodic CRC corectness, etc.
|
68 |
|
|
*/
|
69 |
|
|
class link_l2_tb : public sc_module {
|
70 |
|
|
|
71 |
|
|
public:
|
72 |
|
|
|
73 |
|
|
///Main system clock
|
74 |
|
|
sc_in<bool > clk;
|
75 |
|
|
///Reset of the system
|
76 |
|
|
sc_out<bool> resetx;
|
77 |
|
|
///If the power of the system is ok, for link width sampling
|
78 |
|
|
sc_out<bool> pwrok;
|
79 |
|
|
///If in a LDTSTOP sequence (power saving mode)
|
80 |
|
|
sc_out<bool> ldtstopx;
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
///CTL going to RX part of the link
|
84 |
|
|
sc_out<sc_bv<CAD_IN_DEPTH> > phy_ctl_lk;
|
85 |
|
|
///CAD going to RX part of the link
|
86 |
|
|
sc_out<sc_bv<CAD_IN_DEPTH> > phy_cad_lk[CAD_IN_WIDTH];
|
87 |
|
|
///If there is CTL and CAD available for the RX part of the link
|
88 |
|
|
sc_out<bool> phy_available_lk;
|
89 |
|
|
|
90 |
|
|
///CTL from TX part of the link
|
91 |
|
|
sc_in<sc_bv<CAD_OUT_DEPTH> > lk_ctl_phy;
|
92 |
|
|
///CAD from TX part of the link
|
93 |
|
|
sc_in<sc_bv<CAD_OUT_DEPTH> > lk_cad_phy[CAD_OUT_WIDTH];
|
94 |
|
|
///To consume data coming from TX part of the link
|
95 |
|
|
sc_out<bool> phy_consume_lk;
|
96 |
|
|
|
97 |
|
|
///If the link disables drivers
|
98 |
|
|
sc_in<bool> lk_disable_drivers_phy;
|
99 |
|
|
///If the link disables receivers
|
100 |
|
|
sc_in<bool> lk_disable_receivers_phy;
|
101 |
|
|
|
102 |
|
|
/**
|
103 |
|
|
Data to be sent to the next link
|
104 |
|
|
This data comes from the flow control
|
105 |
|
|
*/
|
106 |
|
|
//@{
|
107 |
|
|
///Dword to send
|
108 |
|
|
sc_out<sc_bv<32> > fc_dword_lk;
|
109 |
|
|
///The LCTL value associated with the dword to send
|
110 |
|
|
sc_out<bool> fc_lctl_lk;
|
111 |
|
|
///The HCTL value associated with the dword to send
|
112 |
|
|
sc_out<bool> fc_hctl_lk;
|
113 |
|
|
///To consume the data from the flow control
|
114 |
|
|
sc_in<bool> lk_consume_fc;
|
115 |
|
|
//@}
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
//*******************************
|
119 |
|
|
// Signals from link
|
120 |
|
|
//*******************************
|
121 |
|
|
|
122 |
|
|
///Bit vector output for command decoder
|
123 |
|
|
sc_in< sc_bv<32> > lk_dword_cd;
|
124 |
|
|
///Control bit
|
125 |
|
|
sc_in< bool > lk_hctl_cd;
|
126 |
|
|
///Control bit
|
127 |
|
|
sc_in< bool > lk_lctl_cd;
|
128 |
|
|
///FIFO is ready to be read from
|
129 |
|
|
sc_in< bool > lk_available_cd;
|
130 |
|
|
|
131 |
|
|
/**
|
132 |
|
|
Link widths
|
133 |
|
|
|
134 |
|
|
000 8 bits
|
135 |
|
|
100 2 bits
|
136 |
|
|
101 4 bits
|
137 |
|
|
111 Link physically not connected
|
138 |
|
|
*/
|
139 |
|
|
//@{
|
140 |
|
|
///The link width for the RX side
|
141 |
|
|
sc_out<sc_bv<3> > csr_rx_link_width_lk;
|
142 |
|
|
///The link width for the TX side
|
143 |
|
|
sc_out<sc_bv<3> > csr_tx_link_width_lk;
|
144 |
|
|
//@}
|
145 |
|
|
|
146 |
|
|
//If the chain is being synched
|
147 |
|
|
sc_out<bool> csr_sync;
|
148 |
|
|
|
149 |
|
|
///If this link should be inactive because it is the end of chain
|
150 |
|
|
sc_out<bool> csr_end_of_chain;
|
151 |
|
|
|
152 |
|
|
///To update the link width registered in the CSR with the new value
|
153 |
|
|
sc_in<bool> lk_update_link_width_csr;
|
154 |
|
|
///The link width that is being sampled
|
155 |
|
|
sc_in<sc_bv<3> > lk_sampled_link_width_csr;
|
156 |
|
|
///A protocol error has been detected
|
157 |
|
|
sc_in<bool> lk_protocol_error_csr;
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
///Force CRC errors to be generated
|
161 |
|
|
sc_out<bool> csr_crc_force_error_lk;
|
162 |
|
|
///To turn off the transmitter
|
163 |
|
|
sc_out<bool> csr_transmitter_off_lk;
|
164 |
|
|
///Hold CTL longer in the ini sequemce
|
165 |
|
|
sc_out<bool> csr_extented_ctl_lk;
|
166 |
|
|
///The timeout for CTL being low too long is extended
|
167 |
|
|
sc_out<bool> csr_extended_ctl_timeout_lk;
|
168 |
|
|
///If we are enabled to tristated the drivers when in ldtstop
|
169 |
|
|
sc_out<bool> csr_ldtstop_tristate_enable_lk;
|
170 |
|
|
|
171 |
|
|
///CRC error detected on link
|
172 |
|
|
sc_in<bool> lk_crc_error_csr;
|
173 |
|
|
///Update the link failure flag in CSR with the lk_link_failure_csr signal
|
174 |
|
|
sc_in<bool> lk_update_link_failure_property_csr;
|
175 |
|
|
|
176 |
|
|
#ifdef RETRY_MODE_ENABLED
|
177 |
|
|
///Start a retry sequence
|
178 |
|
|
sc_in<bool> lk_initiate_retry_disconnect;
|
179 |
|
|
///Command decoder commands a retry disconnect
|
180 |
|
|
sc_out<bool> cd_initiate_retry_disconnect;
|
181 |
|
|
|
182 |
|
|
///The flow control asks us to disconnect the link
|
183 |
|
|
sc_out<bool> fc_disconnect_lk;
|
184 |
|
|
///If we are in the retry mode
|
185 |
|
|
sc_out<bool > csr_retry;
|
186 |
|
|
#endif
|
187 |
|
|
///RX link is connected (identical to lk_initialization_complete_csr)
|
188 |
|
|
sc_in<bool> lk_rx_connected;
|
189 |
|
|
///This signal should only be evaluated at lk_update_link_failure_property_csr
|
190 |
|
|
sc_in<bool> lk_link_failure_csr;
|
191 |
|
|
|
192 |
|
|
//A sync error has been detected
|
193 |
|
|
// - Not used anymore, sync only detected through standard decode logic
|
194 |
|
|
//sc_in<bool> lk_sync_detected_csr;
|
195 |
|
|
|
196 |
|
|
///Command decoder commands a ltdstop disconnect
|
197 |
|
|
sc_out<bool> cd_initiate_nonretry_disconnect_lk;
|
198 |
|
|
|
199 |
|
|
#ifndef INTERNAL_SHIFTER_ALIGNMENT
|
200 |
|
|
///High speed deserializer should stall shifting bits for lk_deser_stall_cycles_phy cycles
|
201 |
|
|
/** Cannot be asserted with a lk_deser_stall_cycles_phy value of 0*/
|
202 |
|
|
sc_in<bool > lk_deser_stall_phy;
|
203 |
|
|
///Number of bit times to stall deserializing incoming data when lk_deser_stall_phy is asserted
|
204 |
|
|
sc_in<sc_uint<LOG2_CAD_IN_DEPTH> > lk_deser_stall_cycles_phy;
|
205 |
|
|
#endif
|
206 |
|
|
|
207 |
|
|
///Queue of dwords to send to the RX side of the link
|
208 |
|
|
std::queue<LinkTransmission> transmit_rx_queue;
|
209 |
|
|
///Queue of dwords expected to be received from the link
|
210 |
|
|
std::queue<LinkTransmission> expected_rx_queue;
|
211 |
|
|
|
212 |
|
|
///Module that takes care of initializing the link and sending data to RX side
|
213 |
|
|
link_rx_transmitter * transmitter;
|
214 |
|
|
///Module that takes validates what is sent from the TX side
|
215 |
|
|
link_tx_validator * validator;
|
216 |
|
|
|
217 |
|
|
///When true, will send warm reset signaling and reinit the link
|
218 |
|
|
/** Once the link is reconnected, reset_rx_connection goes to false*/
|
219 |
|
|
bool reset_rx_connection;
|
220 |
|
|
///Wether to check if what the rx receives is valid
|
221 |
|
|
bool check_rx_dword_reception;
|
222 |
|
|
|
223 |
|
|
///SystemC Macro
|
224 |
|
|
SC_HAS_PROCESS(link_l2_tb);
|
225 |
|
|
|
226 |
|
|
///Constructor
|
227 |
|
|
link_l2_tb(sc_module_name name);
|
228 |
|
|
///Desctructor
|
229 |
|
|
virtual ~link_l2_tb();
|
230 |
|
|
|
231 |
|
|
///Main control of the testbench (scripted events)
|
232 |
|
|
void stimulus();
|
233 |
|
|
///Brings the testbench and link to an initial state, then
|
234 |
|
|
///start the reconnection sequence
|
235 |
|
|
void init();
|
236 |
|
|
|
237 |
|
|
///Takes care of starting initialization and feeding data from queue to RX
|
238 |
|
|
void manage_rx_transmission();
|
239 |
|
|
///Checks that framed data produced from the RX side is correct
|
240 |
|
|
void validate_rx_reception();
|
241 |
|
|
|
242 |
|
|
//Fills TX queue with random transmissions
|
243 |
|
|
/**
|
244 |
|
|
@description Will add random transmission to the queue of
|
245 |
|
|
things for the TX to send. CRC's are NOT inserted
|
246 |
|
|
in the queue by this.
|
247 |
|
|
@param quantity The number of transmissions to add to the queue
|
248 |
|
|
@param updateCRC If the current CRC should be updated with
|
249 |
|
|
the queued transmission
|
250 |
|
|
*/
|
251 |
|
|
void fill_tx_qeues(const unsigned quantity,bool updateCRC);
|
252 |
|
|
///Empties the TX packet queue and resets crc if requested
|
253 |
|
|
void empty_tx_queues(bool reset_crc);
|
254 |
|
|
///Fill both RX and TX queues
|
255 |
|
|
/**
|
256 |
|
|
@description Will fill both RX and TX queues with random
|
257 |
|
|
transmissions. Periodic CRC's will automatically be
|
258 |
|
|
inserted in the stream of transmissions. This is to
|
259 |
|
|
be called only once to setup RX and TX queues as
|
260 |
|
|
it will start to fill the queues as if it's in the
|
261 |
|
|
first CRC window (first window is different from
|
262 |
|
|
following CRC windows).
|
263 |
|
|
@param quantity The number of packet to insert (does not
|
264 |
|
|
take into account the periodic CRC's inserted in the
|
265 |
|
|
stream)
|
266 |
|
|
@param insertLastCrc If a CRC should be added to the stream
|
267 |
|
|
if it's the last thing to add. Example : if 128+16
|
268 |
|
|
transmissions are added, should the CRC just following
|
269 |
|
|
those transmission be added or not
|
270 |
|
|
*/
|
271 |
|
|
void init_fill_queues(const unsigned quantity,bool insertLastCrc);
|
272 |
|
|
|
273 |
|
|
//Fills RX queue with random transmissions
|
274 |
|
|
/**
|
275 |
|
|
@description Will add random transmission to the queue of
|
276 |
|
|
things for the RX to receive. CRC's are NOT inserted
|
277 |
|
|
in the queue by this.
|
278 |
|
|
@param quantity The number of transmissions to add to the queue
|
279 |
|
|
@param updateCRC If the current CRC should be updated with
|
280 |
|
|
the queued transmission
|
281 |
|
|
*/
|
282 |
|
|
void fill_rx_qeues(const unsigned quantity,bool updateCRC);
|
283 |
|
|
///Empties the RX packet queue and resets crc if requested
|
284 |
|
|
void empty_rx_queues(bool reset_crc);
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
///Creates a completely random transmission to send
|
288 |
|
|
void generate_random_transmission(LinkTransmission & t);
|
289 |
|
|
|
290 |
|
|
/**
|
291 |
|
|
@description To update a CRC just like the HT tunnel calculates it
|
292 |
|
|
@param crc Initially contains the current crc value. It is updated
|
293 |
|
|
with the new calculated value
|
294 |
|
|
@param dword The dword to calculate the crc
|
295 |
|
|
@param lctl The lctl value used to calculate the new CRC
|
296 |
|
|
@param hctl The hctl value used to calculate the new CRC
|
297 |
|
|
*/
|
298 |
|
|
void update_crc(int & crc,const sc_bv<32> &dword, bool lctl, bool hctl);
|
299 |
|
|
|
300 |
|
|
///CRC value for the last CRC window sent to RX side
|
301 |
|
|
int last_rx_crc;
|
302 |
|
|
///Current partial CRC value for in-progress window being sent to RX side
|
303 |
|
|
int rx_crc;
|
304 |
|
|
|
305 |
|
|
///CRC value for the last CRC window received from TX side
|
306 |
|
|
int last_tx_crc;
|
307 |
|
|
///Current partial CRC value for in-progress window being received from TX side
|
308 |
|
|
int tx_crc;
|
309 |
|
|
|
310 |
|
|
///Number of RX packet send : for debug only
|
311 |
|
|
int rx_number;
|
312 |
|
|
///If a CRC error is expected
|
313 |
|
|
/** Contains the number of CRC errors that are expected, decremented every
|
314 |
|
|
time the link assert that a CRC error was detected*/
|
315 |
|
|
int expecting_rx_crc_error;
|
316 |
|
|
|
317 |
|
|
};
|
318 |
|
|
|
319 |
|
|
#endif
|