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

Subversion Repositories ht_tunnel

[/] [ht_tunnel/] [trunk/] [rtl/] [systemc/] [link_l2/] [link_l2.h] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 acastong
//link_l2.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_H
40
#define LINK_L2_H
41
 
42
#include "../core_synth/synth_datatypes.h"
43
#include "../core_synth/constants.h"
44
 
45
 
46
#define CRC_POLY 0x04C11DB7
47
 
48
///Values to represent the link with detected
49
enum LinkWidthEncoded
50
{ LINK_8_BIT = 0, LINK_4_BIT = 1, LINK_2_BIT = 2, INVALID_LINK_WIDTH = 3};
51
 
52
//Forward declaration
53
class link_frame_rx_l3;
54
class link_frame_tx_l3;
55
 
56
///Handles low level communicatino of the HyperTransport Tunnel
57
/**
58
        @class link_l2
59
        @author Ami Castonguay
60
        @description Handles initialization of the link, framing of incoming
61
                and outgoing data and also of periodic CRC calculations
62
*/
63
class link_l2 : public sc_module {
64
 
65
 
66
 
67
        /**
68
                States for the reception part of the link
69
        */
70
        enum rx_crc_state {
71
                RX_FIRST_CRC_WINDOW_ST,///< First CRC windows (no CRC sent after 64 dwords 
72
                RX_CRC_WINDOW_BEGIN_ST,///< First 16 dword of the CRC windows
73
                RX_RECEIVE_CRC_ST,///< Receiving the CRC
74
                RX_CRC_WINDOW_END_ST,///< Last 112 dword of the CRC windows
75
 
76
                RX_FIRST_CRC_WINDOW_LDTSTOP_ST,///< First CRC window, stop the link after next CRC sent
77
                RX_CRC_WINDOW_BEGIN_LDTSTOP_ST,///< Beginning of the CRC window, stop the link after next CRC sent
78
                RX_RECEIVE_CRC_LDTSTOP_ST,///< Receiving the CRC, stop the link after next CRC received
79
                RX_CRC_WINDOW_END_LDTSTOP_ST,///< End of the CRC window, stop the link after next CRC sent
80
                RX_CRC_WINDOW_LAST_LDTSTOP_ST,///< Last beginning of the CRC window before stopping the link
81
                RX_RECEIVE_LAST_CRC_LDTSTOP_ST,///< Receiving the last CRC, stop the link after CRC received
82
                RX_DISCONNECTED///< Link is stopped
83
        };
84
 
85
        /**
86
                States for the transmission part of the link
87
        */
88
        enum tx_crc_state {
89
                TX_FIRST_CRC_WINDOW_ST,/**First CRC windows (no CRC sent after 64 dwords) */
90
                TX_CRC_WINDOW_BEGIN_ST,/**<First 64 dword of the CRC windows*/
91
                TX_SEND_CRC_ST,/**< Sending the CRC */
92
                TX_CRC_WINDOW_END_ST,/**<Last 448 dword of the CRC windows*/
93
                TX_INACTIVE_ST,/**<If no link is detected or we are end of chain,
94
                                                        put the link in inactive mode.  Only reset can bring
95
                                                        out of this state. */
96
                TX_SYNC_ST,/**< If a sync was detected, we go in this mode and only reset can bring
97
                                                out of this state.  Syncs are sent out continuously*/
98
 
99
                TX_FIRST_CRC_WINDOW_LDTSTOP_ST,///< First CRC window, stop the link after next CRC sent
100
                TX_CRC_WINDOW_BEGIN_LDTSTOP_ST,///< Beginning of the CRC window, stop the link after next CRC sent
101
                TX_SEND_CRC_LDTSTOP_ST,///< Transmit the CRC, stop the link after next CRC transmitted
102
                TX_CRC_WINDOW_END_LDTSTOP_ST,///< End of the CRC window, stop the link after next CRC sent
103
                TX_CRC_WINDOW_LAST_LDTSTOP_ST,///< Last beginning of the CRC window before stopping the link
104
                TX_SEND_LAST_CRC_LDTSTOP_ST,///< Transmit the last CRC, stop the link after CRC transmitted
105
                TX_LDTSTOP_M64,///< After last CRC, must keep transmitting discon nops for at least 64 bit times
106
                TX_LDTSTOP///< Link is stopped
107
        };
108
 
109
        /**
110
                To select what must be transmitted
111
        */
112
        enum tx_output_selection {
113
                TX_SELECT_DATA = 0,///< Select data received from the flow_control
114
                TX_SELECT_CRC = 1,///< Select calculated CRC
115
                TX_SELECT_DISCON = 2,///< Select disconnect NOP's
116
                TX_SELECT_SYNC = 3,///< Select SYN packets
117
        };
118
 
119
public:
120
 
121
        ///RX CTL Higher is received later (MSB), lower is received first (LSB)
122
        /** This is the content of a shift register that stored the value
123
        of the CTL bit on the input.  CAD_IN_DEPTH depends on the PHY to core
124
        clock ratio.*/
125
        sc_in<sc_bv<CAD_IN_DEPTH> >             phy_ctl_lk;
126
        ///RX CAD Higher is received later (MSB), lower is received first (LSB)
127
        /** This is the content of a shift register that stored the value
128
        of the CAD bits on the input.  CAD_IN_DEPTH depends on the PHY to core
129
        clock ratio.*/
130
        sc_in<sc_bv<CAD_IN_DEPTH> >             phy_cad_lk[CAD_IN_WIDTH];
131
        ///If there is data available for the core from the link
132
        /** If the core runs at a frequency higher than the physical link, sometime
133
        the link will not have data available for the core.  This does not
134
        cause problem*/
135
        sc_in<bool>                                             phy_available_lk;
136
 
137
        ///TX CTL Higher is sent later (MSB), lower is sent first (LSB)
138
        sc_out<sc_bv<CAD_OUT_DEPTH> >   lk_ctl_phy;
139
        ///TX CAD Higher is sent later (MSB), lower is sent first (LSB)
140
        sc_out<sc_bv<CAD_OUT_DEPTH> >   lk_cad_phy[CAD_OUT_WIDTH];
141
        ///If the physical layer can consume the data we produce
142
        /** If the core runs at a frequency higher than the link, sometime
143
        the link will not be able to consume data produced from the core.  This does not
144
        cause problem*/
145
#ifndef INTERNAL_SHIFTER_ALIGNMENT
146
        ///High speed deserializer should stall shifting bits for lk_deser_stall_cycles_phy cycles
147
        /** Cannot be asserted with a lk_deser_stall_cycles_phy value of 0*/
148
        sc_out<bool > lk_deser_stall_phy;
149
        ///Number of bit times to stall deserializing incoming data when lk_deser_stall_phy is asserted
150
        sc_out<sc_uint<LOG2_CAD_IN_DEPTH> > lk_deser_stall_cycles_phy;
151
#endif
152
        sc_in<bool>                                             phy_consume_lk;
153
 
154
        ///To disable the drivers to save power
155
        sc_out<bool>                                    lk_disable_drivers_phy;
156
        ///To disable the receivers to save power
157
        sc_out<bool>                                    lk_disable_receivers_phy;
158
 
159 6 acastong
        ///When the link is completely disconnected for LDTSTOP
160
        sc_out<bool>                                    lk_ldtstop_disconnected;
161
 
162 2 acastong
        ///Register to keep the current calculated RX CRC
163
        sc_signal<sc_uint<32> >         rx_crc;
164
        ///Register to keep the calculated CRC value of the last CRC window
165
        sc_signal<sc_uint<32> >         rx_last_crc;
166
 
167
        ///Register to keep the current calculated TX CRC
168
        sc_signal<sc_uint<32> >         tx_crc;
169
        ///Register to keep the calculated CRC value of the last CRC window
170
        sc_signal<sc_uint<32> >         tx_last_crc;
171
 
172
 
173
        ///To store that a CRC error was encountered.
174
        /**
175
                The CRC error is not actually outputed before a sync error can
176
                be ruled out.
177
        */
178
        sc_signal<bool>                 crc_error;
179
        ///Delay time to know if a sync error has been ruled out.
180
        sc_signal<sc_uint<4> >  crc_error_delay;
181
 
182
 
183
        ///State of the tx side of the link
184
        sc_signal<tx_crc_state> tx_state;
185
        ///State of the rx side of the link
186
        sc_signal<rx_crc_state> rx_state;
187
 
188
        ///Count to know where we are in the RX CRC windows
189
        sc_signal<sc_uint<7> > rx_crc_count;
190
 
191
        ///Count to know where we are in the TX CRC windows
192
        sc_signal<sc_uint<7> > tx_crc_count;
193
 
194
        ///Selects what is transmitted on the link.  See ::tx_output_selection for possible values
195
        sc_signal<sc_uint<2> > transmit_select;
196
 
197
        //How many frames of all 1's have been detected, after 16, it is a sync error
198
        // - Not used anymore, sync only detected through standard decode logic
199
        //sc_signal<sc_uint<6> > sync_count;
200
 
201
 
202
        ///Core clk
203
        sc_in<bool>                     clk;
204
        ///4x Core clk, the link clk
205
 
206
        /**
207
                External global system signals
208
        */
209
        //@{
210
        ///Link is stoped (halted or paused) for power savings
211
        sc_in<bool>                     ldtstopx;
212
        ///Reset the system
213
        sc_in<bool>                     resetx;
214
        ///If power is stabilized - defines wether resetx represents a cold or warm reset
215
        sc_in<bool>                     pwrok;
216
        ///@}
217
 
218
        /**
219
                Data to be sent to the next link
220
                This data comes from the flow control
221
        */
222
        //@{
223
        ///Dword to send
224
        sc_in<sc_bv<32> >       fc_dword_lk;
225
        ///The LCTL value associated with the dword to send
226
        sc_in<bool>                     fc_lctl_lk;
227
        ///The HCTL value associated with the dword to send
228
        sc_in<bool>                     fc_hctl_lk;
229
        ///To consume the data from the flow control
230
        sc_out<bool>            lk_consume_fc;
231
        //@}
232
 
233
 
234
        //*******************************
235
        //      Signals from link
236
        //*******************************
237
 
238
        ///Bit vector output for command decoder 
239
        sc_out< sc_bv<32> >             lk_dword_cd;
240
        ///Control bit
241
        sc_out< bool >                  lk_hctl_cd;
242
        ///Control bit
243
        sc_out< bool >                  lk_lctl_cd;
244
        ///FIFO is ready to be read from
245
        sc_out< bool >                  lk_available_cd;
246
 
247
        /**
248
        Link widths
249
 
250
        000 8 bits
251
        100 2 bits
252
        101 4 bits
253
        111  Link physically not connected
254
        */
255
        //@{
256
        ///The link width for the RX side
257
        sc_in<sc_bv<3> >        csr_rx_link_width_lk;
258
        ///The link width for the TX side
259
        sc_in<sc_bv<3> >        csr_tx_link_width_lk;
260
        //@}
261
 
262
#ifdef RETRY_MODE_ENABLED
263
        ///If we are in the retry mode
264
        sc_in<bool >            csr_retry;
265
#endif
266
        ///If the chain is being synched
267
        sc_in<bool>                     csr_sync;
268
 
269
        ///If this link should be inactive because it is the end of chain
270
        sc_in<bool>                     csr_end_of_chain;
271
        ///Stop the transmitter
272
        sc_in<bool> csr_transmitter_off_lk;
273
 
274
        ///To update the link width registered in the CSR with the new value
275
        sc_out<bool>            lk_update_link_width_csr;
276
        ///The link width that is being sampled
277
        sc_out<sc_bv<3> >       lk_sampled_link_width_csr;
278
        ///A protocol error has been detected
279
        sc_out<bool>            lk_protocol_error_csr;
280
 
281
 
282
        ///Force CRC errors to be generated
283
        sc_in<bool>                     csr_crc_force_error_lk;
284
        ///Hold CTL longer in the init sequence
285
        sc_in<bool>                     csr_extented_ctl_lk;
286
        ///The timeout for CTL being low too long is extended
287
        sc_in<bool>                     csr_extended_ctl_timeout_lk;
288
        ///If we are enabled to tristate the drivers when in ldtstop
289
        sc_in<bool>                     csr_ldtstop_tristate_enable_lk;
290
 
291
        ///CRC error detected on link
292
        sc_out<bool>            lk_crc_error_csr;
293
        ///Update the link failure flag in CSR with the lk_link_failure_csr signal
294
        sc_out<bool>            lk_update_link_failure_property_csr;
295
 
296
#ifdef RETRY_MODE_ENABLED
297
        ///Start a retry sequence
298
        sc_out<bool>            lk_initiate_retry_disconnect;
299
 
300
        ///The flow control asks us to disconnect the link
301
        /** In retry mode, the link will wait for this signal
302
                to disconnect, even in a ldtstopx sequence.  Disconnect
303
                will occur after the dword is done sending*/
304
        sc_in<bool>                     fc_disconnect_lk;
305
#endif
306
        ///RX link is connected (identical to lk_initialization_complete_csr)
307
        sc_out<bool>            lk_rx_connected;
308
        ///This signal should only be evaluated at lk_update_link_failure_property_csr
309
        sc_out<bool>            lk_link_failure_csr;
310
 
311
        //A sync error has been detected
312
        // - Not used anymore, sync only detected through standard decode logic
313
        //sc_out<bool>          lk_sync_detected_csr;
314
 
315
#ifdef RETRY_MODE_ENABLED
316
        ///Command decoder commands a retry disconnect
317
        sc_in<bool>                     cd_initiate_retry_disconnect;
318
#endif
319
        ///Command decoder commands a ltdstop disconnect
320
        sc_in<bool>                     cd_initiate_nonretry_disconnect_lk;
321
 
322
        ///Signal from RX framer - a dword is available
323
        sc_signal<bool>                 framed_data_available;
324
        ///If the framed data can be made available for output
325
        /** It will be false when receiving periodic CRC for examble */
326
        sc_signal<bool>                 framed_data_ready;
327
 
328
        ///CAD signal  send to TX framer to be sent on the link
329
        sc_signal<sc_bv<32> >   cad_to_frame;
330
        ///LCTL signal send to TX framer to be sent on the link
331
        sc_signal<bool >                lctl_to_frame;
332
        ///HCTL signal send to TX framer to be sent on the link
333
        sc_signal<bool >                hctl_to_frame;
334
        ///If the TX framer consumes the data
335
        sc_signal<bool >                tx_consume_data;
336
 
337
        ///Signal to make the TX side disconnect
338
        /** Disables drivers.  Once deasserted, will begin init sequence*/
339
        sc_signal<bool>                 ldtstop_disconnect_tx;
340
        ///Signal to make the RX side disconnect
341
        /** Disables receivers.  Once deasserted, will begin init sequence*/
342
        sc_signal<bool>                 ldtstop_disconnect_rx;
343
 
344
        ///Asserted when the RX side is waiting for CTL to be activated
345
        /** TX cannot start it's init sequence until RX has asserted CTL, this
346
        assures that the next HT node is ready to listen to the init sequence*/
347
        sc_signal<bool>                 rx_waiting_for_ctl_tx;
348
 
349
        ///Asserted when a new RX CRC window begins. 
350
        /**Save CRC as "last" crc and clear current CRC*/
351
        sc_signal<bool>                 new_rx_crc_window;
352
        ///Asserted when a new TX CRC window begins. 
353
        /**Save CRC as "last" crc and clear current CRC*/
354
        sc_signal<bool>                 new_tx_crc_window;
355
 
356
#ifdef RETRY_MODE_ENABLED
357
        ///Signal to RX and TX to initiate a retry disconnect
358
        /**Usually equivalent to fc_disconnect_lk, except when sending CRC and SYN flood*/
359
        sc_signal<bool>                 tx_retry_disconnect;
360
#endif
361
 
362
        ///RX framing and initialization module
363
        link_frame_rx_l3 * frame_rx;
364
        ///TX framing and initialization module
365
        link_frame_tx_l3 * frame_tx;
366
 
367
 
368
 
369
        /**
370
                Keep track of the state for the reception of data, initialization of the
371
                link, CRC calculation, etc.
372
        */
373
 
374
        void rx_crc_state_machine();
375
 
376
        /**
377
                Keep track of the state for the transmission of data, initialization of the
378
                link, CRC calculation, etc.
379
        */
380
        void tx_crc_state_machine();
381
 
382
        /**
383
                Process that calculates the periodic CRC of data that arrives from the link
384
                so it can be compared with the sent CRC.  If the CRC's do not match, it means
385
                there was an error in the last CRC window.
386
        */
387
        void evaluate_rx_crc_process();
388
 
389
        /**
390
                Process that calculates the periodic CRC of data that is sent on the link
391
                so the other side can detect if an error occured during the transmission.
392
                there was an error in the last CRC window.
393
        */
394
        void evaluate_tx_crc_process();
395
 
396
        /**
397
                Selects what to send to the TX frame module using the ::transmit_select signal.
398
                See ::tx_output_selection for possible values of ::transmit_select
399
        */
400
        void select_output();
401
 
402 6 acastong
        /**
403
                Output the signal ldtstop_disconnect_tx signal to the output lk_ldtstop_disconnected.
404
                Yes, a process that ONLY does that!
405
        */
406
        void output_ldtstop_disconnected();
407
 
408 2 acastong
        ///AND gate betweem ::framed_data_available and ::framed_data_ready
409
        void output_framed_data();
410
 
411
        ///SystemC Macro
412
        SC_HAS_PROCESS(link_l2);
413
 
414
        /**
415
        @description Module/class constructor
416
        @param name The name of the instance of the module
417
        */
418
        link_l2( sc_module_name name);
419
};
420
 
421
#endif
422
 

powered by: WebSVN 2.1.0

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