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

Subversion Repositories nysa_sata

[/] [nysa_sata/] [trunk/] [rtl/] [link/] [sata_link_layer.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 cospan
//sata_link_layer.v
2
/*
3
Distributed under the MIT license.
4
Copyright (c) 2011 Dave McCoy (dave.mccoy@cospandesign.com)
5
 
6
Permission is hereby granted, free of charge, to any person obtaining a copy of
7
this software and associated documentation files (the "Software"), to deal in
8
the Software without restriction, including without limitation the rights to
9
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
of the Software, and to permit persons to whom the Software is furnished to do
11
so, subject to the following conditions:
12
 
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
15
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
SOFTWARE.
23
*/
24
 
25
`include "sata_defines.v"
26
 
27
module sata_link_layer (
28
  input               rst,            //reset
29
  input               clk,
30
 
31
//Command Interface
32
  output              link_layer_ready,
33
 
34
  input               sync_escape,
35
  output              post_align_write,
36
  input               hold,
37
 
38
//Phy Layer
39
  input               phy_ready,
40
  output              write_ready,
41
  input               platform_ready,
42
 
43
//XXX: I probably need some feedback to indicate that there is room to write
44
  output    [31:0]    tx_dout,
45 3 cospan
  output              tx_is_k,
46 2 cospan
 
47
  input     [31:0]    rx_din,
48 3 cospan
  input     [3:0]     rx_is_k,
49 2 cospan
 
50
  input               write_start,
51
  output              write_strobe,
52
  input     [31:0]    write_data,
53 3 cospan
  input     [23:0]    write_size,
54 2 cospan
  input               write_hold,
55
  output              write_finished,
56
  input               write_abort,
57
 
58
  output              read_start,
59
  output              read_strobe,
60
  output      [31:0]  read_data,
61
  input               read_ready,
62
  output              read_finished,
63
  output              read_crc_ok,
64
  output              remote_abort,
65
 
66
  output              xmit_error,
67
  output              wsize_z_error,
68
  input               prim_scrambler_en,
69
  input               data_scrambler_en,
70
  input               is_device,
71
 
72
  output      [3:0]   lax_i_state,
73
  output      [3:0]   lax_r_state,
74
  output      [3:0]   lax_w_state,
75
  output      [3:0]   lax_w_fstate,
76
 
77
 
78
//Detection
79
  output              detect_sync,
80
  output              detect_r_rdy,
81
  output              detect_r_ip,
82
  output              detect_r_ok,
83
  output              detect_r_err,
84
  output              detect_x_rdy,
85
  output              detect_sof,
86
  output              detect_eof,
87
  output              detect_wtrm,
88
  output              detect_cont,
89
  output              detect_hold,
90
  output              detect_holda,
91
  output              detect_align,
92
  output              detect_preq_s,
93
  output              detect_preq_p,
94
  output              detect_xrdy_xrdy,
95
  output              send_crc,
96
 
97
  output              dbg_send_holda,
98
 
99
  output      [23:0]  in_data_addra,
100
  output      [12:0]  d_count,
101
  output      [12:0]  write_count,
102
  output      [3:0]   buffer_pos
103
 
104
 
105
 
106
);
107
 
108
 
109
//Parameters
110
parameter           NOT_READY       = 4'h0;
111
parameter           IDLE            = 4'h1;
112
parameter           PM_DENY         = 4'h2;
113
//Registers/Wires
114
reg       [3:0]     state;
115
 
116
 
117
//Primatives
118
reg                 send_sync;
119
reg                 send_pmack;
120
reg                 send_pmnack;
121
 
122
 
123
wire                sli_idle;
124
wire      [31:0]    sli_tx_dout;
125 3 cospan
wire                sli_tx_is_k;
126 2 cospan
 
127
reg                 write_en;
128
wire                write_idle;
129
wire      [31:0]    slw_tx_dout;
130 3 cospan
wire                slw_tx_is_k;
131 2 cospan
 
132
reg                 read_en;
133
wire                read_idle;
134
wire      [31:0]    slr_tx_dout;
135 3 cospan
wire                slr_tx_is_k;
136 2 cospan
 
137
wire      [31:0]    ll_tx_dout;
138 3 cospan
wire                ll_tx_is_k;
139 2 cospan
 
140
wire                last_prim;
141
 
142
//Submodules
143
 
144
//XXX: I can probably use only one CRC checker for the entire stack but to make it easier I'm gonna use two for
145
      //the read and write path
146
 
147
//XXX: maybe add a scrambler for PRIM scrambling
148
 
149
 
150
cont_controller ccon (
151
  .rst                  (rst                    ),
152
  .clk                  (clk                    ),
153
  .phy_ready            (phy_ready              ),
154
  .xmit_cont_en         (prim_scrambler_en      ),
155
  .last_prim            (last_prim              ),
156
 
157
  .rx_din               (rx_din                 ),
158 3 cospan
  .rx_is_k               (rx_is_k                 ),
159 2 cospan
 
160
  .ll_tx_din            (ll_tx_dout             ),
161 3 cospan
  .ll_tx_is_k            (ll_tx_is_k              ),
162 2 cospan
 
163
  .cont_tx_dout         (tx_dout                ),
164 3 cospan
  .cont_tx_is_k          (tx_is_k                 ),
165 2 cospan
 
166
  .detect_sync          (detect_sync            ),
167
  .detect_r_rdy         (detect_r_rdy           ),
168
  .detect_r_ip          (detect_r_ip            ),
169
  .detect_r_err         (detect_r_err           ),
170
  .detect_r_ok          (detect_r_ok            ),
171
  .detect_x_rdy         (detect_x_rdy           ),
172
  .detect_sof           (detect_sof             ),
173
  .detect_eof           (detect_eof             ),
174
  .detect_wtrm          (detect_wtrm            ),
175
  .detect_cont          (detect_cont            ),
176
  .detect_hold          (detect_hold            ),
177
  .detect_holda         (detect_holda           ),
178
  .detect_preq_s        (detect_preq_s          ),
179
  .detect_preq_p        (detect_preq_p          ),
180
  .detect_align         (detect_align           ),
181
  .detect_xrdy_xrdy     (detect_xrdy_xrdy       )
182
);
183
 
184
sata_link_layer_write slw (
185
  .rst                  (rst                    ),
186
  .clk                  (clk                    ),
187
  .en                   (write_en               ),
188
  .idle                 (write_idle             ),
189
  .phy_ready            (phy_ready              ),
190
  .write_ready          (write_ready            ),
191
  .send_sync_escape     (sync_escape            ),
192
 
193
  .detect_x_rdy         (detect_x_rdy           ),
194
  .detect_r_rdy         (detect_r_rdy           ),
195
  .detect_r_ip          (detect_r_ip            ),
196
  .detect_r_err         (detect_r_err           ),
197
  .detect_r_ok          (detect_r_ok            ),
198
  .detect_cont          (detect_cont            ),
199
  .detect_hold          (detect_hold            ),
200
  .detect_holda         (detect_holda           ),
201
  .detect_sync          (detect_sync            ),
202
  .detect_align         (detect_align           ),
203
 
204
  .send_holda           (dbg_send_holda         ),
205
 
206
  .write_start          (write_start            ),
207
  .write_strobe         (write_strobe           ),
208
  .write_data           (write_data             ),
209
  .write_size           (write_size             ),
210
  .write_hold           (write_hold             ),
211
  .write_finished       (write_finished         ),
212
  .write_abort          (write_abort            ),
213
 
214
  .last_prim            (last_prim              ),
215
  .send_crc             (send_crc               ),
216
  .post_align_write     (post_align_write       ),
217
 
218
  .tx_dout              (slw_tx_dout            ),
219 3 cospan
  .tx_is_k              (slw_tx_is_k            ),
220 2 cospan
  .rx_din               (rx_din                 ),
221 3 cospan
  .rx_is_k              (rx_is_k                ),
222 2 cospan
 
223
  .xmit_error           (xmit_error             ),
224
  .wsize_z_error        (wsize_z_error          ),
225
 
226
  .data_scrambler_en    (data_scrambler_en      ),
227
  .is_device            (is_device              ),
228
  .state                (lax_w_state            ),
229
  .fstate               (lax_w_fstate           ),
230
 
231
  .in_data_addra        (in_data_addra          ),
232
  .write_count          (write_count            ),
233
  .d_count              (d_count                ),
234
  .buffer_pos           (buffer_pos             )
235
);
236
 
237
sata_link_layer_read slr (
238
  .rst                  (rst                    ),
239
  .clk                  (clk                    ),
240
  .en                   (read_en                ),
241
  .idle                 (read_idle              ),
242
  .sync_escape          (sync_escape            ),
243
  .phy_ready            (phy_ready              ),
244
  .dbg_hold             (hold                   ),
245
 
246
  .detect_align         (detect_align           ),
247
  .detect_sync          (detect_sync            ),
248
  .detect_x_rdy         (detect_x_rdy           ),
249
  .detect_sof           (detect_sof             ),
250
  .detect_eof           (detect_eof             ),
251
  .detect_wtrm          (detect_wtrm            ),
252
  .detect_cont          (detect_cont            ),
253
  .detect_holda         (detect_holda           ),
254
  .detect_hold          (detect_hold            ),
255
  .detect_xrdy_xrdy     (detect_xrdy_xrdy       ),
256
 
257
  .tx_dout              (slr_tx_dout            ),
258 3 cospan
  .tx_is_k              (slr_tx_is_k            ),
259 2 cospan
  .rx_din               (rx_din                 ),
260 3 cospan
  .rx_is_k              (rx_is_k                ),
261 2 cospan
 
262
  .read_ready           (read_ready             ),
263
  .read_strobe          (read_strobe            ),
264
  .read_data            (read_data              ),
265
  .read_start           (read_start             ),
266
  .read_finished        (read_finished          ),
267
  .remote_abort         (remote_abort           ),
268
 
269
  .crc_ok               (read_crc_ok            ),
270
 
271
  .data_scrambler_en    (data_scrambler_en      ),
272
  .is_device            (is_device              ),
273
  .lax_r_state          (lax_r_state            )
274
);
275
 
276
//Asynchronous logic
277
assign  ll_tx_dout = (!read_idle) ? slr_tx_dout  : (!write_idle) ? slw_tx_dout : sli_tx_dout;
278 3 cospan
assign  ll_tx_is_k  = (!read_idle) ? slr_tx_is_k   : (!write_idle) ? slw_tx_is_k  : sli_tx_is_k;
279 2 cospan
 
280
 
281
assign  sli_tx_dout   = (send_pmnack) ? `PRIM_PMNACK  :
282
                        (send_pmack)  ? `PRIM_PMACK :
283
                        `PRIM_SYNC;
284
 
285 3 cospan
assign  sli_tx_is_k    = 1;
286 2 cospan
 
287
assign  link_layer_ready  = (state == IDLE) && read_idle && write_idle;
288
 
289
assign  lax_i_state       = state;
290
 
291
 
292
 
293
 
294
//Main State Machine
295
always @ (posedge clk) begin
296
  if (rst) begin
297
    state             <=  NOT_READY;
298
    send_pmnack       <=  0;
299
    send_pmack        <=  0;
300
 
301
    write_en          <=  0;
302
    read_en           <=  0;
303
  end
304
  else begin
305
    //Strobes
306
    send_pmnack       <=  0;
307
    send_pmack        <=  0;
308
 
309
    write_en          <=  0;
310
    read_en           <=  0;
311
 
312
    if (!platform_ready) begin
313
      state           <=  NOT_READY;
314
    end
315
 
316
    if (phy_ready) begin
317
      case (state)
318
        NOT_READY: begin
319
          if (platform_ready) begin
320
            state       <=  IDLE;
321
          end
322
        end
323
        IDLE: begin
324
          write_en      <=  1;
325
          read_en       <=  1;
326
          if (detect_preq_s || detect_preq_p) begin
327
            send_pmnack <=  1;
328
            state       <=  PM_DENY;
329
          end
330
        end
331
        PM_DENY: begin
332
           if (detect_preq_s || detect_preq_p) begin
333
            send_pmnack <=  1;
334
          end
335
          else begin
336
            state       <=  IDLE;
337
          end
338
        end
339
        default: begin
340
          state         <=  NOT_READY;
341
        end
342
      endcase
343
    end
344
  end
345
end
346
 
347
endmodule

powered by: WebSVN 2.1.0

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