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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_9/] [bench/] [verilog/] [system.v] - Blame information for rev 154

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 52 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "system.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
////      - Tadej Markovic (tadej@opencores.org)                  ////
11
////                                                              ////
12
//////////////////////////////////////////////////////////////////////
13
////                                                              ////
14
//// Copyright (C) 2000 Miha Dolenc, mihad@opencores.org          ////
15
////                                                              ////
16
//// This source file may be used and distributed without         ////
17
//// restriction provided that this copyright statement is not    ////
18
//// removed from the file and that any derivative work contains  ////
19
//// the original copyright notice and the associated disclaimer. ////
20
////                                                              ////
21
//// This source file is free software; you can redistribute it   ////
22
//// and/or modify it under the terms of the GNU Lesser General   ////
23
//// Public License as published by the Free Software Foundation; ////
24
//// either version 2.1 of the License, or (at your option) any   ////
25
//// later version.                                               ////
26
////                                                              ////
27
//// This source is distributed in the hope that it will be       ////
28
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
29
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
30
//// PURPOSE.  See the GNU Lesser General Public License for more ////
31
//// details.                                                     ////
32
////                                                              ////
33
//// You should have received a copy of the GNU Lesser General    ////
34
//// Public License along with this source; if not, download it   ////
35
//// from http://www.opencores.org/lgpl.shtml                     ////
36
////                                                              ////
37
//////////////////////////////////////////////////////////////////////
38
//
39
// CVS Revision History
40
//
41
// $Log: not supported by cvs2svn $
42 122 markom
// Revision 1.19  2003/08/21 21:00:38  tadejm
43
// Added support for WB B3. Some testcases were updated.
44
//
45 119 tadejm
// Revision 1.18  2003/08/03 18:04:44  mihad
46
// Added limited WISHBONE B3 support for WISHBONE Slave Unit.
47
// Doesn't support full speed bursts yet.
48
//
49 106 mihad
// Revision 1.17  2003/07/29 08:19:47  mihad
50
// Found and simulated the problem in the synchronization logic.
51
// Repaired the synchronization logic in the FIFOs.
52
//
53 104 mihad
// Revision 1.16  2003/06/12 02:30:39  mihad
54
// Update!
55
//
56 92 mihad
// Revision 1.15  2003/03/14 15:33:55  mihad
57
// Updated acording to RTL changes.
58
//
59 87 mihad
// Revision 1.14  2003/01/30 22:01:33  mihad
60
// Updated synchronization in top level fifo modules.
61
//
62 81 mihad
// Revision 1.13  2003/01/21 16:06:50  mihad
63
// Bug fixes, testcases added.
64
//
65 73 mihad
// Revision 1.12  2002/10/21 13:04:30  mihad
66
// Changed BIST signal names etc..
67
//
68 69 mihad
// Revision 1.11  2002/10/11 12:03:12  mihad
69
// The testcase I just added in previous revision repaired
70
//
71 64 mihad
// Revision 1.10  2002/10/11 10:08:57  mihad
72
// Added additional testcase and changed rst name in BIST to trst
73
//
74 63 mihad
// Revision 1.9  2002/10/08 17:17:02  mihad
75
// Added BIST signals for RAMs.
76
//
77 62 mihad
// Revision 1.8  2002/09/25 09:54:47  mihad
78
// Added completion expiration test for WB Slave unit. Changed expiration signalling
79
//
80 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
81
// Oops, never before noticed that OC header is missing
82 52 mihad
//
83 57 mihad
//
84 52 mihad
 
85 15 mihad
`include "pci_constants.v"
86
`include "bus_commands.v"
87
`include "pci_testbench_defines.v"
88
`include "timescale.v"
89
 
90 51 mihad
`ifdef HOST
91
    `ifdef NO_CNF_IMAGE
92
    `else
93
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
94
    `endif
95
`else
96
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
97
`endif
98
 
99 104 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
100
    `define DO_CORNER_CASE_TESTS
101
`endif
102
 
103
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
104
    `define DO_CORNER_CASE_TESTS
105
`endif
106
 
107 15 mihad
module SYSTEM ;
108
 
109
`include "pci_blue_constants.vh"
110
`include "pci_blue_options.vh"
111
 
112
integer tests_successfull ;
113
integer tests_failed ;
114
integer tb_log_file ;
115
reg [799:0] test_name ;
116
 
117
reg pci_clock ;
118
reg wb_clock ;
119
reg reset ;
120
 
121
wire [4:0] arb_grant_out ;
122
 
123
wire [31:0] AD ;
124
wire [3:0]  CBE ;
125 92 mihad
wire INTA ;
126 15 mihad
pullup(INTA) ;
127 92 mihad
wire MAS0_REQ ;
128
wire MAS1_REQ ;
129
wire MAS2_REQ ;
130
wire MAS3_REQ ;
131 15 mihad
pullup(MAS0_REQ) ;
132
pullup(MAS1_REQ) ;
133
pullup(MAS2_REQ) ;
134
pullup(MAS3_REQ) ;
135
 
136
wire MAS0_GNT = ~arb_grant_out[0];
137
wire MAS1_GNT = ~arb_grant_out[1] ;
138
wire MAS2_GNT = ~arb_grant_out[2] ;
139
wire MAS3_GNT = ~arb_grant_out[3] ;
140
 
141 92 mihad
wire FRAME ;
142
wire IRDY ;
143 15 mihad
pullup(FRAME) ;
144
pullup(IRDY) ;
145 45 mihad
 
146
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
147
 
148 92 mihad
wire DEVSEL, TRDY, STOP, PERR, SERR, LOCK ;
149 15 mihad
pullup(DEVSEL) ;
150
pullup(TRDY) ;
151
pullup(STOP) ;
152
wire   PAR ;
153
pullup(PERR) ;
154
pullup(SERR) ;
155
wire [3:0] MAS1_IDSEL ;
156
 
157
pullup lockpu ( LOCK ) ;
158
 
159
wire        RST_O ;
160
wire        INT_O ;
161
reg         INT_I ;
162
wire [31:0] ADR_I ;
163
wire [31:0] SDAT_I ;
164
wire [31:0] SDAT_O ;
165
wire [3:0]  SEL_I ;
166
wire        CYC_I ;
167
wire        STB_I ;
168
wire        WE_I ;
169
wire        CAB_I ;
170 106 mihad
wire [2:0]  CTI_I ;
171
wire [1:0]  BTE_I ;
172 15 mihad
wire        ACK_O ;
173
wire        RTY_O ;
174
wire        ERR_O ;
175
 
176
wire [31:0] ADR_O ;
177
wire [31:0] MDAT_I ;
178
wire [31:0] MDAT_O ;
179
wire [3:0]  SEL_O ;
180
wire        CYC_O ;
181
wire        STB_O ;
182
wire        WE_O ;
183 119 tadejm
wire [2:0]  CTI_O ;
184
wire [1:0]  BTE_O ;
185
wire        CAB_O = 1'b0 ;
186 15 mihad
wire        ACK_I ;
187
wire        RTY_I ;
188
wire        ERR_I ;
189
 
190 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
191
 
192
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
193
 
194 15 mihad
wire        reset_wb ; // reset to Wb devices
195
 
196 62 mihad
`ifdef PCI_BIST
197 122 markom
wire mbist_so_o ;
198
reg  mbist_si_i ;
199
reg  mbist_rst ;
200
reg  mbist_en_i ;
201
reg  mbist_clk ;
202 62 mihad
`endif
203
 
204 92 mihad
wire RST ;
205 15 mihad
`ifdef GUEST
206 92 mihad
    assign  RST = ~reset ;
207 15 mihad
    assign  reset_wb = RST_O ;
208
`else
209
    pullup(RST) ;
210
    assign  reset_wb = reset ;
211
`endif
212
 
213
`define PCI_BRIDGE_INSTANCE bridge32_top
214
 
215 106 mihad
reg tc_gnt_allow ;
216
initial tc_gnt_allow = 1'b0 ;
217
 
218 15 mihad
TOP `PCI_BRIDGE_INSTANCE
219
(
220
    .CLK    ( pci_clock),
221
    .AD     ( AD ),
222
    .CBE    ( CBE ),
223
    .RST    ( RST ),
224
    .INTA   ( INTA ),
225
    .REQ    ( MAS0_REQ ),
226 106 mihad
    .GNT    ( MAS0_GNT | tc_gnt_allow),
227 15 mihad
    .FRAME  ( FRAME ),
228
    .IRDY   ( IRDY ),
229
    .IDSEL  ( TAR0_IDSEL),
230
    .DEVSEL ( DEVSEL ),
231
    .TRDY   ( TRDY ),
232
    .STOP   ( STOP ),
233
    .PAR    ( PAR ),
234
    .PERR   ( PERR ),
235
    .SERR   ( SERR ),
236
 
237
    .CLK_I  ( wb_clock ),
238
    .RST_I  ( reset ),
239
    .RST_O  ( RST_O ),
240
    .INT_I  ( INT_I ),
241
    .INT_O  ( INT_O ),
242
 
243
    // WISHBONE slave interface
244
    .ADR_I  ( ADR_I ),
245
    .SDAT_I ( SDAT_I ),
246
    .SDAT_O ( SDAT_O ),
247
    .SEL_I  ( SEL_I ),
248
    .CYC_I  ( CYC_I ),
249
    .STB_I  ( STB_I ),
250
    .WE_I   ( WE_I ),
251
    .CAB_I  ( CAB_I),
252 106 mihad
    .CTI_I  ( CTI_I),
253
    .BTE_I  ( BTE_I),
254 15 mihad
    .ACK_O  ( ACK_O ),
255
    .RTY_O  ( RTY_O ),
256
    .ERR_O  ( ERR_O ),
257
 
258
    // WISHBONE master interface
259
    .ADR_O  ( ADR_O ),
260
    .MDAT_I ( MDAT_I ),
261
    .MDAT_O ( MDAT_O ),
262
    .SEL_O  ( SEL_O ),
263
    .CYC_O  ( CYC_O ),
264
    .STB_O  ( STB_O ),
265
    .WE_O   ( WE_O ),
266 119 tadejm
    .CTI_O  ( CTI_O),
267
    .BTE_O  ( BTE_O),
268 15 mihad
    .ACK_I  ( ACK_I ),
269
    .RTY_I  ( RTY_I ),
270
    .ERR_I  ( ERR_I )
271 62 mihad
 
272
`ifdef PCI_BIST
273
    ,
274 69 mihad
    // bist chain signals
275 122 markom
    .mbist_si_i   (mbist_si_i),
276
    .mbist_so_o   (mbist_so_o),
277
    .mbist_ctrl_i   ({mbist_en_i, mbist_clk, mbist_rst})
278 62 mihad
`endif
279 15 mihad
) ;
280
 
281
WB_MASTER_BEHAVIORAL wishbone_master
282
(
283
    .CLK_I(wb_clock),
284
    .RST_I(reset_wb),
285 106 mihad
    .TAG_I(`WB_TAG_WIDTH'd0),
286
    .TAG_O({CTI_I, BTE_I}),
287 15 mihad
    .ACK_I(ACK_O),
288
    .ADR_O(ADR_I),
289
    .CYC_O(CYC_I),
290
    .DAT_I(SDAT_O),
291
    .DAT_O(SDAT_I),
292
    .ERR_I(ERR_O),
293
    .RTY_I(RTY_O),
294
    .SEL_O(SEL_I),
295
    .STB_O(STB_I),
296
    .WE_O (WE_I),
297
    .CAB_O(CAB_I)
298
);
299
 
300
WB_SLAVE_BEHAVIORAL wishbone_slave
301
(
302
    .CLK_I              (wb_clock),
303
    .RST_I              (reset_wb),
304
    .ACK_O              (ACK_I),
305
    .ADR_I              (ADR_O),
306
    .CYC_I              (CYC_O),
307
    .DAT_O              (MDAT_I),
308
    .DAT_I              (MDAT_O),
309
    .ERR_O              (ERR_I),
310
    .RTY_O              (RTY_I),
311
    .SEL_I              (SEL_O),
312
    .STB_I              (STB_O),
313
    .WE_I               (WE_O),
314 119 tadejm
    .CTI_I              (CTI_O),
315
    .BTE_I              (BTE_O)
316 15 mihad
);
317
 
318
integer wbu_mon_log_file_desc ;
319
integer pciu_mon_log_file_desc ;
320
WB_BUS_MON wbu_wb_mon(
321
                    .CLK_I(wb_clock),
322
                    .RST_I(reset_wb),
323
                    .ACK_I(ACK_O),
324
                    .ADDR_O(ADR_I),
325
                    .CYC_O(CYC_I),
326
                    .DAT_I(SDAT_O),
327
                    .DAT_O(SDAT_I),
328
                    .ERR_I(ERR_O),
329
                    .RTY_I(RTY_O),
330
                    .SEL_O(SEL_I),
331
                    .STB_O(STB_I),
332
                    .WE_O (WE_I),
333
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
334 106 mihad
                    .TAG_O({CTI_I, BTE_I}),
335 15 mihad
                    .CAB_O(CAB_I),
336 119 tadejm
                    .check_CTI(1'b0),
337 15 mihad
                    .log_file_desc ( wbu_mon_log_file_desc )
338
                  ) ;
339
 
340
WB_BUS_MON pciu_wb_mon(
341
                    .CLK_I(wb_clock),
342
                    .RST_I(reset_wb),
343
                    .ACK_I(ACK_I),
344
                    .ADDR_O(ADR_O),
345
                    .CYC_O(CYC_O),
346
                    .DAT_I(MDAT_I),
347
                    .DAT_O(MDAT_O),
348
                    .ERR_I(ERR_I),
349
                    .RTY_I(RTY_I),
350
                    .SEL_O(SEL_O),
351
                    .STB_O(STB_O),
352
                    .WE_O (WE_O),
353
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
354 119 tadejm
                    .TAG_O({CTI_O, BTE_O}),
355
                    .CAB_O(1'b0),
356
                    .check_CTI(1'b1),
357 15 mihad
                    .log_file_desc( pciu_mon_log_file_desc )
358
                  ) ;
359
 
360
// some aditional signals are needed here because of the arbiter
361
reg [3:0] pci_ext_req_prev ;
362
always@(posedge pci_clock)
363
begin
364
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
365
end
366
reg pci_frame_prev ;
367
always@(posedge pci_clock)
368
begin
369
    pci_frame_prev <= FRAME ;
370
end
371
reg pci_irdy_prev ;
372
always@(posedge pci_clock)
373
begin
374
    pci_irdy_prev <= IRDY ;
375
end
376
 
377
pci_blue_arbiter pci_arbiter
378
(
379
  .pci_int_req_direct(1'b0),
380
  .pci_ext_req_prev(pci_ext_req_prev),
381
  .pci_int_gnt_direct_out(arb_grant_out[4]),
382
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
383
  .pci_frame_prev(~pci_frame_prev),
384
  .pci_irdy_prev(~pci_irdy_prev),
385
  .pci_irdy_now(~IRDY),
386
  .arbitration_enable(1'b1),
387
  .pci_clk(pci_clock),
388
  .pci_reset_comb(~RST)
389
);
390
 
391
reg [31:0] target_message ;
392
 
393
// define output enable signals for monitor inputs
394
// real output enable signals
395
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
396
`ifdef ACTIVE_LOW_OE
397
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
398
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
399
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
400
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
401
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
402
                        !devsel_t_s_oe,
403
                        !ad_oe,
404
                        !cbe_oe,
405
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
406
                        ;
407
`else
408
`ifdef ACTIVE_HIGH_OE
409
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
410
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
411
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
412
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
413
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
414
                        devsel_t_s_oe,
415
                        ad_oe,
416
                        cbe_oe,
417
                        `PCI_BRIDGE_INSTANCE.PERR_en}
418
                        ;
419
`endif
420
`endif
421
/*wire [5:0] oe_sigs_0 = {1'b0,
422
                        1'b0,
423
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
424
                        pci_target32.ad_enable,
425
                        1'b0,
426
                        pci_target32.err_enable | pci_target32.r_err_enable
427
                       } ;
428
*/
429
 
430
wire [5:0] oe_sigs_2 ;
431
wire [5:0] oe_sigs_1 ;
432
 
433
// signals which are used by test modules to know what to do
434
triand  test_accepted_l_int, error_event_int;
435
pullup  (test_accepted_l_int), (error_event_int);
436
 
437
wire    pci_reset_comb  = ~RST;
438
wire    pci_ext_clk     = pci_clock;
439
 
440
integer pci_mon_log_file_desc ;
441
pci_bus_monitor monitor32
442
(
443
    .pci_ext_ad                 (AD),
444
    .pci_ext_cbe_l              (CBE),
445
    .pci_ext_par                (PAR),
446
    .pci_ext_frame_l            (FRAME),
447
    .pci_ext_irdy_l             (IRDY),
448
    .pci_ext_devsel_l           (DEVSEL),
449
    .pci_ext_trdy_l             (TRDY),
450
    .pci_ext_stop_l             (STOP),
451
    .pci_ext_perr_l             (PERR),
452
    .pci_ext_serr_l             (SERR),
453
    .pci_real_req_l             (MAS0_REQ),
454 106 mihad
    .pci_real_gnt_l             (MAS0_GNT | tc_gnt_allow),
455 15 mihad
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
456
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
457
    .test_error_event           (error_event_int),
458
    .test_observe_r_oe_sigs     (r_oe_sigs),
459
    .test_observe_0_oe_sigs     (6'h00),
460
    .test_observe_1_oe_sigs     (oe_sigs_1),
461
    .test_observe_2_oe_sigs     (oe_sigs_2),
462
    .test_observe_3_oe_sigs     (6'h00),
463
    .pci_ext_reset_l            (RST),
464
    .pci_ext_clk                (pci_clock),
465
    .log_file_desc              (pci_mon_log_file_desc)
466
) ;
467
 
468
reg [2:0]  test_master_number ;
469
reg [31:0] test_address ;
470
reg [3:0]  test_command ;
471
reg [31:0] test_data ;
472
reg [3:0]  test_byte_enables_l ;
473
reg [9:0]  test_size ;
474
reg        test_make_addr_par_error ;
475
reg        test_make_data_par_error ;
476
reg [3:0]  test_master_initial_wait_states ;
477
reg [3:0]  test_master_subsequent_wait_states ;
478
reg [3:0]  test_target_initial_wait_states ;
479
reg [3:0]  test_target_subsequent_wait_states ;
480
reg [1:0]  test_target_devsel_speed ;
481
reg        test_fast_back_to_back ;
482
reg [2:0]  test_target_termination ;
483
reg        test_expect_master_abort ;
484
reg        test_start ;
485
reg [25:0] test_target_response ;
486
 
487
wire [31:0] master2_received_data ;
488
wire        master2_received_data_valid ;
489
reg         master2_check_received_data ;
490
pci_behaviorial_device pci_behaviorial_device2
491
(
492
    .pci_ext_ad(AD),
493
    .pci_ext_cbe_l(CBE),
494
    .pci_ext_par(PAR),
495
    .pci_ext_frame_l(FRAME),
496
    .pci_ext_irdy_l(IRDY),
497
    .pci_ext_devsel_l(DEVSEL),
498
    .pci_ext_trdy_l(TRDY),
499
    .pci_ext_stop_l(STOP),
500
    .pci_ext_perr_l(PERR),
501
    .pci_ext_serr_l(SERR),
502
    .pci_ext_idsel(TAR2_IDSEL),
503
    .pci_ext_inta_l(INTA),
504
    .pci_ext_req_l(MAS2_REQ),
505
    .pci_ext_gnt_l(MAS2_GNT),
506
    .pci_ext_reset_l(RST),
507
    .pci_ext_clk(pci_clock),
508
 
509
// Signals used by the test bench instead of using "." notation
510
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
511
    .test_master_number                 (test_master_number[2:0]),
512
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
513
    .test_command                       (test_command[3:0]),
514
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
515
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
516
    .test_size                          (test_size),
517
    .test_make_addr_par_error           (test_make_addr_par_error),
518
    .test_make_data_par_error           (test_make_data_par_error),
519
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
520
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
521
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
522
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
523
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
524
    .test_fast_back_to_back             (test_fast_back_to_back),
525
    .test_target_termination            (test_target_termination[2:0]),
526
    .test_expect_master_abort           (test_expect_master_abort),
527
    .test_start                         (test_start),
528
    .test_accepted_l                    (test_accepted_l_int),
529
    .test_error_event                   (error_event_int),
530
    .test_device_id                     (`Test_Master_2),
531
    .test_target_response               (test_target_response),
532
 
533
    .master_received_data               (master2_received_data),
534
    .master_received_data_valid         (master2_received_data_valid),
535
    .master_check_received_data         (master2_check_received_data)
536
);
537
 
538
wire [31:0] master1_received_data ;
539
wire        master1_received_data_valid ;
540
reg         master1_check_received_data ;
541
pci_behaviorial_device pci_behaviorial_device1
542
(
543
    .pci_ext_ad(AD),
544
    .pci_ext_cbe_l(CBE),
545
    .pci_ext_par(PAR),
546
    .pci_ext_frame_l(FRAME),
547
    .pci_ext_irdy_l(IRDY),
548
    .pci_ext_devsel_l(DEVSEL),
549
    .pci_ext_trdy_l(TRDY),
550
    .pci_ext_stop_l(STOP),
551
    .pci_ext_perr_l(PERR),
552
    .pci_ext_serr_l(SERR),
553
    .pci_ext_idsel(TAR1_IDSEL),
554
    .pci_ext_inta_l(INTA),
555
    .pci_ext_req_l(MAS1_REQ),
556
    .pci_ext_gnt_l(MAS1_GNT),
557
    .pci_ext_reset_l(RST),
558
    .pci_ext_clk(pci_clock),
559
 
560
// Signals used by the test bench instead of using "." notation
561
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
562
    .test_master_number                 (test_master_number[2:0]),
563
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
564
    .test_command                       (test_command[3:0]),
565
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
566
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
567
    .test_size                          (test_size),
568
    .test_make_addr_par_error           (test_make_addr_par_error),
569
    .test_make_data_par_error           (test_make_data_par_error),
570
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
571
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
572
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
573
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
574
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
575
    .test_fast_back_to_back             (test_fast_back_to_back),
576
    .test_target_termination            (test_target_termination[2:0]),
577
    .test_expect_master_abort           (test_expect_master_abort),
578
    .test_start                         (test_start),
579
    .test_accepted_l                    (test_accepted_l_int),
580
    .test_error_event                   (error_event_int),
581
    .test_device_id                     (`Test_Master_1),
582
    .test_target_response               (test_target_response),
583
 
584
    .master_received_data               (master1_received_data),
585
    .master_received_data_valid         (master1_received_data_valid),
586
    .master_check_received_data         (master1_check_received_data)
587
);
588
 
589
pci_unsupported_commands_master ipci_unsupported_commands_master
590
(
591
    .CLK    ( pci_clock),
592
    .AD     ( AD ),
593
    .CBE    ( CBE ),
594
    .RST    ( RST ),
595
    .REQ    ( MAS3_REQ ),
596
    .GNT    ( MAS3_GNT ),
597
    .FRAME  ( FRAME ),
598
    .IRDY   ( IRDY ),
599
    .DEVSEL ( DEVSEL ),
600
    .TRDY   ( TRDY ),
601
    .STOP   ( STOP ),
602
    .PAR    ( PAR )
603
) ;
604
 
605 45 mihad
`ifdef HOST
606
 
607
reg     [1:0]   conf_cyc_type1_target_response ;
608
reg     [31:0]  conf_cyc_type1_target_data ;
609
reg     [7:0]   conf_cyc_type1_target_bus_num ;
610
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
611
 
612
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
613
(
614
    .CLK              ( pci_clock),
615
    .AD               ( AD ),
616
    .CBE              ( CBE ),
617
    .RST              ( RST ),
618
    .FRAME            ( FRAME ),
619
    .IRDY             ( IRDY ),
620
    .DEVSEL           ( DEVSEL ),
621
    .TRDY             ( TRDY ),
622
    .STOP             ( STOP ),
623
    .PAR              ( PAR ),
624
 
625
    .response         ( conf_cyc_type1_target_response ),
626
    .data_out         ( conf_cyc_type1_target_data ),
627
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
628
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
629
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
630
    .bus_number       ( conf_cyc_type1_target_bus_num )
631
);
632
`endif
633
 
634 15 mihad
// pci clock generator
635 63 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
636
    always@(posedge wb_clock)
637
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b1 ;
638
 
639
    always@(negedge wb_clock)
640
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b0 ;
641 15 mihad
`else
642 63 mihad
    always
643
    `ifdef PCI33
644
        #15 pci_clock = ~pci_clock ;
645
    `else
646
    `ifdef PCI66
647
        #7.5 pci_clock = ~pci_clock ;
648
    `endif
649
    `endif
650 15 mihad
`endif
651
 
652
// WISHBONE clock generation
653 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
654
always@(posedge pci_clock)
655
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b1 ;
656 15 mihad
 
657 63 mihad
always@(negedge pci_clock)
658
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b0 ;
659
 
660
`else
661
    always
662 104 mihad
        #(`WB_PERIOD/2) wb_clock = !wb_clock ;
663 63 mihad
`endif
664
 
665 15 mihad
// Make test name visible when the Master starts working on it
666
reg     [79:0] present_test_name;
667
reg     [79:0] next_test_name;
668
wire    test_accepted = ~test_accepted_l_int;
669
always @(posedge test_accepted)
670
begin
671
    present_test_name <= next_test_name;
672
end
673
 
674
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
675
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
676
 
677
// basic configuration parameters for both behavioral devices
678
parameter [2:0] Master_ID_A                           = `Test_Master_1;
679
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
680
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
681
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
682
 
683
parameter [2:0] Master_ID_B                           = `Test_Master_2;
684
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
685
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
686
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
687
 
688
// basic configuration parameters for REAL device
689
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
690
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
691
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
692
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
693
 
694
// reg  [2:0]   ack_err_rty_termination ;
695
// reg          wait_cycles ;
696
// reg  [7:0]   num_of_retries ;
697
 
698
//reg [19:0] pci_config_base ;
699
reg [7:0] system_burst_size ;
700
reg [7:0] bridge_latency ;
701
integer   target_mem_image ;
702
integer   target_io_image ;
703
 
704
initial
705
begin
706 62 mihad
 
707
`ifdef PCI_BIST
708 122 markom
    mbist_si_i    = 0 ;
709
    mbist_ctrl_i    = 0 ;
710
    mbist_clk   = 0 ;
711
    mbist_rst   = 0 ;
712 62 mihad
`endif
713 15 mihad
    next_test_name[79:0] <= "Nowhere___";
714
    reset = 1'b1 ;
715
    pci_clock = 1'b0 ;
716 104 mihad
    wb_clock  = 1'b0 ;
717 15 mihad
    target_message = 32'h0000_0000 ;
718
//  num_of_retries = 8'h01 ;
719
//  ack_err_rty_termination = 3'b100 ;
720
//  wait_cycles = 1'b0 ;
721
 
722
    // system paameters
723
    system_burst_size = 16 ;
724
    bridge_latency    = 8 ;
725
 
726
    // set initial values for controling the behavioral PCI master
727
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
728
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
729
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
730
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
731
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
732
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
733
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
734
 
735
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
736
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
737
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
738
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
739
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
740
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
741
 
742
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
743
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
744
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
745
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
746
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
747
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
748
 
749
    test_master_number = `Test_Master_2 ;
750
    test_address = 32'h0000_0000 ;
751
    test_command = `BC_RESERVED0 ;
752
    test_data = 32'h0000_0000 ;
753
    test_byte_enables_l   = 4'hF ;
754
    test_size = 0 ;
755
    test_make_addr_par_error = 0 ;
756
    test_make_data_par_error = 0;
757
    test_master_initial_wait_states = 0 ;
758
    test_master_subsequent_wait_states = 0 ;
759
    test_target_initial_wait_states = 0 ;
760
    test_target_subsequent_wait_states = 0;
761
    test_target_devsel_speed = `Test_Devsel_Fast ;
762
    test_fast_back_to_back = 0 ;
763
    test_target_termination = `Test_Target_Normal_Completion ;
764
    test_expect_master_abort = 0 ;
765
    test_start = 0 ;
766
    test_target_response = 0 ;
767
 
768
    master1_check_received_data = 0 ;
769
    master2_check_received_data = 0 ;
770
 
771 45 mihad
    `ifdef HOST
772
        conf_cyc_type1_target_response = 0 ;
773
        conf_cyc_type1_target_data = 0 ;
774
        conf_cyc_type1_target_bus_num = 255 ;
775
    `endif
776 15 mihad
 
777
    // fill memory and IO data with random values
778
    fill_memory ;
779
 
780
    INT_I = 0 ;
781
 
782
    // extract from constants which target image can be used as IO and which as memory
783
    `ifdef HOST
784
        target_mem_image = 1 ;
785
        target_io_image  = 1 ;
786
    `else
787
        target_mem_image = -1 ;
788
        target_io_image     = -1 ;
789
        if ( `PCI_BA1_MEM_IO === 0 )
790
            target_mem_image = 1 ;
791
        else
792
            target_io_image = 1 ;
793
 
794
        if ( target_mem_image === -1 )
795
        begin
796
            `ifdef PCI_IMAGE2
797
                if ( `PCI_BA2_MEM_IO === 0 )
798
                    target_mem_image = 2 ;
799
                else if ( target_io_image === -1 )
800
                    target_io_image = 2 ;
801
            `endif
802
        end
803
 
804
        if ( target_mem_image === -1 )
805
        begin
806
            `ifdef PCI_IMAGE3
807
                if ( `PCI_BA3_MEM_IO === 0 )
808
                    target_mem_image = 3 ;
809
                else if ( target_io_image === -1 )
810
                    target_io_image = 3 ;
811
            `endif
812
        end
813
 
814
        if ( target_mem_image === -1 )
815
        begin
816
            `ifdef PCI_IMAGE4
817
                if ( `PCI_BA4_MEM_IO === 0 )
818
                    target_mem_image = 4 ;
819
                else if ( target_io_image === -1 )
820
                    target_io_image = 4 ;
821
            `endif
822
        end
823
 
824
        if ( target_mem_image === -1 )
825
        begin
826
            `ifdef PCI_IMAGE5
827
                if ( `PCI_BA5_MEM_IO === 0 )
828
                    target_mem_image = 5 ;
829
                else if ( target_io_image === -1 )
830
                    target_io_image = 5 ;
831
            `endif
832
        end
833
    `endif
834
 
835
    tests_successfull = 0 ;
836
    tests_failed = 0 ;
837
 
838
    tb_log_file = $fopen("../log/pci_tb.log") ;
839
 
840
    if ( tb_log_file < 2 )
841
    begin
842
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
843
        $finish ;
844
    end
845
 
846
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
847
    $fdisplay( tb_log_file,"" ) ;
848
 
849
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
850
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
851
 
852
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
853
    begin
854
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
855
        $finish ;
856
    end
857
 
858
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
859
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
860
 
861
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
862
    if ( pci_mon_log_file_desc < 2 )
863
    begin
864
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
865
        $finish ;
866
    end
867
 
868
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
869
 
870
    run_tests ;
871
end
872
 
873 106 mihad
task fill_memory ; //wb_b3_ok
874 15 mihad
    integer temp_index ;
875
begin
876
    // fill write memories with random data
877
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
878
    begin
879
        wmem_data[temp_index[9:0]] = $random ;
880 26 mihad
        # 1;
881 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
882 26 mihad
        # 1;
883 15 mihad
    end
884
    // fill WB slave behavioral MEMORY
885
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
886
    begin
887
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
888
        # 1;
889
    end
890
end
891
endtask // fill_memory
892
 
893 92 mihad
reg [2:0] wb_init_waits ;
894
reg [2:0] pci_init_waits ;
895
reg [2:0] wb_subseq_waits ;
896
reg [2:0] pci_subseq_waits ;
897 15 mihad
reg [2:0] tb_target_decode_speed ;
898
 
899 106 mihad
task run_tests ; //wb_b3_ok
900 15 mihad
begin
901 92 mihad
    wb_init_waits          = 0;
902
    pci_init_waits         = 0;
903
    wb_subseq_waits        = 0 ;
904
    pci_subseq_waits       = 0 ;
905
    tb_target_decode_speed = 0 ;
906
 
907 15 mihad
    // first - reset logic
908
    do_reset ;
909 62 mihad
 
910
    // if BIST is implemented, give it a go
911
`ifdef PCI_BIST
912 106 mihad
    run_bist_test ;
913 122 markom
    mbist_rst <= #1 1'b1 ;
914 62 mihad
`endif
915 45 mihad
    test_initial_conf_values ;
916
 
917 15 mihad
    next_test_name[79:0] <= "Initing...";
918
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
919
 
920 92 mihad
    for ( wb_init_waits = 0 ; wb_init_waits <= 4 ; wb_init_waits = wb_init_waits + 1 )
921 15 mihad
    begin
922 92 mihad
        for ( wb_subseq_waits = 0 ; wb_subseq_waits <= 4 ; wb_subseq_waits = wb_subseq_waits + 1 )
923 15 mihad
        begin
924
 
925 92 mihad
            pci_init_waits   = wb_init_waits ;
926
            pci_subseq_waits = wb_subseq_waits ;
927 15 mihad
 
928 92 mihad
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = pci_init_waits ;
929
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = pci_subseq_waits ;
930
 
931 15 mihad
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
932
            begin
933
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
934
 
935
                `ifdef HOST
936
                    configure_bridge_target ;
937
                    find_pci_devices ;
938 45 mihad
                    test_configuration_cycle_target_abort ;
939
                    test_configuration_cycle_type1_generation ;
940 15 mihad
                `endif
941
 
942
                @(posedge pci_clock) ;
943
                configure_target(1) ;
944
                @(posedge pci_clock) ;
945
                configure_target(2) ;
946
 
947
                `ifdef GUEST
948
                    configure_bridge_target ;
949
                `endif
950
 
951
               next_test_name[79:0] <= "WB_SLAVE..";
952
 
953
                $display("Testing WISHBONE slave images' features!") ;
954
                test_wb_image(1) ;
955
 
956
                `ifdef WB_IMAGE2
957
                    test_wb_image(2) ;
958
                `else
959
                    $display(" WB IMAGE 2 not implemented! ") ;
960
                `endif
961
 
962
                `ifdef WB_IMAGE3
963
                    test_wb_image(3) ;
964
                `else
965
                    $display(" WB IMAGE 3 not implemented! ") ;
966
                `endif
967
 
968
                `ifdef WB_IMAGE4
969
                    test_wb_image(4) ;
970
                `else
971
                    $display(" WB IMAGE 4 not implemented! ") ;
972
                `endif
973
 
974
                `ifdef WB_IMAGE5
975
                    test_wb_image(5) ;
976
                `else
977
                    $display(" WB IMAGE 5 not implemented! ") ;
978
                `endif
979
 
980
                wb_slave_errors ;
981
                wb_to_pci_error_handling ;
982
 
983
                parity_checking ;
984
 
985
                wb_to_pci_transactions ;
986
 
987
                `ifdef HOST
988
                iack_cycle ;
989
                `endif
990
 
991 73 mihad
                test_master_overload ;
992
 
993 15 mihad
            end
994 57 mihad
 
995 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
996
        `else
997 57 mihad
            master_completion_expiration ;
998 63 mihad
        `endif
999 57 mihad
 
1000 104 mihad
        `ifdef DO_CORNER_CASE_TESTS
1001 69 mihad
            master_special_corner_case_test ;
1002
        `endif
1003
 
1004 15 mihad
            $display(" ") ;
1005
            $display("WB slave images' tests finished!") ;
1006
 
1007
            $display("########################################################################") ;
1008
            $display("########################################################################") ;
1009
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
1010
            $display("########################################################################") ;
1011
            $display("########################################################################") ;
1012
 
1013
            $display("Testing PCI target images' features!") ;
1014
            configure_bridge_target_base_addresses ;
1015 104 mihad
 
1016 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
1017
                test_conf_cycle_type1_reference ;
1018
            `endif
1019
 
1020 15 mihad
            `ifdef HOST
1021
             `ifdef NO_CNF_IMAGE
1022
              `ifdef PCI_IMAGE0
1023
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
1024
            test_pci_image(0) ;
1025
              `else
1026
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
1027
              `endif
1028
             `else
1029
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
1030
             `endif
1031
            `endif
1032
 
1033
            $display("PCI image 1 is ALWAYS implemented!") ;
1034
            test_pci_image(1) ;
1035
 
1036
            `ifdef PCI_IMAGE2
1037
            $display("PCI image 2 is implemented!") ;
1038
            test_pci_image(2) ;
1039
            `else
1040
            $display("PCI image 2 is NOT implemented!") ;
1041
            `endif
1042
 
1043
            `ifdef PCI_IMAGE3
1044
            $display("PCI image 3 is implemented!") ;
1045
            test_pci_image(3) ;
1046
            `else
1047
            $display("PCI image 3 is NOT implemented!") ;
1048
            `endif
1049
 
1050
            `ifdef PCI_IMAGE4
1051
            $display("PCI image 4 is implemented!") ;
1052
            test_pci_image(4) ;
1053
            `else
1054
            $display("PCI image 4 is NOT implemented!") ;
1055
            `endif
1056
 
1057
            `ifdef PCI_IMAGE5
1058
            $display("PCI image 5 is implemented!") ;
1059
            test_pci_image(5) ;
1060
            `else
1061
            $display("PCI image 5 is NOT implemented!") ;
1062
            `endif
1063
 
1064
            test_wb_error_rd ;
1065
 
1066
            target_fast_back_to_back ;
1067
            target_disconnects ;
1068
 
1069 73 mihad
            test_target_overload ;
1070
 
1071 15 mihad
            if ( target_io_image !== -1 )
1072
                test_target_abort( target_io_image ) ;
1073
            $display(" ") ;
1074
            $display("PCI target images' tests finished!") ;
1075
 
1076
            transaction_ordering ;
1077 33 mihad
 
1078 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
1079
        `else
1080 33 mihad
            target_completion_expiration ;
1081 63 mihad
        `endif
1082
 
1083 15 mihad
            $display(" ") ;
1084
            $display("PCI transaction ordering tests finished!") ;
1085
        end
1086
    end
1087
 
1088 92 mihad
    wb_init_waits   = 0 ;
1089
    pci_init_waits  = 0 ;
1090
    wb_subseq_waits = 0 ;
1091
    pci_subseq_waits = 0 ;
1092 73 mihad
 
1093 104 mihad
    `ifdef DO_CORNER_CASE_TESTS
1094 63 mihad
        test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
1095
        test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
1096
        test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
1097
        test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = 0 ;
1098
 
1099
        `ifdef HOST
1100
            configure_bridge_target ;
1101
        `endif
1102
 
1103
        @(posedge pci_clock) ;
1104
        configure_target(1) ;
1105
        @(posedge pci_clock) ;
1106
        configure_target(2) ;
1107
 
1108
        `ifdef GUEST
1109 106 mihad
            configure_bridge_target ; // b3ok
1110 63 mihad
        `endif
1111
 
1112
        target_special_corner_case_test ;
1113
    `endif
1114
 
1115 92 mihad
    wb_init_waits    = 0 ;
1116
    pci_init_waits   = 0 ;
1117
    wb_subseq_waits  = 0 ;
1118
    pci_subseq_waits = 0 ;
1119 73 mihad
 
1120 15 mihad
    test_summary ;
1121
 
1122
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
1123
    $stop ;
1124
end
1125
endtask // run_tests
1126
 
1127 106 mihad
task do_reset; //wb_b3_ok
1128 15 mihad
begin
1129
    next_test_name[79:0] <= "Reset.....";
1130
 
1131
    reset = 1'b1 ;
1132
    #100 ;
1133
    `ifdef HOST
1134
        @(posedge wb_clock) ;
1135
    `else
1136
    `ifdef GUEST
1137
        @(posedge pci_clock) ;
1138
    `endif
1139
    `endif
1140
 
1141
    reset <= 1'b0 ;
1142
 
1143 45 mihad
    `ifdef HOST
1144
        @(posedge wb_clock) ;
1145
    `else
1146
    `ifdef GUEST
1147
        @(posedge pci_clock) ;
1148
    `endif
1149
    `endif
1150
 
1151 15 mihad
end
1152
endtask
1153
 
1154
/*############################################################################
1155
WB SLAVE UNIT tasks
1156
===================
1157
############################################################################*/
1158
 
1159 106 mihad
task configure_target ; //wb_b3_ok
1160 45 mihad
    input [1:0]  beh_dev_num ;
1161 15 mihad
    reg   [31:0] base_address1 ;
1162
    reg   [31:0] base_address2 ;
1163
    reg   [2:0]  Master_ID;
1164
    reg   [31:0] Target_Config_Addr;
1165 45 mihad
    reg   [4:0]  device_num ;
1166 15 mihad
begin
1167 45 mihad
    if (beh_dev_num === 1)
1168 15 mihad
    begin
1169
        base_address1       = `BEH_TAR1_MEM_START ;
1170
        base_address2       = `BEH_TAR1_IO_START  ;
1171
        Master_ID           = `Test_Master_2 ;
1172
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1173 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1174 15 mihad
    end
1175
    else
1176 45 mihad
    if (beh_dev_num === 2)
1177 15 mihad
    begin
1178
        base_address1       = `BEH_TAR2_MEM_START ;
1179
        base_address2       = `BEH_TAR2_IO_START  ;
1180
        Master_ID           = `Test_Master_1 ;
1181
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1182 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1183 15 mihad
    end
1184
 
1185
    // write target's base addresses
1186
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1187
    // type 0 cycle, byte enables, base address
1188
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1189
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1190
 
1191
    // enable target's response and master
1192
    // enable parity errors, disable system error
1193
 
1194
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1195
 
1196
end
1197
endtask //configure_target
1198
 
1199 106 mihad
task test_wb_image ; //wb_b3_ok
1200 15 mihad
    input [2:0]  image_num ;
1201
    reg   [11:0] ctrl_offset ;
1202
    reg   [11:0] ba_offset ;
1203
    reg   [11:0] am_offset ;
1204
    reg   [11:0] ta_offset ;
1205
    reg   [11:0] err_cs_offset ;
1206
    reg `WRITE_STIM_TYPE write_data ;
1207
    reg `READ_STIM_TYPE  read_data ;
1208
    reg `READ_RETURN_TYPE read_status ;
1209
 
1210
    reg `WRITE_RETURN_TYPE write_status ;
1211
    reg `WB_TRANSFER_FLAGS write_flags ;
1212
    reg [31:0] temp_val ;
1213
    reg        ok   ;
1214
    reg [11:0] pci_ctrl_offset ;
1215
    reg [31:0] image_base ;
1216
    reg [31:0] target_address ;
1217
    reg [31:0] translation_address ;
1218
    integer    i ;
1219
    integer    j ;
1220
begin:main
1221
    pci_ctrl_offset = 12'h4 ;
1222
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1223
    // image 0 can only be configuration image - start with 1
1224
    if (image_num === 1)
1225
    begin
1226
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1227
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1228
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1229
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1230
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1231
    end
1232
    else if (image_num === 2)
1233
    begin
1234
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1235
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1236
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1237
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1238
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1239
    end
1240
    else if (image_num === 3)
1241
    begin
1242
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1243
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1244
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1245
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1246
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1247
    end
1248
    else if (image_num === 4)
1249
    begin
1250
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1251
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1252
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1253
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1254
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1255
    end
1256
    else if (image_num === 5)
1257
    begin
1258
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1259
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1260
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1261
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1262
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1263
    end
1264
    else
1265
    begin
1266
        test_name   = "WB IMAGES' FEATURES TEST" ;
1267
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1268
        disable main ;
1269
    end
1270
 
1271
    target_address  = `BEH_TAR1_MEM_START ;
1272
    image_base      = 0 ;
1273
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1274
 
1275
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1276
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1277
    write_flags                      = 0 ;
1278 92 mihad
    write_flags`INIT_WAITS           = wb_init_waits ;
1279
    write_flags`SUBSEQ_WAITS         = wb_subseq_waits ;
1280 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1281
 
1282
    test_name = "WB IMAGE CONFIGURATION" ;
1283
    // enable master & target operation
1284
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1285
    if ( ok !== 1 )
1286
    begin
1287 69 mihad
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1288 15 mihad
        test_fail("write to PCI Device Control register didn't succeede");
1289
        disable main ;
1290
    end
1291
 
1292
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1293
    if ( ok !== 1 )
1294
    begin
1295 69 mihad
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", $time) ;
1296 15 mihad
        test_fail("write to WB Error Control and Status register didn't succeede");
1297
        disable main ;
1298
    end
1299
 
1300
    // prepare image control register
1301
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1302
    if ( ok !== 1 )
1303
    begin
1304
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1305
        test_fail("write to WB Image Control register didn't succeede");
1306
        disable main ;
1307
    end
1308
 
1309
    // prepare base address register
1310
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1311
    if ( ok !== 1 )
1312
    begin
1313
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1314
        test_fail("write to WB Base Address register didn't succeede");
1315
        disable main ;
1316
    end
1317
 
1318
    // write address mask register
1319
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1320
    if ( ok !== 1 )
1321
    begin
1322
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1323
        test_fail("write to WB Address Mask register didn't succeede");
1324
        disable main ;
1325
    end
1326
 
1327
    fork
1328
    begin
1329
        write_data`WRITE_ADDRESS = target_address ;
1330
        write_data`WRITE_DATA    = wmem_data[0] ;
1331
        write_data`WRITE_SEL     = 4'hF ;
1332
 
1333
        // handle retries from now on
1334 106 mihad
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1335 15 mihad
 
1336
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1337
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1338
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1339
        begin
1340
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1341
            test_fail("WB Slave state machine failed to post single memory write");
1342
            disable main ;
1343
        end
1344
 
1345
        // read written data back
1346
        read_data`READ_ADDRESS  = target_address ;
1347
        read_data`READ_SEL      = 4'hF ;
1348 106 mihad
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
1349 15 mihad
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1350
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1351
        begin
1352
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1353
            test_fail("PCI bridge didn't process the read as expected");
1354
            disable main ;
1355
        end
1356
 
1357
        if (read_status`READ_DATA !== wmem_data[0])
1358
        begin
1359
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1360
            test_fail("PCI bridge returned unexpected Read Data");
1361
        end
1362
        else
1363
            test_ok ;
1364
    end
1365
    begin
1366
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1367
        if ( ok !== 1 )
1368
        begin
1369
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1370
        end
1371
        else
1372
            test_ok ;
1373
 
1374
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1375
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1376
        if ( ok !== 1 )
1377
        begin
1378
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1379
        end
1380
    end
1381
    join
1382
 
1383
    // if address translation is implemented - try it out
1384
    translation_address = image_base ;
1385
    `ifdef ADDR_TRAN_IMPL
1386
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1387
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1388
    if ( ok !== 1 )
1389
    begin
1390
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1391
        test_fail("write to WB Image Translation Address Register failed") ;
1392
        disable main ;
1393
    end
1394
 
1395
    target_address  = `BEH_TAR2_MEM_START ;
1396
    image_base      = 0 ;
1397
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1398
 
1399
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1400
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1401
 
1402
    write_flags                      = 0 ;
1403
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1404
 
1405
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1406
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1407
    if ( ok !== 1 )
1408
    begin
1409
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1410
        test_fail("write to WB Image Base Address Register failed") ;
1411
        disable main ;
1412
    end
1413
 
1414
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1415
    // enable address translation
1416
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1417
    if ( ok !== 1 )
1418
    begin
1419
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1420
        test_fail("write to WB Image Control Register failed") ;
1421
        disable main ;
1422
    end
1423
 
1424
    `endif
1425
 
1426
    fork
1427
    begin
1428 106 mihad
        write_data`WRITE_ADDRESS  = target_address + 4 ;
1429
        write_data`WRITE_DATA     = wmem_data[1] ;
1430
        write_data`WRITE_SEL      = 4'hF ;
1431 15 mihad
 
1432
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1433
 
1434
        `ifdef ADDR_TRAN_IMPL
1435
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1436
        `else
1437
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1438
        `endif
1439
 
1440
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1441
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1442
        begin
1443
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1444
            test_fail("WB Slave state machine failed to post single memory write") ;
1445
            disable main ;
1446
        end
1447
 
1448
        // read written data back
1449
        read_data`READ_ADDRESS  = target_address + 4 ;
1450
        read_data`READ_SEL      = 4'hF ;
1451
 
1452
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1453
 
1454
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1455
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1456
        begin
1457
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1458
            test_fail("PCI bridge failed to process single delayed memory read") ;
1459
            disable main ;
1460
        end
1461
 
1462
        if (read_status`READ_DATA !== wmem_data[1])
1463
        begin
1464
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1465
            test_fail("PCI bridge returned unexpected Read Data");
1466
        end
1467
        else
1468
            test_ok ;
1469
    end
1470
    begin
1471
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 4, translation_address, 1'b1 ), `BC_MEM_WRITE, 1, 0, 1'b1, 0, 0, ok ) ;
1472
        if ( ok !== 1 )
1473
        begin
1474
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1475
        end
1476
        else
1477
            test_ok ;
1478
 
1479
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1480
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 4, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1481
        if ( ok !== 1 )
1482
        begin
1483
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1484
        end
1485
    end
1486
    join
1487
 
1488
    // now do one burst write - length of 6 - minimum depth of fifo is 8, one loc. is always free and one is taken up by address entry
1489
    // prepare write data
1490 106 mihad
 
1491 15 mihad
    for ( i = 0 ; i < 6 ; i = i + 1 )
1492
    begin
1493
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1494
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1495
        write_data`WRITE_SEL     = 4'hF ;
1496
        wishbone_master.blk_write_data[i] = write_data ;
1497
    end
1498
 
1499
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1500
    write_flags`WB_TRANSFER_CAB    = 1 ;
1501
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1502
 
1503
    fork
1504
    begin
1505
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1506
        wishbone_master.wb_block_write(write_flags, write_status) ;
1507
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1508
        begin
1509
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1510
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1511
            disable main ;
1512
        end
1513
    end
1514
    begin
1515
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_WRITE, 6, 0, 1'b1, 0, 0, ok ) ;
1516
        if ( ok !== 1 )
1517
        begin
1518
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1519
        end
1520
        else
1521
            test_ok ;
1522
    end
1523
    join
1524
 
1525
    // set burst size and latency timer
1526
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1527
 
1528
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1529
    write_flags`WB_TRANSFER_CAB    = 1 ;
1530
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1531
 
1532
    // prepare read data
1533
    for ( i = 0 ; i < 4 ; i = i + 1 )
1534
    begin
1535
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1536
        read_data`READ_SEL     = 4'hF ;
1537
        wishbone_master.blk_read_data_in[i] = read_data ;
1538
    end
1539
 
1540
    fork
1541
    begin
1542
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1543
        wishbone_master.wb_block_read(write_flags, read_status) ;
1544
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1545
        begin
1546
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1547
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1548
            disable main ;
1549
        end
1550
 
1551
        // check data read from target
1552
        for ( i = 0 ; i < 4 ; i = i + 1 )
1553
        begin
1554
            read_status = wishbone_master.blk_read_data_out[i] ;
1555
            if (read_status`READ_DATA !== wmem_data[2 + i])
1556
            begin
1557
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1558
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1559
            end
1560
        end
1561
    end
1562
    begin
1563
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1564
        if ( ok !== 1 )
1565
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1566
        else
1567
            test_ok ;
1568
 
1569
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 12, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1570
        if ( ok !== 1 )
1571
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1572
        else
1573
            test_ok ;
1574
 
1575
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 16, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1576
        if ( ok !== 1 )
1577
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1578
        else
1579
            test_ok ;
1580
 
1581
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 20, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1582
        if ( ok !== 1 )
1583
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1584
        else
1585
            test_ok ;
1586
 
1587
    end
1588
    join
1589
 
1590
    // now repeat this same burst read with various image features enabled or disabled
1591
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1592
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1593
    if (ok !== 1)
1594
    begin
1595
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1596
        test_fail("write to WB Image control register failed") ;
1597
        disable main ;
1598
    end
1599
 
1600
    fork
1601
    begin
1602
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1603
        wishbone_master.wb_block_read(write_flags, read_status) ;
1604
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1605
        begin
1606
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1607
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1608
            disable main ;
1609
        end
1610
 
1611
        // check data read from target
1612
        for ( i = 0 ; i < 4 ; i = i + 1 )
1613
        begin
1614
            read_status = wishbone_master.blk_read_data_out[i] ;
1615
            if (read_status`READ_DATA !== wmem_data[2 + i])
1616
            begin
1617
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1618
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1619
            end
1620
            else
1621
                test_ok ;
1622
        end
1623
    end
1624
    begin
1625
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ_LN, 4, 0, 1'b1, 0, 0, ok ) ;
1626
        if ( ok !== 1 )
1627
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1628
    end
1629
    join
1630
 
1631
    read_data`READ_ADDRESS  = target_address ;
1632
    read_data`READ_SEL      = 4'hF ;
1633
 
1634
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1635
    fork
1636
    begin
1637
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1638
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1639
        begin
1640
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1641
            test_fail("delayed single memory read wasn't processed as expected") ;
1642
            disable main ;
1643
        end
1644
 
1645
        if (read_status`READ_DATA !== wmem_data[0])
1646
        begin
1647
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1648
            test_fail("delayed single memory read data value returned was not as expected") ;
1649
        end
1650
        else
1651
            test_ok ;
1652
    end
1653
    begin
1654
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1655
        if ( ok !== 1 )
1656
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1657
    end
1658
    join
1659
 
1660
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1661
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1662
    if (ok !== 1)
1663
    begin
1664
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1665
        test_fail("write to WB Image control register failed") ;
1666
        disable main ;
1667
    end
1668
 
1669
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1670
    fork
1671
    begin
1672
        wishbone_master.wb_block_read(write_flags, read_status) ;
1673
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1674
        begin
1675
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1676
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1677
            disable main ;
1678
        end
1679
 
1680
        // check data read from target
1681
        for ( i = 0 ; i < 4 ; i = i + 1 )
1682
        begin
1683
            read_status = wishbone_master.blk_read_data_out[i] ;
1684
            if (read_status`READ_DATA !== wmem_data[2 + i])
1685
            begin
1686
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1687
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1688
            end
1689
            else
1690
                test_ok ;
1691
        end
1692
    end
1693
    begin
1694
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ, 4, 0, 1'b1, 0, 0, ok ) ;
1695
        if ( ok !== 1 )
1696
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1697
    end
1698
    join
1699
 
1700
    read_data`READ_ADDRESS  = target_address + 4 ;
1701
    read_data`READ_SEL      = 4'hF ;
1702
 
1703
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1704
    fork
1705
    begin
1706
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1707
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1708
        begin
1709
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1710
            test_fail("delayed single memory read wasn't processed as expected") ;
1711
            disable main ;
1712
        end
1713
 
1714
        if (read_status`READ_DATA !== wmem_data[1])
1715
        begin
1716
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1717
            test_fail("delayed single memory read data value returned was not as expected") ;
1718
        end
1719
        else
1720
            test_ok ;
1721
    end
1722
    begin
1723
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 4, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1724
        if ( ok !== 1 )
1725
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1726
    end
1727
    join
1728
 
1729
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1730
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1731
    if (ok !== 1)
1732
    begin
1733
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1734
        test_fail("write to WB Image control register failed") ;
1735
        disable main ;
1736
    end
1737
 
1738
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1739
    fork
1740
    begin
1741
        wishbone_master.wb_block_read(write_flags, read_status) ;
1742
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1743
        begin
1744
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1745
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1746
            disable main ;
1747
        end
1748
 
1749
        // check data read from target
1750
        for ( i = 0 ; i < 4 ; i = i + 1 )
1751
        begin
1752
            read_status = wishbone_master.blk_read_data_out[i] ;
1753
            if (read_status`READ_DATA !== wmem_data[2 + i])
1754
            begin
1755
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1756
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1757
            end
1758
            else
1759
                test_ok ;
1760
        end
1761
    end
1762
    begin
1763
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 0, 0, ok ) ;
1764
        if ( ok !== 1 )
1765
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1766
    end
1767
    join
1768
 
1769
    read_data`READ_ADDRESS  = target_address + 8 ;
1770
    read_data`READ_SEL      = 4'hF ;
1771
 
1772
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1773
    fork
1774
    begin
1775
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1776
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1777
        begin
1778
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1779
            test_fail("delayed single memory read wasn't processed as expected") ;
1780
            disable main ;
1781
        end
1782
 
1783
        if (read_status`READ_DATA !== wmem_data[2])
1784
        begin
1785
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1786
            test_fail("delayed single memory read data value returned was not as expected") ;
1787
        end
1788
        else
1789
            test_ok ;
1790
    end
1791
    begin
1792
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1793
        if ( ok !== 1 )
1794
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1795
    end
1796
    join
1797
 
1798
    // map image to IO space
1799
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1800
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1801
    if ( ok !== 1 )
1802
    begin
1803
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1804
        test_fail("write to WB Image Base Address register failed") ;
1805
        disable main ;
1806
    end
1807
 
1808
    write_data`WRITE_ADDRESS = target_address ;
1809
    write_data`WRITE_DATA    = wmem_data[11] ;
1810
    write_data`WRITE_SEL     = 4'hF ;
1811
 
1812 106 mihad
    // don't handle retries from now on
1813 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1814
 
1815
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1816
    fork
1817
    begin
1818
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1819
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1820
        begin
1821
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1822
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1823
            disable main ;
1824
        end
1825
    end
1826
    begin
1827
        // currently IO commands not supported in behavioral models - master abort
1828
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address, translation_address, 1'b1 ), `BC_IO_WRITE, 0, 0, 1'b1, 0, 0, ok ) ;
1829
        if ( ok !== 1 )
1830
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1831
        else
1832
            test_ok ;
1833
    end
1834
    join
1835
 
1836
    read_data`READ_ADDRESS  = target_address ;
1837
    read_data`READ_SEL      = 4'hF ;
1838
 
1839
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1840
 
1841
    // currently io commands are not supported by behavioral target - transfer should not be completed
1842
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1843
    fork
1844
    begin
1845
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1846
        if (read_status`CYC_ERR !== 1)
1847
        begin
1848
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1849
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1850
            disable main ;
1851
        end
1852
        else
1853
            test_ok ;
1854
    end
1855
    begin
1856
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address, translation_address, 1'b1 ), `BC_IO_READ, 0, 0, 1'b1, 0, 0, ok ) ;
1857
        if ( ok !== 1 )
1858
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1859
    end
1860
    join
1861
 
1862
    // test byte addressing
1863 106 mihad
    read_data`READ_ADDRESS  = target_address + 2 ;
1864
    read_data`READ_SEL      = 4'b1100 ;
1865 15 mihad
 
1866
    fork
1867
    begin
1868
        // currently io commands are not supported by behavioral target - transfer should not be completed
1869
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1870
        if (read_status`CYC_ERR !== 1)
1871
        begin
1872
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1873
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1874
            disable main ;
1875
        end
1876
        else test_ok ;
1877
    end
1878
    begin
1879
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 2, translation_address, 1'b1 ), `BC_IO_READ, 0, 0, 1'b1, 0, 0, ok ) ;
1880
        if ( ok !== 1 )
1881
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1882
    end
1883
    join
1884
 
1885
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1886
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1887
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1888
    if ( ok !== 1 )
1889
    begin
1890
        test_fail("WB Base address register could not be written") ;
1891
        disable main ;
1892
    end
1893
 
1894
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1895
    if ( ok !== 1 )
1896
    begin
1897
        test_fail("WB Address Mask register could not be written") ;
1898
        disable main ;
1899
    end
1900
 
1901
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1902
    if ( ok !== 1 )
1903
    begin
1904
        test_fail("WB Image Control register could not be written") ;
1905
        disable main ;
1906
    end
1907
 
1908 106 mihad
    write_data`WRITE_ADDRESS  = {target_address[31], 31'h7FFF_FFFF} ;
1909
    write_data`WRITE_DATA     = wmem_data[11] ;
1910
    write_data`WRITE_SEL      = 4'b1000 ;
1911 15 mihad
 
1912
    // handle retries from now on
1913
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1914
 
1915
    fork
1916
    begin
1917
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1918
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1919
        begin
1920
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1921
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1922
            disable main ;
1923
        end
1924
    end
1925
    begin
1926
        // currently IO commands not supported in behavioral models - master abort
1927
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1928
        if ( ok !== 1 )
1929
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1930
        else
1931
            test_ok ;
1932
    end
1933
    join
1934
 
1935 106 mihad
    read_data`READ_ADDRESS  = write_data`WRITE_ADDRESS ;
1936
    read_data`READ_SEL      = write_data`WRITE_SEL ;
1937 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1938
 
1939
    fork
1940
    begin
1941
        // currently io commands are not supported by behavioral target - transfer should not be completed
1942
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1943
        if (read_status`CYC_ERR !== 1)
1944
        begin
1945
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1946
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1947
            disable main ;
1948
        end
1949
        else test_ok ;
1950
    end
1951
    begin
1952
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1953
        if ( ok !== 1 )
1954
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1955
    end
1956
    join
1957
 
1958
    test_name = "DISABLING WB IMAGE" ;
1959
 
1960
    // disable current image
1961
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1962
    if ( ok !== 1 )
1963
    begin
1964
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1965
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1966
        disable main ;
1967
    end
1968
 
1969
    // clear master abort status bit
1970
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1971
    if ( ok !== 1 )
1972
    begin
1973
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1974
        test_fail("write to PCI Device Status register not accepted as expected") ;
1975
        disable main ;
1976
    end
1977
 
1978
end //main
1979
endtask //test_wb_image
1980
 
1981 106 mihad
task wb_slave_errors ; //wb_b3_ok
1982 15 mihad
    reg   [11:0] ctrl_offset ;
1983
    reg   [11:0] ba_offset ;
1984
    reg   [11:0] am_offset ;
1985
    reg   [11:0] ta_offset ;
1986
    reg `WRITE_STIM_TYPE write_data ;
1987
    reg `READ_STIM_TYPE  read_data ;
1988
    reg `READ_RETURN_TYPE read_status ;
1989
 
1990
    reg `WRITE_RETURN_TYPE write_status ;
1991
    reg `WB_TRANSFER_FLAGS write_flags ;
1992
    reg [31:0] temp_val1 ;
1993
    reg [31:0] temp_val2 ;
1994
    reg        ok   ;
1995
    reg [11:0] pci_ctrl_offset ;
1996
    reg [31:0] image_base ;
1997
    reg [31:0] target_address ;
1998
    integer    i ;
1999
    reg skip ;
2000
fork
2001
begin:main
2002
 
2003
    `ifdef GUEST
2004
        skip = 1 ;
2005
    `else
2006
        skip = 0 ;
2007
    `endif
2008
 
2009
    pci_ctrl_offset = 12'h4 ;
2010
 
2011
    // image 1 is used for error testing, since it is always implemented
2012
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2013
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2014
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2015
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2016
 
2017
    target_address  = `BEH_TAR1_MEM_START ;
2018
    image_base      = 0 ;
2019
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2020
 
2021
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2022
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2023
    write_flags                    = 0 ;
2024 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
2025
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
2026 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2027
 
2028
    // enable master & target operation
2029
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
2030
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2031
    if ( ok !== 1 )
2032
    begin
2033
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2034
        test_fail("PCI Device Control register couldn't be written") ;
2035
        disable no_transaction ;
2036
        disable main ;
2037
    end
2038
 
2039
    // prepare image control register
2040
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
2041
    if ( ok !== 1 )
2042
    begin
2043
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2044
        test_fail("WB Image Control register couldn't be written") ;
2045
        disable no_transaction ;
2046
        disable main ;
2047
    end
2048
 
2049
    // prepare base address register
2050
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2051
    if ( ok !== 1 )
2052
    begin
2053
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2054
        test_fail("WB Base Address register couldn't be written") ;
2055
        disable no_transaction ;
2056
        disable main ;
2057
    end
2058
 
2059
    // write address mask register
2060
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2061
    if ( ok !== 1 )
2062
    begin
2063
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2064
        test_fail("WB Address Mask register couldn't be written") ;
2065
        disable no_transaction ;
2066
        disable main ;
2067
    end
2068
 
2069
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2070
 
2071
    skip = 0 ;
2072
 
2073
    // memory mapped image - access is erroneous when address is not alligned
2074
    write_data`WRITE_ADDRESS = target_address + 1 ;
2075
    write_data`WRITE_DATA    = wmem_data[0] ;
2076
    write_data`WRITE_SEL     = 4'hF ;
2077
 
2078
    // handle retries from now on
2079
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2080
 
2081
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
2082
 
2083
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2084
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2085
    begin
2086
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2087
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2088
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2089
        disable no_transaction ;
2090
        disable main ;
2091
    end
2092
 
2093
    write_data`WRITE_ADDRESS = target_address + 2 ;
2094
 
2095
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2096
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2097
    begin
2098
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2099
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2100
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2101
        disable no_transaction ;
2102
        disable main ;
2103
 
2104
    end
2105
 
2106
    write_data`WRITE_ADDRESS = target_address + 3 ;
2107
 
2108
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2109
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2110
    begin
2111
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2112
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2113
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2114
        disable no_transaction ;
2115
        disable main ;
2116
    end
2117
 
2118
    test_ok ;
2119
 
2120
    // perform same tests for read accesses
2121
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
2122
 
2123
    read_data`READ_ADDRESS  = target_address + 2 ;
2124
    read_data`READ_SEL      = 4'hF ;
2125
 
2126
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2127
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2128
    begin
2129
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2130
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2131
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
2132
        disable no_transaction ;
2133
        disable main ;
2134
    end
2135
 
2136
    test_ok ;
2137
 
2138
    // prepare write data
2139
    for ( i = 0 ; i < 6 ; i = i + 1 )
2140
    begin
2141
        write_data`WRITE_DATA    = wmem_data[i] ;
2142
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
2143
        write_data`WRITE_SEL     = 4'hF ;
2144
        wishbone_master.blk_write_data[i] = write_data ;
2145
    end
2146
 
2147
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2148
    write_flags`WB_TRANSFER_CAB    = 1 ;
2149
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2150
 
2151
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
2152
    wishbone_master.wb_block_write(write_flags, write_status) ;
2153
 
2154
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2155
    begin
2156
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2157
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2158
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
2159
        disable no_transaction ;
2160
        disable main ;
2161
    end
2162
 
2163
    // prepare read data
2164 106 mihad
 
2165 15 mihad
    for ( i = 0 ; i < 6 ; i = i + 1 )
2166
    begin
2167
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2168
        read_data`READ_SEL     = 4'hF ;
2169
        wishbone_master.blk_read_data_in[i] = read_data ;
2170
    end
2171
 
2172
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2173
    wishbone_master.wb_block_read(write_flags, read_status) ;
2174
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2175
    begin
2176
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2177
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2178
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2179
        disable no_transaction ;
2180
        disable main ;
2181
    end
2182
 
2183
    test_ok ;
2184
 
2185
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2186
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2187
 
2188
    // map image to IO space
2189
    `ifdef GUEST
2190
        skip = 1 ;
2191
    `endif
2192
 
2193
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2194
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2195
    if ( ok !== 1 )
2196
    begin
2197
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2198
        test_fail("WB Image Base Address register couldn't be written") ;
2199
        disable no_transaction ;
2200
        disable main ;
2201
    end
2202
 
2203
    skip = 0 ;
2204
 
2205 106 mihad
    write_data`WRITE_ADDRESS  = target_address ;
2206
    write_data`WRITE_DATA     = wmem_data[0] ;
2207
    write_data`WRITE_SEL      = 4'b1010 ;
2208 15 mihad
 
2209
    // don't handle retries
2210
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2211
 
2212
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2213
 
2214
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2215
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2216
    begin
2217
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2218
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2219
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2220
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2221
        disable no_transaction ;
2222
        disable main ;
2223
    end
2224
 
2225 106 mihad
    write_data`WRITE_ADDRESS  = target_address + 1 ;
2226
    write_data`WRITE_SEL      = 4'b0011 ;
2227 15 mihad
 
2228
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2229
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2230
    begin
2231
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2232
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2233
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2234
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2235
        disable no_transaction ;
2236
        disable main ;
2237
    end
2238
 
2239 106 mihad
    write_data`WRITE_SEL      = 4'b1100 ;
2240 15 mihad
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2241
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2242
    begin
2243
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2244
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2245
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2246
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2247
        disable no_transaction ;
2248
        disable main ;
2249
    end
2250
 
2251 106 mihad
    write_data`WRITE_ADDRESS  = target_address + 2 ;
2252
    write_data`WRITE_SEL      = 4'b0101 ;
2253 15 mihad
 
2254
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2255
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2256
    begin
2257
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2258
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2259
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2260
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2261
        disable no_transaction ;
2262
        disable main ;
2263
    end
2264
 
2265 106 mihad
    write_data`WRITE_SEL      = 4'b1000 ;
2266 15 mihad
 
2267
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2268
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2269
    begin
2270
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2271
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2272
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2273
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2274
        disable no_transaction ;
2275
        disable main ;
2276
    end
2277
 
2278
    write_data`WRITE_ADDRESS = target_address + 3 ;
2279
    write_data`WRITE_SEL     = 4'b1010 ;
2280
 
2281
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2282
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2283
    begin
2284
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2285
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2286
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2287
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2288
        disable no_transaction ;
2289
        disable main ;
2290
    end
2291
 
2292
    write_data`WRITE_SEL     = 4'b0110 ;
2293
 
2294
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2295
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2296
    begin
2297
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2298
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2299
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2300
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2301
        disable no_transaction ;
2302
        disable main ;
2303
    end
2304
 
2305
    test_ok ;
2306
 
2307
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2308
 
2309
    read_data`READ_ADDRESS  = target_address + 3 ;
2310
    read_data`READ_SEL      = 4'hF ;
2311
 
2312
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2313
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2314
    begin
2315
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2316
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2317
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2318
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2319
        disable no_transaction ;
2320
        disable main ;
2321
    end
2322
 
2323
    test_ok ;
2324
 
2325
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2326 106 mihad
 
2327 15 mihad
    // prepare write data
2328
    for ( i = 0 ; i < 6 ; i = i + 1 )
2329
    begin
2330
        write_data`WRITE_DATA    = wmem_data[i] ;
2331
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2332
        write_data`WRITE_SEL     = 4'hF ;
2333
        wishbone_master.blk_write_data[i] = write_data ;
2334
    end
2335
 
2336
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2337
    write_flags`WB_TRANSFER_CAB    = 1 ;
2338
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2339
 
2340
    wishbone_master.wb_block_write(write_flags, write_status) ;
2341
 
2342
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2343
    begin
2344
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2345
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2346
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2347
        disable no_transaction ;
2348
        disable main ;
2349
    end
2350
 
2351
    test_ok ;
2352
 
2353
    test_name = "CAB I/O READ TO WB SLAVE" ;
2354 106 mihad
 
2355 15 mihad
    // prepare read data
2356
    for ( i = 0 ; i < 6 ; i = i + 1 )
2357
    begin
2358
        read_data`READ_ADDRESS = target_address + 4*i ;
2359
        read_data`READ_SEL     = 4'hF ;
2360
        wishbone_master.blk_read_data_in[i] = read_data ;
2361
    end
2362
 
2363
    wishbone_master.wb_block_read(write_flags, read_status) ;
2364
 
2365
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2366
    begin
2367
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2368
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2369
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2370
        disable no_transaction ;
2371
        disable main ;
2372
    end
2373
 
2374
    test_ok ;
2375
 
2376
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2377
 
2378
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2379
 
2380 106 mihad
    begin:test_erroneous_config_access_blk
2381
        reg do_write_test ;
2382
        reg do_read_test  ;
2383 15 mihad
 
2384 106 mihad
        target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2385 15 mihad
 
2386 106 mihad
        do_write_test = 1'b0 ;
2387
        do_read_test  = 1'b0 ;
2388
 
2389 15 mihad
    `ifdef HOST
2390
 
2391 106 mihad
        do_write_test = 1'b1 ;
2392
        do_read_test  = 1'b1 ;
2393 15 mihad
 
2394 106 mihad
    `else
2395 15 mihad
 
2396 106 mihad
    `ifdef WB_CNF_IMAGE
2397 15 mihad
 
2398 106 mihad
        do_read_test = 1'b1 ;
2399 15 mihad
 
2400 106 mihad
    `endif
2401 15 mihad
 
2402
    `endif
2403 106 mihad
 
2404
    `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
2405
    `else
2406 15 mihad
 
2407 106 mihad
        if (do_write_test)
2408
        begin
2409
 
2410
            write_data`WRITE_ADDRESS  = target_address + 1 ;
2411
            write_data`WRITE_DATA     = wmem_data[0] ;
2412
            write_data`WRITE_SEL      = 4'hF ;
2413
 
2414
            // don't handle retries
2415
            write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2416 15 mihad
 
2417 106 mihad
            test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2418
            wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2419
            if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2420
            begin
2421
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2422
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2423
                test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2424
                disable no_transaction ;
2425
                disable main ;
2426
            end
2427
 
2428
            // try write to configuration cycle address register with non alligned address
2429
            write_data`WRITE_ADDRESS  = target_address + {4'h1, `CNF_ADDR_ADDR, 2'b10} ;
2430 15 mihad
 
2431 106 mihad
            wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2432
            if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2433
            begin
2434
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2435
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2436
                test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2437
                disable no_transaction ;
2438
                disable main ;
2439
            end
2440
 
2441
            write_data`WRITE_ADDRESS = target_address + {4'h1, `CNF_DATA_ADDR, 2'b11} ;
2442 15 mihad
 
2443 106 mihad
            // try write to configuration cycle data register with non alligned address
2444
            wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2445
            if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2446
            begin
2447
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2448
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2449
                test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2450
                disable no_transaction ;
2451
                disable main ;
2452
            end
2453
 
2454
            test_ok ;
2455
        end
2456 15 mihad
 
2457 106 mihad
        if (do_read_test)
2458
        begin
2459
            test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2460
            // try read from configuration cycle data register with non alligned address
2461
            read_data`READ_ADDRESS  = target_address + {4'h1, `CNF_DATA_ADDR, 2'b01} ;
2462
            read_data`READ_SEL      = 4'hF ;
2463
 
2464
            wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2465
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2466
            begin
2467
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2468
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2469
                test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2470
                disable no_transaction ;
2471
                disable main ;
2472
            end
2473
 
2474
            test_ok ;
2475
        end
2476 15 mihad
 
2477
    `endif
2478
 
2479 106 mihad
        if (do_write_test)
2480
        begin
2481
            // prepare write data
2482
            test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2483 15 mihad
 
2484 106 mihad
            for ( i = 0 ; i < 6 ; i = i + 1 )
2485
            begin
2486
                write_data`WRITE_DATA    = wmem_data[i] ;
2487
                write_data`WRITE_ADDRESS = target_address + 4*i + {4'h1, `CNF_DATA_ADDR, 2'b00};
2488
                write_data`WRITE_SEL     = 4'hF ;
2489
                wishbone_master.blk_write_data[i] = write_data ;
2490
            end
2491
 
2492
            write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2493
            write_flags`WB_TRANSFER_CAB    = 1 ;
2494
            write_flags`WB_TRANSFER_SIZE   = 6 ;
2495
 
2496
            wishbone_master.wb_block_write(write_flags, write_status) ;
2497
 
2498
            if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2499
            begin
2500
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2501
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2502
                test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2503
                disable no_transaction ;
2504
                disable main ;
2505
            end
2506
            test_ok ;
2507
        end
2508
 
2509
        if (do_read_test)
2510
        begin
2511
            // prepare read data
2512
            test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2513 15 mihad
 
2514 106 mihad
            for ( i = 0 ; i < 6 ; i = i + 1 )
2515
            begin
2516
                read_data`READ_ADDRESS = target_address + 4*i + {4'h1, `CNF_DATA_ADDR, 2'b00};
2517
                read_data`READ_SEL     = 4'hF ;
2518
                wishbone_master.blk_read_data_in[i] = read_data ;
2519
            end
2520
 
2521
            wishbone_master.wb_block_read(write_flags, read_status) ;
2522
 
2523
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2524
            begin
2525
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2526
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2527
                test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2528
                disable no_transaction ;
2529
                disable main ;
2530
            end
2531
            test_ok ;
2532
        end
2533
 
2534
        `ifdef GUEST
2535
            skip = 1 ;
2536
        `endif
2537
    end // test_erroneous_config_access_blk
2538 15 mihad
 
2539
    // disable image
2540
    test_name = "DISABLE IMAGE" ;
2541
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2542
    if ( ok !== 1 )
2543
    begin
2544
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2545
        test_fail("WB Address Mask register couldn't be written") ;
2546
        disable no_transaction ;
2547
        disable main ;
2548
    end
2549
 
2550
    skip = 0 ;
2551
 
2552
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2553
 
2554
    disable no_transaction ;
2555
end
2556
begin:no_transaction
2557
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2558
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2559
    forever
2560
    begin
2561
        @(posedge pci_clock) ;
2562
        if ( skip !== 1 )
2563
        begin
2564
            if ( FRAME !== 1 )
2565
            begin
2566
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2567
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2568
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2569
            end
2570
        end
2571
    end
2572
end
2573
join
2574
endtask //wb_slave_errors
2575
 
2576
task wb_to_pci_error_handling ;
2577
    reg   [11:0] ctrl_offset ;
2578
    reg   [11:0] ba_offset ;
2579
    reg   [11:0] am_offset ;
2580
    reg   [11:0] ta_offset ;
2581
    reg   [11:0] err_cs_offset ;
2582
    reg `WRITE_STIM_TYPE write_data ;
2583
    reg `READ_STIM_TYPE  read_data ;
2584
    reg `READ_RETURN_TYPE read_status ;
2585
 
2586
    reg `WRITE_RETURN_TYPE write_status ;
2587
    reg `WB_TRANSFER_FLAGS write_flags ;
2588
    reg [31:0] temp_val1 ;
2589
    reg [31:0] temp_val2 ;
2590
    reg        ok   ;
2591
    reg [11:0] pci_ctrl_offset ;
2592
    reg [31:0] image_base ;
2593
    reg [31:0] target_address ;
2594
    integer    num_of_trans ;
2595
    integer    current ;
2596
    integer    i ;
2597
begin:main
2598
 
2599
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2600
 
2601
    pci_ctrl_offset = 12'h4 ;
2602
 
2603
    // disable error interrupts and disable error reporting
2604
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2605
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2606
    if ( ok !== 1 )
2607
    begin
2608
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2609
        test_fail("PCI Device Control register couldn't be written") ;
2610
        disable main ;
2611
    end
2612
 
2613
    // image 1 is used for error testing, since it is always implemented
2614
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2615
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2616
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2617
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2618
 
2619
    // set master abort testing address to address that goes out of target's range
2620
    target_address  = `BEH_TAR1_MEM_START ;
2621
    image_base      = 0 ;
2622
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2623
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2624
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2625
 
2626
    write_flags                    = 0 ;
2627 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
2628
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
2629 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2630
 
2631
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2632
 
2633
    // enable master & target operation
2634
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2635
    if ( ok !== 1 )
2636
    begin
2637
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2638
        test_fail("PCI Device Control register couldn't be written") ;
2639
        disable main ;
2640
    end
2641
 
2642
    // prepare image control register
2643
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2644
    if ( ok !== 1 )
2645
    begin
2646
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2647
        test_fail("WB Image Control register couldn't be written") ;
2648
        disable main ;
2649
    end
2650
 
2651
    // prepare base address register
2652
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2653
    if ( ok !== 1 )
2654
    begin
2655
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2656
        test_fail("WB Image Base Address register couldn't be written") ;
2657
        disable main ;
2658
    end
2659
 
2660
    // write address mask register
2661
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2662
    if ( ok !== 1 )
2663
    begin
2664
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2665
        test_fail("WB Image Address Mask register couldn't be written") ;
2666
        disable main ;
2667
    end
2668
 
2669
    // disable error reporting
2670
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2671
    if ( ~ok )
2672
    begin
2673
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2674
        test_fail("WB Error Control and Status register couldn't be written") ;
2675
        disable main ;
2676
    end
2677
 
2678
    // perform two writes - one to error address and one to OK address
2679
    // prepare write buffer
2680
 
2681 106 mihad
    write_data`WRITE_ADDRESS  = target_address ;
2682
    write_data`WRITE_DATA     = wmem_data[100] ;
2683
    write_data`WRITE_SEL      = 4'hF ;
2684 15 mihad
 
2685
    wishbone_master.blk_write_data[0] = write_data ;
2686
 
2687
    write_flags`WB_TRANSFER_SIZE = 2 ;
2688
 
2689
    // don't handle retries
2690
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2691
    write_flags`WB_TRANSFER_CAB    = 0 ;
2692
 
2693
    $display("Introducing master abort error on single WB to PCI write!") ;
2694
 
2695
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2696
    // first disable target 1
2697
 
2698 45 mihad
    configuration_cycle_write(0,                        // bus number
2699
                              `TAR1_IDSEL_INDEX - 11,   // device number
2700
                              0,                        // function number
2701
                              1,                        // register number
2702
                              0,                        // type of configuration cycle
2703
                              4'b0001,                  // byte enables
2704
                              32'h0000_0000             // data
2705 15 mihad
                             ) ;
2706
 
2707
    fork
2708
    begin
2709
        // start no response monitor in parallel with writes
2710
        musnt_respond(ok) ;
2711
        if ( ok !== 1 )
2712
        begin
2713
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2714
            $display("Testbench is configured wrong!") ;
2715
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2716
        end
2717
        else
2718
            test_ok ;
2719
    end
2720
    begin
2721
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2722
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2723
       begin
2724
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2725
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2726
           test_fail("WB Slave state machine failed to post single memory write");
2727
           disable main ;
2728
       end
2729
    end
2730
    join
2731
 
2732 92 mihad
    // read data from second write
2733 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2734
    read_data`READ_ADDRESS = target_address ;
2735
    read_data`READ_SEL     = 4'hF ;
2736
 
2737
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2738
 
2739
    if ( read_status`READ_DATA !== wmem_data[101] )
2740
    begin
2741
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2742
    end
2743
 
2744
    // read error status register - no errors should be reported since reporting was disabled
2745
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2746
 
2747
    @(posedge pci_clock) ;
2748
    // wait for two WB clocks for synchronization to be finished
2749
    repeat (2)
2750
        @(posedge wb_clock) ;
2751
 
2752
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2753
    if ( temp_val1[8] !== 0 )
2754
    begin
2755
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2756
        $display("Error reporting was disabled, but error was reported anyway!") ;
2757
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2758
        disable main ;
2759
    end
2760
    test_ok ;
2761
 
2762
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2763
    // check for interrupts - there should be no interrupt requests active
2764
    `ifdef HOST
2765
        repeat(4)
2766
            @(posedge wb_clock) ;
2767
 
2768
        if ( INT_O !== 0 )
2769
        begin
2770
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2771
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2772
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2773
        end
2774
        else
2775
            test_ok ;
2776
    `else
2777
    `ifdef GUEST
2778
        repeat( 4 )
2779
            @(posedge pci_clock) ;
2780
 
2781
        if ( INTA !== 1 )
2782
        begin
2783
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2784
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2785
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2786
        end
2787
        else
2788
            test_ok ;
2789
    `endif
2790
    `endif
2791
 
2792
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2793
    // check PCI status register
2794
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2795
    if ( temp_val1[29] !== 1 )
2796
    begin
2797
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2798
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2799
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2800
    end
2801
    else
2802
        test_ok ;
2803
 
2804
    // clear
2805
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2806
 
2807
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2808
 
2809
    $display("Introducing master abort error to CAB write!") ;
2810
    // now enable error reporting mechanism
2811
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2812
    // enable error interrupts
2813
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2814
 
2815
    // configure flags for CAB transfer
2816
    write_flags`WB_TRANSFER_CAB = 1 ;
2817
    write_flags`WB_TRANSFER_SIZE = 3 ;
2818
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2819
 
2820
    // prepare data for erroneous write
2821
    for ( i = 0 ; i < 3 ; i = i + 1 )
2822
    begin
2823
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2824
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2825
        write_data`WRITE_SEL     = 4'hF ;
2826
        wishbone_master.blk_write_data[i] = write_data ;
2827
    end
2828 106 mihad
 
2829 15 mihad
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2830
    fork
2831
    begin
2832
        wishbone_master.wb_block_write(write_flags, write_status) ;
2833
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2834
        begin
2835
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2836
            $display("Complete burst write through WB slave didn't succeed!") ;
2837
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2838
            disable main ;
2839
        end
2840
    end
2841
    begin
2842
        musnt_respond(ok) ;
2843
        if ( ok !== 1 )
2844
        begin
2845
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2846
            $display("Testbench is configured wrong!") ;
2847
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2848
        end
2849
        else
2850
            test_ok ;
2851
    end
2852
    join
2853
 
2854
    // check error status address, data, byte enables and bus command
2855
    // error status bit is signalled on PCI clock and synchronized to WB clock
2856
    // wait one PCI clock cycle
2857
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2858
    ok = 1 ;
2859
    @(posedge pci_clock) ;
2860
 
2861
    // wait for two WB clocks for synchronization to be finished
2862
    repeat (2)
2863
        @(posedge wb_clock) ;
2864
 
2865
    // read registers
2866
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2867
    if ( temp_val1[8] !== 1 )
2868
    begin
2869
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2870
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2871
        ok = 0 ;
2872
    end
2873
 
2874
    if ( temp_val1[9] !== 1 )
2875
    begin
2876
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2877
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2878
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2879
        ok = 0 ;
2880
    end
2881
 
2882
    if ( temp_val1[31:28] !== 0 )
2883
    begin
2884
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2885
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2886
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2887
        ok = 0 ;
2888
    end
2889
 
2890
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2891
    begin
2892
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2893
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2894
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2895
        ok = 0 ;
2896
    end
2897
 
2898
    // read error address register
2899
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2900
    if ( temp_val1 !== target_address )
2901
    begin
2902
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2903
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2904
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2905
        ok = 0 ;
2906
    end
2907
 
2908
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2909
    if ( temp_val1 !== wmem_data[110] )
2910
    begin
2911
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2912
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2913
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2914
        ok = 0 ;
2915
    end
2916
 
2917
    // check PCI status register
2918
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2919
    if ( temp_val1[29] !== 1 )
2920
    begin
2921
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2922
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2923
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2924
        ok = 0 ;
2925
    end
2926
 
2927
    if ( temp_val1[28] !== 0 )
2928
    begin
2929
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2930
        $display("Received Target Abort bit was set for no reason!") ;
2931
        test_fail("Received Target Abort bit was set for no reason") ;
2932
        ok = 0 ;
2933
    end
2934
 
2935
    if ( ok )
2936
        test_ok ;
2937
 
2938
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2939
 
2940
    // clear error status bit
2941
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2942
 
2943
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2944
 
2945
    ok = 1 ;
2946
 
2947
    `ifdef HOST
2948
        repeat(4)
2949
        @(posedge wb_clock) ;
2950
        if ( INT_O !== 1 )
2951
        begin
2952
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2953
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2954
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2955
            ok = 0 ;
2956
        end
2957
    `else
2958
    `ifdef GUEST
2959
        repeat(4)
2960
        @(posedge pci_clock) ;
2961
        if ( INTA !== 0 )
2962
        begin
2963
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2964
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2965
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2966
            ok = 0 ;
2967
        end
2968
    `endif
2969
    `endif
2970
 
2971
    // read interrupt status register
2972
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2973
    if ( temp_val1 !== 32'h0000_0002 )
2974
    begin
2975
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2976
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2977
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2978
        test_fail("Interrupt Status register returned wrong value") ;
2979
        ok = 0 ;
2980
    end
2981
 
2982
    if ( ok )
2983
        test_ok ;
2984
    // clear interrupt status bits
2985
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2986
 
2987
    ok = 1 ;
2988
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2989
    // wait for two clock cycles before checking interrupt request deassertion
2990
    `ifdef HOST
2991
        repeat (4)
2992
            @(posedge wb_clock) ;
2993
 
2994
        if ( INT_O !== 0 )
2995
        begin
2996
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2997
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2998
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2999
            ok = 0 ;
3000
        end
3001
    `else
3002
    `ifdef GUEST
3003
        repeat (4)
3004
            @(posedge pci_clock) ;
3005
 
3006
        if ( INTA !== 1 )
3007
        begin
3008
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3009
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
3010
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
3011
            ok = 0 ;
3012
        end
3013
    `endif
3014
    `endif
3015
 
3016
    if ( ok )
3017
        test_ok ;
3018
 
3019
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
3020
    ok = 1 ;
3021
    // enable target
3022 45 mihad
    configuration_cycle_write(0,                        // bus number
3023
                              `TAR1_IDSEL_INDEX - 11,   // device number
3024
                              0,                        // function number
3025
                              1,                        // register number
3026
                              0,                        // type of configuration cycle
3027
                              4'b0001,                  // byte enables
3028
                              32'h0000_0007             // data
3029 15 mihad
                             ) ;
3030
    // prepare data for ok write
3031
    for ( i = 0 ; i < 3 ; i = i + 1 )
3032
    begin
3033
        write_data`WRITE_ADDRESS = target_address + 4*i ;
3034
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
3035
        write_data`WRITE_SEL     = 4'hF ;
3036
        wishbone_master.blk_write_data[i] = write_data ;
3037
    end
3038 106 mihad
 
3039 15 mihad
    wishbone_master.wb_block_write(write_flags, write_status) ;
3040
 
3041
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3042
    begin
3043
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3044
        $display("Complete burst write through WB slave didn't succeed!") ;
3045
        test_fail("WB Slave state machine failed to post CAB write") ;
3046
        disable main ;
3047
    end
3048
 
3049
    // do a read
3050
    for ( i = 0 ; i < 3 ; i = i + 1 )
3051
    begin
3052
        read_data`READ_ADDRESS = target_address + 4*i ;
3053
        read_data`READ_SEL     = 4'hF ;
3054
        wishbone_master.blk_read_data_in[i] = read_data ;
3055
    end
3056
 
3057
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3058
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3059
    write_flags`WB_TRANSFER_CAB    = 1 ;
3060
 
3061
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3062
 
3063
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3064
    begin
3065
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3066
        $display("Complete burst read through WB slave didn't succeed!") ;
3067
        test_fail("Delayed CAB write was not processed as expected") ;
3068
        disable main ;
3069
    end
3070
 
3071
    for ( i = 0 ; i < 3 ; i = i + 1 )
3072
    begin
3073
        read_status = wishbone_master.blk_read_data_out[i] ;
3074
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
3075
        begin
3076
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
3077
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
3078
        end
3079
    end
3080
 
3081
    $display("Introducing master abort error to single read!") ;
3082
    // disable target
3083 45 mihad
    configuration_cycle_write(0,                        // bus number
3084
                              `TAR1_IDSEL_INDEX - 11,   // device number
3085
                              0,                        // function number
3086
                              1,                        // register number
3087
                              0,                        // type of configuration cycle
3088
                              4'b0001,                  // byte enables
3089
                              32'h0000_0000             // data
3090 15 mihad
                             ) ;
3091
    // set read data
3092 106 mihad
    read_data`READ_ADDRESS  = target_address ;
3093
    read_data`READ_SEL      = 4'hF ;
3094 15 mihad
 
3095
    // enable automatic retry handling
3096
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3097 106 mihad
    write_flags`WB_TRANSFER_CAB      = 0 ;
3098 15 mihad
 
3099
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
3100
    fork
3101
    begin
3102
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3103
    end
3104
    begin
3105
        musnt_respond(ok) ;
3106
        if ( ok !== 1 )
3107
        begin
3108
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3109
            $display("Testbench is configured wrong!") ;
3110
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3111
        end
3112
    end
3113
    join
3114
 
3115
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3116
    begin
3117
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3118
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3119
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3120
        test_fail("read didn't finish on WB bus as expected") ;
3121
        disable main ;
3122
    end
3123
 
3124
    test_ok ;
3125
 
3126
 
3127
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
3128
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
3129
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3130
    if ( temp_val1[8] !== 0 )
3131
    begin
3132
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3133
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
3134
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
3135
    end
3136
    else
3137
        test_ok ;
3138
 
3139
    // now check normal read operation
3140 45 mihad
    configuration_cycle_write(0,                        // bus number
3141
                              `TAR1_IDSEL_INDEX - 11,   // device number
3142
                              0,                        // function number
3143
                              1,                        // register number
3144
                              0,                        // type of configuration cycle
3145
                              4'b0001,                  // byte enables
3146
                              32'h0000_0007             // data
3147 15 mihad
                             ) ;
3148
 
3149 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
3150 106 mihad
    read_data`READ_ADDRESS  = target_address ;
3151
    read_data`READ_SEL      = 4'hF ;
3152 15 mihad
 
3153
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3154
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3155
    begin
3156
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3157
        $display("WB slave failed to process single read!") ;
3158
        $display("Slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3159
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
3160
        disable main ;
3161
    end
3162
 
3163
    if ( read_status`READ_DATA !== wmem_data[113] )
3164
    begin
3165
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
3166
        test_fail("when read finished on WB bus, wrong data was provided") ;
3167
    end
3168
    else
3169
        test_ok ;
3170
 
3171
    // check PCI status register
3172 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
3173 15 mihad
    ok = 1 ;
3174
 
3175
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3176
    if ( temp_val1[29] !== 1 )
3177
    begin
3178
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3179
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3180
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3181
        ok = 0 ;
3182
    end
3183
 
3184
    if ( temp_val1[28] !== 0 )
3185
    begin
3186
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3187
        $display("Received Target Abort bit was set for no reason!") ;
3188
        test_fail("Received Target Abort bit was set for no reason") ;
3189
        ok = 0 ;
3190
    end
3191
    if ( ok )
3192
        test_ok ;
3193
 
3194
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3195
 
3196
    $display("Introducing master abort error to CAB read!") ;
3197
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3198
 
3199 45 mihad
    configuration_cycle_write(0,                        // bus number
3200
                              `TAR1_IDSEL_INDEX - 11,   // device number
3201
                              0,                        // function number
3202
                              1,                        // register number
3203
                              0,                        // type of configuration cycle
3204
                              4'b0001,                  // byte enables
3205
                              32'h0000_0000             // data
3206 15 mihad
                             ) ;
3207
 
3208 106 mihad
 
3209 15 mihad
    for ( i = 0 ; i < 3 ; i = i + 1 )
3210
    begin
3211
        read_data`READ_ADDRESS = target_address + 4*i ;
3212
        read_data`READ_SEL     = 4'hF ;
3213
        wishbone_master.blk_read_data_in[i] = read_data ;
3214
    end
3215
 
3216
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3217 106 mihad
    write_flags`WB_TRANSFER_SIZE     = 3 ;
3218
    write_flags`WB_TRANSFER_CAB      = 1 ;
3219 15 mihad
 
3220
    fork
3221
    begin
3222
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3223
    end
3224
    begin
3225
        musnt_respond(ok) ;
3226
        if ( ok !== 1 )
3227
        begin
3228
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3229
            $display("Testbench is configured wrong!") ;
3230
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3231
        end
3232
    end
3233
    join
3234
 
3235
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3236
    begin
3237
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3238
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3239
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3240
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3241
        disable main ;
3242
    end
3243
    else
3244
        test_ok ;
3245
 
3246
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3247
    ok = 1 ;
3248
    // check PCI status register
3249
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3250
    if ( temp_val1[29] !== 1 )
3251
    begin
3252
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3253
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3254
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3255
        ok = 0 ;
3256
    end
3257
 
3258
    if ( temp_val1[28] !== 0 )
3259
    begin
3260
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3261
        $display("Received Target Abort bit was set for no reason!") ;
3262
        test_fail("Received Target Abort bit was set for no reason") ;
3263
        ok = 0 ;
3264
    end
3265
 
3266
    if ( ok )
3267
        test_ok ;
3268
 
3269
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3270
 
3271
    $display("Introducing target abort termination to single write!") ;
3272
 
3273
    // disable error reporting and interrupts
3274
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3275
 
3276 45 mihad
    configuration_cycle_write(0,                        // bus number
3277
                              `TAR1_IDSEL_INDEX - 11,   // device number
3278
                              0,                        // function number
3279
                              1,                        // register number
3280
                              0,                        // type of configuration cycle
3281
                              4'b0001,                  // byte enables
3282
                              32'h0000_0007             // data
3283 15 mihad
                             ) ;
3284
 
3285
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3286
    if ( ok !== 1 )
3287
    begin
3288
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3289
        test_fail("WB Error Control and Status register couldn't be written to") ;
3290
        disable main ;
3291
    end
3292
 
3293
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3294
    if ( ok !== 1 )
3295
    begin
3296
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3297
        test_fail("Interrupt Control register couldn't be written to") ;
3298
        disable main ;
3299
    end
3300
 
3301
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3302
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3303
 
3304
    write_data`WRITE_ADDRESS = target_address ;
3305
    write_data`WRITE_DATA    = wmem_data[0] ;
3306
    write_data`WRITE_SEL     = 4'hF ;
3307
 
3308
    wishbone_master.blk_write_data[0] = write_data ;
3309
 
3310
    write_data`WRITE_ADDRESS = target_address + 4;
3311
    write_data`WRITE_DATA    = wmem_data[1] ;
3312
    write_data`WRITE_SEL     = 4'hF ;
3313
 
3314
    wishbone_master.blk_write_data[1] = write_data ;
3315
 
3316
    write_flags`WB_TRANSFER_SIZE = 2 ;
3317
 
3318
    // don't handle retries
3319
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3320
    write_flags`WB_TRANSFER_CAB    = 0 ;
3321
 
3322
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3323
    fork
3324
    begin
3325
        wishbone_master.wb_block_write(write_flags, write_status) ;
3326
 
3327
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3328
        begin
3329
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3330
            $display("Image writes were not accepted as expected!") ;
3331
            $display("Slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACTUAL_TRANSFER, write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
3332
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3333
            disable main ;
3334
        end
3335
 
3336
        // read data back to see, if it was written OK
3337
        read_data`READ_ADDRESS         = target_address + 4;
3338
        read_data`READ_SEL             = 4'hF ;
3339
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3340
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3341
    end
3342
    begin
3343
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3344
        if ( ok !== 1 )
3345
        begin
3346
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3347
        end
3348
        else
3349
            test_ok ;
3350
 
3351
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3352
 
3353
        // when first transaction finishes - enable normal target response!
3354
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3355
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3356
 
3357
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3358
        if ( ok !== 1 )
3359
        begin
3360
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3361
        end
3362
        else
3363
            test_ok ;
3364
 
3365
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3366
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3367
        if ( ok !== 1 )
3368
        begin
3369
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3370
        end
3371
    end
3372
    join
3373
 
3374
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3375
    begin
3376
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3377
        $display("Bridge failed to process single read after target abort terminated write!") ;
3378
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3379
        disable main ;
3380
    end
3381
 
3382
    if ( read_status`READ_DATA !== wmem_data[1] )
3383
    begin
3384
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3385
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3386
    end
3387
    else
3388
        test_ok ;
3389
 
3390
    // check interrupt and error statuses!
3391
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3392
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3393
    if ( temp_val1[8] !== 0 )
3394
    begin
3395
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3396
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3397
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3398
    end
3399
    else
3400
        test_ok ;
3401
 
3402
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3403
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3404
    if ( temp_val1[1] !== 0 )
3405
    begin
3406
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3407
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3408
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3409
    end
3410
    else
3411
        test_ok ;
3412
 
3413
    // check PCI status register
3414
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3415
    ok = 1 ;
3416
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3417
    if ( temp_val1[29] !== 0 )
3418
    begin
3419
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3420
        $display("Received Master Abort bit was set with no reason!") ;
3421
        test_fail("Received Master Abort bit was set with no reason") ;
3422
        ok = 0 ;
3423
    end
3424
 
3425
    if ( temp_val1[28] !== 1 )
3426
    begin
3427
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3428
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3429
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3430
        ok = 0 ;
3431
    end
3432
 
3433
    if ( ok )
3434
        test_ok ;
3435
 
3436
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3437
 
3438
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3439
 
3440
    $display("Introducing target abort termination to CAB write!") ;
3441
    // enable error reporting mechanism
3442
 
3443
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3444
    if ( ok !== 1 )
3445
    begin
3446
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3447
        test_fail("WB Error Control and Status register could not be written to") ;
3448
        disable main ;
3449
    end
3450
 
3451
    for ( i = 0 ; i < 3 ; i = i + 1 )
3452
    begin
3453
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3454
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3455
        write_data`WRITE_SEL     = 4'b1010 ;
3456
        wishbone_master.blk_write_data[i] = write_data ;
3457
    end
3458
 
3459
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3460
    write_flags`WB_TRANSFER_CAB    = 1 ;
3461
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3462
 
3463
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3464
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3465
 
3466
    fork
3467
    begin
3468
        wishbone_master.wb_block_write(write_flags, write_status) ;
3469
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3470
        begin
3471
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3472
            $display("Bridge failed to process complete CAB write!") ;
3473
            test_fail("bridge failed to post CAB Memory Write") ;
3474
            disable main ;
3475
        end
3476
    end
3477
    begin
3478
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3479
        if ( ok !== 1 )
3480
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3481
        else
3482
            test_ok ;
3483
    end
3484
    join
3485
 
3486
    // check statuses and data from error
3487
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3488
    ok = 1 ;
3489
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3490
    if ( temp_val1[8] !== 1 )
3491
    begin
3492
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3493
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3494
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3495
        ok = 0 ;
3496
    end
3497
 
3498
    if ( temp_val1[9] !== 0 )
3499
    begin
3500
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3501
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3502
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3503
        ok = 0 ;
3504
    end
3505
 
3506
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3507
    begin
3508
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3509
        $display("Value in W_ERR_CS register was wrong!") ;
3510
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3511 106 mihad
        test_fail("BE Field didn't provide expected value") ;
3512 15 mihad
        ok = 0 ;
3513
    end
3514
 
3515
    if ( ok )
3516
        test_ok ;
3517
 
3518
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3519
    ok = 1 ;
3520
    // check erroneous address and data
3521
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3522
    if ( temp_val1 !== (target_address + 8) )
3523
    begin
3524
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3525
        $display("Value in W_ERR_ADDR register was wrong!") ;
3526
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3527
        test_fail("Value in WB Erroneous Address register was wrong") ;
3528
        ok = 0 ;
3529
    end
3530
 
3531
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3532 106 mihad
 
3533
    // mask expected and actual values, since all byte enables were not active
3534
    if ( (temp_val1 & 32'hff_00_ff_00) !== (wmem_data[120] & 32'hff_00_ff_00) )
3535 15 mihad
    begin
3536
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3537
        $display("Value in W_ERR_DATA register was wrong!") ;
3538 106 mihad
        $display("Expected value = %h, actual value = %h " , wmem_data[120] & 32'hff_00_ff_00, temp_val1 & 32'hff_00_ff_00) ;
3539 15 mihad
        test_fail("Value in WB Erroneous Data register was wrong") ;
3540
        ok = 0 ;
3541
    end
3542
 
3543
    if ( ok )
3544
        test_ok ;
3545
 
3546
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3547
    ok = 1 ;
3548
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3549
    if ( temp_val1[29] !== 0 )
3550
    begin
3551
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3552
        $display("Received Master Abort bit was set with no reason!") ;
3553
        test_fail("Received Master Abort bit was set for no reason") ;
3554
        ok = 0 ;
3555
    end
3556
 
3557
    if ( temp_val1[28] !== 1 )
3558
    begin
3559
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3560
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3561
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3562
        ok = 0 ;
3563
    end
3564
 
3565
    if ( ok )
3566
        test_ok ;
3567
 
3568
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3569
 
3570
    // clear error status bit and enable error interrupts
3571
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3572
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3573
 
3574
    // check if error bit was cleared
3575
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3576
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3577
    if ( temp_val1[8] !== 0 )
3578
    begin
3579
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3580
        $display("Error bit was not cleared even though one was written to its location!") ;
3581
        test_fail("Error bit was not cleared even though one was written to its location") ;
3582
    end
3583
 
3584
    // repeat same write with different target configuration
3585
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3586
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3587
 
3588
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3589
    fork
3590
    begin
3591
        write_flags`WB_TRANSFER_SIZE = 2 ;
3592
        wishbone_master.wb_block_write(write_flags, write_status) ;
3593
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3594
        begin
3595
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3596
            $display("Bridge failed to process complete CAB write!") ;
3597
            test_fail("bridge failed to post CAB Memory Write") ;
3598
            disable main ;
3599
        end
3600
 
3601
        write_flags`WB_TRANSFER_SIZE = 3 ;
3602
        wishbone_master.wb_block_write(write_flags, write_status) ;
3603
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3604
        begin
3605
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3606
            $display("Bridge failed to process complete CAB write!") ;
3607
            test_fail("bridge failed to post CAB Memory Write") ;
3608
            disable main ;
3609
        end
3610
    end
3611
    begin
3612
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3613
        if ( ok !== 1 )
3614
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3615
        else
3616
        begin
3617
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3618
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3619
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3620
            if ( ok !== 1 )
3621
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3622
            else
3623
                test_ok ;
3624
        end
3625
    end
3626
    join
3627
 
3628
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3629
    ok = 1 ;
3630
    // check statuses and data from error
3631
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3632
    if ( temp_val1[8] !== 1 )
3633
    begin
3634
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3635
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3636
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3637
        ok = 0 ;
3638
    end
3639
 
3640
    if ( temp_val1[9] !== 0 )
3641
    begin
3642
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3643
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3644
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3645
        ok = 0 ;
3646
    end
3647
 
3648
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3649
    begin
3650
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3651
        $display("Value in W_ERR_CS register was wrong!") ;
3652 106 mihad
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3653 15 mihad
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3654
        ok = 0 ;
3655
    end
3656
 
3657
    if ( ok )
3658
        test_ok ;
3659
 
3660
    // check erroneous address and data
3661
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3662
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3663
    ok = 1 ;
3664
    if ( temp_val1 !== (target_address + 8 + 4) )
3665
    begin
3666
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3667
        $display("Value in W_ERR_ADDR register was wrong!") ;
3668
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3669
        test_fail("Value in WB Erroneous Address register was wrong") ;
3670
        ok = 0 ;
3671
 
3672
    end
3673
 
3674
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3675 106 mihad
    if ( (temp_val1 & 32'hFF_00_FF_00) !== (wmem_data[121] & 32'hFF_00_FF_00) )
3676 15 mihad
    begin
3677
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3678
        $display("Value in W_ERR_DATA register was wrong!") ;
3679 106 mihad
        $display("Expected value = %h, actual value = %h " , wmem_data[121] & 32'hFF_00_FF_00, temp_val1 & 32'hFF_00_FF_00) ;
3680 15 mihad
        test_fail("Value in WB Erroneous Data register was wrong") ;
3681
        ok = 0 ;
3682
    end
3683
 
3684
    if ( ok )
3685
        test_ok ;
3686
 
3687
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3688
    `ifdef HOST
3689
        repeat(4)
3690
            @(posedge wb_clock) ;
3691
        if ( INT_O !== 1 )
3692
        begin
3693
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3694
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3695
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3696
        end
3697
        else
3698
            test_ok ;
3699
    `else
3700
    `ifdef GUEST
3701
        repeat(4)
3702
            @(posedge pci_clock) ;
3703
        if ( INTA !== 0 )
3704
        begin
3705
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3706
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3707
            test_fail("interrupt request was not presented on PCI bus") ;
3708
        end
3709
        else
3710
            test_ok ;
3711
    `endif
3712
    `endif
3713
 
3714
    // read interrupt status register
3715
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3716
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3717
    if ( temp_val1[1] !== 1 )
3718
    begin
3719
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3720
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3721
        test_fail("Expected Interrupt status bit wasn't set") ;
3722
    end
3723
 
3724
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3725
 
3726
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3727
    ok = 1 ;
3728
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3729
    if ( temp_val1[29] !== 0 )
3730
    begin
3731
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3732
        $display("Received Master Abort bit was set with no reason!") ;
3733
        test_fail("Received Master Abort bit was set with no reason") ;
3734
        ok = 0 ;
3735
    end
3736
 
3737
    if ( temp_val1[28] !== 1 )
3738
    begin
3739
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3740
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3741
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3742
        ok = 0 ;
3743
    end
3744
 
3745
    if ( ok )
3746
        test_ok ;
3747
 
3748
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3749
 
3750
    // clear interrupts and errors
3751
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3752
    repeat( 3 )
3753
        @(posedge pci_clock) ;
3754
 
3755
    repeat( 2 )
3756
        @(posedge wb_clock) ;
3757
 
3758
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3759
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3760
    if ( temp_val1[1] !== 0 )
3761
    begin
3762
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3763
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3764
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3765
    end
3766
    else
3767
        test_ok ;
3768
 
3769
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3770
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3771
    if ( temp_val1[8] !== 0 )
3772
    begin
3773
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3774
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3775
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3776
    end
3777
 
3778
 
3779
    $display("Introducing Target Abort error to single read!") ;
3780
    // set read data
3781
    read_data`READ_ADDRESS = target_address + 8 ;
3782
    read_data`READ_SEL     = 4'hF ;
3783
 
3784
    // enable automatic retry handling
3785
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3786
    write_flags`WB_TRANSFER_CAB    = 0 ;
3787
 
3788
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3789
 
3790
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3791
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3792
 
3793
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3794
 
3795
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3796
    begin
3797
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3798
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3799
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3800
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3801
        disable main ;
3802
    end
3803
    else
3804
        test_ok ;
3805
 
3806
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3807
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3808
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3809
    if ( temp_val1[8] !== 0 )
3810
    begin
3811
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3812
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3813
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3814
    end
3815
    else
3816
        test_ok ;
3817
 
3818
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3819
    ok = 1 ;
3820
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3821
    if ( temp_val1[29] !== 0 )
3822
    begin
3823
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3824
        $display("Received Master Abort bit was set with no reason!") ;
3825
        test_fail("Received Master Abort bit was set with no reason") ;
3826
        ok = 0 ;
3827
    end
3828
 
3829
    if ( temp_val1[28] !== 1 )
3830
    begin
3831
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3832
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3833
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3834
        ok = 0 ;
3835
    end
3836
 
3837
    if ( ok )
3838
        test_ok ;
3839
 
3840
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3841
 
3842
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3843
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3844
    if ( temp_val1[1] !== 0 )
3845
    begin
3846
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3847
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3848
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3849
    end
3850
    else
3851
        test_ok ;
3852
 
3853
    $display("Introducing Target Abort error to CAB read!") ;
3854
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3855
 
3856
    for ( i = 0 ; i < 4 ; i = i + 1 )
3857
    begin
3858
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3859
        read_data`READ_SEL     = 4'b1010 ;
3860
        wishbone_master.blk_read_data_in[i] = read_data ;
3861
    end
3862
 
3863
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3864
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3865
    write_flags`WB_TRANSFER_CAB    = 1 ;
3866
 
3867
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3868
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3869
 
3870
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3871
 
3872
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3873
    begin
3874
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3875
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3876
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3877
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3878
        disable main ;
3879
    end
3880
 
3881
    read_status = wishbone_master.blk_read_data_out[0] ;
3882
    temp_val1 = read_status`READ_DATA ;
3883
    temp_val2 = wmem_data[120] ;
3884
 
3885
    // last write to this address was with only two byte enables - check only those
3886
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3887
    begin
3888
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3889
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3890
    end
3891
    else
3892
        test_ok ;
3893
 
3894
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3895
    ok = 1 ;
3896
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3897
    if ( temp_val1[29] !== 0 )
3898
    begin
3899
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3900
        $display("Received Master Abort bit was set with no reason!") ;
3901
        test_fail("Received Master Abort bit was set with no reason") ;
3902
        ok = 0 ;
3903
    end
3904
 
3905
    if ( temp_val1[28] !== 1 )
3906
    begin
3907
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3908
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3909
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3910
        ok = 0 ;
3911
    end
3912
 
3913
    if ( ok )
3914
       test_ok ;
3915
 
3916
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3917
 
3918
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3919
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3920
 
3921
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3922
    for ( i = 0 ; i < 3 ; i = i + 1 )
3923
    begin
3924
        read_data`READ_ADDRESS = target_address + 4*i ;
3925
        read_data`READ_SEL     = 4'b1111 ;
3926
        wishbone_master.blk_read_data_in[i] = read_data ;
3927
    end
3928
 
3929
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3930
 
3931
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3932
 
3933
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3934
    begin
3935
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3936
        $display("Complete burst read through WB slave didn't succeed!") ;
3937
        test_fail("bridge didn't process Burst Read in an expected way") ;
3938
        disable main ;
3939
    end
3940
    else
3941
        test_ok ;
3942
 
3943
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3944
 
3945
    for ( i = 0 ; i < 3 ; i = i + 1 )
3946
    begin
3947
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3948
        read_data`READ_SEL     = 4'b1111 ;
3949
        wishbone_master.blk_read_data_in[i] = read_data ;
3950
    end
3951
 
3952
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3953
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3954
    write_flags`WB_TRANSFER_CAB    = 1 ;
3955
 
3956
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3957
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3958
 
3959
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3960
 
3961
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3962
    begin
3963
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3964
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3965
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3966
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3967
        disable main ;
3968
    end
3969
 
3970
    for ( i = 0 ; i < 3 ; i = i + 1 )
3971
    begin
3972
        ok = 1 ;
3973
        read_status = wishbone_master.blk_read_data_out[i] ;
3974
        temp_val1 = read_status`READ_DATA ;
3975
        temp_val2 = wmem_data[120 + i] ;
3976
 
3977
        // last write to this address was with only two byte enables - check only those
3978
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3979
        begin
3980
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3981
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3982
            ok = 0 ;
3983
        end
3984
    end
3985
 
3986
    if ( ok )
3987
        test_ok ;
3988
 
3989
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3990
    ok = 1 ;
3991
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3992
    if ( temp_val1[29] !== 0 )
3993
    begin
3994
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3995
        $display("Received Master Abort bit was set with no reason!") ;
3996
        test_fail("Received Master Abort bit was set with no reason") ;
3997
        ok = 0 ;
3998
    end
3999
 
4000
    if ( temp_val1[28] !== 1 )
4001
    begin
4002
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4003
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
4004
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
4005
        ok = 0 ;
4006
    end
4007
 
4008
    if ( ok )
4009
       test_ok ;
4010
 
4011
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4012
 
4013
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
4014
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
4015
 
4016
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
4017
    for ( i = 0 ; i < 3 ; i = i + 1 )
4018
    begin
4019
        read_data`READ_ADDRESS = target_address + 4*i ;
4020
        read_data`READ_SEL     = 4'b1111 ;
4021
        wishbone_master.blk_read_data_in[i] = read_data ;
4022
    end
4023
 
4024
    write_flags`WB_TRANSFER_SIZE   = 3 ;
4025
 
4026
    wishbone_master.wb_block_read( write_flags, read_status ) ;
4027
 
4028
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
4029
    begin
4030
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4031
        $display("Complete burst read through WB slave didn't succeed!") ;
4032
        test_fail("bridge didn't process Burst Read in an expected way") ;
4033
        disable main ;
4034
    end
4035
    else
4036
        test_ok ;
4037
 
4038
    // test error on IO write
4039
    // change base address
4040
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
4041
    write_data`WRITE_SEL     = 4'b0101 ;
4042
    write_data`WRITE_ADDRESS = target_address ;
4043
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
4044
 
4045
    write_flags`WB_TRANSFER_CAB    = 0 ;
4046
    write_flags`WB_TRANSFER_SIZE   = 1 ;
4047
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4048
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
4049
    fork
4050
    begin
4051
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
4052
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4053
        begin
4054
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
4055
            $display("WB slave failed to accept IO write!") ;
4056
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
4057
            disable main ;
4058
        end
4059
    end
4060
    begin
4061
        musnt_respond(ok) ;
4062
        if ( ok !== 1 )
4063
        begin
4064
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
4065
            $display("Testbench is configured wrong!") ;
4066
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
4067
        end
4068
        else
4069
            test_ok ;
4070
    end
4071
    join
4072
 
4073
    // check statuses and everything else
4074
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4075
    ok = 1 ;
4076
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
4077
    if ( temp_val1[8] !== 1 )
4078
    begin
4079
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4080
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
4081
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
4082
        ok = 0 ;
4083
    end
4084
 
4085
    if ( temp_val1[9] !== 1 )
4086
    begin
4087
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4088
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
4089
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
4090
        ok = 0 ;
4091
    end
4092
 
4093
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
4094
    begin
4095
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4096
        $display("Value in W_ERR_CS register was wrong!") ;
4097
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
4098
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
4099
        ok = 0 ;
4100
    end
4101
 
4102
    if ( ok )
4103
        test_ok ;
4104
 
4105
    // check erroneous address and data
4106
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
4107
    ok = 1 ;
4108
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4109
    if ( temp_val1 !== target_address )
4110
    begin
4111
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4112
        $display("Value in W_ERR_ADDR register was wrong!") ;
4113
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
4114
        test_fail("WB Erroneous Address register didn't provide right value") ;
4115
        ok = 0 ;
4116
    end
4117
 
4118
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4119 106 mihad
    if ( (temp_val1 & 32'h00_ff_00_ff) !== 32'h00AA_00AA )
4120 15 mihad
    begin
4121
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4122
        $display("Value in W_ERR_DATA register was wrong!") ;
4123 106 mihad
        $display("Expected value = %h, actual value = %h " , 32'h00AA_00AA, temp_val1 & 32'h00_ff_00_ff) ;
4124 15 mihad
        test_fail("WB Erroneous Data register didn't provide right value") ;
4125
        ok = 0 ;
4126
    end
4127
 
4128
    if ( ok )
4129
        test_ok ;
4130
 
4131
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4132
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
4133
    if ( temp_val1[1] !== 1 )
4134
    begin
4135
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4136
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
4137
        test_fail("expected interrupt status bit was not set") ;
4138
    end
4139
    else
4140
        test_ok ;
4141
 
4142
    // clear interrupts and errors
4143
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
4144
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
4145
 
4146
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4147
    ok = 1 ;
4148
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4149
    if ( temp_val1[29] !== 1 )
4150
    begin
4151
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4152
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
4153
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
4154
        ok = 0 ;
4155
    end
4156
 
4157
    if ( temp_val1[28] !== 0 )
4158
    begin
4159
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4160
        $display("Received Target Abort bit was set for no reason!") ;
4161
        test_fail("Received Target Abort bit was set for no reason") ;
4162
        ok = 0 ;
4163
    end
4164
 
4165
    if ( ok )
4166
        test_ok ;
4167
 
4168
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4169
 
4170
    // disable image
4171
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4172
    if ( ok !== 1 )
4173
    begin
4174
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4175
        test_fail("WB Image Address Mask register couldn't be written") ;
4176
        disable main ;
4177
    end
4178
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
4179
 
4180
end
4181
endtask
4182
 
4183
task parity_checking ;
4184
    reg   [11:0] ctrl_offset ;
4185
    reg   [11:0] ba_offset ;
4186
    reg   [11:0] am_offset ;
4187
    reg   [11:0] ta_offset ;
4188
    reg `WRITE_STIM_TYPE write_data ;
4189
    reg `READ_STIM_TYPE  read_data ;
4190
    reg `READ_RETURN_TYPE read_status ;
4191
 
4192
    reg `WRITE_RETURN_TYPE write_status ;
4193
    reg `WB_TRANSFER_FLAGS write_flags ;
4194
    reg [31:0] temp_val1 ;
4195
    reg [31:0] temp_val2 ;
4196
    reg        ok   ;
4197
    reg [11:0] pci_ctrl_offset ;
4198
    reg [31:0] image_base ;
4199
    reg [31:0] target_address ;
4200
    reg [11:0] icr_offset ;
4201
    reg [11:0] isr_offset ;
4202
    reg [11:0] p_ba_offset ;
4203
    reg [11:0] p_am_offset ;
4204
    reg [11:0] p_ctrl_offset ;
4205
    integer    i ;
4206
    reg        perr_asserted ;
4207
begin:main
4208
    $display("******************************* Testing Parity Checker functions ********************************") ;
4209
    $display("Testing Parity Errors during Master Transactions!") ;
4210
    $display("Introducing Parity Erros to Master Writes!") ;
4211
    $fdisplay(pci_mon_log_file_desc,
4212
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4213
 
4214
    // image 1 is used for error testing, since it is always implemented
4215
    pci_ctrl_offset = 12'h004 ;
4216
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4217
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4218
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4219
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4220
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4221
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4222
 
4223
    // image 1 for PCI target
4224
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4225
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4226
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4227
 
4228
    target_address  = `BEH_TAR1_MEM_START ;
4229
    image_base      = 0 ;
4230
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4231
 
4232
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4233
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4234
    write_flags                    = 0 ;
4235 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
4236
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
4237 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4238
 
4239
    // enable master & target operation and disable parity functions
4240
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4241
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4242
    if ( ok !== 1 )
4243
    begin
4244
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4245
        test_fail("PCI Device Control register could not be written to") ;
4246
        disable main ;
4247
    end
4248
 
4249
    // prepare image control register
4250
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4251
    if ( ok !== 1 )
4252
    begin
4253
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4254
        test_fail("WB Image Control register could not be written to") ;
4255
        disable main ;
4256
    end
4257
 
4258
    // prepare base address register
4259
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4260
    if ( ok !== 1 )
4261
    begin
4262
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4263
        test_fail("WB Image Base Address register could not be written to") ;
4264
        disable main ;
4265
    end
4266
 
4267
    // write address mask register
4268
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4269
    if ( ok !== 1 )
4270
    begin
4271
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4272
        test_fail("WB Image Address Mask register could not be written to") ;
4273
        disable main ;
4274
    end
4275
 
4276
    // disable parity interrupts
4277
    config_write( icr_offset, 0, 4'hF, ok ) ;
4278
    if ( ok !== 1 )
4279
    begin
4280
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4281
        test_fail("Interrupt Control register could not be written to") ;
4282
        disable main ;
4283
    end
4284
 
4285
    write_data`WRITE_ADDRESS = target_address ;
4286
    write_data`WRITE_DATA    = wmem_data[0] ;
4287
    write_data`WRITE_SEL     = 4'b1111 ;
4288
 
4289
    // enable target's 1 response to parity errors
4290 45 mihad
    configuration_cycle_write(0,                        // bus number
4291
                              `TAR1_IDSEL_INDEX - 11,   // device number
4292
                              0,                        // function number
4293
                              1,                        // register number
4294
                              0,                        // type of configuration cycle
4295
                              4'b0001,                  // byte enables
4296
                              32'h0000_0047             // data
4297 15 mihad
                             ) ;
4298
 
4299
    // disable target's 2 response to parity errors
4300 45 mihad
    configuration_cycle_write(0,                        // bus number
4301
                              `TAR2_IDSEL_INDEX - 11,   // device number
4302
                              0,                        // function number
4303
                              1,                        // register number
4304
                              0,                        // type of configuration cycle
4305
                              4'b0001,                  // byte enables
4306
                              32'h0000_0007             // data
4307 15 mihad
                             ) ;
4308
 
4309
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4310
 
4311
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4312
    fork
4313
    begin
4314
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4315
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4316
        begin
4317
            $display("Parity checker testing failed! Time %t ", $time) ;
4318
            $display("Bridge failed to process single memory write!") ;
4319
            test_fail("bridge failed to post single WB memory write") ;
4320
            disable main ;
4321
        end
4322
    end
4323
    begin:wait_perr1
4324
        perr_asserted = 0 ;
4325
        @(posedge pci_clock) ;
4326
 
4327 35 mihad
        while ( PERR !== 0 )
4328 15 mihad
            @(posedge pci_clock) ;
4329
 
4330 35 mihad
        perr_asserted = 1 ;
4331 15 mihad
 
4332
    end
4333
    begin
4334
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4335
 
4336
        if ( ok !== 1 )
4337
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4338
 
4339 35 mihad
        repeat(2)
4340 15 mihad
            @(posedge pci_clock) ;
4341
 
4342 35 mihad
        #1 ;
4343
        if ( !perr_asserted )
4344
            disable wait_perr1 ;
4345 15 mihad
    end
4346
    join
4347
 
4348
    if ( perr_asserted && ok )
4349
    begin
4350
        test_ok ;
4351
    end
4352
    else
4353
    if ( ~perr_asserted )
4354
    begin
4355
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4356
        disable main ;
4357
    end
4358
 
4359
    // check all the statuses - if HOST is defined, wait for them to be synced
4360
    `ifdef HOST
4361
    repeat(4)
4362
        @(posedge wb_clock) ;
4363
    `endif
4364
 
4365
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4366
    ok = 1 ;
4367
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4368 45 mihad
    if ( temp_val1[31] !== 0 )
4369 15 mihad
    begin
4370
        $display("Parity checker testing failed! Time %t ", $time) ;
4371 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4372
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4373 15 mihad
        ok = 0 ;
4374
    end
4375
 
4376
    if ( temp_val1[30] !== 0 )
4377
    begin
4378
        $display("Parity checker testing failed! Time %t ", $time) ;
4379
        $display("Signalled System Error bit was set for no reason!") ;
4380
        test_fail("Signalled System Error bit was set for no reason") ;
4381
        ok = 0 ;
4382
    end
4383
 
4384
    if ( temp_val1[24] !== 0 )
4385
    begin
4386
        $display("Parity checker testing failed! Time %t ", $time) ;
4387
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4388
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4389
        ok = 0 ;
4390
    end
4391
 
4392
    if ( ok )
4393
        test_ok ;
4394
 
4395
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4396
    // clear parity bits and enable parity response
4397
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4398
    if ( ok !== 1 )
4399
    begin
4400
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4401
        test_fail("write to PCI Status Register failed") ;
4402
        disable main ;
4403
    end
4404
 
4405
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4406
    fork
4407
    begin
4408
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4409
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4410
        begin
4411
            $display("Parity checker testing failed! Time %t ", $time) ;
4412
            $display("Bridge failed to process single memory write!") ;
4413
            test_fail("bridge failed to post single memory write") ;
4414
            disable main ;
4415
        end
4416
    end
4417
    begin:wait_perr2
4418
        perr_asserted = 0 ;
4419
        @(posedge pci_clock) ;
4420
 
4421 35 mihad
        while ( PERR !== 0 )
4422 15 mihad
            @(posedge pci_clock) ;
4423
 
4424 35 mihad
        perr_asserted = 1 ;
4425 15 mihad
 
4426
    end
4427
    begin
4428
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4429
 
4430
        if ( ok !== 1 )
4431
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4432
 
4433 35 mihad
        repeat(2)
4434 15 mihad
            @(posedge pci_clock) ;
4435
 
4436 35 mihad
        #1 ;
4437
        if (!perr_asserted)
4438
            disable wait_perr2 ;
4439 15 mihad
    end
4440
    join
4441
 
4442
    if ( perr_asserted && ok )
4443
    begin
4444
        test_ok ;
4445
    end
4446
    else
4447
    if ( ~perr_asserted )
4448
    begin
4449
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4450
        disable main ;
4451
    end
4452
 
4453
    // check all the statuses - if HOST is defined, wait for them to be synced
4454
    `ifdef HOST
4455
    repeat(4)
4456
        @(posedge wb_clock) ;
4457
    `endif
4458
 
4459
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4460
    ok = 1 ;
4461
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4462 45 mihad
    if ( temp_val1[31] !== 0 )
4463 15 mihad
    begin
4464
        $display("Parity checker testing failed! Time %t ", $time) ;
4465 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4466
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4467 15 mihad
        ok = 0 ;
4468
    end
4469
 
4470
    if ( temp_val1[30] !== 0 )
4471
    begin
4472
        $display("Parity checker testing failed! Time %t ", $time) ;
4473
        $display("Signalled System Error bit was set for no reason!") ;
4474
        test_fail("Signalled System Error bit was set for no reason") ;
4475
        ok = 0 ;
4476
    end
4477
 
4478
    if ( temp_val1[24] !== 1 )
4479
    begin
4480
        $display("Parity checker testing failed! Time %t ", $time) ;
4481 45 mihad
        $display("Master Data Parity Error bit wasn't set even though Parity Error Response bit was set and data parity error occured during Master write!") ;
4482
        test_fail("Master Data Parity Error bit wasn't set after Data Parity Error during Write on PCI bus, even though Parity Error Response bit was set") ;
4483 15 mihad
        ok = 0 ;
4484
    end
4485
 
4486
    if ( ok )
4487
        test_ok ;
4488
 
4489
    // clear status bits and disable parity error response
4490
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4491
 
4492
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4493
 
4494
    // disable perr generation and perform a write - no bits should be set
4495
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4496
    fork
4497
    begin
4498
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4499
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4500
        begin
4501
            $display("Parity checker testing failed! Time %t ", $time) ;
4502
            $display("Bridge failed to process single memory write!") ;
4503
            test_fail("bridge failed to post single memory write") ;
4504
            disable main ;
4505
        end
4506
    end
4507
    begin
4508
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4509
 
4510
        if ( ok !== 1 )
4511
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4512
        else
4513
            test_ok ;
4514
 
4515
        repeat(3)
4516
            @(posedge pci_clock) ;
4517
    end
4518
    join
4519
 
4520
    `ifdef HOST
4521
    repeat(4)
4522
        @(posedge wb_clock) ;
4523
    `endif
4524
 
4525
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4526
    ok = 1 ;
4527
 
4528
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4529
    if ( temp_val1[31] !== 0 )
4530
    begin
4531
        $display("Parity checker testing failed! Time %t ", $time) ;
4532
        $display("Detected Parity Error bit was set for no reason!") ;
4533
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4534
        ok = 0 ;
4535
    end
4536
 
4537
    if ( temp_val1[30] !== 0 )
4538
    begin
4539
        $display("Parity checker testing failed! Time %t ", $time) ;
4540
        $display("Signalled System Error bit was set for no reason!") ;
4541
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4542
        ok = 0 ;
4543
    end
4544
 
4545
    if ( temp_val1[24] !== 0 )
4546
    begin
4547
        $display("Parity checker testing failed! Time %t ", $time) ;
4548
        $display("Master Data Parity Error bit was set for no reason!") ;
4549
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4550
        ok = 0 ;
4551
    end
4552
 
4553
    if ( ok )
4554
        test_ok ;
4555
 
4556
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4557
 
4558
    read_data = 0 ;
4559
    read_data`READ_ADDRESS  = target_address ;
4560
    read_data`READ_SEL      = 4'hF ;
4561
 
4562
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4563
 
4564
    // enable parity and system error interrupts
4565
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4566
 
4567
    // enable parity error response
4568
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4569
 
4570
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4571
 
4572
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4573
    fork
4574
    begin
4575
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4576
    end
4577
    begin:wait_perr4
4578
        perr_asserted = 0 ;
4579
        @(posedge pci_clock) ;
4580 35 mihad
        while ( PERR !== 0 )
4581 15 mihad
            @(posedge pci_clock) ;
4582
 
4583 35 mihad
        perr_asserted = 1 ;
4584 15 mihad
 
4585
    end
4586
    begin
4587
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4588
 
4589
        if ( ok !== 1 )
4590
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4591
 
4592
        repeat(2)
4593
            @(posedge pci_clock) ;
4594
 
4595 35 mihad
        #1 ;
4596
        if ( !perr_asserted )
4597
            disable wait_perr4 ;
4598 15 mihad
    end
4599
    join
4600
 
4601
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4602
    begin
4603
        $display("Parity checker testing failed! Time %t ", $time) ;
4604
        $display("Bridge failed to process single memory read!") ;
4605
        test_fail("bridge didn't process single memory read correctly") ;
4606
        ok = 0 ;
4607
    end
4608
 
4609
    if ( perr_asserted && ok )
4610
    begin
4611
        test_ok ;
4612
    end
4613
    else
4614
    if ( ~perr_asserted )
4615
    begin
4616
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4617
        disable main ;
4618
    end
4619
 
4620
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4621
    // interrupt should also be present
4622
    `ifdef HOST
4623
        repeat(4)
4624 26 mihad
            @(posedge pci_clock) ;
4625
        repeat(4)
4626 15 mihad
            @(posedge wb_clock) ;
4627
 
4628
        if ( INT_O !== 1 )
4629
        begin
4630
            $display("Parity checker testing failed! Time %t ", $time) ;
4631
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4632
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4633
        end
4634
        else
4635
            test_ok ;
4636
    `else
4637
    `ifdef GUEST
4638 26 mihad
        repeat(4)
4639
            @(posedge wb_clock) ;
4640
        repeat(4)
4641 15 mihad
            @(posedge pci_clock) ;
4642
 
4643
        if ( INTA !== 1 )
4644
        begin
4645
            $display("Parity checker testing failed! Time %t ", $time) ;
4646
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4647
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4648
        end
4649
        else
4650
            test_ok ;
4651
    `endif
4652
    `endif
4653
 
4654
    // check statuses!
4655
 
4656
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4657
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4658
    ok = 1 ;
4659
 
4660
    if ( temp_val1[31] !== 1 )
4661
    begin
4662
        $display("Parity checker testing failed! Time %t ", $time) ;
4663 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4664
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4665 15 mihad
        ok = 0 ;
4666
    end
4667
 
4668
    if ( temp_val1[30] !== 0 )
4669
    begin
4670
        $display("Parity checker testing failed! Time %t ", $time) ;
4671
        $display("Signalled System Error bit was set for no reason!") ;
4672
        test_fail("Signalled System Error bit was set for no reason") ;
4673
        ok = 0 ;
4674
    end
4675
 
4676
    if ( temp_val1[24] !== 1 )
4677
    begin
4678
        $display("Parity checker testing failed! Time %t ", $time) ;
4679 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4680
        test_fail("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction and Parity Error Response was enabled") ;
4681 15 mihad
        ok = 0 ;
4682
    end
4683
 
4684
    if ( ok )
4685
        test_ok ;
4686
 
4687
    // clear statuses and disable parity error response
4688
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4689
 
4690
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4691
    ok = 1 ;
4692
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4693
 
4694
    if ( temp_val1[4] !== 0 )
4695
    begin
4696
        $display("Parity checker testing failed! Time %t ", $time) ;
4697
        $display("System error interrupt status bit set for no reason!") ;
4698
        test_fail("System error interrupt status bit set for no reason") ;
4699
        ok = 0 ;
4700
    end
4701
 
4702
    `ifdef HOST
4703
    if ( temp_val1[3] !== 1 )
4704
    begin
4705
        $display("Parity checker testing failed! Time %t ", $time) ;
4706
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4707
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4708
        ok = 0 ;
4709
    end
4710
    `else
4711
    if ( temp_val1[3] !== 0 )
4712
    begin
4713
        $display("Parity checker testing failed! Time %t ", $time) ;
4714
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4715
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4716
        ok = 0 ;
4717
    end
4718
    `endif
4719
 
4720
    if ( ok )
4721
        test_ok ;
4722
 
4723
    // clear int statuses
4724
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4725
 
4726
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4727
 
4728
    `ifdef HOST
4729
        repeat(4)
4730 26 mihad
            @(posedge pci_clock) ;
4731
        repeat(4)
4732 15 mihad
            @(posedge wb_clock) ;
4733
 
4734
        if ( INT_O !== 0 )
4735
        begin
4736
            $display("Parity checker testing failed! Time %t ", $time) ;
4737
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4738
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4739
        end
4740
        else
4741
            test_ok ;
4742
    `else
4743
    `ifdef GUEST
4744 26 mihad
        repeat(4)
4745
            @(posedge wb_clock) ;
4746
        repeat(4)
4747 15 mihad
            @(posedge pci_clock) ;
4748
 
4749
        if ( INTA !== 1 )
4750
        begin
4751
            $display("Parity checker testing failed! Time %t ", $time) ;
4752
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4753
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4754
        end
4755
        else
4756
            test_ok ;
4757
    `endif
4758
    `endif
4759
 
4760
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4761
 
4762
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4763
    fork
4764
    begin
4765
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4766
    end
4767
    begin:wait_perr5
4768
        perr_asserted = 0 ;
4769
        @(posedge pci_clock) ;
4770
        while ( PERR === 1 )
4771
            @(posedge pci_clock) ;
4772
 
4773
        perr_asserted = 1 ;
4774
        $display("Parity checker testing failed! Time %t ", $time) ;
4775 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4776
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4777 15 mihad
    end
4778
    begin
4779
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4780
        if ( ok !== 1 )
4781
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4782
 
4783
        // perr can be asserted on idle or next PCI address phase
4784
        repeat(2)
4785
            @(posedge pci_clock) ;
4786
 
4787 35 mihad
        #1 ;
4788
        if ( !perr_asserted )
4789
            disable wait_perr5 ;
4790 15 mihad
    end
4791
    join
4792
 
4793
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4794
    begin
4795
        $display("Parity checker testing failed! Time %t ", $time) ;
4796
        $display("Bridge failed to process single memory read!") ;
4797
        test_fail("bridge failed to process single memory read correctly") ;
4798
        ok = 0 ;
4799
    end
4800
 
4801
    if ( ok && !perr_asserted)
4802
        test_ok ;
4803
 
4804
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4805
 
4806
    // interrupts should not be present
4807
    `ifdef HOST
4808
        repeat( 4 )
4809 26 mihad
            @(posedge pci_clock) ;
4810
        repeat( 4 )
4811 15 mihad
            @(posedge wb_clock) ;
4812
        if ( INT_O !== 0 )
4813
        begin
4814
            $display("Parity checker testing failed! Time %t ", $time) ;
4815
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4816
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4817
        end
4818
        else
4819
            test_ok ;
4820
    `else
4821
    `ifdef GUEST
4822
        repeat( 4 )
4823 26 mihad
            @(posedge wb_clock) ;
4824
        repeat( 4 )
4825 15 mihad
            @(posedge pci_clock) ;
4826
        if ( INTA !== 1 )
4827
        begin
4828
            $display("Parity checker testing failed! Time %t ", $time) ;
4829
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4830
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4831
        end
4832
        else
4833
            test_ok ;
4834
    `endif
4835
    `endif
4836
 
4837
    // check statuses!
4838
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4839
    ok = 1 ;
4840
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4841
    if ( temp_val1[31] !== 1 )
4842
    begin
4843
        $display("Parity checker testing failed! Time %t ", $time) ;
4844 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4845 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4846
        ok = 0 ;
4847
    end
4848
 
4849
    if ( temp_val1[30] !== 0 )
4850
    begin
4851
        $display("Parity checker testing failed! Time %t ", $time) ;
4852
        $display("Signalled System Error bit was set for no reason!") ;
4853
        test_fail("Signalled System Error bit was set for no reason") ;
4854
        ok = 0 ;
4855
    end
4856
 
4857
    if ( temp_val1[24] !== 0 )
4858
    begin
4859
        $display("Parity checker testing failed! Time %t ", $time) ;
4860 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4861 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4862
        ok = 0 ;
4863
    end
4864
 
4865
    if ( ok )
4866
        test_ok ;
4867
 
4868
    // clear statuses
4869
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4870
 
4871
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4872
    ok = 1 ;
4873
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4874
 
4875
    if ( temp_val1[4] !== 0 )
4876
    begin
4877
        $display("Parity checker testing failed! Time %t ", $time) ;
4878
        $display("System error interrupt status bit set for no reason!") ;
4879
        test_fail("System error interrupt status bit set for no reason") ;
4880
        ok = 0 ;
4881
    end
4882
 
4883
    if ( temp_val1[3] !== 0 )
4884
    begin
4885
        $display("Parity checker testing failed! Time %t ", $time) ;
4886
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4887
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4888
        ok = 0 ;
4889
    end
4890
 
4891
    if ( ok )
4892
        test_ok ;
4893
 
4894
    // enable all responses to parity errors!
4895
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4896
 
4897
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4898
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4899
 
4900
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4901
 
4902
    // repeat a read
4903
    fork
4904
    begin
4905
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4906
    end
4907
    begin:wait_perr6
4908
        perr_asserted = 0 ;
4909
        @(posedge pci_clock) ;
4910
        while ( PERR === 1 )
4911
            @(posedge pci_clock) ;
4912
 
4913
        perr_asserted = 1 ;
4914
        $display("Parity checker testing failed! Time %t ", $time) ;
4915
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4916
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4917
    end
4918
    begin
4919
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4920
        if ( ok !== 1 )
4921
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4922
 
4923
        repeat(2)
4924
            @(posedge pci_clock) ;
4925
 
4926 35 mihad
        #1 ;
4927
        if ( !perr_asserted )
4928
            disable wait_perr6 ;
4929 15 mihad
    end
4930
    join
4931
 
4932
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4933
    begin
4934
        $display("Parity checker testing failed! Time %t ", $time) ;
4935
        $display("Bridge failed to process single memory read!") ;
4936
        test_fail("bridge didn't process single memory read as expected") ;
4937
        ok = 0 ;
4938
    end
4939
 
4940
    if ( ok && !perr_asserted)
4941
        test_ok ;
4942
 
4943
    // check statuses!
4944
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4945
    ok = 1 ;
4946
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4947
    if ( temp_val1[31] !== 0 )
4948
    begin
4949
        $display("Parity checker testing failed! Time %t ", $time) ;
4950
        $display("Detected Parity Error bit was set for no reason!") ;
4951
        test_fail("Detected Parity Error bit was set for no reason") ;
4952
        ok = 0 ;
4953
    end
4954
 
4955
    if ( temp_val1[30] !== 0 )
4956
    begin
4957
        $display("Parity checker testing failed! Time %t ", $time) ;
4958
        $display("Signalled System Error bit was set for no reason!") ;
4959
        test_fail("Signalled System Error bit was set for no reason") ;
4960
        ok = 0 ;
4961
    end
4962
 
4963
    if ( temp_val1[24] !== 0 )
4964
    begin
4965
        $display("Parity checker testing failed! Time %t ", $time) ;
4966
        $display("Master Data Parity Error bit was set for no reason!") ;
4967
        test_fail("Master Data Parity Error bit was set for no reason") ;
4968
        ok = 0 ;
4969
    end
4970
 
4971
    if ( ok )
4972
        test_ok ;
4973
 
4974
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4975
    ok = 1 ;
4976
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4977
 
4978
    if ( temp_val1[4] !== 0 )
4979
    begin
4980
        $display("Parity checker testing failed! Time %t ", $time) ;
4981
        $display("System error interrupt status bit set for no reason!") ;
4982
        test_fail("System error interrupt status bit set for no reason") ;
4983
        ok = 0 ;
4984
    end
4985
 
4986
    if ( temp_val1[3] !== 0 )
4987
    begin
4988
        $display("Parity checker testing failed! Time %t ", $time) ;
4989
        $display("Parity error interrupt status bit set for no reason!") ;
4990
        test_fail("Parity error interrupt status bit set for no reason") ;
4991
        ok = 0 ;
4992
    end
4993
 
4994
    if ( ok )
4995
        test_ok ;
4996
 
4997
    $display("Presenting address parity error on PCI bus!") ;
4998
    // enable parity errors - this should not affect system errors
4999
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
5000
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
5001
 
5002
    // perform PCI write
5003
    // check transaction progress
5004
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
5005
    fork
5006
    begin
5007
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5008
               target_address, 32'h1234_5678,
5009
               1, 8'h0_0, `Test_One_Zero_Target_WS,
5010
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5011
        do_pause( 1 ) ;
5012
    end
5013
    begin:wait_serr7
5014
        perr_asserted = 0 ;
5015
        @(posedge pci_clock) ;
5016
        while( SERR === 1 )
5017
            @(posedge pci_clock) ;
5018
 
5019
        perr_asserted = 1 ;
5020
        $display("Parity checker testing failed! Time %t ", $time) ;
5021
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5022
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5023
    end
5024
    begin
5025
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5026
        if ( ok !== 1 )
5027
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
5028
 
5029 35 mihad
        if ( !perr_asserted )
5030
            disable wait_serr7 ;
5031 15 mihad
    end
5032
    join
5033
 
5034
    if ( ok && !perr_asserted)
5035
        test_ok ;
5036
 
5037
    // check statuses!
5038
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5039
    ok = 1 ;
5040
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5041
    if ( temp_val1[31] !== 1 )
5042
    begin
5043
        $display("Parity checker testing failed! Time %t ", $time) ;
5044
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5045
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5046
        ok = 0 ;
5047
    end
5048
 
5049
    if ( temp_val1[30] !== 0 )
5050
    begin
5051
        $display("Parity checker testing failed! Time %t ", $time) ;
5052
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5053
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5054
        ok = 0 ;
5055
    end
5056
 
5057
    if ( temp_val1[24] !== 0 )
5058
    begin
5059
        $display("Parity checker testing failed! Time %t ", $time) ;
5060
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5061
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5062
        ok = 0 ;
5063
    end
5064
 
5065
    if ( ok )
5066
        test_ok ;
5067
 
5068
    // clear statuses
5069
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5070
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5071
    fork
5072
    begin
5073 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5074 15 mihad
        (
5075
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5076
            32'h5555_5555,      // second part of address in dual address cycle
5077
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5078
            `BC_MEM_WRITE,      // normal command
5079 92 mihad
            4'hF,               // byte enables
5080 15 mihad
            32'h1234_5678,      // data
5081
            1'b1,               // make address parity error on first phase of dual address
5082
            1'b0,               // make address parity error on second phase of dual address
5083
            ok                  // result of operation
5084
        ) ;
5085 35 mihad
        if ( !perr_asserted )
5086
            disable wait_serr8 ;
5087 15 mihad
    end
5088
    begin:wait_serr8
5089
        perr_asserted = 0 ;
5090
        @(posedge pci_clock) ;
5091
        while( SERR === 1 )
5092
            @(posedge pci_clock) ;
5093
 
5094
        perr_asserted = 1 ;
5095
        $display("Parity checker testing failed! Time %t ", $time) ;
5096
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5097
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5098
    end
5099
    join
5100
 
5101
    if ( ok && !perr_asserted)
5102
        test_ok ;
5103
 
5104
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5105
    fork
5106
    begin
5107 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5108 15 mihad
        (
5109
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5110
            32'h5555_5555,      // second part of address in dual address cycle
5111
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5112
            `BC_MEM_WRITE,      // normal command
5113 92 mihad
            4'hF,               // byte enables
5114 15 mihad
            32'h1234_5678,      // data
5115
            1'b0,               // make address parity error on first phase of dual address
5116
            1'b1,               // make address parity error on second phase of dual address
5117
            ok                  // result of operation
5118
        ) ;
5119 35 mihad
        if ( !perr_asserted )
5120
            disable wait_serr9 ;
5121 15 mihad
    end
5122
    begin:wait_serr9
5123
        perr_asserted = 0 ;
5124
        @(posedge pci_clock) ;
5125
        while( SERR === 1 )
5126
            @(posedge pci_clock) ;
5127
 
5128
        perr_asserted = 1 ;
5129
        $display("Parity checker testing failed! Time %t ", $time) ;
5130
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5131
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5132
    end
5133
    join
5134
 
5135
    if ( ok && !perr_asserted)
5136
        test_ok ;
5137
 
5138
    // check statuses!
5139
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5140
    ok = 1 ;
5141
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5142
    if ( temp_val1[31] !== 1 )
5143
    begin
5144
        $display("Parity checker testing failed! Time %t ", $time) ;
5145
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5146
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5147
        ok = 0 ;
5148
    end
5149
 
5150
    if ( temp_val1[30] !== 0 )
5151
    begin
5152
        $display("Parity checker testing failed! Time %t ", $time) ;
5153
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5154
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5155
        ok = 0 ;
5156
    end
5157
 
5158
    if ( temp_val1[24] !== 0 )
5159
    begin
5160
        $display("Parity checker testing failed! Time %t ", $time) ;
5161
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5162
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5163
        ok = 0 ;
5164
    end
5165
 
5166
    if ( ok )
5167
        test_ok ;
5168
 
5169
    // clear statuses
5170
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5171
 
5172
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5173
    fork
5174
    begin
5175 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5176 15 mihad
        (
5177
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5178
            32'h5555_5555,      // second part of address in dual address cycle
5179
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5180
            `BC_MEM_WRITE,      // normal command
5181 92 mihad
            4'hF,               // byte enables
5182 15 mihad
            32'h1234_5678,      // data
5183
            1'b1,               // make address parity error on first phase of dual address
5184
            1'b1,               // make address parity error on second phase of dual address
5185
            ok                  // result of operation
5186
        ) ;
5187 35 mihad
        if ( !perr_asserted )
5188
            disable wait_serr10 ;
5189 15 mihad
    end
5190
    begin:wait_serr10
5191
        perr_asserted = 0 ;
5192
        @(posedge pci_clock) ;
5193
        while( SERR === 1 )
5194
            @(posedge pci_clock) ;
5195
 
5196
        perr_asserted = 1 ;
5197
        $display("Parity checker testing failed! Time %t ", $time) ;
5198
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5199
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5200
    end
5201
    join
5202
 
5203
    if ( ok && !perr_asserted)
5204
        test_ok ;
5205
 
5206
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5207
 
5208
    `ifdef HOST
5209
        repeat(4)
5210 26 mihad
            @(posedge pci_clock) ;
5211
        repeat(4)
5212 15 mihad
            @(posedge wb_clock) ;
5213
        if ( INT_O !== 0 )
5214
        begin
5215
            $display("Parity checker testing failed! Time %t ", $time) ;
5216
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5217
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5218
        end
5219
        else
5220
            test_ok ;
5221
    `else
5222
    `ifdef GUEST
5223 26 mihad
        repeat(4)
5224
            @(posedge wb_clock) ;
5225
        repeat(4)
5226 15 mihad
            @(posedge pci_clock) ;
5227
 
5228
        if ( INTA !== 1 )
5229
        begin
5230
            $display("Parity checker testing failed! Time %t ", $time) ;
5231
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5232
            test_fail("GUEST bridge asserted Interrupt Request after Address Parity Error, even though SERR was disabled and PCI has other means for signaling parity errors") ;
5233
        end
5234
        else
5235
            test_ok ;
5236
    `endif
5237
    `endif
5238
 
5239
    // check statuses!
5240
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5241
    ok = 1 ;
5242
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5243
    if ( temp_val1[31] !== 1 )
5244
    begin
5245
        $display("Parity checker testing failed! Time %t ", $time) ;
5246
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5247
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5248
        ok = 0 ;
5249
    end
5250
 
5251
    if ( temp_val1[30] !== 0 )
5252
    begin
5253
        $display("Parity checker testing failed! Time %t ", $time) ;
5254
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5255
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5256
        ok = 0 ;
5257
    end
5258
 
5259
    if ( temp_val1[24] !== 0 )
5260
    begin
5261
        $display("Parity checker testing failed! Time %t ", $time) ;
5262
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5263
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5264
        ok = 0 ;
5265
    end
5266
 
5267
    if ( ok )
5268
        test_ok ;
5269
 
5270
    // clear statuses
5271
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5272
 
5273
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5274
    ok = 1 ;
5275
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5276
 
5277
    if ( temp_val1[4] !== 0 )
5278
    begin
5279
        $display("Parity checker testing failed! Time %t ", $time) ;
5280
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5281
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5282
        ok = 0 ;
5283
    end
5284
 
5285
    if ( temp_val1[3] !== 0 )
5286
    begin
5287
        $display("Parity checker testing failed! Time %t ", $time) ;
5288
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5289
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5290
        ok = 0 ;
5291
    end
5292
 
5293
    if ( ok )
5294
        test_ok ;
5295
 
5296
    // now enable system error signaling and test response
5297
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5298
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5299
 
5300
    fork
5301
    begin
5302
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5303
               target_address, 32'h1234_5678,
5304
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5305
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5306
        do_pause( 1 ) ;
5307
    end
5308
    begin:wait_serr11
5309
        perr_asserted = 0 ;
5310
        @(posedge pci_clock) ;
5311 35 mihad
        while( SERR !== 0 )
5312 15 mihad
            @(posedge pci_clock) ;
5313
 
5314 35 mihad
        perr_asserted = 1 ;
5315 15 mihad
    end
5316
    begin
5317
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5318
        if ( ok !== 1 )
5319
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5320
 
5321
        @(posedge pci_clock) ;
5322 35 mihad
        #1 ;
5323
        if ( !perr_asserted )
5324
            disable wait_serr11 ;
5325 15 mihad
    end
5326
    join
5327
 
5328
    if ( ok && perr_asserted)
5329
        test_ok ;
5330
    else
5331
    if ( !perr_asserted )
5332
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5333
 
5334
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5335
 
5336
    `ifdef HOST
5337
        repeat(4)
5338 26 mihad
            @(posedge pci_clock) ;
5339
        repeat(4)
5340 15 mihad
            @(posedge wb_clock) ;
5341
        if ( INT_O !== 1 )
5342
        begin
5343
            $display("Parity checker testing failed! Time %t ", $time) ;
5344
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5345
            test_fail("Interrupt Request was not triggered as expected") ;
5346
        end
5347
        else
5348
            test_ok ;
5349
    `else
5350
    `ifdef GUEST
5351 26 mihad
        repeat(4)
5352
            @(posedge wb_clock) ;
5353
        repeat(4)
5354 15 mihad
            @(posedge pci_clock) ;
5355
 
5356
        if ( INTA !== 1 )
5357
        begin
5358
            $display("Parity checker testing failed! Time %t ", $time) ;
5359
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5360
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5361
        end
5362
        else
5363
            test_ok ;
5364
    `endif
5365
    `endif
5366
 
5367
    // check statuses!
5368
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5369
    ok = 1 ;
5370
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5371
    if ( temp_val1[31] !== 1 )
5372
    begin
5373
        $display("Parity checker testing failed! Time %t ", $time) ;
5374
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5375
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5376
        ok = 0 ;
5377
    end
5378
 
5379
    if ( temp_val1[30] !== 1 )
5380
    begin
5381
        $display("Parity checker testing failed! Time %t ", $time) ;
5382
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5383
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5384
        ok = 0 ;
5385
    end
5386
 
5387
    if ( temp_val1[24] !== 0 )
5388
    begin
5389
        $display("Parity checker testing failed! Time %t ", $time) ;
5390
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5391
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5392
        ok = 0 ;
5393
    end
5394
 
5395
    if ( ok )
5396
        test_ok ;
5397
 
5398
    // clear statuses
5399
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5400
 
5401
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5402
 
5403
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5404
    ok = 1 ;
5405
 
5406
    `ifdef HOST
5407
    if ( temp_val1[4] !== 1 )
5408
    begin
5409
        $display("Parity checker testing failed! Time %t ", $time) ;
5410
        $display("System error interrupt status bit not set when expected!") ;
5411
        test_fail("System error interrupt status bit not set when expected") ;
5412
        ok = 0 ;
5413
    end
5414
    `else
5415
    if ( temp_val1[4] !== 0 )
5416
    begin
5417
        $display("Parity checker testing failed! Time %t ", $time) ;
5418
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5419
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5420
        ok = 0 ;
5421
    end
5422
    `endif
5423
 
5424
    if ( temp_val1[3] !== 0 )
5425
    begin
5426
        $display("Parity checker testing failed! Time %t ", $time) ;
5427
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5428
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5429
        ok = 0 ;
5430
    end
5431
 
5432
    if ( ok )
5433
        test_ok ;
5434
 
5435
    // clear statuses
5436
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5437
 
5438
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5439
    fork
5440
    begin
5441 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5442 15 mihad
        (
5443
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5444
            32'h5555_5555,      // second part of address in dual address cycle
5445
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5446
            `BC_MEM_WRITE,      // normal command
5447 92 mihad
            4'hF,               // byte enables
5448 15 mihad
            32'h1234_5678,      // data
5449
            1'b1,               // make address parity error on first phase of dual address
5450
            1'b0,               // make address parity error on second phase of dual address
5451
            ok                  // result of operation
5452
        ) ;
5453 35 mihad
        if ( !perr_asserted )
5454
            disable wait_serr14 ;
5455 15 mihad
    end
5456
    begin:wait_serr14
5457
        perr_asserted = 0 ;
5458
        @(posedge pci_clock) ;
5459 35 mihad
        while( SERR !== 0 )
5460 15 mihad
            @(posedge pci_clock) ;
5461
 
5462 35 mihad
        perr_asserted = 1 ;
5463 15 mihad
    end
5464
    join
5465
 
5466
    if ( ok && perr_asserted)
5467
        test_ok ;
5468
    else
5469
    if ( !perr_asserted )
5470
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5471
 
5472
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5473
 
5474
    `ifdef HOST
5475
        repeat(4)
5476 26 mihad
            @(posedge pci_clock) ;
5477
        repeat(4)
5478 15 mihad
            @(posedge wb_clock) ;
5479
        if ( INT_O !== 1 )
5480
        begin
5481
            $display("Parity checker testing failed! Time %t ", $time) ;
5482
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5483
            test_fail("Interrupt Request was not triggered as expected") ;
5484
        end
5485
        else
5486
            test_ok ;
5487
    `else
5488
    `ifdef GUEST
5489 26 mihad
        repeat(4)
5490
            @(posedge wb_clock) ;
5491
        repeat(4)
5492 15 mihad
            @(posedge pci_clock) ;
5493
 
5494
        if ( INTA !== 1 )
5495
        begin
5496
            $display("Parity checker testing failed! Time %t ", $time) ;
5497
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5498
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5499
        end
5500
        else
5501
            test_ok ;
5502
    `endif
5503
    `endif
5504
 
5505
    // check statuses!
5506
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5507
    ok = 1 ;
5508
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5509
    if ( temp_val1[31] !== 1 )
5510
    begin
5511
        $display("Parity checker testing failed! Time %t ", $time) ;
5512
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5513
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5514
        ok = 0 ;
5515
    end
5516
 
5517
    if ( temp_val1[30] !== 1 )
5518
    begin
5519
        $display("Parity checker testing failed! Time %t ", $time) ;
5520
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5521
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5522
        ok = 0 ;
5523
    end
5524
 
5525
    if ( temp_val1[24] !== 0 )
5526
    begin
5527
        $display("Parity checker testing failed! Time %t ", $time) ;
5528
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5529
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5530
        ok = 0 ;
5531
    end
5532
 
5533
    if ( ok )
5534
        test_ok ;
5535
 
5536
    // clear statuses
5537
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5538
 
5539
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5540
 
5541
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5542
    ok = 1 ;
5543
 
5544
    `ifdef HOST
5545
    if ( temp_val1[4] !== 1 )
5546
    begin
5547
        $display("Parity checker testing failed! Time %t ", $time) ;
5548
        $display("System error interrupt status bit not set when expected!") ;
5549
        test_fail("System error interrupt status bit not set when expected") ;
5550
        ok = 0 ;
5551
    end
5552
    `else
5553
    if ( temp_val1[4] !== 0 )
5554
    begin
5555
        $display("Parity checker testing failed! Time %t ", $time) ;
5556
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5557
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5558
        ok = 0 ;
5559
    end
5560
    `endif
5561
 
5562
    if ( temp_val1[3] !== 0 )
5563
    begin
5564
        $display("Parity checker testing failed! Time %t ", $time) ;
5565
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5566
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5567
        ok = 0 ;
5568
    end
5569
 
5570
    if ( ok )
5571
        test_ok ;
5572
 
5573
    // clear statuses
5574
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5575
 
5576
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5577
    fork
5578
    begin
5579 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5580 15 mihad
        (
5581
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5582
            32'h5555_5555,      // second part of address in dual address cycle
5583
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5584
            `BC_MEM_WRITE,      // normal command
5585 92 mihad
            4'hF,               // byte enables
5586 15 mihad
            32'h1234_5678,      // data
5587
            1'b0,               // make address parity error on first phase of dual address
5588
            1'b1,               // make address parity error on second phase of dual address
5589
            ok                  // result of operation
5590
        ) ;
5591 35 mihad
        if ( !perr_asserted )
5592
            disable wait_serr15 ;
5593 15 mihad
    end
5594
    begin:wait_serr15
5595
        perr_asserted = 0 ;
5596
        @(posedge pci_clock) ;
5597 35 mihad
        while( SERR !== 0 )
5598 15 mihad
            @(posedge pci_clock) ;
5599
 
5600 35 mihad
        perr_asserted = 1 ;
5601 15 mihad
    end
5602
    join
5603
 
5604
    if ( ok && perr_asserted)
5605
        test_ok ;
5606
    else
5607
    if ( !perr_asserted )
5608
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5609
 
5610
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5611
 
5612
    `ifdef HOST
5613
        repeat(4)
5614 26 mihad
            @(posedge pci_clock) ;
5615
        repeat(4)
5616 15 mihad
            @(posedge wb_clock) ;
5617
        if ( INT_O !== 1 )
5618
        begin
5619
            $display("Parity checker testing failed! Time %t ", $time) ;
5620
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5621
            test_fail("Interrupt Request was not triggered as expected") ;
5622
        end
5623
        else
5624
            test_ok ;
5625
    `else
5626
    `ifdef GUEST
5627 26 mihad
        repeat(4)
5628
            @(posedge wb_clock) ;
5629
        repeat(4)
5630 15 mihad
            @(posedge pci_clock) ;
5631
 
5632
        if ( INTA !== 1 )
5633
        begin
5634
            $display("Parity checker testing failed! Time %t ", $time) ;
5635
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5636
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5637
        end
5638
        else
5639
            test_ok ;
5640
    `endif
5641
    `endif
5642
 
5643
    // check statuses!
5644
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5645
    ok = 1 ;
5646
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5647
    if ( temp_val1[31] !== 1 )
5648
    begin
5649
        $display("Parity checker testing failed! Time %t ", $time) ;
5650
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5651
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5652
        ok = 0 ;
5653
    end
5654
 
5655
    if ( temp_val1[30] !== 1 )
5656
    begin
5657
        $display("Parity checker testing failed! Time %t ", $time) ;
5658
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5659
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5660
        ok = 0 ;
5661
    end
5662
 
5663
    if ( temp_val1[24] !== 0 )
5664
    begin
5665
        $display("Parity checker testing failed! Time %t ", $time) ;
5666
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5667
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5668
        ok = 0 ;
5669
    end
5670
 
5671
    if ( ok )
5672
        test_ok ;
5673
 
5674
    // clear statuses
5675
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5676
 
5677
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5678
 
5679
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5680
    ok = 1 ;
5681
 
5682
    `ifdef HOST
5683
    if ( temp_val1[4] !== 1 )
5684
    begin
5685
        $display("Parity checker testing failed! Time %t ", $time) ;
5686
        $display("System error interrupt status bit not set when expected!") ;
5687
        test_fail("System error interrupt status bit not set when expected") ;
5688
        ok = 0 ;
5689
    end
5690
    `else
5691
    if ( temp_val1[4] !== 0 )
5692
    begin
5693
        $display("Parity checker testing failed! Time %t ", $time) ;
5694
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5695
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5696
        ok = 0 ;
5697
    end
5698
    `endif
5699
 
5700
    if ( temp_val1[3] !== 0 )
5701
    begin
5702
        $display("Parity checker testing failed! Time %t ", $time) ;
5703
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5704
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5705
        ok = 0 ;
5706
    end
5707
 
5708
    if ( ok )
5709
        test_ok ;
5710
 
5711
    // clear statuses
5712
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5713
 
5714
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5715
    fork
5716
    begin
5717 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5718 15 mihad
        (
5719
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5720
            32'h5555_5555,      // second part of address in dual address cycle
5721
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5722
            `BC_MEM_WRITE,      // normal command
5723 92 mihad
            4'hF,               // byte enables
5724 15 mihad
            32'h1234_5678,      // data
5725
            1'b1,               // make address parity error on first phase of dual address
5726
            1'b1,               // make address parity error on second phase of dual address
5727
            ok                  // result of operation
5728
        ) ;
5729 35 mihad
        if ( !perr_asserted )
5730
            disable wait_serr16 ;
5731 15 mihad
    end
5732
    begin:wait_serr16
5733
        perr_asserted = 0 ;
5734
        @(posedge pci_clock) ;
5735 35 mihad
        while( SERR !== 0 )
5736 15 mihad
            @(posedge pci_clock) ;
5737
 
5738 35 mihad
        perr_asserted = 1 ;
5739 15 mihad
    end
5740
    join
5741
 
5742
    if ( ok && perr_asserted)
5743
        test_ok ;
5744
    else
5745
    if ( !perr_asserted )
5746
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5747
 
5748
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5749
 
5750
    `ifdef HOST
5751
        repeat(4)
5752 26 mihad
            @(posedge pci_clock) ;
5753
        repeat(4)
5754 15 mihad
            @(posedge wb_clock) ;
5755
        if ( INT_O !== 1 )
5756
        begin
5757
            $display("Parity checker testing failed! Time %t ", $time) ;
5758
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5759
            test_fail("Interrupt Request was not triggered as expected") ;
5760
        end
5761
        else
5762
            test_ok ;
5763
    `else
5764
    `ifdef GUEST
5765 26 mihad
        repeat(4)
5766
            @(posedge wb_clock) ;
5767
        repeat(4)
5768 15 mihad
            @(posedge pci_clock) ;
5769
 
5770
        if ( INTA !== 1 )
5771
        begin
5772
            $display("Parity checker testing failed! Time %t ", $time) ;
5773
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5774
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5775
        end
5776
        else
5777
            test_ok ;
5778
    `endif
5779
    `endif
5780
 
5781
    // check statuses!
5782
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5783
    ok = 1 ;
5784
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5785
    if ( temp_val1[31] !== 1 )
5786
    begin
5787
        $display("Parity checker testing failed! Time %t ", $time) ;
5788
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5789
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5790
        ok = 0 ;
5791
    end
5792
 
5793
    if ( temp_val1[30] !== 1 )
5794
    begin
5795
        $display("Parity checker testing failed! Time %t ", $time) ;
5796
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5797
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5798
        ok = 0 ;
5799
    end
5800
 
5801
    if ( temp_val1[24] !== 0 )
5802
    begin
5803
        $display("Parity checker testing failed! Time %t ", $time) ;
5804
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5805
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5806
        ok = 0 ;
5807
    end
5808
 
5809
    if ( ok )
5810
        test_ok ;
5811
 
5812
    // clear statuses
5813
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5814
 
5815
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5816
 
5817
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5818
    ok = 1 ;
5819
 
5820
    `ifdef HOST
5821
    if ( temp_val1[4] !== 1 )
5822
    begin
5823
        $display("Parity checker testing failed! Time %t ", $time) ;
5824
        $display("System error interrupt status bit not set when expected!") ;
5825
        test_fail("System error interrupt status bit not set when expected") ;
5826
        ok = 0 ;
5827
    end
5828
    `else
5829
    if ( temp_val1[4] !== 0 )
5830
    begin
5831
        $display("Parity checker testing failed! Time %t ", $time) ;
5832
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5833
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5834
        ok = 0 ;
5835
    end
5836
    `endif
5837
 
5838
    if ( temp_val1[3] !== 0 )
5839
    begin
5840
        $display("Parity checker testing failed! Time %t ", $time) ;
5841
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5842
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5843
        ok = 0 ;
5844
    end
5845
 
5846
    if ( ok )
5847
        test_ok ;
5848
 
5849
    // clear statuses
5850
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5851
 
5852
    // now just disable Parity Error response - on Address par errors nothing should happen
5853
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5854
 
5855
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5856
    fork
5857
    begin
5858
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5859
               target_address, 32'h1234_5678,
5860
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5861
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5862
        do_pause( 1 ) ;
5863
    end
5864
    begin:wait_serr12
5865
        perr_asserted = 0 ;
5866
        @(posedge pci_clock) ;
5867
        while( SERR === 1 )
5868
            @(posedge pci_clock) ;
5869
 
5870
        perr_asserted = 1 ;
5871
        $display("Parity checker testing failed! Time %t ", $time) ;
5872
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5873
        test_fail("SERR asserted when parity error response was disabled") ;
5874
    end
5875
    begin
5876
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5877
        if ( ok !== 1 )
5878
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5879
 
5880 35 mihad
        @(posedge pci_clock) ;
5881
        #1 ;
5882
        if ( !perr_asserted )
5883
            disable wait_serr12 ;
5884 15 mihad
    end
5885
    join
5886
 
5887
    if ( ok && !perr_asserted )
5888
        test_ok ;
5889
 
5890
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5891
    `ifdef HOST
5892 26 mihad
        repeat (4)
5893
            @(posedge pci_clock) ;
5894 15 mihad
        repeat(4)
5895
            @(posedge wb_clock) ;
5896
        if ( INT_O !== 0 )
5897
        begin
5898
            $display("Parity checker testing failed! Time %t ", $time) ;
5899
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5900
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5901
        end
5902
        else
5903
            test_ok ;
5904
    `else
5905
    `ifdef GUEST
5906 26 mihad
        repeat(4)
5907
            @(posedge wb_clock) ;
5908
        repeat (4)
5909 15 mihad
            @(posedge pci_clock) ;
5910
 
5911
        if ( INTA !== 1 )
5912
        begin
5913
            $display("Parity checker testing failed! Time %t ", $time) ;
5914
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5915
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5916
        end
5917
        else
5918
            test_ok ;
5919
    `endif
5920
    `endif
5921
 
5922
    // check statuses!
5923
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5924
    ok = 1 ;
5925
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5926
    if ( temp_val1[31] !== 1 )
5927
    begin
5928
        $display("Parity checker testing failed! Time %t ", $time) ;
5929
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5930
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5931
        ok = 0 ;
5932
    end
5933
 
5934
    if ( temp_val1[30] !== 0 )
5935
    begin
5936
        $display("Parity checker testing failed! Time %t ", $time) ;
5937
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5938
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5939
        ok = 0 ;
5940
    end
5941
 
5942
    if ( temp_val1[24] !== 0 )
5943
    begin
5944
        $display("Parity checker testing failed! Time %t ", $time) ;
5945
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5946
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5947
        ok = 0 ;
5948
    end
5949
 
5950
    if ( ok )
5951
        test_ok ;
5952
 
5953
    // clear statuses
5954
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5955
 
5956
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5957
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5958
    ok = 1 ;
5959
    if ( temp_val1[4] !== 0 )
5960
    begin
5961
        $display("Parity checker testing failed! Time %t ", $time) ;
5962
        $display("System error interrupt status bit set when not expected!") ;
5963
        test_fail("System error interrupt status bit set when not expected") ;
5964
        ok = 0 ;
5965
    end
5966
 
5967
    if ( temp_val1[3] !== 0 )
5968
    begin
5969
        $display("Parity checker testing failed! Time %t ", $time) ;
5970
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5971
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5972
        ok = 0 ;
5973
    end
5974
 
5975
    if ( ok )
5976
        test_ok ;
5977
 
5978
    // clear statuses
5979
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5980
 
5981
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5982
    fork
5983
    begin
5984 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5985 15 mihad
        (
5986
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5987
            32'h5555_5555,      // second part of address in dual address cycle
5988
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5989
            `BC_MEM_WRITE,      // normal command
5990 92 mihad
            4'hF,               // byte enables
5991 15 mihad
            32'h1234_5678,      // data
5992
            1'b1,               // make address parity error on first phase of dual address
5993
            1'b0,               // make address parity error on second phase of dual address
5994
            ok                  // result of operation
5995
        ) ;
5996 35 mihad
        if ( !perr_asserted )
5997
            disable wait_serr17 ;
5998 15 mihad
    end
5999
    begin:wait_serr17
6000
        perr_asserted = 0 ;
6001
        @(posedge pci_clock) ;
6002
        while( SERR === 1 )
6003
            @(posedge pci_clock) ;
6004
 
6005
        perr_asserted = 1 ;
6006
        $display("Parity checker testing failed! Time %t ", $time) ;
6007
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
6008
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6009
    end
6010
    join
6011
 
6012
    if ( ok && !perr_asserted)
6013
        test_ok ;
6014
 
6015
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
6016
    fork
6017
    begin
6018 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
6019 15 mihad
        (
6020
            32'hAAAA_AAAA,      // first part of address in dual address cycle
6021
            32'h5555_5555,      // second part of address in dual address cycle
6022
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
6023
            `BC_MEM_WRITE,      // normal command
6024 92 mihad
            4'hF,               // byte enables
6025 15 mihad
            32'h1234_5678,      // data
6026
            1'b0,               // make address parity error on first phase of dual address
6027
            1'b1,               // make address parity error on second phase of dual address
6028
            ok                  // result of operation
6029
        ) ;
6030 35 mihad
        if ( !perr_asserted )
6031
            disable wait_serr18 ;
6032 15 mihad
    end
6033
    begin:wait_serr18
6034
        perr_asserted = 0 ;
6035
        @(posedge pci_clock) ;
6036
        while( SERR === 1 )
6037
            @(posedge pci_clock) ;
6038
 
6039
        perr_asserted = 1 ;
6040
        $display("Parity checker testing failed! Time %t ", $time) ;
6041
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
6042
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6043
    end
6044
    join
6045
 
6046
    if ( ok && !perr_asserted)
6047
        test_ok ;
6048
 
6049
    // check statuses!
6050
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6051
    ok = 1 ;
6052
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6053
    if ( temp_val1[31] !== 1 )
6054
    begin
6055
        $display("Parity checker testing failed! Time %t ", $time) ;
6056
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6057
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6058
        ok = 0 ;
6059
    end
6060
 
6061
    if ( temp_val1[30] !== 0 )
6062
    begin
6063
        $display("Parity checker testing failed! Time %t ", $time) ;
6064
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6065
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6066
        ok = 0 ;
6067
    end
6068
 
6069
    if ( temp_val1[24] !== 0 )
6070
    begin
6071
        $display("Parity checker testing failed! Time %t ", $time) ;
6072
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6073
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6074
        ok = 0 ;
6075
    end
6076
 
6077
    if ( ok )
6078
        test_ok ;
6079
 
6080
    // clear statuses
6081
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6082
 
6083
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
6084
    fork
6085
    begin
6086 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
6087 15 mihad
        (
6088
            32'hAAAA_AAAA,      // first part of address in dual address cycle
6089
            32'h5555_5555,      // second part of address in dual address cycle
6090
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
6091
            `BC_MEM_WRITE,      // normal command
6092 92 mihad
            4'hF,               // byte enables
6093 15 mihad
            32'h1234_5678,      // data
6094
            1'b1,               // make address parity error on first phase of dual address
6095
            1'b1,               // make address parity error on second phase of dual address
6096
            ok                  // result of operation
6097
        ) ;
6098 35 mihad
        if ( !perr_asserted )
6099
            disable wait_serr19 ;
6100 15 mihad
    end
6101
    begin:wait_serr19
6102
        perr_asserted = 0 ;
6103
        @(posedge pci_clock) ;
6104
        while( SERR === 1 )
6105
            @(posedge pci_clock) ;
6106
 
6107
        perr_asserted = 1 ;
6108
        $display("Parity checker testing failed! Time %t ", $time) ;
6109
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
6110
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6111
    end
6112
    join
6113
 
6114
    if ( ok && !perr_asserted)
6115
        test_ok ;
6116
 
6117
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
6118
 
6119
    `ifdef HOST
6120
        repeat(4)
6121 26 mihad
            @(posedge pci_clock) ;
6122
        repeat(4)
6123 15 mihad
            @(posedge wb_clock) ;
6124
        if ( INT_O !== 0 )
6125
        begin
6126
            $display("Parity checker testing failed! Time %t ", $time) ;
6127
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
6128
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
6129
        end
6130
        else
6131
            test_ok ;
6132
    `else
6133
    `ifdef GUEST
6134 26 mihad
        repeat(4)
6135
            @(posedge wb_clock) ;
6136
        repeat(4)
6137 15 mihad
            @(posedge pci_clock) ;
6138
 
6139
        if ( INTA !== 1 )
6140
        begin
6141
            $display("Parity checker testing failed! Time %t ", $time) ;
6142
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
6143
            test_fail("GUEST bridge asserted Interrupt Request after Address Parity Error, even though SERR was disabled and PCI has other means for signaling parity errors") ;
6144
        end
6145
        else
6146
            test_ok ;
6147
    `endif
6148
    `endif
6149
 
6150
    // check statuses!
6151
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6152
    ok = 1 ;
6153
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6154
    if ( temp_val1[31] !== 1 )
6155
    begin
6156
        $display("Parity checker testing failed! Time %t ", $time) ;
6157
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6158
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6159
        ok = 0 ;
6160
    end
6161
 
6162
    if ( temp_val1[30] !== 0 )
6163
    begin
6164
        $display("Parity checker testing failed! Time %t ", $time) ;
6165
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6166
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6167
        ok = 0 ;
6168
    end
6169
 
6170
    if ( temp_val1[24] !== 0 )
6171
    begin
6172
        $display("Parity checker testing failed! Time %t ", $time) ;
6173
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6174
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6175
        ok = 0 ;
6176
    end
6177
 
6178
    if ( ok )
6179
        test_ok ;
6180
 
6181
    // clear statuses
6182
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6183
 
6184
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
6185
 
6186
    // do normal write
6187
    fork
6188
    begin
6189
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
6190
               target_address, 32'h1234_5678, `Test_All_Bytes,
6191
               1, 8'h3_0, `Test_One_Zero_Target_WS,
6192
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6193
        do_pause( 1 ) ;
6194
    end
6195
    begin:wait_serr13
6196
        perr_asserted = 0 ;
6197
        @(posedge pci_clock) ;
6198
        while( SERR === 1 )
6199
            @(posedge pci_clock) ;
6200
 
6201
        perr_asserted = 1 ;
6202
        $display("Parity checker testing failed! Time %t ", $time) ;
6203
        $display("SERR asserted for no reason!") ;
6204
        test_fail("SERR was asserted for no reason") ;
6205
    end
6206
    begin
6207
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6208
        if ( ok !== 1 )
6209
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6210
 
6211 35 mihad
        @(posedge pci_clock) ;
6212
        #1 ;
6213
        if ( !perr_asserted )
6214
            disable wait_serr13 ;
6215 15 mihad
    end
6216
    join
6217
 
6218
    if ( ok && !perr_asserted )
6219
        test_ok ;
6220
 
6221
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6222
    `ifdef HOST
6223 26 mihad
        repeat( 4 )
6224
            @(posedge pci_clock) ;
6225 15 mihad
        repeat(4)
6226
            @(posedge wb_clock) ;
6227
        if ( INT_O !== 0 )
6228
        begin
6229
            $display("Parity checker testing failed! Time %t ", $time) ;
6230
            $display("Interrupt request asserted for no reason!") ;
6231
            test_fail("Interrupt request was asserted for no reason") ;
6232
        end
6233
        else
6234
            test_ok ;
6235
    `else
6236
    `ifdef GUEST
6237 26 mihad
        repeat(4)
6238
            @(posedge wb_clock) ;
6239
        repeat(4)
6240 15 mihad
            @(posedge pci_clock) ;
6241
 
6242
        if ( INTA !== 1 )
6243
        begin
6244
            $display("Parity checker testing failed! Time %t ", $time) ;
6245
            $display("Interrupt request asserted for no reason!") ;
6246
            test_fail("Interrupt request was asserted for no reason") ;
6247
        end
6248
        else
6249
            test_ok ;
6250
    `endif
6251
    `endif
6252
 
6253
    // check statuses!
6254
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6255
    ok = 1 ;
6256
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6257
    if ( temp_val1[31] !== 0 )
6258
    begin
6259
        $display("Parity checker testing failed! Time %t ", $time) ;
6260
        $display("Detected Parity Error bit was set for no reason!") ;
6261
        test_fail("Detected Parity Error bit was set for no reason") ;
6262
        ok = 0 ;
6263
    end
6264
 
6265
    if ( temp_val1[30] !== 0 )
6266
    begin
6267
        $display("Parity checker testing failed! Time %t ", $time) ;
6268
        $display("Signalled System Error bit was set for no reason!") ;
6269
        test_fail("Signalled System Error bit was set for no reason") ;
6270
        ok = 0 ;
6271
    end
6272
 
6273
    if ( temp_val1[24] !== 0 )
6274
    begin
6275
        $display("Parity checker testing failed! Time %t ", $time) ;
6276
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6277
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6278
        ok = 0 ;
6279
    end
6280
 
6281
    if ( ok )
6282
        test_ok ;
6283
 
6284
    // clear statuses
6285
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6286
 
6287
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6288
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6289
    ok = 1 ;
6290
 
6291
    if ( temp_val1[4] !== 0 )
6292
    begin
6293
        $display("Parity checker testing failed! Time %t ", $time) ;
6294
        $display("System error interrupt status bit set when not expected!") ;
6295
        test_fail("System error interrupt status bit set when not expected") ;
6296
        ok = 0 ;
6297
    end
6298
 
6299
    if ( temp_val1[3] !== 0 )
6300
    begin
6301
        $display("Parity checker testing failed! Time %t ", $time) ;
6302
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6303
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6304
        ok = 0 ;
6305
    end
6306
 
6307
    if ( ok )
6308
        test_ok ;
6309
 
6310
    // clear statuses
6311
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6312
 
6313
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6314
 
6315
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6316
 
6317
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6318 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
6319 15 mihad
 
6320
    // setup target's image!
6321
    target_address  = Target_Base_Addr_R[1] ;
6322
 
6323
    // base address
6324
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6325
 
6326
    // address mask
6327
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6328
 
6329
    // image control
6330
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6331
 
6332
    // enable everything possible for parity checking
6333
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6334
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6335
 
6336
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6337
 
6338
    fork
6339
    begin
6340
        if ( target_mem_image === 1 )
6341
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6342
                   target_address, 32'h1234_5678,
6343
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6344
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6345
        else
6346
            PCIU_IO_WRITE_MAKE_PERR (
6347
                                    `Test_Master_1,
6348
                                    target_address,
6349
                                    32'h1234_5678,
6350
                                    4'h0,
6351
                                    1,
6352
                                    `Test_Target_Normal_Completion
6353
                                    );
6354
 
6355
        do_pause( 1 ) ;
6356
    end
6357
    begin:wait_perr11
6358
        perr_asserted = 0 ;
6359
        @(posedge pci_clock) ;
6360 35 mihad
        while ( PERR !== 0 )
6361 15 mihad
            @(posedge pci_clock) ;
6362
 
6363 35 mihad
        perr_asserted = 1 ;
6364 15 mihad
 
6365
    end
6366
    begin
6367
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6368
 
6369
        if ( ok !== 1 )
6370
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6371
 
6372
        repeat(2)
6373
            @(posedge pci_clock) ;
6374
 
6375 35 mihad
        #1 ;
6376
        if ( !perr_asserted )
6377
            disable wait_perr11 ;
6378 15 mihad
    end
6379
    join
6380
 
6381
    if ( ok && perr_asserted )
6382
        test_ok ;
6383
    else
6384
    if ( !perr_asserted )
6385
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6386
 
6387
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6388
    `ifdef HOST
6389 26 mihad
        repeat (4)
6390
            @(posedge pci_clock) ;
6391 15 mihad
        repeat(4)
6392
            @(posedge wb_clock) ;
6393
        if ( INT_O !== 0 )
6394
        begin
6395
            $display("Parity checker testing failed! Time %t ", $time) ;
6396
            $display("Interrupt request asserted for no reason!") ;
6397
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6398
        end
6399
        else
6400
            test_ok ;
6401
    `else
6402
    `ifdef GUEST
6403 26 mihad
        repeat(4)
6404
            @(posedge wb_clock) ;
6405
        repeat (4)
6406 15 mihad
            @(posedge pci_clock) ;
6407
 
6408
        if ( INTA !== 1 )
6409
        begin
6410
            $display("Parity checker testing failed! Time %t ", $time) ;
6411
            $display("Interrupt request asserted for no reason!") ;
6412
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6413
        end
6414
        else
6415
            test_ok ;
6416
 
6417
    `endif
6418
    `endif
6419
 
6420
    // check statuses!
6421
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6422
    ok = 1 ;
6423
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6424
    if ( temp_val1[31] !== 1 )
6425
    begin
6426
        $display("Parity checker testing failed! Time %t ", $time) ;
6427 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6428
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6429 15 mihad
        ok = 0 ;
6430
    end
6431
 
6432
    if ( temp_val1[30] !== 0 )
6433
    begin
6434
        $display("Parity checker testing failed! Time %t ", $time) ;
6435
        $display("Signalled System Error bit was set for no reason!") ;
6436
        test_fail("Signalled System Error bit was set for no reason") ;
6437
        ok = 0 ;
6438
    end
6439
 
6440
    if ( temp_val1[24] !== 0 )
6441
    begin
6442
        $display("Parity checker testing failed! Time %t ", $time) ;
6443
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6444
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6445
        ok = 0 ;
6446
    end
6447
 
6448
    if ( ok )
6449
        test_ok ;
6450
 
6451
    // clear statuses
6452
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6453
 
6454
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6455
 
6456
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6457
    ok = 1 ;
6458
    if ( temp_val1[4] !== 0 )
6459
    begin
6460
        $display("Parity checker testing failed! Time %t ", $time) ;
6461
        $display("System error interrupt status bit set when not expected!") ;
6462
        test_fail("System error interrupt status bit set when not expected") ;
6463
        ok = 0 ;
6464
    end
6465
 
6466
    if ( temp_val1[3] !== 0 )
6467
    begin
6468
        $display("Parity checker testing failed! Time %t ", $time) ;
6469
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6470
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6471
        ok = 0 ;
6472
    end
6473
 
6474
    if ( ok )
6475
        test_ok ;
6476
 
6477
    // clear statuses
6478
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6479
 
6480
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6481
 
6482
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6483
    fork
6484
    begin
6485
        if ( target_mem_image === 1 )
6486
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6487
                          target_address, 32'h1234_5678,
6488
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6489
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6490
        else
6491
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6492
 
6493
        do_pause( 1 ) ;
6494
    end
6495
    begin:wait_perr12
6496
        perr_asserted = 0 ;
6497
        @(posedge pci_clock) ;
6498 35 mihad
        while ( PERR !== 0 )
6499 15 mihad
            @(posedge pci_clock) ;
6500
 
6501 35 mihad
        perr_asserted = 1 ;
6502 15 mihad
    end
6503
    begin
6504
 
6505
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6506
        if ( ok !== 1 )
6507
        begin
6508
            test_fail("Bridge failed to process Target Memory read correctly") ;
6509
            disable main ;
6510
        end
6511
 
6512
        repeat(3)
6513
            @(posedge pci_clock) ;
6514
 
6515
        if ( target_mem_image === 1 )
6516
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6517
                    target_address, 32'h1234_5678,
6518
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6519
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6520
        else
6521
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6522
 
6523
        do_pause( 1 ) ;
6524
 
6525
    end
6526
    begin
6527
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6528
        if ( ok !== 1 )
6529
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6530
        else
6531
        begin
6532
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6533
            if ( ok !== 1 )
6534
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6535
        end
6536
 
6537 35 mihad
        repeat(2)
6538 15 mihad
            @(posedge pci_clock) ;
6539
 
6540 35 mihad
        #1 ;
6541
        if ( !perr_asserted )
6542
            disable wait_perr12 ;
6543 15 mihad
    end
6544
    join
6545
 
6546
    if ( ok && perr_asserted )
6547
        test_ok ;
6548
    else
6549
    if ( !perr_asserted )
6550
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6551
 
6552
 
6553
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6554
    `ifdef HOST
6555
        repeat(4)
6556 26 mihad
            @(posedge pci_clock) ;
6557
        repeat(4)
6558 15 mihad
            @(posedge wb_clock) ;
6559
        if ( INT_O !== 0 )
6560
        begin
6561
            $display("Parity checker testing failed! Time %t ", $time) ;
6562
            $display("Interrupt request asserted for no reason!") ;
6563
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6564
        end
6565
        else
6566
            test_ok ;
6567
    `else
6568
    `ifdef GUEST
6569 26 mihad
        repeat(4)
6570
            @(posedge wb_clock) ;
6571
        repeat(4)
6572 15 mihad
            @(posedge pci_clock) ;
6573
 
6574
        if ( INTA !== 1 )
6575
        begin
6576
            $display("Parity checker testing failed! Time %t ", $time) ;
6577
            $display("Interrupt request asserted for no reason!") ;
6578
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6579
        end
6580
        else
6581
            test_ok ;
6582
    `endif
6583
    `endif
6584
 
6585
    // check statuses!
6586
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6587
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6588
    ok = 1 ;
6589 45 mihad
    if ( temp_val1[31] !== 0 )
6590 15 mihad
    begin
6591
        $display("Parity checker testing failed! Time %t ", $time) ;
6592 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6593
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6594 15 mihad
        ok = 0 ;
6595
    end
6596
 
6597
    if ( temp_val1[30] !== 0 )
6598
    begin
6599
        $display("Parity checker testing failed! Time %t ", $time) ;
6600
        $display("Signalled System Error bit was set for no reason!") ;
6601
        test_fail("Signalled System Error bit was set for no reason") ;
6602
        ok = 0 ;
6603
    end
6604
 
6605
    if ( temp_val1[24] !== 0 )
6606
    begin
6607
        $display("Parity checker testing failed! Time %t ", $time) ;
6608
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6609
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6610
        ok = 0 ;
6611
    end
6612
 
6613
    if ( ok )
6614
        test_ok ;
6615
 
6616
    // clear statuses
6617
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6618
 
6619
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6620
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6621
    ok = 1 ;
6622
    if ( temp_val1[4] !== 0 )
6623
    begin
6624
        $display("Parity checker testing failed! Time %t ", $time) ;
6625
        $display("System error interrupt status bit set when not expected!") ;
6626
        test_fail("System error interrupt status bit set when not expected") ;
6627
        ok = 0 ;
6628
    end
6629
 
6630
    if ( temp_val1[3] !== 0 )
6631
    begin
6632
        $display("Parity checker testing failed! Time %t ", $time) ;
6633
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6634
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6635
        ok = 0 ;
6636
    end
6637
 
6638
    if ( ok )
6639
        test_ok ;
6640
    // clear statuses
6641
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6642
 
6643
    $fdisplay(pci_mon_log_file_desc,
6644
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6645
    test_name = "DISABLE USED IMAGES" ;
6646
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6647
    if ( ok !== 1 )
6648
    begin
6649
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6650
        test_fail("WB Image Address Mask register could not be written to") ;
6651
        disable main ;
6652
    end
6653
 
6654 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6655 15 mihad
    if ( ok !== 1 )
6656
    begin
6657
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6658
        test_fail("PCI Image Address Mask register could not be written to") ;
6659
        disable main ;
6660
    end
6661
 
6662
    // disable target's 1 response to parity errors
6663 45 mihad
    configuration_cycle_write(0,                        // bus number
6664
                              `TAR1_IDSEL_INDEX - 11,   // device number
6665
                              0,                        // function number
6666
                              1,                        // register number
6667
                              0,                        // type of configuration cycle
6668
                              4'b0001,                  // byte enables
6669
                              32'h0000_0007             // data
6670 15 mihad
                             ) ;
6671
 
6672
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6673
end
6674
endtask // parity_checking
6675
 
6676
task wb_to_pci_transactions ;
6677
    reg   [11:0] ctrl_offset ;
6678
    reg   [11:0] ba_offset ;
6679
    reg   [11:0] am_offset ;
6680
    reg   [11:0] pci_ctrl_offset ;
6681
    reg   [11:0] err_cs_offset ;
6682
    reg   [11:0] icr_offset ;
6683
    reg   [11:0] isr_offset ;
6684
    reg   [11:0] lat_tim_cls_offset ;
6685
 
6686
    reg `WRITE_STIM_TYPE  write_data ;
6687
    reg `READ_STIM_TYPE   read_data ;
6688
    reg `READ_RETURN_TYPE read_status ;
6689
 
6690
    reg `WRITE_RETURN_TYPE write_status ;
6691
    reg `WB_TRANSFER_FLAGS write_flags ;
6692
    reg [31:0] temp_val1 ;
6693
    reg [31:0] temp_val2 ;
6694
    reg        ok   ;
6695
 
6696
    reg [31:0] image_base ;
6697
    reg [31:0] target_address ;
6698
    integer i ;
6699
    integer required_reads ;
6700
    integer writes_left ;
6701
 
6702
begin:main
6703
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6704
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6705
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6706
    pci_ctrl_offset    = 12'h4 ;
6707
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6708
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6709
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6710
    lat_tim_cls_offset = 12'hC ;
6711
 
6712
    $display("Checking WB to PCI transaction lengths!") ;
6713
    target_address  = `BEH_TAR1_MEM_START ;
6714
    image_base      = 0 ;
6715
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6716
 
6717
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6718
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6719
    write_flags                    = 0 ;
6720 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
6721
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
6722 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6723
 
6724
    // enable master & target operation
6725
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6726
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6727
    if ( ok !== 1 )
6728
    begin
6729
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6730
        test_fail("write to PCI Device Control register failed") ;
6731
        disable main ;
6732
    end
6733
 
6734
    // prepare image control register
6735
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6736
    if ( ok !== 1 )
6737
    begin
6738
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6739
        test_fail("write to WB Image Control register failed") ;
6740
        disable main ;
6741
    end
6742
 
6743
    // prepare base address register
6744
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6745
    if ( ok !== 1 )
6746
    begin
6747
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6748
        test_fail("write to WB Base Address register failed") ;
6749
        disable main ;
6750
    end
6751
 
6752
    // write address mask register
6753
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6754
    if ( ok !== 1 )
6755
    begin
6756
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6757
        test_fail("write to WB Address Mask register failed") ;
6758
        disable main ;
6759
    end
6760
 
6761
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6762
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6763
    if ( ok !== 1 )
6764
    begin
6765
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6766
        test_fail("write to WB Error Control and Status register failed") ;
6767
        disable main ;
6768
    end
6769
 
6770
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6771
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6772
    if ( ok !== 1 )
6773
    begin
6774
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6775
        test_fail("write to Interrupt Control register failed") ;
6776
        disable main ;
6777
    end
6778
 
6779
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6780
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6781
    if ( ok !== 1 )
6782
    begin
6783
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6784
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6785
        disable main ;
6786
    end
6787
 
6788
    $display("Testing single write transaction progress from WB to PCI!") ;
6789
    write_data`WRITE_ADDRESS = target_address ;
6790
    write_data`WRITE_DATA    = wmem_data[0] ;
6791
    write_data`WRITE_SEL     = 4'hF ;
6792
 
6793
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6794
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6795
 
6796
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6797
    fork
6798
    begin
6799
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6800
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6801
        begin
6802
            $display("Transaction progress testing failed! Time %t ", $time) ;
6803
            $display("Bridge failed to process single memory write!") ;
6804
            test_fail("bridge failed to post single memory write") ;
6805
            disable main ;
6806
        end
6807
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6808
    end
6809
    begin
6810
        // wait two retries, then enable target response
6811
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6812
        if ( ok !== 1 )
6813
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6814
        else
6815
            test_ok ;
6816
 
6817
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6818
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6819
        if ( ok !== 1 )
6820
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6821
        else
6822
            test_ok ;
6823
 
6824
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6825
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6826
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6827
 
6828
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6829
        if ( ok !== 1 )
6830
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6831
        else
6832
            test_ok ;
6833
    end
6834
    join
6835
 
6836
    $display("Testing burst write transaction progress from WB to PCI!") ;
6837
    write_data`WRITE_ADDRESS = target_address ;
6838
    write_data`WRITE_DATA    = wmem_data[0] ;
6839
    write_data`WRITE_SEL     = 4'hF ;
6840
 
6841
    wishbone_master.blk_write_data[0] = write_data ;
6842
 
6843
    write_data`WRITE_ADDRESS = target_address + 4 ;
6844
    write_data`WRITE_DATA    = wmem_data[1] ;
6845
    write_data`WRITE_SEL     = 4'hF ;
6846
 
6847
    wishbone_master.blk_write_data[1] = write_data ;
6848
 
6849
    write_flags`WB_TRANSFER_SIZE = 2 ;
6850
    write_flags`WB_TRANSFER_CAB  = 1 ;
6851
 
6852
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6853
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6854
 
6855
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6856
 
6857
    fork
6858
    begin
6859
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6860
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6861
        begin
6862
            $display("Transaction progress testing failed! Time %t ", $time) ;
6863
            $display("Bridge failed to process whole CAB memory write!") ;
6864
            test_fail("bridge failed to post whole CAB memory write") ;
6865
            disable main ;
6866
        end
6867
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6868
    end
6869
    begin
6870
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6871
        if ( ok !== 1 )
6872
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6873
        else
6874
            test_ok ;
6875
 
6876
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6877
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6878
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6879
 
6880
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6881
        if ( ok !== 1 )
6882
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6883
        else
6884
            test_ok ;
6885
 
6886
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6887
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6888
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6889
 
6890
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6891
        if ( ok !== 1 )
6892
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6893
        else
6894
            test_ok ;
6895
    end
6896
    join
6897
 
6898
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6899
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6900
 
6901
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6902
    // try same write with other terminations
6903
    fork
6904
    begin
6905
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6906
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6907
        begin
6908
            $display("Transaction progress testing failed! Time %t ", $time) ;
6909
            $display("Bridge failed to process whole CAB memory write!") ;
6910
            test_fail("bridge failed to post whole CAB memory write") ;
6911
            disable main ;
6912
        end
6913
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6914
    end
6915
    begin
6916
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6917
        if ( ok !== 1 )
6918
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6919
        else
6920
            test_ok ;
6921
 
6922
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6923
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6924
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6925
 
6926
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6927
        if ( ok !== 1 )
6928
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6929
        else
6930
            test_ok ;
6931
    end
6932
    join
6933
 
6934
    // repeat the write with normal completion
6935
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6936
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6937
 
6938
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6939
    fork
6940
    begin
6941
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6942
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6943
        begin
6944
            $display("Transaction progress testing failed! Time %t ", $time) ;
6945
            $display("Bridge failed to process whole CAB memory write!") ;
6946
            test_fail("bridge failed to post whole CAB memory write") ;
6947
            disable main ;
6948
        end
6949
    end
6950
    begin
6951
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6952
        if ( ok !== 1 )
6953
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6954
        else
6955
            test_ok ;
6956
    end
6957
    join
6958
 
6959
    // do the same thing with burst length of 3
6960
    write_data`WRITE_ADDRESS = target_address + 8 ;
6961
    write_data`WRITE_DATA    = wmem_data[2] ;
6962
    write_data`WRITE_SEL     = 4'hF ;
6963
 
6964
    wishbone_master.blk_write_data[2] = write_data ;
6965
 
6966
    write_flags`WB_TRANSFER_SIZE = 3 ;
6967
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6968
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6969
 
6970
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6971
 
6972
    fork
6973
    begin
6974
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6975
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6976
        begin
6977
            $display("Transaction progress testing failed! Time %t ", $time) ;
6978
            $display("Bridge failed to process whole CAB memory write!") ;
6979
            test_fail("bridge failed to post whole CAB memory write") ;
6980
            disable main ;
6981
        end
6982
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6983
    end
6984
    begin
6985
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6986
        if ( ok !== 1 )
6987
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6988
        else
6989
            test_ok ;
6990
 
6991
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6992
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6993
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6994
 
6995
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6996
        if ( ok !== 1 )
6997
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6998
        else
6999
            test_ok ;
7000
    end
7001
    join
7002
 
7003
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7004
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7005
 
7006
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
7007
    fork
7008
    begin
7009
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7010
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
7011
        begin
7012
            $display("Transaction progress testing failed! Time %t ", $time) ;
7013
            $display("Bridge failed to process whole CAB memory write!") ;
7014
            test_fail("bridge failed to post whole CAB memory write") ;
7015
            disable main ;
7016
        end
7017
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
7018
    end
7019
    begin
7020
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7021
        if ( ok !== 1 )
7022
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7023
        else
7024
            test_ok ;
7025
 
7026
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
7027
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7028
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7029
 
7030
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7031
        if ( ok !== 1 )
7032
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7033
        else
7034
            test_ok ;
7035
 
7036
    end
7037
    join
7038
 
7039
    // repeat with normal completion
7040
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7041
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7042
 
7043
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
7044
    fork
7045
    begin
7046
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7047
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
7048
        begin
7049
            $display("Transaction progress testing failed! Time %t ", $time) ;
7050
            $display("Bridge failed to process whole CAB memory write!") ;
7051
            test_fail("bridge failed to post whole CAB memory write") ;
7052
            disable main ;
7053
        end
7054
    end
7055
    begin
7056
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
7057
        if ( ok !== 1 )
7058
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7059
        else
7060
            test_ok ;
7061
 
7062
    end
7063
    join
7064
 
7065
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
7066
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
7067
    begin
7068
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7069
        write_data`WRITE_DATA    = wmem_data[i] ;
7070
        write_data`WRITE_SEL     = 4'hF ;
7071
 
7072
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
7073
        read_data`READ_SEL       = write_data`WRITE_SEL ;
7074
 
7075
        wishbone_master.blk_write_data[i]   = write_data ;
7076
        wishbone_master.blk_read_data_in[i] = read_data ;
7077
    end
7078
 
7079
    write_flags`WB_TRANSFER_CAB      = 1 ;
7080
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
7081
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7082
 
7083
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7084
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7085
 
7086
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
7087
    fork
7088
    begin
7089
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7090
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7091
        begin
7092
            $display("Transaction progress testing failed! Time %t ", $time) ;
7093
            $display("Bridge failed to process right number of databeats in CAB write!") ;
7094
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
7095
            test_fail("bridge failed to post whole CAB memory write") ;
7096
            disable main ;
7097
        end
7098
 
7099
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
7100
 
7101
        // read here just checks if data was transfered OK
7102
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7103
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
7104
 
7105
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7106
 
7107
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7108
        begin
7109
            $display("Transaction progress testing failed! Time %t ", $time) ;
7110
            $display("Bridge processed CAB read wrong!") ;
7111
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
7112
        end
7113
 
7114
    end
7115
    begin
7116
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7117
        if ( ok !== 1 )
7118
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7119
        else
7120
            test_ok ;
7121
 
7122
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
7123
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7124
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7125
 
7126
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7127
        if ( ok !== 1 )
7128
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7129
        else
7130
            test_ok ;
7131
 
7132
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
7133
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
7134
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7135
 
7136
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7137
        if ( ok !== 1 )
7138
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7139
        else
7140
            test_ok ;
7141
 
7142
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
7143
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7144
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7145
 
7146
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7147
        if ( ok !== 1 )
7148
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7149
        else
7150
            test_ok ;
7151
 
7152
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
7153
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7154
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7155
 
7156
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
7157
        if ( ok !== 1 )
7158
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7159
        else
7160
            test_ok ;
7161
 
7162
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
7163
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
7164
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
7165
        for ( i = 0 ; i < required_reads ; i = i + 1 )
7166
        begin
7167
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7168
            if ( ok !== 1 )
7169
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7170
        end
7171
    end
7172
    join
7173
 
7174
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
7175
    begin
7176
        read_status = wishbone_master.blk_read_data_out[i] ;
7177
        if (read_status`READ_DATA !== wmem_data[i])
7178
        begin
7179
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
7180
            test_fail("data read from target wasn't the same as data written to it") ;
7181
            ok = 0 ;
7182
        end
7183
    end
7184
 
7185
    if ( ok )
7186
        test_ok ;
7187
 
7188
    $display("Testing single read transaction progress from WB to PCI!") ;
7189
    read_data`READ_ADDRESS = target_address + 8 ;
7190
    read_data`READ_SEL     = 4'hF ;
7191
 
7192
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7193
 
7194
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
7195
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7196
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7197
 
7198
    fork
7199
    begin
7200
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7201
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7202
        begin
7203
            $display("Transaction progress testing failed! Time %t ", $time) ;
7204
            $display("Bridge processed single read wrong!") ;
7205
            test_fail("bridge processed single read wrong") ;
7206
            disable main ;
7207
        end
7208
 
7209
        if (read_status`READ_DATA !== wmem_data[2])
7210
        begin
7211
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7212
            test_fail("data returned from single read was not as expected") ;
7213
        end
7214
        else
7215
        if ( ok )
7216
            test_ok ;
7217
    end
7218
    begin
7219
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7220
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7221
 
7222
        if ( ok !== 1 )
7223
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7224
 
7225
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7226
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7227
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7228
 
7229
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7230
        if ( ok !== 1 )
7231
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7232
    end
7233
    join
7234
 
7235
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7236
 
7237
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7238
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7239
 
7240
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7241
    // first fill target's memory with enough data to fill WBR_FIFO
7242
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7243
    begin
7244
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7245
        write_data`WRITE_DATA    = wmem_data[i] ;
7246
        write_data`WRITE_SEL     = 4'hF ;
7247
 
7248
        wishbone_master.blk_write_data[i] = write_data ;
7249
    end
7250
 
7251
    write_flags`WB_TRANSFER_CAB = 1 ;
7252
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7253
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7254
 
7255
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7256
 
7257
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7258
    begin
7259
        $display("Transaction progress testing failed! Time %t ", $time) ;
7260
        $display("Bridge processed CAB write wrong!") ;
7261
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7262
        disable main ;
7263
    end
7264
 
7265
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7266
    // perform single read to force write data to pci
7267
    read_data`READ_ADDRESS = target_address + 8;
7268
    read_data`READ_SEL     = 4'hF ;
7269
 
7270
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7271
 
7272
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7273
    begin
7274
        $display("Transaction progress testing failed! Time %t ", $time) ;
7275
        $display("Bridge processed single read wrong!") ;
7276
        test_fail("bridge didn't process single memory read as expected") ;
7277
        disable main ;
7278
    end
7279
 
7280
    wishbone_master.blk_read_data_in[0] = read_data ;
7281
 
7282
    read_data`READ_ADDRESS = target_address + 12 ;
7283
    read_data`READ_SEL     = 4'hF ;
7284
 
7285
    wishbone_master.blk_read_data_in[1] = read_data ;
7286
 
7287
    read_data`READ_ADDRESS = target_address + 16 ;
7288
    read_data`READ_SEL     = 4'hF ;
7289
 
7290
    wishbone_master.blk_read_data_in[2] = read_data ;
7291
 
7292
    write_flags`WB_TRANSFER_CAB  = 1 ;
7293
    write_flags`WB_TRANSFER_SIZE = 2 ;
7294
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7295
    read_status = 0 ;
7296
 
7297
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7298
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7299
 
7300
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7301
 
7302
    ok = 1 ;
7303
    fork
7304
    begin
7305
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7306
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7307
 
7308
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7309
        begin
7310
            $display("Transaction progress testing failed! Time %t ", $time) ;
7311
            $display("Bridge processed CAB read wrong!") ;
7312
            test_fail("bridge didn't process disconnected burst read as expected") ;
7313
        end
7314
        else
7315
        begin
7316
 
7317
            read_status = wishbone_master.blk_read_data_out[0] ;
7318
 
7319
            if (read_status`READ_DATA !== wmem_data[2])
7320
            begin
7321
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7322
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7323
            end
7324
            else
7325
                test_ok ;
7326
        end
7327
 
7328
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7329
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7330
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7331
 
7332
        read_status = 0 ;
7333
 
7334
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7335
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7336
 
7337
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7338
        begin
7339
            $display("Transaction progress testing failed! Time %t ", $time) ;
7340
            $display("Bridge processed CAB read wrong!") ;
7341
            test_fail("bridge didn't process disconnected burst read as expected") ;
7342
        end
7343
        else
7344
        begin
7345
 
7346
            read_status = wishbone_master.blk_read_data_out[0] ;
7347
 
7348
            if (read_status`READ_DATA !== wmem_data[3])
7349
            begin
7350
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7351
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7352
            end
7353
            else
7354
                test_ok ;
7355
        end
7356
 
7357
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7358
        // complete delayed read which was requested
7359
        read_data = wishbone_master.blk_read_data_in[2] ;
7360
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7361
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7362
 
7363
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7364
        begin
7365
            $display("Transaction progress testing failed! Time %t ", $time) ;
7366
            $display("Bridge processed single out of burst read wrong!") ;
7367
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7368
        end
7369
        else
7370
        begin
7371
 
7372
            if (read_status`READ_DATA !== wmem_data[4])
7373
            begin
7374
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7375
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7376
            end
7377
            else
7378
                test_ok ;
7379
        end
7380
 
7381
    end
7382
    begin
7383
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7384
 
7385
        if ( ok !== 1 )
7386
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7387
 
7388
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7389
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7390
 
7391
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7392
        if ( ok !== 1 )
7393
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7394
 
7395
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7396
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7397
 
7398
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7399
        if ( ok !== 1 )
7400
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7401
    end
7402
    join
7403
 
7404
    // now try burst read with normal termination
7405
    read_data`READ_ADDRESS = target_address + 12 ;
7406
    read_data`READ_SEL     = 4'hF ;
7407
 
7408
    wishbone_master.blk_read_data_in[0] = read_data ;
7409
 
7410
    read_data`READ_ADDRESS = target_address + 16 ;
7411
    read_data`READ_SEL     = 4'hF ;
7412
 
7413
    wishbone_master.blk_read_data_in[1] = read_data ;
7414
 
7415
    write_flags`WB_TRANSFER_SIZE = 2 ;
7416
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7417
    write_flags`WB_TRANSFER_CAB = 1 ;
7418
 
7419
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7420
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7421
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7422
 
7423
    fork
7424
    begin
7425
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7426
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7427
        begin
7428
            $display("Transaction progress testing failed! Time %t ", $time) ;
7429
            $display("Bridge processed CAB read wrong!") ;
7430
            test_fail("bridge didn't process burst read as expected") ;
7431
            ok = 0 ;
7432
        end
7433
    end
7434
    begin
7435
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7436
        if ( ok !== 1 )
7437
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7438
    end
7439
    join
7440
 
7441
    if ( ok )
7442
    begin
7443
        read_status = wishbone_master.blk_read_data_out[0] ;
7444
        if ( read_status`READ_DATA !== wmem_data[3] )
7445
        begin
7446
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7447
            test_fail("data provided from normaly terminated read was wrong") ;
7448
            ok = 0 ;
7449
        end
7450
 
7451
        read_status = wishbone_master.blk_read_data_out[1] ;
7452
        if ( read_status`READ_DATA !== wmem_data[4] )
7453
        begin
7454
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7455
            test_fail("data provided from normaly terminated read was wrong") ;
7456
            ok = 0 ;
7457
        end
7458
    end
7459
 
7460
    if ( ok )
7461
        test_ok ;
7462
 
7463
    // disable memory read line command and enable prefetch
7464
    // prepare image control register
7465
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7466
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7467
    if ( ok !== 1 )
7468
    begin
7469
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7470
        test_fail("WB Image Control register couldn't be written to") ;
7471
        disable main ;
7472
    end
7473
 
7474
    write_flags`WB_TRANSFER_SIZE = 4 ;
7475
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7476
    write_flags`WB_TRANSFER_CAB = 1 ;
7477
 
7478
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7479
 
7480
    for ( i = 0 ; i < 4 ; i = i + 1 )
7481
    begin
7482
        read_data`READ_ADDRESS = target_address + i*4 ;
7483
        read_data`READ_SEL     = 4'b1010 ;
7484
 
7485
        wishbone_master.blk_read_data_in[i] = read_data ;
7486
    end
7487
 
7488
    fork
7489
    begin
7490
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7491
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7492
        begin
7493
            $display("Transaction progress testing failed! Time %t ", $time) ;
7494
            $display("Bridge processed CAB read wrong!") ;
7495
            test_fail("bridge didn't process prefetched burst read as expected") ;
7496
            ok = 0 ;
7497
        end
7498
    end
7499
    begin
7500
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7501
        if ( ok !== 1 )
7502
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7503
    end
7504
    join
7505
 
7506
    if ( ok )
7507
    begin
7508
        for ( i = 0 ; i < 4 ; i = i + 1 )
7509
        begin
7510
            read_status = wishbone_master.blk_read_data_out[i] ;
7511
            if ( read_status`READ_DATA !== wmem_data[i] )
7512
            begin
7513
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7514
                test_fail("burst read returned unexpected data") ;
7515
                ok = 0 ;
7516
            end
7517
        end
7518
    end
7519
 
7520
    if ( ok )
7521
        test_ok ;
7522
 
7523
    // do one single read with different byte enables
7524
    read_data`READ_ADDRESS = target_address + 4 ;
7525
    read_data`READ_SEL     = 4'b1010 ;
7526
 
7527
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7528
    fork
7529
    begin
7530
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7531
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7532
        begin
7533
            $display("Transaction progress testing failed! Time %t ", $time) ;
7534
            $display("Bridge processed single read wrong!") ;
7535
            test_fail("bridge didn't process single memory read as expected") ;
7536
            ok = 0 ;
7537
        end
7538
    end
7539
    begin
7540
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7541
        if ( ok !== 1 )
7542
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7543
    end
7544
    join
7545
 
7546
    // check read data
7547
    if ( ok )
7548
    begin
7549
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7550
        begin
7551
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7552
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7553
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7554
            ok = 0 ;
7555
            test_fail("unexpected data received from single read") ;
7556
        end
7557
    end
7558
 
7559
    if ( ok )
7560
         test_ok ;
7561
 
7562
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7563
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7564
 
7565
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7566
    if ( ok !== 1 )
7567
    begin
7568
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7569
        test_fail("WB Image Control register could not be written") ;
7570
        disable main ;
7571
    end
7572
 
7573
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7574
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7575
    begin
7576
        read_data`READ_ADDRESS = target_address + i*4 ;
7577
        read_data`READ_SEL     = 4'b1111 ;
7578
 
7579
        wishbone_master.blk_read_data_in[i] = read_data ;
7580
    end
7581
 
7582
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7583
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7584
    write_flags`WB_TRANSFER_CAB = 1 ;
7585
 
7586
    fork
7587
    begin
7588
        read_status         = 0 ;
7589
        read_status`CYC_RTY = 1 ;
7590
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7591
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7592
 
7593
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7594
        begin
7595
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7596
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7597
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7598
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7599
            ok = 0 ;
7600
        end
7601
    end
7602
    begin
7603
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7604
        if ( ok !== 1 )
7605
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7606
    end
7607
    join
7608
 
7609
    // now repeat single read to flush redundant read initiated
7610
    write_flags`WB_TRANSFER_SIZE = 1 ;
7611
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7612
    write_flags`WB_TRANSFER_CAB = 1 ;
7613
 
7614
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7615
    read_data`READ_SEL     = 4'hF ;
7616
 
7617
    wishbone_master.blk_read_data_in[0] = read_data ;
7618
 
7619
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7620
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7621
 
7622
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7623
    begin
7624
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7625
        $display(" PCI bridge failed to process single CAB read!") ;
7626
        test_fail("single CAB write was not processed as expected") ;
7627
    end
7628
 
7629
    // because last read could be very long on PCI - delete target abort status
7630
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7631
 
7632
    // write unsupported value to cache line size register
7633
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7634
 
7635
    read_data`READ_ADDRESS = target_address ;
7636
    read_data`READ_SEL     = 4'hF ;
7637
    wishbone_master.blk_read_data_in[0] = read_data ;
7638
 
7639
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7640
    // perform a read
7641
    fork
7642
    begin
7643
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7644
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7645
        begin
7646
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7647
            $display(" PCI bridge failed to process single CAB read!") ;
7648
            test_fail("burst read was not processed as expected") ;
7649
            ok = 0 ;
7650
        end
7651
    end
7652
    begin
7653
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7654
        if ( ok !== 1 )
7655
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7656
    end
7657
    join
7658
 
7659
    if ( ok )
7660
        test_ok ;
7661
 
7662
    // write 2 to cache line size register
7663
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7664
 
7665
    // perform a read
7666
    fork
7667
    begin
7668
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7669
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7670
        begin
7671
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7672
            $display(" PCI bridge failed to process single CAB read!") ;
7673
            test_fail("burst read was not processed as expected") ;
7674
            ok = 0 ;
7675
        end
7676
    end
7677
    begin
7678
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7679
        if ( ok !== 1 )
7680
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7681
    end
7682
    join
7683
 
7684
    if ( ok )
7685
        test_ok ;
7686
 
7687
    // write 0 to cache line size
7688
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7689
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7690
 
7691
    // perform a read
7692
    fork
7693
    begin
7694
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7695
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7696
        begin
7697
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7698
            $display(" PCI bridge failed to process single CAB read!") ;
7699
            test_fail("burst read was not processed as expected") ;
7700
            ok = 0 ;
7701
        end
7702
    end
7703
    begin
7704
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7705
        if ( ok !== 1 )
7706
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7707
    end
7708
    join
7709
 
7710
    if ( ok )
7711
        test_ok ;
7712
 
7713
    // write normal value to cls register
7714
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7715
 
7716
    $display("Testing Master's latency timer operation!") ;
7717
    $display("Testing Latency timer during Master Writes!") ;
7718
 
7719
    for ( i = 0 ; i < 6 ; i = i + 1 )
7720
    begin
7721
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7722
        write_data`WRITE_SEL     = 4'b1111 ;
7723
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7724
 
7725
        wishbone_master.blk_write_data[i] = write_data ;
7726
    end
7727
 
7728
    write_flags`WB_TRANSFER_SIZE = 6 ;
7729
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7730
    write_flags`WB_TRANSFER_CAB = 1 ;
7731
 
7732
    // start wb write, pci write and monitor in parallel
7733
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7734
    fork
7735
    begin
7736
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7737
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7738
        begin
7739
            $display("Transaction progress testing failed! Time %t ", $time) ;
7740
            $display("Bridge failed to process CAB write!") ;
7741
            test_fail("bridge didn't post whole burst memory write") ;
7742
            disable main ;
7743
        end
7744
    end
7745 106 mihad
    begin:cab_master_write_interrupted_by_latency_timeout2
7746
        reg [31:0] ret_adr ; reg [3:0] ret_bc ; reg ret_gnt_deasserted ;
7747
        integer ret_num_of_transfers ; integer ret_num_of_cycles ;
7748
 
7749
        ok = 1'b1 ;
7750
 
7751 15 mihad
        // wait for bridge's master to start transaction
7752 106 mihad
        monitor32.get_pci_op(ret_adr, ret_bc) ;
7753 15 mihad
 
7754 106 mihad
        if (ret_adr !== target_address)
7755
        begin
7756
            $display("%m detected an error!") ;
7757
            test_fail("invalid address was detected when PCI Master initiated a burst write operation") ;
7758
            ok = 0 ;
7759
        end
7760 15 mihad
 
7761 106 mihad
        if (ret_bc !== `BC_MEM_WRITE)
7762
        begin
7763
            $display("%m detected an error!") ;
7764
            test_fail("invalid bus command was detected when PCI Master should initiate a burst write operation") ;
7765
            ok = 0 ;
7766
        end
7767
 
7768
        // remove the grant from PCI Bridge
7769
        tc_gnt_allow = 1'b1 ;
7770
 
7771
        fork
7772
        begin
7773
            monitor32.get_pci_op_num_of_transfers(ret_num_of_transfers, ret_gnt_deasserted) ;
7774
        end
7775
        begin
7776
            monitor32.get_pci_op_num_of_cycles(ret_num_of_cycles) ;
7777
        end
7778
        join
7779
 
7780
        // put arbiter back into the control of the grant line
7781
        tc_gnt_allow = 1'b0 ;
7782
 
7783
        // check number of cycles bridge kept the frame asserted!
7784
        if (ret_gnt_deasserted !== 1'b1)
7785
        begin
7786
            $display("%m detected an error!") ;
7787
            test_fail("GNT line wasn't deasserted during latency timer operation tests") ;
7788
            ok = 0 ;
7789
        end
7790 15 mihad
        else
7791 106 mihad
        begin
7792
            if (ret_num_of_cycles > 2)
7793
            begin
7794
                $display("%m detected an error!") ;
7795
                test_fail("PCI Master was expected to deassert FRAME after two cycles and it didn't do that!") ;
7796
                ok = 0 ;
7797
            end
7798
        end
7799
 
7800
        if (ret_num_of_transfers !== 2)
7801
        begin
7802
            $display("%m detected an error!") ;
7803
            test_fail("PCI Master must didn't transfer 2 words in a burst, latency timer was set to a value of 2 and timeout occured") ;
7804
            ok = 0 ;
7805
        end
7806
 
7807
        // now check the remainder of the transaction!
7808
        if (ok === 1'b1)
7809
        begin
7810
            pci_transaction_progress_monitor(target_address + 4 * ret_num_of_transfers, `BC_MEM_WRITE, 6 - ret_num_of_transfers, 0, 1'b1, 1'b0, 0, ok) ;
7811
            if (ok !== 1'b1)
7812
            begin
7813
                $display("%m detected an error!") ;
7814
                test_fail("PCI Master did invalid transaction on PCI bus") ;
7815
                ok = 0 ;
7816
            end
7817
        end
7818
 
7819
        if (ok === 1'b1)
7820 15 mihad
            test_ok ;
7821
    end
7822
    join
7823
 
7824
    // perform a read to check data
7825
    for ( i = 0 ; i < 6 ; i = i + 1 )
7826
    begin
7827
        read_data`READ_ADDRESS = target_address + i*4 ;
7828
        read_data`READ_SEL     = 4'b1111 ;
7829
 
7830
        wishbone_master.blk_read_data_in[i] = read_data ;
7831
    end
7832
 
7833
    write_flags`WB_TRANSFER_SIZE = 6 ;
7834
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7835
    write_flags`WB_TRANSFER_CAB = 1 ;
7836
 
7837 106 mihad
    test_name = "CHECK VALUES OF BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7838 15 mihad
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7839
 
7840
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7841
    begin
7842
        $display("Transaction progress testing failed! Time %t ", $time) ;
7843
        $display("Bridge failed to process CAB read!") ;
7844
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7845
        disable main ;
7846
    end
7847
 
7848
    ok = 1 ;
7849
    for ( i = 0 ; i < 6 ; i = i + 1 )
7850
    begin
7851
        read_status = wishbone_master.blk_read_data_out[i] ;
7852
 
7853
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7854
        begin
7855
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7856
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7857
            test_fail("unexpected data read back from PCI") ;
7858
            ok = 0 ;
7859
        end
7860
    end
7861
 
7862
    if ( ok )
7863
        test_ok ;
7864
 
7865
    $display("Testing Latency timer during Master Reads!") ;
7866
 
7867
    // at least 2 words are transfered during Master Reads terminated with timeout
7868
    write_flags`WB_TRANSFER_SIZE = 2 ;
7869
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7870
    fork
7871
    begin
7872
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7873
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7874
        begin
7875
            $display("Transaction progress testing failed! Time %t ", $time) ;
7876
            $display("Bridge failed to process CAB read!") ;
7877
            test_fail("bridge didn't process burst read as expected") ;
7878
            ok = 0 ;
7879
        end
7880
    end
7881 106 mihad
    begin:cab_memory_read_interrupted_by_latency_timeout2
7882
        reg [31:0] ret_adr ; reg [3:0] ret_bc ; reg ret_gnt_deasserted ;
7883
        integer ret_num_of_transfers ; integer ret_num_of_cycles ;
7884
 
7885
        ok = 1'b1 ;
7886
 
7887 15 mihad
        // wait for bridge's master to start transaction
7888 106 mihad
        monitor32.get_pci_op(ret_adr, ret_bc) ;
7889 15 mihad
 
7890 106 mihad
        if (ret_adr !== target_address)
7891
        begin
7892
            $display("%m detected an error!") ;
7893
            test_fail("invalid address was detected when PCI Master initiated a burst read operation") ;
7894
            ok = 0 ;
7895
        end
7896 15 mihad
 
7897 106 mihad
        if (ret_bc !== `BC_MEM_READ_MUL)
7898
        begin
7899
            $display("%m detected an error!") ;
7900
            test_fail("invalid bus command was detected when PCI Master should initiate a burst read operation") ;
7901
            ok = 0 ;
7902
        end
7903
 
7904
        // remove the grant from PCI Bridge
7905
        tc_gnt_allow = 1'b1 ;
7906
 
7907
        fork
7908
        begin
7909
            monitor32.get_pci_op_num_of_transfers(ret_num_of_transfers, ret_gnt_deasserted) ;
7910
        end
7911
        begin
7912
            monitor32.get_pci_op_num_of_cycles(ret_num_of_cycles) ;
7913
        end
7914
        join
7915
 
7916
        // put arbiter back into the control of the grant line
7917
        tc_gnt_allow = 1'b0 ;
7918
 
7919
        // check number of cycles bridge kept the frame asserted!
7920
        if (ret_gnt_deasserted !== 1'b1)
7921
        begin
7922
            $display("%m detected an error!") ;
7923
            test_fail("GNT line wasn't deasserted during latency timer operation tests") ;
7924
            ok = 0 ;
7925
        end
7926
        else
7927
        begin
7928
            if (ret_num_of_cycles > 2)
7929
            begin
7930
                $display("%m detected an error!") ;
7931
                test_fail("PCI Master was expected to deassert FRAME after two cycles and it didn't do that!") ;
7932
                ok = 0 ;
7933
            end
7934
        end
7935
 
7936
        if (ret_num_of_transfers !== 2)
7937
        begin
7938
            $display("%m detected an error!") ;
7939
            test_fail("PCI Master must didn't transfer 2 words in a burst, latency timer was set to a value of 2 and timeout occured") ;
7940
            ok = 0 ;
7941
        end
7942 15 mihad
    end
7943
    join
7944
 
7945
    // check data provided by target
7946
    if ( ok )
7947
    begin
7948
        for ( i = 0 ; i < 2 ; i = i + 1 )
7949
        begin
7950
            read_status = wishbone_master.blk_read_data_out[i] ;
7951
 
7952
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7953
            begin
7954
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7955
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7956
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7957
                ok = 0 ;
7958
            end
7959
        end
7960
    end
7961 106 mihad
 
7962 15 mihad
    if ( ok )
7963
        test_ok ;
7964
 
7965
    test_name = "DISABLE_IMAGE" ;
7966
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7967
    if ( ok !== 1 )
7968
    begin
7969
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7970
        test_fail("write to WB Address Mask register failed") ;
7971
        disable main ;
7972
    end
7973
 
7974
end
7975
endtask //wb_to_pci_transactions
7976
 
7977
task iack_cycle ;
7978
    reg `READ_STIM_TYPE   read_data ;
7979
    reg `READ_RETURN_TYPE read_status ;
7980
    reg `WB_TRANSFER_FLAGS flags ;
7981
 
7982
    reg [31:0] temp_var ;
7983
    reg ok ;
7984 45 mihad
    reg ok_wb ;
7985
    reg ok_pci ;
7986
 
7987
    reg [31:0] irq_vector ;
7988 15 mihad
begin
7989
 
7990 45 mihad
    ok     = 1 ;
7991
    ok_wb  = 1 ;
7992
    ok_pci = 1 ;
7993
 
7994 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7995
 
7996
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7997
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7998
 
7999
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
8000
    read_data`READ_SEL     = 4'hF ;
8001
 
8002
    flags = 0 ;
8003
 
8004
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
8005
 
8006
    irq_vector  = 32'hAAAA_AAAA ;
8007
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
8008
 
8009 45 mihad
    // disable both pci blue behavioral targets
8010
    configuration_cycle_write
8011
    (
8012
        0,                          // bus number [7:0]
8013
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
8014
        0,                          // function number [2:0]
8015
        1,                          // register number [5:0]
8016
        0,                          // type [1:0]
8017
        4'h1,                       // byte enables [3:0]
8018
        32'h0000_0044               // data to write [31:0]
8019
    ) ;
8020
 
8021
    configuration_cycle_write
8022
    (
8023
        0,                          // bus number [7:0]
8024
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
8025
        0,                          // function number [2:0]
8026
        1,                          // register number [5:0]
8027
        0,                          // type [1:0]
8028
        4'h1,                       // byte enables [3:0]
8029
        32'h0000_0044               // data to write [31:0]
8030
    ) ;
8031
 
8032 15 mihad
    fork
8033
    begin
8034
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
8035
    end
8036
    begin
8037 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
8038
        if ( ok_pci !== 1 )
8039 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
8040
    end
8041
    join
8042
 
8043
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
8044
    begin
8045 45 mihad
        ok_wb = 0 ;
8046 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
8047
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
8048
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
8049
    end
8050 45 mihad
 
8051
    if ( ok_pci && ok_wb )
8052 15 mihad
        test_ok ;
8053 45 mihad
 
8054
    ok_wb = 1 ;
8055
    ok_pci = 1 ;
8056
    ok = 1 ;
8057 15 mihad
 
8058 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
8059
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
8060 15 mihad
 
8061
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
8062 45 mihad
    // enable pci blue behavioral target 1
8063
    configuration_cycle_write
8064
    (
8065
        0,                          // bus number [7:0]
8066
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
8067
        0,                          // function number [2:0]
8068
        1,                          // register number [5:0]
8069
        0,                          // type [1:0]
8070
        4'h1,                       // byte enables [3:0]
8071
        32'h0000_0047               // data to write [31:0]
8072
    ) ;
8073 15 mihad
    fork
8074
    begin
8075
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
8076
    end
8077
    begin
8078 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
8079
        if ( ok_pci !== 1 )
8080 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
8081
    end
8082
    join
8083
 
8084
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8085
    begin
8086 45 mihad
        ok_wb = 0 ;
8087 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
8088
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
8089
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
8090
    end
8091
 
8092
    if ( read_status`READ_DATA !== irq_vector )
8093
    begin
8094
        $display(" Time %t ", $time ) ;
8095
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
8096
        test_fail("Interrupt Acknowledge returned unexpected data") ;
8097 45 mihad
        ok_wb = 0 ;
8098 15 mihad
    end
8099
 
8100 45 mihad
    if ( ok_pci && ok_wb )
8101 15 mihad
        test_ok ;
8102
 
8103 45 mihad
    ok_pci = 1 ;
8104
    ok_wb  = 1 ;
8105
    ok     = 1 ;
8106
 
8107 15 mihad
    read_data`READ_SEL = 4'b0101 ;
8108 45 mihad
    irq_vector  = 32'h5555_5555 ;
8109
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
8110
 
8111 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
8112
    fork
8113
    begin
8114
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
8115
    end
8116
    begin
8117 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
8118
        if ( ok_pci !== 1 )
8119 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
8120
    end
8121
    join
8122
 
8123
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8124
    begin
8125
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
8126
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
8127
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
8128 45 mihad
        ok_wb = 0 ;
8129 15 mihad
    end
8130
 
8131 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
8132 15 mihad
    begin
8133
        $display(" Time %t ", $time ) ;
8134 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
8135 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
8136 45 mihad
        ok_wb = 0 ;
8137 15 mihad
    end
8138
 
8139 45 mihad
    if (ok_pci && ok_wb)
8140 15 mihad
        test_ok ;
8141
 
8142 45 mihad
    ok_pci = 1 ;
8143
    ok_wb  = 1 ;
8144
    ok     = 1 ;
8145 15 mihad
 
8146 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
8147
 
8148
    // set target to terminate with target abort
8149
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
8150
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8151
 
8152
    fork
8153
    begin
8154
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
8155
    end
8156
    begin
8157
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
8158
        if ( ok_pci !== 1 )
8159
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
8160
    end
8161
    join
8162
 
8163
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
8164
    begin
8165
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
8166
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
8167
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
8168
        ok_wb = 0 ;
8169
    end
8170
 
8171
    // set target to terminate with target abort
8172
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
8173
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
8174
 
8175
    // enable pci blue behavioral target 2
8176
    configuration_cycle_write
8177
    (
8178
        0,                          // bus number [7:0]
8179
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
8180
        0,                          // function number [2:0]
8181
        1,                          // register number [5:0]
8182
        0,                          // type [1:0]
8183
        4'h1,                       // byte enables [3:0]
8184
        32'h0000_0047               // data to write [31:0]
8185
    ) ;
8186
 
8187
    // read PCI Device status
8188
    config_read(12'h4, 4'hC, temp_var) ;
8189
    if (temp_var[29] !== 1)
8190
    begin
8191
        $display("Time %t", $time) ;
8192
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
8193
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
8194
        ok_wb = 0 ;
8195
    end
8196
 
8197
    if (temp_var[28] !== 1)
8198
    begin
8199
        $display("Time %t", $time) ;
8200
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
8201
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
8202
        ok_wb = 0 ;
8203
    end
8204
 
8205
    // clearing the status bits
8206
        config_write(12'h4, temp_var, 4'hC, ok);
8207
 
8208
    if ( ok && ok_pci && ok_wb )
8209
        test_ok ;
8210
 
8211 15 mihad
end
8212
endtask //iack_cycle
8213
 
8214
task transaction_ordering ;
8215
    reg   [11:0] wb_ctrl_offset ;
8216
    reg   [11:0] wb_ba_offset ;
8217
    reg   [11:0] wb_am_offset ;
8218
    reg   [11:0] pci_ctrl_offset ;
8219
    reg   [11:0] pci_ba_offset ;
8220
    reg   [11:0] pci_am_offset ;
8221
    reg   [11:0] pci_device_ctrl_offset ;
8222
    reg   [11:0] wb_err_cs_offset ;
8223
    reg   [11:0] pci_err_cs_offset ;
8224
    reg   [11:0] icr_offset ;
8225
    reg   [11:0] isr_offset ;
8226
    reg   [11:0] lat_tim_cls_offset ;
8227
 
8228
    reg `WRITE_STIM_TYPE  write_data ;
8229
    reg `READ_STIM_TYPE   read_data ;
8230
    reg `READ_RETURN_TYPE read_status ;
8231
 
8232
    reg `WRITE_RETURN_TYPE write_status ;
8233
    reg `WB_TRANSFER_FLAGS write_flags ;
8234
    reg [31:0] temp_val1 ;
8235
    reg [31:0] temp_val2 ;
8236
    reg        ok   ;
8237
 
8238
    reg [31:0] wb_image_base ;
8239
    reg [31:0] wb_target_address ;
8240
    reg [31:0] pci_image_base ;
8241
    integer i ;
8242
 
8243
    reg     error_monitor_done ;
8244
begin:main
8245 92 mihad
    write_flags`INIT_WAITS   = wb_init_waits ;
8246
    write_flags`SUBSEQ_WAITS = wb_subseq_waits ;
8247 15 mihad
 
8248
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
8249
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
8250
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
8251
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
8252
 
8253
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
8254
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
8255
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
8256
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
8257
 
8258
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
8259
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
8260
    lat_tim_cls_offset = 12'hC ;
8261
    pci_device_ctrl_offset    = 12'h4 ;
8262
 
8263
    wb_target_address  = `BEH_TAR1_MEM_START ;
8264
    wb_image_base      = 0 ;
8265
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
8266
 
8267
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
8268
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
8269
    write_flags                    = 0 ;
8270
    write_flags`INIT_WAITS         = 0 ;
8271
    write_flags`SUBSEQ_WAITS       = 0 ;
8272
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8273
 
8274
    pci_image_base = Target_Base_Addr_R[1] ;
8275
 
8276
    // enable master & target operation
8277
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
8278
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
8279
    if ( ok !== 1 )
8280
    begin
8281
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
8282
        test_fail("write to PCI Device Control register failed") ;
8283
        disable main ;
8284
    end
8285
 
8286
    // prepare image control register
8287
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8288
    if ( ok !== 1 )
8289
    begin
8290
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
8291
        test_fail("write to WB Image Control register failed") ;
8292
        disable main ;
8293
    end
8294
 
8295
    // prepare base address register
8296
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8297
    if ( ok !== 1 )
8298
    begin
8299
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8300
        test_fail("write to WB Base Address register failed") ;
8301
        disable main ;
8302
    end
8303
 
8304
    // write address mask register
8305
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8306
    if ( ok !== 1 )
8307
    begin
8308
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8309
        test_fail("write to WB Address Mask register failed") ;
8310
        disable main ;
8311
    end
8312
 
8313
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8314
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8315
    if ( ok !== 1 )
8316
    begin
8317
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8318
        test_fail("write to WB Error Control and Status register failed") ;
8319
        disable main ;
8320
    end
8321
 
8322
    // prepare image control register
8323
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8324
    if ( ok !== 1 )
8325
    begin
8326
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8327
        test_fail("write to PCI Image Control register failed") ;
8328
        disable main ;
8329
    end
8330
 
8331
    // prepare base address register
8332
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8333
    if ( ok !== 1 )
8334
    begin
8335
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8336
        test_fail("write to PCI Base Address register failed") ;
8337
        disable main ;
8338
    end
8339
 
8340
    // write address mask register
8341
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8342
    if ( ok !== 1 )
8343
    begin
8344
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8345
        test_fail("write to PCI Address Mask register failed") ;
8346
        disable main ;
8347
    end
8348
 
8349
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8350
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8351
    if ( ok !== 1 )
8352
    begin
8353
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8354
        test_fail("write to PCI Error Control and Status register failed") ;
8355
        disable main ;
8356
    end
8357
 
8358
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8359
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8360
    if ( ok !== 1 )
8361
    begin
8362
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8363
        test_fail("write to Interrupt Control register failed") ;
8364
        disable main ;
8365
    end
8366
 
8367
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8368
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8369
    if ( ok !== 1 )
8370
    begin
8371
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8372
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8373
        disable main ;
8374
    end
8375
 
8376
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8377
 
8378
    // prepare wb_master write and read data
8379
    for ( i = 0 ; i < 4 ; i = i + 1 )
8380
    begin
8381
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8382
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8383
        write_data`WRITE_SEL     = 4'hF ;
8384
 
8385
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8386
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8387
 
8388
        wishbone_master.blk_write_data[i]   = write_data ;
8389
        wishbone_master.blk_read_data_in[i] = read_data ;
8390
    end
8391
 
8392
    // put wishbone slave in acknowledge and pci target in retry mode
8393
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8394
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8395
 
8396 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8397 15 mihad
 
8398
    fork
8399
    begin
8400
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8401
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8402
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8403
        begin
8404
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8405
            test_fail("Bridge didn't post single memory write as expected") ;
8406
        end
8407
 
8408
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8409
        if ( ok !== 1 )
8410
        begin
8411
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8412
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8413
            ok = 0 ;
8414
        end
8415
 
8416
        // now post single write to target - normal progress
8417
        if ( target_mem_image == 1 )
8418
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8419
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8420
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8421
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8422
        else
8423
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8424
 
8425
        do_pause( 1 ) ;
8426
 
8427
    end
8428
    begin:error_monitor_1
8429 35 mihad
        error_monitor_done = 0 ;
8430 15 mihad
        @(error_event_int) ;
8431
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8432
        ok = 0 ;
8433 35 mihad
        error_monitor_done = 1 ;
8434 15 mihad
    end
8435
    begin
8436
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8437
        if ( ok !== 1 )
8438
        begin
8439
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8440
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8441
        end
8442
        else
8443
        begin
8444 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8445
//            while ( FRAME === 0 || IRDY === 0 )
8446
//                @(posedge pci_clock) ;
8447 15 mihad
 
8448
            // enable response in PCI target
8449
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8450
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8451
 
8452
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8453
            if ( ok !== 1 )
8454
            begin
8455
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8456
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8457
            end
8458
        end
8459
 
8460 35 mihad
        #1 ;
8461
        if ( !error_monitor_done )
8462
            disable error_monitor_1 ;
8463 15 mihad
    end
8464
    join
8465
 
8466
    if ( ok )
8467
        test_ok ;
8468
 
8469
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8470
 
8471
    // put WISHBONE slave in retry mode
8472 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'hFF);
8473 15 mihad
 
8474
    fork
8475
    begin
8476
        // now post single write to target - normal progress
8477
        if ( target_mem_image == 1 )
8478
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8479
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8480
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8481
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8482
        else
8483
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8484
 
8485
        do_pause( 1 ) ;
8486
 
8487
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8488
        if ( ok !== 1 )
8489
        begin
8490
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8491
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8492
        end
8493
 
8494
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8495
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8496
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8497
        begin
8498
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8499
            test_fail("Bridge didn't post single memory write as expected") ;
8500
        end
8501
 
8502
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8503
        if ( ok !== 1 )
8504
        begin
8505
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8506
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8507
            ok = 0 ;
8508
        end
8509
 
8510
        wait ( CYC_O === 0 ) ;
8511 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8512 15 mihad
 
8513
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8514
        if ( ok !== 1 )
8515
        begin
8516
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8517
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8518
        end
8519
 
8520 35 mihad
        #1 ;
8521
        if ( !error_monitor_done )
8522
            disable error_monitor_2 ;
8523 15 mihad
    end
8524
    begin:error_monitor_2
8525 35 mihad
        error_monitor_done = 0 ;
8526 15 mihad
        @(error_event_int) ;
8527
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8528
        ok = 0 ;
8529 35 mihad
        error_monitor_done = 1 ;
8530 15 mihad
    end
8531
    join
8532
 
8533
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8534
 
8535
    // put wishbone slave in acknowledge and pci target in retry mode
8536
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8537
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8538
 
8539 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8540 15 mihad
 
8541
    fork
8542
    begin
8543
        write_flags`WB_TRANSFER_SIZE = 3 ;
8544
        write_flags`WB_TRANSFER_CAB  = 1 ;
8545
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8546
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8547
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8548
        begin
8549
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8550
            test_fail("Bridge didn't post burst memory write as expected") ;
8551
        end
8552
 
8553
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8554
        if ( ok !== 1 )
8555
        begin
8556
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8557
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8558
            ok = 0 ;
8559
        end
8560
 
8561
        // now post single write to target - normal progress
8562
        if ( target_mem_image == 1 )
8563
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8564
                        pci_image_base, 32'h5555_5555, 4'h0,
8565
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8566
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8567
        else
8568
        begin
8569
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8570
            do_pause( 1 ) ;
8571
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8572
        end
8573
 
8574
        do_pause( 1 ) ;
8575
 
8576
    end
8577
    begin:error_monitor_3
8578 35 mihad
        error_monitor_done = 0 ;
8579 15 mihad
        @(error_event_int) ;
8580
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8581
        ok = 0 ;
8582 35 mihad
        error_monitor_done = 1 ;
8583 15 mihad
    end
8584
    begin
8585
        if ( target_mem_image == 1 )
8586
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8587
        else
8588
        begin
8589
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8590
            if ( ok )
8591
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8592
        end
8593
 
8594
        if ( ok !== 1 )
8595
        begin
8596
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8597
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8598
        end
8599
        else
8600
        begin
8601 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8602
//            while ( FRAME === 0 || IRDY === 0 )
8603
//                @(posedge pci_clock) ;
8604 15 mihad
 
8605
            // enable response in PCI target
8606
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8607
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8608
 
8609
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8610
            if ( ok !== 1 )
8611
            begin
8612
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8613
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8614
            end
8615
        end
8616
 
8617 35 mihad
        #1 ;
8618
        if ( !error_monitor_done )
8619
            disable error_monitor_3 ;
8620 15 mihad
    end
8621
    join
8622
 
8623
    if ( ok )
8624
        test_ok ;
8625
 
8626
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8627
 
8628
    // put WISHBONE slave in retry mode
8629 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'hFF);
8630 15 mihad
 
8631
    fork
8632
    begin
8633
        // now post single write to target - normal progress
8634
        if ( target_mem_image == 1 )
8635
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8636
                        pci_image_base, 32'h5555_5555, 4'h0,
8637
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8638
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8639
        else
8640
        begin
8641
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8642
            do_pause( 1 ) ;
8643
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8644
        end
8645
 
8646
        do_pause( 1 ) ;
8647
 
8648
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8649
 
8650
        if ( ok !== 1 )
8651
        begin
8652
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8653
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8654
        end
8655
 
8656
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8657
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8658
        write_flags`WB_TRANSFER_CAB      = 1 ;
8659
 
8660
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8661
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8662
        begin
8663
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8664
            test_fail("Bridge didn't post burst memory write as expected") ;
8665
        end
8666
 
8667
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8668
        if ( ok !== 1 )
8669
        begin
8670
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after burst memory write was posted! Time %t ", $time) ;
8671
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8672
            ok = 0 ;
8673
        end
8674
 
8675
        @(posedge wb_clock) ;
8676
        while ( CYC_O === 1 )
8677
            @(posedge wb_clock) ;
8678
 
8679 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8680 15 mihad
 
8681
        if ( target_mem_image == 1 )
8682
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8683
        else
8684
        begin
8685
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8686
            if ( ok )
8687
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8688
        end
8689
 
8690 35 mihad
        #1 ;
8691
        if ( !error_monitor_done )
8692
            disable error_monitor_4 ;
8693 15 mihad
    end
8694
    begin:error_monitor_4
8695 35 mihad
        error_monitor_done = 0 ;
8696 15 mihad
        @(error_event_int) ;
8697
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8698
        ok = 0 ;
8699 35 mihad
        error_monitor_done = 1 ;
8700 15 mihad
    end
8701
    join
8702
 
8703
    if ( ok )
8704
        test_ok ;
8705
 
8706
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8707
 
8708
    // put wishbone slave in acknowledge and pci target in retry mode
8709
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8710
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8711
 
8712 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8713 15 mihad
 
8714
    master1_check_received_data = 1 ;
8715
 
8716
    error_monitor_done = 0 ;
8717
    fork
8718
    begin:error_monitor_5
8719
        @(error_event_int or error_monitor_done) ;
8720
        if ( !error_monitor_done )
8721
        begin
8722
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8723
            ok = 0 ;
8724
        end
8725
    end
8726
    begin
8727
 
8728
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8729
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8730
        begin
8731
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8732
            test_fail("Bridge didn't post single memory write as expected") ;
8733
        end
8734
 
8735
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8736
        if ( ok !== 1 )
8737
        begin
8738
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8739
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8740
            ok = 0 ;
8741
        end
8742
 
8743
        // start Read Through pci target
8744
        if ( target_mem_image == 1 )
8745
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8746
                          pci_image_base, 32'h5555_5555,
8747
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8748
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8749
        else
8750
            PCIU_IO_READ
8751
             (
8752
                `Test_Master_1,
8753
                pci_image_base,
8754
                32'h5555_5555,
8755
                4'h0,
8756
                1,
8757
                `Test_Target_Retry_On
8758
             );
8759
 
8760
         do_pause( 1 ) ;
8761
 
8762
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8763
         if ( ok !== 1 )
8764
         begin
8765
            $display("Transaction ordering test failed! WB Master started invalid transaction or none at all on WB bus after single delayed read was requested! Time %t ", $time) ;
8766
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8767
         end
8768
 
8769
         // repeat the read 4 times - it should be retried all the time by pci target
8770
        for ( i = 0 ; i < 4 ; i = i + 1 )
8771
        begin
8772
            if ( target_mem_image == 1 )
8773
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8774
                            pci_image_base, 32'h5555_5555,
8775
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8776
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8777
            else
8778
                PCIU_IO_READ
8779
                (
8780
                    `Test_Master_1,
8781
                    pci_image_base,
8782
                    32'h5555_5555,
8783
                    4'h0,
8784
                    1,
8785
                    `Test_Target_Retry_On
8786
                );
8787
 
8788
            do_pause( 1 ) ;
8789
        end
8790
 
8791
        // now do posted write through target - it must go through OK
8792
        if ( target_mem_image == 1 )
8793
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8794
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8795
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8796
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8797
        else
8798
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8799
 
8800
        do_pause( 1 ) ;
8801
 
8802
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8803
        if ( ok !== 1 )
8804
        begin
8805
           $display("Transaction ordering test failed! WB Master started invalid transaction or none at all on WB bus after single write was posted! Time %t ", $time) ;
8806
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8807
        end
8808
 
8809
        // start a read through wb_slave
8810
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8811
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8812
        begin
8813
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8814
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8815
            ok = 0 ;
8816
        end
8817
 
8818 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8819
//        while ( FRAME === 0 || IRDY === 0 )
8820
//            @(posedge pci_clock) ;
8821 15 mihad
 
8822
        // set the target to normal completion
8823
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8824
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8825
 
8826
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8827
        if ( ok !== 1 )
8828
        begin
8829
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8830
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8831
            ok = 0 ;
8832
        end
8833
 
8834
        // now wait for delayed read to finish
8835
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8836
        if ( ok !== 1 )
8837
        begin
8838
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory read was requested! Time %t ", $time) ;
8839
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8840
            ok = 0 ;
8841
        end
8842
 
8843
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8844
        fork
8845
        begin
8846
                if ( target_mem_image == 1 )
8847
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8848
                                pci_image_base, 32'h5555_5555, 4'h0,
8849
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8850
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8851
                else
8852
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8853
 
8854
                do_pause( 1 ) ;
8855
                end
8856
                begin
8857 73 mihad
            pci_transaction_progress_monitor( pci_image_base, ((target_mem_image == 1) ? `BC_MEM_WRITE : `BC_IO_WRITE), 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8858 15 mihad
                end
8859
                join
8860
 
8861
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8862
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8863
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8864
        begin
8865
            $display("Transaction ordering test failed! WB Slave should reject posted memory write when delayed read completion is present in PCI Target Unit! Time %t ", $time) ;
8866
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8867
            ok = 0 ;
8868
        end
8869
 
8870
        fork
8871
        begin
8872
        // now complete a read from PCI Target
8873
            if ( target_mem_image == 1 )
8874
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8875
                            pci_image_base, 32'h5555_5555,
8876
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8877
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8878
            else
8879
                PCIU_IO_READ
8880
                (
8881
                    `Test_Master_1,
8882
                    pci_image_base,
8883
                    32'h5555_5555,
8884
                    4'h0,
8885
                    1,
8886
                    `Test_Target_Normal_Completion
8887
                );
8888
 
8889
            do_pause( 1 ) ;
8890
        end
8891
        begin
8892
            if ( target_mem_image == 1 )
8893
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8894
            else
8895
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8896
        end
8897
        join
8898
 
8899
        @(posedge pci_clock) ;
8900
        repeat( 4 )
8901
            @(posedge wb_clock) ;
8902
 
8903
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8904
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8905
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8906
        begin
8907
            $display("Transaction ordering test failed! WB Slave should accept posted memory write when delayed read completion is present in WB Slave Unit! Time %t ", $time) ;
8908
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8909
            ok = 0 ;
8910
        end
8911
 
8912
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8913
        if ( ok !== 1 )
8914
        begin
8915
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8916
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8917
            ok = 0 ;
8918
        end
8919
 
8920
        // finish a read on WISHBONE also
8921
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8922
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8923
        begin
8924
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8925
            test_fail("WB Slave didn't process single delayed read as expected") ;
8926
        end
8927
 
8928
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8929
        begin
8930
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8931
            ok = 0 ;
8932
        end
8933
 
8934
 
8935
        error_monitor_done = 1 ;
8936
    end
8937
    join
8938
 
8939
    if ( ok )
8940
        test_ok ;
8941
 
8942
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8943
 
8944
    // put wishbone slave in retry and pci target in completion mode
8945
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8946
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8947
 
8948 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'hFF);
8949 15 mihad
 
8950
    master1_check_received_data = 1 ;
8951
 
8952
    error_monitor_done = 0 ;
8953
    fork
8954
    begin:error_monitor_6
8955
        @(error_event_int or error_monitor_done) ;
8956
        if ( !error_monitor_done )
8957
        begin
8958
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8959
            ok = 0 ;
8960
        end
8961
    end
8962
    begin
8963
 
8964
        // do a write through Target
8965
        fork
8966
        begin
8967
            if ( target_mem_image == 1 )
8968
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8969
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8970
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8971
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8972
            else
8973
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8974
 
8975
            do_pause( 1 ) ;
8976
        end
8977
        begin
8978
            if ( target_mem_image == 1 )
8979
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8980
            else
8981
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8982
        end
8983
        join
8984
 
8985
        // start a read through WB slave
8986
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8987
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8988
        begin
8989
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8990
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8991
            ok = 0 ;
8992
        end
8993
 
8994
        // now wait for this read to finish on pci
8995
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8996
        if ( ok !== 1 )
8997
        begin
8998
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single delayed read was requested! Time %t ", $time) ;
8999
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
9000
            ok = 0 ;
9001
        end
9002
 
9003
        // repeat the read four times - it should be retried
9004
        for ( i = 0 ; i < 4 ; i = i + 1 )
9005
        begin
9006
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
9007
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
9008
            begin
9009
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
9010
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
9011
                ok = 0 ;
9012
            end
9013
        end
9014
 
9015
        // posted write through WB Slave - must go through
9016
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
9017
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
9018
        begin
9019
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
9020
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
9021
            ok = 0 ;
9022
        end
9023
 
9024
        // write must come through
9025
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9026
        if ( ok !== 1 )
9027
        begin
9028
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
9029
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
9030
            ok = 0 ;
9031
        end
9032
 
9033
        // do a read through pci target
9034
        if ( target_mem_image == 1 )
9035
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
9036
                          pci_image_base + 12, 32'hDEAD_BEAF,
9037
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
9038
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
9039
        else
9040
            PCIU_IO_READ
9041
             (
9042
                `Test_Master_1,
9043
                pci_image_base + 12,
9044
                32'hDEAD_BEAF,
9045
                4'h0,
9046
                1,
9047
                `Test_Target_Retry_On
9048
             );
9049
 
9050
         do_pause( 1 ) ;
9051
 
9052
        // wait for current cycle to finish on WB
9053 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
9054
//        @(posedge wb_clock) ;
9055
//        while( CYC_O === 1 )
9056
//            @(posedge wb_clock) ;
9057 15 mihad
 
9058
        // set slave response to acknowledge
9059 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
9060 15 mihad
 
9061
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
9062
        if ( ok !== 1 )
9063
        begin
9064
            $display("Transaction ordering test failed! WB Master started invalid transaction or none at all on WB bus after single write was posted! Time %t ", $time) ;
9065
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
9066
        end
9067
 
9068
        // check the read to finish on wb
9069
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
9070
        if ( ok !== 1 )
9071
        begin
9072
            $display("Transaction ordering test failed! WB Master started invalid transaction or none at all on WB bus after single delayed read was requested! Time %t ", $time) ;
9073
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
9074
        end
9075
 
9076
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
9077
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
9078
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
9079
        begin
9080
            $display("Transaction ordering test failed! WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit! Time %t ", $time) ;
9081
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
9082
            ok = 0 ;
9083
        end
9084
 
9085
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
9086
        fork
9087
        begin
9088
            if ( target_mem_image == 1 )
9089
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
9090
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
9091
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
9092
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
9093
            else
9094
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
9095
        end
9096
        begin
9097
            if ( target_mem_image == 1 )
9098
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9099
            else
9100
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9101
        end
9102
        join
9103
 
9104
        do_pause( 1 ) ;
9105
 
9106
        // complete a read in WB Slave Unit
9107
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
9108
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
9109
        begin
9110
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
9111
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
9112
            ok = 0 ;
9113
        end
9114
 
9115
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
9116
        begin
9117
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
9118
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
9119
            ok = 0 ;
9120
        end
9121
 
9122
        // wait for statuses to be propagated from one side of bridge to another
9123
        repeat( 4 )
9124
            @(posedge pci_clock) ;
9125
 
9126
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
9127
        fork
9128
        begin
9129
            if ( target_mem_image == 1 )
9130
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
9131
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
9132
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
9133
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9134
            else
9135
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
9136
 
9137
            do_pause( 1 ) ;
9138
        end
9139
        begin
9140
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
9141
            if ( ok !== 1 )
9142
            begin
9143
                $display("Transaction ordering test failed! WB Master started invalid transaction or none at all on WB bus after single write was posted! Time %t ", $time) ;
9144
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
9145
            end
9146
        end
9147
        join
9148
 
9149
        // finish the last read in PCI Target Unit
9150
        if ( target_mem_image == 1 )
9151
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
9152
                          pci_image_base + 12, 32'hDEAD_BEAF,
9153
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
9154
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9155
        else
9156
            PCIU_IO_READ
9157
             (
9158
                `Test_Master_1,
9159
                pci_image_base + 12,
9160
                32'hDEAD_BEAF,
9161
                4'h0,
9162
                1,
9163
                `Test_Target_Normal_Completion
9164
             );
9165
 
9166
         do_pause( 1 ) ;
9167
 
9168
         error_monitor_done = 1 ;
9169
    end
9170
    join
9171
 
9172 92 mihad
    // disable wb slave response
9173
    // fill pci target unit write fifo with single writes
9174
    // issue a read request - first all writes must finish on WB, than a read should finish on wishbone
9175
    test_name = "ORDERING OF THE TRANSACTIONS IN THE PCI TARGET UNIT ONLY" ;
9176
 
9177
    // set slave response to RETRY
9178
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'h0);
9179
 
9180
    fork
9181
    begin:pci_generator
9182
        repeat((`PCIW_DEPTH - 1) / 2)
9183
        begin
9184
            if ( target_mem_image == 1 )
9185
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
9186
                                 pci_image_base, 32'hF0F0_F0F0, 4'h0,
9187
                                 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
9188
                                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9189
            else
9190
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hF0F0_F0F0, 4'h0, 1, `Test_Target_Normal_Completion) ;
9191
 
9192
            do_pause(1) ;
9193
        end
9194
 
9195
        // now do a read request
9196
        if ( target_mem_image == 1 )
9197
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
9198
                          pci_image_base, 32'hF0F0_F0F0,
9199
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
9200
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
9201
        else
9202
            PCIU_IO_READ
9203
             (
9204
                `Test_Master_1,
9205
                pci_image_base,
9206
                32'hF0F0_F0F0,
9207
                4'h0,
9208
                1,
9209
                `Test_Target_Retry_On
9210
             );
9211
 
9212
        do_pause( 1 ) ;
9213
    end
9214
    begin:error_monitor_7
9215
        error_monitor_done = 1'b0 ;
9216
        @(error_event_int or error_monitor_done) ;
9217
        if ( !error_monitor_done )
9218
        begin
9219
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
9220
            ok = 0 ;
9221
        end
9222
    end
9223
    begin:pci_check
9224
        repeat((`PCIW_DEPTH - 1) / 2)
9225
        begin
9226
            if ( target_mem_image == 1 )
9227
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9228
            else
9229
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_WRITE,  1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9230
 
9231
            if (~ok)
9232
            begin
9233
                test_fail("PCI transaction monitor detected invalid transaction or none at all on PCI bus") ;
9234
            end
9235
        end
9236
 
9237
        if ( target_mem_image == 1 )
9238
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9239
        else
9240
            pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ,  0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9241
 
9242
        if (~ok)
9243
        begin
9244
            test_fail("PCI transaction monitor detected invalid transaction or none at all on PCI bus") ;
9245
        end
9246
 
9247
 
9248
        repeat(2)
9249
            @(posedge pci_clock) ;
9250
 
9251
        #1 error_monitor_done = 1'b1 ;
9252
    end
9253
    begin:wb_check
9254
 
9255
        // enable the wishbone slave right after the first finished retry response
9256
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
9257
 
9258
        if (~ok)
9259
        begin
9260
            test_fail("WB transaction monitor detected invalid transaction or none at all on WB bus") ;
9261
        end
9262
 
9263
        // set slave response to acknowledge
9264
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
9265
 
9266
        repeat((`PCIW_DEPTH - 1) / 2)
9267
        begin
9268
            wishbone_slave.wb_memory[0] = 32'hxxxx_xxxx ;
9269
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
9270
            if (~ok)
9271
            begin
9272
                test_fail("WB transaction monitor detected invalid transaction or none at all on WB bus") ;
9273
            end
9274
            if (wishbone_slave.wb_memory[0] !== 32'hF0F0_F0F0)
9275
            begin
9276
                test_fail("Invalid data written on WB bus") ;
9277
            end
9278
        end
9279
 
9280
        // now check for read
9281
        wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
9282
 
9283
        if (~ok)
9284
        begin
9285
            test_fail("WB transaction monitor detected invalid transaction or none at all on WB bus") ;
9286
        end
9287
 
9288
    end
9289
    join
9290
 
9291
    // wait for two pci cycles for statuses to propagate through sync logic
9292
    repeat(2)
9293
        @(posedge pci_clock) ;
9294
 
9295
    // now finish the read through PCI target
9296
    fork
9297
    begin
9298
        if ( target_mem_image == 1 )
9299
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
9300
                          pci_image_base, 32'hF0F0_F0F0,
9301
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
9302
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9303
        else
9304
            PCIU_IO_READ
9305
            (
9306
                `Test_Master_1,
9307
                pci_image_base,
9308
                32'hF0F0_F0F0,
9309
                4'h0,
9310
                1,
9311
                `Test_Target_Normal_Completion
9312
            );
9313
 
9314
        do_pause( 1 ) ;
9315
    end
9316
    begin
9317
        error_monitor_done = 1'b0 ;
9318
        @(error_event_int or error_monitor_done) ;
9319
        if ( !error_monitor_done )
9320
        begin
9321
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
9322
            ok = 0 ;
9323
        end
9324
    end
9325
    begin
9326
        if ( target_mem_image == 1 )
9327
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9328
        else
9329
            pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ,  1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9330
 
9331
        if (~ok)
9332
        begin
9333
            test_fail("PCI transaction monitor detected invalid transaction or none at all on PCI bus") ;
9334
        end
9335
 
9336
 
9337
        repeat(2)
9338
            @(posedge pci_clock) ;
9339
 
9340
        #1 error_monitor_done = 1'b1 ;
9341
    end
9342
    join
9343
 
9344 15 mihad
    if ( ok )
9345
        test_ok ;
9346
 
9347 92 mihad
    // disable the images
9348
    // write address mask register
9349
    config_write( wb_am_offset, 32'h0000_0000, 4'hF, ok ) ;
9350
    if ( ok !== 1 )
9351
    begin
9352
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
9353
        test_fail("write to WB Address Mask register failed") ;
9354
        disable main ;
9355
    end
9356
 
9357
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
9358
    if ( ok !== 1 )
9359
    begin
9360
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
9361
        test_fail("write to WB Address Mask register failed") ;
9362
        disable main ;
9363
    end
9364 15 mihad
end
9365
endtask // transaction_ordering
9366
 
9367
task pci_transaction_progress_monitor ;
9368
    input [31:0] address ;
9369
    input [3:0]  bus_command ;
9370
    input [31:0] num_of_transfers ;
9371
    input [31:0] num_of_cycles ;
9372
    input check_transfers ;
9373
    input check_cycles ;
9374
    input doing_fast_back_to_back ;
9375
    output ok ;
9376
    reg in_use ;
9377
    integer transfer_counter ;
9378
    integer cycle_counter ;
9379
    integer deadlock_max_val ;
9380
begin:main
9381
 
9382
    if ( in_use === 1 )
9383
    begin
9384
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9385
        ok = 0 ;
9386
        disable main ;
9387
    end
9388
 
9389 106 mihad
 
9390
    // number of ns to wait before timeout occurs
9391
    deadlock_max_val = `PCIW_DEPTH * 10 ;
9392
    deadlock_max_val = deadlock_max_val + `PCIR_DEPTH * 30 ;
9393 15 mihad
 
9394 106 mihad
    // time used for maximum transaction length on PCI
9395 15 mihad
    `ifdef PCI33
9396 106 mihad
    deadlock_max_val = deadlock_max_val * ( 30 ) ;
9397 15 mihad
    `else
9398 106 mihad
    deadlock_max_val = deadlock_max_val * ( 15 ) ;
9399 15 mihad
    `endif
9400
 
9401 106 mihad
    deadlock_max_val = deadlock_max_val + (`WBW_DEPTH * 10 * `WB_PERIOD) ;
9402
    deadlock_max_val = deadlock_max_val + (`WBR_DEPTH * 30 * `WB_PERIOD) ;
9403
 
9404 15 mihad
    in_use = 1 ;
9405
    ok     = 1 ;
9406
 
9407 106 mihad
    monitor32.get_pci_op.timeout_val = deadlock_max_val ;
9408 15 mihad
 
9409 106 mihad
    begin:monitor_blk
9410
        reg [31:0 ] returned_adr ;
9411
        reg [ 3:0 ] returned_cmd ;
9412
        reg         ret_gnt_deasserted ;
9413 15 mihad
 
9414 106 mihad
        monitor32.get_pci_op(returned_adr, returned_cmd) ;
9415 15 mihad
 
9416
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
9417
        if ( bus_command !== `BC_IACK )
9418
        begin
9419 106 mihad
            if ( returned_adr !== address )
9420 15 mihad
            begin
9421
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
9422 106 mihad
                $display("Expected address = %h, detected address = %h ", address, returned_adr) ;
9423 15 mihad
                ok = 0 ;
9424
            end
9425
        end
9426
 
9427 106 mihad
        if ( returned_cmd !== bus_command )
9428 15 mihad
        begin
9429
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
9430 106 mihad
            $display("Expected bus command = %b, detected bus command = %b", bus_command, returned_cmd) ;
9431 15 mihad
            ok = 0 ;
9432
        end
9433
 
9434 106 mihad
        fork
9435 15 mihad
        begin
9436 106 mihad
            if ( check_transfers === 1 )
9437 15 mihad
            begin
9438 106 mihad
                monitor32.get_pci_op_num_of_transfers(transfer_counter, ret_gnt_deasserted) ;
9439
                if ( transfer_counter !== num_of_transfers )
9440
                begin
9441
                    $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9442
                    $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9443
                    ok = 0 ;
9444
                end
9445 15 mihad
            end
9446
        end
9447
        begin
9448 106 mihad
            if ( check_cycles === 1'b1)
9449 15 mihad
            begin
9450 106 mihad
                monitor32.get_pci_op_num_of_cycles(cycle_counter) ;
9451
                if (cycle_counter > num_of_cycles)
9452 15 mihad
                begin
9453 106 mihad
                    $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9454
                    $display("Possibility of wrong operation in latency timer logic exists!") ;
9455
                    ok = 0 ;
9456 15 mihad
                end
9457
            end
9458
        end
9459 106 mihad
        join
9460 15 mihad
 
9461 106 mihad
    end //monitor_blk
9462
 
9463 15 mihad
    in_use = 0 ;
9464 106 mihad
 
9465 15 mihad
end
9466
endtask //pci_transaction_progress_monitor
9467
 
9468 119 tadejm
reg         CYC_O_previous ;
9469
reg         WE_O_previous ;
9470
reg  [3:0]  SEL_O_previous ;
9471
reg  [2:0]  CTI_O_previous ;
9472
reg  [1:0]  BTE_O_previous ;
9473
reg [31:0]  ADR_O_previous ;
9474
reg  [2:0]  ACK_ERR_RTY_previous ;
9475 15 mihad
always@(posedge wb_clock or posedge reset)
9476
begin
9477
    if ( reset )
9478 119 tadejm
    begin
9479 15 mihad
        CYC_O_previous <= #1 1'b0 ;
9480 119 tadejm
        WE_O_previous  <= #1 1'b0 ;
9481
        SEL_O_previous <= #1 4'h0 ;
9482
        CTI_O_previous <= #1 3'h0 ;
9483
        BTE_O_previous <= #1 2'h0 ;
9484
        ADR_O_previous <= #1 32'h0 ;
9485
        ACK_ERR_RTY_previous <= #1 3'h0;
9486
    end
9487 15 mihad
    else
9488 119 tadejm
    begin
9489 15 mihad
        CYC_O_previous <= #1 CYC_O ;
9490 119 tadejm
        if (CYC_O)
9491
        begin
9492
            WE_O_previous  <= #1 WE_O ;
9493
            SEL_O_previous <= #1 SEL_O ;
9494
            CTI_O_previous <= #1 CTI_O ;
9495
            BTE_O_previous <= #1 BTE_O ;
9496
            ADR_O_previous <= #1 ADR_O ;
9497
            ACK_ERR_RTY_previous <= #1 {ACK_I, ERR_I, RTY_I} ;
9498
        end
9499
    end
9500 15 mihad
end
9501
 
9502
task wb_transaction_progress_monitor ;
9503
    input [31:0] address ;
9504
    input        write ;
9505
    input [31:0] num_of_transfers ;
9506
    input check_transfers ;
9507
    output ok ;
9508
    reg in_use ;
9509
    integer transfer_counter ;
9510 119 tadejm
    integer wait_counter ;
9511 15 mihad
    integer deadlock_max_val ;
9512 73 mihad
    reg [2:0] slave_termination ;
9513
    reg       cab_asserted ;
9514 15 mihad
begin:main
9515
    if ( in_use === 1 )
9516
    begin
9517
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9518
        ok = 0 ;
9519
        disable main ;
9520
    end
9521
 
9522 106 mihad
    // number of ns to wait before timeout occurs
9523
    deadlock_max_val = `PCIW_DEPTH * 10 ;
9524
    deadlock_max_val = deadlock_max_val + `PCIR_DEPTH * 30 ;
9525 15 mihad
 
9526
    // time used for maximum transaction length on PCI
9527
    `ifdef PCI33
9528 106 mihad
    deadlock_max_val = deadlock_max_val * ( 30 ) ;
9529 15 mihad
    `else
9530 106 mihad
    deadlock_max_val = deadlock_max_val * ( 15 ) ;
9531 15 mihad
    `endif
9532
 
9533 106 mihad
    deadlock_max_val = deadlock_max_val + (`WBW_DEPTH * 10 * `WB_PERIOD) ;
9534
    deadlock_max_val = deadlock_max_val + (`WBR_DEPTH * 30 * `WB_PERIOD) ;
9535 15 mihad
 
9536 73 mihad
    in_use       = 1 ;
9537
    ok           = 1 ;
9538
    cab_asserted = 0 ;
9539 15 mihad
 
9540
    fork
9541
    begin:wait_start
9542 106 mihad
        #(deadlock_max_val) ;
9543
        $display("%m timeout! Time %t ", $time) ;
9544
        in_use = 0 ;
9545
        ok     = 0 ;
9546
        disable main ;
9547 15 mihad
    end //wait_start
9548
    begin:addr_monitor
9549
        @(posedge wb_clock) ;
9550
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9551
            @(posedge wb_clock) ;
9552
 
9553
        while( CYC_O !== 1 )
9554
            @(posedge wb_clock) ;
9555
 
9556
        while (STB_O !== 1 )
9557
            @(posedge wb_clock) ;
9558
 
9559
        if ( WE_O !== write )
9560
        begin
9561
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9562
            if ( write !== 1 )
9563
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9564
            else
9565
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9566
        end
9567
 
9568
        if ( ADR_O !== address )
9569
        begin
9570
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9571
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9572
            ok = 0 ;
9573
        end
9574 106 mihad
        disable wait_start ;
9575 15 mihad
    end
9576
    begin:transfer_checker
9577
        transfer_counter = 0 ;
9578 119 tadejm
        wait_counter = 0 ;
9579 15 mihad
        @(posedge wb_clock) ;
9580
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9581
            @(posedge wb_clock) ;
9582
 
9583
        while( CYC_O !== 1 )
9584
            @(posedge wb_clock) ;
9585
 
9586 119 tadejm
        while( ((CYC_O === 1) && ((transfer_counter <= `PCIW_DEPTH) || (transfer_counter <= `PCIR_DEPTH))) ||
9587
               ((CYC_O === 0) && (ACK_ERR_RTY_previous === 3'b100) && (wait_counter < 2) &&
9588
                 (WE_O_previous === 1) && (CTI_O_previous === 3'b111)) ||
9589
               ((CYC_O === 1) && (SEL_O_previous !== SEL_O) && (CTI_O_previous === 3'b111) &&
9590
                 ((ADR_O_previous + 4) === ADR_O) && (WE_O_previous === 1) && (WE_O === 1)) )
9591 15 mihad
        begin
9592 73 mihad
 
9593
            if (!cab_asserted)
9594 119 tadejm
                cab_asserted = ( ((CYC_O === 1) && (CTI_O === 3'b010)) ||
9595
                                 ((CYC_O === 1) && (SEL_O_previous !== SEL_O) && (CTI_O_previous === 3'b111) &&
9596
                                  ((ADR_O_previous + 4) === ADR_O) && (WE_O_previous === 1) && (WE_O === 1)) ) ;
9597 73 mihad
 
9598
            if (STB_O === 1)
9599
            begin
9600
                slave_termination = {ACK_I, ERR_I, RTY_I} ;
9601
                if (ACK_I)
9602
                    transfer_counter = transfer_counter + 1 ;
9603
            end
9604 119 tadejm
 
9605
            if (CYC_O === 0)
9606
                wait_counter = wait_counter + 1 ;
9607
            else
9608
                wait_counter = 0 ;
9609
 
9610 15 mihad
            @(posedge wb_clock) ;
9611 119 tadejm
 
9612 15 mihad
        end
9613
 
9614 73 mihad
        if (cab_asserted)
9615
        begin
9616
            // cab was sampled asserted
9617
            // if number of transfers was less than 2 - check for extraordinary terminations
9618
            if (transfer_counter < 2)
9619
            begin
9620
                // if cycle was terminated because of no response, error or retry, than it is OK to have CAB_O asserted while transfering 0 or 1 data.
9621
                // any other cases are wrong
9622
                case (slave_termination)
9623
                3'b000:begin end
9624
                3'b001:begin end
9625
                3'b010:begin end
9626
                default:begin
9627
                            ok = 0 ;
9628
                            $display("Time %t", $time) ;
9629
                            $display("WB_MASTER asserted CAB_O for single transfer") ;
9630
                        end
9631
                endcase
9632
            end
9633
        end
9634
        else
9635
        begin
9636
            // if cab is not asserted, then WB_MASTER should not read more than one data.
9637
            if (transfer_counter > 1)
9638
            begin
9639
                ok = 0 ;
9640
                $display("Time %t", $time) ;
9641
                $display("WB_MASTER didn't assert CAB_O for consecutive block transfer") ;
9642
            end
9643
        end
9644
 
9645 15 mihad
        if ( check_transfers === 1 )
9646
        begin
9647
            if ( transfer_counter !== num_of_transfers )
9648
            begin
9649
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9650
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9651
                ok = 0 ;
9652
            end
9653
        end
9654
    end //transfer_checker
9655
    join
9656
 
9657
    in_use = 0 ;
9658
end
9659
endtask // wb_transaction_progress_monitor
9660
 
9661
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9662
// so they are not re-entered
9663
task wb_transaction_progress_monitor_backup ;
9664
    input [31:0] address ;
9665
    input        write ;
9666
    input [31:0] num_of_transfers ;
9667
    input check_transfers ;
9668
    output ok ;
9669
    reg in_use ;
9670
    integer transfer_counter ;
9671 119 tadejm
    integer wait_counter ;
9672 15 mihad
    integer deadlock_max_val ;
9673 119 tadejm
    reg [2:0] slave_termination ;
9674
    reg       cab_asserted ;
9675 15 mihad
begin:main
9676
    if ( in_use === 1 )
9677
    begin
9678
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9679
        ok = 0 ;
9680
        disable main ;
9681
    end
9682
 
9683 106 mihad
    // number of ns to wait before timeout occurs
9684
    deadlock_max_val = `PCIW_DEPTH * 10 ;
9685
    deadlock_max_val = deadlock_max_val + `PCIR_DEPTH * 30 ;
9686 15 mihad
 
9687
    // time used for maximum transaction length on PCI
9688
    `ifdef PCI33
9689 106 mihad
    deadlock_max_val = deadlock_max_val * ( 30 ) ;
9690 15 mihad
    `else
9691 106 mihad
    deadlock_max_val = deadlock_max_val * ( 15 ) ;
9692 15 mihad
    `endif
9693
 
9694 106 mihad
    deadlock_max_val = deadlock_max_val + (`WBW_DEPTH * 10 * `WB_PERIOD) ;
9695
    deadlock_max_val = deadlock_max_val + (`WBR_DEPTH * 30 * `WB_PERIOD) ;
9696 15 mihad
 
9697 119 tadejm
    in_use       = 1 ;
9698
    ok           = 1 ;
9699
    cab_asserted = 0 ;
9700 15 mihad
 
9701
    fork
9702
    begin:wait_start
9703 106 mihad
        #(deadlock_max_val) ;
9704
        $display("%m timeout! Time %t ", $time) ;
9705
        in_use = 0 ;
9706
        ok     = 0 ;
9707
        disable main ;
9708 15 mihad
    end //wait_start
9709
    begin:addr_monitor
9710
        @(posedge wb_clock) ;
9711 119 tadejm
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9712 15 mihad
            @(posedge wb_clock) ;
9713
 
9714
        while( CYC_O !== 1 )
9715
            @(posedge wb_clock) ;
9716
 
9717
        while (STB_O !== 1 )
9718
            @(posedge wb_clock) ;
9719
 
9720
        if ( WE_O !== write )
9721
        begin
9722
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9723
            if ( write !== 1 )
9724
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9725
            else
9726
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9727
        end
9728
 
9729
        if ( ADR_O !== address )
9730
        begin
9731
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9732
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9733
            ok = 0 ;
9734
        end
9735 106 mihad
        disable wait_start ;
9736 15 mihad
    end
9737
    begin:transfer_checker
9738
        transfer_counter = 0 ;
9739 119 tadejm
        wait_counter = 0 ;
9740 15 mihad
        @(posedge wb_clock) ;
9741 119 tadejm
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9742 15 mihad
            @(posedge wb_clock) ;
9743
 
9744
        while( CYC_O !== 1 )
9745
            @(posedge wb_clock) ;
9746
 
9747 119 tadejm
        while( ((CYC_O === 1) && ((transfer_counter <= `PCIW_DEPTH) || (transfer_counter <= `PCIR_DEPTH))) ||
9748
               ((CYC_O === 0) && (ACK_ERR_RTY_previous === 3'b100) && (wait_counter < 2) &&
9749
                 (WE_O_previous === 1) && (CTI_O_previous === 3'b111)) ||
9750
               ((CYC_O === 1) && (SEL_O_previous !== SEL_O) && (CTI_O_previous === 3'b111) &&
9751
                 ((ADR_O_previous + 4) === ADR_O) && (WE_O_previous === 1) && (WE_O === 1)) )
9752 15 mihad
        begin
9753 119 tadejm
 
9754
            if (!cab_asserted)
9755
                cab_asserted = ( ((CYC_O === 1) && (CTI_O === 3'b010)) ||
9756
                                 ((CYC_O === 1) && (SEL_O_previous !== SEL_O) && (CTI_O_previous === 3'b111) &&
9757
                                  ((ADR_O_previous + 4) === ADR_O) && (WE_O_previous === 1) && (WE_O === 1)) ) ;
9758
 
9759
            if (STB_O === 1)
9760
            begin
9761
                slave_termination = {ACK_I, ERR_I, RTY_I} ;
9762
                if (ACK_I)
9763
                    transfer_counter = transfer_counter + 1 ;
9764
            end
9765
 
9766
            if (CYC_O === 0)
9767
                wait_counter = wait_counter + 1 ;
9768
            else
9769
                wait_counter = 0 ;
9770
 
9771 15 mihad
            @(posedge wb_clock) ;
9772 119 tadejm
 
9773 15 mihad
        end
9774
 
9775 119 tadejm
        if (cab_asserted)
9776
        begin
9777
            // cab was sampled asserted
9778
            // if number of transfers was less than 2 - check for extraordinary terminations
9779
            if (transfer_counter < 2)
9780
            begin
9781
                // if cycle was terminated because of no response, error or retry, than it is OK to have CAB_O asserted while transfering 0 or 1 data.
9782
                // any other cases are wrong
9783
                case (slave_termination)
9784
                3'b000:begin end
9785
                3'b001:begin end
9786
                3'b010:begin end
9787
                default:begin
9788
                            ok = 0 ;
9789
                            $display("Time %t", $time) ;
9790
                            $display("WB_MASTER asserted CAB_O for single transfer") ;
9791
                        end
9792
                endcase
9793
            end
9794
        end
9795
        else
9796
        begin
9797
            // if cab is not asserted, then WB_MASTER should not read more than one data.
9798
            if (transfer_counter > 1)
9799
            begin
9800
                ok = 0 ;
9801
                $display("Time %t", $time) ;
9802
                $display("WB_MASTER didn't assert CAB_O for consecutive block transfer") ;
9803
            end
9804
        end
9805
 
9806 15 mihad
        if ( check_transfers === 1 )
9807
        begin
9808
            if ( transfer_counter !== num_of_transfers )
9809
            begin
9810
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9811
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9812
                ok = 0 ;
9813
            end
9814
        end
9815
    end //transfer_checker
9816
    join
9817
 
9818
    in_use = 0 ;
9819
end
9820
endtask // wb_transaction_progress_monitor_backup
9821
 
9822 119 tadejm
//    input [31:0] address ;
9823
//    input        write ;
9824
//    input [31:0] num_of_transfers ;
9825
//    input check_transfers ;
9826
//    output ok ;
9827
//    reg in_use ;
9828
//    integer transfer_counter ;
9829
//    integer deadlock_max_val ;
9830
//begin:main
9831
//    if ( in_use === 1 )
9832
//    begin
9833
//        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9834
//        ok = 0 ;
9835
//        disable main ;
9836
//    end
9837
//
9838
//    // number of ns to wait before timeout occurs
9839
//    deadlock_max_val = `PCIW_DEPTH * 10 ;
9840
//    deadlock_max_val = deadlock_max_val + `PCIR_DEPTH * 30 ;
9841
//
9842
//    // time used for maximum transaction length on PCI
9843
//    `ifdef PCI33
9844
//    deadlock_max_val = deadlock_max_val * ( 30 ) ;
9845
//    `else
9846
//    deadlock_max_val = deadlock_max_val * ( 15 ) ;
9847
//    `endif
9848
//
9849
//    deadlock_max_val = deadlock_max_val + (`WBW_DEPTH * 10 * `WB_PERIOD) ;
9850
//    deadlock_max_val = deadlock_max_val + (`WBR_DEPTH * 30 * `WB_PERIOD) ;
9851
//
9852
//    in_use = 1 ;
9853
//    ok     = 1 ;
9854
//
9855
//    fork
9856
//    begin:wait_start
9857
//        #(deadlock_max_val) ;
9858
//        $display("%m timeout! Time %t ", $time) ;
9859
//        in_use = 0 ;
9860
//        ok     = 0 ;
9861
//        disable main ;
9862
//    end //wait_start
9863
//    begin:addr_monitor
9864
//        @(posedge wb_clock) ;
9865
//        while ( CYC_O !== 0 )
9866
//            @(posedge wb_clock) ;
9867
//
9868
//        while( CYC_O !== 1 )
9869
//            @(posedge wb_clock) ;
9870
//
9871
//        while (STB_O !== 1 )
9872
//            @(posedge wb_clock) ;
9873
//
9874
//        if ( WE_O !== write )
9875
//        begin
9876
//            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9877
//            if ( write !== 1 )
9878
//                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9879
//            else
9880
//                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9881
//        end
9882
//
9883
//        if ( ADR_O !== address )
9884
//        begin
9885
//            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9886
//            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9887
//            ok = 0 ;
9888
//        end
9889
//        disable wait_start ;
9890
//    end
9891
//    begin:transfer_checker
9892
//        transfer_counter = 0 ;
9893
//        @(posedge wb_clock) ;
9894
//        while ( CYC_O !== 0 )
9895
//            @(posedge wb_clock) ;
9896
//
9897
//        while( CYC_O !== 1 )
9898
//            @(posedge wb_clock) ;
9899
//
9900
//        while( CYC_O === 1 )
9901
//        begin
9902
//            if ( (STB_O === 1) && (ACK_I === 1) )
9903
//                transfer_counter = transfer_counter + 1 ;
9904
//            @(posedge wb_clock) ;
9905
//        end
9906
//
9907
//        if ( check_transfers === 1 )
9908
//        begin
9909
//            if ( transfer_counter !== num_of_transfers )
9910
//            begin
9911
//                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9912
//                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9913
//                ok = 0 ;
9914
//            end
9915
//        end
9916
//    end //transfer_checker
9917
//    join
9918
//
9919
//    in_use = 0 ;
9920
//end
9921
//endtask // wb_transaction_progress_monitor_backup
9922
 
9923 15 mihad
task wb_transaction_stop ;
9924
    input [31:0] num_of_transfers ;
9925
    integer transfer_counter ;
9926 119 tadejm
    integer wait_counter ;
9927 15 mihad
begin:main
9928
    begin:transfer_checker
9929
        transfer_counter = 0 ;
9930 119 tadejm
        wait_counter = 0 ;
9931 15 mihad
        @(posedge wb_clock) ;
9932 92 mihad
        while ( (CYC_O !== 0) & (CYC_O_previous !== 0) )
9933 15 mihad
            @(posedge wb_clock) ;
9934
 
9935
        while( CYC_O !== 1 )
9936
            @(posedge wb_clock) ;
9937
 
9938
        if ( (STB_O === 1) && (ACK_I === 1) )
9939
            transfer_counter = transfer_counter + 1 ;
9940
 
9941 119 tadejm
        while( ((transfer_counter < num_of_transfers) && (CYC_O === 1)) ||
9942
               ((transfer_counter < num_of_transfers) && (CYC_O === 0) && (wait_counter < 2) &&
9943
                 (WE_O_previous === 1) && (CTI_O_previous === 3'b111)) ||
9944
               ((transfer_counter < num_of_transfers) && (CYC_O === 1) && (SEL_O_previous !== SEL_O) &&
9945
                 (CTI_O_previous === 3'b111) && ((ADR_O_previous + 4) === ADR_O) && (WE_O_previous === 1) && (WE_O === 1)) )
9946 15 mihad
        begin
9947 119 tadejm
            if (CYC_O === 0)
9948
                wait_counter = wait_counter + 1 ;
9949
            else
9950
                wait_counter = 0 ;
9951 15 mihad
            @(posedge wb_clock) ;
9952
            if ( (STB_O === 1) && (ACK_I === 1) )
9953
                transfer_counter = transfer_counter + 1 ;
9954
        end
9955
    end //transfer_checker
9956
end
9957
endtask // wb_transaction_stop
9958
 
9959
task musnt_respond ;
9960
    output ok ;
9961
    reg in_use ;
9962
    integer i ;
9963
begin:main
9964
    if ( in_use === 1 )
9965
    begin
9966
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9967
        #20 $stop ;
9968
        ok = 0 ;
9969
        disable main ;
9970
    end
9971
 
9972
    in_use = 1 ;
9973
    ok = 1 ;
9974
 
9975
    fork
9976
    begin:wait_start
9977
        @(negedge FRAME) ;
9978
        disable count ;
9979
    end
9980
    begin:count
9981
        i = 0 ;
9982
        while ( i < 1000 )
9983
        begin
9984
            @(posedge pci_clock) ;
9985
            i = i + 1 ;
9986
        end
9987
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9988
        ok = 0 ;
9989
        disable wait_start ;
9990
    end
9991
    join
9992
 
9993
    @(posedge pci_clock) ;
9994
    while ( FRAME === 0 && ok )
9995
    begin
9996
        if ( DEVSEL !== 1 )
9997
        begin
9998
            ok = 0 ;
9999
        end
10000
        @(posedge pci_clock) ;
10001
    end
10002
 
10003
    while ( IRDY === 0 && ok )
10004
    begin
10005
        if ( DEVSEL !== 1 )
10006
        begin
10007
            ok = 0 ;
10008
        end
10009
        @(posedge pci_clock) ;
10010
    end
10011
    in_use = 0 ;
10012
end
10013
endtask
10014
 
10015
function [31:0] wb_to_pci_addr_convert ;
10016
    input [31:0] wb_address ;
10017
    input [31:0] translation_address ;
10018
    input [31:0] translate ;
10019
 
10020
    reg   [31:0] temp_address ;
10021
begin
10022
    if ( translate !== 1 )
10023
    begin
10024
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10025
    end
10026
    else
10027
    begin
10028
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10029
    end
10030
 
10031
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
10032
    wb_to_pci_addr_convert = temp_address ;
10033
end
10034
endfunction //wb_to_pci_addr_convert
10035
 
10036 45 mihad
`ifdef HOST
10037 15 mihad
task find_pci_devices ;
10038
    integer device_num ;
10039
    reg     found ;
10040
    reg [11:0] pci_ctrl_offset ;
10041
    reg ok ;
10042
    reg [31:0] data ;
10043 45 mihad
    reg [31:0] expected_data ;
10044
 
10045
    reg [5:0]  reg_num ;
10046 15 mihad
begin:main
10047 45 mihad
 
10048
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
10049 15 mihad
    pci_ctrl_offset = 12'h004 ;
10050
 
10051
    // enable master & target operation
10052
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
10053
 
10054
    if ( ok !== 1 )
10055
    begin
10056
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
10057 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
10058 15 mihad
        disable main ;
10059
    end
10060
    // find all possible devices on pci bus by performing configuration cycles
10061 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
10062 15 mihad
    begin
10063
        find_device ( device_num, found ) ;
10064
 
10065
        // check pci status register - if device is not present, Received Master Abort bit must be set
10066
        config_read( pci_ctrl_offset, 4'hF, data ) ;
10067
 
10068
        if ( (data[29] !== 0) && (found !== 0) )
10069 45 mihad
        begin
10070 15 mihad
            $display( "Time %t ", $time ) ;
10071
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
10072
            $display( "Value read from device status register: %h ", data[31:16] ) ;
10073 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
10074
            ok = 0 ;
10075 15 mihad
        end
10076
 
10077
        if ( (data[29] !== 1) && (found !== 1) )
10078
        begin
10079
            $display( "Time %t ", $time ) ;
10080
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
10081
            $display( "Value read from device status register: %h ", data[31:16] ) ;
10082 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
10083
            ok = 0 ;
10084 15 mihad
        end
10085
 
10086
        // clear Master Abort status if set
10087
        if ( data[29] !== 0 )
10088
        begin
10089
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
10090
        end
10091 45 mihad
 
10092
        if (found === 1)
10093
        begin
10094
            // first check if found target is supposed to exist
10095
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
10096
            begin
10097
                $display("Time %t", $time) ;
10098
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
10099
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
10100
                ok = 0 ;
10101
            end
10102
            else
10103
            begin
10104
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
10105
                begin
10106
 
10107
                    data = 32'hFFFF_FFFF ;
10108
 
10109
                    expected_data = 0 ;
10110
 
10111
                    if (reg_num == 4)
10112
                    begin
10113
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
10114
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
10115
                    end
10116
                    else if (reg_num == 5)
10117
                    begin
10118
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
10119
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
10120
                    end
10121
 
10122
                    // write base address 0
10123
                    generate_configuration_cycle
10124
                    (
10125
                        'h0,            //bus_num
10126
                        device_num,     //device_num
10127
                        'h0,            //func_num
10128
                        reg_num,        //reg_num
10129
                        'h0,            //type
10130
                        4'hF,           // byte_enables
10131
                        data,           //data
10132
                        1'b1            //read0_write1
10133
                    );
10134
 
10135
                    // read data back
10136
                    generate_configuration_cycle
10137
                    (
10138
                        'h0,            //bus_num
10139
                        device_num,     //device_num
10140
                        'h0,            //func_num
10141
                        reg_num,        //reg_num
10142
                        'h0,            //type
10143
                        4'hF,           // byte_enables
10144
                        data,           //data
10145
                        1'b0            //read0_write1
10146
                    );
10147
 
10148
                    if (data !== expected_data)
10149
                    begin
10150
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
10151
                        $display("Data read back not as expected!");
10152
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
10153
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
10154
                        ok = 0 ;
10155
                    end
10156
                end
10157
            end
10158
        end
10159 15 mihad
    end
10160 45 mihad
 
10161
    if (ok)
10162
        test_ok ;
10163 15 mihad
end //main
10164
endtask //find_pci_devices
10165
 
10166
task find_device ;
10167
    input [31:0] device_num ;
10168
    output  found ;
10169
 
10170
    reg [31:0] read_data ;
10171
begin
10172
    found = 1'b0 ;
10173
 
10174
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
10175 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
10176 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
10177
    else
10178
    begin
10179
        $display("Device %d with device id 0x%h and vendor id 0x%h found on PCI bus!", device_num, read_data[31:16], read_data[15:0]) ;
10180
        found = 1'b1 ;
10181
    end
10182
end
10183
endtask //find_device
10184 45 mihad
`endif
10185 15 mihad
 
10186
/*task set_bridge_parameters ;
10187
    reg [11:0] current_offset ;
10188
    reg [2:0] result ;
10189
    reg [31:0] write_data ;
10190
begin
10191
    // set burst size
10192
    // set latency timer
10193
    current_offset = 12'h00C ;
10194
    // set burst size to 16 and latency timer to 8
10195
    write_data     = {24'h0000_08, system_burst_size} ;
10196
    config_write(current_offset, write_data, 4'b1111) ;
10197
 
10198
    // set io image
10199
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
10200
    write_data = 32'h0000_000_3 ;
10201
    config_write(current_offset, write_data, 4'b1111) ;
10202
 
10203
 
10204
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
10205
    write_data = 32'h0001_000_1 ;
10206
    config_write(current_offset, write_data, 4'b1111) ;
10207
 
10208
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
10209
    write_data = 32'hFFFF_0000 ;
10210
    config_write(current_offset, write_data, 4'b1111) ;
10211
 
10212
    // set memory image
10213
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
10214
    write_data = 32'h0000_000_7 ;
10215
    config_write(current_offset, write_data, 4'b1111) ;
10216
 
10217
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
10218
    write_data = 32'h0002_000_0 ;
10219
    config_write(current_offset, write_data, 4'b1111) ;
10220
 
10221
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
10222
    write_data = 32'h0001_0000 ;
10223
    config_write(current_offset, write_data, 4'b1111) ;
10224
 
10225
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
10226
    write_data = 32'hFFFF_0000 ;
10227
    config_write(current_offset, write_data, 4'b1111) ;
10228
 
10229
    // set parameters for bridge's target unit
10230
    // image control 0
10231
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
10232
    write_data     = 32'h0000_0002 ;
10233
    config_write(current_offset, write_data, 4'b0001) ;
10234
 
10235
    // base_address 0
10236
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
10237
    write_data      = 32'h2000_0000 ;
10238
    config_write(current_offset, write_data, 4'b1111) ;
10239
 
10240
    // address mask 0
10241
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
10242
    write_data     = 32'hFFFF_F000 ;
10243
    config_write(current_offset, write_data, 4'b1111) ;
10244
 
10245
    // command register - enable response to io and mem space and PCI master
10246
    current_offset = 12'h004 ;
10247
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
10248
    config_write(current_offset, write_data, 4'b1111) ;
10249
end
10250
endtask // set_bridge_parameters
10251
*/
10252
 
10253
task configuration_cycle_write ;
10254
    input [7:0]  bus_num ;
10255
    input [4:0]  device_num ;
10256
    input [2:0]  func_num ;
10257
    input [5:0]  reg_num ;
10258
    input [1:0]  type ;
10259
    input [3:0]  byte_enables ;
10260
    input [31:0] data ;
10261
 
10262
    reg [31:0] write_address ;
10263
    reg in_use ;
10264
    reg ok ;
10265
begin:main
10266
 
10267
    if ( in_use === 1 )
10268
    begin
10269 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
10270 15 mihad
        disable main ;
10271
    end
10272
 
10273 45 mihad
    if ( (device_num > 20) && (type === 0) )
10274 15 mihad
    begin
10275
        $display("Configuration cycle generation only supports access to 21 devices!") ;
10276
        disable main ;
10277
    end
10278
 
10279
    in_use = 1 ;
10280
 
10281 45 mihad
 
10282
`ifdef HOST
10283
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
10284
`else
10285
`ifdef GUEST
10286
 
10287 15 mihad
    if ( type )
10288
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10289
    else
10290
    begin
10291
        write_address = 0 ;
10292
        write_address[10:0] = { func_num, reg_num, type } ;
10293
        write_address[11 + device_num] = 1'b1 ;
10294
    end
10295 45 mihad
 
10296
    fork
10297 15 mihad
    begin
10298 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
10299
                            write_address,
10300
                            data, ~byte_enables,
10301
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
10302
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10303
        do_pause(1) ;
10304 15 mihad
    end
10305 45 mihad
    begin
10306
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
10307
    end
10308
    join
10309
`endif
10310
`endif
10311
 
10312
    in_use = 0 ;
10313
end
10314
endtask // configuration_cycle_write
10315 15 mihad
 
10316 45 mihad
task configuration_cycle_read ;
10317
    input [7:0]  bus_num ;
10318
    input [4:0]  device_num ;
10319
    input [2:0]  func_num ;
10320
    input [5:0]  reg_num ;
10321
    input [1:0]  type ;
10322
    input [3:0]  byte_enables ;
10323
    output [31:0] data ;
10324 15 mihad
 
10325 45 mihad
    reg [31:0] read_address ;
10326
    reg in_use ;
10327 15 mihad
 
10328 45 mihad
    reg master_check_data_prev ;
10329
begin:main
10330 15 mihad
 
10331 45 mihad
    if ( in_use === 1 )
10332 15 mihad
    begin
10333 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
10334
        data = 32'hxxxx_xxxx ;
10335
        disable main ;
10336 15 mihad
    end
10337
 
10338 45 mihad
    in_use = 1 ;
10339 15 mihad
 
10340 45 mihad
`ifdef HOST
10341
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
10342
`else
10343
`ifdef GUEST
10344
     master_check_data_prev = master1_check_received_data ;
10345 15 mihad
     if ( type )
10346 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10347 15 mihad
     else
10348
     begin
10349 45 mihad
         read_address = 0 ;
10350
         read_address[10:0] = { func_num, reg_num, type } ;
10351
         read_address[11 + device_num] = 1'b1 ;
10352 15 mihad
     end
10353 45 mihad
 
10354
     fork
10355
     begin
10356
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
10357
                 read_address,
10358 15 mihad
                 data, ~byte_enables,
10359
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
10360
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10361 45 mihad
         do_pause(1) ;
10362
     end
10363
     begin
10364
         @(master1_received_data_valid) ;
10365
         data = master1_received_data ;
10366
     end
10367
     join
10368 15 mihad
 
10369 45 mihad
    master1_check_received_data = master_check_data_prev ;
10370
`endif
10371
`endif
10372
 
10373 15 mihad
    in_use = 0 ;
10374
 
10375 45 mihad
end //main
10376
endtask // configuration_cycle_read
10377
 
10378 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
10379
task test_conf_cycle_type1_reference ;
10380
    reg [31:0] address ;
10381
    reg in_use ;
10382
 
10383
    reg master_check_data_prev ;
10384
    reg [31:0] data ;
10385
    reg monitor_ok ;
10386
    reg master_ok ;
10387
begin:main
10388
 
10389
    if ( in_use === 1 )
10390
    begin
10391
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
10392
        disable main ;
10393
    end
10394
 
10395
    in_use = 1 ;
10396
 
10397
    master_check_data_prev = master1_check_received_data ;
10398
 
10399
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
10400
    address = `TAR0_IDSEL_ADDR ;
10401
 
10402
    address[1:0] = 2'b01 ;
10403
 
10404
    `ifdef HOST
10405
        conf_cyc_type1_target_bus_num = 255 ;
10406
    `endif
10407
    master_ok = 1 ;
10408
    fork
10409
    begin
10410
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
10411
        do_pause(1) ;
10412
    end
10413
    begin:error_monitor1
10414
        @(error_event_int) ;
10415
        master_ok = 0 ;
10416
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
10417
    end
10418
    begin
10419
        pci_transaction_progress_monitor
10420
        (
10421
            address,                                                // expected address on PCI bus
10422
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10423
            0,                                                      // expected number of succesfull data phases
10424
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10425
            1'b1,                                                   // monitor checking/not checking number of transfers
10426
            1'b0,                                                   // monitor checking/not checking number of cycles
10427
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10428
            monitor_ok                                              // status - 1 success, 0 failure
10429
        ) ;
10430
 
10431
        @(posedge pci_clock);
10432
        #1 ;
10433
 
10434
        if (master_ok)
10435
            disable error_monitor1 ;
10436
 
10437
        if (!monitor_ok)
10438
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10439
    end
10440
    join
10441
 
10442
    if (monitor_ok && master_ok)
10443
        test_ok ;
10444
 
10445
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
10446
    master_ok = 1 ;
10447
    fork
10448
    begin
10449
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
10450
        do_pause(1) ;
10451
    end
10452
    begin:error_monitor2
10453
        @(error_event_int) ;
10454
        master_ok = 0 ;
10455
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
10456
    end
10457
    begin
10458
        pci_transaction_progress_monitor
10459
        (
10460
            address,                                                // expected address on PCI bus
10461
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10462
            0,                                                      // expected number of succesfull data phases
10463
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10464
            1'b1,                                                   // monitor checking/not checking number of transfers
10465
            1'b0,                                                   // monitor checking/not checking number of cycles
10466
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10467
            monitor_ok                                              // status - 1 success, 0 failure
10468
        ) ;
10469
 
10470
        @(posedge pci_clock);
10471
        #1 ;
10472
 
10473
        if (master_ok)
10474
            disable error_monitor2 ;
10475
 
10476
        if (!monitor_ok)
10477
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10478
    end
10479
    join
10480
 
10481
    master1_check_received_data = master_check_data_prev ;
10482
 
10483
    if (monitor_ok && master_ok)
10484
        test_ok ;
10485
 
10486
    in_use = 0 ;
10487
 
10488
end //main
10489
endtask // test_conf_cycle_type1_reference
10490
`endif
10491
 
10492 45 mihad
`ifdef HOST
10493
task generate_configuration_cycle ;
10494 15 mihad
    input [7:0]  bus_num ;
10495
    input [4:0]  device_num ;
10496
    input [2:0]  func_num ;
10497
    input [5:0]  reg_num ;
10498
    input [1:0]  type ;
10499
    input [3:0]  byte_enables ;
10500 45 mihad
    inout [31:0] data ;
10501
    input        read0_write1 ;
10502 15 mihad
 
10503
    reg `READ_STIM_TYPE read_data ;
10504
    reg `WB_TRANSFER_FLAGS  flags ;
10505
    reg `READ_RETURN_TYPE   read_status ;
10506
 
10507
    reg `WRITE_STIM_TYPE   write_data ;
10508
    reg `WRITE_RETURN_TYPE write_status ;
10509
 
10510 45 mihad
    reg [31:0] pci_address ;
10511 15 mihad
    reg in_use ;
10512 45 mihad
    reg ok ;
10513 15 mihad
 
10514
    reg [31:0] temp_var ;
10515 106 mihad
    integer i ;
10516 15 mihad
begin:main
10517
 
10518 106 mihad
    if (read0_write1 === 1'b0)
10519
        data = 32'hxxxx_xxxx ;
10520
 
10521 15 mihad
    if ( in_use === 1 )
10522
    begin
10523 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
10524 15 mihad
        data = 32'hxxxx_xxxx ;
10525
        disable main ;
10526
    end
10527
 
10528 45 mihad
    in_use = 1 ;
10529
 
10530
    if ( type )
10531
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10532
    else
10533 15 mihad
    begin
10534 45 mihad
        pci_address = 0 ;
10535
        pci_address[10:0] = { func_num, reg_num, type } ;
10536
        if (device_num <= 20)
10537
            pci_address[11 + device_num] = 1'b1 ;
10538
    end
10539
 
10540
    // setup flags
10541
    flags = 0 ;
10542 92 mihad
    flags`INIT_WAITS   = wb_init_waits ;
10543
    flags`SUBSEQ_WAITS = wb_subseq_waits ;
10544 45 mihad
 
10545
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10546
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10547
 
10548
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10549
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10550 106 mihad
 
10551
`ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
10552
 
10553
        write_data`WRITE_SEL = 4'b0001 ;
10554
    repeat(4)
10555
    begin
10556
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10557
 
10558
        // check if write succeeded
10559
        if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10560
        begin
10561
            $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10562
            in_use = 0 ;
10563
            disable main ;
10564
        end
10565
 
10566
        write_data`WRITE_ADDRESS = write_data`WRITE_ADDRESS + 'h1 ;
10567
        write_data`WRITE_SEL     = write_data`WRITE_SEL << 1 ;
10568
    end
10569
 
10570
`else
10571
 
10572 45 mihad
    write_data`WRITE_SEL      = 4'hF ;
10573
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10574
 
10575
    // check if write succeeded
10576
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10577
    begin
10578
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10579
        in_use = 0 ;
10580 15 mihad
        disable main ;
10581
    end
10582
 
10583 106 mihad
`endif
10584
 
10585 45 mihad
    // setup flags for wb master to handle retries and read and write data
10586
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10587
 
10588
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10589
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10590
    read_data`READ_SEL          = byte_enables ;
10591
    write_data`WRITE_SEL        = byte_enables ;
10592
    write_data`WRITE_DATA       = data ;
10593
 
10594
    ok = 0 ;
10595
 
10596 106 mihad
    temp_var = 32'hxxxx_xxxx ;
10597
 
10598
`ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
10599
 
10600
    for (i = 0 ; i < 4 ; i = i + 1)
10601 45 mihad
    begin
10602
 
10603 106 mihad
        if (byte_enables[i] === 1'b1)
10604
        begin
10605
            read_data`READ_SEL   = 4'h1 << i ;
10606
            write_data`WRITE_SEL = read_data`READ_SEL ;
10607
 
10608
`else
10609
 
10610 45 mihad
    begin
10611 106 mihad
        begin
10612 45 mihad
 
10613 106 mihad
`endif
10614
 
10615
            fork
10616
            begin
10617
                if (read0_write1 === 0)
10618
                    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10619
                else if (read0_write1 === 1)
10620
                    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10621
 
10622
 
10623
                // check if transfer succeeded
10624
                if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10625
                begin
10626
                    $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10627
                    data = 32'hxxxx_xxxx ;
10628
                    in_use = 0 ;
10629
                    disable main ;
10630
                end
10631
 
10632
            end
10633
            begin
10634
                pci_transaction_progress_monitor
10635
                (
10636
                    pci_address,                                            // expected address on PCI bus
10637
                    read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10638
                    1,                                                      // expected number of succesfull data phases
10639
                    0,                                                      // expected number of cycles the transaction will take on PCI bus
10640
                    1'b0,                                                   // monitor checking/not checking number of transfers
10641
                    1'b0,                                                   // monitor checking/not checking number of cycles
10642
                    0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10643
                    ok                                                      // status - 1 success, 0 failure
10644
                ) ;
10645
 
10646
                if (!ok)
10647
                begin
10648
                    data = 32'hxxxx_xxxx ;
10649
                    in_use = 0 ;
10650
                    disable main ;
10651
                end
10652
            end
10653
            join
10654
 
10655
        `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
10656
 
10657
            temp_var = read_status`READ_DATA ;
10658
 
10659
            if (read0_write1 === 0)
10660
            begin
10661
                case(read_data`READ_SEL)
10662
                4'b0001:data[ 7:0 ] = temp_var[ 7:0 ] ;
10663
                4'b0010:data[15:8 ] = temp_var[15:8 ] ;
10664
                4'b0100:data[23:16] = temp_var[23:16] ;
10665
                4'b1000:data[31:24] = temp_var[31:24] ;
10666
                endcase
10667
            end
10668
 
10669
        `else
10670
 
10671
            if (read0_write1 === 0)
10672
                data = read_status`READ_DATA ;
10673
 
10674
        `endif
10675
 
10676
        end
10677
        read_data`READ_ADDRESS   = read_data`READ_ADDRESS   + 1'b1 ;
10678
        write_data`WRITE_ADDRESS = write_data`WRITE_ADDRESS + 1'b1 ;
10679 45 mihad
    end
10680
 
10681
    in_use = 0 ;
10682
end
10683
endtask // generate_configuration_cycle
10684
 
10685
task test_configuration_cycle_target_abort ;
10686
    reg `READ_STIM_TYPE read_data ;
10687
    reg `WB_TRANSFER_FLAGS  flags ;
10688
    reg `READ_RETURN_TYPE   read_status ;
10689
 
10690
    reg `WRITE_STIM_TYPE   write_data ;
10691
    reg `WRITE_RETURN_TYPE write_status ;
10692
 
10693
    reg [31:0] pci_address ;
10694
    reg in_use ;
10695
    reg ok_pci ;
10696
    reg ok_wb  ;
10697
    reg ok     ;
10698
 
10699
    reg [31:0] temp_var ;
10700
 
10701
begin:main
10702
 
10703
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10704
 
10705
    if ( in_use === 1 )
10706
    begin
10707
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10708
        disable main ;
10709
    end
10710
 
10711 15 mihad
    in_use = 1 ;
10712
 
10713 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10714
 
10715 15 mihad
    // setup flags
10716
    flags = 0 ;
10717 92 mihad
    flags`INIT_WAITS   = wb_init_waits ;
10718
    flags`SUBSEQ_WAITS = wb_subseq_waits ;
10719 15 mihad
 
10720
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10721
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10722
 
10723
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10724 45 mihad
    temp_var                  = 0 ;
10725
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10726
    write_data`WRITE_DATA     = temp_var ;
10727 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10728
 
10729
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10730
 
10731
    // check if write succeeded
10732
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10733
    begin
10734
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10735 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10736
        in_use = 0 ;
10737 15 mihad
        disable main ;
10738
    end
10739
 
10740 45 mihad
    // setup flags for wb master to handle retries and read and write data
10741 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10742
 
10743 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10744
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10745 15 mihad
 
10746 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10747
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10748
    read_data`READ_SEL          = 4'hF ;
10749
    write_data`WRITE_SEL        = 4'hF ;
10750
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10751
 
10752
    ok_pci = 0 ;
10753
    ok_wb  = 1 ;
10754
 
10755
    // set target to terminate with target abort
10756
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10757
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10758
    fork
10759
    begin
10760
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10761
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10762
        begin
10763
            $display("Time %t", $time) ;
10764
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10765
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10766
            ok_wb = 0 ;
10767
        end
10768
 
10769
        config_read( 12'h4, 4'hF, temp_var ) ;
10770
        if ( temp_var[29] !== 0 )
10771
        begin
10772
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10773
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10774
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10775
            ok_wb = 0 ;
10776
        end
10777
 
10778
        if ( temp_var[28] !== 1 )
10779
        begin
10780
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10781
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10782
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10783
            ok_wb = 0 ;
10784
        end
10785
 
10786
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10787
 
10788
        if (ok !== 1)
10789
        begin
10790
            ok_wb = 0 ;
10791
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10792
            $display("Write to PCI Device Status Register failed") ;
10793
            test_fail("Write to PCI Device Status Register failed") ;
10794
        end
10795
 
10796
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10797
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10798
        begin
10799
            $display("Time %t", $time) ;
10800
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10801
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10802
            ok_wb = 0 ;
10803
        end
10804
 
10805
        config_read( 12'h4, 4'hF, temp_var ) ;
10806
        if ( temp_var[29] !== 0 )
10807
        begin
10808
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10809
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10810
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10811
            ok_wb = 0 ;
10812
        end
10813
 
10814
        if ( temp_var[28] !== 1 )
10815
        begin
10816
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10817
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10818
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10819
            ok_wb = 0 ;
10820
        end
10821
 
10822
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10823
 
10824
        if (ok !== 1)
10825
        begin
10826
            ok_wb = 0 ;
10827
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10828
            $display("Write to PCI Device Status Register failed") ;
10829
            test_fail("Write to PCI Device Status Register failed") ;
10830
        end
10831
    end
10832
    begin
10833
        pci_transaction_progress_monitor
10834
        (
10835
            pci_address,                                            // expected address on PCI bus
10836
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10837
            0,                                                      // expected number of succesfull data phases
10838
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10839
            1'b1,                                                   // monitor checking/not checking number of transfers
10840
            1'b0,                                                   // monitor checking/not checking number of cycles
10841
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10842
            ok_pci                                                  // status - 1 success, 0 failure
10843
        ) ;
10844
 
10845
        if (ok_pci)
10846
        begin
10847
            pci_transaction_progress_monitor
10848
            (
10849
                pci_address,                                            // expected address on PCI bus
10850
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10851
                0,                                                      // expected number of succesfull data phases
10852
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10853
                1'b1,                                                   // monitor checking/not checking number of transfers
10854
                1'b0,                                                   // monitor checking/not checking number of cycles
10855
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10856
                ok_pci                                                  // status - 1 success, 0 failure
10857
            ) ;
10858
        end
10859
 
10860
        if (!ok_pci)
10861
        begin
10862
            $display("Time %t", $time) ;
10863
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10864
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10865
        end
10866
    end
10867
    join
10868
 
10869
    if (ok_pci && ok_wb)
10870
    begin
10871
        test_ok ;
10872
    end
10873
 
10874
    in_use = 0 ;
10875
 
10876
    // set target to terminate normally
10877
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10878
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10879
end
10880
endtask // test_configuration_cycle_target_abort
10881
 
10882
task test_configuration_cycle_type1_generation ;
10883
    reg `READ_STIM_TYPE read_data ;
10884
    reg `WB_TRANSFER_FLAGS  flags ;
10885
    reg `READ_RETURN_TYPE   read_status ;
10886
 
10887
    reg `WRITE_STIM_TYPE   write_data ;
10888
    reg `WRITE_RETURN_TYPE write_status ;
10889
 
10890
    reg [31:0] pci_address ;
10891
    reg in_use ;
10892
    reg ok_pci ;
10893
    reg ok_wb  ;
10894
    reg ok     ;
10895
 
10896
    reg [31:0] temp_var ;
10897
 
10898
begin:main
10899
 
10900
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10901
    conf_cyc_type1_target_data = 0 ;
10902
    conf_cyc_type1_target_bus_num = 0;
10903
 
10904
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10905
 
10906
    if ( in_use === 1 )
10907
    begin
10908
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10909
        disable main ;
10910
    end
10911
 
10912
    in_use = 1 ;
10913
 
10914
    pci_address        = 32'hAAAA_AAAA ;
10915
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10916
 
10917
    // setup flags
10918
    flags = 0 ;
10919 92 mihad
    flags`INIT_WAITS   = wb_init_waits ;
10920
    flags`SUBSEQ_WAITS = wb_subseq_waits ;
10921 45 mihad
 
10922
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10923
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10924
 
10925
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10926
    write_data`WRITE_DATA     = pci_address ;
10927
    write_data`WRITE_SEL      = 4'hF ;
10928
 
10929
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10930
 
10931
    // check if write succeeded
10932
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10933
    begin
10934
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10935
        test_fail("write to configuration cycle address register was not possible") ;
10936
        in_use = 0 ;
10937
        disable main ;
10938
    end
10939
 
10940
    // setup flags for wb master to handle retries and read and write data
10941
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10942
 
10943
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10944
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10945
 
10946
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10947
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10948
    read_data`READ_SEL          = 4'hF ;
10949
    write_data`WRITE_SEL        = 4'hF ;
10950
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10951
 
10952
    ok_pci = 0 ;
10953
    ok_wb  = 1 ;
10954
 
10955
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10956
    pci_address[31:24] = 0 ;
10957
    fork
10958
    begin
10959
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10960
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10961
        begin
10962
            $display("Time %t", $time) ;
10963
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10964
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10965
            ok_wb = 0 ;
10966
        end
10967
 
10968
        config_read( 12'h4, 4'hF, temp_var ) ;
10969
        if ( temp_var[29] !== 1 )
10970
        begin
10971
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10972
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10973
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10974
            ok_wb = 0 ;
10975
        end
10976
 
10977
        if ( temp_var[28] !== 0 )
10978
        begin
10979
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10980
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10981
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10982
            ok_wb = 0 ;
10983
        end
10984
 
10985
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10986
 
10987
        if (ok !== 1)
10988
        begin
10989
            ok_wb = 0 ;
10990
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10991
            $display("Write to PCI Device Status Register failed") ;
10992
            test_fail("Write to PCI Device Status Register failed") ;
10993
        end
10994
 
10995
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10996
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10997
        begin
10998
            $display("Time %t", $time) ;
10999
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
11000
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
11001
            ok_wb = 0 ;
11002
        end
11003
 
11004
        config_read( 12'h4, 4'hF, temp_var ) ;
11005
        if ( temp_var[29] !== 1 )
11006
        begin
11007
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11008
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
11009
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
11010
            ok_wb = 0 ;
11011
        end
11012
 
11013
        if ( temp_var[28] !== 0 )
11014
        begin
11015
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11016
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
11017
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
11018
            ok_wb = 0 ;
11019
        end
11020
 
11021
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
11022
 
11023
        if (ok !== 1)
11024
        begin
11025
            ok_wb = 0 ;
11026
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11027
            $display("Write to PCI Device Status Register failed") ;
11028
            test_fail("Write to PCI Device Status Register failed") ;
11029
        end
11030
    end
11031
    begin
11032
        pci_transaction_progress_monitor
11033
        (
11034
            pci_address,                                            // expected address on PCI bus
11035
            `BC_CONF_READ,                                          // expected bus command on PCI bus
11036
            0,                                                      // expected number of succesfull data phases
11037
            0,                                                      // expected number of cycles the transaction will take on PCI bus
11038
            1'b1,                                                   // monitor checking/not checking number of transfers
11039
            1'b0,                                                   // monitor checking/not checking number of cycles
11040
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11041
            ok_pci                                                  // status - 1 success, 0 failure
11042
        ) ;
11043
 
11044
        if (ok_pci)
11045
        begin
11046
            pci_transaction_progress_monitor
11047
            (
11048
                pci_address,                                            // expected address on PCI bus
11049
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
11050
                0,                                                      // expected number of succesfull data phases
11051
                0,                                                      // expected number of cycles the transaction will take on PCI bus
11052
                1'b1,                                                   // monitor checking/not checking number of transfers
11053
                1'b0,                                                   // monitor checking/not checking number of cycles
11054
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11055
                ok_pci                                                  // status - 1 success, 0 failure
11056
            ) ;
11057
        end
11058
 
11059
        if (!ok_pci)
11060
        begin
11061
            $display("Time %t", $time) ;
11062
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11063
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11064
        end
11065
    end
11066
    join
11067
 
11068
    if (ok_pci && ok_wb)
11069
    begin
11070
        test_ok ;
11071
    end
11072
 
11073
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
11074
    conf_cyc_type1_target_data = 0 ;
11075
    conf_cyc_type1_target_bus_num = 8'h55;
11076
 
11077
    pci_address      = 32'h5555_5555 ;
11078
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
11079
 
11080
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
11081
 
11082
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
11083
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11084
 
11085
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
11086
    write_data`WRITE_DATA     = pci_address ;
11087
    write_data`WRITE_SEL      = 4'hF ;
11088
 
11089
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
11090
 
11091
    // check if write succeeded
11092
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
11093
    begin
11094
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
11095
        test_fail("write to configuration cycle address register was not possible") ;
11096
        in_use = 0 ;
11097
        disable main ;
11098
    end
11099
 
11100
    // setup flags for wb master to handle retries and read and write data
11101
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
11102
 
11103
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
11104
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11105
 
11106
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
11107
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
11108
    read_data`READ_SEL          = 4'hF ;
11109
    write_data`WRITE_SEL        = 4'hF ;
11110
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
11111
 
11112
    ok_pci = 0 ;
11113
    ok_wb  = 1 ;
11114
 
11115
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
11116
    pci_address[31:24] = 0 ;
11117
    fork
11118
    begin
11119
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
11120
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
11121
        begin
11122
            $display("Time %t", $time) ;
11123
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
11124
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
11125
            ok_wb = 0 ;
11126
        end
11127
 
11128
        config_read( 12'h4, 4'hF, temp_var ) ;
11129
        if ( temp_var[29] !== 0 )
11130
        begin
11131
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
11132
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
11133
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
11134
            ok_wb = 0 ;
11135
        end
11136
 
11137
        if ( temp_var[28] !== 1 )
11138
        begin
11139
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
11140
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
11141
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
11142
            ok_wb = 0 ;
11143
        end
11144
 
11145
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
11146
 
11147
        if (ok !== 1)
11148
        begin
11149
            ok_wb = 0 ;
11150
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11151
            $display("Write to PCI Device Status Register failed") ;
11152
            test_fail("Write to PCI Device Status Register failed") ;
11153
        end
11154
 
11155
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
11156
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
11157
        begin
11158
            $display("Time %t", $time) ;
11159
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
11160
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
11161
            ok_wb = 0 ;
11162
        end
11163
 
11164
        config_read( 12'h4, 4'hF, temp_var ) ;
11165
        if ( temp_var[29] !== 0 )
11166
        begin
11167
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11168
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
11169
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
11170
            ok_wb = 0 ;
11171
        end
11172
 
11173
        if ( temp_var[28] !== 1 )
11174
        begin
11175
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11176
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
11177
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
11178
            ok_wb = 0 ;
11179
        end
11180
 
11181
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
11182
 
11183
        if (ok !== 1)
11184
        begin
11185
            ok_wb = 0 ;
11186
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11187
            $display("Write to PCI Device Status Register failed") ;
11188
            test_fail("Write to PCI Device Status Register failed") ;
11189
        end
11190
    end
11191
    begin
11192
        pci_transaction_progress_monitor
11193
        (
11194
            pci_address,                                            // expected address on PCI bus
11195
            `BC_CONF_READ,                                          // expected bus command on PCI bus
11196
            0,                                                      // expected number of succesfull data phases
11197
            0,                                                      // expected number of cycles the transaction will take on PCI bus
11198
            1'b1,                                                   // monitor checking/not checking number of transfers
11199
            1'b0,                                                   // monitor checking/not checking number of cycles
11200
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11201
            ok_pci                                                  // status - 1 success, 0 failure
11202
        ) ;
11203
 
11204
        if (ok_pci)
11205
        begin
11206
            pci_transaction_progress_monitor
11207
            (
11208
                pci_address,                                            // expected address on PCI bus
11209
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
11210
                0,                                                      // expected number of succesfull data phases
11211
                0,                                                      // expected number of cycles the transaction will take on PCI bus
11212
                1'b1,                                                   // monitor checking/not checking number of transfers
11213
                1'b0,                                                   // monitor checking/not checking number of cycles
11214
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11215
                ok_pci                                                  // status - 1 success, 0 failure
11216
            ) ;
11217
        end
11218
 
11219
        if (!ok_pci)
11220
        begin
11221
            $display("Time %t", $time) ;
11222
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11223
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11224
        end
11225
    end
11226
    join
11227
 
11228
    if (ok_pci && ok_wb)
11229
    begin
11230
        test_ok ;
11231
    end
11232
 
11233
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
11234
 
11235
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
11236
    conf_cyc_type1_target_data = 32'h5555_5555 ;
11237
    conf_cyc_type1_target_bus_num = 8'hAA;
11238
 
11239
    pci_address      = 32'hAAAA_AAAA ;
11240
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
11241
 
11242
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
11243
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11244
 
11245
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
11246
    write_data`WRITE_DATA     = pci_address ;
11247
    write_data`WRITE_SEL      = 4'hF ;
11248
 
11249
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
11250
 
11251
    // check if write succeeded
11252
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
11253
    begin
11254
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
11255
        test_fail("write to configuration cycle address register was not possible") ;
11256
        in_use = 0 ;
11257
        disable main ;
11258
    end
11259
 
11260
    // setup flags for wb master to handle retries and read and write data
11261
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
11262
 
11263
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
11264
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11265
 
11266
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
11267
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
11268
    read_data`READ_SEL          = 4'b0101 ;
11269
    write_data`WRITE_SEL        = 4'b1010 ;
11270
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
11271
 
11272
    ok_pci = 0 ;
11273
    ok_wb  = 1 ;
11274
 
11275
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
11276
    pci_address[31:24] = 0 ;
11277
 
11278
    fork
11279
    begin
11280
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
11281
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
11282
        begin
11283
            $display("Time %t", $time) ;
11284
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
11285
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
11286
            ok_wb = 0 ;
11287
        end
11288
 
11289
        config_read( 12'h4, 4'hF, temp_var ) ;
11290
        if ( temp_var[29] !== 0 )
11291
        begin
11292
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
11293
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
11294
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
11295
            ok_wb = 0 ;
11296
        end
11297
 
11298
        if ( temp_var[28] !== 0 )
11299
        begin
11300
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
11301
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
11302
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
11303
            ok_wb = 0 ;
11304
        end
11305
 
11306
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
11307
 
11308
        if (ok !== 1)
11309
        begin
11310
            ok_wb = 0 ;
11311
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11312
            $display("Write to PCI Device Status Register failed") ;
11313
            test_fail("Write to PCI Device Status Register failed") ;
11314
        end
11315
 
11316
        if (read_status`READ_DATA !== 32'hDE55_BE55)
11317
        begin
11318
            ok_wb = 0 ;
11319
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11320
            $display("Read Data provided by the bridge was not as expected!") ;
11321
            test_fail("Read Data provided by the bridge was not as expected") ;
11322
        end
11323
 
11324
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
11325
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
11326
        begin
11327
            $display("Time %t", $time) ;
11328
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
11329
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
11330
            ok_wb = 0 ;
11331
        end
11332
 
11333
        config_read( 12'h4, 4'hF, temp_var ) ;
11334
        if ( temp_var[29] !== 0 )
11335
        begin
11336
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11337
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
11338
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
11339
            ok_wb = 0 ;
11340
        end
11341
 
11342
        if ( temp_var[28] !== 0 )
11343
        begin
11344
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11345
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
11346
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
11347
            ok_wb = 0 ;
11348
        end
11349
 
11350
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
11351
 
11352
        if (ok !== 1)
11353
        begin
11354
            ok_wb = 0 ;
11355
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11356
            $display("Write to PCI Device Status Register failed") ;
11357
            test_fail("Write to PCI Device Status Register failed") ;
11358
        end
11359
 
11360
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
11361
        begin
11362
            ok_wb = 0 ;
11363
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11364
            $display("Data written by the bridge was not as expected!") ;
11365
            test_fail("Data written by the bridge was not as expected") ;
11366
        end
11367
 
11368
    end
11369
    begin
11370
        ok = 1 ;
11371
        repeat(8)
11372
        begin
11373
            pci_transaction_progress_monitor
11374
            (
11375
                pci_address,                                            // expected address on PCI bus
11376
                `BC_CONF_READ,                                          // expected bus command on PCI bus
11377
                0,                                                      // expected number of succesfull data phases
11378
                0,                                                      // expected number of cycles the transaction will take on PCI bus
11379
                1'b1,                                                   // monitor checking/not checking number of transfers
11380
                1'b0,                                                   // monitor checking/not checking number of cycles
11381
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11382
                ok_pci                                                  // status - 1 success, 0 failure
11383
            ) ;
11384
 
11385
            if (!ok_pci)
11386
            begin
11387
                ok = 0 ;
11388
                $display("Time %t", $time) ;
11389
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11390
            end
11391
        end
11392
 
11393
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
11394
 
11395
        pci_transaction_progress_monitor
11396
        (
11397
            pci_address,                                            // expected address on PCI bus
11398
            `BC_CONF_READ,                                          // expected bus command on PCI bus
11399
            1,                                                      // expected number of succesfull data phases
11400
            0,                                                      // expected number of cycles the transaction will take on PCI bus
11401
            1'b1,                                                   // monitor checking/not checking number of transfers
11402
            1'b0,                                                   // monitor checking/not checking number of cycles
11403
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11404
            ok_pci                                                  // status - 1 success, 0 failure
11405
        ) ;
11406
 
11407
        if (!ok_pci)
11408
        begin
11409
            ok = 0 ;
11410
            $display("Time %t", $time) ;
11411
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11412
        end
11413
 
11414
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
11415
        repeat(8)
11416
        begin
11417
            pci_transaction_progress_monitor
11418
            (
11419
                pci_address,                                            // expected address on PCI bus
11420
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
11421
                0,                                                      // expected number of succesfull data phases
11422
                0,                                                      // expected number of cycles the transaction will take on PCI bus
11423
                1'b1,                                                   // monitor checking/not checking number of transfers
11424
                1'b0,                                                   // monitor checking/not checking number of cycles
11425
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11426
                ok_pci                                                  // status - 1 success, 0 failure
11427
            ) ;
11428
 
11429
            if (!ok_pci)
11430
            begin
11431
                ok = 0 ;
11432
                $display("Time %t", $time) ;
11433
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11434
            end
11435
        end
11436
 
11437
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
11438
        pci_transaction_progress_monitor
11439
        (
11440
            pci_address,                                            // expected address on PCI bus
11441
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
11442
            1,                                                      // expected number of succesfull data phases
11443
            0,                                                      // expected number of cycles the transaction will take on PCI bus
11444
            1'b1,                                                   // monitor checking/not checking number of transfers
11445
            1'b0,                                                   // monitor checking/not checking number of cycles
11446
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11447
            ok_pci                                                  // status - 1 success, 0 failure
11448
        ) ;
11449
 
11450
        if (!ok_pci)
11451
        begin
11452
            ok = 0 ;
11453
            $display("Time %t", $time) ;
11454
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11455
        end
11456
 
11457
        if (!ok)
11458
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11459
    end
11460
    join
11461
 
11462
    if (ok_pci && ok_wb)
11463
    begin
11464
        test_ok ;
11465
    end
11466
 
11467
    in_use = 0 ;
11468
end
11469
endtask // test_configuration_cycle_type1_generation
11470
`endif
11471
 
11472
task test_initial_conf_values ;
11473
    reg [11:0] register_offset ;
11474
    reg [31:0] expected_value ;
11475
    reg        failed ;
11476
`ifdef HOST
11477
    reg `READ_STIM_TYPE    read_data ;
11478
    reg `WB_TRANSFER_FLAGS flags ;
11479
    reg `READ_RETURN_TYPE  read_status ;
11480
 
11481
    reg `WRITE_STIM_TYPE   write_data ;
11482
    reg `WRITE_RETURN_TYPE write_status ;
11483
begin
11484
    failed     = 0 ;
11485
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11486
    flags      = 0 ;
11487
    read_data  = 0 ;
11488
    write_data = 0 ;
11489
 
11490
    read_data`READ_SEL = 4'hF ;
11491
 
11492 92 mihad
    flags`INIT_WAITS           = wb_init_waits ;
11493
    flags`SUBSEQ_WAITS         = wb_subseq_waits ;
11494 45 mihad
 
11495
    // test MEM/IO map bit initial value in each PCI BAR
11496
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
11497
 
11498
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11499
 
11500 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11501
 
11502 45 mihad
    `ifdef NO_CNF_IMAGE
11503
        `ifdef PCI_IMAGE0
11504
            if (`PCI_AM0)
11505
                expected_value = `PCI_BA0_MEM_IO ;
11506
            else
11507
                expected_value = 32'h0000_0000 ;
11508
        `else
11509
            expected_value = 32'h0000_0000 ;
11510
        `endif
11511
    `else
11512
        expected_value = 32'h0000_0000 ;
11513
    `endif
11514
 
11515 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11516
    begin
11517 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
11518
        failed = 1 ;
11519 15 mihad
    end
11520 45 mihad
    else
11521
    begin
11522
        if (read_status`READ_DATA !== expected_value)
11523
        begin
11524
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
11525
            failed = 1 ;
11526
        end
11527
    end
11528 15 mihad
 
11529 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
11530 15 mihad
 
11531 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11532
 
11533
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11534
 
11535
    if (`PCI_AM1)
11536
        expected_value = `PCI_BA1_MEM_IO ;
11537
    else
11538
        expected_value = 32'h0000_0000 ;
11539
 
11540
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11541
    begin
11542
        test_fail("read from P_BA1 register didn't succeede") ;
11543
        failed = 1 ;
11544
    end
11545
    else
11546
    begin
11547
        if (read_status`READ_DATA !== expected_value)
11548
        begin
11549
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
11550
            failed = 1 ;
11551
        end
11552
    end
11553
 
11554
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
11555
 
11556
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11557
 
11558
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11559
 
11560
    `ifdef PCI_IMAGE2
11561
        if (`PCI_AM2)
11562
            expected_value = `PCI_BA2_MEM_IO ;
11563
        else
11564
            expected_value = 32'h0000_0000 ;
11565 15 mihad
    `else
11566 45 mihad
        expected_value = 32'h0000_0000 ;
11567
    `endif
11568 15 mihad
 
11569 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11570
    begin
11571
        test_fail("read from P_BA2 register didn't succeede") ;
11572
        failed = 1 ;
11573
    end
11574
    else
11575
    begin
11576
        if (read_status`READ_DATA !== expected_value)
11577
        begin
11578
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
11579
            failed = 1 ;
11580
        end
11581
    end
11582 15 mihad
 
11583 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
11584
 
11585
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11586
 
11587
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11588
 
11589
    `ifdef PCI_IMAGE3
11590
        if (`PCI_AM3)
11591
            expected_value = `PCI_BA3_MEM_IO ;
11592
        else
11593
            expected_value = 32'h0000_0000 ;
11594
    `else
11595
        expected_value = 32'h0000_0000 ;
11596 15 mihad
    `endif
11597 45 mihad
 
11598
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11599
    begin
11600
        test_fail("read from P_BA3 register didn't succeede") ;
11601
        failed = 1 ;
11602
    end
11603
    else
11604
    begin
11605
        if (read_status`READ_DATA !== expected_value)
11606
        begin
11607
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
11608
            failed = 1 ;
11609
        end
11610
    end
11611
 
11612
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
11613
 
11614
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11615
 
11616
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11617
 
11618
    `ifdef PCI_IMAGE4
11619
        if (`PCI_AM4)
11620
            expected_value = `PCI_BA4_MEM_IO ;
11621
        else
11622
            expected_value = 32'h0000_0000 ;
11623
    `else
11624
        expected_value = 32'h0000_0000 ;
11625 15 mihad
    `endif
11626
 
11627 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11628
    begin
11629
        test_fail("read from P_BA4 register didn't succeede") ;
11630
        failed = 1 ;
11631
    end
11632
    else
11633
    begin
11634
        if (read_status`READ_DATA !== expected_value)
11635
        begin
11636
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11637
            failed = 1 ;
11638
        end
11639
    end
11640 15 mihad
 
11641 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11642 15 mihad
 
11643 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11644
 
11645
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11646
 
11647
    `ifdef PCI_IMAGE5
11648
        if(`PCI_AM5)
11649
            expected_value = `PCI_BA5_MEM_IO ;
11650
        else
11651
            expected_value = 32'h0000_0000 ;
11652
    `else
11653
        expected_value = 32'h0000_0000 ;
11654
    `endif
11655
 
11656
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11657
    begin
11658
        test_fail("read from P_BA5 register didn't succeede") ;
11659
        failed = 1 ;
11660
    end
11661
    else
11662
    begin
11663
        if (read_status`READ_DATA !== expected_value)
11664
        begin
11665
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11666
            failed = 1 ;
11667
        end
11668
    end
11669
 
11670
    // test Address Mask initial values
11671
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11672
 
11673
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11674
 
11675
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11676
 
11677
    `ifdef NO_CNF_IMAGE
11678
        `ifdef PCI_IMAGE0
11679
            expected_value = {`PCI_AM0, 12'h000};
11680
 
11681
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11682
        `else
11683
            expected_value = 32'h0000_0000 ;
11684
        `endif
11685
    `else
11686
        expected_value = 32'hFFFF_FFFF ;
11687
 
11688
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11689
    `endif
11690
 
11691
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11692
    begin
11693
        test_fail("read from P_AM0 register didn't succeede") ;
11694
        failed = 1 ;
11695
    end
11696
    else
11697
    begin
11698
        if (read_status`READ_DATA !== expected_value)
11699
        begin
11700
            test_fail("AM0 initial value was not set as defined");
11701
            failed = 1 ;
11702
        end
11703
    end
11704
 
11705
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11706
 
11707
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11708
 
11709
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11710
 
11711
    expected_value = {`PCI_AM1, 12'h000};
11712
 
11713
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11714
 
11715
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11716
    begin
11717
        test_fail("read from P_AM1 register didn't succeede") ;
11718
        failed = 1 ;
11719
    end
11720
    else
11721
    begin
11722
        if (read_status`READ_DATA !== expected_value)
11723
        begin
11724
            test_fail("AM1 initial value was not set as defined");
11725
            failed = 1 ;
11726
        end
11727
    end
11728
 
11729
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11730
 
11731
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11732
 
11733
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11734
 
11735
    `ifdef PCI_IMAGE2
11736
        expected_value = {`PCI_AM2, 12'h000};
11737
 
11738
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11739
    `else
11740
        expected_value = 32'h0000_0000 ;
11741
    `endif
11742
 
11743
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11744
    begin
11745
        test_fail("read from P_AM2 register didn't succeede") ;
11746
        failed = 1 ;
11747
    end
11748
    else
11749
    begin
11750
        if (read_status`READ_DATA !== expected_value)
11751
        begin
11752
            test_fail("AM2 initial value was not set as defined");
11753
            failed = 1 ;
11754
        end
11755
    end
11756
 
11757
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11758
 
11759
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11760
 
11761
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11762
 
11763
    `ifdef PCI_IMAGE3
11764
        expected_value = {`PCI_AM3, 12'h000};
11765
 
11766
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11767
    `else
11768
        expected_value = 32'h0000_0000 ;
11769
    `endif
11770
 
11771
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11772
    begin
11773
        test_fail("read from P_AM3 register didn't succeede") ;
11774
        failed = 1 ;
11775
    end
11776
    else
11777
    begin
11778
        if (read_status`READ_DATA !== expected_value)
11779
        begin
11780
            test_fail("AM3 initial value was not set as defined");
11781
            failed = 1 ;
11782
        end
11783
    end
11784
 
11785
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11786
 
11787
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11788
 
11789
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11790
 
11791
    `ifdef PCI_IMAGE4
11792
        expected_value = {`PCI_AM4, 12'h000};
11793
 
11794
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11795
    `else
11796
        expected_value = 32'h0000_0000 ;
11797
    `endif
11798
 
11799
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11800
    begin
11801
        test_fail("read from P_AM4 register didn't succeede") ;
11802
        failed = 1 ;
11803
    end
11804
    else
11805
    begin
11806
        if (read_status`READ_DATA !== expected_value)
11807
        begin
11808
            test_fail("AM4 initial value was not set as defined");
11809
            failed = 1 ;
11810
        end
11811
    end
11812
 
11813
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11814
 
11815
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11816
 
11817
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11818
 
11819
    `ifdef PCI_IMAGE5
11820
        expected_value = {`PCI_AM5, 12'h000};
11821
 
11822
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11823
    `else
11824
        expected_value = 32'h0000_0000 ;
11825
    `endif
11826
 
11827
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11828
    begin
11829
        test_fail("read from P_AM5 register didn't succeede") ;
11830
        failed = 1 ;
11831
    end
11832
    else
11833
    begin
11834
        if (read_status`READ_DATA !== expected_value)
11835
        begin
11836
            test_fail("AM5 initial value was not set as defined");
11837
            failed = 1 ;
11838
        end
11839
    end
11840
 
11841
`endif
11842
 
11843
`ifdef GUEST
11844
    reg [31:0] read_data ;
11845
begin
11846
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11847
    failed    = 0 ;
11848
 
11849
    // check all images' BARs
11850
 
11851
    // BAR0
11852
    configuration_cycle_read
11853
    (
11854
        8'h00,                          // bus number [7:0]
11855
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11856
        3'h0,                           // function number [2:0]
11857
        6'h4,                           // register number [5:0]
11858
        2'h0,                           // type [1:0]
11859
        4'hF,                           // byte enables [3:0]
11860
        read_data                       // data returned from configuration read [31:0]
11861
    ) ;
11862
 
11863
    expected_value = 32'h0000_0000 ;
11864
 
11865
    if( read_data !== expected_value)
11866
    begin
11867
        test_fail("initial value of BAR0 register not as expected") ;
11868
        failed = 1 ;
11869
    end
11870
 
11871
    // BAR1
11872
    configuration_cycle_read
11873
    (
11874
        8'h00,                          // bus number [7:0]
11875
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11876
        3'h0,                           // function number [2:0]
11877
        6'h5,                           // register number [5:0]
11878
        2'h0,                           // type [1:0]
11879
        4'hF,                           // byte enables [3:0]
11880
        read_data                       // data returned from configuration read [31:0]
11881
    ) ;
11882
 
11883
    if (`PCI_AM1)
11884
        expected_value = `PCI_BA1_MEM_IO ;
11885
    else
11886
        expected_value = 32'h0000_0000 ;
11887
 
11888
    if( read_data !== expected_value)
11889
    begin
11890
        test_fail("initial value of BAR1 register not as expected") ;
11891
        failed = 1 ;
11892
    end
11893
 
11894
    // BAR2
11895
    configuration_cycle_read
11896
    (
11897
        8'h00,                          // bus number [7:0]
11898
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11899
        3'h0,                           // function number [2:0]
11900
        6'h6,                           // register number [5:0]
11901
        2'h0,                           // type [1:0]
11902
        4'hF,                           // byte enables [3:0]
11903
        read_data                       // data returned from configuration read [31:0]
11904
    ) ;
11905
 
11906
    `ifdef PCI_IMAGE2
11907
    if (`PCI_AM2)
11908
        expected_value = `PCI_BA2_MEM_IO ;
11909
    else
11910
        expected_value = 32'h0000_0000 ;
11911
    `else
11912
    expected_value = 32'h0 ;
11913
    `endif
11914
 
11915
    if( read_data !== expected_value)
11916
    begin
11917
        test_fail("initial value of BAR2 register not as expected") ;
11918
        failed = 1 ;
11919
    end
11920
 
11921
    // BAR3
11922
    configuration_cycle_read
11923
    (
11924
        8'h00,                          // bus number [7:0]
11925
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11926
        3'h0,                           // function number [2:0]
11927
        6'h7,                           // register number [5:0]
11928
        2'h0,                           // type [1:0]
11929
        4'hF,                           // byte enables [3:0]
11930
        read_data                       // data returned from configuration read [31:0]
11931
    ) ;
11932
 
11933
    `ifdef PCI_IMAGE3
11934
    if(`PCI_AM3)
11935
        expected_value = `PCI_BA3_MEM_IO ;
11936
    else
11937
        expected_value = 32'h0000_0000 ;
11938
    `else
11939
    expected_value = 32'h0 ;
11940
    `endif
11941
 
11942
    if( read_data !== expected_value)
11943
    begin
11944
        test_fail("initial value of BAR3 register not as expected") ;
11945
        failed = 1 ;
11946
    end
11947
 
11948
    // BAR4
11949
    configuration_cycle_read
11950
    (
11951
        8'h00,                          // bus number [7:0]
11952
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11953
        3'h0,                           // function number [2:0]
11954
        6'h8,                           // register number [5:0]
11955
        2'h0,                           // type [1:0]
11956
        4'hF,                           // byte enables [3:0]
11957
        read_data                       // data returned from configuration read [31:0]
11958
    ) ;
11959
 
11960
    `ifdef PCI_IMAGE4
11961
    if (`PCI_AM4)
11962
        expected_value = `PCI_BA4_MEM_IO ;
11963
    else
11964
        expected_value = 32'h0000_0000 ;
11965
    `else
11966
    expected_value = 32'h0 ;
11967
    `endif
11968
 
11969
    if( read_data !== expected_value)
11970
    begin
11971
        test_fail("initial value of BAR4 register not as expected") ;
11972
        failed = 1 ;
11973
    end
11974
 
11975
    // BAR5
11976
    configuration_cycle_read
11977
    (
11978
        8'h00,                          // bus number [7:0]
11979
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11980
        3'h0,                           // function number [2:0]
11981
        6'h9,                           // register number [5:0]
11982
        2'h0,                           // type [1:0]
11983
        4'hF,                           // byte enables [3:0]
11984
        read_data                       // data returned from configuration read [31:0]
11985
    ) ;
11986
 
11987
    `ifdef PCI_IMAGE5
11988
    if(`PCI_AM5)
11989
        expected_value = `PCI_BA5_MEM_IO ;
11990
    else
11991
        expected_value = 32'h0000_0000 ;
11992
    `else
11993
    expected_value = 32'h0 ;
11994
    `endif
11995
 
11996
    if( read_data !== expected_value)
11997
    begin
11998
        test_fail("initial value of BAR5 register not as expected") ;
11999
        failed = 1 ;
12000
    end
12001
 
12002
    // write all 1s to BAR0
12003
    read_data = 32'hFFFF_FFFF ;
12004
 
12005
    // BAR0
12006
    configuration_cycle_write
12007
    (
12008
        8'h00,                          // bus number [7:0]
12009
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12010
        3'h0,                           // function number [2:0]
12011
        6'h4,                           // register number [5:0]
12012
        2'h0,                           // type [1:0]
12013
        4'hF,                           // byte enables [3:0]
12014
        read_data                       // data to write [31:0]
12015
    ) ;
12016
 
12017
    expected_value = 32'hFFFF_FFFF ;
12018
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12019
 
12020
    configuration_cycle_read
12021
    (
12022
        8'h00,                          // bus number [7:0]
12023
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12024
        3'h0,                           // function number [2:0]
12025
        6'h4,                           // register number [5:0]
12026
        2'h0,                           // type [1:0]
12027
        4'hF,                           // byte enables [3:0]
12028
        read_data                       // data to write [31:0]
12029
    ) ;
12030
 
12031
    if ( read_data !== expected_value )
12032
    begin
12033
        test_fail("BAR0 value was not masked correctly during configuration read") ;
12034
        failed = 1 ;
12035
    end
12036
 
12037
    // write all 1s to BAR1
12038
    read_data = 32'hFFFF_FFFF ;
12039
 
12040
    // BAR1
12041
    configuration_cycle_write
12042
    (
12043
        8'h00,                          // bus number [7:0]
12044
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12045
        3'h0,                           // function number [2:0]
12046
        6'h5,                           // register number [5:0]
12047
        2'h0,                           // type [1:0]
12048
        4'hF,                           // byte enables [3:0]
12049
        read_data                       // data to write [31:0]
12050
    ) ;
12051
 
12052
    expected_value = {`PCI_AM1, 12'h000} ;
12053
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12054
    if (`PCI_AM1)
12055
        expected_value[0] = `PCI_BA1_MEM_IO ;
12056
 
12057
    configuration_cycle_read
12058
    (
12059
        8'h00,                          // bus number [7:0]
12060
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12061
        3'h0,                           // function number [2:0]
12062
        6'h5,                           // register number [5:0]
12063
        2'h0,                           // type [1:0]
12064
        4'hF,                           // byte enables [3:0]
12065
        read_data                       // data to write [31:0]
12066
    ) ;
12067
 
12068
    if ( read_data !== expected_value )
12069
    begin
12070
        test_fail("BAR1 value was not masked correctly during configuration read") ;
12071
        failed = 1 ;
12072
    end
12073
 
12074
    // write all 1s to BAR2
12075
    read_data = 32'hFFFF_FFFF ;
12076
 
12077
    // BAR2
12078
    configuration_cycle_write
12079
    (
12080
        8'h00,                          // bus number [7:0]
12081
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12082
        3'h0,                           // function number [2:0]
12083
        6'h6,                           // register number [5:0]
12084
        2'h0,                           // type [1:0]
12085
        4'hF,                           // byte enables [3:0]
12086
        read_data                       // data to write [31:0]
12087
    ) ;
12088
 
12089
`ifdef PCI_IMAGE2
12090
    expected_value = {`PCI_AM2, 12'h000} ;
12091
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12092
    if (`PCI_AM2)
12093
        expected_value[0] = `PCI_BA2_MEM_IO ;
12094
`else
12095
    expected_value = 0 ;
12096
`endif
12097
 
12098
    configuration_cycle_read
12099
    (
12100
        8'h00,                          // bus number [7:0]
12101
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12102
        3'h0,                           // function number [2:0]
12103
        6'h6,                           // register number [5:0]
12104
        2'h0,                           // type [1:0]
12105
        4'hF,                           // byte enables [3:0]
12106
        read_data                       // data to write [31:0]
12107
    ) ;
12108
 
12109
    if ( read_data !== expected_value )
12110
    begin
12111
        test_fail("BAR2 value was not masked correctly during configuration read") ;
12112
        failed = 1 ;
12113
    end
12114
 
12115
    // write all 1s to BAR3
12116
    read_data = 32'hFFFF_FFFF ;
12117
 
12118
    // BAR3
12119
    configuration_cycle_write
12120
    (
12121
        8'h00,                          // bus number [7:0]
12122
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12123
        3'h0,                           // function number [2:0]
12124
        6'h7,                           // register number [5:0]
12125
        2'h0,                           // type [1:0]
12126
        4'hF,                           // byte enables [3:0]
12127
        read_data                       // data to write [31:0]
12128
    ) ;
12129
 
12130
`ifdef PCI_IMAGE3
12131
    expected_value = {`PCI_AM3, 12'h000} ;
12132
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12133
    if(`PCI_AM3)
12134
        expected_value[0] = `PCI_BA3_MEM_IO ;
12135
`else
12136
    expected_value = 0 ;
12137
`endif
12138
 
12139
    configuration_cycle_read
12140
    (
12141
        8'h00,                          // bus number [7:0]
12142
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12143
        3'h0,                           // function number [2:0]
12144
        6'h7,                           // register number [5:0]
12145
        2'h0,                           // type [1:0]
12146
        4'hF,                           // byte enables [3:0]
12147
        read_data                       // data to write [31:0]
12148
    ) ;
12149
 
12150
    if ( read_data !== expected_value )
12151
    begin
12152
        test_fail("BAR3 value was not masked correctly during configuration read") ;
12153
        failed = 1 ;
12154
    end
12155
 
12156
    // write all 1s to BAR4
12157
    read_data = 32'hFFFF_FFFF ;
12158
 
12159
    // BAR4
12160
    configuration_cycle_write
12161
    (
12162
        8'h00,                          // bus number [7:0]
12163
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12164
        3'h0,                           // function number [2:0]
12165
        6'h8,                           // register number [5:0]
12166
        2'h0,                           // type [1:0]
12167
        4'hF,                           // byte enables [3:0]
12168
        read_data                       // data to write [31:0]
12169
    ) ;
12170
 
12171
`ifdef PCI_IMAGE4
12172
    expected_value = {`PCI_AM4, 12'h000} ;
12173
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12174
    if(`PCI_AM4)
12175
        expected_value[0] = `PCI_BA4_MEM_IO ;
12176
`else
12177
    expected_value = 0 ;
12178
`endif
12179
 
12180
    configuration_cycle_read
12181
    (
12182
        8'h00,                          // bus number [7:0]
12183
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12184
        3'h0,                           // function number [2:0]
12185
        6'h8,                           // register number [5:0]
12186
        2'h0,                           // type [1:0]
12187
        4'hF,                           // byte enables [3:0]
12188
        read_data                       // data to write [31:0]
12189
    ) ;
12190
 
12191
    if ( read_data !== expected_value )
12192
    begin
12193
        test_fail("BAR4 value was not masked correctly during configuration read") ;
12194
        failed = 1 ;
12195
    end
12196
 
12197
    // write all 1s to BAR5
12198
    read_data = 32'hFFFF_FFFF ;
12199
 
12200
    // BAR5
12201
    configuration_cycle_write
12202
    (
12203
        8'h00,                          // bus number [7:0]
12204
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12205
        3'h0,                           // function number [2:0]
12206
        6'h9,                           // register number [5:0]
12207
        2'h0,                           // type [1:0]
12208
        4'hF,                           // byte enables [3:0]
12209
        read_data                       // data to write [31:0]
12210
    ) ;
12211
 
12212
`ifdef PCI_IMAGE5
12213
    expected_value = {`PCI_AM5, 12'h000} ;
12214
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12215
    if(`PCI_AM5)
12216
        expected_value[0] = `PCI_BA5_MEM_IO ;
12217
`else
12218
    expected_value = 0 ;
12219
`endif
12220
 
12221
    configuration_cycle_read
12222
    (
12223
        8'h00,                          // bus number [7:0]
12224
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12225
        3'h0,                           // function number [2:0]
12226
        6'h9,                           // register number [5:0]
12227
        2'h0,                           // type [1:0]
12228
        4'hF,                           // byte enables [3:0]
12229
        read_data                       // data to write [31:0]
12230
    ) ;
12231
 
12232
    if ( read_data !== expected_value )
12233
    begin
12234
        test_fail("BAR5 value was not masked correctly during configuration read") ;
12235
        failed = 1 ;
12236
    end
12237
`endif
12238
 
12239
    if (!failed)
12240
        test_ok ;
12241
end
12242
endtask
12243
 
12244 15 mihad
task display_warning;
12245
    input [31:0] error_address ;
12246
    input [31:0] expected_data ;
12247
    input [31:0] actual ;
12248
begin
12249
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
12250
end
12251
endtask // display warning
12252
 
12253
/*############################################################################
12254
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
12255
=====================
12256
############################################################################*/
12257
 
12258
// Task reslease the PCI bus for 'delay' clocks
12259
task do_pause;
12260
  input  [15:0] delay;
12261
  reg    [15:0] cnt;
12262
  begin
12263
    test_start <= 1'b0;  // no device is allowed to take this
12264
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
12265
    begin
12266
      if (~pci_reset_comb)
12267
      begin
12268
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
12269
      end
12270
      `NO_ELSE;
12271
    end
12272
  end
12273
endtask // do_pause
12274
 
12275
// Reference task for using pci_behavioral_master! (from Blue Beaver)
12276
task DO_REF;
12277
  input  [79:0] name;
12278
  input  [2:0] master_number;
12279
  input  [PCI_BUS_DATA_RANGE:0] address;
12280
  input  [3:0] command;
12281
  input  [PCI_BUS_DATA_RANGE:0] data;
12282
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
12283
  input  [9:0] size;
12284
  input   make_addr_par_error, make_data_par_error;
12285
  input  [7:0] master_wait_states;
12286
  input  [7:0] target_wait_states;
12287
  input  [1:0] target_devsel_speed;
12288
  input   fast_back_to_back;
12289
  input  [2:0] target_termination;
12290
  input   expect_master_abort;
12291
  reg     waiting;
12292
  begin
12293
// Cautiously wait for previous command to be done
12294
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
12295
    begin
12296
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
12297
      begin
12298
        if (~pci_reset_comb)
12299
        begin
12300
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
12301
        end
12302
        `NO_ELSE;
12303
      end
12304
      else
12305
      begin
12306
        waiting = 1'b0;  // ready to do next command
12307
      end
12308
    end
12309
    next_test_name[79:0] <= name[79:0];
12310
    test_master_number <= master_number[2:0];
12311
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
12312
    test_command[3:0] <= command[3:0] ;
12313
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
12314
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
12315
    test_size <= size;
12316
    test_make_addr_par_error <= make_addr_par_error;
12317
    test_make_data_par_error <= make_data_par_error;
12318 92 mihad
    test_master_initial_wait_states <= pci_init_waits ;
12319
    test_master_subsequent_wait_states <= pci_subseq_waits ;
12320 15 mihad
    test_target_initial_wait_states <= target_wait_states[7:4];
12321
    test_target_subsequent_wait_states <= target_wait_states[3:0];
12322
    test_target_devsel_speed <= target_devsel_speed[1:0];
12323
    test_fast_back_to_back <= fast_back_to_back;
12324
    test_target_termination <= target_termination[2:0];
12325
    test_expect_master_abort <= expect_master_abort;
12326
    test_start <= 1'b1;
12327
    if (~pci_reset_comb)
12328
    begin
12329
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
12330
    end
12331
    `NO_ELSE;
12332
// wait for new command to start
12333
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
12334
    begin
12335
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
12336
      begin
12337
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
12338
      end
12339
      else
12340
      begin
12341
        waiting = 1'b0;  // ready to do next command
12342
      end
12343
    end
12344
  end
12345
endtask // DO_REF
12346
 
12347
// Use Macros defined in pci_defines.vh as paramaters
12348
 
12349
// DO_REF (name[79:0], master_number[2:0],
12350
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
12351
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
12352
//          make_addr_par_error, make_data_par_error,
12353
//          master_wait_states[8:0], target_wait_states[8:0],
12354
//          target_devsel_speed[1:0], fast_back_to_back,
12355
//          target_termination[2:0],
12356
//          expect_master_abort);
12357
//
12358
// Example:
12359
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
12360
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
12361
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
12362
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
12363
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
12364
 
12365
// Access a location with no high-order bits set, assuring that no device responds
12366
task PCIU_CONFIG_READ_MASTER_ABORT;
12367
  input  [79:0] name;
12368
  input  [2:0] master_number;
12369 51 mihad
  input  [31:0] address ;
12370
  input  [3:0] be ;
12371 15 mihad
  begin
12372 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
12373
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
12374
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
12375 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
12376
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
12377
  end
12378
endtask // PCIU_CONFIG_READ_MASTER_ABORT
12379
 
12380
// Access a location with no high-order bits set, assuring that no device responds
12381
task PCIU_CONFIG_WRITE_MASTER_ABORT;
12382
  input  [79:0] name;
12383
  input  [2:0] master_number;
12384 51 mihad
  input  [31:0] address ;
12385
  input  [3:0] be ;
12386 15 mihad
  begin
12387 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
12388
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
12389
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
12390 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
12391
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
12392
  end
12393
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
12394
 
12395
// Access a location with no high-order bits set, assuring that no device responds
12396
task PCIU_MEM_READ_MASTER_ABORT;
12397
  input  [79:0] name;
12398
  input  [2:0] master_number;
12399
  input  [9:0] size;
12400
  begin
12401
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
12402
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
12403
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
12404
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
12405
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
12406
  end
12407
endtask // PCIU_MEM_READ_MASTER_ABORT
12408
 
12409
// Access a location with no high-order bits set, assuring that no device responds
12410
task PCIU_MEM_WRITE_MASTER_ABORT;
12411
  input  [79:0] name;
12412
  input  [2:0] master_number;
12413
  input  [9:0] size;
12414
  begin
12415
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
12416
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
12417
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
12418
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
12419
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
12420
  end
12421
endtask // PCIU_MEM_WRITE_MASTER_ABORT
12422
 
12423
// Do variable length transfers with various paramaters
12424
task PCIU_CONFIG_READ;
12425
  input  [79:0] name;
12426
  input  [2:0] master_number;
12427
  input  [PCI_BUS_DATA_RANGE:0] address;
12428
  input  [PCI_BUS_DATA_RANGE:0] data;
12429
  input  [3:0] be ;
12430
  input  [9:0] size;
12431
  input  [7:0] master_wait_states;
12432
  input  [7:0] target_wait_states;
12433
  input  [1:0] target_devsel_speed;
12434
  input  [2:0] target_termination;
12435
  begin
12436
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12437
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
12438
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12439
              8'h0_0, target_wait_states[7:0],
12440
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12441
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12442
  end
12443
endtask // PCIU_CONFIG_READ
12444
 
12445
task PCIU_CONFIG_WRITE;
12446
  input  [79:0] name;
12447
  input  [2:0] master_number;
12448
  input  [PCI_BUS_DATA_RANGE:0] address;
12449
  input  [PCI_BUS_DATA_RANGE:0] data;
12450
  input  [3:0] be ;
12451
  input  [9:0] size;
12452
  input  [7:0] master_wait_states;
12453
  input  [7:0] target_wait_states;
12454
  input  [1:0] target_devsel_speed;
12455
  input  [2:0] target_termination;
12456
  begin
12457
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12458
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
12459
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12460
              8'h0_0, target_wait_states[7:0],
12461
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12462
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12463
  end
12464
endtask // PCIU_CONFIG_WRITE
12465
 
12466
task PCIU_READ;
12467
  input  [2:0] master_number;
12468
  input  [PCI_BUS_DATA_RANGE:0] address;
12469
  input  [3:0] command;
12470
  input  [PCI_BUS_DATA_RANGE:0] data;
12471
  input  [3:0] byte_en;
12472
  input  [9:0] size;
12473
  input  [7:0] master_wait_states;
12474
  input  [7:0] target_wait_states;
12475
  input  [1:0] target_devsel_speed;
12476
  input  [2:0] target_termination;
12477
  reg    [79:0] name;
12478
  begin
12479
    if (command == `BC_MEM_READ)
12480
        name = "MEM_READ  " ;
12481
    else if (command == `BC_MEM_READ_LN)
12482
        name = "MEM_RD_LN " ;
12483
    else if (command == `BC_MEM_READ_MUL )
12484
        name = "MEM_RD_MUL" ;
12485
    else
12486
        name = "WRONG_READ" ;
12487
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12488
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12489
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12490
              8'h0_0, target_wait_states[7:0],
12491
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12492
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12493
  end
12494
endtask // PCIU_READ
12495
 
12496
task PCIU_MEM_READ;
12497
  input  [79:0] name;
12498
  input  [2:0] master_number;
12499
  input  [PCI_BUS_DATA_RANGE:0] address;
12500
  input  [PCI_BUS_DATA_RANGE:0] data;
12501
  input  [9:0] size;
12502
  input  [7:0] master_wait_states;
12503
  input  [7:0] target_wait_states;
12504
  input  [1:0] target_devsel_speed;
12505
  input  [2:0] target_termination;
12506
  begin
12507
 
12508
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12509
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12510
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12511
              8'h0_0, target_wait_states[7:0],
12512
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12513
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12514
  end
12515
endtask // PCIU_MEM_READ
12516
 
12517
task PCIU_IO_READ;
12518
  input  [2:0] master_number;
12519
  input  [PCI_BUS_DATA_RANGE:0] address;
12520
  input  [PCI_BUS_DATA_RANGE:0] data;
12521
  input  [3:0] byte_en ;
12522
  input  [9:0] size;
12523
  input  [2:0] target_termination ;
12524
  begin
12525
 
12526
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12527
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12528
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12529
              8'h0_0, `Test_One_Zero_Target_WS,
12530
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12531
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12532
  end
12533
endtask // PCIU_IO_READ
12534
 
12535
task PCIU_IO_READ_MAKE_PERR;
12536
  input  [2:0] master_number;
12537
  input  [PCI_BUS_DATA_RANGE:0] address;
12538
  input  [PCI_BUS_DATA_RANGE:0] data;
12539
  input  [3:0] byte_en ;
12540
  input  [9:0] size;
12541
  input  [2:0] target_termination ;
12542
  begin
12543
 
12544
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12545
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12546
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12547
              8'h0_0, `Test_One_Zero_Target_WS,
12548
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12549
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12550
  end
12551
endtask // PCIU_IO_READ_MAKE_PERR
12552
 
12553
task PCIU_MEM_READ_LN;
12554
  input  [79:0] name;
12555
  input  [2:0] master_number;
12556
  input  [PCI_BUS_DATA_RANGE:0] address;
12557
  input  [PCI_BUS_DATA_RANGE:0] data;
12558
  input  [9:0] size;
12559
  input  [7:0] master_wait_states;
12560
  input  [7:0] target_wait_states;
12561
  input  [1:0] target_devsel_speed;
12562
  input  [2:0] target_termination;
12563
  begin
12564
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12565
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12566
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12567
              8'h0_0, target_wait_states[7:0],
12568
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12569
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12570
  end
12571
endtask // PCIU_MEM_READ_LN
12572
 
12573
task PCIU_MEM_READ_MUL;
12574
  input  [79:0] name;
12575
  input  [2:0] master_number;
12576
  input  [PCI_BUS_DATA_RANGE:0] address;
12577
  input  [PCI_BUS_DATA_RANGE:0] data;
12578
  input  [9:0] size;
12579
  input  [7:0] master_wait_states;
12580
  input  [7:0] target_wait_states;
12581
  input  [1:0] target_devsel_speed;
12582
  input  [2:0] target_termination;
12583
  begin
12584
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12585
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12586
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12587
              8'h0_0, target_wait_states[7:0],
12588
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12589
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12590
  end
12591
endtask // PCIU_MEM_READ_MUL
12592
 
12593
task PCIU_MEM_READ_MAKE_PERR;
12594
  input  [79:0] name;
12595
  input  [2:0] master_number;
12596
  input  [PCI_BUS_DATA_RANGE:0] address;
12597
  input  [PCI_BUS_DATA_RANGE:0] data;
12598
  input  [9:0] size;
12599
  input  [7:0] master_wait_states;
12600
  input  [7:0] target_wait_states;
12601
  input  [1:0] target_devsel_speed;
12602
  input  [2:0] target_termination;
12603
  begin
12604
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12605
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12606
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12607
              8'h0_0, target_wait_states[7:0],
12608
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12609
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12610
  end
12611
endtask // PCIU_MEM_READ_MAKE_PERR
12612
 
12613
task PCIU_MEM_WRITE;
12614
  input  [79:0] name;
12615
  input  [2:0] master_number;
12616
  input  [PCI_BUS_DATA_RANGE:0] address;
12617
  input  [PCI_BUS_DATA_RANGE:0] data;
12618
  input  [3:0] byte_en;
12619
  input  [9:0] size;
12620
  input  [7:0] master_wait_states;
12621
  input  [7:0] target_wait_states;
12622
  input  [1:0] target_devsel_speed;
12623
  input  [2:0] target_termination;
12624
  begin
12625
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12626
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12627
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12628
              8'h0_0, target_wait_states[7:0],
12629
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12630
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12631
  end
12632
endtask // PCIU_MEM_WRITE
12633
 
12634
task PCIU_IO_WRITE;
12635
  input  [2:0] master_number;
12636
  input  [PCI_BUS_DATA_RANGE:0] address;
12637
  input  [PCI_BUS_DATA_RANGE:0] data;
12638
  input  [3:0] byte_en;
12639
  input  [9:0] size;
12640
  input  [2:0] target_termination ;
12641
  begin
12642
 
12643
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12644
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12645
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12646
              8'h0_0, `Test_One_Zero_Target_WS,
12647
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12648
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12649
  end
12650
endtask // PCIU_IO_WRITE
12651
 
12652
task PCIU_IO_WRITE_MAKE_PERR ;
12653
  input  [2:0] master_number;
12654
  input  [PCI_BUS_DATA_RANGE:0] address;
12655
  input  [PCI_BUS_DATA_RANGE:0] data;
12656
  input  [3:0] byte_en;
12657
  input  [9:0] size;
12658
  input  [2:0] target_termination ;
12659
  begin
12660
 
12661
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12662
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12663
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12664
              8'h0_0, `Test_One_Zero_Target_WS,
12665
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12666
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12667
  end
12668
endtask // PCIU_IO_WRITE
12669
 
12670
task PCIU_MEM_WRITE_MAKE_SERR;
12671
  input  [79:0] name;
12672
  input  [2:0] master_number;
12673
  input  [PCI_BUS_DATA_RANGE:0] address;
12674
  input  [PCI_BUS_DATA_RANGE:0] data;
12675
  input  [9:0] size;
12676
  input  [7:0] master_wait_states;
12677
  input  [7:0] target_wait_states;
12678
  input  [1:0] target_devsel_speed;
12679
  input  [2:0] target_termination;
12680
  begin
12681
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12682
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12683
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12684
              8'h0_0, target_wait_states[7:0],
12685
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12686
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12687
  end
12688
endtask // PCIU_MEM_WRITE_MAKE_SERR
12689
 
12690
task PCIU_MEM_WRITE_MAKE_PERR;
12691
  input  [79:0] name;
12692
  input  [2:0] master_number;
12693
  input  [PCI_BUS_DATA_RANGE:0] address;
12694
  input  [PCI_BUS_DATA_RANGE:0] data;
12695
  input  [9:0] size;
12696
  input  [7:0] master_wait_states;
12697
  input  [7:0] target_wait_states;
12698
  input  [1:0] target_devsel_speed;
12699
  input  [2:0] target_termination;
12700
  begin
12701
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12702
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12703
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12704
              8'h0_0, target_wait_states[7:0],
12705
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12706
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12707
  end
12708
endtask // PCIU_MEM_WRITE
12709
 
12710
/*--------------------------------------------------------------------------
12711
Initialization CASES
12712
--------------------------------------------------------------------------*/
12713
 
12714
// Initialize the basic Config Registers of the PCI bridge target device
12715
task configure_bridge_target;
12716
    reg [11:0] offset ;
12717
    reg [31:0] data ;
12718
    `ifdef HOST
12719
    reg `WRITE_STIM_TYPE   write_data ;
12720
    reg `WB_TRANSFER_FLAGS write_flags ;
12721
    reg `WRITE_RETURN_TYPE write_status ;
12722
    `else
12723
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12724
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12725
    `endif
12726
 
12727
    reg [31:0] temp_var ;
12728
begin
12729
`ifdef HOST //  set Header
12730
    offset  = 12'h4 ; // PCI Header Command register
12731
    data    = 32'h0000_0007 ; // enable master & target operation
12732
 
12733
    write_flags                      = 0 ;
12734 92 mihad
    write_flags`INIT_WAITS           = wb_init_waits ;
12735
    write_flags`SUBSEQ_WAITS         = wb_subseq_waits ;
12736 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12737
 
12738
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12739
    write_data`WRITE_SEL      = 4'h1 ;
12740
    write_data`WRITE_DATA     = data ;
12741
 
12742
    next_test_name[79:0] <= "Init_Tar_R";
12743
 
12744
    $display(" bridge target - Enabling master and target operation!");
12745
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12746
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12747
    begin
12748
        $display("Write to configuration space failed! Time %t ", $time) ;
12749
    end
12750
 
12751
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12752
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12753
 
12754
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12755
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12756
 
12757
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12758
    write_data`WRITE_SEL      = 4'hf ;
12759
    write_data`WRITE_DATA     = data ;
12760
 
12761
 `ifdef  NO_CNF_IMAGE
12762
  `ifdef PCI_IMAGE0 //      set P_BA0
12763
 
12764
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12765
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12766
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12767
    begin
12768
        $display("Write to configuration space failed! Time %t ", $time) ;
12769
    end
12770
  `endif
12771
 `else //      set P_BA0
12772
 
12773
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12774
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12775
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12776
    begin
12777
        $display("Write to configuration space failed! Time %t ", $time) ;
12778
    end
12779
 `endif
12780
 
12781
`else // GUEST, set Header, set P_BA0
12782
    data            = 32'h0000_0007 ; // enable master & target operation
12783
    byte_enables    = 4'hF ;
12784
    $display(" bridge target - Enabling master and target operation!");
12785 45 mihad
    configuration_cycle_write(0,                        // bus number
12786
                              `TAR0_IDSEL_INDEX - 11,   // device number
12787
                              0,                        // function number
12788
                              1,                        // register number
12789
                              0,                        // type of configuration cycle
12790
                              byte_enables,             // byte enables
12791
                              data                      // data
12792 15 mihad
                             ) ;
12793
 
12794
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12795
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12796
    byte_enables = 4'hf ;
12797 45 mihad
    configuration_cycle_write(0,                        // bus number
12798
                              `TAR0_IDSEL_INDEX - 11,   // device number
12799
                              0,                        // function number
12800
                              4,                        // register number
12801
                              0,                        // type of configuration cycle
12802
                              byte_enables,             // byte enables
12803
                              data                      // data
12804 15 mihad
                             ) ;
12805
 
12806
`endif
12807
end
12808
endtask // configure_bridge_target
12809
 
12810
// Initialize the basic Config Registers of the PCI bridge target device
12811
task configure_bridge_target_base_addresses;
12812
    reg [11:0] offset ;
12813
    reg [31:0] data ;
12814
    `ifdef HOST
12815
    reg `WRITE_STIM_TYPE   write_data ;
12816
    reg `WB_TRANSFER_FLAGS write_flags ;
12817
    reg `WRITE_RETURN_TYPE write_status ;
12818
    `else
12819
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12820
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12821
    `endif
12822
 
12823
    reg [31:0] temp_var ;
12824
begin
12825
`ifdef HOST //  set Header
12826
    offset  = 12'h4 ; // PCI Header Command register
12827
    data    = 32'h0000_0007 ; // enable master & target operation
12828
 
12829
    write_flags                    = 0 ;
12830 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
12831
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
12832 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12833
 
12834
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12835
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12836
 
12837
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12838
    write_data`WRITE_SEL      = 4'h1 ;
12839
    write_data`WRITE_DATA     = data ;
12840
 
12841
    next_test_name[79:0] <= "Init_Tar_R";
12842
 
12843
    $display(" bridge target - Enabling master and target operation!");
12844
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12845
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12846
    begin
12847
        $display("Write to configuration space failed! Time %t ", $time) ;
12848
    end
12849
 
12850
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12851
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12852
 
12853
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12854
    write_data`WRITE_SEL      = 4'hf ;
12855
    write_data`WRITE_DATA     = data ;
12856
 
12857
 `ifdef  NO_CNF_IMAGE
12858
  `ifdef PCI_IMAGE0 //      set P_BA0
12859
 
12860
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12861
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12862
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12863
    begin
12864
        $display("Write to configuration space failed! Time %t ", $time) ;
12865
    end
12866
  `endif
12867
 `else //      set P_BA0
12868
 
12869
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12870
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12871
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12872
    begin
12873
        $display("Write to configuration space failed! Time %t ", $time) ;
12874
    end
12875
 `endif
12876
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12877
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12878
 
12879
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12880
    write_data`WRITE_SEL      = 4'hf ;
12881
    write_data`WRITE_DATA     = data ;
12882
 
12883
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12884
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12885
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12886
    begin
12887
        $display("Write to configuration space failed! Time %t ", $time) ;
12888
    end
12889
 `ifdef PCI_IMAGE2
12890
 
12891
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12892
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12893
 
12894
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12895
    write_data`WRITE_SEL      = 4'hf ;
12896
    write_data`WRITE_DATA     = data ;
12897
 
12898
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12899
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12900
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12901
    begin
12902
        $display("Write to configuration space failed! Time %t ", $time) ;
12903
    end
12904
 `endif
12905
 `ifdef PCI_IMAGE3
12906
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12907
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12908
 
12909
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12910
    write_data`WRITE_SEL      = 4'hf ;
12911
    write_data`WRITE_DATA     = data ;
12912
 
12913
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12914
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12915
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12916
    begin
12917
        $display("Write to configuration space failed! Time %t ", $time) ;
12918
    end
12919
 `endif
12920
 `ifdef PCI_IMAGE4
12921
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12922
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12923
 
12924
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12925
    write_data`WRITE_SEL      = 4'hf ;
12926
    write_data`WRITE_DATA     = data ;
12927
 
12928
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12929
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12930
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12931
    begin
12932
        $display("Write to configuration space failed! Time %t ", $time) ;
12933
    end
12934
 `endif
12935
 `ifdef PCI_IMAGE5
12936
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12937
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12938
 
12939
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12940
    write_data`WRITE_SEL      = 4'hf ;
12941
    write_data`WRITE_DATA     = data ;
12942
 
12943
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12944
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12945
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12946
    begin
12947
        $display("Write to configuration space failed! Time %t ", $time) ;
12948
    end
12949
 `endif
12950
 
12951
`else // GUEST, set Header, set P_BA0
12952
    data            = 32'h0000_0007 ; // enable master & target operation
12953
    byte_enables    = 4'hF ;
12954
    $display(" bridge target - Enabling master and target operation!");
12955 45 mihad
    configuration_cycle_write(0,                        // bus number
12956
                              `TAR0_IDSEL_INDEX - 11,   // device number
12957
                              0,                        // function number
12958
                              1,                        // register number
12959
                              0,                        // type of configuration cycle
12960
                              byte_enables,             // byte enables
12961
                              data                      // data
12962 15 mihad
                             ) ;
12963
 
12964
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12965
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12966
    byte_enables = 4'hf ;
12967 45 mihad
    configuration_cycle_write(0,                        // bus number
12968
                              `TAR0_IDSEL_INDEX - 11,   // device number
12969
                              0,                        // function number
12970
                              4,                        // register number
12971
                              0,                        // type of configuration cycle
12972
                              byte_enables,             // byte enables
12973
                              data                      // data
12974 15 mihad
                             ) ;
12975
 
12976
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12977
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12978
    byte_enables = 4'hf ;
12979 45 mihad
    configuration_cycle_write(0,                        // bus number
12980
                              `TAR0_IDSEL_INDEX - 11,   // device number
12981
                              0,                        // function number
12982
                              5,                        // register number
12983
                              0,                        // type of configuration cycle
12984
                              byte_enables,             // byte enables
12985
                              data                      // data
12986 15 mihad
                             ) ;
12987
 `ifdef PCI_IMAGE2
12988
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12989
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12990
    byte_enables = 4'hf ;
12991 45 mihad
    configuration_cycle_write(0,                        // bus number
12992
                              `TAR0_IDSEL_INDEX - 11,   // device number
12993
                              0,                        // function number
12994
                              6,                        // register number
12995
                              0,                        // type of configuration cycle
12996
                              byte_enables,             // byte enables
12997
                              data                      // data
12998 15 mihad
                             ) ;
12999
 `endif
13000
 `ifdef PCI_IMAGE3
13001
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
13002
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
13003
    byte_enables = 4'hf ;
13004 45 mihad
    configuration_cycle_write(0,                        // bus number
13005
                              `TAR0_IDSEL_INDEX - 11,   // device number
13006
                              0,                        // function number
13007
                              7,                        // register number
13008
                              0,                        // type of configuration cycle
13009
                              byte_enables,             // byte enables
13010
                              data                      // data
13011 15 mihad
                             ) ;
13012
 `endif
13013
 `ifdef PCI_IMAGE4
13014
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
13015
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
13016
    byte_enables = 4'hf ;
13017 45 mihad
    configuration_cycle_write(0,                        // bus number
13018
                              `TAR0_IDSEL_INDEX - 11,   // device number
13019
                              0,                        // function number
13020
                              8,                        // register number
13021
                              0,                        // type of configuration cycle
13022
                              byte_enables,             // byte enables
13023
                              data                      // data
13024 15 mihad
                             ) ;
13025
 `endif
13026
 `ifdef PCI_IMAGE5
13027
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
13028
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
13029
    byte_enables = 4'hf ;
13030 45 mihad
    configuration_cycle_write(0,                        // bus number
13031
                              `TAR0_IDSEL_INDEX - 11,   // device number
13032
                              0,                        // function number
13033
                              9,                        // register number
13034
                              0,                        // type of configuration cycle
13035
                              byte_enables,             // byte enables
13036
                              data                      // data
13037 15 mihad
                             ) ;
13038
 `endif
13039
`endif
13040
end
13041
endtask // configure_bridge_target_base_addresses
13042
 
13043
/*--------------------------------------------------------------------------
13044
Test CASES
13045
--------------------------------------------------------------------------*/
13046
 
13047
// function converts PCI address to WB with the same data as the pci_decoder does
13048
function [31:0] pci_to_wb_addr_convert ;
13049
 
13050
    input [31:0] pci_address ;
13051
    input [31:0] translation_address ;
13052
    input [31:0] translate ;
13053
 
13054
    reg   [31:0] temp_address ;
13055
begin
13056
    if ( translate !== 1 )
13057
    begin
13058
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
13059
    end
13060
    else
13061
    begin
13062
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
13063
    end
13064
 
13065
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
13066
    pci_to_wb_addr_convert = temp_address ;
13067
end
13068
endfunction // pci_to_wb_addr_convert
13069
 
13070
// Test normal write and read to WB slave
13071
task test_normal_wr_rd;
13072
  input  [2:0]  Master_ID;
13073
  input  [PCI_BUS_DATA_RANGE:0] Address;
13074
  input  [PCI_BUS_DATA_RANGE:0] Data;
13075
  input  [3:0]  Be;
13076
  input  [2:0]  Image_num;
13077
  input  [9:0]  Set_size;
13078
  input         Set_addr_translation;
13079
  input         Set_prefetch_enable;
13080
  input  [7:0]  Cache_lsize;
13081
  input         Set_wb_wait_states;
13082
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
13083
 
13084
  reg    [31:0] rd_address;
13085
  reg    [31:0] rd_data;
13086
  reg    [3:0]  rd_be;
13087
  reg    [11:0] addr_offset;
13088
  reg    [31:0] read_data;
13089
  reg           continue ;
13090
  reg           ok   ;
13091
  reg    [31:0] expect_address ;
13092
  reg    [31:0] expect_rd_address ;
13093
  reg           expect_we ;
13094
  reg    [9:0]  expect_length_wr ;
13095
  reg    [9:0]  expect_length_rd ;
13096
  reg    [9:0]  expect_length_rd1 ;
13097
  reg    [9:0]  expect_length_rd2 ;
13098
  reg    [3:0]  use_rd_cmd ;
13099
  integer       i ;
13100 35 mihad
  reg           error_monitor_done ;
13101 15 mihad
begin:main
13102
 
13103
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
13104
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13105
    $display(" - errors will be reported, but they should not occur!");
13106
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
13107
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13108
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
13109
    if ( ok !== 1 )
13110
    begin
13111
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13112
        test_fail("write to P_ERR_CS register didn't succeede") ;
13113
        disable main;
13114
    end
13115
 
13116
    `ifdef  ADDR_TRAN_IMPL
13117
 
13118
    // set or clear address translation
13119
    if (Set_addr_translation)
13120
    begin
13121
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
13122
        $display(" - address translation will be performed!");
13123
    end
13124
    else
13125
    begin
13126
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
13127
        $display(" - address translation will not be performed!");
13128
    end
13129
    // set or clear pre-fetch enable
13130
    if (Set_prefetch_enable)
13131
    begin
13132
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
13133
        $display(" - bursts can be performed!");
13134
    end
13135
    else
13136
    begin
13137
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
13138
        $display(" - bursts can not be performed!");
13139
    end
13140
 
13141
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13142
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
13143
    if ( ok !== 1 )
13144
    begin
13145
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
13146
        test_fail("write to P_IMG_CTRL didn't succeede") ;
13147
        disable main;
13148
    end
13149
 
13150
    // predict the address and control signals on WB bus
13151
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
13152
    expect_we      = 1'b1 ; // WRITE
13153
 
13154
    `else
13155
 
13156
    // address translation is not implemented
13157
    $display("Address translation is NOT implemented for PCI images!");
13158
    // set or clear pre-fetch enable
13159
    if (Set_prefetch_enable)
13160
    begin
13161
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
13162
        $display(" - bursts can be performed!");
13163
    end
13164
    else
13165
    begin
13166
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
13167
        $display(" - bursts can not be performed!");
13168
    end
13169
 
13170
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13171
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
13172
    if ( ok !== 1 )
13173
    begin
13174
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
13175
        test_fail("write to P_IMG_CTRL didn't succeede") ;
13176
        disable main;
13177
    end
13178
 
13179
    // predict the address and control signals on WB bus
13180
    expect_address = Address ;
13181
    expect_we      = 1'b1 ; // WRITE
13182
 
13183
    `endif
13184
 
13185
    // set WB SLAVE parameters
13186
    if (Set_wb_wait_states)
13187
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
13188
    else
13189
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
13190
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13191 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
13192 15 mihad
 
13193
    if ( Set_size > (`PCIW_DEPTH - 2) )
13194
    begin
13195
        expect_length_wr = `PCIW_DEPTH - 2 ;
13196
    end
13197
    else
13198
    begin
13199
        expect_length_wr = Set_size ;
13200
    end
13201
    // write through the PCI bridge to WB slave
13202
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
13203
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
13204
 
13205
    fork
13206
    begin
13207
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13208
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13209
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13210
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13211
        do_pause( 1 ) ;
13212
    end
13213
    begin
13214
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
13215
       if ( ok !== 1 )
13216
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13217
       else
13218
           test_ok ;
13219
    end
13220
    join
13221
 
13222
    // predict the address and control signals on WB bus
13223
    expect_we      = 1'b0 ; // READ
13224
 
13225
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
13226
    $display("Memory read through PCI bridge to WB slave!");
13227
 
13228
    if ( expect_length_wr == 1 )
13229
    begin
13230
        if (Set_prefetch_enable)
13231
        begin
13232
            expect_length_rd1 = Cache_lsize ;
13233
            expect_length_rd2 = 0 ;
13234
                // If PCI behavioral master must check received DATA
13235
                master2_check_received_data = 0 ;
13236
                    master1_check_received_data = 0 ;
13237
        end
13238
        else
13239
        begin
13240
            expect_length_rd1 = 1 ;
13241
            expect_length_rd2 = 0 ;
13242
                // If PCI behavioral master must check received DATA
13243
                master2_check_received_data = 1 ;
13244
                    master1_check_received_data = 1 ;
13245
        end
13246
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13247
        expect_length_rd  = expect_length_rd1 ;
13248
    end
13249
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
13250
    begin
13251
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
13252
        expect_length_rd2 = 0 ;
13253
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13254
        expect_length_rd  = expect_length_rd1 ;
13255
                // If PCI behavioral master must check received DATA
13256
        master2_check_received_data = 1 ;
13257
            master1_check_received_data = 1 ;
13258
    end
13259
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
13260
    begin
13261
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
13262
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
13263
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13264
        expect_length_rd  = expect_length_rd1 ;
13265
                // If PCI behavioral master must check received DATA
13266
                master2_check_received_data = 1 ;
13267
            master1_check_received_data = 1 ;
13268
    end
13269
    else
13270
    begin
13271
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
13272
        begin
13273
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
13274
            expect_length_rd2 = 0 ;
13275
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13276
            expect_length_rd  = expect_length_rd1 ;
13277
                // If PCI behavioral master must check received DATA
13278
                master2_check_received_data = 0 ;
13279
                    master1_check_received_data = 0 ;
13280
        end
13281
        else
13282
        begin
13283
            if ( expect_length_wr > Cache_lsize )
13284
            begin
13285
                expect_length_rd1 = Cache_lsize ;
13286
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
13287
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
13288
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
13289
                else
13290
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13291
                expect_length_rd  = expect_length_rd1 ;
13292
                        // If PCI behavioral master must check received DATA
13293
                        master2_check_received_data = 1 ;
13294
                            master1_check_received_data = 1 ;
13295
            end
13296
            else
13297
            begin
13298
                expect_length_rd1 = Cache_lsize ;
13299
                expect_length_rd2 = 0 ;
13300
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
13301
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
13302
                else
13303
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13304
                expect_length_rd  = expect_length_wr ;
13305
                                if ( expect_length_wr == Cache_lsize )
13306
                        begin
13307
                                // If PCI behavioral master must check received DATA
13308
                                master2_check_received_data = 1 ;
13309
                                    master1_check_received_data = 1 ;
13310
                                end
13311
                                else
13312
                                begin
13313
                                // If PCI behavioral master must check received DATA
13314
                                master2_check_received_data = 0 ;
13315
                                    master1_check_received_data = 0 ;
13316
                end
13317
            end
13318
        end
13319
    end
13320
 
13321
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
13322
    expect_rd_address = expect_address ;
13323
    rd_data[31:0] = Data[31:0];
13324
    rd_be[3:0] = Be[3:0];
13325
 
13326
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
13327
    while (expect_length_rd2 > 0)
13328
    begin
13329
        // do read
13330
        $display("Read %d words!", expect_length_rd);
13331
 
13332
        fork
13333
        begin
13334
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13335
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13336
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13337
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
13338
 
13339
            wb_transaction_stop( expect_length_rd - 1) ;
13340
 
13341
            do_pause( 1 ) ;
13342
        end
13343
        begin
13344
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
13345
            if ( ok !== 1 )
13346
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
13347
 
13348
            repeat( 3 )
13349
                @(posedge pci_clock) ;
13350
 
13351
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13352
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13353
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13354
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13355
 
13356
            do_pause( 1 ) ;
13357
            while ( FRAME === 0 )
13358
                @(posedge pci_clock) ;
13359
 
13360
            while ( IRDY === 0 )
13361
                @(posedge pci_clock) ;
13362
 
13363 35 mihad
            #1 ;
13364
            if ( !error_monitor_done )
13365
                disable monitor_error_event1 ;
13366 15 mihad
        end
13367
        begin:monitor_error_event1
13368 35 mihad
            error_monitor_done = 0 ;
13369 15 mihad
            @(error_event_int) ;
13370
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13371
            ok = 0 ;
13372 35 mihad
            error_monitor_done = 1 ;
13373 15 mihad
        end
13374
        join
13375
 
13376
        // increasing the starting address for PCI master and for WB transaction monitor
13377
        rd_address = rd_address + (4 * expect_length_rd) ;
13378
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
13379
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
13380
        rd_data[31:24] = Data[31:24] + expect_length_rd;
13381
        rd_data[23:16] = Data[23:16] + expect_length_rd;
13382
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
13383
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
13384
        for (i=0; i<expect_length_rd; i=i+1)
13385
            rd_be[3:0] = {Be[2:0], Be[3]};
13386
 
13387
        // set parameters for next read
13388
        if ( expect_length_rd2 == 1 )
13389
        begin
13390
                if (Set_prefetch_enable)
13391
                begin
13392
                    expect_length_rd1 = Cache_lsize ;
13393
                    expect_length_rd2 = 0 ;
13394
                        // If PCI behavioral master must check received DATA
13395
                        master2_check_received_data = 0 ;
13396
                            master1_check_received_data = 0 ;
13397
                end
13398
                else
13399
                begin
13400
                    expect_length_rd1 = 1 ;
13401
                    expect_length_rd2 = 0 ;
13402
                        // If PCI behavioral master must check received DATA
13403
                        master2_check_received_data = 1 ;
13404
                            master1_check_received_data = 1 ;
13405
                end
13406
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13407
            expect_length_rd  = expect_length_rd1 ;
13408
        end
13409
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
13410
        begin
13411
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
13412
            expect_length_rd2 = 0 ;
13413
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13414
            expect_length_rd  = expect_length_rd1 ;
13415
                        // If PCI behavioral master must check received DATA
13416
                        master2_check_received_data = 1 ;
13417
                    master1_check_received_data = 1 ;
13418
        end
13419
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
13420
        begin
13421
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
13422
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
13423
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13424
            expect_length_rd  = expect_length_rd1 ;
13425
                        // If PCI behavioral master must check received DATA
13426
                        master2_check_received_data = 1 ;
13427
                    master1_check_received_data = 1 ;
13428
        end
13429
        else
13430
        begin
13431
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
13432
            begin
13433
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
13434
                expect_length_rd2 = 0 ;
13435
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13436
                expect_length_rd  = expect_length_rd1 ;
13437
                        // If PCI behavioral master must check received DATA
13438
                        master2_check_received_data = 0 ;
13439
                            master1_check_received_data = 0 ;
13440
            end
13441
            else
13442
            begin
13443
                if ( expect_length_rd2 > Cache_lsize )
13444
                begin
13445
                    expect_length_rd1 = Cache_lsize ;
13446
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
13447
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
13448
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
13449
                    else
13450
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13451
                    expect_length_rd  = expect_length_rd1 ;
13452
                                // If PCI behavioral master must check received DATA
13453
                                master2_check_received_data = 1 ;
13454
                                    master1_check_received_data = 1 ;
13455
                end
13456
                else
13457
                begin
13458
                    expect_length_rd  = expect_length_rd2 ;
13459
                    expect_length_rd1 = Cache_lsize ;
13460
                    expect_length_rd2 = 0 ;
13461
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
13462
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
13463
                    else
13464
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13465
                                        if ( expect_length_rd2 == Cache_lsize )
13466
                                begin
13467
                                        // If PCI behavioral master must check received DATA
13468
                                        master2_check_received_data = 1 ;
13469
                                            master1_check_received_data = 1 ;
13470
                                        end
13471
                                        else
13472
                                        begin
13473
                                        // If PCI behavioral master must check received DATA
13474
                                        master2_check_received_data = 0 ;
13475
                                            master1_check_received_data = 0 ;
13476
                        end
13477
                end
13478
            end
13479
        end
13480
    end
13481
    // do last read
13482
    $display("Read %d words!", expect_length_rd);
13483
 
13484
    fork
13485
    begin
13486
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13487
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13488
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13489
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
13490
 
13491
        wb_transaction_stop(expect_length_rd - 1) ;
13492
        do_pause( 1 ) ;
13493
    end
13494
    begin
13495
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
13496
 
13497
        do_pause(3) ;
13498
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13499
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13500
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13501
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13502
        do_pause(1) ;
13503
 
13504
        while ( FRAME === 0 )
13505
            @(posedge pci_clock) ;
13506
 
13507
        while ( IRDY === 0 )
13508
            @(posedge pci_clock) ;
13509
 
13510 35 mihad
        #1 ;
13511
        if ( !error_monitor_done )
13512
            disable monitor_error_event2 ;
13513 15 mihad
    end
13514
    begin:monitor_error_event2
13515 35 mihad
        error_monitor_done = 0 ;
13516 15 mihad
        @(error_event_int) ;
13517
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13518
        ok = 0 ;
13519 35 mihad
        error_monitor_done = 1 ;
13520 15 mihad
    end
13521
    join
13522
 
13523
    if ( ok )
13524
        test_ok ;
13525
 
13526
    // Check that no ERRORs were reported
13527
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
13528
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
13529
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13530
    config_read( addr_offset, 4'hF, read_data ) ;
13531
    if ( read_data[8] !== 0 )
13532
    begin
13533
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
13534
        test_fail("error status was set even though no errors occured on WB bus") ;
13535
    end
13536
    else
13537
    begin
13538
        $display("No error was signaled, as expected!");
13539
        test_ok ;
13540
    end
13541
 
13542
end // main
13543
endtask // test_normal_wr_rd
13544
 
13545
// Test erroneous write to WB slave
13546
task test_wb_error_wr;
13547
  input  [2:0]  Master_ID;
13548
  input  [PCI_BUS_DATA_RANGE:0] Address;
13549
  input  [PCI_BUS_DATA_RANGE:0] Data;
13550
  input  [3:0]  Be;
13551
  input  [2:0]  Image_num;
13552
  input  [9:0]  Set_size;
13553
  input         Set_err_and_int_report;
13554
  input         Set_wb_wait_states;
13555
  input  [1:0]  Imm_BefLast_Last_error;
13556
 
13557
  reg    [11:0] addr_offset;
13558
  reg    [31:0] read_data;
13559
  reg           continue ;
13560
  reg           ok   ;
13561
  reg    [9:0]  expect_length ;
13562
  reg    [31:0] expect_address ;
13563
  reg    [0:0]  expect_we ;
13564
  reg    [31:0] rd_address;
13565
  reg    [31:0] rd_data;
13566
  reg    [3:0]  rd_be;
13567
  integer       i ;
13568
begin:main
13569
    if (Set_err_and_int_report)
13570
    begin
13571
        // enable ERROR reporting, because error must be reported and interrupt if required!
13572
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13573
        $display(" - errors will be reported when they will occur!");
13574
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
13575
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13576
        $display(" - interrupt will be reported when error will occur!");
13577
    end
13578
    else
13579
    begin
13580
        // disable ERROR reporting, because error and interrupt must not be reported!
13581
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13582
        $display(" - errors will NOT be reported when they will occur!");
13583
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
13584
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13585
        $display(" - interrupt will NOT be reported when error will occur!");
13586
    end
13587
    // enable/disable ERROR reporting
13588
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
13589
 
13590
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13591
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
13592
    if ( ok !== 1 )
13593
    begin
13594
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13595
        test_fail("PCI Error Control and Status register could not be written") ;
13596
        disable main;
13597
    end
13598
    // enable/disable INTERRUPT reporting
13599
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13600
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
13601
    if ( ok !== 1 )
13602
    begin
13603
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
13604
        test_fail("Interrupt Control register could not be written") ;
13605
        disable main;
13606
    end
13607
 
13608
    `ifdef  ADDR_TRAN_IMPL
13609
 
13610
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
13611
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13612
    config_read( addr_offset, 4'hF, read_data ) ;
13613
    if ( read_data[2] !== 0 )
13614
    begin
13615
        $display("Address translation is set for PCI image%d!", Image_num);
13616
        // predict the address and control signals on WB bus
13617
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13618
        expect_we      = 1'b1 ; // WRITE
13619
    end
13620
    else
13621
    begin
13622
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13623
        // predict the address and control signals on WB bus
13624
        expect_address = Address ;
13625
        expect_we      = 1'b1 ; // WRITE
13626
    end
13627
 
13628
    `else
13629
 
13630
    // address translation is not implemented
13631
    $display("Address translation is NOT implemented for PCI images!");
13632
    // predict the address and control signals on WB bus
13633
    expect_address = Address ;
13634
    expect_we      = 1'b1 ; // WRITE
13635
 
13636
    `endif
13637
 
13638
    if ( Set_size > (`PCIW_DEPTH - 2) )
13639
    begin
13640
        expect_length = `PCIW_DEPTH - 2 ;
13641
    end
13642
    else
13643
    begin
13644
        expect_length = Set_size ;
13645
    end
13646
 
13647
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13648
    begin
13649
        $display("ERR termination with first data!");
13650
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13651
    end
13652
    else if (Imm_BefLast_Last_error == 1)
13653
    begin
13654
        $display("ERR termination before last data!");
13655
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13656
    end
13657
    else
13658
    begin
13659
        $display("ERR termination with last data!");
13660
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13661
    end
13662
 
13663
    // write through the PCI bridge to WB slave
13664
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13665
    fork
13666
    begin
13667
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13668
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13669
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13670
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13671
        do_pause( 1 ) ;
13672
    end
13673
    begin
13674
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13675
        begin
13676
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13677
            if ( ok !== 1 )
13678
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13679
        end
13680
        else if (Imm_BefLast_Last_error == 1)
13681
        begin
13682
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13683
            if ( ok !== 1 )
13684
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13685
        end
13686
        else
13687
        begin
13688
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13689
            if ( ok !== 1 )
13690
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13691
        end
13692
    end
13693
    begin
13694
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13695
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13696 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
13697 15 mihad
        else if (Imm_BefLast_Last_error == 1)
13698
        begin
13699
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13700 92 mihad
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
13701 15 mihad
            wb_transaction_stop(expect_length-2) ;
13702
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13703 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
13704 15 mihad
        end
13705
        else
13706
        begin
13707
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13708 92 mihad
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
13709 15 mihad
            wb_transaction_stop(expect_length-1) ;
13710
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13711 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
13712 15 mihad
        end
13713
    end
13714
    join
13715
 
13716
    if ( ok )
13717
        test_ok ;
13718
 
13719
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13720
    begin
13721
        rd_data[31:0] = Data[31:0];
13722
        rd_address[31:0] = expect_address;
13723
        rd_be[3:0] = Be[3:0];
13724
    end
13725
    else if (Imm_BefLast_Last_error == 1)
13726
    begin
13727
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13728
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13729
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13730
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13731
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13732
        rd_be[3:0] = Be[3:0];
13733
        for (i=0; i<(expect_length-2); i=i+1)
13734
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13735
    end
13736
    else
13737
    begin
13738
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13739
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13740
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13741
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13742
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13743
        rd_be[3:0] = Be[3:0];
13744
        for (i=0; i<(expect_length-1); i=i+1)
13745
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13746
    end
13747
 
13748
    master2_check_received_data = 0 ;
13749
    master1_check_received_data = 0 ;
13750
 
13751
    // Check if ERRORs were reported
13752
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13753
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13754
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13755
 
13756
    ok = 1 ;
13757
    config_read( addr_offset, 4'hF, read_data ) ;
13758
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13759
    begin
13760
        $display("Error was signaled and reported, as expected!");
13761
        if (read_data[31:28] === rd_be)
13762
            $display("Byte enables written into P_ERR_CS register are as expected!");
13763
        else
13764
        begin
13765
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13766
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13767
            ok = 0 ;
13768
        end
13769
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13770
            $display("Bus command written into P_ERR_CS register is as expected!");
13771
        else
13772
        begin
13773
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13774
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13775
            ok = 0 ;
13776
        end
13777
 
13778
        if ( ok )
13779
            test_ok ;
13780
 
13781
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13782
 
13783
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13784
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13785
        config_read( addr_offset, 4'hF, read_data ) ;
13786
        if (read_data === rd_data)
13787
        begin
13788
            $display("Data written into P_ERR_DATA register is as expected!");
13789
            test_ok ;
13790
        end
13791
        else
13792
        begin
13793
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13794
            test_fail("PCI Erroneous Data register value was wrong") ;
13795
        end
13796
 
13797
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13798
 
13799
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13800
 
13801
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13802
        config_read( addr_offset, 4'hF, read_data ) ;
13803
        if (read_data === rd_address)
13804
        begin
13805
            $display("Address written into P_ERR_ADDR register is as expected!");
13806
            test_ok ;
13807
        end
13808
        else
13809
        begin
13810
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13811
            test_fail("PCI Erroneous Address register value was wrong") ;
13812
        end
13813
    end
13814
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13815
    begin
13816
        $display("Error was signaled and not reported, as expected!");
13817
        test_ok ;
13818
    end
13819
    else
13820
    begin
13821
        $display("Error was signaled and reported, as NOT expected!");
13822
        test_fail("Error status bit was set event though error reporting was disabled") ;
13823
    end
13824
 
13825
    // Check if Interrupts were reported
13826
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13827
 
13828
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13829
    ok = 1 ;
13830
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13831
    config_read( addr_offset, 4'hF, read_data ) ;
13832
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13833
    begin
13834
        $display("Interrupts was signaled and reported, as expected!");
13835
    end
13836
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13837
    begin
13838
        $display("Interrupts was signaled and not reported, as expected!");
13839
    end
13840
    else
13841
    begin
13842
        $display("Interrupt was signaled and reported, as NOT expected!");
13843
        test_fail("PCI Error Interrupt status was set when not expected") ;
13844
        ok = 0 ;
13845
    end
13846
 
13847
    `ifdef HOST
13848
    repeat( 4 )
13849
        @(posedge wb_clock) ;
13850
 
13851
    if ( INT_O === Set_err_and_int_report )
13852
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13853
    else
13854
    begin
13855
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13856
        test_fail("Interrupt request didn't have expected value") ;
13857
        ok = 0 ;
13858
    end
13859
 
13860
    `else // GUEST
13861
    repeat( 4 )
13862
        @(posedge pci_clock) ;
13863
 
13864
    if ( INTA === !Set_err_and_int_report )
13865
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13866
    else
13867
    begin
13868
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13869
        test_fail("Interrupt request didn't have expected value") ;
13870
        ok = 0 ;
13871
    end
13872
 
13873
    `endif
13874
 
13875
    if ( ok )
13876
        test_ok ;
13877
 
13878
    if (Set_err_and_int_report)
13879
    begin
13880
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13881
        $display("Error and Interrupt must be cleared!");
13882
        // clear  ERROR reporting bit
13883
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13884
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13885
        if ( ok !== 1 )
13886
        begin
13887
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13888
            test_fail("PCI Error Control and Status register could not be written to") ;
13889
            disable main;
13890
        end
13891
 
13892
        // clear INTERRUPT reporting bit
13893
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13894
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13895
        if ( ok !== 1 )
13896
        begin
13897
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13898
            test_fail("Interrupt Status register could not be written to") ;
13899
            disable main;
13900
        end
13901
 
13902
        test_ok ;
13903
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13904
        `ifdef HOST
13905
 
13906
        repeat(4)
13907
            @(posedge wb_clock) ;
13908
        if ( INT_O === 1'b0 )
13909
        begin
13910
            $display("Interrupt pin INT_O was correctly cleared!");
13911
            test_ok ;
13912
        end
13913
        else
13914
        begin
13915
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13916
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13917
            disable main;
13918
        end
13919
 
13920
        `else // GUEST
13921
 
13922
        repeat(4)
13923
            @(posedge pci_clock) ;
13924
        if ( INTA === 1'b1 )
13925
        begin
13926
            $display("Interrupt pin INTA was correctly cleared!");
13927
            test_ok ;
13928
        end
13929
        else
13930
        begin
13931
            $display("Interrupt pin INTA was NOT correctly cleared!");
13932
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13933
            disable main;
13934
        end
13935
 
13936
        `endif
13937
 
13938
    end
13939
    else
13940
    begin
13941
        $display("Error and Interrupt don't need to be cleared!");
13942
    end
13943
end // main
13944
endtask // test_wb_error_wr
13945
 
13946
task test_wb_error_rd;
13947
    reg    [11:0] addr_offset ;
13948
    reg    [11:0] ctrl_offset ;
13949
    reg    [11:0] ba_offset ;
13950
    reg    [11:0] am_offset ;
13951
    reg    [11:0] ta_offset ;
13952
    reg    [31:0] read_data;
13953
    reg           ok   ;
13954
    reg    [9:0]  expect_length ;
13955
    reg    [31:0] expect_address ;
13956
    reg    [0:0]  expect_we ;
13957
    reg    [31:0] rd_address;
13958
    reg    [31:0] rd_data;
13959
    reg    [3:0]  rd_be;
13960
    integer       i ;
13961
    reg           do_mem_aborts ;
13962
    reg           do_io_aborts ;
13963 35 mihad
    reg           error_monitor_done ;
13964 15 mihad
begin:main
13965
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13966
 
13967
    if ( target_mem_image !== -1 )
13968
    begin
13969
        do_mem_aborts = 1 ;
13970
 
13971
        if (target_mem_image === 1)
13972
        begin
13973
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13974
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13975
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13976
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13977
        end
13978
        else if (target_mem_image === 2)
13979
        begin
13980
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13981
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13982
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13983
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13984
        end
13985
        else if (target_mem_image === 3)
13986
        begin
13987
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13988
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13989
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13990
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13991
        end
13992
        else if (target_mem_image === 4)
13993
        begin
13994
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13995
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13996
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13997
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13998
        end
13999
        else if (target_mem_image === 5)
14000
        begin
14001
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14002
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14003
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14004
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14005
        end
14006
    end
14007
    else
14008
        do_mem_aborts = 0 ;
14009
 
14010
    if ( do_mem_aborts )
14011
    begin
14012
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14013
 
14014
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14015
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14016
        if ( ok !== 1 )
14017
        begin
14018
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14019
            test_fail("PCI Error Control and Status register could not be written") ;
14020
            disable main;
14021
        end
14022
 
14023
        // enable INTERRUPT reporting
14024
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14025
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14026
        if ( ok !== 1 )
14027
        begin
14028
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14029
            test_fail("Interrupt Control register could not be written") ;
14030
            disable main;
14031
        end
14032
 
14033
        addr_offset = 12'h010 + (4*target_mem_image) ;
14034
 
14035
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
14036
        if ( ok !== 1 )
14037
        begin
14038
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14039
            test_fail("PCI Base Address register could not be written") ;
14040
            disable main;
14041
        end
14042
 
14043
        // disable address translation and enable prefetch so read bursts can be performed
14044
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14045
        if ( ok !== 1 )
14046
        begin
14047
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14048
            test_fail("PCI Image Control register could not be written") ;
14049
            disable main;
14050
        end
14051
 
14052
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14053
        if ( ok !== 1 )
14054
        begin
14055
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14056
            test_fail("PCI Address Mask register could not be written") ;
14057
            disable main;
14058
        end
14059
 
14060
        addr_offset = 12'h00C ;
14061
 
14062
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14063
        if ( ok !== 1 )
14064
        begin
14065
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14066
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14067
            disable main;
14068
        end
14069
 
14070
        // disable PCI master data checking
14071
        master1_check_received_data = 0 ;
14072
 
14073
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14074 92 mihad
        wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14075 15 mihad
 
14076
 
14077
        // do a single read error terminated on WB bus
14078
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14079
 
14080
        fork
14081
        begin
14082
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14083
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
14084
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14085
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
14086
 
14087
            do_pause( 1 ) ;
14088
        end
14089
        begin
14090
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
14091
 
14092
            if ( ok !== 1 )
14093
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14094
 
14095
            do_pause(3) ;
14096
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14097
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
14098
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14099
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14100
            do_pause(1) ;
14101
 
14102
            while ( FRAME === 0 )
14103
                @(posedge pci_clock) ;
14104
 
14105
            while ( IRDY === 0 )
14106
                @(posedge pci_clock) ;
14107
 
14108 35 mihad
            #1 ;
14109
            if ( !error_monitor_done )
14110
                disable monitor_error_event1 ;
14111 15 mihad
        end
14112
        begin:monitor_error_event1
14113 35 mihad
            error_monitor_done = 0 ;
14114 15 mihad
            @(error_event_int) ;
14115
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14116
            ok = 0 ;
14117 35 mihad
            error_monitor_done = 1 ;
14118 15 mihad
        end
14119
        join
14120
 
14121
        if ( ok )
14122
            test_ok ;
14123 26 mihad
 
14124
        @(posedge pci_clock) ;
14125
        @(posedge pci_clock) ;
14126
        @(posedge wb_clock) ;
14127
        @(posedge wb_clock) ;
14128 15 mihad
 
14129
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14130
        addr_offset = 12'h004 ;
14131
        config_read(addr_offset, 4'hF, read_data) ;
14132
        ok = 1 ;
14133
        if ( read_data[27] !== 1 )
14134
        begin
14135
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14136
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14137
            ok = 0 ;
14138
        end
14139
        if ( read_data[28] !== 0 )
14140
        begin
14141
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14142
            test_fail("Received Target Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14143
            ok = 0 ;
14144
        end
14145
        if ( read_data[29] !== 0 )
14146
        begin
14147
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14148
            test_fail("Received Master Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14149
            ok = 0 ;
14150
        end
14151
 
14152
        // clear statuses
14153
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14154
        if ( !ok )
14155
        begin
14156
            test_fail("write to PCI Device Status register failed") ;
14157
            $display("Couldn't write PCI Device Status register") ;
14158
            disable main ;
14159
        end
14160
 
14161
        if ( ok )
14162
            test_ok ;
14163
 
14164
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14165
 
14166
        ok = 1 ;
14167
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14168
 
14169
        config_read(addr_offset, 4'hF, read_data) ;
14170
        if (read_data[8] !== 0)
14171
        begin
14172
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14173
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14174
            ok = 0 ;
14175
        end
14176
        else
14177
            test_ok ;
14178
 
14179
        if ( ok !== 1 )
14180
        begin
14181
            config_write(addr_offset, read_data, 4'hF, ok) ;
14182
            if ( !ok )
14183
            begin
14184
                test_fail("PCI Error Control and Status register could not be written") ;
14185
                disable main ;
14186
            end
14187
        end
14188
 
14189 92 mihad
        wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14190 15 mihad
        fork
14191
        begin
14192
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14193
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
14194
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14195
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14196
 
14197
            do_pause( 1 ) ;
14198
        end
14199
        begin
14200
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
14201
 
14202
            if ( ok !== 1 )
14203
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14204
 
14205
            do_pause(3) ;
14206
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14207
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
14208
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14209
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14210
            do_pause(1) ;
14211
 
14212
            while ( FRAME === 0 )
14213
                @(posedge pci_clock) ;
14214
 
14215
            while ( IRDY === 0 )
14216
                @(posedge pci_clock) ;
14217
 
14218 35 mihad
            #1 ;
14219
            if ( !error_monitor_done )
14220
                disable monitor_error_event2 ;
14221 15 mihad
        end
14222
        begin:monitor_error_event2
14223 35 mihad
            error_monitor_done = 0 ;
14224 15 mihad
            @(error_event_int) ;
14225
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14226
            ok = 0 ;
14227 35 mihad
            error_monitor_done = 1 ;
14228 15 mihad
        end
14229
        join
14230
 
14231
        if ( ok )
14232
            test_ok ;
14233
 
14234 26 mihad
        @(posedge pci_clock) ;
14235
        @(posedge pci_clock) ;
14236
        @(posedge wb_clock) ;
14237
        @(posedge wb_clock) ;
14238
 
14239 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14240
        addr_offset = 12'h004 ;
14241
        config_read(addr_offset, 4'hF, read_data) ;
14242
        ok = 1 ;
14243
        if ( read_data[27] !== 1 )
14244
        begin
14245
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14246
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14247
            ok = 0 ;
14248
        end
14249
        if ( read_data[28] !== 0 )
14250
        begin
14251
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14252
            test_fail("Received Target Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14253
            ok = 0 ;
14254
        end
14255
        if ( read_data[29] !== 0 )
14256
        begin
14257
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14258
            test_fail("Received Master Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14259
            ok = 0 ;
14260
        end
14261
 
14262
        // clear statuses
14263
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14264
        if ( !ok )
14265
        begin
14266
            test_fail("write to PCI Device Status register failed") ;
14267
            $display("Couldn't write PCI Device Status register") ;
14268
            disable main ;
14269
        end
14270
 
14271
        if ( ok )
14272
            test_ok ;
14273
 
14274
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14275
 
14276
        ok = 1 ;
14277
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14278
 
14279
        config_read(addr_offset, 4'hF, read_data) ;
14280
        if (read_data[8] !== 0)
14281
        begin
14282
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14283
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14284
            ok = 0 ;
14285
        end
14286
        else
14287
            test_ok ;
14288
 
14289
        if ( ok !== 1 )
14290
        begin
14291
            config_write(addr_offset, read_data, 4'hF, ok) ;
14292
            if ( !ok )
14293
            begin
14294
                test_fail("PCI Error Control and Status register could not be written") ;
14295
                disable main ;
14296
            end
14297
        end
14298
 
14299
        // do a single read error terminated on WB bus
14300
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
14301
 
14302 92 mihad
        wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14303 15 mihad
 
14304
        fork
14305
        begin
14306
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14307
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14308
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14309
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14310
 
14311
            do_pause( 1 ) ;
14312
        end
14313
        begin
14314
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
14315
 
14316
            if ( ok !== 1 )
14317
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14318
 
14319
            do_pause(3) ;
14320
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14321
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14322
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14323
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14324
            do_pause(1) ;
14325
 
14326
            while ( FRAME === 0 )
14327
                @(posedge pci_clock) ;
14328
 
14329
            while ( IRDY === 0 )
14330
                @(posedge pci_clock) ;
14331
 
14332 35 mihad
            if ( !error_monitor_done )
14333
                disable monitor_error_event3 ;
14334 15 mihad
        end
14335
        begin:monitor_error_event3
14336 35 mihad
            error_monitor_done = 0 ;
14337 15 mihad
            @(error_event_int) ;
14338
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14339
            ok = 0 ;
14340 35 mihad
            error_monitor_done = 1 ;
14341 15 mihad
        end
14342
        join
14343
 
14344
        if ( ok )
14345
            test_ok ;
14346
 
14347 26 mihad
        @(posedge pci_clock) ;
14348
        @(posedge pci_clock) ;
14349
        @(posedge wb_clock) ;
14350
        @(posedge wb_clock) ;
14351
 
14352 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14353
        addr_offset = 12'h004 ;
14354
        config_read(addr_offset, 4'hF, read_data) ;
14355
        ok = 1 ;
14356
        if ( read_data[27] !== 1 )
14357
        begin
14358
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14359
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14360
            ok = 0 ;
14361
        end
14362
        if ( read_data[28] !== 0 )
14363
        begin
14364
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14365
            test_fail("Received Target Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14366
            ok = 0 ;
14367
        end
14368
        if ( read_data[29] !== 0 )
14369
        begin
14370
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14371
            test_fail("Received Master Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14372
            ok = 0 ;
14373
        end
14374
 
14375
        // clear statuses
14376
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14377
        if ( !ok )
14378
        begin
14379
            test_fail("write to PCI Device Status register failed") ;
14380
            $display("Couldn't write PCI Device Status register") ;
14381
            disable main ;
14382
        end
14383
 
14384
        if ( ok )
14385
            test_ok ;
14386
 
14387
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14388
 
14389
        ok = 1 ;
14390
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14391
 
14392
        config_read(addr_offset, 4'hF, read_data) ;
14393
        if (read_data[8] !== 0)
14394
        begin
14395
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14396
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14397
            ok = 0 ;
14398
        end
14399
        else
14400
            test_ok ;
14401
 
14402
        if ( ok !== 1 )
14403
        begin
14404
            config_write(addr_offset, read_data, 4'hF, ok) ;
14405
            if ( !ok )
14406
            begin
14407
                test_fail("PCI Error Control and Status register could not be written") ;
14408
                disable main ;
14409
            end
14410
        end
14411
 
14412
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
14413
 
14414 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14415 15 mihad
 
14416
        fork
14417
        begin
14418
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14419
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14420
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14421
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14422
 
14423
            do_pause( 1 ) ;
14424
        end
14425
        begin
14426
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
14427
 
14428
            if ( ok !== 1 )
14429
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14430
 
14431
            do_pause(3) ;
14432
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14433
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14434
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14435
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14436
            do_pause(1) ;
14437
 
14438
            while ( FRAME === 0 )
14439
                @(posedge pci_clock) ;
14440
 
14441
            while ( IRDY === 0 )
14442
                @(posedge pci_clock) ;
14443
 
14444 35 mihad
            #1 ;
14445
            if ( !error_monitor_done )
14446
                disable monitor_error_event4 ;
14447 15 mihad
        end
14448
        begin:monitor_error_event4
14449 35 mihad
            error_monitor_done = 0 ;
14450 15 mihad
            @(error_event_int) ;
14451
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14452
            ok = 0 ;
14453 35 mihad
            error_monitor_done = 1 ;
14454 15 mihad
        end
14455
        begin
14456
            wb_transaction_stop( 1 ) ;
14457 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14458 15 mihad
        end
14459
        join
14460
 
14461
        if ( ok )
14462
            test_ok ;
14463
 
14464 26 mihad
        @(posedge pci_clock) ;
14465
        @(posedge pci_clock) ;
14466
        @(posedge wb_clock) ;
14467
        @(posedge wb_clock) ;
14468
 
14469 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14470
        addr_offset = 12'h004 ;
14471
        config_read(addr_offset, 4'hF, read_data) ;
14472
        ok = 1 ;
14473
        if ( read_data[27] !== 1 )
14474
        begin
14475
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14476
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14477
            ok = 0 ;
14478
        end
14479
        if ( read_data[28] !== 0 )
14480
        begin
14481
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14482
            test_fail("Received Target Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14483
            ok = 0 ;
14484
        end
14485
        if ( read_data[29] !== 0 )
14486
        begin
14487
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14488
            test_fail("Received Master Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14489
            ok = 0 ;
14490
        end
14491
 
14492
        // clear statuses
14493
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14494
        if ( !ok )
14495
        begin
14496
            test_fail("write to PCI Device Status register failed") ;
14497
            $display("Couldn't write PCI Device Status register") ;
14498
            disable main ;
14499
        end
14500
 
14501
        if ( ok )
14502
            test_ok ;
14503
 
14504
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14505
 
14506
        ok = 1 ;
14507
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14508
 
14509
        config_read(addr_offset, 4'hF, read_data) ;
14510
        if (read_data[8] !== 0)
14511
        begin
14512
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14513
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14514
            ok = 0 ;
14515
        end
14516
        else
14517
            test_ok ;
14518
 
14519
        if ( ok !== 1 )
14520
        begin
14521
            config_write(addr_offset, read_data, 4'hF, ok) ;
14522
            if ( !ok )
14523
            begin
14524
                test_fail("PCI Error Control and Status register could not be written") ;
14525
                disable main ;
14526
            end
14527
        end
14528
 
14529
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14530
 
14531 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14532 15 mihad
 
14533
        fork
14534
        begin
14535
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14536
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14537
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14538
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14539
 
14540
            do_pause( 1 ) ;
14541
        end
14542
        begin
14543
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14544
 
14545
            if ( ok !== 1 )
14546
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14547
 
14548
            do_pause(3) ;
14549
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14550
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14551
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14552
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14553
            do_pause(1) ;
14554
 
14555
            while ( FRAME === 0 )
14556
                @(posedge pci_clock) ;
14557
 
14558
            while ( IRDY === 0 )
14559
                @(posedge pci_clock) ;
14560
 
14561 35 mihad
            #1 ;
14562
            if ( !error_monitor_done )
14563
                disable monitor_error_event5 ;
14564 15 mihad
        end
14565
        begin:monitor_error_event5
14566 35 mihad
            error_monitor_done = 0 ;
14567 15 mihad
            @(error_event_int) ;
14568
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14569
            ok = 0 ;
14570 35 mihad
            error_monitor_done = 1 ;
14571 15 mihad
        end
14572
        begin
14573
            wb_transaction_stop( 3 ) ;
14574 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14575 15 mihad
        end
14576
        join
14577
 
14578
        if ( ok )
14579
            test_ok ;
14580
 
14581 26 mihad
        @(posedge pci_clock) ;
14582
        @(posedge pci_clock) ;
14583
        @(posedge wb_clock) ;
14584
        @(posedge wb_clock) ;
14585
 
14586 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14587
        addr_offset = 12'h004 ;
14588
        config_read(addr_offset, 4'hF, read_data) ;
14589
        ok = 1 ;
14590
        if ( read_data[27] !== 1 )
14591
        begin
14592
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14593
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14594
            ok = 0 ;
14595
        end
14596
        if ( read_data[28] !== 0 )
14597
        begin
14598
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14599
            test_fail("Received Target Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14600
            ok = 0 ;
14601
        end
14602
        if ( read_data[29] !== 0 )
14603
        begin
14604
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14605
            test_fail("Received Master Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14606
            ok = 0 ;
14607
        end
14608
 
14609
        // clear statuses
14610
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14611
        if ( !ok )
14612
        begin
14613
            test_fail("write to PCI Device Status register failed") ;
14614
            $display("Couldn't write PCI Device Status register") ;
14615
            disable main ;
14616
        end
14617
 
14618
        if ( ok )
14619
            test_ok ;
14620
 
14621
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14622
 
14623
        ok = 1 ;
14624
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14625
 
14626
        config_read(addr_offset, 4'hF, read_data) ;
14627
        if (read_data[8] !== 0)
14628
        begin
14629
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14630
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14631
            ok = 0 ;
14632
        end
14633
        else
14634
            test_ok ;
14635
 
14636
        if ( ok !== 1 )
14637
        begin
14638
            config_write(addr_offset, read_data, 4'hF, ok) ;
14639
            if ( !ok )
14640
            begin
14641
                test_fail("PCI Error Control and Status register could not be written") ;
14642
                disable main ;
14643
            end
14644
        end
14645
 
14646
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14647 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14648 15 mihad
        fork
14649
        begin
14650
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14651
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14652
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14653
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14654
 
14655
            do_pause( 1 ) ;
14656
        end
14657
        begin
14658
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14659
 
14660
            if ( ok !== 1 )
14661
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14662
 
14663
            do_pause(3) ;
14664
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14665
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14666
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14667
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14668
            do_pause(1) ;
14669
 
14670
            while ( FRAME === 0 )
14671
                @(posedge pci_clock) ;
14672
 
14673
            while ( IRDY === 0 )
14674
                @(posedge pci_clock) ;
14675
 
14676 35 mihad
            #1 ;
14677
            if ( !error_monitor_done )
14678
                disable monitor_error_event6 ;
14679 15 mihad
        end
14680
        begin:monitor_error_event6
14681 35 mihad
            error_monitor_done = 0 ;
14682 15 mihad
            @(error_event_int) ;
14683
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14684
            ok = 0 ;
14685 35 mihad
            error_monitor_done = 1 ;
14686 15 mihad
        end
14687
        begin
14688
            wb_transaction_stop( 3 ) ;
14689 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14690 15 mihad
        end
14691
        join
14692
 
14693
        if ( ok )
14694
            test_ok ;
14695
 
14696 26 mihad
        @(posedge pci_clock) ;
14697
        @(posedge pci_clock) ;
14698
        @(posedge wb_clock) ;
14699
        @(posedge wb_clock) ;
14700
 
14701 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14702
        addr_offset = 12'h004 ;
14703
        config_read(addr_offset, 4'hF, read_data) ;
14704
        ok = 1 ;
14705
        if ( read_data[27] !== 1 )
14706
        begin
14707
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14708
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14709
            ok = 0 ;
14710
        end
14711
        if ( read_data[28] !== 0 )
14712
        begin
14713
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14714
            test_fail("Received Target Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14715
            ok = 0 ;
14716
        end
14717
        if ( read_data[29] !== 0 )
14718
        begin
14719
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14720
            test_fail("Received Master Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14721
            ok = 0 ;
14722
        end
14723
 
14724
        // clear statuses
14725
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14726
        if ( !ok )
14727
        begin
14728
            test_fail("write to PCI Device Status register failed") ;
14729
            $display("Couldn't write PCI Device Status register") ;
14730
            disable main ;
14731
        end
14732
 
14733
        if ( ok )
14734
            test_ok ;
14735
 
14736
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14737
 
14738
        ok = 1 ;
14739
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14740
 
14741
        config_read(addr_offset, 4'hF, read_data) ;
14742
        if (read_data[8] !== 0)
14743
        begin
14744
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14745
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14746
            ok = 0 ;
14747
        end
14748
        else
14749
            test_ok ;
14750
 
14751
        if ( ok !== 1 )
14752
        begin
14753
            config_write(addr_offset, read_data, 4'hF, ok) ;
14754
            if ( !ok )
14755
            begin
14756
                test_fail("PCI Error Control and Status register could not be written") ;
14757
                disable main ;
14758
            end
14759
        end
14760
 
14761
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14762 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14763 15 mihad
        fork
14764
        begin
14765
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14766
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14767
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14768
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14769
 
14770
            do_pause( 1 ) ;
14771
        end
14772
        begin
14773
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14774
 
14775
            if ( ok !== 1 )
14776
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14777
 
14778
            do_pause(3) ;
14779
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14780
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14781
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14782
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14783
            do_pause(1) ;
14784
 
14785
            while ( FRAME === 0 )
14786
                @(posedge pci_clock) ;
14787
 
14788
            while ( IRDY === 0 )
14789
                @(posedge pci_clock) ;
14790
 
14791 35 mihad
            #1 ;
14792
            if ( !error_monitor_done )
14793
                disable monitor_error_event7 ;
14794 15 mihad
        end
14795
        begin:monitor_error_event7
14796 35 mihad
            error_monitor_done = 0 ;
14797 15 mihad
            @(error_event_int) ;
14798
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14799
            ok = 0 ;
14800 35 mihad
            error_monitor_done = 1 ;
14801 15 mihad
        end
14802
        begin
14803
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14804 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14805 15 mihad
        end
14806
        join
14807
 
14808
        if ( ok )
14809
            test_ok ;
14810
 
14811 26 mihad
        @(posedge pci_clock) ;
14812
        @(posedge pci_clock) ;
14813
        @(posedge wb_clock) ;
14814
        @(posedge wb_clock) ;
14815
 
14816 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14817
        addr_offset = 12'h004 ;
14818
        config_read(addr_offset, 4'hF, read_data) ;
14819
        ok = 1 ;
14820
        if ( read_data[27] !== 1 )
14821
        begin
14822
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14823
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14824
            ok = 0 ;
14825
        end
14826
        if ( read_data[28] !== 0 )
14827
        begin
14828
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14829
            test_fail("Received Target Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14830
            ok = 0 ;
14831
        end
14832
        if ( read_data[29] !== 0 )
14833
        begin
14834
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14835
            test_fail("Received Master Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14836
            ok = 0 ;
14837
        end
14838
 
14839
        // clear statuses
14840
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14841
        if ( !ok )
14842
        begin
14843
            test_fail("write to PCI Device Status register failed") ;
14844
            $display("Couldn't write PCI Device Status register") ;
14845
            disable main ;
14846
        end
14847
 
14848
        if ( ok )
14849
            test_ok ;
14850
 
14851
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14852
 
14853
        ok = 1 ;
14854
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14855
 
14856
        config_read(addr_offset, 4'hF, read_data) ;
14857
        if (read_data[8] !== 0)
14858
        begin
14859
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14860
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14861
            ok = 0 ;
14862
        end
14863
        else
14864
            test_ok ;
14865
 
14866
        if ( ok !== 1 )
14867
        begin
14868
            config_write(addr_offset, read_data, 4'hF, ok) ;
14869
            if ( !ok )
14870
            begin
14871
                test_fail("PCI Error Control and Status register could not be written") ;
14872
                disable main ;
14873
            end
14874
        end
14875
 
14876
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14877 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14878 15 mihad
        fork
14879
        begin
14880
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14881
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14882
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14883
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14884
 
14885
            do_pause( 1 ) ;
14886
        end
14887
        begin
14888
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14889
 
14890
            if ( ok !== 1 )
14891
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14892
 
14893
            do_pause(3) ;
14894
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14895
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14896
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14897
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14898
            do_pause(1) ;
14899
 
14900
            while ( FRAME === 0 )
14901
                @(posedge pci_clock) ;
14902
 
14903
            while ( IRDY === 0 )
14904
                @(posedge pci_clock) ;
14905
 
14906 35 mihad
            #1 ;
14907
            if ( !error_monitor_done )
14908
                disable monitor_error_event8 ;
14909 15 mihad
        end
14910
        begin:monitor_error_event8
14911 35 mihad
            error_monitor_done = 0 ;
14912 15 mihad
            @(error_event_int) ;
14913
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14914
            ok = 0 ;
14915 35 mihad
            error_monitor_done = 1 ;
14916 15 mihad
        end
14917
        begin
14918
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14919 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14920 15 mihad
        end
14921
        join
14922
 
14923
        if ( ok )
14924
            test_ok ;
14925
 
14926 26 mihad
        @(posedge pci_clock) ;
14927
        @(posedge pci_clock) ;
14928
        @(posedge wb_clock) ;
14929
        @(posedge wb_clock) ;
14930
 
14931 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14932 15 mihad
 
14933
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14934
        addr_offset = 12'h004 ;
14935
        config_read(addr_offset, 4'hF, read_data) ;
14936
        ok = 1 ;
14937
        if ( read_data[27] !== 1 )
14938
        begin
14939
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14940
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14941
            ok = 0 ;
14942
        end
14943
        if ( read_data[28] !== 0 )
14944
        begin
14945
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14946
            test_fail("Received Target Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14947
            ok = 0 ;
14948
        end
14949
        if ( read_data[29] !== 0 )
14950
        begin
14951
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14952
            test_fail("Received Master Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
14953
            ok = 0 ;
14954
        end
14955
 
14956
        // clear statuses
14957
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14958
        if ( !ok )
14959
        begin
14960
            test_fail("write to PCI Device Status register failed") ;
14961
            $display("Couldn't write PCI Device Status register") ;
14962
            disable main ;
14963
        end
14964
 
14965
        if ( ok )
14966
            test_ok ;
14967
 
14968
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14969
 
14970
        ok = 1 ;
14971
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14972
 
14973
        config_read(addr_offset, 4'hF, read_data) ;
14974
        if (read_data[8] !== 0)
14975
        begin
14976
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14977
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14978
            ok = 0 ;
14979
        end
14980
        else
14981
            test_ok ;
14982
 
14983
        if ( ok !== 1 )
14984
        begin
14985
            config_write(addr_offset, read_data, 4'hF, ok) ;
14986
            if ( !ok )
14987
            begin
14988
                test_fail("PCI Error Control and Status register could not be written") ;
14989
                disable main ;
14990
            end
14991
        end
14992
 
14993
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14994 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14995 15 mihad
        fork
14996
        begin
14997
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14998
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14999
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
15000
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
15001
 
15002
            do_pause( 1 ) ;
15003
        end
15004
        begin
15005
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
15006
 
15007
            if ( ok !== 1 )
15008
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
15009
 
15010
            do_pause(3) ;
15011
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
15012
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
15013
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
15014
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
15015
            do_pause(1) ;
15016
 
15017
            while ( FRAME === 0 )
15018
                @(posedge pci_clock) ;
15019
 
15020
            while ( IRDY === 0 )
15021
                @(posedge pci_clock) ;
15022
 
15023 35 mihad
            #1 ;
15024
            if ( !error_monitor_done )
15025
                disable monitor_error_event9 ;
15026 15 mihad
        end
15027
        begin:monitor_error_event9
15028 35 mihad
            error_monitor_done = 0 ;
15029 15 mihad
            @(error_event_int) ;
15030
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
15031
            ok = 0 ;
15032 35 mihad
            error_monitor_done = 1 ;
15033 15 mihad
        end
15034
        begin
15035
            wb_transaction_stop( 3 ) ;
15036 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
15037 15 mihad
        end
15038
        join
15039
 
15040
        if ( ok )
15041
            test_ok ;
15042
 
15043
        // now check all other statuses too
15044
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
15045
        ok = 1 ;
15046
 
15047
        addr_offset = 12'h004 ;
15048
        config_read(addr_offset, 4'hF, read_data) ;
15049
        if (read_data[31] !== 0)
15050
        begin
15051
            $display("Detected Parity Error bit set for no reason") ;
15052
            test_fail("Detected Parity Error bit was set for no reason") ;
15053
            ok = 0 ;
15054
        end
15055
 
15056
        if (read_data[30] !== 0)
15057
        begin
15058
            $display("Signaled System Error bit set for no reason") ;
15059
            test_fail("Signaled System Error bit was set for no reason") ;
15060
            ok = 0 ;
15061
        end
15062
 
15063
        if (read_data[29] !== 0)
15064
        begin
15065
            $display("Received Master Abort bit set for no reason") ;
15066
            test_fail("Received Master Abort bit was set for no reason") ;
15067
            ok = 0 ;
15068
        end
15069
 
15070
        if (read_data[28] !== 0)
15071
        begin
15072
            $display("Received Target Abort bit set for no reason");
15073
            test_fail("Received Target Abort bit was set for no reason") ;
15074
            ok = 0 ;
15075
        end
15076
 
15077
        if (read_data[27] !== 0)
15078
        begin
15079
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
15080
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
15081
            ok = 0 ;
15082
        end
15083
 
15084
        if (read_data[24] !== 0)
15085
        begin
15086
            $display("Master Data Parity Error bit set for no reason") ;
15087
            test_fail("Master Data Parity Error bit was set for no reason") ;
15088
            ok = 0 ;
15089
        end
15090
 
15091
        if ( ok )
15092
            test_ok ;
15093
 
15094
        test_name = "DISABLE IMAGE" ;
15095 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
15096 15 mihad
        if ( ok !== 1 )
15097
        begin
15098
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
15099
            test_fail("PCI Address Mask register could not be written") ;
15100
            disable main;
15101
        end
15102
    end
15103
 
15104
    if ( target_io_image !== -1 )
15105
    begin
15106
        do_io_aborts = 1 ;
15107
 
15108
        if (target_io_image === 1)
15109
        begin
15110
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15111
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15112
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15113
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15114
        end
15115
        else if (target_io_image === 2)
15116
        begin
15117
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15118
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15119
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15120
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15121
        end
15122
        else if (target_io_image === 3)
15123
        begin
15124
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15125
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15126
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15127
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15128
        end
15129
        else if (target_io_image === 4)
15130
        begin
15131
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15132
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15133
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15134
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15135
        end
15136
        else if (target_io_image === 5)
15137
        begin
15138
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15139
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15140
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15141
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15142
        end
15143
    end
15144
    else
15145
        do_io_aborts = 0 ;
15146
 
15147
    if ( do_io_aborts )
15148
    begin
15149
 
15150
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
15151
 
15152
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15153
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
15154
        if ( ok !== 1 )
15155
        begin
15156
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
15157
            test_fail("PCI Error Control and Status register could not be written") ;
15158
            disable main;
15159
        end
15160
 
15161
        // enable INTERRUPT reporting
15162
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
15163
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
15164
        if ( ok !== 1 )
15165
        begin
15166
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
15167
            test_fail("Interrupt Control register could not be written") ;
15168
            disable main;
15169
        end
15170
 
15171
        addr_offset = 12'h010 + (4*target_io_image) ;
15172
 
15173
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
15174
        if ( ok !== 1 )
15175
        begin
15176
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
15177
            test_fail("PCI Base Address register could not be written") ;
15178
            disable main;
15179
        end
15180
 
15181
        // disable address translation and enable prefetch so read bursts can be performed
15182
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
15183
        if ( ok !== 1 )
15184
        begin
15185
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
15186
            test_fail("PCI Image Control register could not be written") ;
15187
            disable main;
15188
        end
15189
 
15190
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
15191
        if ( ok !== 1 )
15192
        begin
15193
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
15194
            test_fail("PCI Address Mask register could not be written") ;
15195
            disable main;
15196
        end
15197
 
15198
        addr_offset = 12'h00C ;
15199
 
15200
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
15201
        if ( ok !== 1 )
15202
        begin
15203
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
15204
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
15205
            disable main;
15206
        end
15207
 
15208
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
15209 92 mihad
        wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
15210 15 mihad
 
15211
        // do a single read error terminated on WB bus
15212
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
15213
 
15214
        fork
15215
        begin
15216
            PCIU_IO_READ
15217
             (
15218
                `Test_Master_1,
15219
                Target_Base_Addr_R[target_io_image],
15220
                32'hAAAA_5555,
15221
                4'h0,
15222
                1,
15223
                `Test_Target_Retry_On
15224
             );
15225
 
15226
            do_pause( 1 ) ;
15227
        end
15228
        begin
15229
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
15230
 
15231
            if ( ok !== 1 )
15232
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
15233
 
15234
            do_pause(3) ;
15235
 
15236
            PCIU_IO_READ
15237
             (
15238
                `Test_Master_1,
15239
                Target_Base_Addr_R[target_io_image],
15240
                32'hAAAA_5555,
15241
                4'h0,
15242
                1,
15243
                `Test_Target_Abort_On
15244
             );
15245
 
15246
            do_pause( 1 ) ;
15247
 
15248
            while ( FRAME === 0 )
15249
                @(posedge pci_clock) ;
15250
 
15251
            while ( IRDY === 0 )
15252
                @(posedge pci_clock) ;
15253
 
15254 35 mihad
            #1 ;
15255
            if ( !error_monitor_done )
15256
                disable monitor_error_event10 ;
15257 15 mihad
        end
15258
        begin:monitor_error_event10
15259 35 mihad
            error_monitor_done = 0 ;
15260 15 mihad
            @(error_event_int) ;
15261
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
15262
            ok = 0 ;
15263 35 mihad
            error_monitor_done = 1 ;
15264 15 mihad
        end
15265
        join
15266
 
15267
        if ( ok )
15268
            test_ok ;
15269
 
15270 26 mihad
        @(posedge pci_clock) ;
15271
        @(posedge pci_clock) ;
15272
        @(posedge wb_clock) ;
15273
        @(posedge wb_clock) ;
15274
 
15275 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15276
        addr_offset = 12'h004 ;
15277
        config_read(addr_offset, 4'hF, read_data) ;
15278
        ok = 1 ;
15279
        if ( read_data[27] !== 1 )
15280
        begin
15281
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
15282
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
15283
            ok = 0 ;
15284
        end
15285
        if ( read_data[28] !== 0 )
15286
        begin
15287
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
15288
            test_fail("Received Target Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
15289
            ok = 0 ;
15290
        end
15291
        if ( read_data[29] !== 0 )
15292
        begin
15293
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
15294
            test_fail("Received Master Abort bit was set in PCI Device Status register after Target read was terminated with Target Abort and Master wasn't doing references") ;
15295
            ok = 0 ;
15296
        end
15297
 
15298
        // clear statuses
15299
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
15300
        if ( !ok )
15301
        begin
15302
            test_fail("write to PCI Device Status register failed") ;
15303
            $display("Couldn't write PCI Device Status register") ;
15304
            disable main ;
15305
        end
15306
 
15307
        if ( ok )
15308
            test_ok ;
15309
 
15310
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15311
 
15312
        ok = 1 ;
15313
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
15314
 
15315
        config_read(addr_offset, 4'hF, read_data) ;
15316
        if (read_data[8] !== 0)
15317
        begin
15318
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
15319
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
15320
            ok = 0 ;
15321
        end
15322
        else
15323
            test_ok ;
15324
 
15325
        if ( ok !== 1 )
15326
        begin
15327
            config_write(addr_offset, read_data, 4'hF, ok) ;
15328
            if ( !ok )
15329
            begin
15330
                test_fail("PCI Error Control and Status register could not be written") ;
15331
                disable main ;
15332
            end
15333
        end
15334
 
15335
        test_name = "DISABLE IMAGE" ;
15336 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
15337 15 mihad
        if ( ok !== 1 )
15338
        begin
15339
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
15340
            test_fail("PCI Address Mask register could not be written") ;
15341
            disable main;
15342
        end
15343
 
15344 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
15345 15 mihad
 
15346
    end
15347
end // main
15348
endtask // test_wb_error_rd
15349
 
15350
task test_target_abort ;
15351
    input [2:0]  image_num ;
15352
    reg   [11:0] pci_ctrl_offset ;
15353
    reg   [11:0] ctrl_offset ;
15354
    reg   [11:0] ba_offset ;
15355
    reg   [11:0] am_offset ;
15356
    reg   [11:0] ta_offset ;
15357
    reg   [31:0] pci_address ;
15358
    reg   [3:0]  byte_enables ;
15359
    reg          ok ;
15360 35 mihad
    reg          error_monitor_done ;
15361 15 mihad
begin:main
15362
    pci_ctrl_offset = 12'h4 ;
15363
    if (image_num === 0)
15364
    begin
15365
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15366
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15367
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15368
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15369
    end
15370
    else if (image_num === 1)
15371
    begin
15372
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15373
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15374
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15375
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15376
    end
15377
    else if (image_num === 2)
15378
    begin
15379
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15380
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15381
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15382
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15383
    end
15384
    else if (image_num === 3)
15385
    begin
15386
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15387
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15388
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15389
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15390
    end
15391
    else if (image_num === 4)
15392
    begin
15393
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15394
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15395
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15396
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15397
    end
15398
    else if (image_num === 5)
15399
    begin
15400
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15401
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15402
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15403
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15404
    end
15405
 
15406
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
15407
 
15408
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
15409
    if ( ok !== 1 )
15410
    begin
15411
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
15412
        test_fail("PCI Base Address register could not be written") ;
15413
        disable main ;
15414
    end
15415
 
15416
    // Set Address Mask of IMAGE
15417
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15418
    if ( ok !== 1 )
15419
    begin
15420
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15421
        test_fail("PCI Address Mask register could not be written") ;
15422
        disable main ;
15423
    end
15424
 
15425
    // Set Translation Address of IMAGE
15426
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15427
    if ( ok !== 1 )
15428
    begin
15429
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
15430
        test_fail("PCI Translation Address Register could not be written") ;
15431
        disable main ;
15432
    end
15433
 
15434
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
15435
    if ( ok !== 1 )
15436
    begin
15437
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
15438
        test_fail("PCI Image Control register could not be written") ;
15439
        disable main ;
15440
    end
15441
 
15442 92 mihad
    wishbone_slave.cycle_response( 3'b010, wb_subseq_waits, 0 ) ;
15443 15 mihad
 
15444
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
15445
 
15446
    pci_address  = Target_Base_Addr_R[image_num] ;
15447
    byte_enables = 4'b0001 ;
15448
 
15449
    fork
15450
    begin
15451
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15452
        do_pause ( 1 ) ;
15453
    end
15454
    begin:monitor_error_event1
15455 35 mihad
        error_monitor_done = 0 ;
15456 15 mihad
        @(error_event_int) ;
15457
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15458
        ok = 0 ;
15459 35 mihad
        error_monitor_done = 1 ;
15460 15 mihad
    end
15461
    begin
15462
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15463
        @(posedge pci_clock) ;
15464 35 mihad
        #1 ;
15465
        if ( !error_monitor_done )
15466
            disable monitor_error_event1 ;
15467 15 mihad
    end
15468
    join
15469
 
15470
    if ( ok )
15471
        test_ok ;
15472
 
15473
    ok = 1 ;
15474
 
15475
    fork
15476
    begin
15477
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15478
        do_pause ( 1 ) ;
15479
    end
15480
    begin:monitor_error_event2
15481 35 mihad
        error_monitor_done = 0 ;
15482 15 mihad
        @(error_event_int) ;
15483
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15484
        ok = 0 ;
15485 35 mihad
        error_monitor_done = 1 ;
15486 15 mihad
    end
15487
    begin
15488
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15489
        @(posedge pci_clock) ;
15490 35 mihad
        #1 ;
15491
        if ( !error_monitor_done )
15492
            disable monitor_error_event2 ;
15493 15 mihad
    end
15494
    join
15495
 
15496
    if ( ok )
15497
        test_ok ;
15498
 
15499
    ok = 1 ;
15500
 
15501
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
15502
    byte_enables = 4'b0011 ;
15503
 
15504
    fork
15505
    begin
15506
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15507
        do_pause ( 1 ) ;
15508
    end
15509
    begin:monitor_error_event3
15510 35 mihad
        error_monitor_done = 0 ;
15511 15 mihad
        @(error_event_int) ;
15512
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15513
        ok = 0 ;
15514 35 mihad
        error_monitor_done = 1 ;
15515 15 mihad
    end
15516
    begin
15517
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15518
        @(posedge pci_clock) ;
15519 35 mihad
        if ( !error_monitor_done )
15520
            disable monitor_error_event3 ;
15521 15 mihad
    end
15522
    join
15523
 
15524
    if ( ok )
15525
        test_ok ;
15526
 
15527
    ok = 1 ;
15528
 
15529
    byte_enables = 4'b0000 ;
15530
 
15531
    fork
15532
    begin
15533
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15534
        do_pause ( 1 ) ;
15535
    end
15536
    begin:monitor_error_event4
15537 35 mihad
        error_monitor_done = 0 ;
15538 15 mihad
        @(error_event_int) ;
15539
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15540
        ok = 0 ;
15541 35 mihad
        error_monitor_done = 1 ;
15542 15 mihad
    end
15543
    begin
15544
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15545
        @(posedge pci_clock) ;
15546 35 mihad
        #1 ;
15547
        if ( !error_monitor_done )
15548
            disable monitor_error_event4 ;
15549 15 mihad
    end
15550
    join
15551
 
15552
    if ( ok )
15553
        test_ok ;
15554
 
15555
    ok = 1 ;
15556
 
15557
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
15558
    byte_enables = 4'b0111 ;
15559
 
15560
    fork
15561
    begin
15562
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15563
        do_pause ( 1 ) ;
15564
    end
15565
    begin:monitor_error_event5
15566 35 mihad
        error_monitor_done = 0 ;
15567 15 mihad
        @(error_event_int) ;
15568
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15569
        ok = 0 ;
15570 35 mihad
        error_monitor_done = 1 ;
15571 15 mihad
    end
15572
    begin
15573
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15574
        @(posedge pci_clock) ;
15575 35 mihad
        #1 ;
15576
        if ( !error_monitor_done )
15577
            disable monitor_error_event5 ;
15578 15 mihad
    end
15579
    join
15580
 
15581
    if ( ok )
15582
        test_ok ;
15583
 
15584
    ok = 1 ;
15585
 
15586
    byte_enables = 4'b0010 ;
15587
 
15588
    fork
15589
    begin
15590
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15591
        do_pause ( 1 ) ;
15592
    end
15593
    begin:monitor_error_event6
15594 35 mihad
        error_monitor_done = 0 ;
15595 15 mihad
        @(error_event_int) ;
15596
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15597
        ok = 0 ;
15598 35 mihad
        error_monitor_done = 1 ;
15599 15 mihad
    end
15600
    begin
15601
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15602
        @(posedge pci_clock) ;
15603 35 mihad
        #1 ;
15604
        if ( !error_monitor_done )
15605
            disable monitor_error_event6 ;
15606 15 mihad
    end
15607
    join
15608
 
15609
    if ( ok )
15610
        test_ok ;
15611
 
15612
    ok = 1 ;
15613
    byte_enables = 4'b0001 ;
15614
 
15615
    fork
15616
    begin
15617
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15618
        do_pause ( 1 ) ;
15619
    end
15620
    begin:monitor_error_event7
15621 35 mihad
        error_monitor_done = 0 ;
15622 15 mihad
        @(error_event_int) ;
15623
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15624
        ok = 0 ;
15625 35 mihad
        error_monitor_done = 1 ;
15626 15 mihad
    end
15627
    begin
15628
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15629
        @(posedge pci_clock) ;
15630 35 mihad
        #1 ;
15631
        if ( !error_monitor_done )
15632
            disable monitor_error_event7 ;
15633 15 mihad
    end
15634
    join
15635
 
15636
    if ( ok )
15637
        test_ok ;
15638
 
15639
    ok = 1 ;
15640
    byte_enables = 4'b0000 ;
15641
 
15642
    fork
15643
    begin
15644
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15645
        do_pause ( 1 ) ;
15646
    end
15647
    begin:monitor_error_event8
15648 35 mihad
        error_monitor_done = 0 ;
15649 15 mihad
        @(error_event_int) ;
15650
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15651
        ok = 0 ;
15652 35 mihad
        error_monitor_done = 1 ;
15653 15 mihad
    end
15654
    begin
15655
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15656
        @(posedge pci_clock) ;
15657 35 mihad
        #1 ;
15658
        if ( !error_monitor_done )
15659
            disable monitor_error_event8 ;
15660 15 mihad
    end
15661
    join
15662
 
15663
    if ( ok )
15664
        test_ok ;
15665
 
15666
    ok = 1 ;
15667
 
15668
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15669
    byte_enables = 4'b0110 ;
15670
 
15671
    fork
15672
    begin
15673
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15674
        do_pause ( 1 ) ;
15675
    end
15676
    begin:monitor_error_event9
15677 35 mihad
        error_monitor_done = 0 ;
15678 15 mihad
        @(error_event_int) ;
15679
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15680
        ok = 0 ;
15681 35 mihad
        error_monitor_done = 1 ;
15682 15 mihad
    end
15683
    begin
15684
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15685
        @(posedge pci_clock) ;
15686 35 mihad
        #1 ;
15687
        if ( !error_monitor_done )
15688
            disable monitor_error_event9 ;
15689 15 mihad
    end
15690
    join
15691
 
15692
    if ( ok )
15693
        test_ok ;
15694
 
15695
    ok = 1 ;
15696
    fork
15697
    begin
15698
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15699
        do_pause ( 1 ) ;
15700
    end
15701
    begin:monitor_error_event10
15702 35 mihad
        error_monitor_done = 0 ;
15703 15 mihad
        @(error_event_int) ;
15704
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15705
        ok = 0 ;
15706 35 mihad
        error_monitor_done = 1 ;
15707 15 mihad
    end
15708
    begin
15709
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15710
        @(posedge pci_clock) ;
15711 35 mihad
 
15712
        #1 ;
15713
        if ( !error_monitor_done )
15714
            disable monitor_error_event10 ;
15715 15 mihad
    end
15716
    join
15717
 
15718
    if ( ok )
15719
        test_ok ;
15720
 
15721
    ok = 1 ;
15722
 
15723
    byte_enables = 4'b0001 ;
15724
 
15725
    fork
15726
    begin
15727
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15728
        do_pause ( 1 ) ;
15729
    end
15730
    begin:monitor_error_event11
15731 35 mihad
        error_monitor_done = 0 ;
15732 15 mihad
        @(error_event_int) ;
15733
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15734
        ok = 0 ;
15735 35 mihad
        error_monitor_done = 1 ;
15736 15 mihad
    end
15737
    begin
15738
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15739
        @(posedge pci_clock) ;
15740 35 mihad
        #1 ;
15741
        if ( !error_monitor_done )
15742
            disable monitor_error_event11 ;
15743 15 mihad
    end
15744
    join
15745
 
15746
    if ( ok )
15747
        test_ok ;
15748
 
15749
    ok = 1 ;
15750
 
15751
    byte_enables = 4'b0101 ;
15752
 
15753
    fork
15754
    begin
15755
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15756
        do_pause ( 1 ) ;
15757
    end
15758
    begin:monitor_error_event12
15759 35 mihad
        error_monitor_done = 0 ;
15760 15 mihad
        @(error_event_int) ;
15761
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15762
        ok = 0 ;
15763 35 mihad
        error_monitor_done = 1 ;
15764 15 mihad
    end
15765
    begin
15766
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15767
        @(posedge pci_clock) ;
15768 35 mihad
        #1 ;
15769
        if ( !error_monitor_done )
15770
            disable monitor_error_event12 ;
15771 15 mihad
    end
15772
    join
15773
 
15774
    if ( ok )
15775
        test_ok ;
15776
 
15777
    ok = 1 ;
15778
 
15779
    byte_enables = 4'b0011 ;
15780
 
15781
    fork
15782
    begin
15783
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15784
        do_pause ( 1 ) ;
15785
    end
15786
    begin:monitor_error_event13
15787 35 mihad
        error_monitor_done = 0 ;
15788 15 mihad
        @(error_event_int) ;
15789
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15790
        ok = 0 ;
15791 35 mihad
        error_monitor_done = 1 ;
15792 15 mihad
    end
15793
    begin
15794
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15795
        @(posedge pci_clock) ;
15796 35 mihad
        #1 ;
15797
        if ( !error_monitor_done )
15798
            disable monitor_error_event13 ;
15799 15 mihad
    end
15800
    join
15801
 
15802
    if ( ok )
15803
        test_ok ;
15804
 
15805
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15806
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15807
    ok = 1 ;
15808
    if ( pci_address[27] !== 1 )
15809
    begin
15810
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15811
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15812
        ok = 0 ;
15813
    end
15814
    if ( pci_address[28] !== 0 )
15815
    begin
15816
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15817
        test_fail("Received Target Abort bit was set in PCI Device Status register after Target terminated with Target Abort and Master wasn't doing references") ;
15818
        ok = 0 ;
15819
    end
15820
    if ( pci_address[29] !== 0 )
15821
    begin
15822
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15823
        test_fail("Received Master Abort bit was set in PCI Device Status register after Target terminated with Target Abort and Master wasn't doing references") ;
15824
        ok = 0 ;
15825
    end
15826
 
15827
    // clear statuses
15828
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15829
    if ( !ok )
15830
    begin
15831
        test_fail("write to PCI Device Status register failed") ;
15832
        $display("Couldn't write PCI Device Status register") ;
15833
        disable main ;
15834
    end
15835
 
15836
    if ( ok )
15837
        test_ok ;
15838
 
15839
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15840
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15841
    if ( pci_address[8] !== 0 )
15842
    begin
15843
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15844
    end
15845
    else
15846
        test_ok ;
15847
 
15848 92 mihad
    wishbone_slave.cycle_response( 3'b100, wb_subseq_waits, 0 ) ;
15849 15 mihad
 
15850
    test_name = "DISABLE IMAGE" ;
15851
 
15852 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15853 15 mihad
    if ( ok !== 1 )
15854
    begin
15855
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15856
        test_fail("PCI Address Mask register could not be written") ;
15857
        disable main ;
15858
    end
15859
end
15860
endtask // test_target_abort
15861
 
15862
task test_target_io_wr_rd ;
15863
    input [2:0]  image_num ;
15864
    input        translate_address ;
15865
    input [11:0] img_ctrl_offset ;
15866
    reg   [31:0] expect_address ;
15867
    reg   [31:0] pci_address ;
15868
    reg          translation ;
15869
    reg   [31:0] read_data ;
15870
    reg   [3:0]  byte_enables ;
15871
    reg          ok ;
15872
    reg          pci_ok ;
15873
    reg          wb_ok ;
15874
    integer      i ;
15875 35 mihad
    reg          error_monitor_done ;
15876 15 mihad
begin:main
15877
    `ifdef ADDR_TRAN_IMPL
15878
        translation = translate_address ;
15879
    `else
15880
        translation = 0 ;
15881
    `endif
15882
 
15883 92 mihad
    wishbone_slave.cycle_response( 3'b100, wb_subseq_waits, 0 ) ;
15884 15 mihad
 
15885
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15886
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15887
    if ( translation )
15888
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15889
    else
15890
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15891
 
15892
    if ( !ok )
15893
    begin
15894
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15895
        test_fail("PCI Image Control register could not be written") ;
15896
    end
15897
 
15898
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15899
    pci_address  = Target_Base_Addr_R[image_num] ;
15900
    byte_enables = 4'b0000 ;
15901
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15902
 
15903
    fork
15904
    begin
15905
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15906
        do_pause ( 1 ) ;
15907
    end
15908
    begin
15909
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15910
        if ( wb_ok !== 1 )
15911
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15912
 
15913 35 mihad
        #1 ;
15914
        if ( !error_monitor_done )
15915
            disable monitor_pci_error_1 ;
15916 15 mihad
    end
15917
    begin:monitor_pci_error_1
15918 35 mihad
        error_monitor_done = 0 ;
15919 15 mihad
        pci_ok = 1 ;
15920
        @(error_event_int) ;
15921
        pci_ok = 0 ;
15922
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15923 35 mihad
        error_monitor_done = 1 ;
15924 15 mihad
    end
15925
    join
15926
 
15927
    byte_enables = 4'b1111 ;
15928
    for ( i = 0 ; i < 4 ; i = i + 1 )
15929
    begin:loop_1
15930
        byte_enables[i] = 0 ;
15931
        if ( i > 0 )
15932
            byte_enables[i - 1] = 1 ;
15933
        fork
15934
        begin
15935
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15936
            do_pause ( 1 ) ;
15937
        end
15938
        begin
15939
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15940
            if ( wb_ok !== 1 )
15941
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15942
 
15943 35 mihad
            #1 ;
15944
            if ( !error_monitor_done )
15945
                disable monitor_pci_error_2 ;
15946 15 mihad
        end
15947
        begin:monitor_pci_error_2
15948 35 mihad
            error_monitor_done = 0 ;
15949 15 mihad
            pci_ok = 1 ;
15950
            @(error_event_int) ;
15951
            pci_ok = 0 ;
15952
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15953 35 mihad
            error_monitor_done = 1 ;
15954 15 mihad
        end
15955
        join
15956
 
15957
        if ( !pci_ok || !wb_ok )
15958
            disable loop_1 ;
15959
 
15960
        pci_address = pci_address + 1 ;
15961
        expect_address = expect_address + 1 ;
15962
    end
15963
 
15964
    if ( pci_ok && wb_ok )
15965
        test_ok ;
15966
 
15967
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15968
    pci_address  = Target_Base_Addr_R[image_num] ;
15969
    byte_enables = 4'b1100 ;
15970
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15971
 
15972
    master1_check_received_data = 1 ;
15973
    fork
15974
    begin
15975
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15976
        do_pause( 1 ) ;
15977
    end
15978
    begin
15979
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15980
        if ( wb_ok !== 1 )
15981
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15982
 
15983
        do_pause ( 2 ) ;
15984
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15985
        do_pause ( 16 ) ;
15986
 
15987 35 mihad
        #1 ;
15988
        if ( !error_monitor_done )
15989
            disable monitor_pci_error_3 ;
15990 15 mihad
    end
15991
    begin:monitor_pci_error_3
15992 35 mihad
        error_monitor_done = 0 ;
15993 15 mihad
        pci_ok = 1 ;
15994
        @(error_event_int) ;
15995
        pci_ok = 0 ;
15996
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15997 35 mihad
        error_monitor_done = 1 ;
15998 15 mihad
    end
15999
    join
16000
 
16001
    if ( !pci_ok || !wb_ok )
16002
    begin
16003
        disable main ;
16004
    end
16005
 
16006
    pci_address  = Target_Base_Addr_R[image_num] + 2;
16007
    byte_enables = 4'b0011 ;
16008
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
16009
 
16010
    master1_check_received_data = 1 ;
16011
    fork
16012
    begin
16013
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
16014
        do_pause( 1 ) ;
16015
    end
16016
    begin
16017
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
16018
        if ( wb_ok !== 1 )
16019
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
16020
 
16021
        do_pause ( 2 ) ;
16022
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
16023
        do_pause ( 16 ) ;
16024
 
16025 35 mihad
        #1 ;
16026
        if ( !error_monitor_done )
16027
            disable monitor_pci_error_4 ;
16028 15 mihad
    end
16029
    begin:monitor_pci_error_4
16030 35 mihad
        error_monitor_done = 0 ;
16031 15 mihad
        pci_ok = 1 ;
16032
        @(error_event_int) ;
16033
        pci_ok = 0 ;
16034
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
16035 35 mihad
        error_monitor_done = 1 ;
16036 15 mihad
    end
16037
    join
16038
 
16039
    if ( !pci_ok || !wb_ok )
16040
    begin
16041
        disable main ;
16042
    end
16043
 
16044
    pci_address  = Target_Base_Addr_R[image_num] ;
16045
    byte_enables = 4'b0000 ;
16046
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
16047
 
16048
    master1_check_received_data = 1 ;
16049
    fork
16050
    begin
16051
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
16052
        do_pause( 1 ) ;
16053
    end
16054
    begin
16055
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
16056
        if ( wb_ok !== 1 )
16057
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
16058
 
16059
        do_pause ( 2 ) ;
16060
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
16061
        do_pause ( 16 ) ;
16062
 
16063 35 mihad
        #1 ;
16064
        if ( !error_monitor_done )
16065
            disable monitor_pci_error_5 ;
16066 15 mihad
    end
16067
    begin:monitor_pci_error_5
16068 35 mihad
        error_monitor_done = 0 ;
16069 15 mihad
        pci_ok = 1 ;
16070
        @(error_event_int) ;
16071
        pci_ok = 0 ;
16072
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
16073 35 mihad
        error_monitor_done = 1 ;
16074 15 mihad
    end
16075
    join
16076
 
16077
    if ( pci_ok && wb_ok )
16078
        test_ok ;
16079
end
16080
endtask // test_target_io_wr_rd
16081
 
16082
task test_target_io_err_wr ;
16083
    input [2:0]  image_num ;
16084
    input        translate_address ;
16085
    input [11:0] img_ctrl_offset ;
16086
    input        enable_error_report ;
16087
    input        enable_error_interrupt ;
16088
 
16089
    reg   [31:0] expect_address ;
16090
    reg   [31:0] pci_address ;
16091
    reg          translation ;
16092
    reg   [31:0] read_data ;
16093
    reg   [3:0]  byte_enables ;
16094
    reg          ok ;
16095
    reg          pci_ok ;
16096
    reg          wb_ok ;
16097
    integer      i ;
16098
    reg   [11:0] offset ;
16099 35 mihad
    reg          error_monitor_done ;
16100 15 mihad
begin:main
16101
    `ifdef ADDR_TRAN_IMPL
16102
        translation = translate_address ;
16103
    `else
16104
        translation = 0 ;
16105
    `endif
16106
 
16107 92 mihad
    wishbone_slave.cycle_response( 3'b010, wb_subseq_waits, 0 ) ;
16108 15 mihad
 
16109
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
16110
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
16111
    if ( translation )
16112
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
16113
    else
16114
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
16115
 
16116
    if ( !ok )
16117
    begin
16118
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
16119
        test_fail("PCI Image Control register could not be written") ;
16120
    end
16121
 
16122
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
16123
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
16124
    if ( enable_error_report )
16125
    begin
16126
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
16127
        if ( !ok )
16128
        begin
16129
            test_fail("PCI Error Control and Status register could not be written") ;
16130
            disable main ;
16131
        end
16132
    end
16133
    else
16134
    begin
16135
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
16136
        if ( !ok )
16137
        begin
16138
            test_fail("PCI Error Control and Status register could not be written") ;
16139
            disable main ;
16140
        end
16141
    end
16142
 
16143
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
16144
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
16145
    if ( enable_error_interrupt )
16146
    begin
16147
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
16148
        if ( !ok )
16149
        begin
16150
            test_fail("Interrupt Control register could not be written") ;
16151
            disable main ;
16152
        end
16153
    end
16154
    else
16155
    begin
16156
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
16157
        if ( !ok )
16158
        begin
16159
            test_fail("Interrupt Control register could not be written") ;
16160
            disable main ;
16161
        end
16162
    end
16163
 
16164
    pci_address  = Target_Base_Addr_R[image_num] ;
16165
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
16166
 
16167
    byte_enables = 4'b1111 ;
16168
 
16169
    for ( i = 0 ; i < 4 ; i = i + 1 )
16170
    begin:loop_1
16171
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
16172
        byte_enables[i] = 0 ;
16173
        if ( i > 0 )
16174
            byte_enables[i - 1] = 1 ;
16175
 
16176
        fork
16177
        begin
16178
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
16179
            do_pause ( 1 ) ;
16180
        end
16181
        begin
16182
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
16183
            if ( wb_ok !== 1 )
16184
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
16185
 
16186 35 mihad
            #1 ;
16187
            if ( !error_monitor_done )
16188
                disable monitor_pci_error_2 ;
16189 15 mihad
        end
16190
        begin:monitor_pci_error_2
16191 35 mihad
            error_monitor_done = 0 ;
16192 15 mihad
            pci_ok = 1 ;
16193
            @(error_event_int) ;
16194
            pci_ok = 0 ;
16195
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
16196 35 mihad
            error_monitor_done = 1 ;
16197 15 mihad
        end
16198
        join
16199
 
16200
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
16201
        `ifdef HOST
16202
 
16203
            repeat ( 4 )
16204
                @( posedge wb_clock ) ;
16205
 
16206
            if ( enable_error_interrupt && enable_error_report )
16207
            begin
16208
                if ( INT_O !== 1 )
16209
                begin
16210
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
16211
                end
16212
            end
16213
            else
16214
            begin
16215
                if ( INT_O !== 0 )
16216
                begin
16217
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
16218
                end
16219
            end
16220
        `else
16221
            repeat ( 4 )
16222
                @( posedge pci_clock ) ;
16223
 
16224
            if ( enable_error_interrupt && enable_error_report )
16225
            begin
16226
                if ( INTA !== 0 )
16227
                begin
16228
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
16229
                end
16230
            end
16231
            else
16232
            begin
16233
                if ( INTA !== 1 )
16234
                begin
16235
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
16236
                end
16237
            end
16238
        `endif
16239
 
16240
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
16241
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
16242
        config_read( offset, 4'hF, read_data ) ;
16243
        ok = 1 ;
16244
        if ( enable_error_report )
16245
        begin
16246
            if ( read_data[8] !== 1 )
16247
            begin
16248
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
16249
                ok = 0 ;
16250
            end
16251
 
16252
            if ( read_data[9] !== 0 )
16253
            begin
16254
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
16255
                ok = 0 ;
16256
            end
16257
 
16258
            if ( read_data[31:28] !== byte_enables )
16259
            begin
16260
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
16261
                ok = 0 ;
16262
            end
16263
 
16264
            if ( read_data[27:24] !== `BC_IO_WRITE )
16265
            begin
16266
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
16267
                ok = 0 ;
16268
            end
16269
 
16270
            if ( ok )
16271
                test_ok ;
16272
 
16273
            test_name = "CLEAR ERROR STATUS" ;
16274
            config_write( offset, read_data, 4'hF, ok ) ;
16275
            if ( !ok )
16276
                test_fail("PCI Error Control and Status register could not be written") ;
16277
 
16278
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
16279
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
16280
            config_read ( offset, 4'hf, read_data ) ;
16281
 
16282
            if ( read_data !== expect_address )
16283
            begin
16284
                test_fail("value in Erroneous Address register was incorrect") ;
16285
                ok = 0 ;
16286
            end
16287
 
16288
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
16289
            config_read ( offset, 4'hf, read_data ) ;
16290
 
16291
            if ( read_data !== 32'hAAAA_AAAA )
16292
            begin
16293
                test_fail("value in Erroneous Data register was incorrect") ;
16294
                ok = 0 ;
16295
            end
16296
 
16297
            if ( ok )
16298
                test_ok ;
16299
 
16300
        end
16301
        else
16302
        begin
16303
            if ( read_data[8] !== 0 )
16304
            begin
16305
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
16306
                ok = 0 ;
16307
            end
16308
            else
16309
                test_ok ;
16310
        end
16311
 
16312
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
16313
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
16314
        ok = 1 ;
16315
 
16316
        config_read ( offset, 4'hF, read_data ) ;
16317
        if ( enable_error_report && enable_error_interrupt )
16318
        begin
16319
            if ( read_data[2] !== 1 )
16320
            begin
16321
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
16322
                ok = 0 ;
16323
            end
16324
 
16325
            test_name = "CLEARING INTERRUPT STATUS" ;
16326
            config_write( offset, read_data, 4'hF, ok ) ;
16327
            if ( !ok )
16328
                test_fail("Interrupt Status register could not be written") ;
16329
        end
16330
        else
16331
        begin
16332
            if ( read_data[2] !== 0 )
16333
            begin
16334
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
16335
                ok = 0 ;
16336
            end
16337
        end
16338
 
16339
        if ( ok )
16340
            test_ok ;
16341
 
16342
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
16343
        `ifdef HOST
16344
 
16345
            repeat ( 4 )
16346
                @( posedge wb_clock ) ;
16347
 
16348
            if ( INT_O !== 0 )
16349
            begin
16350
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
16351
            end
16352
            else
16353
                test_ok ;
16354
 
16355
        `else
16356
            repeat ( 4 )
16357
                @( posedge pci_clock ) ;
16358
 
16359
            if ( INTA !== 1 )
16360
            begin
16361
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
16362
            end
16363
            else
16364
                test_ok ;
16365
 
16366
        `endif
16367
 
16368
        pci_address = pci_address + 1 ;
16369
        expect_address = expect_address + 1 ;
16370
    end
16371
 
16372
end
16373
endtask // test_target_io_err_wr
16374
 
16375
task test_pci_image ;
16376
    input [2:0]  image_num ;
16377
    reg   [11:0] pci_ctrl_offset ;
16378
    reg   [11:0] ctrl_offset ;
16379
    reg   [11:0] ba_offset ;
16380
    reg   [11:0] am_offset ;
16381
    reg   [11:0] ta_offset ;
16382
    reg   [7:0]  cache_lsize ;
16383
    reg          ok ;
16384
    reg          test_io ;
16385
    reg          test_mem ;
16386
begin
16387
    pci_ctrl_offset = 12'h4 ;
16388
    if (image_num === 0)
16389
    begin
16390
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
16391
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
16392
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
16393
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
16394
    end
16395
    else if (image_num === 1)
16396
    begin
16397
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16398
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16399
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16400
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16401
    end
16402
    else if (image_num === 2)
16403
    begin
16404
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16405
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16406
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16407
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16408
    end
16409
    else if (image_num === 3)
16410
    begin
16411
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16412
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16413
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16414
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16415
    end
16416
    else if (image_num === 4)
16417
    begin
16418
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16419
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16420
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16421
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16422
    end
16423
    else if (image_num === 5)
16424
    begin
16425
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16426
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16427
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16428
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16429
    end
16430
 
16431
    `ifdef HOST
16432
        test_io  = 1 ;
16433
        test_mem = 1 ;
16434
    `else
16435
        if (image_num == 1)
16436
            test_io = `PCI_BA1_MEM_IO ;
16437
        else if ( image_num == 2 )
16438
            test_io = `PCI_BA2_MEM_IO ;
16439
        else if ( image_num == 3 )
16440
            test_io = `PCI_BA3_MEM_IO ;
16441
        else if ( image_num == 4 )
16442
            test_io = `PCI_BA4_MEM_IO ;
16443
        else if ( image_num == 5 )
16444
            test_io = `PCI_BA5_MEM_IO ;
16445
 
16446
        test_mem = !test_io ;
16447
    `endif
16448
 
16449
    $display(" ");
16450
    $display("########################################################################") ;
16451
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
16452
    test_name = "PCI IMAGE SETTINGS" ;
16453
 
16454
    // Set Base Address of IMAGE
16455
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
16456
    if ( ok !== 1 )
16457
    begin
16458
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16459
        test_fail("PCI Base Address register could not be written") ;
16460
    end
16461
 
16462
    // Set Address Mask of IMAGE
16463
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16464
    if ( ok !== 1 )
16465
    begin
16466
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16467
        test_fail("PCI Address Mask register could not be written") ;
16468
    end
16469
 
16470
    // Set Translation Address of IMAGE
16471
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16472
    if ( ok !== 1 )
16473
    begin
16474
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16475
        test_fail("PCI Translation Address register could not be written") ;
16476
    end
16477
 
16478
// Following are defines for byte enable signals !
16479
//      Byte Masks
16480
//      `Test_Byte_0                            (4'b1110)
16481
//      `Test_Byte_1                            (4'b1101)
16482
//      `Test_Byte_2                            (4'b1011)
16483
//      `Test_Byte_3                            (4'b0111)
16484
//      `Test_Half_0                            (4'b1100)
16485
//      `Test_Half_1                            (4'b0011)
16486
//      `Test_All_Bytes                         (4'b0000)
16487
 
16488
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
16489
    // Set Cache Line Size
16490
    cache_lsize = 8'h4 ;
16491
 
16492
    $display(" ");
16493
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16494
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16495
    if ( ok !== 1 )
16496
    begin
16497
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16498
        test_fail("PCI Device Control and Status register could not be written") ;
16499
    end
16500
 
16501
    if (test_mem)
16502
    begin
16503
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
16504
        // Task test_normal_wr_rd has the following parameters:
16505
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16506
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16507
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16508
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
16509 104 mihad
                            `Test_One_Word, 1'b0, 1'b0, cache_lsize, 1'b0, 1'b0 );
16510 15 mihad
 
16511
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16512
        // Set Cache Line Size
16513
        cache_lsize = 8'h4 ;
16514
 
16515
        $display(" ");
16516
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16517
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16518
        if ( ok !== 1 )
16519
        begin
16520
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16521
            test_fail("Cache Line Size register could not be written" ) ;
16522
        end
16523
 
16524
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
16525
        // Task test_normal_wr_rd has the following parameters:
16526
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16527
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16528
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16529
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
16530
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
16531
 
16532 104 mihad
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCHABLE IMAGES
16533 15 mihad
        // Set Cache Line Size
16534
        cache_lsize = 8'h8 ;
16535
 
16536
        $display(" ");
16537
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16538
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16539
        if ( ok !== 1 )
16540
        begin
16541
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16542
            test_fail("Cache Line Size register could not be written" ) ;
16543
        end
16544
 
16545
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
16546
        // Task test_normal_wr_rd has the following parameters:
16547
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16548
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16549
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16550
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
16551
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16552
 
16553
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16554
        // Set Cache Line Size
16555
        cache_lsize = 8'h4 ;
16556
 
16557
        $display(" ");
16558
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16559
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16560
        if ( ok !== 1 )
16561
        begin
16562
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16563
            test_fail("Cache Line Size register could not be written" ) ;
16564
        end
16565
 
16566
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
16567
        // Task test_normal_wr_rd has the following parameters:
16568
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16569
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16570
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16571
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
16572
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16573
 
16574
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16575
        $display(" ");
16576
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
16577
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16578
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16579
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
16580
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
16581
 
16582
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16583
        $display(" ");
16584
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
16585
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16586
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16587
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
16588
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
16589
 
16590
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16591
        $display(" ");
16592
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
16593
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16594
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16595
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
16596
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
16597
 
16598
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16599
        $display(" ");
16600
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
16601
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16602
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16603
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
16604
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
16605
    end
16606
 
16607
    if ( test_io )
16608
    begin
16609
        test_name = "PCI IMAGE SETTINGS" ;
16610
 
16611
        // Set Base Address of IMAGE
16612
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
16613
        if ( ok !== 1 )
16614
        begin
16615
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16616
            test_fail("PCI Base Address register could not be written") ;
16617
        end
16618
 
16619
        // Set Address Mask of IMAGE
16620
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16621
        if ( ok !== 1 )
16622
        begin
16623
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16624
            test_fail("PCI Address Mask register could not be written") ;
16625
        end
16626
 
16627
        // Set Translation Address of IMAGE
16628
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16629
        if ( ok !== 1 )
16630
        begin
16631
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16632
            test_fail("PCI Translation Address register could not be written") ;
16633
        end
16634
 
16635
        // Set Cache Line Size
16636
        cache_lsize = 8'h4 ;
16637
 
16638
        $display(" ");
16639
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16640
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16641
        if ( ok !== 1 )
16642
        begin
16643
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16644
            test_fail("Cache Line Size register could not be written" ) ;
16645
        end
16646
 
16647
        test_target_io_wr_rd
16648
        (
16649
            image_num,    // image number
16650
            0,            // test with address translation
16651
            ctrl_offset   // image control register offset
16652
        ) ;
16653
 
16654
        test_target_io_wr_rd
16655
        (
16656
            image_num,    // image number
16657
            1,            // test with address translation
16658
            ctrl_offset   // image control register offset
16659
        ) ;
16660
 
16661
        test_target_io_err_wr
16662
        (
16663
            image_num,      // image number
16664
            0,              // address translation on/off
16665
            ctrl_offset,    // image control register offset
16666
            0,              // enable error reporting
16667
 
16668
        ) ;
16669
 
16670
        test_target_io_err_wr
16671
        (
16672
            image_num,      // image number
16673
            1,              // address translation on/off
16674
            ctrl_offset,    // image control register offset
16675
            0,              // enable error reporting
16676
            1               // enable error interrupts
16677
        ) ;
16678
 
16679
        test_target_io_err_wr
16680
        (
16681
            image_num,      // image number
16682
            0,              // address translation on/off
16683
            ctrl_offset,    // image control register offset
16684
            1,              // enable error reporting
16685
 
16686
        ) ;
16687
 
16688
        test_target_io_err_wr
16689
        (
16690
            image_num,      // image number
16691
            1,              // address translation on/off
16692
            ctrl_offset,    // image control register offset
16693
            1,              // enable error reporting
16694
            1               // enable error interrupts
16695
        ) ;
16696
    end
16697
 
16698
    // Test master abort with NON supported commands
16699
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16700
 
16701
    // disable the image
16702 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16703 15 mihad
end
16704
endtask //test_pci_image
16705
 
16706
task target_fast_back_to_back ;
16707
    reg   [11:0] pci_ctrl_offset ;
16708
    reg   [11:0] ctrl_offset ;
16709
    reg   [11:0] ba_offset ;
16710
    reg   [11:0] am_offset ;
16711
    reg   [11:0] ta_offset ;
16712
    reg   [11:0] cls_offset ;
16713
    reg          do_mem_fb2b ;
16714
    reg          do_io_fb2b ;
16715
    reg          ok ;
16716
begin:main
16717
 
16718
    if ( target_mem_image !== -1 )
16719
    begin
16720
        do_mem_fb2b = 1 ;
16721
 
16722
        if (target_mem_image === 1)
16723
        begin
16724
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16725
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16726
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16727
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16728
        end
16729
        else if (target_mem_image === 2)
16730
        begin
16731
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16732
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16733
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16734
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16735
        end
16736
        else if (target_mem_image === 3)
16737
        begin
16738
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16739
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16740
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16741
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16742
        end
16743
        else if (target_mem_image === 4)
16744
        begin
16745
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16746
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16747
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16748
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16749
        end
16750
        else if (target_mem_image === 5)
16751
        begin
16752
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16753
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16754
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16755
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16756
        end
16757
    end
16758
    else
16759
        do_mem_fb2b = 0 ;
16760
 
16761
    pci_ctrl_offset = 12'h4 ;
16762
    cls_offset      = 12'h00C ;
16763
 
16764
    if ( do_mem_fb2b )
16765
    begin
16766
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16767
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16768
        if ( ok !== 1 )
16769
        begin
16770
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16771
            test_fail("PCI Base Address register could not be written") ;
16772
            disable main ;
16773
        end
16774
 
16775
        // Set Address Mask of IMAGE
16776
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16777
        if ( ok !== 1 )
16778
        begin
16779
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16780
            test_fail("PCI Address Mask register could not be written") ;
16781
            disable main ;
16782
        end
16783
 
16784
        // Set Translation Address of IMAGE
16785
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16786
        if ( ok !== 1 )
16787
        begin
16788
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16789
            test_fail("PCI Translation Address Register could not be written") ;
16790
            disable main ;
16791
        end
16792
 
16793
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16794
        if ( ok !== 1 )
16795
        begin
16796
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16797
            test_fail("PCI Image Control register could not be written") ;
16798
            disable main ;
16799
        end
16800
 
16801
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16802
        if ( ok !== 1 )
16803
        begin
16804
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16805
            test_fail("Cache Line Size register could not be written") ;
16806
            disable main ;
16807
        end
16808
 
16809
        // enable master 1 fast_b2b
16810 45 mihad
        configuration_cycle_write(0,                        // bus number
16811
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16812
                                  0,                        // function number
16813
                                  1,                        // register number
16814
                                  0,                        // type of configuration cycle
16815
                                  4'b1111,                  // byte enables
16816
                                  32'hFFFF_FFFF             // data
16817 15 mihad
                                 ) ;
16818
 
16819 92 mihad
        wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 0) ;
16820 15 mihad
 
16821
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16822
        fork
16823
        begin
16824
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16825
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16826
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16827
                  0, `Test_One_Zero_Target_WS,
16828
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16829
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16830
 
16831
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16832
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16833
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16834
                  0, `Test_One_Zero_Target_WS,
16835
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16836
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16837
 
16838 92 mihad
            do_pause(1) ;
16839
 
16840 15 mihad
        end
16841
        begin:wb_monitor1
16842 92 mihad
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, 0, 1'b1, ok) ;
16843
 
16844
            if ( ok !== 1 )
16845
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16846
 
16847
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
16848
 
16849 15 mihad
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16850
            if ( ok !== 1 )
16851
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16852
 
16853
            disable monitor_error_event1 ;
16854
        end
16855
        begin:monitor_error_event1
16856
            @(error_event_int) ;
16857
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16858
            ok = 0 ;
16859
            disable wb_monitor1 ;
16860
        end
16861
        join
16862
 
16863
        if ( ok )
16864
            test_ok ;
16865
 
16866
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16867 92 mihad
        wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 0) ;
16868 15 mihad
        fork
16869
        begin
16870
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16871
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16872
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16873
                  0, `Test_One_Zero_Target_WS,
16874
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16875
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16876
 
16877
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16878
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16879
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16880
                  0, `Test_One_Zero_Target_WS,
16881
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16882
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16883
 
16884 92 mihad
            do_pause(1) ;
16885 15 mihad
 
16886
        end
16887
        begin:wb_monitor2
16888 92 mihad
 
16889
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, 0, 1'b1, ok) ;
16890
 
16891
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
16892
 
16893 15 mihad
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16894
            if ( ok !== 1 )
16895
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16896
            else
16897
            begin
16898
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16899
                if ( ok !== 1 )
16900
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16901
            end
16902
 
16903
            disable monitor_error_event2 ;
16904
        end
16905
        begin:monitor_error_event2
16906
            @(error_event_int) ;
16907
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16908
            ok = 0 ;
16909
            disable wb_monitor2 ;
16910
        end
16911
        join
16912
 
16913
        if ( ok )
16914
            test_ok ;
16915
 
16916
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16917 92 mihad
        wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 0) ;
16918 15 mihad
        fork
16919
        begin
16920
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16921
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16922
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16923
                  0, `Test_One_Zero_Target_WS,
16924
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16925
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16926
 
16927
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16928
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16929
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16930
                  0, `Test_One_Zero_Target_WS,
16931
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16932
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16933
 
16934 92 mihad
            do_pause(1) ;
16935
 
16936 15 mihad
        end
16937
        begin:wb_monitor3
16938 92 mihad
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, 0, 1'b1, ok) ;
16939
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
16940 15 mihad
            fork
16941
            begin
16942
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16943
                if ( ok !== 1 )
16944
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16945
            end
16946
            begin
16947
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16948
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16949
                if ( ok !== 1 )
16950
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16951
            end
16952
            join
16953
 
16954
            if ( ok )
16955
            begin
16956
                fork
16957
                begin
16958
                    do_pause(3) ;
16959
 
16960
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16961
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16962
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16963
                        0, `Test_One_Zero_Target_WS,
16964
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16965
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16966
 
16967
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16968
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16969
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16970
                            0, `Test_One_Zero_Target_WS,
16971
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16972
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16973
 
16974
                    do_pause(1) ;
16975
                end
16976
                begin
16977
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16978
                    if ( ok !== 1 )
16979
                    begin
16980
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16981
                        disable monitor_error_event3 ;
16982
                    end
16983
                    else
16984
                    begin
16985
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16986
                        if ( ok !== 1 )
16987
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16988
                    end
16989
                end
16990 26 mihad
                begin
16991
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16992
                        if ( ok !== 1 )
16993
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16994
                end
16995 15 mihad
                join
16996
            end
16997
            disable monitor_error_event3 ;
16998
        end
16999
        begin:monitor_error_event3
17000
            @(error_event_int) ;
17001
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
17002
            ok = 0 ;
17003
            disable wb_monitor3 ;
17004
        end
17005
        join
17006
 
17007
        if ( ok )
17008
            test_ok ;
17009
 
17010
        test_name = "DISABLING MEM IMAGE" ;
17011 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17012 15 mihad
        if ( ok !== 1 )
17013
        begin
17014
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17015
            test_fail("PCI Address Mask register could not be written") ;
17016
            disable main ;
17017
        end
17018
    end
17019
 
17020
    if ( target_io_image !== -1 )
17021
    begin
17022
        do_io_fb2b = 1 ;
17023
 
17024
        if (target_io_image === 1)
17025
        begin
17026
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17027
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17028
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17029
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17030
        end
17031
        else if (target_io_image === 2)
17032
        begin
17033
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17034
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17035
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17036
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17037
        end
17038
        else if (target_io_image === 3)
17039
        begin
17040
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17041
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17042
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17043
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17044
        end
17045
        else if (target_io_image === 4)
17046
        begin
17047
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17048
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17049
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17050
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17051
        end
17052
        else if (target_io_image === 5)
17053
        begin
17054
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17055
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17056
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17057
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17058
        end
17059
    end
17060
    else
17061
        do_io_fb2b = 0 ;
17062
 
17063
    if ( do_io_fb2b )
17064
    begin
17065
 
17066
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
17067
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17068
        if ( ok !== 1 )
17069
        begin
17070
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17071
            test_fail("PCI Base Address register could not be written") ;
17072
            disable main ;
17073
        end
17074
 
17075
        // Set Address Mask of IMAGE
17076
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17077
        if ( ok !== 1 )
17078
        begin
17079
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17080
            test_fail("PCI Address Mask register could not be written") ;
17081
            disable main ;
17082
        end
17083
 
17084
        // Set Translation Address of IMAGE
17085
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17086
        if ( ok !== 1 )
17087
        begin
17088
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17089
            test_fail("PCI Translation Address Register could not be written") ;
17090
            disable main ;
17091
        end
17092
 
17093
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17094
        if ( ok !== 1 )
17095
        begin
17096
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17097
            test_fail("PCI Image Control register could not be written") ;
17098
            disable main ;
17099
        end
17100
 
17101
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
17102
        if ( ok !== 1 )
17103
        begin
17104
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17105
            test_fail("Cache Line Size register could not be written") ;
17106
            disable main ;
17107
        end
17108
 
17109
        // enable master 1 fast_b2b
17110 45 mihad
        configuration_cycle_write(0,                        // bus number
17111
                                  `TAR1_IDSEL_INDEX - 11,   // device number
17112
                                  0,                        // function number
17113
                                  1,                        // register number
17114
                                  0,                        // type of configuration cycle
17115
                                  4'b1111,                  // byte enables
17116
                                  32'hFFFF_FFFF             // data
17117 15 mihad
                                 ) ;
17118
 
17119 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
17120 15 mihad
 
17121
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
17122
        fork
17123
        begin
17124
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
17125
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
17126
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17127
                  0, `Test_One_Zero_Target_WS,
17128
                  `Test_Devsel_Medium, `Test_Fast_B2B,
17129
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
17130
 
17131
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
17132
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
17133
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17134
                  0, `Test_One_Zero_Target_WS,
17135
                  `Test_Devsel_Medium, `Test_Fast_B2B,
17136
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
17137
 
17138 92 mihad
            do_pause(1) ;
17139
 
17140 15 mihad
        end
17141
        begin:wb_monitor4
17142
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
17143
            if ( ok !== 1 )
17144
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
17145
 
17146
            if ( ok )
17147
            begin
17148
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
17149
                if ( ok !== 1 )
17150
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
17151
            end
17152
 
17153
            disable monitor_error_event4 ;
17154
        end
17155
        begin:monitor_error_event4
17156
            @(error_event_int) ;
17157
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
17158
            ok = 0 ;
17159
            disable wb_monitor4 ;
17160
        end
17161
        join
17162
 
17163
        if ( ok )
17164
            test_ok ;
17165
 
17166
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
17167 92 mihad
        wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 0) ;
17168 15 mihad
        fork
17169
        begin
17170
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
17171
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
17172
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17173
                  0, `Test_One_Zero_Target_WS,
17174
                  `Test_Devsel_Medium, `Test_Fast_B2B,
17175
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
17176
 
17177
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
17178
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
17179
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17180
                  0, `Test_One_Zero_Target_WS,
17181
                  `Test_Devsel_Medium, `Test_Fast_B2B,
17182
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17183 92 mihad
 
17184
            do_pause(1) ;
17185
 
17186 15 mihad
        end
17187
        begin:wb_monitor5
17188 92 mihad
 
17189
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 0, 1'b1, ok) ;
17190
 
17191
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
17192
 
17193 15 mihad
            fork
17194
            begin
17195
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
17196
                if ( ok !== 1 )
17197
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
17198
            end
17199
            begin
17200
                wb_transaction_stop( 1 ) ;
17201
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
17202
                if ( ok !== 1 )
17203
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
17204
            end
17205
            join
17206
 
17207
            if ( ok )
17208
            begin
17209
                fork
17210
                begin
17211
                    do_pause(3) ;
17212
 
17213
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
17214
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
17215
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17216
                            0, `Test_One_Zero_Target_WS,
17217
                            `Test_Devsel_Medium, `Test_Fast_B2B,
17218
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
17219
 
17220
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
17221
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
17222
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17223
                            0, `Test_One_Zero_Target_WS,
17224
                            `Test_Devsel_Medium, `Test_Fast_B2B,
17225
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
17226
 
17227
                    do_pause(1) ;
17228
                end
17229
                begin
17230
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
17231
                    if ( ok !== 1 )
17232
                    begin
17233
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
17234
                        disable monitor_error_event5 ;
17235
                    end
17236
                    else
17237
                    begin
17238
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
17239
                        if ( ok !== 1 )
17240
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
17241
                    end
17242
                end
17243
                join
17244
            end
17245
            disable monitor_error_event5 ;
17246
        end
17247
        begin:monitor_error_event5
17248
            @(error_event_int) ;
17249
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
17250
            ok = 0 ;
17251
            disable wb_monitor5 ;
17252
        end
17253
        join
17254
 
17255
        if ( ok )
17256
            test_ok ;
17257
 
17258
        test_name = "DISABLING IO IMAGE" ;
17259 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17260 15 mihad
        if ( ok !== 1 )
17261
        begin
17262
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17263
            test_fail("PCI Address Mask register could not be written") ;
17264
            disable main ;
17265
        end
17266
    end
17267
 
17268
end
17269
endtask //target_fast_back_to_back
17270
 
17271
task target_disconnects ;
17272
    reg   [11:0] pci_ctrl_offset ;
17273
    reg   [11:0] ctrl_offset ;
17274
    reg   [11:0] ba_offset ;
17275
    reg   [11:0] am_offset ;
17276
    reg   [11:0] ta_offset ;
17277
    reg   [11:0] cls_offset ;
17278
    reg          pci_ok ;
17279
    reg          wb_ok ;
17280
    reg          ok ;
17281
    reg   [31:0] pci_address ;
17282
    reg   [31:0] data ;
17283
    reg   [3:0]  byte_enables ;
17284
    reg   [9:0]  expect_length ;
17285
 
17286
    reg          do_mem_disconnects ;
17287
    reg          do_io_disconnects ;
17288 35 mihad
    reg          error_monitor_done ;
17289 15 mihad
begin:main
17290
    if ( target_mem_image !== -1 )
17291
    begin
17292
        do_mem_disconnects = 1 ;
17293
 
17294
        if (target_mem_image === 1)
17295
        begin
17296
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17297
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17298
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17299
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17300
        end
17301
        else if (target_mem_image === 2)
17302
        begin
17303
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17304
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17305
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17306
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17307
        end
17308
        else if (target_mem_image === 3)
17309
        begin
17310
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17311
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17312
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17313
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17314
        end
17315
        else if (target_mem_image === 4)
17316
        begin
17317
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17318
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17319
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17320
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17321
        end
17322
        else if (target_mem_image === 5)
17323
        begin
17324
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17325
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17326
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17327
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17328
        end
17329
    end
17330
    else
17331
        do_mem_disconnects = 0 ;
17332
 
17333
    pci_ctrl_offset = 12'h4 ;
17334
    cls_offset = 12'h00C ;
17335
 
17336
    master1_check_received_data = 0 ;
17337
    master2_check_received_data = 0 ;
17338
 
17339
    `ifdef HOST
17340
        `ifdef NO_CNF_IMAGE
17341
        `else
17342
            `define TEST_BURST_CONFIG_READ
17343
        `endif
17344
    `else
17345
        `define TEST_BURST_CONFIG_READ
17346
        `define TEST_BURST_CONFIG_WRITE
17347
    `endif
17348
 
17349
    `ifdef TEST_BURST_CONFIG_WRITE
17350
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
17351
 
17352
        data = 32'h0000_08_08 ;
17353
 
17354 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
17355 15 mihad
        byte_enables = 4'b0000 ;
17356
 
17357
        fork
17358
        begin
17359
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17360
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17361
                    byte_enables,
17362
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17363
                    8'h0_0, `Test_One_Zero_Target_WS,
17364
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17365
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17366
 
17367
            data = 32'h0000_04_04 ;
17368
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17369
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17370
                    byte_enables,
17371
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17372
                    8'h0_0, `Test_One_Zero_Target_WS,
17373
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17374
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17375
            do_pause( 1 ) ;
17376
            while ( FRAME !== 1 || IRDY !== 1 )
17377
                @(posedge pci_clock) ;
17378
 
17379 35 mihad
            #1 ;
17380
            if ( !error_monitor_done )
17381
                disable monitor_error_event1 ;
17382 15 mihad
        end
17383
        begin:monitor_error_event1
17384 35 mihad
            error_monitor_done = 0 ;
17385 15 mihad
            ok = 1 ;
17386
            @(error_event_int) ;
17387
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17388
            ok = 0 ;
17389 35 mihad
            error_monitor_done = 1 ;
17390 15 mihad
        end
17391
        join
17392
 
17393
        config_read(pci_address, 4'hF, data) ;
17394
        if ( data [15:0] !== 16'h04_04 )
17395
        begin
17396
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
17397
        end
17398
        else if ( ok )
17399
            test_ok ;
17400
 
17401 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
17402
 
17403
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
17404 15 mihad
        data         = 32'h0000_0808 ;
17405
        byte_enables = 4'h0 ;
17406
        fork
17407
        begin
17408
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17409
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
17410
                    byte_enables,
17411
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17412
                    8'h0_0, `Test_One_Zero_Target_WS,
17413
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17414
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17415
 
17416
            data = 32'h0000_04_04 ;
17417
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17418
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
17419
                    byte_enables,
17420
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17421
                    8'h0_0, `Test_One_Zero_Target_WS,
17422
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17423
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17424
 
17425
            do_pause( 1 ) ;
17426
            while ( FRAME !== 1 || IRDY !== 1 )
17427
                @(posedge pci_clock) ;
17428
 
17429 35 mihad
            #1 ;
17430
            if ( !error_monitor_done )
17431
                disable monitor_error_event2 ;
17432 15 mihad
        end
17433
        begin:monitor_error_event2
17434 35 mihad
            error_monitor_done = 0 ;
17435 15 mihad
            ok = 1 ;
17436
            @(error_event_int) ;
17437
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17438
            ok = 0 ;
17439 35 mihad
            error_monitor_done = 1 ;
17440 15 mihad
        end
17441
        join
17442
 
17443
        config_read(pci_address, 4'hF, data) ;
17444
        if ( data [15:0] !== 16'h04_04 )
17445
        begin
17446
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
17447
        end
17448
        else if ( ok )
17449
            test_ok ;
17450
    `endif
17451
 
17452
    `ifdef TEST_BURST_CONFIG_READ
17453
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
17454
 
17455
        data = 32'h0000_04_04 ;
17456
 
17457 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
17458 15 mihad
        byte_enables = 4'b0000 ;
17459
 
17460
        fork
17461
        begin
17462
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17463
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
17464
                    byte_enables,
17465
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17466
                    8'h0_0, `Test_One_Zero_Target_WS,
17467
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17468
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17469
            do_pause( 1 ) ;
17470
 
17471
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17472
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
17473
                    byte_enables,
17474
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17475
                    8'h0_0, `Test_One_Zero_Target_WS,
17476
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17477
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17478
            do_pause( 1 ) ;
17479
 
17480
            while ( FRAME !== 1 || IRDY !== 1 )
17481
                @(posedge pci_clock) ;
17482
 
17483 35 mihad
            if ( !error_monitor_done )
17484
                disable monitor_error_event3 ;
17485 15 mihad
        end
17486
        begin:monitor_error_event3
17487 35 mihad
            error_monitor_done = 0 ;
17488 15 mihad
            ok = 1 ;
17489
            @(error_event_int) ;
17490
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17491
            ok = 0 ;
17492 35 mihad
            error_monitor_done = 1 ;
17493 15 mihad
        end
17494
        join
17495
 
17496
        if ( ok )
17497
            test_ok ;
17498
 
17499 45 mihad
 
17500
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
17501
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
17502 15 mihad
        fork
17503
        begin
17504
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17505
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17506
                    byte_enables,
17507
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17508
                    8'h0_0, `Test_One_Zero_Target_WS,
17509
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17510
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17511
            do_pause( 1 ) ;
17512
 
17513
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17514
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17515
                    byte_enables,
17516
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17517
                    8'h0_0, `Test_One_Zero_Target_WS,
17518
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17519
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17520
            do_pause( 1 ) ;
17521
 
17522
            while ( FRAME !== 1 || IRDY !== 1 )
17523
                @(posedge pci_clock) ;
17524
 
17525 35 mihad
            #1 ;
17526
            if ( !error_monitor_done )
17527
                disable monitor_error_event4 ;
17528 15 mihad
        end
17529
        begin:monitor_error_event4
17530 35 mihad
            error_monitor_done = 0 ;
17531 15 mihad
            ok = 1 ;
17532
            @(error_event_int) ;
17533
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17534
            ok = 0 ;
17535 35 mihad
            error_monitor_done = 1 ;
17536 15 mihad
        end
17537
        join
17538
 
17539
        if ( ok )
17540
            test_ok ;
17541
    `endif
17542
 
17543
    `ifdef TEST_BURST_CONFIG_READ
17544
        `undef TEST_BURST_CONFIG_READ
17545
    `endif
17546
 
17547
    `ifdef TEST_BURST_CONFIG_WRITE
17548
        `undef TEST_BURST_CONFIG_WRITE
17549
    `endif
17550
 
17551
    master1_check_received_data = 1 ;
17552
    master2_check_received_data = 1 ;
17553
 
17554
    if ( do_mem_disconnects )
17555
    begin
17556
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17557
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
17558
        if ( ok !== 1 )
17559
        begin
17560
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17561
            test_fail("PCI Base Address register could not be written") ;
17562
            disable main ;
17563
        end
17564
 
17565
        // Set Address Mask of IMAGE
17566
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
17567
        if ( ok !== 1 )
17568
        begin
17569
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17570
            test_fail("PCI Address Mask register could not be written") ;
17571
            disable main ;
17572
        end
17573
 
17574
        // Set Translation Address of IMAGE
17575
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
17576
        if ( ok !== 1 )
17577
        begin
17578
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17579
            test_fail("PCI Translation Address Register could not be written") ;
17580
            disable main ;
17581
        end
17582
 
17583
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17584
        if ( ok !== 1 )
17585
        begin
17586
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17587
            test_fail("PCI Image Control register could not be written") ;
17588
            disable main ;
17589
        end
17590
 
17591
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17592
        if ( ok !== 1 )
17593
        begin
17594
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17595
            test_fail("Cache Line Size register could not be written") ;
17596
            disable main ;
17597
        end
17598
 
17599
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17600
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17601
        data = 32'hAAAA_AAAA ;
17602
        byte_enables = 4'h0 ;
17603
        expect_length = `PCIW_DEPTH - 2 ;
17604
 
17605 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
17606 15 mihad
        fork
17607
        begin
17608
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17609
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17610
                        byte_enables,
17611 73 mihad
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17612 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17613
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17614 73 mihad
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17615 15 mihad
            do_pause( 3 ) ;
17616
 
17617
            while ( FRAME !== 1 || IRDY !== 1 )
17618
                @(posedge pci_clock) ;
17619
 
17620 35 mihad
            #1 ;
17621
            if ( !error_monitor_done )
17622
                disable monitor_error_event5 ;
17623 15 mihad
        end
17624
        begin:monitor_error_event5
17625 35 mihad
            error_monitor_done = 0 ;
17626 15 mihad
            pci_ok = 1 ;
17627
            @(error_event_int) ;
17628
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17629
            pci_ok = 0 ;
17630 35 mihad
            error_monitor_done = 1 ;
17631 15 mihad
        end
17632
        begin
17633
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17634
            if ( wb_ok !== 1 )
17635
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17636
        end
17637
        join
17638
 
17639
        if ( wb_ok && pci_ok )
17640
            test_ok ;
17641
 
17642
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17643
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17644
        data = 32'hAAAA_AAAA ;
17645
        byte_enables = 4'h0 ;
17646
        expect_length = `PCIW_DEPTH - 2 ;
17647
 
17648 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
17649 15 mihad
        fork
17650
        begin
17651
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17652
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17653
                        byte_enables,
17654 73 mihad
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17655 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17656
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17657 73 mihad
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17658 15 mihad
            do_pause( 3 ) ;
17659
 
17660
            while ( FRAME !== 1 || IRDY !== 1 )
17661
                @(posedge pci_clock) ;
17662
 
17663 35 mihad
            #1 ;
17664
            if ( !error_monitor_done )
17665
                disable monitor_error_event6 ;
17666 15 mihad
        end
17667
        begin:monitor_error_event6
17668 35 mihad
            error_monitor_done = 0 ;
17669 15 mihad
            pci_ok = 1 ;
17670
            @(error_event_int) ;
17671
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17672
            pci_ok = 0 ;
17673 35 mihad
            error_monitor_done = 1 ;
17674 15 mihad
        end
17675
        begin
17676
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17677
            if ( wb_ok !== 1 )
17678
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17679
        end
17680
        join
17681
 
17682
        if ( wb_ok && pci_ok )
17683
            test_ok ;
17684
 
17685
        master1_check_received_data = 1 ;
17686
//        master2_check_received_data = 0 ;
17687
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17688
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17689
        data = 32'hAAAA_AAAA ;
17690
        byte_enables = 4'h0 ;
17691
        expect_length = 4 ;
17692
 
17693
        fork
17694
        begin
17695
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17696
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17697
                        byte_enables,
17698
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17699
                        8'h0_0, `Test_One_Zero_Target_WS,
17700
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17701
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17702
            do_pause( 1 ) ;
17703
 
17704
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17705
            if ( wb_ok !== 1 )
17706
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17707
 
17708
            do_pause(2) ;
17709
 
17710
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17711
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17712
                        byte_enables,
17713
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17714
                        8'h0_0, `Test_One_Zero_Target_WS,
17715
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17716 92 mihad
                        (pci_subseq_waits == 0) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17717 15 mihad
            do_pause( 3 ) ;
17718
 
17719
            while ( FRAME !== 1 || IRDY !== 1 )
17720
                @(posedge pci_clock) ;
17721
 
17722 35 mihad
            #1 ;
17723
            if ( !error_monitor_done )
17724
                disable monitor_error_event7 ;
17725 15 mihad
        end
17726
        begin:monitor_error_event7
17727 35 mihad
            error_monitor_done = 0 ;
17728 15 mihad
            pci_ok = 1 ;
17729
            @(error_event_int) ;
17730
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17731
            pci_ok = 0 ;
17732 35 mihad
            error_monitor_done = 1 ;
17733 15 mihad
        end
17734
        join
17735
 
17736
        if ( wb_ok && pci_ok )
17737
            test_ok ;
17738
 
17739
        master1_check_received_data = 1 ;
17740
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17741
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17742
        data = 32'hAAAA_AAAA ;
17743
        byte_enables = 4'h0 ;
17744
        expect_length = 4 ;
17745
 
17746
        fork
17747
        begin
17748
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17749
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17750
                        byte_enables,
17751
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17752
                        8'h0_0, `Test_One_Zero_Target_WS,
17753
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17754
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17755
            do_pause( 1 ) ;
17756
 
17757
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17758
            if ( wb_ok !== 1 )
17759
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17760
 
17761
            do_pause(2) ;
17762
 
17763
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17764
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17765
                        byte_enables,
17766
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17767
                        8'h0_0, `Test_One_Zero_Target_WS,
17768
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17769
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17770
            do_pause( 3 ) ;
17771
 
17772
            while ( FRAME !== 1 || IRDY !== 1 )
17773
                @(posedge pci_clock) ;
17774
 
17775 35 mihad
            #1 ;
17776
            if ( !error_monitor_done )
17777
                disable monitor_error_event8 ;
17778 15 mihad
        end
17779
        begin:monitor_error_event8
17780 35 mihad
            error_monitor_done = 0 ;
17781 15 mihad
            pci_ok = 1 ;
17782
            @(error_event_int) ;
17783
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17784
            pci_ok = 0 ;
17785 35 mihad
            error_monitor_done = 1 ;
17786 15 mihad
        end
17787
        join
17788
 
17789
        if ( wb_ok && pci_ok )
17790
            test_ok ;
17791
 
17792
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17793
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17794
        data = 32'hDEAF_BEAF ;
17795
        byte_enables = 4'h0 ;
17796
        expect_length = 1 ;
17797
 
17798
        fork
17799
        begin
17800
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17801
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17802
                        byte_enables,
17803
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17804
                        8'h0_0, `Test_One_Zero_Target_WS,
17805
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17806
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17807
            do_pause( 3 ) ;
17808
 
17809
            while ( FRAME !== 1 || IRDY !== 1 )
17810
                @(posedge pci_clock) ;
17811
 
17812 35 mihad
            #1 ;
17813
            if ( !error_monitor_done )
17814
                disable monitor_error_event9 ;
17815 15 mihad
        end
17816
        begin:monitor_error_event9
17817 35 mihad
            error_monitor_done = 0 ;
17818 15 mihad
            pci_ok = 1 ;
17819
            @(error_event_int) ;
17820
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17821
            pci_ok = 0 ;
17822 35 mihad
            error_monitor_done = 1 ;
17823 15 mihad
        end
17824
        begin
17825
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17826
            if ( wb_ok !== 1 )
17827
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17828
        end
17829
        join
17830
 
17831
        if ( wb_ok && pci_ok )
17832
            test_ok ;
17833
 
17834
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17835
        data = 32'hDEAD_BEAF ;
17836
        byte_enables = 4'h0 ;
17837
        expect_length = 1 ;
17838
 
17839
        fork
17840
        begin
17841
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17842
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17843
                        byte_enables,
17844
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17845
                        8'h0_0, `Test_One_Zero_Target_WS,
17846
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17847
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17848
            do_pause( 3 ) ;
17849
 
17850
            while ( FRAME !== 1 || IRDY !== 1 )
17851
                @(posedge pci_clock) ;
17852
 
17853 35 mihad
            #1 ;
17854
            if ( !error_monitor_done )
17855
                disable monitor_error_event10 ;
17856 15 mihad
        end
17857
        begin:monitor_error_event10
17858 35 mihad
            error_monitor_done = 0 ;
17859 15 mihad
            pci_ok = 1 ;
17860
            @(error_event_int) ;
17861
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17862
            pci_ok = 0 ;
17863 35 mihad
            error_monitor_done = 1 ;
17864 15 mihad
        end
17865
        begin
17866
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17867
            if ( wb_ok !== 1 )
17868
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17869
        end
17870
        join
17871
 
17872
        if ( wb_ok && pci_ok )
17873
            test_ok ;
17874
 
17875
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17876
        data = 32'hAAAA_AAAA ;
17877
        byte_enables = 4'h0 ;
17878
        expect_length = 1 ;
17879
 
17880
        fork
17881
        begin
17882
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17883
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17884
                        byte_enables,
17885
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17886
                        8'h0_0, `Test_One_Zero_Target_WS,
17887
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17888
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17889
            do_pause( 3 ) ;
17890
 
17891
            while ( FRAME !== 1 || IRDY !== 1 )
17892
                @(posedge pci_clock) ;
17893
 
17894 35 mihad
            #1 ;
17895
            if ( !error_monitor_done )
17896
                disable monitor_error_event11 ;
17897 15 mihad
        end
17898
        begin:monitor_error_event11
17899 35 mihad
            error_monitor_done = 0 ;
17900 15 mihad
            pci_ok = 1 ;
17901
            @(error_event_int) ;
17902
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17903
            pci_ok = 0 ;
17904 35 mihad
            error_monitor_done = 1 ;
17905 15 mihad
        end
17906
        begin
17907
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17908
            if ( wb_ok !== 1 )
17909
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17910
        end
17911
        join
17912
 
17913
        if ( wb_ok && pci_ok )
17914
            test_ok ;
17915
 
17916
        master1_check_received_data = 1 ;
17917
 
17918
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17919
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17920
        data = 32'hDEAF_BEAF ;
17921
        byte_enables = 4'h0 ;
17922
        expect_length = 1 ;
17923
 
17924
        fork
17925
        begin
17926
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17927
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17928
                        byte_enables,
17929
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17930
                        8'h0_0, `Test_One_Zero_Target_WS,
17931
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17932
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17933
            do_pause( 1 ) ;
17934
 
17935
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17936
            if ( wb_ok !== 1 )
17937
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17938
 
17939
            do_pause(3) ;
17940
 
17941
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17942
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17943
                        byte_enables,
17944
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17945
                        8'h0_0, `Test_One_Zero_Target_WS,
17946
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17947
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17948
            do_pause( 3 ) ;
17949
 
17950
            while ( FRAME !== 1 || IRDY !== 1 )
17951
                @(posedge pci_clock) ;
17952
 
17953 35 mihad
            #1 ;
17954
            if ( !error_monitor_done )
17955
                disable monitor_error_event12 ;
17956 15 mihad
        end
17957
        begin:monitor_error_event12
17958 35 mihad
            error_monitor_done = 0 ;
17959 15 mihad
            pci_ok = 1 ;
17960
            @(error_event_int) ;
17961
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17962
            pci_ok = 0 ;
17963 35 mihad
            error_monitor_done = 1 ;
17964 15 mihad
        end
17965
        join
17966
 
17967
        if ( wb_ok && pci_ok )
17968
            test_ok ;
17969
 
17970
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17971
        data = 32'hDEAD_BEAF ;
17972
        byte_enables = 4'h0 ;
17973
        expect_length = 1 ;
17974
 
17975
        fork
17976
        begin
17977
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17978
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17979
                        byte_enables,
17980
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17981
                        8'h0_0, `Test_One_Zero_Target_WS,
17982
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17983
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17984
            do_pause( 1 ) ;
17985
 
17986
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17987
            if ( wb_ok !== 1 )
17988
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17989
 
17990
            do_pause(3) ;
17991
 
17992
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17993
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17994
                        byte_enables,
17995
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17996
                        8'h0_0, `Test_One_Zero_Target_WS,
17997
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17998
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17999
            do_pause( 3 ) ;
18000
 
18001
            while ( FRAME !== 1 || IRDY !== 1 )
18002
                @(posedge pci_clock) ;
18003
 
18004 35 mihad
            #1 ;
18005
            if ( !error_monitor_done )
18006
                disable monitor_error_event13 ;
18007 15 mihad
        end
18008
        begin:monitor_error_event13
18009 35 mihad
            error_monitor_done = 0 ;
18010 15 mihad
            pci_ok = 1 ;
18011
            @(error_event_int) ;
18012
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
18013
            pci_ok = 0 ;
18014 35 mihad
            error_monitor_done = 1 ;
18015 15 mihad
        end
18016
        join
18017
 
18018
        if ( wb_ok && pci_ok )
18019
            test_ok ;
18020
 
18021
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
18022
        data = 32'hAAAA_AAAA ;
18023
        byte_enables = 4'h0 ;
18024
        expect_length = 1 ;
18025
 
18026
        fork
18027
        begin
18028
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
18029
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
18030
                        byte_enables,
18031
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18032
                        8'h0_0, `Test_One_Zero_Target_WS,
18033
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
18034
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
18035
            do_pause( 1 ) ;
18036
 
18037
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
18038
            if ( wb_ok !== 1 )
18039
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
18040
 
18041
            do_pause(3) ;
18042
 
18043
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
18044
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
18045
                        byte_enables,
18046
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18047
                        8'h0_0, `Test_One_Zero_Target_WS,
18048
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
18049
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
18050
            do_pause( 3 ) ;
18051
 
18052
            while ( FRAME !== 1 || IRDY !== 1 )
18053
                @(posedge pci_clock) ;
18054
 
18055 35 mihad
            #1 ;
18056
            if ( !error_monitor_done )
18057
                disable monitor_error_event14 ;
18058 15 mihad
        end
18059
        begin:monitor_error_event14
18060 35 mihad
            error_monitor_done = 0 ;
18061 15 mihad
            pci_ok = 1 ;
18062
            @(error_event_int) ;
18063
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
18064
            pci_ok = 0 ;
18065 35 mihad
            error_monitor_done = 1 ;
18066 15 mihad
        end
18067
        join
18068
 
18069
        if ( wb_ok && pci_ok )
18070
            test_ok ;
18071
 
18072
        // disable the image
18073
        test_name = "DISABLING MEMORY IMAGE" ;
18074 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
18075 15 mihad
        if ( ok !== 1 )
18076
        begin
18077
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
18078
            test_fail("PCI Address Mask register could not be written") ;
18079
            disable main ;
18080
        end
18081
    end
18082 92 mihad
 
18083 15 mihad
    if ( target_io_image !== -1 )
18084
    begin
18085
        do_io_disconnects = 1 ;
18086
 
18087
        if (target_io_image === 1)
18088
        begin
18089
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18090
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
18091
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
18092
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
18093
        end
18094
        else if (target_io_image === 2)
18095
        begin
18096
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
18097
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
18098
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
18099
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
18100
        end
18101
        else if (target_io_image === 3)
18102
        begin
18103
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
18104
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
18105
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
18106
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
18107
        end
18108
        else if (target_io_image === 4)
18109
        begin
18110
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
18111
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
18112
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
18113
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
18114
        end
18115
        else if (target_io_image === 5)
18116
        begin
18117
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
18118
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
18119
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
18120
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
18121
        end
18122
    end
18123
    else
18124
        do_io_disconnects = 0 ;
18125
 
18126
    if ( do_io_disconnects )
18127
    begin
18128
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
18129
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
18130
        if ( ok !== 1 )
18131
        begin
18132
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
18133
            test_fail("PCI Base Address register could not be written") ;
18134
            disable main ;
18135
        end
18136
 
18137
        // Set Address Mask of IMAGE
18138
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
18139
        if ( ok !== 1 )
18140
        begin
18141
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
18142
            test_fail("PCI Address Mask register could not be written") ;
18143
            disable main ;
18144
        end
18145
 
18146
        // Set Translation Address of IMAGE
18147
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
18148
        if ( ok !== 1 )
18149
        begin
18150
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
18151
            test_fail("PCI Translation Address Register could not be written") ;
18152
            disable main ;
18153
        end
18154
 
18155
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
18156
        if ( ok !== 1 )
18157
        begin
18158
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
18159
            test_fail("PCI Image Control register could not be written") ;
18160
            disable main ;
18161
        end
18162
 
18163
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
18164
        if ( ok !== 1 )
18165
        begin
18166
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
18167
            test_fail("Cache Line Size register could not be written") ;
18168
            disable main ;
18169
        end
18170
 
18171
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
18172
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
18173
        data = 32'h5555_5555 ;
18174
        byte_enables = 4'h0 ;
18175
        expect_length = 1 ;
18176
 
18177 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
18178 15 mihad
 
18179
        fork
18180
        begin
18181
            PCIU_IO_WRITE
18182
            (
18183
                `Test_Master_1,             // which master
18184
                pci_address,                // to what address
18185
                data,                       // data
18186
                byte_enables,               // byte enable
18187
                expect_length + 1,          // length to request
18188
                `Test_Target_Retry_On       // expected target termination
18189
            ) ;
18190
 
18191
            do_pause( 3 ) ;
18192
 
18193
            while ( FRAME !== 1 || IRDY !== 1 )
18194
                @(posedge pci_clock) ;
18195
 
18196 35 mihad
            #1 ;
18197
            if ( !error_monitor_done )
18198
                disable monitor_error_event15 ;
18199 15 mihad
        end
18200
        begin:monitor_error_event15
18201 35 mihad
            error_monitor_done = 0 ;
18202 15 mihad
            pci_ok = 1 ;
18203
            @(error_event_int) ;
18204
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
18205
            pci_ok = 0 ;
18206 35 mihad
            error_monitor_done = 1 ;
18207 15 mihad
        end
18208
        begin
18209
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
18210
            if ( wb_ok !== 1 )
18211
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
18212
        end
18213
        join
18214
 
18215
        if ( wb_ok && pci_ok )
18216
            test_ok ;
18217
 
18218
        data = 32'hAAAA_AAAA ;
18219
        fork
18220
        begin
18221
            PCIU_IO_WRITE
18222
            (
18223
                `Test_Master_1,             // which master
18224
                pci_address,                // to what address
18225
                data,                       // data
18226
                byte_enables,               // byte enable
18227
                expect_length + 2,          // length to request
18228
                `Test_Target_Retry_Before   // expected target termination
18229
            ) ;
18230
 
18231
            do_pause( 3 ) ;
18232
 
18233
            while ( FRAME !== 1 || IRDY !== 1 )
18234
                @(posedge pci_clock) ;
18235
 
18236 35 mihad
            #1 ;
18237
            if ( !error_monitor_done )
18238
                disable monitor_error_event16 ;
18239 15 mihad
        end
18240
        begin:monitor_error_event16
18241 35 mihad
            error_monitor_done = 0 ;
18242 15 mihad
            pci_ok = 1 ;
18243
            @(error_event_int) ;
18244
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
18245
            pci_ok = 0 ;
18246 35 mihad
            error_monitor_done = 1 ;
18247 15 mihad
        end
18248
        begin
18249
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
18250
            if ( wb_ok !== 1 )
18251
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
18252
        end
18253
        join
18254
 
18255
        if ( wb_ok && pci_ok )
18256
            test_ok ;
18257
 
18258
        master2_check_received_data = 1 ;
18259
 
18260
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
18261
 
18262
        fork
18263
        begin
18264
 
18265
             PCIU_IO_READ
18266
             (
18267
                `Test_Master_2,
18268
                pci_address[PCI_BUS_DATA_RANGE:0],
18269
                data,
18270
                byte_enables,
18271
                2,
18272
                `Test_Target_Retry_Before
18273
             );
18274
 
18275
            do_pause( 1 ) ;
18276
 
18277
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
18278
            if ( wb_ok !== 1 )
18279
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
18280
 
18281
            do_pause(3) ;
18282
 
18283
            PCIU_IO_READ
18284
             (
18285
                `Test_Master_2,
18286
                pci_address[PCI_BUS_DATA_RANGE:0],
18287
                data,
18288
                byte_enables,
18289
                expect_length + 1,
18290
                `Test_Target_Retry_On
18291
             );
18292
 
18293
            do_pause( 3 ) ;
18294
 
18295
            while ( FRAME !== 1 || IRDY !== 1 )
18296
                @(posedge pci_clock) ;
18297
 
18298 35 mihad
            #1 ;
18299
            if ( !error_monitor_done )
18300
                disable monitor_error_event17 ;
18301 15 mihad
        end
18302
        begin:monitor_error_event17
18303 35 mihad
            error_monitor_done = 0 ;
18304 15 mihad
            pci_ok = 1 ;
18305
            @(error_event_int) ;
18306
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
18307
            pci_ok = 0 ;
18308 35 mihad
            error_monitor_done = 1 ;
18309 15 mihad
        end
18310
        join
18311
 
18312
        if ( wb_ok && pci_ok )
18313
            test_ok ;
18314
 
18315
        fork
18316
        begin
18317
 
18318
             PCIU_IO_READ
18319
             (
18320
                `Test_Master_2,
18321
                pci_address[PCI_BUS_DATA_RANGE:0],
18322
                data,
18323
                byte_enables,
18324
                2,
18325
                `Test_Target_Retry_Before
18326
             );
18327
 
18328
            do_pause( 1 ) ;
18329
 
18330
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
18331
            if ( wb_ok !== 1 )
18332
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
18333
 
18334
            do_pause(3) ;
18335
 
18336
            PCIU_IO_READ
18337
             (
18338
                `Test_Master_2,
18339
                pci_address[PCI_BUS_DATA_RANGE:0],
18340
                data,
18341
                byte_enables,
18342
                expect_length + 2,
18343
                `Test_Target_Retry_Before
18344
             );
18345
 
18346
            do_pause( 3 ) ;
18347
 
18348
            while ( FRAME !== 1 || IRDY !== 1 )
18349
                @(posedge pci_clock) ;
18350
 
18351 35 mihad
            #1 ;
18352
            if ( !error_monitor_done )
18353
                disable monitor_error_event18 ;
18354 15 mihad
        end
18355
        begin:monitor_error_event18
18356 35 mihad
            error_monitor_done = 0 ;
18357 15 mihad
            pci_ok = 1 ;
18358
            @(error_event_int) ;
18359
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
18360
            pci_ok = 0 ;
18361 35 mihad
            error_monitor_done = 1 ;
18362 15 mihad
        end
18363
        join
18364
 
18365
        if ( wb_ok && pci_ok )
18366
            test_ok ;
18367
 
18368
        test_name = "DISABLING IO IMAGE" ;
18369 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
18370 15 mihad
        if ( ok !== 1 )
18371
        begin
18372
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
18373
            test_fail("PCI Address Mask register could not be written") ;
18374
            disable main ;
18375
        end
18376
    end
18377 92 mihad
 
18378 15 mihad
end
18379
endtask // target_disconnects
18380
 
18381
task target_unsupported_cmds ;
18382
        input [31:0] Address;
18383
        input [2:0]  image_num ;
18384
    reg          ok ;
18385
begin:main
18386
 
18387
    $display("  ") ;
18388
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
18389
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
18390 45 mihad
 
18391
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
18392
    configuration_cycle_write
18393
    (
18394
        0,                        // bus number
18395
        `TAR1_IDSEL_INDEX - 11,   // device number
18396
        0,                        // function number
18397
        1,                        // register number
18398
        0,                        // type of configuration cycle
18399
        4'b0001,                  // byte enables
18400
        32'h0000_0044             // data
18401
    ) ;
18402
 
18403
    configuration_cycle_write
18404
    (
18405
        0,                        // bus number
18406
        `TAR2_IDSEL_INDEX - 11,   // device number
18407
        0,                        // function number
18408
        1,                        // register number
18409
        0,                        // type of configuration cycle
18410
        4'b0001,                  // byte enables
18411
        32'h0000_0044             // data
18412
    ) ;
18413
 
18414 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18415 15 mihad
    (
18416
        Address,                // first part of address in dual address cycle
18417
        Address,                // second part of address in dual address cycle
18418
        `BC_IACK,                       // dual address cycle command
18419
        `BC_IACK,               // normal command
18420 92 mihad
        4'hF,               // byte enables
18421 15 mihad
        32'h1234_5678,      // data
18422
        1'b0,               // make address parity error on first phase of dual address
18423
        1'b0,               // make address parity error on second phase of dual address
18424
        ok                  // result of operation
18425
    ) ;
18426
    if ( ok )
18427
        test_ok ;
18428
    else
18429
    begin
18430
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18431
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
18432
    end
18433
 
18434
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
18435
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
18436 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18437 15 mihad
    (
18438
        Address,                // first part of address in dual address cycle
18439
        Address,                // second part of address in dual address cycle
18440
        `BC_SPECIAL,            // dual address cycle command
18441
        `BC_SPECIAL,            // normal command
18442 92 mihad
        4'hF,               // byte enables
18443 15 mihad
        32'h1234_5678,      // data
18444
        1'b0,               // make address parity error on first phase of dual address
18445
        1'b0,               // make address parity error on second phase of dual address
18446
        ok                  // result of operation
18447
    ) ;
18448
    if ( ok )
18449
        test_ok ;
18450
    else
18451
    begin
18452
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18453
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
18454
    end
18455
 
18456
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
18457
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
18458 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18459 15 mihad
    (
18460
        Address,                // first part of address in dual address cycle
18461
        Address,                // second part of address in dual address cycle
18462
        `BC_RESERVED0,          // dual address cycle command
18463
        `BC_RESERVED0,      // normal command
18464 92 mihad
        4'hF,               // byte enables
18465 15 mihad
        32'h1234_5678,      // data
18466
        1'b0,               // make address parity error on first phase of dual address
18467
        1'b0,               // make address parity error on second phase of dual address
18468
        ok                  // result of operation
18469
    ) ;
18470
    if ( ok )
18471
        test_ok ;
18472
    else
18473
    begin
18474
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18475
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
18476
    end
18477
 
18478
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
18479
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
18480 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18481 15 mihad
    (
18482
        Address,                // first part of address in dual address cycle
18483
        Address,                // second part of address in dual address cycle
18484
        `BC_RESERVED1,          // dual address cycle command
18485
        `BC_RESERVED1,      // normal command
18486 92 mihad
        4'hF,               // byte enables
18487 15 mihad
        32'h1234_5678,      // data
18488
        1'b0,               // make address parity error on first phase of dual address
18489
        1'b0,               // make address parity error on second phase of dual address
18490
        ok                  // result of operation
18491
    ) ;
18492
    if ( ok )
18493
        test_ok ;
18494
    else
18495
    begin
18496
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18497
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
18498
    end
18499
 
18500
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
18501
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
18502 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18503 15 mihad
    (
18504
        Address,                // first part of address in dual address cycle
18505
        Address,                // second part of address in dual address cycle
18506
        `BC_RESERVED2,          // dual address cycle command
18507
        `BC_RESERVED2,      // normal command
18508 92 mihad
        4'hF,               // byte enables
18509 15 mihad
        32'h1234_5678,      // data
18510
        1'b0,               // make address parity error on first phase of dual address
18511
        1'b0,               // make address parity error on second phase of dual address
18512
        ok                  // result of operation
18513
    ) ;
18514
    if ( ok )
18515
        test_ok ;
18516
    else
18517
    begin
18518
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18519
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
18520
    end
18521
 
18522
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
18523
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
18524 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18525 15 mihad
    (
18526
        Address,                // first part of address in dual address cycle
18527
        Address,                // second part of address in dual address cycle
18528
        `BC_RESERVED3,          // dual address cycle command
18529
        `BC_RESERVED3,      // normal command
18530 92 mihad
        4'hF,               // byte enables
18531 15 mihad
        32'h1234_5678,      // data
18532
        1'b0,               // make address parity error on first phase of dual address
18533
        1'b0,               // make address parity error on second phase of dual address
18534
        ok                  // result of operation
18535
    ) ;
18536
    if ( ok )
18537
        test_ok ;
18538
    else
18539
    begin
18540
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18541
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
18542
    end
18543
 
18544
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
18545
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
18546
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
18547
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
18548 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18549 15 mihad
    (
18550
        Address,                // first part of address in dual address cycle
18551
        Address,                // second part of address in dual address cycle
18552
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
18553
        `BC_MEM_WRITE,      // normal command
18554 92 mihad
        4'hF,               // byte enables;
18555 15 mihad
        32'h1234_5678,      // data
18556
        1'b0,               // make address parity error on first phase of dual address
18557
        1'b0,               // make address parity error on second phase of dual address
18558
        ok                  // result of operation
18559
    ) ;
18560
    if ( ok )
18561
        test_ok ;
18562
    else
18563
    begin
18564
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18565
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
18566
    end
18567
 
18568 45 mihad
    // enable pci blue behavioral targets 1 and 2
18569
    configuration_cycle_write
18570
    (
18571
        0,                        // bus number
18572
        `TAR1_IDSEL_INDEX - 11,   // device number
18573
        0,                        // function number
18574
        1,                        // register number
18575
        0,                        // type of configuration cycle
18576
        4'b0001,                  // byte enables
18577
        32'h0000_0047             // data
18578
    ) ;
18579
 
18580
    configuration_cycle_write
18581
    (
18582
        0,                        // bus number
18583
        `TAR2_IDSEL_INDEX - 11,   // device number
18584
        0,                        // function number
18585
        1,                        // register number
18586
        0,                        // type of configuration cycle
18587
        4'b0001,                  // byte enables
18588
        32'h0000_0047             // data
18589
    ) ;
18590 15 mihad
end
18591
endtask // target_unsupported_cmds
18592
 
18593 63 mihad
`ifdef DISABLE_COMPLETION_EXPIRED_TESTS
18594
`else
18595 15 mihad
task target_completion_expiration ;
18596
    reg   [11:0] pci_ctrl_offset ;
18597
    reg   [11:0] pci_ba_offset ;
18598
    reg   [11:0] pci_am_offset ;
18599
    reg   [11:0] pci_device_ctrl_offset ;
18600
    reg   [11:0] pci_err_cs_offset ;
18601
    reg   [11:0] icr_offset ;
18602
    reg   [11:0] isr_offset ;
18603
    reg   [11:0] lat_tim_cls_offset ;
18604
 
18605
    reg [31:0] temp_val1 ;
18606
    reg [31:0] temp_val2 ;
18607
    reg        ok   ;
18608 33 mihad
    reg        ok_wb ;
18609
    reg        ok_pci ;
18610 15 mihad
 
18611
    reg [31:0] pci_image_base ;
18612
    integer i ;
18613 33 mihad
    integer clocks_after_completion ;
18614
    reg     error_monitor_done ;
18615
    reg     test_mem ;
18616 15 mihad
 
18617
begin:main
18618
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18619
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
18620
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
18621
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
18622
 
18623
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
18624
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
18625
    lat_tim_cls_offset = 12'hC ;
18626
    pci_device_ctrl_offset    = 12'h4 ;
18627
 
18628 33 mihad
    `ifdef HOST
18629
        test_mem = 1'b1 ;
18630
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
18631
    `else
18632
        test_mem = !`PCI_BA1_MEM_IO ;
18633
        pci_image_base = Target_Base_Addr_R[1] ;
18634
    `endif
18635 15 mihad
 
18636
    // enable master & target operation
18637
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
18638
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
18639
    if ( ok !== 1 )
18640
    begin
18641
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18642
        test_fail("write to PCI Device Control register failed") ;
18643
        disable main ;
18644
    end
18645
 
18646
    // prepare image control register
18647 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18648 15 mihad
    if ( ok !== 1 )
18649
    begin
18650
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18651
        test_fail("write to PCI Image Control register failed") ;
18652
        disable main ;
18653
    end
18654
 
18655
    // prepare base address register
18656
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18657
    if ( ok !== 1 )
18658
    begin
18659
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18660
        test_fail("write to PCI Base Address register failed") ;
18661
        disable main ;
18662
    end
18663
 
18664
    // write address mask register
18665
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18666
    if ( ok !== 1 )
18667
    begin
18668
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18669
        test_fail("write to PCI Address Mask register failed") ;
18670
        disable main ;
18671
    end
18672
 
18673
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18674
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18675
    if ( ok !== 1 )
18676
    begin
18677
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18678
        test_fail("write to PCI Error Control and Status register failed") ;
18679
        disable main ;
18680
    end
18681
 
18682 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18683 15 mihad
    if ( ok !== 1 )
18684
    begin
18685
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18686
        test_fail("write to Interrupt Control register failed") ;
18687
        disable main ;
18688
    end
18689
 
18690
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18691
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18692
    if ( ok !== 1 )
18693
    begin
18694
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18695
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18696
        disable main ;
18697
    end
18698
 
18699
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18700
 
18701 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
18702 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18703
    master1_check_received_data = 0 ;
18704 15 mihad
 
18705 33 mihad
    ok_pci = 1 ;
18706
    // start a delayed read request
18707
    fork
18708
    begin
18709
        if ( test_mem )
18710
 
18711
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18712
                          pci_image_base, 32'h1234_5678,
18713
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18714
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18715
        else
18716
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18717
 
18718
        do_pause( 1 ) ;
18719
    end
18720
    begin:error_monitor1
18721 35 mihad
        error_monitor_done = 0 ;
18722 33 mihad
        @(error_event_int) ;
18723
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18724
        ok_pci = 0 ;
18725 35 mihad
        error_monitor_done = 1 ;
18726 33 mihad
    end
18727
    begin
18728
        if ( test_mem )
18729
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18730
        else
18731
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18732 15 mihad
 
18733 33 mihad
        if ( ok_wb !== 1 )
18734
        begin
18735
            test_fail("Bridge failed to process Target Memory read correctly") ;
18736
            disable main ;
18737
        end
18738
 
18739 35 mihad
        #1 ;
18740
        if ( !error_monitor_done )
18741 33 mihad
            disable error_monitor1 ;
18742
    end
18743
    join
18744
 
18745
    clocks_after_completion = 0 ;
18746
    // now do another - different transaction
18747
    fork
18748
    begin
18749
        if ( test_mem )
18750
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18751
                          pci_image_base + 4, 32'h1234_5678,
18752
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18753
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18754
        else
18755
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18756
 
18757
        while ( clocks_after_completion < 32'h0000_FFF0 )
18758
        begin
18759
            @(posedge pci_clock) ;
18760
            clocks_after_completion = clocks_after_completion + 1 ;
18761
        end
18762
 
18763
        do_pause('hFF) ;
18764
 
18765
        if ( test_mem )
18766
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18767
                          pci_image_base + 4, 32'h1234_5678,
18768
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18769
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18770
        else
18771
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18772
 
18773
        do_pause( 1 ) ;
18774
    end
18775
    begin:error_monitor2
18776 35 mihad
        error_monitor_done = 0 ;
18777 33 mihad
        @(error_event_int) ;
18778
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18779
        ok_pci = 0 ;
18780 35 mihad
        error_monitor_done = 1 ;
18781 33 mihad
    end
18782
    begin
18783
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18784
        repeat( 'hFF )
18785
            @(posedge pci_clock) ;
18786
 
18787
        if ( test_mem )
18788
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18789
        else
18790
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18791
 
18792
        if ( ok_wb !== 1 )
18793
        begin
18794
            test_fail("Bridge failed to process Target Memory read correctly") ;
18795
            disable main ;
18796
        end
18797
 
18798
        repeat(4)
18799
            @(posedge pci_clock) ;
18800
 
18801
        fork
18802
        begin
18803
            if ( test_mem )
18804
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18805
                              pci_image_base + 4, 32'h1234_5678,
18806
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18807
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18808
            else
18809
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18810
 
18811
            do_pause(1) ;
18812
        end
18813
        begin
18814
           pci_transaction_progress_monitor( pci_image_base + 4, test_mem ? `BC_MEM_READ : `BC_IO_READ, test_mem ? 4 : 1, 0, 1'b1, 1'b0, 0, ok ) ;
18815 35 mihad
           #1 ;
18816
           if ( !error_monitor_done )
18817 33 mihad
               disable error_monitor2 ;
18818
        end
18819
        join
18820
    end
18821
    join
18822
 
18823
    if ( ok && ok_pci && ok_wb )
18824
        test_ok ;
18825
 
18826
    if ( ok !== 1 )
18827
    begin
18828
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18829
        test_fail("write to PCI Address Mask register failed") ;
18830
        disable main ;
18831
    end
18832
 
18833
    // check statuses after this situation - none should be set
18834
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18835
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18836
    if ( ok !== 1 )
18837
    begin
18838
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18839
        test_fail("read from pci device status register failed") ;
18840
        disable main ;
18841
    end
18842
 
18843
    if ( temp_val1[31] )
18844
    begin
18845
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18846
        test_fail("detected parity error bit was set for no reason") ;
18847
    end
18848
 
18849
    if ( temp_val1[30] )
18850
    begin
18851
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18852
        test_fail("signaled system error bit was set for no reason") ;
18853
    end
18854
 
18855
    if ( temp_val1[29] )
18856
    begin
18857
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18858
        test_fail("received master abort bit was set for no reason") ;
18859
    end
18860
 
18861
    if ( temp_val1[28] )
18862
    begin
18863
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18864
        test_fail("received target abort bit was set for no reason") ;
18865
    end
18866
 
18867
    if ( temp_val1[27] )
18868
    begin
18869
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18870
        test_fail("signaled target abort bit was set for no reason") ;
18871
    end
18872
 
18873
    if ( temp_val1[24] )
18874
    begin
18875
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18876
        test_fail("Master Data parity error bit was set for no reason") ;
18877
    end
18878
 
18879
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18880
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18881
    if ( temp_val1[8] !== 0 )
18882
    begin
18883
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18884
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18885
    end
18886 87 mihad
 
18887 33 mihad
    // set wb slave to retry response
18888 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'd255);
18889 33 mihad
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18890
    ok_pci = 1 ;
18891
 
18892
    fork
18893
    begin
18894
        if ( test_mem == 1 )
18895
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18896 87 mihad
                        pci_image_base, 32'hBEAF_DEAD, 4'h5,
18897 33 mihad
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18898
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18899
        else
18900 87 mihad
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h5, 1, `Test_Target_Normal_Completion) ;
18901 33 mihad
 
18902
        do_pause(1) ;
18903
 
18904
        // do another write with same address and different data
18905
        if ( test_mem == 1 )
18906
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18907 87 mihad
                        pci_image_base, 32'h1234_5678, 4'h0,
18908 33 mihad
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18909
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18910
        else
18911 87 mihad
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion) ;
18912 33 mihad
 
18913
        do_pause(1) ;
18914
    end
18915
    begin
18916
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18917
        begin
18918
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18919
            if ( ok_wb !== 1 )
18920
            begin
18921
                $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
18922
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18923
                disable main ;
18924
            end
18925
        end
18926
 
18927
        // set WB slave to normal completion
18928 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
18929 33 mihad
 
18930
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18931
        if ( ok_wb !== 1 )
18932
        begin
18933
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
18934
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18935
            disable main ;
18936
        end
18937
 
18938 35 mihad
        #1 ;
18939
        if ( !error_monitor_done )
18940 33 mihad
            disable error_monitor3 ;
18941
    end
18942
    begin:error_monitor3
18943 35 mihad
        error_monitor_done = 0 ;
18944 33 mihad
        @(error_event_int) ;
18945
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18946
        ok_pci = 0 ;
18947 35 mihad
        error_monitor_done = 1 ;
18948 33 mihad
    end
18949
    join
18950
 
18951
    if ( ok_wb && ok_pci )
18952
    begin
18953
        test_ok ;
18954
    end
18955
 
18956
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18957
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18958
    if ( temp_val1[8] !== 1'b1 )
18959
    begin
18960
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18961
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18962
    end
18963
 
18964
    if ( temp_val1[9] !== 1 )
18965
    begin
18966
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should set Error Source bit when retry counter expires during a write! Time %t", $time) ;
18967
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18968
    end
18969
 
18970
    if ( temp_val1[10] !== 1 )
18971
    begin
18972
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should set Retry Expired bit when retry counter expires during a write! Time %t", $time) ;
18973
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18974
    end
18975
 
18976
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18977
    begin
18978
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in bus command field in error control and status register when retry counter expired during a write! Time %t", $time) ;
18979
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18980
    end
18981
 
18982 87 mihad
    if ( temp_val1[31:28] !== 4'h5 )
18983 33 mihad
    begin
18984
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in byte enable field in error control and status register when retry counter expired during a write! Time %t", $time) ;
18985 87 mihad
        $display("Expected value: %h, actual value %h", 4'h5, temp_val1[31:28]) ;
18986 33 mihad
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18987
    end
18988
 
18989
    // clear error status register
18990
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18991
 
18992
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18993
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18994
    if ( temp_val1 !== pci_image_base )
18995
    begin
18996
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18997
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18998
    end
18999
 
19000
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
19001
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
19002 87 mihad
    if ( temp_val1 !== (32'hBEAF_DEAD) )
19003 33 mihad
    begin
19004
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
19005 87 mihad
        $display("Expected value %h, actual %h", 32'hBEAF_DEAD, temp_val1) ;
19006 33 mihad
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
19007
    end
19008
 
19009
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
19010
    ok_pci = 1 ;
19011 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'd255);
19012 33 mihad
 
19013
    i = 0 ;
19014
    fork
19015
    begin
19016
        if ( test_mem )
19017
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
19018
                          pci_image_base + 4, 32'h1234_5678,
19019
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
19020
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
19021
        else
19022
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
19023
 
19024
        do_pause( 1 ) ;
19025
 
19026
    end
19027
    begin
19028
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
19029
        begin
19030
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
19031
            if ( ok_wb !== 1 )
19032
            begin
19033
                $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
19034
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
19035
                disable main ;
19036
            end
19037
        end
19038
 
19039
        // set WB slave to normal completion
19040 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
19041 33 mihad
 
19042
        fork
19043
        begin
19044
            repeat(4)
19045
                @(posedge pci_clock) ;
19046
 
19047
            if ( test_mem )
19048
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
19049
                              pci_image_base, 32'h8765_4321,
19050
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
19051
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
19052
            else
19053
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
19054
 
19055
            do_pause(1) ;
19056
        end
19057
        begin
19058
 
19059
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
19060
            if ( ok_wb !== 1 )
19061
            begin
19062
                $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
19063
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
19064
                disable main ;
19065
            end
19066
        end
19067
        join
19068
 
19069
        repeat( 4 )
19070
            @(posedge pci_clock) ;
19071
 
19072
        if ( test_mem )
19073
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
19074
                          pci_image_base, 32'h8765_4321,
19075
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
19076
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
19077
        else
19078
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
19079
 
19080
        do_pause(1) ;
19081
 
19082 35 mihad
        #1 ;
19083
        if ( !error_monitor_done )
19084 33 mihad
            disable error_monitor4 ;
19085
    end
19086
    begin:error_monitor4
19087 35 mihad
        error_monitor_done = 0 ;
19088 33 mihad
        @(error_event_int) ;
19089
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
19090
        ok_pci = 0 ;
19091 35 mihad
        error_monitor_done = 1 ;
19092 33 mihad
    end
19093
    join
19094
 
19095
    if ( ok_wb && ok_pci )
19096
        test_ok ;
19097
 
19098
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
19099
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
19100
    if ( temp_val1[8] !== 1'b0 )
19101
    begin
19102
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master shouldn't signal an error when retry counter expires during a read! Time %t", $time) ;
19103
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
19104
    end
19105 87 mihad
 
19106
`ifdef PCI_WBM_NO_RESPONSE_CNT_DISABLE
19107
`else
19108 33 mihad
 
19109 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
19110
    $fdisplay(pciu_mon_log_file_desc,
19111
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
19112 33 mihad
 
19113
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
19114
    ok_pci = 1 ;
19115 92 mihad
    wishbone_slave.cycle_response(3'b000, wb_subseq_waits, 8'd255);
19116 33 mihad
 
19117
    fork
19118
    begin
19119
        if ( test_mem == 1 )
19120
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
19121 87 mihad
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
19122 33 mihad
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
19123
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
19124
        else
19125 87 mihad
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
19126 33 mihad
 
19127
        do_pause(1) ;
19128
 
19129
        // do another write with same address and different data
19130
        if ( test_mem == 1 )
19131
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
19132
                        pci_image_base, 32'h8765_6789, 4'h0,
19133
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
19134
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
19135
        else
19136
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
19137
 
19138
        do_pause(1) ;
19139
    end
19140
    begin
19141
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
19142
        if ( ok_wb !== 1 )
19143
        begin
19144
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
19145
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
19146
            disable main ;
19147
        end
19148
 
19149 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'd255);
19150 33 mihad
 
19151
        if ( test_mem )
19152
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
19153
        else
19154
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
19155
 
19156
        if ( ok_wb !== 1 )
19157
        begin
19158
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
19159
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
19160
            disable main ;
19161
        end
19162
 
19163 35 mihad
        #1 ;
19164
        if ( !error_monitor_done )
19165 33 mihad
            disable error_monitor6 ;
19166
    end
19167
    begin:error_monitor6
19168 35 mihad
        error_monitor_done = 0 ;
19169 33 mihad
        @(error_event_int) ;
19170
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
19171
        ok_pci = 0 ;
19172 35 mihad
        error_monitor_done = 1 ;
19173 33 mihad
    end
19174
    join
19175
 
19176
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
19177
    $fdisplay(pciu_mon_log_file_desc,
19178
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
19179
 
19180
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
19181
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
19182
    if ( temp_val1[8] !== 1'b1 )
19183
    begin
19184
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when no response counter expires during a write! Time %t", $time) ;
19185
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
19186
    end
19187
 
19188
    if ( temp_val1[9] !== 0 )
19189
    begin
19190
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should not set Error Source bit when no response counter expires during a write! Time %t", $time) ;
19191
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
19192
    end
19193
 
19194
    if ( temp_val1[10] !== 1 )
19195
    begin
19196
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should set Retry Expired bit when no response counter expires during a write! Time %t", $time) ;
19197
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
19198
    end
19199
 
19200
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
19201
    begin
19202
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in bus command field in error control and status register when no response counter expired during a write! Time %t", $time) ;
19203
        test_fail("bus command field in error control and status register was wrong when no response counter expired during posted write through PCI Target unit") ;
19204
    end
19205
 
19206 87 mihad
    if ( temp_val1[31:28] !== 4'hA )
19207 33 mihad
    begin
19208
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in byte enable field in error control and status register when no response counter expired during a write! Time %t", $time) ;
19209
        test_fail("byte enable field in error control and status register was wrong when no response counter expired during posted write through PCI Target unit") ;
19210
    end
19211
 
19212
    // clear error status register
19213
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
19214
 
19215
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
19216
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
19217
    if ( temp_val1 !== pci_image_base )
19218
    begin
19219
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when no response counter expired during a write! Time %t", $time) ;
19220
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
19221
    end
19222
 
19223
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
19224
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
19225 87 mihad
    if ( temp_val1 !== 32'hDEAD_BEAF )
19226 33 mihad
    begin
19227
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when no response counter expired during a write! Time %t", $time) ;
19228
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
19229
    end
19230 92 mihad
 
19231
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
19232
    $fdisplay(pciu_mon_log_file_desc,
19233
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
19234
 
19235
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
19236
 
19237
    ok_pci = 1 ;
19238
    wishbone_slave.cycle_response(3'b000, wb_subseq_waits, 8'd255);
19239
 
19240
    fork
19241
    begin
19242
        if ( test_mem )
19243
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
19244
                          pci_image_base + 4, 32'h1234_5678,
19245
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
19246
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
19247
        else
19248
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
19249
 
19250
        do_pause( 1 ) ;
19251
 
19252
    end
19253
    begin
19254
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
19255
        if ( ok_wb !== 1 )
19256
        begin
19257
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
19258
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
19259
            disable main ;
19260
        end
19261
 
19262
        repeat(4)
19263
            @(posedge pci_clock) ;
19264
 
19265
        fork
19266
        begin
19267
 
19268
            if ( test_mem )
19269
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
19270
                              pci_image_base + 4, 32'h8765_4321,
19271
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
19272
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
19273
            else
19274
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
19275
 
19276
            do_pause(1) ;
19277
 
19278
        end
19279
        begin
19280
 
19281
            pci_transaction_progress_monitor( pci_image_base + 4, test_mem ? `BC_MEM_READ : `BC_IO_READ, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
19282
            if ( ok !== 1 )
19283
            begin
19284
                $display("WISHBONE Master Retry Counter expiration test failed! PCI transaction progress monitor detected invalid transaction or none at all on PCI bus! Time %t", $time) ;
19285
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
19286
                disable main ;
19287
            end
19288
        end
19289
        join
19290
 
19291
        #1 ;
19292
        if ( !error_monitor_done )
19293
            disable error_monitor5 ;
19294
    end
19295
    begin:error_monitor5
19296
        error_monitor_done = 0 ;
19297
        @(error_event_int) ;
19298
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
19299
        ok_pci = 0 ;
19300
        error_monitor_done = 1 ;
19301
    end
19302
    join
19303
 
19304
    if ( ok_wb && ok_pci )
19305
        test_ok ;
19306
 
19307
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
19308
    $fdisplay(pciu_mon_log_file_desc,
19309
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
19310
 
19311
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
19312
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
19313
    if ( temp_val1[8] !== 1'b0 )
19314
    begin
19315
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master shouldn't signal an error when retry counter expires during a read! Time %t", $time) ;
19316
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
19317
    end
19318
 
19319
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
19320
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
19321
    if ( temp_val1[25] !== 1'b1 )
19322
    begin
19323
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
19324
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
19325
    end
19326
 
19327
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
19328 87 mihad
`endif
19329 33 mihad
 
19330
    // disable current image - write address mask register
19331 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
19332 15 mihad
end
19333 57 mihad
endtask // target_completion_expiration
19334 15 mihad
 
19335 57 mihad
task master_completion_expiration ;
19336
    reg   [11:0] ctrl_offset ;
19337
    reg   [11:0] ba_offset ;
19338
    reg   [11:0] am_offset ;
19339
    reg `WRITE_STIM_TYPE write_data ;
19340
    reg `READ_STIM_TYPE  read_data ;
19341
    reg `READ_RETURN_TYPE read_status ;
19342
 
19343
    reg `WRITE_RETURN_TYPE write_status ;
19344
    reg `WB_TRANSFER_FLAGS write_flags ;
19345
    reg        ok   ;
19346
    reg [11:0] pci_ctrl_offset ;
19347
    reg [31:0] image_base ;
19348
    reg [31:0] target_address ;
19349
begin:main
19350
    pci_ctrl_offset = 12'h4 ;
19351
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
19352
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
19353
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
19354
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
19355
 
19356
    target_address  = `BEH_TAR1_MEM_START ;
19357
    image_base      = 0 ;
19358
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
19359
 
19360
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
19361
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
19362
    write_flags                      = 0 ;
19363 92 mihad
    write_flags`INIT_WAITS           = wb_init_waits ;
19364
    write_flags`SUBSEQ_WAITS         = wb_subseq_waits ;
19365 57 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19366
 
19367
    // enable master & target operation
19368
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
19369
    if ( ok !== 1 )
19370
    begin
19371
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
19372
        test_fail("write to PCI Device Control register didn't succeede");
19373
        disable main ;
19374
    end
19375
 
19376
    // prepare image control register
19377
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
19378
    if ( ok !== 1 )
19379
    begin
19380
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
19381
        test_fail("write to WB Image Control register didn't succeede");
19382
        disable main ;
19383
    end
19384
 
19385
    // prepare base address register
19386
    config_write( ba_offset, image_base, 4'hF, ok ) ;
19387
    if ( ok !== 1 )
19388
    begin
19389
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
19390
        test_fail("write to WB Base Address register didn't succeede");
19391
        disable main ;
19392
    end
19393
 
19394
    // write address mask register
19395
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
19396
    if ( ok !== 1 )
19397
    begin
19398
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
19399
        test_fail("write to WB Address Mask register didn't succeede");
19400
        disable main ;
19401
    end
19402
 
19403
    fork
19404
    begin
19405
        // do not handle retries
19406
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
19407
 
19408
        // initiate a read request
19409
        read_data`READ_ADDRESS  = target_address ;
19410
        read_data`READ_SEL      = 4'hF ;
19411
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
19412
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
19413
        begin
19414
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
19415
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
19416
            disable main ;
19417
        end
19418
 
19419
        // handle retries from now on
19420
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
19421
 
19422
        write_data`WRITE_ADDRESS = target_address + 4 ;
19423
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
19424
        write_data`WRITE_SEL     = 4'hF ;
19425
 
19426
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
19427
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
19428
        begin
19429
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
19430
            test_fail("WB Slave state machine failed to post single memory write");
19431
            disable main ;
19432
        end
19433
 
19434 81 mihad
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 110
19435
        repeat('h1_0000 - 110)
19436 57 mihad
            @(posedge wb_clock) ;
19437
 
19438
        // now perform a read
19439
        read_data`READ_ADDRESS  = target_address + 4 ;
19440
        read_data`READ_SEL      = 4'hF ;
19441
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
19442
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19443
        begin
19444
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
19445
            test_fail("PCI bridge didn't process the read as expected");
19446
            disable main ;
19447
        end
19448
 
19449
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
19450
        begin
19451
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
19452
            test_fail("PCI bridge returned unexpected Read Data");
19453
        end
19454
        else if (ok === 1'b1)
19455
            test_ok ;
19456
    end
19457
    begin:monitors
19458
        // monitor first read, which will expire
19459
        pci_transaction_progress_monitor
19460
        (
19461
            target_address, // expected address
19462
            `BC_MEM_READ,   // expected bus command
19463
            1,              // expected number of transfers
19464
            0,              // expected number of cycles
19465
            1,              // check number of transfers true/false
19466
            0,              // check number of cycles true/false
19467
            0,              // is this fast B2B true/false
19468
            ok              // return 1 if as expected, anything else on error
19469
        ) ;
19470
 
19471
        if ( ok !== 1 )
19472
        begin
19473
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19474
            #1 disable monitors ;
19475
        end
19476
 
19477
        // monitor normal single write
19478
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
19479
        if ( ok !== 1 )
19480
        begin
19481
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19482
            #1 disable monitors ;
19483
        end
19484
 
19485
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
19486 81 mihad
        repeat('h1_0000 - 100)
19487 57 mihad
            @(posedge wb_clock) ;
19488
 
19489
        // monitor normal single memory read
19490
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
19491
        if ( ok !== 1 )
19492
        begin
19493
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19494
        end
19495
    end
19496
    join
19497
 
19498
    // disable the image
19499
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
19500
    if ( ok !== 1 )
19501
    begin
19502
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
19503
        test_fail("write to WB Address Mask register didn't succeede");
19504
    end
19505
end
19506
endtask // master_completion_expiration
19507 63 mihad
`endif
19508 57 mihad
 
19509 15 mihad
task config_write ;
19510
    input [11:0] offset ;
19511
    input [31:0] data ;
19512
    input [3:0]  byte_enable ;
19513
    output       ok ;
19514
    `ifdef HOST
19515
    reg   `WRITE_STIM_TYPE   write_data ;
19516
    reg   `WB_TRANSFER_FLAGS write_flags ;
19517
    reg   `WRITE_RETURN_TYPE write_status ;
19518
    `else
19519
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
19520
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
19521
    `endif
19522
    reg in_use ;
19523
    reg [31:0] temp_var ;
19524
begin
19525
    if ( in_use === 1 )
19526
    begin
19527
        $display("config_read task re-entered! Time %t ", $time) ;
19528
        ok = 0 ;
19529
        #20 $stop ;
19530
    end
19531
    else
19532
    begin
19533
        ok = 1 ;
19534
        in_use = 1 ;
19535
    end
19536
    `ifdef HOST
19537
    write_flags                    = 0 ;
19538 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
19539
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
19540 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19541
 
19542
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19543
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19544
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
19545
    write_data`WRITE_SEL                         = byte_enable ;
19546
    write_data`WRITE_DATA                        = data ;
19547
 
19548
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
19549
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
19550
    begin
19551
        $display("Write to configuration space failed! Time %t ", $time) ;
19552
        ok = 0 ;
19553
    end
19554
 
19555
    @(posedge wb_clock) ;
19556
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
19557
    // here we just wait for two guest cycles for conf space bits to synchronize
19558
    repeat( 2 )
19559
        @(posedge pci_clock) ;
19560
 
19561
    `else // GUEST
19562
    byte_enables_l = ~byte_enable ;
19563
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19564
 
19565
    fork
19566
    begin
19567
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19568
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
19569
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
19570
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19571
              8'h0_0, `Test_One_Zero_Target_WS,
19572
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
19573
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19574
    do_pause( 1 ) ;
19575
    end
19576
    begin
19577
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
19578
        @(posedge pci_clock) ;
19579
    end
19580
    join
19581
 
19582
     repeat( 2 )
19583
         @(posedge wb_clock) ;
19584
 
19585
    `endif
19586
    in_use = 0 ;
19587
end
19588
endtask // config_write
19589
 
19590
task config_read ;
19591
    input [11:0] offset ;
19592
    input [3:0]  byte_enable ;
19593
    output [31:0] data ;
19594
 
19595
    reg `READ_STIM_TYPE    read_data ;
19596
    reg `WB_TRANSFER_FLAGS read_flags ;
19597
    reg `READ_RETURN_TYPE  read_status ;
19598
 
19599
    reg [31:0] pci_address ;
19600
    reg [3:0] byte_enables_l ;
19601
 
19602
    reg master_check_data_prev ;
19603
    reg in_use ;
19604
    reg [31:0] temp_var ;
19605
begin:main
19606
    if ( in_use === 1 )
19607
    begin
19608
        $display("config_read task re-entered! Time %t ", $time) ;
19609
        data = 32'hxxxx_xxxx ;
19610
        disable main ;
19611
    end
19612
 
19613
    in_use = 1 ;
19614
 
19615
`ifdef HOST
19616 26 mihad
    repeat(4)
19617
        @(posedge pci_clock) ;
19618
    repeat(4)
19619
        @(posedge wb_clock) ;
19620 15 mihad
    read_flags                    = 0 ;
19621 92 mihad
    read_flags`INIT_WAITS         = wb_init_waits ;
19622
    read_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
19623 15 mihad
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19624
 
19625
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19626
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19627
 
19628
    read_data`READ_ADDRESS  = temp_var + offset ;
19629
    read_data`READ_SEL      = byte_enable ;
19630
 
19631
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
19632
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19633
    begin
19634
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
19635
        #20 $stop ;
19636
    end
19637
    data = read_status`READ_DATA ;
19638
`else
19639
  `ifdef GUEST
19640 26 mihad
    repeat(4)
19641
        @(posedge wb_clock) ;
19642
    repeat(4)
19643
        @(posedge pci_clock) ;
19644 15 mihad
    master_check_data_prev = master2_check_received_data ;
19645
    master2_check_received_data = 0 ;
19646
 
19647
    byte_enables_l = ~byte_enable ;
19648
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19649
 
19650
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19651
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
19652
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19653
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19654
             8'h4_0, `Test_One_Zero_Target_WS,
19655
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19656
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19657
    do_pause( 1 ) ;
19658
 
19659
    @(master2_received_data_valid) ;
19660
    data = master2_received_data ;
19661
 
19662
    master2_check_received_data = master_check_data_prev ;
19663
  `endif
19664
`endif
19665
    in_use = 0 ;
19666
end
19667
endtask //config_read
19668
 
19669 62 mihad
`ifdef PCI_BIST
19670
`ifdef WB_RAM_DONT_SHARE
19671
    `ifdef PCI_RAM_DONT_SHARE
19672
        parameter bist_chain_length = 8 ;
19673
    `else
19674
        parameter bist_chain_length = 6 ;
19675
    `endif
19676
`else
19677
    `ifdef PCI_RAM_DONT_SHARE
19678 69 mihad
        parameter bist_chain_length = 6 ;
19679 62 mihad
    `else
19680 69 mihad
        parameter bist_chain_length = 4 ;
19681 62 mihad
    `endif
19682
`endif
19683
 
19684
task run_bist_test ;
19685
    reg [(bist_chain_length - 1):0] bist_result_vector ;
19686
    integer count ;
19687
    integer deadlock_count ;
19688
begin
19689
 
19690
    test_name = "BIST FOR RAMS RUN" ;
19691
 
19692 122 markom
    mbist_ctrl_i  = 0 ;
19693
    mbist_si_i  = 0 ;
19694
    mbist_rst = 0 ;
19695
    mbist_clk = 0 ;
19696 62 mihad
 
19697
    fork
19698
    begin
19699
        repeat(2)
19700
            @(posedge wb_clock) ;
19701
    end
19702
    begin
19703
        repeat(2)
19704
            @(posedge pci_clock) ;
19705
    end
19706
    join
19707
 
19708 69 mihad
    // test is run by reseting the test logic
19709 122 markom
    mbist_rst <= 1'b1 ;
19710 69 mihad
 
19711
    // toggle scan clock for a few times
19712
    repeat (20)
19713 122 markom
        #50 mbist_clk = !mbist_clk ;
19714 69 mihad
 
19715
    // release bist reset
19716 122 markom
    mbist_rst <= 1'b0 ;
19717 62 mihad
 
19718
    bist_result_vector = 0 ;
19719
 
19720
    // result vector must be all 1s, because in RTL there cannot be a reason for BIST to fail
19721
    fork
19722
    begin:scan
19723
        while (bist_result_vector !== {bist_chain_length{1'b1}})
19724
        begin
19725 69 mihad
            #1 ;
19726 122 markom
            @(posedge mbist_clk) ;
19727
            mbist_ctrl_i <= #1 1'b1 ;
19728 62 mihad
            for (count = 0 ; count < bist_chain_length ; count = count + 1'b1)
19729
            begin
19730 122 markom
                @(posedge mbist_clk) ;
19731
                bist_result_vector[count] = mbist_so_o ;
19732 62 mihad
            end
19733
 
19734 122 markom
            mbist_ctrl_i <= #1 1'b0 ;
19735 62 mihad
        end
19736
        #1 disable deadlock ;
19737 122 markom
        @(negedge mbist_clk) ;
19738
        #1 disable mbist_clk_gen ;
19739 62 mihad
        test_ok ;
19740
    end
19741
    begin:deadlock
19742
        for (deadlock_count = 0; deadlock_count <= 100000; deadlock_count = deadlock_count + 1'b1)
19743
        begin
19744
            @(posedge pci_clock) ;
19745
            @(posedge wb_clock) ;
19746
        end
19747
 
19748
        test_fail("BIST Test didn't finish as expected") ;
19749 122 markom
        mbist_ctrl_i <= #1 1'b0 ;
19750 62 mihad
        disable scan ;
19751 122 markom
        @(negedge mbist_clk) ;
19752 62 mihad
        #1 ;
19753 122 markom
        disable mbist_clk_gen ;
19754 62 mihad
    end
19755 122 markom
    begin:mbist_clk_gen
19756 62 mihad
        forever
19757 122 markom
            #50 mbist_clk = !mbist_clk ;
19758 62 mihad
    end
19759
    join
19760
end
19761
endtask // run_bist_test
19762
`endif
19763
 
19764 104 mihad
`ifdef DO_CORNER_CASE_TESTS
19765 63 mihad
task target_special_corner_case_test ;
19766
    reg   [11:0]    pci_ctrl_offset ;
19767
    reg   [11:0]    ctrl_offset ;
19768
    reg   [11:0]    ba_offset ;
19769
    reg   [11:0]    am_offset ;
19770
    reg             ok_wb ;
19771
    reg             ok_pci ;
19772
    reg             test_mem ;
19773
    reg             master_check_data_previous ;
19774
begin:main
19775
    master_check_data_previous  = master1_check_received_data ;
19776
    master1_check_received_data = 1'b1 ;
19777
    pci_ctrl_offset = 12'h4 ;
19778
    // use image 1 for this test
19779
    ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
19780
    ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
19781
    am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
19782
 
19783
    // set behavioral slave cycle response
19784
    `ifdef REGISTER_WBM_OUTPUTS
19785
    wishbone_slave.cycle_response
19786
    (
19787
        3'b100,         // {ACK, ERR, RTY}
19788
        0,              // wait cycles
19789
        8'h0            // num of retries before termination
19790
    );
19791
    `else
19792
    wishbone_slave.cycle_response
19793
    (
19794
        3'b100,         // {ACK, ERR, RTY}
19795
        1,              // wait cycles
19796
        8'h0            // num of retries before termination
19797
    );
19798
    `endif
19799
 
19800
    `ifdef HOST
19801
        test_mem = 1 ;
19802
    `else
19803
        test_mem = `PCI_BA1_MEM_IO ;
19804
        test_mem = !test_mem ;
19805
    `endif
19806
 
19807
    test_name = "PCI TARGET UNIT SPECIAL CORNER CASE" ;
19808
 
19809
    // Set Base Address of IMAGE
19810
    config_write( ba_offset, Target_Base_Addr_R[1], 4'hF, ok_wb ) ;
19811
    if ( ok_wb !== 1 )
19812
    begin
19813 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19814 63 mihad
        test_fail("PCI Base Address register 1 could not be written") ;
19815
        #1 ;
19816
        disable main ;
19817
    end
19818
 
19819
    // Set Address Mask of IMAGE
19820
    config_write( am_offset, Target_Addr_Mask_R[1], 4'hF, ok_wb ) ;
19821
    if ( ok_wb !== 1 )
19822
    begin
19823 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_AM1 register! Time %t ", $time);
19824 63 mihad
        test_fail("PCI Address Mask register 1 could not be written") ;
19825
        #1 ;
19826
        disable main ;
19827
    end
19828
 
19829
    // Disable all the features of the PCI Image 1
19830
    config_write( ctrl_offset, 0, 4'hF, ok_wb ) ;
19831
    if ( ok_wb !== 1 )
19832
    begin
19833 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_CTRL1 register! Time %t ", $time);
19834 63 mihad
        test_fail("PCI Image Control register 1 could not be written") ;
19835
        #1 ;
19836
        disable main ;
19837
    end
19838
 
19839 92 mihad
    // set waits to min on pci, max on wb
19840
    wb_init_waits   = 4 ;
19841
    wb_subseq_waits = 4 ;
19842
 
19843
    pci_init_waits   = 0 ;
19844
    pci_subseq_waits = 0 ;
19845 63 mihad
 
19846
    // do one dummy write, to receive a GNT park
19847
    if (test_mem)
19848
    begin
19849
        PCIU_MEM_WRITE
19850
        (
19851
            "MEM_WRITE ",                       // just the name
19852
            `Test_Master_1,                     // Behavioral Master to use for reference
19853
            Target_Base_Addr_R[1],              // Address of this transaction
19854
            32'hAAAA_AAAA,                      // Data For the transaction
19855
            4'h0,                               // Byte enables
19856
            1,                                  // length of transfer
19857
            `Test_One_Zero_Master_WS,           // Master Waits - don't care
19858
            `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19859
            `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19860
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19861
        );
19862
    end
19863
    else
19864
    begin
19865
        PCIU_IO_WRITE
19866
        (
19867
            `Test_Master_1,                     // Behavioral Master to use for reference
19868
            Target_Base_Addr_R[1],              // Address of this transaction
19869
            32'hAAAA_AAAA,                      // Data For the transaction
19870
            4'h0,                               // Byte enables
19871
            1,                                  // Size of transfer
19872
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19873
        ) ;
19874
    end
19875
 
19876
    do_pause( 1 ) ;
19877
    wb_transaction_progress_monitor
19878
    (
19879
        Target_Base_Addr_R[1],          // expected address
19880
        1'b1,                           // expected operation R/W
19881
        1,                              // 1
19882
        1'b1,                           // turn checking of transfers ON/OFF
19883
        ok_wb                           // succeeded/failed
19884
    ) ;
19885
 
19886
    if (ok_wb !== 1'b1)
19887
    begin
19888
        test_fail("WB Transaction Monitor detected invalid transaction on WB bus after posted memory write through target") ;
19889
        #1 ;
19890
        disable main ;
19891
    end
19892
 
19893
    fork
19894
    begin
19895
        if (test_mem)
19896
        begin
19897
            PCIU_MEM_WRITE
19898
            (
19899
                "MEM_WRITE ",                       // just the name
19900
                `Test_Master_1,                     // Behavioral Master to use for reference
19901
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19902
                32'hF0F0_F0F0,                      // Data For the transaction
19903
                4'h0,                               // Byte enables       
19904
                1,                                  // length of transfer
19905
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19906
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19907
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19908
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19909
            );
19910
        end
19911
        else
19912
        begin
19913
            PCIU_IO_WRITE
19914
            (
19915
                `Test_Master_1,                     // Behavioral Master to use for reference
19916
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19917
                32'hF0F0_F0F0,                      // Data For the transaction
19918
                4'h0,                               // Byte enables
19919
                1,                                  // Size of transfer
19920
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19921
            ) ;
19922
        end
19923
 
19924
        do_pause( 1 ) ;
19925
 
19926
        if (test_mem)
19927
        begin
19928
            PCIU_MEM_WRITE
19929
            (
19930
                "MEM_WRITE ",                       // just the name
19931
                `Test_Master_1,                     // Behavioral Master to use for reference
19932
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19933
                32'h0F0F_0F0F,                      // Data For the transaction
19934
                4'h0,                               // Byte enables
19935
                1,                                  // length of transfer
19936
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19937
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19938
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19939
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19940
            );
19941
        end
19942
        else
19943
        begin
19944
            PCIU_IO_WRITE
19945
            (
19946
                `Test_Master_1,                     // Behavioral Master to use for reference
19947
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19948
                32'h0F0F_0F0F,                      // Data For the transaction
19949
                4'h0,                               // Byte enables
19950
                1,                                  // Size of transfer
19951
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19952
            ) ;
19953
        end
19954
 
19955
        do_pause( 1 ) ;
19956
    end
19957
    begin
19958
        wb_transaction_progress_monitor
19959
        (
19960
            Target_Base_Addr_R[1] + 64,     // expected address
19961
            1'b1,                           // expected operation R/W
19962
            1,                              // expected number of transfers
19963
            1'b1,                           // turn checking of transfers ON/OFF
19964
            ok_wb                           // succeeded/failed
19965
        ) ;
19966
 
19967
        if ( ok_wb === 1 )
19968
        begin
19969
 
19970
            wb_transaction_progress_monitor
19971
            (
19972
                Target_Base_Addr_R[1] + 128,    // expected address
19973
                1'b1,                           // expected operation R/W
19974
                1,                              // expected number of transfers
19975
                1'b1,                           // turn checking of transfers ON/OFF
19976
                ok_wb                           // succeeded/failed
19977
            ) ;
19978
        end
19979
 
19980
        @(posedge pci_clock) ;
19981
        #1 ;
19982
        disable pci_error_mon1 ;
19983
    end
19984
    begin:pci_error_mon1
19985
        ok_pci = 1 ;
19986
        @(error_event_int) ;
19987
        ok_pci = 0 ;
19988
    end
19989
    join
19990
 
19991
    if ( ok_wb !== 1'b1 )
19992
    begin
19993
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19994
    end
19995
 
19996
    if ( ok_pci !== 1'b1)
19997
    begin
19998
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19999
    end
20000
 
20001
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
20002
    begin
20003
        #1 ;
20004
        disable main ;
20005
    end
20006
 
20007
    if ( test_mem )
20008
    begin
20009
        PCIU_MEM_READ
20010
        (
20011
            "MEM_READ  ",                   // description
20012
            `Test_Master_1,                 // behavioral master selection
20013
            Target_Base_Addr_R[1] + 64,     // address of access
20014
            32'hF0F0_F0F0,                  // expected read data
20015
            1,                              // number of transfers
20016
            8'h7_0,                         // don't care (wait cycles)
20017
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
20018
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
20019
            `Test_Target_Retry_On           // expected Target termination
20020
        );
20021
    end
20022
    else
20023
    begin
20024
        PCIU_IO_READ
20025
        (
20026
            `Test_Master_1,                 // behavioral master selection
20027
            Target_Base_Addr_R[1] + 64,     // address of access
20028
            32'hF0F0_F0F0,                  // expected read data
20029
            4'h0,                           // byte enables
20030
            1,                              // number of transfers
20031
            `Test_Target_Retry_On           // expected target termination
20032
        ) ;
20033
    end
20034
 
20035 64 mihad
    do_pause(1) ;
20036
 
20037 63 mihad
    wb_transaction_progress_monitor
20038
    (
20039
            Target_Base_Addr_R[1] + 64,     // expected address
20040
            1'b0,                           // expected operation R/W
20041
            1,                              // expected number transfers
20042
            1'b1,                           // turn checking of transfers ON/OFF
20043
            ok_wb                           // succeeded/failed
20044
    ) ;
20045
 
20046
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
20047
    repeat(3)
20048
        @(posedge pci_clock) ;
20049
 
20050
    // now read data
20051
    fork
20052
    begin
20053
        if ( test_mem )
20054
        begin
20055
            PCIU_MEM_READ
20056
            (
20057
                "MEM_READ  ",                   // description
20058
                `Test_Master_1,                 // behavioral master selection
20059
                Target_Base_Addr_R[1] + 64,     // address of access
20060
                32'hF0F0_F0F0,                  // expected read data
20061
                1,                              // number of transfers
20062
                8'h7_0,                         // don't care (wait cycles)
20063
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
20064
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
20065
                `Test_Target_Normal_Completion  // expected Target termination
20066
            );
20067
        end
20068
        else
20069
        begin
20070
            PCIU_IO_READ
20071
            (
20072
                `Test_Master_1,                 // behavioral master selection
20073
                Target_Base_Addr_R[1] + 64,     // address of access
20074
                32'hF0F0_F0F0,                  // expected read data
20075
                4'h0,                           // byte enables
20076
                1,                              // number of transfers
20077
                `Test_Target_Normal_Completion  // expected target termination
20078
            ) ;
20079
        end
20080
 
20081 64 mihad
        do_pause(1) ;
20082 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
20083
            @(posedge pci_clock) ;
20084
 
20085
        @(posedge pci_clock) ;
20086
        #1 ;
20087
        disable pci_error_mon2 ;
20088
    end
20089
    begin:pci_error_mon2
20090
        ok_pci = 1 ;
20091
        @(error_event_int) ;
20092
        ok_pci = 0 ;
20093
    end
20094
    join
20095
 
20096
    if ( ok_wb !== 1'b1 )
20097
    begin
20098
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
20099
    end
20100
 
20101
    if ( ok_pci !== 1'b1)
20102
    begin
20103
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
20104
    end
20105
 
20106
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
20107
    begin
20108
        #1 ;
20109
        disable main ;
20110
    end
20111
 
20112
    if ( test_mem )
20113
    begin
20114
        PCIU_MEM_READ
20115
        (
20116
            "MEM_READ  ",                   // description
20117
            `Test_Master_1,                 // behavioral master selection
20118
            Target_Base_Addr_R[1] + 128,    // address of access
20119
            32'h0F0F_0F0F,                  // expected read data
20120
            1,                              // number of transfers
20121
            8'h7_0,                         // don't care (wait cycles)
20122
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
20123
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
20124
            `Test_Target_Retry_On           // expected Target termination
20125
        );
20126
    end
20127
    else
20128
    begin
20129
        PCIU_IO_READ
20130
        (
20131
            `Test_Master_1,                 // behavioral master selection
20132
            Target_Base_Addr_R[1] + 128,    // address of access
20133
            32'h0F0F_0F0F,                  // expected read data
20134
            4'h0,                           // byte enables
20135
            1,                              // number of transfers
20136
            `Test_Target_Retry_On           // expected target termination
20137
        ) ;
20138
    end
20139
 
20140 64 mihad
    do_pause(1) ;
20141 63 mihad
    wb_transaction_progress_monitor
20142
    (
20143
            Target_Base_Addr_R[1] + 128,    // expected address
20144
            1'b0,                           // expected operation R/W
20145
            1,                              // expected number transfers
20146
            1'b1,                           // turn checking of transfers ON/OFF
20147
            ok_wb                           // succeeded/failed
20148
    ) ;
20149
 
20150
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
20151
    repeat(3)
20152
        @(posedge pci_clock) ;
20153
 
20154
    // now read data
20155
    fork
20156
    begin
20157
        if ( test_mem )
20158
        begin
20159
            PCIU_MEM_READ
20160
            (
20161
                "MEM_READ  ",                   // description
20162
                `Test_Master_1,                 // behavioral master selection
20163
                Target_Base_Addr_R[1] + 128,    // address of access
20164
                32'h0F0F_0F0F,                  // expected read data
20165
                1,                              // number of transfers
20166
                8'h7_0,                         // don't care (wait cycles)
20167
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
20168
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
20169
                `Test_Target_Normal_Completion  // expected Target termination
20170
            );
20171
        end
20172
        else
20173
        begin
20174
            PCIU_IO_READ
20175
            (
20176
                `Test_Master_1,                 // behavioral master selection
20177
                Target_Base_Addr_R[1] + 128,    // address of access
20178
                32'h0F0F_0F0F,                  // expected read data
20179
                4'h0,                           // byte enables
20180
                1,                              // number of transfers
20181
                `Test_Target_Normal_Completion  // expected target termination
20182
            ) ;
20183
        end
20184
 
20185 64 mihad
        do_pause(1) ;
20186 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
20187
            @(posedge pci_clock) ;
20188
 
20189
        @(posedge pci_clock) ;
20190
        #1 ;
20191
        disable pci_error_mon3 ;
20192
    end
20193
    begin:pci_error_mon3
20194
        ok_pci = 1 ;
20195
        @(error_event_int) ;
20196
        ok_pci = 0 ;
20197
    end
20198
    join
20199
 
20200
    if ((ok_wb === 1'b1) && (ok_pci === 1'b1))
20201
        test_ok ;
20202
 
20203
    if ( ok_wb !== 1'b1 )
20204
    begin
20205
        test_fail("WB Master started invalid transaction or none at all after Target read was requested") ;
20206
    end
20207
 
20208
    if ( ok_pci !== 1'b1)
20209
    begin
20210
        test_fail("PCI Behavioral Master or Monitor signaled an error during read from PCI Bridge Target") ;
20211
    end
20212
 
20213 69 mihad
    // Disable used image
20214
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
20215
    if ( ok_wb !== 1 )
20216
    begin
20217
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
20218
        test_fail("PCI Base Address register 1 could not be written") ;
20219
        #1 ;
20220
        disable main ;
20221
    end
20222
 
20223 63 mihad
    master1_check_received_data = master_check_data_previous ;
20224
end
20225
endtask // target_special_corner_case_test
20226
`endif
20227
 
20228 104 mihad
`ifdef DO_CORNER_CASE_TESTS
20229 69 mihad
task master_special_corner_case_test ;
20230
    reg   [11:0] ctrl_offset ;
20231
    reg   [11:0] ba_offset ;
20232
    reg   [11:0] am_offset ;
20233
    reg `WRITE_STIM_TYPE write_data ;
20234
    reg `READ_STIM_TYPE  read_data ;
20235
    reg `READ_RETURN_TYPE read_status ;
20236
 
20237
    reg `WRITE_RETURN_TYPE write_status ;
20238
    reg `WB_TRANSFER_FLAGS flags ;
20239
    reg ok_pci   ;
20240
    reg ok_wb ;
20241
 
20242
    reg [31:0] target_address ;
20243
 
20244
    reg [11:0] pci_ctrl_offset ;
20245
 
20246
    reg [31:0] image_base ;
20247
begin:main
20248
    test_name = "WISHBONE SLAVE UNIT SPECIAL CORNER CASE" ;
20249
    pci_ctrl_offset = 12'h4 ;
20250
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
20251
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
20252
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
20253
 
20254
    target_address  = `BEH_TAR1_MEM_START ;
20255
    image_base      = 0 ;
20256
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
20257
 
20258
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
20259
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
20260
 
20261
    flags                      = 0 ;
20262
    flags`INIT_WAITS           = 0 ;
20263
    flags`SUBSEQ_WAITS         = 0 ;
20264
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
20265
 
20266
    test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = `Test_Devsel_Fast ;
20267
    test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
20268
    test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
20269
 
20270
    // enable master & target operation
20271
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok_wb) ;
20272
    if ( ok_wb !== 1 )
20273
    begin
20274
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write PCI Device Control register! Time %t ", $time) ;
20275
        test_fail("write to PCI Device Control register didn't succeede");
20276
        disable main ;
20277
    end
20278
 
20279
    // prepare image control register
20280
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok_wb) ;
20281
    if ( ok_wb !== 1 )
20282
    begin
20283
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
20284
        test_fail("write to WB Image Control register didn't succeede");
20285
        disable main ;
20286
    end
20287
 
20288
    // prepare base address register
20289
    config_write( ba_offset, image_base, 4'hF, ok_wb ) ;
20290
    if ( ok_wb !== 1 )
20291
    begin
20292
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
20293
        test_fail("write to WB Base Address register didn't succeede");
20294
        disable main ;
20295
    end
20296
 
20297
    // write address mask register
20298
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok_wb ) ;
20299
    if ( ok_wb !== 1 )
20300
    begin
20301
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_AM1 register! Time %t ", $time) ;
20302
        test_fail("write to WB Address Mask register didn't succeede");
20303
        disable main ;
20304
    end
20305
 
20306
    fork
20307
    begin
20308
 
20309
        // do one dummy read, to receive bus gnt
20310
        read_data`READ_ADDRESS  = target_address ;
20311
        read_data`READ_SEL      = 4'hF ;
20312
 
20313
        // handle retries
20314
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
20315
 
20316
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
20317
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
20318
        begin
20319
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
20320
            test_fail("PCI bridge didn't process the delayed read as expected");
20321
            disable main ;
20322
        end
20323
 
20324
        write_data`WRITE_ADDRESS = target_address + 64;
20325
        write_data`WRITE_DATA    = 32'hABCD_EF12 ;
20326
        write_data`WRITE_SEL     = 4'hF ;
20327
 
20328
        wishbone_master.blk_write_data[0] = write_data ;
20329
 
20330
        write_data`WRITE_ADDRESS = target_address + 128 ;
20331
        write_data`WRITE_DATA    = ~write_data`WRITE_DATA ;
20332
        write_data`WRITE_SEL     = 4'hF ;
20333
 
20334
        wishbone_master.blk_write_data[1] = write_data ;
20335
 
20336
        // no retries should happen
20337
        flags`WB_TRANSFER_AUTO_RTY = 0 ;
20338
 
20339
        flags`WB_TRANSFER_SIZE = 2 ;
20340
 
20341
        wishbone_master.wb_block_write( flags, write_status ) ;
20342
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
20343
        begin
20344
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process block memory write! Time %t ", $time) ;
20345
            test_fail("WB Slave state machine failed to post block memory write");
20346
            disable main ;
20347
        end
20348
 
20349
        // read data back
20350
        read_data`READ_ADDRESS  = target_address + 64 ;
20351
        read_data`READ_SEL      = 4'hF ;
20352
 
20353
        // handle retries
20354
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
20355
 
20356
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
20357
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
20358
        begin
20359
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
20360
            test_fail("PCI bridge didn't process the delayed read as expected");
20361
            disable main ;
20362
        end
20363
 
20364
        if (read_status`READ_DATA !== 32'hABCD_EF12)
20365
        begin
20366
            display_warning(target_address + 64, 32'hABCD_EF12, read_status`READ_DATA) ;
20367
            test_fail("PCI bridge returned unexpected Read Data");
20368
            ok_wb = 0 ;
20369
        end
20370
 
20371
        // read second data back
20372
        read_data`READ_ADDRESS  = target_address + 128 ;
20373
        read_data`READ_SEL      = 4'hF ;
20374
 
20375
        // handle retries
20376
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
20377
 
20378
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
20379
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
20380
        begin
20381
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
20382
            test_fail("PCI bridge didn't process the delayed read as expected");
20383
            disable main ;
20384
        end
20385
 
20386
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
20387
        begin
20388
            display_warning(target_address + 128, write_data`WRITE_DATA, read_status`READ_DATA) ;
20389
            test_fail("PCI bridge returned unexpected Read Data");
20390
            ok_wb = 0 ;
20391
        end
20392
    end
20393
    begin
20394
 
20395
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
20396
        if ( ok_pci !== 1 )
20397
        begin
20398
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
20399
        end
20400
 
20401
        if(ok_pci)
20402
        begin
20403
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
20404
            if ( ok_pci !== 1 )
20405
            begin
20406
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
20407
            end
20408
        end
20409
 
20410
        if (ok_pci)
20411
        begin
20412
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
20413
            if ( ok_pci !== 1 )
20414
            begin
20415
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
20416
            end
20417
        end
20418
 
20419
        if (ok_pci)
20420
        begin
20421
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
20422
            if ( ok_pci !== 1 )
20423
            begin
20424
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
20425
            end
20426
        end
20427
 
20428
        if (ok_pci)
20429
        begin
20430
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
20431
            if ( ok_pci !== 1 )
20432
            begin
20433
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
20434
            end
20435
        end
20436
    end
20437
    join
20438
 
20439
    if (ok_wb && ok_pci)
20440
        test_ok ;
20441
 
20442
    // disable the image
20443
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
20444
    if ( ok_wb !== 1 )
20445
    begin
20446
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
20447
        test_fail("write to WB Base Address register didn't succeede");
20448
        disable main ;
20449
    end
20450
end
20451
endtask // master_special_corner_case_test
20452
`endif
20453
 
20454 73 mihad
task test_target_overload ;
20455
    reg ok_pci ;
20456
    reg ok_wb  ;
20457
    reg ok ;
20458
    reg [2:0] test_image_num ;
20459
    reg addr_translated ;
20460
    integer transfered ;
20461
    reg [2:0] received_termination ;
20462
    integer total_transfers ;
20463
    reg [31:0] transaction_sizes [0:1024] ;
20464
    integer pci_transaction_num ;
20465
    integer wb_transaction_num ;
20466
    reg [31:0] current_wb_address ;
20467
    reg io_mapped ;
20468
    integer current_size ;
20469 92 mihad
    reg [31:0] current_pci_address ;
20470
    reg [31:0] expected_data ;
20471 73 mihad
begin:main
20472
 
20473
    `ifdef HOST
20474
    io_mapped = 1'b0 ;
20475
    `endif
20476
 
20477
    test_image_num = 'd1 ;
20478
    `ifdef GUEST
20479
    io_mapped = `PCI_BA1_MEM_IO ;
20480
    `endif
20481
 
20482
    `ifdef PCI_IMAGE2
20483
        test_image_num = 'd2 ;
20484
        `ifdef GUEST
20485
            io_mapped = `PCI_BA2_MEM_IO ;
20486
        `endif
20487
    `endif
20488
 
20489
    `ifdef PCI_IMAGE3
20490
        test_image_num = 'd3 ;
20491
        `ifdef GUEST
20492
            io_mapped = `PCI_BA3_MEM_IO ;
20493
        `endif
20494
    `endif
20495
 
20496
    `ifdef PCI_IMAGE4
20497
        test_image_num = 'd4 ;
20498
        `ifdef GUEST
20499
            io_mapped = `PCI_BA4_MEM_IO ;
20500
        `endif
20501
    `endif
20502
 
20503
    `ifdef PCI_IMAGE5
20504
        test_image_num = 'd5 ;
20505
        `ifdef GUEST
20506
            io_mapped = `PCI_BA5_MEM_IO ;
20507
        `endif
20508
    `endif
20509
 
20510
    test_name = "PCI TARGET OVERLOAD" ;
20511
    // configure target image 1 via bus accesses
20512
    pci_configure_pci_target_image
20513
    (
20514
        1'b1,                               // selects whether to configure image with bus accesses or directly with dot notation in the configuration space
20515
        test_image_num,                     // image number
20516
        Target_Base_Addr_R[test_image_num], // base address
20517
        Target_Addr_Mask_R[test_image_num], // address mask
20518
        Target_Tran_Addr_R[test_image_num], // translation address
20519
        1'b0,                               // io/mem mapping select
20520
        1'b0,                               // prefetch enable
20521
        1'b1,                               // address translation enable
20522
        ok                                  // finished succesfully
20523
    );
20524
    if (ok !== 1'b1)
20525
    begin
20526
        test_fail("configuration of PCI Target Image didn't succeede") ;
20527
        #1 disable main ;
20528
    end
20529
 
20530
    `ifdef ADDR_TRAN_IMPL
20531
        addr_translated = 1'b1 ;
20532
    `else
20533
        addr_translated = 1'b0 ;
20534
    `endif
20535
 
20536
    // set wb slave's response to max wait cycles
20537
    wishbone_slave.cycle_response
20538
    (
20539
        3'b100,          // ACK, ERR, RTY termination
20540 92 mihad
        wb_subseq_waits, // wait cycles before response
20541 73 mihad
 
20542
    ) ;
20543
 
20544
    ok_pci = 1 ;
20545
    ok_wb  = 1 ;
20546
 
20547
    for (current_size = 2 ; (current_size <= 1024) && ok_pci && ok_wb && ok ; current_size = current_size * 2)
20548
    begin
20549
 
20550
        total_transfers = 0 ;
20551
        pci_transaction_num = 0 ;
20552
        wb_transaction_num = 0 ;
20553
 
20554 92 mihad
        current_wb_address = pci_to_wb_addr_convert
20555
                             (
20556
                               Target_Base_Addr_R[test_image_num], // pci address
20557
                               Target_Tran_Addr_R[test_image_num], // translation address
20558
                               addr_translated
20559
                              );
20560
 
20561
        current_wb_address  = current_wb_address & Target_Addr_Mask_R[test_image_num] ;
20562
        current_wb_address  = current_wb_address + (('d1024 - current_size) * 4) ;
20563
        current_pci_address = (Target_Base_Addr_R[test_image_num] & Target_Addr_Mask_R[test_image_num]) + (('d1024 - current_size) * 4) ;
20564
 
20565 73 mihad
        fork
20566
        begin
20567
            while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20568
            begin
20569
                // try transfering 4kB with no wait cycles through the target
20570
                ipci_unsupported_commands_master.normal_write_transfer
20571
                (
20572
                    // always write to the end of the 4kB window
20573 92 mihad
                    current_pci_address,                            // start_address
20574
                    io_mapped ? `BC_IO_WRITE : `BC_MEM_WRITE,       // bus_command
20575
                    (current_size - total_transfers),               // size
20576
                    pci_subseq_waits[2:0],                          // subsequent wait cycles
20577
                    transfered,                                     // actual_transfer
20578
                    received_termination                            // received_termination
20579 73 mihad
                );
20580
                if (transfered > 0)
20581
                begin
20582
                    transaction_sizes[pci_transaction_num] = transfered ;
20583 92 mihad
                    current_pci_address = current_pci_address + (4 * transfered) ;
20584 73 mihad
                    pci_transaction_num = pci_transaction_num + 1'b1 ;
20585
                end
20586
                total_transfers = total_transfers + transfered ;
20587
                if (received_termination > 2) // terminations with numbers 3(Target Abort), 4(Master Abort) and 5(Error) are not allowed
20588
                begin
20589
                    ok_pci = 0 ;
20590
                    if (received_termination == 3)
20591
                        test_fail("PCI Target signalled Target Abort") ;
20592
 
20593
                    if (received_termination == 4)
20594
                        test_fail("PCI Master generated Master Abort") ;
20595
 
20596
                    if (received_termination == 5)
20597
                        test_fail("PCI behavioral master signaled severe error") ;
20598
                end
20599
            end
20600
        end
20601
        begin:wb_monitoring
20602
            while (((total_transfers < current_size) || (pci_transaction_num > wb_transaction_num)) && ok_pci && ok_wb && ok)
20603
            begin
20604
                wait(pci_transaction_num > wb_transaction_num) ;
20605 92 mihad
                fork
20606 73 mihad
                begin
20607 92 mihad
                    wb_transaction_progress_monitor
20608
                    (
20609
                        current_wb_address,                     //address
20610
                        1'b1,                                   //write/read
20611
                        transaction_sizes[wb_transaction_num],  //num_of_transfers
20612
                        1'b1,                                   //check_transfers
20613
                        ok_wb                                   // success/fail
20614
                    );
20615
                    current_wb_address = current_wb_address + (transaction_sizes[wb_transaction_num] * 4) ;
20616
                    wb_transaction_num = wb_transaction_num + 1'b1 ;
20617
                    if (ok_wb !== 1'b1)
20618
                    begin
20619
                        test_fail("WB Transaction progress monitor detected invalid transaction or none at all on WB bus");
20620
                    end
20621 73 mihad
                end
20622 92 mihad
                begin
20623
                    @(posedge wb_clock) ;
20624
                    while (CYC_O !== 1'b1)
20625
                        @(posedge wb_clock) ;
20626
 
20627
                    while (CYC_O === 1'b1)
20628
                    begin
20629
                        if (STB_O === 1'b1)
20630
                        begin
20631
 
20632
                            expected_data = Target_Base_Addr_R[test_image_num] & Target_Addr_Mask_R[test_image_num] ;
20633
                            expected_data = expected_data | (ADR_O & ~Target_Addr_Mask_R[test_image_num]) ;
20634
                            expected_data = ~expected_data ;
20635
 
20636
                            if (MDAT_O !== expected_data)
20637
                            begin
20638
                                $display("Time %t. Wrong data from WB_MASTER detected! Expected %h, Actual %h", $time, expected_data, MDAT_O) ;
20639
                                test_fail("Wrong WB MASTER output data detected") ;
20640
                            end
20641
                        end
20642
                        @(posedge wb_clock) ;
20643
                    end
20644
                end
20645
                join
20646 73 mihad
            end
20647
 
20648 92 mihad
//            wb_transaction_num = wb_transaction_num - 1'b1 ;
20649
//            current_wb_address = current_wb_address - (transaction_sizes[wb_transaction_num] * 4) ;
20650 73 mihad
 
20651
            if (ok)
20652
                #1 disable pci_monitoring ;
20653
        end
20654
        begin:pci_monitoring
20655
            @(error_event_int) ;
20656
            test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20657
            ok = 0 ;
20658
            ok_pci = 0 ;
20659
            ok_wb  = 0 ;
20660
        end
20661
        join
20662
    end
20663
 
20664
    if ((ok && ok_wb && ok_pci) === 1'b1)
20665
        test_ok ;
20666
end
20667
endtask // test_target_overload
20668
 
20669
task test_master_overload ;
20670 106 mihad
 
20671 73 mihad
    reg ok_pci ;
20672
    reg ok_wb  ;
20673
    reg ok ;
20674
    reg [2:0] test_image_num ;
20675
    reg [2:0] received_termination ;
20676 92 mihad
    reg [31:0] transaction_sizes [0:4095] ;
20677 73 mihad
 
20678
    reg `WRITE_STIM_TYPE write_data ;
20679
 
20680
    reg `WRITE_RETURN_TYPE write_status ;
20681
    reg `WB_TRANSFER_FLAGS write_flags ;
20682
 
20683
    reg [31:0] image_base ;
20684
    reg [31:0] target_address ;
20685
 
20686
begin:main
20687
 
20688
    // set behavioral target to respond normally
20689
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
20690
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
20691
 
20692
    test_image_num = 'd1 ;
20693
 
20694
    `ifdef WB_IMAGE2
20695
        test_image_num = 'd2 ;
20696
    `endif
20697
 
20698
    `ifdef WB_IMAGE3
20699
        test_image_num = 'd3 ;
20700
    `endif
20701
 
20702
    `ifdef WB_IMAGE4
20703
        test_image_num = 'd4 ;
20704
    `endif
20705
 
20706
    `ifdef WB_IMAGE5
20707
        test_image_num = 'd5 ;
20708
    `endif
20709
 
20710
    test_name = "MASTER OVERLOAD" ;
20711
 
20712
    target_address  = `BEH_TAR1_MEM_START ;
20713
    image_base      = 0 ;
20714 92 mihad
 
20715 73 mihad
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
20716
 
20717 92 mihad
    target_address = image_base ;
20718 73 mihad
 
20719 92 mihad
    write_flags                        = 0 ;
20720
    write_flags`INIT_WAITS             = wb_init_waits ;
20721
    write_flags`SUBSEQ_WAITS           = wb_subseq_waits ;
20722
    write_flags`WB_TRANSFER_AUTO_RTY   = 0 ;
20723
    write_flags`WB_TRANSFER_CAB        = 1'b1 ;
20724 73 mihad
 
20725
    pci_configure_wb_slave_image
20726
    (
20727
        1'b1,           // use_bus
20728
        test_image_num, // image_num
20729
        image_base,     // base address
20730 92 mihad
        32'hFFFF_C000,  // address mask
20731 73 mihad
        32'h0000_0000,  // translation address
20732
        1'b0,           // io/mem mapping select
20733
        1'b1,           // prefetch enable
20734
        1'b0,           // address translation enable
20735
        1'b1,           // memory read line enable
20736
        ok              // finished succesfully
20737
    ) ;
20738
 
20739
    if (ok !== 1'b1)
20740
    begin
20741
        test_fail("WB image configuration failed") ;
20742
        disable main ;
20743
    end
20744
 
20745
    ok_wb  = 1 ;
20746
    ok_pci = 1 ;
20747
 
20748 106 mihad
    fork
20749
    begin:wb_write_overflow_blk
20750
        integer current_write_size ;
20751
        integer total_wb_transfers ;
20752
        reg [11:0] wb_transaction_num ;
20753
        integer i ;
20754 73 mihad
 
20755 106 mihad
        wb_transaction_num = 0 ;
20756
        transaction_sizes[wb_transaction_num[11:0]] = 0 ;
20757 73 mihad
 
20758 106 mihad
        for (current_write_size = 1 ; (current_write_size <= 1024) & ok_pci & ok_wb & ok ; current_write_size = current_write_size * 2)
20759 92 mihad
        begin
20760
 
20761 106 mihad
            // fill wishbone master's memory with data - inverted addresses
20762
            write_data = 0 ;
20763
            write_data`WRITE_SEL = 4'hF ;
20764
            for (i = 0 ; i < current_write_size ; i = i + 1)
20765 73 mihad
            begin
20766 106 mihad
                write_data`WRITE_ADDRESS = image_base + ((('d1024 - current_write_size) * 4) + (i * 4)) ;
20767
                write_data`WRITE_DATA    = ~(write_data`WRITE_ADDRESS);
20768
                wishbone_master.blk_write_data[i] = write_data ;
20769
            end
20770
 
20771
            total_wb_transfers = 0 ;
20772
 
20773
            write_flags`WB_FAST_B2B = 1'b0 ;
20774
 
20775
            while ((total_wb_transfers < current_write_size) & ok_pci & ok_wb & ok)
20776
            begin
20777
 
20778
                write_flags`WB_TRANSFER_SIZE = current_write_size - total_wb_transfers ;
20779 73 mihad
                wishbone_master.wb_block_write(write_flags, write_status) ;
20780 106 mihad
                write_flags`WB_FAST_B2B            = 1'b1 ;
20781
 
20782
                if (write_status`CYC_ERR | ((write_status`CYC_ERR !== 1'b1) & (write_status`CYC_RTY !== 1'b1) & (write_status`CYC_ACK !== 1'b1)))
20783 73 mihad
                begin
20784 106 mihad
                    $display("%m detected an error!") ;
20785 73 mihad
                    test_fail("Wishbone slave signaled an error or did not respond to normal write access") ;
20786
                    ok_wb = 0 ;
20787
                end
20788
 
20789 106 mihad
                total_wb_transfers = total_wb_transfers + write_status`CYC_ACTUAL_TRANSFER ;
20790
 
20791
                if (write_status`CYC_ACTUAL_TRANSFER > 0)
20792 73 mihad
                begin
20793 106 mihad
                    transaction_sizes[wb_transaction_num[11:0]] = write_status`CYC_ACTUAL_TRANSFER ;
20794
                    wishbone_master.shift_write_buffer(write_status`CYC_ACTUAL_TRANSFER) ;
20795 92 mihad
 
20796 73 mihad
                    wb_transaction_num = wb_transaction_num + 1'b1 ;
20797 106 mihad
                    transaction_sizes[wb_transaction_num[11:0]] = 0 ;
20798
 
20799 73 mihad
                end
20800
            end
20801
        end
20802 106 mihad
    end
20803
    begin:pci_models_monitoring
20804
        reg [31:0] ret_adr ; reg [3:0] ret_bc ; integer ret_num_of_transfers ; integer total_ret_num_of_transfers ;
20805
        reg ret_gnt_deasserted ;
20806
        integer current_write_size ; reg [11:0] pci_transaction_num ; reg [31:0] current_pci_address ;
20807
        integer i ;
20808
 
20809
        pci_transaction_num = 0 ;
20810
 
20811
        for (current_write_size = 1 ; (current_write_size <= 1024) & ok_pci & ok_wb & ok ; current_write_size = current_write_size * 2)
20812
        begin
20813
 
20814
            current_pci_address = image_base + ('d1024 - current_write_size) * 4 ;
20815
 
20816
            total_ret_num_of_transfers = 0 ;
20817
 
20818
            while ( (total_ret_num_of_transfers < current_write_size) & ok_pci & ok_wb & ok )
20819 73 mihad
            begin
20820 106 mihad
                monitor32.get_pci_op(ret_adr, ret_bc) ;
20821
                monitor32.get_pci_op_num_of_transfers(ret_num_of_transfers, ret_gnt_deasserted) ;
20822 73 mihad
 
20823 106 mihad
                wait( transaction_sizes[pci_transaction_num[11:0]] > 0) ;
20824
 
20825
                if (ret_adr !== current_pci_address)
20826
                begin
20827
                    $display("%m detected an error!") ;
20828
                    test_fail("PCI Master provided unexpected address when it initiated write operation") ;
20829
                    ok_pci = 1'b0 ;
20830
                end
20831
 
20832
                if (ret_bc !== `BC_MEM_WRITE)
20833
                begin
20834
                    $display("%m detected an error!") ;
20835
                    test_fail("PCI Master provided unexpected bus command when it should initiate write operation") ;
20836
                    ok_pci = 1'b0 ;
20837
                end
20838
 
20839
                if (ret_num_of_transfers !== transaction_sizes[pci_transaction_num[11:0]])
20840
                begin
20841
                    $display("%m detected an error!") ;
20842
                    test_fail("PCI Master didn't transfer expected number of words during a burst transfer") ;
20843
                    ok_pci = 1'b0 ;
20844
                end
20845
 
20846
                total_ret_num_of_transfers = total_ret_num_of_transfers + ret_num_of_transfers ;
20847
 
20848 92 mihad
                current_pci_address = current_pci_address + (4 * transaction_sizes[pci_transaction_num[11:0]]) ;
20849 73 mihad
                pci_transaction_num = pci_transaction_num + 1'b1 ;
20850 106 mihad
            end
20851
 
20852
            // check the written data
20853
            @(posedge pci_clock) ;
20854
            #1 ;
20855
            for (i = 0 ; i < current_write_size ; i = i + 1)
20856
            begin:data_chk_blk
20857
                reg [31:0] exp_dat ; reg [31:0] act_dat ;
20858
 
20859
                exp_dat = image_base + ((('d1024 - current_write_size) * 4) + (i * 4)) ;
20860
                exp_dat = ~exp_dat ;
20861
                act_dat = pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem['d1024 - current_write_size + i] ;
20862
                if (exp_dat != act_dat)
20863 73 mihad
                begin
20864 106 mihad
                    $display("Time %t!", $time) ;
20865
                    $display("Wrong data written to the target detected! Expected data %h, actual %h", exp_dat, act_dat) ;
20866
                    test_fail("wrong data was written to the target during the test") ;
20867
                    ok_pci = 0 ;
20868
                    disable main ;
20869 73 mihad
                end
20870
            end
20871 106 mihad
        end
20872 73 mihad
 
20873 106 mihad
        // wait two cycles for any wrong parity errors etc..
20874
        repeat (2)
20875
            @(posedge pci_clock) ;
20876 92 mihad
 
20877 106 mihad
        if (ok)
20878
            #1 disable pci_monitoring ;
20879 73 mihad
    end
20880 106 mihad
    begin:pci_monitoring
20881
        @(error_event_int) ;
20882
        test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20883
        ok = 0 ;
20884
        ok_pci = 0 ;
20885
        ok_wb  = 0 ;
20886
    end
20887
    join
20888 73 mihad
 
20889 106 mihad
    if ((ok & ok_wb & ok_pci) === 1'b1)
20890
        test_ok ;
20891
 
20892 92 mihad
// next two tests take forever - commented out - they are here, because some bugs were reported
20893
// they are commented out, because no bug could be found with them
20894
/*
20895
    total_transfers = 0 ;
20896
    pci_transaction_num = 0 ;
20897
    wb_transaction_num = 0 ;
20898
    current_size = 'd2880 ;
20899
 
20900
    write_data = 0 ;
20901
    write_data`WRITE_SEL = 4'hF ;
20902
    for (i = 0 ; i < current_size ; i = i + 1)
20903
    begin
20904
        write_data`WRITE_ADDRESS = image_base + (i * 4) ;
20905
        write_data`WRITE_DATA    = ~(write_data`WRITE_ADDRESS);
20906
        wishbone_master.blk_write_data[i] = write_data ;
20907
    end
20908
 
20909
    current_pci_address = image_base ;
20910
    fork
20911
    begin
20912
        while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20913
        begin
20914
 
20915
            // wait 1 clock cycle after successfull 64 word transfer, because fast b2b cycles are used
20916
            if ((total_transfers % 64) === 0)
20917
                @(posedge wb_clock) ;
20918
 
20919
            write_flags`WB_TRANSFER_SIZE = 64 - (total_transfers % 64) ;
20920
 
20921
            wishbone_master.wb_block_write(write_flags, write_status) ;
20922
            if (write_status`CYC_ERR || ((write_status`CYC_ERR !== 1'b1) && (write_status`CYC_RTY !== 1'b1) && (write_status`CYC_ACK !== 1'b1)))
20923
            begin
20924
                test_fail("Wishbone slave signaled an error or did not respond to normal write access") ;
20925
                ok_wb = 0 ;
20926
            end
20927
 
20928
            transfered = write_status`CYC_ACTUAL_TRANSFER ;
20929
            total_transfers = total_transfers + transfered ;
20930
            if (transfered > 0)
20931
            begin
20932
                transaction_sizes[wb_transaction_num[11:0]] = transfered ;
20933
                wishbone_master.shift_write_buffer(transfered) ;
20934
 
20935
                wb_transaction_num = wb_transaction_num + 1'b1 ;
20936
            end
20937
        end
20938
    end
20939
    begin:pci_models_monitoring1
20940
        while (((total_transfers < current_size) || (wb_transaction_num > pci_transaction_num)) && ok_pci && ok_wb && ok)
20941
        begin
20942
            wait(wb_transaction_num > pci_transaction_num) ;
20943
            pci_transaction_progress_monitor
20944
            (
20945
                current_pci_address,                            // address
20946
                `BC_MEM_WRITE,                                  // bus_command
20947
                transaction_sizes[pci_transaction_num[11:0]],   // num_of_transfers
20948
                0,                                              // num_of_cycles
20949
                1'b1,                                           // check_transfers
20950
                1'b0,                                           // check_cycles
20951
                1'b0,                                           // doing_fast_back_to_back
20952
                ok_pci                                          // ok
20953
            ) ;
20954
 
20955
            current_pci_address = current_pci_address + (4 * transaction_sizes[pci_transaction_num[11:0]]) ;
20956
            pci_transaction_num = pci_transaction_num + 1'b1 ;
20957
            if (ok_pci !== 1'b1)
20958
            begin
20959
                test_fail("PCI Transaction progress monitor detected invalid transaction or none at all on PCI bus");
20960
            end
20961
        end
20962
 
20963
        if (ok)
20964
            #1 disable pci_monitoring1 ;
20965
    end
20966
    begin:pci_monitoring1
20967
        @(error_event_int) ;
20968
        test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20969
        ok = 0 ;
20970
        ok_pci = 0 ;
20971
        ok_wb  = 0 ;
20972
    end
20973
    join
20974
 
20975
    // nothing should go on on pci from now on
20976
    @(posedge pci_clock) ;
20977
    for (i = 0 ; (i < 100) & (FRAME === 1'b1) ; i = i + 1)
20978
        @(posedge pci_clock) ;
20979
 
20980
    if (i !== 100)
20981
    begin
20982
        $display("Time %t", $time) ;
20983
        $display("Unexpected transaction detected on PCI bus") ;
20984
        test_fail("unexpected transaction was detected on PCI bus");
20985
    end
20986
 
20987
    total_transfers = 0 ;
20988
    pci_transaction_num = 0 ;
20989
    wb_transaction_num = 0 ;
20990
    current_size = 'd1024 *'d2000 ;
20991
 
20992
    write_data = 0 ;
20993
    write_data`WRITE_SEL = 4'hF ;
20994
 
20995
    current_pci_address = image_base ;
20996
 
20997
    fork
20998
    begin
20999
 
21000
        while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
21001
        begin
21002
 
21003
            if ((total_transfers % 'd1024) === 0)
21004
            begin
21005
                // prepare new data
21006
                for (i = 0 ; i < 1024 ; i = i + 1)
21007
                begin
21008
                    j = i + 1 ;
21009
                    write_data`WRITE_ADDRESS = image_base + (i * 4) ;
21010
                    write_data`WRITE_DATA    = $random(j) ;
21011
                    wishbone_master.blk_write_data[i] = write_data ;
21012
                end
21013
 
21014
                // because fast b2b cycles are used, wait for 1 cycle
21015
                @(posedge wb_clock) ;
21016
            end
21017
 
21018
            write_flags`WB_TRANSFER_SIZE = 'd1024 - (total_transfers % 'd1024) ;
21019
 
21020
            wishbone_master.wb_block_write(write_flags, write_status) ;
21021
            if (write_status`CYC_ERR || ((write_status`CYC_ERR !== 1'b1) && (write_status`CYC_RTY !== 1'b1) && (write_status`CYC_ACK !== 1'b1)))
21022
            begin
21023
                test_fail("Wishbone slave signaled an error or did not respond to normal write access") ;
21024
                ok_wb = 0 ;
21025
            end
21026
 
21027
            transfered = write_status`CYC_ACTUAL_TRANSFER ;
21028
            total_transfers = total_transfers + transfered ;
21029
            if (transfered > 0)
21030
            begin
21031
                transaction_sizes[wb_transaction_num[11:0]] = transfered ;
21032
                wishbone_master.shift_write_buffer(transfered) ;
21033
 
21034
                wb_transaction_num = wb_transaction_num + 1'b1 ;
21035
            end
21036
        end
21037
    end
21038
    begin:pci_models_monitoring2
21039
        while (((total_transfers < current_size) || (wb_transaction_num > pci_transaction_num)) && ok_pci && ok_wb && ok)
21040
        begin
21041
            wait(wb_transaction_num > pci_transaction_num) ;
21042
            pci_transaction_progress_monitor
21043
            (
21044
                current_pci_address,                            // address
21045
                `BC_MEM_WRITE,                                  // bus_command
21046
                transaction_sizes[pci_transaction_num[11:0]],   // num_of_transfers
21047
                0,                                              // num_of_cycles
21048
                1'b1,                                           // check_transfers
21049
                1'b0,                                           // check_cycles
21050
                1'b0,                                           // doing_fast_back_to_back
21051
                ok_pci                                          // ok
21052
            ) ;
21053
 
21054
            current_pci_address = current_pci_address + (4 * transaction_sizes[pci_transaction_num[11:0]]) ;
21055
            if (current_pci_address === (image_base + 'd4096))
21056
            begin
21057
                @(posedge pci_clock) ;
21058
                @(posedge pci_clock) ;
21059
                current_pci_address = image_base ;
21060
                for (k = 0 ; k < 1024 ; k = k + 1)
21061
                begin
21062
                    l = k + 1 ;
21063
                    if (pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[k] !== $random(l))
21064
                    begin
21065
                        $display("Time %t", $time) ;
21066
                        $display("Wrong data written to the target device!") ;
21067
                        $display("Expected data %h, actual %h", $random(l), pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[k]) ;
21068
                        ok_pci = 0 ;
21069
                        test_fail("wrong data was written to pci target device") ;
21070
                    end
21071
                end
21072
            end
21073
 
21074
            pci_transaction_num = pci_transaction_num + 1'b1 ;
21075
            if (ok_pci !== 1'b1)
21076
            begin
21077
                test_fail("PCI Transaction progress monitor detected invalid transaction or none at all on PCI bus");
21078
            end
21079
        end
21080
 
21081
        repeat(2)
21082
            @(posedge pci_clock) ;
21083
 
21084
        if (ok)
21085
            #1 disable pci_monitoring2 ;
21086
    end
21087
    begin:pci_monitoring2
21088
        @(error_event_int) ;
21089
        test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
21090
        ok = 0 ;
21091
        ok_pci = 0 ;
21092
        ok_wb  = 0 ;
21093
    end
21094
    join
21095
*/
21096 73 mihad
    // disable the image
21097
    pci_configure_wb_slave_image
21098
    (
21099
        1'b1,           // use_bus
21100
        test_image_num, // image_num
21101
        image_base,     // base address
21102
        32'h0000_0000,  //  address mask
21103
        32'h0000_0000,  // translation address
21104
        1'b0,           // io/mem mapping select
21105
        1'b1,           // prefetch enable
21106
        1'b0,           // address translation enable
21107
        1'b1,           // memory read line enable
21108
        ok              // finished succesfully
21109
    ) ;
21110
 
21111
    if (ok !== 1'b1)
21112
    begin
21113
        test_fail("WB image configuration failed") ;
21114
        disable main ;
21115
    end
21116
end
21117
endtask // test_master_overload
21118
 
21119 106 mihad
`ifdef fofofof
21120
`ifdef PCI_WB_REV_B3
21121
`ifdef PCI_WBS_B3_RTY_DISABLE
21122
task test_wb_slave_with_retry_generation_disabled ;
21123
    reg   [11:0] ctrl_offset ;
21124
    reg   [11:0] ba_offset ;
21125
    reg   [11:0] am_offset ;
21126
    reg `WRITE_STIM_TYPE write_data ;
21127
    reg `READ_STIM_TYPE  read_data ;
21128
    reg `READ_RETURN_TYPE read_status ;
21129
 
21130
    reg `WRITE_RETURN_TYPE write_status ;
21131
    reg `WB_TRANSFER_FLAGS flags ;
21132
    reg        wb_ok   ;
21133
    reg        pci_ok  ;
21134
    reg        ok      ;
21135
    reg [11:0] pci_ctrl_offset ;
21136
    reg [11:0] cl_size_offset  ;
21137
    reg [3:0]  cl_size_mask ;
21138
    reg [31:0] image_base ;
21139
    reg [31:0] target_address ;
21140
 
21141
    integer i ;
21142
    reg [2:0] cur_inc_burst_type ;
21143
 
21144
begin:main
21145
    wb_ok  = 1'b0 ;
21146
    pci_ok = 1'b0 ;
21147
    ok     = 1'b0 ;
21148
 
21149
    test_name   = "CONFIGURE WB IMAGE 1 FOR WB SLAVE WITH NO RETRY RESPONSE TESTING" ;
21150
 
21151
    pci_ctrl_offset = 12'h4 ;
21152
 
21153
    // image 0 can only be configuration image - start with 1
21154
    ctrl_offset    = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
21155
    ba_offset      = {4'h1, `W_BA1_ADDR, 2'b00} ;
21156
    am_offset      = {4'h1, `W_AM1_ADDR, 2'b00} ;
21157
    cl_size_offset = 12'hC ;
21158
    cl_size_mask   = 4'b0001 ;
21159
 
21160
    target_address  = `BEH_TAR1_MEM_START ;
21161
    image_base      = 0 ;
21162
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
21163
 
21164
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
21165
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
21166
    write_flags                      = 0 ;
21167
    write_flags`INIT_WAITS           = wb_init_waits ;
21168
    write_flags`SUBSEQ_WAITS         = wb_subseq_waits ;
21169
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
21170
 
21171
    // enable master & target operation
21172
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
21173
    if ( ok !== 1 )
21174
    begin
21175
        $display("No retry response testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
21176
        test_fail("write to PCI Device Control register didn't succeede");
21177
        disable main ;
21178
    end
21179
 
21180
    // prepare image control register
21181
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
21182
    if ( ok !== 1 )
21183
    begin
21184
        $display("No retry response testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", 1, $time) ;
21185
        test_fail("write to WB Image Control register didn't succeede");
21186
        disable main ;
21187
    end
21188
 
21189
    // prepare base address register
21190
    config_write( ba_offset, image_base, 4'hF, ok ) ;
21191
    if ( ok !== 1 )
21192
    begin
21193
        $display("No retry response testing failed! Failed to write W_BA%d register! Time %t ", 1, $time) ;
21194
        test_fail("write to WB Base Address register didn't succeede");
21195
        disable main ;
21196
    end
21197
 
21198
    // write address mask register
21199
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
21200
    if ( ok !== 1 )
21201
    begin
21202
        $display("No retry response testing failed! Failed to write W_AM%d register! Time %t ", 1, $time) ;
21203
        test_fail("write to WB Address Mask register didn't succeede");
21204
        disable main ;
21205
    end
21206
 
21207
    // write cache line size register
21208
    config_write( cl_size_offset, 32'h4, cl_size_mask, ok ) ;
21209
    if ( ok !== 1 )
21210
    begin
21211
        $display("No retry response testing failed! Failed to write CACHE LINE SIZE register! Time %t ", $time) ;
21212
        test_fail("write to CACHE LINE SIZE register didn't succeede");
21213
        disable main ;
21214
    end
21215
 
21216
    for (cur_inc_burst_type = 0 ; cur_inc_burst_type <= 3 ; cur_inc_burst_type = cur_inc_burst_type + 1'b1)
21217
    begin
21218
        // prepare write data - prepare enough to fill at least 2 write fifos.
21219
        for (i = 0 ; i < ((`PCIW_DEPTH) * 2) ; i = i + 1)
21220
        begin
21221
            write_data`WRITE_DATA    = $random ;
21222
 
21223
            case (cur_inc_burst_type)
21224
            2'b00:
21225
                begin
21226
                    write_data`WRITE_ADDRESS = image_base + i * 4 + 'd8 ;
21227
                end
21228
            2'b01:
21229
                begin
21230
                    write_data`WRITE_ADDRESS = ( image_base[31:4] + (i >> 2) ) << 4 ;
21231
                    if ( (i % 4) === 0 )
21232
                        write_data`WRITE_ADDRESS =  write_data`WRITE_ADDRESS + 'd8 ;
21233
                    else
21234
                        write_data`WRITE_ADDRESS = write_data`WRITE_ADDRESS + (4'd8 + (i * 4 % 4) ;
21235
                end
21236
            2'b10:
21237
                begin
21238
                end
21239
            2'b11:
21240
                begin
21241
                end
21242
            endcase
21243
 
21244
            if (cur_inc_burst_type === 0)
21245
                write_data`WRITE_ADDRESS = image_base + i * 4 + 4 ;
21246
 
21247
            if ( (i % 4) === 0)
21248
                write_data`WRITE_ADDRESS = {image_base[31:4] + (i >> 2), 4'h4}
21249
        end
21250
 
21251
        fork
21252
        begin
21253
            // perform a write with auto retry off, since retries should not be signalled by wishbone slave
21254
            flags`WB_TRANSFER_AUTO_RETRY = 1'b0 ;
21255
 
21256
            // check if received termination is not retry nor error
21257
 
21258
            // check if all transfers completed succesfully!
21259
 
21260
        end
21261
        begin
21262
 
21263
            // set behavioral target to respond with retry
21264
 
21265
            // check 2 transactions terminated with retry
21266
 
21267
            // set behavioral target to disconnect with data on first transfer
21268
            // check the transaction
21269
 
21270
        end
21271
        join
21272
    end
21273
end
21274
endtask // test_wb_slave_with_retry_generation_disabled
21275
`endif
21276
`endif
21277
`endif
21278
 
21279 15 mihad
task test_fail ;
21280
    input [7999:0] failure_reason ;
21281
begin
21282
    tests_failed = tests_failed + 1 ;
21283
 
21284 63 mihad
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
21285 15 mihad
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
21286 106 mihad
    $fdisplay( tb_log_file, " Test %0s", test_name ) ;
21287 15 mihad
    $fdisplay( tb_log_file, " *FAILED* because") ;
21288 106 mihad
    $fdisplay( tb_log_file, " %0s", failure_reason) ;
21289 63 mihad
    current_test_parameters ;
21290
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
21291 15 mihad
    $fdisplay( tb_log_file, " " ) ;
21292
 
21293
    `ifdef STOP_ON_FAILURE
21294
    #20 $stop ;
21295
    `endif
21296
end
21297
endtask // test_fail
21298
 
21299
task test_ok ;
21300
begin
21301
   tests_successfull = tests_successfull + 1 ;
21302
 
21303 63 mihad
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
21304 15 mihad
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
21305 106 mihad
   $fdisplay( tb_log_file, " Test %0s", test_name ) ;
21306 15 mihad
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
21307 63 mihad
   current_test_parameters ;
21308
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
21309 15 mihad
   $fdisplay( tb_log_file, " " ) ;
21310
end
21311
endtask // test_ok
21312
 
21313
task test_summary;
21314
begin
21315 63 mihad
    $fdisplay(tb_log_file, "\n \n");
21316 15 mihad
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
21317
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
21318
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
21319
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
21320
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
21321
    $fclose(tb_log_file) ;
21322
end
21323
endtask
21324
 
21325 63 mihad
task current_test_parameters ;
21326
    reg [87:0] decode_speed_text ;
21327
begin
21328
    case (tb_target_decode_speed)
21329
        3'b000: decode_speed_text = "FAST       " ;
21330
        3'b001: decode_speed_text = "MEDIUM     " ;
21331
        3'b010: decode_speed_text = "SLOW       " ;
21332
        3'b011: decode_speed_text = "SUBTRACTIVE" ;
21333
    endcase
21334
 
21335
    $fdisplay( tb_log_file, "TEST PARAMETERS:") ;
21336 92 mihad
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Initial Wait States         = %d", (pci_init_waits)) ;
21337
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Subsequent Wait States      = %d", (pci_subseq_waits)) ;
21338 63 mihad
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' DEVSEL speed                = %s", decode_speed_text) ;
21339
 
21340 92 mihad
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Initial Wait States    = %d", wb_init_waits) ;
21341
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Subsequent Wait States = %d", wb_subseq_waits) ;
21342 63 mihad
end
21343
endtask
21344
 
21345 73 mihad
`include "pci_bench_common_tasks.v"
21346 15 mihad
endmodule

powered by: WebSVN 2.1.0

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