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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_7/] [bench/] [verilog/] [system.v] - Blame information for rev 106

Go to most recent revision | 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 106 mihad
// Revision 1.17  2003/07/29 08:19:47  mihad
43
// Found and simulated the problem in the synchronization logic.
44
// Repaired the synchronization logic in the FIFOs.
45
//
46 104 mihad
// Revision 1.16  2003/06/12 02:30:39  mihad
47
// Update!
48
//
49 92 mihad
// Revision 1.15  2003/03/14 15:33:55  mihad
50
// Updated acording to RTL changes.
51
//
52 87 mihad
// Revision 1.14  2003/01/30 22:01:33  mihad
53
// Updated synchronization in top level fifo modules.
54
//
55 81 mihad
// Revision 1.13  2003/01/21 16:06:50  mihad
56
// Bug fixes, testcases added.
57
//
58 73 mihad
// Revision 1.12  2002/10/21 13:04:30  mihad
59
// Changed BIST signal names etc..
60
//
61 69 mihad
// Revision 1.11  2002/10/11 12:03:12  mihad
62
// The testcase I just added in previous revision repaired
63
//
64 64 mihad
// Revision 1.10  2002/10/11 10:08:57  mihad
65
// Added additional testcase and changed rst name in BIST to trst
66
//
67 63 mihad
// Revision 1.9  2002/10/08 17:17:02  mihad
68
// Added BIST signals for RAMs.
69
//
70 62 mihad
// Revision 1.8  2002/09/25 09:54:47  mihad
71
// Added completion expiration test for WB Slave unit. Changed expiration signalling
72
//
73 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
74
// Oops, never before noticed that OC header is missing
75 52 mihad
//
76 57 mihad
//
77 52 mihad
 
78 15 mihad
`include "pci_constants.v"
79
`include "bus_commands.v"
80
`include "pci_testbench_defines.v"
81
`include "timescale.v"
82
 
83 51 mihad
`ifdef HOST
84
    `ifdef NO_CNF_IMAGE
85
    `else
86
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
87
    `endif
88
`else
89
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
90
`endif
91
 
92 104 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
93
    `define DO_CORNER_CASE_TESTS
94
`endif
95
 
96
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
97
    `define DO_CORNER_CASE_TESTS
98
`endif
99
 
100 15 mihad
module SYSTEM ;
101
 
102
`include "pci_blue_constants.vh"
103
`include "pci_blue_options.vh"
104
 
105
integer tests_successfull ;
106
integer tests_failed ;
107
integer tb_log_file ;
108
reg [799:0] test_name ;
109
 
110
reg pci_clock ;
111
reg wb_clock ;
112
reg reset ;
113
 
114
wire [4:0] arb_grant_out ;
115
 
116
wire [31:0] AD ;
117
wire [3:0]  CBE ;
118 92 mihad
wire INTA ;
119 15 mihad
pullup(INTA) ;
120 92 mihad
wire MAS0_REQ ;
121
wire MAS1_REQ ;
122
wire MAS2_REQ ;
123
wire MAS3_REQ ;
124 15 mihad
pullup(MAS0_REQ) ;
125
pullup(MAS1_REQ) ;
126
pullup(MAS2_REQ) ;
127
pullup(MAS3_REQ) ;
128
 
129
wire MAS0_GNT = ~arb_grant_out[0];
130
wire MAS1_GNT = ~arb_grant_out[1] ;
131
wire MAS2_GNT = ~arb_grant_out[2] ;
132
wire MAS3_GNT = ~arb_grant_out[3] ;
133
 
134 92 mihad
wire FRAME ;
135
wire IRDY ;
136 15 mihad
pullup(FRAME) ;
137
pullup(IRDY) ;
138 45 mihad
 
139
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
140
 
141 92 mihad
wire DEVSEL, TRDY, STOP, PERR, SERR, LOCK ;
142 15 mihad
pullup(DEVSEL) ;
143
pullup(TRDY) ;
144
pullup(STOP) ;
145
wire   PAR ;
146
pullup(PERR) ;
147
pullup(SERR) ;
148
wire [3:0] MAS1_IDSEL ;
149
 
150
pullup lockpu ( LOCK ) ;
151
 
152
wire        RST_O ;
153
wire        INT_O ;
154
reg         INT_I ;
155
wire [31:0] ADR_I ;
156
wire [31:0] SDAT_I ;
157
wire [31:0] SDAT_O ;
158
wire [3:0]  SEL_I ;
159
wire        CYC_I ;
160
wire        STB_I ;
161
wire        WE_I ;
162
wire        CAB_I ;
163 106 mihad
wire [2:0]  CTI_I ;
164
wire [1:0]  BTE_I ;
165 15 mihad
wire        ACK_O ;
166
wire        RTY_O ;
167
wire        ERR_O ;
168
 
169
wire [31:0] ADR_O ;
170
wire [31:0] MDAT_I ;
171
wire [31:0] MDAT_O ;
172
wire [3:0]  SEL_O ;
173
wire        CYC_O ;
174
wire        STB_O ;
175
wire        WE_O ;
176
wire        CAB_O ;
177
wire        ACK_I ;
178
wire        RTY_I ;
179
wire        ERR_I ;
180
 
181 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
182
 
183
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
184
 
185 15 mihad
wire        reset_wb ; // reset to Wb devices
186
 
187 62 mihad
`ifdef PCI_BIST
188 69 mihad
wire scanb_so ;
189
reg  scanb_si ;
190
reg  scanb_rst ;
191
reg  scanb_en ;
192
reg  scanb_clk ;
193 62 mihad
`endif
194
 
195 92 mihad
wire RST ;
196 15 mihad
`ifdef GUEST
197 92 mihad
    assign  RST = ~reset ;
198 15 mihad
    assign  reset_wb = RST_O ;
199
`else
200
    pullup(RST) ;
201
    assign  reset_wb = reset ;
202
`endif
203
 
204
`define PCI_BRIDGE_INSTANCE bridge32_top
205
 
206 106 mihad
reg tc_gnt_allow ;
207
initial tc_gnt_allow = 1'b0 ;
208
 
209 15 mihad
TOP `PCI_BRIDGE_INSTANCE
210
(
211
    .CLK    ( pci_clock),
212
    .AD     ( AD ),
213
    .CBE    ( CBE ),
214
    .RST    ( RST ),
215
    .INTA   ( INTA ),
216
    .REQ    ( MAS0_REQ ),
217 106 mihad
    .GNT    ( MAS0_GNT | tc_gnt_allow),
218 15 mihad
    .FRAME  ( FRAME ),
219
    .IRDY   ( IRDY ),
220
    .IDSEL  ( TAR0_IDSEL),
221
    .DEVSEL ( DEVSEL ),
222
    .TRDY   ( TRDY ),
223
    .STOP   ( STOP ),
224
    .PAR    ( PAR ),
225
    .PERR   ( PERR ),
226
    .SERR   ( SERR ),
227
 
228
    .CLK_I  ( wb_clock ),
229
    .RST_I  ( reset ),
230
    .RST_O  ( RST_O ),
231
    .INT_I  ( INT_I ),
232
    .INT_O  ( INT_O ),
233
 
234
    // WISHBONE slave interface
235
    .ADR_I  ( ADR_I ),
236
    .SDAT_I ( SDAT_I ),
237
    .SDAT_O ( SDAT_O ),
238
    .SEL_I  ( SEL_I ),
239
    .CYC_I  ( CYC_I ),
240
    .STB_I  ( STB_I ),
241
    .WE_I   ( WE_I ),
242
    .CAB_I  ( CAB_I),
243 106 mihad
    .CTI_I  ( CTI_I),
244
    .BTE_I  ( BTE_I),
245 15 mihad
    .ACK_O  ( ACK_O ),
246
    .RTY_O  ( RTY_O ),
247
    .ERR_O  ( ERR_O ),
248
 
249
    // WISHBONE master interface
250
    .ADR_O  ( ADR_O ),
251
    .MDAT_I ( MDAT_I ),
252
    .MDAT_O ( MDAT_O ),
253
    .SEL_O  ( SEL_O ),
254
    .CYC_O  ( CYC_O ),
255
    .STB_O  ( STB_O ),
256
    .WE_O   ( WE_O ),
257
    .CAB_O  ( CAB_O ),
258
    .ACK_I  ( ACK_I ),
259
    .RTY_I  ( RTY_I ),
260
    .ERR_I  ( ERR_I )
261 62 mihad
 
262
`ifdef PCI_BIST
263
    ,
264 69 mihad
    // bist chain signals
265
    .scanb_rst  (scanb_rst),
266
    .scanb_clk  (scanb_clk),
267
    .scanb_si   (scanb_si),
268
    .scanb_so   (scanb_so),
269
    .scanb_en   (scanb_en)
270 62 mihad
`endif
271 15 mihad
) ;
272
 
273
WB_MASTER_BEHAVIORAL wishbone_master
274
(
275
    .CLK_I(wb_clock),
276
    .RST_I(reset_wb),
277 106 mihad
    .TAG_I(`WB_TAG_WIDTH'd0),
278
    .TAG_O({CTI_I, BTE_I}),
279 15 mihad
    .ACK_I(ACK_O),
280
    .ADR_O(ADR_I),
281
    .CYC_O(CYC_I),
282
    .DAT_I(SDAT_O),
283
    .DAT_O(SDAT_I),
284
    .ERR_I(ERR_O),
285
    .RTY_I(RTY_O),
286
    .SEL_O(SEL_I),
287
    .STB_O(STB_I),
288
    .WE_O (WE_I),
289
    .CAB_O(CAB_I)
290
);
291
 
292
WB_SLAVE_BEHAVIORAL wishbone_slave
293
(
294
    .CLK_I              (wb_clock),
295
    .RST_I              (reset_wb),
296
    .ACK_O              (ACK_I),
297
    .ADR_I              (ADR_O),
298
    .CYC_I              (CYC_O),
299
    .DAT_O              (MDAT_I),
300
    .DAT_I              (MDAT_O),
301
    .ERR_O              (ERR_I),
302
    .RTY_O              (RTY_I),
303
    .SEL_I              (SEL_O),
304
    .STB_I              (STB_O),
305
    .WE_I               (WE_O),
306
    .CAB_I              (CAB_O)
307
);
308
 
309
integer wbu_mon_log_file_desc ;
310
integer pciu_mon_log_file_desc ;
311
WB_BUS_MON wbu_wb_mon(
312
                    .CLK_I(wb_clock),
313
                    .RST_I(reset_wb),
314
                    .ACK_I(ACK_O),
315
                    .ADDR_O(ADR_I),
316
                    .CYC_O(CYC_I),
317
                    .DAT_I(SDAT_O),
318
                    .DAT_O(SDAT_I),
319
                    .ERR_I(ERR_O),
320
                    .RTY_I(RTY_O),
321
                    .SEL_O(SEL_I),
322
                    .STB_O(STB_I),
323
                    .WE_O (WE_I),
324
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
325 106 mihad
                    .TAG_O({CTI_I, BTE_I}),
326 15 mihad
                    .CAB_O(CAB_I),
327
                    .log_file_desc ( wbu_mon_log_file_desc )
328
                  ) ;
329
 
330
WB_BUS_MON pciu_wb_mon(
331
                    .CLK_I(wb_clock),
332
                    .RST_I(reset_wb),
333
                    .ACK_I(ACK_I),
334
                    .ADDR_O(ADR_O),
335
                    .CYC_O(CYC_O),
336
                    .DAT_I(MDAT_I),
337
                    .DAT_O(MDAT_O),
338
                    .ERR_I(ERR_I),
339
                    .RTY_I(RTY_I),
340
                    .SEL_O(SEL_O),
341
                    .STB_O(STB_O),
342
                    .WE_O (WE_O),
343
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
344 106 mihad
                    .TAG_O({`WB_TAG_WIDTH{1'b0}}),
345 15 mihad
                    .CAB_O(CAB_O),
346
                    .log_file_desc( pciu_mon_log_file_desc )
347
                  ) ;
348
 
349
// some aditional signals are needed here because of the arbiter
350
reg [3:0] pci_ext_req_prev ;
351
always@(posedge pci_clock)
352
begin
353
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
354
end
355
reg pci_frame_prev ;
356
always@(posedge pci_clock)
357
begin
358
    pci_frame_prev <= FRAME ;
359
end
360
reg pci_irdy_prev ;
361
always@(posedge pci_clock)
362
begin
363
    pci_irdy_prev <= IRDY ;
364
end
365
 
366
pci_blue_arbiter pci_arbiter
367
(
368
  .pci_int_req_direct(1'b0),
369
  .pci_ext_req_prev(pci_ext_req_prev),
370
  .pci_int_gnt_direct_out(arb_grant_out[4]),
371
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
372
  .pci_frame_prev(~pci_frame_prev),
373
  .pci_irdy_prev(~pci_irdy_prev),
374
  .pci_irdy_now(~IRDY),
375
  .arbitration_enable(1'b1),
376
  .pci_clk(pci_clock),
377
  .pci_reset_comb(~RST)
378
);
379
 
380
reg [31:0] target_message ;
381
 
382
// define output enable signals for monitor inputs
383
// real output enable signals
384
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
385
`ifdef ACTIVE_LOW_OE
386
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
387
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
388
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
389
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
390
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
391
                        !devsel_t_s_oe,
392
                        !ad_oe,
393
                        !cbe_oe,
394
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
395
                        ;
396
`else
397
`ifdef ACTIVE_HIGH_OE
398
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
399
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
400
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
401
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
402
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
403
                        devsel_t_s_oe,
404
                        ad_oe,
405
                        cbe_oe,
406
                        `PCI_BRIDGE_INSTANCE.PERR_en}
407
                        ;
408
`endif
409
`endif
410
/*wire [5:0] oe_sigs_0 = {1'b0,
411
                        1'b0,
412
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
413
                        pci_target32.ad_enable,
414
                        1'b0,
415
                        pci_target32.err_enable | pci_target32.r_err_enable
416
                       } ;
417
*/
418
 
419
wire [5:0] oe_sigs_2 ;
420
wire [5:0] oe_sigs_1 ;
421
 
422
// signals which are used by test modules to know what to do
423
triand  test_accepted_l_int, error_event_int;
424
pullup  (test_accepted_l_int), (error_event_int);
425
 
426
wire    pci_reset_comb  = ~RST;
427
wire    pci_ext_clk     = pci_clock;
428
 
429
integer pci_mon_log_file_desc ;
430
pci_bus_monitor monitor32
431
(
432
    .pci_ext_ad                 (AD),
433
    .pci_ext_cbe_l              (CBE),
434
    .pci_ext_par                (PAR),
435
    .pci_ext_frame_l            (FRAME),
436
    .pci_ext_irdy_l             (IRDY),
437
    .pci_ext_devsel_l           (DEVSEL),
438
    .pci_ext_trdy_l             (TRDY),
439
    .pci_ext_stop_l             (STOP),
440
    .pci_ext_perr_l             (PERR),
441
    .pci_ext_serr_l             (SERR),
442
    .pci_real_req_l             (MAS0_REQ),
443 106 mihad
    .pci_real_gnt_l             (MAS0_GNT | tc_gnt_allow),
444 15 mihad
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
445
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
446
    .test_error_event           (error_event_int),
447
    .test_observe_r_oe_sigs     (r_oe_sigs),
448
    .test_observe_0_oe_sigs     (6'h00),
449
    .test_observe_1_oe_sigs     (oe_sigs_1),
450
    .test_observe_2_oe_sigs     (oe_sigs_2),
451
    .test_observe_3_oe_sigs     (6'h00),
452
    .pci_ext_reset_l            (RST),
453
    .pci_ext_clk                (pci_clock),
454
    .log_file_desc              (pci_mon_log_file_desc)
455
) ;
456
 
457
reg [2:0]  test_master_number ;
458
reg [31:0] test_address ;
459
reg [3:0]  test_command ;
460
reg [31:0] test_data ;
461
reg [3:0]  test_byte_enables_l ;
462
reg [9:0]  test_size ;
463
reg        test_make_addr_par_error ;
464
reg        test_make_data_par_error ;
465
reg [3:0]  test_master_initial_wait_states ;
466
reg [3:0]  test_master_subsequent_wait_states ;
467
reg [3:0]  test_target_initial_wait_states ;
468
reg [3:0]  test_target_subsequent_wait_states ;
469
reg [1:0]  test_target_devsel_speed ;
470
reg        test_fast_back_to_back ;
471
reg [2:0]  test_target_termination ;
472
reg        test_expect_master_abort ;
473
reg        test_start ;
474
reg [25:0] test_target_response ;
475
 
476
wire [31:0] master2_received_data ;
477
wire        master2_received_data_valid ;
478
reg         master2_check_received_data ;
479
pci_behaviorial_device pci_behaviorial_device2
480
(
481
    .pci_ext_ad(AD),
482
    .pci_ext_cbe_l(CBE),
483
    .pci_ext_par(PAR),
484
    .pci_ext_frame_l(FRAME),
485
    .pci_ext_irdy_l(IRDY),
486
    .pci_ext_devsel_l(DEVSEL),
487
    .pci_ext_trdy_l(TRDY),
488
    .pci_ext_stop_l(STOP),
489
    .pci_ext_perr_l(PERR),
490
    .pci_ext_serr_l(SERR),
491
    .pci_ext_idsel(TAR2_IDSEL),
492
    .pci_ext_inta_l(INTA),
493
    .pci_ext_req_l(MAS2_REQ),
494
    .pci_ext_gnt_l(MAS2_GNT),
495
    .pci_ext_reset_l(RST),
496
    .pci_ext_clk(pci_clock),
497
 
498
// Signals used by the test bench instead of using "." notation
499
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
500
    .test_master_number                 (test_master_number[2:0]),
501
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
502
    .test_command                       (test_command[3:0]),
503
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
504
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
505
    .test_size                          (test_size),
506
    .test_make_addr_par_error           (test_make_addr_par_error),
507
    .test_make_data_par_error           (test_make_data_par_error),
508
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
509
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
510
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
511
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
512
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
513
    .test_fast_back_to_back             (test_fast_back_to_back),
514
    .test_target_termination            (test_target_termination[2:0]),
515
    .test_expect_master_abort           (test_expect_master_abort),
516
    .test_start                         (test_start),
517
    .test_accepted_l                    (test_accepted_l_int),
518
    .test_error_event                   (error_event_int),
519
    .test_device_id                     (`Test_Master_2),
520
    .test_target_response               (test_target_response),
521
 
522
    .master_received_data               (master2_received_data),
523
    .master_received_data_valid         (master2_received_data_valid),
524
    .master_check_received_data         (master2_check_received_data)
525
);
526
 
527
wire [31:0] master1_received_data ;
528
wire        master1_received_data_valid ;
529
reg         master1_check_received_data ;
530
pci_behaviorial_device pci_behaviorial_device1
531
(
532
    .pci_ext_ad(AD),
533
    .pci_ext_cbe_l(CBE),
534
    .pci_ext_par(PAR),
535
    .pci_ext_frame_l(FRAME),
536
    .pci_ext_irdy_l(IRDY),
537
    .pci_ext_devsel_l(DEVSEL),
538
    .pci_ext_trdy_l(TRDY),
539
    .pci_ext_stop_l(STOP),
540
    .pci_ext_perr_l(PERR),
541
    .pci_ext_serr_l(SERR),
542
    .pci_ext_idsel(TAR1_IDSEL),
543
    .pci_ext_inta_l(INTA),
544
    .pci_ext_req_l(MAS1_REQ),
545
    .pci_ext_gnt_l(MAS1_GNT),
546
    .pci_ext_reset_l(RST),
547
    .pci_ext_clk(pci_clock),
548
 
549
// Signals used by the test bench instead of using "." notation
550
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
551
    .test_master_number                 (test_master_number[2:0]),
552
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
553
    .test_command                       (test_command[3:0]),
554
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
555
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
556
    .test_size                          (test_size),
557
    .test_make_addr_par_error           (test_make_addr_par_error),
558
    .test_make_data_par_error           (test_make_data_par_error),
559
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
560
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
561
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
562
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
563
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
564
    .test_fast_back_to_back             (test_fast_back_to_back),
565
    .test_target_termination            (test_target_termination[2:0]),
566
    .test_expect_master_abort           (test_expect_master_abort),
567
    .test_start                         (test_start),
568
    .test_accepted_l                    (test_accepted_l_int),
569
    .test_error_event                   (error_event_int),
570
    .test_device_id                     (`Test_Master_1),
571
    .test_target_response               (test_target_response),
572
 
573
    .master_received_data               (master1_received_data),
574
    .master_received_data_valid         (master1_received_data_valid),
575
    .master_check_received_data         (master1_check_received_data)
576
);
577
 
578
pci_unsupported_commands_master ipci_unsupported_commands_master
579
(
580
    .CLK    ( pci_clock),
581
    .AD     ( AD ),
582
    .CBE    ( CBE ),
583
    .RST    ( RST ),
584
    .REQ    ( MAS3_REQ ),
585
    .GNT    ( MAS3_GNT ),
586
    .FRAME  ( FRAME ),
587
    .IRDY   ( IRDY ),
588
    .DEVSEL ( DEVSEL ),
589
    .TRDY   ( TRDY ),
590
    .STOP   ( STOP ),
591
    .PAR    ( PAR )
592
) ;
593
 
594 45 mihad
`ifdef HOST
595
 
596
reg     [1:0]   conf_cyc_type1_target_response ;
597
reg     [31:0]  conf_cyc_type1_target_data ;
598
reg     [7:0]   conf_cyc_type1_target_bus_num ;
599
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
600
 
601
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
602
(
603
    .CLK              ( pci_clock),
604
    .AD               ( AD ),
605
    .CBE              ( CBE ),
606
    .RST              ( RST ),
607
    .FRAME            ( FRAME ),
608
    .IRDY             ( IRDY ),
609
    .DEVSEL           ( DEVSEL ),
610
    .TRDY             ( TRDY ),
611
    .STOP             ( STOP ),
612
    .PAR              ( PAR ),
613
 
614
    .response         ( conf_cyc_type1_target_response ),
615
    .data_out         ( conf_cyc_type1_target_data ),
616
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
617
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
618
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
619
    .bus_number       ( conf_cyc_type1_target_bus_num )
620
);
621
`endif
622
 
623 15 mihad
// pci clock generator
624 63 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
625
    always@(posedge wb_clock)
626
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b1 ;
627
 
628
    always@(negedge wb_clock)
629
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b0 ;
630 15 mihad
`else
631 63 mihad
    always
632
    `ifdef PCI33
633
        #15 pci_clock = ~pci_clock ;
634
    `else
635
    `ifdef PCI66
636
        #7.5 pci_clock = ~pci_clock ;
637
    `endif
638
    `endif
639 15 mihad
`endif
640
 
641
// WISHBONE clock generation
642 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
643
always@(posedge pci_clock)
644
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b1 ;
645 15 mihad
 
646 63 mihad
always@(negedge pci_clock)
647
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b0 ;
648
 
649
`else
650
    always
651 104 mihad
        #(`WB_PERIOD/2) wb_clock = !wb_clock ;
652 63 mihad
`endif
653
 
654 15 mihad
// Make test name visible when the Master starts working on it
655
reg     [79:0] present_test_name;
656
reg     [79:0] next_test_name;
657
wire    test_accepted = ~test_accepted_l_int;
658
always @(posedge test_accepted)
659
begin
660
    present_test_name <= next_test_name;
661
end
662
 
663
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
664
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
665
 
666
// basic configuration parameters for both behavioral devices
667
parameter [2:0] Master_ID_A                           = `Test_Master_1;
668
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
669
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
670
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
671
 
672
parameter [2:0] Master_ID_B                           = `Test_Master_2;
673
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
674
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
675
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
676
 
677
// basic configuration parameters for REAL device
678
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
679
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
680
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
681
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
682
 
683
// reg  [2:0]   ack_err_rty_termination ;
684
// reg          wait_cycles ;
685
// reg  [7:0]   num_of_retries ;
686
 
687
//reg [19:0] pci_config_base ;
688
reg [7:0] system_burst_size ;
689
reg [7:0] bridge_latency ;
690
integer   target_mem_image ;
691
integer   target_io_image ;
692
 
693
initial
694
begin
695 62 mihad
 
696
`ifdef PCI_BIST
697 69 mihad
    scanb_si    = 0 ;
698
    scanb_en    = 0 ;
699
    scanb_clk   = 0 ;
700
    scanb_rst   = 0 ;
701 62 mihad
`endif
702 15 mihad
    next_test_name[79:0] <= "Nowhere___";
703
    reset = 1'b1 ;
704
    pci_clock = 1'b0 ;
705 104 mihad
    wb_clock  = 1'b0 ;
706 15 mihad
    target_message = 32'h0000_0000 ;
707
//  num_of_retries = 8'h01 ;
708
//  ack_err_rty_termination = 3'b100 ;
709
//  wait_cycles = 1'b0 ;
710
 
711
    // system paameters
712
    system_burst_size = 16 ;
713
    bridge_latency    = 8 ;
714
 
715
    // set initial values for controling the behavioral PCI master
716
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
717
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
718
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
719
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
720
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
721
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
722
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
723
 
724
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
725
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
726
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
727
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
728
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
729
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
730
 
731
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
732
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
733
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
734
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
735
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
736
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
737
 
738
    test_master_number = `Test_Master_2 ;
739
    test_address = 32'h0000_0000 ;
740
    test_command = `BC_RESERVED0 ;
741
    test_data = 32'h0000_0000 ;
742
    test_byte_enables_l   = 4'hF ;
743
    test_size = 0 ;
744
    test_make_addr_par_error = 0 ;
745
    test_make_data_par_error = 0;
746
    test_master_initial_wait_states = 0 ;
747
    test_master_subsequent_wait_states = 0 ;
748
    test_target_initial_wait_states = 0 ;
749
    test_target_subsequent_wait_states = 0;
750
    test_target_devsel_speed = `Test_Devsel_Fast ;
751
    test_fast_back_to_back = 0 ;
752
    test_target_termination = `Test_Target_Normal_Completion ;
753
    test_expect_master_abort = 0 ;
754
    test_start = 0 ;
755
    test_target_response = 0 ;
756
 
757
    master1_check_received_data = 0 ;
758
    master2_check_received_data = 0 ;
759
 
760 45 mihad
    `ifdef HOST
761
        conf_cyc_type1_target_response = 0 ;
762
        conf_cyc_type1_target_data = 0 ;
763
        conf_cyc_type1_target_bus_num = 255 ;
764
    `endif
765 15 mihad
 
766
    // fill memory and IO data with random values
767
    fill_memory ;
768
 
769
    INT_I = 0 ;
770
 
771
    // extract from constants which target image can be used as IO and which as memory
772
    `ifdef HOST
773
        target_mem_image = 1 ;
774
        target_io_image  = 1 ;
775
    `else
776
        target_mem_image = -1 ;
777
        target_io_image     = -1 ;
778
        if ( `PCI_BA1_MEM_IO === 0 )
779
            target_mem_image = 1 ;
780
        else
781
            target_io_image = 1 ;
782
 
783
        if ( target_mem_image === -1 )
784
        begin
785
            `ifdef PCI_IMAGE2
786
                if ( `PCI_BA2_MEM_IO === 0 )
787
                    target_mem_image = 2 ;
788
                else if ( target_io_image === -1 )
789
                    target_io_image = 2 ;
790
            `endif
791
        end
792
 
793
        if ( target_mem_image === -1 )
794
        begin
795
            `ifdef PCI_IMAGE3
796
                if ( `PCI_BA3_MEM_IO === 0 )
797
                    target_mem_image = 3 ;
798
                else if ( target_io_image === -1 )
799
                    target_io_image = 3 ;
800
            `endif
801
        end
802
 
803
        if ( target_mem_image === -1 )
804
        begin
805
            `ifdef PCI_IMAGE4
806
                if ( `PCI_BA4_MEM_IO === 0 )
807
                    target_mem_image = 4 ;
808
                else if ( target_io_image === -1 )
809
                    target_io_image = 4 ;
810
            `endif
811
        end
812
 
813
        if ( target_mem_image === -1 )
814
        begin
815
            `ifdef PCI_IMAGE5
816
                if ( `PCI_BA5_MEM_IO === 0 )
817
                    target_mem_image = 5 ;
818
                else if ( target_io_image === -1 )
819
                    target_io_image = 5 ;
820
            `endif
821
        end
822
    `endif
823
 
824
    tests_successfull = 0 ;
825
    tests_failed = 0 ;
826
 
827
    tb_log_file = $fopen("../log/pci_tb.log") ;
828
 
829
    if ( tb_log_file < 2 )
830
    begin
831
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
832
        $finish ;
833
    end
834
 
835
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
836
    $fdisplay( tb_log_file,"" ) ;
837
 
838
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
839
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
840
 
841
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
842
    begin
843
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
844
        $finish ;
845
    end
846
 
847
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
848
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
849
 
850
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
851
    if ( pci_mon_log_file_desc < 2 )
852
    begin
853
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
854
        $finish ;
855
    end
856
 
857
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
858
 
859
    run_tests ;
860
end
861
 
862 106 mihad
task fill_memory ; //wb_b3_ok
863 15 mihad
    integer temp_index ;
864
begin
865
    // fill write memories with random data
866
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
867
    begin
868
        wmem_data[temp_index[9:0]] = $random ;
869 26 mihad
        # 1;
870 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
871 26 mihad
        # 1;
872 15 mihad
    end
873
    // fill WB slave behavioral MEMORY
874
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
875
    begin
876
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
877
        # 1;
878
    end
879
end
880
endtask // fill_memory
881
 
882 92 mihad
reg [2:0] wb_init_waits ;
883
reg [2:0] pci_init_waits ;
884
reg [2:0] wb_subseq_waits ;
885
reg [2:0] pci_subseq_waits ;
886 15 mihad
reg [2:0] tb_target_decode_speed ;
887
 
888 106 mihad
task run_tests ; //wb_b3_ok
889 15 mihad
begin
890 92 mihad
    wb_init_waits          = 0;
891
    pci_init_waits         = 0;
892
    wb_subseq_waits        = 0 ;
893
    pci_subseq_waits       = 0 ;
894
    tb_target_decode_speed = 0 ;
895
 
896 15 mihad
    // first - reset logic
897
    do_reset ;
898 62 mihad
 
899
    // if BIST is implemented, give it a go
900
`ifdef PCI_BIST
901 106 mihad
    run_bist_test ;
902
    scanb_rst <= #1 1'b1 ;
903 62 mihad
`endif
904 45 mihad
    test_initial_conf_values ;
905
 
906 15 mihad
    next_test_name[79:0] <= "Initing...";
907
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
908
 
909 92 mihad
    for ( wb_init_waits = 0 ; wb_init_waits <= 4 ; wb_init_waits = wb_init_waits + 1 )
910 15 mihad
    begin
911 92 mihad
        for ( wb_subseq_waits = 0 ; wb_subseq_waits <= 4 ; wb_subseq_waits = wb_subseq_waits + 1 )
912 15 mihad
        begin
913
 
914 92 mihad
            pci_init_waits   = wb_init_waits ;
915
            pci_subseq_waits = wb_subseq_waits ;
916 15 mihad
 
917 92 mihad
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = pci_init_waits ;
918
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = pci_subseq_waits ;
919
 
920 15 mihad
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
921
            begin
922
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
923
 
924
                `ifdef HOST
925
                    configure_bridge_target ;
926
                    find_pci_devices ;
927 45 mihad
                    test_configuration_cycle_target_abort ;
928
                    test_configuration_cycle_type1_generation ;
929 15 mihad
                `endif
930
 
931
                @(posedge pci_clock) ;
932
                configure_target(1) ;
933
                @(posedge pci_clock) ;
934
                configure_target(2) ;
935
 
936
                `ifdef GUEST
937
                    configure_bridge_target ;
938
                `endif
939
 
940
               next_test_name[79:0] <= "WB_SLAVE..";
941
 
942
                $display("Testing WISHBONE slave images' features!") ;
943
                test_wb_image(1) ;
944
 
945
                `ifdef WB_IMAGE2
946
                    test_wb_image(2) ;
947
                `else
948
                    $display(" WB IMAGE 2 not implemented! ") ;
949
                `endif
950
 
951
                `ifdef WB_IMAGE3
952
                    test_wb_image(3) ;
953
                `else
954
                    $display(" WB IMAGE 3 not implemented! ") ;
955
                `endif
956
 
957
                `ifdef WB_IMAGE4
958
                    test_wb_image(4) ;
959
                `else
960
                    $display(" WB IMAGE 4 not implemented! ") ;
961
                `endif
962
 
963
                `ifdef WB_IMAGE5
964
                    test_wb_image(5) ;
965
                `else
966
                    $display(" WB IMAGE 5 not implemented! ") ;
967
                `endif
968
 
969
                wb_slave_errors ;
970
                wb_to_pci_error_handling ;
971
 
972
                parity_checking ;
973
 
974
                wb_to_pci_transactions ;
975
 
976
                `ifdef HOST
977
                iack_cycle ;
978
                `endif
979
 
980 73 mihad
                test_master_overload ;
981
 
982 15 mihad
            end
983 57 mihad
 
984 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
985
        `else
986 57 mihad
            master_completion_expiration ;
987 63 mihad
        `endif
988 57 mihad
 
989 104 mihad
        `ifdef DO_CORNER_CASE_TESTS
990 69 mihad
            master_special_corner_case_test ;
991
        `endif
992
 
993 15 mihad
            $display(" ") ;
994
            $display("WB slave images' tests finished!") ;
995
 
996
            $display("########################################################################") ;
997
            $display("########################################################################") ;
998
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
999
            $display("########################################################################") ;
1000
            $display("########################################################################") ;
1001
 
1002
            $display("Testing PCI target images' features!") ;
1003
            configure_bridge_target_base_addresses ;
1004 104 mihad
 
1005 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
1006
                test_conf_cycle_type1_reference ;
1007
            `endif
1008
 
1009 15 mihad
            `ifdef HOST
1010
             `ifdef NO_CNF_IMAGE
1011
              `ifdef PCI_IMAGE0
1012
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
1013
            test_pci_image(0) ;
1014
              `else
1015
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
1016
              `endif
1017
             `else
1018
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
1019
             `endif
1020
            `endif
1021
 
1022
            $display("PCI image 1 is ALWAYS implemented!") ;
1023
            test_pci_image(1) ;
1024
 
1025
            `ifdef PCI_IMAGE2
1026
            $display("PCI image 2 is implemented!") ;
1027
            test_pci_image(2) ;
1028
            `else
1029
            $display("PCI image 2 is NOT implemented!") ;
1030
            `endif
1031
 
1032
            `ifdef PCI_IMAGE3
1033
            $display("PCI image 3 is implemented!") ;
1034
            test_pci_image(3) ;
1035
            `else
1036
            $display("PCI image 3 is NOT implemented!") ;
1037
            `endif
1038
 
1039
            `ifdef PCI_IMAGE4
1040
            $display("PCI image 4 is implemented!") ;
1041
            test_pci_image(4) ;
1042
            `else
1043
            $display("PCI image 4 is NOT implemented!") ;
1044
            `endif
1045
 
1046
            `ifdef PCI_IMAGE5
1047
            $display("PCI image 5 is implemented!") ;
1048
            test_pci_image(5) ;
1049
            `else
1050
            $display("PCI image 5 is NOT implemented!") ;
1051
            `endif
1052
 
1053
            test_wb_error_rd ;
1054
 
1055
            target_fast_back_to_back ;
1056
            target_disconnects ;
1057
 
1058 73 mihad
            test_target_overload ;
1059
 
1060 15 mihad
            if ( target_io_image !== -1 )
1061
                test_target_abort( target_io_image ) ;
1062
            $display(" ") ;
1063
            $display("PCI target images' tests finished!") ;
1064
 
1065
            transaction_ordering ;
1066 33 mihad
 
1067 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
1068
        `else
1069 33 mihad
            target_completion_expiration ;
1070 63 mihad
        `endif
1071
 
1072 15 mihad
            $display(" ") ;
1073
            $display("PCI transaction ordering tests finished!") ;
1074
        end
1075
    end
1076
 
1077 92 mihad
    wb_init_waits   = 0 ;
1078
    pci_init_waits  = 0 ;
1079
    wb_subseq_waits = 0 ;
1080
    pci_subseq_waits = 0 ;
1081 73 mihad
 
1082 104 mihad
    `ifdef DO_CORNER_CASE_TESTS
1083 63 mihad
        test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
1084
        test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
1085
        test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
1086
        test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = 0 ;
1087
 
1088
        `ifdef HOST
1089
            configure_bridge_target ;
1090
        `endif
1091
 
1092
        @(posedge pci_clock) ;
1093
        configure_target(1) ;
1094
        @(posedge pci_clock) ;
1095
        configure_target(2) ;
1096
 
1097
        `ifdef GUEST
1098 106 mihad
            configure_bridge_target ; // b3ok
1099 63 mihad
        `endif
1100
 
1101
        target_special_corner_case_test ;
1102
    `endif
1103
 
1104 92 mihad
    wb_init_waits    = 0 ;
1105
    pci_init_waits   = 0 ;
1106
    wb_subseq_waits  = 0 ;
1107
    pci_subseq_waits = 0 ;
1108 73 mihad
 
1109 15 mihad
    test_summary ;
1110
 
1111
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
1112
    $stop ;
1113
end
1114
endtask // run_tests
1115
 
1116 106 mihad
task do_reset; //wb_b3_ok
1117 15 mihad
begin
1118
    next_test_name[79:0] <= "Reset.....";
1119
 
1120
    reset = 1'b1 ;
1121
    #100 ;
1122
    `ifdef HOST
1123
        @(posedge wb_clock) ;
1124
    `else
1125
    `ifdef GUEST
1126
        @(posedge pci_clock) ;
1127
    `endif
1128
    `endif
1129
 
1130
    reset <= 1'b0 ;
1131
 
1132 45 mihad
    `ifdef HOST
1133
        @(posedge wb_clock) ;
1134
    `else
1135
    `ifdef GUEST
1136
        @(posedge pci_clock) ;
1137
    `endif
1138
    `endif
1139
 
1140 15 mihad
end
1141
endtask
1142
 
1143
/*############################################################################
1144
WB SLAVE UNIT tasks
1145
===================
1146
############################################################################*/
1147
 
1148 106 mihad
task configure_target ; //wb_b3_ok
1149 45 mihad
    input [1:0]  beh_dev_num ;
1150 15 mihad
    reg   [31:0] base_address1 ;
1151
    reg   [31:0] base_address2 ;
1152
    reg   [2:0]  Master_ID;
1153
    reg   [31:0] Target_Config_Addr;
1154 45 mihad
    reg   [4:0]  device_num ;
1155 15 mihad
begin
1156 45 mihad
    if (beh_dev_num === 1)
1157 15 mihad
    begin
1158
        base_address1       = `BEH_TAR1_MEM_START ;
1159
        base_address2       = `BEH_TAR1_IO_START  ;
1160
        Master_ID           = `Test_Master_2 ;
1161
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1162 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1163 15 mihad
    end
1164
    else
1165 45 mihad
    if (beh_dev_num === 2)
1166 15 mihad
    begin
1167
        base_address1       = `BEH_TAR2_MEM_START ;
1168
        base_address2       = `BEH_TAR2_IO_START  ;
1169
        Master_ID           = `Test_Master_1 ;
1170
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1171 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1172 15 mihad
    end
1173
 
1174
    // write target's base addresses
1175
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1176
    // type 0 cycle, byte enables, base address
1177
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1178
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1179
 
1180
    // enable target's response and master
1181
    // enable parity errors, disable system error
1182
 
1183
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1184
 
1185
end
1186
endtask //configure_target
1187
 
1188 106 mihad
task test_wb_image ; //wb_b3_ok
1189 15 mihad
    input [2:0]  image_num ;
1190
    reg   [11:0] ctrl_offset ;
1191
    reg   [11:0] ba_offset ;
1192
    reg   [11:0] am_offset ;
1193
    reg   [11:0] ta_offset ;
1194
    reg   [11:0] err_cs_offset ;
1195
    reg `WRITE_STIM_TYPE write_data ;
1196
    reg `READ_STIM_TYPE  read_data ;
1197
    reg `READ_RETURN_TYPE read_status ;
1198
 
1199
    reg `WRITE_RETURN_TYPE write_status ;
1200
    reg `WB_TRANSFER_FLAGS write_flags ;
1201
    reg [31:0] temp_val ;
1202
    reg        ok   ;
1203
    reg [11:0] pci_ctrl_offset ;
1204
    reg [31:0] image_base ;
1205
    reg [31:0] target_address ;
1206
    reg [31:0] translation_address ;
1207
    integer    i ;
1208
    integer    j ;
1209
begin:main
1210
    pci_ctrl_offset = 12'h4 ;
1211
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1212
    // image 0 can only be configuration image - start with 1
1213
    if (image_num === 1)
1214
    begin
1215
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1216
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1217
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1218
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1219
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1220
    end
1221
    else if (image_num === 2)
1222
    begin
1223
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1224
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1225
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1226
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1227
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1228
    end
1229
    else if (image_num === 3)
1230
    begin
1231
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1232
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1233
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1234
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1235
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1236
    end
1237
    else if (image_num === 4)
1238
    begin
1239
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1240
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1241
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1242
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1243
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1244
    end
1245
    else if (image_num === 5)
1246
    begin
1247
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1248
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1249
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1250
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1251
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1252
    end
1253
    else
1254
    begin
1255
        test_name   = "WB IMAGES' FEATURES TEST" ;
1256
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1257
        disable main ;
1258
    end
1259
 
1260
    target_address  = `BEH_TAR1_MEM_START ;
1261
    image_base      = 0 ;
1262
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1263
 
1264
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1265
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1266
    write_flags                      = 0 ;
1267 92 mihad
    write_flags`INIT_WAITS           = wb_init_waits ;
1268
    write_flags`SUBSEQ_WAITS         = wb_subseq_waits ;
1269 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1270
 
1271
    test_name = "WB IMAGE CONFIGURATION" ;
1272
    // enable master & target operation
1273
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1274
    if ( ok !== 1 )
1275
    begin
1276 69 mihad
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1277 15 mihad
        test_fail("write to PCI Device Control register didn't succeede");
1278
        disable main ;
1279
    end
1280
 
1281
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1282
    if ( ok !== 1 )
1283
    begin
1284 69 mihad
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", $time) ;
1285 15 mihad
        test_fail("write to WB Error Control and Status register didn't succeede");
1286
        disable main ;
1287
    end
1288
 
1289
    // prepare image control register
1290
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1291
    if ( ok !== 1 )
1292
    begin
1293
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1294
        test_fail("write to WB Image Control register didn't succeede");
1295
        disable main ;
1296
    end
1297
 
1298
    // prepare base address register
1299
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1300
    if ( ok !== 1 )
1301
    begin
1302
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1303
        test_fail("write to WB Base Address register didn't succeede");
1304
        disable main ;
1305
    end
1306
 
1307
    // write address mask register
1308
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1309
    if ( ok !== 1 )
1310
    begin
1311
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1312
        test_fail("write to WB Address Mask register didn't succeede");
1313
        disable main ;
1314
    end
1315
 
1316
    fork
1317
    begin
1318
        write_data`WRITE_ADDRESS = target_address ;
1319
        write_data`WRITE_DATA    = wmem_data[0] ;
1320
        write_data`WRITE_SEL     = 4'hF ;
1321
 
1322
        // handle retries from now on
1323 106 mihad
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1324 15 mihad
 
1325
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1326
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1327
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1328
        begin
1329
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1330
            test_fail("WB Slave state machine failed to post single memory write");
1331
            disable main ;
1332
        end
1333
 
1334
        // read written data back
1335
        read_data`READ_ADDRESS  = target_address ;
1336
        read_data`READ_SEL      = 4'hF ;
1337 106 mihad
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
1338 15 mihad
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1339
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1340
        begin
1341
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1342
            test_fail("PCI bridge didn't process the read as expected");
1343
            disable main ;
1344
        end
1345
 
1346
        if (read_status`READ_DATA !== wmem_data[0])
1347
        begin
1348
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1349
            test_fail("PCI bridge returned unexpected Read Data");
1350
        end
1351
        else
1352
            test_ok ;
1353
    end
1354
    begin
1355
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1356
        if ( ok !== 1 )
1357
        begin
1358
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1359
        end
1360
        else
1361
            test_ok ;
1362
 
1363
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1364
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1365
        if ( ok !== 1 )
1366
        begin
1367
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1368
        end
1369
    end
1370
    join
1371
 
1372
    // if address translation is implemented - try it out
1373
    translation_address = image_base ;
1374
    `ifdef ADDR_TRAN_IMPL
1375
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1376
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1377
    if ( ok !== 1 )
1378
    begin
1379
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1380
        test_fail("write to WB Image Translation Address Register failed") ;
1381
        disable main ;
1382
    end
1383
 
1384
    target_address  = `BEH_TAR2_MEM_START ;
1385
    image_base      = 0 ;
1386
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1387
 
1388
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1389
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1390
 
1391
    write_flags                      = 0 ;
1392
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1393
 
1394
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1395
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1396
    if ( ok !== 1 )
1397
    begin
1398
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1399
        test_fail("write to WB Image Base Address Register failed") ;
1400
        disable main ;
1401
    end
1402
 
1403
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1404
    // enable address translation
1405
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1406
    if ( ok !== 1 )
1407
    begin
1408
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1409
        test_fail("write to WB Image Control Register failed") ;
1410
        disable main ;
1411
    end
1412
 
1413
    `endif
1414
 
1415
    fork
1416
    begin
1417 106 mihad
        write_data`WRITE_ADDRESS  = target_address + 4 ;
1418
        write_data`WRITE_DATA     = wmem_data[1] ;
1419
        write_data`WRITE_SEL      = 4'hF ;
1420 15 mihad
 
1421
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1422
 
1423
        `ifdef ADDR_TRAN_IMPL
1424
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1425
        `else
1426
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1427
        `endif
1428
 
1429
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1430
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1431
        begin
1432
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1433
            test_fail("WB Slave state machine failed to post single memory write") ;
1434
            disable main ;
1435
        end
1436
 
1437
        // read written data back
1438
        read_data`READ_ADDRESS  = target_address + 4 ;
1439
        read_data`READ_SEL      = 4'hF ;
1440
 
1441
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1442
 
1443
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1444
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1445
        begin
1446
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1447
            test_fail("PCI bridge failed to process single delayed memory read") ;
1448
            disable main ;
1449
        end
1450
 
1451
        if (read_status`READ_DATA !== wmem_data[1])
1452
        begin
1453
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1454
            test_fail("PCI bridge returned unexpected Read Data");
1455
        end
1456
        else
1457
            test_ok ;
1458
    end
1459
    begin
1460
        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 ) ;
1461
        if ( ok !== 1 )
1462
        begin
1463
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1464
        end
1465
        else
1466
            test_ok ;
1467
 
1468
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1469
        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 ) ;
1470
        if ( ok !== 1 )
1471
        begin
1472
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1473
        end
1474
    end
1475
    join
1476
 
1477
    // 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
1478
    // prepare write data
1479 106 mihad
 
1480 15 mihad
    for ( i = 0 ; i < 6 ; i = i + 1 )
1481
    begin
1482
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1483
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1484
        write_data`WRITE_SEL     = 4'hF ;
1485
        wishbone_master.blk_write_data[i] = write_data ;
1486
    end
1487
 
1488
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1489
    write_flags`WB_TRANSFER_CAB    = 1 ;
1490
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1491
 
1492
    fork
1493
    begin
1494
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1495
        wishbone_master.wb_block_write(write_flags, write_status) ;
1496
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1497
        begin
1498
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1499
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1500
            disable main ;
1501
        end
1502
    end
1503
    begin
1504
        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 ) ;
1505
        if ( ok !== 1 )
1506
        begin
1507
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1508
        end
1509
        else
1510
            test_ok ;
1511
    end
1512
    join
1513
 
1514
    // set burst size and latency timer
1515
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1516
 
1517
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1518
    write_flags`WB_TRANSFER_CAB    = 1 ;
1519
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1520
 
1521
    // prepare read data
1522
    for ( i = 0 ; i < 4 ; i = i + 1 )
1523
    begin
1524
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1525
        read_data`READ_SEL     = 4'hF ;
1526
        wishbone_master.blk_read_data_in[i] = read_data ;
1527
    end
1528
 
1529
    fork
1530
    begin
1531
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1532
        wishbone_master.wb_block_read(write_flags, read_status) ;
1533
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1534
        begin
1535
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1536
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1537
            disable main ;
1538
        end
1539
 
1540
        // check data read from target
1541
        for ( i = 0 ; i < 4 ; i = i + 1 )
1542
        begin
1543
            read_status = wishbone_master.blk_read_data_out[i] ;
1544
            if (read_status`READ_DATA !== wmem_data[2 + i])
1545
            begin
1546
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1547
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1548
            end
1549
        end
1550
    end
1551
    begin
1552
        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 ) ;
1553
        if ( ok !== 1 )
1554
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1555
        else
1556
            test_ok ;
1557
 
1558
        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 ) ;
1559
        if ( ok !== 1 )
1560
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1561
        else
1562
            test_ok ;
1563
 
1564
        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 ) ;
1565
        if ( ok !== 1 )
1566
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1567
        else
1568
            test_ok ;
1569
 
1570
        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 ) ;
1571
        if ( ok !== 1 )
1572
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1573
        else
1574
            test_ok ;
1575
 
1576
    end
1577
    join
1578
 
1579
    // now repeat this same burst read with various image features enabled or disabled
1580
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1581
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1582
    if (ok !== 1)
1583
    begin
1584
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1585
        test_fail("write to WB Image control register failed") ;
1586
        disable main ;
1587
    end
1588
 
1589
    fork
1590
    begin
1591
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1592
        wishbone_master.wb_block_read(write_flags, read_status) ;
1593
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1594
        begin
1595
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1596
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1597
            disable main ;
1598
        end
1599
 
1600
        // check data read from target
1601
        for ( i = 0 ; i < 4 ; i = i + 1 )
1602
        begin
1603
            read_status = wishbone_master.blk_read_data_out[i] ;
1604
            if (read_status`READ_DATA !== wmem_data[2 + i])
1605
            begin
1606
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1607
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1608
            end
1609
            else
1610
                test_ok ;
1611
        end
1612
    end
1613
    begin
1614
        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 ) ;
1615
        if ( ok !== 1 )
1616
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1617
    end
1618
    join
1619
 
1620
    read_data`READ_ADDRESS  = target_address ;
1621
    read_data`READ_SEL      = 4'hF ;
1622
 
1623
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1624
    fork
1625
    begin
1626
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1627
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1628
        begin
1629
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1630
            test_fail("delayed single memory read wasn't processed as expected") ;
1631
            disable main ;
1632
        end
1633
 
1634
        if (read_status`READ_DATA !== wmem_data[0])
1635
        begin
1636
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1637
            test_fail("delayed single memory read data value returned was not as expected") ;
1638
        end
1639
        else
1640
            test_ok ;
1641
    end
1642
    begin
1643
        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 ) ;
1644
        if ( ok !== 1 )
1645
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1646
    end
1647
    join
1648
 
1649
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1650
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1651
    if (ok !== 1)
1652
    begin
1653
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1654
        test_fail("write to WB Image control register failed") ;
1655
        disable main ;
1656
    end
1657
 
1658
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1659
    fork
1660
    begin
1661
        wishbone_master.wb_block_read(write_flags, read_status) ;
1662
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1663
        begin
1664
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1665
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1666
            disable main ;
1667
        end
1668
 
1669
        // check data read from target
1670
        for ( i = 0 ; i < 4 ; i = i + 1 )
1671
        begin
1672
            read_status = wishbone_master.blk_read_data_out[i] ;
1673
            if (read_status`READ_DATA !== wmem_data[2 + i])
1674
            begin
1675
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1676
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1677
            end
1678
            else
1679
                test_ok ;
1680
        end
1681
    end
1682
    begin
1683
        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 ) ;
1684
        if ( ok !== 1 )
1685
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1686
    end
1687
    join
1688
 
1689
    read_data`READ_ADDRESS  = target_address + 4 ;
1690
    read_data`READ_SEL      = 4'hF ;
1691
 
1692
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1693
    fork
1694
    begin
1695
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1696
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1697
        begin
1698
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1699
            test_fail("delayed single memory read wasn't processed as expected") ;
1700
            disable main ;
1701
        end
1702
 
1703
        if (read_status`READ_DATA !== wmem_data[1])
1704
        begin
1705
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1706
            test_fail("delayed single memory read data value returned was not as expected") ;
1707
        end
1708
        else
1709
            test_ok ;
1710
    end
1711
    begin
1712
        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 ) ;
1713
        if ( ok !== 1 )
1714
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1715
    end
1716
    join
1717
 
1718
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1719
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1720
    if (ok !== 1)
1721
    begin
1722
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1723
        test_fail("write to WB Image control register failed") ;
1724
        disable main ;
1725
    end
1726
 
1727
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1728
    fork
1729
    begin
1730
        wishbone_master.wb_block_read(write_flags, read_status) ;
1731
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1732
        begin
1733
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1734
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1735
            disable main ;
1736
        end
1737
 
1738
        // check data read from target
1739
        for ( i = 0 ; i < 4 ; i = i + 1 )
1740
        begin
1741
            read_status = wishbone_master.blk_read_data_out[i] ;
1742
            if (read_status`READ_DATA !== wmem_data[2 + i])
1743
            begin
1744
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1745
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1746
            end
1747
            else
1748
                test_ok ;
1749
        end
1750
    end
1751
    begin
1752
        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 ) ;
1753
        if ( ok !== 1 )
1754
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1755
    end
1756
    join
1757
 
1758
    read_data`READ_ADDRESS  = target_address + 8 ;
1759
    read_data`READ_SEL      = 4'hF ;
1760
 
1761
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1762
    fork
1763
    begin
1764
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1765
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1766
        begin
1767
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1768
            test_fail("delayed single memory read wasn't processed as expected") ;
1769
            disable main ;
1770
        end
1771
 
1772
        if (read_status`READ_DATA !== wmem_data[2])
1773
        begin
1774
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1775
            test_fail("delayed single memory read data value returned was not as expected") ;
1776
        end
1777
        else
1778
            test_ok ;
1779
    end
1780
    begin
1781
        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 ) ;
1782
        if ( ok !== 1 )
1783
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1784
    end
1785
    join
1786
 
1787
    // map image to IO space
1788
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1789
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1790
    if ( ok !== 1 )
1791
    begin
1792
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1793
        test_fail("write to WB Image Base Address register failed") ;
1794
        disable main ;
1795
    end
1796
 
1797
    write_data`WRITE_ADDRESS = target_address ;
1798
    write_data`WRITE_DATA    = wmem_data[11] ;
1799
    write_data`WRITE_SEL     = 4'hF ;
1800
 
1801 106 mihad
    // don't handle retries from now on
1802 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1803
 
1804
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1805
    fork
1806
    begin
1807
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1808
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1809
        begin
1810
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1811
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1812
            disable main ;
1813
        end
1814
    end
1815
    begin
1816
        // currently IO commands not supported in behavioral models - master abort
1817
        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 ) ;
1818
        if ( ok !== 1 )
1819
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1820
        else
1821
            test_ok ;
1822
    end
1823
    join
1824
 
1825
    read_data`READ_ADDRESS  = target_address ;
1826
    read_data`READ_SEL      = 4'hF ;
1827
 
1828
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1829
 
1830
    // currently io commands are not supported by behavioral target - transfer should not be completed
1831
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1832
    fork
1833
    begin
1834
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1835
        if (read_status`CYC_ERR !== 1)
1836
        begin
1837
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1838
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1839
            disable main ;
1840
        end
1841
        else
1842
            test_ok ;
1843
    end
1844
    begin
1845
        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 ) ;
1846
        if ( ok !== 1 )
1847
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1848
    end
1849
    join
1850
 
1851
    // test byte addressing
1852 106 mihad
    read_data`READ_ADDRESS  = target_address + 2 ;
1853
    read_data`READ_SEL      = 4'b1100 ;
1854 15 mihad
 
1855
    fork
1856
    begin
1857
        // currently io commands are not supported by behavioral target - transfer should not be completed
1858
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1859
        if (read_status`CYC_ERR !== 1)
1860
        begin
1861
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1862
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1863
            disable main ;
1864
        end
1865
        else test_ok ;
1866
    end
1867
    begin
1868
        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 ) ;
1869
        if ( ok !== 1 )
1870
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1871
    end
1872
    join
1873
 
1874
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1875
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1876
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1877
    if ( ok !== 1 )
1878
    begin
1879
        test_fail("WB Base address register could not be written") ;
1880
        disable main ;
1881
    end
1882
 
1883
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1884
    if ( ok !== 1 )
1885
    begin
1886
        test_fail("WB Address Mask register could not be written") ;
1887
        disable main ;
1888
    end
1889
 
1890
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1891
    if ( ok !== 1 )
1892
    begin
1893
        test_fail("WB Image Control register could not be written") ;
1894
        disable main ;
1895
    end
1896
 
1897 106 mihad
    write_data`WRITE_ADDRESS  = {target_address[31], 31'h7FFF_FFFF} ;
1898
    write_data`WRITE_DATA     = wmem_data[11] ;
1899
    write_data`WRITE_SEL      = 4'b1000 ;
1900 15 mihad
 
1901
    // handle retries from now on
1902
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1903
 
1904
    fork
1905
    begin
1906
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1907
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1908
        begin
1909
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1910
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1911
            disable main ;
1912
        end
1913
    end
1914
    begin
1915
        // currently IO commands not supported in behavioral models - master abort
1916
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1917
        if ( ok !== 1 )
1918
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1919
        else
1920
            test_ok ;
1921
    end
1922
    join
1923
 
1924 106 mihad
    read_data`READ_ADDRESS  = write_data`WRITE_ADDRESS ;
1925
    read_data`READ_SEL      = write_data`WRITE_SEL ;
1926 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1927
 
1928
    fork
1929
    begin
1930
        // currently io commands are not supported by behavioral target - transfer should not be completed
1931
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1932
        if (read_status`CYC_ERR !== 1)
1933
        begin
1934
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1935
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1936
            disable main ;
1937
        end
1938
        else test_ok ;
1939
    end
1940
    begin
1941
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1942
        if ( ok !== 1 )
1943
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1944
    end
1945
    join
1946
 
1947
    test_name = "DISABLING WB IMAGE" ;
1948
 
1949
    // disable current image
1950
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1951
    if ( ok !== 1 )
1952
    begin
1953
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1954
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1955
        disable main ;
1956
    end
1957
 
1958
    // clear master abort status bit
1959
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1960
    if ( ok !== 1 )
1961
    begin
1962
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1963
        test_fail("write to PCI Device Status register not accepted as expected") ;
1964
        disable main ;
1965
    end
1966
 
1967
end //main
1968
endtask //test_wb_image
1969
 
1970 106 mihad
task wb_slave_errors ; //wb_b3_ok
1971 15 mihad
    reg   [11:0] ctrl_offset ;
1972
    reg   [11:0] ba_offset ;
1973
    reg   [11:0] am_offset ;
1974
    reg   [11:0] ta_offset ;
1975
    reg `WRITE_STIM_TYPE write_data ;
1976
    reg `READ_STIM_TYPE  read_data ;
1977
    reg `READ_RETURN_TYPE read_status ;
1978
 
1979
    reg `WRITE_RETURN_TYPE write_status ;
1980
    reg `WB_TRANSFER_FLAGS write_flags ;
1981
    reg [31:0] temp_val1 ;
1982
    reg [31:0] temp_val2 ;
1983
    reg        ok   ;
1984
    reg [11:0] pci_ctrl_offset ;
1985
    reg [31:0] image_base ;
1986
    reg [31:0] target_address ;
1987
    integer    i ;
1988
    reg skip ;
1989
fork
1990
begin:main
1991
 
1992
    `ifdef GUEST
1993
        skip = 1 ;
1994
    `else
1995
        skip = 0 ;
1996
    `endif
1997
 
1998
    pci_ctrl_offset = 12'h4 ;
1999
 
2000
    // image 1 is used for error testing, since it is always implemented
2001
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2002
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2003
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2004
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2005
 
2006
    target_address  = `BEH_TAR1_MEM_START ;
2007
    image_base      = 0 ;
2008
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2009
 
2010
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2011
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2012
    write_flags                    = 0 ;
2013 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
2014
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
2015 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2016
 
2017
    // enable master & target operation
2018
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
2019
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2020
    if ( ok !== 1 )
2021
    begin
2022
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2023
        test_fail("PCI Device Control register couldn't be written") ;
2024
        disable no_transaction ;
2025
        disable main ;
2026
    end
2027
 
2028
    // prepare image control register
2029
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
2030
    if ( ok !== 1 )
2031
    begin
2032
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2033
        test_fail("WB Image Control register couldn't be written") ;
2034
        disable no_transaction ;
2035
        disable main ;
2036
    end
2037
 
2038
    // prepare base address register
2039
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2040
    if ( ok !== 1 )
2041
    begin
2042
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2043
        test_fail("WB Base Address register couldn't be written") ;
2044
        disable no_transaction ;
2045
        disable main ;
2046
    end
2047
 
2048
    // write address mask register
2049
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2050
    if ( ok !== 1 )
2051
    begin
2052
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2053
        test_fail("WB Address Mask register couldn't be written") ;
2054
        disable no_transaction ;
2055
        disable main ;
2056
    end
2057
 
2058
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2059
 
2060
    skip = 0 ;
2061
 
2062
    // memory mapped image - access is erroneous when address is not alligned
2063
    write_data`WRITE_ADDRESS = target_address + 1 ;
2064
    write_data`WRITE_DATA    = wmem_data[0] ;
2065
    write_data`WRITE_SEL     = 4'hF ;
2066
 
2067
    // handle retries from now on
2068
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2069
 
2070
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
2071
 
2072
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2073
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2074
    begin
2075
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2076
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2077
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2078
        disable no_transaction ;
2079
        disable main ;
2080
    end
2081
 
2082
    write_data`WRITE_ADDRESS = target_address + 2 ;
2083
 
2084
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2085
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2086
    begin
2087
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2088
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2089
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2090
        disable no_transaction ;
2091
        disable main ;
2092
 
2093
    end
2094
 
2095
    write_data`WRITE_ADDRESS = target_address + 3 ;
2096
 
2097
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2098
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2099
    begin
2100
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2101
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2102
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2103
        disable no_transaction ;
2104
        disable main ;
2105
    end
2106
 
2107
    test_ok ;
2108
 
2109
    // perform same tests for read accesses
2110
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
2111
 
2112
    read_data`READ_ADDRESS  = target_address + 2 ;
2113
    read_data`READ_SEL      = 4'hF ;
2114
 
2115
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2116
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2117
    begin
2118
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2119
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2120
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
2121
        disable no_transaction ;
2122
        disable main ;
2123
    end
2124
 
2125
    test_ok ;
2126
 
2127
    // prepare write data
2128
    for ( i = 0 ; i < 6 ; i = i + 1 )
2129
    begin
2130
        write_data`WRITE_DATA    = wmem_data[i] ;
2131
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
2132
        write_data`WRITE_SEL     = 4'hF ;
2133
        wishbone_master.blk_write_data[i] = write_data ;
2134
    end
2135
 
2136
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2137
    write_flags`WB_TRANSFER_CAB    = 1 ;
2138
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2139
 
2140
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
2141
    wishbone_master.wb_block_write(write_flags, write_status) ;
2142
 
2143
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2144
    begin
2145
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2146
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2147
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
2148
        disable no_transaction ;
2149
        disable main ;
2150
    end
2151
 
2152
    // prepare read data
2153 106 mihad
 
2154 15 mihad
    for ( i = 0 ; i < 6 ; i = i + 1 )
2155
    begin
2156
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2157
        read_data`READ_SEL     = 4'hF ;
2158
        wishbone_master.blk_read_data_in[i] = read_data ;
2159
    end
2160
 
2161
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2162
    wishbone_master.wb_block_read(write_flags, read_status) ;
2163
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2164
    begin
2165
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2166
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2167
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2168
        disable no_transaction ;
2169
        disable main ;
2170
    end
2171
 
2172
    test_ok ;
2173
 
2174
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2175
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2176
 
2177
    // map image to IO space
2178
    `ifdef GUEST
2179
        skip = 1 ;
2180
    `endif
2181
 
2182
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2183
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2184
    if ( ok !== 1 )
2185
    begin
2186
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2187
        test_fail("WB Image Base Address register couldn't be written") ;
2188
        disable no_transaction ;
2189
        disable main ;
2190
    end
2191
 
2192
    skip = 0 ;
2193
 
2194 106 mihad
    write_data`WRITE_ADDRESS  = target_address ;
2195
    write_data`WRITE_DATA     = wmem_data[0] ;
2196
    write_data`WRITE_SEL      = 4'b1010 ;
2197 15 mihad
 
2198
    // don't handle retries
2199
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2200
 
2201
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2202
 
2203
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2204
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2205
    begin
2206
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2207
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2208
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2209
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2210
        disable no_transaction ;
2211
        disable main ;
2212
    end
2213
 
2214 106 mihad
    write_data`WRITE_ADDRESS  = target_address + 1 ;
2215
    write_data`WRITE_SEL      = 4'b0011 ;
2216 15 mihad
 
2217
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2218
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2219
    begin
2220
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2221
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2222
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2223
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2224
        disable no_transaction ;
2225
        disable main ;
2226
    end
2227
 
2228 106 mihad
    write_data`WRITE_SEL      = 4'b1100 ;
2229 15 mihad
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2230
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2231
    begin
2232
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2233
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2234
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2235
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2236
        disable no_transaction ;
2237
        disable main ;
2238
    end
2239
 
2240 106 mihad
    write_data`WRITE_ADDRESS  = target_address + 2 ;
2241
    write_data`WRITE_SEL      = 4'b0101 ;
2242 15 mihad
 
2243
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2244
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2245
    begin
2246
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2247
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2248
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2249
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2250
        disable no_transaction ;
2251
        disable main ;
2252
    end
2253
 
2254 106 mihad
    write_data`WRITE_SEL      = 4'b1000 ;
2255 15 mihad
 
2256
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2257
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2258
    begin
2259
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2260
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2261
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2262
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2263
        disable no_transaction ;
2264
        disable main ;
2265
    end
2266
 
2267
    write_data`WRITE_ADDRESS = target_address + 3 ;
2268
    write_data`WRITE_SEL     = 4'b1010 ;
2269
 
2270
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2271
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2272
    begin
2273
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2274
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2275
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2276
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2277
        disable no_transaction ;
2278
        disable main ;
2279
    end
2280
 
2281
    write_data`WRITE_SEL     = 4'b0110 ;
2282
 
2283
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2284
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2285
    begin
2286
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2287
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2288
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2289
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2290
        disable no_transaction ;
2291
        disable main ;
2292
    end
2293
 
2294
    test_ok ;
2295
 
2296
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2297
 
2298
    read_data`READ_ADDRESS  = target_address + 3 ;
2299
    read_data`READ_SEL      = 4'hF ;
2300
 
2301
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2302
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2303
    begin
2304
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2305
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2306
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2307
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2308
        disable no_transaction ;
2309
        disable main ;
2310
    end
2311
 
2312
    test_ok ;
2313
 
2314
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2315 106 mihad
 
2316 15 mihad
    // prepare write data
2317
    for ( i = 0 ; i < 6 ; i = i + 1 )
2318
    begin
2319
        write_data`WRITE_DATA    = wmem_data[i] ;
2320
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2321
        write_data`WRITE_SEL     = 4'hF ;
2322
        wishbone_master.blk_write_data[i] = write_data ;
2323
    end
2324
 
2325
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2326
    write_flags`WB_TRANSFER_CAB    = 1 ;
2327
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2328
 
2329
    wishbone_master.wb_block_write(write_flags, write_status) ;
2330
 
2331
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2332
    begin
2333
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2334
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2335
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2336
        disable no_transaction ;
2337
        disable main ;
2338
    end
2339
 
2340
    test_ok ;
2341
 
2342
    test_name = "CAB I/O READ TO WB SLAVE" ;
2343 106 mihad
 
2344 15 mihad
    // prepare read data
2345
    for ( i = 0 ; i < 6 ; i = i + 1 )
2346
    begin
2347
        read_data`READ_ADDRESS = target_address + 4*i ;
2348
        read_data`READ_SEL     = 4'hF ;
2349
        wishbone_master.blk_read_data_in[i] = read_data ;
2350
    end
2351
 
2352
    wishbone_master.wb_block_read(write_flags, read_status) ;
2353
 
2354
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2355
    begin
2356
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2357
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2358
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2359
        disable no_transaction ;
2360
        disable main ;
2361
    end
2362
 
2363
    test_ok ;
2364
 
2365
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2366
 
2367
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2368
 
2369 106 mihad
    begin:test_erroneous_config_access_blk
2370
        reg do_write_test ;
2371
        reg do_read_test  ;
2372 15 mihad
 
2373 106 mihad
        target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2374 15 mihad
 
2375 106 mihad
        do_write_test = 1'b0 ;
2376
        do_read_test  = 1'b0 ;
2377
 
2378 15 mihad
    `ifdef HOST
2379
 
2380 106 mihad
        do_write_test = 1'b1 ;
2381
        do_read_test  = 1'b1 ;
2382 15 mihad
 
2383 106 mihad
    `else
2384 15 mihad
 
2385 106 mihad
    `ifdef WB_CNF_IMAGE
2386 15 mihad
 
2387 106 mihad
        do_read_test = 1'b1 ;
2388 15 mihad
 
2389 106 mihad
    `endif
2390 15 mihad
 
2391
    `endif
2392 106 mihad
 
2393
    `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
2394
    `else
2395 15 mihad
 
2396 106 mihad
        if (do_write_test)
2397
        begin
2398
 
2399
            write_data`WRITE_ADDRESS  = target_address + 1 ;
2400
            write_data`WRITE_DATA     = wmem_data[0] ;
2401
            write_data`WRITE_SEL      = 4'hF ;
2402
 
2403
            // don't handle retries
2404
            write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2405 15 mihad
 
2406 106 mihad
            test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2407
            wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2408
            if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2409
            begin
2410
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2411
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2412
                test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2413
                disable no_transaction ;
2414
                disable main ;
2415
            end
2416
 
2417
            // try write to configuration cycle address register with non alligned address
2418
            write_data`WRITE_ADDRESS  = target_address + {4'h1, `CNF_ADDR_ADDR, 2'b10} ;
2419 15 mihad
 
2420 106 mihad
            wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2421
            if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2422
            begin
2423
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2424
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2425
                test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2426
                disable no_transaction ;
2427
                disable main ;
2428
            end
2429
 
2430
            write_data`WRITE_ADDRESS = target_address + {4'h1, `CNF_DATA_ADDR, 2'b11} ;
2431 15 mihad
 
2432 106 mihad
            // try write to configuration cycle data register with non alligned address
2433
            wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2434
            if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2435
            begin
2436
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2437
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2438
                test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2439
                disable no_transaction ;
2440
                disable main ;
2441
            end
2442
 
2443
            test_ok ;
2444
        end
2445 15 mihad
 
2446 106 mihad
        if (do_read_test)
2447
        begin
2448
            test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2449
            // try read from configuration cycle data register with non alligned address
2450
            read_data`READ_ADDRESS  = target_address + {4'h1, `CNF_DATA_ADDR, 2'b01} ;
2451
            read_data`READ_SEL      = 4'hF ;
2452
 
2453
            wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2454
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2455
            begin
2456
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2457
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2458
                test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2459
                disable no_transaction ;
2460
                disable main ;
2461
            end
2462
 
2463
            test_ok ;
2464
        end
2465 15 mihad
 
2466
    `endif
2467
 
2468 106 mihad
        if (do_write_test)
2469
        begin
2470
            // prepare write data
2471
            test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2472 15 mihad
 
2473 106 mihad
            for ( i = 0 ; i < 6 ; i = i + 1 )
2474
            begin
2475
                write_data`WRITE_DATA    = wmem_data[i] ;
2476
                write_data`WRITE_ADDRESS = target_address + 4*i + {4'h1, `CNF_DATA_ADDR, 2'b00};
2477
                write_data`WRITE_SEL     = 4'hF ;
2478
                wishbone_master.blk_write_data[i] = write_data ;
2479
            end
2480
 
2481
            write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2482
            write_flags`WB_TRANSFER_CAB    = 1 ;
2483
            write_flags`WB_TRANSFER_SIZE   = 6 ;
2484
 
2485
            wishbone_master.wb_block_write(write_flags, write_status) ;
2486
 
2487
            if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2488
            begin
2489
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2490
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2491
                test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2492
                disable no_transaction ;
2493
                disable main ;
2494
            end
2495
            test_ok ;
2496
        end
2497
 
2498
        if (do_read_test)
2499
        begin
2500
            // prepare read data
2501
            test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2502 15 mihad
 
2503 106 mihad
            for ( i = 0 ; i < 6 ; i = i + 1 )
2504
            begin
2505
                read_data`READ_ADDRESS = target_address + 4*i + {4'h1, `CNF_DATA_ADDR, 2'b00};
2506
                read_data`READ_SEL     = 4'hF ;
2507
                wishbone_master.blk_read_data_in[i] = read_data ;
2508
            end
2509
 
2510
            wishbone_master.wb_block_read(write_flags, read_status) ;
2511
 
2512
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2513
            begin
2514
                $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2515
                $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2516
                test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2517
                disable no_transaction ;
2518
                disable main ;
2519
            end
2520
            test_ok ;
2521
        end
2522
 
2523
        `ifdef GUEST
2524
            skip = 1 ;
2525
        `endif
2526
    end // test_erroneous_config_access_blk
2527 15 mihad
 
2528
    // disable image
2529
    test_name = "DISABLE IMAGE" ;
2530
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2531
    if ( ok !== 1 )
2532
    begin
2533
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2534
        test_fail("WB Address Mask register couldn't be written") ;
2535
        disable no_transaction ;
2536
        disable main ;
2537
    end
2538
 
2539
    skip = 0 ;
2540
 
2541
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2542
 
2543
    disable no_transaction ;
2544
end
2545
begin:no_transaction
2546
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2547
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2548
    forever
2549
    begin
2550
        @(posedge pci_clock) ;
2551
        if ( skip !== 1 )
2552
        begin
2553
            if ( FRAME !== 1 )
2554
            begin
2555
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2556
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2557
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2558
            end
2559
        end
2560
    end
2561
end
2562
join
2563
endtask //wb_slave_errors
2564
 
2565
task wb_to_pci_error_handling ;
2566
    reg   [11:0] ctrl_offset ;
2567
    reg   [11:0] ba_offset ;
2568
    reg   [11:0] am_offset ;
2569
    reg   [11:0] ta_offset ;
2570
    reg   [11:0] err_cs_offset ;
2571
    reg `WRITE_STIM_TYPE write_data ;
2572
    reg `READ_STIM_TYPE  read_data ;
2573
    reg `READ_RETURN_TYPE read_status ;
2574
 
2575
    reg `WRITE_RETURN_TYPE write_status ;
2576
    reg `WB_TRANSFER_FLAGS write_flags ;
2577
    reg [31:0] temp_val1 ;
2578
    reg [31:0] temp_val2 ;
2579
    reg        ok   ;
2580
    reg [11:0] pci_ctrl_offset ;
2581
    reg [31:0] image_base ;
2582
    reg [31:0] target_address ;
2583
    integer    num_of_trans ;
2584
    integer    current ;
2585
    integer    i ;
2586
begin:main
2587
 
2588
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2589
 
2590
    pci_ctrl_offset = 12'h4 ;
2591
 
2592
    // disable error interrupts and disable error reporting
2593
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2594
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2595
    if ( ok !== 1 )
2596
    begin
2597
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2598
        test_fail("PCI Device Control register couldn't be written") ;
2599
        disable main ;
2600
    end
2601
 
2602
    // image 1 is used for error testing, since it is always implemented
2603
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2604
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2605
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2606
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2607
 
2608
    // set master abort testing address to address that goes out of target's range
2609
    target_address  = `BEH_TAR1_MEM_START ;
2610
    image_base      = 0 ;
2611
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2612
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2613
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2614
 
2615
    write_flags                    = 0 ;
2616 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
2617
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
2618 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2619
 
2620
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2621
 
2622
    // enable master & target operation
2623
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2624
    if ( ok !== 1 )
2625
    begin
2626
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2627
        test_fail("PCI Device Control register couldn't be written") ;
2628
        disable main ;
2629
    end
2630
 
2631
    // prepare image control register
2632
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2633
    if ( ok !== 1 )
2634
    begin
2635
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2636
        test_fail("WB Image Control register couldn't be written") ;
2637
        disable main ;
2638
    end
2639
 
2640
    // prepare base address register
2641
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2642
    if ( ok !== 1 )
2643
    begin
2644
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2645
        test_fail("WB Image Base Address register couldn't be written") ;
2646
        disable main ;
2647
    end
2648
 
2649
    // write address mask register
2650
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2651
    if ( ok !== 1 )
2652
    begin
2653
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2654
        test_fail("WB Image Address Mask register couldn't be written") ;
2655
        disable main ;
2656
    end
2657
 
2658
    // disable error reporting
2659
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2660
    if ( ~ok )
2661
    begin
2662
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2663
        test_fail("WB Error Control and Status register couldn't be written") ;
2664
        disable main ;
2665
    end
2666
 
2667
    // perform two writes - one to error address and one to OK address
2668
    // prepare write buffer
2669
 
2670 106 mihad
    write_data`WRITE_ADDRESS  = target_address ;
2671
    write_data`WRITE_DATA     = wmem_data[100] ;
2672
    write_data`WRITE_SEL      = 4'hF ;
2673 15 mihad
 
2674
    wishbone_master.blk_write_data[0] = write_data ;
2675
 
2676
    write_flags`WB_TRANSFER_SIZE = 2 ;
2677
 
2678
    // don't handle retries
2679
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2680
    write_flags`WB_TRANSFER_CAB    = 0 ;
2681
 
2682
    $display("Introducing master abort error on single WB to PCI write!") ;
2683
 
2684
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2685
    // first disable target 1
2686
 
2687 45 mihad
    configuration_cycle_write(0,                        // bus number
2688
                              `TAR1_IDSEL_INDEX - 11,   // device number
2689
                              0,                        // function number
2690
                              1,                        // register number
2691
                              0,                        // type of configuration cycle
2692
                              4'b0001,                  // byte enables
2693
                              32'h0000_0000             // data
2694 15 mihad
                             ) ;
2695
 
2696
    fork
2697
    begin
2698
        // start no response monitor in parallel with writes
2699
        musnt_respond(ok) ;
2700
        if ( ok !== 1 )
2701
        begin
2702
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2703
            $display("Testbench is configured wrong!") ;
2704
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2705
        end
2706
        else
2707
            test_ok ;
2708
    end
2709
    begin
2710
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2711
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2712
       begin
2713
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2714
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2715
           test_fail("WB Slave state machine failed to post single memory write");
2716
           disable main ;
2717
       end
2718
    end
2719
    join
2720
 
2721 92 mihad
    // read data from second write
2722 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2723
    read_data`READ_ADDRESS = target_address ;
2724
    read_data`READ_SEL     = 4'hF ;
2725
 
2726
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2727
 
2728
    if ( read_status`READ_DATA !== wmem_data[101] )
2729
    begin
2730
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2731
    end
2732
 
2733
    // read error status register - no errors should be reported since reporting was disabled
2734
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2735
 
2736
    @(posedge pci_clock) ;
2737
    // wait for two WB clocks for synchronization to be finished
2738
    repeat (2)
2739
        @(posedge wb_clock) ;
2740
 
2741
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2742
    if ( temp_val1[8] !== 0 )
2743
    begin
2744
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2745
        $display("Error reporting was disabled, but error was reported anyway!") ;
2746
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2747
        disable main ;
2748
    end
2749
    test_ok ;
2750
 
2751
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2752
    // check for interrupts - there should be no interrupt requests active
2753
    `ifdef HOST
2754
        repeat(4)
2755
            @(posedge wb_clock) ;
2756
 
2757
        if ( INT_O !== 0 )
2758
        begin
2759
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2760
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2761
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2762
        end
2763
        else
2764
            test_ok ;
2765
    `else
2766
    `ifdef GUEST
2767
        repeat( 4 )
2768
            @(posedge pci_clock) ;
2769
 
2770
        if ( INTA !== 1 )
2771
        begin
2772
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2773
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2774
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2775
        end
2776
        else
2777
            test_ok ;
2778
    `endif
2779
    `endif
2780
 
2781
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2782
    // check PCI status register
2783
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2784
    if ( temp_val1[29] !== 1 )
2785
    begin
2786
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2787
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2788
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2789
    end
2790
    else
2791
        test_ok ;
2792
 
2793
    // clear
2794
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2795
 
2796
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2797
 
2798
    $display("Introducing master abort error to CAB write!") ;
2799
    // now enable error reporting mechanism
2800
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2801
    // enable error interrupts
2802
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2803
 
2804
    // configure flags for CAB transfer
2805
    write_flags`WB_TRANSFER_CAB = 1 ;
2806
    write_flags`WB_TRANSFER_SIZE = 3 ;
2807
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2808
 
2809
    // prepare data for erroneous write
2810
    for ( i = 0 ; i < 3 ; i = i + 1 )
2811
    begin
2812
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2813
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2814
        write_data`WRITE_SEL     = 4'hF ;
2815
        wishbone_master.blk_write_data[i] = write_data ;
2816
    end
2817 106 mihad
 
2818 15 mihad
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2819
    fork
2820
    begin
2821
        wishbone_master.wb_block_write(write_flags, write_status) ;
2822
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2823
        begin
2824
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2825
            $display("Complete burst write through WB slave didn't succeed!") ;
2826
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2827
            disable main ;
2828
        end
2829
    end
2830
    begin
2831
        musnt_respond(ok) ;
2832
        if ( ok !== 1 )
2833
        begin
2834
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2835
            $display("Testbench is configured wrong!") ;
2836
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2837
        end
2838
        else
2839
            test_ok ;
2840
    end
2841
    join
2842
 
2843
    // check error status address, data, byte enables and bus command
2844
    // error status bit is signalled on PCI clock and synchronized to WB clock
2845
    // wait one PCI clock cycle
2846
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2847
    ok = 1 ;
2848
    @(posedge pci_clock) ;
2849
 
2850
    // wait for two WB clocks for synchronization to be finished
2851
    repeat (2)
2852
        @(posedge wb_clock) ;
2853
 
2854
    // read registers
2855
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2856
    if ( temp_val1[8] !== 1 )
2857
    begin
2858
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2859
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2860
        ok = 0 ;
2861
    end
2862
 
2863
    if ( temp_val1[9] !== 1 )
2864
    begin
2865
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2866
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2867
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2868
        ok = 0 ;
2869
    end
2870
 
2871
    if ( temp_val1[31:28] !== 0 )
2872
    begin
2873
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2874
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2875
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2876
        ok = 0 ;
2877
    end
2878
 
2879
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2880
    begin
2881
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2882
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2883
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2884
        ok = 0 ;
2885
    end
2886
 
2887
    // read error address register
2888
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2889
    if ( temp_val1 !== target_address )
2890
    begin
2891
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2892
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2893
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2894
        ok = 0 ;
2895
    end
2896
 
2897
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2898
    if ( temp_val1 !== wmem_data[110] )
2899
    begin
2900
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2901
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2902
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2903
        ok = 0 ;
2904
    end
2905
 
2906
    // check PCI status register
2907
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2908
    if ( temp_val1[29] !== 1 )
2909
    begin
2910
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2911
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2912
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2913
        ok = 0 ;
2914
    end
2915
 
2916
    if ( temp_val1[28] !== 0 )
2917
    begin
2918
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2919
        $display("Received Target Abort bit was set for no reason!") ;
2920
        test_fail("Received Target Abort bit was set for no reason") ;
2921
        ok = 0 ;
2922
    end
2923
 
2924
    if ( ok )
2925
        test_ok ;
2926
 
2927
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2928
 
2929
    // clear error status bit
2930
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2931
 
2932
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2933
 
2934
    ok = 1 ;
2935
 
2936
    `ifdef HOST
2937
        repeat(4)
2938
        @(posedge wb_clock) ;
2939
        if ( INT_O !== 1 )
2940
        begin
2941
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2942
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2943
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2944
            ok = 0 ;
2945
        end
2946
    `else
2947
    `ifdef GUEST
2948
        repeat(4)
2949
        @(posedge pci_clock) ;
2950
        if ( INTA !== 0 )
2951
        begin
2952
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2953
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2954
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2955
            ok = 0 ;
2956
        end
2957
    `endif
2958
    `endif
2959
 
2960
    // read interrupt status register
2961
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2962
    if ( temp_val1 !== 32'h0000_0002 )
2963
    begin
2964
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2965
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2966
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2967
        test_fail("Interrupt Status register returned wrong value") ;
2968
        ok = 0 ;
2969
    end
2970
 
2971
    if ( ok )
2972
        test_ok ;
2973
    // clear interrupt status bits
2974
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2975
 
2976
    ok = 1 ;
2977
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2978
    // wait for two clock cycles before checking interrupt request deassertion
2979
    `ifdef HOST
2980
        repeat (4)
2981
            @(posedge wb_clock) ;
2982
 
2983
        if ( INT_O !== 0 )
2984
        begin
2985
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2986
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2987
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2988
            ok = 0 ;
2989
        end
2990
    `else
2991
    `ifdef GUEST
2992
        repeat (4)
2993
            @(posedge pci_clock) ;
2994
 
2995
        if ( INTA !== 1 )
2996
        begin
2997
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2998
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2999
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
3000
            ok = 0 ;
3001
        end
3002
    `endif
3003
    `endif
3004
 
3005
    if ( ok )
3006
        test_ok ;
3007
 
3008
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
3009
    ok = 1 ;
3010
    // enable target
3011 45 mihad
    configuration_cycle_write(0,                        // bus number
3012
                              `TAR1_IDSEL_INDEX - 11,   // device number
3013
                              0,                        // function number
3014
                              1,                        // register number
3015
                              0,                        // type of configuration cycle
3016
                              4'b0001,                  // byte enables
3017
                              32'h0000_0007             // data
3018 15 mihad
                             ) ;
3019
    // prepare data for ok write
3020
    for ( i = 0 ; i < 3 ; i = i + 1 )
3021
    begin
3022
        write_data`WRITE_ADDRESS = target_address + 4*i ;
3023
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
3024
        write_data`WRITE_SEL     = 4'hF ;
3025
        wishbone_master.blk_write_data[i] = write_data ;
3026
    end
3027 106 mihad
 
3028 15 mihad
    wishbone_master.wb_block_write(write_flags, write_status) ;
3029
 
3030
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3031
    begin
3032
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3033
        $display("Complete burst write through WB slave didn't succeed!") ;
3034
        test_fail("WB Slave state machine failed to post CAB write") ;
3035
        disable main ;
3036
    end
3037
 
3038
    // do a read
3039
    for ( i = 0 ; i < 3 ; i = i + 1 )
3040
    begin
3041
        read_data`READ_ADDRESS = target_address + 4*i ;
3042
        read_data`READ_SEL     = 4'hF ;
3043
        wishbone_master.blk_read_data_in[i] = read_data ;
3044
    end
3045
 
3046
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3047
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3048
    write_flags`WB_TRANSFER_CAB    = 1 ;
3049
 
3050
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3051
 
3052
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3053
    begin
3054
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3055
        $display("Complete burst read through WB slave didn't succeed!") ;
3056
        test_fail("Delayed CAB write was not processed as expected") ;
3057
        disable main ;
3058
    end
3059
 
3060
    for ( i = 0 ; i < 3 ; i = i + 1 )
3061
    begin
3062
        read_status = wishbone_master.blk_read_data_out[i] ;
3063
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
3064
        begin
3065
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
3066
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
3067
        end
3068
    end
3069
 
3070
    $display("Introducing master abort error to single read!") ;
3071
    // disable target
3072 45 mihad
    configuration_cycle_write(0,                        // bus number
3073
                              `TAR1_IDSEL_INDEX - 11,   // device number
3074
                              0,                        // function number
3075
                              1,                        // register number
3076
                              0,                        // type of configuration cycle
3077
                              4'b0001,                  // byte enables
3078
                              32'h0000_0000             // data
3079 15 mihad
                             ) ;
3080
    // set read data
3081 106 mihad
    read_data`READ_ADDRESS  = target_address ;
3082
    read_data`READ_SEL      = 4'hF ;
3083 15 mihad
 
3084
    // enable automatic retry handling
3085
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3086 106 mihad
    write_flags`WB_TRANSFER_CAB      = 0 ;
3087 15 mihad
 
3088
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
3089
    fork
3090
    begin
3091
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3092
    end
3093
    begin
3094
        musnt_respond(ok) ;
3095
        if ( ok !== 1 )
3096
        begin
3097
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3098
            $display("Testbench is configured wrong!") ;
3099
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3100
        end
3101
    end
3102
    join
3103
 
3104
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3105
    begin
3106
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3107
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3108
        $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) ;
3109
        test_fail("read didn't finish on WB bus as expected") ;
3110
        disable main ;
3111
    end
3112
 
3113
    test_ok ;
3114
 
3115
 
3116
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
3117
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
3118
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3119
    if ( temp_val1[8] !== 0 )
3120
    begin
3121
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3122
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
3123
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
3124
    end
3125
    else
3126
        test_ok ;
3127
 
3128
    // now check normal read operation
3129 45 mihad
    configuration_cycle_write(0,                        // bus number
3130
                              `TAR1_IDSEL_INDEX - 11,   // device number
3131
                              0,                        // function number
3132
                              1,                        // register number
3133
                              0,                        // type of configuration cycle
3134
                              4'b0001,                  // byte enables
3135
                              32'h0000_0007             // data
3136 15 mihad
                             ) ;
3137
 
3138 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
3139 106 mihad
    read_data`READ_ADDRESS  = target_address ;
3140
    read_data`READ_SEL      = 4'hF ;
3141 15 mihad
 
3142
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3143
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3144
    begin
3145
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3146
        $display("WB slave failed to process single read!") ;
3147
        $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) ;
3148
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
3149
        disable main ;
3150
    end
3151
 
3152
    if ( read_status`READ_DATA !== wmem_data[113] )
3153
    begin
3154
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
3155
        test_fail("when read finished on WB bus, wrong data was provided") ;
3156
    end
3157
    else
3158
        test_ok ;
3159
 
3160
    // check PCI status register
3161 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
3162 15 mihad
    ok = 1 ;
3163
 
3164
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3165
    if ( temp_val1[29] !== 1 )
3166
    begin
3167
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3168
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3169
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3170
        ok = 0 ;
3171
    end
3172
 
3173
    if ( temp_val1[28] !== 0 )
3174
    begin
3175
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3176
        $display("Received Target Abort bit was set for no reason!") ;
3177
        test_fail("Received Target Abort bit was set for no reason") ;
3178
        ok = 0 ;
3179
    end
3180
    if ( ok )
3181
        test_ok ;
3182
 
3183
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3184
 
3185
    $display("Introducing master abort error to CAB read!") ;
3186
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3187
 
3188 45 mihad
    configuration_cycle_write(0,                        // bus number
3189
                              `TAR1_IDSEL_INDEX - 11,   // device number
3190
                              0,                        // function number
3191
                              1,                        // register number
3192
                              0,                        // type of configuration cycle
3193
                              4'b0001,                  // byte enables
3194
                              32'h0000_0000             // data
3195 15 mihad
                             ) ;
3196
 
3197 106 mihad
 
3198 15 mihad
    for ( i = 0 ; i < 3 ; i = i + 1 )
3199
    begin
3200
        read_data`READ_ADDRESS = target_address + 4*i ;
3201
        read_data`READ_SEL     = 4'hF ;
3202
        wishbone_master.blk_read_data_in[i] = read_data ;
3203
    end
3204
 
3205
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3206 106 mihad
    write_flags`WB_TRANSFER_SIZE     = 3 ;
3207
    write_flags`WB_TRANSFER_CAB      = 1 ;
3208 15 mihad
 
3209
    fork
3210
    begin
3211
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3212
    end
3213
    begin
3214
        musnt_respond(ok) ;
3215
        if ( ok !== 1 )
3216
        begin
3217
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3218
            $display("Testbench is configured wrong!") ;
3219
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3220
        end
3221
    end
3222
    join
3223
 
3224
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3225
    begin
3226
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3227
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3228
        $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) ;
3229
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3230
        disable main ;
3231
    end
3232
    else
3233
        test_ok ;
3234
 
3235
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3236
    ok = 1 ;
3237
    // check PCI status register
3238
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3239
    if ( temp_val1[29] !== 1 )
3240
    begin
3241
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3242
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3243
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3244
        ok = 0 ;
3245
    end
3246
 
3247
    if ( temp_val1[28] !== 0 )
3248
    begin
3249
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3250
        $display("Received Target Abort bit was set for no reason!") ;
3251
        test_fail("Received Target Abort bit was set for no reason") ;
3252
        ok = 0 ;
3253
    end
3254
 
3255
    if ( ok )
3256
        test_ok ;
3257
 
3258
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3259
 
3260
    $display("Introducing target abort termination to single write!") ;
3261
 
3262
    // disable error reporting and interrupts
3263
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3264
 
3265 45 mihad
    configuration_cycle_write(0,                        // bus number
3266
                              `TAR1_IDSEL_INDEX - 11,   // device number
3267
                              0,                        // function number
3268
                              1,                        // register number
3269
                              0,                        // type of configuration cycle
3270
                              4'b0001,                  // byte enables
3271
                              32'h0000_0007             // data
3272 15 mihad
                             ) ;
3273
 
3274
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3275
    if ( ok !== 1 )
3276
    begin
3277
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3278
        test_fail("WB Error Control and Status register couldn't be written to") ;
3279
        disable main ;
3280
    end
3281
 
3282
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3283
    if ( ok !== 1 )
3284
    begin
3285
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3286
        test_fail("Interrupt Control register couldn't be written to") ;
3287
        disable main ;
3288
    end
3289
 
3290
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3291
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3292
 
3293
    write_data`WRITE_ADDRESS = target_address ;
3294
    write_data`WRITE_DATA    = wmem_data[0] ;
3295
    write_data`WRITE_SEL     = 4'hF ;
3296
 
3297
    wishbone_master.blk_write_data[0] = write_data ;
3298
 
3299
    write_data`WRITE_ADDRESS = target_address + 4;
3300
    write_data`WRITE_DATA    = wmem_data[1] ;
3301
    write_data`WRITE_SEL     = 4'hF ;
3302
 
3303
    wishbone_master.blk_write_data[1] = write_data ;
3304
 
3305
    write_flags`WB_TRANSFER_SIZE = 2 ;
3306
 
3307
    // don't handle retries
3308
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3309
    write_flags`WB_TRANSFER_CAB    = 0 ;
3310
 
3311
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3312
    fork
3313
    begin
3314
        wishbone_master.wb_block_write(write_flags, write_status) ;
3315
 
3316
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3317
        begin
3318
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3319
            $display("Image writes were not accepted as expected!") ;
3320
            $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) ;
3321
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3322
            disable main ;
3323
        end
3324
 
3325
        // read data back to see, if it was written OK
3326
        read_data`READ_ADDRESS         = target_address + 4;
3327
        read_data`READ_SEL             = 4'hF ;
3328
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3329
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3330
    end
3331
    begin
3332
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3333
        if ( ok !== 1 )
3334
        begin
3335
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3336
        end
3337
        else
3338
            test_ok ;
3339
 
3340
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3341
 
3342
        // when first transaction finishes - enable normal target response!
3343
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3344
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3345
 
3346
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3347
        if ( ok !== 1 )
3348
        begin
3349
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3350
        end
3351
        else
3352
            test_ok ;
3353
 
3354
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3355
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3356
        if ( ok !== 1 )
3357
        begin
3358
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3359
        end
3360
    end
3361
    join
3362
 
3363
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3364
    begin
3365
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3366
        $display("Bridge failed to process single read after target abort terminated write!") ;
3367
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3368
        disable main ;
3369
    end
3370
 
3371
    if ( read_status`READ_DATA !== wmem_data[1] )
3372
    begin
3373
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3374
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3375
    end
3376
    else
3377
        test_ok ;
3378
 
3379
    // check interrupt and error statuses!
3380
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3381
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3382
    if ( temp_val1[8] !== 0 )
3383
    begin
3384
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3385
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3386
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3387
    end
3388
    else
3389
        test_ok ;
3390
 
3391
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3392
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3393
    if ( temp_val1[1] !== 0 )
3394
    begin
3395
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3396
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3397
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3398
    end
3399
    else
3400
        test_ok ;
3401
 
3402
    // check PCI status register
3403
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3404
    ok = 1 ;
3405
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3406
    if ( temp_val1[29] !== 0 )
3407
    begin
3408
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3409
        $display("Received Master Abort bit was set with no reason!") ;
3410
        test_fail("Received Master Abort bit was set with no reason") ;
3411
        ok = 0 ;
3412
    end
3413
 
3414
    if ( temp_val1[28] !== 1 )
3415
    begin
3416
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3417
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3418
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3419
        ok = 0 ;
3420
    end
3421
 
3422
    if ( ok )
3423
        test_ok ;
3424
 
3425
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3426
 
3427
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3428
 
3429
    $display("Introducing target abort termination to CAB write!") ;
3430
    // enable error reporting mechanism
3431
 
3432
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3433
    if ( ok !== 1 )
3434
    begin
3435
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3436
        test_fail("WB Error Control and Status register could not be written to") ;
3437
        disable main ;
3438
    end
3439
 
3440
    for ( i = 0 ; i < 3 ; i = i + 1 )
3441
    begin
3442
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3443
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3444
        write_data`WRITE_SEL     = 4'b1010 ;
3445
        wishbone_master.blk_write_data[i] = write_data ;
3446
    end
3447
 
3448
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3449
    write_flags`WB_TRANSFER_CAB    = 1 ;
3450
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3451
 
3452
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3453
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3454
 
3455
    fork
3456
    begin
3457
        wishbone_master.wb_block_write(write_flags, write_status) ;
3458
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3459
        begin
3460
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3461
            $display("Bridge failed to process complete CAB write!") ;
3462
            test_fail("bridge failed to post CAB Memory Write") ;
3463
            disable main ;
3464
        end
3465
    end
3466
    begin
3467
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3468
        if ( ok !== 1 )
3469
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3470
        else
3471
            test_ok ;
3472
    end
3473
    join
3474
 
3475
    // check statuses and data from error
3476
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3477
    ok = 1 ;
3478
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3479
    if ( temp_val1[8] !== 1 )
3480
    begin
3481
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3482
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3483
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3484
        ok = 0 ;
3485
    end
3486
 
3487
    if ( temp_val1[9] !== 0 )
3488
    begin
3489
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3490
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3491
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3492
        ok = 0 ;
3493
    end
3494
 
3495
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3496
    begin
3497
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3498
        $display("Value in W_ERR_CS register was wrong!") ;
3499
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3500 106 mihad
        test_fail("BE Field didn't provide expected value") ;
3501 15 mihad
        ok = 0 ;
3502
    end
3503
 
3504
    if ( ok )
3505
        test_ok ;
3506
 
3507
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3508
    ok = 1 ;
3509
    // check erroneous address and data
3510
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3511
    if ( temp_val1 !== (target_address + 8) )
3512
    begin
3513
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3514
        $display("Value in W_ERR_ADDR register was wrong!") ;
3515
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3516
        test_fail("Value in WB Erroneous Address register was wrong") ;
3517
        ok = 0 ;
3518
    end
3519
 
3520
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3521 106 mihad
 
3522
    // mask expected and actual values, since all byte enables were not active
3523
    if ( (temp_val1 & 32'hff_00_ff_00) !== (wmem_data[120] & 32'hff_00_ff_00) )
3524 15 mihad
    begin
3525
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3526
        $display("Value in W_ERR_DATA register was wrong!") ;
3527 106 mihad
        $display("Expected value = %h, actual value = %h " , wmem_data[120] & 32'hff_00_ff_00, temp_val1 & 32'hff_00_ff_00) ;
3528 15 mihad
        test_fail("Value in WB Erroneous Data register was wrong") ;
3529
        ok = 0 ;
3530
    end
3531
 
3532
    if ( ok )
3533
        test_ok ;
3534
 
3535
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3536
    ok = 1 ;
3537
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3538
    if ( temp_val1[29] !== 0 )
3539
    begin
3540
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3541
        $display("Received Master Abort bit was set with no reason!") ;
3542
        test_fail("Received Master Abort bit was set for no reason") ;
3543
        ok = 0 ;
3544
    end
3545
 
3546
    if ( temp_val1[28] !== 1 )
3547
    begin
3548
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3549
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3550
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3551
        ok = 0 ;
3552
    end
3553
 
3554
    if ( ok )
3555
        test_ok ;
3556
 
3557
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3558
 
3559
    // clear error status bit and enable error interrupts
3560
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3561
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3562
 
3563
    // check if error bit was cleared
3564
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3565
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3566
    if ( temp_val1[8] !== 0 )
3567
    begin
3568
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3569
        $display("Error bit was not cleared even though one was written to its location!") ;
3570
        test_fail("Error bit was not cleared even though one was written to its location") ;
3571
    end
3572
 
3573
    // repeat same write with different target configuration
3574
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3575
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3576
 
3577
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3578
    fork
3579
    begin
3580
        write_flags`WB_TRANSFER_SIZE = 2 ;
3581
        wishbone_master.wb_block_write(write_flags, write_status) ;
3582
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3583
        begin
3584
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3585
            $display("Bridge failed to process complete CAB write!") ;
3586
            test_fail("bridge failed to post CAB Memory Write") ;
3587
            disable main ;
3588
        end
3589
 
3590
        write_flags`WB_TRANSFER_SIZE = 3 ;
3591
        wishbone_master.wb_block_write(write_flags, write_status) ;
3592
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3593
        begin
3594
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3595
            $display("Bridge failed to process complete CAB write!") ;
3596
            test_fail("bridge failed to post CAB Memory Write") ;
3597
            disable main ;
3598
        end
3599
    end
3600
    begin
3601
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3602
        if ( ok !== 1 )
3603
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3604
        else
3605
        begin
3606
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3607
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3608
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3609
            if ( ok !== 1 )
3610
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3611
            else
3612
                test_ok ;
3613
        end
3614
    end
3615
    join
3616
 
3617
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3618
    ok = 1 ;
3619
    // check statuses and data from error
3620
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3621
    if ( temp_val1[8] !== 1 )
3622
    begin
3623
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3624
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3625
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3626
        ok = 0 ;
3627
    end
3628
 
3629
    if ( temp_val1[9] !== 0 )
3630
    begin
3631
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3632
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3633
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3634
        ok = 0 ;
3635
    end
3636
 
3637
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3638
    begin
3639
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3640
        $display("Value in W_ERR_CS register was wrong!") ;
3641 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]) ;
3642 15 mihad
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3643
        ok = 0 ;
3644
    end
3645
 
3646
    if ( ok )
3647
        test_ok ;
3648
 
3649
    // check erroneous address and data
3650
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3651
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3652
    ok = 1 ;
3653
    if ( temp_val1 !== (target_address + 8 + 4) )
3654
    begin
3655
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3656
        $display("Value in W_ERR_ADDR register was wrong!") ;
3657
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3658
        test_fail("Value in WB Erroneous Address register was wrong") ;
3659
        ok = 0 ;
3660
 
3661
    end
3662
 
3663
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3664 106 mihad
    if ( (temp_val1 & 32'hFF_00_FF_00) !== (wmem_data[121] & 32'hFF_00_FF_00) )
3665 15 mihad
    begin
3666
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3667
        $display("Value in W_ERR_DATA register was wrong!") ;
3668 106 mihad
        $display("Expected value = %h, actual value = %h " , wmem_data[121] & 32'hFF_00_FF_00, temp_val1 & 32'hFF_00_FF_00) ;
3669 15 mihad
        test_fail("Value in WB Erroneous Data register was wrong") ;
3670
        ok = 0 ;
3671
    end
3672
 
3673
    if ( ok )
3674
        test_ok ;
3675
 
3676
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3677
    `ifdef HOST
3678
        repeat(4)
3679
            @(posedge wb_clock) ;
3680
        if ( INT_O !== 1 )
3681
        begin
3682
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3683
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3684
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3685
        end
3686
        else
3687
            test_ok ;
3688
    `else
3689
    `ifdef GUEST
3690
        repeat(4)
3691
            @(posedge pci_clock) ;
3692
        if ( INTA !== 0 )
3693
        begin
3694
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3695
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3696
            test_fail("interrupt request was not presented on PCI bus") ;
3697
        end
3698
        else
3699
            test_ok ;
3700
    `endif
3701
    `endif
3702
 
3703
    // read interrupt status register
3704
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3705
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3706
    if ( temp_val1[1] !== 1 )
3707
    begin
3708
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3709
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3710
        test_fail("Expected Interrupt status bit wasn't set") ;
3711
    end
3712
 
3713
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3714
 
3715
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3716
    ok = 1 ;
3717
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3718
    if ( temp_val1[29] !== 0 )
3719
    begin
3720
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3721
        $display("Received Master Abort bit was set with no reason!") ;
3722
        test_fail("Received Master Abort bit was set with no reason") ;
3723
        ok = 0 ;
3724
    end
3725
 
3726
    if ( temp_val1[28] !== 1 )
3727
    begin
3728
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3729
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3730
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3731
        ok = 0 ;
3732
    end
3733
 
3734
    if ( ok )
3735
        test_ok ;
3736
 
3737
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3738
 
3739
    // clear interrupts and errors
3740
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3741
    repeat( 3 )
3742
        @(posedge pci_clock) ;
3743
 
3744
    repeat( 2 )
3745
        @(posedge wb_clock) ;
3746
 
3747
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3748
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3749
    if ( temp_val1[1] !== 0 )
3750
    begin
3751
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3752
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3753
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3754
    end
3755
    else
3756
        test_ok ;
3757
 
3758
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3759
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3760
    if ( temp_val1[8] !== 0 )
3761
    begin
3762
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3763
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3764
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3765
    end
3766
 
3767
 
3768
    $display("Introducing Target Abort error to single read!") ;
3769
    // set read data
3770
    read_data`READ_ADDRESS = target_address + 8 ;
3771
    read_data`READ_SEL     = 4'hF ;
3772
 
3773
    // enable automatic retry handling
3774
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3775
    write_flags`WB_TRANSFER_CAB    = 0 ;
3776
 
3777
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3778
 
3779
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3780
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3781
 
3782
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3783
 
3784
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3785
    begin
3786
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3787
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3788
        $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) ;
3789
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3790
        disable main ;
3791
    end
3792
    else
3793
        test_ok ;
3794
 
3795
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3796
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3797
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3798
    if ( temp_val1[8] !== 0 )
3799
    begin
3800
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3801
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3802
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3803
    end
3804
    else
3805
        test_ok ;
3806
 
3807
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3808
    ok = 1 ;
3809
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3810
    if ( temp_val1[29] !== 0 )
3811
    begin
3812
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3813
        $display("Received Master Abort bit was set with no reason!") ;
3814
        test_fail("Received Master Abort bit was set with no reason") ;
3815
        ok = 0 ;
3816
    end
3817
 
3818
    if ( temp_val1[28] !== 1 )
3819
    begin
3820
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3821
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3822
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3823
        ok = 0 ;
3824
    end
3825
 
3826
    if ( ok )
3827
        test_ok ;
3828
 
3829
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3830
 
3831
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3832
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3833
    if ( temp_val1[1] !== 0 )
3834
    begin
3835
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3836
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3837
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3838
    end
3839
    else
3840
        test_ok ;
3841
 
3842
    $display("Introducing Target Abort error to CAB read!") ;
3843
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3844
 
3845
    for ( i = 0 ; i < 4 ; i = i + 1 )
3846
    begin
3847
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3848
        read_data`READ_SEL     = 4'b1010 ;
3849
        wishbone_master.blk_read_data_in[i] = read_data ;
3850
    end
3851
 
3852
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3853
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3854
    write_flags`WB_TRANSFER_CAB    = 1 ;
3855
 
3856
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3857
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3858
 
3859
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3860
 
3861
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3862
    begin
3863
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3864
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3865
        $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) ;
3866
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3867
        disable main ;
3868
    end
3869
 
3870
    read_status = wishbone_master.blk_read_data_out[0] ;
3871
    temp_val1 = read_status`READ_DATA ;
3872
    temp_val2 = wmem_data[120] ;
3873
 
3874
    // last write to this address was with only two byte enables - check only those
3875
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3876
    begin
3877
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3878
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3879
    end
3880
    else
3881
        test_ok ;
3882
 
3883
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3884
    ok = 1 ;
3885
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3886
    if ( temp_val1[29] !== 0 )
3887
    begin
3888
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3889
        $display("Received Master Abort bit was set with no reason!") ;
3890
        test_fail("Received Master Abort bit was set with no reason") ;
3891
        ok = 0 ;
3892
    end
3893
 
3894
    if ( temp_val1[28] !== 1 )
3895
    begin
3896
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3897
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3898
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3899
        ok = 0 ;
3900
    end
3901
 
3902
    if ( ok )
3903
       test_ok ;
3904
 
3905
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3906
 
3907
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3908
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3909
 
3910
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3911
    for ( i = 0 ; i < 3 ; i = i + 1 )
3912
    begin
3913
        read_data`READ_ADDRESS = target_address + 4*i ;
3914
        read_data`READ_SEL     = 4'b1111 ;
3915
        wishbone_master.blk_read_data_in[i] = read_data ;
3916
    end
3917
 
3918
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3919
 
3920
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3921
 
3922
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3923
    begin
3924
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3925
        $display("Complete burst read through WB slave didn't succeed!") ;
3926
        test_fail("bridge didn't process Burst Read in an expected way") ;
3927
        disable main ;
3928
    end
3929
    else
3930
        test_ok ;
3931
 
3932
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3933
 
3934
    for ( i = 0 ; i < 3 ; i = i + 1 )
3935
    begin
3936
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3937
        read_data`READ_SEL     = 4'b1111 ;
3938
        wishbone_master.blk_read_data_in[i] = read_data ;
3939
    end
3940
 
3941
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3942
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3943
    write_flags`WB_TRANSFER_CAB    = 1 ;
3944
 
3945
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3946
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3947
 
3948
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3949
 
3950
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3951
    begin
3952
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3953
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3954
        $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) ;
3955
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3956
        disable main ;
3957
    end
3958
 
3959
    for ( i = 0 ; i < 3 ; i = i + 1 )
3960
    begin
3961
        ok = 1 ;
3962
        read_status = wishbone_master.blk_read_data_out[i] ;
3963
        temp_val1 = read_status`READ_DATA ;
3964
        temp_val2 = wmem_data[120 + i] ;
3965
 
3966
        // last write to this address was with only two byte enables - check only those
3967
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3968
        begin
3969
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3970
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3971
            ok = 0 ;
3972
        end
3973
    end
3974
 
3975
    if ( ok )
3976
        test_ok ;
3977
 
3978
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3979
    ok = 1 ;
3980
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3981
    if ( temp_val1[29] !== 0 )
3982
    begin
3983
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3984
        $display("Received Master Abort bit was set with no reason!") ;
3985
        test_fail("Received Master Abort bit was set with no reason") ;
3986
        ok = 0 ;
3987
    end
3988
 
3989
    if ( temp_val1[28] !== 1 )
3990
    begin
3991
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3992
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3993
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3994
        ok = 0 ;
3995
    end
3996
 
3997
    if ( ok )
3998
       test_ok ;
3999
 
4000
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4001
 
4002
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
4003
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
4004
 
4005
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
4006
    for ( i = 0 ; i < 3 ; i = i + 1 )
4007
    begin
4008
        read_data`READ_ADDRESS = target_address + 4*i ;
4009
        read_data`READ_SEL     = 4'b1111 ;
4010
        wishbone_master.blk_read_data_in[i] = read_data ;
4011
    end
4012
 
4013
    write_flags`WB_TRANSFER_SIZE   = 3 ;
4014
 
4015
    wishbone_master.wb_block_read( write_flags, read_status ) ;
4016
 
4017
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
4018
    begin
4019
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4020
        $display("Complete burst read through WB slave didn't succeed!") ;
4021
        test_fail("bridge didn't process Burst Read in an expected way") ;
4022
        disable main ;
4023
    end
4024
    else
4025
        test_ok ;
4026
 
4027
    // test error on IO write
4028
    // change base address
4029
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
4030
    write_data`WRITE_SEL     = 4'b0101 ;
4031
    write_data`WRITE_ADDRESS = target_address ;
4032
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
4033
 
4034
    write_flags`WB_TRANSFER_CAB    = 0 ;
4035
    write_flags`WB_TRANSFER_SIZE   = 1 ;
4036
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4037
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
4038
    fork
4039
    begin
4040
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
4041
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4042
        begin
4043
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
4044
            $display("WB slave failed to accept IO write!") ;
4045
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
4046
            disable main ;
4047
        end
4048
    end
4049
    begin
4050
        musnt_respond(ok) ;
4051
        if ( ok !== 1 )
4052
        begin
4053
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
4054
            $display("Testbench is configured wrong!") ;
4055
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
4056
        end
4057
        else
4058
            test_ok ;
4059
    end
4060
    join
4061
 
4062
    // check statuses and everything else
4063
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4064
    ok = 1 ;
4065
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
4066
    if ( temp_val1[8] !== 1 )
4067
    begin
4068
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4069
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
4070
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
4071
        ok = 0 ;
4072
    end
4073
 
4074
    if ( temp_val1[9] !== 1 )
4075
    begin
4076
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4077
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
4078
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
4079
        ok = 0 ;
4080
    end
4081
 
4082
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
4083
    begin
4084
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4085
        $display("Value in W_ERR_CS register was wrong!") ;
4086
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
4087
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
4088
        ok = 0 ;
4089
    end
4090
 
4091
    if ( ok )
4092
        test_ok ;
4093
 
4094
    // check erroneous address and data
4095
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
4096
    ok = 1 ;
4097
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4098
    if ( temp_val1 !== target_address )
4099
    begin
4100
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4101
        $display("Value in W_ERR_ADDR register was wrong!") ;
4102
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
4103
        test_fail("WB Erroneous Address register didn't provide right value") ;
4104
        ok = 0 ;
4105
    end
4106
 
4107
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4108 106 mihad
    if ( (temp_val1 & 32'h00_ff_00_ff) !== 32'h00AA_00AA )
4109 15 mihad
    begin
4110
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4111
        $display("Value in W_ERR_DATA register was wrong!") ;
4112 106 mihad
        $display("Expected value = %h, actual value = %h " , 32'h00AA_00AA, temp_val1 & 32'h00_ff_00_ff) ;
4113 15 mihad
        test_fail("WB Erroneous Data register didn't provide right value") ;
4114
        ok = 0 ;
4115
    end
4116
 
4117
    if ( ok )
4118
        test_ok ;
4119
 
4120
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4121
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
4122
    if ( temp_val1[1] !== 1 )
4123
    begin
4124
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4125
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
4126
        test_fail("expected interrupt status bit was not set") ;
4127
    end
4128
    else
4129
        test_ok ;
4130
 
4131
    // clear interrupts and errors
4132
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
4133
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
4134
 
4135
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4136
    ok = 1 ;
4137
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4138
    if ( temp_val1[29] !== 1 )
4139
    begin
4140
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4141
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
4142
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
4143
        ok = 0 ;
4144
    end
4145
 
4146
    if ( temp_val1[28] !== 0 )
4147
    begin
4148
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4149
        $display("Received Target Abort bit was set for no reason!") ;
4150
        test_fail("Received Target Abort bit was set for no reason") ;
4151
        ok = 0 ;
4152
    end
4153
 
4154
    if ( ok )
4155
        test_ok ;
4156
 
4157
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4158
 
4159
    // disable image
4160
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4161
    if ( ok !== 1 )
4162
    begin
4163
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4164
        test_fail("WB Image Address Mask register couldn't be written") ;
4165
        disable main ;
4166
    end
4167
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
4168
 
4169
end
4170
endtask
4171
 
4172
task parity_checking ;
4173
    reg   [11:0] ctrl_offset ;
4174
    reg   [11:0] ba_offset ;
4175
    reg   [11:0] am_offset ;
4176
    reg   [11:0] ta_offset ;
4177
    reg `WRITE_STIM_TYPE write_data ;
4178
    reg `READ_STIM_TYPE  read_data ;
4179
    reg `READ_RETURN_TYPE read_status ;
4180
 
4181
    reg `WRITE_RETURN_TYPE write_status ;
4182
    reg `WB_TRANSFER_FLAGS write_flags ;
4183
    reg [31:0] temp_val1 ;
4184
    reg [31:0] temp_val2 ;
4185
    reg        ok   ;
4186
    reg [11:0] pci_ctrl_offset ;
4187
    reg [31:0] image_base ;
4188
    reg [31:0] target_address ;
4189
    reg [11:0] icr_offset ;
4190
    reg [11:0] isr_offset ;
4191
    reg [11:0] p_ba_offset ;
4192
    reg [11:0] p_am_offset ;
4193
    reg [11:0] p_ctrl_offset ;
4194
    integer    i ;
4195
    reg        perr_asserted ;
4196
begin:main
4197
    $display("******************************* Testing Parity Checker functions ********************************") ;
4198
    $display("Testing Parity Errors during Master Transactions!") ;
4199
    $display("Introducing Parity Erros to Master Writes!") ;
4200
    $fdisplay(pci_mon_log_file_desc,
4201
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4202
 
4203
    // image 1 is used for error testing, since it is always implemented
4204
    pci_ctrl_offset = 12'h004 ;
4205
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4206
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4207
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4208
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4209
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4210
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4211
 
4212
    // image 1 for PCI target
4213
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4214
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4215
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4216
 
4217
    target_address  = `BEH_TAR1_MEM_START ;
4218
    image_base      = 0 ;
4219
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4220
 
4221
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4222
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4223
    write_flags                    = 0 ;
4224 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
4225
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
4226 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4227
 
4228
    // enable master & target operation and disable parity functions
4229
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4230
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4231
    if ( ok !== 1 )
4232
    begin
4233
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4234
        test_fail("PCI Device Control register could not be written to") ;
4235
        disable main ;
4236
    end
4237
 
4238
    // prepare image control register
4239
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4240
    if ( ok !== 1 )
4241
    begin
4242
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4243
        test_fail("WB Image Control register could not be written to") ;
4244
        disable main ;
4245
    end
4246
 
4247
    // prepare base address register
4248
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4249
    if ( ok !== 1 )
4250
    begin
4251
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4252
        test_fail("WB Image Base Address register could not be written to") ;
4253
        disable main ;
4254
    end
4255
 
4256
    // write address mask register
4257
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4258
    if ( ok !== 1 )
4259
    begin
4260
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4261
        test_fail("WB Image Address Mask register could not be written to") ;
4262
        disable main ;
4263
    end
4264
 
4265
    // disable parity interrupts
4266
    config_write( icr_offset, 0, 4'hF, ok ) ;
4267
    if ( ok !== 1 )
4268
    begin
4269
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4270
        test_fail("Interrupt Control register could not be written to") ;
4271
        disable main ;
4272
    end
4273
 
4274
    write_data`WRITE_ADDRESS = target_address ;
4275
    write_data`WRITE_DATA    = wmem_data[0] ;
4276
    write_data`WRITE_SEL     = 4'b1111 ;
4277
 
4278
    // enable target's 1 response to parity errors
4279 45 mihad
    configuration_cycle_write(0,                        // bus number
4280
                              `TAR1_IDSEL_INDEX - 11,   // device number
4281
                              0,                        // function number
4282
                              1,                        // register number
4283
                              0,                        // type of configuration cycle
4284
                              4'b0001,                  // byte enables
4285
                              32'h0000_0047             // data
4286 15 mihad
                             ) ;
4287
 
4288
    // disable target's 2 response to parity errors
4289 45 mihad
    configuration_cycle_write(0,                        // bus number
4290
                              `TAR2_IDSEL_INDEX - 11,   // device number
4291
                              0,                        // function number
4292
                              1,                        // register number
4293
                              0,                        // type of configuration cycle
4294
                              4'b0001,                  // byte enables
4295
                              32'h0000_0007             // data
4296 15 mihad
                             ) ;
4297
 
4298
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4299
 
4300
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4301
    fork
4302
    begin
4303
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4304
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4305
        begin
4306
            $display("Parity checker testing failed! Time %t ", $time) ;
4307
            $display("Bridge failed to process single memory write!") ;
4308
            test_fail("bridge failed to post single WB memory write") ;
4309
            disable main ;
4310
        end
4311
    end
4312
    begin:wait_perr1
4313
        perr_asserted = 0 ;
4314
        @(posedge pci_clock) ;
4315
 
4316 35 mihad
        while ( PERR !== 0 )
4317 15 mihad
            @(posedge pci_clock) ;
4318
 
4319 35 mihad
        perr_asserted = 1 ;
4320 15 mihad
 
4321
    end
4322
    begin
4323
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4324
 
4325
        if ( ok !== 1 )
4326
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4327
 
4328 35 mihad
        repeat(2)
4329 15 mihad
            @(posedge pci_clock) ;
4330
 
4331 35 mihad
        #1 ;
4332
        if ( !perr_asserted )
4333
            disable wait_perr1 ;
4334 15 mihad
    end
4335
    join
4336
 
4337
    if ( perr_asserted && ok )
4338
    begin
4339
        test_ok ;
4340
    end
4341
    else
4342
    if ( ~perr_asserted )
4343
    begin
4344
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4345
        disable main ;
4346
    end
4347
 
4348
    // check all the statuses - if HOST is defined, wait for them to be synced
4349
    `ifdef HOST
4350
    repeat(4)
4351
        @(posedge wb_clock) ;
4352
    `endif
4353
 
4354
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4355
    ok = 1 ;
4356
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4357 45 mihad
    if ( temp_val1[31] !== 0 )
4358 15 mihad
    begin
4359
        $display("Parity checker testing failed! Time %t ", $time) ;
4360 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4361
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4362 15 mihad
        ok = 0 ;
4363
    end
4364
 
4365
    if ( temp_val1[30] !== 0 )
4366
    begin
4367
        $display("Parity checker testing failed! Time %t ", $time) ;
4368
        $display("Signalled System Error bit was set for no reason!") ;
4369
        test_fail("Signalled System Error bit was set for no reason") ;
4370
        ok = 0 ;
4371
    end
4372
 
4373
    if ( temp_val1[24] !== 0 )
4374
    begin
4375
        $display("Parity checker testing failed! Time %t ", $time) ;
4376
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4377
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4378
        ok = 0 ;
4379
    end
4380
 
4381
    if ( ok )
4382
        test_ok ;
4383
 
4384
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4385
    // clear parity bits and enable parity response
4386
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4387
    if ( ok !== 1 )
4388
    begin
4389
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4390
        test_fail("write to PCI Status Register failed") ;
4391
        disable main ;
4392
    end
4393
 
4394
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4395
    fork
4396
    begin
4397
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4398
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4399
        begin
4400
            $display("Parity checker testing failed! Time %t ", $time) ;
4401
            $display("Bridge failed to process single memory write!") ;
4402
            test_fail("bridge failed to post single memory write") ;
4403
            disable main ;
4404
        end
4405
    end
4406
    begin:wait_perr2
4407
        perr_asserted = 0 ;
4408
        @(posedge pci_clock) ;
4409
 
4410 35 mihad
        while ( PERR !== 0 )
4411 15 mihad
            @(posedge pci_clock) ;
4412
 
4413 35 mihad
        perr_asserted = 1 ;
4414 15 mihad
 
4415
    end
4416
    begin
4417
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4418
 
4419
        if ( ok !== 1 )
4420
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4421
 
4422 35 mihad
        repeat(2)
4423 15 mihad
            @(posedge pci_clock) ;
4424
 
4425 35 mihad
        #1 ;
4426
        if (!perr_asserted)
4427
            disable wait_perr2 ;
4428 15 mihad
    end
4429
    join
4430
 
4431
    if ( perr_asserted && ok )
4432
    begin
4433
        test_ok ;
4434
    end
4435
    else
4436
    if ( ~perr_asserted )
4437
    begin
4438
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4439
        disable main ;
4440
    end
4441
 
4442
    // check all the statuses - if HOST is defined, wait for them to be synced
4443
    `ifdef HOST
4444
    repeat(4)
4445
        @(posedge wb_clock) ;
4446
    `endif
4447
 
4448
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4449
    ok = 1 ;
4450
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4451 45 mihad
    if ( temp_val1[31] !== 0 )
4452 15 mihad
    begin
4453
        $display("Parity checker testing failed! Time %t ", $time) ;
4454 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4455
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4456 15 mihad
        ok = 0 ;
4457
    end
4458
 
4459
    if ( temp_val1[30] !== 0 )
4460
    begin
4461
        $display("Parity checker testing failed! Time %t ", $time) ;
4462
        $display("Signalled System Error bit was set for no reason!") ;
4463
        test_fail("Signalled System Error bit was set for no reason") ;
4464
        ok = 0 ;
4465
    end
4466
 
4467
    if ( temp_val1[24] !== 1 )
4468
    begin
4469
        $display("Parity checker testing failed! Time %t ", $time) ;
4470 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!") ;
4471
        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") ;
4472 15 mihad
        ok = 0 ;
4473
    end
4474
 
4475
    if ( ok )
4476
        test_ok ;
4477
 
4478
    // clear status bits and disable parity error response
4479
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4480
 
4481
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4482
 
4483
    // disable perr generation and perform a write - no bits should be set
4484
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4485
    fork
4486
    begin
4487
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4488
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4489
        begin
4490
            $display("Parity checker testing failed! Time %t ", $time) ;
4491
            $display("Bridge failed to process single memory write!") ;
4492
            test_fail("bridge failed to post single memory write") ;
4493
            disable main ;
4494
        end
4495
    end
4496
    begin
4497
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4498
 
4499
        if ( ok !== 1 )
4500
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4501
        else
4502
            test_ok ;
4503
 
4504
        repeat(3)
4505
            @(posedge pci_clock) ;
4506
    end
4507
    join
4508
 
4509
    `ifdef HOST
4510
    repeat(4)
4511
        @(posedge wb_clock) ;
4512
    `endif
4513
 
4514
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4515
    ok = 1 ;
4516
 
4517
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4518
    if ( temp_val1[31] !== 0 )
4519
    begin
4520
        $display("Parity checker testing failed! Time %t ", $time) ;
4521
        $display("Detected Parity Error bit was set for no reason!") ;
4522
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4523
        ok = 0 ;
4524
    end
4525
 
4526
    if ( temp_val1[30] !== 0 )
4527
    begin
4528
        $display("Parity checker testing failed! Time %t ", $time) ;
4529
        $display("Signalled System Error bit was set for no reason!") ;
4530
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4531
        ok = 0 ;
4532
    end
4533
 
4534
    if ( temp_val1[24] !== 0 )
4535
    begin
4536
        $display("Parity checker testing failed! Time %t ", $time) ;
4537
        $display("Master Data Parity Error bit was set for no reason!") ;
4538
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4539
        ok = 0 ;
4540
    end
4541
 
4542
    if ( ok )
4543
        test_ok ;
4544
 
4545
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4546
 
4547
    read_data = 0 ;
4548
    read_data`READ_ADDRESS  = target_address ;
4549
    read_data`READ_SEL      = 4'hF ;
4550
 
4551
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4552
 
4553
    // enable parity and system error interrupts
4554
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4555
 
4556
    // enable parity error response
4557
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4558
 
4559
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4560
 
4561
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4562
    fork
4563
    begin
4564
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4565
    end
4566
    begin:wait_perr4
4567
        perr_asserted = 0 ;
4568
        @(posedge pci_clock) ;
4569 35 mihad
        while ( PERR !== 0 )
4570 15 mihad
            @(posedge pci_clock) ;
4571
 
4572 35 mihad
        perr_asserted = 1 ;
4573 15 mihad
 
4574
    end
4575
    begin
4576
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4577
 
4578
        if ( ok !== 1 )
4579
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4580
 
4581
        repeat(2)
4582
            @(posedge pci_clock) ;
4583
 
4584 35 mihad
        #1 ;
4585
        if ( !perr_asserted )
4586
            disable wait_perr4 ;
4587 15 mihad
    end
4588
    join
4589
 
4590
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4591
    begin
4592
        $display("Parity checker testing failed! Time %t ", $time) ;
4593
        $display("Bridge failed to process single memory read!") ;
4594
        test_fail("bridge didn't process single memory read correctly") ;
4595
        ok = 0 ;
4596
    end
4597
 
4598
    if ( perr_asserted && ok )
4599
    begin
4600
        test_ok ;
4601
    end
4602
    else
4603
    if ( ~perr_asserted )
4604
    begin
4605
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4606
        disable main ;
4607
    end
4608
 
4609
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4610
    // interrupt should also be present
4611
    `ifdef HOST
4612
        repeat(4)
4613 26 mihad
            @(posedge pci_clock) ;
4614
        repeat(4)
4615 15 mihad
            @(posedge wb_clock) ;
4616
 
4617
        if ( INT_O !== 1 )
4618
        begin
4619
            $display("Parity checker testing failed! Time %t ", $time) ;
4620
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4621
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4622
        end
4623
        else
4624
            test_ok ;
4625
    `else
4626
    `ifdef GUEST
4627 26 mihad
        repeat(4)
4628
            @(posedge wb_clock) ;
4629
        repeat(4)
4630 15 mihad
            @(posedge pci_clock) ;
4631
 
4632
        if ( INTA !== 1 )
4633
        begin
4634
            $display("Parity checker testing failed! Time %t ", $time) ;
4635
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4636
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4637
        end
4638
        else
4639
            test_ok ;
4640
    `endif
4641
    `endif
4642
 
4643
    // check statuses!
4644
 
4645
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4646
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4647
    ok = 1 ;
4648
 
4649
    if ( temp_val1[31] !== 1 )
4650
    begin
4651
        $display("Parity checker testing failed! Time %t ", $time) ;
4652 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4653
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4654 15 mihad
        ok = 0 ;
4655
    end
4656
 
4657
    if ( temp_val1[30] !== 0 )
4658
    begin
4659
        $display("Parity checker testing failed! Time %t ", $time) ;
4660
        $display("Signalled System Error bit was set for no reason!") ;
4661
        test_fail("Signalled System Error bit was set for no reason") ;
4662
        ok = 0 ;
4663
    end
4664
 
4665
    if ( temp_val1[24] !== 1 )
4666
    begin
4667
        $display("Parity checker testing failed! Time %t ", $time) ;
4668 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4669
        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") ;
4670 15 mihad
        ok = 0 ;
4671
    end
4672
 
4673
    if ( ok )
4674
        test_ok ;
4675
 
4676
    // clear statuses and disable parity error response
4677
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4678
 
4679
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4680
    ok = 1 ;
4681
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4682
 
4683
    if ( temp_val1[4] !== 0 )
4684
    begin
4685
        $display("Parity checker testing failed! Time %t ", $time) ;
4686
        $display("System error interrupt status bit set for no reason!") ;
4687
        test_fail("System error interrupt status bit set for no reason") ;
4688
        ok = 0 ;
4689
    end
4690
 
4691
    `ifdef HOST
4692
    if ( temp_val1[3] !== 1 )
4693
    begin
4694
        $display("Parity checker testing failed! Time %t ", $time) ;
4695
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4696
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4697
        ok = 0 ;
4698
    end
4699
    `else
4700
    if ( temp_val1[3] !== 0 )
4701
    begin
4702
        $display("Parity checker testing failed! Time %t ", $time) ;
4703
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4704
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4705
        ok = 0 ;
4706
    end
4707
    `endif
4708
 
4709
    if ( ok )
4710
        test_ok ;
4711
 
4712
    // clear int statuses
4713
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4714
 
4715
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4716
 
4717
    `ifdef HOST
4718
        repeat(4)
4719 26 mihad
            @(posedge pci_clock) ;
4720
        repeat(4)
4721 15 mihad
            @(posedge wb_clock) ;
4722
 
4723
        if ( INT_O !== 0 )
4724
        begin
4725
            $display("Parity checker testing failed! Time %t ", $time) ;
4726
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4727
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4728
        end
4729
        else
4730
            test_ok ;
4731
    `else
4732
    `ifdef GUEST
4733 26 mihad
        repeat(4)
4734
            @(posedge wb_clock) ;
4735
        repeat(4)
4736 15 mihad
            @(posedge pci_clock) ;
4737
 
4738
        if ( INTA !== 1 )
4739
        begin
4740
            $display("Parity checker testing failed! Time %t ", $time) ;
4741
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4742
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4743
        end
4744
        else
4745
            test_ok ;
4746
    `endif
4747
    `endif
4748
 
4749
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4750
 
4751
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4752
    fork
4753
    begin
4754
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4755
    end
4756
    begin:wait_perr5
4757
        perr_asserted = 0 ;
4758
        @(posedge pci_clock) ;
4759
        while ( PERR === 1 )
4760
            @(posedge pci_clock) ;
4761
 
4762
        perr_asserted = 1 ;
4763
        $display("Parity checker testing failed! Time %t ", $time) ;
4764 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4765
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4766 15 mihad
    end
4767
    begin
4768
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4769
        if ( ok !== 1 )
4770
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4771
 
4772
        // perr can be asserted on idle or next PCI address phase
4773
        repeat(2)
4774
            @(posedge pci_clock) ;
4775
 
4776 35 mihad
        #1 ;
4777
        if ( !perr_asserted )
4778
            disable wait_perr5 ;
4779 15 mihad
    end
4780
    join
4781
 
4782
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4783
    begin
4784
        $display("Parity checker testing failed! Time %t ", $time) ;
4785
        $display("Bridge failed to process single memory read!") ;
4786
        test_fail("bridge failed to process single memory read correctly") ;
4787
        ok = 0 ;
4788
    end
4789
 
4790
    if ( ok && !perr_asserted)
4791
        test_ok ;
4792
 
4793
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4794
 
4795
    // interrupts should not be present
4796
    `ifdef HOST
4797
        repeat( 4 )
4798 26 mihad
            @(posedge pci_clock) ;
4799
        repeat( 4 )
4800 15 mihad
            @(posedge wb_clock) ;
4801
        if ( INT_O !== 0 )
4802
        begin
4803
            $display("Parity checker testing failed! Time %t ", $time) ;
4804
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4805
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4806
        end
4807
        else
4808
            test_ok ;
4809
    `else
4810
    `ifdef GUEST
4811
        repeat( 4 )
4812 26 mihad
            @(posedge wb_clock) ;
4813
        repeat( 4 )
4814 15 mihad
            @(posedge pci_clock) ;
4815
        if ( INTA !== 1 )
4816
        begin
4817
            $display("Parity checker testing failed! Time %t ", $time) ;
4818
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4819
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4820
        end
4821
        else
4822
            test_ok ;
4823
    `endif
4824
    `endif
4825
 
4826
    // check statuses!
4827
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4828
    ok = 1 ;
4829
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4830
    if ( temp_val1[31] !== 1 )
4831
    begin
4832
        $display("Parity checker testing failed! Time %t ", $time) ;
4833 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4834 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4835
        ok = 0 ;
4836
    end
4837
 
4838
    if ( temp_val1[30] !== 0 )
4839
    begin
4840
        $display("Parity checker testing failed! Time %t ", $time) ;
4841
        $display("Signalled System Error bit was set for no reason!") ;
4842
        test_fail("Signalled System Error bit was set for no reason") ;
4843
        ok = 0 ;
4844
    end
4845
 
4846
    if ( temp_val1[24] !== 0 )
4847
    begin
4848
        $display("Parity checker testing failed! Time %t ", $time) ;
4849 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4850 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4851
        ok = 0 ;
4852
    end
4853
 
4854
    if ( ok )
4855
        test_ok ;
4856
 
4857
    // clear statuses
4858
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4859
 
4860
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4861
    ok = 1 ;
4862
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4863
 
4864
    if ( temp_val1[4] !== 0 )
4865
    begin
4866
        $display("Parity checker testing failed! Time %t ", $time) ;
4867
        $display("System error interrupt status bit set for no reason!") ;
4868
        test_fail("System error interrupt status bit set for no reason") ;
4869
        ok = 0 ;
4870
    end
4871
 
4872
    if ( temp_val1[3] !== 0 )
4873
    begin
4874
        $display("Parity checker testing failed! Time %t ", $time) ;
4875
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4876
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4877
        ok = 0 ;
4878
    end
4879
 
4880
    if ( ok )
4881
        test_ok ;
4882
 
4883
    // enable all responses to parity errors!
4884
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4885
 
4886
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4887
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4888
 
4889
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4890
 
4891
    // repeat a read
4892
    fork
4893
    begin
4894
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4895
    end
4896
    begin:wait_perr6
4897
        perr_asserted = 0 ;
4898
        @(posedge pci_clock) ;
4899
        while ( PERR === 1 )
4900
            @(posedge pci_clock) ;
4901
 
4902
        perr_asserted = 1 ;
4903
        $display("Parity checker testing failed! Time %t ", $time) ;
4904
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4905
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4906
    end
4907
    begin
4908
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4909
        if ( ok !== 1 )
4910
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4911
 
4912
        repeat(2)
4913
            @(posedge pci_clock) ;
4914
 
4915 35 mihad
        #1 ;
4916
        if ( !perr_asserted )
4917
            disable wait_perr6 ;
4918 15 mihad
    end
4919
    join
4920
 
4921
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4922
    begin
4923
        $display("Parity checker testing failed! Time %t ", $time) ;
4924
        $display("Bridge failed to process single memory read!") ;
4925
        test_fail("bridge didn't process single memory read as expected") ;
4926
        ok = 0 ;
4927
    end
4928
 
4929
    if ( ok && !perr_asserted)
4930
        test_ok ;
4931
 
4932
    // check statuses!
4933
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4934
    ok = 1 ;
4935
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4936
    if ( temp_val1[31] !== 0 )
4937
    begin
4938
        $display("Parity checker testing failed! Time %t ", $time) ;
4939
        $display("Detected Parity Error bit was set for no reason!") ;
4940
        test_fail("Detected Parity Error bit was set for no reason") ;
4941
        ok = 0 ;
4942
    end
4943
 
4944
    if ( temp_val1[30] !== 0 )
4945
    begin
4946
        $display("Parity checker testing failed! Time %t ", $time) ;
4947
        $display("Signalled System Error bit was set for no reason!") ;
4948
        test_fail("Signalled System Error bit was set for no reason") ;
4949
        ok = 0 ;
4950
    end
4951
 
4952
    if ( temp_val1[24] !== 0 )
4953
    begin
4954
        $display("Parity checker testing failed! Time %t ", $time) ;
4955
        $display("Master Data Parity Error bit was set for no reason!") ;
4956
        test_fail("Master Data Parity Error bit was set for no reason") ;
4957
        ok = 0 ;
4958
    end
4959
 
4960
    if ( ok )
4961
        test_ok ;
4962
 
4963
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4964
    ok = 1 ;
4965
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4966
 
4967
    if ( temp_val1[4] !== 0 )
4968
    begin
4969
        $display("Parity checker testing failed! Time %t ", $time) ;
4970
        $display("System error interrupt status bit set for no reason!") ;
4971
        test_fail("System error interrupt status bit set for no reason") ;
4972
        ok = 0 ;
4973
    end
4974
 
4975
    if ( temp_val1[3] !== 0 )
4976
    begin
4977
        $display("Parity checker testing failed! Time %t ", $time) ;
4978
        $display("Parity error interrupt status bit set for no reason!") ;
4979
        test_fail("Parity error interrupt status bit set for no reason") ;
4980
        ok = 0 ;
4981
    end
4982
 
4983
    if ( ok )
4984
        test_ok ;
4985
 
4986
    $display("Presenting address parity error on PCI bus!") ;
4987
    // enable parity errors - this should not affect system errors
4988
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4989
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4990
 
4991
    // perform PCI write
4992
    // check transaction progress
4993
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4994
    fork
4995
    begin
4996
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4997
               target_address, 32'h1234_5678,
4998
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4999
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5000
        do_pause( 1 ) ;
5001
    end
5002
    begin:wait_serr7
5003
        perr_asserted = 0 ;
5004
        @(posedge pci_clock) ;
5005
        while( SERR === 1 )
5006
            @(posedge pci_clock) ;
5007
 
5008
        perr_asserted = 1 ;
5009
        $display("Parity checker testing failed! Time %t ", $time) ;
5010
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5011
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5012
    end
5013
    begin
5014
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5015
        if ( ok !== 1 )
5016
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
5017
 
5018 35 mihad
        if ( !perr_asserted )
5019
            disable wait_serr7 ;
5020 15 mihad
    end
5021
    join
5022
 
5023
    if ( ok && !perr_asserted)
5024
        test_ok ;
5025
 
5026
    // check statuses!
5027
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5028
    ok = 1 ;
5029
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5030
    if ( temp_val1[31] !== 1 )
5031
    begin
5032
        $display("Parity checker testing failed! Time %t ", $time) ;
5033
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5034
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5035
        ok = 0 ;
5036
    end
5037
 
5038
    if ( temp_val1[30] !== 0 )
5039
    begin
5040
        $display("Parity checker testing failed! Time %t ", $time) ;
5041
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5042
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5043
        ok = 0 ;
5044
    end
5045
 
5046
    if ( temp_val1[24] !== 0 )
5047
    begin
5048
        $display("Parity checker testing failed! Time %t ", $time) ;
5049
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5050
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5051
        ok = 0 ;
5052
    end
5053
 
5054
    if ( ok )
5055
        test_ok ;
5056
 
5057
    // clear statuses
5058
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5059
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5060
    fork
5061
    begin
5062 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5063 15 mihad
        (
5064
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5065
            32'h5555_5555,      // second part of address in dual address cycle
5066
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5067
            `BC_MEM_WRITE,      // normal command
5068 92 mihad
            4'hF,               // byte enables
5069 15 mihad
            32'h1234_5678,      // data
5070
            1'b1,               // make address parity error on first phase of dual address
5071
            1'b0,               // make address parity error on second phase of dual address
5072
            ok                  // result of operation
5073
        ) ;
5074 35 mihad
        if ( !perr_asserted )
5075
            disable wait_serr8 ;
5076 15 mihad
    end
5077
    begin:wait_serr8
5078
        perr_asserted = 0 ;
5079
        @(posedge pci_clock) ;
5080
        while( SERR === 1 )
5081
            @(posedge pci_clock) ;
5082
 
5083
        perr_asserted = 1 ;
5084
        $display("Parity checker testing failed! Time %t ", $time) ;
5085
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5086
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5087
    end
5088
    join
5089
 
5090
    if ( ok && !perr_asserted)
5091
        test_ok ;
5092
 
5093
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5094
    fork
5095
    begin
5096 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5097 15 mihad
        (
5098
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5099
            32'h5555_5555,      // second part of address in dual address cycle
5100
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5101
            `BC_MEM_WRITE,      // normal command
5102 92 mihad
            4'hF,               // byte enables
5103 15 mihad
            32'h1234_5678,      // data
5104
            1'b0,               // make address parity error on first phase of dual address
5105
            1'b1,               // make address parity error on second phase of dual address
5106
            ok                  // result of operation
5107
        ) ;
5108 35 mihad
        if ( !perr_asserted )
5109
            disable wait_serr9 ;
5110 15 mihad
    end
5111
    begin:wait_serr9
5112
        perr_asserted = 0 ;
5113
        @(posedge pci_clock) ;
5114
        while( SERR === 1 )
5115
            @(posedge pci_clock) ;
5116
 
5117
        perr_asserted = 1 ;
5118
        $display("Parity checker testing failed! Time %t ", $time) ;
5119
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5120
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5121
    end
5122
    join
5123
 
5124
    if ( ok && !perr_asserted)
5125
        test_ok ;
5126
 
5127
    // check statuses!
5128
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5129
    ok = 1 ;
5130
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5131
    if ( temp_val1[31] !== 1 )
5132
    begin
5133
        $display("Parity checker testing failed! Time %t ", $time) ;
5134
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5135
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5136
        ok = 0 ;
5137
    end
5138
 
5139
    if ( temp_val1[30] !== 0 )
5140
    begin
5141
        $display("Parity checker testing failed! Time %t ", $time) ;
5142
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5143
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5144
        ok = 0 ;
5145
    end
5146
 
5147
    if ( temp_val1[24] !== 0 )
5148
    begin
5149
        $display("Parity checker testing failed! Time %t ", $time) ;
5150
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5151
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5152
        ok = 0 ;
5153
    end
5154
 
5155
    if ( ok )
5156
        test_ok ;
5157
 
5158
    // clear statuses
5159
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5160
 
5161
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5162
    fork
5163
    begin
5164 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5165 15 mihad
        (
5166
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5167
            32'h5555_5555,      // second part of address in dual address cycle
5168
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5169
            `BC_MEM_WRITE,      // normal command
5170 92 mihad
            4'hF,               // byte enables
5171 15 mihad
            32'h1234_5678,      // data
5172
            1'b1,               // make address parity error on first phase of dual address
5173
            1'b1,               // make address parity error on second phase of dual address
5174
            ok                  // result of operation
5175
        ) ;
5176 35 mihad
        if ( !perr_asserted )
5177
            disable wait_serr10 ;
5178 15 mihad
    end
5179
    begin:wait_serr10
5180
        perr_asserted = 0 ;
5181
        @(posedge pci_clock) ;
5182
        while( SERR === 1 )
5183
            @(posedge pci_clock) ;
5184
 
5185
        perr_asserted = 1 ;
5186
        $display("Parity checker testing failed! Time %t ", $time) ;
5187
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5188
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5189
    end
5190
    join
5191
 
5192
    if ( ok && !perr_asserted)
5193
        test_ok ;
5194
 
5195
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5196
 
5197
    `ifdef HOST
5198
        repeat(4)
5199 26 mihad
            @(posedge pci_clock) ;
5200
        repeat(4)
5201 15 mihad
            @(posedge wb_clock) ;
5202
        if ( INT_O !== 0 )
5203
        begin
5204
            $display("Parity checker testing failed! Time %t ", $time) ;
5205
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5206
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5207
        end
5208
        else
5209
            test_ok ;
5210
    `else
5211
    `ifdef GUEST
5212 26 mihad
        repeat(4)
5213
            @(posedge wb_clock) ;
5214
        repeat(4)
5215 15 mihad
            @(posedge pci_clock) ;
5216
 
5217
        if ( INTA !== 1 )
5218
        begin
5219
            $display("Parity checker testing failed! Time %t ", $time) ;
5220
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5221
            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") ;
5222
        end
5223
        else
5224
            test_ok ;
5225
    `endif
5226
    `endif
5227
 
5228
    // check statuses!
5229
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5230
    ok = 1 ;
5231
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5232
    if ( temp_val1[31] !== 1 )
5233
    begin
5234
        $display("Parity checker testing failed! Time %t ", $time) ;
5235
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5236
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5237
        ok = 0 ;
5238
    end
5239
 
5240
    if ( temp_val1[30] !== 0 )
5241
    begin
5242
        $display("Parity checker testing failed! Time %t ", $time) ;
5243
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5244
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5245
        ok = 0 ;
5246
    end
5247
 
5248
    if ( temp_val1[24] !== 0 )
5249
    begin
5250
        $display("Parity checker testing failed! Time %t ", $time) ;
5251
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5252
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5253
        ok = 0 ;
5254
    end
5255
 
5256
    if ( ok )
5257
        test_ok ;
5258
 
5259
    // clear statuses
5260
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5261
 
5262
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5263
    ok = 1 ;
5264
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5265
 
5266
    if ( temp_val1[4] !== 0 )
5267
    begin
5268
        $display("Parity checker testing failed! Time %t ", $time) ;
5269
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5270
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5271
        ok = 0 ;
5272
    end
5273
 
5274
    if ( temp_val1[3] !== 0 )
5275
    begin
5276
        $display("Parity checker testing failed! Time %t ", $time) ;
5277
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5278
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5279
        ok = 0 ;
5280
    end
5281
 
5282
    if ( ok )
5283
        test_ok ;
5284
 
5285
    // now enable system error signaling and test response
5286
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5287
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5288
 
5289
    fork
5290
    begin
5291
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5292
               target_address, 32'h1234_5678,
5293
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5294
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5295
        do_pause( 1 ) ;
5296
    end
5297
    begin:wait_serr11
5298
        perr_asserted = 0 ;
5299
        @(posedge pci_clock) ;
5300 35 mihad
        while( SERR !== 0 )
5301 15 mihad
            @(posedge pci_clock) ;
5302
 
5303 35 mihad
        perr_asserted = 1 ;
5304 15 mihad
    end
5305
    begin
5306
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5307
        if ( ok !== 1 )
5308
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5309
 
5310
        @(posedge pci_clock) ;
5311 35 mihad
        #1 ;
5312
        if ( !perr_asserted )
5313
            disable wait_serr11 ;
5314 15 mihad
    end
5315
    join
5316
 
5317
    if ( ok && perr_asserted)
5318
        test_ok ;
5319
    else
5320
    if ( !perr_asserted )
5321
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5322
 
5323
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5324
 
5325
    `ifdef HOST
5326
        repeat(4)
5327 26 mihad
            @(posedge pci_clock) ;
5328
        repeat(4)
5329 15 mihad
            @(posedge wb_clock) ;
5330
        if ( INT_O !== 1 )
5331
        begin
5332
            $display("Parity checker testing failed! Time %t ", $time) ;
5333
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5334
            test_fail("Interrupt Request was not triggered as expected") ;
5335
        end
5336
        else
5337
            test_ok ;
5338
    `else
5339
    `ifdef GUEST
5340 26 mihad
        repeat(4)
5341
            @(posedge wb_clock) ;
5342
        repeat(4)
5343 15 mihad
            @(posedge pci_clock) ;
5344
 
5345
        if ( INTA !== 1 )
5346
        begin
5347
            $display("Parity checker testing failed! Time %t ", $time) ;
5348
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5349
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5350
        end
5351
        else
5352
            test_ok ;
5353
    `endif
5354
    `endif
5355
 
5356
    // check statuses!
5357
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5358
    ok = 1 ;
5359
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5360
    if ( temp_val1[31] !== 1 )
5361
    begin
5362
        $display("Parity checker testing failed! Time %t ", $time) ;
5363
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5364
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5365
        ok = 0 ;
5366
    end
5367
 
5368
    if ( temp_val1[30] !== 1 )
5369
    begin
5370
        $display("Parity checker testing failed! Time %t ", $time) ;
5371
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5372
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5373
        ok = 0 ;
5374
    end
5375
 
5376
    if ( temp_val1[24] !== 0 )
5377
    begin
5378
        $display("Parity checker testing failed! Time %t ", $time) ;
5379
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5380
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5381
        ok = 0 ;
5382
    end
5383
 
5384
    if ( ok )
5385
        test_ok ;
5386
 
5387
    // clear statuses
5388
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5389
 
5390
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5391
 
5392
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5393
    ok = 1 ;
5394
 
5395
    `ifdef HOST
5396
    if ( temp_val1[4] !== 1 )
5397
    begin
5398
        $display("Parity checker testing failed! Time %t ", $time) ;
5399
        $display("System error interrupt status bit not set when expected!") ;
5400
        test_fail("System error interrupt status bit not set when expected") ;
5401
        ok = 0 ;
5402
    end
5403
    `else
5404
    if ( temp_val1[4] !== 0 )
5405
    begin
5406
        $display("Parity checker testing failed! Time %t ", $time) ;
5407
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5408
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5409
        ok = 0 ;
5410
    end
5411
    `endif
5412
 
5413
    if ( temp_val1[3] !== 0 )
5414
    begin
5415
        $display("Parity checker testing failed! Time %t ", $time) ;
5416
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5417
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5418
        ok = 0 ;
5419
    end
5420
 
5421
    if ( ok )
5422
        test_ok ;
5423
 
5424
    // clear statuses
5425
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5426
 
5427
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5428
    fork
5429
    begin
5430 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5431 15 mihad
        (
5432
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5433
            32'h5555_5555,      // second part of address in dual address cycle
5434
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5435
            `BC_MEM_WRITE,      // normal command
5436 92 mihad
            4'hF,               // byte enables
5437 15 mihad
            32'h1234_5678,      // data
5438
            1'b1,               // make address parity error on first phase of dual address
5439
            1'b0,               // make address parity error on second phase of dual address
5440
            ok                  // result of operation
5441
        ) ;
5442 35 mihad
        if ( !perr_asserted )
5443
            disable wait_serr14 ;
5444 15 mihad
    end
5445
    begin:wait_serr14
5446
        perr_asserted = 0 ;
5447
        @(posedge pci_clock) ;
5448 35 mihad
        while( SERR !== 0 )
5449 15 mihad
            @(posedge pci_clock) ;
5450
 
5451 35 mihad
        perr_asserted = 1 ;
5452 15 mihad
    end
5453
    join
5454
 
5455
    if ( ok && perr_asserted)
5456
        test_ok ;
5457
    else
5458
    if ( !perr_asserted )
5459
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5460
 
5461
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5462
 
5463
    `ifdef HOST
5464
        repeat(4)
5465 26 mihad
            @(posedge pci_clock) ;
5466
        repeat(4)
5467 15 mihad
            @(posedge wb_clock) ;
5468
        if ( INT_O !== 1 )
5469
        begin
5470
            $display("Parity checker testing failed! Time %t ", $time) ;
5471
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5472
            test_fail("Interrupt Request was not triggered as expected") ;
5473
        end
5474
        else
5475
            test_ok ;
5476
    `else
5477
    `ifdef GUEST
5478 26 mihad
        repeat(4)
5479
            @(posedge wb_clock) ;
5480
        repeat(4)
5481 15 mihad
            @(posedge pci_clock) ;
5482
 
5483
        if ( INTA !== 1 )
5484
        begin
5485
            $display("Parity checker testing failed! Time %t ", $time) ;
5486
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5487
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5488
        end
5489
        else
5490
            test_ok ;
5491
    `endif
5492
    `endif
5493
 
5494
    // check statuses!
5495
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5496
    ok = 1 ;
5497
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5498
    if ( temp_val1[31] !== 1 )
5499
    begin
5500
        $display("Parity checker testing failed! Time %t ", $time) ;
5501
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5502
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5503
        ok = 0 ;
5504
    end
5505
 
5506
    if ( temp_val1[30] !== 1 )
5507
    begin
5508
        $display("Parity checker testing failed! Time %t ", $time) ;
5509
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5510
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5511
        ok = 0 ;
5512
    end
5513
 
5514
    if ( temp_val1[24] !== 0 )
5515
    begin
5516
        $display("Parity checker testing failed! Time %t ", $time) ;
5517
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5518
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5519
        ok = 0 ;
5520
    end
5521
 
5522
    if ( ok )
5523
        test_ok ;
5524
 
5525
    // clear statuses
5526
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5527
 
5528
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5529
 
5530
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5531
    ok = 1 ;
5532
 
5533
    `ifdef HOST
5534
    if ( temp_val1[4] !== 1 )
5535
    begin
5536
        $display("Parity checker testing failed! Time %t ", $time) ;
5537
        $display("System error interrupt status bit not set when expected!") ;
5538
        test_fail("System error interrupt status bit not set when expected") ;
5539
        ok = 0 ;
5540
    end
5541
    `else
5542
    if ( temp_val1[4] !== 0 )
5543
    begin
5544
        $display("Parity checker testing failed! Time %t ", $time) ;
5545
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5546
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5547
        ok = 0 ;
5548
    end
5549
    `endif
5550
 
5551
    if ( temp_val1[3] !== 0 )
5552
    begin
5553
        $display("Parity checker testing failed! Time %t ", $time) ;
5554
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5555
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5556
        ok = 0 ;
5557
    end
5558
 
5559
    if ( ok )
5560
        test_ok ;
5561
 
5562
    // clear statuses
5563
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5564
 
5565
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5566
    fork
5567
    begin
5568 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5569 15 mihad
        (
5570
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5571
            32'h5555_5555,      // second part of address in dual address cycle
5572
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5573
            `BC_MEM_WRITE,      // normal command
5574 92 mihad
            4'hF,               // byte enables
5575 15 mihad
            32'h1234_5678,      // data
5576
            1'b0,               // make address parity error on first phase of dual address
5577
            1'b1,               // make address parity error on second phase of dual address
5578
            ok                  // result of operation
5579
        ) ;
5580 35 mihad
        if ( !perr_asserted )
5581
            disable wait_serr15 ;
5582 15 mihad
    end
5583
    begin:wait_serr15
5584
        perr_asserted = 0 ;
5585
        @(posedge pci_clock) ;
5586 35 mihad
        while( SERR !== 0 )
5587 15 mihad
            @(posedge pci_clock) ;
5588
 
5589 35 mihad
        perr_asserted = 1 ;
5590 15 mihad
    end
5591
    join
5592
 
5593
    if ( ok && perr_asserted)
5594
        test_ok ;
5595
    else
5596
    if ( !perr_asserted )
5597
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5598
 
5599
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5600
 
5601
    `ifdef HOST
5602
        repeat(4)
5603 26 mihad
            @(posedge pci_clock) ;
5604
        repeat(4)
5605 15 mihad
            @(posedge wb_clock) ;
5606
        if ( INT_O !== 1 )
5607
        begin
5608
            $display("Parity checker testing failed! Time %t ", $time) ;
5609
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5610
            test_fail("Interrupt Request was not triggered as expected") ;
5611
        end
5612
        else
5613
            test_ok ;
5614
    `else
5615
    `ifdef GUEST
5616 26 mihad
        repeat(4)
5617
            @(posedge wb_clock) ;
5618
        repeat(4)
5619 15 mihad
            @(posedge pci_clock) ;
5620
 
5621
        if ( INTA !== 1 )
5622
        begin
5623
            $display("Parity checker testing failed! Time %t ", $time) ;
5624
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5625
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5626
        end
5627
        else
5628
            test_ok ;
5629
    `endif
5630
    `endif
5631
 
5632
    // check statuses!
5633
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5634
    ok = 1 ;
5635
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5636
    if ( temp_val1[31] !== 1 )
5637
    begin
5638
        $display("Parity checker testing failed! Time %t ", $time) ;
5639
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5640
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5641
        ok = 0 ;
5642
    end
5643
 
5644
    if ( temp_val1[30] !== 1 )
5645
    begin
5646
        $display("Parity checker testing failed! Time %t ", $time) ;
5647
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5648
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5649
        ok = 0 ;
5650
    end
5651
 
5652
    if ( temp_val1[24] !== 0 )
5653
    begin
5654
        $display("Parity checker testing failed! Time %t ", $time) ;
5655
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5656
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5657
        ok = 0 ;
5658
    end
5659
 
5660
    if ( ok )
5661
        test_ok ;
5662
 
5663
    // clear statuses
5664
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5665
 
5666
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5667
 
5668
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5669
    ok = 1 ;
5670
 
5671
    `ifdef HOST
5672
    if ( temp_val1[4] !== 1 )
5673
    begin
5674
        $display("Parity checker testing failed! Time %t ", $time) ;
5675
        $display("System error interrupt status bit not set when expected!") ;
5676
        test_fail("System error interrupt status bit not set when expected") ;
5677
        ok = 0 ;
5678
    end
5679
    `else
5680
    if ( temp_val1[4] !== 0 )
5681
    begin
5682
        $display("Parity checker testing failed! Time %t ", $time) ;
5683
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5684
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5685
        ok = 0 ;
5686
    end
5687
    `endif
5688
 
5689
    if ( temp_val1[3] !== 0 )
5690
    begin
5691
        $display("Parity checker testing failed! Time %t ", $time) ;
5692
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5693
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5694
        ok = 0 ;
5695
    end
5696
 
5697
    if ( ok )
5698
        test_ok ;
5699
 
5700
    // clear statuses
5701
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5702
 
5703
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5704
    fork
5705
    begin
5706 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5707 15 mihad
        (
5708
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5709
            32'h5555_5555,      // second part of address in dual address cycle
5710
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5711
            `BC_MEM_WRITE,      // normal command
5712 92 mihad
            4'hF,               // byte enables
5713 15 mihad
            32'h1234_5678,      // data
5714
            1'b1,               // make address parity error on first phase of dual address
5715
            1'b1,               // make address parity error on second phase of dual address
5716
            ok                  // result of operation
5717
        ) ;
5718 35 mihad
        if ( !perr_asserted )
5719
            disable wait_serr16 ;
5720 15 mihad
    end
5721
    begin:wait_serr16
5722
        perr_asserted = 0 ;
5723
        @(posedge pci_clock) ;
5724 35 mihad
        while( SERR !== 0 )
5725 15 mihad
            @(posedge pci_clock) ;
5726
 
5727 35 mihad
        perr_asserted = 1 ;
5728 15 mihad
    end
5729
    join
5730
 
5731
    if ( ok && perr_asserted)
5732
        test_ok ;
5733
    else
5734
    if ( !perr_asserted )
5735
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5736
 
5737
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5738
 
5739
    `ifdef HOST
5740
        repeat(4)
5741 26 mihad
            @(posedge pci_clock) ;
5742
        repeat(4)
5743 15 mihad
            @(posedge wb_clock) ;
5744
        if ( INT_O !== 1 )
5745
        begin
5746
            $display("Parity checker testing failed! Time %t ", $time) ;
5747
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5748
            test_fail("Interrupt Request was not triggered as expected") ;
5749
        end
5750
        else
5751
            test_ok ;
5752
    `else
5753
    `ifdef GUEST
5754 26 mihad
        repeat(4)
5755
            @(posedge wb_clock) ;
5756
        repeat(4)
5757 15 mihad
            @(posedge pci_clock) ;
5758
 
5759
        if ( INTA !== 1 )
5760
        begin
5761
            $display("Parity checker testing failed! Time %t ", $time) ;
5762
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5763
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5764
        end
5765
        else
5766
            test_ok ;
5767
    `endif
5768
    `endif
5769
 
5770
    // check statuses!
5771
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5772
    ok = 1 ;
5773
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5774
    if ( temp_val1[31] !== 1 )
5775
    begin
5776
        $display("Parity checker testing failed! Time %t ", $time) ;
5777
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5778
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5779
        ok = 0 ;
5780
    end
5781
 
5782
    if ( temp_val1[30] !== 1 )
5783
    begin
5784
        $display("Parity checker testing failed! Time %t ", $time) ;
5785
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5786
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5787
        ok = 0 ;
5788
    end
5789
 
5790
    if ( temp_val1[24] !== 0 )
5791
    begin
5792
        $display("Parity checker testing failed! Time %t ", $time) ;
5793
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5794
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5795
        ok = 0 ;
5796
    end
5797
 
5798
    if ( ok )
5799
        test_ok ;
5800
 
5801
    // clear statuses
5802
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5803
 
5804
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5805
 
5806
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5807
    ok = 1 ;
5808
 
5809
    `ifdef HOST
5810
    if ( temp_val1[4] !== 1 )
5811
    begin
5812
        $display("Parity checker testing failed! Time %t ", $time) ;
5813
        $display("System error interrupt status bit not set when expected!") ;
5814
        test_fail("System error interrupt status bit not set when expected") ;
5815
        ok = 0 ;
5816
    end
5817
    `else
5818
    if ( temp_val1[4] !== 0 )
5819
    begin
5820
        $display("Parity checker testing failed! Time %t ", $time) ;
5821
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5822
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5823
        ok = 0 ;
5824
    end
5825
    `endif
5826
 
5827
    if ( temp_val1[3] !== 0 )
5828
    begin
5829
        $display("Parity checker testing failed! Time %t ", $time) ;
5830
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5831
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5832
        ok = 0 ;
5833
    end
5834
 
5835
    if ( ok )
5836
        test_ok ;
5837
 
5838
    // clear statuses
5839
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5840
 
5841
    // now just disable Parity Error response - on Address par errors nothing should happen
5842
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5843
 
5844
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5845
    fork
5846
    begin
5847
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5848
               target_address, 32'h1234_5678,
5849
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5850
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5851
        do_pause( 1 ) ;
5852
    end
5853
    begin:wait_serr12
5854
        perr_asserted = 0 ;
5855
        @(posedge pci_clock) ;
5856
        while( SERR === 1 )
5857
            @(posedge pci_clock) ;
5858
 
5859
        perr_asserted = 1 ;
5860
        $display("Parity checker testing failed! Time %t ", $time) ;
5861
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5862
        test_fail("SERR asserted when parity error response was disabled") ;
5863
    end
5864
    begin
5865
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5866
        if ( ok !== 1 )
5867
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5868
 
5869 35 mihad
        @(posedge pci_clock) ;
5870
        #1 ;
5871
        if ( !perr_asserted )
5872
            disable wait_serr12 ;
5873 15 mihad
    end
5874
    join
5875
 
5876
    if ( ok && !perr_asserted )
5877
        test_ok ;
5878
 
5879
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5880
    `ifdef HOST
5881 26 mihad
        repeat (4)
5882
            @(posedge pci_clock) ;
5883 15 mihad
        repeat(4)
5884
            @(posedge wb_clock) ;
5885
        if ( INT_O !== 0 )
5886
        begin
5887
            $display("Parity checker testing failed! Time %t ", $time) ;
5888
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5889
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5890
        end
5891
        else
5892
            test_ok ;
5893
    `else
5894
    `ifdef GUEST
5895 26 mihad
        repeat(4)
5896
            @(posedge wb_clock) ;
5897
        repeat (4)
5898 15 mihad
            @(posedge pci_clock) ;
5899
 
5900
        if ( INTA !== 1 )
5901
        begin
5902
            $display("Parity checker testing failed! Time %t ", $time) ;
5903
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5904
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5905
        end
5906
        else
5907
            test_ok ;
5908
    `endif
5909
    `endif
5910
 
5911
    // check statuses!
5912
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5913
    ok = 1 ;
5914
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5915
    if ( temp_val1[31] !== 1 )
5916
    begin
5917
        $display("Parity checker testing failed! Time %t ", $time) ;
5918
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5919
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5920
        ok = 0 ;
5921
    end
5922
 
5923
    if ( temp_val1[30] !== 0 )
5924
    begin
5925
        $display("Parity checker testing failed! Time %t ", $time) ;
5926
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5927
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5928
        ok = 0 ;
5929
    end
5930
 
5931
    if ( temp_val1[24] !== 0 )
5932
    begin
5933
        $display("Parity checker testing failed! Time %t ", $time) ;
5934
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5935
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5936
        ok = 0 ;
5937
    end
5938
 
5939
    if ( ok )
5940
        test_ok ;
5941
 
5942
    // clear statuses
5943
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5944
 
5945
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5946
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5947
    ok = 1 ;
5948
    if ( temp_val1[4] !== 0 )
5949
    begin
5950
        $display("Parity checker testing failed! Time %t ", $time) ;
5951
        $display("System error interrupt status bit set when not expected!") ;
5952
        test_fail("System error interrupt status bit set when not expected") ;
5953
        ok = 0 ;
5954
    end
5955
 
5956
    if ( temp_val1[3] !== 0 )
5957
    begin
5958
        $display("Parity checker testing failed! Time %t ", $time) ;
5959
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5960
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5961
        ok = 0 ;
5962
    end
5963
 
5964
    if ( ok )
5965
        test_ok ;
5966
 
5967
    // clear statuses
5968
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5969
 
5970
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5971
    fork
5972
    begin
5973 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5974 15 mihad
        (
5975
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5976
            32'h5555_5555,      // second part of address in dual address cycle
5977
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5978
            `BC_MEM_WRITE,      // normal command
5979 92 mihad
            4'hF,               // byte enables
5980 15 mihad
            32'h1234_5678,      // data
5981
            1'b1,               // make address parity error on first phase of dual address
5982
            1'b0,               // make address parity error on second phase of dual address
5983
            ok                  // result of operation
5984
        ) ;
5985 35 mihad
        if ( !perr_asserted )
5986
            disable wait_serr17 ;
5987 15 mihad
    end
5988
    begin:wait_serr17
5989
        perr_asserted = 0 ;
5990
        @(posedge pci_clock) ;
5991
        while( SERR === 1 )
5992
            @(posedge pci_clock) ;
5993
 
5994
        perr_asserted = 1 ;
5995
        $display("Parity checker testing failed! Time %t ", $time) ;
5996
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5997
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5998
    end
5999
    join
6000
 
6001
    if ( ok && !perr_asserted)
6002
        test_ok ;
6003
 
6004
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
6005
    fork
6006
    begin
6007 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
6008 15 mihad
        (
6009
            32'hAAAA_AAAA,      // first part of address in dual address cycle
6010
            32'h5555_5555,      // second part of address in dual address cycle
6011
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
6012
            `BC_MEM_WRITE,      // normal command
6013 92 mihad
            4'hF,               // byte enables
6014 15 mihad
            32'h1234_5678,      // data
6015
            1'b0,               // make address parity error on first phase of dual address
6016
            1'b1,               // make address parity error on second phase of dual address
6017
            ok                  // result of operation
6018
        ) ;
6019 35 mihad
        if ( !perr_asserted )
6020
            disable wait_serr18 ;
6021 15 mihad
    end
6022
    begin:wait_serr18
6023
        perr_asserted = 0 ;
6024
        @(posedge pci_clock) ;
6025
        while( SERR === 1 )
6026
            @(posedge pci_clock) ;
6027
 
6028
        perr_asserted = 1 ;
6029
        $display("Parity checker testing failed! Time %t ", $time) ;
6030
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
6031
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6032
    end
6033
    join
6034
 
6035
    if ( ok && !perr_asserted)
6036
        test_ok ;
6037
 
6038
    // check statuses!
6039
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6040
    ok = 1 ;
6041
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6042
    if ( temp_val1[31] !== 1 )
6043
    begin
6044
        $display("Parity checker testing failed! Time %t ", $time) ;
6045
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6046
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6047
        ok = 0 ;
6048
    end
6049
 
6050
    if ( temp_val1[30] !== 0 )
6051
    begin
6052
        $display("Parity checker testing failed! Time %t ", $time) ;
6053
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6054
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6055
        ok = 0 ;
6056
    end
6057
 
6058
    if ( temp_val1[24] !== 0 )
6059
    begin
6060
        $display("Parity checker testing failed! Time %t ", $time) ;
6061
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6062
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6063
        ok = 0 ;
6064
    end
6065
 
6066
    if ( ok )
6067
        test_ok ;
6068
 
6069
    // clear statuses
6070
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6071
 
6072
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
6073
    fork
6074
    begin
6075 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
6076 15 mihad
        (
6077
            32'hAAAA_AAAA,      // first part of address in dual address cycle
6078
            32'h5555_5555,      // second part of address in dual address cycle
6079
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
6080
            `BC_MEM_WRITE,      // normal command
6081 92 mihad
            4'hF,               // byte enables
6082 15 mihad
            32'h1234_5678,      // data
6083
            1'b1,               // make address parity error on first phase of dual address
6084
            1'b1,               // make address parity error on second phase of dual address
6085
            ok                  // result of operation
6086
        ) ;
6087 35 mihad
        if ( !perr_asserted )
6088
            disable wait_serr19 ;
6089 15 mihad
    end
6090
    begin:wait_serr19
6091
        perr_asserted = 0 ;
6092
        @(posedge pci_clock) ;
6093
        while( SERR === 1 )
6094
            @(posedge pci_clock) ;
6095
 
6096
        perr_asserted = 1 ;
6097
        $display("Parity checker testing failed! Time %t ", $time) ;
6098
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
6099
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6100
    end
6101
    join
6102
 
6103
    if ( ok && !perr_asserted)
6104
        test_ok ;
6105
 
6106
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
6107
 
6108
    `ifdef HOST
6109
        repeat(4)
6110 26 mihad
            @(posedge pci_clock) ;
6111
        repeat(4)
6112 15 mihad
            @(posedge wb_clock) ;
6113
        if ( INT_O !== 0 )
6114
        begin
6115
            $display("Parity checker testing failed! Time %t ", $time) ;
6116
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
6117
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
6118
        end
6119
        else
6120
            test_ok ;
6121
    `else
6122
    `ifdef GUEST
6123 26 mihad
        repeat(4)
6124
            @(posedge wb_clock) ;
6125
        repeat(4)
6126 15 mihad
            @(posedge pci_clock) ;
6127
 
6128
        if ( INTA !== 1 )
6129
        begin
6130
            $display("Parity checker testing failed! Time %t ", $time) ;
6131
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
6132
            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") ;
6133
        end
6134
        else
6135
            test_ok ;
6136
    `endif
6137
    `endif
6138
 
6139
    // check statuses!
6140
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6141
    ok = 1 ;
6142
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6143
    if ( temp_val1[31] !== 1 )
6144
    begin
6145
        $display("Parity checker testing failed! Time %t ", $time) ;
6146
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6147
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6148
        ok = 0 ;
6149
    end
6150
 
6151
    if ( temp_val1[30] !== 0 )
6152
    begin
6153
        $display("Parity checker testing failed! Time %t ", $time) ;
6154
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6155
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6156
        ok = 0 ;
6157
    end
6158
 
6159
    if ( temp_val1[24] !== 0 )
6160
    begin
6161
        $display("Parity checker testing failed! Time %t ", $time) ;
6162
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6163
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6164
        ok = 0 ;
6165
    end
6166
 
6167
    if ( ok )
6168
        test_ok ;
6169
 
6170
    // clear statuses
6171
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6172
 
6173
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
6174
 
6175
    // do normal write
6176
    fork
6177
    begin
6178
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
6179
               target_address, 32'h1234_5678, `Test_All_Bytes,
6180
               1, 8'h3_0, `Test_One_Zero_Target_WS,
6181
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6182
        do_pause( 1 ) ;
6183
    end
6184
    begin:wait_serr13
6185
        perr_asserted = 0 ;
6186
        @(posedge pci_clock) ;
6187
        while( SERR === 1 )
6188
            @(posedge pci_clock) ;
6189
 
6190
        perr_asserted = 1 ;
6191
        $display("Parity checker testing failed! Time %t ", $time) ;
6192
        $display("SERR asserted for no reason!") ;
6193
        test_fail("SERR was asserted for no reason") ;
6194
    end
6195
    begin
6196
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6197
        if ( ok !== 1 )
6198
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6199
 
6200 35 mihad
        @(posedge pci_clock) ;
6201
        #1 ;
6202
        if ( !perr_asserted )
6203
            disable wait_serr13 ;
6204 15 mihad
    end
6205
    join
6206
 
6207
    if ( ok && !perr_asserted )
6208
        test_ok ;
6209
 
6210
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6211
    `ifdef HOST
6212 26 mihad
        repeat( 4 )
6213
            @(posedge pci_clock) ;
6214 15 mihad
        repeat(4)
6215
            @(posedge wb_clock) ;
6216
        if ( INT_O !== 0 )
6217
        begin
6218
            $display("Parity checker testing failed! Time %t ", $time) ;
6219
            $display("Interrupt request asserted for no reason!") ;
6220
            test_fail("Interrupt request was asserted for no reason") ;
6221
        end
6222
        else
6223
            test_ok ;
6224
    `else
6225
    `ifdef GUEST
6226 26 mihad
        repeat(4)
6227
            @(posedge wb_clock) ;
6228
        repeat(4)
6229 15 mihad
            @(posedge pci_clock) ;
6230
 
6231
        if ( INTA !== 1 )
6232
        begin
6233
            $display("Parity checker testing failed! Time %t ", $time) ;
6234
            $display("Interrupt request asserted for no reason!") ;
6235
            test_fail("Interrupt request was asserted for no reason") ;
6236
        end
6237
        else
6238
            test_ok ;
6239
    `endif
6240
    `endif
6241
 
6242
    // check statuses!
6243
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6244
    ok = 1 ;
6245
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6246
    if ( temp_val1[31] !== 0 )
6247
    begin
6248
        $display("Parity checker testing failed! Time %t ", $time) ;
6249
        $display("Detected Parity Error bit was set for no reason!") ;
6250
        test_fail("Detected Parity Error bit was set for no reason") ;
6251
        ok = 0 ;
6252
    end
6253
 
6254
    if ( temp_val1[30] !== 0 )
6255
    begin
6256
        $display("Parity checker testing failed! Time %t ", $time) ;
6257
        $display("Signalled System Error bit was set for no reason!") ;
6258
        test_fail("Signalled System Error bit was set for no reason") ;
6259
        ok = 0 ;
6260
    end
6261
 
6262
    if ( temp_val1[24] !== 0 )
6263
    begin
6264
        $display("Parity checker testing failed! Time %t ", $time) ;
6265
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6266
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6267
        ok = 0 ;
6268
    end
6269
 
6270
    if ( ok )
6271
        test_ok ;
6272
 
6273
    // clear statuses
6274
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6275
 
6276
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6277
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6278
    ok = 1 ;
6279
 
6280
    if ( temp_val1[4] !== 0 )
6281
    begin
6282
        $display("Parity checker testing failed! Time %t ", $time) ;
6283
        $display("System error interrupt status bit set when not expected!") ;
6284
        test_fail("System error interrupt status bit set when not expected") ;
6285
        ok = 0 ;
6286
    end
6287
 
6288
    if ( temp_val1[3] !== 0 )
6289
    begin
6290
        $display("Parity checker testing failed! Time %t ", $time) ;
6291
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6292
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6293
        ok = 0 ;
6294
    end
6295
 
6296
    if ( ok )
6297
        test_ok ;
6298
 
6299
    // clear statuses
6300
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6301
 
6302
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6303
 
6304
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6305
 
6306
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6307 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
6308 15 mihad
 
6309
    // setup target's image!
6310
    target_address  = Target_Base_Addr_R[1] ;
6311
 
6312
    // base address
6313
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6314
 
6315
    // address mask
6316
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6317
 
6318
    // image control
6319
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6320
 
6321
    // enable everything possible for parity checking
6322
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6323
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6324
 
6325
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6326
 
6327
    fork
6328
    begin
6329
        if ( target_mem_image === 1 )
6330
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6331
                   target_address, 32'h1234_5678,
6332
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6333
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6334
        else
6335
            PCIU_IO_WRITE_MAKE_PERR (
6336
                                    `Test_Master_1,
6337
                                    target_address,
6338
                                    32'h1234_5678,
6339
                                    4'h0,
6340
                                    1,
6341
                                    `Test_Target_Normal_Completion
6342
                                    );
6343
 
6344
        do_pause( 1 ) ;
6345
    end
6346
    begin:wait_perr11
6347
        perr_asserted = 0 ;
6348
        @(posedge pci_clock) ;
6349 35 mihad
        while ( PERR !== 0 )
6350 15 mihad
            @(posedge pci_clock) ;
6351
 
6352 35 mihad
        perr_asserted = 1 ;
6353 15 mihad
 
6354
    end
6355
    begin
6356
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6357
 
6358
        if ( ok !== 1 )
6359
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6360
 
6361
        repeat(2)
6362
            @(posedge pci_clock) ;
6363
 
6364 35 mihad
        #1 ;
6365
        if ( !perr_asserted )
6366
            disable wait_perr11 ;
6367 15 mihad
    end
6368
    join
6369
 
6370
    if ( ok && perr_asserted )
6371
        test_ok ;
6372
    else
6373
    if ( !perr_asserted )
6374
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6375
 
6376
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6377
    `ifdef HOST
6378 26 mihad
        repeat (4)
6379
            @(posedge pci_clock) ;
6380 15 mihad
        repeat(4)
6381
            @(posedge wb_clock) ;
6382
        if ( INT_O !== 0 )
6383
        begin
6384
            $display("Parity checker testing failed! Time %t ", $time) ;
6385
            $display("Interrupt request asserted for no reason!") ;
6386
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6387
        end
6388
        else
6389
            test_ok ;
6390
    `else
6391
    `ifdef GUEST
6392 26 mihad
        repeat(4)
6393
            @(posedge wb_clock) ;
6394
        repeat (4)
6395 15 mihad
            @(posedge pci_clock) ;
6396
 
6397
        if ( INTA !== 1 )
6398
        begin
6399
            $display("Parity checker testing failed! Time %t ", $time) ;
6400
            $display("Interrupt request asserted for no reason!") ;
6401
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6402
        end
6403
        else
6404
            test_ok ;
6405
 
6406
    `endif
6407
    `endif
6408
 
6409
    // check statuses!
6410
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6411
    ok = 1 ;
6412
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6413
    if ( temp_val1[31] !== 1 )
6414
    begin
6415
        $display("Parity checker testing failed! Time %t ", $time) ;
6416 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6417
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6418 15 mihad
        ok = 0 ;
6419
    end
6420
 
6421
    if ( temp_val1[30] !== 0 )
6422
    begin
6423
        $display("Parity checker testing failed! Time %t ", $time) ;
6424
        $display("Signalled System Error bit was set for no reason!") ;
6425
        test_fail("Signalled System Error bit was set for no reason") ;
6426
        ok = 0 ;
6427
    end
6428
 
6429
    if ( temp_val1[24] !== 0 )
6430
    begin
6431
        $display("Parity checker testing failed! Time %t ", $time) ;
6432
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6433
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6434
        ok = 0 ;
6435
    end
6436
 
6437
    if ( ok )
6438
        test_ok ;
6439
 
6440
    // clear statuses
6441
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6442
 
6443
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6444
 
6445
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6446
    ok = 1 ;
6447
    if ( temp_val1[4] !== 0 )
6448
    begin
6449
        $display("Parity checker testing failed! Time %t ", $time) ;
6450
        $display("System error interrupt status bit set when not expected!") ;
6451
        test_fail("System error interrupt status bit set when not expected") ;
6452
        ok = 0 ;
6453
    end
6454
 
6455
    if ( temp_val1[3] !== 0 )
6456
    begin
6457
        $display("Parity checker testing failed! Time %t ", $time) ;
6458
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6459
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6460
        ok = 0 ;
6461
    end
6462
 
6463
    if ( ok )
6464
        test_ok ;
6465
 
6466
    // clear statuses
6467
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6468
 
6469
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6470
 
6471
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6472
    fork
6473
    begin
6474
        if ( target_mem_image === 1 )
6475
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6476
                          target_address, 32'h1234_5678,
6477
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6478
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6479
        else
6480
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6481
 
6482
        do_pause( 1 ) ;
6483
    end
6484
    begin:wait_perr12
6485
        perr_asserted = 0 ;
6486
        @(posedge pci_clock) ;
6487 35 mihad
        while ( PERR !== 0 )
6488 15 mihad
            @(posedge pci_clock) ;
6489
 
6490 35 mihad
        perr_asserted = 1 ;
6491 15 mihad
    end
6492
    begin
6493
 
6494
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6495
        if ( ok !== 1 )
6496
        begin
6497
            test_fail("Bridge failed to process Target Memory read correctly") ;
6498
            disable main ;
6499
        end
6500
 
6501
        repeat(3)
6502
            @(posedge pci_clock) ;
6503
 
6504
        if ( target_mem_image === 1 )
6505
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6506
                    target_address, 32'h1234_5678,
6507
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6508
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6509
        else
6510
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6511
 
6512
        do_pause( 1 ) ;
6513
 
6514
    end
6515
    begin
6516
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6517
        if ( ok !== 1 )
6518
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6519
        else
6520
        begin
6521
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6522
            if ( ok !== 1 )
6523
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6524
        end
6525
 
6526 35 mihad
        repeat(2)
6527 15 mihad
            @(posedge pci_clock) ;
6528
 
6529 35 mihad
        #1 ;
6530
        if ( !perr_asserted )
6531
            disable wait_perr12 ;
6532 15 mihad
    end
6533
    join
6534
 
6535
    if ( ok && perr_asserted )
6536
        test_ok ;
6537
    else
6538
    if ( !perr_asserted )
6539
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6540
 
6541
 
6542
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6543
    `ifdef HOST
6544
        repeat(4)
6545 26 mihad
            @(posedge pci_clock) ;
6546
        repeat(4)
6547 15 mihad
            @(posedge wb_clock) ;
6548
        if ( INT_O !== 0 )
6549
        begin
6550
            $display("Parity checker testing failed! Time %t ", $time) ;
6551
            $display("Interrupt request asserted for no reason!") ;
6552
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6553
        end
6554
        else
6555
            test_ok ;
6556
    `else
6557
    `ifdef GUEST
6558 26 mihad
        repeat(4)
6559
            @(posedge wb_clock) ;
6560
        repeat(4)
6561 15 mihad
            @(posedge pci_clock) ;
6562
 
6563
        if ( INTA !== 1 )
6564
        begin
6565
            $display("Parity checker testing failed! Time %t ", $time) ;
6566
            $display("Interrupt request asserted for no reason!") ;
6567
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6568
        end
6569
        else
6570
            test_ok ;
6571
    `endif
6572
    `endif
6573
 
6574
    // check statuses!
6575
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6576
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6577
    ok = 1 ;
6578 45 mihad
    if ( temp_val1[31] !== 0 )
6579 15 mihad
    begin
6580
        $display("Parity checker testing failed! Time %t ", $time) ;
6581 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6582
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6583 15 mihad
        ok = 0 ;
6584
    end
6585
 
6586
    if ( temp_val1[30] !== 0 )
6587
    begin
6588
        $display("Parity checker testing failed! Time %t ", $time) ;
6589
        $display("Signalled System Error bit was set for no reason!") ;
6590
        test_fail("Signalled System Error bit was set for no reason") ;
6591
        ok = 0 ;
6592
    end
6593
 
6594
    if ( temp_val1[24] !== 0 )
6595
    begin
6596
        $display("Parity checker testing failed! Time %t ", $time) ;
6597
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6598
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6599
        ok = 0 ;
6600
    end
6601
 
6602
    if ( ok )
6603
        test_ok ;
6604
 
6605
    // clear statuses
6606
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6607
 
6608
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6609
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6610
    ok = 1 ;
6611
    if ( temp_val1[4] !== 0 )
6612
    begin
6613
        $display("Parity checker testing failed! Time %t ", $time) ;
6614
        $display("System error interrupt status bit set when not expected!") ;
6615
        test_fail("System error interrupt status bit set when not expected") ;
6616
        ok = 0 ;
6617
    end
6618
 
6619
    if ( temp_val1[3] !== 0 )
6620
    begin
6621
        $display("Parity checker testing failed! Time %t ", $time) ;
6622
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6623
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6624
        ok = 0 ;
6625
    end
6626
 
6627
    if ( ok )
6628
        test_ok ;
6629
    // clear statuses
6630
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6631
 
6632
    $fdisplay(pci_mon_log_file_desc,
6633
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6634
    test_name = "DISABLE USED IMAGES" ;
6635
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6636
    if ( ok !== 1 )
6637
    begin
6638
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6639
        test_fail("WB Image Address Mask register could not be written to") ;
6640
        disable main ;
6641
    end
6642
 
6643 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6644 15 mihad
    if ( ok !== 1 )
6645
    begin
6646
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6647
        test_fail("PCI Image Address Mask register could not be written to") ;
6648
        disable main ;
6649
    end
6650
 
6651
    // disable target's 1 response to parity errors
6652 45 mihad
    configuration_cycle_write(0,                        // bus number
6653
                              `TAR1_IDSEL_INDEX - 11,   // device number
6654
                              0,                        // function number
6655
                              1,                        // register number
6656
                              0,                        // type of configuration cycle
6657
                              4'b0001,                  // byte enables
6658
                              32'h0000_0007             // data
6659 15 mihad
                             ) ;
6660
 
6661
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6662
end
6663
endtask // parity_checking
6664
 
6665
task wb_to_pci_transactions ;
6666
    reg   [11:0] ctrl_offset ;
6667
    reg   [11:0] ba_offset ;
6668
    reg   [11:0] am_offset ;
6669
    reg   [11:0] pci_ctrl_offset ;
6670
    reg   [11:0] err_cs_offset ;
6671
    reg   [11:0] icr_offset ;
6672
    reg   [11:0] isr_offset ;
6673
    reg   [11:0] lat_tim_cls_offset ;
6674
 
6675
    reg `WRITE_STIM_TYPE  write_data ;
6676
    reg `READ_STIM_TYPE   read_data ;
6677
    reg `READ_RETURN_TYPE read_status ;
6678
 
6679
    reg `WRITE_RETURN_TYPE write_status ;
6680
    reg `WB_TRANSFER_FLAGS write_flags ;
6681
    reg [31:0] temp_val1 ;
6682
    reg [31:0] temp_val2 ;
6683
    reg        ok   ;
6684
 
6685
    reg [31:0] image_base ;
6686
    reg [31:0] target_address ;
6687
    integer i ;
6688
    integer required_reads ;
6689
    integer writes_left ;
6690
 
6691
begin:main
6692
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6693
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6694
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6695
    pci_ctrl_offset    = 12'h4 ;
6696
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6697
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6698
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6699
    lat_tim_cls_offset = 12'hC ;
6700
 
6701
    $display("Checking WB to PCI transaction lengths!") ;
6702
    target_address  = `BEH_TAR1_MEM_START ;
6703
    image_base      = 0 ;
6704
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6705
 
6706
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6707
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6708
    write_flags                    = 0 ;
6709 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
6710
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
6711 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6712
 
6713
    // enable master & target operation
6714
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6715
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6716
    if ( ok !== 1 )
6717
    begin
6718
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6719
        test_fail("write to PCI Device Control register failed") ;
6720
        disable main ;
6721
    end
6722
 
6723
    // prepare image control register
6724
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6725
    if ( ok !== 1 )
6726
    begin
6727
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6728
        test_fail("write to WB Image Control register failed") ;
6729
        disable main ;
6730
    end
6731
 
6732
    // prepare base address register
6733
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6734
    if ( ok !== 1 )
6735
    begin
6736
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6737
        test_fail("write to WB Base Address register failed") ;
6738
        disable main ;
6739
    end
6740
 
6741
    // write address mask register
6742
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6743
    if ( ok !== 1 )
6744
    begin
6745
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6746
        test_fail("write to WB Address Mask register failed") ;
6747
        disable main ;
6748
    end
6749
 
6750
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6751
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6752
    if ( ok !== 1 )
6753
    begin
6754
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6755
        test_fail("write to WB Error Control and Status register failed") ;
6756
        disable main ;
6757
    end
6758
 
6759
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6760
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6761
    if ( ok !== 1 )
6762
    begin
6763
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6764
        test_fail("write to Interrupt Control register failed") ;
6765
        disable main ;
6766
    end
6767
 
6768
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6769
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6770
    if ( ok !== 1 )
6771
    begin
6772
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6773
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6774
        disable main ;
6775
    end
6776
 
6777
    $display("Testing single write transaction progress from WB to PCI!") ;
6778
    write_data`WRITE_ADDRESS = target_address ;
6779
    write_data`WRITE_DATA    = wmem_data[0] ;
6780
    write_data`WRITE_SEL     = 4'hF ;
6781
 
6782
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6783
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6784
 
6785
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6786
    fork
6787
    begin
6788
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6789
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6790
        begin
6791
            $display("Transaction progress testing failed! Time %t ", $time) ;
6792
            $display("Bridge failed to process single memory write!") ;
6793
            test_fail("bridge failed to post single memory write") ;
6794
            disable main ;
6795
        end
6796
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6797
    end
6798
    begin
6799
        // wait two retries, then enable target response
6800
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6801
        if ( ok !== 1 )
6802
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6803
        else
6804
            test_ok ;
6805
 
6806
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6807
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6808
        if ( ok !== 1 )
6809
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6810
        else
6811
            test_ok ;
6812
 
6813
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6814
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6815
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6816
 
6817
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6818
        if ( ok !== 1 )
6819
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6820
        else
6821
            test_ok ;
6822
    end
6823
    join
6824
 
6825
    $display("Testing burst write transaction progress from WB to PCI!") ;
6826
    write_data`WRITE_ADDRESS = target_address ;
6827
    write_data`WRITE_DATA    = wmem_data[0] ;
6828
    write_data`WRITE_SEL     = 4'hF ;
6829
 
6830
    wishbone_master.blk_write_data[0] = write_data ;
6831
 
6832
    write_data`WRITE_ADDRESS = target_address + 4 ;
6833
    write_data`WRITE_DATA    = wmem_data[1] ;
6834
    write_data`WRITE_SEL     = 4'hF ;
6835
 
6836
    wishbone_master.blk_write_data[1] = write_data ;
6837
 
6838
    write_flags`WB_TRANSFER_SIZE = 2 ;
6839
    write_flags`WB_TRANSFER_CAB  = 1 ;
6840
 
6841
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6842
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6843
 
6844
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6845
 
6846
    fork
6847
    begin
6848
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6849
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6850
        begin
6851
            $display("Transaction progress testing failed! Time %t ", $time) ;
6852
            $display("Bridge failed to process whole CAB memory write!") ;
6853
            test_fail("bridge failed to post whole CAB memory write") ;
6854
            disable main ;
6855
        end
6856
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6857
    end
6858
    begin
6859
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6860
        if ( ok !== 1 )
6861
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6862
        else
6863
            test_ok ;
6864
 
6865
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6866
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6867
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6868
 
6869
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6870
        if ( ok !== 1 )
6871
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6872
        else
6873
            test_ok ;
6874
 
6875
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6876
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6877
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6878
 
6879
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6880
        if ( ok !== 1 )
6881
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6882
        else
6883
            test_ok ;
6884
    end
6885
    join
6886
 
6887
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6888
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6889
 
6890
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6891
    // try same write with other terminations
6892
    fork
6893
    begin
6894
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6895
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6896
        begin
6897
            $display("Transaction progress testing failed! Time %t ", $time) ;
6898
            $display("Bridge failed to process whole CAB memory write!") ;
6899
            test_fail("bridge failed to post whole CAB memory write") ;
6900
            disable main ;
6901
        end
6902
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6903
    end
6904
    begin
6905
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6906
        if ( ok !== 1 )
6907
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6908
        else
6909
            test_ok ;
6910
 
6911
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6912
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6913
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6914
 
6915
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6916
        if ( ok !== 1 )
6917
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6918
        else
6919
            test_ok ;
6920
    end
6921
    join
6922
 
6923
    // repeat the write with normal completion
6924
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6925
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6926
 
6927
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6928
    fork
6929
    begin
6930
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6931
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6932
        begin
6933
            $display("Transaction progress testing failed! Time %t ", $time) ;
6934
            $display("Bridge failed to process whole CAB memory write!") ;
6935
            test_fail("bridge failed to post whole CAB memory write") ;
6936
            disable main ;
6937
        end
6938
    end
6939
    begin
6940
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6941
        if ( ok !== 1 )
6942
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6943
        else
6944
            test_ok ;
6945
    end
6946
    join
6947
 
6948
    // do the same thing with burst length of 3
6949
    write_data`WRITE_ADDRESS = target_address + 8 ;
6950
    write_data`WRITE_DATA    = wmem_data[2] ;
6951
    write_data`WRITE_SEL     = 4'hF ;
6952
 
6953
    wishbone_master.blk_write_data[2] = write_data ;
6954
 
6955
    write_flags`WB_TRANSFER_SIZE = 3 ;
6956
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6957
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6958
 
6959
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6960
 
6961
    fork
6962
    begin
6963
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6964
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6965
        begin
6966
            $display("Transaction progress testing failed! Time %t ", $time) ;
6967
            $display("Bridge failed to process whole CAB memory write!") ;
6968
            test_fail("bridge failed to post whole CAB memory write") ;
6969
            disable main ;
6970
        end
6971
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6972
    end
6973
    begin
6974
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6975
        if ( ok !== 1 )
6976
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6977
        else
6978
            test_ok ;
6979
 
6980
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6981
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6982
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6983
 
6984
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6985
        if ( ok !== 1 )
6986
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6987
        else
6988
            test_ok ;
6989
    end
6990
    join
6991
 
6992
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6993
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6994
 
6995
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6996
    fork
6997
    begin
6998
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6999
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
7000
        begin
7001
            $display("Transaction progress testing failed! Time %t ", $time) ;
7002
            $display("Bridge failed to process whole CAB memory write!") ;
7003
            test_fail("bridge failed to post whole CAB memory write") ;
7004
            disable main ;
7005
        end
7006
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
7007
    end
7008
    begin
7009
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7010
        if ( ok !== 1 )
7011
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7012
        else
7013
            test_ok ;
7014
 
7015
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
7016
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7017
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7018
 
7019
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7020
        if ( ok !== 1 )
7021
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7022
        else
7023
            test_ok ;
7024
 
7025
    end
7026
    join
7027
 
7028
    // repeat with normal completion
7029
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7030
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7031
 
7032
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
7033
    fork
7034
    begin
7035
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7036
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
7037
        begin
7038
            $display("Transaction progress testing failed! Time %t ", $time) ;
7039
            $display("Bridge failed to process whole CAB memory write!") ;
7040
            test_fail("bridge failed to post whole CAB memory write") ;
7041
            disable main ;
7042
        end
7043
    end
7044
    begin
7045
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
7046
        if ( ok !== 1 )
7047
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7048
        else
7049
            test_ok ;
7050
 
7051
    end
7052
    join
7053
 
7054
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
7055
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
7056
    begin
7057
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7058
        write_data`WRITE_DATA    = wmem_data[i] ;
7059
        write_data`WRITE_SEL     = 4'hF ;
7060
 
7061
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
7062
        read_data`READ_SEL       = write_data`WRITE_SEL ;
7063
 
7064
        wishbone_master.blk_write_data[i]   = write_data ;
7065
        wishbone_master.blk_read_data_in[i] = read_data ;
7066
    end
7067
 
7068
    write_flags`WB_TRANSFER_CAB      = 1 ;
7069
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
7070
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7071
 
7072
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7073
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7074
 
7075
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
7076
    fork
7077
    begin
7078
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7079
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7080
        begin
7081
            $display("Transaction progress testing failed! Time %t ", $time) ;
7082
            $display("Bridge failed to process right number of databeats in CAB write!") ;
7083
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
7084
            test_fail("bridge failed to post whole CAB memory write") ;
7085
            disable main ;
7086
        end
7087
 
7088
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
7089
 
7090
        // read here just checks if data was transfered OK
7091
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7092
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
7093
 
7094
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7095
 
7096
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7097
        begin
7098
            $display("Transaction progress testing failed! Time %t ", $time) ;
7099
            $display("Bridge processed CAB read wrong!") ;
7100
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
7101
        end
7102
 
7103
    end
7104
    begin
7105
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7106
        if ( ok !== 1 )
7107
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7108
        else
7109
            test_ok ;
7110
 
7111
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
7112
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7113
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7114
 
7115
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7116
        if ( ok !== 1 )
7117
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7118
        else
7119
            test_ok ;
7120
 
7121
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
7122
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
7123
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7124
 
7125
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7126
        if ( ok !== 1 )
7127
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7128
        else
7129
            test_ok ;
7130
 
7131
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
7132
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7133
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7134
 
7135
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7136
        if ( ok !== 1 )
7137
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7138
        else
7139
            test_ok ;
7140
 
7141
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
7142
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7143
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7144
 
7145
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
7146
        if ( ok !== 1 )
7147
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7148
        else
7149
            test_ok ;
7150
 
7151
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
7152
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
7153
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
7154
        for ( i = 0 ; i < required_reads ; i = i + 1 )
7155
        begin
7156
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 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
        end
7160
    end
7161
    join
7162
 
7163
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
7164
    begin
7165
        read_status = wishbone_master.blk_read_data_out[i] ;
7166
        if (read_status`READ_DATA !== wmem_data[i])
7167
        begin
7168
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
7169
            test_fail("data read from target wasn't the same as data written to it") ;
7170
            ok = 0 ;
7171
        end
7172
    end
7173
 
7174
    if ( ok )
7175
        test_ok ;
7176
 
7177
    $display("Testing single read transaction progress from WB to PCI!") ;
7178
    read_data`READ_ADDRESS = target_address + 8 ;
7179
    read_data`READ_SEL     = 4'hF ;
7180
 
7181
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7182
 
7183
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
7184
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7185
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7186
 
7187
    fork
7188
    begin
7189
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7190
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7191
        begin
7192
            $display("Transaction progress testing failed! Time %t ", $time) ;
7193
            $display("Bridge processed single read wrong!") ;
7194
            test_fail("bridge processed single read wrong") ;
7195
            disable main ;
7196
        end
7197
 
7198
        if (read_status`READ_DATA !== wmem_data[2])
7199
        begin
7200
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7201
            test_fail("data returned from single read was not as expected") ;
7202
        end
7203
        else
7204
        if ( ok )
7205
            test_ok ;
7206
    end
7207
    begin
7208
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7209
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7210
 
7211
        if ( ok !== 1 )
7212
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7213
 
7214
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7215
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7216
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7217
 
7218
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7219
        if ( ok !== 1 )
7220
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7221
    end
7222
    join
7223
 
7224
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7225
 
7226
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7227
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7228
 
7229
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7230
    // first fill target's memory with enough data to fill WBR_FIFO
7231
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7232
    begin
7233
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7234
        write_data`WRITE_DATA    = wmem_data[i] ;
7235
        write_data`WRITE_SEL     = 4'hF ;
7236
 
7237
        wishbone_master.blk_write_data[i] = write_data ;
7238
    end
7239
 
7240
    write_flags`WB_TRANSFER_CAB = 1 ;
7241
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7242
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7243
 
7244
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7245
 
7246
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7247
    begin
7248
        $display("Transaction progress testing failed! Time %t ", $time) ;
7249
        $display("Bridge processed CAB write wrong!") ;
7250
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7251
        disable main ;
7252
    end
7253
 
7254
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7255
    // perform single read to force write data to pci
7256
    read_data`READ_ADDRESS = target_address + 8;
7257
    read_data`READ_SEL     = 4'hF ;
7258
 
7259
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7260
 
7261
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7262
    begin
7263
        $display("Transaction progress testing failed! Time %t ", $time) ;
7264
        $display("Bridge processed single read wrong!") ;
7265
        test_fail("bridge didn't process single memory read as expected") ;
7266
        disable main ;
7267
    end
7268
 
7269
    wishbone_master.blk_read_data_in[0] = read_data ;
7270
 
7271
    read_data`READ_ADDRESS = target_address + 12 ;
7272
    read_data`READ_SEL     = 4'hF ;
7273
 
7274
    wishbone_master.blk_read_data_in[1] = read_data ;
7275
 
7276
    read_data`READ_ADDRESS = target_address + 16 ;
7277
    read_data`READ_SEL     = 4'hF ;
7278
 
7279
    wishbone_master.blk_read_data_in[2] = read_data ;
7280
 
7281
    write_flags`WB_TRANSFER_CAB  = 1 ;
7282
    write_flags`WB_TRANSFER_SIZE = 2 ;
7283
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7284
    read_status = 0 ;
7285
 
7286
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7287
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7288
 
7289
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7290
 
7291
    ok = 1 ;
7292
    fork
7293
    begin
7294
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7295
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7296
 
7297
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7298
        begin
7299
            $display("Transaction progress testing failed! Time %t ", $time) ;
7300
            $display("Bridge processed CAB read wrong!") ;
7301
            test_fail("bridge didn't process disconnected burst read as expected") ;
7302
        end
7303
        else
7304
        begin
7305
 
7306
            read_status = wishbone_master.blk_read_data_out[0] ;
7307
 
7308
            if (read_status`READ_DATA !== wmem_data[2])
7309
            begin
7310
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7311
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7312
            end
7313
            else
7314
                test_ok ;
7315
        end
7316
 
7317
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7318
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7319
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7320
 
7321
        read_status = 0 ;
7322
 
7323
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7324
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7325
 
7326
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7327
        begin
7328
            $display("Transaction progress testing failed! Time %t ", $time) ;
7329
            $display("Bridge processed CAB read wrong!") ;
7330
            test_fail("bridge didn't process disconnected burst read as expected") ;
7331
        end
7332
        else
7333
        begin
7334
 
7335
            read_status = wishbone_master.blk_read_data_out[0] ;
7336
 
7337
            if (read_status`READ_DATA !== wmem_data[3])
7338
            begin
7339
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7340
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7341
            end
7342
            else
7343
                test_ok ;
7344
        end
7345
 
7346
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7347
        // complete delayed read which was requested
7348
        read_data = wishbone_master.blk_read_data_in[2] ;
7349
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7350
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7351
 
7352
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7353
        begin
7354
            $display("Transaction progress testing failed! Time %t ", $time) ;
7355
            $display("Bridge processed single out of burst read wrong!") ;
7356
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7357
        end
7358
        else
7359
        begin
7360
 
7361
            if (read_status`READ_DATA !== wmem_data[4])
7362
            begin
7363
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7364
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7365
            end
7366
            else
7367
                test_ok ;
7368
        end
7369
 
7370
    end
7371
    begin
7372
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7373
 
7374
        if ( ok !== 1 )
7375
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7376
 
7377
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7378
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7379
 
7380
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7381
        if ( ok !== 1 )
7382
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7383
 
7384
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7385
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7386
 
7387
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7388
        if ( ok !== 1 )
7389
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7390
    end
7391
    join
7392
 
7393
    // now try burst read with normal termination
7394
    read_data`READ_ADDRESS = target_address + 12 ;
7395
    read_data`READ_SEL     = 4'hF ;
7396
 
7397
    wishbone_master.blk_read_data_in[0] = read_data ;
7398
 
7399
    read_data`READ_ADDRESS = target_address + 16 ;
7400
    read_data`READ_SEL     = 4'hF ;
7401
 
7402
    wishbone_master.blk_read_data_in[1] = read_data ;
7403
 
7404
    write_flags`WB_TRANSFER_SIZE = 2 ;
7405
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7406
    write_flags`WB_TRANSFER_CAB = 1 ;
7407
 
7408
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7409
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7410
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7411
 
7412
    fork
7413
    begin
7414
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7415
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7416
        begin
7417
            $display("Transaction progress testing failed! Time %t ", $time) ;
7418
            $display("Bridge processed CAB read wrong!") ;
7419
            test_fail("bridge didn't process burst read as expected") ;
7420
            ok = 0 ;
7421
        end
7422
    end
7423
    begin
7424
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7425
        if ( ok !== 1 )
7426
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7427
    end
7428
    join
7429
 
7430
    if ( ok )
7431
    begin
7432
        read_status = wishbone_master.blk_read_data_out[0] ;
7433
        if ( read_status`READ_DATA !== wmem_data[3] )
7434
        begin
7435
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7436
            test_fail("data provided from normaly terminated read was wrong") ;
7437
            ok = 0 ;
7438
        end
7439
 
7440
        read_status = wishbone_master.blk_read_data_out[1] ;
7441
        if ( read_status`READ_DATA !== wmem_data[4] )
7442
        begin
7443
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7444
            test_fail("data provided from normaly terminated read was wrong") ;
7445
            ok = 0 ;
7446
        end
7447
    end
7448
 
7449
    if ( ok )
7450
        test_ok ;
7451
 
7452
    // disable memory read line command and enable prefetch
7453
    // prepare image control register
7454
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7455
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7456
    if ( ok !== 1 )
7457
    begin
7458
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7459
        test_fail("WB Image Control register couldn't be written to") ;
7460
        disable main ;
7461
    end
7462
 
7463
    write_flags`WB_TRANSFER_SIZE = 4 ;
7464
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7465
    write_flags`WB_TRANSFER_CAB = 1 ;
7466
 
7467
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7468
 
7469
    for ( i = 0 ; i < 4 ; i = i + 1 )
7470
    begin
7471
        read_data`READ_ADDRESS = target_address + i*4 ;
7472
        read_data`READ_SEL     = 4'b1010 ;
7473
 
7474
        wishbone_master.blk_read_data_in[i] = read_data ;
7475
    end
7476
 
7477
    fork
7478
    begin
7479
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7480
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7481
        begin
7482
            $display("Transaction progress testing failed! Time %t ", $time) ;
7483
            $display("Bridge processed CAB read wrong!") ;
7484
            test_fail("bridge didn't process prefetched burst read as expected") ;
7485
            ok = 0 ;
7486
        end
7487
    end
7488
    begin
7489
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7490
        if ( ok !== 1 )
7491
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7492
    end
7493
    join
7494
 
7495
    if ( ok )
7496
    begin
7497
        for ( i = 0 ; i < 4 ; i = i + 1 )
7498
        begin
7499
            read_status = wishbone_master.blk_read_data_out[i] ;
7500
            if ( read_status`READ_DATA !== wmem_data[i] )
7501
            begin
7502
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7503
                test_fail("burst read returned unexpected data") ;
7504
                ok = 0 ;
7505
            end
7506
        end
7507
    end
7508
 
7509
    if ( ok )
7510
        test_ok ;
7511
 
7512
    // do one single read with different byte enables
7513
    read_data`READ_ADDRESS = target_address + 4 ;
7514
    read_data`READ_SEL     = 4'b1010 ;
7515
 
7516
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7517
    fork
7518
    begin
7519
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7520
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7521
        begin
7522
            $display("Transaction progress testing failed! Time %t ", $time) ;
7523
            $display("Bridge processed single read wrong!") ;
7524
            test_fail("bridge didn't process single memory read as expected") ;
7525
            ok = 0 ;
7526
        end
7527
    end
7528
    begin
7529
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7530
        if ( ok !== 1 )
7531
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7532
    end
7533
    join
7534
 
7535
    // check read data
7536
    if ( ok )
7537
    begin
7538
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7539
        begin
7540
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7541
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7542
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7543
            ok = 0 ;
7544
            test_fail("unexpected data received from single read") ;
7545
        end
7546
    end
7547
 
7548
    if ( ok )
7549
         test_ok ;
7550
 
7551
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7552
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7553
 
7554
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7555
    if ( ok !== 1 )
7556
    begin
7557
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7558
        test_fail("WB Image Control register could not be written") ;
7559
        disable main ;
7560
    end
7561
 
7562
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7563
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7564
    begin
7565
        read_data`READ_ADDRESS = target_address + i*4 ;
7566
        read_data`READ_SEL     = 4'b1111 ;
7567
 
7568
        wishbone_master.blk_read_data_in[i] = read_data ;
7569
    end
7570
 
7571
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7572
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7573
    write_flags`WB_TRANSFER_CAB = 1 ;
7574
 
7575
    fork
7576
    begin
7577
        read_status         = 0 ;
7578
        read_status`CYC_RTY = 1 ;
7579
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7580
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7581
 
7582
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7583
        begin
7584
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7585
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7586
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7587
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7588
            ok = 0 ;
7589
        end
7590
    end
7591
    begin
7592
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7593
        if ( ok !== 1 )
7594
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7595
    end
7596
    join
7597
 
7598
    // now repeat single read to flush redundant read initiated
7599
    write_flags`WB_TRANSFER_SIZE = 1 ;
7600
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7601
    write_flags`WB_TRANSFER_CAB = 1 ;
7602
 
7603
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7604
    read_data`READ_SEL     = 4'hF ;
7605
 
7606
    wishbone_master.blk_read_data_in[0] = read_data ;
7607
 
7608
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7609
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7610
 
7611
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7612
    begin
7613
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7614
        $display(" PCI bridge failed to process single CAB read!") ;
7615
        test_fail("single CAB write was not processed as expected") ;
7616
    end
7617
 
7618
    // because last read could be very long on PCI - delete target abort status
7619
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7620
 
7621
    // write unsupported value to cache line size register
7622
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7623
 
7624
    read_data`READ_ADDRESS = target_address ;
7625
    read_data`READ_SEL     = 4'hF ;
7626
    wishbone_master.blk_read_data_in[0] = read_data ;
7627
 
7628
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7629
    // perform a read
7630
    fork
7631
    begin
7632
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7633
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7634
        begin
7635
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7636
            $display(" PCI bridge failed to process single CAB read!") ;
7637
            test_fail("burst read was not processed as expected") ;
7638
            ok = 0 ;
7639
        end
7640
    end
7641
    begin
7642
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7643
        if ( ok !== 1 )
7644
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7645
    end
7646
    join
7647
 
7648
    if ( ok )
7649
        test_ok ;
7650
 
7651
    // write 2 to cache line size register
7652
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7653
 
7654
    // perform a read
7655
    fork
7656
    begin
7657
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7658
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7659
        begin
7660
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7661
            $display(" PCI bridge failed to process single CAB read!") ;
7662
            test_fail("burst read was not processed as expected") ;
7663
            ok = 0 ;
7664
        end
7665
    end
7666
    begin
7667
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7668
        if ( ok !== 1 )
7669
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7670
    end
7671
    join
7672
 
7673
    if ( ok )
7674
        test_ok ;
7675
 
7676
    // write 0 to cache line size
7677
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7678
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7679
 
7680
    // perform a read
7681
    fork
7682
    begin
7683
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7684
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7685
        begin
7686
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7687
            $display(" PCI bridge failed to process single CAB read!") ;
7688
            test_fail("burst read was not processed as expected") ;
7689
            ok = 0 ;
7690
        end
7691
    end
7692
    begin
7693
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7694
        if ( ok !== 1 )
7695
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7696
    end
7697
    join
7698
 
7699
    if ( ok )
7700
        test_ok ;
7701
 
7702
    // write normal value to cls register
7703
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7704
 
7705
    $display("Testing Master's latency timer operation!") ;
7706
    $display("Testing Latency timer during Master Writes!") ;
7707
 
7708
    for ( i = 0 ; i < 6 ; i = i + 1 )
7709
    begin
7710
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7711
        write_data`WRITE_SEL     = 4'b1111 ;
7712
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7713
 
7714
        wishbone_master.blk_write_data[i] = write_data ;
7715
    end
7716
 
7717
    write_flags`WB_TRANSFER_SIZE = 6 ;
7718
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7719
    write_flags`WB_TRANSFER_CAB = 1 ;
7720
 
7721
    // start wb write, pci write and monitor in parallel
7722
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7723
    fork
7724
    begin
7725
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7726
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7727
        begin
7728
            $display("Transaction progress testing failed! Time %t ", $time) ;
7729
            $display("Bridge failed to process CAB write!") ;
7730
            test_fail("bridge didn't post whole burst memory write") ;
7731
            disable main ;
7732
        end
7733
    end
7734 106 mihad
    begin:cab_master_write_interrupted_by_latency_timeout2
7735
        reg [31:0] ret_adr ; reg [3:0] ret_bc ; reg ret_gnt_deasserted ;
7736
        integer ret_num_of_transfers ; integer ret_num_of_cycles ;
7737
 
7738
        ok = 1'b1 ;
7739
 
7740 15 mihad
        // wait for bridge's master to start transaction
7741 106 mihad
        monitor32.get_pci_op(ret_adr, ret_bc) ;
7742 15 mihad
 
7743 106 mihad
        if (ret_adr !== target_address)
7744
        begin
7745
            $display("%m detected an error!") ;
7746
            test_fail("invalid address was detected when PCI Master initiated a burst write operation") ;
7747
            ok = 0 ;
7748
        end
7749 15 mihad
 
7750 106 mihad
        if (ret_bc !== `BC_MEM_WRITE)
7751
        begin
7752
            $display("%m detected an error!") ;
7753
            test_fail("invalid bus command was detected when PCI Master should initiate a burst write operation") ;
7754
            ok = 0 ;
7755
        end
7756
 
7757
        // remove the grant from PCI Bridge
7758
        tc_gnt_allow = 1'b1 ;
7759
 
7760
        fork
7761
        begin
7762
            monitor32.get_pci_op_num_of_transfers(ret_num_of_transfers, ret_gnt_deasserted) ;
7763
        end
7764
        begin
7765
            monitor32.get_pci_op_num_of_cycles(ret_num_of_cycles) ;
7766
        end
7767
        join
7768
 
7769
        // put arbiter back into the control of the grant line
7770
        tc_gnt_allow = 1'b0 ;
7771
 
7772
        // check number of cycles bridge kept the frame asserted!
7773
        if (ret_gnt_deasserted !== 1'b1)
7774
        begin
7775
            $display("%m detected an error!") ;
7776
            test_fail("GNT line wasn't deasserted during latency timer operation tests") ;
7777
            ok = 0 ;
7778
        end
7779 15 mihad
        else
7780 106 mihad
        begin
7781
            if (ret_num_of_cycles > 2)
7782
            begin
7783
                $display("%m detected an error!") ;
7784
                test_fail("PCI Master was expected to deassert FRAME after two cycles and it didn't do that!") ;
7785
                ok = 0 ;
7786
            end
7787
        end
7788
 
7789
        if (ret_num_of_transfers !== 2)
7790
        begin
7791
            $display("%m detected an error!") ;
7792
            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") ;
7793
            ok = 0 ;
7794
        end
7795
 
7796
        // now check the remainder of the transaction!
7797
        if (ok === 1'b1)
7798
        begin
7799
            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) ;
7800
            if (ok !== 1'b1)
7801
            begin
7802
                $display("%m detected an error!") ;
7803
                test_fail("PCI Master did invalid transaction on PCI bus") ;
7804
                ok = 0 ;
7805
            end
7806
        end
7807
 
7808
        if (ok === 1'b1)
7809 15 mihad
            test_ok ;
7810
    end
7811
    join
7812
 
7813
    // perform a read to check data
7814
    for ( i = 0 ; i < 6 ; i = i + 1 )
7815
    begin
7816
        read_data`READ_ADDRESS = target_address + i*4 ;
7817
        read_data`READ_SEL     = 4'b1111 ;
7818
 
7819
        wishbone_master.blk_read_data_in[i] = read_data ;
7820
    end
7821
 
7822
    write_flags`WB_TRANSFER_SIZE = 6 ;
7823
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7824
    write_flags`WB_TRANSFER_CAB = 1 ;
7825
 
7826 106 mihad
    test_name = "CHECK VALUES OF BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7827 15 mihad
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7828
 
7829
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7830
    begin
7831
        $display("Transaction progress testing failed! Time %t ", $time) ;
7832
        $display("Bridge failed to process CAB read!") ;
7833
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7834
        disable main ;
7835
    end
7836
 
7837
    ok = 1 ;
7838
    for ( i = 0 ; i < 6 ; i = i + 1 )
7839
    begin
7840
        read_status = wishbone_master.blk_read_data_out[i] ;
7841
 
7842
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7843
        begin
7844
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7845
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7846
            test_fail("unexpected data read back from PCI") ;
7847
            ok = 0 ;
7848
        end
7849
    end
7850
 
7851
    if ( ok )
7852
        test_ok ;
7853
 
7854
    $display("Testing Latency timer during Master Reads!") ;
7855
 
7856
    // at least 2 words are transfered during Master Reads terminated with timeout
7857
    write_flags`WB_TRANSFER_SIZE = 2 ;
7858
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7859
    fork
7860
    begin
7861
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7862
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7863
        begin
7864
            $display("Transaction progress testing failed! Time %t ", $time) ;
7865
            $display("Bridge failed to process CAB read!") ;
7866
            test_fail("bridge didn't process burst read as expected") ;
7867
            ok = 0 ;
7868
        end
7869
    end
7870 106 mihad
    begin:cab_memory_read_interrupted_by_latency_timeout2
7871
        reg [31:0] ret_adr ; reg [3:0] ret_bc ; reg ret_gnt_deasserted ;
7872
        integer ret_num_of_transfers ; integer ret_num_of_cycles ;
7873
 
7874
        ok = 1'b1 ;
7875
 
7876 15 mihad
        // wait for bridge's master to start transaction
7877 106 mihad
        monitor32.get_pci_op(ret_adr, ret_bc) ;
7878 15 mihad
 
7879 106 mihad
        if (ret_adr !== target_address)
7880
        begin
7881
            $display("%m detected an error!") ;
7882
            test_fail("invalid address was detected when PCI Master initiated a burst read operation") ;
7883
            ok = 0 ;
7884
        end
7885 15 mihad
 
7886 106 mihad
        if (ret_bc !== `BC_MEM_READ_MUL)
7887
        begin
7888
            $display("%m detected an error!") ;
7889
            test_fail("invalid bus command was detected when PCI Master should initiate a burst read operation") ;
7890
            ok = 0 ;
7891
        end
7892
 
7893
        // remove the grant from PCI Bridge
7894
        tc_gnt_allow = 1'b1 ;
7895
 
7896
        fork
7897
        begin
7898
            monitor32.get_pci_op_num_of_transfers(ret_num_of_transfers, ret_gnt_deasserted) ;
7899
        end
7900
        begin
7901
            monitor32.get_pci_op_num_of_cycles(ret_num_of_cycles) ;
7902
        end
7903
        join
7904
 
7905
        // put arbiter back into the control of the grant line
7906
        tc_gnt_allow = 1'b0 ;
7907
 
7908
        // check number of cycles bridge kept the frame asserted!
7909
        if (ret_gnt_deasserted !== 1'b1)
7910
        begin
7911
            $display("%m detected an error!") ;
7912
            test_fail("GNT line wasn't deasserted during latency timer operation tests") ;
7913
            ok = 0 ;
7914
        end
7915
        else
7916
        begin
7917
            if (ret_num_of_cycles > 2)
7918
            begin
7919
                $display("%m detected an error!") ;
7920
                test_fail("PCI Master was expected to deassert FRAME after two cycles and it didn't do that!") ;
7921
                ok = 0 ;
7922
            end
7923
        end
7924
 
7925
        if (ret_num_of_transfers !== 2)
7926
        begin
7927
            $display("%m detected an error!") ;
7928
            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") ;
7929
            ok = 0 ;
7930
        end
7931 15 mihad
    end
7932
    join
7933
 
7934
    // check data provided by target
7935
    if ( ok )
7936
    begin
7937
        for ( i = 0 ; i < 2 ; i = i + 1 )
7938
        begin
7939
            read_status = wishbone_master.blk_read_data_out[i] ;
7940
 
7941
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7942
            begin
7943
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7944
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7945
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7946
                ok = 0 ;
7947
            end
7948
        end
7949
    end
7950 106 mihad
 
7951 15 mihad
    if ( ok )
7952
        test_ok ;
7953
 
7954
    test_name = "DISABLE_IMAGE" ;
7955
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7956
    if ( ok !== 1 )
7957
    begin
7958
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7959
        test_fail("write to WB Address Mask register failed") ;
7960
        disable main ;
7961
    end
7962
 
7963
end
7964
endtask //wb_to_pci_transactions
7965
 
7966
task iack_cycle ;
7967
    reg `READ_STIM_TYPE   read_data ;
7968
    reg `READ_RETURN_TYPE read_status ;
7969
    reg `WB_TRANSFER_FLAGS flags ;
7970
 
7971
    reg [31:0] temp_var ;
7972
    reg ok ;
7973 45 mihad
    reg ok_wb ;
7974
    reg ok_pci ;
7975
 
7976
    reg [31:0] irq_vector ;
7977 15 mihad
begin
7978
 
7979 45 mihad
    ok     = 1 ;
7980
    ok_wb  = 1 ;
7981
    ok_pci = 1 ;
7982
 
7983 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7984
 
7985
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7986
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7987
 
7988
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7989
    read_data`READ_SEL     = 4'hF ;
7990
 
7991
    flags = 0 ;
7992
 
7993
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7994
 
7995
    irq_vector  = 32'hAAAA_AAAA ;
7996
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7997
 
7998 45 mihad
    // disable both pci blue behavioral targets
7999
    configuration_cycle_write
8000
    (
8001
        0,                          // bus number [7:0]
8002
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
8003
        0,                          // function number [2:0]
8004
        1,                          // register number [5:0]
8005
        0,                          // type [1:0]
8006
        4'h1,                       // byte enables [3:0]
8007
        32'h0000_0044               // data to write [31:0]
8008
    ) ;
8009
 
8010
    configuration_cycle_write
8011
    (
8012
        0,                          // bus number [7:0]
8013
        `TAR2_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 15 mihad
    fork
8022
    begin
8023
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
8024
    end
8025
    begin
8026 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
8027
        if ( ok_pci !== 1 )
8028 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
8029
    end
8030
    join
8031
 
8032
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
8033
    begin
8034 45 mihad
        ok_wb = 0 ;
8035 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
8036
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
8037
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
8038
    end
8039 45 mihad
 
8040
    if ( ok_pci && ok_wb )
8041 15 mihad
        test_ok ;
8042 45 mihad
 
8043
    ok_wb = 1 ;
8044
    ok_pci = 1 ;
8045
    ok = 1 ;
8046 15 mihad
 
8047 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
8048
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
8049 15 mihad
 
8050
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
8051 45 mihad
    // enable pci blue behavioral target 1
8052
    configuration_cycle_write
8053
    (
8054
        0,                          // bus number [7:0]
8055
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
8056
        0,                          // function number [2:0]
8057
        1,                          // register number [5:0]
8058
        0,                          // type [1:0]
8059
        4'h1,                       // byte enables [3:0]
8060
        32'h0000_0047               // data to write [31:0]
8061
    ) ;
8062 15 mihad
    fork
8063
    begin
8064
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
8065
    end
8066
    begin
8067 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
8068
        if ( ok_pci !== 1 )
8069 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
8070
    end
8071
    join
8072
 
8073
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8074
    begin
8075 45 mihad
        ok_wb = 0 ;
8076 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
8077
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
8078
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
8079
    end
8080
 
8081
    if ( read_status`READ_DATA !== irq_vector )
8082
    begin
8083
        $display(" Time %t ", $time ) ;
8084
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
8085
        test_fail("Interrupt Acknowledge returned unexpected data") ;
8086 45 mihad
        ok_wb = 0 ;
8087 15 mihad
    end
8088
 
8089 45 mihad
    if ( ok_pci && ok_wb )
8090 15 mihad
        test_ok ;
8091
 
8092 45 mihad
    ok_pci = 1 ;
8093
    ok_wb  = 1 ;
8094
    ok     = 1 ;
8095
 
8096 15 mihad
    read_data`READ_SEL = 4'b0101 ;
8097 45 mihad
    irq_vector  = 32'h5555_5555 ;
8098
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
8099
 
8100 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
8101
    fork
8102
    begin
8103
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
8104
    end
8105
    begin
8106 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
8107
        if ( ok_pci !== 1 )
8108 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
8109
    end
8110
    join
8111
 
8112
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8113
    begin
8114
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
8115
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
8116
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
8117 45 mihad
        ok_wb = 0 ;
8118 15 mihad
    end
8119
 
8120 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
8121 15 mihad
    begin
8122
        $display(" Time %t ", $time ) ;
8123 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
8124 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
8125 45 mihad
        ok_wb = 0 ;
8126 15 mihad
    end
8127
 
8128 45 mihad
    if (ok_pci && ok_wb)
8129 15 mihad
        test_ok ;
8130
 
8131 45 mihad
    ok_pci = 1 ;
8132
    ok_wb  = 1 ;
8133
    ok     = 1 ;
8134 15 mihad
 
8135 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
8136
 
8137
    // set target to terminate with target abort
8138
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
8139
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8140
 
8141
    fork
8142
    begin
8143
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
8144
    end
8145
    begin
8146
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
8147
        if ( ok_pci !== 1 )
8148
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
8149
    end
8150
    join
8151
 
8152
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
8153
    begin
8154
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
8155
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
8156
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
8157
        ok_wb = 0 ;
8158
    end
8159
 
8160
    // set target to terminate with target abort
8161
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
8162
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
8163
 
8164
    // enable pci blue behavioral target 2
8165
    configuration_cycle_write
8166
    (
8167
        0,                          // bus number [7:0]
8168
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
8169
        0,                          // function number [2:0]
8170
        1,                          // register number [5:0]
8171
        0,                          // type [1:0]
8172
        4'h1,                       // byte enables [3:0]
8173
        32'h0000_0047               // data to write [31:0]
8174
    ) ;
8175
 
8176
    // read PCI Device status
8177
    config_read(12'h4, 4'hC, temp_var) ;
8178
    if (temp_var[29] !== 1)
8179
    begin
8180
        $display("Time %t", $time) ;
8181
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
8182
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
8183
        ok_wb = 0 ;
8184
    end
8185
 
8186
    if (temp_var[28] !== 1)
8187
    begin
8188
        $display("Time %t", $time) ;
8189
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
8190
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
8191
        ok_wb = 0 ;
8192
    end
8193
 
8194
    // clearing the status bits
8195
        config_write(12'h4, temp_var, 4'hC, ok);
8196
 
8197
    if ( ok && ok_pci && ok_wb )
8198
        test_ok ;
8199
 
8200 15 mihad
end
8201
endtask //iack_cycle
8202
 
8203
task transaction_ordering ;
8204
    reg   [11:0] wb_ctrl_offset ;
8205
    reg   [11:0] wb_ba_offset ;
8206
    reg   [11:0] wb_am_offset ;
8207
    reg   [11:0] pci_ctrl_offset ;
8208
    reg   [11:0] pci_ba_offset ;
8209
    reg   [11:0] pci_am_offset ;
8210
    reg   [11:0] pci_device_ctrl_offset ;
8211
    reg   [11:0] wb_err_cs_offset ;
8212
    reg   [11:0] pci_err_cs_offset ;
8213
    reg   [11:0] icr_offset ;
8214
    reg   [11:0] isr_offset ;
8215
    reg   [11:0] lat_tim_cls_offset ;
8216
 
8217
    reg `WRITE_STIM_TYPE  write_data ;
8218
    reg `READ_STIM_TYPE   read_data ;
8219
    reg `READ_RETURN_TYPE read_status ;
8220
 
8221
    reg `WRITE_RETURN_TYPE write_status ;
8222
    reg `WB_TRANSFER_FLAGS write_flags ;
8223
    reg [31:0] temp_val1 ;
8224
    reg [31:0] temp_val2 ;
8225
    reg        ok   ;
8226
 
8227
    reg [31:0] wb_image_base ;
8228
    reg [31:0] wb_target_address ;
8229
    reg [31:0] pci_image_base ;
8230
    integer i ;
8231
 
8232
    reg     error_monitor_done ;
8233
begin:main
8234 92 mihad
    write_flags`INIT_WAITS   = wb_init_waits ;
8235
    write_flags`SUBSEQ_WAITS = wb_subseq_waits ;
8236 15 mihad
 
8237
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
8238
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
8239
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
8240
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
8241
 
8242
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
8243
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
8244
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
8245
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
8246
 
8247
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
8248
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
8249
    lat_tim_cls_offset = 12'hC ;
8250
    pci_device_ctrl_offset    = 12'h4 ;
8251
 
8252
    wb_target_address  = `BEH_TAR1_MEM_START ;
8253
    wb_image_base      = 0 ;
8254
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
8255
 
8256
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
8257
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
8258
    write_flags                    = 0 ;
8259
    write_flags`INIT_WAITS         = 0 ;
8260
    write_flags`SUBSEQ_WAITS       = 0 ;
8261
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8262
 
8263
    pci_image_base = Target_Base_Addr_R[1] ;
8264
 
8265
    // enable master & target operation
8266
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
8267
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
8268
    if ( ok !== 1 )
8269
    begin
8270
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
8271
        test_fail("write to PCI Device Control register failed") ;
8272
        disable main ;
8273
    end
8274
 
8275
    // prepare image control register
8276
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8277
    if ( ok !== 1 )
8278
    begin
8279
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
8280
        test_fail("write to WB Image Control register failed") ;
8281
        disable main ;
8282
    end
8283
 
8284
    // prepare base address register
8285
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8286
    if ( ok !== 1 )
8287
    begin
8288
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8289
        test_fail("write to WB Base Address register failed") ;
8290
        disable main ;
8291
    end
8292
 
8293
    // write address mask register
8294
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8295
    if ( ok !== 1 )
8296
    begin
8297
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8298
        test_fail("write to WB Address Mask register failed") ;
8299
        disable main ;
8300
    end
8301
 
8302
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8303
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8304
    if ( ok !== 1 )
8305
    begin
8306
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8307
        test_fail("write to WB Error Control and Status register failed") ;
8308
        disable main ;
8309
    end
8310
 
8311
    // prepare image control register
8312
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8313
    if ( ok !== 1 )
8314
    begin
8315
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8316
        test_fail("write to PCI Image Control register failed") ;
8317
        disable main ;
8318
    end
8319
 
8320
    // prepare base address register
8321
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8322
    if ( ok !== 1 )
8323
    begin
8324
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8325
        test_fail("write to PCI Base Address register failed") ;
8326
        disable main ;
8327
    end
8328
 
8329
    // write address mask register
8330
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8331
    if ( ok !== 1 )
8332
    begin
8333
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8334
        test_fail("write to PCI Address Mask register failed") ;
8335
        disable main ;
8336
    end
8337
 
8338
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8339
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8340
    if ( ok !== 1 )
8341
    begin
8342
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8343
        test_fail("write to PCI Error Control and Status register failed") ;
8344
        disable main ;
8345
    end
8346
 
8347
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8348
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8349
    if ( ok !== 1 )
8350
    begin
8351
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8352
        test_fail("write to Interrupt Control register failed") ;
8353
        disable main ;
8354
    end
8355
 
8356
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8357
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8358
    if ( ok !== 1 )
8359
    begin
8360
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8361
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8362
        disable main ;
8363
    end
8364
 
8365
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8366
 
8367
    // prepare wb_master write and read data
8368
    for ( i = 0 ; i < 4 ; i = i + 1 )
8369
    begin
8370
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8371
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8372
        write_data`WRITE_SEL     = 4'hF ;
8373
 
8374
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8375
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8376
 
8377
        wishbone_master.blk_write_data[i]   = write_data ;
8378
        wishbone_master.blk_read_data_in[i] = read_data ;
8379
    end
8380
 
8381
    // put wishbone slave in acknowledge and pci target in retry mode
8382
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8383
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8384
 
8385 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8386 15 mihad
 
8387
    fork
8388
    begin
8389
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8390
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8391
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8392
        begin
8393
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8394
            test_fail("Bridge didn't post single memory write as expected") ;
8395
        end
8396
 
8397
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8398
        if ( ok !== 1 )
8399
        begin
8400
            $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) ;
8401
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8402
            ok = 0 ;
8403
        end
8404
 
8405
        // now post single write to target - normal progress
8406
        if ( target_mem_image == 1 )
8407
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8408
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8409
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8410
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8411
        else
8412
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8413
 
8414
        do_pause( 1 ) ;
8415
 
8416
    end
8417
    begin:error_monitor_1
8418 35 mihad
        error_monitor_done = 0 ;
8419 15 mihad
        @(error_event_int) ;
8420
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8421
        ok = 0 ;
8422 35 mihad
        error_monitor_done = 1 ;
8423 15 mihad
    end
8424
    begin
8425
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8426
        if ( ok !== 1 )
8427
        begin
8428
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8429
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8430
        end
8431
        else
8432
        begin
8433 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8434
//            while ( FRAME === 0 || IRDY === 0 )
8435
//                @(posedge pci_clock) ;
8436 15 mihad
 
8437
            // enable response in PCI target
8438
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8439
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8440
 
8441
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8442
            if ( ok !== 1 )
8443
            begin
8444
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8445
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8446
            end
8447
        end
8448
 
8449 35 mihad
        #1 ;
8450
        if ( !error_monitor_done )
8451
            disable error_monitor_1 ;
8452 15 mihad
    end
8453
    join
8454
 
8455
    if ( ok )
8456
        test_ok ;
8457
 
8458
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8459
 
8460
    // put WISHBONE slave in retry mode
8461 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'hFF);
8462 15 mihad
 
8463
    fork
8464
    begin
8465
        // now post single write to target - normal progress
8466
        if ( target_mem_image == 1 )
8467
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8468
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8469
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8470
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8471
        else
8472
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8473
 
8474
        do_pause( 1 ) ;
8475
 
8476
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8477
        if ( ok !== 1 )
8478
        begin
8479
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8480
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8481
        end
8482
 
8483
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8484
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8485
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8486
        begin
8487
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8488
            test_fail("Bridge didn't post single memory write as expected") ;
8489
        end
8490
 
8491
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8492
        if ( ok !== 1 )
8493
        begin
8494
            $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) ;
8495
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8496
            ok = 0 ;
8497
        end
8498
 
8499
        wait ( CYC_O === 0 ) ;
8500 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8501 15 mihad
 
8502
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8503
        if ( ok !== 1 )
8504
        begin
8505
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8506
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8507
        end
8508
 
8509 35 mihad
        #1 ;
8510
        if ( !error_monitor_done )
8511
            disable error_monitor_2 ;
8512 15 mihad
    end
8513
    begin:error_monitor_2
8514 35 mihad
        error_monitor_done = 0 ;
8515 15 mihad
        @(error_event_int) ;
8516
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8517
        ok = 0 ;
8518 35 mihad
        error_monitor_done = 1 ;
8519 15 mihad
    end
8520
    join
8521
 
8522
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8523
 
8524
    // put wishbone slave in acknowledge and pci target in retry mode
8525
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8526
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8527
 
8528 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8529 15 mihad
 
8530
    fork
8531
    begin
8532
        write_flags`WB_TRANSFER_SIZE = 3 ;
8533
        write_flags`WB_TRANSFER_CAB  = 1 ;
8534
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8535
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8536
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8537
        begin
8538
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8539
            test_fail("Bridge didn't post burst memory write as expected") ;
8540
        end
8541
 
8542
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8543
        if ( ok !== 1 )
8544
        begin
8545
            $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) ;
8546
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8547
            ok = 0 ;
8548
        end
8549
 
8550
        // now post single write to target - normal progress
8551
        if ( target_mem_image == 1 )
8552
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8553
                        pci_image_base, 32'h5555_5555, 4'h0,
8554
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8555
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8556
        else
8557
        begin
8558
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8559
            do_pause( 1 ) ;
8560
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8561
        end
8562
 
8563
        do_pause( 1 ) ;
8564
 
8565
    end
8566
    begin:error_monitor_3
8567 35 mihad
        error_monitor_done = 0 ;
8568 15 mihad
        @(error_event_int) ;
8569
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8570
        ok = 0 ;
8571 35 mihad
        error_monitor_done = 1 ;
8572 15 mihad
    end
8573
    begin
8574
        if ( target_mem_image == 1 )
8575
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8576
        else
8577
        begin
8578
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8579
            if ( ok )
8580
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8581
        end
8582
 
8583
        if ( ok !== 1 )
8584
        begin
8585
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8586
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8587
        end
8588
        else
8589
        begin
8590 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8591
//            while ( FRAME === 0 || IRDY === 0 )
8592
//                @(posedge pci_clock) ;
8593 15 mihad
 
8594
            // enable response in PCI target
8595
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8596
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8597
 
8598
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8599
            if ( ok !== 1 )
8600
            begin
8601
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8602
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8603
            end
8604
        end
8605
 
8606 35 mihad
        #1 ;
8607
        if ( !error_monitor_done )
8608
            disable error_monitor_3 ;
8609 15 mihad
    end
8610
    join
8611
 
8612
    if ( ok )
8613
        test_ok ;
8614
 
8615
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8616
 
8617
    // put WISHBONE slave in retry mode
8618 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'hFF);
8619 15 mihad
 
8620
    fork
8621
    begin
8622
        // now post single write to target - normal progress
8623
        if ( target_mem_image == 1 )
8624
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8625
                        pci_image_base, 32'h5555_5555, 4'h0,
8626
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8627
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8628
        else
8629
        begin
8630
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8631
            do_pause( 1 ) ;
8632
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8633
        end
8634
 
8635
        do_pause( 1 ) ;
8636
 
8637
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8638
 
8639
        if ( ok !== 1 )
8640
        begin
8641
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8642
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8643
        end
8644
 
8645
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8646
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8647
        write_flags`WB_TRANSFER_CAB      = 1 ;
8648
 
8649
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8650
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8651
        begin
8652
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8653
            test_fail("Bridge didn't post burst memory write as expected") ;
8654
        end
8655
 
8656
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8657
        if ( ok !== 1 )
8658
        begin
8659
            $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) ;
8660
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8661
            ok = 0 ;
8662
        end
8663
 
8664
        @(posedge wb_clock) ;
8665
        while ( CYC_O === 1 )
8666
            @(posedge wb_clock) ;
8667
 
8668 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8669 15 mihad
 
8670
        if ( target_mem_image == 1 )
8671
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8672
        else
8673
        begin
8674
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8675
            if ( ok )
8676
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8677
        end
8678
 
8679 35 mihad
        #1 ;
8680
        if ( !error_monitor_done )
8681
            disable error_monitor_4 ;
8682 15 mihad
    end
8683
    begin:error_monitor_4
8684 35 mihad
        error_monitor_done = 0 ;
8685 15 mihad
        @(error_event_int) ;
8686
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8687
        ok = 0 ;
8688 35 mihad
        error_monitor_done = 1 ;
8689 15 mihad
    end
8690
    join
8691
 
8692
    if ( ok )
8693
        test_ok ;
8694
 
8695
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8696
 
8697
    // put wishbone slave in acknowledge and pci target in retry mode
8698
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8699
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8700
 
8701 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
8702 15 mihad
 
8703
    master1_check_received_data = 1 ;
8704
 
8705
    error_monitor_done = 0 ;
8706
    fork
8707
    begin:error_monitor_5
8708
        @(error_event_int or error_monitor_done) ;
8709
        if ( !error_monitor_done )
8710
        begin
8711
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8712
            ok = 0 ;
8713
        end
8714
    end
8715
    begin
8716
 
8717
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8718
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8719
        begin
8720
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8721
            test_fail("Bridge didn't post single memory write as expected") ;
8722
        end
8723
 
8724
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8725
        if ( ok !== 1 )
8726
        begin
8727
            $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) ;
8728
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8729
            ok = 0 ;
8730
        end
8731
 
8732
        // start Read Through pci target
8733
        if ( target_mem_image == 1 )
8734
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8735
                          pci_image_base, 32'h5555_5555,
8736
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8737
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8738
        else
8739
            PCIU_IO_READ
8740
             (
8741
                `Test_Master_1,
8742
                pci_image_base,
8743
                32'h5555_5555,
8744
                4'h0,
8745
                1,
8746
                `Test_Target_Retry_On
8747
             );
8748
 
8749
         do_pause( 1 ) ;
8750
 
8751
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8752
         if ( ok !== 1 )
8753
         begin
8754
            $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) ;
8755
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8756
         end
8757
 
8758
         // repeat the read 4 times - it should be retried all the time by pci target
8759
        for ( i = 0 ; i < 4 ; i = i + 1 )
8760
        begin
8761
            if ( target_mem_image == 1 )
8762
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8763
                            pci_image_base, 32'h5555_5555,
8764
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8765
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8766
            else
8767
                PCIU_IO_READ
8768
                (
8769
                    `Test_Master_1,
8770
                    pci_image_base,
8771
                    32'h5555_5555,
8772
                    4'h0,
8773
                    1,
8774
                    `Test_Target_Retry_On
8775
                );
8776
 
8777
            do_pause( 1 ) ;
8778
        end
8779
 
8780
        // now do posted write through target - it must go through OK
8781
        if ( target_mem_image == 1 )
8782
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8783
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8784
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8785
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8786
        else
8787
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8788
 
8789
        do_pause( 1 ) ;
8790
 
8791
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8792
        if ( ok !== 1 )
8793
        begin
8794
           $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) ;
8795
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8796
        end
8797
 
8798
        // start a read through wb_slave
8799
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8800
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8801
        begin
8802
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8803
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8804
            ok = 0 ;
8805
        end
8806
 
8807 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8808
//        while ( FRAME === 0 || IRDY === 0 )
8809
//            @(posedge pci_clock) ;
8810 15 mihad
 
8811
        // set the target to normal completion
8812
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8813
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8814
 
8815
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8816
        if ( ok !== 1 )
8817
        begin
8818
            $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) ;
8819
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8820
            ok = 0 ;
8821
        end
8822
 
8823
        // now wait for delayed read to finish
8824
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8825
        if ( ok !== 1 )
8826
        begin
8827
            $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) ;
8828
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8829
            ok = 0 ;
8830
        end
8831
 
8832
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8833
        fork
8834
        begin
8835
                if ( target_mem_image == 1 )
8836
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8837
                                pci_image_base, 32'h5555_5555, 4'h0,
8838
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8839
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8840
                else
8841
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8842
 
8843
                do_pause( 1 ) ;
8844
                end
8845
                begin
8846 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 ) ;
8847 15 mihad
                end
8848
                join
8849
 
8850
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8851
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8852
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8853
        begin
8854
            $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) ;
8855
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8856
            ok = 0 ;
8857
        end
8858
 
8859
        fork
8860
        begin
8861
        // now complete a read from PCI Target
8862
            if ( target_mem_image == 1 )
8863
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8864
                            pci_image_base, 32'h5555_5555,
8865
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8866
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8867
            else
8868
                PCIU_IO_READ
8869
                (
8870
                    `Test_Master_1,
8871
                    pci_image_base,
8872
                    32'h5555_5555,
8873
                    4'h0,
8874
                    1,
8875
                    `Test_Target_Normal_Completion
8876
                );
8877
 
8878
            do_pause( 1 ) ;
8879
        end
8880
        begin
8881
            if ( target_mem_image == 1 )
8882
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8883
            else
8884
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8885
        end
8886
        join
8887
 
8888
        @(posedge pci_clock) ;
8889
        repeat( 4 )
8890
            @(posedge wb_clock) ;
8891
 
8892
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8893
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8894
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8895
        begin
8896
            $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) ;
8897
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8898
            ok = 0 ;
8899
        end
8900
 
8901
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8902
        if ( ok !== 1 )
8903
        begin
8904
            $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) ;
8905
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8906
            ok = 0 ;
8907
        end
8908
 
8909
        // finish a read on WISHBONE also
8910
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8911
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8912
        begin
8913
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8914
            test_fail("WB Slave didn't process single delayed read as expected") ;
8915
        end
8916
 
8917
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8918
        begin
8919
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8920
            ok = 0 ;
8921
        end
8922
 
8923
 
8924
        error_monitor_done = 1 ;
8925
    end
8926
    join
8927
 
8928
    if ( ok )
8929
        test_ok ;
8930
 
8931
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8932
 
8933
    // put wishbone slave in retry and pci target in completion mode
8934
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8935
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8936
 
8937 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'hFF);
8938 15 mihad
 
8939
    master1_check_received_data = 1 ;
8940
 
8941
    error_monitor_done = 0 ;
8942
    fork
8943
    begin:error_monitor_6
8944
        @(error_event_int or error_monitor_done) ;
8945
        if ( !error_monitor_done )
8946
        begin
8947
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8948
            ok = 0 ;
8949
        end
8950
    end
8951
    begin
8952
 
8953
        // do a write through Target
8954
        fork
8955
        begin
8956
            if ( target_mem_image == 1 )
8957
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8958
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8959
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8960
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8961
            else
8962
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8963
 
8964
            do_pause( 1 ) ;
8965
        end
8966
        begin
8967
            if ( target_mem_image == 1 )
8968
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8969
            else
8970
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8971
        end
8972
        join
8973
 
8974
        // start a read through WB slave
8975
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8976
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8977
        begin
8978
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8979
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8980
            ok = 0 ;
8981
        end
8982
 
8983
        // now wait for this read to finish on pci
8984
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8985
        if ( ok !== 1 )
8986
        begin
8987
            $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) ;
8988
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8989
            ok = 0 ;
8990
        end
8991
 
8992
        // repeat the read four times - it should be retried
8993
        for ( i = 0 ; i < 4 ; i = i + 1 )
8994
        begin
8995
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8996
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8997
            begin
8998
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8999
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
9000
                ok = 0 ;
9001
            end
9002
        end
9003
 
9004
        // posted write through WB Slave - must go through
9005
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
9006
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
9007
        begin
9008
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
9009
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
9010
            ok = 0 ;
9011
        end
9012
 
9013
        // write must come through
9014
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9015
        if ( ok !== 1 )
9016
        begin
9017
            $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) ;
9018
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
9019
            ok = 0 ;
9020
        end
9021
 
9022
        // do a read through pci target
9023
        if ( target_mem_image == 1 )
9024
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
9025
                          pci_image_base + 12, 32'hDEAD_BEAF,
9026
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
9027
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
9028
        else
9029
            PCIU_IO_READ
9030
             (
9031
                `Test_Master_1,
9032
                pci_image_base + 12,
9033
                32'hDEAD_BEAF,
9034
                4'h0,
9035
                1,
9036
                `Test_Target_Retry_On
9037
             );
9038
 
9039
         do_pause( 1 ) ;
9040
 
9041
        // wait for current cycle to finish on WB
9042 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
9043
//        @(posedge wb_clock) ;
9044
//        while( CYC_O === 1 )
9045
//            @(posedge wb_clock) ;
9046 15 mihad
 
9047
        // set slave response to acknowledge
9048 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
9049 15 mihad
 
9050
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
9051
        if ( ok !== 1 )
9052
        begin
9053
            $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) ;
9054
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
9055
        end
9056
 
9057
        // check the read to finish on wb
9058
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
9059
        if ( ok !== 1 )
9060
        begin
9061
            $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) ;
9062
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
9063
        end
9064
 
9065
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
9066
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
9067
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
9068
        begin
9069
            $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) ;
9070
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
9071
            ok = 0 ;
9072
        end
9073
 
9074
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
9075
        fork
9076
        begin
9077
            if ( target_mem_image == 1 )
9078
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
9079
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
9080
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
9081
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
9082
            else
9083
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
9084
        end
9085
        begin
9086
            if ( target_mem_image == 1 )
9087
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9088
            else
9089
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9090
        end
9091
        join
9092
 
9093
        do_pause( 1 ) ;
9094
 
9095
        // complete a read in WB Slave Unit
9096
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
9097
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
9098
        begin
9099
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
9100
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
9101
            ok = 0 ;
9102
        end
9103
 
9104
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
9105
        begin
9106
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
9107
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
9108
            ok = 0 ;
9109
        end
9110
 
9111
        // wait for statuses to be propagated from one side of bridge to another
9112
        repeat( 4 )
9113
            @(posedge pci_clock) ;
9114
 
9115
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
9116
        fork
9117
        begin
9118
            if ( target_mem_image == 1 )
9119
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
9120
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
9121
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
9122
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9123
            else
9124
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
9125
 
9126
            do_pause( 1 ) ;
9127
        end
9128
        begin
9129
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
9130
            if ( ok !== 1 )
9131
            begin
9132
                $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) ;
9133
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
9134
            end
9135
        end
9136
        join
9137
 
9138
        // finish the last read in PCI Target Unit
9139
        if ( target_mem_image == 1 )
9140
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
9141
                          pci_image_base + 12, 32'hDEAD_BEAF,
9142
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
9143
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9144
        else
9145
            PCIU_IO_READ
9146
             (
9147
                `Test_Master_1,
9148
                pci_image_base + 12,
9149
                32'hDEAD_BEAF,
9150
                4'h0,
9151
                1,
9152
                `Test_Target_Normal_Completion
9153
             );
9154
 
9155
         do_pause( 1 ) ;
9156
 
9157
         error_monitor_done = 1 ;
9158
    end
9159
    join
9160
 
9161 92 mihad
    // disable wb slave response
9162
    // fill pci target unit write fifo with single writes
9163
    // issue a read request - first all writes must finish on WB, than a read should finish on wishbone
9164
    test_name = "ORDERING OF THE TRANSACTIONS IN THE PCI TARGET UNIT ONLY" ;
9165
 
9166
    // set slave response to RETRY
9167
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'h0);
9168
 
9169
    fork
9170
    begin:pci_generator
9171
        repeat((`PCIW_DEPTH - 1) / 2)
9172
        begin
9173
            if ( target_mem_image == 1 )
9174
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
9175
                                 pci_image_base, 32'hF0F0_F0F0, 4'h0,
9176
                                 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
9177
                                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9178
            else
9179
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hF0F0_F0F0, 4'h0, 1, `Test_Target_Normal_Completion) ;
9180
 
9181
            do_pause(1) ;
9182
        end
9183
 
9184
        // now do a read request
9185
        if ( target_mem_image == 1 )
9186
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
9187
                          pci_image_base, 32'hF0F0_F0F0,
9188
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
9189
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
9190
        else
9191
            PCIU_IO_READ
9192
             (
9193
                `Test_Master_1,
9194
                pci_image_base,
9195
                32'hF0F0_F0F0,
9196
                4'h0,
9197
                1,
9198
                `Test_Target_Retry_On
9199
             );
9200
 
9201
        do_pause( 1 ) ;
9202
    end
9203
    begin:error_monitor_7
9204
        error_monitor_done = 1'b0 ;
9205
        @(error_event_int or error_monitor_done) ;
9206
        if ( !error_monitor_done )
9207
        begin
9208
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
9209
            ok = 0 ;
9210
        end
9211
    end
9212
    begin:pci_check
9213
        repeat((`PCIW_DEPTH - 1) / 2)
9214
        begin
9215
            if ( target_mem_image == 1 )
9216
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9217
            else
9218
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_WRITE,  1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9219
 
9220
            if (~ok)
9221
            begin
9222
                test_fail("PCI transaction monitor detected invalid transaction or none at all on PCI bus") ;
9223
            end
9224
        end
9225
 
9226
        if ( target_mem_image == 1 )
9227
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9228
        else
9229
            pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ,  0, 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
 
9236
 
9237
        repeat(2)
9238
            @(posedge pci_clock) ;
9239
 
9240
        #1 error_monitor_done = 1'b1 ;
9241
    end
9242
    begin:wb_check
9243
 
9244
        // enable the wishbone slave right after the first finished retry response
9245
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
9246
 
9247
        if (~ok)
9248
        begin
9249
            test_fail("WB transaction monitor detected invalid transaction or none at all on WB bus") ;
9250
        end
9251
 
9252
        // set slave response to acknowledge
9253
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
9254
 
9255
        repeat((`PCIW_DEPTH - 1) / 2)
9256
        begin
9257
            wishbone_slave.wb_memory[0] = 32'hxxxx_xxxx ;
9258
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
9259
            if (~ok)
9260
            begin
9261
                test_fail("WB transaction monitor detected invalid transaction or none at all on WB bus") ;
9262
            end
9263
            if (wishbone_slave.wb_memory[0] !== 32'hF0F0_F0F0)
9264
            begin
9265
                test_fail("Invalid data written on WB bus") ;
9266
            end
9267
        end
9268
 
9269
        // now check for read
9270
        wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
9271
 
9272
        if (~ok)
9273
        begin
9274
            test_fail("WB transaction monitor detected invalid transaction or none at all on WB bus") ;
9275
        end
9276
 
9277
    end
9278
    join
9279
 
9280
    // wait for two pci cycles for statuses to propagate through sync logic
9281
    repeat(2)
9282
        @(posedge pci_clock) ;
9283
 
9284
    // now finish the read through PCI target
9285
    fork
9286
    begin
9287
        if ( target_mem_image == 1 )
9288
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
9289
                          pci_image_base, 32'hF0F0_F0F0,
9290
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
9291
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9292
        else
9293
            PCIU_IO_READ
9294
            (
9295
                `Test_Master_1,
9296
                pci_image_base,
9297
                32'hF0F0_F0F0,
9298
                4'h0,
9299
                1,
9300
                `Test_Target_Normal_Completion
9301
            );
9302
 
9303
        do_pause( 1 ) ;
9304
    end
9305
    begin
9306
        error_monitor_done = 1'b0 ;
9307
        @(error_event_int or error_monitor_done) ;
9308
        if ( !error_monitor_done )
9309
        begin
9310
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
9311
            ok = 0 ;
9312
        end
9313
    end
9314
    begin
9315
        if ( target_mem_image == 1 )
9316
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9317
        else
9318
            pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ,  1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
9319
 
9320
        if (~ok)
9321
        begin
9322
            test_fail("PCI transaction monitor detected invalid transaction or none at all on PCI bus") ;
9323
        end
9324
 
9325
 
9326
        repeat(2)
9327
            @(posedge pci_clock) ;
9328
 
9329
        #1 error_monitor_done = 1'b1 ;
9330
    end
9331
    join
9332
 
9333 15 mihad
    if ( ok )
9334
        test_ok ;
9335
 
9336 92 mihad
    // disable the images
9337
    // write address mask register
9338
    config_write( wb_am_offset, 32'h0000_0000, 4'hF, ok ) ;
9339
    if ( ok !== 1 )
9340
    begin
9341
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
9342
        test_fail("write to WB Address Mask register failed") ;
9343
        disable main ;
9344
    end
9345
 
9346
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
9347
    if ( ok !== 1 )
9348
    begin
9349
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
9350
        test_fail("write to WB Address Mask register failed") ;
9351
        disable main ;
9352
    end
9353 15 mihad
end
9354
endtask // transaction_ordering
9355
 
9356
task pci_transaction_progress_monitor ;
9357
    input [31:0] address ;
9358
    input [3:0]  bus_command ;
9359
    input [31:0] num_of_transfers ;
9360
    input [31:0] num_of_cycles ;
9361
    input check_transfers ;
9362
    input check_cycles ;
9363
    input doing_fast_back_to_back ;
9364
    output ok ;
9365
    reg in_use ;
9366
    integer transfer_counter ;
9367
    integer cycle_counter ;
9368
    integer deadlock_max_val ;
9369
begin:main
9370
 
9371
    if ( in_use === 1 )
9372
    begin
9373
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9374
        ok = 0 ;
9375
        disable main ;
9376
    end
9377
 
9378 106 mihad
 
9379
    // number of ns to wait before timeout occurs
9380
    deadlock_max_val = `PCIW_DEPTH * 10 ;
9381
    deadlock_max_val = deadlock_max_val + `PCIR_DEPTH * 30 ;
9382 15 mihad
 
9383 106 mihad
    // time used for maximum transaction length on PCI
9384 15 mihad
    `ifdef PCI33
9385 106 mihad
    deadlock_max_val = deadlock_max_val * ( 30 ) ;
9386 15 mihad
    `else
9387 106 mihad
    deadlock_max_val = deadlock_max_val * ( 15 ) ;
9388 15 mihad
    `endif
9389
 
9390 106 mihad
    deadlock_max_val = deadlock_max_val + (`WBW_DEPTH * 10 * `WB_PERIOD) ;
9391
    deadlock_max_val = deadlock_max_val + (`WBR_DEPTH * 30 * `WB_PERIOD) ;
9392
 
9393 15 mihad
    in_use = 1 ;
9394
    ok     = 1 ;
9395
 
9396 106 mihad
    monitor32.get_pci_op.timeout_val = deadlock_max_val ;
9397 15 mihad
 
9398 106 mihad
    begin:monitor_blk
9399
        reg [31:0 ] returned_adr ;
9400
        reg [ 3:0 ] returned_cmd ;
9401
        reg         ret_gnt_deasserted ;
9402 15 mihad
 
9403 106 mihad
        monitor32.get_pci_op(returned_adr, returned_cmd) ;
9404 15 mihad
 
9405
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
9406
        if ( bus_command !== `BC_IACK )
9407
        begin
9408 106 mihad
            if ( returned_adr !== address )
9409 15 mihad
            begin
9410
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
9411 106 mihad
                $display("Expected address = %h, detected address = %h ", address, returned_adr) ;
9412 15 mihad
                ok = 0 ;
9413
            end
9414
        end
9415
 
9416 106 mihad
        if ( returned_cmd !== bus_command )
9417 15 mihad
        begin
9418
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
9419 106 mihad
            $display("Expected bus command = %b, detected bus command = %b", bus_command, returned_cmd) ;
9420 15 mihad
            ok = 0 ;
9421
        end
9422
 
9423 106 mihad
        fork
9424 15 mihad
        begin
9425 106 mihad
            if ( check_transfers === 1 )
9426 15 mihad
            begin
9427 106 mihad
                monitor32.get_pci_op_num_of_transfers(transfer_counter, ret_gnt_deasserted) ;
9428
                if ( transfer_counter !== num_of_transfers )
9429
                begin
9430
                    $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9431
                    $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9432
                    ok = 0 ;
9433
                end
9434 15 mihad
            end
9435
        end
9436
        begin
9437 106 mihad
            if ( check_cycles === 1'b1)
9438 15 mihad
            begin
9439 106 mihad
                monitor32.get_pci_op_num_of_cycles(cycle_counter) ;
9440
                if (cycle_counter > num_of_cycles)
9441 15 mihad
                begin
9442 106 mihad
                    $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9443
                    $display("Possibility of wrong operation in latency timer logic exists!") ;
9444
                    ok = 0 ;
9445 15 mihad
                end
9446
            end
9447
        end
9448 106 mihad
        join
9449 15 mihad
 
9450 106 mihad
    end //monitor_blk
9451
 
9452 15 mihad
    in_use = 0 ;
9453 106 mihad
 
9454 15 mihad
end
9455
endtask //pci_transaction_progress_monitor
9456
 
9457
reg CYC_O_previous ;
9458
always@(posedge wb_clock or posedge reset)
9459
begin
9460
    if ( reset )
9461
        CYC_O_previous <= #1 1'b0 ;
9462
    else
9463
        CYC_O_previous <= #1 CYC_O ;
9464
end
9465
 
9466
task wb_transaction_progress_monitor ;
9467
    input [31:0] address ;
9468
    input        write ;
9469
    input [31:0] num_of_transfers ;
9470
    input check_transfers ;
9471
    output ok ;
9472
    reg in_use ;
9473
    integer transfer_counter ;
9474
    integer deadlock_max_val ;
9475 73 mihad
    reg [2:0] slave_termination ;
9476
    reg       cab_asserted ;
9477 15 mihad
begin:main
9478
    if ( in_use === 1 )
9479
    begin
9480
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9481
        ok = 0 ;
9482
        disable main ;
9483
    end
9484
 
9485 106 mihad
    // number of ns to wait before timeout occurs
9486
    deadlock_max_val = `PCIW_DEPTH * 10 ;
9487
    deadlock_max_val = deadlock_max_val + `PCIR_DEPTH * 30 ;
9488 15 mihad
 
9489
    // time used for maximum transaction length on PCI
9490
    `ifdef PCI33
9491 106 mihad
    deadlock_max_val = deadlock_max_val * ( 30 ) ;
9492 15 mihad
    `else
9493 106 mihad
    deadlock_max_val = deadlock_max_val * ( 15 ) ;
9494 15 mihad
    `endif
9495
 
9496 106 mihad
    deadlock_max_val = deadlock_max_val + (`WBW_DEPTH * 10 * `WB_PERIOD) ;
9497
    deadlock_max_val = deadlock_max_val + (`WBR_DEPTH * 30 * `WB_PERIOD) ;
9498 15 mihad
 
9499 73 mihad
    in_use       = 1 ;
9500
    ok           = 1 ;
9501
    cab_asserted = 0 ;
9502 15 mihad
 
9503
    fork
9504
    begin:wait_start
9505 106 mihad
        #(deadlock_max_val) ;
9506
        $display("%m timeout! Time %t ", $time) ;
9507
        in_use = 0 ;
9508
        ok     = 0 ;
9509
        disable main ;
9510 15 mihad
    end //wait_start
9511
    begin:addr_monitor
9512
        @(posedge wb_clock) ;
9513
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9514
            @(posedge wb_clock) ;
9515
 
9516
        while( CYC_O !== 1 )
9517
            @(posedge wb_clock) ;
9518
 
9519
        while (STB_O !== 1 )
9520
            @(posedge wb_clock) ;
9521
 
9522
        if ( WE_O !== write )
9523
        begin
9524
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9525
            if ( write !== 1 )
9526
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9527
            else
9528
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9529
        end
9530
 
9531
        if ( ADR_O !== address )
9532
        begin
9533
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9534
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9535
            ok = 0 ;
9536
        end
9537 106 mihad
        disable wait_start ;
9538 15 mihad
    end
9539
    begin:transfer_checker
9540
        transfer_counter = 0 ;
9541
        @(posedge wb_clock) ;
9542
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9543
            @(posedge wb_clock) ;
9544
 
9545
        while( CYC_O !== 1 )
9546
            @(posedge wb_clock) ;
9547
 
9548 63 mihad
        while( (CYC_O === 1) && ((transfer_counter <= `PCIW_DEPTH) || (transfer_counter <= `PCIR_DEPTH)) )
9549 15 mihad
        begin
9550 73 mihad
 
9551
            if (!cab_asserted)
9552
                cab_asserted = (CAB_O !== 1'b0) ;
9553
 
9554
            if (STB_O === 1)
9555
            begin
9556
                slave_termination = {ACK_I, ERR_I, RTY_I} ;
9557
                if (ACK_I)
9558
                    transfer_counter = transfer_counter + 1 ;
9559
            end
9560 15 mihad
            @(posedge wb_clock) ;
9561
        end
9562
 
9563 73 mihad
        if (cab_asserted)
9564
        begin
9565
            // cab was sampled asserted
9566
            // if number of transfers was less than 2 - check for extraordinary terminations
9567
            if (transfer_counter < 2)
9568
            begin
9569
                // 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.
9570
                // any other cases are wrong
9571
                case (slave_termination)
9572
                3'b000:begin end
9573
                3'b001:begin end
9574
                3'b010:begin end
9575
                default:begin
9576
                            ok = 0 ;
9577
                            $display("Time %t", $time) ;
9578
                            $display("WB_MASTER asserted CAB_O for single transfer") ;
9579
                        end
9580
                endcase
9581
            end
9582
        end
9583
        else
9584
        begin
9585
            // if cab is not asserted, then WB_MASTER should not read more than one data.
9586
            if (transfer_counter > 1)
9587
            begin
9588
                ok = 0 ;
9589
                $display("Time %t", $time) ;
9590
                $display("WB_MASTER didn't assert CAB_O for consecutive block transfer") ;
9591
            end
9592
        end
9593
 
9594 15 mihad
        if ( check_transfers === 1 )
9595
        begin
9596
            if ( transfer_counter !== num_of_transfers )
9597
            begin
9598
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9599
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9600
                ok = 0 ;
9601
            end
9602
        end
9603
    end //transfer_checker
9604
    join
9605
 
9606
    in_use = 0 ;
9607
end
9608
endtask // wb_transaction_progress_monitor
9609
 
9610
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9611
// so they are not re-entered
9612
task wb_transaction_progress_monitor_backup ;
9613
    input [31:0] address ;
9614
    input        write ;
9615
    input [31:0] num_of_transfers ;
9616
    input check_transfers ;
9617
    output ok ;
9618
    reg in_use ;
9619
    integer transfer_counter ;
9620
    integer deadlock_max_val ;
9621
begin:main
9622
    if ( in_use === 1 )
9623
    begin
9624
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9625
        ok = 0 ;
9626
        disable main ;
9627
    end
9628
 
9629 106 mihad
    // number of ns to wait before timeout occurs
9630
    deadlock_max_val = `PCIW_DEPTH * 10 ;
9631
    deadlock_max_val = deadlock_max_val + `PCIR_DEPTH * 30 ;
9632 15 mihad
 
9633
    // time used for maximum transaction length on PCI
9634
    `ifdef PCI33
9635 106 mihad
    deadlock_max_val = deadlock_max_val * ( 30 ) ;
9636 15 mihad
    `else
9637 106 mihad
    deadlock_max_val = deadlock_max_val * ( 15 ) ;
9638 15 mihad
    `endif
9639
 
9640 106 mihad
    deadlock_max_val = deadlock_max_val + (`WBW_DEPTH * 10 * `WB_PERIOD) ;
9641
    deadlock_max_val = deadlock_max_val + (`WBR_DEPTH * 30 * `WB_PERIOD) ;
9642 15 mihad
 
9643
    in_use = 1 ;
9644
    ok     = 1 ;
9645
 
9646
    fork
9647
    begin:wait_start
9648 106 mihad
        #(deadlock_max_val) ;
9649
        $display("%m timeout! Time %t ", $time) ;
9650
        in_use = 0 ;
9651
        ok     = 0 ;
9652
        disable main ;
9653 15 mihad
    end //wait_start
9654
    begin:addr_monitor
9655
        @(posedge wb_clock) ;
9656
        while ( CYC_O !== 0 )
9657
            @(posedge wb_clock) ;
9658
 
9659
        while( CYC_O !== 1 )
9660
            @(posedge wb_clock) ;
9661
 
9662
        while (STB_O !== 1 )
9663
            @(posedge wb_clock) ;
9664
 
9665
        if ( WE_O !== write )
9666
        begin
9667
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9668
            if ( write !== 1 )
9669
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9670
            else
9671
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9672
        end
9673
 
9674
        if ( ADR_O !== address )
9675
        begin
9676
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9677
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9678
            ok = 0 ;
9679
        end
9680 106 mihad
        disable wait_start ;
9681 15 mihad
    end
9682
    begin:transfer_checker
9683
        transfer_counter = 0 ;
9684
        @(posedge wb_clock) ;
9685
        while ( CYC_O !== 0 )
9686
            @(posedge wb_clock) ;
9687
 
9688
        while( CYC_O !== 1 )
9689
            @(posedge wb_clock) ;
9690
 
9691
        while( CYC_O === 1 )
9692
        begin
9693
            if ( (STB_O === 1) && (ACK_I === 1) )
9694
                transfer_counter = transfer_counter + 1 ;
9695
            @(posedge wb_clock) ;
9696
        end
9697
 
9698
        if ( check_transfers === 1 )
9699
        begin
9700
            if ( transfer_counter !== num_of_transfers )
9701
            begin
9702
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9703
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9704
                ok = 0 ;
9705
            end
9706
        end
9707
    end //transfer_checker
9708
    join
9709
 
9710
    in_use = 0 ;
9711
end
9712
endtask // wb_transaction_progress_monitor_backup
9713
 
9714
task wb_transaction_stop ;
9715
    input [31:0] num_of_transfers ;
9716
    integer transfer_counter ;
9717
begin:main
9718
    begin:transfer_checker
9719
        transfer_counter = 0 ;
9720
        @(posedge wb_clock) ;
9721 92 mihad
        while ( (CYC_O !== 0) & (CYC_O_previous !== 0) )
9722 15 mihad
            @(posedge wb_clock) ;
9723
 
9724
        while( CYC_O !== 1 )
9725
            @(posedge wb_clock) ;
9726
 
9727
        if ( (STB_O === 1) && (ACK_I === 1) )
9728
            transfer_counter = transfer_counter + 1 ;
9729
 
9730
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9731
        begin
9732
            @(posedge wb_clock) ;
9733
            if ( (STB_O === 1) && (ACK_I === 1) )
9734
                transfer_counter = transfer_counter + 1 ;
9735
        end
9736
    end //transfer_checker
9737
end
9738
endtask // wb_transaction_stop
9739
 
9740
task musnt_respond ;
9741
    output ok ;
9742
    reg in_use ;
9743
    integer i ;
9744
begin:main
9745
    if ( in_use === 1 )
9746
    begin
9747
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9748
        #20 $stop ;
9749
        ok = 0 ;
9750
        disable main ;
9751
    end
9752
 
9753
    in_use = 1 ;
9754
    ok = 1 ;
9755
 
9756
    fork
9757
    begin:wait_start
9758
        @(negedge FRAME) ;
9759
        disable count ;
9760
    end
9761
    begin:count
9762
        i = 0 ;
9763
        while ( i < 1000 )
9764
        begin
9765
            @(posedge pci_clock) ;
9766
            i = i + 1 ;
9767
        end
9768
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9769
        ok = 0 ;
9770
        disable wait_start ;
9771
    end
9772
    join
9773
 
9774
    @(posedge pci_clock) ;
9775
    while ( FRAME === 0 && ok )
9776
    begin
9777
        if ( DEVSEL !== 1 )
9778
        begin
9779
            ok = 0 ;
9780
        end
9781
        @(posedge pci_clock) ;
9782
    end
9783
 
9784
    while ( IRDY === 0 && ok )
9785
    begin
9786
        if ( DEVSEL !== 1 )
9787
        begin
9788
            ok = 0 ;
9789
        end
9790
        @(posedge pci_clock) ;
9791
    end
9792
    in_use = 0 ;
9793
end
9794
endtask
9795
 
9796
function [31:0] wb_to_pci_addr_convert ;
9797
    input [31:0] wb_address ;
9798
    input [31:0] translation_address ;
9799
    input [31:0] translate ;
9800
 
9801
    reg   [31:0] temp_address ;
9802
begin
9803
    if ( translate !== 1 )
9804
    begin
9805
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9806
    end
9807
    else
9808
    begin
9809
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9810
    end
9811
 
9812
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9813
    wb_to_pci_addr_convert = temp_address ;
9814
end
9815
endfunction //wb_to_pci_addr_convert
9816
 
9817 45 mihad
`ifdef HOST
9818 15 mihad
task find_pci_devices ;
9819
    integer device_num ;
9820
    reg     found ;
9821
    reg [11:0] pci_ctrl_offset ;
9822
    reg ok ;
9823
    reg [31:0] data ;
9824 45 mihad
    reg [31:0] expected_data ;
9825
 
9826
    reg [5:0]  reg_num ;
9827 15 mihad
begin:main
9828 45 mihad
 
9829
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9830 15 mihad
    pci_ctrl_offset = 12'h004 ;
9831
 
9832
    // enable master & target operation
9833
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9834
 
9835
    if ( ok !== 1 )
9836
    begin
9837
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9838 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9839 15 mihad
        disable main ;
9840
    end
9841
    // find all possible devices on pci bus by performing configuration cycles
9842 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9843 15 mihad
    begin
9844
        find_device ( device_num, found ) ;
9845
 
9846
        // check pci status register - if device is not present, Received Master Abort bit must be set
9847
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9848
 
9849
        if ( (data[29] !== 0) && (found !== 0) )
9850 45 mihad
        begin
9851 15 mihad
            $display( "Time %t ", $time ) ;
9852
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9853
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9854 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9855
            ok = 0 ;
9856 15 mihad
        end
9857
 
9858
        if ( (data[29] !== 1) && (found !== 1) )
9859
        begin
9860
            $display( "Time %t ", $time ) ;
9861
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9862
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9863 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9864
            ok = 0 ;
9865 15 mihad
        end
9866
 
9867
        // clear Master Abort status if set
9868
        if ( data[29] !== 0 )
9869
        begin
9870
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9871
        end
9872 45 mihad
 
9873
        if (found === 1)
9874
        begin
9875
            // first check if found target is supposed to exist
9876
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9877
            begin
9878
                $display("Time %t", $time) ;
9879
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9880
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9881
                ok = 0 ;
9882
            end
9883
            else
9884
            begin
9885
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9886
                begin
9887
 
9888
                    data = 32'hFFFF_FFFF ;
9889
 
9890
                    expected_data = 0 ;
9891
 
9892
                    if (reg_num == 4)
9893
                    begin
9894
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9895
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9896
                    end
9897
                    else if (reg_num == 5)
9898
                    begin
9899
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9900
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9901
                    end
9902
 
9903
                    // write base address 0
9904
                    generate_configuration_cycle
9905
                    (
9906
                        'h0,            //bus_num
9907
                        device_num,     //device_num
9908
                        'h0,            //func_num
9909
                        reg_num,        //reg_num
9910
                        'h0,            //type
9911
                        4'hF,           // byte_enables
9912
                        data,           //data
9913
                        1'b1            //read0_write1
9914
                    );
9915
 
9916
                    // read data back
9917
                    generate_configuration_cycle
9918
                    (
9919
                        'h0,            //bus_num
9920
                        device_num,     //device_num
9921
                        'h0,            //func_num
9922
                        reg_num,        //reg_num
9923
                        'h0,            //type
9924
                        4'hF,           // byte_enables
9925
                        data,           //data
9926
                        1'b0            //read0_write1
9927
                    );
9928
 
9929
                    if (data !== expected_data)
9930
                    begin
9931
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9932
                        $display("Data read back not as expected!");
9933
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9934
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9935
                        ok = 0 ;
9936
                    end
9937
                end
9938
            end
9939
        end
9940 15 mihad
    end
9941 45 mihad
 
9942
    if (ok)
9943
        test_ok ;
9944 15 mihad
end //main
9945
endtask //find_pci_devices
9946
 
9947
task find_device ;
9948
    input [31:0] device_num ;
9949
    output  found ;
9950
 
9951
    reg [31:0] read_data ;
9952
begin
9953
    found = 1'b0 ;
9954
 
9955
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9956 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9957 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9958
    else
9959
    begin
9960
        $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]) ;
9961
        found = 1'b1 ;
9962
    end
9963
end
9964
endtask //find_device
9965 45 mihad
`endif
9966 15 mihad
 
9967
/*task set_bridge_parameters ;
9968
    reg [11:0] current_offset ;
9969
    reg [2:0] result ;
9970
    reg [31:0] write_data ;
9971
begin
9972
    // set burst size
9973
    // set latency timer
9974
    current_offset = 12'h00C ;
9975
    // set burst size to 16 and latency timer to 8
9976
    write_data     = {24'h0000_08, system_burst_size} ;
9977
    config_write(current_offset, write_data, 4'b1111) ;
9978
 
9979
    // set io image
9980
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9981
    write_data = 32'h0000_000_3 ;
9982
    config_write(current_offset, write_data, 4'b1111) ;
9983
 
9984
 
9985
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9986
    write_data = 32'h0001_000_1 ;
9987
    config_write(current_offset, write_data, 4'b1111) ;
9988
 
9989
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9990
    write_data = 32'hFFFF_0000 ;
9991
    config_write(current_offset, write_data, 4'b1111) ;
9992
 
9993
    // set memory image
9994
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9995
    write_data = 32'h0000_000_7 ;
9996
    config_write(current_offset, write_data, 4'b1111) ;
9997
 
9998
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9999
    write_data = 32'h0002_000_0 ;
10000
    config_write(current_offset, write_data, 4'b1111) ;
10001
 
10002
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
10003
    write_data = 32'h0001_0000 ;
10004
    config_write(current_offset, write_data, 4'b1111) ;
10005
 
10006
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
10007
    write_data = 32'hFFFF_0000 ;
10008
    config_write(current_offset, write_data, 4'b1111) ;
10009
 
10010
    // set parameters for bridge's target unit
10011
    // image control 0
10012
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
10013
    write_data     = 32'h0000_0002 ;
10014
    config_write(current_offset, write_data, 4'b0001) ;
10015
 
10016
    // base_address 0
10017
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
10018
    write_data      = 32'h2000_0000 ;
10019
    config_write(current_offset, write_data, 4'b1111) ;
10020
 
10021
    // address mask 0
10022
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
10023
    write_data     = 32'hFFFF_F000 ;
10024
    config_write(current_offset, write_data, 4'b1111) ;
10025
 
10026
    // command register - enable response to io and mem space and PCI master
10027
    current_offset = 12'h004 ;
10028
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
10029
    config_write(current_offset, write_data, 4'b1111) ;
10030
end
10031
endtask // set_bridge_parameters
10032
*/
10033
 
10034
task configuration_cycle_write ;
10035
    input [7:0]  bus_num ;
10036
    input [4:0]  device_num ;
10037
    input [2:0]  func_num ;
10038
    input [5:0]  reg_num ;
10039
    input [1:0]  type ;
10040
    input [3:0]  byte_enables ;
10041
    input [31:0] data ;
10042
 
10043
    reg [31:0] write_address ;
10044
    reg in_use ;
10045
    reg ok ;
10046
begin:main
10047
 
10048
    if ( in_use === 1 )
10049
    begin
10050 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
10051 15 mihad
        disable main ;
10052
    end
10053
 
10054 45 mihad
    if ( (device_num > 20) && (type === 0) )
10055 15 mihad
    begin
10056
        $display("Configuration cycle generation only supports access to 21 devices!") ;
10057
        disable main ;
10058
    end
10059
 
10060
    in_use = 1 ;
10061
 
10062 45 mihad
 
10063
`ifdef HOST
10064
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
10065
`else
10066
`ifdef GUEST
10067
 
10068 15 mihad
    if ( type )
10069
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10070
    else
10071
    begin
10072
        write_address = 0 ;
10073
        write_address[10:0] = { func_num, reg_num, type } ;
10074
        write_address[11 + device_num] = 1'b1 ;
10075
    end
10076 45 mihad
 
10077
    fork
10078 15 mihad
    begin
10079 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
10080
                            write_address,
10081
                            data, ~byte_enables,
10082
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
10083
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10084
        do_pause(1) ;
10085 15 mihad
    end
10086 45 mihad
    begin
10087
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
10088
    end
10089
    join
10090
`endif
10091
`endif
10092
 
10093
    in_use = 0 ;
10094
end
10095
endtask // configuration_cycle_write
10096 15 mihad
 
10097 45 mihad
task configuration_cycle_read ;
10098
    input [7:0]  bus_num ;
10099
    input [4:0]  device_num ;
10100
    input [2:0]  func_num ;
10101
    input [5:0]  reg_num ;
10102
    input [1:0]  type ;
10103
    input [3:0]  byte_enables ;
10104
    output [31:0] data ;
10105 15 mihad
 
10106 45 mihad
    reg [31:0] read_address ;
10107
    reg in_use ;
10108 15 mihad
 
10109 45 mihad
    reg master_check_data_prev ;
10110
begin:main
10111 15 mihad
 
10112 45 mihad
    if ( in_use === 1 )
10113 15 mihad
    begin
10114 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
10115
        data = 32'hxxxx_xxxx ;
10116
        disable main ;
10117 15 mihad
    end
10118
 
10119 45 mihad
    in_use = 1 ;
10120 15 mihad
 
10121 45 mihad
`ifdef HOST
10122
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
10123
`else
10124
`ifdef GUEST
10125
     master_check_data_prev = master1_check_received_data ;
10126 15 mihad
     if ( type )
10127 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10128 15 mihad
     else
10129
     begin
10130 45 mihad
         read_address = 0 ;
10131
         read_address[10:0] = { func_num, reg_num, type } ;
10132
         read_address[11 + device_num] = 1'b1 ;
10133 15 mihad
     end
10134 45 mihad
 
10135
     fork
10136
     begin
10137
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
10138
                 read_address,
10139 15 mihad
                 data, ~byte_enables,
10140
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
10141
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10142 45 mihad
         do_pause(1) ;
10143
     end
10144
     begin
10145
         @(master1_received_data_valid) ;
10146
         data = master1_received_data ;
10147
     end
10148
     join
10149 15 mihad
 
10150 45 mihad
    master1_check_received_data = master_check_data_prev ;
10151
`endif
10152
`endif
10153
 
10154 15 mihad
    in_use = 0 ;
10155
 
10156 45 mihad
end //main
10157
endtask // configuration_cycle_read
10158
 
10159 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
10160
task test_conf_cycle_type1_reference ;
10161
    reg [31:0] address ;
10162
    reg in_use ;
10163
 
10164
    reg master_check_data_prev ;
10165
    reg [31:0] data ;
10166
    reg monitor_ok ;
10167
    reg master_ok ;
10168
begin:main
10169
 
10170
    if ( in_use === 1 )
10171
    begin
10172
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
10173
        disable main ;
10174
    end
10175
 
10176
    in_use = 1 ;
10177
 
10178
    master_check_data_prev = master1_check_received_data ;
10179
 
10180
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
10181
    address = `TAR0_IDSEL_ADDR ;
10182
 
10183
    address[1:0] = 2'b01 ;
10184
 
10185
    `ifdef HOST
10186
        conf_cyc_type1_target_bus_num = 255 ;
10187
    `endif
10188
    master_ok = 1 ;
10189
    fork
10190
    begin
10191
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
10192
        do_pause(1) ;
10193
    end
10194
    begin:error_monitor1
10195
        @(error_event_int) ;
10196
        master_ok = 0 ;
10197
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
10198
    end
10199
    begin
10200
        pci_transaction_progress_monitor
10201
        (
10202
            address,                                                // expected address on PCI bus
10203
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10204
            0,                                                      // expected number of succesfull data phases
10205
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10206
            1'b1,                                                   // monitor checking/not checking number of transfers
10207
            1'b0,                                                   // monitor checking/not checking number of cycles
10208
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10209
            monitor_ok                                              // status - 1 success, 0 failure
10210
        ) ;
10211
 
10212
        @(posedge pci_clock);
10213
        #1 ;
10214
 
10215
        if (master_ok)
10216
            disable error_monitor1 ;
10217
 
10218
        if (!monitor_ok)
10219
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10220
    end
10221
    join
10222
 
10223
    if (monitor_ok && master_ok)
10224
        test_ok ;
10225
 
10226
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
10227
    master_ok = 1 ;
10228
    fork
10229
    begin
10230
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
10231
        do_pause(1) ;
10232
    end
10233
    begin:error_monitor2
10234
        @(error_event_int) ;
10235
        master_ok = 0 ;
10236
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
10237
    end
10238
    begin
10239
        pci_transaction_progress_monitor
10240
        (
10241
            address,                                                // expected address on PCI bus
10242
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10243
            0,                                                      // expected number of succesfull data phases
10244
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10245
            1'b1,                                                   // monitor checking/not checking number of transfers
10246
            1'b0,                                                   // monitor checking/not checking number of cycles
10247
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10248
            monitor_ok                                              // status - 1 success, 0 failure
10249
        ) ;
10250
 
10251
        @(posedge pci_clock);
10252
        #1 ;
10253
 
10254
        if (master_ok)
10255
            disable error_monitor2 ;
10256
 
10257
        if (!monitor_ok)
10258
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10259
    end
10260
    join
10261
 
10262
    master1_check_received_data = master_check_data_prev ;
10263
 
10264
    if (monitor_ok && master_ok)
10265
        test_ok ;
10266
 
10267
    in_use = 0 ;
10268
 
10269
end //main
10270
endtask // test_conf_cycle_type1_reference
10271
`endif
10272
 
10273 45 mihad
`ifdef HOST
10274
task generate_configuration_cycle ;
10275 15 mihad
    input [7:0]  bus_num ;
10276
    input [4:0]  device_num ;
10277
    input [2:0]  func_num ;
10278
    input [5:0]  reg_num ;
10279
    input [1:0]  type ;
10280
    input [3:0]  byte_enables ;
10281 45 mihad
    inout [31:0] data ;
10282
    input        read0_write1 ;
10283 15 mihad
 
10284
    reg `READ_STIM_TYPE read_data ;
10285
    reg `WB_TRANSFER_FLAGS  flags ;
10286
    reg `READ_RETURN_TYPE   read_status ;
10287
 
10288
    reg `WRITE_STIM_TYPE   write_data ;
10289
    reg `WRITE_RETURN_TYPE write_status ;
10290
 
10291 45 mihad
    reg [31:0] pci_address ;
10292 15 mihad
    reg in_use ;
10293 45 mihad
    reg ok ;
10294 15 mihad
 
10295
    reg [31:0] temp_var ;
10296 106 mihad
    integer i ;
10297 15 mihad
begin:main
10298
 
10299 106 mihad
    if (read0_write1 === 1'b0)
10300
        data = 32'hxxxx_xxxx ;
10301
 
10302 15 mihad
    if ( in_use === 1 )
10303
    begin
10304 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
10305 15 mihad
        data = 32'hxxxx_xxxx ;
10306
        disable main ;
10307
    end
10308
 
10309 45 mihad
    in_use = 1 ;
10310
 
10311
    if ( type )
10312
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10313
    else
10314 15 mihad
    begin
10315 45 mihad
        pci_address = 0 ;
10316
        pci_address[10:0] = { func_num, reg_num, type } ;
10317
        if (device_num <= 20)
10318
            pci_address[11 + device_num] = 1'b1 ;
10319
    end
10320
 
10321
    // setup flags
10322
    flags = 0 ;
10323 92 mihad
    flags`INIT_WAITS   = wb_init_waits ;
10324
    flags`SUBSEQ_WAITS = wb_subseq_waits ;
10325 45 mihad
 
10326
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10327
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10328
 
10329
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10330
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10331 106 mihad
 
10332
`ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
10333
 
10334
        write_data`WRITE_SEL = 4'b0001 ;
10335
    repeat(4)
10336
    begin
10337
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10338
 
10339
        // check if write succeeded
10340
        if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10341
        begin
10342
            $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10343
            in_use = 0 ;
10344
            disable main ;
10345
        end
10346
 
10347
        write_data`WRITE_ADDRESS = write_data`WRITE_ADDRESS + 'h1 ;
10348
        write_data`WRITE_SEL     = write_data`WRITE_SEL << 1 ;
10349
    end
10350
 
10351
`else
10352
 
10353 45 mihad
    write_data`WRITE_SEL      = 4'hF ;
10354
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10355
 
10356
    // check if write succeeded
10357
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10358
    begin
10359
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10360
        in_use = 0 ;
10361 15 mihad
        disable main ;
10362
    end
10363
 
10364 106 mihad
`endif
10365
 
10366 45 mihad
    // setup flags for wb master to handle retries and read and write data
10367
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10368
 
10369
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10370
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10371
    read_data`READ_SEL          = byte_enables ;
10372
    write_data`WRITE_SEL        = byte_enables ;
10373
    write_data`WRITE_DATA       = data ;
10374
 
10375
    ok = 0 ;
10376
 
10377 106 mihad
    temp_var = 32'hxxxx_xxxx ;
10378
 
10379
`ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
10380
 
10381
    for (i = 0 ; i < 4 ; i = i + 1)
10382 45 mihad
    begin
10383
 
10384 106 mihad
        if (byte_enables[i] === 1'b1)
10385
        begin
10386
            read_data`READ_SEL   = 4'h1 << i ;
10387
            write_data`WRITE_SEL = read_data`READ_SEL ;
10388
 
10389
`else
10390
 
10391 45 mihad
    begin
10392 106 mihad
        begin
10393 45 mihad
 
10394 106 mihad
`endif
10395
 
10396
            fork
10397
            begin
10398
                if (read0_write1 === 0)
10399
                    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10400
                else if (read0_write1 === 1)
10401
                    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10402
 
10403
 
10404
                // check if transfer succeeded
10405
                if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10406
                begin
10407
                    $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10408
                    data = 32'hxxxx_xxxx ;
10409
                    in_use = 0 ;
10410
                    disable main ;
10411
                end
10412
 
10413
            end
10414
            begin
10415
                pci_transaction_progress_monitor
10416
                (
10417
                    pci_address,                                            // expected address on PCI bus
10418
                    read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10419
                    1,                                                      // expected number of succesfull data phases
10420
                    0,                                                      // expected number of cycles the transaction will take on PCI bus
10421
                    1'b0,                                                   // monitor checking/not checking number of transfers
10422
                    1'b0,                                                   // monitor checking/not checking number of cycles
10423
                    0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10424
                    ok                                                      // status - 1 success, 0 failure
10425
                ) ;
10426
 
10427
                if (!ok)
10428
                begin
10429
                    data = 32'hxxxx_xxxx ;
10430
                    in_use = 0 ;
10431
                    disable main ;
10432
                end
10433
            end
10434
            join
10435
 
10436
        `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
10437
 
10438
            temp_var = read_status`READ_DATA ;
10439
 
10440
            if (read0_write1 === 0)
10441
            begin
10442
                case(read_data`READ_SEL)
10443
                4'b0001:data[ 7:0 ] = temp_var[ 7:0 ] ;
10444
                4'b0010:data[15:8 ] = temp_var[15:8 ] ;
10445
                4'b0100:data[23:16] = temp_var[23:16] ;
10446
                4'b1000:data[31:24] = temp_var[31:24] ;
10447
                endcase
10448
            end
10449
 
10450
        `else
10451
 
10452
            if (read0_write1 === 0)
10453
                data = read_status`READ_DATA ;
10454
 
10455
        `endif
10456
 
10457
        end
10458
        read_data`READ_ADDRESS   = read_data`READ_ADDRESS   + 1'b1 ;
10459
        write_data`WRITE_ADDRESS = write_data`WRITE_ADDRESS + 1'b1 ;
10460 45 mihad
    end
10461
 
10462
    in_use = 0 ;
10463
end
10464
endtask // generate_configuration_cycle
10465
 
10466
task test_configuration_cycle_target_abort ;
10467
    reg `READ_STIM_TYPE read_data ;
10468
    reg `WB_TRANSFER_FLAGS  flags ;
10469
    reg `READ_RETURN_TYPE   read_status ;
10470
 
10471
    reg `WRITE_STIM_TYPE   write_data ;
10472
    reg `WRITE_RETURN_TYPE write_status ;
10473
 
10474
    reg [31:0] pci_address ;
10475
    reg in_use ;
10476
    reg ok_pci ;
10477
    reg ok_wb  ;
10478
    reg ok     ;
10479
 
10480
    reg [31:0] temp_var ;
10481
 
10482
begin:main
10483
 
10484
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10485
 
10486
    if ( in_use === 1 )
10487
    begin
10488
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10489
        disable main ;
10490
    end
10491
 
10492 15 mihad
    in_use = 1 ;
10493
 
10494 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10495
 
10496 15 mihad
    // setup flags
10497
    flags = 0 ;
10498 92 mihad
    flags`INIT_WAITS   = wb_init_waits ;
10499
    flags`SUBSEQ_WAITS = wb_subseq_waits ;
10500 15 mihad
 
10501
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10502
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10503
 
10504
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10505 45 mihad
    temp_var                  = 0 ;
10506
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10507
    write_data`WRITE_DATA     = temp_var ;
10508 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10509
 
10510
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10511
 
10512
    // check if write succeeded
10513
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10514
    begin
10515
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10516 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10517
        in_use = 0 ;
10518 15 mihad
        disable main ;
10519
    end
10520
 
10521 45 mihad
    // setup flags for wb master to handle retries and read and write data
10522 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10523
 
10524 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10525
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10526 15 mihad
 
10527 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10528
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10529
    read_data`READ_SEL          = 4'hF ;
10530
    write_data`WRITE_SEL        = 4'hF ;
10531
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10532
 
10533
    ok_pci = 0 ;
10534
    ok_wb  = 1 ;
10535
 
10536
    // set target to terminate with target abort
10537
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10538
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10539
    fork
10540
    begin
10541
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10542
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10543
        begin
10544
            $display("Time %t", $time) ;
10545
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10546
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10547
            ok_wb = 0 ;
10548
        end
10549
 
10550
        config_read( 12'h4, 4'hF, temp_var ) ;
10551
        if ( temp_var[29] !== 0 )
10552
        begin
10553
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10554
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10555
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10556
            ok_wb = 0 ;
10557
        end
10558
 
10559
        if ( temp_var[28] !== 1 )
10560
        begin
10561
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10562
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10563
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10564
            ok_wb = 0 ;
10565
        end
10566
 
10567
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10568
 
10569
        if (ok !== 1)
10570
        begin
10571
            ok_wb = 0 ;
10572
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10573
            $display("Write to PCI Device Status Register failed") ;
10574
            test_fail("Write to PCI Device Status Register failed") ;
10575
        end
10576
 
10577
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10578
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10579
        begin
10580
            $display("Time %t", $time) ;
10581
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10582
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10583
            ok_wb = 0 ;
10584
        end
10585
 
10586
        config_read( 12'h4, 4'hF, temp_var ) ;
10587
        if ( temp_var[29] !== 0 )
10588
        begin
10589
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10590
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10591
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10592
            ok_wb = 0 ;
10593
        end
10594
 
10595
        if ( temp_var[28] !== 1 )
10596
        begin
10597
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10598
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10599
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10600
            ok_wb = 0 ;
10601
        end
10602
 
10603
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10604
 
10605
        if (ok !== 1)
10606
        begin
10607
            ok_wb = 0 ;
10608
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10609
            $display("Write to PCI Device Status Register failed") ;
10610
            test_fail("Write to PCI Device Status Register failed") ;
10611
        end
10612
    end
10613
    begin
10614
        pci_transaction_progress_monitor
10615
        (
10616
            pci_address,                                            // expected address on PCI bus
10617
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10618
            0,                                                      // expected number of succesfull data phases
10619
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10620
            1'b1,                                                   // monitor checking/not checking number of transfers
10621
            1'b0,                                                   // monitor checking/not checking number of cycles
10622
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10623
            ok_pci                                                  // status - 1 success, 0 failure
10624
        ) ;
10625
 
10626
        if (ok_pci)
10627
        begin
10628
            pci_transaction_progress_monitor
10629
            (
10630
                pci_address,                                            // expected address on PCI bus
10631
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10632
                0,                                                      // expected number of succesfull data phases
10633
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10634
                1'b1,                                                   // monitor checking/not checking number of transfers
10635
                1'b0,                                                   // monitor checking/not checking number of cycles
10636
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10637
                ok_pci                                                  // status - 1 success, 0 failure
10638
            ) ;
10639
        end
10640
 
10641
        if (!ok_pci)
10642
        begin
10643
            $display("Time %t", $time) ;
10644
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10645
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10646
        end
10647
    end
10648
    join
10649
 
10650
    if (ok_pci && ok_wb)
10651
    begin
10652
        test_ok ;
10653
    end
10654
 
10655
    in_use = 0 ;
10656
 
10657
    // set target to terminate normally
10658
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10659
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10660
end
10661
endtask // test_configuration_cycle_target_abort
10662
 
10663
task test_configuration_cycle_type1_generation ;
10664
    reg `READ_STIM_TYPE read_data ;
10665
    reg `WB_TRANSFER_FLAGS  flags ;
10666
    reg `READ_RETURN_TYPE   read_status ;
10667
 
10668
    reg `WRITE_STIM_TYPE   write_data ;
10669
    reg `WRITE_RETURN_TYPE write_status ;
10670
 
10671
    reg [31:0] pci_address ;
10672
    reg in_use ;
10673
    reg ok_pci ;
10674
    reg ok_wb  ;
10675
    reg ok     ;
10676
 
10677
    reg [31:0] temp_var ;
10678
 
10679
begin:main
10680
 
10681
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10682
    conf_cyc_type1_target_data = 0 ;
10683
    conf_cyc_type1_target_bus_num = 0;
10684
 
10685
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10686
 
10687
    if ( in_use === 1 )
10688
    begin
10689
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10690
        disable main ;
10691
    end
10692
 
10693
    in_use = 1 ;
10694
 
10695
    pci_address        = 32'hAAAA_AAAA ;
10696
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10697
 
10698
    // setup flags
10699
    flags = 0 ;
10700 92 mihad
    flags`INIT_WAITS   = wb_init_waits ;
10701
    flags`SUBSEQ_WAITS = wb_subseq_waits ;
10702 45 mihad
 
10703
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10704
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10705
 
10706
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10707
    write_data`WRITE_DATA     = pci_address ;
10708
    write_data`WRITE_SEL      = 4'hF ;
10709
 
10710
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10711
 
10712
    // check if write succeeded
10713
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10714
    begin
10715
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10716
        test_fail("write to configuration cycle address register was not possible") ;
10717
        in_use = 0 ;
10718
        disable main ;
10719
    end
10720
 
10721
    // setup flags for wb master to handle retries and read and write data
10722
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10723
 
10724
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10725
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10726
 
10727
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10728
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10729
    read_data`READ_SEL          = 4'hF ;
10730
    write_data`WRITE_SEL        = 4'hF ;
10731
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10732
 
10733
    ok_pci = 0 ;
10734
    ok_wb  = 1 ;
10735
 
10736
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10737
    pci_address[31:24] = 0 ;
10738
    fork
10739
    begin
10740
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10741
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10742
        begin
10743
            $display("Time %t", $time) ;
10744
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10745
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10746
            ok_wb = 0 ;
10747
        end
10748
 
10749
        config_read( 12'h4, 4'hF, temp_var ) ;
10750
        if ( temp_var[29] !== 1 )
10751
        begin
10752
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10753
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10754
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10755
            ok_wb = 0 ;
10756
        end
10757
 
10758
        if ( temp_var[28] !== 0 )
10759
        begin
10760
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10761
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10762
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10763
            ok_wb = 0 ;
10764
        end
10765
 
10766
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10767
 
10768
        if (ok !== 1)
10769
        begin
10770
            ok_wb = 0 ;
10771
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10772
            $display("Write to PCI Device Status Register failed") ;
10773
            test_fail("Write to PCI Device Status Register failed") ;
10774
        end
10775
 
10776
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10777
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10778
        begin
10779
            $display("Time %t", $time) ;
10780
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10781
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10782
            ok_wb = 0 ;
10783
        end
10784
 
10785
        config_read( 12'h4, 4'hF, temp_var ) ;
10786
        if ( temp_var[29] !== 1 )
10787
        begin
10788
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10789
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10790
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10791
            ok_wb = 0 ;
10792
        end
10793
 
10794
        if ( temp_var[28] !== 0 )
10795
        begin
10796
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10797
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10798
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10799
            ok_wb = 0 ;
10800
        end
10801
 
10802
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10803
 
10804
        if (ok !== 1)
10805
        begin
10806
            ok_wb = 0 ;
10807
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10808
            $display("Write to PCI Device Status Register failed") ;
10809
            test_fail("Write to PCI Device Status Register failed") ;
10810
        end
10811
    end
10812
    begin
10813
        pci_transaction_progress_monitor
10814
        (
10815
            pci_address,                                            // expected address on PCI bus
10816
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10817
            0,                                                      // expected number of succesfull data phases
10818
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10819
            1'b1,                                                   // monitor checking/not checking number of transfers
10820
            1'b0,                                                   // monitor checking/not checking number of cycles
10821
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10822
            ok_pci                                                  // status - 1 success, 0 failure
10823
        ) ;
10824
 
10825
        if (ok_pci)
10826
        begin
10827
            pci_transaction_progress_monitor
10828
            (
10829
                pci_address,                                            // expected address on PCI bus
10830
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10831
                0,                                                      // expected number of succesfull data phases
10832
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10833
                1'b1,                                                   // monitor checking/not checking number of transfers
10834
                1'b0,                                                   // monitor checking/not checking number of cycles
10835
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10836
                ok_pci                                                  // status - 1 success, 0 failure
10837
            ) ;
10838
        end
10839
 
10840
        if (!ok_pci)
10841
        begin
10842
            $display("Time %t", $time) ;
10843
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10844
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10845
        end
10846
    end
10847
    join
10848
 
10849
    if (ok_pci && ok_wb)
10850
    begin
10851
        test_ok ;
10852
    end
10853
 
10854
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10855
    conf_cyc_type1_target_data = 0 ;
10856
    conf_cyc_type1_target_bus_num = 8'h55;
10857
 
10858
    pci_address      = 32'h5555_5555 ;
10859
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10860
 
10861
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10862
 
10863
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10864
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10865
 
10866
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10867
    write_data`WRITE_DATA     = pci_address ;
10868
    write_data`WRITE_SEL      = 4'hF ;
10869
 
10870
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10871
 
10872
    // check if write succeeded
10873
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10874
    begin
10875
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10876
        test_fail("write to configuration cycle address register was not possible") ;
10877
        in_use = 0 ;
10878
        disable main ;
10879
    end
10880
 
10881
    // setup flags for wb master to handle retries and read and write data
10882
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10883
 
10884
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10885
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10886
 
10887
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10888
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10889
    read_data`READ_SEL          = 4'hF ;
10890
    write_data`WRITE_SEL        = 4'hF ;
10891
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10892
 
10893
    ok_pci = 0 ;
10894
    ok_wb  = 1 ;
10895
 
10896
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10897
    pci_address[31:24] = 0 ;
10898
    fork
10899
    begin
10900
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10901
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10902
        begin
10903
            $display("Time %t", $time) ;
10904
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10905
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10906
            ok_wb = 0 ;
10907
        end
10908
 
10909
        config_read( 12'h4, 4'hF, temp_var ) ;
10910
        if ( temp_var[29] !== 0 )
10911
        begin
10912
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10913
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10914
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10915
            ok_wb = 0 ;
10916
        end
10917
 
10918
        if ( temp_var[28] !== 1 )
10919
        begin
10920
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10921
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10922
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10923
            ok_wb = 0 ;
10924
        end
10925
 
10926
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10927
 
10928
        if (ok !== 1)
10929
        begin
10930
            ok_wb = 0 ;
10931
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10932
            $display("Write to PCI Device Status Register failed") ;
10933
            test_fail("Write to PCI Device Status Register failed") ;
10934
        end
10935
 
10936
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10937
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10938
        begin
10939
            $display("Time %t", $time) ;
10940
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10941
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10942
            ok_wb = 0 ;
10943
        end
10944
 
10945
        config_read( 12'h4, 4'hF, temp_var ) ;
10946
        if ( temp_var[29] !== 0 )
10947
        begin
10948
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10949
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10950
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10951
            ok_wb = 0 ;
10952
        end
10953
 
10954
        if ( temp_var[28] !== 1 )
10955
        begin
10956
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10957
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10958
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10959
            ok_wb = 0 ;
10960
        end
10961
 
10962
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10963
 
10964
        if (ok !== 1)
10965
        begin
10966
            ok_wb = 0 ;
10967
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10968
            $display("Write to PCI Device Status Register failed") ;
10969
            test_fail("Write to PCI Device Status Register failed") ;
10970
        end
10971
    end
10972
    begin
10973
        pci_transaction_progress_monitor
10974
        (
10975
            pci_address,                                            // expected address on PCI bus
10976
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10977
            0,                                                      // expected number of succesfull data phases
10978
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10979
            1'b1,                                                   // monitor checking/not checking number of transfers
10980
            1'b0,                                                   // monitor checking/not checking number of cycles
10981
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10982
            ok_pci                                                  // status - 1 success, 0 failure
10983
        ) ;
10984
 
10985
        if (ok_pci)
10986
        begin
10987
            pci_transaction_progress_monitor
10988
            (
10989
                pci_address,                                            // expected address on PCI bus
10990
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10991
                0,                                                      // expected number of succesfull data phases
10992
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10993
                1'b1,                                                   // monitor checking/not checking number of transfers
10994
                1'b0,                                                   // monitor checking/not checking number of cycles
10995
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10996
                ok_pci                                                  // status - 1 success, 0 failure
10997
            ) ;
10998
        end
10999
 
11000
        if (!ok_pci)
11001
        begin
11002
            $display("Time %t", $time) ;
11003
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11004
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11005
        end
11006
    end
11007
    join
11008
 
11009
    if (ok_pci && ok_wb)
11010
    begin
11011
        test_ok ;
11012
    end
11013
 
11014
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
11015
 
11016
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
11017
    conf_cyc_type1_target_data = 32'h5555_5555 ;
11018
    conf_cyc_type1_target_bus_num = 8'hAA;
11019
 
11020
    pci_address      = 32'hAAAA_AAAA ;
11021
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
11022
 
11023
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
11024
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11025
 
11026
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
11027
    write_data`WRITE_DATA     = pci_address ;
11028
    write_data`WRITE_SEL      = 4'hF ;
11029
 
11030
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
11031
 
11032
    // check if write succeeded
11033
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
11034
    begin
11035
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
11036
        test_fail("write to configuration cycle address register was not possible") ;
11037
        in_use = 0 ;
11038
        disable main ;
11039
    end
11040
 
11041
    // setup flags for wb master to handle retries and read and write data
11042
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
11043
 
11044
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
11045
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11046
 
11047
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
11048
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
11049
    read_data`READ_SEL          = 4'b0101 ;
11050
    write_data`WRITE_SEL        = 4'b1010 ;
11051
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
11052
 
11053
    ok_pci = 0 ;
11054
    ok_wb  = 1 ;
11055
 
11056
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
11057
    pci_address[31:24] = 0 ;
11058
 
11059
    fork
11060
    begin
11061
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
11062
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
11063
        begin
11064
            $display("Time %t", $time) ;
11065
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
11066
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
11067
            ok_wb = 0 ;
11068
        end
11069
 
11070
        config_read( 12'h4, 4'hF, temp_var ) ;
11071
        if ( temp_var[29] !== 0 )
11072
        begin
11073
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
11074
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
11075
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
11076
            ok_wb = 0 ;
11077
        end
11078
 
11079
        if ( temp_var[28] !== 0 )
11080
        begin
11081
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
11082
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
11083
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
11084
            ok_wb = 0 ;
11085
        end
11086
 
11087
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
11088
 
11089
        if (ok !== 1)
11090
        begin
11091
            ok_wb = 0 ;
11092
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11093
            $display("Write to PCI Device Status Register failed") ;
11094
            test_fail("Write to PCI Device Status Register failed") ;
11095
        end
11096
 
11097
        if (read_status`READ_DATA !== 32'hDE55_BE55)
11098
        begin
11099
            ok_wb = 0 ;
11100
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11101
            $display("Read Data provided by the bridge was not as expected!") ;
11102
            test_fail("Read Data provided by the bridge was not as expected") ;
11103
        end
11104
 
11105
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
11106
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
11107
        begin
11108
            $display("Time %t", $time) ;
11109
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
11110
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
11111
            ok_wb = 0 ;
11112
        end
11113
 
11114
        config_read( 12'h4, 4'hF, temp_var ) ;
11115
        if ( temp_var[29] !== 0 )
11116
        begin
11117
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11118
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
11119
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
11120
            ok_wb = 0 ;
11121
        end
11122
 
11123
        if ( temp_var[28] !== 0 )
11124
        begin
11125
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11126
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
11127
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
11128
            ok_wb = 0 ;
11129
        end
11130
 
11131
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
11132
 
11133
        if (ok !== 1)
11134
        begin
11135
            ok_wb = 0 ;
11136
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11137
            $display("Write to PCI Device Status Register failed") ;
11138
            test_fail("Write to PCI Device Status Register failed") ;
11139
        end
11140
 
11141
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
11142
        begin
11143
            ok_wb = 0 ;
11144
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
11145
            $display("Data written by the bridge was not as expected!") ;
11146
            test_fail("Data written by the bridge was not as expected") ;
11147
        end
11148
 
11149
    end
11150
    begin
11151
        ok = 1 ;
11152
        repeat(8)
11153
        begin
11154
            pci_transaction_progress_monitor
11155
            (
11156
                pci_address,                                            // expected address on PCI bus
11157
                `BC_CONF_READ,                                          // expected bus command on PCI bus
11158
                0,                                                      // expected number of succesfull data phases
11159
                0,                                                      // expected number of cycles the transaction will take on PCI bus
11160
                1'b1,                                                   // monitor checking/not checking number of transfers
11161
                1'b0,                                                   // monitor checking/not checking number of cycles
11162
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11163
                ok_pci                                                  // status - 1 success, 0 failure
11164
            ) ;
11165
 
11166
            if (!ok_pci)
11167
            begin
11168
                ok = 0 ;
11169
                $display("Time %t", $time) ;
11170
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11171
            end
11172
        end
11173
 
11174
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
11175
 
11176
        pci_transaction_progress_monitor
11177
        (
11178
            pci_address,                                            // expected address on PCI bus
11179
            `BC_CONF_READ,                                          // expected bus command on PCI bus
11180
            1,                                                      // expected number of succesfull data phases
11181
            0,                                                      // expected number of cycles the transaction will take on PCI bus
11182
            1'b1,                                                   // monitor checking/not checking number of transfers
11183
            1'b0,                                                   // monitor checking/not checking number of cycles
11184
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11185
            ok_pci                                                  // status - 1 success, 0 failure
11186
        ) ;
11187
 
11188
        if (!ok_pci)
11189
        begin
11190
            ok = 0 ;
11191
            $display("Time %t", $time) ;
11192
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11193
        end
11194
 
11195
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
11196
        repeat(8)
11197
        begin
11198
            pci_transaction_progress_monitor
11199
            (
11200
                pci_address,                                            // expected address on PCI bus
11201
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
11202
                0,                                                      // expected number of succesfull data phases
11203
                0,                                                      // expected number of cycles the transaction will take on PCI bus
11204
                1'b1,                                                   // monitor checking/not checking number of transfers
11205
                1'b0,                                                   // monitor checking/not checking number of cycles
11206
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11207
                ok_pci                                                  // status - 1 success, 0 failure
11208
            ) ;
11209
 
11210
            if (!ok_pci)
11211
            begin
11212
                ok = 0 ;
11213
                $display("Time %t", $time) ;
11214
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11215
            end
11216
        end
11217
 
11218
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
11219
        pci_transaction_progress_monitor
11220
        (
11221
            pci_address,                                            // expected address on PCI bus
11222
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
11223
            1,                                                      // expected number of succesfull data phases
11224
            0,                                                      // expected number of cycles the transaction will take on PCI bus
11225
            1'b1,                                                   // monitor checking/not checking number of transfers
11226
            1'b0,                                                   // monitor checking/not checking number of cycles
11227
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
11228
            ok_pci                                                  // status - 1 success, 0 failure
11229
        ) ;
11230
 
11231
        if (!ok_pci)
11232
        begin
11233
            ok = 0 ;
11234
            $display("Time %t", $time) ;
11235
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11236
        end
11237
 
11238
        if (!ok)
11239
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
11240
    end
11241
    join
11242
 
11243
    if (ok_pci && ok_wb)
11244
    begin
11245
        test_ok ;
11246
    end
11247
 
11248
    in_use = 0 ;
11249
end
11250
endtask // test_configuration_cycle_type1_generation
11251
`endif
11252
 
11253
task test_initial_conf_values ;
11254
    reg [11:0] register_offset ;
11255
    reg [31:0] expected_value ;
11256
    reg        failed ;
11257
`ifdef HOST
11258
    reg `READ_STIM_TYPE    read_data ;
11259
    reg `WB_TRANSFER_FLAGS flags ;
11260
    reg `READ_RETURN_TYPE  read_status ;
11261
 
11262
    reg `WRITE_STIM_TYPE   write_data ;
11263
    reg `WRITE_RETURN_TYPE write_status ;
11264
begin
11265
    failed     = 0 ;
11266
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11267
    flags      = 0 ;
11268
    read_data  = 0 ;
11269
    write_data = 0 ;
11270
 
11271
    read_data`READ_SEL = 4'hF ;
11272
 
11273 92 mihad
    flags`INIT_WAITS           = wb_init_waits ;
11274
    flags`SUBSEQ_WAITS         = wb_subseq_waits ;
11275 45 mihad
 
11276
    // test MEM/IO map bit initial value in each PCI BAR
11277
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
11278
 
11279
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11280
 
11281 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11282
 
11283 45 mihad
    `ifdef NO_CNF_IMAGE
11284
        `ifdef PCI_IMAGE0
11285
            if (`PCI_AM0)
11286
                expected_value = `PCI_BA0_MEM_IO ;
11287
            else
11288
                expected_value = 32'h0000_0000 ;
11289
        `else
11290
            expected_value = 32'h0000_0000 ;
11291
        `endif
11292
    `else
11293
        expected_value = 32'h0000_0000 ;
11294
    `endif
11295
 
11296 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11297
    begin
11298 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
11299
        failed = 1 ;
11300 15 mihad
    end
11301 45 mihad
    else
11302
    begin
11303
        if (read_status`READ_DATA !== expected_value)
11304
        begin
11305
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
11306
            failed = 1 ;
11307
        end
11308
    end
11309 15 mihad
 
11310 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
11311 15 mihad
 
11312 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11313
 
11314
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11315
 
11316
    if (`PCI_AM1)
11317
        expected_value = `PCI_BA1_MEM_IO ;
11318
    else
11319
        expected_value = 32'h0000_0000 ;
11320
 
11321
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11322
    begin
11323
        test_fail("read from P_BA1 register didn't succeede") ;
11324
        failed = 1 ;
11325
    end
11326
    else
11327
    begin
11328
        if (read_status`READ_DATA !== expected_value)
11329
        begin
11330
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
11331
            failed = 1 ;
11332
        end
11333
    end
11334
 
11335
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
11336
 
11337
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11338
 
11339
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11340
 
11341
    `ifdef PCI_IMAGE2
11342
        if (`PCI_AM2)
11343
            expected_value = `PCI_BA2_MEM_IO ;
11344
        else
11345
            expected_value = 32'h0000_0000 ;
11346 15 mihad
    `else
11347 45 mihad
        expected_value = 32'h0000_0000 ;
11348
    `endif
11349 15 mihad
 
11350 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11351
    begin
11352
        test_fail("read from P_BA2 register didn't succeede") ;
11353
        failed = 1 ;
11354
    end
11355
    else
11356
    begin
11357
        if (read_status`READ_DATA !== expected_value)
11358
        begin
11359
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
11360
            failed = 1 ;
11361
        end
11362
    end
11363 15 mihad
 
11364 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
11365
 
11366
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11367
 
11368
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11369
 
11370
    `ifdef PCI_IMAGE3
11371
        if (`PCI_AM3)
11372
            expected_value = `PCI_BA3_MEM_IO ;
11373
        else
11374
            expected_value = 32'h0000_0000 ;
11375
    `else
11376
        expected_value = 32'h0000_0000 ;
11377 15 mihad
    `endif
11378 45 mihad
 
11379
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11380
    begin
11381
        test_fail("read from P_BA3 register didn't succeede") ;
11382
        failed = 1 ;
11383
    end
11384
    else
11385
    begin
11386
        if (read_status`READ_DATA !== expected_value)
11387
        begin
11388
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
11389
            failed = 1 ;
11390
        end
11391
    end
11392
 
11393
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
11394
 
11395
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11396
 
11397
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11398
 
11399
    `ifdef PCI_IMAGE4
11400
        if (`PCI_AM4)
11401
            expected_value = `PCI_BA4_MEM_IO ;
11402
        else
11403
            expected_value = 32'h0000_0000 ;
11404
    `else
11405
        expected_value = 32'h0000_0000 ;
11406 15 mihad
    `endif
11407
 
11408 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11409
    begin
11410
        test_fail("read from P_BA4 register didn't succeede") ;
11411
        failed = 1 ;
11412
    end
11413
    else
11414
    begin
11415
        if (read_status`READ_DATA !== expected_value)
11416
        begin
11417
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11418
            failed = 1 ;
11419
        end
11420
    end
11421 15 mihad
 
11422 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11423 15 mihad
 
11424 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11425
 
11426
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11427
 
11428
    `ifdef PCI_IMAGE5
11429
        if(`PCI_AM5)
11430
            expected_value = `PCI_BA5_MEM_IO ;
11431
        else
11432
            expected_value = 32'h0000_0000 ;
11433
    `else
11434
        expected_value = 32'h0000_0000 ;
11435
    `endif
11436
 
11437
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11438
    begin
11439
        test_fail("read from P_BA5 register didn't succeede") ;
11440
        failed = 1 ;
11441
    end
11442
    else
11443
    begin
11444
        if (read_status`READ_DATA !== expected_value)
11445
        begin
11446
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11447
            failed = 1 ;
11448
        end
11449
    end
11450
 
11451
    // test Address Mask initial values
11452
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11453
 
11454
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11455
 
11456
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11457
 
11458
    `ifdef NO_CNF_IMAGE
11459
        `ifdef PCI_IMAGE0
11460
            expected_value = {`PCI_AM0, 12'h000};
11461
 
11462
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11463
        `else
11464
            expected_value = 32'h0000_0000 ;
11465
        `endif
11466
    `else
11467
        expected_value = 32'hFFFF_FFFF ;
11468
 
11469
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11470
    `endif
11471
 
11472
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11473
    begin
11474
        test_fail("read from P_AM0 register didn't succeede") ;
11475
        failed = 1 ;
11476
    end
11477
    else
11478
    begin
11479
        if (read_status`READ_DATA !== expected_value)
11480
        begin
11481
            test_fail("AM0 initial value was not set as defined");
11482
            failed = 1 ;
11483
        end
11484
    end
11485
 
11486
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11487
 
11488
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11489
 
11490
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11491
 
11492
    expected_value = {`PCI_AM1, 12'h000};
11493
 
11494
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11495
 
11496
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11497
    begin
11498
        test_fail("read from P_AM1 register didn't succeede") ;
11499
        failed = 1 ;
11500
    end
11501
    else
11502
    begin
11503
        if (read_status`READ_DATA !== expected_value)
11504
        begin
11505
            test_fail("AM1 initial value was not set as defined");
11506
            failed = 1 ;
11507
        end
11508
    end
11509
 
11510
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11511
 
11512
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11513
 
11514
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11515
 
11516
    `ifdef PCI_IMAGE2
11517
        expected_value = {`PCI_AM2, 12'h000};
11518
 
11519
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11520
    `else
11521
        expected_value = 32'h0000_0000 ;
11522
    `endif
11523
 
11524
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11525
    begin
11526
        test_fail("read from P_AM2 register didn't succeede") ;
11527
        failed = 1 ;
11528
    end
11529
    else
11530
    begin
11531
        if (read_status`READ_DATA !== expected_value)
11532
        begin
11533
            test_fail("AM2 initial value was not set as defined");
11534
            failed = 1 ;
11535
        end
11536
    end
11537
 
11538
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11539
 
11540
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11541
 
11542
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11543
 
11544
    `ifdef PCI_IMAGE3
11545
        expected_value = {`PCI_AM3, 12'h000};
11546
 
11547
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11548
    `else
11549
        expected_value = 32'h0000_0000 ;
11550
    `endif
11551
 
11552
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11553
    begin
11554
        test_fail("read from P_AM3 register didn't succeede") ;
11555
        failed = 1 ;
11556
    end
11557
    else
11558
    begin
11559
        if (read_status`READ_DATA !== expected_value)
11560
        begin
11561
            test_fail("AM3 initial value was not set as defined");
11562
            failed = 1 ;
11563
        end
11564
    end
11565
 
11566
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11567
 
11568
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11569
 
11570
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11571
 
11572
    `ifdef PCI_IMAGE4
11573
        expected_value = {`PCI_AM4, 12'h000};
11574
 
11575
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11576
    `else
11577
        expected_value = 32'h0000_0000 ;
11578
    `endif
11579
 
11580
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11581
    begin
11582
        test_fail("read from P_AM4 register didn't succeede") ;
11583
        failed = 1 ;
11584
    end
11585
    else
11586
    begin
11587
        if (read_status`READ_DATA !== expected_value)
11588
        begin
11589
            test_fail("AM4 initial value was not set as defined");
11590
            failed = 1 ;
11591
        end
11592
    end
11593
 
11594
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11595
 
11596
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11597
 
11598
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11599
 
11600
    `ifdef PCI_IMAGE5
11601
        expected_value = {`PCI_AM5, 12'h000};
11602
 
11603
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11604
    `else
11605
        expected_value = 32'h0000_0000 ;
11606
    `endif
11607
 
11608
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11609
    begin
11610
        test_fail("read from P_AM5 register didn't succeede") ;
11611
        failed = 1 ;
11612
    end
11613
    else
11614
    begin
11615
        if (read_status`READ_DATA !== expected_value)
11616
        begin
11617
            test_fail("AM5 initial value was not set as defined");
11618
            failed = 1 ;
11619
        end
11620
    end
11621
 
11622
`endif
11623
 
11624
`ifdef GUEST
11625
    reg [31:0] read_data ;
11626
begin
11627
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11628
    failed    = 0 ;
11629
 
11630
    // check all images' BARs
11631
 
11632
    // BAR0
11633
    configuration_cycle_read
11634
    (
11635
        8'h00,                          // bus number [7:0]
11636
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11637
        3'h0,                           // function number [2:0]
11638
        6'h4,                           // register number [5:0]
11639
        2'h0,                           // type [1:0]
11640
        4'hF,                           // byte enables [3:0]
11641
        read_data                       // data returned from configuration read [31:0]
11642
    ) ;
11643
 
11644
    expected_value = 32'h0000_0000 ;
11645
 
11646
    if( read_data !== expected_value)
11647
    begin
11648
        test_fail("initial value of BAR0 register not as expected") ;
11649
        failed = 1 ;
11650
    end
11651
 
11652
    // BAR1
11653
    configuration_cycle_read
11654
    (
11655
        8'h00,                          // bus number [7:0]
11656
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11657
        3'h0,                           // function number [2:0]
11658
        6'h5,                           // register number [5:0]
11659
        2'h0,                           // type [1:0]
11660
        4'hF,                           // byte enables [3:0]
11661
        read_data                       // data returned from configuration read [31:0]
11662
    ) ;
11663
 
11664
    if (`PCI_AM1)
11665
        expected_value = `PCI_BA1_MEM_IO ;
11666
    else
11667
        expected_value = 32'h0000_0000 ;
11668
 
11669
    if( read_data !== expected_value)
11670
    begin
11671
        test_fail("initial value of BAR1 register not as expected") ;
11672
        failed = 1 ;
11673
    end
11674
 
11675
    // BAR2
11676
    configuration_cycle_read
11677
    (
11678
        8'h00,                          // bus number [7:0]
11679
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11680
        3'h0,                           // function number [2:0]
11681
        6'h6,                           // register number [5:0]
11682
        2'h0,                           // type [1:0]
11683
        4'hF,                           // byte enables [3:0]
11684
        read_data                       // data returned from configuration read [31:0]
11685
    ) ;
11686
 
11687
    `ifdef PCI_IMAGE2
11688
    if (`PCI_AM2)
11689
        expected_value = `PCI_BA2_MEM_IO ;
11690
    else
11691
        expected_value = 32'h0000_0000 ;
11692
    `else
11693
    expected_value = 32'h0 ;
11694
    `endif
11695
 
11696
    if( read_data !== expected_value)
11697
    begin
11698
        test_fail("initial value of BAR2 register not as expected") ;
11699
        failed = 1 ;
11700
    end
11701
 
11702
    // BAR3
11703
    configuration_cycle_read
11704
    (
11705
        8'h00,                          // bus number [7:0]
11706
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11707
        3'h0,                           // function number [2:0]
11708
        6'h7,                           // register number [5:0]
11709
        2'h0,                           // type [1:0]
11710
        4'hF,                           // byte enables [3:0]
11711
        read_data                       // data returned from configuration read [31:0]
11712
    ) ;
11713
 
11714
    `ifdef PCI_IMAGE3
11715
    if(`PCI_AM3)
11716
        expected_value = `PCI_BA3_MEM_IO ;
11717
    else
11718
        expected_value = 32'h0000_0000 ;
11719
    `else
11720
    expected_value = 32'h0 ;
11721
    `endif
11722
 
11723
    if( read_data !== expected_value)
11724
    begin
11725
        test_fail("initial value of BAR3 register not as expected") ;
11726
        failed = 1 ;
11727
    end
11728
 
11729
    // BAR4
11730
    configuration_cycle_read
11731
    (
11732
        8'h00,                          // bus number [7:0]
11733
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11734
        3'h0,                           // function number [2:0]
11735
        6'h8,                           // register number [5:0]
11736
        2'h0,                           // type [1:0]
11737
        4'hF,                           // byte enables [3:0]
11738
        read_data                       // data returned from configuration read [31:0]
11739
    ) ;
11740
 
11741
    `ifdef PCI_IMAGE4
11742
    if (`PCI_AM4)
11743
        expected_value = `PCI_BA4_MEM_IO ;
11744
    else
11745
        expected_value = 32'h0000_0000 ;
11746
    `else
11747
    expected_value = 32'h0 ;
11748
    `endif
11749
 
11750
    if( read_data !== expected_value)
11751
    begin
11752
        test_fail("initial value of BAR4 register not as expected") ;
11753
        failed = 1 ;
11754
    end
11755
 
11756
    // BAR5
11757
    configuration_cycle_read
11758
    (
11759
        8'h00,                          // bus number [7:0]
11760
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11761
        3'h0,                           // function number [2:0]
11762
        6'h9,                           // register number [5:0]
11763
        2'h0,                           // type [1:0]
11764
        4'hF,                           // byte enables [3:0]
11765
        read_data                       // data returned from configuration read [31:0]
11766
    ) ;
11767
 
11768
    `ifdef PCI_IMAGE5
11769
    if(`PCI_AM5)
11770
        expected_value = `PCI_BA5_MEM_IO ;
11771
    else
11772
        expected_value = 32'h0000_0000 ;
11773
    `else
11774
    expected_value = 32'h0 ;
11775
    `endif
11776
 
11777
    if( read_data !== expected_value)
11778
    begin
11779
        test_fail("initial value of BAR5 register not as expected") ;
11780
        failed = 1 ;
11781
    end
11782
 
11783
    // write all 1s to BAR0
11784
    read_data = 32'hFFFF_FFFF ;
11785
 
11786
    // BAR0
11787
    configuration_cycle_write
11788
    (
11789
        8'h00,                          // bus number [7:0]
11790
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11791
        3'h0,                           // function number [2:0]
11792
        6'h4,                           // register number [5:0]
11793
        2'h0,                           // type [1:0]
11794
        4'hF,                           // byte enables [3:0]
11795
        read_data                       // data to write [31:0]
11796
    ) ;
11797
 
11798
    expected_value = 32'hFFFF_FFFF ;
11799
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11800
 
11801
    configuration_cycle_read
11802
    (
11803
        8'h00,                          // bus number [7:0]
11804
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11805
        3'h0,                           // function number [2:0]
11806
        6'h4,                           // register number [5:0]
11807
        2'h0,                           // type [1:0]
11808
        4'hF,                           // byte enables [3:0]
11809
        read_data                       // data to write [31:0]
11810
    ) ;
11811
 
11812
    if ( read_data !== expected_value )
11813
    begin
11814
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11815
        failed = 1 ;
11816
    end
11817
 
11818
    // write all 1s to BAR1
11819
    read_data = 32'hFFFF_FFFF ;
11820
 
11821
    // BAR1
11822
    configuration_cycle_write
11823
    (
11824
        8'h00,                          // bus number [7:0]
11825
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11826
        3'h0,                           // function number [2:0]
11827
        6'h5,                           // register number [5:0]
11828
        2'h0,                           // type [1:0]
11829
        4'hF,                           // byte enables [3:0]
11830
        read_data                       // data to write [31:0]
11831
    ) ;
11832
 
11833
    expected_value = {`PCI_AM1, 12'h000} ;
11834
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11835
    if (`PCI_AM1)
11836
        expected_value[0] = `PCI_BA1_MEM_IO ;
11837
 
11838
    configuration_cycle_read
11839
    (
11840
        8'h00,                          // bus number [7:0]
11841
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11842
        3'h0,                           // function number [2:0]
11843
        6'h5,                           // register number [5:0]
11844
        2'h0,                           // type [1:0]
11845
        4'hF,                           // byte enables [3:0]
11846
        read_data                       // data to write [31:0]
11847
    ) ;
11848
 
11849
    if ( read_data !== expected_value )
11850
    begin
11851
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11852
        failed = 1 ;
11853
    end
11854
 
11855
    // write all 1s to BAR2
11856
    read_data = 32'hFFFF_FFFF ;
11857
 
11858
    // BAR2
11859
    configuration_cycle_write
11860
    (
11861
        8'h00,                          // bus number [7:0]
11862
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11863
        3'h0,                           // function number [2:0]
11864
        6'h6,                           // register number [5:0]
11865
        2'h0,                           // type [1:0]
11866
        4'hF,                           // byte enables [3:0]
11867
        read_data                       // data to write [31:0]
11868
    ) ;
11869
 
11870
`ifdef PCI_IMAGE2
11871
    expected_value = {`PCI_AM2, 12'h000} ;
11872
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11873
    if (`PCI_AM2)
11874
        expected_value[0] = `PCI_BA2_MEM_IO ;
11875
`else
11876
    expected_value = 0 ;
11877
`endif
11878
 
11879
    configuration_cycle_read
11880
    (
11881
        8'h00,                          // bus number [7:0]
11882
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11883
        3'h0,                           // function number [2:0]
11884
        6'h6,                           // register number [5:0]
11885
        2'h0,                           // type [1:0]
11886
        4'hF,                           // byte enables [3:0]
11887
        read_data                       // data to write [31:0]
11888
    ) ;
11889
 
11890
    if ( read_data !== expected_value )
11891
    begin
11892
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11893
        failed = 1 ;
11894
    end
11895
 
11896
    // write all 1s to BAR3
11897
    read_data = 32'hFFFF_FFFF ;
11898
 
11899
    // BAR3
11900
    configuration_cycle_write
11901
    (
11902
        8'h00,                          // bus number [7:0]
11903
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11904
        3'h0,                           // function number [2:0]
11905
        6'h7,                           // register number [5:0]
11906
        2'h0,                           // type [1:0]
11907
        4'hF,                           // byte enables [3:0]
11908
        read_data                       // data to write [31:0]
11909
    ) ;
11910
 
11911
`ifdef PCI_IMAGE3
11912
    expected_value = {`PCI_AM3, 12'h000} ;
11913
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11914
    if(`PCI_AM3)
11915
        expected_value[0] = `PCI_BA3_MEM_IO ;
11916
`else
11917
    expected_value = 0 ;
11918
`endif
11919
 
11920
    configuration_cycle_read
11921
    (
11922
        8'h00,                          // bus number [7:0]
11923
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11924
        3'h0,                           // function number [2:0]
11925
        6'h7,                           // register number [5:0]
11926
        2'h0,                           // type [1:0]
11927
        4'hF,                           // byte enables [3:0]
11928
        read_data                       // data to write [31:0]
11929
    ) ;
11930
 
11931
    if ( read_data !== expected_value )
11932
    begin
11933
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11934
        failed = 1 ;
11935
    end
11936
 
11937
    // write all 1s to BAR4
11938
    read_data = 32'hFFFF_FFFF ;
11939
 
11940
    // BAR4
11941
    configuration_cycle_write
11942
    (
11943
        8'h00,                          // bus number [7:0]
11944
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11945
        3'h0,                           // function number [2:0]
11946
        6'h8,                           // register number [5:0]
11947
        2'h0,                           // type [1:0]
11948
        4'hF,                           // byte enables [3:0]
11949
        read_data                       // data to write [31:0]
11950
    ) ;
11951
 
11952
`ifdef PCI_IMAGE4
11953
    expected_value = {`PCI_AM4, 12'h000} ;
11954
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11955
    if(`PCI_AM4)
11956
        expected_value[0] = `PCI_BA4_MEM_IO ;
11957
`else
11958
    expected_value = 0 ;
11959
`endif
11960
 
11961
    configuration_cycle_read
11962
    (
11963
        8'h00,                          // bus number [7:0]
11964
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11965
        3'h0,                           // function number [2:0]
11966
        6'h8,                           // register number [5:0]
11967
        2'h0,                           // type [1:0]
11968
        4'hF,                           // byte enables [3:0]
11969
        read_data                       // data to write [31:0]
11970
    ) ;
11971
 
11972
    if ( read_data !== expected_value )
11973
    begin
11974
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11975
        failed = 1 ;
11976
    end
11977
 
11978
    // write all 1s to BAR5
11979
    read_data = 32'hFFFF_FFFF ;
11980
 
11981
    // BAR5
11982
    configuration_cycle_write
11983
    (
11984
        8'h00,                          // bus number [7:0]
11985
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11986
        3'h0,                           // function number [2:0]
11987
        6'h9,                           // register number [5:0]
11988
        2'h0,                           // type [1:0]
11989
        4'hF,                           // byte enables [3:0]
11990
        read_data                       // data to write [31:0]
11991
    ) ;
11992
 
11993
`ifdef PCI_IMAGE5
11994
    expected_value = {`PCI_AM5, 12'h000} ;
11995
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11996
    if(`PCI_AM5)
11997
        expected_value[0] = `PCI_BA5_MEM_IO ;
11998
`else
11999
    expected_value = 0 ;
12000
`endif
12001
 
12002
    configuration_cycle_read
12003
    (
12004
        8'h00,                          // bus number [7:0]
12005
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
12006
        3'h0,                           // function number [2:0]
12007
        6'h9,                           // register number [5:0]
12008
        2'h0,                           // type [1:0]
12009
        4'hF,                           // byte enables [3:0]
12010
        read_data                       // data to write [31:0]
12011
    ) ;
12012
 
12013
    if ( read_data !== expected_value )
12014
    begin
12015
        test_fail("BAR5 value was not masked correctly during configuration read") ;
12016
        failed = 1 ;
12017
    end
12018
`endif
12019
 
12020
    if (!failed)
12021
        test_ok ;
12022
end
12023
endtask
12024
 
12025 15 mihad
task display_warning;
12026
    input [31:0] error_address ;
12027
    input [31:0] expected_data ;
12028
    input [31:0] actual ;
12029
begin
12030
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
12031
end
12032
endtask // display warning
12033
 
12034
/*############################################################################
12035
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
12036
=====================
12037
############################################################################*/
12038
 
12039
// Task reslease the PCI bus for 'delay' clocks
12040
task do_pause;
12041
  input  [15:0] delay;
12042
  reg    [15:0] cnt;
12043
  begin
12044
    test_start <= 1'b0;  // no device is allowed to take this
12045
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
12046
    begin
12047
      if (~pci_reset_comb)
12048
      begin
12049
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
12050
      end
12051
      `NO_ELSE;
12052
    end
12053
  end
12054
endtask // do_pause
12055
 
12056
// Reference task for using pci_behavioral_master! (from Blue Beaver)
12057
task DO_REF;
12058
  input  [79:0] name;
12059
  input  [2:0] master_number;
12060
  input  [PCI_BUS_DATA_RANGE:0] address;
12061
  input  [3:0] command;
12062
  input  [PCI_BUS_DATA_RANGE:0] data;
12063
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
12064
  input  [9:0] size;
12065
  input   make_addr_par_error, make_data_par_error;
12066
  input  [7:0] master_wait_states;
12067
  input  [7:0] target_wait_states;
12068
  input  [1:0] target_devsel_speed;
12069
  input   fast_back_to_back;
12070
  input  [2:0] target_termination;
12071
  input   expect_master_abort;
12072
  reg     waiting;
12073
  begin
12074
// Cautiously wait for previous command to be done
12075
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
12076
    begin
12077
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
12078
      begin
12079
        if (~pci_reset_comb)
12080
        begin
12081
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
12082
        end
12083
        `NO_ELSE;
12084
      end
12085
      else
12086
      begin
12087
        waiting = 1'b0;  // ready to do next command
12088
      end
12089
    end
12090
    next_test_name[79:0] <= name[79:0];
12091
    test_master_number <= master_number[2:0];
12092
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
12093
    test_command[3:0] <= command[3:0] ;
12094
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
12095
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
12096
    test_size <= size;
12097
    test_make_addr_par_error <= make_addr_par_error;
12098
    test_make_data_par_error <= make_data_par_error;
12099 92 mihad
    test_master_initial_wait_states <= pci_init_waits ;
12100
    test_master_subsequent_wait_states <= pci_subseq_waits ;
12101 15 mihad
    test_target_initial_wait_states <= target_wait_states[7:4];
12102
    test_target_subsequent_wait_states <= target_wait_states[3:0];
12103
    test_target_devsel_speed <= target_devsel_speed[1:0];
12104
    test_fast_back_to_back <= fast_back_to_back;
12105
    test_target_termination <= target_termination[2:0];
12106
    test_expect_master_abort <= expect_master_abort;
12107
    test_start <= 1'b1;
12108
    if (~pci_reset_comb)
12109
    begin
12110
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
12111
    end
12112
    `NO_ELSE;
12113
// wait for new command to start
12114
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
12115
    begin
12116
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
12117
      begin
12118
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
12119
      end
12120
      else
12121
      begin
12122
        waiting = 1'b0;  // ready to do next command
12123
      end
12124
    end
12125
  end
12126
endtask // DO_REF
12127
 
12128
// Use Macros defined in pci_defines.vh as paramaters
12129
 
12130
// DO_REF (name[79:0], master_number[2:0],
12131
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
12132
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
12133
//          make_addr_par_error, make_data_par_error,
12134
//          master_wait_states[8:0], target_wait_states[8:0],
12135
//          target_devsel_speed[1:0], fast_back_to_back,
12136
//          target_termination[2:0],
12137
//          expect_master_abort);
12138
//
12139
// Example:
12140
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
12141
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
12142
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
12143
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
12144
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
12145
 
12146
// Access a location with no high-order bits set, assuring that no device responds
12147
task PCIU_CONFIG_READ_MASTER_ABORT;
12148
  input  [79:0] name;
12149
  input  [2:0] master_number;
12150 51 mihad
  input  [31:0] address ;
12151
  input  [3:0] be ;
12152 15 mihad
  begin
12153 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
12154
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
12155
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
12156 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
12157
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
12158
  end
12159
endtask // PCIU_CONFIG_READ_MASTER_ABORT
12160
 
12161
// Access a location with no high-order bits set, assuring that no device responds
12162
task PCIU_CONFIG_WRITE_MASTER_ABORT;
12163
  input  [79:0] name;
12164
  input  [2:0] master_number;
12165 51 mihad
  input  [31:0] address ;
12166
  input  [3:0] be ;
12167 15 mihad
  begin
12168 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
12169
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
12170
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
12171 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
12172
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
12173
  end
12174
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
12175
 
12176
// Access a location with no high-order bits set, assuring that no device responds
12177
task PCIU_MEM_READ_MASTER_ABORT;
12178
  input  [79:0] name;
12179
  input  [2:0] master_number;
12180
  input  [9:0] size;
12181
  begin
12182
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
12183
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
12184
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
12185
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
12186
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
12187
  end
12188
endtask // PCIU_MEM_READ_MASTER_ABORT
12189
 
12190
// Access a location with no high-order bits set, assuring that no device responds
12191
task PCIU_MEM_WRITE_MASTER_ABORT;
12192
  input  [79:0] name;
12193
  input  [2:0] master_number;
12194
  input  [9:0] size;
12195
  begin
12196
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
12197
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
12198
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
12199
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
12200
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
12201
  end
12202
endtask // PCIU_MEM_WRITE_MASTER_ABORT
12203
 
12204
// Do variable length transfers with various paramaters
12205
task PCIU_CONFIG_READ;
12206
  input  [79:0] name;
12207
  input  [2:0] master_number;
12208
  input  [PCI_BUS_DATA_RANGE:0] address;
12209
  input  [PCI_BUS_DATA_RANGE:0] data;
12210
  input  [3:0] be ;
12211
  input  [9:0] size;
12212
  input  [7:0] master_wait_states;
12213
  input  [7:0] target_wait_states;
12214
  input  [1:0] target_devsel_speed;
12215
  input  [2:0] target_termination;
12216
  begin
12217
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12218
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
12219
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12220
              8'h0_0, target_wait_states[7:0],
12221
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12222
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12223
  end
12224
endtask // PCIU_CONFIG_READ
12225
 
12226
task PCIU_CONFIG_WRITE;
12227
  input  [79:0] name;
12228
  input  [2:0] master_number;
12229
  input  [PCI_BUS_DATA_RANGE:0] address;
12230
  input  [PCI_BUS_DATA_RANGE:0] data;
12231
  input  [3:0] be ;
12232
  input  [9:0] size;
12233
  input  [7:0] master_wait_states;
12234
  input  [7:0] target_wait_states;
12235
  input  [1:0] target_devsel_speed;
12236
  input  [2:0] target_termination;
12237
  begin
12238
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12239
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
12240
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12241
              8'h0_0, target_wait_states[7:0],
12242
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12243
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12244
  end
12245
endtask // PCIU_CONFIG_WRITE
12246
 
12247
task PCIU_READ;
12248
  input  [2:0] master_number;
12249
  input  [PCI_BUS_DATA_RANGE:0] address;
12250
  input  [3:0] command;
12251
  input  [PCI_BUS_DATA_RANGE:0] data;
12252
  input  [3:0] byte_en;
12253
  input  [9:0] size;
12254
  input  [7:0] master_wait_states;
12255
  input  [7:0] target_wait_states;
12256
  input  [1:0] target_devsel_speed;
12257
  input  [2:0] target_termination;
12258
  reg    [79:0] name;
12259
  begin
12260
    if (command == `BC_MEM_READ)
12261
        name = "MEM_READ  " ;
12262
    else if (command == `BC_MEM_READ_LN)
12263
        name = "MEM_RD_LN " ;
12264
    else if (command == `BC_MEM_READ_MUL )
12265
        name = "MEM_RD_MUL" ;
12266
    else
12267
        name = "WRONG_READ" ;
12268
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12269
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12270
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12271
              8'h0_0, target_wait_states[7:0],
12272
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12273
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12274
  end
12275
endtask // PCIU_READ
12276
 
12277
task PCIU_MEM_READ;
12278
  input  [79:0] name;
12279
  input  [2:0] master_number;
12280
  input  [PCI_BUS_DATA_RANGE:0] address;
12281
  input  [PCI_BUS_DATA_RANGE:0] data;
12282
  input  [9:0] size;
12283
  input  [7:0] master_wait_states;
12284
  input  [7:0] target_wait_states;
12285
  input  [1:0] target_devsel_speed;
12286
  input  [2:0] target_termination;
12287
  begin
12288
 
12289
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12290
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12291
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12292
              8'h0_0, target_wait_states[7:0],
12293
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12294
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12295
  end
12296
endtask // PCIU_MEM_READ
12297
 
12298
task PCIU_IO_READ;
12299
  input  [2:0] master_number;
12300
  input  [PCI_BUS_DATA_RANGE:0] address;
12301
  input  [PCI_BUS_DATA_RANGE:0] data;
12302
  input  [3:0] byte_en ;
12303
  input  [9:0] size;
12304
  input  [2:0] target_termination ;
12305
  begin
12306
 
12307
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12308
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12309
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12310
              8'h0_0, `Test_One_Zero_Target_WS,
12311
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12312
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12313
  end
12314
endtask // PCIU_IO_READ
12315
 
12316
task PCIU_IO_READ_MAKE_PERR;
12317
  input  [2:0] master_number;
12318
  input  [PCI_BUS_DATA_RANGE:0] address;
12319
  input  [PCI_BUS_DATA_RANGE:0] data;
12320
  input  [3:0] byte_en ;
12321
  input  [9:0] size;
12322
  input  [2:0] target_termination ;
12323
  begin
12324
 
12325
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12326
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12327
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12328
              8'h0_0, `Test_One_Zero_Target_WS,
12329
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12330
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12331
  end
12332
endtask // PCIU_IO_READ_MAKE_PERR
12333
 
12334
task PCIU_MEM_READ_LN;
12335
  input  [79:0] name;
12336
  input  [2:0] master_number;
12337
  input  [PCI_BUS_DATA_RANGE:0] address;
12338
  input  [PCI_BUS_DATA_RANGE:0] data;
12339
  input  [9:0] size;
12340
  input  [7:0] master_wait_states;
12341
  input  [7:0] target_wait_states;
12342
  input  [1:0] target_devsel_speed;
12343
  input  [2:0] target_termination;
12344
  begin
12345
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12346
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12347
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12348
              8'h0_0, target_wait_states[7:0],
12349
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12350
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12351
  end
12352
endtask // PCIU_MEM_READ_LN
12353
 
12354
task PCIU_MEM_READ_MUL;
12355
  input  [79:0] name;
12356
  input  [2:0] master_number;
12357
  input  [PCI_BUS_DATA_RANGE:0] address;
12358
  input  [PCI_BUS_DATA_RANGE:0] data;
12359
  input  [9:0] size;
12360
  input  [7:0] master_wait_states;
12361
  input  [7:0] target_wait_states;
12362
  input  [1:0] target_devsel_speed;
12363
  input  [2:0] target_termination;
12364
  begin
12365
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12366
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12367
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12368
              8'h0_0, target_wait_states[7:0],
12369
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12370
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12371
  end
12372
endtask // PCIU_MEM_READ_MUL
12373
 
12374
task PCIU_MEM_READ_MAKE_PERR;
12375
  input  [79:0] name;
12376
  input  [2:0] master_number;
12377
  input  [PCI_BUS_DATA_RANGE:0] address;
12378
  input  [PCI_BUS_DATA_RANGE:0] data;
12379
  input  [9:0] size;
12380
  input  [7:0] master_wait_states;
12381
  input  [7:0] target_wait_states;
12382
  input  [1:0] target_devsel_speed;
12383
  input  [2:0] target_termination;
12384
  begin
12385
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12386
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12387
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12388
              8'h0_0, target_wait_states[7:0],
12389
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12390
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12391
  end
12392
endtask // PCIU_MEM_READ_MAKE_PERR
12393
 
12394
task PCIU_MEM_WRITE;
12395
  input  [79:0] name;
12396
  input  [2:0] master_number;
12397
  input  [PCI_BUS_DATA_RANGE:0] address;
12398
  input  [PCI_BUS_DATA_RANGE:0] data;
12399
  input  [3:0] byte_en;
12400
  input  [9:0] size;
12401
  input  [7:0] master_wait_states;
12402
  input  [7:0] target_wait_states;
12403
  input  [1:0] target_devsel_speed;
12404
  input  [2:0] target_termination;
12405
  begin
12406
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12407
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12408
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12409
              8'h0_0, target_wait_states[7:0],
12410
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12411
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12412
  end
12413
endtask // PCIU_MEM_WRITE
12414
 
12415
task PCIU_IO_WRITE;
12416
  input  [2:0] master_number;
12417
  input  [PCI_BUS_DATA_RANGE:0] address;
12418
  input  [PCI_BUS_DATA_RANGE:0] data;
12419
  input  [3:0] byte_en;
12420
  input  [9:0] size;
12421
  input  [2:0] target_termination ;
12422
  begin
12423
 
12424
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12425
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12426
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12427
              8'h0_0, `Test_One_Zero_Target_WS,
12428
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12429
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12430
  end
12431
endtask // PCIU_IO_WRITE
12432
 
12433
task PCIU_IO_WRITE_MAKE_PERR ;
12434
  input  [2:0] master_number;
12435
  input  [PCI_BUS_DATA_RANGE:0] address;
12436
  input  [PCI_BUS_DATA_RANGE:0] data;
12437
  input  [3:0] byte_en;
12438
  input  [9:0] size;
12439
  input  [2:0] target_termination ;
12440
  begin
12441
 
12442
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12443
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12444
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12445
              8'h0_0, `Test_One_Zero_Target_WS,
12446
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12447
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12448
  end
12449
endtask // PCIU_IO_WRITE
12450
 
12451
task PCIU_MEM_WRITE_MAKE_SERR;
12452
  input  [79:0] name;
12453
  input  [2:0] master_number;
12454
  input  [PCI_BUS_DATA_RANGE:0] address;
12455
  input  [PCI_BUS_DATA_RANGE:0] data;
12456
  input  [9:0] size;
12457
  input  [7:0] master_wait_states;
12458
  input  [7:0] target_wait_states;
12459
  input  [1:0] target_devsel_speed;
12460
  input  [2:0] target_termination;
12461
  begin
12462
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12463
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12464
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12465
              8'h0_0, target_wait_states[7:0],
12466
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12467
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12468
  end
12469
endtask // PCIU_MEM_WRITE_MAKE_SERR
12470
 
12471
task PCIU_MEM_WRITE_MAKE_PERR;
12472
  input  [79:0] name;
12473
  input  [2:0] master_number;
12474
  input  [PCI_BUS_DATA_RANGE:0] address;
12475
  input  [PCI_BUS_DATA_RANGE:0] data;
12476
  input  [9:0] size;
12477
  input  [7:0] master_wait_states;
12478
  input  [7:0] target_wait_states;
12479
  input  [1:0] target_devsel_speed;
12480
  input  [2:0] target_termination;
12481
  begin
12482
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12483
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12484
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12485
              8'h0_0, target_wait_states[7:0],
12486
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12487
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12488
  end
12489
endtask // PCIU_MEM_WRITE
12490
 
12491
/*--------------------------------------------------------------------------
12492
Initialization CASES
12493
--------------------------------------------------------------------------*/
12494
 
12495
// Initialize the basic Config Registers of the PCI bridge target device
12496
task configure_bridge_target;
12497
    reg [11:0] offset ;
12498
    reg [31:0] data ;
12499
    `ifdef HOST
12500
    reg `WRITE_STIM_TYPE   write_data ;
12501
    reg `WB_TRANSFER_FLAGS write_flags ;
12502
    reg `WRITE_RETURN_TYPE write_status ;
12503
    `else
12504
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12505
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12506
    `endif
12507
 
12508
    reg [31:0] temp_var ;
12509
begin
12510
`ifdef HOST //  set Header
12511
    offset  = 12'h4 ; // PCI Header Command register
12512
    data    = 32'h0000_0007 ; // enable master & target operation
12513
 
12514
    write_flags                      = 0 ;
12515 92 mihad
    write_flags`INIT_WAITS           = wb_init_waits ;
12516
    write_flags`SUBSEQ_WAITS         = wb_subseq_waits ;
12517 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12518
 
12519
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12520
    write_data`WRITE_SEL      = 4'h1 ;
12521
    write_data`WRITE_DATA     = data ;
12522
 
12523
    next_test_name[79:0] <= "Init_Tar_R";
12524
 
12525
    $display(" bridge target - Enabling master and target operation!");
12526
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12527
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12528
    begin
12529
        $display("Write to configuration space failed! Time %t ", $time) ;
12530
    end
12531
 
12532
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12533
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12534
 
12535
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12536
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12537
 
12538
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12539
    write_data`WRITE_SEL      = 4'hf ;
12540
    write_data`WRITE_DATA     = data ;
12541
 
12542
 `ifdef  NO_CNF_IMAGE
12543
  `ifdef PCI_IMAGE0 //      set P_BA0
12544
 
12545
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12546
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12547
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12548
    begin
12549
        $display("Write to configuration space failed! Time %t ", $time) ;
12550
    end
12551
  `endif
12552
 `else //      set P_BA0
12553
 
12554
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12555
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12556
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12557
    begin
12558
        $display("Write to configuration space failed! Time %t ", $time) ;
12559
    end
12560
 `endif
12561
 
12562
`else // GUEST, set Header, set P_BA0
12563
    data            = 32'h0000_0007 ; // enable master & target operation
12564
    byte_enables    = 4'hF ;
12565
    $display(" bridge target - Enabling master and target operation!");
12566 45 mihad
    configuration_cycle_write(0,                        // bus number
12567
                              `TAR0_IDSEL_INDEX - 11,   // device number
12568
                              0,                        // function number
12569
                              1,                        // register number
12570
                              0,                        // type of configuration cycle
12571
                              byte_enables,             // byte enables
12572
                              data                      // data
12573 15 mihad
                             ) ;
12574
 
12575
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12576
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12577
    byte_enables = 4'hf ;
12578 45 mihad
    configuration_cycle_write(0,                        // bus number
12579
                              `TAR0_IDSEL_INDEX - 11,   // device number
12580
                              0,                        // function number
12581
                              4,                        // register number
12582
                              0,                        // type of configuration cycle
12583
                              byte_enables,             // byte enables
12584
                              data                      // data
12585 15 mihad
                             ) ;
12586
 
12587
`endif
12588
end
12589
endtask // configure_bridge_target
12590
 
12591
// Initialize the basic Config Registers of the PCI bridge target device
12592
task configure_bridge_target_base_addresses;
12593
    reg [11:0] offset ;
12594
    reg [31:0] data ;
12595
    `ifdef HOST
12596
    reg `WRITE_STIM_TYPE   write_data ;
12597
    reg `WB_TRANSFER_FLAGS write_flags ;
12598
    reg `WRITE_RETURN_TYPE write_status ;
12599
    `else
12600
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12601
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12602
    `endif
12603
 
12604
    reg [31:0] temp_var ;
12605
begin
12606
`ifdef HOST //  set Header
12607
    offset  = 12'h4 ; // PCI Header Command register
12608
    data    = 32'h0000_0007 ; // enable master & target operation
12609
 
12610
    write_flags                    = 0 ;
12611 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
12612
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
12613 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12614
 
12615
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12616
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12617
 
12618
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12619
    write_data`WRITE_SEL      = 4'h1 ;
12620
    write_data`WRITE_DATA     = data ;
12621
 
12622
    next_test_name[79:0] <= "Init_Tar_R";
12623
 
12624
    $display(" bridge target - Enabling master and target operation!");
12625
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12626
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12627
    begin
12628
        $display("Write to configuration space failed! Time %t ", $time) ;
12629
    end
12630
 
12631
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12632
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12633
 
12634
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12635
    write_data`WRITE_SEL      = 4'hf ;
12636
    write_data`WRITE_DATA     = data ;
12637
 
12638
 `ifdef  NO_CNF_IMAGE
12639
  `ifdef PCI_IMAGE0 //      set P_BA0
12640
 
12641
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12642
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12643
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12644
    begin
12645
        $display("Write to configuration space failed! Time %t ", $time) ;
12646
    end
12647
  `endif
12648
 `else //      set P_BA0
12649
 
12650
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12651
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12652
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12653
    begin
12654
        $display("Write to configuration space failed! Time %t ", $time) ;
12655
    end
12656
 `endif
12657
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12658
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12659
 
12660
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12661
    write_data`WRITE_SEL      = 4'hf ;
12662
    write_data`WRITE_DATA     = data ;
12663
 
12664
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12665
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12666
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12667
    begin
12668
        $display("Write to configuration space failed! Time %t ", $time) ;
12669
    end
12670
 `ifdef PCI_IMAGE2
12671
 
12672
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12673
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12674
 
12675
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12676
    write_data`WRITE_SEL      = 4'hf ;
12677
    write_data`WRITE_DATA     = data ;
12678
 
12679
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12680
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12681
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12682
    begin
12683
        $display("Write to configuration space failed! Time %t ", $time) ;
12684
    end
12685
 `endif
12686
 `ifdef PCI_IMAGE3
12687
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12688
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12689
 
12690
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12691
    write_data`WRITE_SEL      = 4'hf ;
12692
    write_data`WRITE_DATA     = data ;
12693
 
12694
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12695
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12696
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12697
    begin
12698
        $display("Write to configuration space failed! Time %t ", $time) ;
12699
    end
12700
 `endif
12701
 `ifdef PCI_IMAGE4
12702
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12703
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12704
 
12705
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12706
    write_data`WRITE_SEL      = 4'hf ;
12707
    write_data`WRITE_DATA     = data ;
12708
 
12709
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12710
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12711
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12712
    begin
12713
        $display("Write to configuration space failed! Time %t ", $time) ;
12714
    end
12715
 `endif
12716
 `ifdef PCI_IMAGE5
12717
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12718
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12719
 
12720
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12721
    write_data`WRITE_SEL      = 4'hf ;
12722
    write_data`WRITE_DATA     = data ;
12723
 
12724
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12725
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12726
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12727
    begin
12728
        $display("Write to configuration space failed! Time %t ", $time) ;
12729
    end
12730
 `endif
12731
 
12732
`else // GUEST, set Header, set P_BA0
12733
    data            = 32'h0000_0007 ; // enable master & target operation
12734
    byte_enables    = 4'hF ;
12735
    $display(" bridge target - Enabling master and target operation!");
12736 45 mihad
    configuration_cycle_write(0,                        // bus number
12737
                              `TAR0_IDSEL_INDEX - 11,   // device number
12738
                              0,                        // function number
12739
                              1,                        // register number
12740
                              0,                        // type of configuration cycle
12741
                              byte_enables,             // byte enables
12742
                              data                      // data
12743 15 mihad
                             ) ;
12744
 
12745
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12746
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12747
    byte_enables = 4'hf ;
12748 45 mihad
    configuration_cycle_write(0,                        // bus number
12749
                              `TAR0_IDSEL_INDEX - 11,   // device number
12750
                              0,                        // function number
12751
                              4,                        // register number
12752
                              0,                        // type of configuration cycle
12753
                              byte_enables,             // byte enables
12754
                              data                      // data
12755 15 mihad
                             ) ;
12756
 
12757
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12758
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12759
    byte_enables = 4'hf ;
12760 45 mihad
    configuration_cycle_write(0,                        // bus number
12761
                              `TAR0_IDSEL_INDEX - 11,   // device number
12762
                              0,                        // function number
12763
                              5,                        // register number
12764
                              0,                        // type of configuration cycle
12765
                              byte_enables,             // byte enables
12766
                              data                      // data
12767 15 mihad
                             ) ;
12768
 `ifdef PCI_IMAGE2
12769
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12770
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12771
    byte_enables = 4'hf ;
12772 45 mihad
    configuration_cycle_write(0,                        // bus number
12773
                              `TAR0_IDSEL_INDEX - 11,   // device number
12774
                              0,                        // function number
12775
                              6,                        // register number
12776
                              0,                        // type of configuration cycle
12777
                              byte_enables,             // byte enables
12778
                              data                      // data
12779 15 mihad
                             ) ;
12780
 `endif
12781
 `ifdef PCI_IMAGE3
12782
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12783
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12784
    byte_enables = 4'hf ;
12785 45 mihad
    configuration_cycle_write(0,                        // bus number
12786
                              `TAR0_IDSEL_INDEX - 11,   // device number
12787
                              0,                        // function number
12788
                              7,                        // register number
12789
                              0,                        // type of configuration cycle
12790
                              byte_enables,             // byte enables
12791
                              data                      // data
12792 15 mihad
                             ) ;
12793
 `endif
12794
 `ifdef PCI_IMAGE4
12795
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12796
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12797
    byte_enables = 4'hf ;
12798 45 mihad
    configuration_cycle_write(0,                        // bus number
12799
                              `TAR0_IDSEL_INDEX - 11,   // device number
12800
                              0,                        // function number
12801
                              8,                        // register number
12802
                              0,                        // type of configuration cycle
12803
                              byte_enables,             // byte enables
12804
                              data                      // data
12805 15 mihad
                             ) ;
12806
 `endif
12807
 `ifdef PCI_IMAGE5
12808
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12809
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12810
    byte_enables = 4'hf ;
12811 45 mihad
    configuration_cycle_write(0,                        // bus number
12812
                              `TAR0_IDSEL_INDEX - 11,   // device number
12813
                              0,                        // function number
12814
                              9,                        // register number
12815
                              0,                        // type of configuration cycle
12816
                              byte_enables,             // byte enables
12817
                              data                      // data
12818 15 mihad
                             ) ;
12819
 `endif
12820
`endif
12821
end
12822
endtask // configure_bridge_target_base_addresses
12823
 
12824
/*--------------------------------------------------------------------------
12825
Test CASES
12826
--------------------------------------------------------------------------*/
12827
 
12828
// function converts PCI address to WB with the same data as the pci_decoder does
12829
function [31:0] pci_to_wb_addr_convert ;
12830
 
12831
    input [31:0] pci_address ;
12832
    input [31:0] translation_address ;
12833
    input [31:0] translate ;
12834
 
12835
    reg   [31:0] temp_address ;
12836
begin
12837
    if ( translate !== 1 )
12838
    begin
12839
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12840
    end
12841
    else
12842
    begin
12843
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12844
    end
12845
 
12846
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12847
    pci_to_wb_addr_convert = temp_address ;
12848
end
12849
endfunction // pci_to_wb_addr_convert
12850
 
12851
// Test normal write and read to WB slave
12852
task test_normal_wr_rd;
12853
  input  [2:0]  Master_ID;
12854
  input  [PCI_BUS_DATA_RANGE:0] Address;
12855
  input  [PCI_BUS_DATA_RANGE:0] Data;
12856
  input  [3:0]  Be;
12857
  input  [2:0]  Image_num;
12858
  input  [9:0]  Set_size;
12859
  input         Set_addr_translation;
12860
  input         Set_prefetch_enable;
12861
  input  [7:0]  Cache_lsize;
12862
  input         Set_wb_wait_states;
12863
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12864
 
12865
  reg    [31:0] rd_address;
12866
  reg    [31:0] rd_data;
12867
  reg    [3:0]  rd_be;
12868
  reg    [11:0] addr_offset;
12869
  reg    [31:0] read_data;
12870
  reg           continue ;
12871
  reg           ok   ;
12872
  reg    [31:0] expect_address ;
12873
  reg    [31:0] expect_rd_address ;
12874
  reg           expect_we ;
12875
  reg    [9:0]  expect_length_wr ;
12876
  reg    [9:0]  expect_length_rd ;
12877
  reg    [9:0]  expect_length_rd1 ;
12878
  reg    [9:0]  expect_length_rd2 ;
12879
  reg    [3:0]  use_rd_cmd ;
12880
  integer       i ;
12881 35 mihad
  reg           error_monitor_done ;
12882 15 mihad
begin:main
12883
 
12884
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12885
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12886
    $display(" - errors will be reported, but they should not occur!");
12887
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12888
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12889
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12890
    if ( ok !== 1 )
12891
    begin
12892
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12893
        test_fail("write to P_ERR_CS register didn't succeede") ;
12894
        disable main;
12895
    end
12896
 
12897
    `ifdef  ADDR_TRAN_IMPL
12898
 
12899
    // set or clear address translation
12900
    if (Set_addr_translation)
12901
    begin
12902
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12903
        $display(" - address translation will be performed!");
12904
    end
12905
    else
12906
    begin
12907
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12908
        $display(" - address translation will not be performed!");
12909
    end
12910
    // set or clear pre-fetch enable
12911
    if (Set_prefetch_enable)
12912
    begin
12913
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12914
        $display(" - bursts can be performed!");
12915
    end
12916
    else
12917
    begin
12918
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12919
        $display(" - bursts can not be performed!");
12920
    end
12921
 
12922
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12923
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12924
    if ( ok !== 1 )
12925
    begin
12926
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12927
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12928
        disable main;
12929
    end
12930
 
12931
    // predict the address and control signals on WB bus
12932
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12933
    expect_we      = 1'b1 ; // WRITE
12934
 
12935
    `else
12936
 
12937
    // address translation is not implemented
12938
    $display("Address translation is NOT implemented for PCI images!");
12939
    // set or clear pre-fetch enable
12940
    if (Set_prefetch_enable)
12941
    begin
12942
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12943
        $display(" - bursts can be performed!");
12944
    end
12945
    else
12946
    begin
12947
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12948
        $display(" - bursts can not be performed!");
12949
    end
12950
 
12951
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12952
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12953
    if ( ok !== 1 )
12954
    begin
12955
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12956
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12957
        disable main;
12958
    end
12959
 
12960
    // predict the address and control signals on WB bus
12961
    expect_address = Address ;
12962
    expect_we      = 1'b1 ; // WRITE
12963
 
12964
    `endif
12965
 
12966
    // set WB SLAVE parameters
12967
    if (Set_wb_wait_states)
12968
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12969
    else
12970
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12971
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12972 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
12973 15 mihad
 
12974
    if ( Set_size > (`PCIW_DEPTH - 2) )
12975
    begin
12976
        expect_length_wr = `PCIW_DEPTH - 2 ;
12977
    end
12978
    else
12979
    begin
12980
        expect_length_wr = Set_size ;
12981
    end
12982
    // write through the PCI bridge to WB slave
12983
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12984
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12985
 
12986
    fork
12987
    begin
12988
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12989
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12990
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12991
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12992
        do_pause( 1 ) ;
12993
    end
12994
    begin
12995
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12996
       if ( ok !== 1 )
12997
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12998
       else
12999
           test_ok ;
13000
    end
13001
    join
13002
 
13003
    // predict the address and control signals on WB bus
13004
    expect_we      = 1'b0 ; // READ
13005
 
13006
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
13007
    $display("Memory read through PCI bridge to WB slave!");
13008
 
13009
    if ( expect_length_wr == 1 )
13010
    begin
13011
        if (Set_prefetch_enable)
13012
        begin
13013
            expect_length_rd1 = Cache_lsize ;
13014
            expect_length_rd2 = 0 ;
13015
                // If PCI behavioral master must check received DATA
13016
                master2_check_received_data = 0 ;
13017
                    master1_check_received_data = 0 ;
13018
        end
13019
        else
13020
        begin
13021
            expect_length_rd1 = 1 ;
13022
            expect_length_rd2 = 0 ;
13023
                // If PCI behavioral master must check received DATA
13024
                master2_check_received_data = 1 ;
13025
                    master1_check_received_data = 1 ;
13026
        end
13027
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13028
        expect_length_rd  = expect_length_rd1 ;
13029
    end
13030
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
13031
    begin
13032
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
13033
        expect_length_rd2 = 0 ;
13034
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13035
        expect_length_rd  = expect_length_rd1 ;
13036
                // If PCI behavioral master must check received DATA
13037
        master2_check_received_data = 1 ;
13038
            master1_check_received_data = 1 ;
13039
    end
13040
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
13041
    begin
13042
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
13043
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
13044
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13045
        expect_length_rd  = expect_length_rd1 ;
13046
                // If PCI behavioral master must check received DATA
13047
                master2_check_received_data = 1 ;
13048
            master1_check_received_data = 1 ;
13049
    end
13050
    else
13051
    begin
13052
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
13053
        begin
13054
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
13055
            expect_length_rd2 = 0 ;
13056
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13057
            expect_length_rd  = expect_length_rd1 ;
13058
                // If PCI behavioral master must check received DATA
13059
                master2_check_received_data = 0 ;
13060
                    master1_check_received_data = 0 ;
13061
        end
13062
        else
13063
        begin
13064
            if ( expect_length_wr > Cache_lsize )
13065
            begin
13066
                expect_length_rd1 = Cache_lsize ;
13067
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
13068
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
13069
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
13070
                else
13071
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13072
                expect_length_rd  = expect_length_rd1 ;
13073
                        // If PCI behavioral master must check received DATA
13074
                        master2_check_received_data = 1 ;
13075
                            master1_check_received_data = 1 ;
13076
            end
13077
            else
13078
            begin
13079
                expect_length_rd1 = Cache_lsize ;
13080
                expect_length_rd2 = 0 ;
13081
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
13082
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
13083
                else
13084
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13085
                expect_length_rd  = expect_length_wr ;
13086
                                if ( expect_length_wr == Cache_lsize )
13087
                        begin
13088
                                // If PCI behavioral master must check received DATA
13089
                                master2_check_received_data = 1 ;
13090
                                    master1_check_received_data = 1 ;
13091
                                end
13092
                                else
13093
                                begin
13094
                                // If PCI behavioral master must check received DATA
13095
                                master2_check_received_data = 0 ;
13096
                                    master1_check_received_data = 0 ;
13097
                end
13098
            end
13099
        end
13100
    end
13101
 
13102
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
13103
    expect_rd_address = expect_address ;
13104
    rd_data[31:0] = Data[31:0];
13105
    rd_be[3:0] = Be[3:0];
13106
 
13107
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
13108
    while (expect_length_rd2 > 0)
13109
    begin
13110
        // do read
13111
        $display("Read %d words!", expect_length_rd);
13112
 
13113
        fork
13114
        begin
13115
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13116
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13117
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13118
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
13119
 
13120
            wb_transaction_stop( expect_length_rd - 1) ;
13121
 
13122
            do_pause( 1 ) ;
13123
        end
13124
        begin
13125
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
13126
            if ( ok !== 1 )
13127
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
13128
 
13129
            repeat( 3 )
13130
                @(posedge pci_clock) ;
13131
 
13132
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13133
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13134
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13135
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13136
 
13137
            do_pause( 1 ) ;
13138
            while ( FRAME === 0 )
13139
                @(posedge pci_clock) ;
13140
 
13141
            while ( IRDY === 0 )
13142
                @(posedge pci_clock) ;
13143
 
13144 35 mihad
            #1 ;
13145
            if ( !error_monitor_done )
13146
                disable monitor_error_event1 ;
13147 15 mihad
        end
13148
        begin:monitor_error_event1
13149 35 mihad
            error_monitor_done = 0 ;
13150 15 mihad
            @(error_event_int) ;
13151
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13152
            ok = 0 ;
13153 35 mihad
            error_monitor_done = 1 ;
13154 15 mihad
        end
13155
        join
13156
 
13157
        // increasing the starting address for PCI master and for WB transaction monitor
13158
        rd_address = rd_address + (4 * expect_length_rd) ;
13159
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
13160
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
13161
        rd_data[31:24] = Data[31:24] + expect_length_rd;
13162
        rd_data[23:16] = Data[23:16] + expect_length_rd;
13163
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
13164
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
13165
        for (i=0; i<expect_length_rd; i=i+1)
13166
            rd_be[3:0] = {Be[2:0], Be[3]};
13167
 
13168
        // set parameters for next read
13169
        if ( expect_length_rd2 == 1 )
13170
        begin
13171
                if (Set_prefetch_enable)
13172
                begin
13173
                    expect_length_rd1 = Cache_lsize ;
13174
                    expect_length_rd2 = 0 ;
13175
                        // If PCI behavioral master must check received DATA
13176
                        master2_check_received_data = 0 ;
13177
                            master1_check_received_data = 0 ;
13178
                end
13179
                else
13180
                begin
13181
                    expect_length_rd1 = 1 ;
13182
                    expect_length_rd2 = 0 ;
13183
                        // If PCI behavioral master must check received DATA
13184
                        master2_check_received_data = 1 ;
13185
                            master1_check_received_data = 1 ;
13186
                end
13187
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13188
            expect_length_rd  = expect_length_rd1 ;
13189
        end
13190
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
13191
        begin
13192
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
13193
            expect_length_rd2 = 0 ;
13194
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13195
            expect_length_rd  = expect_length_rd1 ;
13196
                        // If PCI behavioral master must check received DATA
13197
                        master2_check_received_data = 1 ;
13198
                    master1_check_received_data = 1 ;
13199
        end
13200
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
13201
        begin
13202
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
13203
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
13204
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13205
            expect_length_rd  = expect_length_rd1 ;
13206
                        // If PCI behavioral master must check received DATA
13207
                        master2_check_received_data = 1 ;
13208
                    master1_check_received_data = 1 ;
13209
        end
13210
        else
13211
        begin
13212
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
13213
            begin
13214
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
13215
                expect_length_rd2 = 0 ;
13216
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
13217
                expect_length_rd  = expect_length_rd1 ;
13218
                        // If PCI behavioral master must check received DATA
13219
                        master2_check_received_data = 0 ;
13220
                            master1_check_received_data = 0 ;
13221
            end
13222
            else
13223
            begin
13224
                if ( expect_length_rd2 > Cache_lsize )
13225
                begin
13226
                    expect_length_rd1 = Cache_lsize ;
13227
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
13228
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
13229
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
13230
                    else
13231
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13232
                    expect_length_rd  = expect_length_rd1 ;
13233
                                // If PCI behavioral master must check received DATA
13234
                                master2_check_received_data = 1 ;
13235
                                    master1_check_received_data = 1 ;
13236
                end
13237
                else
13238
                begin
13239
                    expect_length_rd  = expect_length_rd2 ;
13240
                    expect_length_rd1 = Cache_lsize ;
13241
                    expect_length_rd2 = 0 ;
13242
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
13243
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
13244
                    else
13245
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13246
                                        if ( expect_length_rd2 == Cache_lsize )
13247
                                begin
13248
                                        // If PCI behavioral master must check received DATA
13249
                                        master2_check_received_data = 1 ;
13250
                                            master1_check_received_data = 1 ;
13251
                                        end
13252
                                        else
13253
                                        begin
13254
                                        // If PCI behavioral master must check received DATA
13255
                                        master2_check_received_data = 0 ;
13256
                                            master1_check_received_data = 0 ;
13257
                        end
13258
                end
13259
            end
13260
        end
13261
    end
13262
    // do last read
13263
    $display("Read %d words!", expect_length_rd);
13264
 
13265
    fork
13266
    begin
13267
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13268
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13269
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13270
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
13271
 
13272
        wb_transaction_stop(expect_length_rd - 1) ;
13273
        do_pause( 1 ) ;
13274
    end
13275
    begin
13276
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
13277
 
13278
        do_pause(3) ;
13279
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13280
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13281
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13282
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13283
        do_pause(1) ;
13284
 
13285
        while ( FRAME === 0 )
13286
            @(posedge pci_clock) ;
13287
 
13288
        while ( IRDY === 0 )
13289
            @(posedge pci_clock) ;
13290
 
13291 35 mihad
        #1 ;
13292
        if ( !error_monitor_done )
13293
            disable monitor_error_event2 ;
13294 15 mihad
    end
13295
    begin:monitor_error_event2
13296 35 mihad
        error_monitor_done = 0 ;
13297 15 mihad
        @(error_event_int) ;
13298
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13299
        ok = 0 ;
13300 35 mihad
        error_monitor_done = 1 ;
13301 15 mihad
    end
13302
    join
13303
 
13304
    if ( ok )
13305
        test_ok ;
13306
 
13307
    // Check that no ERRORs were reported
13308
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
13309
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
13310
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13311
    config_read( addr_offset, 4'hF, read_data ) ;
13312
    if ( read_data[8] !== 0 )
13313
    begin
13314
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
13315
        test_fail("error status was set even though no errors occured on WB bus") ;
13316
    end
13317
    else
13318
    begin
13319
        $display("No error was signaled, as expected!");
13320
        test_ok ;
13321
    end
13322
 
13323
end // main
13324
endtask // test_normal_wr_rd
13325
 
13326
// Test erroneous write to WB slave
13327
task test_wb_error_wr;
13328
  input  [2:0]  Master_ID;
13329
  input  [PCI_BUS_DATA_RANGE:0] Address;
13330
  input  [PCI_BUS_DATA_RANGE:0] Data;
13331
  input  [3:0]  Be;
13332
  input  [2:0]  Image_num;
13333
  input  [9:0]  Set_size;
13334
  input         Set_err_and_int_report;
13335
  input         Set_wb_wait_states;
13336
  input  [1:0]  Imm_BefLast_Last_error;
13337
 
13338
  reg    [11:0] addr_offset;
13339
  reg    [31:0] read_data;
13340
  reg           continue ;
13341
  reg           ok   ;
13342
  reg    [9:0]  expect_length ;
13343
  reg    [31:0] expect_address ;
13344
  reg    [0:0]  expect_we ;
13345
  reg    [31:0] rd_address;
13346
  reg    [31:0] rd_data;
13347
  reg    [3:0]  rd_be;
13348
  integer       i ;
13349
begin:main
13350
    if (Set_err_and_int_report)
13351
    begin
13352
        // enable ERROR reporting, because error must be reported and interrupt if required!
13353
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13354
        $display(" - errors will be reported when they will occur!");
13355
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
13356
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13357
        $display(" - interrupt will be reported when error will occur!");
13358
    end
13359
    else
13360
    begin
13361
        // disable ERROR reporting, because error and interrupt must not be reported!
13362
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13363
        $display(" - errors will NOT be reported when they will occur!");
13364
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
13365
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13366
        $display(" - interrupt will NOT be reported when error will occur!");
13367
    end
13368
    // enable/disable ERROR reporting
13369
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
13370
 
13371
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13372
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
13373
    if ( ok !== 1 )
13374
    begin
13375
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13376
        test_fail("PCI Error Control and Status register could not be written") ;
13377
        disable main;
13378
    end
13379
    // enable/disable INTERRUPT reporting
13380
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13381
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
13382
    if ( ok !== 1 )
13383
    begin
13384
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
13385
        test_fail("Interrupt Control register could not be written") ;
13386
        disable main;
13387
    end
13388
 
13389
    `ifdef  ADDR_TRAN_IMPL
13390
 
13391
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
13392
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13393
    config_read( addr_offset, 4'hF, read_data ) ;
13394
    if ( read_data[2] !== 0 )
13395
    begin
13396
        $display("Address translation is set for PCI image%d!", Image_num);
13397
        // predict the address and control signals on WB bus
13398
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13399
        expect_we      = 1'b1 ; // WRITE
13400
    end
13401
    else
13402
    begin
13403
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13404
        // predict the address and control signals on WB bus
13405
        expect_address = Address ;
13406
        expect_we      = 1'b1 ; // WRITE
13407
    end
13408
 
13409
    `else
13410
 
13411
    // address translation is not implemented
13412
    $display("Address translation is NOT implemented for PCI images!");
13413
    // predict the address and control signals on WB bus
13414
    expect_address = Address ;
13415
    expect_we      = 1'b1 ; // WRITE
13416
 
13417
    `endif
13418
 
13419
    if ( Set_size > (`PCIW_DEPTH - 2) )
13420
    begin
13421
        expect_length = `PCIW_DEPTH - 2 ;
13422
    end
13423
    else
13424
    begin
13425
        expect_length = Set_size ;
13426
    end
13427
 
13428
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13429
    begin
13430
        $display("ERR termination with first data!");
13431
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13432
    end
13433
    else if (Imm_BefLast_Last_error == 1)
13434
    begin
13435
        $display("ERR termination before last data!");
13436
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13437
    end
13438
    else
13439
    begin
13440
        $display("ERR termination with last data!");
13441
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13442
    end
13443
 
13444
    // write through the PCI bridge to WB slave
13445
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13446
    fork
13447
    begin
13448
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13449
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13450
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13451
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13452
        do_pause( 1 ) ;
13453
    end
13454
    begin
13455
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13456
        begin
13457
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13458
            if ( ok !== 1 )
13459
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13460
        end
13461
        else if (Imm_BefLast_Last_error == 1)
13462
        begin
13463
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13464
            if ( ok !== 1 )
13465
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13466
        end
13467
        else
13468
        begin
13469
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13470
            if ( ok !== 1 )
13471
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13472
        end
13473
    end
13474
    begin
13475
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13476
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13477 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
13478 15 mihad
        else if (Imm_BefLast_Last_error == 1)
13479
        begin
13480
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13481 92 mihad
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
13482 15 mihad
            wb_transaction_stop(expect_length-2) ;
13483
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13484 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
13485 15 mihad
        end
13486
        else
13487
        begin
13488
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13489 92 mihad
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
13490 15 mihad
            wb_transaction_stop(expect_length-1) ;
13491
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13492 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
13493 15 mihad
        end
13494
    end
13495
    join
13496
 
13497
    if ( ok )
13498
        test_ok ;
13499
 
13500
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13501
    begin
13502
        rd_data[31:0] = Data[31:0];
13503
        rd_address[31:0] = expect_address;
13504
        rd_be[3:0] = Be[3:0];
13505
    end
13506
    else if (Imm_BefLast_Last_error == 1)
13507
    begin
13508
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13509
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13510
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13511
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13512
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13513
        rd_be[3:0] = Be[3:0];
13514
        for (i=0; i<(expect_length-2); i=i+1)
13515
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13516
    end
13517
    else
13518
    begin
13519
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13520
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13521
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13522
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13523
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13524
        rd_be[3:0] = Be[3:0];
13525
        for (i=0; i<(expect_length-1); i=i+1)
13526
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13527
    end
13528
 
13529
    master2_check_received_data = 0 ;
13530
    master1_check_received_data = 0 ;
13531
 
13532
    // Check if ERRORs were reported
13533
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13534
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13535
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13536
 
13537
    ok = 1 ;
13538
    config_read( addr_offset, 4'hF, read_data ) ;
13539
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13540
    begin
13541
        $display("Error was signaled and reported, as expected!");
13542
        if (read_data[31:28] === rd_be)
13543
            $display("Byte enables written into P_ERR_CS register are as expected!");
13544
        else
13545
        begin
13546
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13547
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13548
            ok = 0 ;
13549
        end
13550
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13551
            $display("Bus command written into P_ERR_CS register is as expected!");
13552
        else
13553
        begin
13554
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13555
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13556
            ok = 0 ;
13557
        end
13558
 
13559
        if ( ok )
13560
            test_ok ;
13561
 
13562
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13563
 
13564
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13565
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13566
        config_read( addr_offset, 4'hF, read_data ) ;
13567
        if (read_data === rd_data)
13568
        begin
13569
            $display("Data written into P_ERR_DATA register is as expected!");
13570
            test_ok ;
13571
        end
13572
        else
13573
        begin
13574
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13575
            test_fail("PCI Erroneous Data register value was wrong") ;
13576
        end
13577
 
13578
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13579
 
13580
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13581
 
13582
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13583
        config_read( addr_offset, 4'hF, read_data ) ;
13584
        if (read_data === rd_address)
13585
        begin
13586
            $display("Address written into P_ERR_ADDR register is as expected!");
13587
            test_ok ;
13588
        end
13589
        else
13590
        begin
13591
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13592
            test_fail("PCI Erroneous Address register value was wrong") ;
13593
        end
13594
    end
13595
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13596
    begin
13597
        $display("Error was signaled and not reported, as expected!");
13598
        test_ok ;
13599
    end
13600
    else
13601
    begin
13602
        $display("Error was signaled and reported, as NOT expected!");
13603
        test_fail("Error status bit was set event though error reporting was disabled") ;
13604
    end
13605
 
13606
    // Check if Interrupts were reported
13607
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13608
 
13609
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13610
    ok = 1 ;
13611
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13612
    config_read( addr_offset, 4'hF, read_data ) ;
13613
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13614
    begin
13615
        $display("Interrupts was signaled and reported, as expected!");
13616
    end
13617
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13618
    begin
13619
        $display("Interrupts was signaled and not reported, as expected!");
13620
    end
13621
    else
13622
    begin
13623
        $display("Interrupt was signaled and reported, as NOT expected!");
13624
        test_fail("PCI Error Interrupt status was set when not expected") ;
13625
        ok = 0 ;
13626
    end
13627
 
13628
    `ifdef HOST
13629
    repeat( 4 )
13630
        @(posedge wb_clock) ;
13631
 
13632
    if ( INT_O === Set_err_and_int_report )
13633
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13634
    else
13635
    begin
13636
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13637
        test_fail("Interrupt request didn't have expected value") ;
13638
        ok = 0 ;
13639
    end
13640
 
13641
    `else // GUEST
13642
    repeat( 4 )
13643
        @(posedge pci_clock) ;
13644
 
13645
    if ( INTA === !Set_err_and_int_report )
13646
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13647
    else
13648
    begin
13649
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13650
        test_fail("Interrupt request didn't have expected value") ;
13651
        ok = 0 ;
13652
    end
13653
 
13654
    `endif
13655
 
13656
    if ( ok )
13657
        test_ok ;
13658
 
13659
    if (Set_err_and_int_report)
13660
    begin
13661
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13662
        $display("Error and Interrupt must be cleared!");
13663
        // clear  ERROR reporting bit
13664
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13665
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13666
        if ( ok !== 1 )
13667
        begin
13668
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13669
            test_fail("PCI Error Control and Status register could not be written to") ;
13670
            disable main;
13671
        end
13672
 
13673
        // clear INTERRUPT reporting bit
13674
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13675
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13676
        if ( ok !== 1 )
13677
        begin
13678
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13679
            test_fail("Interrupt Status register could not be written to") ;
13680
            disable main;
13681
        end
13682
 
13683
        test_ok ;
13684
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13685
        `ifdef HOST
13686
 
13687
        repeat(4)
13688
            @(posedge wb_clock) ;
13689
        if ( INT_O === 1'b0 )
13690
        begin
13691
            $display("Interrupt pin INT_O was correctly cleared!");
13692
            test_ok ;
13693
        end
13694
        else
13695
        begin
13696
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13697
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13698
            disable main;
13699
        end
13700
 
13701
        `else // GUEST
13702
 
13703
        repeat(4)
13704
            @(posedge pci_clock) ;
13705
        if ( INTA === 1'b1 )
13706
        begin
13707
            $display("Interrupt pin INTA was correctly cleared!");
13708
            test_ok ;
13709
        end
13710
        else
13711
        begin
13712
            $display("Interrupt pin INTA was NOT correctly cleared!");
13713
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13714
            disable main;
13715
        end
13716
 
13717
        `endif
13718
 
13719
    end
13720
    else
13721
    begin
13722
        $display("Error and Interrupt don't need to be cleared!");
13723
    end
13724
end // main
13725
endtask // test_wb_error_wr
13726
 
13727
task test_wb_error_rd;
13728
    reg    [11:0] addr_offset ;
13729
    reg    [11:0] ctrl_offset ;
13730
    reg    [11:0] ba_offset ;
13731
    reg    [11:0] am_offset ;
13732
    reg    [11:0] ta_offset ;
13733
    reg    [31:0] read_data;
13734
    reg           ok   ;
13735
    reg    [9:0]  expect_length ;
13736
    reg    [31:0] expect_address ;
13737
    reg    [0:0]  expect_we ;
13738
    reg    [31:0] rd_address;
13739
    reg    [31:0] rd_data;
13740
    reg    [3:0]  rd_be;
13741
    integer       i ;
13742
    reg           do_mem_aborts ;
13743
    reg           do_io_aborts ;
13744 35 mihad
    reg           error_monitor_done ;
13745 15 mihad
begin:main
13746
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13747
 
13748
    if ( target_mem_image !== -1 )
13749
    begin
13750
        do_mem_aborts = 1 ;
13751
 
13752
        if (target_mem_image === 1)
13753
        begin
13754
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13755
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13756
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13757
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13758
        end
13759
        else if (target_mem_image === 2)
13760
        begin
13761
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13762
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13763
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13764
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13765
        end
13766
        else if (target_mem_image === 3)
13767
        begin
13768
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13769
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13770
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13771
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13772
        end
13773
        else if (target_mem_image === 4)
13774
        begin
13775
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13776
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13777
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13778
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13779
        end
13780
        else if (target_mem_image === 5)
13781
        begin
13782
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13783
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13784
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13785
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13786
        end
13787
    end
13788
    else
13789
        do_mem_aborts = 0 ;
13790
 
13791
    if ( do_mem_aborts )
13792
    begin
13793
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13794
 
13795
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13796
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13797
        if ( ok !== 1 )
13798
        begin
13799
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13800
            test_fail("PCI Error Control and Status register could not be written") ;
13801
            disable main;
13802
        end
13803
 
13804
        // enable INTERRUPT reporting
13805
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13806
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13807
        if ( ok !== 1 )
13808
        begin
13809
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13810
            test_fail("Interrupt Control register could not be written") ;
13811
            disable main;
13812
        end
13813
 
13814
        addr_offset = 12'h010 + (4*target_mem_image) ;
13815
 
13816
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13817
        if ( ok !== 1 )
13818
        begin
13819
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13820
            test_fail("PCI Base Address register could not be written") ;
13821
            disable main;
13822
        end
13823
 
13824
        // disable address translation and enable prefetch so read bursts can be performed
13825
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13826
        if ( ok !== 1 )
13827
        begin
13828
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13829
            test_fail("PCI Image Control register could not be written") ;
13830
            disable main;
13831
        end
13832
 
13833
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13834
        if ( ok !== 1 )
13835
        begin
13836
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13837
            test_fail("PCI Address Mask register could not be written") ;
13838
            disable main;
13839
        end
13840
 
13841
        addr_offset = 12'h00C ;
13842
 
13843
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13844
        if ( ok !== 1 )
13845
        begin
13846
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13847
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13848
            disable main;
13849
        end
13850
 
13851
        // disable PCI master data checking
13852
        master1_check_received_data = 0 ;
13853
 
13854
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13855 92 mihad
        wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
13856 15 mihad
 
13857
 
13858
        // do a single read error terminated on WB bus
13859
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13860
 
13861
        fork
13862
        begin
13863
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13864
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13865
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13866
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13867
 
13868
            do_pause( 1 ) ;
13869
        end
13870
        begin
13871
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13872
 
13873
            if ( ok !== 1 )
13874
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13875
 
13876
            do_pause(3) ;
13877
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13878
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13879
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13880
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13881
            do_pause(1) ;
13882
 
13883
            while ( FRAME === 0 )
13884
                @(posedge pci_clock) ;
13885
 
13886
            while ( IRDY === 0 )
13887
                @(posedge pci_clock) ;
13888
 
13889 35 mihad
            #1 ;
13890
            if ( !error_monitor_done )
13891
                disable monitor_error_event1 ;
13892 15 mihad
        end
13893
        begin:monitor_error_event1
13894 35 mihad
            error_monitor_done = 0 ;
13895 15 mihad
            @(error_event_int) ;
13896
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13897
            ok = 0 ;
13898 35 mihad
            error_monitor_done = 1 ;
13899 15 mihad
        end
13900
        join
13901
 
13902
        if ( ok )
13903
            test_ok ;
13904 26 mihad
 
13905
        @(posedge pci_clock) ;
13906
        @(posedge pci_clock) ;
13907
        @(posedge wb_clock) ;
13908
        @(posedge wb_clock) ;
13909 15 mihad
 
13910
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13911
        addr_offset = 12'h004 ;
13912
        config_read(addr_offset, 4'hF, read_data) ;
13913
        ok = 1 ;
13914
        if ( read_data[27] !== 1 )
13915
        begin
13916
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13917
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13918
            ok = 0 ;
13919
        end
13920
        if ( read_data[28] !== 0 )
13921
        begin
13922
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13923
            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") ;
13924
            ok = 0 ;
13925
        end
13926
        if ( read_data[29] !== 0 )
13927
        begin
13928
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13929
            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") ;
13930
            ok = 0 ;
13931
        end
13932
 
13933
        // clear statuses
13934
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13935
        if ( !ok )
13936
        begin
13937
            test_fail("write to PCI Device Status register failed") ;
13938
            $display("Couldn't write PCI Device Status register") ;
13939
            disable main ;
13940
        end
13941
 
13942
        if ( ok )
13943
            test_ok ;
13944
 
13945
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13946
 
13947
        ok = 1 ;
13948
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13949
 
13950
        config_read(addr_offset, 4'hF, read_data) ;
13951
        if (read_data[8] !== 0)
13952
        begin
13953
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13954
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13955
            ok = 0 ;
13956
        end
13957
        else
13958
            test_ok ;
13959
 
13960
        if ( ok !== 1 )
13961
        begin
13962
            config_write(addr_offset, read_data, 4'hF, ok) ;
13963
            if ( !ok )
13964
            begin
13965
                test_fail("PCI Error Control and Status register could not be written") ;
13966
                disable main ;
13967
            end
13968
        end
13969
 
13970 92 mihad
        wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
13971 15 mihad
        fork
13972
        begin
13973
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13974
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13975
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13976
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13977
 
13978
            do_pause( 1 ) ;
13979
        end
13980
        begin
13981
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13982
 
13983
            if ( ok !== 1 )
13984
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13985
 
13986
            do_pause(3) ;
13987
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13988
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13989
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13990
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13991
            do_pause(1) ;
13992
 
13993
            while ( FRAME === 0 )
13994
                @(posedge pci_clock) ;
13995
 
13996
            while ( IRDY === 0 )
13997
                @(posedge pci_clock) ;
13998
 
13999 35 mihad
            #1 ;
14000
            if ( !error_monitor_done )
14001
                disable monitor_error_event2 ;
14002 15 mihad
        end
14003
        begin:monitor_error_event2
14004 35 mihad
            error_monitor_done = 0 ;
14005 15 mihad
            @(error_event_int) ;
14006
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14007
            ok = 0 ;
14008 35 mihad
            error_monitor_done = 1 ;
14009 15 mihad
        end
14010
        join
14011
 
14012
        if ( ok )
14013
            test_ok ;
14014
 
14015 26 mihad
        @(posedge pci_clock) ;
14016
        @(posedge pci_clock) ;
14017
        @(posedge wb_clock) ;
14018
        @(posedge wb_clock) ;
14019
 
14020 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14021
        addr_offset = 12'h004 ;
14022
        config_read(addr_offset, 4'hF, read_data) ;
14023
        ok = 1 ;
14024
        if ( read_data[27] !== 1 )
14025
        begin
14026
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14027
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14028
            ok = 0 ;
14029
        end
14030
        if ( read_data[28] !== 0 )
14031
        begin
14032
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14033
            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") ;
14034
            ok = 0 ;
14035
        end
14036
        if ( read_data[29] !== 0 )
14037
        begin
14038
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14039
            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") ;
14040
            ok = 0 ;
14041
        end
14042
 
14043
        // clear statuses
14044
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14045
        if ( !ok )
14046
        begin
14047
            test_fail("write to PCI Device Status register failed") ;
14048
            $display("Couldn't write PCI Device Status register") ;
14049
            disable main ;
14050
        end
14051
 
14052
        if ( ok )
14053
            test_ok ;
14054
 
14055
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14056
 
14057
        ok = 1 ;
14058
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14059
 
14060
        config_read(addr_offset, 4'hF, read_data) ;
14061
        if (read_data[8] !== 0)
14062
        begin
14063
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14064
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14065
            ok = 0 ;
14066
        end
14067
        else
14068
            test_ok ;
14069
 
14070
        if ( ok !== 1 )
14071
        begin
14072
            config_write(addr_offset, read_data, 4'hF, ok) ;
14073
            if ( !ok )
14074
            begin
14075
                test_fail("PCI Error Control and Status register could not be written") ;
14076
                disable main ;
14077
            end
14078
        end
14079
 
14080
        // do a single read error terminated on WB bus
14081
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
14082
 
14083 92 mihad
        wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14084 15 mihad
 
14085
        fork
14086
        begin
14087
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14088
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14089
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14090
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14091
 
14092
            do_pause( 1 ) ;
14093
        end
14094
        begin
14095
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
14096
 
14097
            if ( ok !== 1 )
14098
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14099
 
14100
            do_pause(3) ;
14101
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14102
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14103
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14104
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14105
            do_pause(1) ;
14106
 
14107
            while ( FRAME === 0 )
14108
                @(posedge pci_clock) ;
14109
 
14110
            while ( IRDY === 0 )
14111
                @(posedge pci_clock) ;
14112
 
14113 35 mihad
            if ( !error_monitor_done )
14114
                disable monitor_error_event3 ;
14115 15 mihad
        end
14116
        begin:monitor_error_event3
14117 35 mihad
            error_monitor_done = 0 ;
14118 15 mihad
            @(error_event_int) ;
14119
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14120
            ok = 0 ;
14121 35 mihad
            error_monitor_done = 1 ;
14122 15 mihad
        end
14123
        join
14124
 
14125
        if ( ok )
14126
            test_ok ;
14127
 
14128 26 mihad
        @(posedge pci_clock) ;
14129
        @(posedge pci_clock) ;
14130
        @(posedge wb_clock) ;
14131
        @(posedge wb_clock) ;
14132
 
14133 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14134
        addr_offset = 12'h004 ;
14135
        config_read(addr_offset, 4'hF, read_data) ;
14136
        ok = 1 ;
14137
        if ( read_data[27] !== 1 )
14138
        begin
14139
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14140
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14141
            ok = 0 ;
14142
        end
14143
        if ( read_data[28] !== 0 )
14144
        begin
14145
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14146
            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") ;
14147
            ok = 0 ;
14148
        end
14149
        if ( read_data[29] !== 0 )
14150
        begin
14151
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14152
            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") ;
14153
            ok = 0 ;
14154
        end
14155
 
14156
        // clear statuses
14157
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14158
        if ( !ok )
14159
        begin
14160
            test_fail("write to PCI Device Status register failed") ;
14161
            $display("Couldn't write PCI Device Status register") ;
14162
            disable main ;
14163
        end
14164
 
14165
        if ( ok )
14166
            test_ok ;
14167
 
14168
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14169
 
14170
        ok = 1 ;
14171
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14172
 
14173
        config_read(addr_offset, 4'hF, read_data) ;
14174
        if (read_data[8] !== 0)
14175
        begin
14176
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14177
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14178
            ok = 0 ;
14179
        end
14180
        else
14181
            test_ok ;
14182
 
14183
        if ( ok !== 1 )
14184
        begin
14185
            config_write(addr_offset, read_data, 4'hF, ok) ;
14186
            if ( !ok )
14187
            begin
14188
                test_fail("PCI Error Control and Status register could not be written") ;
14189
                disable main ;
14190
            end
14191
        end
14192
 
14193
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
14194
 
14195 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14196 15 mihad
 
14197
        fork
14198
        begin
14199
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14200
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14201
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14202
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14203
 
14204
            do_pause( 1 ) ;
14205
        end
14206
        begin
14207
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
14208
 
14209
            if ( ok !== 1 )
14210
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14211
 
14212
            do_pause(3) ;
14213
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14214
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14215
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14216
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14217
            do_pause(1) ;
14218
 
14219
            while ( FRAME === 0 )
14220
                @(posedge pci_clock) ;
14221
 
14222
            while ( IRDY === 0 )
14223
                @(posedge pci_clock) ;
14224
 
14225 35 mihad
            #1 ;
14226
            if ( !error_monitor_done )
14227
                disable monitor_error_event4 ;
14228 15 mihad
        end
14229
        begin:monitor_error_event4
14230 35 mihad
            error_monitor_done = 0 ;
14231 15 mihad
            @(error_event_int) ;
14232
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14233
            ok = 0 ;
14234 35 mihad
            error_monitor_done = 1 ;
14235 15 mihad
        end
14236
        begin
14237
            wb_transaction_stop( 1 ) ;
14238 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14239 15 mihad
        end
14240
        join
14241
 
14242
        if ( ok )
14243
            test_ok ;
14244
 
14245 26 mihad
        @(posedge pci_clock) ;
14246
        @(posedge pci_clock) ;
14247
        @(posedge wb_clock) ;
14248
        @(posedge wb_clock) ;
14249
 
14250 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14251
        addr_offset = 12'h004 ;
14252
        config_read(addr_offset, 4'hF, read_data) ;
14253
        ok = 1 ;
14254
        if ( read_data[27] !== 1 )
14255
        begin
14256
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14257
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14258
            ok = 0 ;
14259
        end
14260
        if ( read_data[28] !== 0 )
14261
        begin
14262
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14263
            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") ;
14264
            ok = 0 ;
14265
        end
14266
        if ( read_data[29] !== 0 )
14267
        begin
14268
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14269
            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") ;
14270
            ok = 0 ;
14271
        end
14272
 
14273
        // clear statuses
14274
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14275
        if ( !ok )
14276
        begin
14277
            test_fail("write to PCI Device Status register failed") ;
14278
            $display("Couldn't write PCI Device Status register") ;
14279
            disable main ;
14280
        end
14281
 
14282
        if ( ok )
14283
            test_ok ;
14284
 
14285
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14286
 
14287
        ok = 1 ;
14288
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14289
 
14290
        config_read(addr_offset, 4'hF, read_data) ;
14291
        if (read_data[8] !== 0)
14292
        begin
14293
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14294
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14295
            ok = 0 ;
14296
        end
14297
        else
14298
            test_ok ;
14299
 
14300
        if ( ok !== 1 )
14301
        begin
14302
            config_write(addr_offset, read_data, 4'hF, ok) ;
14303
            if ( !ok )
14304
            begin
14305
                test_fail("PCI Error Control and Status register could not be written") ;
14306
                disable main ;
14307
            end
14308
        end
14309
 
14310
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14311
 
14312 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14313 15 mihad
 
14314
        fork
14315
        begin
14316
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14317
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14318
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14319
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14320
 
14321
            do_pause( 1 ) ;
14322
        end
14323
        begin
14324
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14325
 
14326
            if ( ok !== 1 )
14327
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14328
 
14329
            do_pause(3) ;
14330
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14331
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14332
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14333
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14334
            do_pause(1) ;
14335
 
14336
            while ( FRAME === 0 )
14337
                @(posedge pci_clock) ;
14338
 
14339
            while ( IRDY === 0 )
14340
                @(posedge pci_clock) ;
14341
 
14342 35 mihad
            #1 ;
14343
            if ( !error_monitor_done )
14344
                disable monitor_error_event5 ;
14345 15 mihad
        end
14346
        begin:monitor_error_event5
14347 35 mihad
            error_monitor_done = 0 ;
14348 15 mihad
            @(error_event_int) ;
14349
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14350
            ok = 0 ;
14351 35 mihad
            error_monitor_done = 1 ;
14352 15 mihad
        end
14353
        begin
14354
            wb_transaction_stop( 3 ) ;
14355 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14356 15 mihad
        end
14357
        join
14358
 
14359
        if ( ok )
14360
            test_ok ;
14361
 
14362 26 mihad
        @(posedge pci_clock) ;
14363
        @(posedge pci_clock) ;
14364
        @(posedge wb_clock) ;
14365
        @(posedge wb_clock) ;
14366
 
14367 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14368
        addr_offset = 12'h004 ;
14369
        config_read(addr_offset, 4'hF, read_data) ;
14370
        ok = 1 ;
14371
        if ( read_data[27] !== 1 )
14372
        begin
14373
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14374
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14375
            ok = 0 ;
14376
        end
14377
        if ( read_data[28] !== 0 )
14378
        begin
14379
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14380
            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") ;
14381
            ok = 0 ;
14382
        end
14383
        if ( read_data[29] !== 0 )
14384
        begin
14385
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14386
            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") ;
14387
            ok = 0 ;
14388
        end
14389
 
14390
        // clear statuses
14391
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14392
        if ( !ok )
14393
        begin
14394
            test_fail("write to PCI Device Status register failed") ;
14395
            $display("Couldn't write PCI Device Status register") ;
14396
            disable main ;
14397
        end
14398
 
14399
        if ( ok )
14400
            test_ok ;
14401
 
14402
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14403
 
14404
        ok = 1 ;
14405
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14406
 
14407
        config_read(addr_offset, 4'hF, read_data) ;
14408
        if (read_data[8] !== 0)
14409
        begin
14410
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14411
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14412
            ok = 0 ;
14413
        end
14414
        else
14415
            test_ok ;
14416
 
14417
        if ( ok !== 1 )
14418
        begin
14419
            config_write(addr_offset, read_data, 4'hF, ok) ;
14420
            if ( !ok )
14421
            begin
14422
                test_fail("PCI Error Control and Status register could not be written") ;
14423
                disable main ;
14424
            end
14425
        end
14426
 
14427
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14428 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14429 15 mihad
        fork
14430
        begin
14431
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14432
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14433
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14434
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14435
 
14436
            do_pause( 1 ) ;
14437
        end
14438
        begin
14439
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14440
 
14441
            if ( ok !== 1 )
14442
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14443
 
14444
            do_pause(3) ;
14445
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14446
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14447
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14448
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14449
            do_pause(1) ;
14450
 
14451
            while ( FRAME === 0 )
14452
                @(posedge pci_clock) ;
14453
 
14454
            while ( IRDY === 0 )
14455
                @(posedge pci_clock) ;
14456
 
14457 35 mihad
            #1 ;
14458
            if ( !error_monitor_done )
14459
                disable monitor_error_event6 ;
14460 15 mihad
        end
14461
        begin:monitor_error_event6
14462 35 mihad
            error_monitor_done = 0 ;
14463 15 mihad
            @(error_event_int) ;
14464
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14465
            ok = 0 ;
14466 35 mihad
            error_monitor_done = 1 ;
14467 15 mihad
        end
14468
        begin
14469
            wb_transaction_stop( 3 ) ;
14470 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14471 15 mihad
        end
14472
        join
14473
 
14474
        if ( ok )
14475
            test_ok ;
14476
 
14477 26 mihad
        @(posedge pci_clock) ;
14478
        @(posedge pci_clock) ;
14479
        @(posedge wb_clock) ;
14480
        @(posedge wb_clock) ;
14481
 
14482 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14483
        addr_offset = 12'h004 ;
14484
        config_read(addr_offset, 4'hF, read_data) ;
14485
        ok = 1 ;
14486
        if ( read_data[27] !== 1 )
14487
        begin
14488
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14489
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14490
            ok = 0 ;
14491
        end
14492
        if ( read_data[28] !== 0 )
14493
        begin
14494
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14495
            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") ;
14496
            ok = 0 ;
14497
        end
14498
        if ( read_data[29] !== 0 )
14499
        begin
14500
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14501
            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") ;
14502
            ok = 0 ;
14503
        end
14504
 
14505
        // clear statuses
14506
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14507
        if ( !ok )
14508
        begin
14509
            test_fail("write to PCI Device Status register failed") ;
14510
            $display("Couldn't write PCI Device Status register") ;
14511
            disable main ;
14512
        end
14513
 
14514
        if ( ok )
14515
            test_ok ;
14516
 
14517
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14518
 
14519
        ok = 1 ;
14520
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14521
 
14522
        config_read(addr_offset, 4'hF, read_data) ;
14523
        if (read_data[8] !== 0)
14524
        begin
14525
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14526
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14527
            ok = 0 ;
14528
        end
14529
        else
14530
            test_ok ;
14531
 
14532
        if ( ok !== 1 )
14533
        begin
14534
            config_write(addr_offset, read_data, 4'hF, ok) ;
14535
            if ( !ok )
14536
            begin
14537
                test_fail("PCI Error Control and Status register could not be written") ;
14538
                disable main ;
14539
            end
14540
        end
14541
 
14542
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14543 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14544 15 mihad
        fork
14545
        begin
14546
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14547
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14548
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14549
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14550
 
14551
            do_pause( 1 ) ;
14552
        end
14553
        begin
14554
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14555
 
14556
            if ( ok !== 1 )
14557
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14558
 
14559
            do_pause(3) ;
14560
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14561
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14562
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14563
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14564
            do_pause(1) ;
14565
 
14566
            while ( FRAME === 0 )
14567
                @(posedge pci_clock) ;
14568
 
14569
            while ( IRDY === 0 )
14570
                @(posedge pci_clock) ;
14571
 
14572 35 mihad
            #1 ;
14573
            if ( !error_monitor_done )
14574
                disable monitor_error_event7 ;
14575 15 mihad
        end
14576
        begin:monitor_error_event7
14577 35 mihad
            error_monitor_done = 0 ;
14578 15 mihad
            @(error_event_int) ;
14579
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14580
            ok = 0 ;
14581 35 mihad
            error_monitor_done = 1 ;
14582 15 mihad
        end
14583
        begin
14584
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14585 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14586 15 mihad
        end
14587
        join
14588
 
14589
        if ( ok )
14590
            test_ok ;
14591
 
14592 26 mihad
        @(posedge pci_clock) ;
14593
        @(posedge pci_clock) ;
14594
        @(posedge wb_clock) ;
14595
        @(posedge wb_clock) ;
14596
 
14597 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14598
        addr_offset = 12'h004 ;
14599
        config_read(addr_offset, 4'hF, read_data) ;
14600
        ok = 1 ;
14601
        if ( read_data[27] !== 1 )
14602
        begin
14603
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14604
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14605
            ok = 0 ;
14606
        end
14607
        if ( read_data[28] !== 0 )
14608
        begin
14609
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14610
            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") ;
14611
            ok = 0 ;
14612
        end
14613
        if ( read_data[29] !== 0 )
14614
        begin
14615
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14616
            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") ;
14617
            ok = 0 ;
14618
        end
14619
 
14620
        // clear statuses
14621
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14622
        if ( !ok )
14623
        begin
14624
            test_fail("write to PCI Device Status register failed") ;
14625
            $display("Couldn't write PCI Device Status register") ;
14626
            disable main ;
14627
        end
14628
 
14629
        if ( ok )
14630
            test_ok ;
14631
 
14632
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14633
 
14634
        ok = 1 ;
14635
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14636
 
14637
        config_read(addr_offset, 4'hF, read_data) ;
14638
        if (read_data[8] !== 0)
14639
        begin
14640
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14641
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14642
            ok = 0 ;
14643
        end
14644
        else
14645
            test_ok ;
14646
 
14647
        if ( ok !== 1 )
14648
        begin
14649
            config_write(addr_offset, read_data, 4'hF, ok) ;
14650
            if ( !ok )
14651
            begin
14652
                test_fail("PCI Error Control and Status register could not be written") ;
14653
                disable main ;
14654
            end
14655
        end
14656
 
14657
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14658 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14659 15 mihad
        fork
14660
        begin
14661
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14662
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14663
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14664
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14665
 
14666
            do_pause( 1 ) ;
14667
        end
14668
        begin
14669
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14670
 
14671
            if ( ok !== 1 )
14672
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14673
 
14674
            do_pause(3) ;
14675
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14676
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14677
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14678
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14679
            do_pause(1) ;
14680
 
14681
            while ( FRAME === 0 )
14682
                @(posedge pci_clock) ;
14683
 
14684
            while ( IRDY === 0 )
14685
                @(posedge pci_clock) ;
14686
 
14687 35 mihad
            #1 ;
14688
            if ( !error_monitor_done )
14689
                disable monitor_error_event8 ;
14690 15 mihad
        end
14691
        begin:monitor_error_event8
14692 35 mihad
            error_monitor_done = 0 ;
14693 15 mihad
            @(error_event_int) ;
14694
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14695
            ok = 0 ;
14696 35 mihad
            error_monitor_done = 1 ;
14697 15 mihad
        end
14698
        begin
14699
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14700 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14701 15 mihad
        end
14702
        join
14703
 
14704
        if ( ok )
14705
            test_ok ;
14706
 
14707 26 mihad
        @(posedge pci_clock) ;
14708
        @(posedge pci_clock) ;
14709
        @(posedge wb_clock) ;
14710
        @(posedge wb_clock) ;
14711
 
14712 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14713 15 mihad
 
14714
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14715
        addr_offset = 12'h004 ;
14716
        config_read(addr_offset, 4'hF, read_data) ;
14717
        ok = 1 ;
14718
        if ( read_data[27] !== 1 )
14719
        begin
14720
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14721
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14722
            ok = 0 ;
14723
        end
14724
        if ( read_data[28] !== 0 )
14725
        begin
14726
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14727
            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") ;
14728
            ok = 0 ;
14729
        end
14730
        if ( read_data[29] !== 0 )
14731
        begin
14732
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14733
            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") ;
14734
            ok = 0 ;
14735
        end
14736
 
14737
        // clear statuses
14738
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14739
        if ( !ok )
14740
        begin
14741
            test_fail("write to PCI Device Status register failed") ;
14742
            $display("Couldn't write PCI Device Status register") ;
14743
            disable main ;
14744
        end
14745
 
14746
        if ( ok )
14747
            test_ok ;
14748
 
14749
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14750
 
14751
        ok = 1 ;
14752
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14753
 
14754
        config_read(addr_offset, 4'hF, read_data) ;
14755
        if (read_data[8] !== 0)
14756
        begin
14757
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14758
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14759
            ok = 0 ;
14760
        end
14761
        else
14762
            test_ok ;
14763
 
14764
        if ( ok !== 1 )
14765
        begin
14766
            config_write(addr_offset, read_data, 4'hF, ok) ;
14767
            if ( !ok )
14768
            begin
14769
                test_fail("PCI Error Control and Status register could not be written") ;
14770
                disable main ;
14771
            end
14772
        end
14773
 
14774
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14775 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
14776 15 mihad
        fork
14777
        begin
14778
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14779
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14780
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14781
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14782
 
14783
            do_pause( 1 ) ;
14784
        end
14785
        begin
14786
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14787
 
14788
            if ( ok !== 1 )
14789
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14790
 
14791
            do_pause(3) ;
14792
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14793
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14794
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14795
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14796
            do_pause(1) ;
14797
 
14798
            while ( FRAME === 0 )
14799
                @(posedge pci_clock) ;
14800
 
14801
            while ( IRDY === 0 )
14802
                @(posedge pci_clock) ;
14803
 
14804 35 mihad
            #1 ;
14805
            if ( !error_monitor_done )
14806
                disable monitor_error_event9 ;
14807 15 mihad
        end
14808
        begin:monitor_error_event9
14809 35 mihad
            error_monitor_done = 0 ;
14810 15 mihad
            @(error_event_int) ;
14811
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14812
            ok = 0 ;
14813 35 mihad
            error_monitor_done = 1 ;
14814 15 mihad
        end
14815
        begin
14816
            wb_transaction_stop( 3 ) ;
14817 92 mihad
            wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14818 15 mihad
        end
14819
        join
14820
 
14821
        if ( ok )
14822
            test_ok ;
14823
 
14824
        // now check all other statuses too
14825
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14826
        ok = 1 ;
14827
 
14828
        addr_offset = 12'h004 ;
14829
        config_read(addr_offset, 4'hF, read_data) ;
14830
        if (read_data[31] !== 0)
14831
        begin
14832
            $display("Detected Parity Error bit set for no reason") ;
14833
            test_fail("Detected Parity Error bit was set for no reason") ;
14834
            ok = 0 ;
14835
        end
14836
 
14837
        if (read_data[30] !== 0)
14838
        begin
14839
            $display("Signaled System Error bit set for no reason") ;
14840
            test_fail("Signaled System Error bit was set for no reason") ;
14841
            ok = 0 ;
14842
        end
14843
 
14844
        if (read_data[29] !== 0)
14845
        begin
14846
            $display("Received Master Abort bit set for no reason") ;
14847
            test_fail("Received Master Abort bit was set for no reason") ;
14848
            ok = 0 ;
14849
        end
14850
 
14851
        if (read_data[28] !== 0)
14852
        begin
14853
            $display("Received Target Abort bit set for no reason");
14854
            test_fail("Received Target Abort bit was set for no reason") ;
14855
            ok = 0 ;
14856
        end
14857
 
14858
        if (read_data[27] !== 0)
14859
        begin
14860
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14861
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14862
            ok = 0 ;
14863
        end
14864
 
14865
        if (read_data[24] !== 0)
14866
        begin
14867
            $display("Master Data Parity Error bit set for no reason") ;
14868
            test_fail("Master Data Parity Error bit was set for no reason") ;
14869
            ok = 0 ;
14870
        end
14871
 
14872
        if ( ok )
14873
            test_ok ;
14874
 
14875
        test_name = "DISABLE IMAGE" ;
14876 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14877 15 mihad
        if ( ok !== 1 )
14878
        begin
14879
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14880
            test_fail("PCI Address Mask register could not be written") ;
14881
            disable main;
14882
        end
14883
    end
14884
 
14885
    if ( target_io_image !== -1 )
14886
    begin
14887
        do_io_aborts = 1 ;
14888
 
14889
        if (target_io_image === 1)
14890
        begin
14891
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14892
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14893
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14894
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14895
        end
14896
        else if (target_io_image === 2)
14897
        begin
14898
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14899
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14900
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14901
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14902
        end
14903
        else if (target_io_image === 3)
14904
        begin
14905
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14906
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14907
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14908
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14909
        end
14910
        else if (target_io_image === 4)
14911
        begin
14912
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14913
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14914
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14915
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14916
        end
14917
        else if (target_io_image === 5)
14918
        begin
14919
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14920
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14921
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14922
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14923
        end
14924
    end
14925
    else
14926
        do_io_aborts = 0 ;
14927
 
14928
    if ( do_io_aborts )
14929
    begin
14930
 
14931
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14932
 
14933
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14934
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14935
        if ( ok !== 1 )
14936
        begin
14937
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14938
            test_fail("PCI Error Control and Status register could not be written") ;
14939
            disable main;
14940
        end
14941
 
14942
        // enable INTERRUPT reporting
14943
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14944
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14945
        if ( ok !== 1 )
14946
        begin
14947
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14948
            test_fail("Interrupt Control register could not be written") ;
14949
            disable main;
14950
        end
14951
 
14952
        addr_offset = 12'h010 + (4*target_io_image) ;
14953
 
14954
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14955
        if ( ok !== 1 )
14956
        begin
14957
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14958
            test_fail("PCI Base Address register could not be written") ;
14959
            disable main;
14960
        end
14961
 
14962
        // disable address translation and enable prefetch so read bursts can be performed
14963
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14964
        if ( ok !== 1 )
14965
        begin
14966
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14967
            test_fail("PCI Image Control register could not be written") ;
14968
            disable main;
14969
        end
14970
 
14971
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14972
        if ( ok !== 1 )
14973
        begin
14974
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14975
            test_fail("PCI Address Mask register could not be written") ;
14976
            disable main;
14977
        end
14978
 
14979
        addr_offset = 12'h00C ;
14980
 
14981
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14982
        if ( ok !== 1 )
14983
        begin
14984
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14985
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14986
            disable main;
14987
        end
14988
 
14989
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14990 92 mihad
        wishbone_slave.cycle_response(3'b010, wb_subseq_waits, 8'h0);
14991 15 mihad
 
14992
        // do a single read error terminated on WB bus
14993
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14994
 
14995
        fork
14996
        begin
14997
            PCIU_IO_READ
14998
             (
14999
                `Test_Master_1,
15000
                Target_Base_Addr_R[target_io_image],
15001
                32'hAAAA_5555,
15002
                4'h0,
15003
                1,
15004
                `Test_Target_Retry_On
15005
             );
15006
 
15007
            do_pause( 1 ) ;
15008
        end
15009
        begin
15010
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
15011
 
15012
            if ( ok !== 1 )
15013
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
15014
 
15015
            do_pause(3) ;
15016
 
15017
            PCIU_IO_READ
15018
             (
15019
                `Test_Master_1,
15020
                Target_Base_Addr_R[target_io_image],
15021
                32'hAAAA_5555,
15022
                4'h0,
15023
                1,
15024
                `Test_Target_Abort_On
15025
             );
15026
 
15027
            do_pause( 1 ) ;
15028
 
15029
            while ( FRAME === 0 )
15030
                @(posedge pci_clock) ;
15031
 
15032
            while ( IRDY === 0 )
15033
                @(posedge pci_clock) ;
15034
 
15035 35 mihad
            #1 ;
15036
            if ( !error_monitor_done )
15037
                disable monitor_error_event10 ;
15038 15 mihad
        end
15039
        begin:monitor_error_event10
15040 35 mihad
            error_monitor_done = 0 ;
15041 15 mihad
            @(error_event_int) ;
15042
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
15043
            ok = 0 ;
15044 35 mihad
            error_monitor_done = 1 ;
15045 15 mihad
        end
15046
        join
15047
 
15048
        if ( ok )
15049
            test_ok ;
15050
 
15051 26 mihad
        @(posedge pci_clock) ;
15052
        @(posedge pci_clock) ;
15053
        @(posedge wb_clock) ;
15054
        @(posedge wb_clock) ;
15055
 
15056 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15057
        addr_offset = 12'h004 ;
15058
        config_read(addr_offset, 4'hF, read_data) ;
15059
        ok = 1 ;
15060
        if ( read_data[27] !== 1 )
15061
        begin
15062
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
15063
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
15064
            ok = 0 ;
15065
        end
15066
        if ( read_data[28] !== 0 )
15067
        begin
15068
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
15069
            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") ;
15070
            ok = 0 ;
15071
        end
15072
        if ( read_data[29] !== 0 )
15073
        begin
15074
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
15075
            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") ;
15076
            ok = 0 ;
15077
        end
15078
 
15079
        // clear statuses
15080
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
15081
        if ( !ok )
15082
        begin
15083
            test_fail("write to PCI Device Status register failed") ;
15084
            $display("Couldn't write PCI Device Status register") ;
15085
            disable main ;
15086
        end
15087
 
15088
        if ( ok )
15089
            test_ok ;
15090
 
15091
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15092
 
15093
        ok = 1 ;
15094
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
15095
 
15096
        config_read(addr_offset, 4'hF, read_data) ;
15097
        if (read_data[8] !== 0)
15098
        begin
15099
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
15100
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
15101
            ok = 0 ;
15102
        end
15103
        else
15104
            test_ok ;
15105
 
15106
        if ( ok !== 1 )
15107
        begin
15108
            config_write(addr_offset, read_data, 4'hF, ok) ;
15109
            if ( !ok )
15110
            begin
15111
                test_fail("PCI Error Control and Status register could not be written") ;
15112
                disable main ;
15113
            end
15114
        end
15115
 
15116
        test_name = "DISABLE IMAGE" ;
15117 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
15118 15 mihad
        if ( ok !== 1 )
15119
        begin
15120
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
15121
            test_fail("PCI Address Mask register could not be written") ;
15122
            disable main;
15123
        end
15124
 
15125 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
15126 15 mihad
 
15127
    end
15128
end // main
15129
endtask // test_wb_error_rd
15130
 
15131
task test_target_abort ;
15132
    input [2:0]  image_num ;
15133
    reg   [11:0] pci_ctrl_offset ;
15134
    reg   [11:0] ctrl_offset ;
15135
    reg   [11:0] ba_offset ;
15136
    reg   [11:0] am_offset ;
15137
    reg   [11:0] ta_offset ;
15138
    reg   [31:0] pci_address ;
15139
    reg   [3:0]  byte_enables ;
15140
    reg          ok ;
15141 35 mihad
    reg          error_monitor_done ;
15142 15 mihad
begin:main
15143
    pci_ctrl_offset = 12'h4 ;
15144
    if (image_num === 0)
15145
    begin
15146
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15147
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15148
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15149
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15150
    end
15151
    else if (image_num === 1)
15152
    begin
15153
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15154
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15155
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15156
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15157
    end
15158
    else if (image_num === 2)
15159
    begin
15160
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15161
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15162
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15163
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15164
    end
15165
    else if (image_num === 3)
15166
    begin
15167
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15168
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15169
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15170
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15171
    end
15172
    else if (image_num === 4)
15173
    begin
15174
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15175
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15176
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15177
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15178
    end
15179
    else if (image_num === 5)
15180
    begin
15181
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15182
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15183
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15184
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15185
    end
15186
 
15187
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
15188
 
15189
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
15190
    if ( ok !== 1 )
15191
    begin
15192
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
15193
        test_fail("PCI Base Address register could not be written") ;
15194
        disable main ;
15195
    end
15196
 
15197
    // Set Address Mask of IMAGE
15198
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15199
    if ( ok !== 1 )
15200
    begin
15201
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15202
        test_fail("PCI Address Mask register could not be written") ;
15203
        disable main ;
15204
    end
15205
 
15206
    // Set Translation Address of IMAGE
15207
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15208
    if ( ok !== 1 )
15209
    begin
15210
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
15211
        test_fail("PCI Translation Address Register could not be written") ;
15212
        disable main ;
15213
    end
15214
 
15215
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
15216
    if ( ok !== 1 )
15217
    begin
15218
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
15219
        test_fail("PCI Image Control register could not be written") ;
15220
        disable main ;
15221
    end
15222
 
15223 92 mihad
    wishbone_slave.cycle_response( 3'b010, wb_subseq_waits, 0 ) ;
15224 15 mihad
 
15225
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
15226
 
15227
    pci_address  = Target_Base_Addr_R[image_num] ;
15228
    byte_enables = 4'b0001 ;
15229
 
15230
    fork
15231
    begin
15232
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15233
        do_pause ( 1 ) ;
15234
    end
15235
    begin:monitor_error_event1
15236 35 mihad
        error_monitor_done = 0 ;
15237 15 mihad
        @(error_event_int) ;
15238
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15239
        ok = 0 ;
15240 35 mihad
        error_monitor_done = 1 ;
15241 15 mihad
    end
15242
    begin
15243
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15244
        @(posedge pci_clock) ;
15245 35 mihad
        #1 ;
15246
        if ( !error_monitor_done )
15247
            disable monitor_error_event1 ;
15248 15 mihad
    end
15249
    join
15250
 
15251
    if ( ok )
15252
        test_ok ;
15253
 
15254
    ok = 1 ;
15255
 
15256
    fork
15257
    begin
15258
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15259
        do_pause ( 1 ) ;
15260
    end
15261
    begin:monitor_error_event2
15262 35 mihad
        error_monitor_done = 0 ;
15263 15 mihad
        @(error_event_int) ;
15264
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15265
        ok = 0 ;
15266 35 mihad
        error_monitor_done = 1 ;
15267 15 mihad
    end
15268
    begin
15269
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15270
        @(posedge pci_clock) ;
15271 35 mihad
        #1 ;
15272
        if ( !error_monitor_done )
15273
            disable monitor_error_event2 ;
15274 15 mihad
    end
15275
    join
15276
 
15277
    if ( ok )
15278
        test_ok ;
15279
 
15280
    ok = 1 ;
15281
 
15282
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
15283
    byte_enables = 4'b0011 ;
15284
 
15285
    fork
15286
    begin
15287
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15288
        do_pause ( 1 ) ;
15289
    end
15290
    begin:monitor_error_event3
15291 35 mihad
        error_monitor_done = 0 ;
15292 15 mihad
        @(error_event_int) ;
15293
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15294
        ok = 0 ;
15295 35 mihad
        error_monitor_done = 1 ;
15296 15 mihad
    end
15297
    begin
15298
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15299
        @(posedge pci_clock) ;
15300 35 mihad
        if ( !error_monitor_done )
15301
            disable monitor_error_event3 ;
15302 15 mihad
    end
15303
    join
15304
 
15305
    if ( ok )
15306
        test_ok ;
15307
 
15308
    ok = 1 ;
15309
 
15310
    byte_enables = 4'b0000 ;
15311
 
15312
    fork
15313
    begin
15314
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15315
        do_pause ( 1 ) ;
15316
    end
15317
    begin:monitor_error_event4
15318 35 mihad
        error_monitor_done = 0 ;
15319 15 mihad
        @(error_event_int) ;
15320
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15321
        ok = 0 ;
15322 35 mihad
        error_monitor_done = 1 ;
15323 15 mihad
    end
15324
    begin
15325
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15326
        @(posedge pci_clock) ;
15327 35 mihad
        #1 ;
15328
        if ( !error_monitor_done )
15329
            disable monitor_error_event4 ;
15330 15 mihad
    end
15331
    join
15332
 
15333
    if ( ok )
15334
        test_ok ;
15335
 
15336
    ok = 1 ;
15337
 
15338
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
15339
    byte_enables = 4'b0111 ;
15340
 
15341
    fork
15342
    begin
15343
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15344
        do_pause ( 1 ) ;
15345
    end
15346
    begin:monitor_error_event5
15347 35 mihad
        error_monitor_done = 0 ;
15348 15 mihad
        @(error_event_int) ;
15349
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15350
        ok = 0 ;
15351 35 mihad
        error_monitor_done = 1 ;
15352 15 mihad
    end
15353
    begin
15354
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15355
        @(posedge pci_clock) ;
15356 35 mihad
        #1 ;
15357
        if ( !error_monitor_done )
15358
            disable monitor_error_event5 ;
15359 15 mihad
    end
15360
    join
15361
 
15362
    if ( ok )
15363
        test_ok ;
15364
 
15365
    ok = 1 ;
15366
 
15367
    byte_enables = 4'b0010 ;
15368
 
15369
    fork
15370
    begin
15371
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15372
        do_pause ( 1 ) ;
15373
    end
15374
    begin:monitor_error_event6
15375 35 mihad
        error_monitor_done = 0 ;
15376 15 mihad
        @(error_event_int) ;
15377
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15378
        ok = 0 ;
15379 35 mihad
        error_monitor_done = 1 ;
15380 15 mihad
    end
15381
    begin
15382
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15383
        @(posedge pci_clock) ;
15384 35 mihad
        #1 ;
15385
        if ( !error_monitor_done )
15386
            disable monitor_error_event6 ;
15387 15 mihad
    end
15388
    join
15389
 
15390
    if ( ok )
15391
        test_ok ;
15392
 
15393
    ok = 1 ;
15394
    byte_enables = 4'b0001 ;
15395
 
15396
    fork
15397
    begin
15398
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15399
        do_pause ( 1 ) ;
15400
    end
15401
    begin:monitor_error_event7
15402 35 mihad
        error_monitor_done = 0 ;
15403 15 mihad
        @(error_event_int) ;
15404
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15405
        ok = 0 ;
15406 35 mihad
        error_monitor_done = 1 ;
15407 15 mihad
    end
15408
    begin
15409
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15410
        @(posedge pci_clock) ;
15411 35 mihad
        #1 ;
15412
        if ( !error_monitor_done )
15413
            disable monitor_error_event7 ;
15414 15 mihad
    end
15415
    join
15416
 
15417
    if ( ok )
15418
        test_ok ;
15419
 
15420
    ok = 1 ;
15421
    byte_enables = 4'b0000 ;
15422
 
15423
    fork
15424
    begin
15425
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15426
        do_pause ( 1 ) ;
15427
    end
15428
    begin:monitor_error_event8
15429 35 mihad
        error_monitor_done = 0 ;
15430 15 mihad
        @(error_event_int) ;
15431
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15432
        ok = 0 ;
15433 35 mihad
        error_monitor_done = 1 ;
15434 15 mihad
    end
15435
    begin
15436
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15437
        @(posedge pci_clock) ;
15438 35 mihad
        #1 ;
15439
        if ( !error_monitor_done )
15440
            disable monitor_error_event8 ;
15441 15 mihad
    end
15442
    join
15443
 
15444
    if ( ok )
15445
        test_ok ;
15446
 
15447
    ok = 1 ;
15448
 
15449
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15450
    byte_enables = 4'b0110 ;
15451
 
15452
    fork
15453
    begin
15454
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15455
        do_pause ( 1 ) ;
15456
    end
15457
    begin:monitor_error_event9
15458 35 mihad
        error_monitor_done = 0 ;
15459 15 mihad
        @(error_event_int) ;
15460
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15461
        ok = 0 ;
15462 35 mihad
        error_monitor_done = 1 ;
15463 15 mihad
    end
15464
    begin
15465
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15466
        @(posedge pci_clock) ;
15467 35 mihad
        #1 ;
15468
        if ( !error_monitor_done )
15469
            disable monitor_error_event9 ;
15470 15 mihad
    end
15471
    join
15472
 
15473
    if ( ok )
15474
        test_ok ;
15475
 
15476
    ok = 1 ;
15477
    fork
15478
    begin
15479
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15480
        do_pause ( 1 ) ;
15481
    end
15482
    begin:monitor_error_event10
15483 35 mihad
        error_monitor_done = 0 ;
15484 15 mihad
        @(error_event_int) ;
15485
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15486
        ok = 0 ;
15487 35 mihad
        error_monitor_done = 1 ;
15488 15 mihad
    end
15489
    begin
15490
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15491
        @(posedge pci_clock) ;
15492 35 mihad
 
15493
        #1 ;
15494
        if ( !error_monitor_done )
15495
            disable monitor_error_event10 ;
15496 15 mihad
    end
15497
    join
15498
 
15499
    if ( ok )
15500
        test_ok ;
15501
 
15502
    ok = 1 ;
15503
 
15504
    byte_enables = 4'b0001 ;
15505
 
15506
    fork
15507
    begin
15508
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15509
        do_pause ( 1 ) ;
15510
    end
15511
    begin:monitor_error_event11
15512 35 mihad
        error_monitor_done = 0 ;
15513 15 mihad
        @(error_event_int) ;
15514
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15515
        ok = 0 ;
15516 35 mihad
        error_monitor_done = 1 ;
15517 15 mihad
    end
15518
    begin
15519
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15520
        @(posedge pci_clock) ;
15521 35 mihad
        #1 ;
15522
        if ( !error_monitor_done )
15523
            disable monitor_error_event11 ;
15524 15 mihad
    end
15525
    join
15526
 
15527
    if ( ok )
15528
        test_ok ;
15529
 
15530
    ok = 1 ;
15531
 
15532
    byte_enables = 4'b0101 ;
15533
 
15534
    fork
15535
    begin
15536
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15537
        do_pause ( 1 ) ;
15538
    end
15539
    begin:monitor_error_event12
15540 35 mihad
        error_monitor_done = 0 ;
15541 15 mihad
        @(error_event_int) ;
15542
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15543
        ok = 0 ;
15544 35 mihad
        error_monitor_done = 1 ;
15545 15 mihad
    end
15546
    begin
15547
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15548
        @(posedge pci_clock) ;
15549 35 mihad
        #1 ;
15550
        if ( !error_monitor_done )
15551
            disable monitor_error_event12 ;
15552 15 mihad
    end
15553
    join
15554
 
15555
    if ( ok )
15556
        test_ok ;
15557
 
15558
    ok = 1 ;
15559
 
15560
    byte_enables = 4'b0011 ;
15561
 
15562
    fork
15563
    begin
15564
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15565
        do_pause ( 1 ) ;
15566
    end
15567
    begin:monitor_error_event13
15568 35 mihad
        error_monitor_done = 0 ;
15569 15 mihad
        @(error_event_int) ;
15570
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15571
        ok = 0 ;
15572 35 mihad
        error_monitor_done = 1 ;
15573 15 mihad
    end
15574
    begin
15575
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15576
        @(posedge pci_clock) ;
15577 35 mihad
        #1 ;
15578
        if ( !error_monitor_done )
15579
            disable monitor_error_event13 ;
15580 15 mihad
    end
15581
    join
15582
 
15583
    if ( ok )
15584
        test_ok ;
15585
 
15586
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15587
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15588
    ok = 1 ;
15589
    if ( pci_address[27] !== 1 )
15590
    begin
15591
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15592
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15593
        ok = 0 ;
15594
    end
15595
    if ( pci_address[28] !== 0 )
15596
    begin
15597
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15598
        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") ;
15599
        ok = 0 ;
15600
    end
15601
    if ( pci_address[29] !== 0 )
15602
    begin
15603
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15604
        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") ;
15605
        ok = 0 ;
15606
    end
15607
 
15608
    // clear statuses
15609
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15610
    if ( !ok )
15611
    begin
15612
        test_fail("write to PCI Device Status register failed") ;
15613
        $display("Couldn't write PCI Device Status register") ;
15614
        disable main ;
15615
    end
15616
 
15617
    if ( ok )
15618
        test_ok ;
15619
 
15620
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15621
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15622
    if ( pci_address[8] !== 0 )
15623
    begin
15624
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15625
    end
15626
    else
15627
        test_ok ;
15628
 
15629 92 mihad
    wishbone_slave.cycle_response( 3'b100, wb_subseq_waits, 0 ) ;
15630 15 mihad
 
15631
    test_name = "DISABLE IMAGE" ;
15632
 
15633 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15634 15 mihad
    if ( ok !== 1 )
15635
    begin
15636
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15637
        test_fail("PCI Address Mask register could not be written") ;
15638
        disable main ;
15639
    end
15640
end
15641
endtask // test_target_abort
15642
 
15643
task test_target_io_wr_rd ;
15644
    input [2:0]  image_num ;
15645
    input        translate_address ;
15646
    input [11:0] img_ctrl_offset ;
15647
    reg   [31:0] expect_address ;
15648
    reg   [31:0] pci_address ;
15649
    reg          translation ;
15650
    reg   [31:0] read_data ;
15651
    reg   [3:0]  byte_enables ;
15652
    reg          ok ;
15653
    reg          pci_ok ;
15654
    reg          wb_ok ;
15655
    integer      i ;
15656 35 mihad
    reg          error_monitor_done ;
15657 15 mihad
begin:main
15658
    `ifdef ADDR_TRAN_IMPL
15659
        translation = translate_address ;
15660
    `else
15661
        translation = 0 ;
15662
    `endif
15663
 
15664 92 mihad
    wishbone_slave.cycle_response( 3'b100, wb_subseq_waits, 0 ) ;
15665 15 mihad
 
15666
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15667
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15668
    if ( translation )
15669
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15670
    else
15671
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15672
 
15673
    if ( !ok )
15674
    begin
15675
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15676
        test_fail("PCI Image Control register could not be written") ;
15677
    end
15678
 
15679
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15680
    pci_address  = Target_Base_Addr_R[image_num] ;
15681
    byte_enables = 4'b0000 ;
15682
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15683
 
15684
    fork
15685
    begin
15686
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15687
        do_pause ( 1 ) ;
15688
    end
15689
    begin
15690
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15691
        if ( wb_ok !== 1 )
15692
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15693
 
15694 35 mihad
        #1 ;
15695
        if ( !error_monitor_done )
15696
            disable monitor_pci_error_1 ;
15697 15 mihad
    end
15698
    begin:monitor_pci_error_1
15699 35 mihad
        error_monitor_done = 0 ;
15700 15 mihad
        pci_ok = 1 ;
15701
        @(error_event_int) ;
15702
        pci_ok = 0 ;
15703
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15704 35 mihad
        error_monitor_done = 1 ;
15705 15 mihad
    end
15706
    join
15707
 
15708
    byte_enables = 4'b1111 ;
15709
    for ( i = 0 ; i < 4 ; i = i + 1 )
15710
    begin:loop_1
15711
        byte_enables[i] = 0 ;
15712
        if ( i > 0 )
15713
            byte_enables[i - 1] = 1 ;
15714
        fork
15715
        begin
15716
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15717
            do_pause ( 1 ) ;
15718
        end
15719
        begin
15720
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15721
            if ( wb_ok !== 1 )
15722
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15723
 
15724 35 mihad
            #1 ;
15725
            if ( !error_monitor_done )
15726
                disable monitor_pci_error_2 ;
15727 15 mihad
        end
15728
        begin:monitor_pci_error_2
15729 35 mihad
            error_monitor_done = 0 ;
15730 15 mihad
            pci_ok = 1 ;
15731
            @(error_event_int) ;
15732
            pci_ok = 0 ;
15733
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15734 35 mihad
            error_monitor_done = 1 ;
15735 15 mihad
        end
15736
        join
15737
 
15738
        if ( !pci_ok || !wb_ok )
15739
            disable loop_1 ;
15740
 
15741
        pci_address = pci_address + 1 ;
15742
        expect_address = expect_address + 1 ;
15743
    end
15744
 
15745
    if ( pci_ok && wb_ok )
15746
        test_ok ;
15747
 
15748
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15749
    pci_address  = Target_Base_Addr_R[image_num] ;
15750
    byte_enables = 4'b1100 ;
15751
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15752
 
15753
    master1_check_received_data = 1 ;
15754
    fork
15755
    begin
15756
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15757
        do_pause( 1 ) ;
15758
    end
15759
    begin
15760
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15761
        if ( wb_ok !== 1 )
15762
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15763
 
15764
        do_pause ( 2 ) ;
15765
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15766
        do_pause ( 16 ) ;
15767
 
15768 35 mihad
        #1 ;
15769
        if ( !error_monitor_done )
15770
            disable monitor_pci_error_3 ;
15771 15 mihad
    end
15772
    begin:monitor_pci_error_3
15773 35 mihad
        error_monitor_done = 0 ;
15774 15 mihad
        pci_ok = 1 ;
15775
        @(error_event_int) ;
15776
        pci_ok = 0 ;
15777
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15778 35 mihad
        error_monitor_done = 1 ;
15779 15 mihad
    end
15780
    join
15781
 
15782
    if ( !pci_ok || !wb_ok )
15783
    begin
15784
        disable main ;
15785
    end
15786
 
15787
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15788
    byte_enables = 4'b0011 ;
15789
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15790
 
15791
    master1_check_received_data = 1 ;
15792
    fork
15793
    begin
15794
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15795
        do_pause( 1 ) ;
15796
    end
15797
    begin
15798
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15799
        if ( wb_ok !== 1 )
15800
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15801
 
15802
        do_pause ( 2 ) ;
15803
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15804
        do_pause ( 16 ) ;
15805
 
15806 35 mihad
        #1 ;
15807
        if ( !error_monitor_done )
15808
            disable monitor_pci_error_4 ;
15809 15 mihad
    end
15810
    begin:monitor_pci_error_4
15811 35 mihad
        error_monitor_done = 0 ;
15812 15 mihad
        pci_ok = 1 ;
15813
        @(error_event_int) ;
15814
        pci_ok = 0 ;
15815
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15816 35 mihad
        error_monitor_done = 1 ;
15817 15 mihad
    end
15818
    join
15819
 
15820
    if ( !pci_ok || !wb_ok )
15821
    begin
15822
        disable main ;
15823
    end
15824
 
15825
    pci_address  = Target_Base_Addr_R[image_num] ;
15826
    byte_enables = 4'b0000 ;
15827
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15828
 
15829
    master1_check_received_data = 1 ;
15830
    fork
15831
    begin
15832
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15833
        do_pause( 1 ) ;
15834
    end
15835
    begin
15836
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15837
        if ( wb_ok !== 1 )
15838
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15839
 
15840
        do_pause ( 2 ) ;
15841
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15842
        do_pause ( 16 ) ;
15843
 
15844 35 mihad
        #1 ;
15845
        if ( !error_monitor_done )
15846
            disable monitor_pci_error_5 ;
15847 15 mihad
    end
15848
    begin:monitor_pci_error_5
15849 35 mihad
        error_monitor_done = 0 ;
15850 15 mihad
        pci_ok = 1 ;
15851
        @(error_event_int) ;
15852
        pci_ok = 0 ;
15853
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15854 35 mihad
        error_monitor_done = 1 ;
15855 15 mihad
    end
15856
    join
15857
 
15858
    if ( pci_ok && wb_ok )
15859
        test_ok ;
15860
end
15861
endtask // test_target_io_wr_rd
15862
 
15863
task test_target_io_err_wr ;
15864
    input [2:0]  image_num ;
15865
    input        translate_address ;
15866
    input [11:0] img_ctrl_offset ;
15867
    input        enable_error_report ;
15868
    input        enable_error_interrupt ;
15869
 
15870
    reg   [31:0] expect_address ;
15871
    reg   [31:0] pci_address ;
15872
    reg          translation ;
15873
    reg   [31:0] read_data ;
15874
    reg   [3:0]  byte_enables ;
15875
    reg          ok ;
15876
    reg          pci_ok ;
15877
    reg          wb_ok ;
15878
    integer      i ;
15879
    reg   [11:0] offset ;
15880 35 mihad
    reg          error_monitor_done ;
15881 15 mihad
begin:main
15882
    `ifdef ADDR_TRAN_IMPL
15883
        translation = translate_address ;
15884
    `else
15885
        translation = 0 ;
15886
    `endif
15887
 
15888 92 mihad
    wishbone_slave.cycle_response( 3'b010, wb_subseq_waits, 0 ) ;
15889 15 mihad
 
15890
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15891
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15892
    if ( translation )
15893
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15894
    else
15895
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15896
 
15897
    if ( !ok )
15898
    begin
15899
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15900
        test_fail("PCI Image Control register could not be written") ;
15901
    end
15902
 
15903
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15904
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15905
    if ( enable_error_report )
15906
    begin
15907
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15908
        if ( !ok )
15909
        begin
15910
            test_fail("PCI Error Control and Status register could not be written") ;
15911
            disable main ;
15912
        end
15913
    end
15914
    else
15915
    begin
15916
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15917
        if ( !ok )
15918
        begin
15919
            test_fail("PCI Error Control and Status register could not be written") ;
15920
            disable main ;
15921
        end
15922
    end
15923
 
15924
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15925
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15926
    if ( enable_error_interrupt )
15927
    begin
15928
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15929
        if ( !ok )
15930
        begin
15931
            test_fail("Interrupt Control register could not be written") ;
15932
            disable main ;
15933
        end
15934
    end
15935
    else
15936
    begin
15937
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15938
        if ( !ok )
15939
        begin
15940
            test_fail("Interrupt Control register could not be written") ;
15941
            disable main ;
15942
        end
15943
    end
15944
 
15945
    pci_address  = Target_Base_Addr_R[image_num] ;
15946
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15947
 
15948
    byte_enables = 4'b1111 ;
15949
 
15950
    for ( i = 0 ; i < 4 ; i = i + 1 )
15951
    begin:loop_1
15952
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15953
        byte_enables[i] = 0 ;
15954
        if ( i > 0 )
15955
            byte_enables[i - 1] = 1 ;
15956
 
15957
        fork
15958
        begin
15959
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15960
            do_pause ( 1 ) ;
15961
        end
15962
        begin
15963
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15964
            if ( wb_ok !== 1 )
15965
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15966
 
15967 35 mihad
            #1 ;
15968
            if ( !error_monitor_done )
15969
                disable monitor_pci_error_2 ;
15970 15 mihad
        end
15971
        begin:monitor_pci_error_2
15972 35 mihad
            error_monitor_done = 0 ;
15973 15 mihad
            pci_ok = 1 ;
15974
            @(error_event_int) ;
15975
            pci_ok = 0 ;
15976
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15977 35 mihad
            error_monitor_done = 1 ;
15978 15 mihad
        end
15979
        join
15980
 
15981
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15982
        `ifdef HOST
15983
 
15984
            repeat ( 4 )
15985
                @( posedge wb_clock ) ;
15986
 
15987
            if ( enable_error_interrupt && enable_error_report )
15988
            begin
15989
                if ( INT_O !== 1 )
15990
                begin
15991
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15992
                end
15993
            end
15994
            else
15995
            begin
15996
                if ( INT_O !== 0 )
15997
                begin
15998
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15999
                end
16000
            end
16001
        `else
16002
            repeat ( 4 )
16003
                @( posedge pci_clock ) ;
16004
 
16005
            if ( enable_error_interrupt && enable_error_report )
16006
            begin
16007
                if ( INTA !== 0 )
16008
                begin
16009
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
16010
                end
16011
            end
16012
            else
16013
            begin
16014
                if ( INTA !== 1 )
16015
                begin
16016
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
16017
                end
16018
            end
16019
        `endif
16020
 
16021
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
16022
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
16023
        config_read( offset, 4'hF, read_data ) ;
16024
        ok = 1 ;
16025
        if ( enable_error_report )
16026
        begin
16027
            if ( read_data[8] !== 1 )
16028
            begin
16029
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
16030
                ok = 0 ;
16031
            end
16032
 
16033
            if ( read_data[9] !== 0 )
16034
            begin
16035
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
16036
                ok = 0 ;
16037
            end
16038
 
16039
            if ( read_data[31:28] !== byte_enables )
16040
            begin
16041
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
16042
                ok = 0 ;
16043
            end
16044
 
16045
            if ( read_data[27:24] !== `BC_IO_WRITE )
16046
            begin
16047
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
16048
                ok = 0 ;
16049
            end
16050
 
16051
            if ( ok )
16052
                test_ok ;
16053
 
16054
            test_name = "CLEAR ERROR STATUS" ;
16055
            config_write( offset, read_data, 4'hF, ok ) ;
16056
            if ( !ok )
16057
                test_fail("PCI Error Control and Status register could not be written") ;
16058
 
16059
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
16060
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
16061
            config_read ( offset, 4'hf, read_data ) ;
16062
 
16063
            if ( read_data !== expect_address )
16064
            begin
16065
                test_fail("value in Erroneous Address register was incorrect") ;
16066
                ok = 0 ;
16067
            end
16068
 
16069
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
16070
            config_read ( offset, 4'hf, read_data ) ;
16071
 
16072
            if ( read_data !== 32'hAAAA_AAAA )
16073
            begin
16074
                test_fail("value in Erroneous Data register was incorrect") ;
16075
                ok = 0 ;
16076
            end
16077
 
16078
            if ( ok )
16079
                test_ok ;
16080
 
16081
        end
16082
        else
16083
        begin
16084
            if ( read_data[8] !== 0 )
16085
            begin
16086
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
16087
                ok = 0 ;
16088
            end
16089
            else
16090
                test_ok ;
16091
        end
16092
 
16093
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
16094
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
16095
        ok = 1 ;
16096
 
16097
        config_read ( offset, 4'hF, read_data ) ;
16098
        if ( enable_error_report && enable_error_interrupt )
16099
        begin
16100
            if ( read_data[2] !== 1 )
16101
            begin
16102
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
16103
                ok = 0 ;
16104
            end
16105
 
16106
            test_name = "CLEARING INTERRUPT STATUS" ;
16107
            config_write( offset, read_data, 4'hF, ok ) ;
16108
            if ( !ok )
16109
                test_fail("Interrupt Status register could not be written") ;
16110
        end
16111
        else
16112
        begin
16113
            if ( read_data[2] !== 0 )
16114
            begin
16115
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
16116
                ok = 0 ;
16117
            end
16118
        end
16119
 
16120
        if ( ok )
16121
            test_ok ;
16122
 
16123
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
16124
        `ifdef HOST
16125
 
16126
            repeat ( 4 )
16127
                @( posedge wb_clock ) ;
16128
 
16129
            if ( INT_O !== 0 )
16130
            begin
16131
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
16132
            end
16133
            else
16134
                test_ok ;
16135
 
16136
        `else
16137
            repeat ( 4 )
16138
                @( posedge pci_clock ) ;
16139
 
16140
            if ( INTA !== 1 )
16141
            begin
16142
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
16143
            end
16144
            else
16145
                test_ok ;
16146
 
16147
        `endif
16148
 
16149
        pci_address = pci_address + 1 ;
16150
        expect_address = expect_address + 1 ;
16151
    end
16152
 
16153
end
16154
endtask // test_target_io_err_wr
16155
 
16156
task test_pci_image ;
16157
    input [2:0]  image_num ;
16158
    reg   [11:0] pci_ctrl_offset ;
16159
    reg   [11:0] ctrl_offset ;
16160
    reg   [11:0] ba_offset ;
16161
    reg   [11:0] am_offset ;
16162
    reg   [11:0] ta_offset ;
16163
    reg   [7:0]  cache_lsize ;
16164
    reg          ok ;
16165
    reg          test_io ;
16166
    reg          test_mem ;
16167
begin
16168
    pci_ctrl_offset = 12'h4 ;
16169
    if (image_num === 0)
16170
    begin
16171
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
16172
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
16173
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
16174
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
16175
    end
16176
    else if (image_num === 1)
16177
    begin
16178
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16179
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16180
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16181
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16182
    end
16183
    else if (image_num === 2)
16184
    begin
16185
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16186
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16187
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16188
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16189
    end
16190
    else if (image_num === 3)
16191
    begin
16192
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16193
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16194
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16195
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16196
    end
16197
    else if (image_num === 4)
16198
    begin
16199
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16200
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16201
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16202
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16203
    end
16204
    else if (image_num === 5)
16205
    begin
16206
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16207
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16208
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16209
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16210
    end
16211
 
16212
    `ifdef HOST
16213
        test_io  = 1 ;
16214
        test_mem = 1 ;
16215
    `else
16216
        if (image_num == 1)
16217
            test_io = `PCI_BA1_MEM_IO ;
16218
        else if ( image_num == 2 )
16219
            test_io = `PCI_BA2_MEM_IO ;
16220
        else if ( image_num == 3 )
16221
            test_io = `PCI_BA3_MEM_IO ;
16222
        else if ( image_num == 4 )
16223
            test_io = `PCI_BA4_MEM_IO ;
16224
        else if ( image_num == 5 )
16225
            test_io = `PCI_BA5_MEM_IO ;
16226
 
16227
        test_mem = !test_io ;
16228
    `endif
16229
 
16230
    $display(" ");
16231
    $display("########################################################################") ;
16232
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
16233
    test_name = "PCI IMAGE SETTINGS" ;
16234
 
16235
    // Set Base Address of IMAGE
16236
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
16237
    if ( ok !== 1 )
16238
    begin
16239
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16240
        test_fail("PCI Base Address register could not be written") ;
16241
    end
16242
 
16243
    // Set Address Mask of IMAGE
16244
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16245
    if ( ok !== 1 )
16246
    begin
16247
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16248
        test_fail("PCI Address Mask register could not be written") ;
16249
    end
16250
 
16251
    // Set Translation Address of IMAGE
16252
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16253
    if ( ok !== 1 )
16254
    begin
16255
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16256
        test_fail("PCI Translation Address register could not be written") ;
16257
    end
16258
 
16259
// Following are defines for byte enable signals !
16260
//      Byte Masks
16261
//      `Test_Byte_0                            (4'b1110)
16262
//      `Test_Byte_1                            (4'b1101)
16263
//      `Test_Byte_2                            (4'b1011)
16264
//      `Test_Byte_3                            (4'b0111)
16265
//      `Test_Half_0                            (4'b1100)
16266
//      `Test_Half_1                            (4'b0011)
16267
//      `Test_All_Bytes                         (4'b0000)
16268
 
16269
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
16270
    // Set Cache Line Size
16271
    cache_lsize = 8'h4 ;
16272
 
16273
    $display(" ");
16274
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16275
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16276
    if ( ok !== 1 )
16277
    begin
16278
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16279
        test_fail("PCI Device Control and Status register could not be written") ;
16280
    end
16281
 
16282
    if (test_mem)
16283
    begin
16284
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
16285
        // Task test_normal_wr_rd has the following parameters:
16286
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16287
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16288
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16289
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
16290 104 mihad
                            `Test_One_Word, 1'b0, 1'b0, cache_lsize, 1'b0, 1'b0 );
16291 15 mihad
 
16292
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16293
        // Set Cache Line Size
16294
        cache_lsize = 8'h4 ;
16295
 
16296
        $display(" ");
16297
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16298
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16299
        if ( ok !== 1 )
16300
        begin
16301
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16302
            test_fail("Cache Line Size register could not be written" ) ;
16303
        end
16304
 
16305
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
16306
        // Task test_normal_wr_rd has the following parameters:
16307
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16308
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16309
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16310
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
16311
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
16312
 
16313 104 mihad
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCHABLE IMAGES
16314 15 mihad
        // Set Cache Line Size
16315
        cache_lsize = 8'h8 ;
16316
 
16317
        $display(" ");
16318
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16319
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16320
        if ( ok !== 1 )
16321
        begin
16322
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16323
            test_fail("Cache Line Size register could not be written" ) ;
16324
        end
16325
 
16326
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
16327
        // Task test_normal_wr_rd has the following parameters:
16328
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16329
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16330
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16331
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
16332
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16333
 
16334
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16335
        // Set Cache Line Size
16336
        cache_lsize = 8'h4 ;
16337
 
16338
        $display(" ");
16339
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16340
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16341
        if ( ok !== 1 )
16342
        begin
16343
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16344
            test_fail("Cache Line Size register could not be written" ) ;
16345
        end
16346
 
16347
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
16348
        // Task test_normal_wr_rd has the following parameters:
16349
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16350
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16351
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16352
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
16353
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16354
 
16355
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16356
        $display(" ");
16357
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
16358
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16359
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16360
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
16361
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
16362
 
16363
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16364
        $display(" ");
16365
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
16366
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16367
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16368
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
16369
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
16370
 
16371
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16372
        $display(" ");
16373
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
16374
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16375
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16376
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
16377
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
16378
 
16379
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16380
        $display(" ");
16381
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
16382
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16383
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16384
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
16385
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
16386
    end
16387
 
16388
    if ( test_io )
16389
    begin
16390
        test_name = "PCI IMAGE SETTINGS" ;
16391
 
16392
        // Set Base Address of IMAGE
16393
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
16394
        if ( ok !== 1 )
16395
        begin
16396
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16397
            test_fail("PCI Base Address register could not be written") ;
16398
        end
16399
 
16400
        // Set Address Mask of IMAGE
16401
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16402
        if ( ok !== 1 )
16403
        begin
16404
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16405
            test_fail("PCI Address Mask register could not be written") ;
16406
        end
16407
 
16408
        // Set Translation Address of IMAGE
16409
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16410
        if ( ok !== 1 )
16411
        begin
16412
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16413
            test_fail("PCI Translation Address register could not be written") ;
16414
        end
16415
 
16416
        // Set Cache Line Size
16417
        cache_lsize = 8'h4 ;
16418
 
16419
        $display(" ");
16420
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16421
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16422
        if ( ok !== 1 )
16423
        begin
16424
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16425
            test_fail("Cache Line Size register could not be written" ) ;
16426
        end
16427
 
16428
        test_target_io_wr_rd
16429
        (
16430
            image_num,    // image number
16431
            0,            // test with address translation
16432
            ctrl_offset   // image control register offset
16433
        ) ;
16434
 
16435
        test_target_io_wr_rd
16436
        (
16437
            image_num,    // image number
16438
            1,            // test with address translation
16439
            ctrl_offset   // image control register offset
16440
        ) ;
16441
 
16442
        test_target_io_err_wr
16443
        (
16444
            image_num,      // image number
16445
            0,              // address translation on/off
16446
            ctrl_offset,    // image control register offset
16447
            0,              // enable error reporting
16448
 
16449
        ) ;
16450
 
16451
        test_target_io_err_wr
16452
        (
16453
            image_num,      // image number
16454
            1,              // address translation on/off
16455
            ctrl_offset,    // image control register offset
16456
            0,              // enable error reporting
16457
            1               // enable error interrupts
16458
        ) ;
16459
 
16460
        test_target_io_err_wr
16461
        (
16462
            image_num,      // image number
16463
            0,              // address translation on/off
16464
            ctrl_offset,    // image control register offset
16465
            1,              // enable error reporting
16466
 
16467
        ) ;
16468
 
16469
        test_target_io_err_wr
16470
        (
16471
            image_num,      // image number
16472
            1,              // address translation on/off
16473
            ctrl_offset,    // image control register offset
16474
            1,              // enable error reporting
16475
            1               // enable error interrupts
16476
        ) ;
16477
    end
16478
 
16479
    // Test master abort with NON supported commands
16480
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16481
 
16482
    // disable the image
16483 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16484 15 mihad
end
16485
endtask //test_pci_image
16486
 
16487
task target_fast_back_to_back ;
16488
    reg   [11:0] pci_ctrl_offset ;
16489
    reg   [11:0] ctrl_offset ;
16490
    reg   [11:0] ba_offset ;
16491
    reg   [11:0] am_offset ;
16492
    reg   [11:0] ta_offset ;
16493
    reg   [11:0] cls_offset ;
16494
    reg          do_mem_fb2b ;
16495
    reg          do_io_fb2b ;
16496
    reg          ok ;
16497
begin:main
16498
 
16499
    if ( target_mem_image !== -1 )
16500
    begin
16501
        do_mem_fb2b = 1 ;
16502
 
16503
        if (target_mem_image === 1)
16504
        begin
16505
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16506
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16507
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16508
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16509
        end
16510
        else if (target_mem_image === 2)
16511
        begin
16512
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16513
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16514
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16515
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16516
        end
16517
        else if (target_mem_image === 3)
16518
        begin
16519
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16520
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16521
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16522
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16523
        end
16524
        else if (target_mem_image === 4)
16525
        begin
16526
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16527
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16528
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16529
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16530
        end
16531
        else if (target_mem_image === 5)
16532
        begin
16533
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16534
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16535
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16536
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16537
        end
16538
    end
16539
    else
16540
        do_mem_fb2b = 0 ;
16541
 
16542
    pci_ctrl_offset = 12'h4 ;
16543
    cls_offset      = 12'h00C ;
16544
 
16545
    if ( do_mem_fb2b )
16546
    begin
16547
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16548
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16549
        if ( ok !== 1 )
16550
        begin
16551
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16552
            test_fail("PCI Base Address register could not be written") ;
16553
            disable main ;
16554
        end
16555
 
16556
        // Set Address Mask of IMAGE
16557
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16558
        if ( ok !== 1 )
16559
        begin
16560
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16561
            test_fail("PCI Address Mask register could not be written") ;
16562
            disable main ;
16563
        end
16564
 
16565
        // Set Translation Address of IMAGE
16566
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16567
        if ( ok !== 1 )
16568
        begin
16569
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16570
            test_fail("PCI Translation Address Register could not be written") ;
16571
            disable main ;
16572
        end
16573
 
16574
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16575
        if ( ok !== 1 )
16576
        begin
16577
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16578
            test_fail("PCI Image Control register could not be written") ;
16579
            disable main ;
16580
        end
16581
 
16582
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16583
        if ( ok !== 1 )
16584
        begin
16585
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16586
            test_fail("Cache Line Size register could not be written") ;
16587
            disable main ;
16588
        end
16589
 
16590
        // enable master 1 fast_b2b
16591 45 mihad
        configuration_cycle_write(0,                        // bus number
16592
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16593
                                  0,                        // function number
16594
                                  1,                        // register number
16595
                                  0,                        // type of configuration cycle
16596
                                  4'b1111,                  // byte enables
16597
                                  32'hFFFF_FFFF             // data
16598 15 mihad
                                 ) ;
16599
 
16600 92 mihad
        wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 0) ;
16601 15 mihad
 
16602
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16603
        fork
16604
        begin
16605
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16606
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16607
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16608
                  0, `Test_One_Zero_Target_WS,
16609
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16610
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16611
 
16612
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16613
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16614
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16615
                  0, `Test_One_Zero_Target_WS,
16616
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16617
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16618
 
16619 92 mihad
            do_pause(1) ;
16620
 
16621 15 mihad
        end
16622
        begin:wb_monitor1
16623 92 mihad
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, 0, 1'b1, ok) ;
16624
 
16625
            if ( ok !== 1 )
16626
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16627
 
16628
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
16629
 
16630 15 mihad
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16631
            if ( ok !== 1 )
16632
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16633
 
16634
            disable monitor_error_event1 ;
16635
        end
16636
        begin:monitor_error_event1
16637
            @(error_event_int) ;
16638
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16639
            ok = 0 ;
16640
            disable wb_monitor1 ;
16641
        end
16642
        join
16643
 
16644
        if ( ok )
16645
            test_ok ;
16646
 
16647
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16648 92 mihad
        wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 0) ;
16649 15 mihad
        fork
16650
        begin
16651
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16652
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16653
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16654
                  0, `Test_One_Zero_Target_WS,
16655
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16656
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16657
 
16658
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16659
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16660
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16661
                  0, `Test_One_Zero_Target_WS,
16662
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16663
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16664
 
16665 92 mihad
            do_pause(1) ;
16666 15 mihad
 
16667
        end
16668
        begin:wb_monitor2
16669 92 mihad
 
16670
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, 0, 1'b1, ok) ;
16671
 
16672
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
16673
 
16674 15 mihad
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16675
            if ( ok !== 1 )
16676
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16677
            else
16678
            begin
16679
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16680
                if ( ok !== 1 )
16681
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16682
            end
16683
 
16684
            disable monitor_error_event2 ;
16685
        end
16686
        begin:monitor_error_event2
16687
            @(error_event_int) ;
16688
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16689
            ok = 0 ;
16690
            disable wb_monitor2 ;
16691
        end
16692
        join
16693
 
16694
        if ( ok )
16695
            test_ok ;
16696
 
16697
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16698 92 mihad
        wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 0) ;
16699 15 mihad
        fork
16700
        begin
16701
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16702
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16703
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16704
                  0, `Test_One_Zero_Target_WS,
16705
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16706
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16707
 
16708
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16709
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16710
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16711
                  0, `Test_One_Zero_Target_WS,
16712
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16713
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16714
 
16715 92 mihad
            do_pause(1) ;
16716
 
16717 15 mihad
        end
16718
        begin:wb_monitor3
16719 92 mihad
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, 0, 1'b1, ok) ;
16720
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
16721 15 mihad
            fork
16722
            begin
16723
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16724
                if ( ok !== 1 )
16725
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16726
            end
16727
            begin
16728
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16729
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16730
                if ( ok !== 1 )
16731
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16732
            end
16733
            join
16734
 
16735
            if ( ok )
16736
            begin
16737
                fork
16738
                begin
16739
                    do_pause(3) ;
16740
 
16741
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16742
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16743
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16744
                        0, `Test_One_Zero_Target_WS,
16745
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16746
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16747
 
16748
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16749
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16750
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16751
                            0, `Test_One_Zero_Target_WS,
16752
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16753
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16754
 
16755
                    do_pause(1) ;
16756
                end
16757
                begin
16758
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16759
                    if ( ok !== 1 )
16760
                    begin
16761
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16762
                        disable monitor_error_event3 ;
16763
                    end
16764
                    else
16765
                    begin
16766
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16767
                        if ( ok !== 1 )
16768
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16769
                    end
16770
                end
16771 26 mihad
                begin
16772
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16773
                        if ( ok !== 1 )
16774
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16775
                end
16776 15 mihad
                join
16777
            end
16778
            disable monitor_error_event3 ;
16779
        end
16780
        begin:monitor_error_event3
16781
            @(error_event_int) ;
16782
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16783
            ok = 0 ;
16784
            disable wb_monitor3 ;
16785
        end
16786
        join
16787
 
16788
        if ( ok )
16789
            test_ok ;
16790
 
16791
        test_name = "DISABLING MEM IMAGE" ;
16792 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16793 15 mihad
        if ( ok !== 1 )
16794
        begin
16795
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16796
            test_fail("PCI Address Mask register could not be written") ;
16797
            disable main ;
16798
        end
16799
    end
16800
 
16801
    if ( target_io_image !== -1 )
16802
    begin
16803
        do_io_fb2b = 1 ;
16804
 
16805
        if (target_io_image === 1)
16806
        begin
16807
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16808
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16809
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16810
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16811
        end
16812
        else if (target_io_image === 2)
16813
        begin
16814
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16815
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16816
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16817
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16818
        end
16819
        else if (target_io_image === 3)
16820
        begin
16821
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16822
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16823
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16824
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16825
        end
16826
        else if (target_io_image === 4)
16827
        begin
16828
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16829
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16830
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16831
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16832
        end
16833
        else if (target_io_image === 5)
16834
        begin
16835
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16836
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16837
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16838
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16839
        end
16840
    end
16841
    else
16842
        do_io_fb2b = 0 ;
16843
 
16844
    if ( do_io_fb2b )
16845
    begin
16846
 
16847
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16848
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16849
        if ( ok !== 1 )
16850
        begin
16851
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16852
            test_fail("PCI Base Address register could not be written") ;
16853
            disable main ;
16854
        end
16855
 
16856
        // Set Address Mask of IMAGE
16857
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16858
        if ( ok !== 1 )
16859
        begin
16860
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16861
            test_fail("PCI Address Mask register could not be written") ;
16862
            disable main ;
16863
        end
16864
 
16865
        // Set Translation Address of IMAGE
16866
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16867
        if ( ok !== 1 )
16868
        begin
16869
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16870
            test_fail("PCI Translation Address Register could not be written") ;
16871
            disable main ;
16872
        end
16873
 
16874
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16875
        if ( ok !== 1 )
16876
        begin
16877
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16878
            test_fail("PCI Image Control register could not be written") ;
16879
            disable main ;
16880
        end
16881
 
16882
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16883
        if ( ok !== 1 )
16884
        begin
16885
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16886
            test_fail("Cache Line Size register could not be written") ;
16887
            disable main ;
16888
        end
16889
 
16890
        // enable master 1 fast_b2b
16891 45 mihad
        configuration_cycle_write(0,                        // bus number
16892
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16893
                                  0,                        // function number
16894
                                  1,                        // register number
16895
                                  0,                        // type of configuration cycle
16896
                                  4'b1111,                  // byte enables
16897
                                  32'hFFFF_FFFF             // data
16898 15 mihad
                                 ) ;
16899
 
16900 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
16901 15 mihad
 
16902
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16903
        fork
16904
        begin
16905
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16906
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16907
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16908
                  0, `Test_One_Zero_Target_WS,
16909
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16910
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16911
 
16912
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16913
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16914
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16915
                  0, `Test_One_Zero_Target_WS,
16916
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16917
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16918
 
16919 92 mihad
            do_pause(1) ;
16920
 
16921 15 mihad
        end
16922
        begin:wb_monitor4
16923
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16924
            if ( ok !== 1 )
16925
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16926
 
16927
            if ( ok )
16928
            begin
16929
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16930
                if ( ok !== 1 )
16931
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16932
            end
16933
 
16934
            disable monitor_error_event4 ;
16935
        end
16936
        begin:monitor_error_event4
16937
            @(error_event_int) ;
16938
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16939
            ok = 0 ;
16940
            disable wb_monitor4 ;
16941
        end
16942
        join
16943
 
16944
        if ( ok )
16945
            test_ok ;
16946
 
16947
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16948 92 mihad
        wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 0) ;
16949 15 mihad
        fork
16950
        begin
16951
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16952
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16953
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16954
                  0, `Test_One_Zero_Target_WS,
16955
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16956
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16957
 
16958
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16959
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16960
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16961
                  0, `Test_One_Zero_Target_WS,
16962
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16963
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16964 92 mihad
 
16965
            do_pause(1) ;
16966
 
16967 15 mihad
        end
16968
        begin:wb_monitor5
16969 92 mihad
 
16970
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 0, 1'b1, ok) ;
16971
 
16972
            wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 0) ;
16973
 
16974 15 mihad
            fork
16975
            begin
16976
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16977
                if ( ok !== 1 )
16978
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16979
            end
16980
            begin
16981
                wb_transaction_stop( 1 ) ;
16982
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16983
                if ( ok !== 1 )
16984
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16985
            end
16986
            join
16987
 
16988
            if ( ok )
16989
            begin
16990
                fork
16991
                begin
16992
                    do_pause(3) ;
16993
 
16994
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16995
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16996
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16997
                            0, `Test_One_Zero_Target_WS,
16998
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16999
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
17000
 
17001
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
17002
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
17003
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17004
                            0, `Test_One_Zero_Target_WS,
17005
                            `Test_Devsel_Medium, `Test_Fast_B2B,
17006
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
17007
 
17008
                    do_pause(1) ;
17009
                end
17010
                begin
17011
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
17012
                    if ( ok !== 1 )
17013
                    begin
17014
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
17015
                        disable monitor_error_event5 ;
17016
                    end
17017
                    else
17018
                    begin
17019
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
17020
                        if ( ok !== 1 )
17021
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
17022
                    end
17023
                end
17024
                join
17025
            end
17026
            disable monitor_error_event5 ;
17027
        end
17028
        begin:monitor_error_event5
17029
            @(error_event_int) ;
17030
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
17031
            ok = 0 ;
17032
            disable wb_monitor5 ;
17033
        end
17034
        join
17035
 
17036
        if ( ok )
17037
            test_ok ;
17038
 
17039
        test_name = "DISABLING IO IMAGE" ;
17040 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17041 15 mihad
        if ( ok !== 1 )
17042
        begin
17043
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17044
            test_fail("PCI Address Mask register could not be written") ;
17045
            disable main ;
17046
        end
17047
    end
17048
 
17049
end
17050
endtask //target_fast_back_to_back
17051
 
17052
task target_disconnects ;
17053
    reg   [11:0] pci_ctrl_offset ;
17054
    reg   [11:0] ctrl_offset ;
17055
    reg   [11:0] ba_offset ;
17056
    reg   [11:0] am_offset ;
17057
    reg   [11:0] ta_offset ;
17058
    reg   [11:0] cls_offset ;
17059
    reg          pci_ok ;
17060
    reg          wb_ok ;
17061
    reg          ok ;
17062
    reg   [31:0] pci_address ;
17063
    reg   [31:0] data ;
17064
    reg   [3:0]  byte_enables ;
17065
    reg   [9:0]  expect_length ;
17066
 
17067
    reg          do_mem_disconnects ;
17068
    reg          do_io_disconnects ;
17069 35 mihad
    reg          error_monitor_done ;
17070 15 mihad
begin:main
17071
    if ( target_mem_image !== -1 )
17072
    begin
17073
        do_mem_disconnects = 1 ;
17074
 
17075
        if (target_mem_image === 1)
17076
        begin
17077
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17078
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17079
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17080
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17081
        end
17082
        else if (target_mem_image === 2)
17083
        begin
17084
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17085
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17086
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17087
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17088
        end
17089
        else if (target_mem_image === 3)
17090
        begin
17091
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17092
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17093
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17094
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17095
        end
17096
        else if (target_mem_image === 4)
17097
        begin
17098
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17099
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17100
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17101
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17102
        end
17103
        else if (target_mem_image === 5)
17104
        begin
17105
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17106
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17107
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17108
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17109
        end
17110
    end
17111
    else
17112
        do_mem_disconnects = 0 ;
17113
 
17114
    pci_ctrl_offset = 12'h4 ;
17115
    cls_offset = 12'h00C ;
17116
 
17117
    master1_check_received_data = 0 ;
17118
    master2_check_received_data = 0 ;
17119
 
17120
    `ifdef HOST
17121
        `ifdef NO_CNF_IMAGE
17122
        `else
17123
            `define TEST_BURST_CONFIG_READ
17124
        `endif
17125
    `else
17126
        `define TEST_BURST_CONFIG_READ
17127
        `define TEST_BURST_CONFIG_WRITE
17128
    `endif
17129
 
17130
    `ifdef TEST_BURST_CONFIG_WRITE
17131
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
17132
 
17133
        data = 32'h0000_08_08 ;
17134
 
17135 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
17136 15 mihad
        byte_enables = 4'b0000 ;
17137
 
17138
        fork
17139
        begin
17140
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17141
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17142
                    byte_enables,
17143
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17144
                    8'h0_0, `Test_One_Zero_Target_WS,
17145
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17146
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17147
 
17148
            data = 32'h0000_04_04 ;
17149
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17150
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17151
                    byte_enables,
17152
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17153
                    8'h0_0, `Test_One_Zero_Target_WS,
17154
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17155
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17156
            do_pause( 1 ) ;
17157
            while ( FRAME !== 1 || IRDY !== 1 )
17158
                @(posedge pci_clock) ;
17159
 
17160 35 mihad
            #1 ;
17161
            if ( !error_monitor_done )
17162
                disable monitor_error_event1 ;
17163 15 mihad
        end
17164
        begin:monitor_error_event1
17165 35 mihad
            error_monitor_done = 0 ;
17166 15 mihad
            ok = 1 ;
17167
            @(error_event_int) ;
17168
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17169
            ok = 0 ;
17170 35 mihad
            error_monitor_done = 1 ;
17171 15 mihad
        end
17172
        join
17173
 
17174
        config_read(pci_address, 4'hF, data) ;
17175
        if ( data [15:0] !== 16'h04_04 )
17176
        begin
17177
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
17178
        end
17179
        else if ( ok )
17180
            test_ok ;
17181
 
17182 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
17183
 
17184
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
17185 15 mihad
        data         = 32'h0000_0808 ;
17186
        byte_enables = 4'h0 ;
17187
        fork
17188
        begin
17189
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17190
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
17191
                    byte_enables,
17192
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17193
                    8'h0_0, `Test_One_Zero_Target_WS,
17194
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17195
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17196
 
17197
            data = 32'h0000_04_04 ;
17198
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17199
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
17200
                    byte_enables,
17201
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17202
                    8'h0_0, `Test_One_Zero_Target_WS,
17203
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17204
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17205
 
17206
            do_pause( 1 ) ;
17207
            while ( FRAME !== 1 || IRDY !== 1 )
17208
                @(posedge pci_clock) ;
17209
 
17210 35 mihad
            #1 ;
17211
            if ( !error_monitor_done )
17212
                disable monitor_error_event2 ;
17213 15 mihad
        end
17214
        begin:monitor_error_event2
17215 35 mihad
            error_monitor_done = 0 ;
17216 15 mihad
            ok = 1 ;
17217
            @(error_event_int) ;
17218
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17219
            ok = 0 ;
17220 35 mihad
            error_monitor_done = 1 ;
17221 15 mihad
        end
17222
        join
17223
 
17224
        config_read(pci_address, 4'hF, data) ;
17225
        if ( data [15:0] !== 16'h04_04 )
17226
        begin
17227
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
17228
        end
17229
        else if ( ok )
17230
            test_ok ;
17231
    `endif
17232
 
17233
    `ifdef TEST_BURST_CONFIG_READ
17234
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
17235
 
17236
        data = 32'h0000_04_04 ;
17237
 
17238 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
17239 15 mihad
        byte_enables = 4'b0000 ;
17240
 
17241
        fork
17242
        begin
17243
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17244
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
17245
                    byte_enables,
17246
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17247
                    8'h0_0, `Test_One_Zero_Target_WS,
17248
                    `Test_Devsel_Medium, `Test_Fast_B2B,
17249
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17250
            do_pause( 1 ) ;
17251
 
17252
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17253
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
17254
                    byte_enables,
17255
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17256
                    8'h0_0, `Test_One_Zero_Target_WS,
17257
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17258
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17259
            do_pause( 1 ) ;
17260
 
17261
            while ( FRAME !== 1 || IRDY !== 1 )
17262
                @(posedge pci_clock) ;
17263
 
17264 35 mihad
            if ( !error_monitor_done )
17265
                disable monitor_error_event3 ;
17266 15 mihad
        end
17267
        begin:monitor_error_event3
17268 35 mihad
            error_monitor_done = 0 ;
17269 15 mihad
            ok = 1 ;
17270
            @(error_event_int) ;
17271
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17272
            ok = 0 ;
17273 35 mihad
            error_monitor_done = 1 ;
17274 15 mihad
        end
17275
        join
17276
 
17277
        if ( ok )
17278
            test_ok ;
17279
 
17280 45 mihad
 
17281
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
17282
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
17283 15 mihad
        fork
17284
        begin
17285
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17286
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17287
                    byte_enables,
17288
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17289
                    8'h0_0, `Test_One_Zero_Target_WS,
17290
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17291
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17292
            do_pause( 1 ) ;
17293
 
17294
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17295
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17296
                    byte_enables,
17297
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17298
                    8'h0_0, `Test_One_Zero_Target_WS,
17299
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17300
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17301
            do_pause( 1 ) ;
17302
 
17303
            while ( FRAME !== 1 || IRDY !== 1 )
17304
                @(posedge pci_clock) ;
17305
 
17306 35 mihad
            #1 ;
17307
            if ( !error_monitor_done )
17308
                disable monitor_error_event4 ;
17309 15 mihad
        end
17310
        begin:monitor_error_event4
17311 35 mihad
            error_monitor_done = 0 ;
17312 15 mihad
            ok = 1 ;
17313
            @(error_event_int) ;
17314
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17315
            ok = 0 ;
17316 35 mihad
            error_monitor_done = 1 ;
17317 15 mihad
        end
17318
        join
17319
 
17320
        if ( ok )
17321
            test_ok ;
17322
    `endif
17323
 
17324
    `ifdef TEST_BURST_CONFIG_READ
17325
        `undef TEST_BURST_CONFIG_READ
17326
    `endif
17327
 
17328
    `ifdef TEST_BURST_CONFIG_WRITE
17329
        `undef TEST_BURST_CONFIG_WRITE
17330
    `endif
17331
 
17332
    master1_check_received_data = 1 ;
17333
    master2_check_received_data = 1 ;
17334
 
17335
    if ( do_mem_disconnects )
17336
    begin
17337
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17338
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
17339
        if ( ok !== 1 )
17340
        begin
17341
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17342
            test_fail("PCI Base Address register could not be written") ;
17343
            disable main ;
17344
        end
17345
 
17346
        // Set Address Mask of IMAGE
17347
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
17348
        if ( ok !== 1 )
17349
        begin
17350
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17351
            test_fail("PCI Address Mask register could not be written") ;
17352
            disable main ;
17353
        end
17354
 
17355
        // Set Translation Address of IMAGE
17356
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
17357
        if ( ok !== 1 )
17358
        begin
17359
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17360
            test_fail("PCI Translation Address Register could not be written") ;
17361
            disable main ;
17362
        end
17363
 
17364
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17365
        if ( ok !== 1 )
17366
        begin
17367
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17368
            test_fail("PCI Image Control register could not be written") ;
17369
            disable main ;
17370
        end
17371
 
17372
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17373
        if ( ok !== 1 )
17374
        begin
17375
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17376
            test_fail("Cache Line Size register could not be written") ;
17377
            disable main ;
17378
        end
17379
 
17380
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17381
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17382
        data = 32'hAAAA_AAAA ;
17383
        byte_enables = 4'h0 ;
17384
        expect_length = `PCIW_DEPTH - 2 ;
17385
 
17386 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
17387 15 mihad
        fork
17388
        begin
17389
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17390
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17391
                        byte_enables,
17392 73 mihad
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17393 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17394
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17395 73 mihad
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17396 15 mihad
            do_pause( 3 ) ;
17397
 
17398
            while ( FRAME !== 1 || IRDY !== 1 )
17399
                @(posedge pci_clock) ;
17400
 
17401 35 mihad
            #1 ;
17402
            if ( !error_monitor_done )
17403
                disable monitor_error_event5 ;
17404 15 mihad
        end
17405
        begin:monitor_error_event5
17406 35 mihad
            error_monitor_done = 0 ;
17407 15 mihad
            pci_ok = 1 ;
17408
            @(error_event_int) ;
17409
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17410
            pci_ok = 0 ;
17411 35 mihad
            error_monitor_done = 1 ;
17412 15 mihad
        end
17413
        begin
17414
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17415
            if ( wb_ok !== 1 )
17416
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17417
        end
17418
        join
17419
 
17420
        if ( wb_ok && pci_ok )
17421
            test_ok ;
17422
 
17423
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17424
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17425
        data = 32'hAAAA_AAAA ;
17426
        byte_enables = 4'h0 ;
17427
        expect_length = `PCIW_DEPTH - 2 ;
17428
 
17429 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
17430 15 mihad
        fork
17431
        begin
17432
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17433
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17434
                        byte_enables,
17435 73 mihad
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17436 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17437
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17438 73 mihad
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17439 15 mihad
            do_pause( 3 ) ;
17440
 
17441
            while ( FRAME !== 1 || IRDY !== 1 )
17442
                @(posedge pci_clock) ;
17443
 
17444 35 mihad
            #1 ;
17445
            if ( !error_monitor_done )
17446
                disable monitor_error_event6 ;
17447 15 mihad
        end
17448
        begin:monitor_error_event6
17449 35 mihad
            error_monitor_done = 0 ;
17450 15 mihad
            pci_ok = 1 ;
17451
            @(error_event_int) ;
17452
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17453
            pci_ok = 0 ;
17454 35 mihad
            error_monitor_done = 1 ;
17455 15 mihad
        end
17456
        begin
17457
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17458
            if ( wb_ok !== 1 )
17459
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17460
        end
17461
        join
17462
 
17463
        if ( wb_ok && pci_ok )
17464
            test_ok ;
17465
 
17466
        master1_check_received_data = 1 ;
17467
//        master2_check_received_data = 0 ;
17468
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17469
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17470
        data = 32'hAAAA_AAAA ;
17471
        byte_enables = 4'h0 ;
17472
        expect_length = 4 ;
17473
 
17474
        fork
17475
        begin
17476
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17477
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17478
                        byte_enables,
17479
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17480
                        8'h0_0, `Test_One_Zero_Target_WS,
17481
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17482
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17483
            do_pause( 1 ) ;
17484
 
17485
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17486
            if ( wb_ok !== 1 )
17487
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17488
 
17489
            do_pause(2) ;
17490
 
17491
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17492
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17493
                        byte_enables,
17494
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17495
                        8'h0_0, `Test_One_Zero_Target_WS,
17496
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17497 92 mihad
                        (pci_subseq_waits == 0) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17498 15 mihad
            do_pause( 3 ) ;
17499
 
17500
            while ( FRAME !== 1 || IRDY !== 1 )
17501
                @(posedge pci_clock) ;
17502
 
17503 35 mihad
            #1 ;
17504
            if ( !error_monitor_done )
17505
                disable monitor_error_event7 ;
17506 15 mihad
        end
17507
        begin:monitor_error_event7
17508 35 mihad
            error_monitor_done = 0 ;
17509 15 mihad
            pci_ok = 1 ;
17510
            @(error_event_int) ;
17511
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17512
            pci_ok = 0 ;
17513 35 mihad
            error_monitor_done = 1 ;
17514 15 mihad
        end
17515
        join
17516
 
17517
        if ( wb_ok && pci_ok )
17518
            test_ok ;
17519
 
17520
        master1_check_received_data = 1 ;
17521
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17522
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17523
        data = 32'hAAAA_AAAA ;
17524
        byte_enables = 4'h0 ;
17525
        expect_length = 4 ;
17526
 
17527
        fork
17528
        begin
17529
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17530
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17531
                        byte_enables,
17532
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17533
                        8'h0_0, `Test_One_Zero_Target_WS,
17534
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17535
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17536
            do_pause( 1 ) ;
17537
 
17538
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17539
            if ( wb_ok !== 1 )
17540
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17541
 
17542
            do_pause(2) ;
17543
 
17544
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17545
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17546
                        byte_enables,
17547
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17548
                        8'h0_0, `Test_One_Zero_Target_WS,
17549
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17550
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17551
            do_pause( 3 ) ;
17552
 
17553
            while ( FRAME !== 1 || IRDY !== 1 )
17554
                @(posedge pci_clock) ;
17555
 
17556 35 mihad
            #1 ;
17557
            if ( !error_monitor_done )
17558
                disable monitor_error_event8 ;
17559 15 mihad
        end
17560
        begin:monitor_error_event8
17561 35 mihad
            error_monitor_done = 0 ;
17562 15 mihad
            pci_ok = 1 ;
17563
            @(error_event_int) ;
17564
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17565
            pci_ok = 0 ;
17566 35 mihad
            error_monitor_done = 1 ;
17567 15 mihad
        end
17568
        join
17569
 
17570
        if ( wb_ok && pci_ok )
17571
            test_ok ;
17572
 
17573
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17574
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17575
        data = 32'hDEAF_BEAF ;
17576
        byte_enables = 4'h0 ;
17577
        expect_length = 1 ;
17578
 
17579
        fork
17580
        begin
17581
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17582
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17583
                        byte_enables,
17584
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17585
                        8'h0_0, `Test_One_Zero_Target_WS,
17586
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17587
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17588
            do_pause( 3 ) ;
17589
 
17590
            while ( FRAME !== 1 || IRDY !== 1 )
17591
                @(posedge pci_clock) ;
17592
 
17593 35 mihad
            #1 ;
17594
            if ( !error_monitor_done )
17595
                disable monitor_error_event9 ;
17596 15 mihad
        end
17597
        begin:monitor_error_event9
17598 35 mihad
            error_monitor_done = 0 ;
17599 15 mihad
            pci_ok = 1 ;
17600
            @(error_event_int) ;
17601
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17602
            pci_ok = 0 ;
17603 35 mihad
            error_monitor_done = 1 ;
17604 15 mihad
        end
17605
        begin
17606
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17607
            if ( wb_ok !== 1 )
17608
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17609
        end
17610
        join
17611
 
17612
        if ( wb_ok && pci_ok )
17613
            test_ok ;
17614
 
17615
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17616
        data = 32'hDEAD_BEAF ;
17617
        byte_enables = 4'h0 ;
17618
        expect_length = 1 ;
17619
 
17620
        fork
17621
        begin
17622
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17623
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17624
                        byte_enables,
17625
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17626
                        8'h0_0, `Test_One_Zero_Target_WS,
17627
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17628
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17629
            do_pause( 3 ) ;
17630
 
17631
            while ( FRAME !== 1 || IRDY !== 1 )
17632
                @(posedge pci_clock) ;
17633
 
17634 35 mihad
            #1 ;
17635
            if ( !error_monitor_done )
17636
                disable monitor_error_event10 ;
17637 15 mihad
        end
17638
        begin:monitor_error_event10
17639 35 mihad
            error_monitor_done = 0 ;
17640 15 mihad
            pci_ok = 1 ;
17641
            @(error_event_int) ;
17642
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17643
            pci_ok = 0 ;
17644 35 mihad
            error_monitor_done = 1 ;
17645 15 mihad
        end
17646
        begin
17647
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17648
            if ( wb_ok !== 1 )
17649
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17650
        end
17651
        join
17652
 
17653
        if ( wb_ok && pci_ok )
17654
            test_ok ;
17655
 
17656
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17657
        data = 32'hAAAA_AAAA ;
17658
        byte_enables = 4'h0 ;
17659
        expect_length = 1 ;
17660
 
17661
        fork
17662
        begin
17663
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17664
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17665
                        byte_enables,
17666
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17667
                        8'h0_0, `Test_One_Zero_Target_WS,
17668
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17669
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17670
            do_pause( 3 ) ;
17671
 
17672
            while ( FRAME !== 1 || IRDY !== 1 )
17673
                @(posedge pci_clock) ;
17674
 
17675 35 mihad
            #1 ;
17676
            if ( !error_monitor_done )
17677
                disable monitor_error_event11 ;
17678 15 mihad
        end
17679
        begin:monitor_error_event11
17680 35 mihad
            error_monitor_done = 0 ;
17681 15 mihad
            pci_ok = 1 ;
17682
            @(error_event_int) ;
17683
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17684
            pci_ok = 0 ;
17685 35 mihad
            error_monitor_done = 1 ;
17686 15 mihad
        end
17687
        begin
17688
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17689
            if ( wb_ok !== 1 )
17690
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17691
        end
17692
        join
17693
 
17694
        if ( wb_ok && pci_ok )
17695
            test_ok ;
17696
 
17697
        master1_check_received_data = 1 ;
17698
 
17699
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17700
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17701
        data = 32'hDEAF_BEAF ;
17702
        byte_enables = 4'h0 ;
17703
        expect_length = 1 ;
17704
 
17705
        fork
17706
        begin
17707
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17708
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17709
                        byte_enables,
17710
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17711
                        8'h0_0, `Test_One_Zero_Target_WS,
17712
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17713
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17714
            do_pause( 1 ) ;
17715
 
17716
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17717
            if ( wb_ok !== 1 )
17718
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17719
 
17720
            do_pause(3) ;
17721
 
17722
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17723
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17724
                        byte_enables,
17725
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17726
                        8'h0_0, `Test_One_Zero_Target_WS,
17727
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17728
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17729
            do_pause( 3 ) ;
17730
 
17731
            while ( FRAME !== 1 || IRDY !== 1 )
17732
                @(posedge pci_clock) ;
17733
 
17734 35 mihad
            #1 ;
17735
            if ( !error_monitor_done )
17736
                disable monitor_error_event12 ;
17737 15 mihad
        end
17738
        begin:monitor_error_event12
17739 35 mihad
            error_monitor_done = 0 ;
17740 15 mihad
            pci_ok = 1 ;
17741
            @(error_event_int) ;
17742
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17743
            pci_ok = 0 ;
17744 35 mihad
            error_monitor_done = 1 ;
17745 15 mihad
        end
17746
        join
17747
 
17748
        if ( wb_ok && pci_ok )
17749
            test_ok ;
17750
 
17751
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17752
        data = 32'hDEAD_BEAF ;
17753
        byte_enables = 4'h0 ;
17754
        expect_length = 1 ;
17755
 
17756
        fork
17757
        begin
17758
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17759
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17760
                        byte_enables,
17761
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17762
                        8'h0_0, `Test_One_Zero_Target_WS,
17763
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17764
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17765
            do_pause( 1 ) ;
17766
 
17767
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17768
            if ( wb_ok !== 1 )
17769
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17770
 
17771
            do_pause(3) ;
17772
 
17773
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17774
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17775
                        byte_enables,
17776
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17777
                        8'h0_0, `Test_One_Zero_Target_WS,
17778
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17779
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17780
            do_pause( 3 ) ;
17781
 
17782
            while ( FRAME !== 1 || IRDY !== 1 )
17783
                @(posedge pci_clock) ;
17784
 
17785 35 mihad
            #1 ;
17786
            if ( !error_monitor_done )
17787
                disable monitor_error_event13 ;
17788 15 mihad
        end
17789
        begin:monitor_error_event13
17790 35 mihad
            error_monitor_done = 0 ;
17791 15 mihad
            pci_ok = 1 ;
17792
            @(error_event_int) ;
17793
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17794
            pci_ok = 0 ;
17795 35 mihad
            error_monitor_done = 1 ;
17796 15 mihad
        end
17797
        join
17798
 
17799
        if ( wb_ok && pci_ok )
17800
            test_ok ;
17801
 
17802
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17803
        data = 32'hAAAA_AAAA ;
17804
        byte_enables = 4'h0 ;
17805
        expect_length = 1 ;
17806
 
17807
        fork
17808
        begin
17809
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17810
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17811
                        byte_enables,
17812
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17813
                        8'h0_0, `Test_One_Zero_Target_WS,
17814
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17815
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17816
            do_pause( 1 ) ;
17817
 
17818
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17819
            if ( wb_ok !== 1 )
17820
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17821
 
17822
            do_pause(3) ;
17823
 
17824
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17825
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17826
                        byte_enables,
17827
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17828
                        8'h0_0, `Test_One_Zero_Target_WS,
17829
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17830
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17831
            do_pause( 3 ) ;
17832
 
17833
            while ( FRAME !== 1 || IRDY !== 1 )
17834
                @(posedge pci_clock) ;
17835
 
17836 35 mihad
            #1 ;
17837
            if ( !error_monitor_done )
17838
                disable monitor_error_event14 ;
17839 15 mihad
        end
17840
        begin:monitor_error_event14
17841 35 mihad
            error_monitor_done = 0 ;
17842 15 mihad
            pci_ok = 1 ;
17843
            @(error_event_int) ;
17844
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17845
            pci_ok = 0 ;
17846 35 mihad
            error_monitor_done = 1 ;
17847 15 mihad
        end
17848
        join
17849
 
17850
        if ( wb_ok && pci_ok )
17851
            test_ok ;
17852
 
17853
        // disable the image
17854
        test_name = "DISABLING MEMORY IMAGE" ;
17855 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17856 15 mihad
        if ( ok !== 1 )
17857
        begin
17858
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17859
            test_fail("PCI Address Mask register could not be written") ;
17860
            disable main ;
17861
        end
17862
    end
17863 92 mihad
 
17864 15 mihad
    if ( target_io_image !== -1 )
17865
    begin
17866
        do_io_disconnects = 1 ;
17867
 
17868
        if (target_io_image === 1)
17869
        begin
17870
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17871
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17872
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17873
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17874
        end
17875
        else if (target_io_image === 2)
17876
        begin
17877
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17878
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17879
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17880
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17881
        end
17882
        else if (target_io_image === 3)
17883
        begin
17884
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17885
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17886
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17887
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17888
        end
17889
        else if (target_io_image === 4)
17890
        begin
17891
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17892
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17893
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17894
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17895
        end
17896
        else if (target_io_image === 5)
17897
        begin
17898
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17899
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17900
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17901
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17902
        end
17903
    end
17904
    else
17905
        do_io_disconnects = 0 ;
17906
 
17907
    if ( do_io_disconnects )
17908
    begin
17909
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17910
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17911
        if ( ok !== 1 )
17912
        begin
17913
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17914
            test_fail("PCI Base Address register could not be written") ;
17915
            disable main ;
17916
        end
17917
 
17918
        // Set Address Mask of IMAGE
17919
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17920
        if ( ok !== 1 )
17921
        begin
17922
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17923
            test_fail("PCI Address Mask register could not be written") ;
17924
            disable main ;
17925
        end
17926
 
17927
        // Set Translation Address of IMAGE
17928
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17929
        if ( ok !== 1 )
17930
        begin
17931
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17932
            test_fail("PCI Translation Address Register could not be written") ;
17933
            disable main ;
17934
        end
17935
 
17936
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17937
        if ( ok !== 1 )
17938
        begin
17939
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17940
            test_fail("PCI Image Control register could not be written") ;
17941
            disable main ;
17942
        end
17943
 
17944
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17945
        if ( ok !== 1 )
17946
        begin
17947
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17948
            test_fail("Cache Line Size register could not be written") ;
17949
            disable main ;
17950
        end
17951
 
17952
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17953
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17954
        data = 32'h5555_5555 ;
17955
        byte_enables = 4'h0 ;
17956
        expect_length = 1 ;
17957
 
17958 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
17959 15 mihad
 
17960
        fork
17961
        begin
17962
            PCIU_IO_WRITE
17963
            (
17964
                `Test_Master_1,             // which master
17965
                pci_address,                // to what address
17966
                data,                       // data
17967
                byte_enables,               // byte enable
17968
                expect_length + 1,          // length to request
17969
                `Test_Target_Retry_On       // expected target termination
17970
            ) ;
17971
 
17972
            do_pause( 3 ) ;
17973
 
17974
            while ( FRAME !== 1 || IRDY !== 1 )
17975
                @(posedge pci_clock) ;
17976
 
17977 35 mihad
            #1 ;
17978
            if ( !error_monitor_done )
17979
                disable monitor_error_event15 ;
17980 15 mihad
        end
17981
        begin:monitor_error_event15
17982 35 mihad
            error_monitor_done = 0 ;
17983 15 mihad
            pci_ok = 1 ;
17984
            @(error_event_int) ;
17985
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17986
            pci_ok = 0 ;
17987 35 mihad
            error_monitor_done = 1 ;
17988 15 mihad
        end
17989
        begin
17990
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17991
            if ( wb_ok !== 1 )
17992
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17993
        end
17994
        join
17995
 
17996
        if ( wb_ok && pci_ok )
17997
            test_ok ;
17998
 
17999
        data = 32'hAAAA_AAAA ;
18000
        fork
18001
        begin
18002
            PCIU_IO_WRITE
18003
            (
18004
                `Test_Master_1,             // which master
18005
                pci_address,                // to what address
18006
                data,                       // data
18007
                byte_enables,               // byte enable
18008
                expect_length + 2,          // length to request
18009
                `Test_Target_Retry_Before   // expected target termination
18010
            ) ;
18011
 
18012
            do_pause( 3 ) ;
18013
 
18014
            while ( FRAME !== 1 || IRDY !== 1 )
18015
                @(posedge pci_clock) ;
18016
 
18017 35 mihad
            #1 ;
18018
            if ( !error_monitor_done )
18019
                disable monitor_error_event16 ;
18020 15 mihad
        end
18021
        begin:monitor_error_event16
18022 35 mihad
            error_monitor_done = 0 ;
18023 15 mihad
            pci_ok = 1 ;
18024
            @(error_event_int) ;
18025
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
18026
            pci_ok = 0 ;
18027 35 mihad
            error_monitor_done = 1 ;
18028 15 mihad
        end
18029
        begin
18030
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
18031
            if ( wb_ok !== 1 )
18032
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
18033
        end
18034
        join
18035
 
18036
        if ( wb_ok && pci_ok )
18037
            test_ok ;
18038
 
18039
        master2_check_received_data = 1 ;
18040
 
18041
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
18042
 
18043
        fork
18044
        begin
18045
 
18046
             PCIU_IO_READ
18047
             (
18048
                `Test_Master_2,
18049
                pci_address[PCI_BUS_DATA_RANGE:0],
18050
                data,
18051
                byte_enables,
18052
                2,
18053
                `Test_Target_Retry_Before
18054
             );
18055
 
18056
            do_pause( 1 ) ;
18057
 
18058
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
18059
            if ( wb_ok !== 1 )
18060
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
18061
 
18062
            do_pause(3) ;
18063
 
18064
            PCIU_IO_READ
18065
             (
18066
                `Test_Master_2,
18067
                pci_address[PCI_BUS_DATA_RANGE:0],
18068
                data,
18069
                byte_enables,
18070
                expect_length + 1,
18071
                `Test_Target_Retry_On
18072
             );
18073
 
18074
            do_pause( 3 ) ;
18075
 
18076
            while ( FRAME !== 1 || IRDY !== 1 )
18077
                @(posedge pci_clock) ;
18078
 
18079 35 mihad
            #1 ;
18080
            if ( !error_monitor_done )
18081
                disable monitor_error_event17 ;
18082 15 mihad
        end
18083
        begin:monitor_error_event17
18084 35 mihad
            error_monitor_done = 0 ;
18085 15 mihad
            pci_ok = 1 ;
18086
            @(error_event_int) ;
18087
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
18088
            pci_ok = 0 ;
18089 35 mihad
            error_monitor_done = 1 ;
18090 15 mihad
        end
18091
        join
18092
 
18093
        if ( wb_ok && pci_ok )
18094
            test_ok ;
18095
 
18096
        fork
18097
        begin
18098
 
18099
             PCIU_IO_READ
18100
             (
18101
                `Test_Master_2,
18102
                pci_address[PCI_BUS_DATA_RANGE:0],
18103
                data,
18104
                byte_enables,
18105
                2,
18106
                `Test_Target_Retry_Before
18107
             );
18108
 
18109
            do_pause( 1 ) ;
18110
 
18111
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
18112
            if ( wb_ok !== 1 )
18113
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
18114
 
18115
            do_pause(3) ;
18116
 
18117
            PCIU_IO_READ
18118
             (
18119
                `Test_Master_2,
18120
                pci_address[PCI_BUS_DATA_RANGE:0],
18121
                data,
18122
                byte_enables,
18123
                expect_length + 2,
18124
                `Test_Target_Retry_Before
18125
             );
18126
 
18127
            do_pause( 3 ) ;
18128
 
18129
            while ( FRAME !== 1 || IRDY !== 1 )
18130
                @(posedge pci_clock) ;
18131
 
18132 35 mihad
            #1 ;
18133
            if ( !error_monitor_done )
18134
                disable monitor_error_event18 ;
18135 15 mihad
        end
18136
        begin:monitor_error_event18
18137 35 mihad
            error_monitor_done = 0 ;
18138 15 mihad
            pci_ok = 1 ;
18139
            @(error_event_int) ;
18140
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
18141
            pci_ok = 0 ;
18142 35 mihad
            error_monitor_done = 1 ;
18143 15 mihad
        end
18144
        join
18145
 
18146
        if ( wb_ok && pci_ok )
18147
            test_ok ;
18148
 
18149
        test_name = "DISABLING IO IMAGE" ;
18150 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
18151 15 mihad
        if ( ok !== 1 )
18152
        begin
18153
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
18154
            test_fail("PCI Address Mask register could not be written") ;
18155
            disable main ;
18156
        end
18157
    end
18158 92 mihad
 
18159 15 mihad
end
18160
endtask // target_disconnects
18161
 
18162
task target_unsupported_cmds ;
18163
        input [31:0] Address;
18164
        input [2:0]  image_num ;
18165
    reg          ok ;
18166
begin:main
18167
 
18168
    $display("  ") ;
18169
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
18170
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
18171 45 mihad
 
18172
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
18173
    configuration_cycle_write
18174
    (
18175
        0,                        // bus number
18176
        `TAR1_IDSEL_INDEX - 11,   // device number
18177
        0,                        // function number
18178
        1,                        // register number
18179
        0,                        // type of configuration cycle
18180
        4'b0001,                  // byte enables
18181
        32'h0000_0044             // data
18182
    ) ;
18183
 
18184
    configuration_cycle_write
18185
    (
18186
        0,                        // bus number
18187
        `TAR2_IDSEL_INDEX - 11,   // device number
18188
        0,                        // function number
18189
        1,                        // register number
18190
        0,                        // type of configuration cycle
18191
        4'b0001,                  // byte enables
18192
        32'h0000_0044             // data
18193
    ) ;
18194
 
18195 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18196 15 mihad
    (
18197
        Address,                // first part of address in dual address cycle
18198
        Address,                // second part of address in dual address cycle
18199
        `BC_IACK,                       // dual address cycle command
18200
        `BC_IACK,               // normal command
18201 92 mihad
        4'hF,               // byte enables
18202 15 mihad
        32'h1234_5678,      // data
18203
        1'b0,               // make address parity error on first phase of dual address
18204
        1'b0,               // make address parity error on second phase of dual address
18205
        ok                  // result of operation
18206
    ) ;
18207
    if ( ok )
18208
        test_ok ;
18209
    else
18210
    begin
18211
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18212
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
18213
    end
18214
 
18215
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
18216
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
18217 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18218 15 mihad
    (
18219
        Address,                // first part of address in dual address cycle
18220
        Address,                // second part of address in dual address cycle
18221
        `BC_SPECIAL,            // dual address cycle command
18222
        `BC_SPECIAL,            // normal command
18223 92 mihad
        4'hF,               // byte enables
18224 15 mihad
        32'h1234_5678,      // data
18225
        1'b0,               // make address parity error on first phase of dual address
18226
        1'b0,               // make address parity error on second phase of dual address
18227
        ok                  // result of operation
18228
    ) ;
18229
    if ( ok )
18230
        test_ok ;
18231
    else
18232
    begin
18233
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18234
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
18235
    end
18236
 
18237
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
18238
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
18239 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18240 15 mihad
    (
18241
        Address,                // first part of address in dual address cycle
18242
        Address,                // second part of address in dual address cycle
18243
        `BC_RESERVED0,          // dual address cycle command
18244
        `BC_RESERVED0,      // normal command
18245 92 mihad
        4'hF,               // byte enables
18246 15 mihad
        32'h1234_5678,      // data
18247
        1'b0,               // make address parity error on first phase of dual address
18248
        1'b0,               // make address parity error on second phase of dual address
18249
        ok                  // result of operation
18250
    ) ;
18251
    if ( ok )
18252
        test_ok ;
18253
    else
18254
    begin
18255
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18256
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
18257
    end
18258
 
18259
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
18260
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
18261 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18262 15 mihad
    (
18263
        Address,                // first part of address in dual address cycle
18264
        Address,                // second part of address in dual address cycle
18265
        `BC_RESERVED1,          // dual address cycle command
18266
        `BC_RESERVED1,      // normal command
18267 92 mihad
        4'hF,               // byte enables
18268 15 mihad
        32'h1234_5678,      // data
18269
        1'b0,               // make address parity error on first phase of dual address
18270
        1'b0,               // make address parity error on second phase of dual address
18271
        ok                  // result of operation
18272
    ) ;
18273
    if ( ok )
18274
        test_ok ;
18275
    else
18276
    begin
18277
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18278
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
18279
    end
18280
 
18281
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
18282
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
18283 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18284 15 mihad
    (
18285
        Address,                // first part of address in dual address cycle
18286
        Address,                // second part of address in dual address cycle
18287
        `BC_RESERVED2,          // dual address cycle command
18288
        `BC_RESERVED2,      // normal command
18289 92 mihad
        4'hF,               // byte enables
18290 15 mihad
        32'h1234_5678,      // data
18291
        1'b0,               // make address parity error on first phase of dual address
18292
        1'b0,               // make address parity error on second phase of dual address
18293
        ok                  // result of operation
18294
    ) ;
18295
    if ( ok )
18296
        test_ok ;
18297
    else
18298
    begin
18299
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18300
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
18301
    end
18302
 
18303
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
18304
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
18305 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18306 15 mihad
    (
18307
        Address,                // first part of address in dual address cycle
18308
        Address,                // second part of address in dual address cycle
18309
        `BC_RESERVED3,          // dual address cycle command
18310
        `BC_RESERVED3,      // normal command
18311 92 mihad
        4'hF,               // byte enables
18312 15 mihad
        32'h1234_5678,      // data
18313
        1'b0,               // make address parity error on first phase of dual address
18314
        1'b0,               // make address parity error on second phase of dual address
18315
        ok                  // result of operation
18316
    ) ;
18317
    if ( ok )
18318
        test_ok ;
18319
    else
18320
    begin
18321
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18322
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
18323
    end
18324
 
18325
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
18326
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
18327
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
18328
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
18329 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18330 15 mihad
    (
18331
        Address,                // first part of address in dual address cycle
18332
        Address,                // second part of address in dual address cycle
18333
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
18334
        `BC_MEM_WRITE,      // normal command
18335 92 mihad
        4'hF,               // byte enables;
18336 15 mihad
        32'h1234_5678,      // data
18337
        1'b0,               // make address parity error on first phase of dual address
18338
        1'b0,               // make address parity error on second phase of dual address
18339
        ok                  // result of operation
18340
    ) ;
18341
    if ( ok )
18342
        test_ok ;
18343
    else
18344
    begin
18345
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18346
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
18347
    end
18348
 
18349 45 mihad
    // enable pci blue behavioral targets 1 and 2
18350
    configuration_cycle_write
18351
    (
18352
        0,                        // bus number
18353
        `TAR1_IDSEL_INDEX - 11,   // device number
18354
        0,                        // function number
18355
        1,                        // register number
18356
        0,                        // type of configuration cycle
18357
        4'b0001,                  // byte enables
18358
        32'h0000_0047             // data
18359
    ) ;
18360
 
18361
    configuration_cycle_write
18362
    (
18363
        0,                        // bus number
18364
        `TAR2_IDSEL_INDEX - 11,   // device number
18365
        0,                        // function number
18366
        1,                        // register number
18367
        0,                        // type of configuration cycle
18368
        4'b0001,                  // byte enables
18369
        32'h0000_0047             // data
18370
    ) ;
18371 15 mihad
end
18372
endtask // target_unsupported_cmds
18373
 
18374 63 mihad
`ifdef DISABLE_COMPLETION_EXPIRED_TESTS
18375
`else
18376 15 mihad
task target_completion_expiration ;
18377
    reg   [11:0] pci_ctrl_offset ;
18378
    reg   [11:0] pci_ba_offset ;
18379
    reg   [11:0] pci_am_offset ;
18380
    reg   [11:0] pci_device_ctrl_offset ;
18381
    reg   [11:0] pci_err_cs_offset ;
18382
    reg   [11:0] icr_offset ;
18383
    reg   [11:0] isr_offset ;
18384
    reg   [11:0] lat_tim_cls_offset ;
18385
 
18386
    reg [31:0] temp_val1 ;
18387
    reg [31:0] temp_val2 ;
18388
    reg        ok   ;
18389 33 mihad
    reg        ok_wb ;
18390
    reg        ok_pci ;
18391 15 mihad
 
18392
    reg [31:0] pci_image_base ;
18393
    integer i ;
18394 33 mihad
    integer clocks_after_completion ;
18395
    reg     error_monitor_done ;
18396
    reg     test_mem ;
18397 15 mihad
 
18398
begin:main
18399
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18400
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
18401
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
18402
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
18403
 
18404
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
18405
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
18406
    lat_tim_cls_offset = 12'hC ;
18407
    pci_device_ctrl_offset    = 12'h4 ;
18408
 
18409 33 mihad
    `ifdef HOST
18410
        test_mem = 1'b1 ;
18411
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
18412
    `else
18413
        test_mem = !`PCI_BA1_MEM_IO ;
18414
        pci_image_base = Target_Base_Addr_R[1] ;
18415
    `endif
18416 15 mihad
 
18417
    // enable master & target operation
18418
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
18419
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
18420
    if ( ok !== 1 )
18421
    begin
18422
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18423
        test_fail("write to PCI Device Control register failed") ;
18424
        disable main ;
18425
    end
18426
 
18427
    // prepare image control register
18428 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18429 15 mihad
    if ( ok !== 1 )
18430
    begin
18431
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18432
        test_fail("write to PCI Image Control register failed") ;
18433
        disable main ;
18434
    end
18435
 
18436
    // prepare base address register
18437
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18438
    if ( ok !== 1 )
18439
    begin
18440
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18441
        test_fail("write to PCI Base Address register failed") ;
18442
        disable main ;
18443
    end
18444
 
18445
    // write address mask register
18446
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18447
    if ( ok !== 1 )
18448
    begin
18449
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18450
        test_fail("write to PCI Address Mask register failed") ;
18451
        disable main ;
18452
    end
18453
 
18454
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18455
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18456
    if ( ok !== 1 )
18457
    begin
18458
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18459
        test_fail("write to PCI Error Control and Status register failed") ;
18460
        disable main ;
18461
    end
18462
 
18463 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18464 15 mihad
    if ( ok !== 1 )
18465
    begin
18466
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18467
        test_fail("write to Interrupt Control register failed") ;
18468
        disable main ;
18469
    end
18470
 
18471
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18472
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18473
    if ( ok !== 1 )
18474
    begin
18475
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18476
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18477
        disable main ;
18478
    end
18479
 
18480
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18481
 
18482 92 mihad
    wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
18483 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18484
    master1_check_received_data = 0 ;
18485 15 mihad
 
18486 33 mihad
    ok_pci = 1 ;
18487
    // start a delayed read request
18488
    fork
18489
    begin
18490
        if ( test_mem )
18491
 
18492
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18493
                          pci_image_base, 32'h1234_5678,
18494
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18495
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18496
        else
18497
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18498
 
18499
        do_pause( 1 ) ;
18500
    end
18501
    begin:error_monitor1
18502 35 mihad
        error_monitor_done = 0 ;
18503 33 mihad
        @(error_event_int) ;
18504
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18505
        ok_pci = 0 ;
18506 35 mihad
        error_monitor_done = 1 ;
18507 33 mihad
    end
18508
    begin
18509
        if ( test_mem )
18510
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18511
        else
18512
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18513 15 mihad
 
18514 33 mihad
        if ( ok_wb !== 1 )
18515
        begin
18516
            test_fail("Bridge failed to process Target Memory read correctly") ;
18517
            disable main ;
18518
        end
18519
 
18520 35 mihad
        #1 ;
18521
        if ( !error_monitor_done )
18522 33 mihad
            disable error_monitor1 ;
18523
    end
18524
    join
18525
 
18526
    clocks_after_completion = 0 ;
18527
    // now do another - different transaction
18528
    fork
18529
    begin
18530
        if ( test_mem )
18531
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18532
                          pci_image_base + 4, 32'h1234_5678,
18533
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18534
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18535
        else
18536
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18537
 
18538
        while ( clocks_after_completion < 32'h0000_FFF0 )
18539
        begin
18540
            @(posedge pci_clock) ;
18541
            clocks_after_completion = clocks_after_completion + 1 ;
18542
        end
18543
 
18544
        do_pause('hFF) ;
18545
 
18546
        if ( test_mem )
18547
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18548
                          pci_image_base + 4, 32'h1234_5678,
18549
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18550
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18551
        else
18552
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18553
 
18554
        do_pause( 1 ) ;
18555
    end
18556
    begin:error_monitor2
18557 35 mihad
        error_monitor_done = 0 ;
18558 33 mihad
        @(error_event_int) ;
18559
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18560
        ok_pci = 0 ;
18561 35 mihad
        error_monitor_done = 1 ;
18562 33 mihad
    end
18563
    begin
18564
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18565
        repeat( 'hFF )
18566
            @(posedge pci_clock) ;
18567
 
18568
        if ( test_mem )
18569
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18570
        else
18571
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18572
 
18573
        if ( ok_wb !== 1 )
18574
        begin
18575
            test_fail("Bridge failed to process Target Memory read correctly") ;
18576
            disable main ;
18577
        end
18578
 
18579
        repeat(4)
18580
            @(posedge pci_clock) ;
18581
 
18582
        fork
18583
        begin
18584
            if ( test_mem )
18585
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18586
                              pci_image_base + 4, 32'h1234_5678,
18587
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18588
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18589
            else
18590
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18591
 
18592
            do_pause(1) ;
18593
        end
18594
        begin
18595
           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 ) ;
18596 35 mihad
           #1 ;
18597
           if ( !error_monitor_done )
18598 33 mihad
               disable error_monitor2 ;
18599
        end
18600
        join
18601
    end
18602
    join
18603
 
18604
    if ( ok && ok_pci && ok_wb )
18605
        test_ok ;
18606
 
18607
    if ( ok !== 1 )
18608
    begin
18609
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18610
        test_fail("write to PCI Address Mask register failed") ;
18611
        disable main ;
18612
    end
18613
 
18614
    // check statuses after this situation - none should be set
18615
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18616
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18617
    if ( ok !== 1 )
18618
    begin
18619
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18620
        test_fail("read from pci device status register failed") ;
18621
        disable main ;
18622
    end
18623
 
18624
    if ( temp_val1[31] )
18625
    begin
18626
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18627
        test_fail("detected parity error bit was set for no reason") ;
18628
    end
18629
 
18630
    if ( temp_val1[30] )
18631
    begin
18632
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18633
        test_fail("signaled system error bit was set for no reason") ;
18634
    end
18635
 
18636
    if ( temp_val1[29] )
18637
    begin
18638
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18639
        test_fail("received master abort bit was set for no reason") ;
18640
    end
18641
 
18642
    if ( temp_val1[28] )
18643
    begin
18644
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18645
        test_fail("received target abort bit was set for no reason") ;
18646
    end
18647
 
18648
    if ( temp_val1[27] )
18649
    begin
18650
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18651
        test_fail("signaled target abort bit was set for no reason") ;
18652
    end
18653
 
18654
    if ( temp_val1[24] )
18655
    begin
18656
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18657
        test_fail("Master Data parity error bit was set for no reason") ;
18658
    end
18659
 
18660
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18661
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18662
    if ( temp_val1[8] !== 0 )
18663
    begin
18664
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18665
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18666
    end
18667 87 mihad
 
18668 33 mihad
    // set wb slave to retry response
18669 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'd255);
18670 33 mihad
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18671
    ok_pci = 1 ;
18672
 
18673
    fork
18674
    begin
18675
        if ( test_mem == 1 )
18676
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18677 87 mihad
                        pci_image_base, 32'hBEAF_DEAD, 4'h5,
18678 33 mihad
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18679
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18680
        else
18681 87 mihad
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h5, 1, `Test_Target_Normal_Completion) ;
18682 33 mihad
 
18683
        do_pause(1) ;
18684
 
18685
        // do another write with same address and different data
18686
        if ( test_mem == 1 )
18687
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18688 87 mihad
                        pci_image_base, 32'h1234_5678, 4'h0,
18689 33 mihad
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18690
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18691
        else
18692 87 mihad
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion) ;
18693 33 mihad
 
18694
        do_pause(1) ;
18695
    end
18696
    begin
18697
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18698
        begin
18699
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18700
            if ( ok_wb !== 1 )
18701
            begin
18702
                $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) ;
18703
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18704
                disable main ;
18705
            end
18706
        end
18707
 
18708
        // set WB slave to normal completion
18709 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
18710 33 mihad
 
18711
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18712
        if ( ok_wb !== 1 )
18713
        begin
18714
            $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) ;
18715
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18716
            disable main ;
18717
        end
18718
 
18719 35 mihad
        #1 ;
18720
        if ( !error_monitor_done )
18721 33 mihad
            disable error_monitor3 ;
18722
    end
18723
    begin:error_monitor3
18724 35 mihad
        error_monitor_done = 0 ;
18725 33 mihad
        @(error_event_int) ;
18726
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18727
        ok_pci = 0 ;
18728 35 mihad
        error_monitor_done = 1 ;
18729 33 mihad
    end
18730
    join
18731
 
18732
    if ( ok_wb && ok_pci )
18733
    begin
18734
        test_ok ;
18735
    end
18736
 
18737
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18738
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18739
    if ( temp_val1[8] !== 1'b1 )
18740
    begin
18741
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18742
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18743
    end
18744
 
18745
    if ( temp_val1[9] !== 1 )
18746
    begin
18747
        $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) ;
18748
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18749
    end
18750
 
18751
    if ( temp_val1[10] !== 1 )
18752
    begin
18753
        $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) ;
18754
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18755
    end
18756
 
18757
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18758
    begin
18759
        $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) ;
18760
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18761
    end
18762
 
18763 87 mihad
    if ( temp_val1[31:28] !== 4'h5 )
18764 33 mihad
    begin
18765
        $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) ;
18766 87 mihad
        $display("Expected value: %h, actual value %h", 4'h5, temp_val1[31:28]) ;
18767 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") ;
18768
    end
18769
 
18770
    // clear error status register
18771
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18772
 
18773
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18774
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18775
    if ( temp_val1 !== pci_image_base )
18776
    begin
18777
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18778
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18779
    end
18780
 
18781
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18782
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18783 87 mihad
    if ( temp_val1 !== (32'hBEAF_DEAD) )
18784 33 mihad
    begin
18785
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18786 87 mihad
        $display("Expected value %h, actual %h", 32'hBEAF_DEAD, temp_val1) ;
18787 33 mihad
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18788
    end
18789
 
18790
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18791
    ok_pci = 1 ;
18792 92 mihad
    wishbone_slave.cycle_response(3'b001, wb_subseq_waits, 8'd255);
18793 33 mihad
 
18794
    i = 0 ;
18795
    fork
18796
    begin
18797
        if ( test_mem )
18798
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18799
                          pci_image_base + 4, 32'h1234_5678,
18800
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18801
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18802
        else
18803
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18804
 
18805
        do_pause( 1 ) ;
18806
 
18807
    end
18808
    begin
18809
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18810
        begin
18811
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18812
            if ( ok_wb !== 1 )
18813
            begin
18814
                $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) ;
18815
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18816
                disable main ;
18817
            end
18818
        end
18819
 
18820
        // set WB slave to normal completion
18821 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'h0);
18822 33 mihad
 
18823
        fork
18824
        begin
18825
            repeat(4)
18826
                @(posedge pci_clock) ;
18827
 
18828
            if ( test_mem )
18829
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18830
                              pci_image_base, 32'h8765_4321,
18831
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18832
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18833
            else
18834
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18835
 
18836
            do_pause(1) ;
18837
        end
18838
        begin
18839
 
18840
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18841
            if ( ok_wb !== 1 )
18842
            begin
18843
                $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) ;
18844
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18845
                disable main ;
18846
            end
18847
        end
18848
        join
18849
 
18850
        repeat( 4 )
18851
            @(posedge pci_clock) ;
18852
 
18853
        if ( test_mem )
18854
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18855
                          pci_image_base, 32'h8765_4321,
18856
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18857
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18858
        else
18859
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18860
 
18861
        do_pause(1) ;
18862
 
18863 35 mihad
        #1 ;
18864
        if ( !error_monitor_done )
18865 33 mihad
            disable error_monitor4 ;
18866
    end
18867
    begin:error_monitor4
18868 35 mihad
        error_monitor_done = 0 ;
18869 33 mihad
        @(error_event_int) ;
18870
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18871
        ok_pci = 0 ;
18872 35 mihad
        error_monitor_done = 1 ;
18873 33 mihad
    end
18874
    join
18875
 
18876
    if ( ok_wb && ok_pci )
18877
        test_ok ;
18878
 
18879
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18880
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18881
    if ( temp_val1[8] !== 1'b0 )
18882
    begin
18883
        $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) ;
18884
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18885
    end
18886 87 mihad
 
18887
`ifdef PCI_WBM_NO_RESPONSE_CNT_DISABLE
18888
`else
18889 33 mihad
 
18890 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18891
    $fdisplay(pciu_mon_log_file_desc,
18892
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18893 33 mihad
 
18894
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18895
    ok_pci = 1 ;
18896 92 mihad
    wishbone_slave.cycle_response(3'b000, wb_subseq_waits, 8'd255);
18897 33 mihad
 
18898
    fork
18899
    begin
18900
        if ( test_mem == 1 )
18901
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18902 87 mihad
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18903 33 mihad
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18904
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18905
        else
18906 87 mihad
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
18907 33 mihad
 
18908
        do_pause(1) ;
18909
 
18910
        // do another write with same address and different data
18911
        if ( test_mem == 1 )
18912
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18913
                        pci_image_base, 32'h8765_6789, 4'h0,
18914
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18915
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18916
        else
18917
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18918
 
18919
        do_pause(1) ;
18920
    end
18921
    begin
18922
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18923
        if ( ok_wb !== 1 )
18924
        begin
18925
            $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) ;
18926
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18927
            disable main ;
18928
        end
18929
 
18930 92 mihad
        wishbone_slave.cycle_response(3'b100, wb_subseq_waits, 8'd255);
18931 33 mihad
 
18932
        if ( test_mem )
18933
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18934
        else
18935
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18936
 
18937
        if ( ok_wb !== 1 )
18938
        begin
18939
            $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) ;
18940
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18941
            disable main ;
18942
        end
18943
 
18944 35 mihad
        #1 ;
18945
        if ( !error_monitor_done )
18946 33 mihad
            disable error_monitor6 ;
18947
    end
18948
    begin:error_monitor6
18949 35 mihad
        error_monitor_done = 0 ;
18950 33 mihad
        @(error_event_int) ;
18951
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18952
        ok_pci = 0 ;
18953 35 mihad
        error_monitor_done = 1 ;
18954 33 mihad
    end
18955
    join
18956
 
18957
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18958
    $fdisplay(pciu_mon_log_file_desc,
18959
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18960
 
18961
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18962
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18963
    if ( temp_val1[8] !== 1'b1 )
18964
    begin
18965
        $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) ;
18966
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18967
    end
18968
 
18969
    if ( temp_val1[9] !== 0 )
18970
    begin
18971
        $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) ;
18972
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18973
    end
18974
 
18975
    if ( temp_val1[10] !== 1 )
18976
    begin
18977
        $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) ;
18978
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18979
    end
18980
 
18981
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18982
    begin
18983
        $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) ;
18984
        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") ;
18985
    end
18986
 
18987 87 mihad
    if ( temp_val1[31:28] !== 4'hA )
18988 33 mihad
    begin
18989
        $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) ;
18990
        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") ;
18991
    end
18992
 
18993
    // clear error status register
18994
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18995
 
18996
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18997
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18998
    if ( temp_val1 !== pci_image_base )
18999
    begin
19000
        $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) ;
19001
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
19002
    end
19003
 
19004
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
19005
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
19006 87 mihad
    if ( temp_val1 !== 32'hDEAD_BEAF )
19007 33 mihad
    begin
19008
        $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) ;
19009
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
19010
    end
19011 92 mihad
 
19012
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
19013
    $fdisplay(pciu_mon_log_file_desc,
19014
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
19015
 
19016
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
19017
 
19018
    ok_pci = 1 ;
19019
    wishbone_slave.cycle_response(3'b000, wb_subseq_waits, 8'd255);
19020
 
19021
    fork
19022
    begin
19023
        if ( test_mem )
19024
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
19025
                          pci_image_base + 4, 32'h1234_5678,
19026
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
19027
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
19028
        else
19029
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
19030
 
19031
        do_pause( 1 ) ;
19032
 
19033
    end
19034
    begin
19035
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
19036
        if ( ok_wb !== 1 )
19037
        begin
19038
            $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) ;
19039
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
19040
            disable main ;
19041
        end
19042
 
19043
        repeat(4)
19044
            @(posedge pci_clock) ;
19045
 
19046
        fork
19047
        begin
19048
 
19049
            if ( test_mem )
19050
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
19051
                              pci_image_base + 4, 32'h8765_4321,
19052
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
19053
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
19054
            else
19055
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
19056
 
19057
            do_pause(1) ;
19058
 
19059
        end
19060
        begin
19061
 
19062
            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 ) ;
19063
            if ( ok !== 1 )
19064
            begin
19065
                $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) ;
19066
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
19067
                disable main ;
19068
            end
19069
        end
19070
        join
19071
 
19072
        #1 ;
19073
        if ( !error_monitor_done )
19074
            disable error_monitor5 ;
19075
    end
19076
    begin:error_monitor5
19077
        error_monitor_done = 0 ;
19078
        @(error_event_int) ;
19079
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
19080
        ok_pci = 0 ;
19081
        error_monitor_done = 1 ;
19082
    end
19083
    join
19084
 
19085
    if ( ok_wb && ok_pci )
19086
        test_ok ;
19087
 
19088
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
19089
    $fdisplay(pciu_mon_log_file_desc,
19090
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
19091
 
19092
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
19093
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
19094
    if ( temp_val1[8] !== 1'b0 )
19095
    begin
19096
        $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) ;
19097
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
19098
    end
19099
 
19100
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
19101
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
19102
    if ( temp_val1[25] !== 1'b1 )
19103
    begin
19104
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
19105
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
19106
    end
19107
 
19108
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
19109 87 mihad
`endif
19110 33 mihad
 
19111
    // disable current image - write address mask register
19112 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
19113 15 mihad
end
19114 57 mihad
endtask // target_completion_expiration
19115 15 mihad
 
19116 57 mihad
task master_completion_expiration ;
19117
    reg   [11:0] ctrl_offset ;
19118
    reg   [11:0] ba_offset ;
19119
    reg   [11:0] am_offset ;
19120
    reg `WRITE_STIM_TYPE write_data ;
19121
    reg `READ_STIM_TYPE  read_data ;
19122
    reg `READ_RETURN_TYPE read_status ;
19123
 
19124
    reg `WRITE_RETURN_TYPE write_status ;
19125
    reg `WB_TRANSFER_FLAGS write_flags ;
19126
    reg        ok   ;
19127
    reg [11:0] pci_ctrl_offset ;
19128
    reg [31:0] image_base ;
19129
    reg [31:0] target_address ;
19130
begin:main
19131
    pci_ctrl_offset = 12'h4 ;
19132
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
19133
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
19134
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
19135
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
19136
 
19137
    target_address  = `BEH_TAR1_MEM_START ;
19138
    image_base      = 0 ;
19139
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
19140
 
19141
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
19142
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
19143
    write_flags                      = 0 ;
19144 92 mihad
    write_flags`INIT_WAITS           = wb_init_waits ;
19145
    write_flags`SUBSEQ_WAITS         = wb_subseq_waits ;
19146 57 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19147
 
19148
    // enable master & target operation
19149
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
19150
    if ( ok !== 1 )
19151
    begin
19152
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
19153
        test_fail("write to PCI Device Control register didn't succeede");
19154
        disable main ;
19155
    end
19156
 
19157
    // prepare image control register
19158
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
19159
    if ( ok !== 1 )
19160
    begin
19161
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
19162
        test_fail("write to WB Image Control register didn't succeede");
19163
        disable main ;
19164
    end
19165
 
19166
    // prepare base address register
19167
    config_write( ba_offset, image_base, 4'hF, ok ) ;
19168
    if ( ok !== 1 )
19169
    begin
19170
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
19171
        test_fail("write to WB Base Address register didn't succeede");
19172
        disable main ;
19173
    end
19174
 
19175
    // write address mask register
19176
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
19177
    if ( ok !== 1 )
19178
    begin
19179
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
19180
        test_fail("write to WB Address Mask register didn't succeede");
19181
        disable main ;
19182
    end
19183
 
19184
    fork
19185
    begin
19186
        // do not handle retries
19187
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
19188
 
19189
        // initiate a read request
19190
        read_data`READ_ADDRESS  = target_address ;
19191
        read_data`READ_SEL      = 4'hF ;
19192
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
19193
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
19194
        begin
19195
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
19196
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
19197
            disable main ;
19198
        end
19199
 
19200
        // handle retries from now on
19201
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
19202
 
19203
        write_data`WRITE_ADDRESS = target_address + 4 ;
19204
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
19205
        write_data`WRITE_SEL     = 4'hF ;
19206
 
19207
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
19208
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
19209
        begin
19210
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
19211
            test_fail("WB Slave state machine failed to post single memory write");
19212
            disable main ;
19213
        end
19214
 
19215 81 mihad
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 110
19216
        repeat('h1_0000 - 110)
19217 57 mihad
            @(posedge wb_clock) ;
19218
 
19219
        // now perform a read
19220
        read_data`READ_ADDRESS  = target_address + 4 ;
19221
        read_data`READ_SEL      = 4'hF ;
19222
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
19223
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19224
        begin
19225
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
19226
            test_fail("PCI bridge didn't process the read as expected");
19227
            disable main ;
19228
        end
19229
 
19230
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
19231
        begin
19232
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
19233
            test_fail("PCI bridge returned unexpected Read Data");
19234
        end
19235
        else if (ok === 1'b1)
19236
            test_ok ;
19237
    end
19238
    begin:monitors
19239
        // monitor first read, which will expire
19240
        pci_transaction_progress_monitor
19241
        (
19242
            target_address, // expected address
19243
            `BC_MEM_READ,   // expected bus command
19244
            1,              // expected number of transfers
19245
            0,              // expected number of cycles
19246
            1,              // check number of transfers true/false
19247
            0,              // check number of cycles true/false
19248
            0,              // is this fast B2B true/false
19249
            ok              // return 1 if as expected, anything else on error
19250
        ) ;
19251
 
19252
        if ( ok !== 1 )
19253
        begin
19254
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19255
            #1 disable monitors ;
19256
        end
19257
 
19258
        // monitor normal single write
19259
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
19260
        if ( ok !== 1 )
19261
        begin
19262
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19263
            #1 disable monitors ;
19264
        end
19265
 
19266
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
19267 81 mihad
        repeat('h1_0000 - 100)
19268 57 mihad
            @(posedge wb_clock) ;
19269
 
19270
        // monitor normal single memory read
19271
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
19272
        if ( ok !== 1 )
19273
        begin
19274
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19275
        end
19276
    end
19277
    join
19278
 
19279
    // disable the image
19280
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
19281
    if ( ok !== 1 )
19282
    begin
19283
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
19284
        test_fail("write to WB Address Mask register didn't succeede");
19285
    end
19286
end
19287
endtask // master_completion_expiration
19288 63 mihad
`endif
19289 57 mihad
 
19290 15 mihad
task config_write ;
19291
    input [11:0] offset ;
19292
    input [31:0] data ;
19293
    input [3:0]  byte_enable ;
19294
    output       ok ;
19295
    `ifdef HOST
19296
    reg   `WRITE_STIM_TYPE   write_data ;
19297
    reg   `WB_TRANSFER_FLAGS write_flags ;
19298
    reg   `WRITE_RETURN_TYPE write_status ;
19299
    `else
19300
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
19301
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
19302
    `endif
19303
    reg in_use ;
19304
    reg [31:0] temp_var ;
19305
begin
19306
    if ( in_use === 1 )
19307
    begin
19308
        $display("config_read task re-entered! Time %t ", $time) ;
19309
        ok = 0 ;
19310
        #20 $stop ;
19311
    end
19312
    else
19313
    begin
19314
        ok = 1 ;
19315
        in_use = 1 ;
19316
    end
19317
    `ifdef HOST
19318
    write_flags                    = 0 ;
19319 92 mihad
    write_flags`INIT_WAITS         = wb_init_waits ;
19320
    write_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
19321 15 mihad
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19322
 
19323
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19324
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19325
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
19326
    write_data`WRITE_SEL                         = byte_enable ;
19327
    write_data`WRITE_DATA                        = data ;
19328
 
19329
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
19330
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
19331
    begin
19332
        $display("Write to configuration space failed! Time %t ", $time) ;
19333
        ok = 0 ;
19334
    end
19335
 
19336
    @(posedge wb_clock) ;
19337
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
19338
    // here we just wait for two guest cycles for conf space bits to synchronize
19339
    repeat( 2 )
19340
        @(posedge pci_clock) ;
19341
 
19342
    `else // GUEST
19343
    byte_enables_l = ~byte_enable ;
19344
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19345
 
19346
    fork
19347
    begin
19348
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19349
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
19350
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
19351
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19352
              8'h0_0, `Test_One_Zero_Target_WS,
19353
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
19354
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19355
    do_pause( 1 ) ;
19356
    end
19357
    begin
19358
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
19359
        @(posedge pci_clock) ;
19360
    end
19361
    join
19362
 
19363
     repeat( 2 )
19364
         @(posedge wb_clock) ;
19365
 
19366
    `endif
19367
    in_use = 0 ;
19368
end
19369
endtask // config_write
19370
 
19371
task config_read ;
19372
    input [11:0] offset ;
19373
    input [3:0]  byte_enable ;
19374
    output [31:0] data ;
19375
 
19376
    reg `READ_STIM_TYPE    read_data ;
19377
    reg `WB_TRANSFER_FLAGS read_flags ;
19378
    reg `READ_RETURN_TYPE  read_status ;
19379
 
19380
    reg [31:0] pci_address ;
19381
    reg [3:0] byte_enables_l ;
19382
 
19383
    reg master_check_data_prev ;
19384
    reg in_use ;
19385
    reg [31:0] temp_var ;
19386
begin:main
19387
    if ( in_use === 1 )
19388
    begin
19389
        $display("config_read task re-entered! Time %t ", $time) ;
19390
        data = 32'hxxxx_xxxx ;
19391
        disable main ;
19392
    end
19393
 
19394
    in_use = 1 ;
19395
 
19396
`ifdef HOST
19397 26 mihad
    repeat(4)
19398
        @(posedge pci_clock) ;
19399
    repeat(4)
19400
        @(posedge wb_clock) ;
19401 15 mihad
    read_flags                    = 0 ;
19402 92 mihad
    read_flags`INIT_WAITS         = wb_init_waits ;
19403
    read_flags`SUBSEQ_WAITS       = wb_subseq_waits ;
19404 15 mihad
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19405
 
19406
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19407
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19408
 
19409
    read_data`READ_ADDRESS  = temp_var + offset ;
19410
    read_data`READ_SEL      = byte_enable ;
19411
 
19412
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
19413
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19414
    begin
19415
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
19416
        #20 $stop ;
19417
    end
19418
    data = read_status`READ_DATA ;
19419
`else
19420
  `ifdef GUEST
19421 26 mihad
    repeat(4)
19422
        @(posedge wb_clock) ;
19423
    repeat(4)
19424
        @(posedge pci_clock) ;
19425 15 mihad
    master_check_data_prev = master2_check_received_data ;
19426
    master2_check_received_data = 0 ;
19427
 
19428
    byte_enables_l = ~byte_enable ;
19429
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19430
 
19431
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19432
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
19433
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19434
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19435
             8'h4_0, `Test_One_Zero_Target_WS,
19436
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19437
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19438
    do_pause( 1 ) ;
19439
 
19440
    @(master2_received_data_valid) ;
19441
    data = master2_received_data ;
19442
 
19443
    master2_check_received_data = master_check_data_prev ;
19444
  `endif
19445
`endif
19446
    in_use = 0 ;
19447
end
19448
endtask //config_read
19449
 
19450 62 mihad
`ifdef PCI_BIST
19451
`ifdef WB_RAM_DONT_SHARE
19452
    `ifdef PCI_RAM_DONT_SHARE
19453
        parameter bist_chain_length = 8 ;
19454
    `else
19455
        parameter bist_chain_length = 6 ;
19456
    `endif
19457
`else
19458
    `ifdef PCI_RAM_DONT_SHARE
19459 69 mihad
        parameter bist_chain_length = 6 ;
19460 62 mihad
    `else
19461 69 mihad
        parameter bist_chain_length = 4 ;
19462 62 mihad
    `endif
19463
`endif
19464
 
19465
task run_bist_test ;
19466
    reg [(bist_chain_length - 1):0] bist_result_vector ;
19467
    integer count ;
19468
    integer deadlock_count ;
19469
begin
19470
 
19471
    test_name = "BIST FOR RAMS RUN" ;
19472
 
19473 69 mihad
    scanb_en  = 0 ;
19474
    scanb_si  = 0 ;
19475
    scanb_rst = 0 ;
19476
    scanb_clk = 0 ;
19477 62 mihad
 
19478
    fork
19479
    begin
19480
        repeat(2)
19481
            @(posedge wb_clock) ;
19482
    end
19483
    begin
19484
        repeat(2)
19485
            @(posedge pci_clock) ;
19486
    end
19487
    join
19488
 
19489 69 mihad
    // test is run by reseting the test logic
19490
    scanb_rst <= 1'b1 ;
19491
 
19492
    // toggle scan clock for a few times
19493
    repeat (20)
19494
        #50 scanb_clk = !scanb_clk ;
19495
 
19496
    // release bist reset
19497
    scanb_rst <= 1'b0 ;
19498 62 mihad
 
19499
    bist_result_vector = 0 ;
19500
 
19501
    // result vector must be all 1s, because in RTL there cannot be a reason for BIST to fail
19502
    fork
19503
    begin:scan
19504
        while (bist_result_vector !== {bist_chain_length{1'b1}})
19505
        begin
19506 69 mihad
            #1 ;
19507
            @(posedge scanb_clk) ;
19508
            scanb_en <= #1 1'b1 ;
19509 62 mihad
            for (count = 0 ; count < bist_chain_length ; count = count + 1'b1)
19510
            begin
19511 69 mihad
                @(posedge scanb_clk) ;
19512
                bist_result_vector[count] = scanb_so ;
19513 62 mihad
            end
19514
 
19515 69 mihad
            scanb_en <= #1 1'b0 ;
19516 62 mihad
        end
19517
        #1 disable deadlock ;
19518 69 mihad
        @(negedge scanb_clk) ;
19519
        #1 disable scanb_clk_gen ;
19520 62 mihad
        test_ok ;
19521
    end
19522
    begin:deadlock
19523
        for (deadlock_count = 0; deadlock_count <= 100000; deadlock_count = deadlock_count + 1'b1)
19524
        begin
19525
            @(posedge pci_clock) ;
19526
            @(posedge wb_clock) ;
19527
        end
19528
 
19529
        test_fail("BIST Test didn't finish as expected") ;
19530 69 mihad
        scanb_en <= #1 1'b0 ;
19531 62 mihad
        disable scan ;
19532 69 mihad
        @(negedge scanb_clk) ;
19533 62 mihad
        #1 ;
19534 69 mihad
        disable scanb_clk_gen ;
19535 62 mihad
    end
19536 69 mihad
    begin:scanb_clk_gen
19537 62 mihad
        forever
19538 69 mihad
            #50 scanb_clk = !scanb_clk ;
19539 62 mihad
    end
19540
    join
19541
end
19542
endtask // run_bist_test
19543
`endif
19544
 
19545 104 mihad
`ifdef DO_CORNER_CASE_TESTS
19546 63 mihad
task target_special_corner_case_test ;
19547
    reg   [11:0]    pci_ctrl_offset ;
19548
    reg   [11:0]    ctrl_offset ;
19549
    reg   [11:0]    ba_offset ;
19550
    reg   [11:0]    am_offset ;
19551
    reg             ok_wb ;
19552
    reg             ok_pci ;
19553
    reg             test_mem ;
19554
    reg             master_check_data_previous ;
19555
begin:main
19556
    master_check_data_previous  = master1_check_received_data ;
19557
    master1_check_received_data = 1'b1 ;
19558
    pci_ctrl_offset = 12'h4 ;
19559
    // use image 1 for this test
19560
    ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
19561
    ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
19562
    am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
19563
 
19564
    // set behavioral slave cycle response
19565
    `ifdef REGISTER_WBM_OUTPUTS
19566
    wishbone_slave.cycle_response
19567
    (
19568
        3'b100,         // {ACK, ERR, RTY}
19569
        0,              // wait cycles
19570
        8'h0            // num of retries before termination
19571
    );
19572
    `else
19573
    wishbone_slave.cycle_response
19574
    (
19575
        3'b100,         // {ACK, ERR, RTY}
19576
        1,              // wait cycles
19577
        8'h0            // num of retries before termination
19578
    );
19579
    `endif
19580
 
19581
    `ifdef HOST
19582
        test_mem = 1 ;
19583
    `else
19584
        test_mem = `PCI_BA1_MEM_IO ;
19585
        test_mem = !test_mem ;
19586
    `endif
19587
 
19588
    test_name = "PCI TARGET UNIT SPECIAL CORNER CASE" ;
19589
 
19590
    // Set Base Address of IMAGE
19591
    config_write( ba_offset, Target_Base_Addr_R[1], 4'hF, ok_wb ) ;
19592
    if ( ok_wb !== 1 )
19593
    begin
19594 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19595 63 mihad
        test_fail("PCI Base Address register 1 could not be written") ;
19596
        #1 ;
19597
        disable main ;
19598
    end
19599
 
19600
    // Set Address Mask of IMAGE
19601
    config_write( am_offset, Target_Addr_Mask_R[1], 4'hF, ok_wb ) ;
19602
    if ( ok_wb !== 1 )
19603
    begin
19604 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_AM1 register! Time %t ", $time);
19605 63 mihad
        test_fail("PCI Address Mask register 1 could not be written") ;
19606
        #1 ;
19607
        disable main ;
19608
    end
19609
 
19610
    // Disable all the features of the PCI Image 1
19611
    config_write( ctrl_offset, 0, 4'hF, ok_wb ) ;
19612
    if ( ok_wb !== 1 )
19613
    begin
19614 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_CTRL1 register! Time %t ", $time);
19615 63 mihad
        test_fail("PCI Image Control register 1 could not be written") ;
19616
        #1 ;
19617
        disable main ;
19618
    end
19619
 
19620 92 mihad
    // set waits to min on pci, max on wb
19621
    wb_init_waits   = 4 ;
19622
    wb_subseq_waits = 4 ;
19623
 
19624
    pci_init_waits   = 0 ;
19625
    pci_subseq_waits = 0 ;
19626 63 mihad
 
19627
    // do one dummy write, to receive a GNT park
19628
    if (test_mem)
19629
    begin
19630
        PCIU_MEM_WRITE
19631
        (
19632
            "MEM_WRITE ",                       // just the name
19633
            `Test_Master_1,                     // Behavioral Master to use for reference
19634
            Target_Base_Addr_R[1],              // Address of this transaction
19635
            32'hAAAA_AAAA,                      // Data For the transaction
19636
            4'h0,                               // Byte enables
19637
            1,                                  // length of transfer
19638
            `Test_One_Zero_Master_WS,           // Master Waits - don't care
19639
            `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19640
            `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19641
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19642
        );
19643
    end
19644
    else
19645
    begin
19646
        PCIU_IO_WRITE
19647
        (
19648
            `Test_Master_1,                     // Behavioral Master to use for reference
19649
            Target_Base_Addr_R[1],              // Address of this transaction
19650
            32'hAAAA_AAAA,                      // Data For the transaction
19651
            4'h0,                               // Byte enables
19652
            1,                                  // Size of transfer
19653
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19654
        ) ;
19655
    end
19656
 
19657
    do_pause( 1 ) ;
19658
    wb_transaction_progress_monitor
19659
    (
19660
        Target_Base_Addr_R[1],          // expected address
19661
        1'b1,                           // expected operation R/W
19662
        1,                              // 1
19663
        1'b1,                           // turn checking of transfers ON/OFF
19664
        ok_wb                           // succeeded/failed
19665
    ) ;
19666
 
19667
    if (ok_wb !== 1'b1)
19668
    begin
19669
        test_fail("WB Transaction Monitor detected invalid transaction on WB bus after posted memory write through target") ;
19670
        #1 ;
19671
        disable main ;
19672
    end
19673
 
19674
    fork
19675
    begin
19676
        if (test_mem)
19677
        begin
19678
            PCIU_MEM_WRITE
19679
            (
19680
                "MEM_WRITE ",                       // just the name
19681
                `Test_Master_1,                     // Behavioral Master to use for reference
19682
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19683
                32'hF0F0_F0F0,                      // Data For the transaction
19684
                4'h0,                               // Byte enables       
19685
                1,                                  // length of transfer
19686
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19687
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19688
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19689
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19690
            );
19691
        end
19692
        else
19693
        begin
19694
            PCIU_IO_WRITE
19695
            (
19696
                `Test_Master_1,                     // Behavioral Master to use for reference
19697
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19698
                32'hF0F0_F0F0,                      // Data For the transaction
19699
                4'h0,                               // Byte enables
19700
                1,                                  // Size of transfer
19701
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19702
            ) ;
19703
        end
19704
 
19705
        do_pause( 1 ) ;
19706
 
19707
        if (test_mem)
19708
        begin
19709
            PCIU_MEM_WRITE
19710
            (
19711
                "MEM_WRITE ",                       // just the name
19712
                `Test_Master_1,                     // Behavioral Master to use for reference
19713
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19714
                32'h0F0F_0F0F,                      // Data For the transaction
19715
                4'h0,                               // Byte enables
19716
                1,                                  // length of transfer
19717
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19718
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19719
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19720
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19721
            );
19722
        end
19723
        else
19724
        begin
19725
            PCIU_IO_WRITE
19726
            (
19727
                `Test_Master_1,                     // Behavioral Master to use for reference
19728
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19729
                32'h0F0F_0F0F,                      // Data For the transaction
19730
                4'h0,                               // Byte enables
19731
                1,                                  // Size of transfer
19732
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19733
            ) ;
19734
        end
19735
 
19736
        do_pause( 1 ) ;
19737
    end
19738
    begin
19739
        wb_transaction_progress_monitor
19740
        (
19741
            Target_Base_Addr_R[1] + 64,     // expected address
19742
            1'b1,                           // expected operation R/W
19743
            1,                              // expected number of transfers
19744
            1'b1,                           // turn checking of transfers ON/OFF
19745
            ok_wb                           // succeeded/failed
19746
        ) ;
19747
 
19748
        if ( ok_wb === 1 )
19749
        begin
19750
 
19751
            wb_transaction_progress_monitor
19752
            (
19753
                Target_Base_Addr_R[1] + 128,    // expected address
19754
                1'b1,                           // expected operation R/W
19755
                1,                              // expected number of transfers
19756
                1'b1,                           // turn checking of transfers ON/OFF
19757
                ok_wb                           // succeeded/failed
19758
            ) ;
19759
        end
19760
 
19761
        @(posedge pci_clock) ;
19762
        #1 ;
19763
        disable pci_error_mon1 ;
19764
    end
19765
    begin:pci_error_mon1
19766
        ok_pci = 1 ;
19767
        @(error_event_int) ;
19768
        ok_pci = 0 ;
19769
    end
19770
    join
19771
 
19772
    if ( ok_wb !== 1'b1 )
19773
    begin
19774
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19775
    end
19776
 
19777
    if ( ok_pci !== 1'b1)
19778
    begin
19779
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19780
    end
19781
 
19782
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19783
    begin
19784
        #1 ;
19785
        disable main ;
19786
    end
19787
 
19788
    if ( test_mem )
19789
    begin
19790
        PCIU_MEM_READ
19791
        (
19792
            "MEM_READ  ",                   // description
19793
            `Test_Master_1,                 // behavioral master selection
19794
            Target_Base_Addr_R[1] + 64,     // address of access
19795
            32'hF0F0_F0F0,                  // expected read data
19796
            1,                              // number of transfers
19797
            8'h7_0,                         // don't care (wait cycles)
19798
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19799
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19800
            `Test_Target_Retry_On           // expected Target termination
19801
        );
19802
    end
19803
    else
19804
    begin
19805
        PCIU_IO_READ
19806
        (
19807
            `Test_Master_1,                 // behavioral master selection
19808
            Target_Base_Addr_R[1] + 64,     // address of access
19809
            32'hF0F0_F0F0,                  // expected read data
19810
            4'h0,                           // byte enables
19811
            1,                              // number of transfers
19812
            `Test_Target_Retry_On           // expected target termination
19813
        ) ;
19814
    end
19815
 
19816 64 mihad
    do_pause(1) ;
19817
 
19818 63 mihad
    wb_transaction_progress_monitor
19819
    (
19820
            Target_Base_Addr_R[1] + 64,     // expected address
19821
            1'b0,                           // expected operation R/W
19822
            1,                              // expected number transfers
19823
            1'b1,                           // turn checking of transfers ON/OFF
19824
            ok_wb                           // succeeded/failed
19825
    ) ;
19826
 
19827
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19828
    repeat(3)
19829
        @(posedge pci_clock) ;
19830
 
19831
    // now read data
19832
    fork
19833
    begin
19834
        if ( test_mem )
19835
        begin
19836
            PCIU_MEM_READ
19837
            (
19838
                "MEM_READ  ",                   // description
19839
                `Test_Master_1,                 // behavioral master selection
19840
                Target_Base_Addr_R[1] + 64,     // address of access
19841
                32'hF0F0_F0F0,                  // expected read data
19842
                1,                              // number of transfers
19843
                8'h7_0,                         // don't care (wait cycles)
19844
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19845
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19846
                `Test_Target_Normal_Completion  // expected Target termination
19847
            );
19848
        end
19849
        else
19850
        begin
19851
            PCIU_IO_READ
19852
            (
19853
                `Test_Master_1,                 // behavioral master selection
19854
                Target_Base_Addr_R[1] + 64,     // address of access
19855
                32'hF0F0_F0F0,                  // expected read data
19856
                4'h0,                           // byte enables
19857
                1,                              // number of transfers
19858
                `Test_Target_Normal_Completion  // expected target termination
19859
            ) ;
19860
        end
19861
 
19862 64 mihad
        do_pause(1) ;
19863 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19864
            @(posedge pci_clock) ;
19865
 
19866
        @(posedge pci_clock) ;
19867
        #1 ;
19868
        disable pci_error_mon2 ;
19869
    end
19870
    begin:pci_error_mon2
19871
        ok_pci = 1 ;
19872
        @(error_event_int) ;
19873
        ok_pci = 0 ;
19874
    end
19875
    join
19876
 
19877
    if ( ok_wb !== 1'b1 )
19878
    begin
19879
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19880
    end
19881
 
19882
    if ( ok_pci !== 1'b1)
19883
    begin
19884
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19885
    end
19886
 
19887
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19888
    begin
19889
        #1 ;
19890
        disable main ;
19891
    end
19892
 
19893
    if ( test_mem )
19894
    begin
19895
        PCIU_MEM_READ
19896
        (
19897
            "MEM_READ  ",                   // description
19898
            `Test_Master_1,                 // behavioral master selection
19899
            Target_Base_Addr_R[1] + 128,    // address of access
19900
            32'h0F0F_0F0F,                  // expected read data
19901
            1,                              // number of transfers
19902
            8'h7_0,                         // don't care (wait cycles)
19903
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19904
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19905
            `Test_Target_Retry_On           // expected Target termination
19906
        );
19907
    end
19908
    else
19909
    begin
19910
        PCIU_IO_READ
19911
        (
19912
            `Test_Master_1,                 // behavioral master selection
19913
            Target_Base_Addr_R[1] + 128,    // address of access
19914
            32'h0F0F_0F0F,                  // expected read data
19915
            4'h0,                           // byte enables
19916
            1,                              // number of transfers
19917
            `Test_Target_Retry_On           // expected target termination
19918
        ) ;
19919
    end
19920
 
19921 64 mihad
    do_pause(1) ;
19922 63 mihad
    wb_transaction_progress_monitor
19923
    (
19924
            Target_Base_Addr_R[1] + 128,    // expected address
19925
            1'b0,                           // expected operation R/W
19926
            1,                              // expected number transfers
19927
            1'b1,                           // turn checking of transfers ON/OFF
19928
            ok_wb                           // succeeded/failed
19929
    ) ;
19930
 
19931
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19932
    repeat(3)
19933
        @(posedge pci_clock) ;
19934
 
19935
    // now read data
19936
    fork
19937
    begin
19938
        if ( test_mem )
19939
        begin
19940
            PCIU_MEM_READ
19941
            (
19942
                "MEM_READ  ",                   // description
19943
                `Test_Master_1,                 // behavioral master selection
19944
                Target_Base_Addr_R[1] + 128,    // address of access
19945
                32'h0F0F_0F0F,                  // expected read data
19946
                1,                              // number of transfers
19947
                8'h7_0,                         // don't care (wait cycles)
19948
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19949
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19950
                `Test_Target_Normal_Completion  // expected Target termination
19951
            );
19952
        end
19953
        else
19954
        begin
19955
            PCIU_IO_READ
19956
            (
19957
                `Test_Master_1,                 // behavioral master selection
19958
                Target_Base_Addr_R[1] + 128,    // address of access
19959
                32'h0F0F_0F0F,                  // expected read data
19960
                4'h0,                           // byte enables
19961
                1,                              // number of transfers
19962
                `Test_Target_Normal_Completion  // expected target termination
19963
            ) ;
19964
        end
19965
 
19966 64 mihad
        do_pause(1) ;
19967 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19968
            @(posedge pci_clock) ;
19969
 
19970
        @(posedge pci_clock) ;
19971
        #1 ;
19972
        disable pci_error_mon3 ;
19973
    end
19974
    begin:pci_error_mon3
19975
        ok_pci = 1 ;
19976
        @(error_event_int) ;
19977
        ok_pci = 0 ;
19978
    end
19979
    join
19980
 
19981
    if ((ok_wb === 1'b1) && (ok_pci === 1'b1))
19982
        test_ok ;
19983
 
19984
    if ( ok_wb !== 1'b1 )
19985
    begin
19986
        test_fail("WB Master started invalid transaction or none at all after Target read was requested") ;
19987
    end
19988
 
19989
    if ( ok_pci !== 1'b1)
19990
    begin
19991
        test_fail("PCI Behavioral Master or Monitor signaled an error during read from PCI Bridge Target") ;
19992
    end
19993
 
19994 69 mihad
    // Disable used image
19995
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
19996
    if ( ok_wb !== 1 )
19997
    begin
19998
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19999
        test_fail("PCI Base Address register 1 could not be written") ;
20000
        #1 ;
20001
        disable main ;
20002
    end
20003
 
20004 63 mihad
    master1_check_received_data = master_check_data_previous ;
20005
end
20006
endtask // target_special_corner_case_test
20007
`endif
20008
 
20009 104 mihad
`ifdef DO_CORNER_CASE_TESTS
20010 69 mihad
task master_special_corner_case_test ;
20011
    reg   [11:0] ctrl_offset ;
20012
    reg   [11:0] ba_offset ;
20013
    reg   [11:0] am_offset ;
20014
    reg `WRITE_STIM_TYPE write_data ;
20015
    reg `READ_STIM_TYPE  read_data ;
20016
    reg `READ_RETURN_TYPE read_status ;
20017
 
20018
    reg `WRITE_RETURN_TYPE write_status ;
20019
    reg `WB_TRANSFER_FLAGS flags ;
20020
    reg ok_pci   ;
20021
    reg ok_wb ;
20022
 
20023
    reg [31:0] target_address ;
20024
 
20025
    reg [11:0] pci_ctrl_offset ;
20026
 
20027
    reg [31:0] image_base ;
20028
begin:main
20029
    test_name = "WISHBONE SLAVE UNIT SPECIAL CORNER CASE" ;
20030
    pci_ctrl_offset = 12'h4 ;
20031
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
20032
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
20033
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
20034
 
20035
    target_address  = `BEH_TAR1_MEM_START ;
20036
    image_base      = 0 ;
20037
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
20038
 
20039
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
20040
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
20041
 
20042
    flags                      = 0 ;
20043
    flags`INIT_WAITS           = 0 ;
20044
    flags`SUBSEQ_WAITS         = 0 ;
20045
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
20046
 
20047
    test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = `Test_Devsel_Fast ;
20048
    test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
20049
    test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
20050
 
20051
    // enable master & target operation
20052
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok_wb) ;
20053
    if ( ok_wb !== 1 )
20054
    begin
20055
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write PCI Device Control register! Time %t ", $time) ;
20056
        test_fail("write to PCI Device Control register didn't succeede");
20057
        disable main ;
20058
    end
20059
 
20060
    // prepare image control register
20061
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok_wb) ;
20062
    if ( ok_wb !== 1 )
20063
    begin
20064
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
20065
        test_fail("write to WB Image Control register didn't succeede");
20066
        disable main ;
20067
    end
20068
 
20069
    // prepare base address register
20070
    config_write( ba_offset, image_base, 4'hF, ok_wb ) ;
20071
    if ( ok_wb !== 1 )
20072
    begin
20073
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
20074
        test_fail("write to WB Base Address register didn't succeede");
20075
        disable main ;
20076
    end
20077
 
20078
    // write address mask register
20079
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok_wb ) ;
20080
    if ( ok_wb !== 1 )
20081
    begin
20082
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_AM1 register! Time %t ", $time) ;
20083
        test_fail("write to WB Address Mask register didn't succeede");
20084
        disable main ;
20085
    end
20086
 
20087
    fork
20088
    begin
20089
 
20090
        // do one dummy read, to receive bus gnt
20091
        read_data`READ_ADDRESS  = target_address ;
20092
        read_data`READ_SEL      = 4'hF ;
20093
 
20094
        // handle retries
20095
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
20096
 
20097
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
20098
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
20099
        begin
20100
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
20101
            test_fail("PCI bridge didn't process the delayed read as expected");
20102
            disable main ;
20103
        end
20104
 
20105
        write_data`WRITE_ADDRESS = target_address + 64;
20106
        write_data`WRITE_DATA    = 32'hABCD_EF12 ;
20107
        write_data`WRITE_SEL     = 4'hF ;
20108
 
20109
        wishbone_master.blk_write_data[0] = write_data ;
20110
 
20111
        write_data`WRITE_ADDRESS = target_address + 128 ;
20112
        write_data`WRITE_DATA    = ~write_data`WRITE_DATA ;
20113
        write_data`WRITE_SEL     = 4'hF ;
20114
 
20115
        wishbone_master.blk_write_data[1] = write_data ;
20116
 
20117
        // no retries should happen
20118
        flags`WB_TRANSFER_AUTO_RTY = 0 ;
20119
 
20120
        flags`WB_TRANSFER_SIZE = 2 ;
20121
 
20122
        wishbone_master.wb_block_write( flags, write_status ) ;
20123
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
20124
        begin
20125
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process block memory write! Time %t ", $time) ;
20126
            test_fail("WB Slave state machine failed to post block memory write");
20127
            disable main ;
20128
        end
20129
 
20130
        // read data back
20131
        read_data`READ_ADDRESS  = target_address + 64 ;
20132
        read_data`READ_SEL      = 4'hF ;
20133
 
20134
        // handle retries
20135
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
20136
 
20137
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
20138
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
20139
        begin
20140
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
20141
            test_fail("PCI bridge didn't process the delayed read as expected");
20142
            disable main ;
20143
        end
20144
 
20145
        if (read_status`READ_DATA !== 32'hABCD_EF12)
20146
        begin
20147
            display_warning(target_address + 64, 32'hABCD_EF12, read_status`READ_DATA) ;
20148
            test_fail("PCI bridge returned unexpected Read Data");
20149
            ok_wb = 0 ;
20150
        end
20151
 
20152
        // read second data back
20153
        read_data`READ_ADDRESS  = target_address + 128 ;
20154
        read_data`READ_SEL      = 4'hF ;
20155
 
20156
        // handle retries
20157
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
20158
 
20159
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
20160
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
20161
        begin
20162
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
20163
            test_fail("PCI bridge didn't process the delayed read as expected");
20164
            disable main ;
20165
        end
20166
 
20167
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
20168
        begin
20169
            display_warning(target_address + 128, write_data`WRITE_DATA, read_status`READ_DATA) ;
20170
            test_fail("PCI bridge returned unexpected Read Data");
20171
            ok_wb = 0 ;
20172
        end
20173
    end
20174
    begin
20175
 
20176
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
20177
        if ( ok_pci !== 1 )
20178
        begin
20179
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
20180
        end
20181
 
20182
        if(ok_pci)
20183
        begin
20184
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
20185
            if ( ok_pci !== 1 )
20186
            begin
20187
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
20188
            end
20189
        end
20190
 
20191
        if (ok_pci)
20192
        begin
20193
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
20194
            if ( ok_pci !== 1 )
20195
            begin
20196
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
20197
            end
20198
        end
20199
 
20200
        if (ok_pci)
20201
        begin
20202
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
20203
            if ( ok_pci !== 1 )
20204
            begin
20205
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
20206
            end
20207
        end
20208
 
20209
        if (ok_pci)
20210
        begin
20211
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
20212
            if ( ok_pci !== 1 )
20213
            begin
20214
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
20215
            end
20216
        end
20217
    end
20218
    join
20219
 
20220
    if (ok_wb && ok_pci)
20221
        test_ok ;
20222
 
20223
    // disable the image
20224
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
20225
    if ( ok_wb !== 1 )
20226
    begin
20227
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
20228
        test_fail("write to WB Base Address register didn't succeede");
20229
        disable main ;
20230
    end
20231
end
20232
endtask // master_special_corner_case_test
20233
`endif
20234
 
20235 73 mihad
task test_target_overload ;
20236
    reg ok_pci ;
20237
    reg ok_wb  ;
20238
    reg ok ;
20239
    reg [2:0] test_image_num ;
20240
    reg addr_translated ;
20241
    integer transfered ;
20242
    reg [2:0] received_termination ;
20243
    integer total_transfers ;
20244
    reg [31:0] transaction_sizes [0:1024] ;
20245
    integer pci_transaction_num ;
20246
    integer wb_transaction_num ;
20247
    reg [31:0] current_wb_address ;
20248
    reg io_mapped ;
20249
    integer current_size ;
20250 92 mihad
    reg [31:0] current_pci_address ;
20251
    reg [31:0] expected_data ;
20252 73 mihad
begin:main
20253
 
20254
    `ifdef HOST
20255
    io_mapped = 1'b0 ;
20256
    `endif
20257
 
20258
    test_image_num = 'd1 ;
20259
    `ifdef GUEST
20260
    io_mapped = `PCI_BA1_MEM_IO ;
20261
    `endif
20262
 
20263
    `ifdef PCI_IMAGE2
20264
        test_image_num = 'd2 ;
20265
        `ifdef GUEST
20266
            io_mapped = `PCI_BA2_MEM_IO ;
20267
        `endif
20268
    `endif
20269
 
20270
    `ifdef PCI_IMAGE3
20271
        test_image_num = 'd3 ;
20272
        `ifdef GUEST
20273
            io_mapped = `PCI_BA3_MEM_IO ;
20274
        `endif
20275
    `endif
20276
 
20277
    `ifdef PCI_IMAGE4
20278
        test_image_num = 'd4 ;
20279
        `ifdef GUEST
20280
            io_mapped = `PCI_BA4_MEM_IO ;
20281
        `endif
20282
    `endif
20283
 
20284
    `ifdef PCI_IMAGE5
20285
        test_image_num = 'd5 ;
20286
        `ifdef GUEST
20287
            io_mapped = `PCI_BA5_MEM_IO ;
20288
        `endif
20289
    `endif
20290
 
20291
    test_name = "PCI TARGET OVERLOAD" ;
20292
    // configure target image 1 via bus accesses
20293
    pci_configure_pci_target_image
20294
    (
20295
        1'b1,                               // selects whether to configure image with bus accesses or directly with dot notation in the configuration space
20296
        test_image_num,                     // image number
20297
        Target_Base_Addr_R[test_image_num], // base address
20298
        Target_Addr_Mask_R[test_image_num], // address mask
20299
        Target_Tran_Addr_R[test_image_num], // translation address
20300
        1'b0,                               // io/mem mapping select
20301
        1'b0,                               // prefetch enable
20302
        1'b1,                               // address translation enable
20303
        ok                                  // finished succesfully
20304
    );
20305
    if (ok !== 1'b1)
20306
    begin
20307
        test_fail("configuration of PCI Target Image didn't succeede") ;
20308
        #1 disable main ;
20309
    end
20310
 
20311
    `ifdef ADDR_TRAN_IMPL
20312
        addr_translated = 1'b1 ;
20313
    `else
20314
        addr_translated = 1'b0 ;
20315
    `endif
20316
 
20317
    // set wb slave's response to max wait cycles
20318
    wishbone_slave.cycle_response
20319
    (
20320
        3'b100,          // ACK, ERR, RTY termination
20321 92 mihad
        wb_subseq_waits, // wait cycles before response
20322 73 mihad
 
20323
    ) ;
20324
 
20325
    ok_pci = 1 ;
20326
    ok_wb  = 1 ;
20327
 
20328
    for (current_size = 2 ; (current_size <= 1024) && ok_pci && ok_wb && ok ; current_size = current_size * 2)
20329
    begin
20330
 
20331
        total_transfers = 0 ;
20332
        pci_transaction_num = 0 ;
20333
        wb_transaction_num = 0 ;
20334
 
20335 92 mihad
        current_wb_address = pci_to_wb_addr_convert
20336
                             (
20337
                               Target_Base_Addr_R[test_image_num], // pci address
20338
                               Target_Tran_Addr_R[test_image_num], // translation address
20339
                               addr_translated
20340
                              );
20341
 
20342
        current_wb_address  = current_wb_address & Target_Addr_Mask_R[test_image_num] ;
20343
        current_wb_address  = current_wb_address + (('d1024 - current_size) * 4) ;
20344
        current_pci_address = (Target_Base_Addr_R[test_image_num] & Target_Addr_Mask_R[test_image_num]) + (('d1024 - current_size) * 4) ;
20345
 
20346 73 mihad
        fork
20347
        begin
20348
            while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20349
            begin
20350
                // try transfering 4kB with no wait cycles through the target
20351
                ipci_unsupported_commands_master.normal_write_transfer
20352
                (
20353
                    // always write to the end of the 4kB window
20354 92 mihad
                    current_pci_address,                            // start_address
20355
                    io_mapped ? `BC_IO_WRITE : `BC_MEM_WRITE,       // bus_command
20356
                    (current_size - total_transfers),               // size
20357
                    pci_subseq_waits[2:0],                          // subsequent wait cycles
20358
                    transfered,                                     // actual_transfer
20359
                    received_termination                            // received_termination
20360 73 mihad
                );
20361
                if (transfered > 0)
20362
                begin
20363
                    transaction_sizes[pci_transaction_num] = transfered ;
20364 92 mihad
                    current_pci_address = current_pci_address + (4 * transfered) ;
20365 73 mihad
                    pci_transaction_num = pci_transaction_num + 1'b1 ;
20366
                end
20367
                total_transfers = total_transfers + transfered ;
20368
                if (received_termination > 2) // terminations with numbers 3(Target Abort), 4(Master Abort) and 5(Error) are not allowed
20369
                begin
20370
                    ok_pci = 0 ;
20371
                    if (received_termination == 3)
20372
                        test_fail("PCI Target signalled Target Abort") ;
20373
 
20374
                    if (received_termination == 4)
20375
                        test_fail("PCI Master generated Master Abort") ;
20376
 
20377
                    if (received_termination == 5)
20378
                        test_fail("PCI behavioral master signaled severe error") ;
20379
                end
20380
            end
20381
        end
20382
        begin:wb_monitoring
20383
            while (((total_transfers < current_size) || (pci_transaction_num > wb_transaction_num)) && ok_pci && ok_wb && ok)
20384
            begin
20385
                wait(pci_transaction_num > wb_transaction_num) ;
20386 92 mihad
                fork
20387 73 mihad
                begin
20388 92 mihad
                    wb_transaction_progress_monitor
20389
                    (
20390
                        current_wb_address,                     //address
20391
                        1'b1,                                   //write/read
20392
                        transaction_sizes[wb_transaction_num],  //num_of_transfers
20393
                        1'b1,                                   //check_transfers
20394
                        ok_wb                                   // success/fail
20395
                    );
20396
                    current_wb_address = current_wb_address + (transaction_sizes[wb_transaction_num] * 4) ;
20397
                    wb_transaction_num = wb_transaction_num + 1'b1 ;
20398
                    if (ok_wb !== 1'b1)
20399
                    begin
20400
                        test_fail("WB Transaction progress monitor detected invalid transaction or none at all on WB bus");
20401
                    end
20402 73 mihad
                end
20403 92 mihad
                begin
20404
                    @(posedge wb_clock) ;
20405
                    while (CYC_O !== 1'b1)
20406
                        @(posedge wb_clock) ;
20407
 
20408
                    while (CYC_O === 1'b1)
20409
                    begin
20410
                        if (STB_O === 1'b1)
20411
                        begin
20412
 
20413
                            expected_data = Target_Base_Addr_R[test_image_num] & Target_Addr_Mask_R[test_image_num] ;
20414
                            expected_data = expected_data | (ADR_O & ~Target_Addr_Mask_R[test_image_num]) ;
20415
                            expected_data = ~expected_data ;
20416
 
20417
                            if (MDAT_O !== expected_data)
20418
                            begin
20419
                                $display("Time %t. Wrong data from WB_MASTER detected! Expected %h, Actual %h", $time, expected_data, MDAT_O) ;
20420
                                test_fail("Wrong WB MASTER output data detected") ;
20421
                            end
20422
                        end
20423
                        @(posedge wb_clock) ;
20424
                    end
20425
                end
20426
                join
20427 73 mihad
            end
20428
 
20429 92 mihad
//            wb_transaction_num = wb_transaction_num - 1'b1 ;
20430
//            current_wb_address = current_wb_address - (transaction_sizes[wb_transaction_num] * 4) ;
20431 73 mihad
 
20432
            if (ok)
20433
                #1 disable pci_monitoring ;
20434
        end
20435
        begin:pci_monitoring
20436
            @(error_event_int) ;
20437
            test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20438
            ok = 0 ;
20439
            ok_pci = 0 ;
20440
            ok_wb  = 0 ;
20441
        end
20442
        join
20443
    end
20444
 
20445
    if ((ok && ok_wb && ok_pci) === 1'b1)
20446
        test_ok ;
20447
end
20448
endtask // test_target_overload
20449
 
20450
task test_master_overload ;
20451 106 mihad
 
20452 73 mihad
    reg ok_pci ;
20453
    reg ok_wb  ;
20454
    reg ok ;
20455
    reg [2:0] test_image_num ;
20456
    reg [2:0] received_termination ;
20457 92 mihad
    reg [31:0] transaction_sizes [0:4095] ;
20458 73 mihad
 
20459
    reg `WRITE_STIM_TYPE write_data ;
20460
 
20461
    reg `WRITE_RETURN_TYPE write_status ;
20462
    reg `WB_TRANSFER_FLAGS write_flags ;
20463
 
20464
    reg [31:0] image_base ;
20465
    reg [31:0] target_address ;
20466
 
20467
begin:main
20468
 
20469
    // set behavioral target to respond normally
20470
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
20471
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
20472
 
20473
    test_image_num = 'd1 ;
20474
 
20475
    `ifdef WB_IMAGE2
20476
        test_image_num = 'd2 ;
20477
    `endif
20478
 
20479
    `ifdef WB_IMAGE3
20480
        test_image_num = 'd3 ;
20481
    `endif
20482
 
20483
    `ifdef WB_IMAGE4
20484
        test_image_num = 'd4 ;
20485
    `endif
20486
 
20487
    `ifdef WB_IMAGE5
20488
        test_image_num = 'd5 ;
20489
    `endif
20490
 
20491
    test_name = "MASTER OVERLOAD" ;
20492
 
20493
    target_address  = `BEH_TAR1_MEM_START ;
20494
    image_base      = 0 ;
20495 92 mihad
 
20496 73 mihad
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
20497
 
20498 92 mihad
    target_address = image_base ;
20499 73 mihad
 
20500 92 mihad
    write_flags                        = 0 ;
20501
    write_flags`INIT_WAITS             = wb_init_waits ;
20502
    write_flags`SUBSEQ_WAITS           = wb_subseq_waits ;
20503
    write_flags`WB_TRANSFER_AUTO_RTY   = 0 ;
20504
    write_flags`WB_TRANSFER_CAB        = 1'b1 ;
20505 73 mihad
 
20506
    pci_configure_wb_slave_image
20507
    (
20508
        1'b1,           // use_bus
20509
        test_image_num, // image_num
20510
        image_base,     // base address
20511 92 mihad
        32'hFFFF_C000,  // address mask
20512 73 mihad
        32'h0000_0000,  // translation address
20513
        1'b0,           // io/mem mapping select
20514
        1'b1,           // prefetch enable
20515
        1'b0,           // address translation enable
20516
        1'b1,           // memory read line enable
20517
        ok              // finished succesfully
20518
    ) ;
20519
 
20520
    if (ok !== 1'b1)
20521
    begin
20522
        test_fail("WB image configuration failed") ;
20523
        disable main ;
20524
    end
20525
 
20526
    ok_wb  = 1 ;
20527
    ok_pci = 1 ;
20528
 
20529 106 mihad
    fork
20530
    begin:wb_write_overflow_blk
20531
        integer current_write_size ;
20532
        integer total_wb_transfers ;
20533
        reg [11:0] wb_transaction_num ;
20534
        integer i ;
20535 73 mihad
 
20536 106 mihad
        wb_transaction_num = 0 ;
20537
        transaction_sizes[wb_transaction_num[11:0]] = 0 ;
20538 73 mihad
 
20539 106 mihad
        for (current_write_size = 1 ; (current_write_size <= 1024) & ok_pci & ok_wb & ok ; current_write_size = current_write_size * 2)
20540 92 mihad
        begin
20541
 
20542 106 mihad
            // fill wishbone master's memory with data - inverted addresses
20543
            write_data = 0 ;
20544
            write_data`WRITE_SEL = 4'hF ;
20545
            for (i = 0 ; i < current_write_size ; i = i + 1)
20546 73 mihad
            begin
20547 106 mihad
                write_data`WRITE_ADDRESS = image_base + ((('d1024 - current_write_size) * 4) + (i * 4)) ;
20548
                write_data`WRITE_DATA    = ~(write_data`WRITE_ADDRESS);
20549
                wishbone_master.blk_write_data[i] = write_data ;
20550
            end
20551
 
20552
            total_wb_transfers = 0 ;
20553
 
20554
            write_flags`WB_FAST_B2B = 1'b0 ;
20555
 
20556
            while ((total_wb_transfers < current_write_size) & ok_pci & ok_wb & ok)
20557
            begin
20558
 
20559
                write_flags`WB_TRANSFER_SIZE = current_write_size - total_wb_transfers ;
20560 73 mihad
                wishbone_master.wb_block_write(write_flags, write_status) ;
20561 106 mihad
                write_flags`WB_FAST_B2B            = 1'b1 ;
20562
 
20563
                if (write_status`CYC_ERR | ((write_status`CYC_ERR !== 1'b1) & (write_status`CYC_RTY !== 1'b1) & (write_status`CYC_ACK !== 1'b1)))
20564 73 mihad
                begin
20565 106 mihad
                    $display("%m detected an error!") ;
20566 73 mihad
                    test_fail("Wishbone slave signaled an error or did not respond to normal write access") ;
20567
                    ok_wb = 0 ;
20568
                end
20569
 
20570 106 mihad
                total_wb_transfers = total_wb_transfers + write_status`CYC_ACTUAL_TRANSFER ;
20571
 
20572
                if (write_status`CYC_ACTUAL_TRANSFER > 0)
20573 73 mihad
                begin
20574 106 mihad
                    transaction_sizes[wb_transaction_num[11:0]] = write_status`CYC_ACTUAL_TRANSFER ;
20575
                    wishbone_master.shift_write_buffer(write_status`CYC_ACTUAL_TRANSFER) ;
20576 92 mihad
 
20577 73 mihad
                    wb_transaction_num = wb_transaction_num + 1'b1 ;
20578 106 mihad
                    transaction_sizes[wb_transaction_num[11:0]] = 0 ;
20579
 
20580 73 mihad
                end
20581
            end
20582
        end
20583 106 mihad
    end
20584
    begin:pci_models_monitoring
20585
        reg [31:0] ret_adr ; reg [3:0] ret_bc ; integer ret_num_of_transfers ; integer total_ret_num_of_transfers ;
20586
        reg ret_gnt_deasserted ;
20587
        integer current_write_size ; reg [11:0] pci_transaction_num ; reg [31:0] current_pci_address ;
20588
        integer i ;
20589
 
20590
        pci_transaction_num = 0 ;
20591
 
20592
        for (current_write_size = 1 ; (current_write_size <= 1024) & ok_pci & ok_wb & ok ; current_write_size = current_write_size * 2)
20593
        begin
20594
 
20595
            current_pci_address = image_base + ('d1024 - current_write_size) * 4 ;
20596
 
20597
            total_ret_num_of_transfers = 0 ;
20598
 
20599
            while ( (total_ret_num_of_transfers < current_write_size) & ok_pci & ok_wb & ok )
20600 73 mihad
            begin
20601 106 mihad
                monitor32.get_pci_op(ret_adr, ret_bc) ;
20602
                monitor32.get_pci_op_num_of_transfers(ret_num_of_transfers, ret_gnt_deasserted) ;
20603 73 mihad
 
20604 106 mihad
                wait( transaction_sizes[pci_transaction_num[11:0]] > 0) ;
20605
 
20606
                if (ret_adr !== current_pci_address)
20607
                begin
20608
                    $display("%m detected an error!") ;
20609
                    test_fail("PCI Master provided unexpected address when it initiated write operation") ;
20610
                    ok_pci = 1'b0 ;
20611
                end
20612
 
20613
                if (ret_bc !== `BC_MEM_WRITE)
20614
                begin
20615
                    $display("%m detected an error!") ;
20616
                    test_fail("PCI Master provided unexpected bus command when it should initiate write operation") ;
20617
                    ok_pci = 1'b0 ;
20618
                end
20619
 
20620
                if (ret_num_of_transfers !== transaction_sizes[pci_transaction_num[11:0]])
20621
                begin
20622
                    $display("%m detected an error!") ;
20623
                    test_fail("PCI Master didn't transfer expected number of words during a burst transfer") ;
20624
                    ok_pci = 1'b0 ;
20625
                end
20626
 
20627
                total_ret_num_of_transfers = total_ret_num_of_transfers + ret_num_of_transfers ;
20628
 
20629 92 mihad
                current_pci_address = current_pci_address + (4 * transaction_sizes[pci_transaction_num[11:0]]) ;
20630 73 mihad
                pci_transaction_num = pci_transaction_num + 1'b1 ;
20631 106 mihad
            end
20632
 
20633
            // check the written data
20634
            @(posedge pci_clock) ;
20635
            #1 ;
20636
            for (i = 0 ; i < current_write_size ; i = i + 1)
20637
            begin:data_chk_blk
20638
                reg [31:0] exp_dat ; reg [31:0] act_dat ;
20639
 
20640
                exp_dat = image_base + ((('d1024 - current_write_size) * 4) + (i * 4)) ;
20641
                exp_dat = ~exp_dat ;
20642
                act_dat = pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem['d1024 - current_write_size + i] ;
20643
                if (exp_dat != act_dat)
20644 73 mihad
                begin
20645 106 mihad
                    $display("Time %t!", $time) ;
20646
                    $display("Wrong data written to the target detected! Expected data %h, actual %h", exp_dat, act_dat) ;
20647
                    test_fail("wrong data was written to the target during the test") ;
20648
                    ok_pci = 0 ;
20649
                    disable main ;
20650 73 mihad
                end
20651
            end
20652 106 mihad
        end
20653 73 mihad
 
20654 106 mihad
        // wait two cycles for any wrong parity errors etc..
20655
        repeat (2)
20656
            @(posedge pci_clock) ;
20657 92 mihad
 
20658 106 mihad
        if (ok)
20659
            #1 disable pci_monitoring ;
20660 73 mihad
    end
20661 106 mihad
    begin:pci_monitoring
20662
        @(error_event_int) ;
20663
        test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20664
        ok = 0 ;
20665
        ok_pci = 0 ;
20666
        ok_wb  = 0 ;
20667
    end
20668
    join
20669 73 mihad
 
20670 106 mihad
    if ((ok & ok_wb & ok_pci) === 1'b1)
20671
        test_ok ;
20672
 
20673 92 mihad
// next two tests take forever - commented out - they are here, because some bugs were reported
20674
// they are commented out, because no bug could be found with them
20675
/*
20676
    total_transfers = 0 ;
20677
    pci_transaction_num = 0 ;
20678
    wb_transaction_num = 0 ;
20679
    current_size = 'd2880 ;
20680
 
20681
    write_data = 0 ;
20682
    write_data`WRITE_SEL = 4'hF ;
20683
    for (i = 0 ; i < current_size ; i = i + 1)
20684
    begin
20685
        write_data`WRITE_ADDRESS = image_base + (i * 4) ;
20686
        write_data`WRITE_DATA    = ~(write_data`WRITE_ADDRESS);
20687
        wishbone_master.blk_write_data[i] = write_data ;
20688
    end
20689
 
20690
    current_pci_address = image_base ;
20691
    fork
20692
    begin
20693
        while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20694
        begin
20695
 
20696
            // wait 1 clock cycle after successfull 64 word transfer, because fast b2b cycles are used
20697
            if ((total_transfers % 64) === 0)
20698
                @(posedge wb_clock) ;
20699
 
20700
            write_flags`WB_TRANSFER_SIZE = 64 - (total_transfers % 64) ;
20701
 
20702
            wishbone_master.wb_block_write(write_flags, write_status) ;
20703
            if (write_status`CYC_ERR || ((write_status`CYC_ERR !== 1'b1) && (write_status`CYC_RTY !== 1'b1) && (write_status`CYC_ACK !== 1'b1)))
20704
            begin
20705
                test_fail("Wishbone slave signaled an error or did not respond to normal write access") ;
20706
                ok_wb = 0 ;
20707
            end
20708
 
20709
            transfered = write_status`CYC_ACTUAL_TRANSFER ;
20710
            total_transfers = total_transfers + transfered ;
20711
            if (transfered > 0)
20712
            begin
20713
                transaction_sizes[wb_transaction_num[11:0]] = transfered ;
20714
                wishbone_master.shift_write_buffer(transfered) ;
20715
 
20716
                wb_transaction_num = wb_transaction_num + 1'b1 ;
20717
            end
20718
        end
20719
    end
20720
    begin:pci_models_monitoring1
20721
        while (((total_transfers < current_size) || (wb_transaction_num > pci_transaction_num)) && ok_pci && ok_wb && ok)
20722
        begin
20723
            wait(wb_transaction_num > pci_transaction_num) ;
20724
            pci_transaction_progress_monitor
20725
            (
20726
                current_pci_address,                            // address
20727
                `BC_MEM_WRITE,                                  // bus_command
20728
                transaction_sizes[pci_transaction_num[11:0]],   // num_of_transfers
20729
                0,                                              // num_of_cycles
20730
                1'b1,                                           // check_transfers
20731
                1'b0,                                           // check_cycles
20732
                1'b0,                                           // doing_fast_back_to_back
20733
                ok_pci                                          // ok
20734
            ) ;
20735
 
20736
            current_pci_address = current_pci_address + (4 * transaction_sizes[pci_transaction_num[11:0]]) ;
20737
            pci_transaction_num = pci_transaction_num + 1'b1 ;
20738
            if (ok_pci !== 1'b1)
20739
            begin
20740
                test_fail("PCI Transaction progress monitor detected invalid transaction or none at all on PCI bus");
20741
            end
20742
        end
20743
 
20744
        if (ok)
20745
            #1 disable pci_monitoring1 ;
20746
    end
20747
    begin:pci_monitoring1
20748
        @(error_event_int) ;
20749
        test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20750
        ok = 0 ;
20751
        ok_pci = 0 ;
20752
        ok_wb  = 0 ;
20753
    end
20754
    join
20755
 
20756
    // nothing should go on on pci from now on
20757
    @(posedge pci_clock) ;
20758
    for (i = 0 ; (i < 100) & (FRAME === 1'b1) ; i = i + 1)
20759
        @(posedge pci_clock) ;
20760
 
20761
    if (i !== 100)
20762
    begin
20763
        $display("Time %t", $time) ;
20764
        $display("Unexpected transaction detected on PCI bus") ;
20765
        test_fail("unexpected transaction was detected on PCI bus");
20766
    end
20767
 
20768
    total_transfers = 0 ;
20769
    pci_transaction_num = 0 ;
20770
    wb_transaction_num = 0 ;
20771
    current_size = 'd1024 *'d2000 ;
20772
 
20773
    write_data = 0 ;
20774
    write_data`WRITE_SEL = 4'hF ;
20775
 
20776
    current_pci_address = image_base ;
20777
 
20778
    fork
20779
    begin
20780
 
20781
        while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20782
        begin
20783
 
20784
            if ((total_transfers % 'd1024) === 0)
20785
            begin
20786
                // prepare new data
20787
                for (i = 0 ; i < 1024 ; i = i + 1)
20788
                begin
20789
                    j = i + 1 ;
20790
                    write_data`WRITE_ADDRESS = image_base + (i * 4) ;
20791
                    write_data`WRITE_DATA    = $random(j) ;
20792
                    wishbone_master.blk_write_data[i] = write_data ;
20793
                end
20794
 
20795
                // because fast b2b cycles are used, wait for 1 cycle
20796
                @(posedge wb_clock) ;
20797
            end
20798
 
20799
            write_flags`WB_TRANSFER_SIZE = 'd1024 - (total_transfers % 'd1024) ;
20800
 
20801
            wishbone_master.wb_block_write(write_flags, write_status) ;
20802
            if (write_status`CYC_ERR || ((write_status`CYC_ERR !== 1'b1) && (write_status`CYC_RTY !== 1'b1) && (write_status`CYC_ACK !== 1'b1)))
20803
            begin
20804
                test_fail("Wishbone slave signaled an error or did not respond to normal write access") ;
20805
                ok_wb = 0 ;
20806
            end
20807
 
20808
            transfered = write_status`CYC_ACTUAL_TRANSFER ;
20809
            total_transfers = total_transfers + transfered ;
20810
            if (transfered > 0)
20811
            begin
20812
                transaction_sizes[wb_transaction_num[11:0]] = transfered ;
20813
                wishbone_master.shift_write_buffer(transfered) ;
20814
 
20815
                wb_transaction_num = wb_transaction_num + 1'b1 ;
20816
            end
20817
        end
20818
    end
20819
    begin:pci_models_monitoring2
20820
        while (((total_transfers < current_size) || (wb_transaction_num > pci_transaction_num)) && ok_pci && ok_wb && ok)
20821
        begin
20822
            wait(wb_transaction_num > pci_transaction_num) ;
20823
            pci_transaction_progress_monitor
20824
            (
20825
                current_pci_address,                            // address
20826
                `BC_MEM_WRITE,                                  // bus_command
20827
                transaction_sizes[pci_transaction_num[11:0]],   // num_of_transfers
20828
                0,                                              // num_of_cycles
20829
                1'b1,                                           // check_transfers
20830
                1'b0,                                           // check_cycles
20831
                1'b0,                                           // doing_fast_back_to_back
20832
                ok_pci                                          // ok
20833
            ) ;
20834
 
20835
            current_pci_address = current_pci_address + (4 * transaction_sizes[pci_transaction_num[11:0]]) ;
20836
            if (current_pci_address === (image_base + 'd4096))
20837
            begin
20838
                @(posedge pci_clock) ;
20839
                @(posedge pci_clock) ;
20840
                current_pci_address = image_base ;
20841
                for (k = 0 ; k < 1024 ; k = k + 1)
20842
                begin
20843
                    l = k + 1 ;
20844
                    if (pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[k] !== $random(l))
20845
                    begin
20846
                        $display("Time %t", $time) ;
20847
                        $display("Wrong data written to the target device!") ;
20848
                        $display("Expected data %h, actual %h", $random(l), pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[k]) ;
20849
                        ok_pci = 0 ;
20850
                        test_fail("wrong data was written to pci target device") ;
20851
                    end
20852
                end
20853
            end
20854
 
20855
            pci_transaction_num = pci_transaction_num + 1'b1 ;
20856
            if (ok_pci !== 1'b1)
20857
            begin
20858
                test_fail("PCI Transaction progress monitor detected invalid transaction or none at all on PCI bus");
20859
            end
20860
        end
20861
 
20862
        repeat(2)
20863
            @(posedge pci_clock) ;
20864
 
20865
        if (ok)
20866
            #1 disable pci_monitoring2 ;
20867
    end
20868
    begin:pci_monitoring2
20869
        @(error_event_int) ;
20870
        test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20871
        ok = 0 ;
20872
        ok_pci = 0 ;
20873
        ok_wb  = 0 ;
20874
    end
20875
    join
20876
*/
20877 73 mihad
    // disable the image
20878
    pci_configure_wb_slave_image
20879
    (
20880
        1'b1,           // use_bus
20881
        test_image_num, // image_num
20882
        image_base,     // base address
20883
        32'h0000_0000,  //  address mask
20884
        32'h0000_0000,  // translation address
20885
        1'b0,           // io/mem mapping select
20886
        1'b1,           // prefetch enable
20887
        1'b0,           // address translation enable
20888
        1'b1,           // memory read line enable
20889
        ok              // finished succesfully
20890
    ) ;
20891
 
20892
    if (ok !== 1'b1)
20893
    begin
20894
        test_fail("WB image configuration failed") ;
20895
        disable main ;
20896
    end
20897
end
20898
endtask // test_master_overload
20899
 
20900 106 mihad
`ifdef fofofof
20901
`ifdef PCI_WB_REV_B3
20902
`ifdef PCI_WBS_B3_RTY_DISABLE
20903
task test_wb_slave_with_retry_generation_disabled ;
20904
    reg   [11:0] ctrl_offset ;
20905
    reg   [11:0] ba_offset ;
20906
    reg   [11:0] am_offset ;
20907
    reg `WRITE_STIM_TYPE write_data ;
20908
    reg `READ_STIM_TYPE  read_data ;
20909
    reg `READ_RETURN_TYPE read_status ;
20910
 
20911
    reg `WRITE_RETURN_TYPE write_status ;
20912
    reg `WB_TRANSFER_FLAGS flags ;
20913
    reg        wb_ok   ;
20914
    reg        pci_ok  ;
20915
    reg        ok      ;
20916
    reg [11:0] pci_ctrl_offset ;
20917
    reg [11:0] cl_size_offset  ;
20918
    reg [3:0]  cl_size_mask ;
20919
    reg [31:0] image_base ;
20920
    reg [31:0] target_address ;
20921
 
20922
    integer i ;
20923
    reg [2:0] cur_inc_burst_type ;
20924
 
20925
begin:main
20926
    wb_ok  = 1'b0 ;
20927
    pci_ok = 1'b0 ;
20928
    ok     = 1'b0 ;
20929
 
20930
    test_name   = "CONFIGURE WB IMAGE 1 FOR WB SLAVE WITH NO RETRY RESPONSE TESTING" ;
20931
 
20932
    pci_ctrl_offset = 12'h4 ;
20933
 
20934
    // image 0 can only be configuration image - start with 1
20935
    ctrl_offset    = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
20936
    ba_offset      = {4'h1, `W_BA1_ADDR, 2'b00} ;
20937
    am_offset      = {4'h1, `W_AM1_ADDR, 2'b00} ;
20938
    cl_size_offset = 12'hC ;
20939
    cl_size_mask   = 4'b0001 ;
20940
 
20941
    target_address  = `BEH_TAR1_MEM_START ;
20942
    image_base      = 0 ;
20943
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
20944
 
20945
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
20946
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
20947
    write_flags                      = 0 ;
20948
    write_flags`INIT_WAITS           = wb_init_waits ;
20949
    write_flags`SUBSEQ_WAITS         = wb_subseq_waits ;
20950
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
20951
 
20952
    // enable master & target operation
20953
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
20954
    if ( ok !== 1 )
20955
    begin
20956
        $display("No retry response testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
20957
        test_fail("write to PCI Device Control register didn't succeede");
20958
        disable main ;
20959
    end
20960
 
20961
    // prepare image control register
20962
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
20963
    if ( ok !== 1 )
20964
    begin
20965
        $display("No retry response testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", 1, $time) ;
20966
        test_fail("write to WB Image Control register didn't succeede");
20967
        disable main ;
20968
    end
20969
 
20970
    // prepare base address register
20971
    config_write( ba_offset, image_base, 4'hF, ok ) ;
20972
    if ( ok !== 1 )
20973
    begin
20974
        $display("No retry response testing failed! Failed to write W_BA%d register! Time %t ", 1, $time) ;
20975
        test_fail("write to WB Base Address register didn't succeede");
20976
        disable main ;
20977
    end
20978
 
20979
    // write address mask register
20980
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
20981
    if ( ok !== 1 )
20982
    begin
20983
        $display("No retry response testing failed! Failed to write W_AM%d register! Time %t ", 1, $time) ;
20984
        test_fail("write to WB Address Mask register didn't succeede");
20985
        disable main ;
20986
    end
20987
 
20988
    // write cache line size register
20989
    config_write( cl_size_offset, 32'h4, cl_size_mask, ok ) ;
20990
    if ( ok !== 1 )
20991
    begin
20992
        $display("No retry response testing failed! Failed to write CACHE LINE SIZE register! Time %t ", $time) ;
20993
        test_fail("write to CACHE LINE SIZE register didn't succeede");
20994
        disable main ;
20995
    end
20996
 
20997
    for (cur_inc_burst_type = 0 ; cur_inc_burst_type <= 3 ; cur_inc_burst_type = cur_inc_burst_type + 1'b1)
20998
    begin
20999
        // prepare write data - prepare enough to fill at least 2 write fifos.
21000
        for (i = 0 ; i < ((`PCIW_DEPTH) * 2) ; i = i + 1)
21001
        begin
21002
            write_data`WRITE_DATA    = $random ;
21003
 
21004
            case (cur_inc_burst_type)
21005
            2'b00:
21006
                begin
21007
                    write_data`WRITE_ADDRESS = image_base + i * 4 + 'd8 ;
21008
                end
21009
            2'b01:
21010
                begin
21011
                    write_data`WRITE_ADDRESS = ( image_base[31:4] + (i >> 2) ) << 4 ;
21012
                    if ( (i % 4) === 0 )
21013
                        write_data`WRITE_ADDRESS =  write_data`WRITE_ADDRESS + 'd8 ;
21014
                    else
21015
                        write_data`WRITE_ADDRESS = write_data`WRITE_ADDRESS + (4'd8 + (i * 4 % 4) ;
21016
                end
21017
            2'b10:
21018
                begin
21019
                end
21020
            2'b11:
21021
                begin
21022
                end
21023
            endcase
21024
 
21025
            if (cur_inc_burst_type === 0)
21026
                write_data`WRITE_ADDRESS = image_base + i * 4 + 4 ;
21027
 
21028
            if ( (i % 4) === 0)
21029
                write_data`WRITE_ADDRESS = {image_base[31:4] + (i >> 2), 4'h4}
21030
        end
21031
 
21032
        fork
21033
        begin
21034
            // perform a write with auto retry off, since retries should not be signalled by wishbone slave
21035
            flags`WB_TRANSFER_AUTO_RETRY = 1'b0 ;
21036
 
21037
            // check if received termination is not retry nor error
21038
 
21039
            // check if all transfers completed succesfully!
21040
 
21041
        end
21042
        begin
21043
 
21044
            // set behavioral target to respond with retry
21045
 
21046
            // check 2 transactions terminated with retry
21047
 
21048
            // set behavioral target to disconnect with data on first transfer
21049
            // check the transaction
21050
 
21051
        end
21052
        join
21053
    end
21054
end
21055
endtask // test_wb_slave_with_retry_generation_disabled
21056
`endif
21057
`endif
21058
`endif
21059
 
21060 15 mihad
task test_fail ;
21061
    input [7999:0] failure_reason ;
21062
begin
21063
    tests_failed = tests_failed + 1 ;
21064
 
21065 63 mihad
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
21066 15 mihad
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
21067 106 mihad
    $fdisplay( tb_log_file, " Test %0s", test_name ) ;
21068 15 mihad
    $fdisplay( tb_log_file, " *FAILED* because") ;
21069 106 mihad
    $fdisplay( tb_log_file, " %0s", failure_reason) ;
21070 63 mihad
    current_test_parameters ;
21071
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
21072 15 mihad
    $fdisplay( tb_log_file, " " ) ;
21073
 
21074
    `ifdef STOP_ON_FAILURE
21075
    #20 $stop ;
21076
    `endif
21077
end
21078
endtask // test_fail
21079
 
21080
task test_ok ;
21081
begin
21082
   tests_successfull = tests_successfull + 1 ;
21083
 
21084 63 mihad
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
21085 15 mihad
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
21086 106 mihad
   $fdisplay( tb_log_file, " Test %0s", test_name ) ;
21087 15 mihad
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
21088 63 mihad
   current_test_parameters ;
21089
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
21090 15 mihad
   $fdisplay( tb_log_file, " " ) ;
21091
end
21092
endtask // test_ok
21093
 
21094
task test_summary;
21095
begin
21096 63 mihad
    $fdisplay(tb_log_file, "\n \n");
21097 15 mihad
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
21098
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
21099
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
21100
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
21101
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
21102
    $fclose(tb_log_file) ;
21103
end
21104
endtask
21105
 
21106 63 mihad
task current_test_parameters ;
21107
    reg [87:0] decode_speed_text ;
21108
begin
21109
    case (tb_target_decode_speed)
21110
        3'b000: decode_speed_text = "FAST       " ;
21111
        3'b001: decode_speed_text = "MEDIUM     " ;
21112
        3'b010: decode_speed_text = "SLOW       " ;
21113
        3'b011: decode_speed_text = "SUBTRACTIVE" ;
21114
    endcase
21115
 
21116
    $fdisplay( tb_log_file, "TEST PARAMETERS:") ;
21117 92 mihad
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Initial Wait States         = %d", (pci_init_waits)) ;
21118
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Subsequent Wait States      = %d", (pci_subseq_waits)) ;
21119 63 mihad
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' DEVSEL speed                = %s", decode_speed_text) ;
21120
 
21121 92 mihad
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Initial Wait States    = %d", wb_init_waits) ;
21122
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Subsequent Wait States = %d", wb_subseq_waits) ;
21123 63 mihad
end
21124
endtask
21125
 
21126 73 mihad
`include "pci_bench_common_tasks.v"
21127 15 mihad
endmodule

powered by: WebSVN 2.1.0

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