1 |
2 |
mihad |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// File name "pci_master32_sm_if.v" ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the "PCI bridge" project ////
|
6 |
|
|
//// http://www.opencores.org/cores/pci/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Author(s): ////
|
9 |
|
|
//// - Miha Dolenc (mihad@opencores.org) ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// All additional information is avaliable in the README ////
|
12 |
|
|
//// file. ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// ////
|
15 |
|
|
//////////////////////////////////////////////////////////////////////
|
16 |
|
|
//// ////
|
17 |
|
|
//// Copyright (C) 2001 Miha Dolenc, mihad@opencores.org ////
|
18 |
|
|
//// ////
|
19 |
|
|
//// This source file may be used and distributed without ////
|
20 |
|
|
//// restriction provided that this copyright statement is not ////
|
21 |
|
|
//// removed from the file and that any derivative work contains ////
|
22 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
23 |
|
|
//// ////
|
24 |
|
|
//// This source file is free software; you can redistribute it ////
|
25 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
26 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
27 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
28 |
|
|
//// later version. ////
|
29 |
|
|
//// ////
|
30 |
|
|
//// This source is distributed in the hope that it will be ////
|
31 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
32 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
33 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
34 |
|
|
//// details. ////
|
35 |
|
|
//// ////
|
36 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
37 |
|
|
//// Public License along with this source; if not, download it ////
|
38 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
39 |
|
|
//// ////
|
40 |
|
|
//////////////////////////////////////////////////////////////////////
|
41 |
|
|
//
|
42 |
|
|
// CVS Revision History
|
43 |
|
|
//
|
44 |
|
|
// $Log: not supported by cvs2svn $
|
45 |
6 |
mihad |
// Revision 1.1.1.1 2001/10/02 15:33:46 mihad
|
46 |
|
|
// New project directory structure
|
47 |
2 |
mihad |
//
|
48 |
6 |
mihad |
//
|
49 |
2 |
mihad |
|
50 |
|
|
`include "constants.v"
|
51 |
|
|
`include "bus_commands.v"
|
52 |
6 |
mihad |
`include "timescale.v"
|
53 |
2 |
mihad |
|
54 |
|
|
/*====================================================================
|
55 |
|
|
Module provides interface between PCI bridge internals and PCI master
|
56 |
|
|
state machine
|
57 |
|
|
====================================================================*/
|
58 |
|
|
module PCI_MASTER32_SM_IF
|
59 |
|
|
(
|
60 |
|
|
clk_in,
|
61 |
|
|
reset_in,
|
62 |
|
|
|
63 |
|
|
// interconnect to pci master state machine
|
64 |
|
|
address_out,
|
65 |
|
|
bc_out,
|
66 |
|
|
data_out,
|
67 |
|
|
data_in,
|
68 |
|
|
be_out,
|
69 |
|
|
req_out,
|
70 |
|
|
rdy_out,
|
71 |
|
|
last_out,
|
72 |
|
|
|
73 |
|
|
next_data_out,
|
74 |
|
|
next_be_out,
|
75 |
|
|
next_last_out,
|
76 |
|
|
|
77 |
|
|
// status inputs from master SM
|
78 |
|
|
wait_in,
|
79 |
|
|
wtransfer_in,
|
80 |
|
|
rtransfer_in,
|
81 |
|
|
retry_in,
|
82 |
|
|
werror_in,
|
83 |
|
|
rerror_in,
|
84 |
|
|
first_in ,
|
85 |
|
|
mabort_in,
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
// WISHBONE WRITE fifo inputs and outputs
|
89 |
|
|
wbw_renable_out,
|
90 |
|
|
wbw_fifo_addr_data_in,
|
91 |
|
|
wbw_fifo_cbe_in,
|
92 |
|
|
wbw_fifo_control_in,
|
93 |
|
|
wbw_fifo_empty_in,
|
94 |
|
|
wbw_fifo_transaction_ready_in,
|
95 |
|
|
|
96 |
|
|
// WISHBONE READ fifo inputs and outputs
|
97 |
|
|
wbr_fifo_wenable_out,
|
98 |
|
|
wbr_fifo_data_out,
|
99 |
|
|
wbr_fifo_be_out,
|
100 |
|
|
wbr_fifo_control_out,
|
101 |
|
|
|
102 |
|
|
// delayed transaction control logic inputs and outputs
|
103 |
|
|
del_wdata_in,
|
104 |
|
|
del_complete_out,
|
105 |
|
|
del_req_in,
|
106 |
|
|
del_addr_in,
|
107 |
|
|
del_bc_in,
|
108 |
|
|
del_be_in,
|
109 |
|
|
del_burst_in,
|
110 |
|
|
del_error_out,
|
111 |
|
|
del_rty_exp_out,
|
112 |
|
|
del_we_in,
|
113 |
|
|
|
114 |
|
|
// configuration space interconnect
|
115 |
|
|
// error reporting
|
116 |
|
|
err_addr_out,
|
117 |
|
|
err_bc_out,
|
118 |
|
|
err_signal_out,
|
119 |
|
|
err_source_out,
|
120 |
|
|
err_pending_in,
|
121 |
|
|
err_rty_exp_out,
|
122 |
|
|
|
123 |
|
|
cache_line_size_in,
|
124 |
|
|
|
125 |
|
|
// two signals for pci control and status
|
126 |
|
|
mabort_received_out,
|
127 |
|
|
tabort_received_out
|
128 |
|
|
);
|
129 |
|
|
|
130 |
|
|
// system inputs
|
131 |
|
|
input clk_in ;
|
132 |
|
|
input reset_in ;
|
133 |
|
|
|
134 |
|
|
// PCI master state machine interconnect
|
135 |
|
|
output [31:0] address_out ; // address output
|
136 |
|
|
|
137 |
|
|
output [3:0] bc_out ; // bus command output
|
138 |
|
|
reg [3:0] bc_out ;
|
139 |
|
|
|
140 |
|
|
output [31:0] data_out ; // data output for writes
|
141 |
|
|
reg [31:0] data_out ;
|
142 |
|
|
|
143 |
|
|
input [31:0] data_in ; // data input for reads
|
144 |
|
|
output [3:0] be_out ; // byte enable output
|
145 |
|
|
reg [3:0] be_out ;
|
146 |
|
|
|
147 |
|
|
output req_out ; // request output
|
148 |
|
|
|
149 |
|
|
output rdy_out ; // ready output
|
150 |
|
|
reg rdy_out ;
|
151 |
|
|
|
152 |
|
|
output last_out ; // last data indicator output
|
153 |
|
|
|
154 |
|
|
output [31:0] next_data_out ; // next data output
|
155 |
|
|
output [3:0] next_be_out ; // next byte enable output
|
156 |
|
|
output next_last_out ; // next transfer last indicator
|
157 |
|
|
|
158 |
|
|
input wait_in,
|
159 |
|
|
wtransfer_in,
|
160 |
|
|
rtransfer_in,
|
161 |
|
|
retry_in,
|
162 |
|
|
werror_in,
|
163 |
|
|
rerror_in,
|
164 |
|
|
first_in ,
|
165 |
|
|
mabort_in ;
|
166 |
|
|
|
167 |
|
|
// WISHBONE write fifo interconnect
|
168 |
|
|
output wbw_renable_out ; // WBW_FIFO read enable signal
|
169 |
|
|
|
170 |
|
|
input [31:0] wbw_fifo_addr_data_in ; // WBW_FIFO address/data bus
|
171 |
|
|
input [3:0] wbw_fifo_cbe_in ; // WBW_FIFO command/byte enable bus
|
172 |
|
|
input [3:0] wbw_fifo_control_in ; // WBW_FIFO control bus
|
173 |
|
|
input wbw_fifo_empty_in ; // WBW_FIFO's empty status indicator
|
174 |
|
|
input wbw_fifo_transaction_ready_in ; // WBW_FIFO transaction ready indicator
|
175 |
|
|
|
176 |
|
|
// WISHBONE read FIFO interconnect
|
177 |
|
|
output wbr_fifo_wenable_out ; // write enable for WBR_FIFO
|
178 |
|
|
|
179 |
|
|
output [31:0] wbr_fifo_data_out ; // data output to WBR_FIFO
|
180 |
|
|
|
181 |
|
|
output [3:0] wbr_fifo_be_out ; // byte enable output for WBR_FIFO
|
182 |
|
|
|
183 |
|
|
output [3:0] wbr_fifo_control_out ; // WBR_FIFO control output
|
184 |
|
|
|
185 |
|
|
// delayed transaction control logic inputs and outputs
|
186 |
|
|
input [31:0] del_wdata_in ; // delayed write data input
|
187 |
|
|
output del_complete_out ; // delayed transaction completed output
|
188 |
|
|
|
189 |
|
|
input del_req_in ; // delayed transaction request
|
190 |
|
|
input [31:0] del_addr_in ; // delayed transaction address
|
191 |
|
|
input [3:0] del_bc_in ; // delayed transaction bus command input
|
192 |
|
|
input [3:0] del_be_in ; // delayed transaction byte enables input
|
193 |
|
|
input del_burst_in ; // delayed transaction burst req. indicator
|
194 |
|
|
output del_error_out ; // delayed transation error termination signal
|
195 |
|
|
|
196 |
|
|
output del_rty_exp_out ; // retry expired output for delayed transactions
|
197 |
|
|
|
198 |
|
|
input del_we_in ; // delayed write request indicator
|
199 |
|
|
|
200 |
|
|
output [31:0] err_addr_out ; // erroneous address output
|
201 |
|
|
output [3:0] err_bc_out ; // erroneous bus command output
|
202 |
|
|
|
203 |
|
|
output err_signal_out ; // error signalization
|
204 |
|
|
|
205 |
|
|
output err_source_out ; // error source indicator
|
206 |
|
|
|
207 |
|
|
input err_pending_in ;
|
208 |
|
|
|
209 |
|
|
input [7:0] cache_line_size_in ; // cache line size value input
|
210 |
|
|
|
211 |
|
|
output err_rty_exp_out ; // retry expired error output
|
212 |
|
|
|
213 |
|
|
output mabort_received_out ; // master abort signaled to status register
|
214 |
|
|
output tabort_received_out ; // target abort signaled to status register
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
assign err_bc_out = bc_out ;
|
218 |
|
|
|
219 |
|
|
// assign read outputs
|
220 |
|
|
/*==================================================================================================================
|
221 |
|
|
WISHBONE read FIFO data outputs - just link them to SM data outputs and delayed BE input
|
222 |
|
|
==================================================================================================================*/
|
223 |
|
|
assign wbr_fifo_data_out = data_in ;
|
224 |
|
|
assign wbr_fifo_be_out = del_be_in ;
|
225 |
|
|
|
226 |
|
|
// decode if current bus command is configuration command
|
227 |
|
|
wire conf_cyc_bc = ( bc_out[3:1] == `BC_CONF_RW ) ;
|
228 |
|
|
|
229 |
|
|
// register for indicating that current data is also last in transfer
|
230 |
|
|
reg current_last ;
|
231 |
|
|
|
232 |
|
|
// register indicating that last data was transfered OK
|
233 |
|
|
reg last_transfered ;
|
234 |
|
|
always@(posedge reset_in or posedge clk_in)
|
235 |
|
|
begin
|
236 |
|
|
if (reset_in)
|
237 |
|
|
last_transfered <= #`FF_DELAY 1'b0 ;
|
238 |
|
|
else
|
239 |
|
|
last_transfered <= #`FF_DELAY ~wait_in && last_out && wtransfer_in ;
|
240 |
|
|
end
|
241 |
|
|
|
242 |
|
|
// status signals output assignement
|
243 |
|
|
assign mabort_received_out = mabort_in ;
|
244 |
|
|
|
245 |
|
|
wire tabort_ff_in = ~wait_in && rerror_in ;
|
246 |
|
|
|
247 |
|
|
reg tabort_received_out ;
|
248 |
|
|
always@(posedge reset_in or posedge clk_in)
|
249 |
|
|
begin
|
250 |
|
|
if ( reset_in )
|
251 |
|
|
tabort_received_out <= #`FF_DELAY 1'b0 ;
|
252 |
|
|
else
|
253 |
|
|
tabort_received_out <= #`FF_DELAY tabort_ff_in ;
|
254 |
|
|
end
|
255 |
|
|
|
256 |
|
|
// error recovery indicator
|
257 |
|
|
reg err_recovery ;
|
258 |
|
|
|
259 |
|
|
// operation is locked until error recovery is in progress or error bit is not cleared in configuration space
|
260 |
|
|
wire err_lock = err_recovery || err_pending_in ;
|
261 |
|
|
|
262 |
|
|
// three requests are possible - posted write, delayed write and delayed read
|
263 |
|
|
reg del_write_req ;
|
264 |
|
|
reg posted_write_req ;
|
265 |
|
|
reg del_read_req ;
|
266 |
|
|
|
267 |
|
|
// assign request output
|
268 |
|
|
assign req_out = del_write_req || posted_write_req || del_read_req ;
|
269 |
|
|
|
270 |
|
|
// write requests are staged, so data is read from source into current data register and next data register
|
271 |
|
|
reg write_req_int ;
|
272 |
|
|
always@(posedge reset_in or posedge clk_in)
|
273 |
|
|
begin
|
274 |
|
|
if ( reset_in )
|
275 |
|
|
write_req_int <= #`FF_DELAY 1'b0 ;
|
276 |
|
|
else
|
277 |
|
|
write_req_int <= #`FF_DELAY posted_write_req || del_write_req ;
|
278 |
|
|
|
279 |
|
|
end
|
280 |
|
|
|
281 |
|
|
// ready output is generated one clock after request for reads and two after for writes
|
282 |
|
|
always@(posedge reset_in or posedge clk_in)
|
283 |
|
|
begin
|
284 |
|
|
if (reset_in)
|
285 |
|
|
rdy_out <= #`FF_DELAY 1'b0 ;
|
286 |
|
|
else
|
287 |
|
|
rdy_out <= #`FF_DELAY del_read_req || ( (posted_write_req || del_write_req) && write_req_int) ;
|
288 |
|
|
end
|
289 |
|
|
|
290 |
|
|
// wires with logic used as inputs to request FFs
|
291 |
|
|
wire do_posted_write = ( wbw_fifo_transaction_ready_in && ~wbw_fifo_empty_in && ~err_lock ) ;
|
292 |
|
|
wire do_del = ( del_req_in && ~err_lock && wbw_fifo_empty_in ) ;
|
293 |
|
|
wire do_del_write = do_del && del_we_in ;
|
294 |
|
|
wire do_del_read = do_del && ~del_we_in ;
|
295 |
|
|
|
296 |
|
|
// register for indicating current operation's data source
|
297 |
|
|
parameter DELAYED_WRITE = 1'b1 ;
|
298 |
|
|
parameter POSTED_WRITE = 1'b0 ;
|
299 |
|
|
|
300 |
|
|
// new data source - depending on which transaction will be processed next - delayed read is here because source of byte enables must
|
301 |
|
|
// be specified for delayed reads also - data source is not relevant for delayed reads, so value is don't care anyway
|
302 |
|
|
wire new_data_source = (do_del_write || do_del_read) ? DELAYED_WRITE : POSTED_WRITE ; // input to data source register
|
303 |
|
|
wire data_source_change = ~req_out ; // change (enable) for data source register - when no requests are in progress
|
304 |
|
|
|
305 |
|
|
reg data_source ; // data source value
|
306 |
|
|
always@(posedge reset_in or posedge clk_in)
|
307 |
|
|
begin
|
308 |
|
|
if (reset_in)
|
309 |
|
|
// default value is posted write source - wbw_fifo
|
310 |
|
|
data_source <= #`FF_DELAY POSTED_WRITE ;
|
311 |
|
|
else
|
312 |
|
|
if (data_source_change)
|
313 |
|
|
// change data source on rising clock edge
|
314 |
|
|
data_source <= #`FF_DELAY new_data_source ;
|
315 |
|
|
end
|
316 |
|
|
|
317 |
|
|
// multiplexer for data output to PCI MASTER state machine
|
318 |
|
|
reg [31:0] source_data ;
|
319 |
|
|
reg [3:0] source_be ;
|
320 |
|
|
always@(data_source or wbw_fifo_addr_data_in or wbw_fifo_cbe_in or del_wdata_in or del_be_in)
|
321 |
|
|
begin
|
322 |
|
|
case (data_source)
|
323 |
|
|
POSTED_WRITE: begin
|
324 |
|
|
source_data = wbw_fifo_addr_data_in ;
|
325 |
|
|
source_be = wbw_fifo_cbe_in ;
|
326 |
|
|
end
|
327 |
|
|
DELAYED_WRITE: begin
|
328 |
|
|
source_data = del_wdata_in ;
|
329 |
|
|
source_be = ~del_be_in ;
|
330 |
|
|
end
|
331 |
|
|
endcase
|
332 |
|
|
end
|
333 |
|
|
|
334 |
|
|
wire waddr = wbw_fifo_control_in[`ADDR_CTRL_BIT] ;
|
335 |
|
|
|
336 |
|
|
// address change indicator - address is allowed to be loaded only when no transaction is in progress!
|
337 |
|
|
wire address_change = ~req_out ; // address change - whenever there is no request in progress
|
338 |
|
|
|
339 |
|
|
// new address - input to register storing address of current request - if posted write request will be next,
|
340 |
|
|
// load address and bus command from wbw_fifo, else load data from delayed transaction logic
|
341 |
|
|
wire [31:0] new_address = ( ~req_out && do_posted_write ) ? wbw_fifo_addr_data_in[31:0] : del_addr_in[31:0] ;
|
342 |
|
|
wire [3:0] new_bc = ( ~req_out && do_posted_write ) ? wbw_fifo_cbe_in : del_bc_in ;
|
343 |
|
|
|
344 |
|
|
// address counter enable - only for posted writes when data is actually transfered
|
345 |
|
|
wire addr_count_en = ~wait_in && posted_write_req && wtransfer_in ;
|
346 |
|
|
|
347 |
|
|
always@(posedge reset_in or posedge clk_in)
|
348 |
|
|
begin
|
349 |
|
|
if (reset_in)
|
350 |
|
|
bc_out <= #`FF_DELAY `BC_RESERVED0 ;
|
351 |
|
|
else
|
352 |
|
|
if (address_change)
|
353 |
|
|
bc_out <= #`FF_DELAY new_bc ;
|
354 |
|
|
end
|
355 |
|
|
|
356 |
|
|
reg [31:2] current_dword_address ;
|
357 |
|
|
|
358 |
|
|
// DWORD address counter with load
|
359 |
|
|
always@(posedge reset_in or posedge clk_in)
|
360 |
|
|
begin
|
361 |
|
|
if (reset_in)
|
362 |
|
|
current_dword_address <= #`FF_DELAY 30'h0000_0000 ;
|
363 |
|
|
else
|
364 |
|
|
if (address_change)
|
365 |
|
|
current_dword_address <= #`FF_DELAY new_address[31:2] ;
|
366 |
|
|
else
|
367 |
|
|
if (addr_count_en)
|
368 |
|
|
current_dword_address <= #`FF_DELAY current_dword_address + 1'b1 ;
|
369 |
|
|
end
|
370 |
|
|
|
371 |
|
|
reg [1:0] current_byte_address ;
|
372 |
|
|
always@(posedge reset_in or posedge clk_in)
|
373 |
|
|
begin
|
374 |
|
|
if (reset_in)
|
375 |
|
|
current_byte_address <= #`FF_DELAY 2'b00 ;
|
376 |
|
|
else
|
377 |
|
|
if (address_change)
|
378 |
|
|
current_byte_address <= #`FF_DELAY new_address[1:0] ;
|
379 |
|
|
end
|
380 |
|
|
|
381 |
|
|
// address output to PCI master state machine assignement
|
382 |
|
|
assign address_out = { current_dword_address, current_byte_address } ;
|
383 |
|
|
|
384 |
|
|
// the same for erroneous address assignement
|
385 |
|
|
assign err_addr_out = { current_dword_address, current_byte_address } ;
|
386 |
|
|
|
387 |
|
|
// cacheline size counter - for read transaction length control
|
388 |
|
|
// cache line count is enabled during burst reads when data is actually transfered
|
389 |
|
|
wire read_count_enable = ~wait_in && del_read_req && del_burst_in && wtransfer_in ;
|
390 |
|
|
|
391 |
|
|
// cache line counter is loaded when del read request is not in progress
|
392 |
|
|
wire read_count_load = ~del_read_req ;
|
393 |
|
|
|
394 |
|
|
reg [8:0] max_read_count ;
|
395 |
|
|
always@(cache_line_size_in or del_bc_in)
|
396 |
|
|
begin
|
397 |
|
|
if ( (cache_line_size_in >= `WBR_DEPTH) || (~del_bc_in[1] && ~del_bc_in[0]) )
|
398 |
|
|
max_read_count = `WBR_DEPTH - 1'b1;
|
399 |
|
|
else
|
400 |
|
|
max_read_count = cache_line_size_in ;
|
401 |
|
|
end
|
402 |
|
|
|
403 |
|
|
reg [8:0] read_count ;
|
404 |
|
|
|
405 |
|
|
// cache line bound indicator - it signals when data for one complete cacheline was read
|
406 |
|
|
wire read_bound_comb = ~|(read_count[8:2]) ;
|
407 |
|
|
reg read_bound ;
|
408 |
|
|
always@(posedge clk_in)
|
409 |
|
|
begin
|
410 |
|
|
if (read_count_load)
|
411 |
|
|
read_bound <= #`FF_DELAY 1'b0 ;
|
412 |
|
|
else if ( read_count_enable )
|
413 |
|
|
read_bound <= #`FF_DELAY read_bound_comb ;
|
414 |
|
|
end
|
415 |
|
|
|
416 |
|
|
// down counter with load
|
417 |
|
|
always@(posedge reset_in or posedge clk_in)
|
418 |
|
|
begin
|
419 |
|
|
if (reset_in)
|
420 |
|
|
read_count <= #`FF_DELAY 8'h00 ;
|
421 |
|
|
else
|
422 |
|
|
if (read_count_load)
|
423 |
|
|
read_count <= #`FF_DELAY max_read_count ;
|
424 |
|
|
else
|
425 |
|
|
if (read_count_enable)
|
426 |
|
|
read_count <= #`FF_DELAY read_count - 1'b1 ;
|
427 |
|
|
|
428 |
|
|
end
|
429 |
|
|
|
430 |
|
|
// flip flop indicating error recovery is in progress
|
431 |
|
|
reg err_recovery_in ;
|
432 |
|
|
always@(posedge reset_in or posedge clk_in)
|
433 |
|
|
begin
|
434 |
|
|
if (reset_in)
|
435 |
|
|
err_recovery <= #`FF_DELAY 1'b0 ;
|
436 |
|
|
else
|
437 |
|
|
err_recovery <= #`FF_DELAY err_recovery_in ;
|
438 |
|
|
end
|
439 |
|
|
|
440 |
|
|
/*// retry counter implementation
|
441 |
|
|
reg [7:0] retry_count ;
|
442 |
|
|
|
443 |
|
|
wire retry_expired = ~|(retry_count[7:1]) ;
|
444 |
|
|
|
445 |
|
|
// loading of retry counter - whenever no request is present or other termination than retry or wait is signalled
|
446 |
|
|
wire retry_load = ~req_out || (~wait_in && rtransfer_in) ;
|
447 |
|
|
|
448 |
|
|
// retry DOWN counter with load
|
449 |
|
|
always@(posedge reset_in or posedge clk_in)
|
450 |
|
|
begin
|
451 |
|
|
if (reset_in)
|
452 |
|
|
retry_count <= #`FF_DELAY 8'hFF ;
|
453 |
|
|
else
|
454 |
|
|
if ( retry_load )
|
455 |
|
|
retry_count <= #`FF_DELAY `PCI_RTY_CNT_MAX ;
|
456 |
|
|
else
|
457 |
|
|
if (retry_in)
|
458 |
|
|
retry_count <= #`FF_DELAY retry_count - 1'b1 ;
|
459 |
|
|
end*/
|
460 |
|
|
|
461 |
|
|
/*==================================================================================================================
|
462 |
|
|
Delayed write requests are always single transfers!
|
463 |
|
|
Delayed write request starts, when no request is currently beeing processed and it is signaled from other side
|
464 |
|
|
of the bridge.
|
465 |
|
|
==================================================================================================================*/
|
466 |
|
|
// delayed write request FF input control
|
467 |
|
|
reg del_write_req_input ;
|
468 |
|
|
|
469 |
|
|
always@(
|
470 |
|
|
do_del_write or
|
471 |
|
|
del_write_req or
|
472 |
|
|
posted_write_req or
|
473 |
|
|
del_read_req or
|
474 |
|
|
wait_in or
|
475 |
|
|
//retry_in or
|
476 |
|
|
//retry_expired or
|
477 |
|
|
rtransfer_in or
|
478 |
|
|
rerror_in or
|
479 |
|
|
mabort_in
|
480 |
|
|
)
|
481 |
|
|
begin
|
482 |
|
|
if (~del_write_req)
|
483 |
|
|
begin
|
484 |
|
|
// delayed write is not in progress and is requested
|
485 |
|
|
// delayed write can be requested when no other request is in progress
|
486 |
|
|
del_write_req_input = ~posted_write_req && ~del_read_req && do_del_write ;
|
487 |
|
|
end
|
488 |
|
|
else
|
489 |
|
|
begin
|
490 |
|
|
// delayed write request is in progress - assign input
|
491 |
|
|
del_write_req_input = wait_in ||
|
492 |
|
|
( /*~( retry_in && retry_expired) &&*/
|
493 |
|
|
~rtransfer_in && ~rerror_in && ~mabort_in
|
494 |
|
|
);
|
495 |
|
|
end
|
496 |
|
|
end
|
497 |
|
|
|
498 |
|
|
// delayed write request FLIP-FLOP
|
499 |
|
|
always@(posedge reset_in or posedge clk_in)
|
500 |
|
|
begin
|
501 |
|
|
if (reset_in)
|
502 |
|
|
del_write_req <= #`FF_DELAY 1'b0 ;
|
503 |
|
|
else
|
504 |
|
|
del_write_req <= #`FF_DELAY del_write_req_input ;
|
505 |
|
|
end
|
506 |
|
|
|
507 |
|
|
/*================================================================================================
|
508 |
|
|
Posted write request indicator.
|
509 |
|
|
Posted write starts whenever no request is in progress and one whole posted write is
|
510 |
|
|
stored in WBW_FIFO. It ends on error terminations ( master, target abort, retry expired) or
|
511 |
|
|
data transfer terminations if last data is on top of FIFO.
|
512 |
|
|
Continues on wait, retry, and disconnect without data.
|
513 |
|
|
================================================================================================*/
|
514 |
|
|
// posted write request FF input control
|
515 |
|
|
reg posted_write_req_input ;
|
516 |
|
|
always@(
|
517 |
|
|
do_posted_write or
|
518 |
|
|
del_write_req or
|
519 |
|
|
posted_write_req or
|
520 |
|
|
del_read_req or
|
521 |
|
|
wait_in or
|
522 |
|
|
//retry_in or
|
523 |
|
|
rerror_in or
|
524 |
|
|
mabort_in or
|
525 |
|
|
//retry_expired or
|
526 |
|
|
rtransfer_in or
|
527 |
|
|
last_transfered
|
528 |
|
|
)
|
529 |
|
|
begin
|
530 |
|
|
if (~posted_write_req)
|
531 |
|
|
begin
|
532 |
|
|
// posted write is not in progress
|
533 |
|
|
posted_write_req_input = ~del_write_req && ~del_read_req && do_posted_write ;
|
534 |
|
|
end
|
535 |
|
|
else
|
536 |
|
|
begin
|
537 |
|
|
posted_write_req_input = wait_in ||
|
538 |
|
|
(/*~(retry_in && retry_expired && ~rtransfer_in) &&*/
|
539 |
|
|
~rerror_in && ~mabort_in &&
|
540 |
|
|
~(last_transfered)
|
541 |
|
|
) ;
|
542 |
|
|
|
543 |
|
|
end
|
544 |
|
|
end
|
545 |
|
|
|
546 |
|
|
// posted write request flip flop
|
547 |
|
|
always@(posedge reset_in or posedge clk_in)
|
548 |
|
|
begin
|
549 |
|
|
if (reset_in)
|
550 |
|
|
posted_write_req <= #`FF_DELAY 1'b0 ;
|
551 |
|
|
else
|
552 |
|
|
posted_write_req <= #`FF_DELAY posted_write_req_input ;
|
553 |
|
|
|
554 |
|
|
end
|
555 |
|
|
|
556 |
|
|
/*================================================================================================
|
557 |
|
|
Delayed read request indicator.
|
558 |
|
|
Delayed read starts whenever no request is in progress and delayed read request is signaled from
|
559 |
|
|
other side of bridge. It ends on error terminations ( master, target abort, retry expired) or
|
560 |
|
|
data transfer terminations if it is not burst transfer or on cache line bounds on burst transfer.
|
561 |
|
|
It also ends on disconnects.
|
562 |
|
|
Continues on wait and retry.
|
563 |
|
|
================================================================================================*/
|
564 |
|
|
// delayed read FF input control
|
565 |
|
|
reg del_read_req_input ;
|
566 |
|
|
always@(
|
567 |
|
|
do_del_read or
|
568 |
|
|
del_write_req or
|
569 |
|
|
posted_write_req or
|
570 |
|
|
del_read_req or
|
571 |
|
|
last_transfered or
|
572 |
|
|
wait_in or
|
573 |
|
|
retry_in or
|
574 |
|
|
//retry_expired or
|
575 |
|
|
mabort_in or
|
576 |
|
|
rtransfer_in or
|
577 |
|
|
rerror_in or
|
578 |
|
|
first_in or
|
579 |
|
|
del_complete_out
|
580 |
|
|
)
|
581 |
|
|
begin
|
582 |
|
|
if (~del_read_req)
|
583 |
|
|
begin
|
584 |
|
|
del_read_req_input = ~del_write_req && ~posted_write_req && ~del_complete_out && do_del_read ;
|
585 |
|
|
end
|
586 |
|
|
else
|
587 |
|
|
begin
|
588 |
|
|
del_read_req_input = wait_in ||
|
589 |
|
|
( ~(retry_in && (~first_in /*|| retry_expired */)) &&
|
590 |
|
|
~mabort_in && ~rerror_in &&
|
591 |
|
|
~(last_transfered)
|
592 |
|
|
) ;
|
593 |
|
|
end
|
594 |
|
|
end
|
595 |
|
|
|
596 |
|
|
// delayed read request FF
|
597 |
|
|
always@(posedge reset_in or posedge clk_in)
|
598 |
|
|
begin
|
599 |
|
|
if (reset_in)
|
600 |
|
|
del_read_req <= #`FF_DELAY 1'b0 ;
|
601 |
|
|
else
|
602 |
|
|
del_read_req <= #`FF_DELAY del_read_req_input ;
|
603 |
|
|
end
|
604 |
|
|
|
605 |
|
|
// wire indicating last entry of transaction on top of fifo
|
606 |
|
|
wire wlast = wbw_fifo_control_in[`LAST_CTRL_BIT] ;
|
607 |
|
|
|
608 |
|
|
wire last_int = posted_write_req && wlast || del_write_req ;
|
609 |
|
|
|
610 |
|
|
// intermidiate data, byte enable and last registers
|
611 |
|
|
reg [31:0] intermediate_data ;
|
612 |
|
|
reg [3:0] intermediate_be ;
|
613 |
|
|
reg intermediate_last ;
|
614 |
|
|
|
615 |
|
|
wire intermediate_enable = ( posted_write_req || del_write_req ) && ( ~write_req_int || (( ~rdy_out || ~wait_in && rtransfer_in ) && ~intermediate_last)) ;
|
616 |
|
|
|
617 |
|
|
always@(posedge reset_in or posedge clk_in)
|
618 |
|
|
begin
|
619 |
|
|
if ( reset_in )
|
620 |
|
|
begin
|
621 |
|
|
intermediate_data <= #`FF_DELAY 32'h0000_0000 ;
|
622 |
|
|
intermediate_be <= #`FF_DELAY 4'h0 ;
|
623 |
|
|
intermediate_last <= #`FF_DELAY 1'b0 ;
|
624 |
|
|
end
|
625 |
|
|
else
|
626 |
|
|
if ( intermediate_enable )
|
627 |
|
|
begin
|
628 |
|
|
intermediate_data <= #`FF_DELAY source_data ;
|
629 |
|
|
intermediate_be <= #`FF_DELAY source_be ;
|
630 |
|
|
intermediate_last <= #`FF_DELAY last_int ;
|
631 |
|
|
end
|
632 |
|
|
end
|
633 |
|
|
|
634 |
|
|
// multiplexer for next data
|
635 |
|
|
reg [31:0] next_data_out ;
|
636 |
|
|
reg [3:0] next_be_out ;
|
637 |
|
|
reg write_next_last ;
|
638 |
|
|
reg [3:0] write_next_be ;
|
639 |
|
|
|
640 |
|
|
always@(rtransfer_in or intermediate_data or intermediate_be or intermediate_last or wbw_fifo_addr_data_in or wbw_fifo_cbe_in or wlast)
|
641 |
|
|
begin
|
642 |
|
|
if( rtransfer_in )
|
643 |
|
|
begin
|
644 |
|
|
next_data_out = wbw_fifo_addr_data_in ;
|
645 |
|
|
write_next_last = wlast ;
|
646 |
|
|
write_next_be = wbw_fifo_cbe_in ;
|
647 |
|
|
end
|
648 |
|
|
else
|
649 |
|
|
begin
|
650 |
|
|
next_data_out = intermediate_data ;
|
651 |
|
|
write_next_last = intermediate_last ;
|
652 |
|
|
write_next_be = intermediate_be ;
|
653 |
|
|
end
|
654 |
|
|
end
|
655 |
|
|
|
656 |
|
|
always@(del_read_req or source_be or write_next_be)
|
657 |
|
|
begin
|
658 |
|
|
if (del_read_req)
|
659 |
|
|
next_be_out = source_be ;
|
660 |
|
|
else
|
661 |
|
|
next_be_out = write_next_be ;
|
662 |
|
|
end
|
663 |
|
|
/*================================================================================================
|
664 |
|
|
WBW_FIFO read enable - read from WBW_FIFO is performed on posted writes, when data transfer
|
665 |
|
|
termination is received - transfer or disconnect with data. Reads are enabled during error
|
666 |
|
|
recovery also, since erroneous transaction must be pulled out of FIFO!
|
667 |
|
|
================================================================================================*/
|
668 |
|
|
// wbw_fifo read enable input control
|
669 |
|
|
|
670 |
|
|
assign wbw_renable_out = ~req_out && (do_posted_write || err_recovery) ||
|
671 |
|
|
posted_write_req && ( ~write_req_int || (~rdy_out && ~intermediate_last) || (~wait_in && rtransfer_in && ~intermediate_last)) ;
|
672 |
|
|
|
673 |
|
|
/*================================================================================================
|
674 |
|
|
WBR_FIFO write enable control -
|
675 |
|
|
writes to FIFO are possible only when delayed read request is in progress and data transfer
|
676 |
|
|
or error termination is signalled. It is not enabled on retry or disconnect without data.
|
677 |
|
|
================================================================================================*/
|
678 |
|
|
// wbr_fifo write enable control - enabled when transfer is in progress and data is transfered or error is signalled
|
679 |
|
|
assign wbr_fifo_wenable_out = del_read_req && ~wait_in && ( rtransfer_in || mabort_in || rerror_in ) ;
|
680 |
|
|
|
681 |
|
|
/*================================================================================================
|
682 |
|
|
WBR_FIFO control output for identifying data entries.
|
683 |
|
|
This is necesary because of prefetched reads, which partially succeed. On error, error entry
|
684 |
|
|
gets in to signal it on WISHBONE bus if WISHBONE master reads up to this entry.
|
685 |
|
|
================================================================================================*/
|
686 |
|
|
assign wbr_fifo_control_out[`ADDR_CTRL_BIT] = 1'b0 ;
|
687 |
|
|
assign wbr_fifo_control_out[`LAST_CTRL_BIT] = last_transfered ;
|
688 |
|
|
assign wbr_fifo_control_out[`DATA_ERROR_CTRL_BIT] = rerror_in || (mabort_in && ~conf_cyc_bc) ;
|
689 |
|
|
assign wbr_fifo_control_out[`UNUSED_CTRL_BIT] = 1'b0 ;
|
690 |
|
|
|
691 |
|
|
// retry expired error for posted writes control
|
692 |
|
|
//assign err_rty_exp_out = posted_write_req && ~wait_in && retry_in && retry_expired && ~rtransfer_in;
|
693 |
|
|
assign err_rty_exp_out = 1'b0 ;
|
694 |
|
|
|
695 |
|
|
// error source and error signal output control logic - only for posted writes
|
696 |
|
|
assign err_source_out = mabort_in /*|| err_rty_exp_out*/ ;
|
697 |
|
|
|
698 |
|
|
assign err_signal_out = /*err_rty_exp_out || */ posted_write_req && ~wait_in && (mabort_in || rerror_in) ;
|
699 |
|
|
|
700 |
|
|
//assign del_rty_exp_out = (~wait_in && (del_read_req || del_write_req)) && (retry_in && retry_expired && ~rtransfer_in) ;
|
701 |
|
|
assign del_rty_exp_out = 1'b0 ;
|
702 |
|
|
|
703 |
|
|
assign del_error_out = ~wait_in && (del_write_req || del_read_req) && ( (mabort_in && ~conf_cyc_bc) || rerror_in ) ;
|
704 |
|
|
|
705 |
|
|
wire del_write_complete = del_write_req && ( rtransfer_in || rerror_in || mabort_in ) ;
|
706 |
|
|
wire del_read_complete = del_read_req && ( rerror_in || mabort_in || ( last_transfered ) || ( retry_in && ~first_in ) ) ;
|
707 |
|
|
|
708 |
|
|
assign del_complete_out = ~wait_in && ( del_write_complete || del_read_complete ) ;
|
709 |
|
|
|
710 |
|
|
|
711 |
|
|
// next last output generation
|
712 |
|
|
assign next_last_out = del_write_req || del_read_req && ( ~del_burst_in || read_bound ) || posted_write_req && ( write_next_last ) ;
|
713 |
|
|
/*==================================================================================================================
|
714 |
|
|
Error recovery FF gets a value of one, when during posted write error occurs. It is cleared when all the data provided
|
715 |
|
|
for erroneous transaction is pulled out of WBW_FIFO
|
716 |
|
|
==================================================================================================================*/
|
717 |
|
|
|
718 |
|
|
// error recovery flip flop input - used when posted write is terminated with an error
|
719 |
|
|
always@(
|
720 |
|
|
err_recovery or
|
721 |
|
|
last_out or
|
722 |
|
|
wlast or
|
723 |
|
|
err_signal_out or
|
724 |
|
|
intermediate_last
|
725 |
|
|
)
|
726 |
|
|
begin
|
727 |
|
|
// when error recovery is not set - drive its input so it gets set
|
728 |
|
|
if ( ~err_recovery )
|
729 |
|
|
err_recovery_in = ~last_out && ~intermediate_last && err_signal_out ;
|
730 |
|
|
else
|
731 |
|
|
// when error recovery is set, wbw_fifo is enabled - clear err_recovery when last data entry of erroneous transaction is pulled out of fifo
|
732 |
|
|
err_recovery_in = ~wlast ;
|
733 |
|
|
end
|
734 |
|
|
|
735 |
|
|
wire data_load_slow = (req_out && ~rdy_out) && (del_read_req || write_req_int) ;
|
736 |
|
|
wire data_load_en = posted_write_req && ~last_out && ~wait_in ;
|
737 |
|
|
wire data_be_load = data_load_slow || (data_load_en && wtransfer_in) ;
|
738 |
|
|
|
739 |
|
|
wire last_load = req_out && ( ~rdy_out || ~wait_in && wtransfer_in ) ;
|
740 |
|
|
|
741 |
|
|
always@(posedge reset_in or posedge clk_in)
|
742 |
|
|
begin
|
743 |
|
|
if (reset_in)
|
744 |
|
|
begin
|
745 |
|
|
be_out <= #`FF_DELAY 4'hF ;
|
746 |
|
|
data_out <= #`FF_DELAY 32'h0000_0000 ;
|
747 |
|
|
end
|
748 |
|
|
else
|
749 |
|
|
if ( data_be_load )
|
750 |
|
|
begin
|
751 |
|
|
data_out <= #`FF_DELAY next_data_out ;
|
752 |
|
|
be_out <= #`FF_DELAY next_be_out ;
|
753 |
|
|
end
|
754 |
|
|
end
|
755 |
|
|
|
756 |
|
|
always@(posedge reset_in or posedge clk_in)
|
757 |
|
|
begin
|
758 |
|
|
if (reset_in)
|
759 |
|
|
current_last <= #`FF_DELAY 1'b0 ;
|
760 |
|
|
else
|
761 |
|
|
if ( last_load )
|
762 |
|
|
current_last <= #`FF_DELAY next_last_out ;
|
763 |
|
|
end
|
764 |
|
|
|
765 |
|
|
assign last_out = current_last ;
|
766 |
|
|
endmodule
|