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

Subversion Repositories pci

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 52 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "system.v"                                        ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Miha Dolenc (mihad@opencores.org)                     ////
10
////      - Tadej Markovic (tadej@opencores.org)                  ////
11
////                                                              ////
12
//////////////////////////////////////////////////////////////////////
13
////                                                              ////
14
//// Copyright (C) 2000 Miha Dolenc, mihad@opencores.org          ////
15
////                                                              ////
16
//// This source file may be used and distributed without         ////
17
//// restriction provided that this copyright statement is not    ////
18
//// removed from the file and that any derivative work contains  ////
19
//// the original copyright notice and the associated disclaimer. ////
20
////                                                              ////
21
//// This source file is free software; you can redistribute it   ////
22
//// and/or modify it under the terms of the GNU Lesser General   ////
23
//// Public License as published by the Free Software Foundation; ////
24
//// either version 2.1 of the License, or (at your option) any   ////
25
//// later version.                                               ////
26
////                                                              ////
27
//// This source is distributed in the hope that it will be       ////
28
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
29
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
30
//// PURPOSE.  See the GNU Lesser General Public License for more ////
31
//// details.                                                     ////
32
////                                                              ////
33
//// You should have received a copy of the GNU Lesser General    ////
34
//// Public License along with this source; if not, download it   ////
35
//// from http://www.opencores.org/lgpl.shtml                     ////
36
////                                                              ////
37
//////////////////////////////////////////////////////////////////////
38
//
39
// CVS Revision History
40
//
41
// $Log: not supported by cvs2svn $
42 81 mihad
// Revision 1.13  2003/01/21 16:06:50  mihad
43
// Bug fixes, testcases added.
44
//
45 73 mihad
// Revision 1.12  2002/10/21 13:04:30  mihad
46
// Changed BIST signal names etc..
47
//
48 69 mihad
// Revision 1.11  2002/10/11 12:03:12  mihad
49
// The testcase I just added in previous revision repaired
50
//
51 64 mihad
// Revision 1.10  2002/10/11 10:08:57  mihad
52
// Added additional testcase and changed rst name in BIST to trst
53
//
54 63 mihad
// Revision 1.9  2002/10/08 17:17:02  mihad
55
// Added BIST signals for RAMs.
56
//
57 62 mihad
// Revision 1.8  2002/09/25 09:54:47  mihad
58
// Added completion expiration test for WB Slave unit. Changed expiration signalling
59
//
60 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
61
// Oops, never before noticed that OC header is missing
62 52 mihad
//
63 57 mihad
//
64 52 mihad
 
65 15 mihad
`include "pci_constants.v"
66
`include "bus_commands.v"
67
`include "pci_testbench_defines.v"
68
`include "timescale.v"
69
 
70 51 mihad
`ifdef HOST
71
    `ifdef NO_CNF_IMAGE
72
    `else
73
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
74
    `endif
75
`else
76
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
77
`endif
78
 
79 15 mihad
module SYSTEM ;
80
 
81
`include "pci_blue_constants.vh"
82
`include "pci_blue_options.vh"
83
 
84
integer tests_successfull ;
85
integer tests_failed ;
86
integer tb_log_file ;
87
reg [799:0] test_name ;
88
 
89
reg pci_clock ;
90
reg wb_clock ;
91
reg reset ;
92
 
93
wire [4:0] arb_grant_out ;
94
 
95
wire [31:0] AD ;
96
wire [3:0]  CBE ;
97
pullup(INTA) ;
98
pullup(MAS0_REQ) ;
99
pullup(MAS1_REQ) ;
100
pullup(MAS2_REQ) ;
101
pullup(MAS3_REQ) ;
102
 
103
wire MAS0_GNT = ~arb_grant_out[0];
104
wire MAS1_GNT = ~arb_grant_out[1] ;
105
wire MAS2_GNT = ~arb_grant_out[2] ;
106
wire MAS3_GNT = ~arb_grant_out[3] ;
107
 
108
pullup(FRAME) ;
109
pullup(IRDY) ;
110 45 mihad
 
111
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
112
 
113 15 mihad
pullup(DEVSEL) ;
114
pullup(TRDY) ;
115
pullup(STOP) ;
116
wire   PAR ;
117
pullup(PERR) ;
118
pullup(SERR) ;
119
wire [3:0] MAS1_IDSEL ;
120
 
121
pullup lockpu ( LOCK ) ;
122
 
123
wire        RST_O ;
124
wire        INT_O ;
125
reg         INT_I ;
126
wire [31:0] ADR_I ;
127
wire [31:0] SDAT_I ;
128
wire [31:0] SDAT_O ;
129
wire [3:0]  SEL_I ;
130
wire        CYC_I ;
131
wire        STB_I ;
132
wire        WE_I ;
133
wire        CAB_I ;
134
wire        ACK_O ;
135
wire        RTY_O ;
136
wire        ERR_O ;
137
 
138
wire [31:0] ADR_O ;
139
wire [31:0] MDAT_I ;
140
wire [31:0] MDAT_O ;
141
wire [3:0]  SEL_O ;
142
wire        CYC_O ;
143
wire        STB_O ;
144
wire        WE_O ;
145
wire        CAB_O ;
146
wire        ACK_I ;
147
wire        RTY_I ;
148
wire        ERR_I ;
149
 
150 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
151
 
152
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
153
 
154 15 mihad
wire        reset_wb ; // reset to Wb devices
155
 
156 62 mihad
`ifdef PCI_BIST
157 69 mihad
wire scanb_so ;
158
reg  scanb_si ;
159
reg  scanb_rst ;
160
reg  scanb_en ;
161
reg  scanb_clk ;
162 62 mihad
`endif
163
 
164 15 mihad
`ifdef GUEST
165
    wire    RST = ~reset ;
166
    assign  reset_wb = RST_O ;
167
`else
168
    pullup(RST) ;
169
    assign  reset_wb = reset ;
170
`endif
171
 
172
`define PCI_BRIDGE_INSTANCE bridge32_top
173
 
174
TOP `PCI_BRIDGE_INSTANCE
175
(
176
    .CLK    ( pci_clock),
177
    .AD     ( AD ),
178
    .CBE    ( CBE ),
179
    .RST    ( RST ),
180
    .INTA   ( INTA ),
181
    .REQ    ( MAS0_REQ ),
182
    .GNT    ( MAS0_GNT ),
183
    .FRAME  ( FRAME ),
184
    .IRDY   ( IRDY ),
185
    .IDSEL  ( TAR0_IDSEL),
186
    .DEVSEL ( DEVSEL ),
187
    .TRDY   ( TRDY ),
188
    .STOP   ( STOP ),
189
    .PAR    ( PAR ),
190
    .PERR   ( PERR ),
191
    .SERR   ( SERR ),
192
 
193
    .CLK_I  ( wb_clock ),
194
    .RST_I  ( reset ),
195
    .RST_O  ( RST_O ),
196
    .INT_I  ( INT_I ),
197
    .INT_O  ( INT_O ),
198
 
199
    // WISHBONE slave interface
200
    .ADR_I  ( ADR_I ),
201
    .SDAT_I ( SDAT_I ),
202
    .SDAT_O ( SDAT_O ),
203
    .SEL_I  ( SEL_I ),
204
    .CYC_I  ( CYC_I ),
205
    .STB_I  ( STB_I ),
206
    .WE_I   ( WE_I ),
207
    .CAB_I  ( CAB_I),
208
    .ACK_O  ( ACK_O ),
209
    .RTY_O  ( RTY_O ),
210
    .ERR_O  ( ERR_O ),
211
 
212
    // WISHBONE master interface
213
    .ADR_O  ( ADR_O ),
214
    .MDAT_I ( MDAT_I ),
215
    .MDAT_O ( MDAT_O ),
216
    .SEL_O  ( SEL_O ),
217
    .CYC_O  ( CYC_O ),
218
    .STB_O  ( STB_O ),
219
    .WE_O   ( WE_O ),
220
    .CAB_O  ( CAB_O ),
221
    .ACK_I  ( ACK_I ),
222
    .RTY_I  ( RTY_I ),
223
    .ERR_I  ( ERR_I )
224 62 mihad
 
225
`ifdef PCI_BIST
226
    ,
227 69 mihad
    // bist chain signals
228
    .scanb_rst  (scanb_rst),
229
    .scanb_clk  (scanb_clk),
230
    .scanb_si   (scanb_si),
231
    .scanb_so   (scanb_so),
232
    .scanb_en   (scanb_en)
233 62 mihad
`endif
234 15 mihad
) ;
235
 
236
WB_MASTER_BEHAVIORAL wishbone_master
237
(
238
    .CLK_I(wb_clock),
239
    .RST_I(reset_wb),
240
    .TAG_I(4'b0000),
241
    .TAG_O(),
242
    .ACK_I(ACK_O),
243
    .ADR_O(ADR_I),
244
    .CYC_O(CYC_I),
245
    .DAT_I(SDAT_O),
246
    .DAT_O(SDAT_I),
247
    .ERR_I(ERR_O),
248
    .RTY_I(RTY_O),
249
    .SEL_O(SEL_I),
250
    .STB_O(STB_I),
251
    .WE_O (WE_I),
252
    .CAB_O(CAB_I)
253
);
254
 
255
WB_SLAVE_BEHAVIORAL wishbone_slave
256
(
257
    .CLK_I              (wb_clock),
258
    .RST_I              (reset_wb),
259
    .ACK_O              (ACK_I),
260
    .ADR_I              (ADR_O),
261
    .CYC_I              (CYC_O),
262
    .DAT_O              (MDAT_I),
263
    .DAT_I              (MDAT_O),
264
    .ERR_O              (ERR_I),
265
    .RTY_O              (RTY_I),
266
    .SEL_I              (SEL_O),
267
    .STB_I              (STB_O),
268
    .WE_I               (WE_O),
269
    .CAB_I              (CAB_O)
270
);
271
 
272
integer wbu_mon_log_file_desc ;
273
integer pciu_mon_log_file_desc ;
274
WB_BUS_MON wbu_wb_mon(
275
                    .CLK_I(wb_clock),
276
                    .RST_I(reset_wb),
277
                    .ACK_I(ACK_O),
278
                    .ADDR_O(ADR_I),
279
                    .CYC_O(CYC_I),
280
                    .DAT_I(SDAT_O),
281
                    .DAT_O(SDAT_I),
282
                    .ERR_I(ERR_O),
283
                    .RTY_I(RTY_O),
284
                    .SEL_O(SEL_I),
285
                    .STB_O(STB_I),
286
                    .WE_O (WE_I),
287
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
288
                    .TAG_O(),
289
                    .CAB_O(CAB_I),
290
                    .log_file_desc ( wbu_mon_log_file_desc )
291
                  ) ;
292
 
293
WB_BUS_MON pciu_wb_mon(
294
                    .CLK_I(wb_clock),
295
                    .RST_I(reset_wb),
296
                    .ACK_I(ACK_I),
297
                    .ADDR_O(ADR_O),
298
                    .CYC_O(CYC_O),
299
                    .DAT_I(MDAT_I),
300
                    .DAT_O(MDAT_O),
301
                    .ERR_I(ERR_I),
302
                    .RTY_I(RTY_I),
303
                    .SEL_O(SEL_O),
304
                    .STB_O(STB_O),
305
                    .WE_O (WE_O),
306
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
307
                    .TAG_O(),
308
                    .CAB_O(CAB_O),
309
                    .log_file_desc( pciu_mon_log_file_desc )
310
                  ) ;
311
 
312
// some aditional signals are needed here because of the arbiter
313
reg [3:0] pci_ext_req_prev ;
314
always@(posedge pci_clock)
315
begin
316
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
317
end
318
reg pci_frame_prev ;
319
always@(posedge pci_clock)
320
begin
321
    pci_frame_prev <= FRAME ;
322
end
323
reg pci_irdy_prev ;
324
always@(posedge pci_clock)
325
begin
326
    pci_irdy_prev <= IRDY ;
327
end
328
 
329
pci_blue_arbiter pci_arbiter
330
(
331
  .pci_int_req_direct(1'b0),
332
  .pci_ext_req_prev(pci_ext_req_prev),
333
  .pci_int_gnt_direct_out(arb_grant_out[4]),
334
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
335
  .pci_frame_prev(~pci_frame_prev),
336
  .pci_irdy_prev(~pci_irdy_prev),
337
  .pci_irdy_now(~IRDY),
338
  .arbitration_enable(1'b1),
339
  .pci_clk(pci_clock),
340
  .pci_reset_comb(~RST)
341
);
342
 
343
reg [31:0] target_message ;
344
 
345
// define output enable signals for monitor inputs
346
// real output enable signals
347
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
348
`ifdef ACTIVE_LOW_OE
349
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
350
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
351
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
352
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
353
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
354
                        !devsel_t_s_oe,
355
                        !ad_oe,
356
                        !cbe_oe,
357
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
358
                        ;
359
`else
360
`ifdef ACTIVE_HIGH_OE
361
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
362
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
363
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
364
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
365
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
366
                        devsel_t_s_oe,
367
                        ad_oe,
368
                        cbe_oe,
369
                        `PCI_BRIDGE_INSTANCE.PERR_en}
370
                        ;
371
`endif
372
`endif
373
/*wire [5:0] oe_sigs_0 = {1'b0,
374
                        1'b0,
375
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
376
                        pci_target32.ad_enable,
377
                        1'b0,
378
                        pci_target32.err_enable | pci_target32.r_err_enable
379
                       } ;
380
*/
381
 
382
wire [5:0] oe_sigs_2 ;
383
wire [5:0] oe_sigs_1 ;
384
 
385
// signals which are used by test modules to know what to do
386
triand  test_accepted_l_int, error_event_int;
387
pullup  (test_accepted_l_int), (error_event_int);
388
 
389
wire    pci_reset_comb  = ~RST;
390
wire    pci_ext_clk     = pci_clock;
391
 
392
integer pci_mon_log_file_desc ;
393
pci_bus_monitor monitor32
394
(
395
    .pci_ext_ad                 (AD),
396
    .pci_ext_cbe_l              (CBE),
397
    .pci_ext_par                (PAR),
398
    .pci_ext_frame_l            (FRAME),
399
    .pci_ext_irdy_l             (IRDY),
400
    .pci_ext_devsel_l           (DEVSEL),
401
    .pci_ext_trdy_l             (TRDY),
402
    .pci_ext_stop_l             (STOP),
403
    .pci_ext_perr_l             (PERR),
404
    .pci_ext_serr_l             (SERR),
405
    .pci_real_req_l             (MAS0_REQ),
406
    .pci_real_gnt_l             (MAS0_GNT),
407
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
408
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
409
    .test_error_event           (error_event_int),
410
    .test_observe_r_oe_sigs     (r_oe_sigs),
411
    .test_observe_0_oe_sigs     (6'h00),
412
    .test_observe_1_oe_sigs     (oe_sigs_1),
413
    .test_observe_2_oe_sigs     (oe_sigs_2),
414
    .test_observe_3_oe_sigs     (6'h00),
415
    .pci_ext_reset_l            (RST),
416
    .pci_ext_clk                (pci_clock),
417
    .log_file_desc              (pci_mon_log_file_desc)
418
) ;
419
 
420
reg [2:0]  test_master_number ;
421
reg [31:0] test_address ;
422
reg [3:0]  test_command ;
423
reg [31:0] test_data ;
424
reg [3:0]  test_byte_enables_l ;
425
reg [9:0]  test_size ;
426
reg        test_make_addr_par_error ;
427
reg        test_make_data_par_error ;
428
reg [3:0]  test_master_initial_wait_states ;
429
reg [3:0]  test_master_subsequent_wait_states ;
430
reg [3:0]  test_target_initial_wait_states ;
431
reg [3:0]  test_target_subsequent_wait_states ;
432
reg [1:0]  test_target_devsel_speed ;
433
reg        test_fast_back_to_back ;
434
reg [2:0]  test_target_termination ;
435
reg        test_expect_master_abort ;
436
reg        test_start ;
437
reg [25:0] test_target_response ;
438
 
439
wire [31:0] master2_received_data ;
440
wire        master2_received_data_valid ;
441
reg         master2_check_received_data ;
442
pci_behaviorial_device pci_behaviorial_device2
443
(
444
    .pci_ext_ad(AD),
445
    .pci_ext_cbe_l(CBE),
446
    .pci_ext_par(PAR),
447
    .pci_ext_frame_l(FRAME),
448
    .pci_ext_irdy_l(IRDY),
449
    .pci_ext_devsel_l(DEVSEL),
450
    .pci_ext_trdy_l(TRDY),
451
    .pci_ext_stop_l(STOP),
452
    .pci_ext_perr_l(PERR),
453
    .pci_ext_serr_l(SERR),
454
    .pci_ext_idsel(TAR2_IDSEL),
455
    .pci_ext_inta_l(INTA),
456
    .pci_ext_req_l(MAS2_REQ),
457
    .pci_ext_gnt_l(MAS2_GNT),
458
    .pci_ext_reset_l(RST),
459
    .pci_ext_clk(pci_clock),
460
 
461
// Signals used by the test bench instead of using "." notation
462
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
463
    .test_master_number                 (test_master_number[2:0]),
464
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
465
    .test_command                       (test_command[3:0]),
466
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
467
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
468
    .test_size                          (test_size),
469
    .test_make_addr_par_error           (test_make_addr_par_error),
470
    .test_make_data_par_error           (test_make_data_par_error),
471
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
472
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
473
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
474
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
475
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
476
    .test_fast_back_to_back             (test_fast_back_to_back),
477
    .test_target_termination            (test_target_termination[2:0]),
478
    .test_expect_master_abort           (test_expect_master_abort),
479
    .test_start                         (test_start),
480
    .test_accepted_l                    (test_accepted_l_int),
481
    .test_error_event                   (error_event_int),
482
    .test_device_id                     (`Test_Master_2),
483
    .test_target_response               (test_target_response),
484
 
485
    .master_received_data               (master2_received_data),
486
    .master_received_data_valid         (master2_received_data_valid),
487
    .master_check_received_data         (master2_check_received_data)
488
);
489
 
490
wire [31:0] master1_received_data ;
491
wire        master1_received_data_valid ;
492
reg         master1_check_received_data ;
493
pci_behaviorial_device pci_behaviorial_device1
494
(
495
    .pci_ext_ad(AD),
496
    .pci_ext_cbe_l(CBE),
497
    .pci_ext_par(PAR),
498
    .pci_ext_frame_l(FRAME),
499
    .pci_ext_irdy_l(IRDY),
500
    .pci_ext_devsel_l(DEVSEL),
501
    .pci_ext_trdy_l(TRDY),
502
    .pci_ext_stop_l(STOP),
503
    .pci_ext_perr_l(PERR),
504
    .pci_ext_serr_l(SERR),
505
    .pci_ext_idsel(TAR1_IDSEL),
506
    .pci_ext_inta_l(INTA),
507
    .pci_ext_req_l(MAS1_REQ),
508
    .pci_ext_gnt_l(MAS1_GNT),
509
    .pci_ext_reset_l(RST),
510
    .pci_ext_clk(pci_clock),
511
 
512
// Signals used by the test bench instead of using "." notation
513
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
514
    .test_master_number                 (test_master_number[2:0]),
515
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
516
    .test_command                       (test_command[3:0]),
517
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
518
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
519
    .test_size                          (test_size),
520
    .test_make_addr_par_error           (test_make_addr_par_error),
521
    .test_make_data_par_error           (test_make_data_par_error),
522
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
523
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
524
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
525
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
526
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
527
    .test_fast_back_to_back             (test_fast_back_to_back),
528
    .test_target_termination            (test_target_termination[2:0]),
529
    .test_expect_master_abort           (test_expect_master_abort),
530
    .test_start                         (test_start),
531
    .test_accepted_l                    (test_accepted_l_int),
532
    .test_error_event                   (error_event_int),
533
    .test_device_id                     (`Test_Master_1),
534
    .test_target_response               (test_target_response),
535
 
536
    .master_received_data               (master1_received_data),
537
    .master_received_data_valid         (master1_received_data_valid),
538
    .master_check_received_data         (master1_check_received_data)
539
);
540
 
541
pci_unsupported_commands_master ipci_unsupported_commands_master
542
(
543
    .CLK    ( pci_clock),
544
    .AD     ( AD ),
545
    .CBE    ( CBE ),
546
    .RST    ( RST ),
547
    .REQ    ( MAS3_REQ ),
548
    .GNT    ( MAS3_GNT ),
549
    .FRAME  ( FRAME ),
550
    .IRDY   ( IRDY ),
551
    .DEVSEL ( DEVSEL ),
552
    .TRDY   ( TRDY ),
553
    .STOP   ( STOP ),
554
    .PAR    ( PAR )
555
) ;
556
 
557 45 mihad
`ifdef HOST
558
 
559
reg     [1:0]   conf_cyc_type1_target_response ;
560
reg     [31:0]  conf_cyc_type1_target_data ;
561
reg     [7:0]   conf_cyc_type1_target_bus_num ;
562
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
563
 
564
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
565
(
566
    .CLK              ( pci_clock),
567
    .AD               ( AD ),
568
    .CBE              ( CBE ),
569
    .RST              ( RST ),
570
    .FRAME            ( FRAME ),
571
    .IRDY             ( IRDY ),
572
    .DEVSEL           ( DEVSEL ),
573
    .TRDY             ( TRDY ),
574
    .STOP             ( STOP ),
575
    .PAR              ( PAR ),
576
 
577
    .response         ( conf_cyc_type1_target_response ),
578
    .data_out         ( conf_cyc_type1_target_data ),
579
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
580
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
581
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
582
    .bus_number       ( conf_cyc_type1_target_bus_num )
583
);
584
`endif
585
 
586 15 mihad
// pci clock generator
587 63 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
588
    always@(posedge wb_clock)
589
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b1 ;
590
 
591
    always@(negedge wb_clock)
592
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b0 ;
593 15 mihad
`else
594 63 mihad
    always
595
    `ifdef PCI33
596
        #15 pci_clock = ~pci_clock ;
597
    `else
598
    `ifdef PCI66
599
        #7.5 pci_clock = ~pci_clock ;
600
    `endif
601
    `endif
602 15 mihad
`endif
603
 
604
// WISHBONE clock generation
605 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
606
always@(posedge pci_clock)
607
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b1 ;
608 15 mihad
 
609 63 mihad
always@(negedge pci_clock)
610
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b0 ;
611
 
612
`else
613
    always
614
        #(((1/`WB_FREQ)/2)) wb_clock = !wb_clock ;
615
`endif
616
 
617 15 mihad
// Make test name visible when the Master starts working on it
618
reg     [79:0] present_test_name;
619
reg     [79:0] next_test_name;
620
wire    test_accepted = ~test_accepted_l_int;
621
always @(posedge test_accepted)
622
begin
623
    present_test_name <= next_test_name;
624
end
625
 
626
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
627
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
628
 
629
// basic configuration parameters for both behavioral devices
630
parameter [2:0] Master_ID_A                           = `Test_Master_1;
631
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
632
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
633
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
634
 
635
parameter [2:0] Master_ID_B                           = `Test_Master_2;
636
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
637
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
638
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
639
 
640
// basic configuration parameters for REAL device
641
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
642
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
643
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
644
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
645
 
646
// reg  [2:0]   ack_err_rty_termination ;
647
// reg          wait_cycles ;
648
// reg  [7:0]   num_of_retries ;
649
 
650
//reg [19:0] pci_config_base ;
651
reg [7:0] system_burst_size ;
652
reg [7:0] bridge_latency ;
653
integer   target_mem_image ;
654
integer   target_io_image ;
655
 
656
initial
657
begin
658 62 mihad
 
659
`ifdef PCI_BIST
660 69 mihad
    scanb_si    = 0 ;
661
    scanb_en    = 0 ;
662
    scanb_clk   = 0 ;
663
    scanb_rst   = 0 ;
664 62 mihad
`endif
665 15 mihad
    next_test_name[79:0] <= "Nowhere___";
666
    reset = 1'b1 ;
667
    pci_clock = 1'b0 ;
668
    wb_clock  = 1'b1 ;
669
    target_message = 32'h0000_0000 ;
670
//  num_of_retries = 8'h01 ;
671
//  ack_err_rty_termination = 3'b100 ;
672
//  wait_cycles = 1'b0 ;
673
 
674
    // system paameters
675
    system_burst_size = 16 ;
676
    bridge_latency    = 8 ;
677
 
678
    // set initial values for controling the behavioral PCI master
679
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
680
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
681
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
682
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
683
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
684
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
685
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
686
 
687
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
688
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
689
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
690
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
691
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
692
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
693
 
694
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
695
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
696
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
697
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
698
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
699
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
700
 
701
    test_master_number = `Test_Master_2 ;
702
    test_address = 32'h0000_0000 ;
703
    test_command = `BC_RESERVED0 ;
704
    test_data = 32'h0000_0000 ;
705
    test_byte_enables_l   = 4'hF ;
706
    test_size = 0 ;
707
    test_make_addr_par_error = 0 ;
708
    test_make_data_par_error = 0;
709
    test_master_initial_wait_states = 0 ;
710
    test_master_subsequent_wait_states = 0 ;
711
    test_target_initial_wait_states = 0 ;
712
    test_target_subsequent_wait_states = 0;
713
    test_target_devsel_speed = `Test_Devsel_Fast ;
714
    test_fast_back_to_back = 0 ;
715
    test_target_termination = `Test_Target_Normal_Completion ;
716
    test_expect_master_abort = 0 ;
717
    test_start = 0 ;
718
    test_target_response = 0 ;
719
 
720
    master1_check_received_data = 0 ;
721
    master2_check_received_data = 0 ;
722
 
723 45 mihad
    `ifdef HOST
724
        conf_cyc_type1_target_response = 0 ;
725
        conf_cyc_type1_target_data = 0 ;
726
        conf_cyc_type1_target_bus_num = 255 ;
727
    `endif
728 15 mihad
 
729
    // fill memory and IO data with random values
730
    fill_memory ;
731
 
732
    INT_I = 0 ;
733
 
734
    // extract from constants which target image can be used as IO and which as memory
735
    `ifdef HOST
736
        target_mem_image = 1 ;
737
        target_io_image  = 1 ;
738
    `else
739
        target_mem_image = -1 ;
740
        target_io_image     = -1 ;
741
        if ( `PCI_BA1_MEM_IO === 0 )
742
            target_mem_image = 1 ;
743
        else
744
            target_io_image = 1 ;
745
 
746
        if ( target_mem_image === -1 )
747
        begin
748
            `ifdef PCI_IMAGE2
749
                if ( `PCI_BA2_MEM_IO === 0 )
750
                    target_mem_image = 2 ;
751
                else if ( target_io_image === -1 )
752
                    target_io_image = 2 ;
753
            `endif
754
        end
755
 
756
        if ( target_mem_image === -1 )
757
        begin
758
            `ifdef PCI_IMAGE3
759
                if ( `PCI_BA3_MEM_IO === 0 )
760
                    target_mem_image = 3 ;
761
                else if ( target_io_image === -1 )
762
                    target_io_image = 3 ;
763
            `endif
764
        end
765
 
766
        if ( target_mem_image === -1 )
767
        begin
768
            `ifdef PCI_IMAGE4
769
                if ( `PCI_BA4_MEM_IO === 0 )
770
                    target_mem_image = 4 ;
771
                else if ( target_io_image === -1 )
772
                    target_io_image = 4 ;
773
            `endif
774
        end
775
 
776
        if ( target_mem_image === -1 )
777
        begin
778
            `ifdef PCI_IMAGE5
779
                if ( `PCI_BA5_MEM_IO === 0 )
780
                    target_mem_image = 5 ;
781
                else if ( target_io_image === -1 )
782
                    target_io_image = 5 ;
783
            `endif
784
        end
785
    `endif
786
 
787
    tests_successfull = 0 ;
788
    tests_failed = 0 ;
789
 
790
    tb_log_file = $fopen("../log/pci_tb.log") ;
791
 
792
    if ( tb_log_file < 2 )
793
    begin
794
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
795
        $finish ;
796
    end
797
 
798
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
799
    $fdisplay( tb_log_file,"" ) ;
800
 
801
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
802
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
803
 
804
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
805
    begin
806
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
807
        $finish ;
808
    end
809
 
810
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
811
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
812
 
813
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
814
    if ( pci_mon_log_file_desc < 2 )
815
    begin
816
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
817
        $finish ;
818
    end
819
 
820
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
821
 
822
    run_tests ;
823
end
824
 
825
task fill_memory ;
826
    integer temp_index ;
827
begin
828
    // fill write memories with random data
829
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
830
    begin
831
        wmem_data[temp_index[9:0]] = $random ;
832 26 mihad
        # 1;
833 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
834 26 mihad
        # 1;
835 15 mihad
    end
836
    // fill WB slave behavioral MEMORY
837
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
838
    begin
839
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
840
        # 1;
841
    end
842
end
843
endtask // fill_memory
844
 
845
reg [2:0] tb_init_waits ;
846
reg [2:0] tb_subseq_waits ;
847
reg [2:0] tb_target_decode_speed ;
848
 
849
task run_tests ;
850
begin
851
    // first - reset logic
852
    do_reset ;
853 62 mihad
 
854
    // if BIST is implemented, give it a go
855
`ifdef PCI_BIST
856 73 mihad
//    run_bist_test ;
857
scanb_rst <= #1 1'b1 ;
858 62 mihad
`endif
859 45 mihad
    test_initial_conf_values ;
860
 
861 15 mihad
    next_test_name[79:0] <= "Initing...";
862
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
863
 
864
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
865
    begin
866
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
867
        begin
868
 
869
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
870
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
871
 
872
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
873
            begin
874
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
875
 
876
                `ifdef HOST
877
                    configure_bridge_target ;
878
                    find_pci_devices ;
879 45 mihad
                    test_configuration_cycle_target_abort ;
880
                    test_configuration_cycle_type1_generation ;
881 15 mihad
                `endif
882
 
883
                @(posedge pci_clock) ;
884
                configure_target(1) ;
885
                @(posedge pci_clock) ;
886
                configure_target(2) ;
887
 
888
                `ifdef GUEST
889
                    configure_bridge_target ;
890
                `endif
891
 
892
               next_test_name[79:0] <= "WB_SLAVE..";
893
 
894
                $display("Testing WISHBONE slave images' features!") ;
895
                test_wb_image(1) ;
896
 
897
                `ifdef WB_IMAGE2
898
                    test_wb_image(2) ;
899
                `else
900
                    $display(" WB IMAGE 2 not implemented! ") ;
901
                `endif
902
 
903
                `ifdef WB_IMAGE3
904
                    test_wb_image(3) ;
905
                `else
906
                    $display(" WB IMAGE 3 not implemented! ") ;
907
                `endif
908
 
909
                `ifdef WB_IMAGE4
910
                    test_wb_image(4) ;
911
                `else
912
                    $display(" WB IMAGE 4 not implemented! ") ;
913
                `endif
914
 
915
                `ifdef WB_IMAGE5
916
                    test_wb_image(5) ;
917
                `else
918
                    $display(" WB IMAGE 5 not implemented! ") ;
919
                `endif
920
 
921
                wb_slave_errors ;
922
                wb_to_pci_error_handling ;
923
 
924
                parity_checking ;
925
 
926
                wb_to_pci_transactions ;
927
 
928
                `ifdef HOST
929
                iack_cycle ;
930
                `endif
931
 
932 73 mihad
                test_master_overload ;
933
 
934 15 mihad
            end
935 57 mihad
 
936 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
937
        `else
938 57 mihad
            master_completion_expiration ;
939 63 mihad
        `endif
940 57 mihad
 
941 69 mihad
        `ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
942
            master_special_corner_case_test ;
943
        `endif
944
 
945 15 mihad
            $display(" ") ;
946
            $display("WB slave images' tests finished!") ;
947
 
948
            $display("########################################################################") ;
949
            $display("########################################################################") ;
950
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
951
            $display("########################################################################") ;
952
            $display("########################################################################") ;
953
 
954
            $display("Testing PCI target images' features!") ;
955
            configure_bridge_target_base_addresses ;
956 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
957
                test_conf_cycle_type1_reference ;
958
            `endif
959
 
960 15 mihad
            `ifdef HOST
961
             `ifdef NO_CNF_IMAGE
962
              `ifdef PCI_IMAGE0
963
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
964
            test_pci_image(0) ;
965
              `else
966
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
967
              `endif
968
             `else
969
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
970
             `endif
971
            `endif
972
 
973
            $display("PCI image 1 is ALWAYS implemented!") ;
974
            test_pci_image(1) ;
975
 
976
            `ifdef PCI_IMAGE2
977
            $display("PCI image 2 is implemented!") ;
978
            test_pci_image(2) ;
979
            `else
980
            $display("PCI image 2 is NOT implemented!") ;
981
            `endif
982
 
983
            `ifdef PCI_IMAGE3
984
            $display("PCI image 3 is implemented!") ;
985
            test_pci_image(3) ;
986
            `else
987
            $display("PCI image 3 is NOT implemented!") ;
988
            `endif
989
 
990
            `ifdef PCI_IMAGE4
991
            $display("PCI image 4 is implemented!") ;
992
            test_pci_image(4) ;
993
            `else
994
            $display("PCI image 4 is NOT implemented!") ;
995
            `endif
996
 
997
            `ifdef PCI_IMAGE5
998
            $display("PCI image 5 is implemented!") ;
999
            test_pci_image(5) ;
1000
            `else
1001
            $display("PCI image 5 is NOT implemented!") ;
1002
            `endif
1003
 
1004
            test_wb_error_rd ;
1005
 
1006
            target_fast_back_to_back ;
1007
            target_disconnects ;
1008
 
1009 73 mihad
            test_target_overload ;
1010
 
1011 15 mihad
            if ( target_io_image !== -1 )
1012
                test_target_abort( target_io_image ) ;
1013
            $display(" ") ;
1014
            $display("PCI target images' tests finished!") ;
1015
 
1016
            transaction_ordering ;
1017 33 mihad
 
1018 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
1019
        `else
1020 33 mihad
            target_completion_expiration ;
1021 63 mihad
        `endif
1022
 
1023 15 mihad
            $display(" ") ;
1024
            $display("PCI transaction ordering tests finished!") ;
1025
        end
1026
    end
1027
 
1028 73 mihad
    tb_init_waits   = 0 ;
1029
    tb_subseq_waits = 0 ;
1030
 
1031 63 mihad
    `ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
1032
        test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
1033
        test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
1034
        test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
1035
        test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = 0 ;
1036
 
1037
        `ifdef HOST
1038
            configure_bridge_target ;
1039
        `endif
1040
 
1041
        @(posedge pci_clock) ;
1042
        configure_target(1) ;
1043
        @(posedge pci_clock) ;
1044
        configure_target(2) ;
1045
 
1046
        `ifdef GUEST
1047
            configure_bridge_target ;
1048
        `endif
1049
 
1050
        target_special_corner_case_test ;
1051
    `endif
1052
 
1053 73 mihad
    tb_init_waits   = 0 ;
1054
    tb_subseq_waits = 0 ;
1055
 
1056 15 mihad
    test_summary ;
1057
 
1058
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
1059
    $stop ;
1060
end
1061
endtask // run_tests
1062
 
1063
task do_reset;
1064
begin
1065
    next_test_name[79:0] <= "Reset.....";
1066
 
1067
    reset = 1'b1 ;
1068
    #100 ;
1069
    `ifdef HOST
1070
        @(posedge wb_clock) ;
1071
    `else
1072
    `ifdef GUEST
1073
        @(posedge pci_clock) ;
1074
    `endif
1075
    `endif
1076
 
1077
    reset <= 1'b0 ;
1078
 
1079 45 mihad
    `ifdef HOST
1080
        @(posedge wb_clock) ;
1081
    `else
1082
    `ifdef GUEST
1083
        @(posedge pci_clock) ;
1084
    `endif
1085
    `endif
1086
 
1087 15 mihad
end
1088
endtask
1089
 
1090
/*############################################################################
1091
WB SLAVE UNIT tasks
1092
===================
1093
############################################################################*/
1094
 
1095
task configure_target ;
1096 45 mihad
    input [1:0]  beh_dev_num ;
1097 15 mihad
    reg   [31:0] base_address1 ;
1098
    reg   [31:0] base_address2 ;
1099
    reg   [2:0]  Master_ID;
1100
    reg   [31:0] Target_Config_Addr;
1101 45 mihad
    reg   [4:0]  device_num ;
1102 15 mihad
begin
1103 45 mihad
    if (beh_dev_num === 1)
1104 15 mihad
    begin
1105
        base_address1       = `BEH_TAR1_MEM_START ;
1106
        base_address2       = `BEH_TAR1_IO_START  ;
1107
        Master_ID           = `Test_Master_2 ;
1108
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1109 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1110 15 mihad
    end
1111
    else
1112 45 mihad
    if (beh_dev_num === 2)
1113 15 mihad
    begin
1114
        base_address1       = `BEH_TAR2_MEM_START ;
1115
        base_address2       = `BEH_TAR2_IO_START  ;
1116
        Master_ID           = `Test_Master_1 ;
1117
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1118 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1119 15 mihad
    end
1120
 
1121
    // write target's base addresses
1122
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1123
    // type 0 cycle, byte enables, base address
1124
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1125
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1126
 
1127
    // enable target's response and master
1128
    // enable parity errors, disable system error
1129
 
1130
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1131
 
1132
end
1133
endtask //configure_target
1134
 
1135
task test_wb_image ;
1136
    input [2:0]  image_num ;
1137
    reg   [11:0] ctrl_offset ;
1138
    reg   [11:0] ba_offset ;
1139
    reg   [11:0] am_offset ;
1140
    reg   [11:0] ta_offset ;
1141
    reg   [11:0] err_cs_offset ;
1142
    reg `WRITE_STIM_TYPE write_data ;
1143
    reg `READ_STIM_TYPE  read_data ;
1144
    reg `READ_RETURN_TYPE read_status ;
1145
 
1146
    reg `WRITE_RETURN_TYPE write_status ;
1147
    reg `WB_TRANSFER_FLAGS write_flags ;
1148
    reg [31:0] temp_val ;
1149
    reg        ok   ;
1150
    reg [11:0] pci_ctrl_offset ;
1151
    reg [31:0] image_base ;
1152
    reg [31:0] target_address ;
1153
    reg [31:0] translation_address ;
1154
    integer    i ;
1155
    integer    j ;
1156
begin:main
1157
    pci_ctrl_offset = 12'h4 ;
1158
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1159
    // image 0 can only be configuration image - start with 1
1160
    if (image_num === 1)
1161
    begin
1162
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1163
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1164
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1165
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1166
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1167
    end
1168
    else if (image_num === 2)
1169
    begin
1170
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1171
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1172
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1173
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1174
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1175
    end
1176
    else if (image_num === 3)
1177
    begin
1178
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1179
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1180
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1181
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1182
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1183
    end
1184
    else if (image_num === 4)
1185
    begin
1186
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1187
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1188
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1189
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1190
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1191
    end
1192
    else if (image_num === 5)
1193
    begin
1194
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1195
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1196
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1197
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1198
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1199
    end
1200
    else
1201
    begin
1202
        test_name   = "WB IMAGES' FEATURES TEST" ;
1203
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1204
        disable main ;
1205
    end
1206
 
1207
    target_address  = `BEH_TAR1_MEM_START ;
1208
    image_base      = 0 ;
1209
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1210
 
1211
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1212
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1213
    write_flags                      = 0 ;
1214
    write_flags`INIT_WAITS           = tb_init_waits ;
1215
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1216
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1217
 
1218
    test_name = "WB IMAGE CONFIGURATION" ;
1219
    // enable master & target operation
1220
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1221
    if ( ok !== 1 )
1222
    begin
1223 69 mihad
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1224 15 mihad
        test_fail("write to PCI Device Control register didn't succeede");
1225
        disable main ;
1226
    end
1227
 
1228
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1229
    if ( ok !== 1 )
1230
    begin
1231 69 mihad
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", $time) ;
1232 15 mihad
        test_fail("write to WB Error Control and Status register didn't succeede");
1233
        disable main ;
1234
    end
1235
 
1236
    // prepare image control register
1237
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1238
    if ( ok !== 1 )
1239
    begin
1240
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1241
        test_fail("write to WB Image Control register didn't succeede");
1242
        disable main ;
1243
    end
1244
 
1245
    // prepare base address register
1246
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1247
    if ( ok !== 1 )
1248
    begin
1249
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1250
        test_fail("write to WB Base Address register didn't succeede");
1251
        disable main ;
1252
    end
1253
 
1254
    // write address mask register
1255
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1256
    if ( ok !== 1 )
1257
    begin
1258
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1259
        test_fail("write to WB Address Mask register didn't succeede");
1260
        disable main ;
1261
    end
1262
 
1263
    fork
1264
    begin
1265
        write_data`WRITE_ADDRESS = target_address ;
1266
        write_data`WRITE_DATA    = wmem_data[0] ;
1267
        write_data`WRITE_SEL     = 4'hF ;
1268
 
1269
        // handle retries from now on
1270
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1271
 
1272
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1273
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1274
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1275
        begin
1276
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1277
            test_fail("WB Slave state machine failed to post single memory write");
1278
            disable main ;
1279
        end
1280
 
1281
        // read written data back
1282
        read_data`READ_ADDRESS  = target_address ;
1283
        read_data`READ_SEL      = 4'hF ;
1284
        read_data`READ_TAG_STIM = 0 ;
1285
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1286
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1287
        begin
1288
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1289
            test_fail("PCI bridge didn't process the read as expected");
1290
            disable main ;
1291
        end
1292
 
1293
        if (read_status`READ_DATA !== wmem_data[0])
1294
        begin
1295
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1296
            test_fail("PCI bridge returned unexpected Read Data");
1297
        end
1298
        else
1299
            test_ok ;
1300
    end
1301
    begin
1302
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1303
        if ( ok !== 1 )
1304
        begin
1305
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1306
        end
1307
        else
1308
            test_ok ;
1309
 
1310
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1311
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1312
        if ( ok !== 1 )
1313
        begin
1314
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1315
        end
1316
    end
1317
    join
1318
 
1319
    // if address translation is implemented - try it out
1320
    translation_address = image_base ;
1321
    `ifdef ADDR_TRAN_IMPL
1322
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1323
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1324
    if ( ok !== 1 )
1325
    begin
1326
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1327
        test_fail("write to WB Image Translation Address Register failed") ;
1328
        disable main ;
1329
    end
1330
 
1331
    target_address  = `BEH_TAR2_MEM_START ;
1332
    image_base      = 0 ;
1333
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1334
 
1335
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1336
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1337
 
1338
    write_flags                      = 0 ;
1339
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1340
 
1341
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1342
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1343
    if ( ok !== 1 )
1344
    begin
1345
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1346
        test_fail("write to WB Image Base Address Register failed") ;
1347
        disable main ;
1348
    end
1349
 
1350
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1351
    // enable address translation
1352
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1353
    if ( ok !== 1 )
1354
    begin
1355
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1356
        test_fail("write to WB Image Control Register failed") ;
1357
        disable main ;
1358
    end
1359
 
1360
    `endif
1361
 
1362
    fork
1363
    begin
1364
        write_data`WRITE_ADDRESS = target_address + 4 ;
1365
        write_data`WRITE_DATA    = wmem_data[1] ;
1366
        write_data`WRITE_SEL     = 4'hF ;
1367
 
1368
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1369
 
1370
        `ifdef ADDR_TRAN_IMPL
1371
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1372
        `else
1373
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1374
        `endif
1375
 
1376
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1377
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1378
        begin
1379
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1380
            test_fail("WB Slave state machine failed to post single memory write") ;
1381
            disable main ;
1382
        end
1383
 
1384
        // read written data back
1385
        read_data`READ_ADDRESS  = target_address + 4 ;
1386
        read_data`READ_SEL      = 4'hF ;
1387
        read_data`READ_TAG_STIM = 0 ;
1388
 
1389
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1390
 
1391
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1392
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1393
        begin
1394
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1395
            test_fail("PCI bridge failed to process single delayed memory read") ;
1396
            disable main ;
1397
        end
1398
 
1399
        if (read_status`READ_DATA !== wmem_data[1])
1400
        begin
1401
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1402
            test_fail("PCI bridge returned unexpected Read Data");
1403
        end
1404
        else
1405
            test_ok ;
1406
    end
1407
    begin
1408
        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 ) ;
1409
        if ( ok !== 1 )
1410
        begin
1411
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1412
        end
1413
        else
1414
            test_ok ;
1415
 
1416
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1417
        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 ) ;
1418
        if ( ok !== 1 )
1419
        begin
1420
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1421
        end
1422
    end
1423
    join
1424
 
1425
    // 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
1426
    // prepare write data
1427
    for ( i = 0 ; i < 6 ; i = i + 1 )
1428
    begin
1429
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1430
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1431
        write_data`WRITE_SEL     = 4'hF ;
1432
        wishbone_master.blk_write_data[i] = write_data ;
1433
    end
1434
 
1435
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1436
    write_flags`WB_TRANSFER_CAB    = 1 ;
1437
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1438
 
1439
    fork
1440
    begin
1441
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1442
        wishbone_master.wb_block_write(write_flags, write_status) ;
1443
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1444
        begin
1445
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1446
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1447
            disable main ;
1448
        end
1449
    end
1450
    begin
1451
        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 ) ;
1452
        if ( ok !== 1 )
1453
        begin
1454
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1455
        end
1456
        else
1457
            test_ok ;
1458
    end
1459
    join
1460
 
1461
    // set burst size and latency timer
1462
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1463
 
1464
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1465
    write_flags`WB_TRANSFER_CAB    = 1 ;
1466
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1467
 
1468
    // prepare read data
1469
    for ( i = 0 ; i < 4 ; i = i + 1 )
1470
    begin
1471
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1472
        read_data`READ_SEL     = 4'hF ;
1473
        wishbone_master.blk_read_data_in[i] = read_data ;
1474
    end
1475
 
1476
    fork
1477
    begin
1478
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1479
        wishbone_master.wb_block_read(write_flags, read_status) ;
1480
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1481
        begin
1482
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1483
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1484
            disable main ;
1485
        end
1486
 
1487
        // check data read from target
1488
        for ( i = 0 ; i < 4 ; i = i + 1 )
1489
        begin
1490
            read_status = wishbone_master.blk_read_data_out[i] ;
1491
            if (read_status`READ_DATA !== wmem_data[2 + i])
1492
            begin
1493
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1494
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1495
            end
1496
        end
1497
    end
1498
    begin
1499
        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 ) ;
1500
        if ( ok !== 1 )
1501
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1502
        else
1503
            test_ok ;
1504
 
1505
        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 ) ;
1506
        if ( ok !== 1 )
1507
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1508
        else
1509
            test_ok ;
1510
 
1511
        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 ) ;
1512
        if ( ok !== 1 )
1513
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1514
        else
1515
            test_ok ;
1516
 
1517
        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 ) ;
1518
        if ( ok !== 1 )
1519
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1520
        else
1521
            test_ok ;
1522
 
1523
    end
1524
    join
1525
 
1526
    // now repeat this same burst read with various image features enabled or disabled
1527
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1528
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1529
    if (ok !== 1)
1530
    begin
1531
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1532
        test_fail("write to WB Image control register failed") ;
1533
        disable main ;
1534
    end
1535
 
1536
    fork
1537
    begin
1538
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1539
        wishbone_master.wb_block_read(write_flags, read_status) ;
1540
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1541
        begin
1542
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1543
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1544
            disable main ;
1545
        end
1546
 
1547
        // check data read from target
1548
        for ( i = 0 ; i < 4 ; i = i + 1 )
1549
        begin
1550
            read_status = wishbone_master.blk_read_data_out[i] ;
1551
            if (read_status`READ_DATA !== wmem_data[2 + i])
1552
            begin
1553
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1554
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1555
            end
1556
            else
1557
                test_ok ;
1558
        end
1559
    end
1560
    begin
1561
        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 ) ;
1562
        if ( ok !== 1 )
1563
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1564
    end
1565
    join
1566
 
1567
    read_data`READ_ADDRESS  = target_address ;
1568
    read_data`READ_SEL      = 4'hF ;
1569
    read_data`READ_TAG_STIM = 0 ;
1570
 
1571
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1572
    fork
1573
    begin
1574
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1575
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1576
        begin
1577
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1578
            test_fail("delayed single memory read wasn't processed as expected") ;
1579
            disable main ;
1580
        end
1581
 
1582
        if (read_status`READ_DATA !== wmem_data[0])
1583
        begin
1584
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1585
            test_fail("delayed single memory read data value returned was not as expected") ;
1586
        end
1587
        else
1588
            test_ok ;
1589
    end
1590
    begin
1591
        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 ) ;
1592
        if ( ok !== 1 )
1593
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1594
    end
1595
    join
1596
 
1597
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1598
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1599
    if (ok !== 1)
1600
    begin
1601
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1602
        test_fail("write to WB Image control register failed") ;
1603
        disable main ;
1604
    end
1605
 
1606
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1607
    fork
1608
    begin
1609
        wishbone_master.wb_block_read(write_flags, read_status) ;
1610
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1611
        begin
1612
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1613
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1614
            disable main ;
1615
        end
1616
 
1617
        // check data read from target
1618
        for ( i = 0 ; i < 4 ; i = i + 1 )
1619
        begin
1620
            read_status = wishbone_master.blk_read_data_out[i] ;
1621
            if (read_status`READ_DATA !== wmem_data[2 + i])
1622
            begin
1623
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1624
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1625
            end
1626
            else
1627
                test_ok ;
1628
        end
1629
    end
1630
    begin
1631
        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 ) ;
1632
        if ( ok !== 1 )
1633
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1634
    end
1635
    join
1636
 
1637
    read_data`READ_ADDRESS  = target_address + 4 ;
1638
    read_data`READ_SEL      = 4'hF ;
1639
    read_data`READ_TAG_STIM = 0 ;
1640
 
1641
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1642
    fork
1643
    begin
1644
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1645
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1646
        begin
1647
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1648
            test_fail("delayed single memory read wasn't processed as expected") ;
1649
            disable main ;
1650
        end
1651
 
1652
        if (read_status`READ_DATA !== wmem_data[1])
1653
        begin
1654
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1655
            test_fail("delayed single memory read data value returned was not as expected") ;
1656
        end
1657
        else
1658
            test_ok ;
1659
    end
1660
    begin
1661
        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 ) ;
1662
        if ( ok !== 1 )
1663
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1664
    end
1665
    join
1666
 
1667
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1668
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1669
    if (ok !== 1)
1670
    begin
1671
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1672
        test_fail("write to WB Image control register failed") ;
1673
        disable main ;
1674
    end
1675
 
1676
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1677
    fork
1678
    begin
1679
        wishbone_master.wb_block_read(write_flags, read_status) ;
1680
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1681
        begin
1682
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1683
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1684
            disable main ;
1685
        end
1686
 
1687
        // check data read from target
1688
        for ( i = 0 ; i < 4 ; i = i + 1 )
1689
        begin
1690
            read_status = wishbone_master.blk_read_data_out[i] ;
1691
            if (read_status`READ_DATA !== wmem_data[2 + i])
1692
            begin
1693
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1694
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1695
            end
1696
            else
1697
                test_ok ;
1698
        end
1699
    end
1700
    begin
1701
        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 ) ;
1702
        if ( ok !== 1 )
1703
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1704
    end
1705
    join
1706
 
1707
    read_data`READ_ADDRESS  = target_address + 8 ;
1708
    read_data`READ_SEL      = 4'hF ;
1709
    read_data`READ_TAG_STIM = 0 ;
1710
 
1711
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1712
    fork
1713
    begin
1714
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1715
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1716
        begin
1717
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1718
            test_fail("delayed single memory read wasn't processed as expected") ;
1719
            disable main ;
1720
        end
1721
 
1722
        if (read_status`READ_DATA !== wmem_data[2])
1723
        begin
1724
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1725
            test_fail("delayed single memory read data value returned was not as expected") ;
1726
        end
1727
        else
1728
            test_ok ;
1729
    end
1730
    begin
1731
        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 ) ;
1732
        if ( ok !== 1 )
1733
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1734
    end
1735
    join
1736
 
1737
    // map image to IO space
1738
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1739
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1740
    if ( ok !== 1 )
1741
    begin
1742
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1743
        test_fail("write to WB Image Base Address register failed") ;
1744
        disable main ;
1745
    end
1746
 
1747
    write_data`WRITE_ADDRESS = target_address ;
1748
    write_data`WRITE_DATA    = wmem_data[11] ;
1749
    write_data`WRITE_SEL     = 4'hF ;
1750
 
1751
    // handle retries from now on
1752
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1753
 
1754
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1755
    fork
1756
    begin
1757
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1758
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1759
        begin
1760
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1761
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1762
            disable main ;
1763
        end
1764
    end
1765
    begin
1766
        // currently IO commands not supported in behavioral models - master abort
1767
        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 ) ;
1768
        if ( ok !== 1 )
1769
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1770
        else
1771
            test_ok ;
1772
    end
1773
    join
1774
 
1775
    read_data`READ_ADDRESS  = target_address ;
1776
    read_data`READ_SEL      = 4'hF ;
1777
    read_data`READ_TAG_STIM = 0 ;
1778
 
1779
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1780
 
1781
    // currently io commands are not supported by behavioral target - transfer should not be completed
1782
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1783
    fork
1784
    begin
1785
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1786
        if (read_status`CYC_ERR !== 1)
1787
        begin
1788
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1789
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1790
            disable main ;
1791
        end
1792
        else
1793
            test_ok ;
1794
    end
1795
    begin
1796
        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 ) ;
1797
        if ( ok !== 1 )
1798
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1799
    end
1800
    join
1801
 
1802
    // test byte addressing
1803
    read_data`READ_ADDRESS = target_address + 2 ;
1804
    read_data`READ_SEL     = 4'b1100 ;
1805
 
1806
    fork
1807
    begin
1808
        // currently io commands are not supported by behavioral target - transfer should not be completed
1809
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1810
        if (read_status`CYC_ERR !== 1)
1811
        begin
1812
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1813
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1814
            disable main ;
1815
        end
1816
        else test_ok ;
1817
    end
1818
    begin
1819
        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 ) ;
1820
        if ( ok !== 1 )
1821
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1822
    end
1823
    join
1824
 
1825
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1826
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1827
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1828
    if ( ok !== 1 )
1829
    begin
1830
        test_fail("WB Base address register could not be written") ;
1831
        disable main ;
1832
    end
1833
 
1834
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1835
    if ( ok !== 1 )
1836
    begin
1837
        test_fail("WB Address Mask register could not be written") ;
1838
        disable main ;
1839
    end
1840
 
1841
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1842
    if ( ok !== 1 )
1843
    begin
1844
        test_fail("WB Image Control register could not be written") ;
1845
        disable main ;
1846
    end
1847
 
1848
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1849
    write_data`WRITE_DATA    = wmem_data[11] ;
1850
    write_data`WRITE_SEL     = 4'b1000 ;
1851
 
1852
    // handle retries from now on
1853
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1854
 
1855
    fork
1856
    begin
1857
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1858
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1859
        begin
1860
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1861
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1862
            disable main ;
1863
        end
1864
    end
1865
    begin
1866
        // currently IO commands not supported in behavioral models - master abort
1867
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1868
        if ( ok !== 1 )
1869
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1870
        else
1871
            test_ok ;
1872
    end
1873
    join
1874
 
1875
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1876
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1877
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1878
 
1879
    fork
1880
    begin
1881
        // currently io commands are not supported by behavioral target - transfer should not be completed
1882
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1883
        if (read_status`CYC_ERR !== 1)
1884
        begin
1885
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1886
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1887
            disable main ;
1888
        end
1889
        else test_ok ;
1890
    end
1891
    begin
1892
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1893
        if ( ok !== 1 )
1894
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1895
    end
1896
    join
1897
 
1898
    test_name = "DISABLING WB IMAGE" ;
1899
 
1900
    // disable current image
1901
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1902
    if ( ok !== 1 )
1903
    begin
1904
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1905
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1906
        disable main ;
1907
    end
1908
 
1909
    // clear master abort status bit
1910
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1911
    if ( ok !== 1 )
1912
    begin
1913
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1914
        test_fail("write to PCI Device Status register not accepted as expected") ;
1915
        disable main ;
1916
    end
1917
 
1918
end //main
1919
endtask //test_wb_image
1920
 
1921
task wb_slave_errors ;
1922
    reg   [11:0] ctrl_offset ;
1923
    reg   [11:0] ba_offset ;
1924
    reg   [11:0] am_offset ;
1925
    reg   [11:0] ta_offset ;
1926
    reg `WRITE_STIM_TYPE write_data ;
1927
    reg `READ_STIM_TYPE  read_data ;
1928
    reg `READ_RETURN_TYPE read_status ;
1929
 
1930
    reg `WRITE_RETURN_TYPE write_status ;
1931
    reg `WB_TRANSFER_FLAGS write_flags ;
1932
    reg [31:0] temp_val1 ;
1933
    reg [31:0] temp_val2 ;
1934
    reg        ok   ;
1935
    reg [11:0] pci_ctrl_offset ;
1936
    reg [31:0] image_base ;
1937
    reg [31:0] target_address ;
1938
    integer    i ;
1939
    reg skip ;
1940
fork
1941
begin:main
1942
 
1943
    `ifdef GUEST
1944
        skip = 1 ;
1945
    `else
1946
        skip = 0 ;
1947
    `endif
1948
 
1949
    pci_ctrl_offset = 12'h4 ;
1950
 
1951
    // image 1 is used for error testing, since it is always implemented
1952
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1953
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1954
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1955
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1956
 
1957
    target_address  = `BEH_TAR1_MEM_START ;
1958
    image_base      = 0 ;
1959
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1960
 
1961
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1962
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1963
    write_flags                    = 0 ;
1964
    write_flags`INIT_WAITS         = tb_init_waits ;
1965
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1966
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1967
 
1968
    // enable master & target operation
1969
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1970
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1971
    if ( ok !== 1 )
1972
    begin
1973
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1974
        test_fail("PCI Device Control register couldn't be written") ;
1975
        disable no_transaction ;
1976
        disable main ;
1977
    end
1978
 
1979
    // prepare image control register
1980
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1981
    if ( ok !== 1 )
1982
    begin
1983
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1984
        test_fail("WB Image Control register couldn't be written") ;
1985
        disable no_transaction ;
1986
        disable main ;
1987
    end
1988
 
1989
    // prepare base address register
1990
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1991
    if ( ok !== 1 )
1992
    begin
1993
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1994
        test_fail("WB Base Address register couldn't be written") ;
1995
        disable no_transaction ;
1996
        disable main ;
1997
    end
1998
 
1999
    // write address mask register
2000
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2001
    if ( ok !== 1 )
2002
    begin
2003
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2004
        test_fail("WB Address Mask register couldn't be written") ;
2005
        disable no_transaction ;
2006
        disable main ;
2007
    end
2008
 
2009
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2010
 
2011
    skip = 0 ;
2012
 
2013
    // memory mapped image - access is erroneous when address is not alligned
2014
    write_data`WRITE_ADDRESS = target_address + 1 ;
2015
    write_data`WRITE_DATA    = wmem_data[0] ;
2016
    write_data`WRITE_SEL     = 4'hF ;
2017
 
2018
    // handle retries from now on
2019
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2020
 
2021
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
2022
 
2023
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2024
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2025
    begin
2026
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2027
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2028
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2029
        disable no_transaction ;
2030
        disable main ;
2031
    end
2032
 
2033
    write_data`WRITE_ADDRESS = target_address + 2 ;
2034
 
2035
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2036
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2037
    begin
2038
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2039
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2040
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2041
        disable no_transaction ;
2042
        disable main ;
2043
 
2044
    end
2045
 
2046
    write_data`WRITE_ADDRESS = target_address + 3 ;
2047
 
2048
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2049
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2050
    begin
2051
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2052
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2053
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2054
        disable no_transaction ;
2055
        disable main ;
2056
    end
2057
 
2058
    test_ok ;
2059
 
2060
    // perform same tests for read accesses
2061
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
2062
 
2063
    read_data`READ_ADDRESS  = target_address + 2 ;
2064
    read_data`READ_SEL      = 4'hF ;
2065
    read_data`READ_TAG_STIM = 0 ;
2066
 
2067
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2068
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2069
    begin
2070
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2071
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2072
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
2073
        disable no_transaction ;
2074
        disable main ;
2075
    end
2076
 
2077
    test_ok ;
2078
 
2079
    // prepare write data
2080
    for ( i = 0 ; i < 6 ; i = i + 1 )
2081
    begin
2082
        write_data`WRITE_DATA    = wmem_data[i] ;
2083
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
2084
        write_data`WRITE_SEL     = 4'hF ;
2085
        wishbone_master.blk_write_data[i] = write_data ;
2086
    end
2087
 
2088
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2089
    write_flags`WB_TRANSFER_CAB    = 1 ;
2090
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2091
 
2092
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
2093
    wishbone_master.wb_block_write(write_flags, write_status) ;
2094
 
2095
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2096
    begin
2097
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2098
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2099
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
2100
        disable no_transaction ;
2101
        disable main ;
2102
    end
2103
 
2104
    // prepare read data
2105
    for ( i = 0 ; i < 6 ; i = i + 1 )
2106
    begin
2107
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2108
        read_data`READ_SEL     = 4'hF ;
2109
        wishbone_master.blk_read_data_in[i] = read_data ;
2110
    end
2111
 
2112
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2113
    wishbone_master.wb_block_read(write_flags, read_status) ;
2114
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2115
    begin
2116
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2117
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2118
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2119
        disable no_transaction ;
2120
        disable main ;
2121
    end
2122
 
2123
    test_ok ;
2124
 
2125
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2126
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2127
 
2128
    // map image to IO space
2129
    `ifdef GUEST
2130
        skip = 1 ;
2131
    `endif
2132
 
2133
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2134
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2135
    if ( ok !== 1 )
2136
    begin
2137
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2138
        test_fail("WB Image Base Address register couldn't be written") ;
2139
        disable no_transaction ;
2140
        disable main ;
2141
    end
2142
 
2143
    skip = 0 ;
2144
 
2145
    write_data`WRITE_ADDRESS = target_address ;
2146
    write_data`WRITE_DATA    = wmem_data[0] ;
2147
    write_data`WRITE_SEL     = 4'b1010 ;
2148
 
2149
    // don't handle retries
2150
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2151
 
2152
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2153
 
2154
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2155
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2156
    begin
2157
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2158
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2159
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2160
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2161
        disable no_transaction ;
2162
        disable main ;
2163
    end
2164
 
2165
    write_data`WRITE_ADDRESS = target_address + 1 ;
2166
    write_data`WRITE_SEL     = 4'b0011 ;
2167
 
2168
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2169
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2170
    begin
2171
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2172
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2173
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2174
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2175
        disable no_transaction ;
2176
        disable main ;
2177
    end
2178
 
2179
    write_data`WRITE_SEL     = 4'b1100 ;
2180
 
2181
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2182
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2183
    begin
2184
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2185
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2186
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2187
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2188
        disable no_transaction ;
2189
        disable main ;
2190
    end
2191
 
2192
    write_data`WRITE_ADDRESS = target_address + 2 ;
2193
    write_data`WRITE_SEL     = 4'b0101 ;
2194
 
2195
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2196
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2197
    begin
2198
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2199
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2200
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2201
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2202
        disable no_transaction ;
2203
        disable main ;
2204
    end
2205
 
2206
    write_data`WRITE_SEL     = 4'b1000 ;
2207
 
2208
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2209
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2210
    begin
2211
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2212
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2213
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2214
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2215
        disable no_transaction ;
2216
        disable main ;
2217
    end
2218
 
2219
    write_data`WRITE_ADDRESS = target_address + 3 ;
2220
    write_data`WRITE_SEL     = 4'b1010 ;
2221
 
2222
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2223
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2224
    begin
2225
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2226
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2227
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2228
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2229
        disable no_transaction ;
2230
        disable main ;
2231
    end
2232
 
2233
    write_data`WRITE_SEL     = 4'b0110 ;
2234
 
2235
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2236
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2237
    begin
2238
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2239
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2240
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2241
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2242
        disable no_transaction ;
2243
        disable main ;
2244
    end
2245
 
2246
    test_ok ;
2247
 
2248
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2249
 
2250
    read_data`READ_ADDRESS  = target_address + 3 ;
2251
    read_data`READ_SEL      = 4'hF ;
2252
    read_data`READ_TAG_STIM = 0 ;
2253
 
2254
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2255
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2256
    begin
2257
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2258
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2259
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2260
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2261
        disable no_transaction ;
2262
        disable main ;
2263
    end
2264
 
2265
    test_ok ;
2266
 
2267
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2268
    // prepare write data
2269
    for ( i = 0 ; i < 6 ; i = i + 1 )
2270
    begin
2271
        write_data`WRITE_DATA    = wmem_data[i] ;
2272
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2273
        write_data`WRITE_SEL     = 4'hF ;
2274
        wishbone_master.blk_write_data[i] = write_data ;
2275
    end
2276
 
2277
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2278
    write_flags`WB_TRANSFER_CAB    = 1 ;
2279
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2280
 
2281
    wishbone_master.wb_block_write(write_flags, write_status) ;
2282
 
2283
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2284
    begin
2285
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2286
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2287
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2288
        disable no_transaction ;
2289
        disable main ;
2290
    end
2291
 
2292
    test_ok ;
2293
 
2294
    test_name = "CAB I/O READ TO WB SLAVE" ;
2295
    // prepare read data
2296
    for ( i = 0 ; i < 6 ; i = i + 1 )
2297
    begin
2298
        read_data`READ_ADDRESS = target_address + 4*i ;
2299
        read_data`READ_SEL     = 4'hF ;
2300
        wishbone_master.blk_read_data_in[i] = read_data ;
2301
    end
2302
 
2303
    wishbone_master.wb_block_read(write_flags, read_status) ;
2304
 
2305
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2306
    begin
2307
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2308
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2309
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2310
        disable no_transaction ;
2311
        disable main ;
2312
    end
2313
 
2314
    test_ok ;
2315
 
2316
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2317
 
2318
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2319
 
2320
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2321
    write_data`WRITE_ADDRESS = target_address + 1 ;
2322
    write_data`WRITE_DATA    = wmem_data[0] ;
2323
    write_data`WRITE_SEL     = 4'hF ;
2324
 
2325
    // don't handle retries
2326
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2327
 
2328
    `ifdef HOST
2329
        `define DO_W_CONF_TEST
2330
        `define DO_R_CONF_TEST
2331
    `else
2332
        `ifdef WB_CNF_IMAGE
2333
             `define DO_R_CONF_TEST
2334
        `endif
2335
    `endif
2336
 
2337
    `ifdef DO_W_CONF_TEST
2338
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2339
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2340
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2341
    begin
2342
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2343
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2344
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2345
        disable no_transaction ;
2346
        disable main ;
2347
    end
2348
 
2349
    write_data`WRITE_ADDRESS = target_address + 2 ;
2350
 
2351
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2352
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2353
    begin
2354
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2355
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2356
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2357
        disable no_transaction ;
2358
        disable main ;
2359
    end
2360
 
2361
    write_data`WRITE_ADDRESS = target_address + 3 ;
2362
 
2363
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2364
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2365
    begin
2366
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2367
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2368
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2369
        disable no_transaction ;
2370
        disable main ;
2371
    end
2372
 
2373
    test_ok ;
2374
    `endif
2375
 
2376
    `ifdef DO_R_CONF_TEST
2377
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2378
    read_data`READ_ADDRESS  = target_address + 3 ;
2379
    read_data`READ_SEL      = 4'hF ;
2380
    read_data`READ_TAG_STIM = 0 ;
2381
 
2382
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2383
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2384
    begin
2385
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2386
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2387
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2388
        disable no_transaction ;
2389
        disable main ;
2390
    end
2391
 
2392
    test_ok ;
2393
    `endif
2394
 
2395
    `ifdef DO_W_CONF_TEST
2396
    // prepare write data
2397
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2398
    for ( i = 0 ; i < 6 ; i = i + 1 )
2399
    begin
2400
        write_data`WRITE_DATA    = wmem_data[i] ;
2401
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2402
        write_data`WRITE_SEL     = 4'hF ;
2403
        wishbone_master.blk_write_data[i] = write_data ;
2404
    end
2405
 
2406
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2407
    write_flags`WB_TRANSFER_CAB    = 1 ;
2408
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2409
 
2410
    wishbone_master.wb_block_write(write_flags, write_status) ;
2411
 
2412
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2413
    begin
2414
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2415
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2416
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2417
        disable no_transaction ;
2418
        disable main ;
2419
    end
2420
    test_ok ;
2421
    `endif
2422
 
2423
    `ifdef DO_R_CONF_TEST
2424
    // prepare read data
2425
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2426
    for ( i = 0 ; i < 6 ; i = i + 1 )
2427
    begin
2428
        read_data`READ_ADDRESS = target_address + 4*i ;
2429
        read_data`READ_SEL     = 4'hF ;
2430
        wishbone_master.blk_read_data_in[i] = read_data ;
2431
    end
2432
 
2433
    wishbone_master.wb_block_read(write_flags, read_status) ;
2434
 
2435
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2436
    begin
2437
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2438
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2439
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2440
        disable no_transaction ;
2441
        disable main ;
2442
    end
2443
    test_ok ;
2444
    `endif
2445
 
2446
    `ifdef GUEST
2447
        skip = 1 ;
2448
    `endif
2449
 
2450
    // disable image
2451
    test_name = "DISABLE IMAGE" ;
2452
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2453
    if ( ok !== 1 )
2454
    begin
2455
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2456
        test_fail("WB Address Mask register couldn't be written") ;
2457
        disable no_transaction ;
2458
        disable main ;
2459
    end
2460
 
2461
    skip = 0 ;
2462
 
2463
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2464
 
2465
    disable no_transaction ;
2466
end
2467
begin:no_transaction
2468
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2469
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2470
    forever
2471
    begin
2472
        @(posedge pci_clock) ;
2473
        if ( skip !== 1 )
2474
        begin
2475
            if ( FRAME !== 1 )
2476
            begin
2477
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2478
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2479
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2480
            end
2481
        end
2482
    end
2483
end
2484
join
2485
endtask //wb_slave_errors
2486
 
2487
task wb_to_pci_error_handling ;
2488
    reg   [11:0] ctrl_offset ;
2489
    reg   [11:0] ba_offset ;
2490
    reg   [11:0] am_offset ;
2491
    reg   [11:0] ta_offset ;
2492
    reg   [11:0] err_cs_offset ;
2493
    reg `WRITE_STIM_TYPE write_data ;
2494
    reg `READ_STIM_TYPE  read_data ;
2495
    reg `READ_RETURN_TYPE read_status ;
2496
 
2497
    reg `WRITE_RETURN_TYPE write_status ;
2498
    reg `WB_TRANSFER_FLAGS write_flags ;
2499
    reg [31:0] temp_val1 ;
2500
    reg [31:0] temp_val2 ;
2501
    reg        ok   ;
2502
    reg [11:0] pci_ctrl_offset ;
2503
    reg [31:0] image_base ;
2504
    reg [31:0] target_address ;
2505
    integer    num_of_trans ;
2506
    integer    current ;
2507
    integer    i ;
2508
begin:main
2509
 
2510
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2511
 
2512
    pci_ctrl_offset = 12'h4 ;
2513
 
2514
    // disable error interrupts and disable error reporting
2515
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2516
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2517
    if ( ok !== 1 )
2518
    begin
2519
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2520
        test_fail("PCI Device Control register couldn't be written") ;
2521
        disable main ;
2522
    end
2523
 
2524
    // image 1 is used for error testing, since it is always implemented
2525
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2526
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2527
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2528
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2529
 
2530
    // set master abort testing address to address that goes out of target's range
2531
    target_address  = `BEH_TAR1_MEM_START ;
2532
    image_base      = 0 ;
2533
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2534
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2535
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2536
 
2537
    write_flags                    = 0 ;
2538
    write_flags`INIT_WAITS         = tb_init_waits ;
2539
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2540
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2541
 
2542
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2543
 
2544
    // enable master & target operation
2545
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2546
    if ( ok !== 1 )
2547
    begin
2548
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2549
        test_fail("PCI Device Control register couldn't be written") ;
2550
        disable main ;
2551
    end
2552
 
2553
    // prepare image control register
2554
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2555
    if ( ok !== 1 )
2556
    begin
2557
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2558
        test_fail("WB Image Control register couldn't be written") ;
2559
        disable main ;
2560
    end
2561
 
2562
    // prepare base address register
2563
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2564
    if ( ok !== 1 )
2565
    begin
2566
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2567
        test_fail("WB Image Base Address register couldn't be written") ;
2568
        disable main ;
2569
    end
2570
 
2571
    // write address mask register
2572
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2573
    if ( ok !== 1 )
2574
    begin
2575
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2576
        test_fail("WB Image Address Mask register couldn't be written") ;
2577
        disable main ;
2578
    end
2579
 
2580
    // disable error reporting
2581
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2582
    if ( ~ok )
2583
    begin
2584
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2585
        test_fail("WB Error Control and Status register couldn't be written") ;
2586
        disable main ;
2587
    end
2588
 
2589
    // perform two writes - one to error address and one to OK address
2590
    // prepare write buffer
2591
 
2592
    write_data`WRITE_ADDRESS = target_address ;
2593
    write_data`WRITE_DATA    = wmem_data[100] ;
2594
    write_data`WRITE_SEL     = 4'hF ;
2595
 
2596
    wishbone_master.blk_write_data[0] = write_data ;
2597
 
2598
    write_flags`WB_TRANSFER_SIZE = 2 ;
2599
 
2600
    // don't handle retries
2601
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2602
    write_flags`WB_TRANSFER_CAB    = 0 ;
2603
 
2604
    $display("Introducing master abort error on single WB to PCI write!") ;
2605
 
2606
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2607
    // first disable target 1
2608
 
2609 45 mihad
    configuration_cycle_write(0,                        // bus number
2610
                              `TAR1_IDSEL_INDEX - 11,   // device number
2611
                              0,                        // function number
2612
                              1,                        // register number
2613
                              0,                        // type of configuration cycle
2614
                              4'b0001,                  // byte enables
2615
                              32'h0000_0000             // data
2616 15 mihad
                             ) ;
2617
 
2618
    fork
2619
    begin
2620
        // start no response monitor in parallel with writes
2621
        musnt_respond(ok) ;
2622
        if ( ok !== 1 )
2623
        begin
2624
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2625
            $display("Testbench is configured wrong!") ;
2626
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2627
        end
2628
        else
2629
            test_ok ;
2630
    end
2631
    begin
2632
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2633
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2634
       begin
2635
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2636
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2637
           test_fail("WB Slave state machine failed to post single memory write");
2638
           disable main ;
2639
       end
2640
    end
2641
    join
2642
 
2643
    /*// read data from second write
2644
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2645
    read_data`READ_ADDRESS = target_address ;
2646
    read_data`READ_SEL     = 4'hF ;
2647
    read_data`READ_TAG_STIM = 0 ;
2648
 
2649
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2650
 
2651
    if ( read_status`READ_DATA !== wmem_data[101] )
2652
    begin
2653
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2654
    end
2655
    */
2656
 
2657
    // read error status register - no errors should be reported since reporting was disabled
2658
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2659
 
2660
    @(posedge pci_clock) ;
2661
    // wait for two WB clocks for synchronization to be finished
2662
    repeat (2)
2663
        @(posedge wb_clock) ;
2664
 
2665
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2666
    if ( temp_val1[8] !== 0 )
2667
    begin
2668
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2669
        $display("Error reporting was disabled, but error was reported anyway!") ;
2670
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2671
        disable main ;
2672
    end
2673
    test_ok ;
2674
 
2675
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2676
    // check for interrupts - there should be no interrupt requests active
2677
    `ifdef HOST
2678
        repeat(4)
2679
            @(posedge wb_clock) ;
2680
 
2681
        if ( INT_O !== 0 )
2682
        begin
2683
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2684
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2685
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2686
        end
2687
        else
2688
            test_ok ;
2689
    `else
2690
    `ifdef GUEST
2691
        repeat( 4 )
2692
            @(posedge pci_clock) ;
2693
 
2694
        if ( INTA !== 1 )
2695
        begin
2696
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2697
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2698
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2699
        end
2700
        else
2701
            test_ok ;
2702
    `endif
2703
    `endif
2704
 
2705
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2706
    // check PCI status register
2707
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2708
    if ( temp_val1[29] !== 1 )
2709
    begin
2710
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2711
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2712
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2713
    end
2714
    else
2715
        test_ok ;
2716
 
2717
    // clear
2718
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2719
 
2720
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2721
 
2722
    $display("Introducing master abort error to CAB write!") ;
2723
    // now enable error reporting mechanism
2724
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2725
    // enable error interrupts
2726
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2727
 
2728
    // configure flags for CAB transfer
2729
    write_flags`WB_TRANSFER_CAB = 1 ;
2730
    write_flags`WB_TRANSFER_SIZE = 3 ;
2731
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2732
 
2733
    // prepare data for erroneous write
2734
    for ( i = 0 ; i < 3 ; i = i + 1 )
2735
    begin
2736
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2737
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2738
        write_data`WRITE_SEL     = 4'hF ;
2739
        wishbone_master.blk_write_data[i] = write_data ;
2740
    end
2741
 
2742
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2743
    fork
2744
    begin
2745
        wishbone_master.wb_block_write(write_flags, write_status) ;
2746
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2747
        begin
2748
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2749
            $display("Complete burst write through WB slave didn't succeed!") ;
2750
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2751
            disable main ;
2752
        end
2753
    end
2754
    begin
2755
        musnt_respond(ok) ;
2756
        if ( ok !== 1 )
2757
        begin
2758
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2759
            $display("Testbench is configured wrong!") ;
2760
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2761
        end
2762
        else
2763
            test_ok ;
2764
    end
2765
    join
2766
 
2767
    // check error status address, data, byte enables and bus command
2768
    // error status bit is signalled on PCI clock and synchronized to WB clock
2769
    // wait one PCI clock cycle
2770
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2771
    ok = 1 ;
2772
    @(posedge pci_clock) ;
2773
 
2774
    // wait for two WB clocks for synchronization to be finished
2775
    repeat (2)
2776
        @(posedge wb_clock) ;
2777
 
2778
    // read registers
2779
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2780
    if ( temp_val1[8] !== 1 )
2781
    begin
2782
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2783
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2784
        ok = 0 ;
2785
    end
2786
 
2787
    if ( temp_val1[9] !== 1 )
2788
    begin
2789
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2790
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2791
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2792
        ok = 0 ;
2793
    end
2794
 
2795
    if ( temp_val1[31:28] !== 0 )
2796
    begin
2797
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2798
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2799
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2800
        ok = 0 ;
2801
    end
2802
 
2803
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2804
    begin
2805
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2806
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2807
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2808
        ok = 0 ;
2809
    end
2810
 
2811
    // read error address register
2812
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2813
    if ( temp_val1 !== target_address )
2814
    begin
2815
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2816
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2817
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2818
        ok = 0 ;
2819
    end
2820
 
2821
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2822
    if ( temp_val1 !== wmem_data[110] )
2823
    begin
2824
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2825
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2826
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2827
        ok = 0 ;
2828
    end
2829
 
2830
    // check PCI status register
2831
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2832
    if ( temp_val1[29] !== 1 )
2833
    begin
2834
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2835
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2836
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2837
        ok = 0 ;
2838
    end
2839
 
2840
    if ( temp_val1[28] !== 0 )
2841
    begin
2842
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2843
        $display("Received Target Abort bit was set for no reason!") ;
2844
        test_fail("Received Target Abort bit was set for no reason") ;
2845
        ok = 0 ;
2846
    end
2847
 
2848
    if ( ok )
2849
        test_ok ;
2850
 
2851
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2852
 
2853
    // clear error status bit
2854
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2855
 
2856
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2857
 
2858
    ok = 1 ;
2859
 
2860
    `ifdef HOST
2861
        repeat(4)
2862
        @(posedge wb_clock) ;
2863
        if ( INT_O !== 1 )
2864
        begin
2865
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2866
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2867
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2868
            ok = 0 ;
2869
        end
2870
    `else
2871
    `ifdef GUEST
2872
        repeat(4)
2873
        @(posedge pci_clock) ;
2874
        if ( INTA !== 0 )
2875
        begin
2876
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2877
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2878
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2879
            ok = 0 ;
2880
        end
2881
    `endif
2882
    `endif
2883
 
2884
    // read interrupt status register
2885
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2886
    if ( temp_val1 !== 32'h0000_0002 )
2887
    begin
2888
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2889
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2890
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2891
        test_fail("Interrupt Status register returned wrong value") ;
2892
        ok = 0 ;
2893
    end
2894
 
2895
    if ( ok )
2896
        test_ok ;
2897
    // clear interrupt status bits
2898
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2899
 
2900
    ok = 1 ;
2901
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2902
    // wait for two clock cycles before checking interrupt request deassertion
2903
    `ifdef HOST
2904
        repeat (4)
2905
            @(posedge wb_clock) ;
2906
 
2907
        if ( INT_O !== 0 )
2908
        begin
2909
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2910
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2911
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2912
            ok = 0 ;
2913
        end
2914
    `else
2915
    `ifdef GUEST
2916
        repeat (4)
2917
            @(posedge pci_clock) ;
2918
 
2919
        if ( INTA !== 1 )
2920
        begin
2921
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2922
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2923
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2924
            ok = 0 ;
2925
        end
2926
    `endif
2927
    `endif
2928
 
2929
    if ( ok )
2930
        test_ok ;
2931
 
2932
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2933
    ok = 1 ;
2934
    // enable target
2935 45 mihad
    configuration_cycle_write(0,                        // bus number
2936
                              `TAR1_IDSEL_INDEX - 11,   // device number
2937
                              0,                        // function number
2938
                              1,                        // register number
2939
                              0,                        // type of configuration cycle
2940
                              4'b0001,                  // byte enables
2941
                              32'h0000_0007             // data
2942 15 mihad
                             ) ;
2943
    // prepare data for ok write
2944
    for ( i = 0 ; i < 3 ; i = i + 1 )
2945
    begin
2946
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2947
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2948
        write_data`WRITE_SEL     = 4'hF ;
2949
        wishbone_master.blk_write_data[i] = write_data ;
2950
    end
2951
 
2952
    wishbone_master.wb_block_write(write_flags, write_status) ;
2953
 
2954
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2955
    begin
2956
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2957
        $display("Complete burst write through WB slave didn't succeed!") ;
2958
        test_fail("WB Slave state machine failed to post CAB write") ;
2959
        disable main ;
2960
    end
2961
 
2962
    // do a read
2963
    for ( i = 0 ; i < 3 ; i = i + 1 )
2964
    begin
2965
        read_data`READ_ADDRESS = target_address + 4*i ;
2966
        read_data`READ_SEL     = 4'hF ;
2967
        wishbone_master.blk_read_data_in[i] = read_data ;
2968
    end
2969
 
2970
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2971
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2972
    write_flags`WB_TRANSFER_CAB    = 1 ;
2973
 
2974
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2975
 
2976
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2977
    begin
2978
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2979
        $display("Complete burst read through WB slave didn't succeed!") ;
2980
        test_fail("Delayed CAB write was not processed as expected") ;
2981
        disable main ;
2982
    end
2983
 
2984
    for ( i = 0 ; i < 3 ; i = i + 1 )
2985
    begin
2986
        read_status = wishbone_master.blk_read_data_out[i] ;
2987
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2988
        begin
2989
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2990
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2991
        end
2992
    end
2993
 
2994
    $display("Introducing master abort error to single read!") ;
2995
    // disable target
2996 45 mihad
    configuration_cycle_write(0,                        // bus number
2997
                              `TAR1_IDSEL_INDEX - 11,   // device number
2998
                              0,                        // function number
2999
                              1,                        // register number
3000
                              0,                        // type of configuration cycle
3001
                              4'b0001,                  // byte enables
3002
                              32'h0000_0000             // data
3003 15 mihad
                             ) ;
3004
    // set read data
3005
    read_data`READ_ADDRESS = target_address ;
3006
    read_data`READ_SEL     = 4'hF ;
3007
 
3008
    // enable automatic retry handling
3009
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3010
    write_flags`WB_TRANSFER_CAB    = 0 ;
3011
 
3012
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
3013
    fork
3014
    begin
3015
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3016
    end
3017
    begin
3018
        musnt_respond(ok) ;
3019
        if ( ok !== 1 )
3020
        begin
3021
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3022
            $display("Testbench is configured wrong!") ;
3023
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3024
        end
3025
    end
3026
    join
3027
 
3028
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3029
    begin
3030
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3031
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3032
        $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) ;
3033
        test_fail("read didn't finish on WB bus as expected") ;
3034
        disable main ;
3035
    end
3036
 
3037
    test_ok ;
3038
 
3039
 
3040
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
3041
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
3042
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3043
    if ( temp_val1[8] !== 0 )
3044
    begin
3045
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3046
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
3047
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
3048
    end
3049
    else
3050
        test_ok ;
3051
 
3052
    // now check normal read operation
3053 45 mihad
    configuration_cycle_write(0,                        // bus number
3054
                              `TAR1_IDSEL_INDEX - 11,   // device number
3055
                              0,                        // function number
3056
                              1,                        // register number
3057
                              0,                        // type of configuration cycle
3058
                              4'b0001,                  // byte enables
3059
                              32'h0000_0007             // data
3060 15 mihad
                             ) ;
3061
 
3062 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
3063 15 mihad
    read_data`READ_ADDRESS = target_address ;
3064
    read_data`READ_SEL     = 4'hF ;
3065
 
3066
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3067
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3068
    begin
3069
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3070
        $display("WB slave failed to process single read!") ;
3071
        $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) ;
3072
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
3073
        disable main ;
3074
    end
3075
 
3076
    if ( read_status`READ_DATA !== wmem_data[113] )
3077
    begin
3078
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
3079
        test_fail("when read finished on WB bus, wrong data was provided") ;
3080
    end
3081
    else
3082
        test_ok ;
3083
 
3084
    // check PCI status register
3085 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
3086 15 mihad
    ok = 1 ;
3087
 
3088
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3089
    if ( temp_val1[29] !== 1 )
3090
    begin
3091
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3092
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3093
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3094
        ok = 0 ;
3095
    end
3096
 
3097
    if ( temp_val1[28] !== 0 )
3098
    begin
3099
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3100
        $display("Received Target Abort bit was set for no reason!") ;
3101
        test_fail("Received Target Abort bit was set for no reason") ;
3102
        ok = 0 ;
3103
    end
3104
    if ( ok )
3105
        test_ok ;
3106
 
3107
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3108
 
3109
    $display("Introducing master abort error to CAB read!") ;
3110
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3111
 
3112 45 mihad
    configuration_cycle_write(0,                        // bus number
3113
                              `TAR1_IDSEL_INDEX - 11,   // device number
3114
                              0,                        // function number
3115
                              1,                        // register number
3116
                              0,                        // type of configuration cycle
3117
                              4'b0001,                  // byte enables
3118
                              32'h0000_0000             // data
3119 15 mihad
                             ) ;
3120
 
3121
    for ( i = 0 ; i < 3 ; i = i + 1 )
3122
    begin
3123
        read_data`READ_ADDRESS = target_address + 4*i ;
3124
        read_data`READ_SEL     = 4'hF ;
3125
        wishbone_master.blk_read_data_in[i] = read_data ;
3126
    end
3127
 
3128
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3129
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3130
    write_flags`WB_TRANSFER_CAB    = 1 ;
3131
 
3132
    fork
3133
    begin
3134
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3135
    end
3136
    begin
3137
        musnt_respond(ok) ;
3138
        if ( ok !== 1 )
3139
        begin
3140
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3141
            $display("Testbench is configured wrong!") ;
3142
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3143
        end
3144
    end
3145
    join
3146
 
3147
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3148
    begin
3149
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3150
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3151
        $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) ;
3152
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3153
        disable main ;
3154
    end
3155
    else
3156
        test_ok ;
3157
 
3158
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3159
    ok = 1 ;
3160
    // check PCI status register
3161
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3162
    if ( temp_val1[29] !== 1 )
3163
    begin
3164
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3165
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3166
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3167
        ok = 0 ;
3168
    end
3169
 
3170
    if ( temp_val1[28] !== 0 )
3171
    begin
3172
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3173
        $display("Received Target Abort bit was set for no reason!") ;
3174
        test_fail("Received Target Abort bit was set for no reason") ;
3175
        ok = 0 ;
3176
    end
3177
 
3178
    if ( ok )
3179
        test_ok ;
3180
 
3181
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3182
 
3183
    $display("Introducing target abort termination to single write!") ;
3184
 
3185
    // disable error reporting and interrupts
3186
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
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_0007             // data
3195 15 mihad
                             ) ;
3196
 
3197
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3198
    if ( ok !== 1 )
3199
    begin
3200
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3201
        test_fail("WB Error Control and Status register couldn't be written to") ;
3202
        disable main ;
3203
    end
3204
 
3205
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3206
    if ( ok !== 1 )
3207
    begin
3208
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3209
        test_fail("Interrupt Control register couldn't be written to") ;
3210
        disable main ;
3211
    end
3212
 
3213
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3214
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3215
 
3216
    write_data`WRITE_ADDRESS = target_address ;
3217
    write_data`WRITE_DATA    = wmem_data[0] ;
3218
    write_data`WRITE_SEL     = 4'hF ;
3219
 
3220
    wishbone_master.blk_write_data[0] = write_data ;
3221
 
3222
    write_data`WRITE_ADDRESS = target_address + 4;
3223
    write_data`WRITE_DATA    = wmem_data[1] ;
3224
    write_data`WRITE_SEL     = 4'hF ;
3225
 
3226
    wishbone_master.blk_write_data[1] = write_data ;
3227
 
3228
    write_flags`WB_TRANSFER_SIZE = 2 ;
3229
 
3230
    // don't handle retries
3231
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3232
    write_flags`WB_TRANSFER_CAB    = 0 ;
3233
 
3234
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3235
    fork
3236
    begin
3237
        wishbone_master.wb_block_write(write_flags, write_status) ;
3238
 
3239
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3240
        begin
3241
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3242
            $display("Image writes were not accepted as expected!") ;
3243
            $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) ;
3244
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3245
            disable main ;
3246
        end
3247
 
3248
        // read data back to see, if it was written OK
3249
        read_data`READ_ADDRESS         = target_address + 4;
3250
        read_data`READ_SEL             = 4'hF ;
3251
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3252
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3253
    end
3254
    begin
3255
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3256
        if ( ok !== 1 )
3257
        begin
3258
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3259
        end
3260
        else
3261
            test_ok ;
3262
 
3263
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3264
 
3265
        // when first transaction finishes - enable normal target response!
3266
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3267
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3268
 
3269
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3270
        if ( ok !== 1 )
3271
        begin
3272
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3273
        end
3274
        else
3275
            test_ok ;
3276
 
3277
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3278
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3279
        if ( ok !== 1 )
3280
        begin
3281
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3282
        end
3283
    end
3284
    join
3285
 
3286
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3287
    begin
3288
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3289
        $display("Bridge failed to process single read after target abort terminated write!") ;
3290
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3291
        disable main ;
3292
    end
3293
 
3294
    if ( read_status`READ_DATA !== wmem_data[1] )
3295
    begin
3296
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3297
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3298
    end
3299
    else
3300
        test_ok ;
3301
 
3302
    // check interrupt and error statuses!
3303
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3304
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3305
    if ( temp_val1[8] !== 0 )
3306
    begin
3307
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3308
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3309
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3310
    end
3311
    else
3312
        test_ok ;
3313
 
3314
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3315
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3316
    if ( temp_val1[1] !== 0 )
3317
    begin
3318
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3319
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3320
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3321
    end
3322
    else
3323
        test_ok ;
3324
 
3325
    // check PCI status register
3326
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3327
    ok = 1 ;
3328
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3329
    if ( temp_val1[29] !== 0 )
3330
    begin
3331
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3332
        $display("Received Master Abort bit was set with no reason!") ;
3333
        test_fail("Received Master Abort bit was set with no reason") ;
3334
        ok = 0 ;
3335
    end
3336
 
3337
    if ( temp_val1[28] !== 1 )
3338
    begin
3339
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3340
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3341
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3342
        ok = 0 ;
3343
    end
3344
 
3345
    if ( ok )
3346
        test_ok ;
3347
 
3348
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3349
 
3350
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3351
 
3352
    $display("Introducing target abort termination to CAB write!") ;
3353
    // enable error reporting mechanism
3354
 
3355
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3356
    if ( ok !== 1 )
3357
    begin
3358
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3359
        test_fail("WB Error Control and Status register could not be written to") ;
3360
        disable main ;
3361
    end
3362
 
3363
    for ( i = 0 ; i < 3 ; i = i + 1 )
3364
    begin
3365
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3366
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3367
        write_data`WRITE_SEL     = 4'b1010 ;
3368
        wishbone_master.blk_write_data[i] = write_data ;
3369
    end
3370
 
3371
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3372
    write_flags`WB_TRANSFER_CAB    = 1 ;
3373
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3374
 
3375
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3376
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3377
 
3378
    fork
3379
    begin
3380
        wishbone_master.wb_block_write(write_flags, write_status) ;
3381
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3382
        begin
3383
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3384
            $display("Bridge failed to process complete CAB write!") ;
3385
            test_fail("bridge failed to post CAB Memory Write") ;
3386
            disable main ;
3387
        end
3388
    end
3389
    begin
3390
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3391
        if ( ok !== 1 )
3392
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3393
        else
3394
            test_ok ;
3395
    end
3396
    join
3397
 
3398
    // check statuses and data from error
3399
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3400
    ok = 1 ;
3401
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3402
    if ( temp_val1[8] !== 1 )
3403
    begin
3404
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3405
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3406
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3407
        ok = 0 ;
3408
    end
3409
 
3410
    if ( temp_val1[9] !== 0 )
3411
    begin
3412
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3413
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3414
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3415
        ok = 0 ;
3416
    end
3417
 
3418
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3419
    begin
3420
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3421
        $display("Value in W_ERR_CS register was wrong!") ;
3422
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3423
        test_fail("BE Field didn't provided expected value") ;
3424
        ok = 0 ;
3425
    end
3426
 
3427
    if ( ok )
3428
        test_ok ;
3429
 
3430
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3431
    ok = 1 ;
3432
    // check erroneous address and data
3433
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3434
    if ( temp_val1 !== (target_address + 8) )
3435
    begin
3436
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3437
        $display("Value in W_ERR_ADDR register was wrong!") ;
3438
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3439
        test_fail("Value in WB Erroneous Address register was wrong") ;
3440
        ok = 0 ;
3441
    end
3442
 
3443
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3444
    if ( temp_val1 !== wmem_data[120] )
3445
    begin
3446
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3447
        $display("Value in W_ERR_DATA register was wrong!") ;
3448
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3449
        test_fail("Value in WB Erroneous Data register was wrong") ;
3450
        ok = 0 ;
3451
    end
3452
 
3453
    if ( ok )
3454
        test_ok ;
3455
 
3456
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3457
    ok = 1 ;
3458
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3459
    if ( temp_val1[29] !== 0 )
3460
    begin
3461
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3462
        $display("Received Master Abort bit was set with no reason!") ;
3463
        test_fail("Received Master Abort bit was set for no reason") ;
3464
        ok = 0 ;
3465
    end
3466
 
3467
    if ( temp_val1[28] !== 1 )
3468
    begin
3469
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3470
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3471
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3472
        ok = 0 ;
3473
    end
3474
 
3475
    if ( ok )
3476
        test_ok ;
3477
 
3478
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3479
 
3480
    // clear error status bit and enable error interrupts
3481
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3482
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3483
 
3484
    // check if error bit was cleared
3485
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3486
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3487
    if ( temp_val1[8] !== 0 )
3488
    begin
3489
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3490
        $display("Error bit was not cleared even though one was written to its location!") ;
3491
        test_fail("Error bit was not cleared even though one was written to its location") ;
3492
    end
3493
 
3494
    // repeat same write with different target configuration
3495
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3496
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3497
 
3498
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3499
    fork
3500
    begin
3501
        write_flags`WB_TRANSFER_SIZE = 2 ;
3502
        wishbone_master.wb_block_write(write_flags, write_status) ;
3503
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3504
        begin
3505
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3506
            $display("Bridge failed to process complete CAB write!") ;
3507
            test_fail("bridge failed to post CAB Memory Write") ;
3508
            disable main ;
3509
        end
3510
 
3511
        write_flags`WB_TRANSFER_SIZE = 3 ;
3512
        wishbone_master.wb_block_write(write_flags, write_status) ;
3513
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3514
        begin
3515
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3516
            $display("Bridge failed to process complete CAB write!") ;
3517
            test_fail("bridge failed to post CAB Memory Write") ;
3518
            disable main ;
3519
        end
3520
    end
3521
    begin
3522
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3523
        if ( ok !== 1 )
3524
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3525
        else
3526
        begin
3527
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3528
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3529
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3530
            if ( ok !== 1 )
3531
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3532
            else
3533
                test_ok ;
3534
        end
3535
    end
3536
    join
3537
 
3538
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3539
    ok = 1 ;
3540
    // check statuses and data from error
3541
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3542
    if ( temp_val1[8] !== 1 )
3543
    begin
3544
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3545
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3546
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3547
        ok = 0 ;
3548
    end
3549
 
3550
    if ( temp_val1[9] !== 0 )
3551
    begin
3552
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3553
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3554
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3555
        ok = 0 ;
3556
    end
3557
 
3558
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3559
    begin
3560
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3561
        $display("Value in W_ERR_CS register was wrong!") ;
3562
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3563
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3564
        ok = 0 ;
3565
    end
3566
 
3567
    if ( ok )
3568
        test_ok ;
3569
 
3570
    // check erroneous address and data
3571
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3572
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3573
    ok = 1 ;
3574
    if ( temp_val1 !== (target_address + 8 + 4) )
3575
    begin
3576
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3577
        $display("Value in W_ERR_ADDR register was wrong!") ;
3578
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3579
        test_fail("Value in WB Erroneous Address register was wrong") ;
3580
        ok = 0 ;
3581
 
3582
    end
3583
 
3584
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3585
    if ( temp_val1 !== wmem_data[121] )
3586
    begin
3587
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3588
        $display("Value in W_ERR_DATA register was wrong!") ;
3589
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3590
        test_fail("Value in WB Erroneous Data register was wrong") ;
3591
        ok = 0 ;
3592
    end
3593
 
3594
    if ( ok )
3595
        test_ok ;
3596
 
3597
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3598
    `ifdef HOST
3599
        repeat(4)
3600
            @(posedge wb_clock) ;
3601
        if ( INT_O !== 1 )
3602
        begin
3603
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3604
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3605
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3606
        end
3607
        else
3608
            test_ok ;
3609
    `else
3610
    `ifdef GUEST
3611
        repeat(4)
3612
            @(posedge pci_clock) ;
3613
        if ( INTA !== 0 )
3614
        begin
3615
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3616
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3617
            test_fail("interrupt request was not presented on PCI bus") ;
3618
        end
3619
        else
3620
            test_ok ;
3621
    `endif
3622
    `endif
3623
 
3624
    // read interrupt status register
3625
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3626
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3627
    if ( temp_val1[1] !== 1 )
3628
    begin
3629
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3630
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3631
        test_fail("Expected Interrupt status bit wasn't set") ;
3632
    end
3633
 
3634
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3635
 
3636
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3637
    ok = 1 ;
3638
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3639
    if ( temp_val1[29] !== 0 )
3640
    begin
3641
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3642
        $display("Received Master Abort bit was set with no reason!") ;
3643
        test_fail("Received Master Abort bit was set with no reason") ;
3644
        ok = 0 ;
3645
    end
3646
 
3647
    if ( temp_val1[28] !== 1 )
3648
    begin
3649
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3650
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3651
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3652
        ok = 0 ;
3653
    end
3654
 
3655
    if ( ok )
3656
        test_ok ;
3657
 
3658
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3659
 
3660
    // clear interrupts and errors
3661
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3662
    repeat( 3 )
3663
        @(posedge pci_clock) ;
3664
 
3665
    repeat( 2 )
3666
        @(posedge wb_clock) ;
3667
 
3668
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3669
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3670
    if ( temp_val1[1] !== 0 )
3671
    begin
3672
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3673
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3674
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3675
    end
3676
    else
3677
        test_ok ;
3678
 
3679
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3680
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3681
    if ( temp_val1[8] !== 0 )
3682
    begin
3683
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3684
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3685
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3686
    end
3687
 
3688
 
3689
    $display("Introducing Target Abort error to single read!") ;
3690
    // set read data
3691
    read_data`READ_ADDRESS = target_address + 8 ;
3692
    read_data`READ_SEL     = 4'hF ;
3693
 
3694
    // enable automatic retry handling
3695
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3696
    write_flags`WB_TRANSFER_CAB    = 0 ;
3697
 
3698
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3699
 
3700
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3701
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3702
 
3703
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3704
 
3705
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3706
    begin
3707
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3708
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3709
        $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) ;
3710
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3711
        disable main ;
3712
    end
3713
    else
3714
        test_ok ;
3715
 
3716
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3717
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3718
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3719
    if ( temp_val1[8] !== 0 )
3720
    begin
3721
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3722
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3723
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3724
    end
3725
    else
3726
        test_ok ;
3727
 
3728
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3729
    ok = 1 ;
3730
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3731
    if ( temp_val1[29] !== 0 )
3732
    begin
3733
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3734
        $display("Received Master Abort bit was set with no reason!") ;
3735
        test_fail("Received Master Abort bit was set with no reason") ;
3736
        ok = 0 ;
3737
    end
3738
 
3739
    if ( temp_val1[28] !== 1 )
3740
    begin
3741
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3742
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3743
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3744
        ok = 0 ;
3745
    end
3746
 
3747
    if ( ok )
3748
        test_ok ;
3749
 
3750
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3751
 
3752
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3753
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3754
    if ( temp_val1[1] !== 0 )
3755
    begin
3756
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3757
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3758
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3759
    end
3760
    else
3761
        test_ok ;
3762
 
3763
    $display("Introducing Target Abort error to CAB read!") ;
3764
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3765
 
3766
    for ( i = 0 ; i < 4 ; i = i + 1 )
3767
    begin
3768
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3769
        read_data`READ_SEL     = 4'b1010 ;
3770
        wishbone_master.blk_read_data_in[i] = read_data ;
3771
    end
3772
 
3773
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3774
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3775
    write_flags`WB_TRANSFER_CAB    = 1 ;
3776
 
3777
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3778
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3779
 
3780
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3781
 
3782
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3783
    begin
3784
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3785
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3786
        $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) ;
3787
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3788
        disable main ;
3789
    end
3790
 
3791
    read_status = wishbone_master.blk_read_data_out[0] ;
3792
    temp_val1 = read_status`READ_DATA ;
3793
    temp_val2 = wmem_data[120] ;
3794
 
3795
    // last write to this address was with only two byte enables - check only those
3796
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3797
    begin
3798
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3799
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3800
    end
3801
    else
3802
        test_ok ;
3803
 
3804
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3805
    ok = 1 ;
3806
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3807
    if ( temp_val1[29] !== 0 )
3808
    begin
3809
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3810
        $display("Received Master Abort bit was set with no reason!") ;
3811
        test_fail("Received Master Abort bit was set with no reason") ;
3812
        ok = 0 ;
3813
    end
3814
 
3815
    if ( temp_val1[28] !== 1 )
3816
    begin
3817
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3818
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3819
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3820
        ok = 0 ;
3821
    end
3822
 
3823
    if ( ok )
3824
       test_ok ;
3825
 
3826
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3827
 
3828
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3829
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3830
 
3831
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3832
    for ( i = 0 ; i < 3 ; i = i + 1 )
3833
    begin
3834
        read_data`READ_ADDRESS = target_address + 4*i ;
3835
        read_data`READ_SEL     = 4'b1111 ;
3836
        wishbone_master.blk_read_data_in[i] = read_data ;
3837
    end
3838
 
3839
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3840
 
3841
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3842
 
3843
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3844
    begin
3845
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3846
        $display("Complete burst read through WB slave didn't succeed!") ;
3847
        test_fail("bridge didn't process Burst Read in an expected way") ;
3848
        disable main ;
3849
    end
3850
    else
3851
        test_ok ;
3852
 
3853
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3854
 
3855
    for ( i = 0 ; i < 3 ; i = i + 1 )
3856
    begin
3857
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3858
        read_data`READ_SEL     = 4'b1111 ;
3859
        wishbone_master.blk_read_data_in[i] = read_data ;
3860
    end
3861
 
3862
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3863
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3864
    write_flags`WB_TRANSFER_CAB    = 1 ;
3865
 
3866
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3867
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3868
 
3869
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3870
 
3871
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3872
    begin
3873
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3874
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3875
        $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) ;
3876
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3877
        disable main ;
3878
    end
3879
 
3880
    for ( i = 0 ; i < 3 ; i = i + 1 )
3881
    begin
3882
        ok = 1 ;
3883
        read_status = wishbone_master.blk_read_data_out[i] ;
3884
        temp_val1 = read_status`READ_DATA ;
3885
        temp_val2 = wmem_data[120 + i] ;
3886
 
3887
        // last write to this address was with only two byte enables - check only those
3888
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3889
        begin
3890
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3891
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3892
            ok = 0 ;
3893
        end
3894
    end
3895
 
3896
    if ( ok )
3897
        test_ok ;
3898
 
3899
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3900
    ok = 1 ;
3901
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3902
    if ( temp_val1[29] !== 0 )
3903
    begin
3904
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3905
        $display("Received Master Abort bit was set with no reason!") ;
3906
        test_fail("Received Master Abort bit was set with no reason") ;
3907
        ok = 0 ;
3908
    end
3909
 
3910
    if ( temp_val1[28] !== 1 )
3911
    begin
3912
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3913
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3914
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3915
        ok = 0 ;
3916
    end
3917
 
3918
    if ( ok )
3919
       test_ok ;
3920
 
3921
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3922
 
3923
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3924
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3925
 
3926
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3927
    for ( i = 0 ; i < 3 ; i = i + 1 )
3928
    begin
3929
        read_data`READ_ADDRESS = target_address + 4*i ;
3930
        read_data`READ_SEL     = 4'b1111 ;
3931
        wishbone_master.blk_read_data_in[i] = read_data ;
3932
    end
3933
 
3934
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3935
 
3936
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3937
 
3938
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3939
    begin
3940
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3941
        $display("Complete burst read through WB slave didn't succeed!") ;
3942
        test_fail("bridge didn't process Burst Read in an expected way") ;
3943
        disable main ;
3944
    end
3945
    else
3946
        test_ok ;
3947
 
3948
    // test error on IO write
3949
    // change base address
3950
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3951
    write_data`WRITE_SEL     = 4'b0101 ;
3952
    write_data`WRITE_ADDRESS = target_address ;
3953
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3954
 
3955
    write_flags`WB_TRANSFER_CAB    = 0 ;
3956
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3957
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3958
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3959
    fork
3960
    begin
3961
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3962
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3963
        begin
3964
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3965
            $display("WB slave failed to accept IO write!") ;
3966
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3967
            disable main ;
3968
        end
3969
    end
3970
    begin
3971
        musnt_respond(ok) ;
3972
        if ( ok !== 1 )
3973
        begin
3974
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3975
            $display("Testbench is configured wrong!") ;
3976
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3977
        end
3978
        else
3979
            test_ok ;
3980
    end
3981
    join
3982
 
3983
    // check statuses and everything else
3984
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3985
    ok = 1 ;
3986
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3987
    if ( temp_val1[8] !== 1 )
3988
    begin
3989
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3990
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3991
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3992
        ok = 0 ;
3993
    end
3994
 
3995
    if ( temp_val1[9] !== 1 )
3996
    begin
3997
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3998
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3999
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
4000
        ok = 0 ;
4001
    end
4002
 
4003
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
4004
    begin
4005
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4006
        $display("Value in W_ERR_CS register was wrong!") ;
4007
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
4008
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
4009
        ok = 0 ;
4010
    end
4011
 
4012
    if ( ok )
4013
        test_ok ;
4014
 
4015
    // check erroneous address and data
4016
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
4017
    ok = 1 ;
4018
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4019
    if ( temp_val1 !== target_address )
4020
    begin
4021
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4022
        $display("Value in W_ERR_ADDR register was wrong!") ;
4023
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
4024
        test_fail("WB Erroneous Address register didn't provide right value") ;
4025
        ok = 0 ;
4026
    end
4027
 
4028
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4029
    if ( temp_val1 !== 32'hAAAA_AAAA )
4030
    begin
4031
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4032
        $display("Value in W_ERR_DATA register was wrong!") ;
4033
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
4034
        test_fail("WB Erroneous Data register didn't provide right value") ;
4035
        ok = 0 ;
4036
    end
4037
 
4038
    if ( ok )
4039
        test_ok ;
4040
 
4041
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4042
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
4043
    if ( temp_val1[1] !== 1 )
4044
    begin
4045
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4046
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
4047
        test_fail("expected interrupt status bit was not set") ;
4048
    end
4049
    else
4050
        test_ok ;
4051
 
4052
    // clear interrupts and errors
4053
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
4054
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
4055
 
4056
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4057
    ok = 1 ;
4058
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4059
    if ( temp_val1[29] !== 1 )
4060
    begin
4061
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4062
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
4063
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
4064
        ok = 0 ;
4065
    end
4066
 
4067
    if ( temp_val1[28] !== 0 )
4068
    begin
4069
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4070
        $display("Received Target Abort bit was set for no reason!") ;
4071
        test_fail("Received Target Abort bit was set for no reason") ;
4072
        ok = 0 ;
4073
    end
4074
 
4075
    if ( ok )
4076
        test_ok ;
4077
 
4078
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4079
 
4080
    // disable image
4081
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4082
    if ( ok !== 1 )
4083
    begin
4084
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4085
        test_fail("WB Image Address Mask register couldn't be written") ;
4086
        disable main ;
4087
    end
4088
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
4089
 
4090
end
4091
endtask
4092
 
4093
task parity_checking ;
4094
    reg   [11:0] ctrl_offset ;
4095
    reg   [11:0] ba_offset ;
4096
    reg   [11:0] am_offset ;
4097
    reg   [11:0] ta_offset ;
4098
    reg `WRITE_STIM_TYPE write_data ;
4099
    reg `READ_STIM_TYPE  read_data ;
4100
    reg `READ_RETURN_TYPE read_status ;
4101
 
4102
    reg `WRITE_RETURN_TYPE write_status ;
4103
    reg `WB_TRANSFER_FLAGS write_flags ;
4104
    reg [31:0] temp_val1 ;
4105
    reg [31:0] temp_val2 ;
4106
    reg        ok   ;
4107
    reg [11:0] pci_ctrl_offset ;
4108
    reg [31:0] image_base ;
4109
    reg [31:0] target_address ;
4110
    reg [11:0] icr_offset ;
4111
    reg [11:0] isr_offset ;
4112
    reg [11:0] p_ba_offset ;
4113
    reg [11:0] p_am_offset ;
4114
    reg [11:0] p_ctrl_offset ;
4115
    integer    i ;
4116
    reg        perr_asserted ;
4117
begin:main
4118
    $display("******************************* Testing Parity Checker functions ********************************") ;
4119
    $display("Testing Parity Errors during Master Transactions!") ;
4120
    $display("Introducing Parity Erros to Master Writes!") ;
4121
    $fdisplay(pci_mon_log_file_desc,
4122
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4123
 
4124
    // image 1 is used for error testing, since it is always implemented
4125
    pci_ctrl_offset = 12'h004 ;
4126
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4127
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4128
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4129
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4130
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4131
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4132
 
4133
    // image 1 for PCI target
4134
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4135
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4136
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4137
 
4138
    target_address  = `BEH_TAR1_MEM_START ;
4139
    image_base      = 0 ;
4140
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4141
 
4142
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4143
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4144
    write_flags                    = 0 ;
4145
    write_flags`INIT_WAITS         = tb_init_waits ;
4146
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
4147
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4148
 
4149
    // enable master & target operation and disable parity functions
4150
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4151
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4152
    if ( ok !== 1 )
4153
    begin
4154
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4155
        test_fail("PCI Device Control register could not be written to") ;
4156
        disable main ;
4157
    end
4158
 
4159
    // prepare image control register
4160
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4161
    if ( ok !== 1 )
4162
    begin
4163
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4164
        test_fail("WB Image Control register could not be written to") ;
4165
        disable main ;
4166
    end
4167
 
4168
    // prepare base address register
4169
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4170
    if ( ok !== 1 )
4171
    begin
4172
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4173
        test_fail("WB Image Base Address register could not be written to") ;
4174
        disable main ;
4175
    end
4176
 
4177
    // write address mask register
4178
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4179
    if ( ok !== 1 )
4180
    begin
4181
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4182
        test_fail("WB Image Address Mask register could not be written to") ;
4183
        disable main ;
4184
    end
4185
 
4186
    // disable parity interrupts
4187
    config_write( icr_offset, 0, 4'hF, ok ) ;
4188
    if ( ok !== 1 )
4189
    begin
4190
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4191
        test_fail("Interrupt Control register could not be written to") ;
4192
        disable main ;
4193
    end
4194
 
4195
    write_data`WRITE_ADDRESS = target_address ;
4196
    write_data`WRITE_DATA    = wmem_data[0] ;
4197
    write_data`WRITE_SEL     = 4'b1111 ;
4198
 
4199
    // enable target's 1 response to parity errors
4200 45 mihad
    configuration_cycle_write(0,                        // bus number
4201
                              `TAR1_IDSEL_INDEX - 11,   // device number
4202
                              0,                        // function number
4203
                              1,                        // register number
4204
                              0,                        // type of configuration cycle
4205
                              4'b0001,                  // byte enables
4206
                              32'h0000_0047             // data
4207 15 mihad
                             ) ;
4208
 
4209
    // disable target's 2 response to parity errors
4210 45 mihad
    configuration_cycle_write(0,                        // bus number
4211
                              `TAR2_IDSEL_INDEX - 11,   // device number
4212
                              0,                        // function number
4213
                              1,                        // register number
4214
                              0,                        // type of configuration cycle
4215
                              4'b0001,                  // byte enables
4216
                              32'h0000_0007             // data
4217 15 mihad
                             ) ;
4218
 
4219
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4220
 
4221
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4222
    fork
4223
    begin
4224
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4225
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4226
        begin
4227
            $display("Parity checker testing failed! Time %t ", $time) ;
4228
            $display("Bridge failed to process single memory write!") ;
4229
            test_fail("bridge failed to post single WB memory write") ;
4230
            disable main ;
4231
        end
4232
    end
4233
    begin:wait_perr1
4234
        perr_asserted = 0 ;
4235
        @(posedge pci_clock) ;
4236
 
4237 35 mihad
        while ( PERR !== 0 )
4238 15 mihad
            @(posedge pci_clock) ;
4239
 
4240 35 mihad
        perr_asserted = 1 ;
4241 15 mihad
 
4242
    end
4243
    begin
4244
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4245
 
4246
        if ( ok !== 1 )
4247
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4248
 
4249 35 mihad
        repeat(2)
4250 15 mihad
            @(posedge pci_clock) ;
4251
 
4252 35 mihad
        #1 ;
4253
        if ( !perr_asserted )
4254
            disable wait_perr1 ;
4255 15 mihad
    end
4256
    join
4257
 
4258
    if ( perr_asserted && ok )
4259
    begin
4260
        test_ok ;
4261
    end
4262
    else
4263
    if ( ~perr_asserted )
4264
    begin
4265
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4266
        disable main ;
4267
    end
4268
 
4269
    // check all the statuses - if HOST is defined, wait for them to be synced
4270
    `ifdef HOST
4271
    repeat(4)
4272
        @(posedge wb_clock) ;
4273
    `endif
4274
 
4275
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4276
    ok = 1 ;
4277
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4278 45 mihad
    if ( temp_val1[31] !== 0 )
4279 15 mihad
    begin
4280
        $display("Parity checker testing failed! Time %t ", $time) ;
4281 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4282
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4283 15 mihad
        ok = 0 ;
4284
    end
4285
 
4286
    if ( temp_val1[30] !== 0 )
4287
    begin
4288
        $display("Parity checker testing failed! Time %t ", $time) ;
4289
        $display("Signalled System Error bit was set for no reason!") ;
4290
        test_fail("Signalled System Error bit was set for no reason") ;
4291
        ok = 0 ;
4292
    end
4293
 
4294
    if ( temp_val1[24] !== 0 )
4295
    begin
4296
        $display("Parity checker testing failed! Time %t ", $time) ;
4297
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4298
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4299
        ok = 0 ;
4300
    end
4301
 
4302
    if ( ok )
4303
        test_ok ;
4304
 
4305
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4306
    // clear parity bits and enable parity response
4307
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4308
    if ( ok !== 1 )
4309
    begin
4310
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4311
        test_fail("write to PCI Status Register failed") ;
4312
        disable main ;
4313
    end
4314
 
4315
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4316
    fork
4317
    begin
4318
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4319
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4320
        begin
4321
            $display("Parity checker testing failed! Time %t ", $time) ;
4322
            $display("Bridge failed to process single memory write!") ;
4323
            test_fail("bridge failed to post single memory write") ;
4324
            disable main ;
4325
        end
4326
    end
4327
    begin:wait_perr2
4328
        perr_asserted = 0 ;
4329
        @(posedge pci_clock) ;
4330
 
4331 35 mihad
        while ( PERR !== 0 )
4332 15 mihad
            @(posedge pci_clock) ;
4333
 
4334 35 mihad
        perr_asserted = 1 ;
4335 15 mihad
 
4336
    end
4337
    begin
4338
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4339
 
4340
        if ( ok !== 1 )
4341
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4342
 
4343 35 mihad
        repeat(2)
4344 15 mihad
            @(posedge pci_clock) ;
4345
 
4346 35 mihad
        #1 ;
4347
        if (!perr_asserted)
4348
            disable wait_perr2 ;
4349 15 mihad
    end
4350
    join
4351
 
4352
    if ( perr_asserted && ok )
4353
    begin
4354
        test_ok ;
4355
    end
4356
    else
4357
    if ( ~perr_asserted )
4358
    begin
4359
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4360
        disable main ;
4361
    end
4362
 
4363
    // check all the statuses - if HOST is defined, wait for them to be synced
4364
    `ifdef HOST
4365
    repeat(4)
4366
        @(posedge wb_clock) ;
4367
    `endif
4368
 
4369
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4370
    ok = 1 ;
4371
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4372 45 mihad
    if ( temp_val1[31] !== 0 )
4373 15 mihad
    begin
4374
        $display("Parity checker testing failed! Time %t ", $time) ;
4375 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4376
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4377 15 mihad
        ok = 0 ;
4378
    end
4379
 
4380
    if ( temp_val1[30] !== 0 )
4381
    begin
4382
        $display("Parity checker testing failed! Time %t ", $time) ;
4383
        $display("Signalled System Error bit was set for no reason!") ;
4384
        test_fail("Signalled System Error bit was set for no reason") ;
4385
        ok = 0 ;
4386
    end
4387
 
4388
    if ( temp_val1[24] !== 1 )
4389
    begin
4390
        $display("Parity checker testing failed! Time %t ", $time) ;
4391 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!") ;
4392
        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") ;
4393 15 mihad
        ok = 0 ;
4394
    end
4395
 
4396
    if ( ok )
4397
        test_ok ;
4398
 
4399
    // clear status bits and disable parity error response
4400
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4401
 
4402
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4403
 
4404
    // disable perr generation and perform a write - no bits should be set
4405
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4406
    fork
4407
    begin
4408
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4409
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4410
        begin
4411
            $display("Parity checker testing failed! Time %t ", $time) ;
4412
            $display("Bridge failed to process single memory write!") ;
4413
            test_fail("bridge failed to post single memory write") ;
4414
            disable main ;
4415
        end
4416
    end
4417
    begin
4418
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4419
 
4420
        if ( ok !== 1 )
4421
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4422
        else
4423
            test_ok ;
4424
 
4425
        repeat(3)
4426
            @(posedge pci_clock) ;
4427
    end
4428
    join
4429
 
4430
    `ifdef HOST
4431
    repeat(4)
4432
        @(posedge wb_clock) ;
4433
    `endif
4434
 
4435
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4436
    ok = 1 ;
4437
 
4438
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4439
    if ( temp_val1[31] !== 0 )
4440
    begin
4441
        $display("Parity checker testing failed! Time %t ", $time) ;
4442
        $display("Detected Parity Error bit was set for no reason!") ;
4443
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4444
        ok = 0 ;
4445
    end
4446
 
4447
    if ( temp_val1[30] !== 0 )
4448
    begin
4449
        $display("Parity checker testing failed! Time %t ", $time) ;
4450
        $display("Signalled System Error bit was set for no reason!") ;
4451
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4452
        ok = 0 ;
4453
    end
4454
 
4455
    if ( temp_val1[24] !== 0 )
4456
    begin
4457
        $display("Parity checker testing failed! Time %t ", $time) ;
4458
        $display("Master Data Parity Error bit was set for no reason!") ;
4459
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4460
        ok = 0 ;
4461
    end
4462
 
4463
    if ( ok )
4464
        test_ok ;
4465
 
4466
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4467
 
4468
    read_data = 0 ;
4469
    read_data`READ_ADDRESS  = target_address ;
4470
    read_data`READ_SEL      = 4'hF ;
4471
    read_data`READ_TAG_STIM = 0 ;
4472
 
4473
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4474
 
4475
    // enable parity and system error interrupts
4476
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4477
 
4478
    // enable parity error response
4479
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4480
 
4481
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4482
 
4483
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4484
    fork
4485
    begin
4486
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4487
    end
4488
    begin:wait_perr4
4489
        perr_asserted = 0 ;
4490
        @(posedge pci_clock) ;
4491 35 mihad
        while ( PERR !== 0 )
4492 15 mihad
            @(posedge pci_clock) ;
4493
 
4494 35 mihad
        perr_asserted = 1 ;
4495 15 mihad
 
4496
    end
4497
    begin
4498
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4499
 
4500
        if ( ok !== 1 )
4501
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4502
 
4503
        repeat(2)
4504
            @(posedge pci_clock) ;
4505
 
4506 35 mihad
        #1 ;
4507
        if ( !perr_asserted )
4508
            disable wait_perr4 ;
4509 15 mihad
    end
4510
    join
4511
 
4512
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4513
    begin
4514
        $display("Parity checker testing failed! Time %t ", $time) ;
4515
        $display("Bridge failed to process single memory read!") ;
4516
        test_fail("bridge didn't process single memory read correctly") ;
4517
        ok = 0 ;
4518
    end
4519
 
4520
    if ( perr_asserted && ok )
4521
    begin
4522
        test_ok ;
4523
    end
4524
    else
4525
    if ( ~perr_asserted )
4526
    begin
4527
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4528
        disable main ;
4529
    end
4530
 
4531
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4532
    // interrupt should also be present
4533
    `ifdef HOST
4534
        repeat(4)
4535 26 mihad
            @(posedge pci_clock) ;
4536
        repeat(4)
4537 15 mihad
            @(posedge wb_clock) ;
4538
 
4539
        if ( INT_O !== 1 )
4540
        begin
4541
            $display("Parity checker testing failed! Time %t ", $time) ;
4542
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4543
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4544
        end
4545
        else
4546
            test_ok ;
4547
    `else
4548
    `ifdef GUEST
4549 26 mihad
        repeat(4)
4550
            @(posedge wb_clock) ;
4551
        repeat(4)
4552 15 mihad
            @(posedge pci_clock) ;
4553
 
4554
        if ( INTA !== 1 )
4555
        begin
4556
            $display("Parity checker testing failed! Time %t ", $time) ;
4557
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4558
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4559
        end
4560
        else
4561
            test_ok ;
4562
    `endif
4563
    `endif
4564
 
4565
    // check statuses!
4566
 
4567
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4568
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4569
    ok = 1 ;
4570
 
4571
    if ( temp_val1[31] !== 1 )
4572
    begin
4573
        $display("Parity checker testing failed! Time %t ", $time) ;
4574 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4575
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4576 15 mihad
        ok = 0 ;
4577
    end
4578
 
4579
    if ( temp_val1[30] !== 0 )
4580
    begin
4581
        $display("Parity checker testing failed! Time %t ", $time) ;
4582
        $display("Signalled System Error bit was set for no reason!") ;
4583
        test_fail("Signalled System Error bit was set for no reason") ;
4584
        ok = 0 ;
4585
    end
4586
 
4587
    if ( temp_val1[24] !== 1 )
4588
    begin
4589
        $display("Parity checker testing failed! Time %t ", $time) ;
4590 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4591
        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") ;
4592 15 mihad
        ok = 0 ;
4593
    end
4594
 
4595
    if ( ok )
4596
        test_ok ;
4597
 
4598
    // clear statuses and disable parity error response
4599
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4600
 
4601
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4602
    ok = 1 ;
4603
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4604
 
4605
    if ( temp_val1[4] !== 0 )
4606
    begin
4607
        $display("Parity checker testing failed! Time %t ", $time) ;
4608
        $display("System error interrupt status bit set for no reason!") ;
4609
        test_fail("System error interrupt status bit set for no reason") ;
4610
        ok = 0 ;
4611
    end
4612
 
4613
    `ifdef HOST
4614
    if ( temp_val1[3] !== 1 )
4615
    begin
4616
        $display("Parity checker testing failed! Time %t ", $time) ;
4617
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4618
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4619
        ok = 0 ;
4620
    end
4621
    `else
4622
    if ( temp_val1[3] !== 0 )
4623
    begin
4624
        $display("Parity checker testing failed! Time %t ", $time) ;
4625
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4626
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4627
        ok = 0 ;
4628
    end
4629
    `endif
4630
 
4631
    if ( ok )
4632
        test_ok ;
4633
 
4634
    // clear int statuses
4635
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4636
 
4637
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4638
 
4639
    `ifdef HOST
4640
        repeat(4)
4641 26 mihad
            @(posedge pci_clock) ;
4642
        repeat(4)
4643 15 mihad
            @(posedge wb_clock) ;
4644
 
4645
        if ( INT_O !== 0 )
4646
        begin
4647
            $display("Parity checker testing failed! Time %t ", $time) ;
4648
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4649
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4650
        end
4651
        else
4652
            test_ok ;
4653
    `else
4654
    `ifdef GUEST
4655 26 mihad
        repeat(4)
4656
            @(posedge wb_clock) ;
4657
        repeat(4)
4658 15 mihad
            @(posedge pci_clock) ;
4659
 
4660
        if ( INTA !== 1 )
4661
        begin
4662
            $display("Parity checker testing failed! Time %t ", $time) ;
4663
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4664
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4665
        end
4666
        else
4667
            test_ok ;
4668
    `endif
4669
    `endif
4670
 
4671
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4672
 
4673
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4674
    fork
4675
    begin
4676
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4677
    end
4678
    begin:wait_perr5
4679
        perr_asserted = 0 ;
4680
        @(posedge pci_clock) ;
4681
        while ( PERR === 1 )
4682
            @(posedge pci_clock) ;
4683
 
4684
        perr_asserted = 1 ;
4685
        $display("Parity checker testing failed! Time %t ", $time) ;
4686 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4687
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4688 15 mihad
    end
4689
    begin
4690
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4691
        if ( ok !== 1 )
4692
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4693
 
4694
        // perr can be asserted on idle or next PCI address phase
4695
        repeat(2)
4696
            @(posedge pci_clock) ;
4697
 
4698 35 mihad
        #1 ;
4699
        if ( !perr_asserted )
4700
            disable wait_perr5 ;
4701 15 mihad
    end
4702
    join
4703
 
4704
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4705
    begin
4706
        $display("Parity checker testing failed! Time %t ", $time) ;
4707
        $display("Bridge failed to process single memory read!") ;
4708
        test_fail("bridge failed to process single memory read correctly") ;
4709
        ok = 0 ;
4710
    end
4711
 
4712
    if ( ok && !perr_asserted)
4713
        test_ok ;
4714
 
4715
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4716
 
4717
    // interrupts should not be present
4718
    `ifdef HOST
4719
        repeat( 4 )
4720 26 mihad
            @(posedge pci_clock) ;
4721
        repeat( 4 )
4722 15 mihad
            @(posedge wb_clock) ;
4723
        if ( INT_O !== 0 )
4724
        begin
4725
            $display("Parity checker testing failed! Time %t ", $time) ;
4726
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4727
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4728
        end
4729
        else
4730
            test_ok ;
4731
    `else
4732
    `ifdef GUEST
4733
        repeat( 4 )
4734 26 mihad
            @(posedge wb_clock) ;
4735
        repeat( 4 )
4736 15 mihad
            @(posedge pci_clock) ;
4737
        if ( INTA !== 1 )
4738
        begin
4739
            $display("Parity checker testing failed! Time %t ", $time) ;
4740
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4741
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4742
        end
4743
        else
4744
            test_ok ;
4745
    `endif
4746
    `endif
4747
 
4748
    // check statuses!
4749
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4750
    ok = 1 ;
4751
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4752
    if ( temp_val1[31] !== 1 )
4753
    begin
4754
        $display("Parity checker testing failed! Time %t ", $time) ;
4755 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4756 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4757
        ok = 0 ;
4758
    end
4759
 
4760
    if ( temp_val1[30] !== 0 )
4761
    begin
4762
        $display("Parity checker testing failed! Time %t ", $time) ;
4763
        $display("Signalled System Error bit was set for no reason!") ;
4764
        test_fail("Signalled System Error bit was set for no reason") ;
4765
        ok = 0 ;
4766
    end
4767
 
4768
    if ( temp_val1[24] !== 0 )
4769
    begin
4770
        $display("Parity checker testing failed! Time %t ", $time) ;
4771 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4772 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4773
        ok = 0 ;
4774
    end
4775
 
4776
    if ( ok )
4777
        test_ok ;
4778
 
4779
    // clear statuses
4780
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4781
 
4782
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4783
    ok = 1 ;
4784
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4785
 
4786
    if ( temp_val1[4] !== 0 )
4787
    begin
4788
        $display("Parity checker testing failed! Time %t ", $time) ;
4789
        $display("System error interrupt status bit set for no reason!") ;
4790
        test_fail("System error interrupt status bit set for no reason") ;
4791
        ok = 0 ;
4792
    end
4793
 
4794
    if ( temp_val1[3] !== 0 )
4795
    begin
4796
        $display("Parity checker testing failed! Time %t ", $time) ;
4797
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4798
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4799
        ok = 0 ;
4800
    end
4801
 
4802
    if ( ok )
4803
        test_ok ;
4804
 
4805
    // enable all responses to parity errors!
4806
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4807
 
4808
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4809
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4810
 
4811
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4812
 
4813
    // repeat a read
4814
    fork
4815
    begin
4816
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4817
    end
4818
    begin:wait_perr6
4819
        perr_asserted = 0 ;
4820
        @(posedge pci_clock) ;
4821
        while ( PERR === 1 )
4822
            @(posedge pci_clock) ;
4823
 
4824
        perr_asserted = 1 ;
4825
        $display("Parity checker testing failed! Time %t ", $time) ;
4826
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4827
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4828
    end
4829
    begin
4830
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4831
        if ( ok !== 1 )
4832
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4833
 
4834
        repeat(2)
4835
            @(posedge pci_clock) ;
4836
 
4837 35 mihad
        #1 ;
4838
        if ( !perr_asserted )
4839
            disable wait_perr6 ;
4840 15 mihad
    end
4841
    join
4842
 
4843
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4844
    begin
4845
        $display("Parity checker testing failed! Time %t ", $time) ;
4846
        $display("Bridge failed to process single memory read!") ;
4847
        test_fail("bridge didn't process single memory read as expected") ;
4848
        ok = 0 ;
4849
    end
4850
 
4851
    if ( ok && !perr_asserted)
4852
        test_ok ;
4853
 
4854
    // check statuses!
4855
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4856
    ok = 1 ;
4857
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4858
    if ( temp_val1[31] !== 0 )
4859
    begin
4860
        $display("Parity checker testing failed! Time %t ", $time) ;
4861
        $display("Detected Parity Error bit was set for no reason!") ;
4862
        test_fail("Detected Parity Error bit was set for no reason") ;
4863
        ok = 0 ;
4864
    end
4865
 
4866
    if ( temp_val1[30] !== 0 )
4867
    begin
4868
        $display("Parity checker testing failed! Time %t ", $time) ;
4869
        $display("Signalled System Error bit was set for no reason!") ;
4870
        test_fail("Signalled System Error bit was set for no reason") ;
4871
        ok = 0 ;
4872
    end
4873
 
4874
    if ( temp_val1[24] !== 0 )
4875
    begin
4876
        $display("Parity checker testing failed! Time %t ", $time) ;
4877
        $display("Master Data Parity Error bit was set for no reason!") ;
4878
        test_fail("Master Data Parity Error bit was set for no reason") ;
4879
        ok = 0 ;
4880
    end
4881
 
4882
    if ( ok )
4883
        test_ok ;
4884
 
4885
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4886
    ok = 1 ;
4887
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4888
 
4889
    if ( temp_val1[4] !== 0 )
4890
    begin
4891
        $display("Parity checker testing failed! Time %t ", $time) ;
4892
        $display("System error interrupt status bit set for no reason!") ;
4893
        test_fail("System error interrupt status bit set for no reason") ;
4894
        ok = 0 ;
4895
    end
4896
 
4897
    if ( temp_val1[3] !== 0 )
4898
    begin
4899
        $display("Parity checker testing failed! Time %t ", $time) ;
4900
        $display("Parity error interrupt status bit set for no reason!") ;
4901
        test_fail("Parity error interrupt status bit set for no reason") ;
4902
        ok = 0 ;
4903
    end
4904
 
4905
    if ( ok )
4906
        test_ok ;
4907
 
4908
    $display("Presenting address parity error on PCI bus!") ;
4909
    // enable parity errors - this should not affect system errors
4910
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4911
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4912
 
4913
    // perform PCI write
4914
    // check transaction progress
4915
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4916
    fork
4917
    begin
4918
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4919
               target_address, 32'h1234_5678,
4920
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4921
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4922
        do_pause( 1 ) ;
4923
    end
4924
    begin:wait_serr7
4925
        perr_asserted = 0 ;
4926
        @(posedge pci_clock) ;
4927
        while( SERR === 1 )
4928
            @(posedge pci_clock) ;
4929
 
4930
        perr_asserted = 1 ;
4931
        $display("Parity checker testing failed! Time %t ", $time) ;
4932
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4933
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4934
    end
4935
    begin
4936
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4937
        if ( ok !== 1 )
4938
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4939
 
4940 35 mihad
        if ( !perr_asserted )
4941
            disable wait_serr7 ;
4942 15 mihad
    end
4943
    join
4944
 
4945
    if ( ok && !perr_asserted)
4946
        test_ok ;
4947
 
4948
    // check statuses!
4949
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4950
    ok = 1 ;
4951
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4952
    if ( temp_val1[31] !== 1 )
4953
    begin
4954
        $display("Parity checker testing failed! Time %t ", $time) ;
4955
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4956
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4957
        ok = 0 ;
4958
    end
4959
 
4960
    if ( temp_val1[30] !== 0 )
4961
    begin
4962
        $display("Parity checker testing failed! Time %t ", $time) ;
4963
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4964
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4965
        ok = 0 ;
4966
    end
4967
 
4968
    if ( temp_val1[24] !== 0 )
4969
    begin
4970
        $display("Parity checker testing failed! Time %t ", $time) ;
4971
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4972
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4973
        ok = 0 ;
4974
    end
4975
 
4976
    if ( ok )
4977
        test_ok ;
4978
 
4979
    // clear statuses
4980
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4981
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4982
    fork
4983
    begin
4984 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
4985 15 mihad
        (
4986
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4987
            32'h5555_5555,      // second part of address in dual address cycle
4988
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4989
            `BC_MEM_WRITE,      // normal command
4990
            4'h0,               // byte enables
4991
            32'h1234_5678,      // data
4992
            1'b1,               // make address parity error on first phase of dual address
4993
            1'b0,               // make address parity error on second phase of dual address
4994
            ok                  // result of operation
4995
        ) ;
4996 35 mihad
        if ( !perr_asserted )
4997
            disable wait_serr8 ;
4998 15 mihad
    end
4999
    begin:wait_serr8
5000
        perr_asserted = 0 ;
5001
        @(posedge pci_clock) ;
5002
        while( SERR === 1 )
5003
            @(posedge pci_clock) ;
5004
 
5005
        perr_asserted = 1 ;
5006
        $display("Parity checker testing failed! Time %t ", $time) ;
5007
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5008
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5009
    end
5010
    join
5011
 
5012
    if ( ok && !perr_asserted)
5013
        test_ok ;
5014
 
5015
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5016
    fork
5017
    begin
5018 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5019 15 mihad
        (
5020
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5021
            32'h5555_5555,      // second part of address in dual address cycle
5022
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5023
            `BC_MEM_WRITE,      // normal command
5024
            4'h0,               // byte enables
5025
            32'h1234_5678,      // data
5026
            1'b0,               // make address parity error on first phase of dual address
5027
            1'b1,               // make address parity error on second phase of dual address
5028
            ok                  // result of operation
5029
        ) ;
5030 35 mihad
        if ( !perr_asserted )
5031
            disable wait_serr9 ;
5032 15 mihad
    end
5033
    begin:wait_serr9
5034
        perr_asserted = 0 ;
5035
        @(posedge pci_clock) ;
5036
        while( SERR === 1 )
5037
            @(posedge pci_clock) ;
5038
 
5039
        perr_asserted = 1 ;
5040
        $display("Parity checker testing failed! Time %t ", $time) ;
5041
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5042
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5043
    end
5044
    join
5045
 
5046
    if ( ok && !perr_asserted)
5047
        test_ok ;
5048
 
5049
    // check statuses!
5050
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5051
    ok = 1 ;
5052
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5053
    if ( temp_val1[31] !== 1 )
5054
    begin
5055
        $display("Parity checker testing failed! Time %t ", $time) ;
5056
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5057
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5058
        ok = 0 ;
5059
    end
5060
 
5061
    if ( temp_val1[30] !== 0 )
5062
    begin
5063
        $display("Parity checker testing failed! Time %t ", $time) ;
5064
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5065
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5066
        ok = 0 ;
5067
    end
5068
 
5069
    if ( temp_val1[24] !== 0 )
5070
    begin
5071
        $display("Parity checker testing failed! Time %t ", $time) ;
5072
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5073
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5074
        ok = 0 ;
5075
    end
5076
 
5077
    if ( ok )
5078
        test_ok ;
5079
 
5080
    // clear statuses
5081
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5082
 
5083
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5084
    fork
5085
    begin
5086 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5087 15 mihad
        (
5088
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5089
            32'h5555_5555,      // second part of address in dual address cycle
5090
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5091
            `BC_MEM_WRITE,      // normal command
5092
            4'h0,               // byte enables
5093
            32'h1234_5678,      // data
5094
            1'b1,               // make address parity error on first phase of dual address
5095
            1'b1,               // make address parity error on second phase of dual address
5096
            ok                  // result of operation
5097
        ) ;
5098 35 mihad
        if ( !perr_asserted )
5099
            disable wait_serr10 ;
5100 15 mihad
    end
5101
    begin:wait_serr10
5102
        perr_asserted = 0 ;
5103
        @(posedge pci_clock) ;
5104
        while( SERR === 1 )
5105
            @(posedge pci_clock) ;
5106
 
5107
        perr_asserted = 1 ;
5108
        $display("Parity checker testing failed! Time %t ", $time) ;
5109
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5110
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5111
    end
5112
    join
5113
 
5114
    if ( ok && !perr_asserted)
5115
        test_ok ;
5116
 
5117
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5118
 
5119
    `ifdef HOST
5120
        repeat(4)
5121 26 mihad
            @(posedge pci_clock) ;
5122
        repeat(4)
5123 15 mihad
            @(posedge wb_clock) ;
5124
        if ( INT_O !== 0 )
5125
        begin
5126
            $display("Parity checker testing failed! Time %t ", $time) ;
5127
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5128
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5129
        end
5130
        else
5131
            test_ok ;
5132
    `else
5133
    `ifdef GUEST
5134 26 mihad
        repeat(4)
5135
            @(posedge wb_clock) ;
5136
        repeat(4)
5137 15 mihad
            @(posedge pci_clock) ;
5138
 
5139
        if ( INTA !== 1 )
5140
        begin
5141
            $display("Parity checker testing failed! Time %t ", $time) ;
5142
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5143
            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") ;
5144
        end
5145
        else
5146
            test_ok ;
5147
    `endif
5148
    `endif
5149
 
5150
    // check statuses!
5151
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5152
    ok = 1 ;
5153
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5154
    if ( temp_val1[31] !== 1 )
5155
    begin
5156
        $display("Parity checker testing failed! Time %t ", $time) ;
5157
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5158
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5159
        ok = 0 ;
5160
    end
5161
 
5162
    if ( temp_val1[30] !== 0 )
5163
    begin
5164
        $display("Parity checker testing failed! Time %t ", $time) ;
5165
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5166
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5167
        ok = 0 ;
5168
    end
5169
 
5170
    if ( temp_val1[24] !== 0 )
5171
    begin
5172
        $display("Parity checker testing failed! Time %t ", $time) ;
5173
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5174
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5175
        ok = 0 ;
5176
    end
5177
 
5178
    if ( ok )
5179
        test_ok ;
5180
 
5181
    // clear statuses
5182
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5183
 
5184
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5185
    ok = 1 ;
5186
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5187
 
5188
    if ( temp_val1[4] !== 0 )
5189
    begin
5190
        $display("Parity checker testing failed! Time %t ", $time) ;
5191
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5192
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5193
        ok = 0 ;
5194
    end
5195
 
5196
    if ( temp_val1[3] !== 0 )
5197
    begin
5198
        $display("Parity checker testing failed! Time %t ", $time) ;
5199
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5200
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5201
        ok = 0 ;
5202
    end
5203
 
5204
    if ( ok )
5205
        test_ok ;
5206
 
5207
    // now enable system error signaling and test response
5208
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5209
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5210
 
5211
    fork
5212
    begin
5213
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5214
               target_address, 32'h1234_5678,
5215
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5216
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5217
        do_pause( 1 ) ;
5218
    end
5219
    begin:wait_serr11
5220
        perr_asserted = 0 ;
5221
        @(posedge pci_clock) ;
5222 35 mihad
        while( SERR !== 0 )
5223 15 mihad
            @(posedge pci_clock) ;
5224
 
5225 35 mihad
        perr_asserted = 1 ;
5226 15 mihad
    end
5227
    begin
5228
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5229
        if ( ok !== 1 )
5230
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5231
 
5232
        @(posedge pci_clock) ;
5233 35 mihad
        #1 ;
5234
        if ( !perr_asserted )
5235
            disable wait_serr11 ;
5236 15 mihad
    end
5237
    join
5238
 
5239
    if ( ok && perr_asserted)
5240
        test_ok ;
5241
    else
5242
    if ( !perr_asserted )
5243
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5244
 
5245
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5246
 
5247
    `ifdef HOST
5248
        repeat(4)
5249 26 mihad
            @(posedge pci_clock) ;
5250
        repeat(4)
5251 15 mihad
            @(posedge wb_clock) ;
5252
        if ( INT_O !== 1 )
5253
        begin
5254
            $display("Parity checker testing failed! Time %t ", $time) ;
5255
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5256
            test_fail("Interrupt Request was not triggered as expected") ;
5257
        end
5258
        else
5259
            test_ok ;
5260
    `else
5261
    `ifdef GUEST
5262 26 mihad
        repeat(4)
5263
            @(posedge wb_clock) ;
5264
        repeat(4)
5265 15 mihad
            @(posedge pci_clock) ;
5266
 
5267
        if ( INTA !== 1 )
5268
        begin
5269
            $display("Parity checker testing failed! Time %t ", $time) ;
5270
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5271
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5272
        end
5273
        else
5274
            test_ok ;
5275
    `endif
5276
    `endif
5277
 
5278
    // check statuses!
5279
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5280
    ok = 1 ;
5281
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5282
    if ( temp_val1[31] !== 1 )
5283
    begin
5284
        $display("Parity checker testing failed! Time %t ", $time) ;
5285
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5286
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5287
        ok = 0 ;
5288
    end
5289
 
5290
    if ( temp_val1[30] !== 1 )
5291
    begin
5292
        $display("Parity checker testing failed! Time %t ", $time) ;
5293
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5294
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5295
        ok = 0 ;
5296
    end
5297
 
5298
    if ( temp_val1[24] !== 0 )
5299
    begin
5300
        $display("Parity checker testing failed! Time %t ", $time) ;
5301
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5302
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5303
        ok = 0 ;
5304
    end
5305
 
5306
    if ( ok )
5307
        test_ok ;
5308
 
5309
    // clear statuses
5310
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5311
 
5312
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5313
 
5314
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5315
    ok = 1 ;
5316
 
5317
    `ifdef HOST
5318
    if ( temp_val1[4] !== 1 )
5319
    begin
5320
        $display("Parity checker testing failed! Time %t ", $time) ;
5321
        $display("System error interrupt status bit not set when expected!") ;
5322
        test_fail("System error interrupt status bit not set when expected") ;
5323
        ok = 0 ;
5324
    end
5325
    `else
5326
    if ( temp_val1[4] !== 0 )
5327
    begin
5328
        $display("Parity checker testing failed! Time %t ", $time) ;
5329
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5330
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5331
        ok = 0 ;
5332
    end
5333
    `endif
5334
 
5335
    if ( temp_val1[3] !== 0 )
5336
    begin
5337
        $display("Parity checker testing failed! Time %t ", $time) ;
5338
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5339
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5340
        ok = 0 ;
5341
    end
5342
 
5343
    if ( ok )
5344
        test_ok ;
5345
 
5346
    // clear statuses
5347
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5348
 
5349
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5350
    fork
5351
    begin
5352 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5353 15 mihad
        (
5354
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5355
            32'h5555_5555,      // second part of address in dual address cycle
5356
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5357
            `BC_MEM_WRITE,      // normal command
5358
            4'h0,               // byte enables
5359
            32'h1234_5678,      // data
5360
            1'b1,               // make address parity error on first phase of dual address
5361
            1'b0,               // make address parity error on second phase of dual address
5362
            ok                  // result of operation
5363
        ) ;
5364 35 mihad
        if ( !perr_asserted )
5365
            disable wait_serr14 ;
5366 15 mihad
    end
5367
    begin:wait_serr14
5368
        perr_asserted = 0 ;
5369
        @(posedge pci_clock) ;
5370 35 mihad
        while( SERR !== 0 )
5371 15 mihad
            @(posedge pci_clock) ;
5372
 
5373 35 mihad
        perr_asserted = 1 ;
5374 15 mihad
    end
5375
    join
5376
 
5377
    if ( ok && perr_asserted)
5378
        test_ok ;
5379
    else
5380
    if ( !perr_asserted )
5381
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5382
 
5383
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5384
 
5385
    `ifdef HOST
5386
        repeat(4)
5387 26 mihad
            @(posedge pci_clock) ;
5388
        repeat(4)
5389 15 mihad
            @(posedge wb_clock) ;
5390
        if ( INT_O !== 1 )
5391
        begin
5392
            $display("Parity checker testing failed! Time %t ", $time) ;
5393
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5394
            test_fail("Interrupt Request was not triggered as expected") ;
5395
        end
5396
        else
5397
            test_ok ;
5398
    `else
5399
    `ifdef GUEST
5400 26 mihad
        repeat(4)
5401
            @(posedge wb_clock) ;
5402
        repeat(4)
5403 15 mihad
            @(posedge pci_clock) ;
5404
 
5405
        if ( INTA !== 1 )
5406
        begin
5407
            $display("Parity checker testing failed! Time %t ", $time) ;
5408
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5409
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5410
        end
5411
        else
5412
            test_ok ;
5413
    `endif
5414
    `endif
5415
 
5416
    // check statuses!
5417
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5418
    ok = 1 ;
5419
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5420
    if ( temp_val1[31] !== 1 )
5421
    begin
5422
        $display("Parity checker testing failed! Time %t ", $time) ;
5423
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5424
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5425
        ok = 0 ;
5426
    end
5427
 
5428
    if ( temp_val1[30] !== 1 )
5429
    begin
5430
        $display("Parity checker testing failed! Time %t ", $time) ;
5431
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5432
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5433
        ok = 0 ;
5434
    end
5435
 
5436
    if ( temp_val1[24] !== 0 )
5437
    begin
5438
        $display("Parity checker testing failed! Time %t ", $time) ;
5439
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5440
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5441
        ok = 0 ;
5442
    end
5443
 
5444
    if ( ok )
5445
        test_ok ;
5446
 
5447
    // clear statuses
5448
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5449
 
5450
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5451
 
5452
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5453
    ok = 1 ;
5454
 
5455
    `ifdef HOST
5456
    if ( temp_val1[4] !== 1 )
5457
    begin
5458
        $display("Parity checker testing failed! Time %t ", $time) ;
5459
        $display("System error interrupt status bit not set when expected!") ;
5460
        test_fail("System error interrupt status bit not set when expected") ;
5461
        ok = 0 ;
5462
    end
5463
    `else
5464
    if ( temp_val1[4] !== 0 )
5465
    begin
5466
        $display("Parity checker testing failed! Time %t ", $time) ;
5467
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5468
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5469
        ok = 0 ;
5470
    end
5471
    `endif
5472
 
5473
    if ( temp_val1[3] !== 0 )
5474
    begin
5475
        $display("Parity checker testing failed! Time %t ", $time) ;
5476
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5477
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5478
        ok = 0 ;
5479
    end
5480
 
5481
    if ( ok )
5482
        test_ok ;
5483
 
5484
    // clear statuses
5485
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5486
 
5487
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5488
    fork
5489
    begin
5490 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5491 15 mihad
        (
5492
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5493
            32'h5555_5555,      // second part of address in dual address cycle
5494
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5495
            `BC_MEM_WRITE,      // normal command
5496
            4'h0,               // byte enables
5497
            32'h1234_5678,      // data
5498
            1'b0,               // make address parity error on first phase of dual address
5499
            1'b1,               // make address parity error on second phase of dual address
5500
            ok                  // result of operation
5501
        ) ;
5502 35 mihad
        if ( !perr_asserted )
5503
            disable wait_serr15 ;
5504 15 mihad
    end
5505
    begin:wait_serr15
5506
        perr_asserted = 0 ;
5507
        @(posedge pci_clock) ;
5508 35 mihad
        while( SERR !== 0 )
5509 15 mihad
            @(posedge pci_clock) ;
5510
 
5511 35 mihad
        perr_asserted = 1 ;
5512 15 mihad
    end
5513
    join
5514
 
5515
    if ( ok && perr_asserted)
5516
        test_ok ;
5517
    else
5518
    if ( !perr_asserted )
5519
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5520
 
5521
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5522
 
5523
    `ifdef HOST
5524
        repeat(4)
5525 26 mihad
            @(posedge pci_clock) ;
5526
        repeat(4)
5527 15 mihad
            @(posedge wb_clock) ;
5528
        if ( INT_O !== 1 )
5529
        begin
5530
            $display("Parity checker testing failed! Time %t ", $time) ;
5531
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5532
            test_fail("Interrupt Request was not triggered as expected") ;
5533
        end
5534
        else
5535
            test_ok ;
5536
    `else
5537
    `ifdef GUEST
5538 26 mihad
        repeat(4)
5539
            @(posedge wb_clock) ;
5540
        repeat(4)
5541 15 mihad
            @(posedge pci_clock) ;
5542
 
5543
        if ( INTA !== 1 )
5544
        begin
5545
            $display("Parity checker testing failed! Time %t ", $time) ;
5546
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5547
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5548
        end
5549
        else
5550
            test_ok ;
5551
    `endif
5552
    `endif
5553
 
5554
    // check statuses!
5555
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5556
    ok = 1 ;
5557
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5558
    if ( temp_val1[31] !== 1 )
5559
    begin
5560
        $display("Parity checker testing failed! Time %t ", $time) ;
5561
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5562
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5563
        ok = 0 ;
5564
    end
5565
 
5566
    if ( temp_val1[30] !== 1 )
5567
    begin
5568
        $display("Parity checker testing failed! Time %t ", $time) ;
5569
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5570
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5571
        ok = 0 ;
5572
    end
5573
 
5574
    if ( temp_val1[24] !== 0 )
5575
    begin
5576
        $display("Parity checker testing failed! Time %t ", $time) ;
5577
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5578
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5579
        ok = 0 ;
5580
    end
5581
 
5582
    if ( ok )
5583
        test_ok ;
5584
 
5585
    // clear statuses
5586
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5587
 
5588
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5589
 
5590
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5591
    ok = 1 ;
5592
 
5593
    `ifdef HOST
5594
    if ( temp_val1[4] !== 1 )
5595
    begin
5596
        $display("Parity checker testing failed! Time %t ", $time) ;
5597
        $display("System error interrupt status bit not set when expected!") ;
5598
        test_fail("System error interrupt status bit not set when expected") ;
5599
        ok = 0 ;
5600
    end
5601
    `else
5602
    if ( temp_val1[4] !== 0 )
5603
    begin
5604
        $display("Parity checker testing failed! Time %t ", $time) ;
5605
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5606
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5607
        ok = 0 ;
5608
    end
5609
    `endif
5610
 
5611
    if ( temp_val1[3] !== 0 )
5612
    begin
5613
        $display("Parity checker testing failed! Time %t ", $time) ;
5614
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5615
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5616
        ok = 0 ;
5617
    end
5618
 
5619
    if ( ok )
5620
        test_ok ;
5621
 
5622
    // clear statuses
5623
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5624
 
5625
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5626
    fork
5627
    begin
5628 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5629 15 mihad
        (
5630
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5631
            32'h5555_5555,      // second part of address in dual address cycle
5632
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5633
            `BC_MEM_WRITE,      // normal command
5634
            4'h0,               // byte enables
5635
            32'h1234_5678,      // data
5636
            1'b1,               // make address parity error on first phase of dual address
5637
            1'b1,               // make address parity error on second phase of dual address
5638
            ok                  // result of operation
5639
        ) ;
5640 35 mihad
        if ( !perr_asserted )
5641
            disable wait_serr16 ;
5642 15 mihad
    end
5643
    begin:wait_serr16
5644
        perr_asserted = 0 ;
5645
        @(posedge pci_clock) ;
5646 35 mihad
        while( SERR !== 0 )
5647 15 mihad
            @(posedge pci_clock) ;
5648
 
5649 35 mihad
        perr_asserted = 1 ;
5650 15 mihad
    end
5651
    join
5652
 
5653
    if ( ok && perr_asserted)
5654
        test_ok ;
5655
    else
5656
    if ( !perr_asserted )
5657
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5658
 
5659
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5660
 
5661
    `ifdef HOST
5662
        repeat(4)
5663 26 mihad
            @(posedge pci_clock) ;
5664
        repeat(4)
5665 15 mihad
            @(posedge wb_clock) ;
5666
        if ( INT_O !== 1 )
5667
        begin
5668
            $display("Parity checker testing failed! Time %t ", $time) ;
5669
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5670
            test_fail("Interrupt Request was not triggered as expected") ;
5671
        end
5672
        else
5673
            test_ok ;
5674
    `else
5675
    `ifdef GUEST
5676 26 mihad
        repeat(4)
5677
            @(posedge wb_clock) ;
5678
        repeat(4)
5679 15 mihad
            @(posedge pci_clock) ;
5680
 
5681
        if ( INTA !== 1 )
5682
        begin
5683
            $display("Parity checker testing failed! Time %t ", $time) ;
5684
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5685
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5686
        end
5687
        else
5688
            test_ok ;
5689
    `endif
5690
    `endif
5691
 
5692
    // check statuses!
5693
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5694
    ok = 1 ;
5695
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5696
    if ( temp_val1[31] !== 1 )
5697
    begin
5698
        $display("Parity checker testing failed! Time %t ", $time) ;
5699
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5700
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5701
        ok = 0 ;
5702
    end
5703
 
5704
    if ( temp_val1[30] !== 1 )
5705
    begin
5706
        $display("Parity checker testing failed! Time %t ", $time) ;
5707
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5708
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5709
        ok = 0 ;
5710
    end
5711
 
5712
    if ( temp_val1[24] !== 0 )
5713
    begin
5714
        $display("Parity checker testing failed! Time %t ", $time) ;
5715
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5716
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5717
        ok = 0 ;
5718
    end
5719
 
5720
    if ( ok )
5721
        test_ok ;
5722
 
5723
    // clear statuses
5724
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5725
 
5726
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5727
 
5728
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5729
    ok = 1 ;
5730
 
5731
    `ifdef HOST
5732
    if ( temp_val1[4] !== 1 )
5733
    begin
5734
        $display("Parity checker testing failed! Time %t ", $time) ;
5735
        $display("System error interrupt status bit not set when expected!") ;
5736
        test_fail("System error interrupt status bit not set when expected") ;
5737
        ok = 0 ;
5738
    end
5739
    `else
5740
    if ( temp_val1[4] !== 0 )
5741
    begin
5742
        $display("Parity checker testing failed! Time %t ", $time) ;
5743
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5744
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5745
        ok = 0 ;
5746
    end
5747
    `endif
5748
 
5749
    if ( temp_val1[3] !== 0 )
5750
    begin
5751
        $display("Parity checker testing failed! Time %t ", $time) ;
5752
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5753
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5754
        ok = 0 ;
5755
    end
5756
 
5757
    if ( ok )
5758
        test_ok ;
5759
 
5760
    // clear statuses
5761
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5762
 
5763
    // now just disable Parity Error response - on Address par errors nothing should happen
5764
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5765
 
5766
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5767
    fork
5768
    begin
5769
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5770
               target_address, 32'h1234_5678,
5771
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5772
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5773
        do_pause( 1 ) ;
5774
    end
5775
    begin:wait_serr12
5776
        perr_asserted = 0 ;
5777
        @(posedge pci_clock) ;
5778
        while( SERR === 1 )
5779
            @(posedge pci_clock) ;
5780
 
5781
        perr_asserted = 1 ;
5782
        $display("Parity checker testing failed! Time %t ", $time) ;
5783
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5784
        test_fail("SERR asserted when parity error response was disabled") ;
5785
    end
5786
    begin
5787
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5788
        if ( ok !== 1 )
5789
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5790
 
5791 35 mihad
        @(posedge pci_clock) ;
5792
        #1 ;
5793
        if ( !perr_asserted )
5794
            disable wait_serr12 ;
5795 15 mihad
    end
5796
    join
5797
 
5798
    if ( ok && !perr_asserted )
5799
        test_ok ;
5800
 
5801
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5802
    `ifdef HOST
5803 26 mihad
        repeat (4)
5804
            @(posedge pci_clock) ;
5805 15 mihad
        repeat(4)
5806
            @(posedge wb_clock) ;
5807
        if ( INT_O !== 0 )
5808
        begin
5809
            $display("Parity checker testing failed! Time %t ", $time) ;
5810
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5811
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5812
        end
5813
        else
5814
            test_ok ;
5815
    `else
5816
    `ifdef GUEST
5817 26 mihad
        repeat(4)
5818
            @(posedge wb_clock) ;
5819
        repeat (4)
5820 15 mihad
            @(posedge pci_clock) ;
5821
 
5822
        if ( INTA !== 1 )
5823
        begin
5824
            $display("Parity checker testing failed! Time %t ", $time) ;
5825
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5826
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5827
        end
5828
        else
5829
            test_ok ;
5830
    `endif
5831
    `endif
5832
 
5833
    // check statuses!
5834
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5835
    ok = 1 ;
5836
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5837
    if ( temp_val1[31] !== 1 )
5838
    begin
5839
        $display("Parity checker testing failed! Time %t ", $time) ;
5840
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5841
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5842
        ok = 0 ;
5843
    end
5844
 
5845
    if ( temp_val1[30] !== 0 )
5846
    begin
5847
        $display("Parity checker testing failed! Time %t ", $time) ;
5848
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5849
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5850
        ok = 0 ;
5851
    end
5852
 
5853
    if ( temp_val1[24] !== 0 )
5854
    begin
5855
        $display("Parity checker testing failed! Time %t ", $time) ;
5856
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5857
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5858
        ok = 0 ;
5859
    end
5860
 
5861
    if ( ok )
5862
        test_ok ;
5863
 
5864
    // clear statuses
5865
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5866
 
5867
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5868
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5869
    ok = 1 ;
5870
    if ( temp_val1[4] !== 0 )
5871
    begin
5872
        $display("Parity checker testing failed! Time %t ", $time) ;
5873
        $display("System error interrupt status bit set when not expected!") ;
5874
        test_fail("System error interrupt status bit set when not expected") ;
5875
        ok = 0 ;
5876
    end
5877
 
5878
    if ( temp_val1[3] !== 0 )
5879
    begin
5880
        $display("Parity checker testing failed! Time %t ", $time) ;
5881
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5882
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5883
        ok = 0 ;
5884
    end
5885
 
5886
    if ( ok )
5887
        test_ok ;
5888
 
5889
    // clear statuses
5890
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5891
 
5892
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5893
    fork
5894
    begin
5895 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5896 15 mihad
        (
5897
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5898
            32'h5555_5555,      // second part of address in dual address cycle
5899
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5900
            `BC_MEM_WRITE,      // normal command
5901
            4'h0,               // byte enables
5902
            32'h1234_5678,      // data
5903
            1'b1,               // make address parity error on first phase of dual address
5904
            1'b0,               // make address parity error on second phase of dual address
5905
            ok                  // result of operation
5906
        ) ;
5907 35 mihad
        if ( !perr_asserted )
5908
            disable wait_serr17 ;
5909 15 mihad
    end
5910
    begin:wait_serr17
5911
        perr_asserted = 0 ;
5912
        @(posedge pci_clock) ;
5913
        while( SERR === 1 )
5914
            @(posedge pci_clock) ;
5915
 
5916
        perr_asserted = 1 ;
5917
        $display("Parity checker testing failed! Time %t ", $time) ;
5918
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5919
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5920
    end
5921
    join
5922
 
5923
    if ( ok && !perr_asserted)
5924
        test_ok ;
5925
 
5926
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5927
    fork
5928
    begin
5929 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5930 15 mihad
        (
5931
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5932
            32'h5555_5555,      // second part of address in dual address cycle
5933
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5934
            `BC_MEM_WRITE,      // normal command
5935
            4'h0,               // byte enables
5936
            32'h1234_5678,      // data
5937
            1'b0,               // make address parity error on first phase of dual address
5938
            1'b1,               // make address parity error on second phase of dual address
5939
            ok                  // result of operation
5940
        ) ;
5941 35 mihad
        if ( !perr_asserted )
5942
            disable wait_serr18 ;
5943 15 mihad
    end
5944
    begin:wait_serr18
5945
        perr_asserted = 0 ;
5946
        @(posedge pci_clock) ;
5947
        while( SERR === 1 )
5948
            @(posedge pci_clock) ;
5949
 
5950
        perr_asserted = 1 ;
5951
        $display("Parity checker testing failed! Time %t ", $time) ;
5952
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5953
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5954
    end
5955
    join
5956
 
5957
    if ( ok && !perr_asserted)
5958
        test_ok ;
5959
 
5960
    // check statuses!
5961
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5962
    ok = 1 ;
5963
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5964
    if ( temp_val1[31] !== 1 )
5965
    begin
5966
        $display("Parity checker testing failed! Time %t ", $time) ;
5967
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5968
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5969
        ok = 0 ;
5970
    end
5971
 
5972
    if ( temp_val1[30] !== 0 )
5973
    begin
5974
        $display("Parity checker testing failed! Time %t ", $time) ;
5975
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5976
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5977
        ok = 0 ;
5978
    end
5979
 
5980
    if ( temp_val1[24] !== 0 )
5981
    begin
5982
        $display("Parity checker testing failed! Time %t ", $time) ;
5983
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5984
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5985
        ok = 0 ;
5986
    end
5987
 
5988
    if ( ok )
5989
        test_ok ;
5990
 
5991
    // clear statuses
5992
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5993
 
5994
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5995
    fork
5996
    begin
5997 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5998 15 mihad
        (
5999
            32'hAAAA_AAAA,      // first part of address in dual address cycle
6000
            32'h5555_5555,      // second part of address in dual address cycle
6001
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
6002
            `BC_MEM_WRITE,      // normal command
6003
            4'h0,               // byte enables
6004
            32'h1234_5678,      // data
6005
            1'b1,               // make address parity error on first phase of dual address
6006
            1'b1,               // make address parity error on second phase of dual address
6007
            ok                  // result of operation
6008
        ) ;
6009 35 mihad
        if ( !perr_asserted )
6010
            disable wait_serr19 ;
6011 15 mihad
    end
6012
    begin:wait_serr19
6013
        perr_asserted = 0 ;
6014
        @(posedge pci_clock) ;
6015
        while( SERR === 1 )
6016
            @(posedge pci_clock) ;
6017
 
6018
        perr_asserted = 1 ;
6019
        $display("Parity checker testing failed! Time %t ", $time) ;
6020
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
6021
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6022
    end
6023
    join
6024
 
6025
    if ( ok && !perr_asserted)
6026
        test_ok ;
6027
 
6028
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
6029
 
6030
    `ifdef HOST
6031
        repeat(4)
6032 26 mihad
            @(posedge pci_clock) ;
6033
        repeat(4)
6034 15 mihad
            @(posedge wb_clock) ;
6035
        if ( INT_O !== 0 )
6036
        begin
6037
            $display("Parity checker testing failed! Time %t ", $time) ;
6038
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
6039
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
6040
        end
6041
        else
6042
            test_ok ;
6043
    `else
6044
    `ifdef GUEST
6045 26 mihad
        repeat(4)
6046
            @(posedge wb_clock) ;
6047
        repeat(4)
6048 15 mihad
            @(posedge pci_clock) ;
6049
 
6050
        if ( INTA !== 1 )
6051
        begin
6052
            $display("Parity checker testing failed! Time %t ", $time) ;
6053
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
6054
            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") ;
6055
        end
6056
        else
6057
            test_ok ;
6058
    `endif
6059
    `endif
6060
 
6061
    // check statuses!
6062
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6063
    ok = 1 ;
6064
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6065
    if ( temp_val1[31] !== 1 )
6066
    begin
6067
        $display("Parity checker testing failed! Time %t ", $time) ;
6068
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6069
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6070
        ok = 0 ;
6071
    end
6072
 
6073
    if ( temp_val1[30] !== 0 )
6074
    begin
6075
        $display("Parity checker testing failed! Time %t ", $time) ;
6076
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6077
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6078
        ok = 0 ;
6079
    end
6080
 
6081
    if ( temp_val1[24] !== 0 )
6082
    begin
6083
        $display("Parity checker testing failed! Time %t ", $time) ;
6084
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6085
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6086
        ok = 0 ;
6087
    end
6088
 
6089
    if ( ok )
6090
        test_ok ;
6091
 
6092
    // clear statuses
6093
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6094
 
6095
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
6096
 
6097
    // do normal write
6098
    fork
6099
    begin
6100
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
6101
               target_address, 32'h1234_5678, `Test_All_Bytes,
6102
               1, 8'h3_0, `Test_One_Zero_Target_WS,
6103
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6104
        do_pause( 1 ) ;
6105
    end
6106
    begin:wait_serr13
6107
        perr_asserted = 0 ;
6108
        @(posedge pci_clock) ;
6109
        while( SERR === 1 )
6110
            @(posedge pci_clock) ;
6111
 
6112
        perr_asserted = 1 ;
6113
        $display("Parity checker testing failed! Time %t ", $time) ;
6114
        $display("SERR asserted for no reason!") ;
6115
        test_fail("SERR was asserted for no reason") ;
6116
    end
6117
    begin
6118
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6119
        if ( ok !== 1 )
6120
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6121
 
6122 35 mihad
        @(posedge pci_clock) ;
6123
        #1 ;
6124
        if ( !perr_asserted )
6125
            disable wait_serr13 ;
6126 15 mihad
    end
6127
    join
6128
 
6129
    if ( ok && !perr_asserted )
6130
        test_ok ;
6131
 
6132
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6133
    `ifdef HOST
6134 26 mihad
        repeat( 4 )
6135
            @(posedge pci_clock) ;
6136 15 mihad
        repeat(4)
6137
            @(posedge wb_clock) ;
6138
        if ( INT_O !== 0 )
6139
        begin
6140
            $display("Parity checker testing failed! Time %t ", $time) ;
6141
            $display("Interrupt request asserted for no reason!") ;
6142
            test_fail("Interrupt request was asserted for no reason") ;
6143
        end
6144
        else
6145
            test_ok ;
6146
    `else
6147
    `ifdef GUEST
6148 26 mihad
        repeat(4)
6149
            @(posedge wb_clock) ;
6150
        repeat(4)
6151 15 mihad
            @(posedge pci_clock) ;
6152
 
6153
        if ( INTA !== 1 )
6154
        begin
6155
            $display("Parity checker testing failed! Time %t ", $time) ;
6156
            $display("Interrupt request asserted for no reason!") ;
6157
            test_fail("Interrupt request was asserted for no reason") ;
6158
        end
6159
        else
6160
            test_ok ;
6161
    `endif
6162
    `endif
6163
 
6164
    // check statuses!
6165
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6166
    ok = 1 ;
6167
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6168
    if ( temp_val1[31] !== 0 )
6169
    begin
6170
        $display("Parity checker testing failed! Time %t ", $time) ;
6171
        $display("Detected Parity Error bit was set for no reason!") ;
6172
        test_fail("Detected Parity Error bit was set for no reason") ;
6173
        ok = 0 ;
6174
    end
6175
 
6176
    if ( temp_val1[30] !== 0 )
6177
    begin
6178
        $display("Parity checker testing failed! Time %t ", $time) ;
6179
        $display("Signalled System Error bit was set for no reason!") ;
6180
        test_fail("Signalled System Error bit was set for no reason") ;
6181
        ok = 0 ;
6182
    end
6183
 
6184
    if ( temp_val1[24] !== 0 )
6185
    begin
6186
        $display("Parity checker testing failed! Time %t ", $time) ;
6187
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6188
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6189
        ok = 0 ;
6190
    end
6191
 
6192
    if ( ok )
6193
        test_ok ;
6194
 
6195
    // clear statuses
6196
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6197
 
6198
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6199
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6200
    ok = 1 ;
6201
 
6202
    if ( temp_val1[4] !== 0 )
6203
    begin
6204
        $display("Parity checker testing failed! Time %t ", $time) ;
6205
        $display("System error interrupt status bit set when not expected!") ;
6206
        test_fail("System error interrupt status bit set when not expected") ;
6207
        ok = 0 ;
6208
    end
6209
 
6210
    if ( temp_val1[3] !== 0 )
6211
    begin
6212
        $display("Parity checker testing failed! Time %t ", $time) ;
6213
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6214
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6215
        ok = 0 ;
6216
    end
6217
 
6218
    if ( ok )
6219
        test_ok ;
6220
 
6221
    // clear statuses
6222
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6223
 
6224
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6225
 
6226
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6227
 
6228
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6229
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6230
 
6231
    // setup target's image!
6232
    target_address  = Target_Base_Addr_R[1] ;
6233
 
6234
    // base address
6235
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6236
 
6237
    // address mask
6238
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6239
 
6240
    // image control
6241
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6242
 
6243
    // enable everything possible for parity checking
6244
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6245
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6246
 
6247
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6248
 
6249
    fork
6250
    begin
6251
        if ( target_mem_image === 1 )
6252
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6253
                   target_address, 32'h1234_5678,
6254
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6255
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6256
        else
6257
            PCIU_IO_WRITE_MAKE_PERR (
6258
                                    `Test_Master_1,
6259
                                    target_address,
6260
                                    32'h1234_5678,
6261
                                    4'h0,
6262
                                    1,
6263
                                    `Test_Target_Normal_Completion
6264
                                    );
6265
 
6266
        do_pause( 1 ) ;
6267
    end
6268
    begin:wait_perr11
6269
        perr_asserted = 0 ;
6270
        @(posedge pci_clock) ;
6271 35 mihad
        while ( PERR !== 0 )
6272 15 mihad
            @(posedge pci_clock) ;
6273
 
6274 35 mihad
        perr_asserted = 1 ;
6275 15 mihad
 
6276
    end
6277
    begin
6278
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6279
 
6280
        if ( ok !== 1 )
6281
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6282
 
6283
        repeat(2)
6284
            @(posedge pci_clock) ;
6285
 
6286 35 mihad
        #1 ;
6287
        if ( !perr_asserted )
6288
            disable wait_perr11 ;
6289 15 mihad
    end
6290
    join
6291
 
6292
    if ( ok && perr_asserted )
6293
        test_ok ;
6294
    else
6295
    if ( !perr_asserted )
6296
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6297
 
6298
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6299
    `ifdef HOST
6300 26 mihad
        repeat (4)
6301
            @(posedge pci_clock) ;
6302 15 mihad
        repeat(4)
6303
            @(posedge wb_clock) ;
6304
        if ( INT_O !== 0 )
6305
        begin
6306
            $display("Parity checker testing failed! Time %t ", $time) ;
6307
            $display("Interrupt request asserted for no reason!") ;
6308
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6309
        end
6310
        else
6311
            test_ok ;
6312
    `else
6313
    `ifdef GUEST
6314 26 mihad
        repeat(4)
6315
            @(posedge wb_clock) ;
6316
        repeat (4)
6317 15 mihad
            @(posedge pci_clock) ;
6318
 
6319
        if ( INTA !== 1 )
6320
        begin
6321
            $display("Parity checker testing failed! Time %t ", $time) ;
6322
            $display("Interrupt request asserted for no reason!") ;
6323
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6324
        end
6325
        else
6326
            test_ok ;
6327
 
6328
    `endif
6329
    `endif
6330
 
6331
    // check statuses!
6332
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6333
    ok = 1 ;
6334
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6335
    if ( temp_val1[31] !== 1 )
6336
    begin
6337
        $display("Parity checker testing failed! Time %t ", $time) ;
6338 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6339
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6340 15 mihad
        ok = 0 ;
6341
    end
6342
 
6343
    if ( temp_val1[30] !== 0 )
6344
    begin
6345
        $display("Parity checker testing failed! Time %t ", $time) ;
6346
        $display("Signalled System Error bit was set for no reason!") ;
6347
        test_fail("Signalled System Error bit was set for no reason") ;
6348
        ok = 0 ;
6349
    end
6350
 
6351
    if ( temp_val1[24] !== 0 )
6352
    begin
6353
        $display("Parity checker testing failed! Time %t ", $time) ;
6354
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6355
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6356
        ok = 0 ;
6357
    end
6358
 
6359
    if ( ok )
6360
        test_ok ;
6361
 
6362
    // clear statuses
6363
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6364
 
6365
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6366
 
6367
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6368
    ok = 1 ;
6369
    if ( temp_val1[4] !== 0 )
6370
    begin
6371
        $display("Parity checker testing failed! Time %t ", $time) ;
6372
        $display("System error interrupt status bit set when not expected!") ;
6373
        test_fail("System error interrupt status bit set when not expected") ;
6374
        ok = 0 ;
6375
    end
6376
 
6377
    if ( temp_val1[3] !== 0 )
6378
    begin
6379
        $display("Parity checker testing failed! Time %t ", $time) ;
6380
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6381
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6382
        ok = 0 ;
6383
    end
6384
 
6385
    if ( ok )
6386
        test_ok ;
6387
 
6388
    // clear statuses
6389
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6390
 
6391
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6392
 
6393
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6394
    fork
6395
    begin
6396
        if ( target_mem_image === 1 )
6397
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6398
                          target_address, 32'h1234_5678,
6399
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6400
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6401
        else
6402
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6403
 
6404
        do_pause( 1 ) ;
6405
    end
6406
    begin:wait_perr12
6407
        perr_asserted = 0 ;
6408
        @(posedge pci_clock) ;
6409 35 mihad
        while ( PERR !== 0 )
6410 15 mihad
            @(posedge pci_clock) ;
6411
 
6412 35 mihad
        perr_asserted = 1 ;
6413 15 mihad
    end
6414
    begin
6415
 
6416
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6417
        if ( ok !== 1 )
6418
        begin
6419
            test_fail("Bridge failed to process Target Memory read correctly") ;
6420
            disable main ;
6421
        end
6422
 
6423
        repeat(3)
6424
            @(posedge pci_clock) ;
6425
 
6426
        if ( target_mem_image === 1 )
6427
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6428
                    target_address, 32'h1234_5678,
6429
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6430
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6431
        else
6432
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6433
 
6434
        do_pause( 1 ) ;
6435
 
6436
    end
6437
    begin
6438
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6439
        if ( ok !== 1 )
6440
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6441
        else
6442
        begin
6443
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6444
            if ( ok !== 1 )
6445
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6446
        end
6447
 
6448 35 mihad
        repeat(2)
6449 15 mihad
            @(posedge pci_clock) ;
6450
 
6451 35 mihad
        #1 ;
6452
        if ( !perr_asserted )
6453
            disable wait_perr12 ;
6454 15 mihad
    end
6455
    join
6456
 
6457
    if ( ok && perr_asserted )
6458
        test_ok ;
6459
    else
6460
    if ( !perr_asserted )
6461
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6462
 
6463
 
6464
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6465
    `ifdef HOST
6466
        repeat(4)
6467 26 mihad
            @(posedge pci_clock) ;
6468
        repeat(4)
6469 15 mihad
            @(posedge wb_clock) ;
6470
        if ( INT_O !== 0 )
6471
        begin
6472
            $display("Parity checker testing failed! Time %t ", $time) ;
6473
            $display("Interrupt request asserted for no reason!") ;
6474
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6475
        end
6476
        else
6477
            test_ok ;
6478
    `else
6479
    `ifdef GUEST
6480 26 mihad
        repeat(4)
6481
            @(posedge wb_clock) ;
6482
        repeat(4)
6483 15 mihad
            @(posedge pci_clock) ;
6484
 
6485
        if ( INTA !== 1 )
6486
        begin
6487
            $display("Parity checker testing failed! Time %t ", $time) ;
6488
            $display("Interrupt request asserted for no reason!") ;
6489
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6490
        end
6491
        else
6492
            test_ok ;
6493
    `endif
6494
    `endif
6495
 
6496
    // check statuses!
6497
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6498
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6499
    ok = 1 ;
6500 45 mihad
    if ( temp_val1[31] !== 0 )
6501 15 mihad
    begin
6502
        $display("Parity checker testing failed! Time %t ", $time) ;
6503 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6504
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6505 15 mihad
        ok = 0 ;
6506
    end
6507
 
6508
    if ( temp_val1[30] !== 0 )
6509
    begin
6510
        $display("Parity checker testing failed! Time %t ", $time) ;
6511
        $display("Signalled System Error bit was set for no reason!") ;
6512
        test_fail("Signalled System Error bit was set for no reason") ;
6513
        ok = 0 ;
6514
    end
6515
 
6516
    if ( temp_val1[24] !== 0 )
6517
    begin
6518
        $display("Parity checker testing failed! Time %t ", $time) ;
6519
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6520
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6521
        ok = 0 ;
6522
    end
6523
 
6524
    if ( ok )
6525
        test_ok ;
6526
 
6527
    // clear statuses
6528
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6529
 
6530
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6531
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6532
    ok = 1 ;
6533
    if ( temp_val1[4] !== 0 )
6534
    begin
6535
        $display("Parity checker testing failed! Time %t ", $time) ;
6536
        $display("System error interrupt status bit set when not expected!") ;
6537
        test_fail("System error interrupt status bit set when not expected") ;
6538
        ok = 0 ;
6539
    end
6540
 
6541
    if ( temp_val1[3] !== 0 )
6542
    begin
6543
        $display("Parity checker testing failed! Time %t ", $time) ;
6544
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6545
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6546
        ok = 0 ;
6547
    end
6548
 
6549
    if ( ok )
6550
        test_ok ;
6551
    // clear statuses
6552
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6553
 
6554
    $fdisplay(pci_mon_log_file_desc,
6555
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6556
    test_name = "DISABLE USED IMAGES" ;
6557
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6558
    if ( ok !== 1 )
6559
    begin
6560
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6561
        test_fail("WB Image Address Mask register could not be written to") ;
6562
        disable main ;
6563
    end
6564
 
6565 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6566 15 mihad
    if ( ok !== 1 )
6567
    begin
6568
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6569
        test_fail("PCI Image Address Mask register could not be written to") ;
6570
        disable main ;
6571
    end
6572
 
6573
    // disable target's 1 response to parity errors
6574 45 mihad
    configuration_cycle_write(0,                        // bus number
6575
                              `TAR1_IDSEL_INDEX - 11,   // device number
6576
                              0,                        // function number
6577
                              1,                        // register number
6578
                              0,                        // type of configuration cycle
6579
                              4'b0001,                  // byte enables
6580
                              32'h0000_0007             // data
6581 15 mihad
                             ) ;
6582
 
6583
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6584
end
6585
endtask // parity_checking
6586
 
6587
task wb_to_pci_transactions ;
6588
    reg   [11:0] ctrl_offset ;
6589
    reg   [11:0] ba_offset ;
6590
    reg   [11:0] am_offset ;
6591
    reg   [11:0] pci_ctrl_offset ;
6592
    reg   [11:0] err_cs_offset ;
6593
    reg   [11:0] icr_offset ;
6594
    reg   [11:0] isr_offset ;
6595
    reg   [11:0] lat_tim_cls_offset ;
6596
 
6597
    reg `WRITE_STIM_TYPE  write_data ;
6598
    reg `READ_STIM_TYPE   read_data ;
6599
    reg `READ_RETURN_TYPE read_status ;
6600
 
6601
    reg `WRITE_RETURN_TYPE write_status ;
6602
    reg `WB_TRANSFER_FLAGS write_flags ;
6603
    reg [31:0] temp_val1 ;
6604
    reg [31:0] temp_val2 ;
6605
    reg        ok   ;
6606
 
6607
    reg [31:0] image_base ;
6608
    reg [31:0] target_address ;
6609
    integer i ;
6610
    integer required_reads ;
6611
    integer writes_left ;
6612
 
6613
begin:main
6614
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6615
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6616
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6617
    pci_ctrl_offset    = 12'h4 ;
6618
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6619
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6620
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6621
    lat_tim_cls_offset = 12'hC ;
6622
 
6623
    $display("Checking WB to PCI transaction lengths!") ;
6624
    target_address  = `BEH_TAR1_MEM_START ;
6625
    image_base      = 0 ;
6626
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6627
 
6628
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6629
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6630
    write_flags                    = 0 ;
6631
    write_flags`INIT_WAITS         = tb_init_waits ;
6632
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6633
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6634
 
6635
    // enable master & target operation
6636
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6637
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6638
    if ( ok !== 1 )
6639
    begin
6640
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6641
        test_fail("write to PCI Device Control register failed") ;
6642
        disable main ;
6643
    end
6644
 
6645
    // prepare image control register
6646
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6647
    if ( ok !== 1 )
6648
    begin
6649
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6650
        test_fail("write to WB Image Control register failed") ;
6651
        disable main ;
6652
    end
6653
 
6654
    // prepare base address register
6655
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6656
    if ( ok !== 1 )
6657
    begin
6658
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6659
        test_fail("write to WB Base Address register failed") ;
6660
        disable main ;
6661
    end
6662
 
6663
    // write address mask register
6664
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6665
    if ( ok !== 1 )
6666
    begin
6667
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6668
        test_fail("write to WB Address Mask register failed") ;
6669
        disable main ;
6670
    end
6671
 
6672
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6673
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6674
    if ( ok !== 1 )
6675
    begin
6676
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6677
        test_fail("write to WB Error Control and Status register failed") ;
6678
        disable main ;
6679
    end
6680
 
6681
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6682
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6683
    if ( ok !== 1 )
6684
    begin
6685
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6686
        test_fail("write to Interrupt Control register failed") ;
6687
        disable main ;
6688
    end
6689
 
6690
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6691
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6692
    if ( ok !== 1 )
6693
    begin
6694
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6695
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6696
        disable main ;
6697
    end
6698
 
6699
    $display("Testing single write transaction progress from WB to PCI!") ;
6700
    write_data`WRITE_ADDRESS = target_address ;
6701
    write_data`WRITE_DATA    = wmem_data[0] ;
6702
    write_data`WRITE_SEL     = 4'hF ;
6703
 
6704
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6705
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6706
 
6707
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6708
    fork
6709
    begin
6710
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6711
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6712
        begin
6713
            $display("Transaction progress testing failed! Time %t ", $time) ;
6714
            $display("Bridge failed to process single memory write!") ;
6715
            test_fail("bridge failed to post single memory write") ;
6716
            disable main ;
6717
        end
6718
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6719
    end
6720
    begin
6721
        // wait two retries, then enable target response
6722
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6723
        if ( ok !== 1 )
6724
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6725
        else
6726
            test_ok ;
6727
 
6728
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6729
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6730
        if ( ok !== 1 )
6731
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6732
        else
6733
            test_ok ;
6734
 
6735
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6736
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6737
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6738
 
6739
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6740
        if ( ok !== 1 )
6741
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6742
        else
6743
            test_ok ;
6744
    end
6745
    join
6746
 
6747
    $display("Testing burst write transaction progress from WB to PCI!") ;
6748
    write_data`WRITE_ADDRESS = target_address ;
6749
    write_data`WRITE_DATA    = wmem_data[0] ;
6750
    write_data`WRITE_SEL     = 4'hF ;
6751
 
6752
    wishbone_master.blk_write_data[0] = write_data ;
6753
 
6754
    write_data`WRITE_ADDRESS = target_address + 4 ;
6755
    write_data`WRITE_DATA    = wmem_data[1] ;
6756
    write_data`WRITE_SEL     = 4'hF ;
6757
 
6758
    wishbone_master.blk_write_data[1] = write_data ;
6759
 
6760
    write_flags`WB_TRANSFER_SIZE = 2 ;
6761
    write_flags`WB_TRANSFER_CAB  = 1 ;
6762
 
6763
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6764
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6765
 
6766
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6767
 
6768
    fork
6769
    begin
6770
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6771
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6772
        begin
6773
            $display("Transaction progress testing failed! Time %t ", $time) ;
6774
            $display("Bridge failed to process whole CAB memory write!") ;
6775
            test_fail("bridge failed to post whole CAB memory write") ;
6776
            disable main ;
6777
        end
6778
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6779
    end
6780
    begin
6781
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6782
        if ( ok !== 1 )
6783
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6784
        else
6785
            test_ok ;
6786
 
6787
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6788
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6789
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6790
 
6791
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6792
        if ( ok !== 1 )
6793
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6794
        else
6795
            test_ok ;
6796
 
6797
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6798
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6799
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6800
 
6801
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6802
        if ( ok !== 1 )
6803
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6804
        else
6805
            test_ok ;
6806
    end
6807
    join
6808
 
6809
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6810
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6811
 
6812
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6813
    // try same write with other terminations
6814
    fork
6815
    begin
6816
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6817
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6818
        begin
6819
            $display("Transaction progress testing failed! Time %t ", $time) ;
6820
            $display("Bridge failed to process whole CAB memory write!") ;
6821
            test_fail("bridge failed to post whole CAB memory write") ;
6822
            disable main ;
6823
        end
6824
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6825
    end
6826
    begin
6827
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6828
        if ( ok !== 1 )
6829
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6830
        else
6831
            test_ok ;
6832
 
6833
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6834
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6835
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6836
 
6837
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6838
        if ( ok !== 1 )
6839
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6840
        else
6841
            test_ok ;
6842
    end
6843
    join
6844
 
6845
    // repeat the write with normal completion
6846
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6847
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6848
 
6849
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6850
    fork
6851
    begin
6852
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6853
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6854
        begin
6855
            $display("Transaction progress testing failed! Time %t ", $time) ;
6856
            $display("Bridge failed to process whole CAB memory write!") ;
6857
            test_fail("bridge failed to post whole CAB memory write") ;
6858
            disable main ;
6859
        end
6860
    end
6861
    begin
6862
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6863
        if ( ok !== 1 )
6864
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6865
        else
6866
            test_ok ;
6867
    end
6868
    join
6869
 
6870
    // do the same thing with burst length of 3
6871
    write_data`WRITE_ADDRESS = target_address + 8 ;
6872
    write_data`WRITE_DATA    = wmem_data[2] ;
6873
    write_data`WRITE_SEL     = 4'hF ;
6874
 
6875
    wishbone_master.blk_write_data[2] = write_data ;
6876
 
6877
    write_flags`WB_TRANSFER_SIZE = 3 ;
6878
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6879
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6880
 
6881
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6882
 
6883
    fork
6884
    begin
6885
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6886
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6887
        begin
6888
            $display("Transaction progress testing failed! Time %t ", $time) ;
6889
            $display("Bridge failed to process whole CAB memory write!") ;
6890
            test_fail("bridge failed to post whole CAB memory write") ;
6891
            disable main ;
6892
        end
6893
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6894
    end
6895
    begin
6896
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6897
        if ( ok !== 1 )
6898
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6899
        else
6900
            test_ok ;
6901
 
6902
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6903
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6904
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6905
 
6906
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6907
        if ( ok !== 1 )
6908
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6909
        else
6910
            test_ok ;
6911
    end
6912
    join
6913
 
6914
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6915
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6916
 
6917
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6918
    fork
6919
    begin
6920
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6921
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6922
        begin
6923
            $display("Transaction progress testing failed! Time %t ", $time) ;
6924
            $display("Bridge failed to process whole CAB memory write!") ;
6925
            test_fail("bridge failed to post whole CAB memory write") ;
6926
            disable main ;
6927
        end
6928
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6929
    end
6930
    begin
6931
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6932
        if ( ok !== 1 )
6933
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6934
        else
6935
            test_ok ;
6936
 
6937
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6938
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6939
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6940
 
6941
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6942
        if ( ok !== 1 )
6943
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6944
        else
6945
            test_ok ;
6946
 
6947
    end
6948
    join
6949
 
6950
    // repeat with normal completion
6951
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6952
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6953
 
6954
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6955
    fork
6956
    begin
6957
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6958
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6959
        begin
6960
            $display("Transaction progress testing failed! Time %t ", $time) ;
6961
            $display("Bridge failed to process whole CAB memory write!") ;
6962
            test_fail("bridge failed to post whole CAB memory write") ;
6963
            disable main ;
6964
        end
6965
    end
6966
    begin
6967
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6968
        if ( ok !== 1 )
6969
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6970
        else
6971
            test_ok ;
6972
 
6973
    end
6974
    join
6975
 
6976
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6977
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6978
    begin
6979
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6980
        write_data`WRITE_DATA    = wmem_data[i] ;
6981
        write_data`WRITE_SEL     = 4'hF ;
6982
 
6983
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6984
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6985
 
6986
        wishbone_master.blk_write_data[i]   = write_data ;
6987
        wishbone_master.blk_read_data_in[i] = read_data ;
6988
    end
6989
 
6990
    write_flags`WB_TRANSFER_CAB      = 1 ;
6991
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6992
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6993
 
6994
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6995
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6996
 
6997
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6998
    fork
6999
    begin
7000
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7001
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7002
        begin
7003
            $display("Transaction progress testing failed! Time %t ", $time) ;
7004
            $display("Bridge failed to process right number of databeats in CAB write!") ;
7005
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
7006
            test_fail("bridge failed to post whole CAB memory write") ;
7007
            disable main ;
7008
        end
7009
 
7010
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
7011
 
7012
        // read here just checks if data was transfered OK
7013
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7014
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
7015
 
7016
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7017
 
7018
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7019
        begin
7020
            $display("Transaction progress testing failed! Time %t ", $time) ;
7021
            $display("Bridge processed CAB read wrong!") ;
7022
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
7023
        end
7024
 
7025
    end
7026
    begin
7027
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7028
        if ( ok !== 1 )
7029
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7030
        else
7031
            test_ok ;
7032
 
7033
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
7034
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7035
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7036
 
7037
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7038
        if ( ok !== 1 )
7039
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7040
        else
7041
            test_ok ;
7042
 
7043
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
7044
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
7045
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7046
 
7047
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7048
        if ( ok !== 1 )
7049
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7050
        else
7051
            test_ok ;
7052
 
7053
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
7054
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7055
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7056
 
7057
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7058
        if ( ok !== 1 )
7059
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7060
        else
7061
            test_ok ;
7062
 
7063
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
7064
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7065
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7066
 
7067
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
7068
        if ( ok !== 1 )
7069
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7070
        else
7071
            test_ok ;
7072
 
7073
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
7074
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
7075
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
7076
        for ( i = 0 ; i < required_reads ; i = i + 1 )
7077
        begin
7078
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7079
            if ( ok !== 1 )
7080
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7081
        end
7082
    end
7083
    join
7084
 
7085
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
7086
    begin
7087
        read_status = wishbone_master.blk_read_data_out[i] ;
7088
        if (read_status`READ_DATA !== wmem_data[i])
7089
        begin
7090
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
7091
            test_fail("data read from target wasn't the same as data written to it") ;
7092
            ok = 0 ;
7093
        end
7094
    end
7095
 
7096
    if ( ok )
7097
        test_ok ;
7098
 
7099
    $display("Testing single read transaction progress from WB to PCI!") ;
7100
    read_data`READ_ADDRESS = target_address + 8 ;
7101
    read_data`READ_SEL     = 4'hF ;
7102
 
7103
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7104
 
7105
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
7106
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7107
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7108
 
7109
    fork
7110
    begin
7111
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7112
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7113
        begin
7114
            $display("Transaction progress testing failed! Time %t ", $time) ;
7115
            $display("Bridge processed single read wrong!") ;
7116
            test_fail("bridge processed single read wrong") ;
7117
            disable main ;
7118
        end
7119
 
7120
        if (read_status`READ_DATA !== wmem_data[2])
7121
        begin
7122
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7123
            test_fail("data returned from single read was not as expected") ;
7124
        end
7125
        else
7126
        if ( ok )
7127
            test_ok ;
7128
    end
7129
    begin
7130
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7131
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7132
 
7133
        if ( ok !== 1 )
7134
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7135
 
7136
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7137
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7138
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7139
 
7140
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7141
        if ( ok !== 1 )
7142
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7143
    end
7144
    join
7145
 
7146
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7147
 
7148
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7149
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7150
 
7151
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7152
    // first fill target's memory with enough data to fill WBR_FIFO
7153
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7154
    begin
7155
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7156
        write_data`WRITE_DATA    = wmem_data[i] ;
7157
        write_data`WRITE_SEL     = 4'hF ;
7158
 
7159
        wishbone_master.blk_write_data[i] = write_data ;
7160
    end
7161
 
7162
    write_flags`WB_TRANSFER_CAB = 1 ;
7163
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7164
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7165
 
7166
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7167
 
7168
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7169
    begin
7170
        $display("Transaction progress testing failed! Time %t ", $time) ;
7171
        $display("Bridge processed CAB write wrong!") ;
7172
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7173
        disable main ;
7174
    end
7175
 
7176
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7177
    // perform single read to force write data to pci
7178
    read_data`READ_ADDRESS = target_address + 8;
7179
    read_data`READ_SEL     = 4'hF ;
7180
 
7181
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7182
 
7183
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7184
    begin
7185
        $display("Transaction progress testing failed! Time %t ", $time) ;
7186
        $display("Bridge processed single read wrong!") ;
7187
        test_fail("bridge didn't process single memory read as expected") ;
7188
        disable main ;
7189
    end
7190
 
7191
    wishbone_master.blk_read_data_in[0] = read_data ;
7192
 
7193
    read_data`READ_ADDRESS = target_address + 12 ;
7194
    read_data`READ_SEL     = 4'hF ;
7195
 
7196
    wishbone_master.blk_read_data_in[1] = read_data ;
7197
 
7198
    read_data`READ_ADDRESS = target_address + 16 ;
7199
    read_data`READ_SEL     = 4'hF ;
7200
 
7201
    wishbone_master.blk_read_data_in[2] = read_data ;
7202
 
7203
    write_flags`WB_TRANSFER_CAB  = 1 ;
7204
    write_flags`WB_TRANSFER_SIZE = 2 ;
7205
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7206
    read_status = 0 ;
7207
 
7208
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7209
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7210
 
7211
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7212
 
7213
    ok = 1 ;
7214
    fork
7215
    begin
7216
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7217
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7218
 
7219
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7220
        begin
7221
            $display("Transaction progress testing failed! Time %t ", $time) ;
7222
            $display("Bridge processed CAB read wrong!") ;
7223
            test_fail("bridge didn't process disconnected burst read as expected") ;
7224
        end
7225
        else
7226
        begin
7227
 
7228
            read_status = wishbone_master.blk_read_data_out[0] ;
7229
 
7230
            if (read_status`READ_DATA !== wmem_data[2])
7231
            begin
7232
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7233
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7234
            end
7235
            else
7236
                test_ok ;
7237
        end
7238
 
7239
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7240
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7241
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7242
 
7243
        read_status = 0 ;
7244
 
7245
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7246
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7247
 
7248
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7249
        begin
7250
            $display("Transaction progress testing failed! Time %t ", $time) ;
7251
            $display("Bridge processed CAB read wrong!") ;
7252
            test_fail("bridge didn't process disconnected burst read as expected") ;
7253
        end
7254
        else
7255
        begin
7256
 
7257
            read_status = wishbone_master.blk_read_data_out[0] ;
7258
 
7259
            if (read_status`READ_DATA !== wmem_data[3])
7260
            begin
7261
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7262
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7263
            end
7264
            else
7265
                test_ok ;
7266
        end
7267
 
7268
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7269
        // complete delayed read which was requested
7270
        read_data = wishbone_master.blk_read_data_in[2] ;
7271
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7272
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7273
 
7274
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7275
        begin
7276
            $display("Transaction progress testing failed! Time %t ", $time) ;
7277
            $display("Bridge processed single out of burst read wrong!") ;
7278
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7279
        end
7280
        else
7281
        begin
7282
 
7283
            if (read_status`READ_DATA !== wmem_data[4])
7284
            begin
7285
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7286
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7287
            end
7288
            else
7289
                test_ok ;
7290
        end
7291
 
7292
    end
7293
    begin
7294
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7295
 
7296
        if ( ok !== 1 )
7297
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7298
 
7299
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7300
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7301
 
7302
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7303
        if ( ok !== 1 )
7304
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7305
 
7306
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7307
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7308
 
7309
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7310
        if ( ok !== 1 )
7311
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7312
    end
7313
    join
7314
 
7315
    // now try burst read with normal termination
7316
    read_data`READ_ADDRESS = target_address + 12 ;
7317
    read_data`READ_SEL     = 4'hF ;
7318
 
7319
    wishbone_master.blk_read_data_in[0] = read_data ;
7320
 
7321
    read_data`READ_ADDRESS = target_address + 16 ;
7322
    read_data`READ_SEL     = 4'hF ;
7323
 
7324
    wishbone_master.blk_read_data_in[1] = read_data ;
7325
 
7326
    write_flags`WB_TRANSFER_SIZE = 2 ;
7327
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7328
    write_flags`WB_TRANSFER_CAB = 1 ;
7329
 
7330
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7331
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7332
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7333
 
7334
    fork
7335
    begin
7336
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7337
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7338
        begin
7339
            $display("Transaction progress testing failed! Time %t ", $time) ;
7340
            $display("Bridge processed CAB read wrong!") ;
7341
            test_fail("bridge didn't process burst read as expected") ;
7342
            ok = 0 ;
7343
        end
7344
    end
7345
    begin
7346
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7347
        if ( ok !== 1 )
7348
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7349
    end
7350
    join
7351
 
7352
    if ( ok )
7353
    begin
7354
        read_status = wishbone_master.blk_read_data_out[0] ;
7355
        if ( read_status`READ_DATA !== wmem_data[3] )
7356
        begin
7357
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7358
            test_fail("data provided from normaly terminated read was wrong") ;
7359
            ok = 0 ;
7360
        end
7361
 
7362
        read_status = wishbone_master.blk_read_data_out[1] ;
7363
        if ( read_status`READ_DATA !== wmem_data[4] )
7364
        begin
7365
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7366
            test_fail("data provided from normaly terminated read was wrong") ;
7367
            ok = 0 ;
7368
        end
7369
    end
7370
 
7371
    if ( ok )
7372
        test_ok ;
7373
 
7374
    // disable memory read line command and enable prefetch
7375
    // prepare image control register
7376
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7377
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7378
    if ( ok !== 1 )
7379
    begin
7380
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7381
        test_fail("WB Image Control register couldn't be written to") ;
7382
        disable main ;
7383
    end
7384
 
7385
    write_flags`WB_TRANSFER_SIZE = 4 ;
7386
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7387
    write_flags`WB_TRANSFER_CAB = 1 ;
7388
 
7389
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7390
 
7391
    for ( i = 0 ; i < 4 ; i = i + 1 )
7392
    begin
7393
        read_data`READ_ADDRESS = target_address + i*4 ;
7394
        read_data`READ_SEL     = 4'b1010 ;
7395
 
7396
        wishbone_master.blk_read_data_in[i] = read_data ;
7397
    end
7398
 
7399
    fork
7400
    begin
7401
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7402
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7403
        begin
7404
            $display("Transaction progress testing failed! Time %t ", $time) ;
7405
            $display("Bridge processed CAB read wrong!") ;
7406
            test_fail("bridge didn't process prefetched burst read as expected") ;
7407
            ok = 0 ;
7408
        end
7409
    end
7410
    begin
7411
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7412
        if ( ok !== 1 )
7413
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7414
    end
7415
    join
7416
 
7417
    if ( ok )
7418
    begin
7419
        for ( i = 0 ; i < 4 ; i = i + 1 )
7420
        begin
7421
            read_status = wishbone_master.blk_read_data_out[i] ;
7422
            if ( read_status`READ_DATA !== wmem_data[i] )
7423
            begin
7424
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7425
                test_fail("burst read returned unexpected data") ;
7426
                ok = 0 ;
7427
            end
7428
        end
7429
    end
7430
 
7431
    if ( ok )
7432
        test_ok ;
7433
 
7434
    // do one single read with different byte enables
7435
    read_data`READ_ADDRESS = target_address + 4 ;
7436
    read_data`READ_SEL     = 4'b1010 ;
7437
 
7438
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7439
    fork
7440
    begin
7441
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7442
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7443
        begin
7444
            $display("Transaction progress testing failed! Time %t ", $time) ;
7445
            $display("Bridge processed single read wrong!") ;
7446
            test_fail("bridge didn't process single memory read as expected") ;
7447
            ok = 0 ;
7448
        end
7449
    end
7450
    begin
7451
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7452
        if ( ok !== 1 )
7453
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7454
    end
7455
    join
7456
 
7457
    // check read data
7458
    if ( ok )
7459
    begin
7460
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7461
        begin
7462
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7463
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7464
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7465
            ok = 0 ;
7466
            test_fail("unexpected data received from single read") ;
7467
        end
7468
    end
7469
 
7470
    if ( ok )
7471
         test_ok ;
7472
 
7473
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7474
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7475
 
7476
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7477
    if ( ok !== 1 )
7478
    begin
7479
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7480
        test_fail("WB Image Control register could not be written") ;
7481
        disable main ;
7482
    end
7483
 
7484
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7485
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7486
    begin
7487
        read_data`READ_ADDRESS = target_address + i*4 ;
7488
        read_data`READ_SEL     = 4'b1111 ;
7489
 
7490
        wishbone_master.blk_read_data_in[i] = read_data ;
7491
    end
7492
 
7493
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7494
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7495
    write_flags`WB_TRANSFER_CAB = 1 ;
7496
 
7497
    fork
7498
    begin
7499
        read_status         = 0 ;
7500
        read_status`CYC_RTY = 1 ;
7501
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7502
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7503
 
7504
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7505
        begin
7506
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7507
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7508
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7509
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7510
            ok = 0 ;
7511
        end
7512
    end
7513
    begin
7514
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7515
        if ( ok !== 1 )
7516
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7517
    end
7518
    join
7519
 
7520
    // now repeat single read to flush redundant read initiated
7521
    write_flags`WB_TRANSFER_SIZE = 1 ;
7522
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7523
    write_flags`WB_TRANSFER_CAB = 1 ;
7524
 
7525
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7526
    read_data`READ_SEL     = 4'hF ;
7527
 
7528
    wishbone_master.blk_read_data_in[0] = read_data ;
7529
 
7530
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7531
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7532
 
7533
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7534
    begin
7535
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7536
        $display(" PCI bridge failed to process single CAB read!") ;
7537
        test_fail("single CAB write was not processed as expected") ;
7538
    end
7539
 
7540
    // because last read could be very long on PCI - delete target abort status
7541
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7542
 
7543
    // write unsupported value to cache line size register
7544
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7545
 
7546
    read_data`READ_ADDRESS = target_address ;
7547
    read_data`READ_SEL     = 4'hF ;
7548
    wishbone_master.blk_read_data_in[0] = read_data ;
7549
 
7550
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7551
    // perform a read
7552
    fork
7553
    begin
7554
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7555
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7556
        begin
7557
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7558
            $display(" PCI bridge failed to process single CAB read!") ;
7559
            test_fail("burst read was not processed as expected") ;
7560
            ok = 0 ;
7561
        end
7562
    end
7563
    begin
7564
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7565
        if ( ok !== 1 )
7566
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7567
    end
7568
    join
7569
 
7570
    if ( ok )
7571
        test_ok ;
7572
 
7573
    // write 2 to cache line size register
7574
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7575
 
7576
    // perform a read
7577
    fork
7578
    begin
7579
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7580
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7581
        begin
7582
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7583
            $display(" PCI bridge failed to process single CAB read!") ;
7584
            test_fail("burst read was not processed as expected") ;
7585
            ok = 0 ;
7586
        end
7587
    end
7588
    begin
7589
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7590
        if ( ok !== 1 )
7591
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7592
    end
7593
    join
7594
 
7595
    if ( ok )
7596
        test_ok ;
7597
 
7598
    // write 0 to cache line size
7599
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7600
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7601
 
7602
    // perform a read
7603
    fork
7604
    begin
7605
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7606
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7607
        begin
7608
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7609
            $display(" PCI bridge failed to process single CAB read!") ;
7610
            test_fail("burst read was not processed as expected") ;
7611
            ok = 0 ;
7612
        end
7613
    end
7614
    begin
7615
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7616
        if ( ok !== 1 )
7617
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7618
    end
7619
    join
7620
 
7621
    if ( ok )
7622
        test_ok ;
7623
 
7624
    // write normal value to cls register
7625
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7626
 
7627
    $display("Testing Master's latency timer operation!") ;
7628
    $display("Testing Latency timer during Master Writes!") ;
7629
 
7630
    for ( i = 0 ; i < 6 ; i = i + 1 )
7631
    begin
7632
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7633
        write_data`WRITE_SEL     = 4'b1111 ;
7634
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7635
 
7636
        wishbone_master.blk_write_data[i] = write_data ;
7637
    end
7638
 
7639
    write_flags`WB_TRANSFER_SIZE = 6 ;
7640
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7641
    write_flags`WB_TRANSFER_CAB = 1 ;
7642
 
7643
    // start wb write, pci write and monitor in parallel
7644
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7645
    fork
7646
    begin
7647
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7648
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7649
        begin
7650
            $display("Transaction progress testing failed! Time %t ", $time) ;
7651
            $display("Bridge failed to process CAB write!") ;
7652
            test_fail("bridge didn't post whole burst memory write") ;
7653
            disable main ;
7654
        end
7655
    end
7656
    begin
7657
        // wait for bridge's master to start transaction
7658
        @(posedge pci_clock) ;
7659
        while ( FRAME === 1 )
7660
            @(posedge pci_clock) ;
7661
 
7662
        // start behavioral master request
7663
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7664
               target_address, wmem_data[1023], `Test_All_Bytes,
7665
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7666
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7667
 
7668
        do_pause ( 1 ) ;
7669
    end
7670
    begin
7671
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7672
        if ( ok !== 1 )
7673
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7674
        else
7675
            test_ok ;
7676
    end
7677
    join
7678
 
7679
    // perform a read to check data
7680
    for ( i = 0 ; i < 6 ; i = i + 1 )
7681
    begin
7682
        read_data`READ_ADDRESS = target_address + i*4 ;
7683
        read_data`READ_SEL     = 4'b1111 ;
7684
 
7685
        wishbone_master.blk_read_data_in[i] = read_data ;
7686
    end
7687
 
7688
    write_flags`WB_TRANSFER_SIZE = 6 ;
7689
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7690
    write_flags`WB_TRANSFER_CAB = 1 ;
7691
 
7692
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7693
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7694
 
7695
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7696
    begin
7697
        $display("Transaction progress testing failed! Time %t ", $time) ;
7698
        $display("Bridge failed to process CAB read!") ;
7699
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7700
        disable main ;
7701
    end
7702
 
7703
    ok = 1 ;
7704
    for ( i = 0 ; i < 6 ; i = i + 1 )
7705
    begin
7706
        read_status = wishbone_master.blk_read_data_out[i] ;
7707
 
7708
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7709
        begin
7710
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7711
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7712
            test_fail("unexpected data read back from PCI") ;
7713
            ok = 0 ;
7714
        end
7715
    end
7716
 
7717
    if ( ok )
7718
        test_ok ;
7719
 
7720
    $display("Testing Latency timer during Master Reads!") ;
7721
 
7722
    // at least 2 words are transfered during Master Reads terminated with timeout
7723
    write_flags`WB_TRANSFER_SIZE = 2 ;
7724
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7725
    fork
7726
    begin
7727
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7728
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7729
        begin
7730
            $display("Transaction progress testing failed! Time %t ", $time) ;
7731
            $display("Bridge failed to process CAB read!") ;
7732
            test_fail("bridge didn't process burst read as expected") ;
7733
            ok = 0 ;
7734
        end
7735
    end
7736
    begin
7737
        // wait for bridge's master to start transaction
7738
        @(posedge pci_clock) ;
7739
        while ( FRAME === 1 )
7740
            @(posedge pci_clock) ;
7741
 
7742
        // start behavioral master request
7743
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7744
               target_address, wmem_data[0], `Test_All_Bytes,
7745
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7746
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7747
 
7748
        do_pause ( 1 ) ;
7749
    end
7750
    begin
7751
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7752
        if ( ok !== 1 )
7753
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7754
    end
7755
    join
7756
 
7757
    // check data provided by target
7758
    if ( ok )
7759
    begin
7760
        for ( i = 0 ; i < 2 ; i = i + 1 )
7761
        begin
7762
            read_status = wishbone_master.blk_read_data_out[i] ;
7763
 
7764
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7765
            begin
7766
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7767
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7768
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7769
                ok = 0 ;
7770
            end
7771
        end
7772
    end
7773
    if ( ok )
7774
        test_ok ;
7775
 
7776
    test_name = "DISABLE_IMAGE" ;
7777
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7778
    if ( ok !== 1 )
7779
    begin
7780
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7781
        test_fail("write to WB Address Mask register failed") ;
7782
        disable main ;
7783
    end
7784
 
7785
end
7786
endtask //wb_to_pci_transactions
7787
 
7788
task iack_cycle ;
7789
    reg `READ_STIM_TYPE   read_data ;
7790
    reg `READ_RETURN_TYPE read_status ;
7791
    reg `WB_TRANSFER_FLAGS flags ;
7792
 
7793
    reg [31:0] temp_var ;
7794
    reg ok ;
7795 45 mihad
    reg ok_wb ;
7796
    reg ok_pci ;
7797
 
7798
    reg [31:0] irq_vector ;
7799 15 mihad
begin
7800
 
7801 45 mihad
    ok     = 1 ;
7802
    ok_wb  = 1 ;
7803
    ok_pci = 1 ;
7804
 
7805 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7806
 
7807
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7808
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7809
 
7810
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7811
    read_data`READ_SEL     = 4'hF ;
7812
 
7813
    flags = 0 ;
7814
 
7815
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7816
 
7817
    irq_vector  = 32'hAAAA_AAAA ;
7818
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7819
 
7820 45 mihad
    // disable both pci blue behavioral targets
7821
    configuration_cycle_write
7822
    (
7823
        0,                          // bus number [7:0]
7824
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7825
        0,                          // function number [2:0]
7826
        1,                          // register number [5:0]
7827
        0,                          // type [1:0]
7828
        4'h1,                       // byte enables [3:0]
7829
        32'h0000_0044               // data to write [31:0]
7830
    ) ;
7831
 
7832
    configuration_cycle_write
7833
    (
7834
        0,                          // bus number [7:0]
7835
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7836
        0,                          // function number [2:0]
7837
        1,                          // register number [5:0]
7838
        0,                          // type [1:0]
7839
        4'h1,                       // byte enables [3:0]
7840
        32'h0000_0044               // data to write [31:0]
7841
    ) ;
7842
 
7843 15 mihad
    fork
7844
    begin
7845
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7846
    end
7847
    begin
7848 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7849
        if ( ok_pci !== 1 )
7850 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7851
    end
7852
    join
7853
 
7854
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7855
    begin
7856 45 mihad
        ok_wb = 0 ;
7857 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7858
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7859
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7860
    end
7861 45 mihad
 
7862
    if ( ok_pci && ok_wb )
7863 15 mihad
        test_ok ;
7864 45 mihad
 
7865
    ok_wb = 1 ;
7866
    ok_pci = 1 ;
7867
    ok = 1 ;
7868 15 mihad
 
7869 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7870
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7871 15 mihad
 
7872
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7873 45 mihad
    // enable pci blue behavioral target 1
7874
    configuration_cycle_write
7875
    (
7876
        0,                          // bus number [7:0]
7877
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7878
        0,                          // function number [2:0]
7879
        1,                          // register number [5:0]
7880
        0,                          // type [1:0]
7881
        4'h1,                       // byte enables [3:0]
7882
        32'h0000_0047               // data to write [31:0]
7883
    ) ;
7884 15 mihad
    fork
7885
    begin
7886
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7887
    end
7888
    begin
7889 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7890
        if ( ok_pci !== 1 )
7891 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7892
    end
7893
    join
7894
 
7895
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7896
    begin
7897 45 mihad
        ok_wb = 0 ;
7898 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7899
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7900
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7901
    end
7902
 
7903
    if ( read_status`READ_DATA !== irq_vector )
7904
    begin
7905
        $display(" Time %t ", $time ) ;
7906
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7907
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7908 45 mihad
        ok_wb = 0 ;
7909 15 mihad
    end
7910
 
7911 45 mihad
    if ( ok_pci && ok_wb )
7912 15 mihad
        test_ok ;
7913
 
7914 45 mihad
    ok_pci = 1 ;
7915
    ok_wb  = 1 ;
7916
    ok     = 1 ;
7917
 
7918 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7919 45 mihad
    irq_vector  = 32'h5555_5555 ;
7920
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7921
 
7922 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7923
    fork
7924
    begin
7925
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7926
    end
7927
    begin
7928 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7929
        if ( ok_pci !== 1 )
7930 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7931
    end
7932
    join
7933
 
7934
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7935
    begin
7936
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7937
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7938
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7939 45 mihad
        ok_wb = 0 ;
7940 15 mihad
    end
7941
 
7942 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7943 15 mihad
    begin
7944
        $display(" Time %t ", $time ) ;
7945 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7946 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7947 45 mihad
        ok_wb = 0 ;
7948 15 mihad
    end
7949
 
7950 45 mihad
    if (ok_pci && ok_wb)
7951 15 mihad
        test_ok ;
7952
 
7953 45 mihad
    ok_pci = 1 ;
7954
    ok_wb  = 1 ;
7955
    ok     = 1 ;
7956 15 mihad
 
7957 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7958
 
7959
    // set target to terminate with target abort
7960
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7961
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7962
 
7963
    fork
7964
    begin
7965
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7966
    end
7967
    begin
7968
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7969
        if ( ok_pci !== 1 )
7970
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7971
    end
7972
    join
7973
 
7974
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7975
    begin
7976
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7977
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7978
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7979
        ok_wb = 0 ;
7980
    end
7981
 
7982
    // set target to terminate with target abort
7983
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7984
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7985
 
7986
    // enable pci blue behavioral target 2
7987
    configuration_cycle_write
7988
    (
7989
        0,                          // bus number [7:0]
7990
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7991
        0,                          // function number [2:0]
7992
        1,                          // register number [5:0]
7993
        0,                          // type [1:0]
7994
        4'h1,                       // byte enables [3:0]
7995
        32'h0000_0047               // data to write [31:0]
7996
    ) ;
7997
 
7998
    // read PCI Device status
7999
    config_read(12'h4, 4'hC, temp_var) ;
8000
    if (temp_var[29] !== 1)
8001
    begin
8002
        $display("Time %t", $time) ;
8003
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
8004
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
8005
        ok_wb = 0 ;
8006
    end
8007
 
8008
    if (temp_var[28] !== 1)
8009
    begin
8010
        $display("Time %t", $time) ;
8011
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
8012
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
8013
        ok_wb = 0 ;
8014
    end
8015
 
8016
    // clearing the status bits
8017
        config_write(12'h4, temp_var, 4'hC, ok);
8018
 
8019
    if ( ok && ok_pci && ok_wb )
8020
        test_ok ;
8021
 
8022 15 mihad
end
8023
endtask //iack_cycle
8024
 
8025
task transaction_ordering ;
8026
    reg   [11:0] wb_ctrl_offset ;
8027
    reg   [11:0] wb_ba_offset ;
8028
    reg   [11:0] wb_am_offset ;
8029
    reg   [11:0] pci_ctrl_offset ;
8030
    reg   [11:0] pci_ba_offset ;
8031
    reg   [11:0] pci_am_offset ;
8032
    reg   [11:0] pci_device_ctrl_offset ;
8033
    reg   [11:0] wb_err_cs_offset ;
8034
    reg   [11:0] pci_err_cs_offset ;
8035
    reg   [11:0] icr_offset ;
8036
    reg   [11:0] isr_offset ;
8037
    reg   [11:0] lat_tim_cls_offset ;
8038
 
8039
    reg `WRITE_STIM_TYPE  write_data ;
8040
    reg `READ_STIM_TYPE   read_data ;
8041
    reg `READ_RETURN_TYPE read_status ;
8042
 
8043
    reg `WRITE_RETURN_TYPE write_status ;
8044
    reg `WB_TRANSFER_FLAGS write_flags ;
8045
    reg [31:0] temp_val1 ;
8046
    reg [31:0] temp_val2 ;
8047
    reg        ok   ;
8048
 
8049
    reg [31:0] wb_image_base ;
8050
    reg [31:0] wb_target_address ;
8051
    reg [31:0] pci_image_base ;
8052
    integer i ;
8053
 
8054
    reg     error_monitor_done ;
8055
begin:main
8056
    write_flags`INIT_WAITS = tb_init_waits ;
8057
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
8058
 
8059
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
8060
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
8061
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
8062
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
8063
 
8064
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
8065
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
8066
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
8067
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
8068
 
8069
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
8070
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
8071
    lat_tim_cls_offset = 12'hC ;
8072
    pci_device_ctrl_offset    = 12'h4 ;
8073
 
8074
    wb_target_address  = `BEH_TAR1_MEM_START ;
8075
    wb_image_base      = 0 ;
8076
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
8077
 
8078
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
8079
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
8080
    write_flags                    = 0 ;
8081
    write_flags`INIT_WAITS         = 0 ;
8082
    write_flags`SUBSEQ_WAITS       = 0 ;
8083
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8084
 
8085
    pci_image_base = Target_Base_Addr_R[1] ;
8086
 
8087
    // enable master & target operation
8088
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
8089
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
8090
    if ( ok !== 1 )
8091
    begin
8092
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
8093
        test_fail("write to PCI Device Control register failed") ;
8094
        disable main ;
8095
    end
8096
 
8097
    // prepare image control register
8098
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8099
    if ( ok !== 1 )
8100
    begin
8101
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
8102
        test_fail("write to WB Image Control register failed") ;
8103
        disable main ;
8104
    end
8105
 
8106
    // prepare base address register
8107
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8108
    if ( ok !== 1 )
8109
    begin
8110
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8111
        test_fail("write to WB Base Address register failed") ;
8112
        disable main ;
8113
    end
8114
 
8115
    // write address mask register
8116
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8117
    if ( ok !== 1 )
8118
    begin
8119
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8120
        test_fail("write to WB Address Mask register failed") ;
8121
        disable main ;
8122
    end
8123
 
8124
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8125
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8126
    if ( ok !== 1 )
8127
    begin
8128
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8129
        test_fail("write to WB Error Control and Status register failed") ;
8130
        disable main ;
8131
    end
8132
 
8133
    // prepare image control register
8134
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8135
    if ( ok !== 1 )
8136
    begin
8137
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8138
        test_fail("write to PCI Image Control register failed") ;
8139
        disable main ;
8140
    end
8141
 
8142
    // prepare base address register
8143
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8144
    if ( ok !== 1 )
8145
    begin
8146
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8147
        test_fail("write to PCI Base Address register failed") ;
8148
        disable main ;
8149
    end
8150
 
8151
    // write address mask register
8152
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8153
    if ( ok !== 1 )
8154
    begin
8155
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8156
        test_fail("write to PCI Address Mask register failed") ;
8157
        disable main ;
8158
    end
8159
 
8160
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8161
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8162
    if ( ok !== 1 )
8163
    begin
8164
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8165
        test_fail("write to PCI Error Control and Status register failed") ;
8166
        disable main ;
8167
    end
8168
 
8169
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8170
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8171
    if ( ok !== 1 )
8172
    begin
8173
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8174
        test_fail("write to Interrupt Control register failed") ;
8175
        disable main ;
8176
    end
8177
 
8178
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8179
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8180
    if ( ok !== 1 )
8181
    begin
8182
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8183
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8184
        disable main ;
8185
    end
8186
 
8187
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8188
 
8189
    // prepare wb_master write and read data
8190
    for ( i = 0 ; i < 4 ; i = i + 1 )
8191
    begin
8192
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8193
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8194
        write_data`WRITE_SEL     = 4'hF ;
8195
 
8196
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8197
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8198
 
8199
        wishbone_master.blk_write_data[i]   = write_data ;
8200
        wishbone_master.blk_read_data_in[i] = read_data ;
8201
    end
8202
 
8203
    // put wishbone slave in acknowledge and pci target in retry mode
8204
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8205
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8206
 
8207
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8208
 
8209
    fork
8210
    begin
8211
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8212
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8213
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8214
        begin
8215
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8216
            test_fail("Bridge didn't post single memory write as expected") ;
8217
        end
8218
 
8219
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8220
        if ( ok !== 1 )
8221
        begin
8222
            $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) ;
8223
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8224
            ok = 0 ;
8225
        end
8226
 
8227
        // now post single write to target - normal progress
8228
        if ( target_mem_image == 1 )
8229
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8230
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8231
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8232
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8233
        else
8234
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8235
 
8236
        do_pause( 1 ) ;
8237
 
8238
    end
8239
    begin:error_monitor_1
8240 35 mihad
        error_monitor_done = 0 ;
8241 15 mihad
        @(error_event_int) ;
8242
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8243
        ok = 0 ;
8244 35 mihad
        error_monitor_done = 1 ;
8245 15 mihad
    end
8246
    begin
8247
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8248
        if ( ok !== 1 )
8249
        begin
8250
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8251
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8252
        end
8253
        else
8254
        begin
8255 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8256
//            while ( FRAME === 0 || IRDY === 0 )
8257
//                @(posedge pci_clock) ;
8258 15 mihad
 
8259
            // enable response in PCI target
8260
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8261
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8262
 
8263
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8264
            if ( ok !== 1 )
8265
            begin
8266
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8267
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8268
            end
8269
        end
8270
 
8271 35 mihad
        #1 ;
8272
        if ( !error_monitor_done )
8273
            disable error_monitor_1 ;
8274 15 mihad
    end
8275
    join
8276
 
8277
    if ( ok )
8278
        test_ok ;
8279
 
8280
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8281
 
8282
    // put WISHBONE slave in retry mode
8283
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8284
 
8285
    fork
8286
    begin
8287
        // now post single write to target - normal progress
8288
        if ( target_mem_image == 1 )
8289
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8290
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8291
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8292
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8293
        else
8294
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8295
 
8296
        do_pause( 1 ) ;
8297
 
8298
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8299
        if ( ok !== 1 )
8300
        begin
8301
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8302
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8303
        end
8304
 
8305
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8306
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8307
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8308
        begin
8309
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8310
            test_fail("Bridge didn't post single memory write as expected") ;
8311
        end
8312
 
8313
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8314
        if ( ok !== 1 )
8315
        begin
8316
            $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) ;
8317
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8318
            ok = 0 ;
8319
        end
8320
 
8321
        wait ( CYC_O === 0 ) ;
8322
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8323
 
8324
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8325
        if ( ok !== 1 )
8326
        begin
8327
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8328
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8329
        end
8330
 
8331 35 mihad
        #1 ;
8332
        if ( !error_monitor_done )
8333
            disable error_monitor_2 ;
8334 15 mihad
    end
8335
    begin:error_monitor_2
8336 35 mihad
        error_monitor_done = 0 ;
8337 15 mihad
        @(error_event_int) ;
8338
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8339
        ok = 0 ;
8340 35 mihad
        error_monitor_done = 1 ;
8341 15 mihad
    end
8342
    join
8343
 
8344
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8345
 
8346
    // put wishbone slave in acknowledge and pci target in retry mode
8347
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8348
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8349
 
8350
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8351
 
8352
    fork
8353
    begin
8354
        write_flags`WB_TRANSFER_SIZE = 3 ;
8355
        write_flags`WB_TRANSFER_CAB  = 1 ;
8356
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8357
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8358
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8359
        begin
8360
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8361
            test_fail("Bridge didn't post burst memory write as expected") ;
8362
        end
8363
 
8364
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8365
        if ( ok !== 1 )
8366
        begin
8367
            $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) ;
8368
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8369
            ok = 0 ;
8370
        end
8371
 
8372
        // now post single write to target - normal progress
8373
        if ( target_mem_image == 1 )
8374
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8375
                        pci_image_base, 32'h5555_5555, 4'h0,
8376
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8377
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8378
        else
8379
        begin
8380
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8381
            do_pause( 1 ) ;
8382
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8383
        end
8384
 
8385
        do_pause( 1 ) ;
8386
 
8387
    end
8388
    begin:error_monitor_3
8389 35 mihad
        error_monitor_done = 0 ;
8390 15 mihad
        @(error_event_int) ;
8391
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8392
        ok = 0 ;
8393 35 mihad
        error_monitor_done = 1 ;
8394 15 mihad
    end
8395
    begin
8396
        if ( target_mem_image == 1 )
8397
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8398
        else
8399
        begin
8400
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8401
            if ( ok )
8402
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8403
        end
8404
 
8405
        if ( ok !== 1 )
8406
        begin
8407
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8408
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8409
        end
8410
        else
8411
        begin
8412 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8413
//            while ( FRAME === 0 || IRDY === 0 )
8414
//                @(posedge pci_clock) ;
8415 15 mihad
 
8416
            // enable response in PCI target
8417
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8418
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8419
 
8420
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8421
            if ( ok !== 1 )
8422
            begin
8423
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8424
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8425
            end
8426
        end
8427
 
8428 35 mihad
        #1 ;
8429
        if ( !error_monitor_done )
8430
            disable error_monitor_3 ;
8431 15 mihad
    end
8432
    join
8433
 
8434
    if ( ok )
8435
        test_ok ;
8436
 
8437
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8438
 
8439
    // put WISHBONE slave in retry mode
8440
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8441
 
8442
    fork
8443
    begin
8444
        // now post single write to target - normal progress
8445
        if ( target_mem_image == 1 )
8446
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8447
                        pci_image_base, 32'h5555_5555, 4'h0,
8448
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8449
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8450
        else
8451
        begin
8452
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8453
            do_pause( 1 ) ;
8454
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8455
        end
8456
 
8457
        do_pause( 1 ) ;
8458
 
8459
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8460
 
8461
        if ( ok !== 1 )
8462
        begin
8463
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8464
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8465
        end
8466
 
8467
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8468
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8469
        write_flags`WB_TRANSFER_CAB      = 1 ;
8470
 
8471
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8472
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8473
        begin
8474
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8475
            test_fail("Bridge didn't post burst memory write as expected") ;
8476
        end
8477
 
8478
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8479
        if ( ok !== 1 )
8480
        begin
8481
            $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) ;
8482
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8483
            ok = 0 ;
8484
        end
8485
 
8486
        @(posedge wb_clock) ;
8487
        while ( CYC_O === 1 )
8488
            @(posedge wb_clock) ;
8489
 
8490
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8491
 
8492
        if ( target_mem_image == 1 )
8493
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8494
        else
8495
        begin
8496
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8497
            if ( ok )
8498
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8499
        end
8500
 
8501 35 mihad
        #1 ;
8502
        if ( !error_monitor_done )
8503
            disable error_monitor_4 ;
8504 15 mihad
    end
8505
    begin:error_monitor_4
8506 35 mihad
        error_monitor_done = 0 ;
8507 15 mihad
        @(error_event_int) ;
8508
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8509
        ok = 0 ;
8510 35 mihad
        error_monitor_done = 1 ;
8511 15 mihad
    end
8512
    join
8513
 
8514
    if ( ok )
8515
        test_ok ;
8516
 
8517
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8518
 
8519
    // put wishbone slave in acknowledge and pci target in retry mode
8520
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8521
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8522
 
8523
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8524
 
8525
    master1_check_received_data = 1 ;
8526
 
8527
    error_monitor_done = 0 ;
8528
    fork
8529
    begin:error_monitor_5
8530
        @(error_event_int or error_monitor_done) ;
8531
        if ( !error_monitor_done )
8532
        begin
8533
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8534
            ok = 0 ;
8535
        end
8536
    end
8537
    begin
8538
 
8539
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8540
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8541
        begin
8542
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8543
            test_fail("Bridge didn't post single memory write as expected") ;
8544
        end
8545
 
8546
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8547
        if ( ok !== 1 )
8548
        begin
8549
            $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) ;
8550
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8551
            ok = 0 ;
8552
        end
8553
 
8554
        // start Read Through pci target
8555
        if ( target_mem_image == 1 )
8556
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8557
                          pci_image_base, 32'h5555_5555,
8558
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8559
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8560
        else
8561
            PCIU_IO_READ
8562
             (
8563
                `Test_Master_1,
8564
                pci_image_base,
8565
                32'h5555_5555,
8566
                4'h0,
8567
                1,
8568
                `Test_Target_Retry_On
8569
             );
8570
 
8571
         do_pause( 1 ) ;
8572
 
8573
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8574
         if ( ok !== 1 )
8575
         begin
8576
            $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) ;
8577
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8578
         end
8579
 
8580
         // repeat the read 4 times - it should be retried all the time by pci target
8581
        for ( i = 0 ; i < 4 ; i = i + 1 )
8582
        begin
8583
            if ( target_mem_image == 1 )
8584
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8585
                            pci_image_base, 32'h5555_5555,
8586
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8587
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8588
            else
8589
                PCIU_IO_READ
8590
                (
8591
                    `Test_Master_1,
8592
                    pci_image_base,
8593
                    32'h5555_5555,
8594
                    4'h0,
8595
                    1,
8596
                    `Test_Target_Retry_On
8597
                );
8598
 
8599
            do_pause( 1 ) ;
8600
        end
8601
 
8602
        // now do posted write through target - it must go through OK
8603
        if ( target_mem_image == 1 )
8604
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8605
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8606
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8607
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8608
        else
8609
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8610
 
8611
        do_pause( 1 ) ;
8612
 
8613
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8614
        if ( ok !== 1 )
8615
        begin
8616
           $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) ;
8617
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8618
        end
8619
 
8620
        // start a read through wb_slave
8621
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8622
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8623
        begin
8624
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8625
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8626
            ok = 0 ;
8627
        end
8628
 
8629 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8630
//        while ( FRAME === 0 || IRDY === 0 )
8631
//            @(posedge pci_clock) ;
8632 15 mihad
 
8633
        // set the target to normal completion
8634
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8635
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8636
 
8637
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8638
        if ( ok !== 1 )
8639
        begin
8640
            $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) ;
8641
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8642
            ok = 0 ;
8643
        end
8644
 
8645
        // now wait for delayed read to finish
8646
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8647
        if ( ok !== 1 )
8648
        begin
8649
            $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) ;
8650
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8651
            ok = 0 ;
8652
        end
8653
 
8654
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8655
        fork
8656
        begin
8657
                if ( target_mem_image == 1 )
8658
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8659
                                pci_image_base, 32'h5555_5555, 4'h0,
8660
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8661
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8662
                else
8663
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8664
 
8665
                do_pause( 1 ) ;
8666
                end
8667
                begin
8668 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 ) ;
8669 15 mihad
                end
8670
                join
8671
 
8672
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8673
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8674
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8675
        begin
8676
            $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) ;
8677
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8678
            ok = 0 ;
8679
        end
8680
 
8681
        fork
8682
        begin
8683
        // now complete a read from PCI Target
8684
            if ( target_mem_image == 1 )
8685
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8686
                            pci_image_base, 32'h5555_5555,
8687
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8688
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8689
            else
8690
                PCIU_IO_READ
8691
                (
8692
                    `Test_Master_1,
8693
                    pci_image_base,
8694
                    32'h5555_5555,
8695
                    4'h0,
8696
                    1,
8697
                    `Test_Target_Normal_Completion
8698
                );
8699
 
8700
            do_pause( 1 ) ;
8701
        end
8702
        begin
8703
            if ( target_mem_image == 1 )
8704
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8705
            else
8706
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8707
        end
8708
        join
8709
 
8710
        @(posedge pci_clock) ;
8711
        repeat( 4 )
8712
            @(posedge wb_clock) ;
8713
 
8714
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8715
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8716
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8717
        begin
8718
            $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) ;
8719
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8720
            ok = 0 ;
8721
        end
8722
 
8723
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8724
        if ( ok !== 1 )
8725
        begin
8726
            $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) ;
8727
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8728
            ok = 0 ;
8729
        end
8730
 
8731
        // finish a read on WISHBONE also
8732
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8733
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8734
        begin
8735
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8736
            test_fail("WB Slave didn't process single delayed read as expected") ;
8737
        end
8738
 
8739
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8740
        begin
8741
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8742
            ok = 0 ;
8743
        end
8744
 
8745
 
8746
        error_monitor_done = 1 ;
8747
    end
8748
    join
8749
 
8750
    if ( ok )
8751
        test_ok ;
8752
 
8753
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8754
 
8755
    // put wishbone slave in retry and pci target in completion mode
8756
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8757
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8758
 
8759
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8760
 
8761
    master1_check_received_data = 1 ;
8762
 
8763
    error_monitor_done = 0 ;
8764
    fork
8765
    begin:error_monitor_6
8766
        @(error_event_int or error_monitor_done) ;
8767
        if ( !error_monitor_done )
8768
        begin
8769
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8770
            ok = 0 ;
8771
        end
8772
    end
8773
    begin
8774
 
8775
        // do a write through Target
8776
        fork
8777
        begin
8778
            if ( target_mem_image == 1 )
8779
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8780
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8781
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8782
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8783
            else
8784
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8785
 
8786
            do_pause( 1 ) ;
8787
        end
8788
        begin
8789
            if ( target_mem_image == 1 )
8790
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8791
            else
8792
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8793
        end
8794
        join
8795
 
8796
        // start a read through WB slave
8797
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8798
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8799
        begin
8800
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8801
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8802
            ok = 0 ;
8803
        end
8804
 
8805
        // now wait for this read to finish on pci
8806
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8807
        if ( ok !== 1 )
8808
        begin
8809
            $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) ;
8810
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8811
            ok = 0 ;
8812
        end
8813
 
8814
        // repeat the read four times - it should be retried
8815
        for ( i = 0 ; i < 4 ; i = i + 1 )
8816
        begin
8817
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8818
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8819
            begin
8820
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8821
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8822
                ok = 0 ;
8823
            end
8824
        end
8825
 
8826
        // posted write through WB Slave - must go through
8827
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8828
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8829
        begin
8830
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8831
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8832
            ok = 0 ;
8833
        end
8834
 
8835
        // write must come through
8836
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8837
        if ( ok !== 1 )
8838
        begin
8839
            $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) ;
8840
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8841
            ok = 0 ;
8842
        end
8843
 
8844
        // do a read through pci target
8845
        if ( target_mem_image == 1 )
8846
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8847
                          pci_image_base + 12, 32'hDEAD_BEAF,
8848
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8849
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8850
        else
8851
            PCIU_IO_READ
8852
             (
8853
                `Test_Master_1,
8854
                pci_image_base + 12,
8855
                32'hDEAD_BEAF,
8856
                4'h0,
8857
                1,
8858
                `Test_Target_Retry_On
8859
             );
8860
 
8861
         do_pause( 1 ) ;
8862
 
8863
        // wait for current cycle to finish on WB
8864 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8865
//        @(posedge wb_clock) ;
8866
//        while( CYC_O === 1 )
8867
//            @(posedge wb_clock) ;
8868 15 mihad
 
8869
        // set slave response to acknowledge
8870
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8871
 
8872
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8873
        if ( ok !== 1 )
8874
        begin
8875
            $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) ;
8876
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8877
        end
8878
 
8879
        // check the read to finish on wb
8880
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8881
        if ( ok !== 1 )
8882
        begin
8883
            $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) ;
8884
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8885
        end
8886
 
8887
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8888
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8889
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8890
        begin
8891
            $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) ;
8892
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8893
            ok = 0 ;
8894
        end
8895
 
8896
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8897
        fork
8898
        begin
8899
            if ( target_mem_image == 1 )
8900
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8901
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8902
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8903
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8904
            else
8905
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8906
        end
8907
        begin
8908
            if ( target_mem_image == 1 )
8909
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8910
            else
8911
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8912
        end
8913
        join
8914
 
8915
        do_pause( 1 ) ;
8916
 
8917
        // complete a read in WB Slave Unit
8918
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8919
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8920
        begin
8921
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8922
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8923
            ok = 0 ;
8924
        end
8925
 
8926
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8927
        begin
8928
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8929
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8930
            ok = 0 ;
8931
        end
8932
 
8933
        // wait for statuses to be propagated from one side of bridge to another
8934
        repeat( 4 )
8935
            @(posedge pci_clock) ;
8936
 
8937
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8938
        fork
8939
        begin
8940
            if ( target_mem_image == 1 )
8941
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8942
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8943
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8944
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8945
            else
8946
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8947
 
8948
            do_pause( 1 ) ;
8949
        end
8950
        begin
8951
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8952
            if ( ok !== 1 )
8953
            begin
8954
                $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) ;
8955
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8956
            end
8957
        end
8958
        join
8959
 
8960
        // finish the last read in PCI Target Unit
8961
        if ( target_mem_image == 1 )
8962
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8963
                          pci_image_base + 12, 32'hDEAD_BEAF,
8964
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8965
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8966
        else
8967
            PCIU_IO_READ
8968
             (
8969
                `Test_Master_1,
8970
                pci_image_base + 12,
8971
                32'hDEAD_BEAF,
8972
                4'h0,
8973
                1,
8974
                `Test_Target_Normal_Completion
8975
             );
8976
 
8977
         do_pause( 1 ) ;
8978
 
8979
         error_monitor_done = 1 ;
8980
    end
8981
    join
8982
 
8983
    if ( ok )
8984
        test_ok ;
8985
 
8986
end
8987
endtask // transaction_ordering
8988
 
8989
task pci_transaction_progress_monitor ;
8990
    input [31:0] address ;
8991
    input [3:0]  bus_command ;
8992
    input [31:0] num_of_transfers ;
8993
    input [31:0] num_of_cycles ;
8994
    input check_transfers ;
8995
    input check_cycles ;
8996
    input doing_fast_back_to_back ;
8997
    output ok ;
8998
    reg in_use ;
8999
    integer deadlock_counter ;
9000
    integer transfer_counter ;
9001
    integer cycle_counter ;
9002
    integer deadlock_max_val ;
9003
begin:main
9004
 
9005
    if ( in_use === 1 )
9006
    begin
9007
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9008
        ok = 0 ;
9009
        disable main ;
9010
    end
9011
 
9012
    // approximate number of cycles on WB bus for maximum transaction length
9013
    deadlock_max_val = tb_init_waits + 100 +
9014
                       `WBW_DEPTH *
9015
                       (tb_subseq_waits + 1 +
9016
                       `ifdef REGISTER_WBS_OUTPUTS
9017
                       1) ;
9018
                       `else
9019
                       0) ;
9020
                       `endif
9021
 
9022
    // time used for maximum transaction length on WB
9023
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
9024
 
9025
    // maximum pci clock cycles
9026
    `ifdef PCI33
9027
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
9028
    `else
9029
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
9030
    `endif
9031
 
9032
    in_use = 1 ;
9033
    ok     = 1 ;
9034
 
9035
    fork
9036
    begin:wait_start
9037
 
9038
        deadlock_counter = 0 ;
9039
 
9040
        @(posedge pci_clock) ;
9041
 
9042
        if ( doing_fast_back_to_back !== 1 )
9043
        begin
9044
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
9045
            begin
9046 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
9047
                    deadlock_counter = 0 ;
9048
                else
9049
                    deadlock_counter = deadlock_counter + 1 ;
9050 15 mihad
                @(posedge pci_clock) ;
9051
            end
9052
            if ( FRAME !== 1 )
9053
            begin
9054
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9055
                in_use = 0 ;
9056
                ok     = 0 ;
9057
                disable main ;
9058
            end
9059
        end
9060
 
9061
        deadlock_counter = 0 ;
9062
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
9063
        begin
9064
            deadlock_counter = deadlock_counter + 1 ;
9065
            @(posedge pci_clock) ;
9066
        end
9067
 
9068
        if ( FRAME !== 0 )
9069
        begin
9070
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9071
            in_use = 0 ;
9072
            ok     = 0 ;
9073
            disable main ;
9074
        end
9075
    end //wait_start
9076
 
9077
    begin:addr_bc_monitor
9078
 
9079
        @(posedge pci_clock) ;
9080
 
9081
        if ( doing_fast_back_to_back !== 1 )
9082
        begin
9083
            while ( FRAME !== 1 )
9084
                @(posedge pci_clock) ;
9085
        end
9086
 
9087
        while( FRAME !== 0 )
9088
            @(posedge pci_clock) ;
9089
 
9090
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
9091
        if ( bus_command !== `BC_IACK )
9092
        begin
9093
            if ( AD !== address )
9094
            begin
9095
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
9096
                $display("Expected address = %h, detected address = %h ", address, AD) ;
9097
                ok = 0 ;
9098
            end
9099
        end
9100
 
9101
        if ( CBE !== bus_command )
9102
        begin
9103
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
9104
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
9105
            ok = 0 ;
9106
        end
9107
    end //addr_bc_monitor
9108
 
9109
    begin:transfer_checker
9110
        transfer_counter = 0 ;
9111
 
9112
        @(posedge pci_clock) ;
9113
 
9114
        if ( doing_fast_back_to_back !== 1 )
9115
        begin
9116
            while ( FRAME !== 1 )
9117
                @(posedge pci_clock) ;
9118
        end
9119
 
9120
        while( FRAME !== 0 )
9121
            @(posedge pci_clock) ;
9122
 
9123
        while( FRAME === 0 )
9124
        begin
9125
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
9126
                transfer_counter = transfer_counter + 1 ;
9127
            @(posedge pci_clock) ;
9128
        end
9129
 
9130
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
9131
        begin
9132
            @(posedge pci_clock) ;
9133
        end
9134
 
9135
        if ( (TRDY === 0) && (DEVSEL === 0) )
9136
                transfer_counter = transfer_counter + 1 ;
9137
 
9138
        if ( check_transfers === 1 )
9139
        begin
9140
            if ( transfer_counter !== num_of_transfers )
9141
            begin
9142
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9143
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9144
                ok = 0 ;
9145
            end
9146
        end
9147
    end //transfer_checker
9148
    begin:cycle_checker
9149
        if ( check_cycles )
9150
        begin
9151
            cycle_counter = 0 ;
9152
            @(posedge pci_clock) ;
9153
 
9154
            if ( doing_fast_back_to_back !== 1)
9155
            begin
9156
                while ( FRAME !== 1 )
9157
                    @(posedge pci_clock) ;
9158
            end
9159
 
9160
            while( FRAME !== 0 )
9161
                @(posedge pci_clock) ;
9162
 
9163
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9164
            begin
9165
                cycle_counter = cycle_counter + 1 ;
9166
                @(posedge pci_clock) ;
9167
            end
9168
 
9169
            if ( FRAME !== 1 )
9170
            begin
9171
                while ((FRAME === 0) && (MAS0_GNT === 0))
9172
                    @(posedge pci_clock) ;
9173
 
9174
                if ( FRAME !== 1 )
9175
                begin
9176
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9177
                        @(posedge pci_clock) ;
9178
 
9179
                    @(posedge pci_clock) ;
9180
 
9181
                    if ( FRAME !== 1 )
9182
                    begin
9183
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9184
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9185
                        ok = 0 ;
9186
                    end
9187
                end
9188
            end
9189
        end
9190
    end // cycle_checker
9191
    join
9192
 
9193
    in_use = 0 ;
9194
end
9195
endtask //pci_transaction_progress_monitor
9196
 
9197
reg CYC_O_previous ;
9198
always@(posedge wb_clock or posedge reset)
9199
begin
9200
    if ( reset )
9201
        CYC_O_previous <= #1 1'b0 ;
9202
    else
9203
        CYC_O_previous <= #1 CYC_O ;
9204
end
9205
 
9206
task wb_transaction_progress_monitor ;
9207
    input [31:0] address ;
9208
    input        write ;
9209
    input [31:0] num_of_transfers ;
9210
    input check_transfers ;
9211
    output ok ;
9212
    reg in_use ;
9213
    integer deadlock_counter ;
9214
    integer transfer_counter ;
9215
    integer deadlock_max_val ;
9216 73 mihad
    reg [2:0] slave_termination ;
9217
    reg       cab_asserted ;
9218 15 mihad
begin:main
9219
    if ( in_use === 1 )
9220
    begin
9221
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9222
        ok = 0 ;
9223
        disable main ;
9224
    end
9225
 
9226
    // number of cycles on WB bus for maximum transaction length
9227
    deadlock_max_val = 4 - tb_init_waits + 100 +
9228
                       `PCIW_DEPTH *
9229
                       (4 - tb_subseq_waits + 1) ;
9230
 
9231
    // time used for maximum transaction length on PCI
9232
    `ifdef PCI33
9233
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9234
    `else
9235
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9236
    `endif
9237
 
9238
    // maximum wb clock cycles
9239
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9240
 
9241 73 mihad
    in_use       = 1 ;
9242
    ok           = 1 ;
9243
    cab_asserted = 0 ;
9244 15 mihad
 
9245
    fork
9246
    begin:wait_start
9247
        deadlock_counter = 0 ;
9248
        @(posedge wb_clock) ;
9249
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9250
        begin
9251 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9252
                deadlock_counter = deadlock_counter + 1 ;
9253
            else
9254
                deadlock_counter = 0;
9255 15 mihad
            @(posedge wb_clock) ;
9256
        end
9257
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9258
        begin
9259
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9260
            in_use = 0 ;
9261
            ok     = 0 ;
9262
            disable main ;
9263
        end
9264
 
9265
        deadlock_counter = 0 ;
9266
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9267
        begin
9268
            deadlock_counter = deadlock_counter + 1 ;
9269
            @(posedge wb_clock) ;
9270
        end
9271
 
9272
        if ( CYC_O !== 1 )
9273
        begin
9274
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9275
            in_use = 0 ;
9276
            ok     = 0 ;
9277
            disable main ;
9278
        end
9279
    end //wait_start
9280
    begin:addr_monitor
9281
        @(posedge wb_clock) ;
9282
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9283
            @(posedge wb_clock) ;
9284
 
9285
        while( CYC_O !== 1 )
9286
            @(posedge wb_clock) ;
9287
 
9288
        while (STB_O !== 1 )
9289
            @(posedge wb_clock) ;
9290
 
9291
        if ( WE_O !== write )
9292
        begin
9293
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9294
            if ( write !== 1 )
9295
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9296
            else
9297
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9298
        end
9299
 
9300
        if ( ADR_O !== address )
9301
        begin
9302
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9303
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9304
            ok = 0 ;
9305
        end
9306
    end
9307
    begin:transfer_checker
9308
        transfer_counter = 0 ;
9309
        @(posedge wb_clock) ;
9310
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9311
            @(posedge wb_clock) ;
9312
 
9313
        while( CYC_O !== 1 )
9314
            @(posedge wb_clock) ;
9315
 
9316 63 mihad
        while( (CYC_O === 1) && ((transfer_counter <= `PCIW_DEPTH) || (transfer_counter <= `PCIR_DEPTH)) )
9317 15 mihad
        begin
9318 73 mihad
 
9319
            if (!cab_asserted)
9320
                cab_asserted = (CAB_O !== 1'b0) ;
9321
 
9322
            if (STB_O === 1)
9323
            begin
9324
                slave_termination = {ACK_I, ERR_I, RTY_I} ;
9325
                if (ACK_I)
9326
                    transfer_counter = transfer_counter + 1 ;
9327
            end
9328 15 mihad
            @(posedge wb_clock) ;
9329
        end
9330
 
9331 73 mihad
        if (cab_asserted)
9332
        begin
9333
            // cab was sampled asserted
9334
            // if number of transfers was less than 2 - check for extraordinary terminations
9335
            if (transfer_counter < 2)
9336
            begin
9337
                // 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.
9338
                // any other cases are wrong
9339
                case (slave_termination)
9340
                3'b000:begin end
9341
                3'b001:begin end
9342
                3'b010:begin end
9343
                default:begin
9344
                            ok = 0 ;
9345
                            $display("Time %t", $time) ;
9346
                            $display("WB_MASTER asserted CAB_O for single transfer") ;
9347
                        end
9348
                endcase
9349
            end
9350
        end
9351
        else
9352
        begin
9353
            // if cab is not asserted, then WB_MASTER should not read more than one data.
9354
            if (transfer_counter > 1)
9355
            begin
9356
                ok = 0 ;
9357
                $display("Time %t", $time) ;
9358
                $display("WB_MASTER didn't assert CAB_O for consecutive block transfer") ;
9359
            end
9360
        end
9361
 
9362 15 mihad
        if ( check_transfers === 1 )
9363
        begin
9364
            if ( transfer_counter !== num_of_transfers )
9365
            begin
9366
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9367
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9368
                ok = 0 ;
9369
            end
9370
        end
9371
    end //transfer_checker
9372
    join
9373
 
9374
    in_use = 0 ;
9375
end
9376
endtask // wb_transaction_progress_monitor
9377
 
9378
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9379
// so they are not re-entered
9380
task wb_transaction_progress_monitor_backup ;
9381
    input [31:0] address ;
9382
    input        write ;
9383
    input [31:0] num_of_transfers ;
9384
    input check_transfers ;
9385
    output ok ;
9386
    reg in_use ;
9387
    integer deadlock_counter ;
9388
    integer transfer_counter ;
9389
    integer deadlock_max_val ;
9390
begin:main
9391
    if ( in_use === 1 )
9392
    begin
9393
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9394
        ok = 0 ;
9395
        disable main ;
9396
    end
9397
 
9398
    // number of cycles on WB bus for maximum transaction length
9399
    deadlock_max_val = 4 - tb_init_waits + 100 +
9400
                       `PCIW_DEPTH *
9401
                       (4 - tb_subseq_waits + 1) ;
9402
 
9403
    // time used for maximum transaction length on PCI
9404
    `ifdef PCI33
9405
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9406
    `else
9407
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9408
    `endif
9409
 
9410
    // maximum wb clock cycles
9411
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9412
 
9413
    in_use = 1 ;
9414
    ok     = 1 ;
9415
 
9416
    fork
9417
    begin:wait_start
9418
        deadlock_counter = 0 ;
9419
        @(posedge wb_clock) ;
9420
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9421
        begin
9422 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9423
                deadlock_counter = deadlock_counter + 1 ;
9424
            else
9425
                deadlock_counter = 0;
9426 15 mihad
            @(posedge wb_clock) ;
9427
        end
9428
        if ( CYC_O !== 0 )
9429
        begin
9430
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9431
            in_use = 0 ;
9432
            ok     = 0 ;
9433
            disable main ;
9434
        end
9435
 
9436
        deadlock_counter = 0 ;
9437
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9438
        begin
9439
            deadlock_counter = deadlock_counter + 1 ;
9440
            @(posedge wb_clock) ;
9441
        end
9442
 
9443
        if ( CYC_O !== 1 )
9444
        begin
9445
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9446
            in_use = 0 ;
9447
            ok     = 0 ;
9448
            disable main ;
9449
        end
9450
    end //wait_start
9451
    begin:addr_monitor
9452
        @(posedge wb_clock) ;
9453
        while ( CYC_O !== 0 )
9454
            @(posedge wb_clock) ;
9455
 
9456
        while( CYC_O !== 1 )
9457
            @(posedge wb_clock) ;
9458
 
9459
        while (STB_O !== 1 )
9460
            @(posedge wb_clock) ;
9461
 
9462
        if ( WE_O !== write )
9463
        begin
9464
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9465
            if ( write !== 1 )
9466
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9467
            else
9468
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9469
        end
9470
 
9471
        if ( ADR_O !== address )
9472
        begin
9473
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9474
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9475
            ok = 0 ;
9476
        end
9477
    end
9478
    begin:transfer_checker
9479
        transfer_counter = 0 ;
9480
        @(posedge wb_clock) ;
9481
        while ( CYC_O !== 0 )
9482
            @(posedge wb_clock) ;
9483
 
9484
        while( CYC_O !== 1 )
9485
            @(posedge wb_clock) ;
9486
 
9487
        while( CYC_O === 1 )
9488
        begin
9489
            if ( (STB_O === 1) && (ACK_I === 1) )
9490
                transfer_counter = transfer_counter + 1 ;
9491
            @(posedge wb_clock) ;
9492
        end
9493
 
9494
        if ( check_transfers === 1 )
9495
        begin
9496
            if ( transfer_counter !== num_of_transfers )
9497
            begin
9498
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9499
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9500
                ok = 0 ;
9501
            end
9502
        end
9503
    end //transfer_checker
9504
    join
9505
 
9506
    in_use = 0 ;
9507
end
9508
endtask // wb_transaction_progress_monitor_backup
9509
 
9510
task wb_transaction_stop ;
9511
    input [31:0] num_of_transfers ;
9512
    integer transfer_counter ;
9513
begin:main
9514
    begin:transfer_checker
9515
        transfer_counter = 0 ;
9516
        @(posedge wb_clock) ;
9517
        while ( CYC_O !== 0 )
9518
            @(posedge wb_clock) ;
9519
 
9520
        while( CYC_O !== 1 )
9521
            @(posedge wb_clock) ;
9522
 
9523
        if ( (STB_O === 1) && (ACK_I === 1) )
9524
            transfer_counter = transfer_counter + 1 ;
9525
 
9526
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9527
        begin
9528
            @(posedge wb_clock) ;
9529
            if ( (STB_O === 1) && (ACK_I === 1) )
9530
                transfer_counter = transfer_counter + 1 ;
9531
        end
9532
    end //transfer_checker
9533
end
9534
endtask // wb_transaction_stop
9535
 
9536
task musnt_respond ;
9537
    output ok ;
9538
    reg in_use ;
9539
    integer i ;
9540
begin:main
9541
    if ( in_use === 1 )
9542
    begin
9543
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9544
        #20 $stop ;
9545
        ok = 0 ;
9546
        disable main ;
9547
    end
9548
 
9549
    in_use = 1 ;
9550
    ok = 1 ;
9551
 
9552
    fork
9553
    begin:wait_start
9554
        @(negedge FRAME) ;
9555
        disable count ;
9556
    end
9557
    begin:count
9558
        i = 0 ;
9559
        while ( i < 1000 )
9560
        begin
9561
            @(posedge pci_clock) ;
9562
            i = i + 1 ;
9563
        end
9564
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9565
        ok = 0 ;
9566
        disable wait_start ;
9567
    end
9568
    join
9569
 
9570
    @(posedge pci_clock) ;
9571
    while ( FRAME === 0 && ok )
9572
    begin
9573
        if ( DEVSEL !== 1 )
9574
        begin
9575
            ok = 0 ;
9576
        end
9577
        @(posedge pci_clock) ;
9578
    end
9579
 
9580
    while ( IRDY === 0 && ok )
9581
    begin
9582
        if ( DEVSEL !== 1 )
9583
        begin
9584
            ok = 0 ;
9585
        end
9586
        @(posedge pci_clock) ;
9587
    end
9588
    in_use = 0 ;
9589
end
9590
endtask
9591
 
9592
function [31:0] wb_to_pci_addr_convert ;
9593
    input [31:0] wb_address ;
9594
    input [31:0] translation_address ;
9595
    input [31:0] translate ;
9596
 
9597
    reg   [31:0] temp_address ;
9598
begin
9599
    if ( translate !== 1 )
9600
    begin
9601
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9602
    end
9603
    else
9604
    begin
9605
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9606
    end
9607
 
9608
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9609
    wb_to_pci_addr_convert = temp_address ;
9610
end
9611
endfunction //wb_to_pci_addr_convert
9612
 
9613 45 mihad
`ifdef HOST
9614 15 mihad
task find_pci_devices ;
9615
    integer device_num ;
9616
    reg     found ;
9617
    reg [11:0] pci_ctrl_offset ;
9618
    reg ok ;
9619
    reg [31:0] data ;
9620 45 mihad
    reg [31:0] expected_data ;
9621
 
9622
    reg [5:0]  reg_num ;
9623 15 mihad
begin:main
9624 45 mihad
 
9625
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9626 15 mihad
    pci_ctrl_offset = 12'h004 ;
9627
 
9628
    // enable master & target operation
9629
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9630
 
9631
    if ( ok !== 1 )
9632
    begin
9633
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9634 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9635 15 mihad
        disable main ;
9636
    end
9637
    // find all possible devices on pci bus by performing configuration cycles
9638 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9639 15 mihad
    begin
9640
        find_device ( device_num, found ) ;
9641
 
9642
        // check pci status register - if device is not present, Received Master Abort bit must be set
9643
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9644
 
9645
        if ( (data[29] !== 0) && (found !== 0) )
9646 45 mihad
        begin
9647 15 mihad
            $display( "Time %t ", $time ) ;
9648
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9649
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9650 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9651
            ok = 0 ;
9652 15 mihad
        end
9653
 
9654
        if ( (data[29] !== 1) && (found !== 1) )
9655
        begin
9656
            $display( "Time %t ", $time ) ;
9657
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9658
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9659 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9660
            ok = 0 ;
9661 15 mihad
        end
9662
 
9663
        // clear Master Abort status if set
9664
        if ( data[29] !== 0 )
9665
        begin
9666
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9667
        end
9668 45 mihad
 
9669
        if (found === 1)
9670
        begin
9671
            // first check if found target is supposed to exist
9672
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9673
            begin
9674
                $display("Time %t", $time) ;
9675
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9676
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9677
                ok = 0 ;
9678
            end
9679
            else
9680
            begin
9681
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9682
                begin
9683
 
9684
                    data = 32'hFFFF_FFFF ;
9685
 
9686
                    expected_data = 0 ;
9687
 
9688
                    if (reg_num == 4)
9689
                    begin
9690
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9691
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9692
                    end
9693
                    else if (reg_num == 5)
9694
                    begin
9695
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9696
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9697
                    end
9698
 
9699
                    // write base address 0
9700
                    generate_configuration_cycle
9701
                    (
9702
                        'h0,            //bus_num
9703
                        device_num,     //device_num
9704
                        'h0,            //func_num
9705
                        reg_num,        //reg_num
9706
                        'h0,            //type
9707
                        4'hF,           // byte_enables
9708
                        data,           //data
9709
                        1'b1            //read0_write1
9710
                    );
9711
 
9712
                    // read data back
9713
                    generate_configuration_cycle
9714
                    (
9715
                        'h0,            //bus_num
9716
                        device_num,     //device_num
9717
                        'h0,            //func_num
9718
                        reg_num,        //reg_num
9719
                        'h0,            //type
9720
                        4'hF,           // byte_enables
9721
                        data,           //data
9722
                        1'b0            //read0_write1
9723
                    );
9724
 
9725
                    if (data !== expected_data)
9726
                    begin
9727
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9728
                        $display("Data read back not as expected!");
9729
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9730
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9731
                        ok = 0 ;
9732
                    end
9733
                end
9734
            end
9735
        end
9736 15 mihad
    end
9737 45 mihad
 
9738
    if (ok)
9739
        test_ok ;
9740 15 mihad
end //main
9741
endtask //find_pci_devices
9742
 
9743
task find_device ;
9744
    input [31:0] device_num ;
9745
    output  found ;
9746
 
9747
    reg [31:0] read_data ;
9748
begin
9749
    found = 1'b0 ;
9750
 
9751
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9752 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9753 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9754
    else
9755
    begin
9756
        $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]) ;
9757
        found = 1'b1 ;
9758
    end
9759
end
9760
endtask //find_device
9761 45 mihad
`endif
9762 15 mihad
 
9763
/*task set_bridge_parameters ;
9764
    reg [11:0] current_offset ;
9765
    reg [2:0] result ;
9766
    reg [31:0] write_data ;
9767
begin
9768
    // set burst size
9769
    // set latency timer
9770
    current_offset = 12'h00C ;
9771
    // set burst size to 16 and latency timer to 8
9772
    write_data     = {24'h0000_08, system_burst_size} ;
9773
    config_write(current_offset, write_data, 4'b1111) ;
9774
 
9775
    // set io image
9776
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9777
    write_data = 32'h0000_000_3 ;
9778
    config_write(current_offset, write_data, 4'b1111) ;
9779
 
9780
 
9781
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9782
    write_data = 32'h0001_000_1 ;
9783
    config_write(current_offset, write_data, 4'b1111) ;
9784
 
9785
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9786
    write_data = 32'hFFFF_0000 ;
9787
    config_write(current_offset, write_data, 4'b1111) ;
9788
 
9789
    // set memory image
9790
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9791
    write_data = 32'h0000_000_7 ;
9792
    config_write(current_offset, write_data, 4'b1111) ;
9793
 
9794
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9795
    write_data = 32'h0002_000_0 ;
9796
    config_write(current_offset, write_data, 4'b1111) ;
9797
 
9798
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9799
    write_data = 32'h0001_0000 ;
9800
    config_write(current_offset, write_data, 4'b1111) ;
9801
 
9802
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9803
    write_data = 32'hFFFF_0000 ;
9804
    config_write(current_offset, write_data, 4'b1111) ;
9805
 
9806
    // set parameters for bridge's target unit
9807
    // image control 0
9808
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9809
    write_data     = 32'h0000_0002 ;
9810
    config_write(current_offset, write_data, 4'b0001) ;
9811
 
9812
    // base_address 0
9813
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9814
    write_data      = 32'h2000_0000 ;
9815
    config_write(current_offset, write_data, 4'b1111) ;
9816
 
9817
    // address mask 0
9818
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9819
    write_data     = 32'hFFFF_F000 ;
9820
    config_write(current_offset, write_data, 4'b1111) ;
9821
 
9822
    // command register - enable response to io and mem space and PCI master
9823
    current_offset = 12'h004 ;
9824
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9825
    config_write(current_offset, write_data, 4'b1111) ;
9826
end
9827
endtask // set_bridge_parameters
9828
*/
9829
 
9830
task configuration_cycle_write ;
9831
    input [7:0]  bus_num ;
9832
    input [4:0]  device_num ;
9833
    input [2:0]  func_num ;
9834
    input [5:0]  reg_num ;
9835
    input [1:0]  type ;
9836
    input [3:0]  byte_enables ;
9837
    input [31:0] data ;
9838
 
9839
    reg [31:0] write_address ;
9840
    reg in_use ;
9841
    reg ok ;
9842
begin:main
9843
 
9844
    if ( in_use === 1 )
9845
    begin
9846 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9847 15 mihad
        disable main ;
9848
    end
9849
 
9850 45 mihad
    if ( (device_num > 20) && (type === 0) )
9851 15 mihad
    begin
9852
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9853
        disable main ;
9854
    end
9855
 
9856
    in_use = 1 ;
9857
 
9858 45 mihad
 
9859
`ifdef HOST
9860
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9861
`else
9862
`ifdef GUEST
9863
 
9864 15 mihad
    if ( type )
9865
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9866
    else
9867
    begin
9868
        write_address = 0 ;
9869
        write_address[10:0] = { func_num, reg_num, type } ;
9870
        write_address[11 + device_num] = 1'b1 ;
9871
    end
9872 45 mihad
 
9873
    fork
9874 15 mihad
    begin
9875 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9876
                            write_address,
9877
                            data, ~byte_enables,
9878
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9879
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9880
        do_pause(1) ;
9881 15 mihad
    end
9882 45 mihad
    begin
9883
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9884
    end
9885
    join
9886
`endif
9887
`endif
9888
 
9889
    in_use = 0 ;
9890
end
9891
endtask // configuration_cycle_write
9892 15 mihad
 
9893 45 mihad
task configuration_cycle_read ;
9894
    input [7:0]  bus_num ;
9895
    input [4:0]  device_num ;
9896
    input [2:0]  func_num ;
9897
    input [5:0]  reg_num ;
9898
    input [1:0]  type ;
9899
    input [3:0]  byte_enables ;
9900
    output [31:0] data ;
9901 15 mihad
 
9902 45 mihad
    reg [31:0] read_address ;
9903
    reg in_use ;
9904 15 mihad
 
9905 45 mihad
    reg master_check_data_prev ;
9906
begin:main
9907 15 mihad
 
9908 45 mihad
    if ( in_use === 1 )
9909 15 mihad
    begin
9910 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9911
        data = 32'hxxxx_xxxx ;
9912
        disable main ;
9913 15 mihad
    end
9914
 
9915 45 mihad
    in_use = 1 ;
9916 15 mihad
 
9917 45 mihad
`ifdef HOST
9918
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9919
`else
9920
`ifdef GUEST
9921
     master_check_data_prev = master1_check_received_data ;
9922 15 mihad
     if ( type )
9923 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9924 15 mihad
     else
9925
     begin
9926 45 mihad
         read_address = 0 ;
9927
         read_address[10:0] = { func_num, reg_num, type } ;
9928
         read_address[11 + device_num] = 1'b1 ;
9929 15 mihad
     end
9930 45 mihad
 
9931
     fork
9932
     begin
9933
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9934
                 read_address,
9935 15 mihad
                 data, ~byte_enables,
9936
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9937
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9938 45 mihad
         do_pause(1) ;
9939
     end
9940
     begin
9941
         @(master1_received_data_valid) ;
9942
         data = master1_received_data ;
9943
     end
9944
     join
9945 15 mihad
 
9946 45 mihad
    master1_check_received_data = master_check_data_prev ;
9947
`endif
9948
`endif
9949
 
9950 15 mihad
    in_use = 0 ;
9951
 
9952 45 mihad
end //main
9953
endtask // configuration_cycle_read
9954
 
9955 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9956
task test_conf_cycle_type1_reference ;
9957
    reg [31:0] address ;
9958
    reg in_use ;
9959
 
9960
    reg master_check_data_prev ;
9961
    reg [31:0] data ;
9962
    reg monitor_ok ;
9963
    reg master_ok ;
9964
begin:main
9965
 
9966
    if ( in_use === 1 )
9967
    begin
9968
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9969
        disable main ;
9970
    end
9971
 
9972
    in_use = 1 ;
9973
 
9974
    master_check_data_prev = master1_check_received_data ;
9975
 
9976
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9977
    address = `TAR0_IDSEL_ADDR ;
9978
 
9979
    address[1:0] = 2'b01 ;
9980
 
9981
    `ifdef HOST
9982
        conf_cyc_type1_target_bus_num = 255 ;
9983
    `endif
9984
    master_ok = 1 ;
9985
    fork
9986
    begin
9987
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9988
        do_pause(1) ;
9989
    end
9990
    begin:error_monitor1
9991
        @(error_event_int) ;
9992
        master_ok = 0 ;
9993
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9994
    end
9995
    begin
9996
        pci_transaction_progress_monitor
9997
        (
9998
            address,                                                // expected address on PCI bus
9999
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10000
            0,                                                      // expected number of succesfull data phases
10001
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10002
            1'b1,                                                   // monitor checking/not checking number of transfers
10003
            1'b0,                                                   // monitor checking/not checking number of cycles
10004
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10005
            monitor_ok                                              // status - 1 success, 0 failure
10006
        ) ;
10007
 
10008
        @(posedge pci_clock);
10009
        #1 ;
10010
 
10011
        if (master_ok)
10012
            disable error_monitor1 ;
10013
 
10014
        if (!monitor_ok)
10015
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10016
    end
10017
    join
10018
 
10019
    if (monitor_ok && master_ok)
10020
        test_ok ;
10021
 
10022
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
10023
    master_ok = 1 ;
10024
    fork
10025
    begin
10026
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
10027
        do_pause(1) ;
10028
    end
10029
    begin:error_monitor2
10030
        @(error_event_int) ;
10031
        master_ok = 0 ;
10032
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
10033
    end
10034
    begin
10035
        pci_transaction_progress_monitor
10036
        (
10037
            address,                                                // expected address on PCI bus
10038
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10039
            0,                                                      // expected number of succesfull data phases
10040
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10041
            1'b1,                                                   // monitor checking/not checking number of transfers
10042
            1'b0,                                                   // monitor checking/not checking number of cycles
10043
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10044
            monitor_ok                                              // status - 1 success, 0 failure
10045
        ) ;
10046
 
10047
        @(posedge pci_clock);
10048
        #1 ;
10049
 
10050
        if (master_ok)
10051
            disable error_monitor2 ;
10052
 
10053
        if (!monitor_ok)
10054
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10055
    end
10056
    join
10057
 
10058
    master1_check_received_data = master_check_data_prev ;
10059
 
10060
    if (monitor_ok && master_ok)
10061
        test_ok ;
10062
 
10063
    in_use = 0 ;
10064
 
10065
end //main
10066
endtask // test_conf_cycle_type1_reference
10067
`endif
10068
 
10069 45 mihad
`ifdef HOST
10070
task generate_configuration_cycle ;
10071 15 mihad
    input [7:0]  bus_num ;
10072
    input [4:0]  device_num ;
10073
    input [2:0]  func_num ;
10074
    input [5:0]  reg_num ;
10075
    input [1:0]  type ;
10076
    input [3:0]  byte_enables ;
10077 45 mihad
    inout [31:0] data ;
10078
    input        read0_write1 ;
10079 15 mihad
 
10080
    reg `READ_STIM_TYPE read_data ;
10081
    reg `WB_TRANSFER_FLAGS  flags ;
10082
    reg `READ_RETURN_TYPE   read_status ;
10083
 
10084
    reg `WRITE_STIM_TYPE   write_data ;
10085
    reg `WRITE_RETURN_TYPE write_status ;
10086
 
10087 45 mihad
    reg [31:0] pci_address ;
10088 15 mihad
    reg in_use ;
10089 45 mihad
    reg ok ;
10090 15 mihad
 
10091
    reg [31:0] temp_var ;
10092
begin:main
10093
 
10094
    if ( in_use === 1 )
10095
    begin
10096 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
10097 15 mihad
        data = 32'hxxxx_xxxx ;
10098
        disable main ;
10099
    end
10100
 
10101 45 mihad
    in_use = 1 ;
10102
 
10103
    if ( type )
10104
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10105
    else
10106 15 mihad
    begin
10107 45 mihad
        pci_address = 0 ;
10108
        pci_address[10:0] = { func_num, reg_num, type } ;
10109
        if (device_num <= 20)
10110
            pci_address[11 + device_num] = 1'b1 ;
10111
    end
10112
 
10113
    // setup flags
10114
    flags = 0 ;
10115
    flags`INIT_WAITS   = tb_init_waits ;
10116
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10117
 
10118
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10119
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10120
 
10121
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10122
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10123
    write_data`WRITE_SEL      = 4'hF ;
10124
    write_data`WRITE_TAG_STIM = 0 ;
10125
 
10126
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10127
 
10128
    // check if write succeeded
10129
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10130
    begin
10131
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10132 15 mihad
        data = 32'hxxxx_xxxx ;
10133 45 mihad
        in_use = 0 ;
10134 15 mihad
        disable main ;
10135
    end
10136
 
10137 45 mihad
    // setup flags for wb master to handle retries and read and write data
10138
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10139
 
10140
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10141
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10142
    read_data`READ_SEL          = byte_enables ;
10143
    write_data`WRITE_SEL        = byte_enables ;
10144
    read_data`READ_TAG_STIM     = 0 ;
10145
    write_data`WRITE_TAG_STIM   = 0 ;
10146
    write_data`WRITE_DATA       = data ;
10147
 
10148
    ok = 0 ;
10149
 
10150
    fork
10151
    begin
10152
        if (read0_write1 === 0)
10153
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
10154
        else
10155
        if (read0_write1 === 1)
10156
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
10157
    end
10158
    begin
10159
        pci_transaction_progress_monitor
10160
        (
10161
            pci_address,                                            // expected address on PCI bus
10162
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10163
            1,                                                      // expected number of succesfull data phases
10164
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10165
            1'b0,                                                   // monitor checking/not checking number of transfers
10166
            1'b0,                                                   // monitor checking/not checking number of cycles
10167
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10168
            ok                                                      // status - 1 success, 0 failure
10169
        ) ;
10170
    end
10171
    join
10172
 
10173
    // check if transfer succeeded
10174
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10175
    begin
10176
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10177
        data = 32'hxxxx_xxxx ;
10178
        in_use = 0 ;
10179
        disable main ;
10180
    end
10181
 
10182
    if (!ok)
10183
    begin
10184
        data = 32'hxxxx_xxxx ;
10185
        in_use = 0 ;
10186
        disable main ;
10187
    end
10188
 
10189
    if (read0_write1 === 0)
10190
        data = read_status`READ_DATA ;
10191
 
10192
    in_use = 0 ;
10193
end
10194
endtask // generate_configuration_cycle
10195
 
10196
task test_configuration_cycle_target_abort ;
10197
    reg `READ_STIM_TYPE read_data ;
10198
    reg `WB_TRANSFER_FLAGS  flags ;
10199
    reg `READ_RETURN_TYPE   read_status ;
10200
 
10201
    reg `WRITE_STIM_TYPE   write_data ;
10202
    reg `WRITE_RETURN_TYPE write_status ;
10203
 
10204
    reg [31:0] pci_address ;
10205
    reg in_use ;
10206
    reg ok_pci ;
10207
    reg ok_wb  ;
10208
    reg ok     ;
10209
 
10210
    reg [31:0] temp_var ;
10211
 
10212
begin:main
10213
 
10214
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10215
 
10216
    if ( in_use === 1 )
10217
    begin
10218
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10219
        disable main ;
10220
    end
10221
 
10222 15 mihad
    in_use = 1 ;
10223
 
10224 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10225
 
10226 15 mihad
    // setup flags
10227
    flags = 0 ;
10228 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10229
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10230 15 mihad
 
10231
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10232
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10233
 
10234
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10235 45 mihad
    temp_var                  = 0 ;
10236
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10237
    write_data`WRITE_DATA     = temp_var ;
10238 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10239
    write_data`WRITE_TAG_STIM = 0 ;
10240
 
10241
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10242
 
10243
    // check if write succeeded
10244
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10245
    begin
10246
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10247 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10248
        in_use = 0 ;
10249 15 mihad
        disable main ;
10250
    end
10251
 
10252 45 mihad
    // setup flags for wb master to handle retries and read and write data
10253 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10254
 
10255 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10256
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10257 15 mihad
 
10258 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10259
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10260
    read_data`READ_SEL          = 4'hF ;
10261
    write_data`WRITE_SEL        = 4'hF ;
10262
    read_data`READ_TAG_STIM     = 0 ;
10263
    write_data`WRITE_TAG_STIM   = 0 ;
10264
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10265
 
10266
    ok_pci = 0 ;
10267
    ok_wb  = 1 ;
10268
 
10269
    // set target to terminate with target abort
10270
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10271
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10272
    fork
10273
    begin
10274
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10275
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10276
        begin
10277
            $display("Time %t", $time) ;
10278
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10279
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10280
            ok_wb = 0 ;
10281
        end
10282
 
10283
        config_read( 12'h4, 4'hF, temp_var ) ;
10284
        if ( temp_var[29] !== 0 )
10285
        begin
10286
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10287
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10288
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10289
            ok_wb = 0 ;
10290
        end
10291
 
10292
        if ( temp_var[28] !== 1 )
10293
        begin
10294
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10295
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10296
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10297
            ok_wb = 0 ;
10298
        end
10299
 
10300
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10301
 
10302
        if (ok !== 1)
10303
        begin
10304
            ok_wb = 0 ;
10305
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10306
            $display("Write to PCI Device Status Register failed") ;
10307
            test_fail("Write to PCI Device Status Register failed") ;
10308
        end
10309
 
10310
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10311
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10312
        begin
10313
            $display("Time %t", $time) ;
10314
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10315
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10316
            ok_wb = 0 ;
10317
        end
10318
 
10319
        config_read( 12'h4, 4'hF, temp_var ) ;
10320
        if ( temp_var[29] !== 0 )
10321
        begin
10322
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10323
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10324
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10325
            ok_wb = 0 ;
10326
        end
10327
 
10328
        if ( temp_var[28] !== 1 )
10329
        begin
10330
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10331
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10332
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10333
            ok_wb = 0 ;
10334
        end
10335
 
10336
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10337
 
10338
        if (ok !== 1)
10339
        begin
10340
            ok_wb = 0 ;
10341
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10342
            $display("Write to PCI Device Status Register failed") ;
10343
            test_fail("Write to PCI Device Status Register failed") ;
10344
        end
10345
    end
10346
    begin
10347
        pci_transaction_progress_monitor
10348
        (
10349
            pci_address,                                            // expected address on PCI bus
10350
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10351
            0,                                                      // expected number of succesfull data phases
10352
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10353
            1'b1,                                                   // monitor checking/not checking number of transfers
10354
            1'b0,                                                   // monitor checking/not checking number of cycles
10355
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10356
            ok_pci                                                  // status - 1 success, 0 failure
10357
        ) ;
10358
 
10359
        if (ok_pci)
10360
        begin
10361
            pci_transaction_progress_monitor
10362
            (
10363
                pci_address,                                            // expected address on PCI bus
10364
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10365
                0,                                                      // expected number of succesfull data phases
10366
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10367
                1'b1,                                                   // monitor checking/not checking number of transfers
10368
                1'b0,                                                   // monitor checking/not checking number of cycles
10369
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10370
                ok_pci                                                  // status - 1 success, 0 failure
10371
            ) ;
10372
        end
10373
 
10374
        if (!ok_pci)
10375
        begin
10376
            $display("Time %t", $time) ;
10377
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10378
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10379
        end
10380
    end
10381
    join
10382
 
10383
    if (ok_pci && ok_wb)
10384
    begin
10385
        test_ok ;
10386
    end
10387
 
10388
    in_use = 0 ;
10389
 
10390
    // set target to terminate normally
10391
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10392
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10393
end
10394
endtask // test_configuration_cycle_target_abort
10395
 
10396
task test_configuration_cycle_type1_generation ;
10397
    reg `READ_STIM_TYPE read_data ;
10398
    reg `WB_TRANSFER_FLAGS  flags ;
10399
    reg `READ_RETURN_TYPE   read_status ;
10400
 
10401
    reg `WRITE_STIM_TYPE   write_data ;
10402
    reg `WRITE_RETURN_TYPE write_status ;
10403
 
10404
    reg [31:0] pci_address ;
10405
    reg in_use ;
10406
    reg ok_pci ;
10407
    reg ok_wb  ;
10408
    reg ok     ;
10409
 
10410
    reg [31:0] temp_var ;
10411
 
10412
begin:main
10413
 
10414
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10415
    conf_cyc_type1_target_data = 0 ;
10416
    conf_cyc_type1_target_bus_num = 0;
10417
 
10418
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10419
 
10420
    if ( in_use === 1 )
10421
    begin
10422
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10423
        disable main ;
10424
    end
10425
 
10426
    in_use = 1 ;
10427
 
10428
    pci_address        = 32'hAAAA_AAAA ;
10429
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10430
 
10431
    // setup flags
10432
    flags = 0 ;
10433
    flags`INIT_WAITS   = tb_init_waits ;
10434
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10435
 
10436
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10437
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10438
 
10439
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10440
    write_data`WRITE_DATA     = pci_address ;
10441
    write_data`WRITE_SEL      = 4'hF ;
10442
    write_data`WRITE_TAG_STIM = 0 ;
10443
 
10444
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10445
 
10446
    // check if write succeeded
10447
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10448
    begin
10449
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10450
        test_fail("write to configuration cycle address register was not possible") ;
10451
        in_use = 0 ;
10452
        disable main ;
10453
    end
10454
 
10455
    // setup flags for wb master to handle retries and read and write data
10456
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10457
 
10458
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10459
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10460
 
10461
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10462
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10463
    read_data`READ_SEL          = 4'hF ;
10464
    write_data`WRITE_SEL        = 4'hF ;
10465
    read_data`READ_TAG_STIM     = 0 ;
10466
    write_data`WRITE_TAG_STIM   = 0 ;
10467
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10468
 
10469
    ok_pci = 0 ;
10470
    ok_wb  = 1 ;
10471
 
10472
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10473
    pci_address[31:24] = 0 ;
10474
    fork
10475
    begin
10476
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10477
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10478
        begin
10479
            $display("Time %t", $time) ;
10480
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10481
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10482
            ok_wb = 0 ;
10483
        end
10484
 
10485
        config_read( 12'h4, 4'hF, temp_var ) ;
10486
        if ( temp_var[29] !== 1 )
10487
        begin
10488
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10489
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10490
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10491
            ok_wb = 0 ;
10492
        end
10493
 
10494
        if ( temp_var[28] !== 0 )
10495
        begin
10496
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10497
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10498
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10499
            ok_wb = 0 ;
10500
        end
10501
 
10502
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10503
 
10504
        if (ok !== 1)
10505
        begin
10506
            ok_wb = 0 ;
10507
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10508
            $display("Write to PCI Device Status Register failed") ;
10509
            test_fail("Write to PCI Device Status Register failed") ;
10510
        end
10511
 
10512
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10513
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10514
        begin
10515
            $display("Time %t", $time) ;
10516
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10517
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10518
            ok_wb = 0 ;
10519
        end
10520
 
10521
        config_read( 12'h4, 4'hF, temp_var ) ;
10522
        if ( temp_var[29] !== 1 )
10523
        begin
10524
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10525
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10526
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10527
            ok_wb = 0 ;
10528
        end
10529
 
10530
        if ( temp_var[28] !== 0 )
10531
        begin
10532
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10533
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10534
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10535
            ok_wb = 0 ;
10536
        end
10537
 
10538
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10539
 
10540
        if (ok !== 1)
10541
        begin
10542
            ok_wb = 0 ;
10543
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10544
            $display("Write to PCI Device Status Register failed") ;
10545
            test_fail("Write to PCI Device Status Register failed") ;
10546
        end
10547
    end
10548
    begin
10549
        pci_transaction_progress_monitor
10550
        (
10551
            pci_address,                                            // expected address on PCI bus
10552
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10553
            0,                                                      // expected number of succesfull data phases
10554
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10555
            1'b1,                                                   // monitor checking/not checking number of transfers
10556
            1'b0,                                                   // monitor checking/not checking number of cycles
10557
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10558
            ok_pci                                                  // status - 1 success, 0 failure
10559
        ) ;
10560
 
10561
        if (ok_pci)
10562
        begin
10563
            pci_transaction_progress_monitor
10564
            (
10565
                pci_address,                                            // expected address on PCI bus
10566
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10567
                0,                                                      // expected number of succesfull data phases
10568
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10569
                1'b1,                                                   // monitor checking/not checking number of transfers
10570
                1'b0,                                                   // monitor checking/not checking number of cycles
10571
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10572
                ok_pci                                                  // status - 1 success, 0 failure
10573
            ) ;
10574
        end
10575
 
10576
        if (!ok_pci)
10577
        begin
10578
            $display("Time %t", $time) ;
10579
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10580
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10581
        end
10582
    end
10583
    join
10584
 
10585
    if (ok_pci && ok_wb)
10586
    begin
10587
        test_ok ;
10588
    end
10589
 
10590
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10591
    conf_cyc_type1_target_data = 0 ;
10592
    conf_cyc_type1_target_bus_num = 8'h55;
10593
 
10594
    pci_address      = 32'h5555_5555 ;
10595
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10596
 
10597
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10598
 
10599
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10600
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10601
 
10602
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10603
    write_data`WRITE_DATA     = pci_address ;
10604
    write_data`WRITE_SEL      = 4'hF ;
10605
    write_data`WRITE_TAG_STIM = 0 ;
10606
 
10607
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10608
 
10609
    // check if write succeeded
10610
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10611
    begin
10612
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10613
        test_fail("write to configuration cycle address register was not possible") ;
10614
        in_use = 0 ;
10615
        disable main ;
10616
    end
10617
 
10618
    // setup flags for wb master to handle retries and read and write data
10619
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10620
 
10621
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10622
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10623
 
10624
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10625
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10626
    read_data`READ_SEL          = 4'hF ;
10627
    write_data`WRITE_SEL        = 4'hF ;
10628
    read_data`READ_TAG_STIM     = 0 ;
10629
    write_data`WRITE_TAG_STIM   = 0 ;
10630
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10631
 
10632
    ok_pci = 0 ;
10633
    ok_wb  = 1 ;
10634
 
10635
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10636
    pci_address[31:24] = 0 ;
10637
    fork
10638
    begin
10639
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10640
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10641
        begin
10642
            $display("Time %t", $time) ;
10643
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10644
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10645
            ok_wb = 0 ;
10646
        end
10647
 
10648
        config_read( 12'h4, 4'hF, temp_var ) ;
10649
        if ( temp_var[29] !== 0 )
10650
        begin
10651
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10652
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10653
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10654
            ok_wb = 0 ;
10655
        end
10656
 
10657
        if ( temp_var[28] !== 1 )
10658
        begin
10659
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10660
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10661
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10662
            ok_wb = 0 ;
10663
        end
10664
 
10665
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10666
 
10667
        if (ok !== 1)
10668
        begin
10669
            ok_wb = 0 ;
10670
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10671
            $display("Write to PCI Device Status Register failed") ;
10672
            test_fail("Write to PCI Device Status Register failed") ;
10673
        end
10674
 
10675
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10676
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10677
        begin
10678
            $display("Time %t", $time) ;
10679
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10680
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10681
            ok_wb = 0 ;
10682
        end
10683
 
10684
        config_read( 12'h4, 4'hF, temp_var ) ;
10685
        if ( temp_var[29] !== 0 )
10686
        begin
10687
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10688
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10689
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10690
            ok_wb = 0 ;
10691
        end
10692
 
10693
        if ( temp_var[28] !== 1 )
10694
        begin
10695
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10696
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10697
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10698
            ok_wb = 0 ;
10699
        end
10700
 
10701
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10702
 
10703
        if (ok !== 1)
10704
        begin
10705
            ok_wb = 0 ;
10706
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10707
            $display("Write to PCI Device Status Register failed") ;
10708
            test_fail("Write to PCI Device Status Register failed") ;
10709
        end
10710
    end
10711
    begin
10712
        pci_transaction_progress_monitor
10713
        (
10714
            pci_address,                                            // expected address on PCI bus
10715
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10716
            0,                                                      // expected number of succesfull data phases
10717
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10718
            1'b1,                                                   // monitor checking/not checking number of transfers
10719
            1'b0,                                                   // monitor checking/not checking number of cycles
10720
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10721
            ok_pci                                                  // status - 1 success, 0 failure
10722
        ) ;
10723
 
10724
        if (ok_pci)
10725
        begin
10726
            pci_transaction_progress_monitor
10727
            (
10728
                pci_address,                                            // expected address on PCI bus
10729
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10730
                0,                                                      // expected number of succesfull data phases
10731
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10732
                1'b1,                                                   // monitor checking/not checking number of transfers
10733
                1'b0,                                                   // monitor checking/not checking number of cycles
10734
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10735
                ok_pci                                                  // status - 1 success, 0 failure
10736
            ) ;
10737
        end
10738
 
10739
        if (!ok_pci)
10740
        begin
10741
            $display("Time %t", $time) ;
10742
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10743
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10744
        end
10745
    end
10746
    join
10747
 
10748
    if (ok_pci && ok_wb)
10749
    begin
10750
        test_ok ;
10751
    end
10752
 
10753
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10754
 
10755
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10756
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10757
    conf_cyc_type1_target_bus_num = 8'hAA;
10758
 
10759
    pci_address      = 32'hAAAA_AAAA ;
10760
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10761
 
10762
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10763
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10764
 
10765
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10766
    write_data`WRITE_DATA     = pci_address ;
10767
    write_data`WRITE_SEL      = 4'hF ;
10768
    write_data`WRITE_TAG_STIM = 0 ;
10769
 
10770
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10771
 
10772
    // check if write succeeded
10773
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10774
    begin
10775
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10776
        test_fail("write to configuration cycle address register was not possible") ;
10777
        in_use = 0 ;
10778
        disable main ;
10779
    end
10780
 
10781
    // setup flags for wb master to handle retries and read and write data
10782
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10783
 
10784
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10785
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10786
 
10787
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10788
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10789
    read_data`READ_SEL          = 4'b0101 ;
10790
    write_data`WRITE_SEL        = 4'b1010 ;
10791
    read_data`READ_TAG_STIM     = 0 ;
10792
    write_data`WRITE_TAG_STIM   = 0 ;
10793
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10794
 
10795
    ok_pci = 0 ;
10796
    ok_wb  = 1 ;
10797
 
10798
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10799
    pci_address[31:24] = 0 ;
10800
 
10801
    fork
10802
    begin
10803
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10804
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10805
        begin
10806
            $display("Time %t", $time) ;
10807
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10808
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10809
            ok_wb = 0 ;
10810
        end
10811
 
10812
        config_read( 12'h4, 4'hF, temp_var ) ;
10813
        if ( temp_var[29] !== 0 )
10814
        begin
10815
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10816
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10817
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10818
            ok_wb = 0 ;
10819
        end
10820
 
10821
        if ( temp_var[28] !== 0 )
10822
        begin
10823
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10824
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10825
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10826
            ok_wb = 0 ;
10827
        end
10828
 
10829
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10830
 
10831
        if (ok !== 1)
10832
        begin
10833
            ok_wb = 0 ;
10834
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10835
            $display("Write to PCI Device Status Register failed") ;
10836
            test_fail("Write to PCI Device Status Register failed") ;
10837
        end
10838
 
10839
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10840
        begin
10841
            ok_wb = 0 ;
10842
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10843
            $display("Read Data provided by the bridge was not as expected!") ;
10844
            test_fail("Read Data provided by the bridge was not as expected") ;
10845
        end
10846
 
10847
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10848
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10849
        begin
10850
            $display("Time %t", $time) ;
10851
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10852
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10853
            ok_wb = 0 ;
10854
        end
10855
 
10856
        config_read( 12'h4, 4'hF, temp_var ) ;
10857
        if ( temp_var[29] !== 0 )
10858
        begin
10859
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10860
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10861
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10862
            ok_wb = 0 ;
10863
        end
10864
 
10865
        if ( temp_var[28] !== 0 )
10866
        begin
10867
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10868
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10869
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10870
            ok_wb = 0 ;
10871
        end
10872
 
10873
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10874
 
10875
        if (ok !== 1)
10876
        begin
10877
            ok_wb = 0 ;
10878
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10879
            $display("Write to PCI Device Status Register failed") ;
10880
            test_fail("Write to PCI Device Status Register failed") ;
10881
        end
10882
 
10883
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10884
        begin
10885
            ok_wb = 0 ;
10886
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10887
            $display("Data written by the bridge was not as expected!") ;
10888
            test_fail("Data written by the bridge was not as expected") ;
10889
        end
10890
 
10891
    end
10892
    begin
10893
        ok = 1 ;
10894
        repeat(8)
10895
        begin
10896
            pci_transaction_progress_monitor
10897
            (
10898
                pci_address,                                            // expected address on PCI bus
10899
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10900
                0,                                                      // expected number of succesfull data phases
10901
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10902
                1'b1,                                                   // monitor checking/not checking number of transfers
10903
                1'b0,                                                   // monitor checking/not checking number of cycles
10904
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10905
                ok_pci                                                  // status - 1 success, 0 failure
10906
            ) ;
10907
 
10908
            if (!ok_pci)
10909
            begin
10910
                ok = 0 ;
10911
                $display("Time %t", $time) ;
10912
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10913
            end
10914
        end
10915
 
10916
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10917
 
10918
        pci_transaction_progress_monitor
10919
        (
10920
            pci_address,                                            // expected address on PCI bus
10921
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10922
            1,                                                      // expected number of succesfull data phases
10923
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10924
            1'b1,                                                   // monitor checking/not checking number of transfers
10925
            1'b0,                                                   // monitor checking/not checking number of cycles
10926
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10927
            ok_pci                                                  // status - 1 success, 0 failure
10928
        ) ;
10929
 
10930
        if (!ok_pci)
10931
        begin
10932
            ok = 0 ;
10933
            $display("Time %t", $time) ;
10934
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10935
        end
10936
 
10937
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10938
        repeat(8)
10939
        begin
10940
            pci_transaction_progress_monitor
10941
            (
10942
                pci_address,                                            // expected address on PCI bus
10943
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10944
                0,                                                      // expected number of succesfull data phases
10945
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10946
                1'b1,                                                   // monitor checking/not checking number of transfers
10947
                1'b0,                                                   // monitor checking/not checking number of cycles
10948
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10949
                ok_pci                                                  // status - 1 success, 0 failure
10950
            ) ;
10951
 
10952
            if (!ok_pci)
10953
            begin
10954
                ok = 0 ;
10955
                $display("Time %t", $time) ;
10956
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10957
            end
10958
        end
10959
 
10960
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10961
        pci_transaction_progress_monitor
10962
        (
10963
            pci_address,                                            // expected address on PCI bus
10964
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10965
            1,                                                      // expected number of succesfull data phases
10966
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10967
            1'b1,                                                   // monitor checking/not checking number of transfers
10968
            1'b0,                                                   // monitor checking/not checking number of cycles
10969
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10970
            ok_pci                                                  // status - 1 success, 0 failure
10971
        ) ;
10972
 
10973
        if (!ok_pci)
10974
        begin
10975
            ok = 0 ;
10976
            $display("Time %t", $time) ;
10977
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10978
        end
10979
 
10980
        if (!ok)
10981
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10982
    end
10983
    join
10984
 
10985
    if (ok_pci && ok_wb)
10986
    begin
10987
        test_ok ;
10988
    end
10989
 
10990
    in_use = 0 ;
10991
end
10992
endtask // test_configuration_cycle_type1_generation
10993
`endif
10994
 
10995
task test_initial_conf_values ;
10996
    reg [11:0] register_offset ;
10997
    reg [31:0] expected_value ;
10998
    reg        failed ;
10999
`ifdef HOST
11000
    reg `READ_STIM_TYPE    read_data ;
11001
    reg `WB_TRANSFER_FLAGS flags ;
11002
    reg `READ_RETURN_TYPE  read_status ;
11003
 
11004
    reg `WRITE_STIM_TYPE   write_data ;
11005
    reg `WRITE_RETURN_TYPE write_status ;
11006
begin
11007
    failed     = 0 ;
11008
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11009
    flags      = 0 ;
11010
    read_data  = 0 ;
11011
    write_data = 0 ;
11012
 
11013
    read_data`READ_SEL = 4'hF ;
11014
 
11015
    flags`INIT_WAITS           = tb_init_waits ;
11016
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
11017
 
11018
    // test MEM/IO map bit initial value in each PCI BAR
11019
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
11020
 
11021
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11022
 
11023 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11024
 
11025 45 mihad
    `ifdef NO_CNF_IMAGE
11026
        `ifdef PCI_IMAGE0
11027
            if (`PCI_AM0)
11028
                expected_value = `PCI_BA0_MEM_IO ;
11029
            else
11030
                expected_value = 32'h0000_0000 ;
11031
        `else
11032
            expected_value = 32'h0000_0000 ;
11033
        `endif
11034
    `else
11035
        expected_value = 32'h0000_0000 ;
11036
    `endif
11037
 
11038 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11039
    begin
11040 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
11041
        failed = 1 ;
11042 15 mihad
    end
11043 45 mihad
    else
11044
    begin
11045
        if (read_status`READ_DATA !== expected_value)
11046
        begin
11047
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
11048
            failed = 1 ;
11049
        end
11050
    end
11051 15 mihad
 
11052 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
11053 15 mihad
 
11054 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11055
 
11056
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11057
 
11058
    if (`PCI_AM1)
11059
        expected_value = `PCI_BA1_MEM_IO ;
11060
    else
11061
        expected_value = 32'h0000_0000 ;
11062
 
11063
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11064
    begin
11065
        test_fail("read from P_BA1 register didn't succeede") ;
11066
        failed = 1 ;
11067
    end
11068
    else
11069
    begin
11070
        if (read_status`READ_DATA !== expected_value)
11071
        begin
11072
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
11073
            failed = 1 ;
11074
        end
11075
    end
11076
 
11077
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
11078
 
11079
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11080
 
11081
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11082
 
11083
    `ifdef PCI_IMAGE2
11084
        if (`PCI_AM2)
11085
            expected_value = `PCI_BA2_MEM_IO ;
11086
        else
11087
            expected_value = 32'h0000_0000 ;
11088 15 mihad
    `else
11089 45 mihad
        expected_value = 32'h0000_0000 ;
11090
    `endif
11091 15 mihad
 
11092 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11093
    begin
11094
        test_fail("read from P_BA2 register didn't succeede") ;
11095
        failed = 1 ;
11096
    end
11097
    else
11098
    begin
11099
        if (read_status`READ_DATA !== expected_value)
11100
        begin
11101
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
11102
            failed = 1 ;
11103
        end
11104
    end
11105 15 mihad
 
11106 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
11107
 
11108
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11109
 
11110
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11111
 
11112
    `ifdef PCI_IMAGE3
11113
        if (`PCI_AM3)
11114
            expected_value = `PCI_BA3_MEM_IO ;
11115
        else
11116
            expected_value = 32'h0000_0000 ;
11117
    `else
11118
        expected_value = 32'h0000_0000 ;
11119 15 mihad
    `endif
11120 45 mihad
 
11121
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11122
    begin
11123
        test_fail("read from P_BA3 register didn't succeede") ;
11124
        failed = 1 ;
11125
    end
11126
    else
11127
    begin
11128
        if (read_status`READ_DATA !== expected_value)
11129
        begin
11130
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
11131
            failed = 1 ;
11132
        end
11133
    end
11134
 
11135
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
11136
 
11137
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11138
 
11139
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11140
 
11141
    `ifdef PCI_IMAGE4
11142
        if (`PCI_AM4)
11143
            expected_value = `PCI_BA4_MEM_IO ;
11144
        else
11145
            expected_value = 32'h0000_0000 ;
11146
    `else
11147
        expected_value = 32'h0000_0000 ;
11148 15 mihad
    `endif
11149
 
11150 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11151
    begin
11152
        test_fail("read from P_BA4 register didn't succeede") ;
11153
        failed = 1 ;
11154
    end
11155
    else
11156
    begin
11157
        if (read_status`READ_DATA !== expected_value)
11158
        begin
11159
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11160
            failed = 1 ;
11161
        end
11162
    end
11163 15 mihad
 
11164 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11165 15 mihad
 
11166 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11167
 
11168
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11169
 
11170
    `ifdef PCI_IMAGE5
11171
        if(`PCI_AM5)
11172
            expected_value = `PCI_BA5_MEM_IO ;
11173
        else
11174
            expected_value = 32'h0000_0000 ;
11175
    `else
11176
        expected_value = 32'h0000_0000 ;
11177
    `endif
11178
 
11179
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11180
    begin
11181
        test_fail("read from P_BA5 register didn't succeede") ;
11182
        failed = 1 ;
11183
    end
11184
    else
11185
    begin
11186
        if (read_status`READ_DATA !== expected_value)
11187
        begin
11188
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11189
            failed = 1 ;
11190
        end
11191
    end
11192
 
11193
    // test Address Mask initial values
11194
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11195
 
11196
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11197
 
11198
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11199
 
11200
    `ifdef NO_CNF_IMAGE
11201
        `ifdef PCI_IMAGE0
11202
            expected_value = {`PCI_AM0, 12'h000};
11203
 
11204
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11205
        `else
11206
            expected_value = 32'h0000_0000 ;
11207
        `endif
11208
    `else
11209
        expected_value = 32'hFFFF_FFFF ;
11210
 
11211
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11212
    `endif
11213
 
11214
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11215
    begin
11216
        test_fail("read from P_AM0 register didn't succeede") ;
11217
        failed = 1 ;
11218
    end
11219
    else
11220
    begin
11221
        if (read_status`READ_DATA !== expected_value)
11222
        begin
11223
            test_fail("AM0 initial value was not set as defined");
11224
            failed = 1 ;
11225
        end
11226
    end
11227
 
11228
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11229
 
11230
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11231
 
11232
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11233
 
11234
    expected_value = {`PCI_AM1, 12'h000};
11235
 
11236
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11237
 
11238
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11239
    begin
11240
        test_fail("read from P_AM1 register didn't succeede") ;
11241
        failed = 1 ;
11242
    end
11243
    else
11244
    begin
11245
        if (read_status`READ_DATA !== expected_value)
11246
        begin
11247
            test_fail("AM1 initial value was not set as defined");
11248
            failed = 1 ;
11249
        end
11250
    end
11251
 
11252
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11253
 
11254
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11255
 
11256
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11257
 
11258
    `ifdef PCI_IMAGE2
11259
        expected_value = {`PCI_AM2, 12'h000};
11260
 
11261
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11262
    `else
11263
        expected_value = 32'h0000_0000 ;
11264
    `endif
11265
 
11266
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11267
    begin
11268
        test_fail("read from P_AM2 register didn't succeede") ;
11269
        failed = 1 ;
11270
    end
11271
    else
11272
    begin
11273
        if (read_status`READ_DATA !== expected_value)
11274
        begin
11275
            test_fail("AM2 initial value was not set as defined");
11276
            failed = 1 ;
11277
        end
11278
    end
11279
 
11280
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11281
 
11282
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11283
 
11284
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11285
 
11286
    `ifdef PCI_IMAGE3
11287
        expected_value = {`PCI_AM3, 12'h000};
11288
 
11289
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11290
    `else
11291
        expected_value = 32'h0000_0000 ;
11292
    `endif
11293
 
11294
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11295
    begin
11296
        test_fail("read from P_AM3 register didn't succeede") ;
11297
        failed = 1 ;
11298
    end
11299
    else
11300
    begin
11301
        if (read_status`READ_DATA !== expected_value)
11302
        begin
11303
            test_fail("AM3 initial value was not set as defined");
11304
            failed = 1 ;
11305
        end
11306
    end
11307
 
11308
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11309
 
11310
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11311
 
11312
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11313
 
11314
    `ifdef PCI_IMAGE4
11315
        expected_value = {`PCI_AM4, 12'h000};
11316
 
11317
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11318
    `else
11319
        expected_value = 32'h0000_0000 ;
11320
    `endif
11321
 
11322
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11323
    begin
11324
        test_fail("read from P_AM4 register didn't succeede") ;
11325
        failed = 1 ;
11326
    end
11327
    else
11328
    begin
11329
        if (read_status`READ_DATA !== expected_value)
11330
        begin
11331
            test_fail("AM4 initial value was not set as defined");
11332
            failed = 1 ;
11333
        end
11334
    end
11335
 
11336
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11337
 
11338
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11339
 
11340
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11341
 
11342
    `ifdef PCI_IMAGE5
11343
        expected_value = {`PCI_AM5, 12'h000};
11344
 
11345
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11346
    `else
11347
        expected_value = 32'h0000_0000 ;
11348
    `endif
11349
 
11350
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11351
    begin
11352
        test_fail("read from P_AM5 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("AM5 initial value was not set as defined");
11360
            failed = 1 ;
11361
        end
11362
    end
11363
 
11364
`endif
11365
 
11366
`ifdef GUEST
11367
    reg [31:0] read_data ;
11368
begin
11369
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11370
    failed    = 0 ;
11371
 
11372
    // check all images' BARs
11373
 
11374
    // BAR0
11375
    configuration_cycle_read
11376
    (
11377
        8'h00,                          // bus number [7:0]
11378
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11379
        3'h0,                           // function number [2:0]
11380
        6'h4,                           // register number [5:0]
11381
        2'h0,                           // type [1:0]
11382
        4'hF,                           // byte enables [3:0]
11383
        read_data                       // data returned from configuration read [31:0]
11384
    ) ;
11385
 
11386
    expected_value = 32'h0000_0000 ;
11387
 
11388
    if( read_data !== expected_value)
11389
    begin
11390
        test_fail("initial value of BAR0 register not as expected") ;
11391
        failed = 1 ;
11392
    end
11393
 
11394
    // BAR1
11395
    configuration_cycle_read
11396
    (
11397
        8'h00,                          // bus number [7:0]
11398
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11399
        3'h0,                           // function number [2:0]
11400
        6'h5,                           // register number [5:0]
11401
        2'h0,                           // type [1:0]
11402
        4'hF,                           // byte enables [3:0]
11403
        read_data                       // data returned from configuration read [31:0]
11404
    ) ;
11405
 
11406
    if (`PCI_AM1)
11407
        expected_value = `PCI_BA1_MEM_IO ;
11408
    else
11409
        expected_value = 32'h0000_0000 ;
11410
 
11411
    if( read_data !== expected_value)
11412
    begin
11413
        test_fail("initial value of BAR1 register not as expected") ;
11414
        failed = 1 ;
11415
    end
11416
 
11417
    // BAR2
11418
    configuration_cycle_read
11419
    (
11420
        8'h00,                          // bus number [7:0]
11421
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11422
        3'h0,                           // function number [2:0]
11423
        6'h6,                           // register number [5:0]
11424
        2'h0,                           // type [1:0]
11425
        4'hF,                           // byte enables [3:0]
11426
        read_data                       // data returned from configuration read [31:0]
11427
    ) ;
11428
 
11429
    `ifdef PCI_IMAGE2
11430
    if (`PCI_AM2)
11431
        expected_value = `PCI_BA2_MEM_IO ;
11432
    else
11433
        expected_value = 32'h0000_0000 ;
11434
    `else
11435
    expected_value = 32'h0 ;
11436
    `endif
11437
 
11438
    if( read_data !== expected_value)
11439
    begin
11440
        test_fail("initial value of BAR2 register not as expected") ;
11441
        failed = 1 ;
11442
    end
11443
 
11444
    // BAR3
11445
    configuration_cycle_read
11446
    (
11447
        8'h00,                          // bus number [7:0]
11448
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11449
        3'h0,                           // function number [2:0]
11450
        6'h7,                           // register number [5:0]
11451
        2'h0,                           // type [1:0]
11452
        4'hF,                           // byte enables [3:0]
11453
        read_data                       // data returned from configuration read [31:0]
11454
    ) ;
11455
 
11456
    `ifdef PCI_IMAGE3
11457
    if(`PCI_AM3)
11458
        expected_value = `PCI_BA3_MEM_IO ;
11459
    else
11460
        expected_value = 32'h0000_0000 ;
11461
    `else
11462
    expected_value = 32'h0 ;
11463
    `endif
11464
 
11465
    if( read_data !== expected_value)
11466
    begin
11467
        test_fail("initial value of BAR3 register not as expected") ;
11468
        failed = 1 ;
11469
    end
11470
 
11471
    // BAR4
11472
    configuration_cycle_read
11473
    (
11474
        8'h00,                          // bus number [7:0]
11475
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11476
        3'h0,                           // function number [2:0]
11477
        6'h8,                           // register number [5:0]
11478
        2'h0,                           // type [1:0]
11479
        4'hF,                           // byte enables [3:0]
11480
        read_data                       // data returned from configuration read [31:0]
11481
    ) ;
11482
 
11483
    `ifdef PCI_IMAGE4
11484
    if (`PCI_AM4)
11485
        expected_value = `PCI_BA4_MEM_IO ;
11486
    else
11487
        expected_value = 32'h0000_0000 ;
11488
    `else
11489
    expected_value = 32'h0 ;
11490
    `endif
11491
 
11492
    if( read_data !== expected_value)
11493
    begin
11494
        test_fail("initial value of BAR4 register not as expected") ;
11495
        failed = 1 ;
11496
    end
11497
 
11498
    // BAR5
11499
    configuration_cycle_read
11500
    (
11501
        8'h00,                          // bus number [7:0]
11502
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11503
        3'h0,                           // function number [2:0]
11504
        6'h9,                           // register number [5:0]
11505
        2'h0,                           // type [1:0]
11506
        4'hF,                           // byte enables [3:0]
11507
        read_data                       // data returned from configuration read [31:0]
11508
    ) ;
11509
 
11510
    `ifdef PCI_IMAGE5
11511
    if(`PCI_AM5)
11512
        expected_value = `PCI_BA5_MEM_IO ;
11513
    else
11514
        expected_value = 32'h0000_0000 ;
11515
    `else
11516
    expected_value = 32'h0 ;
11517
    `endif
11518
 
11519
    if( read_data !== expected_value)
11520
    begin
11521
        test_fail("initial value of BAR5 register not as expected") ;
11522
        failed = 1 ;
11523
    end
11524
 
11525
    // write all 1s to BAR0
11526
    read_data = 32'hFFFF_FFFF ;
11527
 
11528
    // BAR0
11529
    configuration_cycle_write
11530
    (
11531
        8'h00,                          // bus number [7:0]
11532
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11533
        3'h0,                           // function number [2:0]
11534
        6'h4,                           // register number [5:0]
11535
        2'h0,                           // type [1:0]
11536
        4'hF,                           // byte enables [3:0]
11537
        read_data                       // data to write [31:0]
11538
    ) ;
11539
 
11540
    expected_value = 32'hFFFF_FFFF ;
11541
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11542
 
11543
    configuration_cycle_read
11544
    (
11545
        8'h00,                          // bus number [7:0]
11546
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11547
        3'h0,                           // function number [2:0]
11548
        6'h4,                           // register number [5:0]
11549
        2'h0,                           // type [1:0]
11550
        4'hF,                           // byte enables [3:0]
11551
        read_data                       // data to write [31:0]
11552
    ) ;
11553
 
11554
    if ( read_data !== expected_value )
11555
    begin
11556
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11557
        failed = 1 ;
11558
    end
11559
 
11560
    // write all 1s to BAR1
11561
    read_data = 32'hFFFF_FFFF ;
11562
 
11563
    // BAR1
11564
    configuration_cycle_write
11565
    (
11566
        8'h00,                          // bus number [7:0]
11567
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11568
        3'h0,                           // function number [2:0]
11569
        6'h5,                           // register number [5:0]
11570
        2'h0,                           // type [1:0]
11571
        4'hF,                           // byte enables [3:0]
11572
        read_data                       // data to write [31:0]
11573
    ) ;
11574
 
11575
    expected_value = {`PCI_AM1, 12'h000} ;
11576
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11577
    if (`PCI_AM1)
11578
        expected_value[0] = `PCI_BA1_MEM_IO ;
11579
 
11580
    configuration_cycle_read
11581
    (
11582
        8'h00,                          // bus number [7:0]
11583
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11584
        3'h0,                           // function number [2:0]
11585
        6'h5,                           // register number [5:0]
11586
        2'h0,                           // type [1:0]
11587
        4'hF,                           // byte enables [3:0]
11588
        read_data                       // data to write [31:0]
11589
    ) ;
11590
 
11591
    if ( read_data !== expected_value )
11592
    begin
11593
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11594
        failed = 1 ;
11595
    end
11596
 
11597
    // write all 1s to BAR2
11598
    read_data = 32'hFFFF_FFFF ;
11599
 
11600
    // BAR2
11601
    configuration_cycle_write
11602
    (
11603
        8'h00,                          // bus number [7:0]
11604
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11605
        3'h0,                           // function number [2:0]
11606
        6'h6,                           // register number [5:0]
11607
        2'h0,                           // type [1:0]
11608
        4'hF,                           // byte enables [3:0]
11609
        read_data                       // data to write [31:0]
11610
    ) ;
11611
 
11612
`ifdef PCI_IMAGE2
11613
    expected_value = {`PCI_AM2, 12'h000} ;
11614
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11615
    if (`PCI_AM2)
11616
        expected_value[0] = `PCI_BA2_MEM_IO ;
11617
`else
11618
    expected_value = 0 ;
11619
`endif
11620
 
11621
    configuration_cycle_read
11622
    (
11623
        8'h00,                          // bus number [7:0]
11624
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11625
        3'h0,                           // function number [2:0]
11626
        6'h6,                           // register number [5:0]
11627
        2'h0,                           // type [1:0]
11628
        4'hF,                           // byte enables [3:0]
11629
        read_data                       // data to write [31:0]
11630
    ) ;
11631
 
11632
    if ( read_data !== expected_value )
11633
    begin
11634
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11635
        failed = 1 ;
11636
    end
11637
 
11638
    // write all 1s to BAR3
11639
    read_data = 32'hFFFF_FFFF ;
11640
 
11641
    // BAR3
11642
    configuration_cycle_write
11643
    (
11644
        8'h00,                          // bus number [7:0]
11645
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11646
        3'h0,                           // function number [2:0]
11647
        6'h7,                           // register number [5:0]
11648
        2'h0,                           // type [1:0]
11649
        4'hF,                           // byte enables [3:0]
11650
        read_data                       // data to write [31:0]
11651
    ) ;
11652
 
11653
`ifdef PCI_IMAGE3
11654
    expected_value = {`PCI_AM3, 12'h000} ;
11655
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11656
    if(`PCI_AM3)
11657
        expected_value[0] = `PCI_BA3_MEM_IO ;
11658
`else
11659
    expected_value = 0 ;
11660
`endif
11661
 
11662
    configuration_cycle_read
11663
    (
11664
        8'h00,                          // bus number [7:0]
11665
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11666
        3'h0,                           // function number [2:0]
11667
        6'h7,                           // register number [5:0]
11668
        2'h0,                           // type [1:0]
11669
        4'hF,                           // byte enables [3:0]
11670
        read_data                       // data to write [31:0]
11671
    ) ;
11672
 
11673
    if ( read_data !== expected_value )
11674
    begin
11675
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11676
        failed = 1 ;
11677
    end
11678
 
11679
    // write all 1s to BAR4
11680
    read_data = 32'hFFFF_FFFF ;
11681
 
11682
    // BAR4
11683
    configuration_cycle_write
11684
    (
11685
        8'h00,                          // bus number [7:0]
11686
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11687
        3'h0,                           // function number [2:0]
11688
        6'h8,                           // register number [5:0]
11689
        2'h0,                           // type [1:0]
11690
        4'hF,                           // byte enables [3:0]
11691
        read_data                       // data to write [31:0]
11692
    ) ;
11693
 
11694
`ifdef PCI_IMAGE4
11695
    expected_value = {`PCI_AM4, 12'h000} ;
11696
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11697
    if(`PCI_AM4)
11698
        expected_value[0] = `PCI_BA4_MEM_IO ;
11699
`else
11700
    expected_value = 0 ;
11701
`endif
11702
 
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'h8,                           // register number [5:0]
11709
        2'h0,                           // type [1:0]
11710
        4'hF,                           // byte enables [3:0]
11711
        read_data                       // data to write [31:0]
11712
    ) ;
11713
 
11714
    if ( read_data !== expected_value )
11715
    begin
11716
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11717
        failed = 1 ;
11718
    end
11719
 
11720
    // write all 1s to BAR5
11721
    read_data = 32'hFFFF_FFFF ;
11722
 
11723
    // BAR5
11724
    configuration_cycle_write
11725
    (
11726
        8'h00,                          // bus number [7:0]
11727
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11728
        3'h0,                           // function number [2:0]
11729
        6'h9,                           // register number [5:0]
11730
        2'h0,                           // type [1:0]
11731
        4'hF,                           // byte enables [3:0]
11732
        read_data                       // data to write [31:0]
11733
    ) ;
11734
 
11735
`ifdef PCI_IMAGE5
11736
    expected_value = {`PCI_AM5, 12'h000} ;
11737
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11738
    if(`PCI_AM5)
11739
        expected_value[0] = `PCI_BA5_MEM_IO ;
11740
`else
11741
    expected_value = 0 ;
11742
`endif
11743
 
11744
    configuration_cycle_read
11745
    (
11746
        8'h00,                          // bus number [7:0]
11747
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11748
        3'h0,                           // function number [2:0]
11749
        6'h9,                           // register number [5:0]
11750
        2'h0,                           // type [1:0]
11751
        4'hF,                           // byte enables [3:0]
11752
        read_data                       // data to write [31:0]
11753
    ) ;
11754
 
11755
    if ( read_data !== expected_value )
11756
    begin
11757
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11758
        failed = 1 ;
11759
    end
11760
`endif
11761
 
11762
    if (!failed)
11763
        test_ok ;
11764
end
11765
endtask
11766
 
11767 15 mihad
task display_warning;
11768
    input [31:0] error_address ;
11769
    input [31:0] expected_data ;
11770
    input [31:0] actual ;
11771
begin
11772
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11773
end
11774
endtask // display warning
11775
 
11776
/*############################################################################
11777
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11778
=====================
11779
############################################################################*/
11780
 
11781
// Task reslease the PCI bus for 'delay' clocks
11782
task do_pause;
11783
  input  [15:0] delay;
11784
  reg    [15:0] cnt;
11785
  begin
11786
    test_start <= 1'b0;  // no device is allowed to take this
11787
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11788
    begin
11789
      if (~pci_reset_comb)
11790
      begin
11791
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11792
      end
11793
      `NO_ELSE;
11794
    end
11795
  end
11796
endtask // do_pause
11797
 
11798
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11799
task DO_REF;
11800
  input  [79:0] name;
11801
  input  [2:0] master_number;
11802
  input  [PCI_BUS_DATA_RANGE:0] address;
11803
  input  [3:0] command;
11804
  input  [PCI_BUS_DATA_RANGE:0] data;
11805
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11806
  input  [9:0] size;
11807
  input   make_addr_par_error, make_data_par_error;
11808
  input  [7:0] master_wait_states;
11809
  input  [7:0] target_wait_states;
11810
  input  [1:0] target_devsel_speed;
11811
  input   fast_back_to_back;
11812
  input  [2:0] target_termination;
11813
  input   expect_master_abort;
11814
  reg     waiting;
11815
  begin
11816
// Cautiously wait for previous command to be done
11817
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11818
    begin
11819
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11820
      begin
11821
        if (~pci_reset_comb)
11822
        begin
11823
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11824
        end
11825
        `NO_ELSE;
11826
      end
11827
      else
11828
      begin
11829
        waiting = 1'b0;  // ready to do next command
11830
      end
11831
    end
11832
    next_test_name[79:0] <= name[79:0];
11833
    test_master_number <= master_number[2:0];
11834
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11835
    test_command[3:0] <= command[3:0] ;
11836
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11837
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11838
    test_size <= size;
11839
    test_make_addr_par_error <= make_addr_par_error;
11840
    test_make_data_par_error <= make_data_par_error;
11841
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11842
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11843
    test_target_initial_wait_states <= target_wait_states[7:4];
11844
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11845
    test_target_devsel_speed <= target_devsel_speed[1:0];
11846
    test_fast_back_to_back <= fast_back_to_back;
11847
    test_target_termination <= target_termination[2:0];
11848
    test_expect_master_abort <= expect_master_abort;
11849
    test_start <= 1'b1;
11850
    if (~pci_reset_comb)
11851
    begin
11852
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11853
    end
11854
    `NO_ELSE;
11855
// wait for new command to start
11856
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11857
    begin
11858
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11859
      begin
11860
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11861
      end
11862
      else
11863
      begin
11864
        waiting = 1'b0;  // ready to do next command
11865
      end
11866
    end
11867
  end
11868
endtask // DO_REF
11869
 
11870
// Use Macros defined in pci_defines.vh as paramaters
11871
 
11872
// DO_REF (name[79:0], master_number[2:0],
11873
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11874
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11875
//          make_addr_par_error, make_data_par_error,
11876
//          master_wait_states[8:0], target_wait_states[8:0],
11877
//          target_devsel_speed[1:0], fast_back_to_back,
11878
//          target_termination[2:0],
11879
//          expect_master_abort);
11880
//
11881
// Example:
11882
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11883
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11884
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11885
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11886
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11887
 
11888
// Access a location with no high-order bits set, assuring that no device responds
11889
task PCIU_CONFIG_READ_MASTER_ABORT;
11890
  input  [79:0] name;
11891
  input  [2:0] master_number;
11892 51 mihad
  input  [31:0] address ;
11893
  input  [3:0] be ;
11894 15 mihad
  begin
11895 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11896
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11897
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11898 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11899
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11900
  end
11901
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11902
 
11903
// Access a location with no high-order bits set, assuring that no device responds
11904
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11905
  input  [79:0] name;
11906
  input  [2:0] master_number;
11907 51 mihad
  input  [31:0] address ;
11908
  input  [3:0] be ;
11909 15 mihad
  begin
11910 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11911
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11912
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11913 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11914
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11915
  end
11916
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11917
 
11918
// Access a location with no high-order bits set, assuring that no device responds
11919
task PCIU_MEM_READ_MASTER_ABORT;
11920
  input  [79:0] name;
11921
  input  [2:0] master_number;
11922
  input  [9:0] size;
11923
  begin
11924
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11925
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11926
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11927
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11928
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11929
  end
11930
endtask // PCIU_MEM_READ_MASTER_ABORT
11931
 
11932
// Access a location with no high-order bits set, assuring that no device responds
11933
task PCIU_MEM_WRITE_MASTER_ABORT;
11934
  input  [79:0] name;
11935
  input  [2:0] master_number;
11936
  input  [9:0] size;
11937
  begin
11938
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11939
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11940
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11941
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11942
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11943
  end
11944
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11945
 
11946
// Do variable length transfers with various paramaters
11947
task PCIU_CONFIG_READ;
11948
  input  [79:0] name;
11949
  input  [2:0] master_number;
11950
  input  [PCI_BUS_DATA_RANGE:0] address;
11951
  input  [PCI_BUS_DATA_RANGE:0] data;
11952
  input  [3:0] be ;
11953
  input  [9:0] size;
11954
  input  [7:0] master_wait_states;
11955
  input  [7:0] target_wait_states;
11956
  input  [1:0] target_devsel_speed;
11957
  input  [2:0] target_termination;
11958
  begin
11959
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11960
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11961
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11962
              8'h0_0, target_wait_states[7:0],
11963
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11964
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11965
  end
11966
endtask // PCIU_CONFIG_READ
11967
 
11968
task PCIU_CONFIG_WRITE;
11969
  input  [79:0] name;
11970
  input  [2:0] master_number;
11971
  input  [PCI_BUS_DATA_RANGE:0] address;
11972
  input  [PCI_BUS_DATA_RANGE:0] data;
11973
  input  [3:0] be ;
11974
  input  [9:0] size;
11975
  input  [7:0] master_wait_states;
11976
  input  [7:0] target_wait_states;
11977
  input  [1:0] target_devsel_speed;
11978
  input  [2:0] target_termination;
11979
  begin
11980
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11981
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11982
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11983
              8'h0_0, target_wait_states[7:0],
11984
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11985
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11986
  end
11987
endtask // PCIU_CONFIG_WRITE
11988
 
11989
task PCIU_READ;
11990
  input  [2:0] master_number;
11991
  input  [PCI_BUS_DATA_RANGE:0] address;
11992
  input  [3:0] command;
11993
  input  [PCI_BUS_DATA_RANGE:0] data;
11994
  input  [3:0] byte_en;
11995
  input  [9:0] size;
11996
  input  [7:0] master_wait_states;
11997
  input  [7:0] target_wait_states;
11998
  input  [1:0] target_devsel_speed;
11999
  input  [2:0] target_termination;
12000
  reg    [79:0] name;
12001
  begin
12002
    if (command == `BC_MEM_READ)
12003
        name = "MEM_READ  " ;
12004
    else if (command == `BC_MEM_READ_LN)
12005
        name = "MEM_RD_LN " ;
12006
    else if (command == `BC_MEM_READ_MUL )
12007
        name = "MEM_RD_MUL" ;
12008
    else
12009
        name = "WRONG_READ" ;
12010
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12011
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12012
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12013
              8'h0_0, target_wait_states[7:0],
12014
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12015
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12016
  end
12017
endtask // PCIU_READ
12018
 
12019
task PCIU_MEM_READ;
12020
  input  [79:0] name;
12021
  input  [2:0] master_number;
12022
  input  [PCI_BUS_DATA_RANGE:0] address;
12023
  input  [PCI_BUS_DATA_RANGE:0] data;
12024
  input  [9:0] size;
12025
  input  [7:0] master_wait_states;
12026
  input  [7:0] target_wait_states;
12027
  input  [1:0] target_devsel_speed;
12028
  input  [2:0] target_termination;
12029
  begin
12030
 
12031
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12032
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12033
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12034
              8'h0_0, target_wait_states[7:0],
12035
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12036
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12037
  end
12038
endtask // PCIU_MEM_READ
12039
 
12040
task PCIU_IO_READ;
12041
  input  [2:0] master_number;
12042
  input  [PCI_BUS_DATA_RANGE:0] address;
12043
  input  [PCI_BUS_DATA_RANGE:0] data;
12044
  input  [3:0] byte_en ;
12045
  input  [9:0] size;
12046
  input  [2:0] target_termination ;
12047
  begin
12048
 
12049
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12050
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12051
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12052
              8'h0_0, `Test_One_Zero_Target_WS,
12053
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12054
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12055
  end
12056
endtask // PCIU_IO_READ
12057
 
12058
task PCIU_IO_READ_MAKE_PERR;
12059
  input  [2:0] master_number;
12060
  input  [PCI_BUS_DATA_RANGE:0] address;
12061
  input  [PCI_BUS_DATA_RANGE:0] data;
12062
  input  [3:0] byte_en ;
12063
  input  [9:0] size;
12064
  input  [2:0] target_termination ;
12065
  begin
12066
 
12067
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12068
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12069
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12070
              8'h0_0, `Test_One_Zero_Target_WS,
12071
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12072
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12073
  end
12074
endtask // PCIU_IO_READ_MAKE_PERR
12075
 
12076
task PCIU_MEM_READ_LN;
12077
  input  [79:0] name;
12078
  input  [2:0] master_number;
12079
  input  [PCI_BUS_DATA_RANGE:0] address;
12080
  input  [PCI_BUS_DATA_RANGE:0] data;
12081
  input  [9:0] size;
12082
  input  [7:0] master_wait_states;
12083
  input  [7:0] target_wait_states;
12084
  input  [1:0] target_devsel_speed;
12085
  input  [2:0] target_termination;
12086
  begin
12087
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12088
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12089
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12090
              8'h0_0, target_wait_states[7:0],
12091
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12092
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12093
  end
12094
endtask // PCIU_MEM_READ_LN
12095
 
12096
task PCIU_MEM_READ_MUL;
12097
  input  [79:0] name;
12098
  input  [2:0] master_number;
12099
  input  [PCI_BUS_DATA_RANGE:0] address;
12100
  input  [PCI_BUS_DATA_RANGE:0] data;
12101
  input  [9:0] size;
12102
  input  [7:0] master_wait_states;
12103
  input  [7:0] target_wait_states;
12104
  input  [1:0] target_devsel_speed;
12105
  input  [2:0] target_termination;
12106
  begin
12107
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12108
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12109
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12110
              8'h0_0, target_wait_states[7:0],
12111
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12112
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12113
  end
12114
endtask // PCIU_MEM_READ_MUL
12115
 
12116
task PCIU_MEM_READ_MAKE_PERR;
12117
  input  [79:0] name;
12118
  input  [2:0] master_number;
12119
  input  [PCI_BUS_DATA_RANGE:0] address;
12120
  input  [PCI_BUS_DATA_RANGE:0] data;
12121
  input  [9:0] size;
12122
  input  [7:0] master_wait_states;
12123
  input  [7:0] target_wait_states;
12124
  input  [1:0] target_devsel_speed;
12125
  input  [2:0] target_termination;
12126
  begin
12127
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12128
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12129
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12130
              8'h0_0, target_wait_states[7:0],
12131
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12132
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12133
  end
12134
endtask // PCIU_MEM_READ_MAKE_PERR
12135
 
12136
task PCIU_MEM_WRITE;
12137
  input  [79:0] name;
12138
  input  [2:0] master_number;
12139
  input  [PCI_BUS_DATA_RANGE:0] address;
12140
  input  [PCI_BUS_DATA_RANGE:0] data;
12141
  input  [3:0] byte_en;
12142
  input  [9:0] size;
12143
  input  [7:0] master_wait_states;
12144
  input  [7:0] target_wait_states;
12145
  input  [1:0] target_devsel_speed;
12146
  input  [2:0] target_termination;
12147
  begin
12148
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12149
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12150
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12151
              8'h0_0, target_wait_states[7:0],
12152
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12153
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12154
  end
12155
endtask // PCIU_MEM_WRITE
12156
 
12157
task PCIU_IO_WRITE;
12158
  input  [2:0] master_number;
12159
  input  [PCI_BUS_DATA_RANGE:0] address;
12160
  input  [PCI_BUS_DATA_RANGE:0] data;
12161
  input  [3:0] byte_en;
12162
  input  [9:0] size;
12163
  input  [2:0] target_termination ;
12164
  begin
12165
 
12166
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12167
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12168
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12169
              8'h0_0, `Test_One_Zero_Target_WS,
12170
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12171
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12172
  end
12173
endtask // PCIU_IO_WRITE
12174
 
12175
task PCIU_IO_WRITE_MAKE_PERR ;
12176
  input  [2:0] master_number;
12177
  input  [PCI_BUS_DATA_RANGE:0] address;
12178
  input  [PCI_BUS_DATA_RANGE:0] data;
12179
  input  [3:0] byte_en;
12180
  input  [9:0] size;
12181
  input  [2:0] target_termination ;
12182
  begin
12183
 
12184
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12185
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12186
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12187
              8'h0_0, `Test_One_Zero_Target_WS,
12188
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12189
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12190
  end
12191
endtask // PCIU_IO_WRITE
12192
 
12193
task PCIU_MEM_WRITE_MAKE_SERR;
12194
  input  [79:0] name;
12195
  input  [2:0] master_number;
12196
  input  [PCI_BUS_DATA_RANGE:0] address;
12197
  input  [PCI_BUS_DATA_RANGE:0] data;
12198
  input  [9:0] size;
12199
  input  [7:0] master_wait_states;
12200
  input  [7:0] target_wait_states;
12201
  input  [1:0] target_devsel_speed;
12202
  input  [2:0] target_termination;
12203
  begin
12204
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12205
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12206
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12207
              8'h0_0, target_wait_states[7:0],
12208
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12209
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12210
  end
12211
endtask // PCIU_MEM_WRITE_MAKE_SERR
12212
 
12213
task PCIU_MEM_WRITE_MAKE_PERR;
12214
  input  [79:0] name;
12215
  input  [2:0] master_number;
12216
  input  [PCI_BUS_DATA_RANGE:0] address;
12217
  input  [PCI_BUS_DATA_RANGE:0] data;
12218
  input  [9:0] size;
12219
  input  [7:0] master_wait_states;
12220
  input  [7:0] target_wait_states;
12221
  input  [1:0] target_devsel_speed;
12222
  input  [2:0] target_termination;
12223
  begin
12224
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12225
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12226
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12227
              8'h0_0, target_wait_states[7:0],
12228
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12229
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12230
  end
12231
endtask // PCIU_MEM_WRITE
12232
 
12233
/*--------------------------------------------------------------------------
12234
Initialization CASES
12235
--------------------------------------------------------------------------*/
12236
 
12237
// Initialize the basic Config Registers of the PCI bridge target device
12238
task configure_bridge_target;
12239
    reg [11:0] offset ;
12240
    reg [31:0] data ;
12241
    `ifdef HOST
12242
    reg `WRITE_STIM_TYPE   write_data ;
12243
    reg `WB_TRANSFER_FLAGS write_flags ;
12244
    reg `WRITE_RETURN_TYPE write_status ;
12245
    `else
12246
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12247
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12248
    `endif
12249
 
12250
    reg [31:0] temp_var ;
12251
begin
12252
`ifdef HOST //  set Header
12253
    offset  = 12'h4 ; // PCI Header Command register
12254
    data    = 32'h0000_0007 ; // enable master & target operation
12255
 
12256
    write_flags                      = 0 ;
12257
    write_flags`INIT_WAITS           = tb_init_waits ;
12258
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12259
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12260
 
12261
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12262
    write_data`WRITE_SEL      = 4'h1 ;
12263
    write_data`WRITE_TAG_STIM = 0 ;
12264
    write_data`WRITE_DATA     = data ;
12265
 
12266
    next_test_name[79:0] <= "Init_Tar_R";
12267
 
12268
    $display(" bridge target - Enabling master and target operation!");
12269
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12270
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12271
    begin
12272
        $display("Write to configuration space failed! Time %t ", $time) ;
12273
    end
12274
 
12275
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12276
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12277
 
12278
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12279
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12280
 
12281
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12282
    write_data`WRITE_SEL      = 4'hf ;
12283
    write_data`WRITE_TAG_STIM = 0 ;
12284
    write_data`WRITE_DATA     = data ;
12285
 
12286
 `ifdef  NO_CNF_IMAGE
12287
  `ifdef PCI_IMAGE0 //      set P_BA0
12288
 
12289
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12290
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12291
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12292
    begin
12293
        $display("Write to configuration space failed! Time %t ", $time) ;
12294
    end
12295
  `endif
12296
 `else //      set P_BA0
12297
 
12298
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12299
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12300
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12301
    begin
12302
        $display("Write to configuration space failed! Time %t ", $time) ;
12303
    end
12304
 `endif
12305
 
12306
`else // GUEST, set Header, set P_BA0
12307
    data            = 32'h0000_0007 ; // enable master & target operation
12308
    byte_enables    = 4'hF ;
12309
    $display(" bridge target - Enabling master and target operation!");
12310 45 mihad
    configuration_cycle_write(0,                        // bus number
12311
                              `TAR0_IDSEL_INDEX - 11,   // device number
12312
                              0,                        // function number
12313
                              1,                        // register number
12314
                              0,                        // type of configuration cycle
12315
                              byte_enables,             // byte enables
12316
                              data                      // data
12317 15 mihad
                             ) ;
12318
 
12319
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12320
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12321
    byte_enables = 4'hf ;
12322 45 mihad
    configuration_cycle_write(0,                        // bus number
12323
                              `TAR0_IDSEL_INDEX - 11,   // device number
12324
                              0,                        // function number
12325
                              4,                        // register number
12326
                              0,                        // type of configuration cycle
12327
                              byte_enables,             // byte enables
12328
                              data                      // data
12329 15 mihad
                             ) ;
12330
 
12331
`endif
12332
end
12333
endtask // configure_bridge_target
12334
 
12335
// Initialize the basic Config Registers of the PCI bridge target device
12336
task configure_bridge_target_base_addresses;
12337
    reg [11:0] offset ;
12338
    reg [31:0] data ;
12339
    `ifdef HOST
12340
    reg `WRITE_STIM_TYPE   write_data ;
12341
    reg `WB_TRANSFER_FLAGS write_flags ;
12342
    reg `WRITE_RETURN_TYPE write_status ;
12343
    `else
12344
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12345
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12346
    `endif
12347
 
12348
    reg [31:0] temp_var ;
12349
begin
12350
`ifdef HOST //  set Header
12351
    offset  = 12'h4 ; // PCI Header Command register
12352
    data    = 32'h0000_0007 ; // enable master & target operation
12353
 
12354
    write_flags                    = 0 ;
12355
    write_flags`INIT_WAITS         = tb_init_waits ;
12356
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12357
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12358
 
12359
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12360
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12361
 
12362
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12363
    write_data`WRITE_SEL      = 4'h1 ;
12364
    write_data`WRITE_TAG_STIM = 0 ;
12365
    write_data`WRITE_DATA     = data ;
12366
 
12367
    next_test_name[79:0] <= "Init_Tar_R";
12368
 
12369
    $display(" bridge target - Enabling master and target operation!");
12370
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12371
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12372
    begin
12373
        $display("Write to configuration space failed! Time %t ", $time) ;
12374
    end
12375
 
12376
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12377
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12378
 
12379
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12380
    write_data`WRITE_SEL      = 4'hf ;
12381
    write_data`WRITE_TAG_STIM = 0 ;
12382
    write_data`WRITE_DATA     = data ;
12383
 
12384
 `ifdef  NO_CNF_IMAGE
12385
  `ifdef PCI_IMAGE0 //      set P_BA0
12386
 
12387
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12388
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12389
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12390
    begin
12391
        $display("Write to configuration space failed! Time %t ", $time) ;
12392
    end
12393
  `endif
12394
 `else //      set P_BA0
12395
 
12396
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12397
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12398
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12399
    begin
12400
        $display("Write to configuration space failed! Time %t ", $time) ;
12401
    end
12402
 `endif
12403
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12404
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12405
 
12406
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12407
    write_data`WRITE_SEL      = 4'hf ;
12408
    write_data`WRITE_TAG_STIM = 0 ;
12409
    write_data`WRITE_DATA     = data ;
12410
 
12411
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12412
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12413
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12414
    begin
12415
        $display("Write to configuration space failed! Time %t ", $time) ;
12416
    end
12417
 `ifdef PCI_IMAGE2
12418
 
12419
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12420
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12421
 
12422
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12423
    write_data`WRITE_SEL      = 4'hf ;
12424
    write_data`WRITE_TAG_STIM = 0 ;
12425
    write_data`WRITE_DATA     = data ;
12426
 
12427
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12428
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12429
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12430
    begin
12431
        $display("Write to configuration space failed! Time %t ", $time) ;
12432
    end
12433
 `endif
12434
 `ifdef PCI_IMAGE3
12435
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12436
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12437
 
12438
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12439
    write_data`WRITE_SEL      = 4'hf ;
12440
    write_data`WRITE_TAG_STIM = 0 ;
12441
    write_data`WRITE_DATA     = data ;
12442
 
12443
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12444
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12445
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12446
    begin
12447
        $display("Write to configuration space failed! Time %t ", $time) ;
12448
    end
12449
 `endif
12450
 `ifdef PCI_IMAGE4
12451
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12452
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12453
 
12454
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12455
    write_data`WRITE_SEL      = 4'hf ;
12456
    write_data`WRITE_TAG_STIM = 0 ;
12457
    write_data`WRITE_DATA     = data ;
12458
 
12459
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12460
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12461
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12462
    begin
12463
        $display("Write to configuration space failed! Time %t ", $time) ;
12464
    end
12465
 `endif
12466
 `ifdef PCI_IMAGE5
12467
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12468
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12469
 
12470
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12471
    write_data`WRITE_SEL      = 4'hf ;
12472
    write_data`WRITE_TAG_STIM = 0 ;
12473
    write_data`WRITE_DATA     = data ;
12474
 
12475
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12476
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12477
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12478
    begin
12479
        $display("Write to configuration space failed! Time %t ", $time) ;
12480
    end
12481
 `endif
12482
 
12483
`else // GUEST, set Header, set P_BA0
12484
    data            = 32'h0000_0007 ; // enable master & target operation
12485
    byte_enables    = 4'hF ;
12486
    $display(" bridge target - Enabling master and target operation!");
12487 45 mihad
    configuration_cycle_write(0,                        // bus number
12488
                              `TAR0_IDSEL_INDEX - 11,   // device number
12489
                              0,                        // function number
12490
                              1,                        // register number
12491
                              0,                        // type of configuration cycle
12492
                              byte_enables,             // byte enables
12493
                              data                      // data
12494 15 mihad
                             ) ;
12495
 
12496
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12497
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12498
    byte_enables = 4'hf ;
12499 45 mihad
    configuration_cycle_write(0,                        // bus number
12500
                              `TAR0_IDSEL_INDEX - 11,   // device number
12501
                              0,                        // function number
12502
                              4,                        // register number
12503
                              0,                        // type of configuration cycle
12504
                              byte_enables,             // byte enables
12505
                              data                      // data
12506 15 mihad
                             ) ;
12507
 
12508
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12509
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12510
    byte_enables = 4'hf ;
12511 45 mihad
    configuration_cycle_write(0,                        // bus number
12512
                              `TAR0_IDSEL_INDEX - 11,   // device number
12513
                              0,                        // function number
12514
                              5,                        // register number
12515
                              0,                        // type of configuration cycle
12516
                              byte_enables,             // byte enables
12517
                              data                      // data
12518 15 mihad
                             ) ;
12519
 `ifdef PCI_IMAGE2
12520
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12521
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12522
    byte_enables = 4'hf ;
12523 45 mihad
    configuration_cycle_write(0,                        // bus number
12524
                              `TAR0_IDSEL_INDEX - 11,   // device number
12525
                              0,                        // function number
12526
                              6,                        // register number
12527
                              0,                        // type of configuration cycle
12528
                              byte_enables,             // byte enables
12529
                              data                      // data
12530 15 mihad
                             ) ;
12531
 `endif
12532
 `ifdef PCI_IMAGE3
12533
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12534
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12535
    byte_enables = 4'hf ;
12536 45 mihad
    configuration_cycle_write(0,                        // bus number
12537
                              `TAR0_IDSEL_INDEX - 11,   // device number
12538
                              0,                        // function number
12539
                              7,                        // register number
12540
                              0,                        // type of configuration cycle
12541
                              byte_enables,             // byte enables
12542
                              data                      // data
12543 15 mihad
                             ) ;
12544
 `endif
12545
 `ifdef PCI_IMAGE4
12546
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12547
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12548
    byte_enables = 4'hf ;
12549 45 mihad
    configuration_cycle_write(0,                        // bus number
12550
                              `TAR0_IDSEL_INDEX - 11,   // device number
12551
                              0,                        // function number
12552
                              8,                        // register number
12553
                              0,                        // type of configuration cycle
12554
                              byte_enables,             // byte enables
12555
                              data                      // data
12556 15 mihad
                             ) ;
12557
 `endif
12558
 `ifdef PCI_IMAGE5
12559
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12560
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12561
    byte_enables = 4'hf ;
12562 45 mihad
    configuration_cycle_write(0,                        // bus number
12563
                              `TAR0_IDSEL_INDEX - 11,   // device number
12564
                              0,                        // function number
12565
                              9,                        // register number
12566
                              0,                        // type of configuration cycle
12567
                              byte_enables,             // byte enables
12568
                              data                      // data
12569 15 mihad
                             ) ;
12570
 `endif
12571
`endif
12572
end
12573
endtask // configure_bridge_target_base_addresses
12574
 
12575
/*--------------------------------------------------------------------------
12576
Test CASES
12577
--------------------------------------------------------------------------*/
12578
 
12579
// function converts PCI address to WB with the same data as the pci_decoder does
12580
function [31:0] pci_to_wb_addr_convert ;
12581
 
12582
    input [31:0] pci_address ;
12583
    input [31:0] translation_address ;
12584
    input [31:0] translate ;
12585
 
12586
    reg   [31:0] temp_address ;
12587
begin
12588
    if ( translate !== 1 )
12589
    begin
12590
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12591
    end
12592
    else
12593
    begin
12594
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12595
    end
12596
 
12597
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12598
    pci_to_wb_addr_convert = temp_address ;
12599
end
12600
endfunction // pci_to_wb_addr_convert
12601
 
12602
// Test normal write and read to WB slave
12603
task test_normal_wr_rd;
12604
  input  [2:0]  Master_ID;
12605
  input  [PCI_BUS_DATA_RANGE:0] Address;
12606
  input  [PCI_BUS_DATA_RANGE:0] Data;
12607
  input  [3:0]  Be;
12608
  input  [2:0]  Image_num;
12609
  input  [9:0]  Set_size;
12610
  input         Set_addr_translation;
12611
  input         Set_prefetch_enable;
12612
  input  [7:0]  Cache_lsize;
12613
  input         Set_wb_wait_states;
12614
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12615
 
12616
  reg    [31:0] rd_address;
12617
  reg    [31:0] rd_data;
12618
  reg    [3:0]  rd_be;
12619
  reg    [11:0] addr_offset;
12620
  reg    [31:0] read_data;
12621
  reg           continue ;
12622
  reg           ok   ;
12623
  reg    [31:0] expect_address ;
12624
  reg    [31:0] expect_rd_address ;
12625
  reg           expect_we ;
12626
  reg    [9:0]  expect_length_wr ;
12627
  reg    [9:0]  expect_length_rd ;
12628
  reg    [9:0]  expect_length_rd1 ;
12629
  reg    [9:0]  expect_length_rd2 ;
12630
  reg    [3:0]  use_rd_cmd ;
12631
  integer       i ;
12632 35 mihad
  reg           error_monitor_done ;
12633 15 mihad
begin:main
12634
 
12635
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12636
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12637
    $display(" - errors will be reported, but they should not occur!");
12638
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12639
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12640
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12641
    if ( ok !== 1 )
12642
    begin
12643
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12644
        test_fail("write to P_ERR_CS register didn't succeede") ;
12645
        disable main;
12646
    end
12647
 
12648
    `ifdef  ADDR_TRAN_IMPL
12649
 
12650
    // set or clear address translation
12651
    if (Set_addr_translation)
12652
    begin
12653
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12654
        $display(" - address translation will be performed!");
12655
    end
12656
    else
12657
    begin
12658
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12659
        $display(" - address translation will not be performed!");
12660
    end
12661
    // set or clear pre-fetch enable
12662
    if (Set_prefetch_enable)
12663
    begin
12664
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12665
        $display(" - bursts can be performed!");
12666
    end
12667
    else
12668
    begin
12669
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12670
        $display(" - bursts can not be performed!");
12671
    end
12672
 
12673
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12674
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12675
    if ( ok !== 1 )
12676
    begin
12677
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12678
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12679
        disable main;
12680
    end
12681
 
12682
    // predict the address and control signals on WB bus
12683
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12684
    expect_we      = 1'b1 ; // WRITE
12685
 
12686
    `else
12687
 
12688
    // address translation is not implemented
12689
    $display("Address translation is NOT implemented for PCI images!");
12690
    // set or clear pre-fetch enable
12691
    if (Set_prefetch_enable)
12692
    begin
12693
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12694
        $display(" - bursts can be performed!");
12695
    end
12696
    else
12697
    begin
12698
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12699
        $display(" - bursts can not be performed!");
12700
    end
12701
 
12702
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12703
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12704
    if ( ok !== 1 )
12705
    begin
12706
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12707
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12708
        disable main;
12709
    end
12710
 
12711
    // predict the address and control signals on WB bus
12712
    expect_address = Address ;
12713
    expect_we      = 1'b1 ; // WRITE
12714
 
12715
    `endif
12716
 
12717
    // set WB SLAVE parameters
12718
    if (Set_wb_wait_states)
12719
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12720
    else
12721
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12722
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12723
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12724
 
12725
    if ( Set_size > (`PCIW_DEPTH - 2) )
12726
    begin
12727
        expect_length_wr = `PCIW_DEPTH - 2 ;
12728
    end
12729
    else
12730
    begin
12731
        expect_length_wr = Set_size ;
12732
    end
12733
    // write through the PCI bridge to WB slave
12734
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12735
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12736
 
12737
    fork
12738
    begin
12739
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12740
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12741
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12742
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12743
        do_pause( 1 ) ;
12744
    end
12745
    begin
12746
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12747
       if ( ok !== 1 )
12748
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12749
       else
12750
           test_ok ;
12751
    end
12752
    join
12753
 
12754
    // predict the address and control signals on WB bus
12755
    expect_we      = 1'b0 ; // READ
12756
 
12757
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12758
    $display("Memory read through PCI bridge to WB slave!");
12759
 
12760
    if ( expect_length_wr == 1 )
12761
    begin
12762
        if (Set_prefetch_enable)
12763
        begin
12764
            expect_length_rd1 = Cache_lsize ;
12765
            expect_length_rd2 = 0 ;
12766
                // If PCI behavioral master must check received DATA
12767
                master2_check_received_data = 0 ;
12768
                    master1_check_received_data = 0 ;
12769
        end
12770
        else
12771
        begin
12772
            expect_length_rd1 = 1 ;
12773
            expect_length_rd2 = 0 ;
12774
                // If PCI behavioral master must check received DATA
12775
                master2_check_received_data = 1 ;
12776
                    master1_check_received_data = 1 ;
12777
        end
12778
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12779
        expect_length_rd  = expect_length_rd1 ;
12780
    end
12781
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12782
    begin
12783
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12784
        expect_length_rd2 = 0 ;
12785
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12786
        expect_length_rd  = expect_length_rd1 ;
12787
                // If PCI behavioral master must check received DATA
12788
        master2_check_received_data = 1 ;
12789
            master1_check_received_data = 1 ;
12790
    end
12791
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12792
    begin
12793
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12794
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12795
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12796
        expect_length_rd  = expect_length_rd1 ;
12797
                // If PCI behavioral master must check received DATA
12798
                master2_check_received_data = 1 ;
12799
            master1_check_received_data = 1 ;
12800
    end
12801
    else
12802
    begin
12803
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12804
        begin
12805
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12806
            expect_length_rd2 = 0 ;
12807
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12808
            expect_length_rd  = expect_length_rd1 ;
12809
                // If PCI behavioral master must check received DATA
12810
                master2_check_received_data = 0 ;
12811
                    master1_check_received_data = 0 ;
12812
        end
12813
        else
12814
        begin
12815
            if ( expect_length_wr > Cache_lsize )
12816
            begin
12817
                expect_length_rd1 = Cache_lsize ;
12818
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12819
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12820
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12821
                else
12822
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12823
                expect_length_rd  = expect_length_rd1 ;
12824
                        // If PCI behavioral master must check received DATA
12825
                        master2_check_received_data = 1 ;
12826
                            master1_check_received_data = 1 ;
12827
            end
12828
            else
12829
            begin
12830
                expect_length_rd1 = Cache_lsize ;
12831
                expect_length_rd2 = 0 ;
12832
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12833
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12834
                else
12835
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12836
                expect_length_rd  = expect_length_wr ;
12837
                                if ( expect_length_wr == Cache_lsize )
12838
                        begin
12839
                                // If PCI behavioral master must check received DATA
12840
                                master2_check_received_data = 1 ;
12841
                                    master1_check_received_data = 1 ;
12842
                                end
12843
                                else
12844
                                begin
12845
                                // If PCI behavioral master must check received DATA
12846
                                master2_check_received_data = 0 ;
12847
                                    master1_check_received_data = 0 ;
12848
                end
12849
            end
12850
        end
12851
    end
12852
 
12853
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12854
    expect_rd_address = expect_address ;
12855
    rd_data[31:0] = Data[31:0];
12856
    rd_be[3:0] = Be[3:0];
12857
 
12858
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12859
    while (expect_length_rd2 > 0)
12860
    begin
12861
        // do read
12862
        $display("Read %d words!", expect_length_rd);
12863
 
12864
        fork
12865
        begin
12866
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12867
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12868
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12869
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12870
 
12871
            wb_transaction_stop( expect_length_rd - 1) ;
12872
 
12873
            do_pause( 1 ) ;
12874
        end
12875
        begin
12876
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12877
            if ( ok !== 1 )
12878
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12879
 
12880
            repeat( 3 )
12881
                @(posedge pci_clock) ;
12882
 
12883
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12884
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12885
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12886
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12887
 
12888
            do_pause( 1 ) ;
12889
            while ( FRAME === 0 )
12890
                @(posedge pci_clock) ;
12891
 
12892
            while ( IRDY === 0 )
12893
                @(posedge pci_clock) ;
12894
 
12895 35 mihad
            #1 ;
12896
            if ( !error_monitor_done )
12897
                disable monitor_error_event1 ;
12898 15 mihad
        end
12899
        begin:monitor_error_event1
12900 35 mihad
            error_monitor_done = 0 ;
12901 15 mihad
            @(error_event_int) ;
12902
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12903
            ok = 0 ;
12904 35 mihad
            error_monitor_done = 1 ;
12905 15 mihad
        end
12906
        join
12907
 
12908
        // increasing the starting address for PCI master and for WB transaction monitor
12909
        rd_address = rd_address + (4 * expect_length_rd) ;
12910
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12911
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12912
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12913
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12914
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12915
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12916
        for (i=0; i<expect_length_rd; i=i+1)
12917
            rd_be[3:0] = {Be[2:0], Be[3]};
12918
 
12919
        // set parameters for next read
12920
        if ( expect_length_rd2 == 1 )
12921
        begin
12922
                if (Set_prefetch_enable)
12923
                begin
12924
                    expect_length_rd1 = Cache_lsize ;
12925
                    expect_length_rd2 = 0 ;
12926
                        // If PCI behavioral master must check received DATA
12927
                        master2_check_received_data = 0 ;
12928
                            master1_check_received_data = 0 ;
12929
                end
12930
                else
12931
                begin
12932
                    expect_length_rd1 = 1 ;
12933
                    expect_length_rd2 = 0 ;
12934
                        // If PCI behavioral master must check received DATA
12935
                        master2_check_received_data = 1 ;
12936
                            master1_check_received_data = 1 ;
12937
                end
12938
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12939
            expect_length_rd  = expect_length_rd1 ;
12940
        end
12941
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12942
        begin
12943
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12944
            expect_length_rd2 = 0 ;
12945
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12946
            expect_length_rd  = expect_length_rd1 ;
12947
                        // If PCI behavioral master must check received DATA
12948
                        master2_check_received_data = 1 ;
12949
                    master1_check_received_data = 1 ;
12950
        end
12951
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12952
        begin
12953
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12954
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12955
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12956
            expect_length_rd  = expect_length_rd1 ;
12957
                        // If PCI behavioral master must check received DATA
12958
                        master2_check_received_data = 1 ;
12959
                    master1_check_received_data = 1 ;
12960
        end
12961
        else
12962
        begin
12963
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12964
            begin
12965
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12966
                expect_length_rd2 = 0 ;
12967
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12968
                expect_length_rd  = expect_length_rd1 ;
12969
                        // If PCI behavioral master must check received DATA
12970
                        master2_check_received_data = 0 ;
12971
                            master1_check_received_data = 0 ;
12972
            end
12973
            else
12974
            begin
12975
                if ( expect_length_rd2 > Cache_lsize )
12976
                begin
12977
                    expect_length_rd1 = Cache_lsize ;
12978
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12979
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12980
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12981
                    else
12982
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12983
                    expect_length_rd  = expect_length_rd1 ;
12984
                                // If PCI behavioral master must check received DATA
12985
                                master2_check_received_data = 1 ;
12986
                                    master1_check_received_data = 1 ;
12987
                end
12988
                else
12989
                begin
12990
                    expect_length_rd  = expect_length_rd2 ;
12991
                    expect_length_rd1 = Cache_lsize ;
12992
                    expect_length_rd2 = 0 ;
12993
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12994
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12995
                    else
12996
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12997
                                        if ( expect_length_rd2 == Cache_lsize )
12998
                                begin
12999
                                        // If PCI behavioral master must check received DATA
13000
                                        master2_check_received_data = 1 ;
13001
                                            master1_check_received_data = 1 ;
13002
                                        end
13003
                                        else
13004
                                        begin
13005
                                        // If PCI behavioral master must check received DATA
13006
                                        master2_check_received_data = 0 ;
13007
                                            master1_check_received_data = 0 ;
13008
                        end
13009
                end
13010
            end
13011
        end
13012
    end
13013
    // do last read
13014
    $display("Read %d words!", expect_length_rd);
13015
 
13016
    fork
13017
    begin
13018
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13019
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13020
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13021
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
13022
 
13023
        wb_transaction_stop(expect_length_rd - 1) ;
13024
        do_pause( 1 ) ;
13025
    end
13026
    begin
13027
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
13028
 
13029
        do_pause(3) ;
13030
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13031
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13032
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13033
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13034
        do_pause(1) ;
13035
 
13036
        while ( FRAME === 0 )
13037
            @(posedge pci_clock) ;
13038
 
13039
        while ( IRDY === 0 )
13040
            @(posedge pci_clock) ;
13041
 
13042 35 mihad
        #1 ;
13043
        if ( !error_monitor_done )
13044
            disable monitor_error_event2 ;
13045 15 mihad
    end
13046
    begin:monitor_error_event2
13047 35 mihad
        error_monitor_done = 0 ;
13048 15 mihad
        @(error_event_int) ;
13049
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13050
        ok = 0 ;
13051 35 mihad
        error_monitor_done = 1 ;
13052 15 mihad
    end
13053
    join
13054
 
13055
    if ( ok )
13056
        test_ok ;
13057
 
13058
    // Check that no ERRORs were reported
13059
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
13060
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
13061
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13062
    config_read( addr_offset, 4'hF, read_data ) ;
13063
    if ( read_data[8] !== 0 )
13064
    begin
13065
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
13066
        test_fail("error status was set even though no errors occured on WB bus") ;
13067
    end
13068
    else
13069
    begin
13070
        $display("No error was signaled, as expected!");
13071
        test_ok ;
13072
    end
13073
 
13074
end // main
13075
endtask // test_normal_wr_rd
13076
 
13077
// Test erroneous write to WB slave
13078
task test_wb_error_wr;
13079
  input  [2:0]  Master_ID;
13080
  input  [PCI_BUS_DATA_RANGE:0] Address;
13081
  input  [PCI_BUS_DATA_RANGE:0] Data;
13082
  input  [3:0]  Be;
13083
  input  [2:0]  Image_num;
13084
  input  [9:0]  Set_size;
13085
  input         Set_err_and_int_report;
13086
  input         Set_wb_wait_states;
13087
  input  [1:0]  Imm_BefLast_Last_error;
13088
 
13089
  reg    [11:0] addr_offset;
13090
  reg    [31:0] read_data;
13091
  reg           continue ;
13092
  reg           ok   ;
13093
  reg    [9:0]  expect_length ;
13094
  reg    [31:0] expect_address ;
13095
  reg    [0:0]  expect_we ;
13096
  reg    [31:0] rd_address;
13097
  reg    [31:0] rd_data;
13098
  reg    [3:0]  rd_be;
13099
  integer       i ;
13100
begin:main
13101
    if (Set_err_and_int_report)
13102
    begin
13103
        // enable ERROR reporting, because error must be reported and interrupt if required!
13104
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13105
        $display(" - errors will be reported when they will occur!");
13106
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
13107
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13108
        $display(" - interrupt will be reported when error will occur!");
13109
    end
13110
    else
13111
    begin
13112
        // disable ERROR reporting, because error and interrupt must not be reported!
13113
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13114
        $display(" - errors will NOT be reported when they will occur!");
13115
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
13116
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13117
        $display(" - interrupt will NOT be reported when error will occur!");
13118
    end
13119
    // enable/disable ERROR reporting
13120
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
13121
 
13122
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13123
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
13124
    if ( ok !== 1 )
13125
    begin
13126
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13127
        test_fail("PCI Error Control and Status register could not be written") ;
13128
        disable main;
13129
    end
13130
    // enable/disable INTERRUPT reporting
13131
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13132
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
13133
    if ( ok !== 1 )
13134
    begin
13135
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
13136
        test_fail("Interrupt Control register could not be written") ;
13137
        disable main;
13138
    end
13139
 
13140
    `ifdef  ADDR_TRAN_IMPL
13141
 
13142
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
13143
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13144
    config_read( addr_offset, 4'hF, read_data ) ;
13145
    if ( read_data[2] !== 0 )
13146
    begin
13147
        $display("Address translation is set for PCI image%d!", Image_num);
13148
        // predict the address and control signals on WB bus
13149
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13150
        expect_we      = 1'b1 ; // WRITE
13151
    end
13152
    else
13153
    begin
13154
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13155
        // predict the address and control signals on WB bus
13156
        expect_address = Address ;
13157
        expect_we      = 1'b1 ; // WRITE
13158
    end
13159
 
13160
    `else
13161
 
13162
    // address translation is not implemented
13163
    $display("Address translation is NOT implemented for PCI images!");
13164
    // predict the address and control signals on WB bus
13165
    expect_address = Address ;
13166
    expect_we      = 1'b1 ; // WRITE
13167
 
13168
    `endif
13169
 
13170
    if ( Set_size > (`PCIW_DEPTH - 2) )
13171
    begin
13172
        expect_length = `PCIW_DEPTH - 2 ;
13173
    end
13174
    else
13175
    begin
13176
        expect_length = Set_size ;
13177
    end
13178
 
13179
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13180
    begin
13181
        $display("ERR termination with first data!");
13182
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13183
    end
13184
    else if (Imm_BefLast_Last_error == 1)
13185
    begin
13186
        $display("ERR termination before last data!");
13187
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13188
    end
13189
    else
13190
    begin
13191
        $display("ERR termination with last data!");
13192
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13193
    end
13194
 
13195
    // write through the PCI bridge to WB slave
13196
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13197
    fork
13198
    begin
13199
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13200
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13201
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13202
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13203
        do_pause( 1 ) ;
13204
    end
13205
    begin
13206
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13207
        begin
13208
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13209
            if ( ok !== 1 )
13210
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13211
        end
13212
        else if (Imm_BefLast_Last_error == 1)
13213
        begin
13214
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13215
            if ( ok !== 1 )
13216
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13217
        end
13218
        else
13219
        begin
13220
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13221
            if ( ok !== 1 )
13222
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13223
        end
13224
    end
13225
    begin
13226
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13227
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13228
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13229
        else if (Imm_BefLast_Last_error == 1)
13230
        begin
13231
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13232
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13233
            wb_transaction_stop(expect_length-2) ;
13234
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13235
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13236
        end
13237
        else
13238
        begin
13239
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13240
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13241
            wb_transaction_stop(expect_length-1) ;
13242
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13243
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13244
        end
13245
    end
13246
    join
13247
 
13248
    if ( ok )
13249
        test_ok ;
13250
 
13251
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13252
    begin
13253
        rd_data[31:0] = Data[31:0];
13254
        rd_address[31:0] = expect_address;
13255
        rd_be[3:0] = Be[3:0];
13256
    end
13257
    else if (Imm_BefLast_Last_error == 1)
13258
    begin
13259
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13260
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13261
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13262
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13263
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13264
        rd_be[3:0] = Be[3:0];
13265
        for (i=0; i<(expect_length-2); i=i+1)
13266
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13267
    end
13268
    else
13269
    begin
13270
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13271
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13272
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13273
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13274
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13275
        rd_be[3:0] = Be[3:0];
13276
        for (i=0; i<(expect_length-1); i=i+1)
13277
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13278
    end
13279
 
13280
    master2_check_received_data = 0 ;
13281
    master1_check_received_data = 0 ;
13282
 
13283
    // Check if ERRORs were reported
13284
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13285
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13286
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13287
 
13288
    ok = 1 ;
13289
    config_read( addr_offset, 4'hF, read_data ) ;
13290
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13291
    begin
13292
        $display("Error was signaled and reported, as expected!");
13293
        if (read_data[31:28] === rd_be)
13294
            $display("Byte enables written into P_ERR_CS register are as expected!");
13295
        else
13296
        begin
13297
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13298
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13299
            ok = 0 ;
13300
        end
13301
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13302
            $display("Bus command written into P_ERR_CS register is as expected!");
13303
        else
13304
        begin
13305
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13306
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13307
            ok = 0 ;
13308
        end
13309
 
13310
        if ( ok )
13311
            test_ok ;
13312
 
13313
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13314
 
13315
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13316
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13317
        config_read( addr_offset, 4'hF, read_data ) ;
13318
        if (read_data === rd_data)
13319
        begin
13320
            $display("Data written into P_ERR_DATA register is as expected!");
13321
            test_ok ;
13322
        end
13323
        else
13324
        begin
13325
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13326
            test_fail("PCI Erroneous Data register value was wrong") ;
13327
        end
13328
 
13329
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13330
 
13331
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13332
 
13333
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13334
        config_read( addr_offset, 4'hF, read_data ) ;
13335
        if (read_data === rd_address)
13336
        begin
13337
            $display("Address written into P_ERR_ADDR register is as expected!");
13338
            test_ok ;
13339
        end
13340
        else
13341
        begin
13342
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13343
            test_fail("PCI Erroneous Address register value was wrong") ;
13344
        end
13345
    end
13346
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13347
    begin
13348
        $display("Error was signaled and not reported, as expected!");
13349
        test_ok ;
13350
    end
13351
    else
13352
    begin
13353
        $display("Error was signaled and reported, as NOT expected!");
13354
        test_fail("Error status bit was set event though error reporting was disabled") ;
13355
    end
13356
 
13357
    // Check if Interrupts were reported
13358
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13359
 
13360
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13361
    ok = 1 ;
13362
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13363
    config_read( addr_offset, 4'hF, read_data ) ;
13364
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13365
    begin
13366
        $display("Interrupts was signaled and reported, as expected!");
13367
    end
13368
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13369
    begin
13370
        $display("Interrupts was signaled and not reported, as expected!");
13371
    end
13372
    else
13373
    begin
13374
        $display("Interrupt was signaled and reported, as NOT expected!");
13375
        test_fail("PCI Error Interrupt status was set when not expected") ;
13376
        ok = 0 ;
13377
    end
13378
 
13379
    `ifdef HOST
13380
    repeat( 4 )
13381
        @(posedge wb_clock) ;
13382
 
13383
    if ( INT_O === Set_err_and_int_report )
13384
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13385
    else
13386
    begin
13387
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13388
        test_fail("Interrupt request didn't have expected value") ;
13389
        ok = 0 ;
13390
    end
13391
 
13392
    `else // GUEST
13393
    repeat( 4 )
13394
        @(posedge pci_clock) ;
13395
 
13396
    if ( INTA === !Set_err_and_int_report )
13397
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13398
    else
13399
    begin
13400
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13401
        test_fail("Interrupt request didn't have expected value") ;
13402
        ok = 0 ;
13403
    end
13404
 
13405
    `endif
13406
 
13407
    if ( ok )
13408
        test_ok ;
13409
 
13410
    if (Set_err_and_int_report)
13411
    begin
13412
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13413
        $display("Error and Interrupt must be cleared!");
13414
        // clear  ERROR reporting bit
13415
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13416
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13417
        if ( ok !== 1 )
13418
        begin
13419
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13420
            test_fail("PCI Error Control and Status register could not be written to") ;
13421
            disable main;
13422
        end
13423
 
13424
        // clear INTERRUPT reporting bit
13425
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13426
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13427
        if ( ok !== 1 )
13428
        begin
13429
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13430
            test_fail("Interrupt Status register could not be written to") ;
13431
            disable main;
13432
        end
13433
 
13434
        test_ok ;
13435
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13436
        `ifdef HOST
13437
 
13438
        repeat(4)
13439
            @(posedge wb_clock) ;
13440
        if ( INT_O === 1'b0 )
13441
        begin
13442
            $display("Interrupt pin INT_O was correctly cleared!");
13443
            test_ok ;
13444
        end
13445
        else
13446
        begin
13447
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13448
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13449
            disable main;
13450
        end
13451
 
13452
        `else // GUEST
13453
 
13454
        repeat(4)
13455
            @(posedge pci_clock) ;
13456
        if ( INTA === 1'b1 )
13457
        begin
13458
            $display("Interrupt pin INTA was correctly cleared!");
13459
            test_ok ;
13460
        end
13461
        else
13462
        begin
13463
            $display("Interrupt pin INTA was NOT correctly cleared!");
13464
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13465
            disable main;
13466
        end
13467
 
13468
        `endif
13469
 
13470
    end
13471
    else
13472
    begin
13473
        $display("Error and Interrupt don't need to be cleared!");
13474
    end
13475
end // main
13476
endtask // test_wb_error_wr
13477
 
13478
task test_wb_error_rd;
13479
    reg    [11:0] addr_offset ;
13480
    reg    [11:0] ctrl_offset ;
13481
    reg    [11:0] ba_offset ;
13482
    reg    [11:0] am_offset ;
13483
    reg    [11:0] ta_offset ;
13484
    reg    [31:0] read_data;
13485
    reg           ok   ;
13486
    reg    [9:0]  expect_length ;
13487
    reg    [31:0] expect_address ;
13488
    reg    [0:0]  expect_we ;
13489
    reg    [31:0] rd_address;
13490
    reg    [31:0] rd_data;
13491
    reg    [3:0]  rd_be;
13492
    integer       i ;
13493
    reg           do_mem_aborts ;
13494
    reg           do_io_aborts ;
13495 35 mihad
    reg           error_monitor_done ;
13496 15 mihad
begin:main
13497
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13498
 
13499
    if ( target_mem_image !== -1 )
13500
    begin
13501
        do_mem_aborts = 1 ;
13502
 
13503
        if (target_mem_image === 1)
13504
        begin
13505
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13506
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13507
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13508
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13509
        end
13510
        else if (target_mem_image === 2)
13511
        begin
13512
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13513
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13514
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13515
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13516
        end
13517
        else if (target_mem_image === 3)
13518
        begin
13519
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13520
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13521
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13522
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13523
        end
13524
        else if (target_mem_image === 4)
13525
        begin
13526
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13527
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13528
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13529
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13530
        end
13531
        else if (target_mem_image === 5)
13532
        begin
13533
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13534
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13535
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13536
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13537
        end
13538
    end
13539
    else
13540
        do_mem_aborts = 0 ;
13541
 
13542
    if ( do_mem_aborts )
13543
    begin
13544
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13545
 
13546
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13547
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13548
        if ( ok !== 1 )
13549
        begin
13550
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13551
            test_fail("PCI Error Control and Status register could not be written") ;
13552
            disable main;
13553
        end
13554
 
13555
        // enable INTERRUPT reporting
13556
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13557
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13558
        if ( ok !== 1 )
13559
        begin
13560
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13561
            test_fail("Interrupt Control register could not be written") ;
13562
            disable main;
13563
        end
13564
 
13565
        addr_offset = 12'h010 + (4*target_mem_image) ;
13566
 
13567
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13568
        if ( ok !== 1 )
13569
        begin
13570
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13571
            test_fail("PCI Base Address register could not be written") ;
13572
            disable main;
13573
        end
13574
 
13575
        // disable address translation and enable prefetch so read bursts can be performed
13576
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13577
        if ( ok !== 1 )
13578
        begin
13579
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13580
            test_fail("PCI Image Control register could not be written") ;
13581
            disable main;
13582
        end
13583
 
13584
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13585
        if ( ok !== 1 )
13586
        begin
13587
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13588
            test_fail("PCI Address Mask register could not be written") ;
13589
            disable main;
13590
        end
13591
 
13592
        addr_offset = 12'h00C ;
13593
 
13594
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13595
        if ( ok !== 1 )
13596
        begin
13597
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13598
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13599
            disable main;
13600
        end
13601
 
13602
        // disable PCI master data checking
13603
        master1_check_received_data = 0 ;
13604
 
13605
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13606
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13607
 
13608
 
13609
        // do a single read error terminated on WB bus
13610
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13611
 
13612
        fork
13613
        begin
13614
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13615
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13616
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13617
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13618
 
13619
            do_pause( 1 ) ;
13620
        end
13621
        begin
13622
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13623
 
13624
            if ( ok !== 1 )
13625
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13626
 
13627
            do_pause(3) ;
13628
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13629
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13630
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13631
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13632
            do_pause(1) ;
13633
 
13634
            while ( FRAME === 0 )
13635
                @(posedge pci_clock) ;
13636
 
13637
            while ( IRDY === 0 )
13638
                @(posedge pci_clock) ;
13639
 
13640 35 mihad
            #1 ;
13641
            if ( !error_monitor_done )
13642
                disable monitor_error_event1 ;
13643 15 mihad
        end
13644
        begin:monitor_error_event1
13645 35 mihad
            error_monitor_done = 0 ;
13646 15 mihad
            @(error_event_int) ;
13647
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13648
            ok = 0 ;
13649 35 mihad
            error_monitor_done = 1 ;
13650 15 mihad
        end
13651
        join
13652
 
13653
        if ( ok )
13654
            test_ok ;
13655 26 mihad
 
13656
        @(posedge pci_clock) ;
13657
        @(posedge pci_clock) ;
13658
        @(posedge wb_clock) ;
13659
        @(posedge wb_clock) ;
13660 15 mihad
 
13661
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13662
        addr_offset = 12'h004 ;
13663
        config_read(addr_offset, 4'hF, read_data) ;
13664
        ok = 1 ;
13665
        if ( read_data[27] !== 1 )
13666
        begin
13667
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13668
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13669
            ok = 0 ;
13670
        end
13671
        if ( read_data[28] !== 0 )
13672
        begin
13673
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13674
            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") ;
13675
            ok = 0 ;
13676
        end
13677
        if ( read_data[29] !== 0 )
13678
        begin
13679
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13680
            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") ;
13681
            ok = 0 ;
13682
        end
13683
 
13684
        // clear statuses
13685
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13686
        if ( !ok )
13687
        begin
13688
            test_fail("write to PCI Device Status register failed") ;
13689
            $display("Couldn't write PCI Device Status register") ;
13690
            disable main ;
13691
        end
13692
 
13693
        if ( ok )
13694
            test_ok ;
13695
 
13696
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13697
 
13698
        ok = 1 ;
13699
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13700
 
13701
        config_read(addr_offset, 4'hF, read_data) ;
13702
        if (read_data[8] !== 0)
13703
        begin
13704
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13705
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13706
            ok = 0 ;
13707
        end
13708
        else
13709
            test_ok ;
13710
 
13711
        if ( ok !== 1 )
13712
        begin
13713
            config_write(addr_offset, read_data, 4'hF, ok) ;
13714
            if ( !ok )
13715
            begin
13716
                test_fail("PCI Error Control and Status register could not be written") ;
13717
                disable main ;
13718
            end
13719
        end
13720
 
13721
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13722
        fork
13723
        begin
13724
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13725
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13726
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13727
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13728
 
13729
            do_pause( 1 ) ;
13730
        end
13731
        begin
13732
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13733
 
13734
            if ( ok !== 1 )
13735
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13736
 
13737
            do_pause(3) ;
13738
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13739
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13740
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13741
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13742
            do_pause(1) ;
13743
 
13744
            while ( FRAME === 0 )
13745
                @(posedge pci_clock) ;
13746
 
13747
            while ( IRDY === 0 )
13748
                @(posedge pci_clock) ;
13749
 
13750 35 mihad
            #1 ;
13751
            if ( !error_monitor_done )
13752
                disable monitor_error_event2 ;
13753 15 mihad
        end
13754
        begin:monitor_error_event2
13755 35 mihad
            error_monitor_done = 0 ;
13756 15 mihad
            @(error_event_int) ;
13757
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13758
            ok = 0 ;
13759 35 mihad
            error_monitor_done = 1 ;
13760 15 mihad
        end
13761
        join
13762
 
13763
        if ( ok )
13764
            test_ok ;
13765
 
13766 26 mihad
        @(posedge pci_clock) ;
13767
        @(posedge pci_clock) ;
13768
        @(posedge wb_clock) ;
13769
        @(posedge wb_clock) ;
13770
 
13771 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13772
        addr_offset = 12'h004 ;
13773
        config_read(addr_offset, 4'hF, read_data) ;
13774
        ok = 1 ;
13775
        if ( read_data[27] !== 1 )
13776
        begin
13777
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13778
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13779
            ok = 0 ;
13780
        end
13781
        if ( read_data[28] !== 0 )
13782
        begin
13783
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13784
            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") ;
13785
            ok = 0 ;
13786
        end
13787
        if ( read_data[29] !== 0 )
13788
        begin
13789
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13790
            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") ;
13791
            ok = 0 ;
13792
        end
13793
 
13794
        // clear statuses
13795
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13796
        if ( !ok )
13797
        begin
13798
            test_fail("write to PCI Device Status register failed") ;
13799
            $display("Couldn't write PCI Device Status register") ;
13800
            disable main ;
13801
        end
13802
 
13803
        if ( ok )
13804
            test_ok ;
13805
 
13806
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13807
 
13808
        ok = 1 ;
13809
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13810
 
13811
        config_read(addr_offset, 4'hF, read_data) ;
13812
        if (read_data[8] !== 0)
13813
        begin
13814
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13815
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13816
            ok = 0 ;
13817
        end
13818
        else
13819
            test_ok ;
13820
 
13821
        if ( ok !== 1 )
13822
        begin
13823
            config_write(addr_offset, read_data, 4'hF, ok) ;
13824
            if ( !ok )
13825
            begin
13826
                test_fail("PCI Error Control and Status register could not be written") ;
13827
                disable main ;
13828
            end
13829
        end
13830
 
13831
        // do a single read error terminated on WB bus
13832
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13833
 
13834
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13835
 
13836
        fork
13837
        begin
13838
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13839
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13840
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13841
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13842
 
13843
            do_pause( 1 ) ;
13844
        end
13845
        begin
13846
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13847
 
13848
            if ( ok !== 1 )
13849
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13850
 
13851
            do_pause(3) ;
13852
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13853
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13854
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13855
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13856
            do_pause(1) ;
13857
 
13858
            while ( FRAME === 0 )
13859
                @(posedge pci_clock) ;
13860
 
13861
            while ( IRDY === 0 )
13862
                @(posedge pci_clock) ;
13863
 
13864 35 mihad
            if ( !error_monitor_done )
13865
                disable monitor_error_event3 ;
13866 15 mihad
        end
13867
        begin:monitor_error_event3
13868 35 mihad
            error_monitor_done = 0 ;
13869 15 mihad
            @(error_event_int) ;
13870
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13871
            ok = 0 ;
13872 35 mihad
            error_monitor_done = 1 ;
13873 15 mihad
        end
13874
        join
13875
 
13876
        if ( ok )
13877
            test_ok ;
13878
 
13879 26 mihad
        @(posedge pci_clock) ;
13880
        @(posedge pci_clock) ;
13881
        @(posedge wb_clock) ;
13882
        @(posedge wb_clock) ;
13883
 
13884 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13885
        addr_offset = 12'h004 ;
13886
        config_read(addr_offset, 4'hF, read_data) ;
13887
        ok = 1 ;
13888
        if ( read_data[27] !== 1 )
13889
        begin
13890
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13891
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13892
            ok = 0 ;
13893
        end
13894
        if ( read_data[28] !== 0 )
13895
        begin
13896
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13897
            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") ;
13898
            ok = 0 ;
13899
        end
13900
        if ( read_data[29] !== 0 )
13901
        begin
13902
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13903
            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") ;
13904
            ok = 0 ;
13905
        end
13906
 
13907
        // clear statuses
13908
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13909
        if ( !ok )
13910
        begin
13911
            test_fail("write to PCI Device Status register failed") ;
13912
            $display("Couldn't write PCI Device Status register") ;
13913
            disable main ;
13914
        end
13915
 
13916
        if ( ok )
13917
            test_ok ;
13918
 
13919
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13920
 
13921
        ok = 1 ;
13922
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13923
 
13924
        config_read(addr_offset, 4'hF, read_data) ;
13925
        if (read_data[8] !== 0)
13926
        begin
13927
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13928
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13929
            ok = 0 ;
13930
        end
13931
        else
13932
            test_ok ;
13933
 
13934
        if ( ok !== 1 )
13935
        begin
13936
            config_write(addr_offset, read_data, 4'hF, ok) ;
13937
            if ( !ok )
13938
            begin
13939
                test_fail("PCI Error Control and Status register could not be written") ;
13940
                disable main ;
13941
            end
13942
        end
13943
 
13944
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13945
 
13946
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13947
 
13948
        fork
13949
        begin
13950
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13951
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13952
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13953
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13954
 
13955
            do_pause( 1 ) ;
13956
        end
13957
        begin
13958
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13959
 
13960
            if ( ok !== 1 )
13961
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13962
 
13963
            do_pause(3) ;
13964
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13965
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13966
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13967
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13968
            do_pause(1) ;
13969
 
13970
            while ( FRAME === 0 )
13971
                @(posedge pci_clock) ;
13972
 
13973
            while ( IRDY === 0 )
13974
                @(posedge pci_clock) ;
13975
 
13976 35 mihad
            #1 ;
13977
            if ( !error_monitor_done )
13978
                disable monitor_error_event4 ;
13979 15 mihad
        end
13980
        begin:monitor_error_event4
13981 35 mihad
            error_monitor_done = 0 ;
13982 15 mihad
            @(error_event_int) ;
13983
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13984
            ok = 0 ;
13985 35 mihad
            error_monitor_done = 1 ;
13986 15 mihad
        end
13987
        begin
13988
            wb_transaction_stop( 1 ) ;
13989
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13990
        end
13991
        join
13992
 
13993
        if ( ok )
13994
            test_ok ;
13995
 
13996 26 mihad
        @(posedge pci_clock) ;
13997
        @(posedge pci_clock) ;
13998
        @(posedge wb_clock) ;
13999
        @(posedge wb_clock) ;
14000
 
14001 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14002
        addr_offset = 12'h004 ;
14003
        config_read(addr_offset, 4'hF, read_data) ;
14004
        ok = 1 ;
14005
        if ( read_data[27] !== 1 )
14006
        begin
14007
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14008
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14009
            ok = 0 ;
14010
        end
14011
        if ( read_data[28] !== 0 )
14012
        begin
14013
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14014
            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") ;
14015
            ok = 0 ;
14016
        end
14017
        if ( read_data[29] !== 0 )
14018
        begin
14019
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14020
            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") ;
14021
            ok = 0 ;
14022
        end
14023
 
14024
        // clear statuses
14025
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14026
        if ( !ok )
14027
        begin
14028
            test_fail("write to PCI Device Status register failed") ;
14029
            $display("Couldn't write PCI Device Status register") ;
14030
            disable main ;
14031
        end
14032
 
14033
        if ( ok )
14034
            test_ok ;
14035
 
14036
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14037
 
14038
        ok = 1 ;
14039
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14040
 
14041
        config_read(addr_offset, 4'hF, read_data) ;
14042
        if (read_data[8] !== 0)
14043
        begin
14044
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14045
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14046
            ok = 0 ;
14047
        end
14048
        else
14049
            test_ok ;
14050
 
14051
        if ( ok !== 1 )
14052
        begin
14053
            config_write(addr_offset, read_data, 4'hF, ok) ;
14054
            if ( !ok )
14055
            begin
14056
                test_fail("PCI Error Control and Status register could not be written") ;
14057
                disable main ;
14058
            end
14059
        end
14060
 
14061
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14062
 
14063
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14064
 
14065
        fork
14066
        begin
14067
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14068
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14069
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14070
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14071
 
14072
            do_pause( 1 ) ;
14073
        end
14074
        begin
14075
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14076
 
14077
            if ( ok !== 1 )
14078
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14079
 
14080
            do_pause(3) ;
14081
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14082
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14083
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14084
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14085
            do_pause(1) ;
14086
 
14087
            while ( FRAME === 0 )
14088
                @(posedge pci_clock) ;
14089
 
14090
            while ( IRDY === 0 )
14091
                @(posedge pci_clock) ;
14092
 
14093 35 mihad
            #1 ;
14094
            if ( !error_monitor_done )
14095
                disable monitor_error_event5 ;
14096 15 mihad
        end
14097
        begin:monitor_error_event5
14098 35 mihad
            error_monitor_done = 0 ;
14099 15 mihad
            @(error_event_int) ;
14100
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14101
            ok = 0 ;
14102 35 mihad
            error_monitor_done = 1 ;
14103 15 mihad
        end
14104
        begin
14105
            wb_transaction_stop( 3 ) ;
14106
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14107
        end
14108
        join
14109
 
14110
        if ( ok )
14111
            test_ok ;
14112
 
14113 26 mihad
        @(posedge pci_clock) ;
14114
        @(posedge pci_clock) ;
14115
        @(posedge wb_clock) ;
14116
        @(posedge wb_clock) ;
14117
 
14118 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14119
        addr_offset = 12'h004 ;
14120
        config_read(addr_offset, 4'hF, read_data) ;
14121
        ok = 1 ;
14122
        if ( read_data[27] !== 1 )
14123
        begin
14124
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14125
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14126
            ok = 0 ;
14127
        end
14128
        if ( read_data[28] !== 0 )
14129
        begin
14130
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14131
            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") ;
14132
            ok = 0 ;
14133
        end
14134
        if ( read_data[29] !== 0 )
14135
        begin
14136
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14137
            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") ;
14138
            ok = 0 ;
14139
        end
14140
 
14141
        // clear statuses
14142
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14143
        if ( !ok )
14144
        begin
14145
            test_fail("write to PCI Device Status register failed") ;
14146
            $display("Couldn't write PCI Device Status register") ;
14147
            disable main ;
14148
        end
14149
 
14150
        if ( ok )
14151
            test_ok ;
14152
 
14153
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14154
 
14155
        ok = 1 ;
14156
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14157
 
14158
        config_read(addr_offset, 4'hF, read_data) ;
14159
        if (read_data[8] !== 0)
14160
        begin
14161
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14162
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14163
            ok = 0 ;
14164
        end
14165
        else
14166
            test_ok ;
14167
 
14168
        if ( ok !== 1 )
14169
        begin
14170
            config_write(addr_offset, read_data, 4'hF, ok) ;
14171
            if ( !ok )
14172
            begin
14173
                test_fail("PCI Error Control and Status register could not be written") ;
14174
                disable main ;
14175
            end
14176
        end
14177
 
14178
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14179
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14180
        fork
14181
        begin
14182
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14183
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14184
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14185
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14186
 
14187
            do_pause( 1 ) ;
14188
        end
14189
        begin
14190
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14191
 
14192
            if ( ok !== 1 )
14193
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14194
 
14195
            do_pause(3) ;
14196
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14197
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14198
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14199
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14200
            do_pause(1) ;
14201
 
14202
            while ( FRAME === 0 )
14203
                @(posedge pci_clock) ;
14204
 
14205
            while ( IRDY === 0 )
14206
                @(posedge pci_clock) ;
14207
 
14208 35 mihad
            #1 ;
14209
            if ( !error_monitor_done )
14210
                disable monitor_error_event6 ;
14211 15 mihad
        end
14212
        begin:monitor_error_event6
14213 35 mihad
            error_monitor_done = 0 ;
14214 15 mihad
            @(error_event_int) ;
14215
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14216
            ok = 0 ;
14217 35 mihad
            error_monitor_done = 1 ;
14218 15 mihad
        end
14219
        begin
14220
            wb_transaction_stop( 3 ) ;
14221
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14222
        end
14223
        join
14224
 
14225
        if ( ok )
14226
            test_ok ;
14227
 
14228 26 mihad
        @(posedge pci_clock) ;
14229
        @(posedge pci_clock) ;
14230
        @(posedge wb_clock) ;
14231
        @(posedge wb_clock) ;
14232
 
14233 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14234
        addr_offset = 12'h004 ;
14235
        config_read(addr_offset, 4'hF, read_data) ;
14236
        ok = 1 ;
14237
        if ( read_data[27] !== 1 )
14238
        begin
14239
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14240
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14241
            ok = 0 ;
14242
        end
14243
        if ( read_data[28] !== 0 )
14244
        begin
14245
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14246
            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") ;
14247
            ok = 0 ;
14248
        end
14249
        if ( read_data[29] !== 0 )
14250
        begin
14251
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14252
            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") ;
14253
            ok = 0 ;
14254
        end
14255
 
14256
        // clear statuses
14257
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14258
        if ( !ok )
14259
        begin
14260
            test_fail("write to PCI Device Status register failed") ;
14261
            $display("Couldn't write PCI Device Status register") ;
14262
            disable main ;
14263
        end
14264
 
14265
        if ( ok )
14266
            test_ok ;
14267
 
14268
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14269
 
14270
        ok = 1 ;
14271
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14272
 
14273
        config_read(addr_offset, 4'hF, read_data) ;
14274
        if (read_data[8] !== 0)
14275
        begin
14276
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14277
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14278
            ok = 0 ;
14279
        end
14280
        else
14281
            test_ok ;
14282
 
14283
        if ( ok !== 1 )
14284
        begin
14285
            config_write(addr_offset, read_data, 4'hF, ok) ;
14286
            if ( !ok )
14287
            begin
14288
                test_fail("PCI Error Control and Status register could not be written") ;
14289
                disable main ;
14290
            end
14291
        end
14292
 
14293
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14294
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14295
        fork
14296
        begin
14297
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14298
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14299
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14300
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14301
 
14302
            do_pause( 1 ) ;
14303
        end
14304
        begin
14305
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14306
 
14307
            if ( ok !== 1 )
14308
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14309
 
14310
            do_pause(3) ;
14311
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14312
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14313
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14314
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14315
            do_pause(1) ;
14316
 
14317
            while ( FRAME === 0 )
14318
                @(posedge pci_clock) ;
14319
 
14320
            while ( IRDY === 0 )
14321
                @(posedge pci_clock) ;
14322
 
14323 35 mihad
            #1 ;
14324
            if ( !error_monitor_done )
14325
                disable monitor_error_event7 ;
14326 15 mihad
        end
14327
        begin:monitor_error_event7
14328 35 mihad
            error_monitor_done = 0 ;
14329 15 mihad
            @(error_event_int) ;
14330
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14331
            ok = 0 ;
14332 35 mihad
            error_monitor_done = 1 ;
14333 15 mihad
        end
14334
        begin
14335
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14336
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14337
        end
14338
        join
14339
 
14340
        if ( ok )
14341
            test_ok ;
14342
 
14343 26 mihad
        @(posedge pci_clock) ;
14344
        @(posedge pci_clock) ;
14345
        @(posedge wb_clock) ;
14346
        @(posedge wb_clock) ;
14347
 
14348 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14349
        addr_offset = 12'h004 ;
14350
        config_read(addr_offset, 4'hF, read_data) ;
14351
        ok = 1 ;
14352
        if ( read_data[27] !== 1 )
14353
        begin
14354
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14355
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14356
            ok = 0 ;
14357
        end
14358
        if ( read_data[28] !== 0 )
14359
        begin
14360
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14361
            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") ;
14362
            ok = 0 ;
14363
        end
14364
        if ( read_data[29] !== 0 )
14365
        begin
14366
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14367
            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") ;
14368
            ok = 0 ;
14369
        end
14370
 
14371
        // clear statuses
14372
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14373
        if ( !ok )
14374
        begin
14375
            test_fail("write to PCI Device Status register failed") ;
14376
            $display("Couldn't write PCI Device Status register") ;
14377
            disable main ;
14378
        end
14379
 
14380
        if ( ok )
14381
            test_ok ;
14382
 
14383
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14384
 
14385
        ok = 1 ;
14386
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14387
 
14388
        config_read(addr_offset, 4'hF, read_data) ;
14389
        if (read_data[8] !== 0)
14390
        begin
14391
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14392
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14393
            ok = 0 ;
14394
        end
14395
        else
14396
            test_ok ;
14397
 
14398
        if ( ok !== 1 )
14399
        begin
14400
            config_write(addr_offset, read_data, 4'hF, ok) ;
14401
            if ( !ok )
14402
            begin
14403
                test_fail("PCI Error Control and Status register could not be written") ;
14404
                disable main ;
14405
            end
14406
        end
14407
 
14408
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14409
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14410
        fork
14411
        begin
14412
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14413
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14414
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14415
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14416
 
14417
            do_pause( 1 ) ;
14418
        end
14419
        begin
14420
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14421
 
14422
            if ( ok !== 1 )
14423
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14424
 
14425
            do_pause(3) ;
14426
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14427
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14428
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14429
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14430
            do_pause(1) ;
14431
 
14432
            while ( FRAME === 0 )
14433
                @(posedge pci_clock) ;
14434
 
14435
            while ( IRDY === 0 )
14436
                @(posedge pci_clock) ;
14437
 
14438 35 mihad
            #1 ;
14439
            if ( !error_monitor_done )
14440
                disable monitor_error_event8 ;
14441 15 mihad
        end
14442
        begin:monitor_error_event8
14443 35 mihad
            error_monitor_done = 0 ;
14444 15 mihad
            @(error_event_int) ;
14445
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14446
            ok = 0 ;
14447 35 mihad
            error_monitor_done = 1 ;
14448 15 mihad
        end
14449
        begin
14450
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14451
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14452
        end
14453
        join
14454
 
14455
        if ( ok )
14456
            test_ok ;
14457
 
14458 26 mihad
        @(posedge pci_clock) ;
14459
        @(posedge pci_clock) ;
14460
        @(posedge wb_clock) ;
14461
        @(posedge wb_clock) ;
14462
 
14463 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14464
 
14465
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14466
        addr_offset = 12'h004 ;
14467
        config_read(addr_offset, 4'hF, read_data) ;
14468
        ok = 1 ;
14469
        if ( read_data[27] !== 1 )
14470
        begin
14471
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14472
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14473
            ok = 0 ;
14474
        end
14475
        if ( read_data[28] !== 0 )
14476
        begin
14477
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14478
            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") ;
14479
            ok = 0 ;
14480
        end
14481
        if ( read_data[29] !== 0 )
14482
        begin
14483
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14484
            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") ;
14485
            ok = 0 ;
14486
        end
14487
 
14488
        // clear statuses
14489
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14490
        if ( !ok )
14491
        begin
14492
            test_fail("write to PCI Device Status register failed") ;
14493
            $display("Couldn't write PCI Device Status register") ;
14494
            disable main ;
14495
        end
14496
 
14497
        if ( ok )
14498
            test_ok ;
14499
 
14500
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14501
 
14502
        ok = 1 ;
14503
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14504
 
14505
        config_read(addr_offset, 4'hF, read_data) ;
14506
        if (read_data[8] !== 0)
14507
        begin
14508
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14509
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14510
            ok = 0 ;
14511
        end
14512
        else
14513
            test_ok ;
14514
 
14515
        if ( ok !== 1 )
14516
        begin
14517
            config_write(addr_offset, read_data, 4'hF, ok) ;
14518
            if ( !ok )
14519
            begin
14520
                test_fail("PCI Error Control and Status register could not be written") ;
14521
                disable main ;
14522
            end
14523
        end
14524
 
14525
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14526
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14527
        fork
14528
        begin
14529
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14530
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14531
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14532
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14533
 
14534
            do_pause( 1 ) ;
14535
        end
14536
        begin
14537
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14538
 
14539
            if ( ok !== 1 )
14540
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14541
 
14542
            do_pause(3) ;
14543
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14544
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14545
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14546
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14547
            do_pause(1) ;
14548
 
14549
            while ( FRAME === 0 )
14550
                @(posedge pci_clock) ;
14551
 
14552
            while ( IRDY === 0 )
14553
                @(posedge pci_clock) ;
14554
 
14555 35 mihad
            #1 ;
14556
            if ( !error_monitor_done )
14557
                disable monitor_error_event9 ;
14558 15 mihad
        end
14559
        begin:monitor_error_event9
14560 35 mihad
            error_monitor_done = 0 ;
14561 15 mihad
            @(error_event_int) ;
14562
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14563
            ok = 0 ;
14564 35 mihad
            error_monitor_done = 1 ;
14565 15 mihad
        end
14566
        begin
14567
            wb_transaction_stop( 3 ) ;
14568
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14569
        end
14570
        join
14571
 
14572
        if ( ok )
14573
            test_ok ;
14574
 
14575
        // now check all other statuses too
14576
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14577
        ok = 1 ;
14578
 
14579
        addr_offset = 12'h004 ;
14580
        config_read(addr_offset, 4'hF, read_data) ;
14581
        if (read_data[31] !== 0)
14582
        begin
14583
            $display("Detected Parity Error bit set for no reason") ;
14584
            test_fail("Detected Parity Error bit was set for no reason") ;
14585
            ok = 0 ;
14586
        end
14587
 
14588
        if (read_data[30] !== 0)
14589
        begin
14590
            $display("Signaled System Error bit set for no reason") ;
14591
            test_fail("Signaled System Error bit was set for no reason") ;
14592
            ok = 0 ;
14593
        end
14594
 
14595
        if (read_data[29] !== 0)
14596
        begin
14597
            $display("Received Master Abort bit set for no reason") ;
14598
            test_fail("Received Master Abort bit was set for no reason") ;
14599
            ok = 0 ;
14600
        end
14601
 
14602
        if (read_data[28] !== 0)
14603
        begin
14604
            $display("Received Target Abort bit set for no reason");
14605
            test_fail("Received Target Abort bit was set for no reason") ;
14606
            ok = 0 ;
14607
        end
14608
 
14609
        if (read_data[27] !== 0)
14610
        begin
14611
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14612
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14613
            ok = 0 ;
14614
        end
14615
 
14616
        if (read_data[24] !== 0)
14617
        begin
14618
            $display("Master Data Parity Error bit set for no reason") ;
14619
            test_fail("Master Data Parity Error bit was set for no reason") ;
14620
            ok = 0 ;
14621
        end
14622
 
14623
        if ( ok )
14624
            test_ok ;
14625
 
14626
        test_name = "DISABLE IMAGE" ;
14627 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14628 15 mihad
        if ( ok !== 1 )
14629
        begin
14630
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14631
            test_fail("PCI Address Mask register could not be written") ;
14632
            disable main;
14633
        end
14634
    end
14635
 
14636
    if ( target_io_image !== -1 )
14637
    begin
14638
        do_io_aborts = 1 ;
14639
 
14640
        if (target_io_image === 1)
14641
        begin
14642
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14643
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14644
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14645
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14646
        end
14647
        else if (target_io_image === 2)
14648
        begin
14649
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14650
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14651
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14652
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14653
        end
14654
        else if (target_io_image === 3)
14655
        begin
14656
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14657
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14658
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14659
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14660
        end
14661
        else if (target_io_image === 4)
14662
        begin
14663
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14664
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14665
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14666
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14667
        end
14668
        else if (target_io_image === 5)
14669
        begin
14670
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14671
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14672
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14673
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14674
        end
14675
    end
14676
    else
14677
        do_io_aborts = 0 ;
14678
 
14679
    if ( do_io_aborts )
14680
    begin
14681
 
14682
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14683
 
14684
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14685
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14686
        if ( ok !== 1 )
14687
        begin
14688
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14689
            test_fail("PCI Error Control and Status register could not be written") ;
14690
            disable main;
14691
        end
14692
 
14693
        // enable INTERRUPT reporting
14694
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14695
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14696
        if ( ok !== 1 )
14697
        begin
14698
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14699
            test_fail("Interrupt Control register could not be written") ;
14700
            disable main;
14701
        end
14702
 
14703
        addr_offset = 12'h010 + (4*target_io_image) ;
14704
 
14705
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14706
        if ( ok !== 1 )
14707
        begin
14708
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14709
            test_fail("PCI Base Address register could not be written") ;
14710
            disable main;
14711
        end
14712
 
14713
        // disable address translation and enable prefetch so read bursts can be performed
14714
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14715
        if ( ok !== 1 )
14716
        begin
14717
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14718
            test_fail("PCI Image Control register could not be written") ;
14719
            disable main;
14720
        end
14721
 
14722
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14723
        if ( ok !== 1 )
14724
        begin
14725
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14726
            test_fail("PCI Address Mask register could not be written") ;
14727
            disable main;
14728
        end
14729
 
14730
        addr_offset = 12'h00C ;
14731
 
14732
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14733
        if ( ok !== 1 )
14734
        begin
14735
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14736
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14737
            disable main;
14738
        end
14739
 
14740
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14741
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14742
 
14743
        // do a single read error terminated on WB bus
14744
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14745
 
14746
        fork
14747
        begin
14748
            PCIU_IO_READ
14749
             (
14750
                `Test_Master_1,
14751
                Target_Base_Addr_R[target_io_image],
14752
                32'hAAAA_5555,
14753
                4'h0,
14754
                1,
14755
                `Test_Target_Retry_On
14756
             );
14757
 
14758
            do_pause( 1 ) ;
14759
        end
14760
        begin
14761
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14762
 
14763
            if ( ok !== 1 )
14764
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14765
 
14766
            do_pause(3) ;
14767
 
14768
            PCIU_IO_READ
14769
             (
14770
                `Test_Master_1,
14771
                Target_Base_Addr_R[target_io_image],
14772
                32'hAAAA_5555,
14773
                4'h0,
14774
                1,
14775
                `Test_Target_Abort_On
14776
             );
14777
 
14778
            do_pause( 1 ) ;
14779
 
14780
            while ( FRAME === 0 )
14781
                @(posedge pci_clock) ;
14782
 
14783
            while ( IRDY === 0 )
14784
                @(posedge pci_clock) ;
14785
 
14786 35 mihad
            #1 ;
14787
            if ( !error_monitor_done )
14788
                disable monitor_error_event10 ;
14789 15 mihad
        end
14790
        begin:monitor_error_event10
14791 35 mihad
            error_monitor_done = 0 ;
14792 15 mihad
            @(error_event_int) ;
14793
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14794
            ok = 0 ;
14795 35 mihad
            error_monitor_done = 1 ;
14796 15 mihad
        end
14797
        join
14798
 
14799
        if ( ok )
14800
            test_ok ;
14801
 
14802 26 mihad
        @(posedge pci_clock) ;
14803
        @(posedge pci_clock) ;
14804
        @(posedge wb_clock) ;
14805
        @(posedge wb_clock) ;
14806
 
14807 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14808
        addr_offset = 12'h004 ;
14809
        config_read(addr_offset, 4'hF, read_data) ;
14810
        ok = 1 ;
14811
        if ( read_data[27] !== 1 )
14812
        begin
14813
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14814
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14815
            ok = 0 ;
14816
        end
14817
        if ( read_data[28] !== 0 )
14818
        begin
14819
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14820
            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") ;
14821
            ok = 0 ;
14822
        end
14823
        if ( read_data[29] !== 0 )
14824
        begin
14825
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14826
            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") ;
14827
            ok = 0 ;
14828
        end
14829
 
14830
        // clear statuses
14831
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14832
        if ( !ok )
14833
        begin
14834
            test_fail("write to PCI Device Status register failed") ;
14835
            $display("Couldn't write PCI Device Status register") ;
14836
            disable main ;
14837
        end
14838
 
14839
        if ( ok )
14840
            test_ok ;
14841
 
14842
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14843
 
14844
        ok = 1 ;
14845
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14846
 
14847
        config_read(addr_offset, 4'hF, read_data) ;
14848
        if (read_data[8] !== 0)
14849
        begin
14850
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14851
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14852
            ok = 0 ;
14853
        end
14854
        else
14855
            test_ok ;
14856
 
14857
        if ( ok !== 1 )
14858
        begin
14859
            config_write(addr_offset, read_data, 4'hF, ok) ;
14860
            if ( !ok )
14861
            begin
14862
                test_fail("PCI Error Control and Status register could not be written") ;
14863
                disable main ;
14864
            end
14865
        end
14866
 
14867
        test_name = "DISABLE IMAGE" ;
14868 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14869 15 mihad
        if ( ok !== 1 )
14870
        begin
14871
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14872
            test_fail("PCI Address Mask register could not be written") ;
14873
            disable main;
14874
        end
14875
 
14876
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14877
 
14878
    end
14879
end // main
14880
endtask // test_wb_error_rd
14881
 
14882
task test_target_abort ;
14883
    input [2:0]  image_num ;
14884
    reg   [11:0] pci_ctrl_offset ;
14885
    reg   [11:0] ctrl_offset ;
14886
    reg   [11:0] ba_offset ;
14887
    reg   [11:0] am_offset ;
14888
    reg   [11:0] ta_offset ;
14889
    reg   [31:0] pci_address ;
14890
    reg   [3:0]  byte_enables ;
14891
    reg          ok ;
14892 35 mihad
    reg          error_monitor_done ;
14893 15 mihad
begin:main
14894
    pci_ctrl_offset = 12'h4 ;
14895
    if (image_num === 0)
14896
    begin
14897
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14898
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14899
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14900
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14901
    end
14902
    else if (image_num === 1)
14903
    begin
14904
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14905
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14906
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14907
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14908
    end
14909
    else if (image_num === 2)
14910
    begin
14911
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14912
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14913
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14914
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14915
    end
14916
    else if (image_num === 3)
14917
    begin
14918
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14919
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14920
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14921
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14922
    end
14923
    else if (image_num === 4)
14924
    begin
14925
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14926
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14927
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14928
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14929
    end
14930
    else if (image_num === 5)
14931
    begin
14932
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14933
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14934
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14935
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14936
    end
14937
 
14938
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14939
 
14940
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14941
    if ( ok !== 1 )
14942
    begin
14943
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14944
        test_fail("PCI Base Address register could not be written") ;
14945
        disable main ;
14946
    end
14947
 
14948
    // Set Address Mask of IMAGE
14949
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14950
    if ( ok !== 1 )
14951
    begin
14952
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14953
        test_fail("PCI Address Mask register could not be written") ;
14954
        disable main ;
14955
    end
14956
 
14957
    // Set Translation Address of IMAGE
14958
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14959
    if ( ok !== 1 )
14960
    begin
14961
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14962
        test_fail("PCI Translation Address Register could not be written") ;
14963
        disable main ;
14964
    end
14965
 
14966
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14967
    if ( ok !== 1 )
14968
    begin
14969
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14970
        test_fail("PCI Image Control register could not be written") ;
14971
        disable main ;
14972
    end
14973
 
14974
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14975
 
14976
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14977
 
14978
    pci_address  = Target_Base_Addr_R[image_num] ;
14979
    byte_enables = 4'b0001 ;
14980
 
14981
    fork
14982
    begin
14983
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14984
        do_pause ( 1 ) ;
14985
    end
14986
    begin:monitor_error_event1
14987 35 mihad
        error_monitor_done = 0 ;
14988 15 mihad
        @(error_event_int) ;
14989
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14990
        ok = 0 ;
14991 35 mihad
        error_monitor_done = 1 ;
14992 15 mihad
    end
14993
    begin
14994
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14995
        @(posedge pci_clock) ;
14996 35 mihad
        #1 ;
14997
        if ( !error_monitor_done )
14998
            disable monitor_error_event1 ;
14999 15 mihad
    end
15000
    join
15001
 
15002
    if ( ok )
15003
        test_ok ;
15004
 
15005
    ok = 1 ;
15006
 
15007
    fork
15008
    begin
15009
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15010
        do_pause ( 1 ) ;
15011
    end
15012
    begin:monitor_error_event2
15013 35 mihad
        error_monitor_done = 0 ;
15014 15 mihad
        @(error_event_int) ;
15015
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15016
        ok = 0 ;
15017 35 mihad
        error_monitor_done = 1 ;
15018 15 mihad
    end
15019
    begin
15020
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15021
        @(posedge pci_clock) ;
15022 35 mihad
        #1 ;
15023
        if ( !error_monitor_done )
15024
            disable monitor_error_event2 ;
15025 15 mihad
    end
15026
    join
15027
 
15028
    if ( ok )
15029
        test_ok ;
15030
 
15031
    ok = 1 ;
15032
 
15033
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
15034
    byte_enables = 4'b0011 ;
15035
 
15036
    fork
15037
    begin
15038
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15039
        do_pause ( 1 ) ;
15040
    end
15041
    begin:monitor_error_event3
15042 35 mihad
        error_monitor_done = 0 ;
15043 15 mihad
        @(error_event_int) ;
15044
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15045
        ok = 0 ;
15046 35 mihad
        error_monitor_done = 1 ;
15047 15 mihad
    end
15048
    begin
15049
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15050
        @(posedge pci_clock) ;
15051 35 mihad
        if ( !error_monitor_done )
15052
            disable monitor_error_event3 ;
15053 15 mihad
    end
15054
    join
15055
 
15056
    if ( ok )
15057
        test_ok ;
15058
 
15059
    ok = 1 ;
15060
 
15061
    byte_enables = 4'b0000 ;
15062
 
15063
    fork
15064
    begin
15065
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15066
        do_pause ( 1 ) ;
15067
    end
15068
    begin:monitor_error_event4
15069 35 mihad
        error_monitor_done = 0 ;
15070 15 mihad
        @(error_event_int) ;
15071
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15072
        ok = 0 ;
15073 35 mihad
        error_monitor_done = 1 ;
15074 15 mihad
    end
15075
    begin
15076
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15077
        @(posedge pci_clock) ;
15078 35 mihad
        #1 ;
15079
        if ( !error_monitor_done )
15080
            disable monitor_error_event4 ;
15081 15 mihad
    end
15082
    join
15083
 
15084
    if ( ok )
15085
        test_ok ;
15086
 
15087
    ok = 1 ;
15088
 
15089
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
15090
    byte_enables = 4'b0111 ;
15091
 
15092
    fork
15093
    begin
15094
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15095
        do_pause ( 1 ) ;
15096
    end
15097
    begin:monitor_error_event5
15098 35 mihad
        error_monitor_done = 0 ;
15099 15 mihad
        @(error_event_int) ;
15100
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15101
        ok = 0 ;
15102 35 mihad
        error_monitor_done = 1 ;
15103 15 mihad
    end
15104
    begin
15105
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15106
        @(posedge pci_clock) ;
15107 35 mihad
        #1 ;
15108
        if ( !error_monitor_done )
15109
            disable monitor_error_event5 ;
15110 15 mihad
    end
15111
    join
15112
 
15113
    if ( ok )
15114
        test_ok ;
15115
 
15116
    ok = 1 ;
15117
 
15118
    byte_enables = 4'b0010 ;
15119
 
15120
    fork
15121
    begin
15122
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15123
        do_pause ( 1 ) ;
15124
    end
15125
    begin:monitor_error_event6
15126 35 mihad
        error_monitor_done = 0 ;
15127 15 mihad
        @(error_event_int) ;
15128
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15129
        ok = 0 ;
15130 35 mihad
        error_monitor_done = 1 ;
15131 15 mihad
    end
15132
    begin
15133
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15134
        @(posedge pci_clock) ;
15135 35 mihad
        #1 ;
15136
        if ( !error_monitor_done )
15137
            disable monitor_error_event6 ;
15138 15 mihad
    end
15139
    join
15140
 
15141
    if ( ok )
15142
        test_ok ;
15143
 
15144
    ok = 1 ;
15145
    byte_enables = 4'b0001 ;
15146
 
15147
    fork
15148
    begin
15149
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15150
        do_pause ( 1 ) ;
15151
    end
15152
    begin:monitor_error_event7
15153 35 mihad
        error_monitor_done = 0 ;
15154 15 mihad
        @(error_event_int) ;
15155
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15156
        ok = 0 ;
15157 35 mihad
        error_monitor_done = 1 ;
15158 15 mihad
    end
15159
    begin
15160
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15161
        @(posedge pci_clock) ;
15162 35 mihad
        #1 ;
15163
        if ( !error_monitor_done )
15164
            disable monitor_error_event7 ;
15165 15 mihad
    end
15166
    join
15167
 
15168
    if ( ok )
15169
        test_ok ;
15170
 
15171
    ok = 1 ;
15172
    byte_enables = 4'b0000 ;
15173
 
15174
    fork
15175
    begin
15176
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15177
        do_pause ( 1 ) ;
15178
    end
15179
    begin:monitor_error_event8
15180 35 mihad
        error_monitor_done = 0 ;
15181 15 mihad
        @(error_event_int) ;
15182
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15183
        ok = 0 ;
15184 35 mihad
        error_monitor_done = 1 ;
15185 15 mihad
    end
15186
    begin
15187
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15188
        @(posedge pci_clock) ;
15189 35 mihad
        #1 ;
15190
        if ( !error_monitor_done )
15191
            disable monitor_error_event8 ;
15192 15 mihad
    end
15193
    join
15194
 
15195
    if ( ok )
15196
        test_ok ;
15197
 
15198
    ok = 1 ;
15199
 
15200
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15201
    byte_enables = 4'b0110 ;
15202
 
15203
    fork
15204
    begin
15205
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15206
        do_pause ( 1 ) ;
15207
    end
15208
    begin:monitor_error_event9
15209 35 mihad
        error_monitor_done = 0 ;
15210 15 mihad
        @(error_event_int) ;
15211
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15212
        ok = 0 ;
15213 35 mihad
        error_monitor_done = 1 ;
15214 15 mihad
    end
15215
    begin
15216
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15217
        @(posedge pci_clock) ;
15218 35 mihad
        #1 ;
15219
        if ( !error_monitor_done )
15220
            disable monitor_error_event9 ;
15221 15 mihad
    end
15222
    join
15223
 
15224
    if ( ok )
15225
        test_ok ;
15226
 
15227
    ok = 1 ;
15228
    fork
15229
    begin
15230
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15231
        do_pause ( 1 ) ;
15232
    end
15233
    begin:monitor_error_event10
15234 35 mihad
        error_monitor_done = 0 ;
15235 15 mihad
        @(error_event_int) ;
15236
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15237
        ok = 0 ;
15238 35 mihad
        error_monitor_done = 1 ;
15239 15 mihad
    end
15240
    begin
15241
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15242
        @(posedge pci_clock) ;
15243 35 mihad
 
15244
        #1 ;
15245
        if ( !error_monitor_done )
15246
            disable monitor_error_event10 ;
15247 15 mihad
    end
15248
    join
15249
 
15250
    if ( ok )
15251
        test_ok ;
15252
 
15253
    ok = 1 ;
15254
 
15255
    byte_enables = 4'b0001 ;
15256
 
15257
    fork
15258
    begin
15259
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15260
        do_pause ( 1 ) ;
15261
    end
15262
    begin:monitor_error_event11
15263 35 mihad
        error_monitor_done = 0 ;
15264 15 mihad
        @(error_event_int) ;
15265
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15266
        ok = 0 ;
15267 35 mihad
        error_monitor_done = 1 ;
15268 15 mihad
    end
15269
    begin
15270
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15271
        @(posedge pci_clock) ;
15272 35 mihad
        #1 ;
15273
        if ( !error_monitor_done )
15274
            disable monitor_error_event11 ;
15275 15 mihad
    end
15276
    join
15277
 
15278
    if ( ok )
15279
        test_ok ;
15280
 
15281
    ok = 1 ;
15282
 
15283
    byte_enables = 4'b0101 ;
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_event12
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
        #1 ;
15301
        if ( !error_monitor_done )
15302
            disable monitor_error_event12 ;
15303 15 mihad
    end
15304
    join
15305
 
15306
    if ( ok )
15307
        test_ok ;
15308
 
15309
    ok = 1 ;
15310
 
15311
    byte_enables = 4'b0011 ;
15312
 
15313
    fork
15314
    begin
15315
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15316
        do_pause ( 1 ) ;
15317
    end
15318
    begin:monitor_error_event13
15319 35 mihad
        error_monitor_done = 0 ;
15320 15 mihad
        @(error_event_int) ;
15321
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15322
        ok = 0 ;
15323 35 mihad
        error_monitor_done = 1 ;
15324 15 mihad
    end
15325
    begin
15326
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15327
        @(posedge pci_clock) ;
15328 35 mihad
        #1 ;
15329
        if ( !error_monitor_done )
15330
            disable monitor_error_event13 ;
15331 15 mihad
    end
15332
    join
15333
 
15334
    if ( ok )
15335
        test_ok ;
15336
 
15337
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15338
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15339
    ok = 1 ;
15340
    if ( pci_address[27] !== 1 )
15341
    begin
15342
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15343
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15344
        ok = 0 ;
15345
    end
15346
    if ( pci_address[28] !== 0 )
15347
    begin
15348
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15349
        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") ;
15350
        ok = 0 ;
15351
    end
15352
    if ( pci_address[29] !== 0 )
15353
    begin
15354
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15355
        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") ;
15356
        ok = 0 ;
15357
    end
15358
 
15359
    // clear statuses
15360
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15361
    if ( !ok )
15362
    begin
15363
        test_fail("write to PCI Device Status register failed") ;
15364
        $display("Couldn't write PCI Device Status register") ;
15365
        disable main ;
15366
    end
15367
 
15368
    if ( ok )
15369
        test_ok ;
15370
 
15371
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15372
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15373
    if ( pci_address[8] !== 0 )
15374
    begin
15375
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15376
    end
15377
    else
15378
        test_ok ;
15379
 
15380
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15381
 
15382
    test_name = "DISABLE IMAGE" ;
15383
 
15384 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15385 15 mihad
    if ( ok !== 1 )
15386
    begin
15387
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15388
        test_fail("PCI Address Mask register could not be written") ;
15389
        disable main ;
15390
    end
15391
end
15392
endtask // test_target_abort
15393
 
15394
task test_target_io_wr_rd ;
15395
    input [2:0]  image_num ;
15396
    input        translate_address ;
15397
    input [11:0] img_ctrl_offset ;
15398
    reg   [31:0] expect_address ;
15399
    reg   [31:0] pci_address ;
15400
    reg          translation ;
15401
    reg   [31:0] read_data ;
15402
    reg   [3:0]  byte_enables ;
15403
    reg          ok ;
15404
    reg          pci_ok ;
15405
    reg          wb_ok ;
15406
    integer      i ;
15407 35 mihad
    reg          error_monitor_done ;
15408 15 mihad
begin:main
15409
    `ifdef ADDR_TRAN_IMPL
15410
        translation = translate_address ;
15411
    `else
15412
        translation = 0 ;
15413
    `endif
15414
 
15415
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15416
 
15417
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15418
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15419
    if ( translation )
15420
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15421
    else
15422
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15423
 
15424
    if ( !ok )
15425
    begin
15426
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15427
        test_fail("PCI Image Control register could not be written") ;
15428
    end
15429
 
15430
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15431
    pci_address  = Target_Base_Addr_R[image_num] ;
15432
    byte_enables = 4'b0000 ;
15433
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15434
 
15435
    fork
15436
    begin
15437
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15438
        do_pause ( 1 ) ;
15439
    end
15440
    begin
15441
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15442
        if ( wb_ok !== 1 )
15443
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15444
 
15445 35 mihad
        #1 ;
15446
        if ( !error_monitor_done )
15447
            disable monitor_pci_error_1 ;
15448 15 mihad
    end
15449
    begin:monitor_pci_error_1
15450 35 mihad
        error_monitor_done = 0 ;
15451 15 mihad
        pci_ok = 1 ;
15452
        @(error_event_int) ;
15453
        pci_ok = 0 ;
15454
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15455 35 mihad
        error_monitor_done = 1 ;
15456 15 mihad
    end
15457
    join
15458
 
15459
    byte_enables = 4'b1111 ;
15460
    for ( i = 0 ; i < 4 ; i = i + 1 )
15461
    begin:loop_1
15462
        byte_enables[i] = 0 ;
15463
        if ( i > 0 )
15464
            byte_enables[i - 1] = 1 ;
15465
        fork
15466
        begin
15467
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15468
            do_pause ( 1 ) ;
15469
        end
15470
        begin
15471
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15472
            if ( wb_ok !== 1 )
15473
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15474
 
15475 35 mihad
            #1 ;
15476
            if ( !error_monitor_done )
15477
                disable monitor_pci_error_2 ;
15478 15 mihad
        end
15479
        begin:monitor_pci_error_2
15480 35 mihad
            error_monitor_done = 0 ;
15481 15 mihad
            pci_ok = 1 ;
15482
            @(error_event_int) ;
15483
            pci_ok = 0 ;
15484
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15485 35 mihad
            error_monitor_done = 1 ;
15486 15 mihad
        end
15487
        join
15488
 
15489
        if ( !pci_ok || !wb_ok )
15490
            disable loop_1 ;
15491
 
15492
        pci_address = pci_address + 1 ;
15493
        expect_address = expect_address + 1 ;
15494
    end
15495
 
15496
    if ( pci_ok && wb_ok )
15497
        test_ok ;
15498
 
15499
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15500
    pci_address  = Target_Base_Addr_R[image_num] ;
15501
    byte_enables = 4'b1100 ;
15502
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15503
 
15504
    master1_check_received_data = 1 ;
15505
    fork
15506
    begin
15507
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15508
        do_pause( 1 ) ;
15509
    end
15510
    begin
15511
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15512
        if ( wb_ok !== 1 )
15513
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15514
 
15515
        do_pause ( 2 ) ;
15516
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15517
        do_pause ( 16 ) ;
15518
 
15519 35 mihad
        #1 ;
15520
        if ( !error_monitor_done )
15521
            disable monitor_pci_error_3 ;
15522 15 mihad
    end
15523
    begin:monitor_pci_error_3
15524 35 mihad
        error_monitor_done = 0 ;
15525 15 mihad
        pci_ok = 1 ;
15526
        @(error_event_int) ;
15527
        pci_ok = 0 ;
15528
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15529 35 mihad
        error_monitor_done = 1 ;
15530 15 mihad
    end
15531
    join
15532
 
15533
    if ( !pci_ok || !wb_ok )
15534
    begin
15535
        disable main ;
15536
    end
15537
 
15538
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15539
    byte_enables = 4'b0011 ;
15540
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15541
 
15542
    master1_check_received_data = 1 ;
15543
    fork
15544
    begin
15545
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15546
        do_pause( 1 ) ;
15547
    end
15548
    begin
15549
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15550
        if ( wb_ok !== 1 )
15551
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15552
 
15553
        do_pause ( 2 ) ;
15554
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15555
        do_pause ( 16 ) ;
15556
 
15557 35 mihad
        #1 ;
15558
        if ( !error_monitor_done )
15559
            disable monitor_pci_error_4 ;
15560 15 mihad
    end
15561
    begin:monitor_pci_error_4
15562 35 mihad
        error_monitor_done = 0 ;
15563 15 mihad
        pci_ok = 1 ;
15564
        @(error_event_int) ;
15565
        pci_ok = 0 ;
15566
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15567 35 mihad
        error_monitor_done = 1 ;
15568 15 mihad
    end
15569
    join
15570
 
15571
    if ( !pci_ok || !wb_ok )
15572
    begin
15573
        disable main ;
15574
    end
15575
 
15576
    pci_address  = Target_Base_Addr_R[image_num] ;
15577
    byte_enables = 4'b0000 ;
15578
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15579
 
15580
    master1_check_received_data = 1 ;
15581
    fork
15582
    begin
15583
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15584
        do_pause( 1 ) ;
15585
    end
15586
    begin
15587
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15588
        if ( wb_ok !== 1 )
15589
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15590
 
15591
        do_pause ( 2 ) ;
15592
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15593
        do_pause ( 16 ) ;
15594
 
15595 35 mihad
        #1 ;
15596
        if ( !error_monitor_done )
15597
            disable monitor_pci_error_5 ;
15598 15 mihad
    end
15599
    begin:monitor_pci_error_5
15600 35 mihad
        error_monitor_done = 0 ;
15601 15 mihad
        pci_ok = 1 ;
15602
        @(error_event_int) ;
15603
        pci_ok = 0 ;
15604
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15605 35 mihad
        error_monitor_done = 1 ;
15606 15 mihad
    end
15607
    join
15608
 
15609
    if ( pci_ok && wb_ok )
15610
        test_ok ;
15611
end
15612
endtask // test_target_io_wr_rd
15613
 
15614
task test_target_io_err_wr ;
15615
    input [2:0]  image_num ;
15616
    input        translate_address ;
15617
    input [11:0] img_ctrl_offset ;
15618
    input        enable_error_report ;
15619
    input        enable_error_interrupt ;
15620
 
15621
    reg   [31:0] expect_address ;
15622
    reg   [31:0] pci_address ;
15623
    reg          translation ;
15624
    reg   [31:0] read_data ;
15625
    reg   [3:0]  byte_enables ;
15626
    reg          ok ;
15627
    reg          pci_ok ;
15628
    reg          wb_ok ;
15629
    integer      i ;
15630
    reg   [11:0] offset ;
15631 35 mihad
    reg          error_monitor_done ;
15632 15 mihad
begin:main
15633
    `ifdef ADDR_TRAN_IMPL
15634
        translation = translate_address ;
15635
    `else
15636
        translation = 0 ;
15637
    `endif
15638
 
15639
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15640
 
15641
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15642
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15643
    if ( translation )
15644
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15645
    else
15646
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15647
 
15648
    if ( !ok )
15649
    begin
15650
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15651
        test_fail("PCI Image Control register could not be written") ;
15652
    end
15653
 
15654
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15655
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15656
    if ( enable_error_report )
15657
    begin
15658
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15659
        if ( !ok )
15660
        begin
15661
            test_fail("PCI Error Control and Status register could not be written") ;
15662
            disable main ;
15663
        end
15664
    end
15665
    else
15666
    begin
15667
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15668
        if ( !ok )
15669
        begin
15670
            test_fail("PCI Error Control and Status register could not be written") ;
15671
            disable main ;
15672
        end
15673
    end
15674
 
15675
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15676
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15677
    if ( enable_error_interrupt )
15678
    begin
15679
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15680
        if ( !ok )
15681
        begin
15682
            test_fail("Interrupt Control register could not be written") ;
15683
            disable main ;
15684
        end
15685
    end
15686
    else
15687
    begin
15688
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15689
        if ( !ok )
15690
        begin
15691
            test_fail("Interrupt Control register could not be written") ;
15692
            disable main ;
15693
        end
15694
    end
15695
 
15696
    pci_address  = Target_Base_Addr_R[image_num] ;
15697
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15698
 
15699
    byte_enables = 4'b1111 ;
15700
 
15701
    for ( i = 0 ; i < 4 ; i = i + 1 )
15702
    begin:loop_1
15703
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15704
        byte_enables[i] = 0 ;
15705
        if ( i > 0 )
15706
            byte_enables[i - 1] = 1 ;
15707
 
15708
        fork
15709
        begin
15710
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15711
            do_pause ( 1 ) ;
15712
        end
15713
        begin
15714
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15715
            if ( wb_ok !== 1 )
15716
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15717
 
15718 35 mihad
            #1 ;
15719
            if ( !error_monitor_done )
15720
                disable monitor_pci_error_2 ;
15721 15 mihad
        end
15722
        begin:monitor_pci_error_2
15723 35 mihad
            error_monitor_done = 0 ;
15724 15 mihad
            pci_ok = 1 ;
15725
            @(error_event_int) ;
15726
            pci_ok = 0 ;
15727
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15728 35 mihad
            error_monitor_done = 1 ;
15729 15 mihad
        end
15730
        join
15731
 
15732
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15733
        `ifdef HOST
15734
 
15735
            repeat ( 4 )
15736
                @( posedge wb_clock ) ;
15737
 
15738
            if ( enable_error_interrupt && enable_error_report )
15739
            begin
15740
                if ( INT_O !== 1 )
15741
                begin
15742
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15743
                end
15744
            end
15745
            else
15746
            begin
15747
                if ( INT_O !== 0 )
15748
                begin
15749
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15750
                end
15751
            end
15752
        `else
15753
            repeat ( 4 )
15754
                @( posedge pci_clock ) ;
15755
 
15756
            if ( enable_error_interrupt && enable_error_report )
15757
            begin
15758
                if ( INTA !== 0 )
15759
                begin
15760
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15761
                end
15762
            end
15763
            else
15764
            begin
15765
                if ( INTA !== 1 )
15766
                begin
15767
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15768
                end
15769
            end
15770
        `endif
15771
 
15772
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15773
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15774
        config_read( offset, 4'hF, read_data ) ;
15775
        ok = 1 ;
15776
        if ( enable_error_report )
15777
        begin
15778
            if ( read_data[8] !== 1 )
15779
            begin
15780
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15781
                ok = 0 ;
15782
            end
15783
 
15784
            if ( read_data[9] !== 0 )
15785
            begin
15786
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15787
                ok = 0 ;
15788
            end
15789
 
15790
            if ( read_data[31:28] !== byte_enables )
15791
            begin
15792
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15793
                ok = 0 ;
15794
            end
15795
 
15796
            if ( read_data[27:24] !== `BC_IO_WRITE )
15797
            begin
15798
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15799
                ok = 0 ;
15800
            end
15801
 
15802
            if ( ok )
15803
                test_ok ;
15804
 
15805
            test_name = "CLEAR ERROR STATUS" ;
15806
            config_write( offset, read_data, 4'hF, ok ) ;
15807
            if ( !ok )
15808
                test_fail("PCI Error Control and Status register could not be written") ;
15809
 
15810
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15811
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15812
            config_read ( offset, 4'hf, read_data ) ;
15813
 
15814
            if ( read_data !== expect_address )
15815
            begin
15816
                test_fail("value in Erroneous Address register was incorrect") ;
15817
                ok = 0 ;
15818
            end
15819
 
15820
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15821
            config_read ( offset, 4'hf, read_data ) ;
15822
 
15823
            if ( read_data !== 32'hAAAA_AAAA )
15824
            begin
15825
                test_fail("value in Erroneous Data register was incorrect") ;
15826
                ok = 0 ;
15827
            end
15828
 
15829
            if ( ok )
15830
                test_ok ;
15831
 
15832
        end
15833
        else
15834
        begin
15835
            if ( read_data[8] !== 0 )
15836
            begin
15837
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15838
                ok = 0 ;
15839
            end
15840
            else
15841
                test_ok ;
15842
        end
15843
 
15844
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15845
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15846
        ok = 1 ;
15847
 
15848
        config_read ( offset, 4'hF, read_data ) ;
15849
        if ( enable_error_report && enable_error_interrupt )
15850
        begin
15851
            if ( read_data[2] !== 1 )
15852
            begin
15853
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15854
                ok = 0 ;
15855
            end
15856
 
15857
            test_name = "CLEARING INTERRUPT STATUS" ;
15858
            config_write( offset, read_data, 4'hF, ok ) ;
15859
            if ( !ok )
15860
                test_fail("Interrupt Status register could not be written") ;
15861
        end
15862
        else
15863
        begin
15864
            if ( read_data[2] !== 0 )
15865
            begin
15866
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15867
                ok = 0 ;
15868
            end
15869
        end
15870
 
15871
        if ( ok )
15872
            test_ok ;
15873
 
15874
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15875
        `ifdef HOST
15876
 
15877
            repeat ( 4 )
15878
                @( posedge wb_clock ) ;
15879
 
15880
            if ( INT_O !== 0 )
15881
            begin
15882
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15883
            end
15884
            else
15885
                test_ok ;
15886
 
15887
        `else
15888
            repeat ( 4 )
15889
                @( posedge pci_clock ) ;
15890
 
15891
            if ( INTA !== 1 )
15892
            begin
15893
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15894
            end
15895
            else
15896
                test_ok ;
15897
 
15898
        `endif
15899
 
15900
        pci_address = pci_address + 1 ;
15901
        expect_address = expect_address + 1 ;
15902
    end
15903
 
15904
end
15905
endtask // test_target_io_err_wr
15906
 
15907
task test_pci_image ;
15908
    input [2:0]  image_num ;
15909
    reg   [11:0] pci_ctrl_offset ;
15910
    reg   [11:0] ctrl_offset ;
15911
    reg   [11:0] ba_offset ;
15912
    reg   [11:0] am_offset ;
15913
    reg   [11:0] ta_offset ;
15914
    reg   [7:0]  cache_lsize ;
15915
    reg          ok ;
15916
    reg          test_io ;
15917
    reg          test_mem ;
15918
begin
15919
    pci_ctrl_offset = 12'h4 ;
15920
    if (image_num === 0)
15921
    begin
15922
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15923
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15924
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15925
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15926
    end
15927
    else if (image_num === 1)
15928
    begin
15929
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15930
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15931
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15932
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15933
    end
15934
    else if (image_num === 2)
15935
    begin
15936
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15937
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15938
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15939
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15940
    end
15941
    else if (image_num === 3)
15942
    begin
15943
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15944
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15945
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15946
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15947
    end
15948
    else if (image_num === 4)
15949
    begin
15950
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15951
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15952
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15953
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15954
    end
15955
    else if (image_num === 5)
15956
    begin
15957
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15958
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15959
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15960
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15961
    end
15962
 
15963
    `ifdef HOST
15964
        test_io  = 1 ;
15965
        test_mem = 1 ;
15966
    `else
15967
        if (image_num == 1)
15968
            test_io = `PCI_BA1_MEM_IO ;
15969
        else if ( image_num == 2 )
15970
            test_io = `PCI_BA2_MEM_IO ;
15971
        else if ( image_num == 3 )
15972
            test_io = `PCI_BA3_MEM_IO ;
15973
        else if ( image_num == 4 )
15974
            test_io = `PCI_BA4_MEM_IO ;
15975
        else if ( image_num == 5 )
15976
            test_io = `PCI_BA5_MEM_IO ;
15977
 
15978
        test_mem = !test_io ;
15979
    `endif
15980
 
15981
    $display(" ");
15982
    $display("########################################################################") ;
15983
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15984
    test_name = "PCI IMAGE SETTINGS" ;
15985
 
15986
    // Set Base Address of IMAGE
15987
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15988
    if ( ok !== 1 )
15989
    begin
15990
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15991
        test_fail("PCI Base Address register could not be written") ;
15992
    end
15993
 
15994
    // Set Address Mask of IMAGE
15995
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15996
    if ( ok !== 1 )
15997
    begin
15998
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15999
        test_fail("PCI Address Mask register could not be written") ;
16000
    end
16001
 
16002
    // Set Translation Address of IMAGE
16003
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16004
    if ( ok !== 1 )
16005
    begin
16006
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16007
        test_fail("PCI Translation Address register could not be written") ;
16008
    end
16009
 
16010
// Following are defines for byte enable signals !
16011
//      Byte Masks
16012
//      `Test_Byte_0                            (4'b1110)
16013
//      `Test_Byte_1                            (4'b1101)
16014
//      `Test_Byte_2                            (4'b1011)
16015
//      `Test_Byte_3                            (4'b0111)
16016
//      `Test_Half_0                            (4'b1100)
16017
//      `Test_Half_1                            (4'b0011)
16018
//      `Test_All_Bytes                         (4'b0000)
16019
 
16020
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
16021
    // Set Cache Line Size
16022
    cache_lsize = 8'h4 ;
16023
 
16024
    $display(" ");
16025
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16026
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16027
    if ( ok !== 1 )
16028
    begin
16029
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16030
        test_fail("PCI Device Control and Status register could not be written") ;
16031
    end
16032
 
16033
    if (test_mem)
16034
    begin
16035
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
16036
        // Task test_normal_wr_rd has the following parameters:
16037
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16038
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16039
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16040
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
16041
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
16042
 
16043
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16044
        // Set Cache Line Size
16045
        cache_lsize = 8'h4 ;
16046
 
16047
        $display(" ");
16048
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16049
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16050
        if ( ok !== 1 )
16051
        begin
16052
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16053
            test_fail("Cache Line Size register could not be written" ) ;
16054
        end
16055
 
16056
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
16057
        // Task test_normal_wr_rd has the following parameters:
16058
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16059
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16060
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16061
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
16062
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
16063
 
16064
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16065
        // Set Cache Line Size
16066
        cache_lsize = 8'h8 ;
16067
 
16068
        $display(" ");
16069
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16070
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16071
        if ( ok !== 1 )
16072
        begin
16073
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16074
            test_fail("Cache Line Size register could not be written" ) ;
16075
        end
16076
 
16077
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
16078
        // Task test_normal_wr_rd has the following parameters:
16079
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16080
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16081
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16082
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
16083
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16084
 
16085
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16086
        // Set Cache Line Size
16087
        cache_lsize = 8'h4 ;
16088
 
16089
        $display(" ");
16090
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16091
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16092
        if ( ok !== 1 )
16093
        begin
16094
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16095
            test_fail("Cache Line Size register could not be written" ) ;
16096
        end
16097
 
16098
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
16099
        // Task test_normal_wr_rd has the following parameters:
16100
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16101
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16102
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16103
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
16104
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16105
 
16106
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16107
        $display(" ");
16108
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
16109
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16110
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16111
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
16112
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
16113
 
16114
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16115
        $display(" ");
16116
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
16117
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16118
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16119
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
16120
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
16121
 
16122
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16123
        $display(" ");
16124
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
16125
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16126
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16127
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
16128
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
16129
 
16130
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16131
        $display(" ");
16132
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
16133
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16134
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16135
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
16136
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
16137
    end
16138
 
16139
    if ( test_io )
16140
    begin
16141
        test_name = "PCI IMAGE SETTINGS" ;
16142
 
16143
        // Set Base Address of IMAGE
16144
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
16145
        if ( ok !== 1 )
16146
        begin
16147
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16148
            test_fail("PCI Base Address register could not be written") ;
16149
        end
16150
 
16151
        // Set Address Mask of IMAGE
16152
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16153
        if ( ok !== 1 )
16154
        begin
16155
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16156
            test_fail("PCI Address Mask register could not be written") ;
16157
        end
16158
 
16159
        // Set Translation Address of IMAGE
16160
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16161
        if ( ok !== 1 )
16162
        begin
16163
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16164
            test_fail("PCI Translation Address register could not be written") ;
16165
        end
16166
 
16167
        // Set Cache Line Size
16168
        cache_lsize = 8'h4 ;
16169
 
16170
        $display(" ");
16171
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16172
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16173
        if ( ok !== 1 )
16174
        begin
16175
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16176
            test_fail("Cache Line Size register could not be written" ) ;
16177
        end
16178
 
16179
        test_target_io_wr_rd
16180
        (
16181
            image_num,    // image number
16182
            0,            // test with address translation
16183
            ctrl_offset   // image control register offset
16184
        ) ;
16185
 
16186
        test_target_io_wr_rd
16187
        (
16188
            image_num,    // image number
16189
            1,            // test with address translation
16190
            ctrl_offset   // image control register offset
16191
        ) ;
16192
 
16193
        test_target_io_err_wr
16194
        (
16195
            image_num,      // image number
16196
            0,              // address translation on/off
16197
            ctrl_offset,    // image control register offset
16198
            0,              // enable error reporting
16199
 
16200
        ) ;
16201
 
16202
        test_target_io_err_wr
16203
        (
16204
            image_num,      // image number
16205
            1,              // address translation on/off
16206
            ctrl_offset,    // image control register offset
16207
            0,              // enable error reporting
16208
            1               // enable error interrupts
16209
        ) ;
16210
 
16211
        test_target_io_err_wr
16212
        (
16213
            image_num,      // image number
16214
            0,              // address translation on/off
16215
            ctrl_offset,    // image control register offset
16216
            1,              // enable error reporting
16217
 
16218
        ) ;
16219
 
16220
        test_target_io_err_wr
16221
        (
16222
            image_num,      // image number
16223
            1,              // address translation on/off
16224
            ctrl_offset,    // image control register offset
16225
            1,              // enable error reporting
16226
            1               // enable error interrupts
16227
        ) ;
16228
    end
16229
 
16230
    // Test master abort with NON supported commands
16231
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16232
 
16233
    // disable the image
16234 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16235 15 mihad
end
16236
endtask //test_pci_image
16237
 
16238
task target_fast_back_to_back ;
16239
    reg   [11:0] pci_ctrl_offset ;
16240
    reg   [11:0] ctrl_offset ;
16241
    reg   [11:0] ba_offset ;
16242
    reg   [11:0] am_offset ;
16243
    reg   [11:0] ta_offset ;
16244
    reg   [11:0] cls_offset ;
16245
    reg          do_mem_fb2b ;
16246
    reg          do_io_fb2b ;
16247
    reg          ok ;
16248
begin:main
16249
 
16250
    if ( target_mem_image !== -1 )
16251
    begin
16252
        do_mem_fb2b = 1 ;
16253
 
16254
        if (target_mem_image === 1)
16255
        begin
16256
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16257
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16258
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16259
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16260
        end
16261
        else if (target_mem_image === 2)
16262
        begin
16263
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16264
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16265
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16266
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16267
        end
16268
        else if (target_mem_image === 3)
16269
        begin
16270
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16271
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16272
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16273
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16274
        end
16275
        else if (target_mem_image === 4)
16276
        begin
16277
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16278
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16279
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16280
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16281
        end
16282
        else if (target_mem_image === 5)
16283
        begin
16284
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16285
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16286
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16287
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16288
        end
16289
    end
16290
    else
16291
        do_mem_fb2b = 0 ;
16292
 
16293
    pci_ctrl_offset = 12'h4 ;
16294
    cls_offset      = 12'h00C ;
16295
 
16296
    if ( do_mem_fb2b )
16297
    begin
16298
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16299
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16300
        if ( ok !== 1 )
16301
        begin
16302
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16303
            test_fail("PCI Base Address register could not be written") ;
16304
            disable main ;
16305
        end
16306
 
16307
        // Set Address Mask of IMAGE
16308
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16309
        if ( ok !== 1 )
16310
        begin
16311
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16312
            test_fail("PCI Address Mask register could not be written") ;
16313
            disable main ;
16314
        end
16315
 
16316
        // Set Translation Address of IMAGE
16317
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16318
        if ( ok !== 1 )
16319
        begin
16320
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16321
            test_fail("PCI Translation Address Register could not be written") ;
16322
            disable main ;
16323
        end
16324
 
16325
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16326
        if ( ok !== 1 )
16327
        begin
16328
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16329
            test_fail("PCI Image Control register could not be written") ;
16330
            disable main ;
16331
        end
16332
 
16333
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16334
        if ( ok !== 1 )
16335
        begin
16336
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16337
            test_fail("Cache Line Size register could not be written") ;
16338
            disable main ;
16339
        end
16340
 
16341
        // enable master 1 fast_b2b
16342 45 mihad
        configuration_cycle_write(0,                        // bus number
16343
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16344
                                  0,                        // function number
16345
                                  1,                        // register number
16346
                                  0,                        // type of configuration cycle
16347
                                  4'b1111,                  // byte enables
16348
                                  32'hFFFF_FFFF             // data
16349 15 mihad
                                 ) ;
16350
 
16351
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16352
 
16353
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16354
        fork
16355
        begin
16356
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16357
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16358
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16359
                  0, `Test_One_Zero_Target_WS,
16360
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16361
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16362
 
16363
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16364
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16365
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16366
                  0, `Test_One_Zero_Target_WS,
16367
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16368
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16369
            do_pause(5) ;
16370
 
16371
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16372
        end
16373
        begin:wb_monitor1
16374
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16375
            if ( ok !== 1 )
16376
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16377
 
16378
            disable monitor_error_event1 ;
16379
        end
16380
        begin:monitor_error_event1
16381
            @(error_event_int) ;
16382
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16383
            ok = 0 ;
16384
            disable wb_monitor1 ;
16385
        end
16386
        join
16387
 
16388
        if ( ok )
16389
            test_ok ;
16390
 
16391
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16392
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16393
        fork
16394
        begin
16395
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16396
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16397
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16398
                  0, `Test_One_Zero_Target_WS,
16399
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16400
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16401
 
16402
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16403
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16404
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16405
                  0, `Test_One_Zero_Target_WS,
16406
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16407
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16408
            do_pause(5) ;
16409
 
16410
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16411
 
16412
        end
16413
        begin:wb_monitor2
16414
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16415
            if ( ok !== 1 )
16416
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16417
            else
16418
            begin
16419
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16420
                if ( ok !== 1 )
16421
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16422
            end
16423
 
16424
            disable monitor_error_event2 ;
16425
        end
16426
        begin:monitor_error_event2
16427
            @(error_event_int) ;
16428
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16429
            ok = 0 ;
16430
            disable wb_monitor2 ;
16431
        end
16432
        join
16433
 
16434
        if ( ok )
16435
            test_ok ;
16436
 
16437
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16438
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16439
        fork
16440
        begin
16441
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16442
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16443
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16444
                  0, `Test_One_Zero_Target_WS,
16445
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16446
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16447
 
16448
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16449
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16450
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16451
                  0, `Test_One_Zero_Target_WS,
16452
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16453
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16454
            do_pause(5) ;
16455
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16456
 
16457
        end
16458
        begin:wb_monitor3
16459
            fork
16460
            begin
16461
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16462
                if ( ok !== 1 )
16463
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16464
            end
16465
            begin
16466
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16467
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16468
                if ( ok !== 1 )
16469
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16470
            end
16471
            join
16472
 
16473
            if ( ok )
16474
            begin
16475
                fork
16476
                begin
16477
                    do_pause(3) ;
16478
 
16479
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16480
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16481
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16482
                        0, `Test_One_Zero_Target_WS,
16483
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16484
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16485
 
16486
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16487
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16488
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16489
                            0, `Test_One_Zero_Target_WS,
16490
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16491
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16492
 
16493
                    do_pause(1) ;
16494
                end
16495
                begin
16496
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16497
                    if ( ok !== 1 )
16498
                    begin
16499
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16500
                        disable monitor_error_event3 ;
16501
                    end
16502
                    else
16503
                    begin
16504
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16505
                        if ( ok !== 1 )
16506
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16507
                    end
16508
                end
16509 26 mihad
                begin
16510
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16511
                        if ( ok !== 1 )
16512
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16513
                end
16514 15 mihad
                join
16515
            end
16516
            disable monitor_error_event3 ;
16517
        end
16518
        begin:monitor_error_event3
16519
            @(error_event_int) ;
16520
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16521
            ok = 0 ;
16522
            disable wb_monitor3 ;
16523
        end
16524
        join
16525
 
16526
        if ( ok )
16527
            test_ok ;
16528
 
16529
        test_name = "DISABLING MEM IMAGE" ;
16530 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16531 15 mihad
        if ( ok !== 1 )
16532
        begin
16533
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16534
            test_fail("PCI Address Mask register could not be written") ;
16535
            disable main ;
16536
        end
16537
    end
16538
 
16539
    if ( target_io_image !== -1 )
16540
    begin
16541
        do_io_fb2b = 1 ;
16542
 
16543
        if (target_io_image === 1)
16544
        begin
16545
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16546
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16547
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16548
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16549
        end
16550
        else if (target_io_image === 2)
16551
        begin
16552
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16553
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16554
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16555
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16556
        end
16557
        else if (target_io_image === 3)
16558
        begin
16559
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16560
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16561
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16562
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16563
        end
16564
        else if (target_io_image === 4)
16565
        begin
16566
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16567
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16568
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16569
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16570
        end
16571
        else if (target_io_image === 5)
16572
        begin
16573
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16574
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16575
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16576
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16577
        end
16578
    end
16579
    else
16580
        do_io_fb2b = 0 ;
16581
 
16582
    if ( do_io_fb2b )
16583
    begin
16584
 
16585
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16586
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16587
        if ( ok !== 1 )
16588
        begin
16589
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16590
            test_fail("PCI Base Address register could not be written") ;
16591
            disable main ;
16592
        end
16593
 
16594
        // Set Address Mask of IMAGE
16595
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16596
        if ( ok !== 1 )
16597
        begin
16598
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16599
            test_fail("PCI Address Mask register could not be written") ;
16600
            disable main ;
16601
        end
16602
 
16603
        // Set Translation Address of IMAGE
16604
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16605
        if ( ok !== 1 )
16606
        begin
16607
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16608
            test_fail("PCI Translation Address Register could not be written") ;
16609
            disable main ;
16610
        end
16611
 
16612
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16613
        if ( ok !== 1 )
16614
        begin
16615
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16616
            test_fail("PCI Image Control register could not be written") ;
16617
            disable main ;
16618
        end
16619
 
16620
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16621
        if ( ok !== 1 )
16622
        begin
16623
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16624
            test_fail("Cache Line Size register could not be written") ;
16625
            disable main ;
16626
        end
16627
 
16628
        // enable master 1 fast_b2b
16629 45 mihad
        configuration_cycle_write(0,                        // bus number
16630
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16631
                                  0,                        // function number
16632
                                  1,                        // register number
16633
                                  0,                        // type of configuration cycle
16634
                                  4'b1111,                  // byte enables
16635
                                  32'hFFFF_FFFF             // data
16636 15 mihad
                                 ) ;
16637
 
16638
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16639
 
16640
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16641
        fork
16642
        begin
16643
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16644
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16645
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16646
                  0, `Test_One_Zero_Target_WS,
16647
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16648
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16649
 
16650
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16651
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16652
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16653
                  0, `Test_One_Zero_Target_WS,
16654
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16655
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16656
            do_pause(5) ;
16657
 
16658
        end
16659
        begin:wb_monitor4
16660
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16661
            if ( ok !== 1 )
16662
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16663
 
16664
            if ( ok )
16665
            begin
16666
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16667
                if ( ok !== 1 )
16668
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16669
            end
16670
 
16671
            disable monitor_error_event4 ;
16672
        end
16673
        begin:monitor_error_event4
16674
            @(error_event_int) ;
16675
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16676
            ok = 0 ;
16677
            disable wb_monitor4 ;
16678
        end
16679
        join
16680
 
16681
        if ( ok )
16682
            test_ok ;
16683
 
16684
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16685
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16686
        fork
16687
        begin
16688
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16689
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16690
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16691
                  0, `Test_One_Zero_Target_WS,
16692
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16693
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16694
 
16695
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16696
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16697
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16698
                  0, `Test_One_Zero_Target_WS,
16699
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16700
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16701
            do_pause(5) ;
16702
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16703
        end
16704
        begin:wb_monitor5
16705
            fork
16706
            begin
16707
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16708
                if ( ok !== 1 )
16709
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16710
            end
16711
            begin
16712
                wb_transaction_stop( 1 ) ;
16713
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16714
                if ( ok !== 1 )
16715
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16716
            end
16717
            join
16718
 
16719
            if ( ok )
16720
            begin
16721
                fork
16722
                begin
16723
                    do_pause(3) ;
16724
 
16725
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16726
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16727
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16728
                            0, `Test_One_Zero_Target_WS,
16729
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16730
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16731
 
16732
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16733
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16734
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16735
                            0, `Test_One_Zero_Target_WS,
16736
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16737
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16738
 
16739
                    do_pause(1) ;
16740
                end
16741
                begin
16742
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16743
                    if ( ok !== 1 )
16744
                    begin
16745
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16746
                        disable monitor_error_event5 ;
16747
                    end
16748
                    else
16749
                    begin
16750
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16751
                        if ( ok !== 1 )
16752
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16753
                    end
16754
                end
16755
                join
16756
            end
16757
            disable monitor_error_event5 ;
16758
        end
16759
        begin:monitor_error_event5
16760
            @(error_event_int) ;
16761
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16762
            ok = 0 ;
16763
            disable wb_monitor5 ;
16764
        end
16765
        join
16766
 
16767
        if ( ok )
16768
            test_ok ;
16769
 
16770
        test_name = "DISABLING IO IMAGE" ;
16771 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16772 15 mihad
        if ( ok !== 1 )
16773
        begin
16774
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16775
            test_fail("PCI Address Mask register could not be written") ;
16776
            disable main ;
16777
        end
16778
    end
16779
 
16780
end
16781
endtask //target_fast_back_to_back
16782
 
16783
task target_disconnects ;
16784
    reg   [11:0] pci_ctrl_offset ;
16785
    reg   [11:0] ctrl_offset ;
16786
    reg   [11:0] ba_offset ;
16787
    reg   [11:0] am_offset ;
16788
    reg   [11:0] ta_offset ;
16789
    reg   [11:0] cls_offset ;
16790
    reg          pci_ok ;
16791
    reg          wb_ok ;
16792
    reg          ok ;
16793
    reg   [31:0] pci_address ;
16794
    reg   [31:0] data ;
16795
    reg   [3:0]  byte_enables ;
16796
    reg   [9:0]  expect_length ;
16797
 
16798
    reg          do_mem_disconnects ;
16799
    reg          do_io_disconnects ;
16800 35 mihad
    reg          error_monitor_done ;
16801 15 mihad
begin:main
16802
    if ( target_mem_image !== -1 )
16803
    begin
16804
        do_mem_disconnects = 1 ;
16805
 
16806
        if (target_mem_image === 1)
16807
        begin
16808
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16809
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16810
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16811
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16812
        end
16813
        else if (target_mem_image === 2)
16814
        begin
16815
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16816
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16817
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16818
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16819
        end
16820
        else if (target_mem_image === 3)
16821
        begin
16822
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16823
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16824
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16825
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16826
        end
16827
        else if (target_mem_image === 4)
16828
        begin
16829
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16830
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16831
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16832
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16833
        end
16834
        else if (target_mem_image === 5)
16835
        begin
16836
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16837
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16838
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16839
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16840
        end
16841
    end
16842
    else
16843
        do_mem_disconnects = 0 ;
16844
 
16845
    pci_ctrl_offset = 12'h4 ;
16846
    cls_offset = 12'h00C ;
16847
 
16848
    master1_check_received_data = 0 ;
16849
    master2_check_received_data = 0 ;
16850
 
16851
    `ifdef HOST
16852
        `ifdef NO_CNF_IMAGE
16853
        `else
16854
            `define TEST_BURST_CONFIG_READ
16855
        `endif
16856
    `else
16857
        `define TEST_BURST_CONFIG_READ
16858
        `define TEST_BURST_CONFIG_WRITE
16859
    `endif
16860
 
16861
    `ifdef TEST_BURST_CONFIG_WRITE
16862
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16863
 
16864
        data = 32'h0000_08_08 ;
16865
 
16866 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16867 15 mihad
        byte_enables = 4'b0000 ;
16868
 
16869
        fork
16870
        begin
16871
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16872
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16873
                    byte_enables,
16874
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16875
                    8'h0_0, `Test_One_Zero_Target_WS,
16876
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16877
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16878
 
16879
            data = 32'h0000_04_04 ;
16880
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16881
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16882
                    byte_enables,
16883
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16884
                    8'h0_0, `Test_One_Zero_Target_WS,
16885
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16886
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16887
            do_pause( 1 ) ;
16888
            while ( FRAME !== 1 || IRDY !== 1 )
16889
                @(posedge pci_clock) ;
16890
 
16891 35 mihad
            #1 ;
16892
            if ( !error_monitor_done )
16893
                disable monitor_error_event1 ;
16894 15 mihad
        end
16895
        begin:monitor_error_event1
16896 35 mihad
            error_monitor_done = 0 ;
16897 15 mihad
            ok = 1 ;
16898
            @(error_event_int) ;
16899
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16900
            ok = 0 ;
16901 35 mihad
            error_monitor_done = 1 ;
16902 15 mihad
        end
16903
        join
16904
 
16905
        config_read(pci_address, 4'hF, data) ;
16906
        if ( data [15:0] !== 16'h04_04 )
16907
        begin
16908
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16909
        end
16910
        else if ( ok )
16911
            test_ok ;
16912
 
16913 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16914
 
16915
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16916 15 mihad
        data         = 32'h0000_0808 ;
16917
        byte_enables = 4'h0 ;
16918
        fork
16919
        begin
16920
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16921
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16922
                    byte_enables,
16923
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16924
                    8'h0_0, `Test_One_Zero_Target_WS,
16925
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16926
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16927
 
16928
            data = 32'h0000_04_04 ;
16929
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16930
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16931
                    byte_enables,
16932
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16933
                    8'h0_0, `Test_One_Zero_Target_WS,
16934
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16935
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16936
 
16937
            do_pause( 1 ) ;
16938
            while ( FRAME !== 1 || IRDY !== 1 )
16939
                @(posedge pci_clock) ;
16940
 
16941 35 mihad
            #1 ;
16942
            if ( !error_monitor_done )
16943
                disable monitor_error_event2 ;
16944 15 mihad
        end
16945
        begin:monitor_error_event2
16946 35 mihad
            error_monitor_done = 0 ;
16947 15 mihad
            ok = 1 ;
16948
            @(error_event_int) ;
16949
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16950
            ok = 0 ;
16951 35 mihad
            error_monitor_done = 1 ;
16952 15 mihad
        end
16953
        join
16954
 
16955
        config_read(pci_address, 4'hF, data) ;
16956
        if ( data [15:0] !== 16'h04_04 )
16957
        begin
16958
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16959
        end
16960
        else if ( ok )
16961
            test_ok ;
16962
    `endif
16963
 
16964
    `ifdef TEST_BURST_CONFIG_READ
16965
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16966
 
16967
        data = 32'h0000_04_04 ;
16968
 
16969 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16970 15 mihad
        byte_enables = 4'b0000 ;
16971
 
16972
        fork
16973
        begin
16974
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16975
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16976
                    byte_enables,
16977
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16978
                    8'h0_0, `Test_One_Zero_Target_WS,
16979
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16980
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16981
            do_pause( 1 ) ;
16982
 
16983
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16984
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16985
                    byte_enables,
16986
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16987
                    8'h0_0, `Test_One_Zero_Target_WS,
16988
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16989
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16990
            do_pause( 1 ) ;
16991
 
16992
            while ( FRAME !== 1 || IRDY !== 1 )
16993
                @(posedge pci_clock) ;
16994
 
16995 35 mihad
            if ( !error_monitor_done )
16996
                disable monitor_error_event3 ;
16997 15 mihad
        end
16998
        begin:monitor_error_event3
16999 35 mihad
            error_monitor_done = 0 ;
17000 15 mihad
            ok = 1 ;
17001
            @(error_event_int) ;
17002
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17003
            ok = 0 ;
17004 35 mihad
            error_monitor_done = 1 ;
17005 15 mihad
        end
17006
        join
17007
 
17008
        if ( ok )
17009
            test_ok ;
17010
 
17011 45 mihad
 
17012
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
17013
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
17014 15 mihad
        fork
17015
        begin
17016
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17017
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17018
                    byte_enables,
17019
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17020
                    8'h0_0, `Test_One_Zero_Target_WS,
17021
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17022
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17023
            do_pause( 1 ) ;
17024
 
17025
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17026
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17027
                    byte_enables,
17028
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17029
                    8'h0_0, `Test_One_Zero_Target_WS,
17030
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17031
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17032
            do_pause( 1 ) ;
17033
 
17034
            while ( FRAME !== 1 || IRDY !== 1 )
17035
                @(posedge pci_clock) ;
17036
 
17037 35 mihad
            #1 ;
17038
            if ( !error_monitor_done )
17039
                disable monitor_error_event4 ;
17040 15 mihad
        end
17041
        begin:monitor_error_event4
17042 35 mihad
            error_monitor_done = 0 ;
17043 15 mihad
            ok = 1 ;
17044
            @(error_event_int) ;
17045
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17046
            ok = 0 ;
17047 35 mihad
            error_monitor_done = 1 ;
17048 15 mihad
        end
17049
        join
17050
 
17051
        if ( ok )
17052
            test_ok ;
17053
    `endif
17054
 
17055
    `ifdef TEST_BURST_CONFIG_READ
17056
        `undef TEST_BURST_CONFIG_READ
17057
    `endif
17058
 
17059
    `ifdef TEST_BURST_CONFIG_WRITE
17060
        `undef TEST_BURST_CONFIG_WRITE
17061
    `endif
17062
 
17063
    master1_check_received_data = 1 ;
17064
    master2_check_received_data = 1 ;
17065
 
17066
    if ( do_mem_disconnects )
17067
    begin
17068
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17069
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
17070
        if ( ok !== 1 )
17071
        begin
17072
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17073
            test_fail("PCI Base Address register could not be written") ;
17074
            disable main ;
17075
        end
17076
 
17077
        // Set Address Mask of IMAGE
17078
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
17079
        if ( ok !== 1 )
17080
        begin
17081
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17082
            test_fail("PCI Address Mask register could not be written") ;
17083
            disable main ;
17084
        end
17085
 
17086
        // Set Translation Address of IMAGE
17087
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
17088
        if ( ok !== 1 )
17089
        begin
17090
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17091
            test_fail("PCI Translation Address Register could not be written") ;
17092
            disable main ;
17093
        end
17094
 
17095
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17096
        if ( ok !== 1 )
17097
        begin
17098
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17099
            test_fail("PCI Image Control register could not be written") ;
17100
            disable main ;
17101
        end
17102
 
17103
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17104
        if ( ok !== 1 )
17105
        begin
17106
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17107
            test_fail("Cache Line Size register could not be written") ;
17108
            disable main ;
17109
        end
17110
 
17111
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17112
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17113
        data = 32'hAAAA_AAAA ;
17114
        byte_enables = 4'h0 ;
17115
        expect_length = `PCIW_DEPTH - 2 ;
17116
 
17117
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17118
        fork
17119
        begin
17120
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17121
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17122
                        byte_enables,
17123 73 mihad
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17124 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17125
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17126 73 mihad
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17127 15 mihad
            do_pause( 3 ) ;
17128
 
17129
            while ( FRAME !== 1 || IRDY !== 1 )
17130
                @(posedge pci_clock) ;
17131
 
17132 35 mihad
            #1 ;
17133
            if ( !error_monitor_done )
17134
                disable monitor_error_event5 ;
17135 15 mihad
        end
17136
        begin:monitor_error_event5
17137 35 mihad
            error_monitor_done = 0 ;
17138 15 mihad
            pci_ok = 1 ;
17139
            @(error_event_int) ;
17140
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17141
            pci_ok = 0 ;
17142 35 mihad
            error_monitor_done = 1 ;
17143 15 mihad
        end
17144
        begin
17145
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17146
            if ( wb_ok !== 1 )
17147
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17148
        end
17149
        join
17150
 
17151
        if ( wb_ok && pci_ok )
17152
            test_ok ;
17153
 
17154
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17155
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17156
        data = 32'hAAAA_AAAA ;
17157
        byte_enables = 4'h0 ;
17158
        expect_length = `PCIW_DEPTH - 2 ;
17159
 
17160
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17161
        fork
17162
        begin
17163
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17164
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17165
                        byte_enables,
17166 73 mihad
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17167 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17168
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17169 73 mihad
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17170 15 mihad
            do_pause( 3 ) ;
17171
 
17172
            while ( FRAME !== 1 || IRDY !== 1 )
17173
                @(posedge pci_clock) ;
17174
 
17175 35 mihad
            #1 ;
17176
            if ( !error_monitor_done )
17177
                disable monitor_error_event6 ;
17178 15 mihad
        end
17179
        begin:monitor_error_event6
17180 35 mihad
            error_monitor_done = 0 ;
17181 15 mihad
            pci_ok = 1 ;
17182
            @(error_event_int) ;
17183
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17184
            pci_ok = 0 ;
17185 35 mihad
            error_monitor_done = 1 ;
17186 15 mihad
        end
17187
        begin
17188
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17189
            if ( wb_ok !== 1 )
17190
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17191
        end
17192
        join
17193
 
17194
        if ( wb_ok && pci_ok )
17195
            test_ok ;
17196
 
17197
        master1_check_received_data = 1 ;
17198
//        master2_check_received_data = 0 ;
17199
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17200
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17201
        data = 32'hAAAA_AAAA ;
17202
        byte_enables = 4'h0 ;
17203
        expect_length = 4 ;
17204
 
17205
        fork
17206
        begin
17207
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17208
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17209
                        byte_enables,
17210
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17211
                        8'h0_0, `Test_One_Zero_Target_WS,
17212
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17213
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17214
            do_pause( 1 ) ;
17215
 
17216
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17217
            if ( wb_ok !== 1 )
17218
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17219
 
17220
            do_pause(2) ;
17221
 
17222
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17223
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17224
                        byte_enables,
17225
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17226
                        8'h0_0, `Test_One_Zero_Target_WS,
17227
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17228
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17229
            do_pause( 3 ) ;
17230
 
17231
            while ( FRAME !== 1 || IRDY !== 1 )
17232
                @(posedge pci_clock) ;
17233
 
17234 35 mihad
            #1 ;
17235
            if ( !error_monitor_done )
17236
                disable monitor_error_event7 ;
17237 15 mihad
        end
17238
        begin:monitor_error_event7
17239 35 mihad
            error_monitor_done = 0 ;
17240 15 mihad
            pci_ok = 1 ;
17241
            @(error_event_int) ;
17242
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17243
            pci_ok = 0 ;
17244 35 mihad
            error_monitor_done = 1 ;
17245 15 mihad
        end
17246
        join
17247
 
17248
        if ( wb_ok && pci_ok )
17249
            test_ok ;
17250
 
17251
        master1_check_received_data = 1 ;
17252
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17253
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17254
        data = 32'hAAAA_AAAA ;
17255
        byte_enables = 4'h0 ;
17256
        expect_length = 4 ;
17257
 
17258
        fork
17259
        begin
17260
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17261
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17262
                        byte_enables,
17263
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17264
                        8'h0_0, `Test_One_Zero_Target_WS,
17265
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17266
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17267
            do_pause( 1 ) ;
17268
 
17269
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17270
            if ( wb_ok !== 1 )
17271
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17272
 
17273
            do_pause(2) ;
17274
 
17275
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17276
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17277
                        byte_enables,
17278
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17279
                        8'h0_0, `Test_One_Zero_Target_WS,
17280
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17281
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17282
            do_pause( 3 ) ;
17283
 
17284
            while ( FRAME !== 1 || IRDY !== 1 )
17285
                @(posedge pci_clock) ;
17286
 
17287 35 mihad
            #1 ;
17288
            if ( !error_monitor_done )
17289
                disable monitor_error_event8 ;
17290 15 mihad
        end
17291
        begin:monitor_error_event8
17292 35 mihad
            error_monitor_done = 0 ;
17293 15 mihad
            pci_ok = 1 ;
17294
            @(error_event_int) ;
17295
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17296
            pci_ok = 0 ;
17297 35 mihad
            error_monitor_done = 1 ;
17298 15 mihad
        end
17299
        join
17300
 
17301
        if ( wb_ok && pci_ok )
17302
            test_ok ;
17303
 
17304
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17305
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17306
        data = 32'hDEAF_BEAF ;
17307
        byte_enables = 4'h0 ;
17308
        expect_length = 1 ;
17309
 
17310
        fork
17311
        begin
17312
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17313
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17314
                        byte_enables,
17315
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17316
                        8'h0_0, `Test_One_Zero_Target_WS,
17317
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17318
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17319
            do_pause( 3 ) ;
17320
 
17321
            while ( FRAME !== 1 || IRDY !== 1 )
17322
                @(posedge pci_clock) ;
17323
 
17324 35 mihad
            #1 ;
17325
            if ( !error_monitor_done )
17326
                disable monitor_error_event9 ;
17327 15 mihad
        end
17328
        begin:monitor_error_event9
17329 35 mihad
            error_monitor_done = 0 ;
17330 15 mihad
            pci_ok = 1 ;
17331
            @(error_event_int) ;
17332
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17333
            pci_ok = 0 ;
17334 35 mihad
            error_monitor_done = 1 ;
17335 15 mihad
        end
17336
        begin
17337
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17338
            if ( wb_ok !== 1 )
17339
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17340
        end
17341
        join
17342
 
17343
        if ( wb_ok && pci_ok )
17344
            test_ok ;
17345
 
17346
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17347
        data = 32'hDEAD_BEAF ;
17348
        byte_enables = 4'h0 ;
17349
        expect_length = 1 ;
17350
 
17351
        fork
17352
        begin
17353
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17354
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17355
                        byte_enables,
17356
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17357
                        8'h0_0, `Test_One_Zero_Target_WS,
17358
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17359
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17360
            do_pause( 3 ) ;
17361
 
17362
            while ( FRAME !== 1 || IRDY !== 1 )
17363
                @(posedge pci_clock) ;
17364
 
17365 35 mihad
            #1 ;
17366
            if ( !error_monitor_done )
17367
                disable monitor_error_event10 ;
17368 15 mihad
        end
17369
        begin:monitor_error_event10
17370 35 mihad
            error_monitor_done = 0 ;
17371 15 mihad
            pci_ok = 1 ;
17372
            @(error_event_int) ;
17373
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17374
            pci_ok = 0 ;
17375 35 mihad
            error_monitor_done = 1 ;
17376 15 mihad
        end
17377
        begin
17378
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17379
            if ( wb_ok !== 1 )
17380
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17381
        end
17382
        join
17383
 
17384
        if ( wb_ok && pci_ok )
17385
            test_ok ;
17386
 
17387
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17388
        data = 32'hAAAA_AAAA ;
17389
        byte_enables = 4'h0 ;
17390
        expect_length = 1 ;
17391
 
17392
        fork
17393
        begin
17394
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17395
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17396
                        byte_enables,
17397
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17398
                        8'h0_0, `Test_One_Zero_Target_WS,
17399
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17400
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17401
            do_pause( 3 ) ;
17402
 
17403
            while ( FRAME !== 1 || IRDY !== 1 )
17404
                @(posedge pci_clock) ;
17405
 
17406 35 mihad
            #1 ;
17407
            if ( !error_monitor_done )
17408
                disable monitor_error_event11 ;
17409 15 mihad
        end
17410
        begin:monitor_error_event11
17411 35 mihad
            error_monitor_done = 0 ;
17412 15 mihad
            pci_ok = 1 ;
17413
            @(error_event_int) ;
17414
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17415
            pci_ok = 0 ;
17416 35 mihad
            error_monitor_done = 1 ;
17417 15 mihad
        end
17418
        begin
17419
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17420
            if ( wb_ok !== 1 )
17421
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17422
        end
17423
        join
17424
 
17425
        if ( wb_ok && pci_ok )
17426
            test_ok ;
17427
 
17428
        master1_check_received_data = 1 ;
17429
 
17430
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17431
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17432
        data = 32'hDEAF_BEAF ;
17433
        byte_enables = 4'h0 ;
17434
        expect_length = 1 ;
17435
 
17436
        fork
17437
        begin
17438
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17439
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17440
                        byte_enables,
17441
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17442
                        8'h0_0, `Test_One_Zero_Target_WS,
17443
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17444
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17445
            do_pause( 1 ) ;
17446
 
17447
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17448
            if ( wb_ok !== 1 )
17449
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17450
 
17451
            do_pause(3) ;
17452
 
17453
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17454
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17455
                        byte_enables,
17456
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17457
                        8'h0_0, `Test_One_Zero_Target_WS,
17458
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17459
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17460
            do_pause( 3 ) ;
17461
 
17462
            while ( FRAME !== 1 || IRDY !== 1 )
17463
                @(posedge pci_clock) ;
17464
 
17465 35 mihad
            #1 ;
17466
            if ( !error_monitor_done )
17467
                disable monitor_error_event12 ;
17468 15 mihad
        end
17469
        begin:monitor_error_event12
17470 35 mihad
            error_monitor_done = 0 ;
17471 15 mihad
            pci_ok = 1 ;
17472
            @(error_event_int) ;
17473
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17474
            pci_ok = 0 ;
17475 35 mihad
            error_monitor_done = 1 ;
17476 15 mihad
        end
17477
        join
17478
 
17479
        if ( wb_ok && pci_ok )
17480
            test_ok ;
17481
 
17482
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17483
        data = 32'hDEAD_BEAF ;
17484
        byte_enables = 4'h0 ;
17485
        expect_length = 1 ;
17486
 
17487
        fork
17488
        begin
17489
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17490
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17491
                        byte_enables,
17492
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17493
                        8'h0_0, `Test_One_Zero_Target_WS,
17494
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17495
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17496
            do_pause( 1 ) ;
17497
 
17498
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17499
            if ( wb_ok !== 1 )
17500
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17501
 
17502
            do_pause(3) ;
17503
 
17504
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17505
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17506
                        byte_enables,
17507
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17508
                        8'h0_0, `Test_One_Zero_Target_WS,
17509
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17510
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17511
            do_pause( 3 ) ;
17512
 
17513
            while ( FRAME !== 1 || IRDY !== 1 )
17514
                @(posedge pci_clock) ;
17515
 
17516 35 mihad
            #1 ;
17517
            if ( !error_monitor_done )
17518
                disable monitor_error_event13 ;
17519 15 mihad
        end
17520
        begin:monitor_error_event13
17521 35 mihad
            error_monitor_done = 0 ;
17522 15 mihad
            pci_ok = 1 ;
17523
            @(error_event_int) ;
17524
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17525
            pci_ok = 0 ;
17526 35 mihad
            error_monitor_done = 1 ;
17527 15 mihad
        end
17528
        join
17529
 
17530
        if ( wb_ok && pci_ok )
17531
            test_ok ;
17532
 
17533
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17534
        data = 32'hAAAA_AAAA ;
17535
        byte_enables = 4'h0 ;
17536
        expect_length = 1 ;
17537
 
17538
        fork
17539
        begin
17540
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17541
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17542
                        byte_enables,
17543
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17544
                        8'h0_0, `Test_One_Zero_Target_WS,
17545
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17546
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17547
            do_pause( 1 ) ;
17548
 
17549
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17550
            if ( wb_ok !== 1 )
17551
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17552
 
17553
            do_pause(3) ;
17554
 
17555
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17556
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17557
                        byte_enables,
17558
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17559
                        8'h0_0, `Test_One_Zero_Target_WS,
17560
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17561
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17562
            do_pause( 3 ) ;
17563
 
17564
            while ( FRAME !== 1 || IRDY !== 1 )
17565
                @(posedge pci_clock) ;
17566
 
17567 35 mihad
            #1 ;
17568
            if ( !error_monitor_done )
17569
                disable monitor_error_event14 ;
17570 15 mihad
        end
17571
        begin:monitor_error_event14
17572 35 mihad
            error_monitor_done = 0 ;
17573 15 mihad
            pci_ok = 1 ;
17574
            @(error_event_int) ;
17575
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17576
            pci_ok = 0 ;
17577 35 mihad
            error_monitor_done = 1 ;
17578 15 mihad
        end
17579
        join
17580
 
17581
        if ( wb_ok && pci_ok )
17582
            test_ok ;
17583
 
17584
        // disable the image
17585
        test_name = "DISABLING MEMORY IMAGE" ;
17586 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17587 15 mihad
        if ( ok !== 1 )
17588
        begin
17589
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17590
            test_fail("PCI Address Mask register could not be written") ;
17591
            disable main ;
17592
        end
17593
    end
17594
//*
17595
    if ( target_io_image !== -1 )
17596
    begin
17597
        do_io_disconnects = 1 ;
17598
 
17599
        if (target_io_image === 1)
17600
        begin
17601
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17602
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17603
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17604
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17605
        end
17606
        else if (target_io_image === 2)
17607
        begin
17608
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17609
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17610
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17611
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17612
        end
17613
        else if (target_io_image === 3)
17614
        begin
17615
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17616
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17617
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17618
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17619
        end
17620
        else if (target_io_image === 4)
17621
        begin
17622
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17623
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17624
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17625
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17626
        end
17627
        else if (target_io_image === 5)
17628
        begin
17629
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17630
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17631
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17632
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17633
        end
17634
    end
17635
    else
17636
        do_io_disconnects = 0 ;
17637
 
17638
    if ( do_io_disconnects )
17639
    begin
17640
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17641
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17642
        if ( ok !== 1 )
17643
        begin
17644
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17645
            test_fail("PCI Base Address register could not be written") ;
17646
            disable main ;
17647
        end
17648
 
17649
        // Set Address Mask of IMAGE
17650
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17651
        if ( ok !== 1 )
17652
        begin
17653
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17654
            test_fail("PCI Address Mask register could not be written") ;
17655
            disable main ;
17656
        end
17657
 
17658
        // Set Translation Address of IMAGE
17659
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17660
        if ( ok !== 1 )
17661
        begin
17662
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17663
            test_fail("PCI Translation Address Register could not be written") ;
17664
            disable main ;
17665
        end
17666
 
17667
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17668
        if ( ok !== 1 )
17669
        begin
17670
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17671
            test_fail("PCI Image Control register could not be written") ;
17672
            disable main ;
17673
        end
17674
 
17675
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17676
        if ( ok !== 1 )
17677
        begin
17678
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17679
            test_fail("Cache Line Size register could not be written") ;
17680
            disable main ;
17681
        end
17682
 
17683
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17684
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17685
        data = 32'h5555_5555 ;
17686
        byte_enables = 4'h0 ;
17687
        expect_length = 1 ;
17688
 
17689
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17690
 
17691
        fork
17692
        begin
17693
            PCIU_IO_WRITE
17694
            (
17695
                `Test_Master_1,             // which master
17696
                pci_address,                // to what address
17697
                data,                       // data
17698
                byte_enables,               // byte enable
17699
                expect_length + 1,          // length to request
17700
                `Test_Target_Retry_On       // expected target termination
17701
            ) ;
17702
 
17703
            do_pause( 3 ) ;
17704
 
17705
            while ( FRAME !== 1 || IRDY !== 1 )
17706
                @(posedge pci_clock) ;
17707
 
17708 35 mihad
            #1 ;
17709
            if ( !error_monitor_done )
17710
                disable monitor_error_event15 ;
17711 15 mihad
        end
17712
        begin:monitor_error_event15
17713 35 mihad
            error_monitor_done = 0 ;
17714 15 mihad
            pci_ok = 1 ;
17715
            @(error_event_int) ;
17716
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17717
            pci_ok = 0 ;
17718 35 mihad
            error_monitor_done = 1 ;
17719 15 mihad
        end
17720
        begin
17721
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17722
            if ( wb_ok !== 1 )
17723
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17724
        end
17725
        join
17726
 
17727
        if ( wb_ok && pci_ok )
17728
            test_ok ;
17729
 
17730
        data = 32'hAAAA_AAAA ;
17731
        fork
17732
        begin
17733
            PCIU_IO_WRITE
17734
            (
17735
                `Test_Master_1,             // which master
17736
                pci_address,                // to what address
17737
                data,                       // data
17738
                byte_enables,               // byte enable
17739
                expect_length + 2,          // length to request
17740
                `Test_Target_Retry_Before   // expected target termination
17741
            ) ;
17742
 
17743
            do_pause( 3 ) ;
17744
 
17745
            while ( FRAME !== 1 || IRDY !== 1 )
17746
                @(posedge pci_clock) ;
17747
 
17748 35 mihad
            #1 ;
17749
            if ( !error_monitor_done )
17750
                disable monitor_error_event16 ;
17751 15 mihad
        end
17752
        begin:monitor_error_event16
17753 35 mihad
            error_monitor_done = 0 ;
17754 15 mihad
            pci_ok = 1 ;
17755
            @(error_event_int) ;
17756
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17757
            pci_ok = 0 ;
17758 35 mihad
            error_monitor_done = 1 ;
17759 15 mihad
        end
17760
        begin
17761
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17762
            if ( wb_ok !== 1 )
17763
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17764
        end
17765
        join
17766
 
17767
        if ( wb_ok && pci_ok )
17768
            test_ok ;
17769
 
17770
        master2_check_received_data = 1 ;
17771
 
17772
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17773
 
17774
        fork
17775
        begin
17776
 
17777
             PCIU_IO_READ
17778
             (
17779
                `Test_Master_2,
17780
                pci_address[PCI_BUS_DATA_RANGE:0],
17781
                data,
17782
                byte_enables,
17783
                2,
17784
                `Test_Target_Retry_Before
17785
             );
17786
 
17787
            do_pause( 1 ) ;
17788
 
17789
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17790
            if ( wb_ok !== 1 )
17791
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17792
 
17793
            do_pause(3) ;
17794
 
17795
            PCIU_IO_READ
17796
             (
17797
                `Test_Master_2,
17798
                pci_address[PCI_BUS_DATA_RANGE:0],
17799
                data,
17800
                byte_enables,
17801
                expect_length + 1,
17802
                `Test_Target_Retry_On
17803
             );
17804
 
17805
            do_pause( 3 ) ;
17806
 
17807
            while ( FRAME !== 1 || IRDY !== 1 )
17808
                @(posedge pci_clock) ;
17809
 
17810 35 mihad
            #1 ;
17811
            if ( !error_monitor_done )
17812
                disable monitor_error_event17 ;
17813 15 mihad
        end
17814
        begin:monitor_error_event17
17815 35 mihad
            error_monitor_done = 0 ;
17816 15 mihad
            pci_ok = 1 ;
17817
            @(error_event_int) ;
17818
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17819
            pci_ok = 0 ;
17820 35 mihad
            error_monitor_done = 1 ;
17821 15 mihad
        end
17822
        join
17823
 
17824
        if ( wb_ok && pci_ok )
17825
            test_ok ;
17826
 
17827
        fork
17828
        begin
17829
 
17830
             PCIU_IO_READ
17831
             (
17832
                `Test_Master_2,
17833
                pci_address[PCI_BUS_DATA_RANGE:0],
17834
                data,
17835
                byte_enables,
17836
                2,
17837
                `Test_Target_Retry_Before
17838
             );
17839
 
17840
            do_pause( 1 ) ;
17841
 
17842
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17843
            if ( wb_ok !== 1 )
17844
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17845
 
17846
            do_pause(3) ;
17847
 
17848
            PCIU_IO_READ
17849
             (
17850
                `Test_Master_2,
17851
                pci_address[PCI_BUS_DATA_RANGE:0],
17852
                data,
17853
                byte_enables,
17854
                expect_length + 2,
17855
                `Test_Target_Retry_Before
17856
             );
17857
 
17858
            do_pause( 3 ) ;
17859
 
17860
            while ( FRAME !== 1 || IRDY !== 1 )
17861
                @(posedge pci_clock) ;
17862
 
17863 35 mihad
            #1 ;
17864
            if ( !error_monitor_done )
17865
                disable monitor_error_event18 ;
17866 15 mihad
        end
17867
        begin:monitor_error_event18
17868 35 mihad
            error_monitor_done = 0 ;
17869 15 mihad
            pci_ok = 1 ;
17870
            @(error_event_int) ;
17871
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17872
            pci_ok = 0 ;
17873 35 mihad
            error_monitor_done = 1 ;
17874 15 mihad
        end
17875
        join
17876
 
17877
        if ( wb_ok && pci_ok )
17878
            test_ok ;
17879
 
17880
        test_name = "DISABLING IO IMAGE" ;
17881 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17882 15 mihad
        if ( ok !== 1 )
17883
        begin
17884
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17885
            test_fail("PCI Address Mask register could not be written") ;
17886
            disable main ;
17887
        end
17888
    end
17889
//*/
17890
end
17891
endtask // target_disconnects
17892
 
17893
task target_unsupported_cmds ;
17894
        input [31:0] Address;
17895
        input [2:0]  image_num ;
17896
    reg          ok ;
17897
begin:main
17898
 
17899
    $display("  ") ;
17900
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17901
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17902 45 mihad
 
17903
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17904
    configuration_cycle_write
17905
    (
17906
        0,                        // bus number
17907
        `TAR1_IDSEL_INDEX - 11,   // device number
17908
        0,                        // function number
17909
        1,                        // register number
17910
        0,                        // type of configuration cycle
17911
        4'b0001,                  // byte enables
17912
        32'h0000_0044             // data
17913
    ) ;
17914
 
17915
    configuration_cycle_write
17916
    (
17917
        0,                        // bus number
17918
        `TAR2_IDSEL_INDEX - 11,   // device number
17919
        0,                        // function number
17920
        1,                        // register number
17921
        0,                        // type of configuration cycle
17922
        4'b0001,                  // byte enables
17923
        32'h0000_0044             // data
17924
    ) ;
17925
 
17926 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17927 15 mihad
    (
17928
        Address,                // first part of address in dual address cycle
17929
        Address,                // second part of address in dual address cycle
17930
        `BC_IACK,                       // dual address cycle command
17931
        `BC_IACK,               // normal command
17932
        4'h0,               // byte enables
17933
        32'h1234_5678,      // data
17934
        1'b0,               // make address parity error on first phase of dual address
17935
        1'b0,               // make address parity error on second phase of dual address
17936
        ok                  // result of operation
17937
    ) ;
17938
    if ( ok )
17939
        test_ok ;
17940
    else
17941
    begin
17942
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17943
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17944
    end
17945
 
17946
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17947
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17948 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17949 15 mihad
    (
17950
        Address,                // first part of address in dual address cycle
17951
        Address,                // second part of address in dual address cycle
17952
        `BC_SPECIAL,            // dual address cycle command
17953
        `BC_SPECIAL,            // normal command
17954
        4'h0,               // byte enables
17955
        32'h1234_5678,      // data
17956
        1'b0,               // make address parity error on first phase of dual address
17957
        1'b0,               // make address parity error on second phase of dual address
17958
        ok                  // result of operation
17959
    ) ;
17960
    if ( ok )
17961
        test_ok ;
17962
    else
17963
    begin
17964
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17965
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17966
    end
17967
 
17968
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17969
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17970 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17971 15 mihad
    (
17972
        Address,                // first part of address in dual address cycle
17973
        Address,                // second part of address in dual address cycle
17974
        `BC_RESERVED0,          // dual address cycle command
17975
        `BC_RESERVED0,      // normal command
17976
        4'h0,               // byte enables
17977
        32'h1234_5678,      // data
17978
        1'b0,               // make address parity error on first phase of dual address
17979
        1'b0,               // make address parity error on second phase of dual address
17980
        ok                  // result of operation
17981
    ) ;
17982
    if ( ok )
17983
        test_ok ;
17984
    else
17985
    begin
17986
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17987
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17988
    end
17989
 
17990
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17991
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17992 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17993 15 mihad
    (
17994
        Address,                // first part of address in dual address cycle
17995
        Address,                // second part of address in dual address cycle
17996
        `BC_RESERVED1,          // dual address cycle command
17997
        `BC_RESERVED1,      // normal command
17998
        4'h0,               // byte enables
17999
        32'h1234_5678,      // data
18000
        1'b0,               // make address parity error on first phase of dual address
18001
        1'b0,               // make address parity error on second phase of dual address
18002
        ok                  // result of operation
18003
    ) ;
18004
    if ( ok )
18005
        test_ok ;
18006
    else
18007
    begin
18008
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18009
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
18010
    end
18011
 
18012
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
18013
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
18014 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18015 15 mihad
    (
18016
        Address,                // first part of address in dual address cycle
18017
        Address,                // second part of address in dual address cycle
18018
        `BC_RESERVED2,          // dual address cycle command
18019
        `BC_RESERVED2,      // normal command
18020
        4'h0,               // byte enables
18021
        32'h1234_5678,      // data
18022
        1'b0,               // make address parity error on first phase of dual address
18023
        1'b0,               // make address parity error on second phase of dual address
18024
        ok                  // result of operation
18025
    ) ;
18026
    if ( ok )
18027
        test_ok ;
18028
    else
18029
    begin
18030
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18031
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
18032
    end
18033
 
18034
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
18035
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
18036 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18037 15 mihad
    (
18038
        Address,                // first part of address in dual address cycle
18039
        Address,                // second part of address in dual address cycle
18040
        `BC_RESERVED3,          // dual address cycle command
18041
        `BC_RESERVED3,      // normal command
18042
        4'h0,               // byte enables
18043
        32'h1234_5678,      // data
18044
        1'b0,               // make address parity error on first phase of dual address
18045
        1'b0,               // make address parity error on second phase of dual address
18046
        ok                  // result of operation
18047
    ) ;
18048
    if ( ok )
18049
        test_ok ;
18050
    else
18051
    begin
18052
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18053
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
18054
    end
18055
 
18056
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
18057
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
18058
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
18059
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
18060 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18061 15 mihad
    (
18062
        Address,                // first part of address in dual address cycle
18063
        Address,                // second part of address in dual address cycle
18064
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
18065
        `BC_MEM_WRITE,      // normal command
18066
        4'h0,               // byte enables;
18067
        32'h1234_5678,      // data
18068
        1'b0,               // make address parity error on first phase of dual address
18069
        1'b0,               // make address parity error on second phase of dual address
18070
        ok                  // result of operation
18071
    ) ;
18072
    if ( ok )
18073
        test_ok ;
18074
    else
18075
    begin
18076
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18077
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
18078
    end
18079
 
18080 45 mihad
    // enable pci blue behavioral targets 1 and 2
18081
    configuration_cycle_write
18082
    (
18083
        0,                        // bus number
18084
        `TAR1_IDSEL_INDEX - 11,   // device number
18085
        0,                        // function number
18086
        1,                        // register number
18087
        0,                        // type of configuration cycle
18088
        4'b0001,                  // byte enables
18089
        32'h0000_0047             // data
18090
    ) ;
18091
 
18092
    configuration_cycle_write
18093
    (
18094
        0,                        // bus number
18095
        `TAR2_IDSEL_INDEX - 11,   // device number
18096
        0,                        // function number
18097
        1,                        // register number
18098
        0,                        // type of configuration cycle
18099
        4'b0001,                  // byte enables
18100
        32'h0000_0047             // data
18101
    ) ;
18102 15 mihad
end
18103
endtask // target_unsupported_cmds
18104
 
18105 63 mihad
`ifdef DISABLE_COMPLETION_EXPIRED_TESTS
18106
`else
18107 15 mihad
task target_completion_expiration ;
18108
    reg   [11:0] pci_ctrl_offset ;
18109
    reg   [11:0] pci_ba_offset ;
18110
    reg   [11:0] pci_am_offset ;
18111
    reg   [11:0] pci_device_ctrl_offset ;
18112
    reg   [11:0] pci_err_cs_offset ;
18113
    reg   [11:0] icr_offset ;
18114
    reg   [11:0] isr_offset ;
18115
    reg   [11:0] lat_tim_cls_offset ;
18116
 
18117
    reg [31:0] temp_val1 ;
18118
    reg [31:0] temp_val2 ;
18119
    reg        ok   ;
18120 33 mihad
    reg        ok_wb ;
18121
    reg        ok_pci ;
18122 15 mihad
 
18123
    reg [31:0] pci_image_base ;
18124
    integer i ;
18125 33 mihad
    integer clocks_after_completion ;
18126
    reg     error_monitor_done ;
18127
    reg     test_mem ;
18128 15 mihad
 
18129
begin:main
18130
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18131
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
18132
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
18133
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
18134
 
18135
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
18136
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
18137
    lat_tim_cls_offset = 12'hC ;
18138
    pci_device_ctrl_offset    = 12'h4 ;
18139
 
18140 33 mihad
    `ifdef HOST
18141
        test_mem = 1'b1 ;
18142
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
18143
    `else
18144
        test_mem = !`PCI_BA1_MEM_IO ;
18145
        pci_image_base = Target_Base_Addr_R[1] ;
18146
    `endif
18147 15 mihad
 
18148
    // enable master & target operation
18149
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
18150
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
18151
    if ( ok !== 1 )
18152
    begin
18153
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18154
        test_fail("write to PCI Device Control register failed") ;
18155
        disable main ;
18156
    end
18157
 
18158
    // prepare image control register
18159 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18160 15 mihad
    if ( ok !== 1 )
18161
    begin
18162
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18163
        test_fail("write to PCI Image Control register failed") ;
18164
        disable main ;
18165
    end
18166
 
18167
    // prepare base address register
18168
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18169
    if ( ok !== 1 )
18170
    begin
18171
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18172
        test_fail("write to PCI Base Address register failed") ;
18173
        disable main ;
18174
    end
18175
 
18176
    // write address mask register
18177
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18178
    if ( ok !== 1 )
18179
    begin
18180
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18181
        test_fail("write to PCI Address Mask register failed") ;
18182
        disable main ;
18183
    end
18184
 
18185
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18186
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18187
    if ( ok !== 1 )
18188
    begin
18189
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18190
        test_fail("write to PCI Error Control and Status register failed") ;
18191
        disable main ;
18192
    end
18193
 
18194 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18195 15 mihad
    if ( ok !== 1 )
18196
    begin
18197
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18198
        test_fail("write to Interrupt Control register failed") ;
18199
        disable main ;
18200
    end
18201
 
18202
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18203
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18204
    if ( ok !== 1 )
18205
    begin
18206
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18207
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18208
        disable main ;
18209
    end
18210
 
18211
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18212
 
18213
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18214 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18215
    master1_check_received_data = 0 ;
18216 15 mihad
 
18217 33 mihad
    ok_pci = 1 ;
18218
    // start a delayed read request
18219
    fork
18220
    begin
18221
        if ( test_mem )
18222
 
18223
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18224
                          pci_image_base, 32'h1234_5678,
18225
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18226
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18227
        else
18228
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18229
 
18230
        do_pause( 1 ) ;
18231
    end
18232
    begin:error_monitor1
18233 35 mihad
        error_monitor_done = 0 ;
18234 33 mihad
        @(error_event_int) ;
18235
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18236
        ok_pci = 0 ;
18237 35 mihad
        error_monitor_done = 1 ;
18238 33 mihad
    end
18239
    begin
18240
        if ( test_mem )
18241
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18242
        else
18243
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18244 15 mihad
 
18245 33 mihad
        if ( ok_wb !== 1 )
18246
        begin
18247
            test_fail("Bridge failed to process Target Memory read correctly") ;
18248
            disable main ;
18249
        end
18250
 
18251 35 mihad
        #1 ;
18252
        if ( !error_monitor_done )
18253 33 mihad
            disable error_monitor1 ;
18254
    end
18255
    join
18256
 
18257
    clocks_after_completion = 0 ;
18258
    // now do another - different transaction
18259
    fork
18260
    begin
18261
        if ( test_mem )
18262
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18263
                          pci_image_base + 4, 32'h1234_5678,
18264
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18265
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18266
        else
18267
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18268
 
18269
        while ( clocks_after_completion < 32'h0000_FFF0 )
18270
        begin
18271
            @(posedge pci_clock) ;
18272
            clocks_after_completion = clocks_after_completion + 1 ;
18273
        end
18274
 
18275
        do_pause('hFF) ;
18276
 
18277
        if ( test_mem )
18278
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18279
                          pci_image_base + 4, 32'h1234_5678,
18280
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18281
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18282
        else
18283
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18284
 
18285
        do_pause( 1 ) ;
18286
    end
18287
    begin:error_monitor2
18288 35 mihad
        error_monitor_done = 0 ;
18289 33 mihad
        @(error_event_int) ;
18290
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18291
        ok_pci = 0 ;
18292 35 mihad
        error_monitor_done = 1 ;
18293 33 mihad
    end
18294
    begin
18295
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18296
        repeat( 'hFF )
18297
            @(posedge pci_clock) ;
18298
 
18299
        if ( test_mem )
18300
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18301
        else
18302
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18303
 
18304
        if ( ok_wb !== 1 )
18305
        begin
18306
            test_fail("Bridge failed to process Target Memory read correctly") ;
18307
            disable main ;
18308
        end
18309
 
18310
        repeat(4)
18311
            @(posedge pci_clock) ;
18312
 
18313
        fork
18314
        begin
18315
            if ( test_mem )
18316
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18317
                              pci_image_base + 4, 32'h1234_5678,
18318
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18319
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18320
            else
18321
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18322
 
18323
            do_pause(1) ;
18324
        end
18325
        begin
18326
           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 ) ;
18327 35 mihad
           #1 ;
18328
           if ( !error_monitor_done )
18329 33 mihad
               disable error_monitor2 ;
18330
        end
18331
        join
18332
    end
18333
    join
18334
 
18335
    if ( ok && ok_pci && ok_wb )
18336
        test_ok ;
18337
 
18338
    if ( ok !== 1 )
18339
    begin
18340
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18341
        test_fail("write to PCI Address Mask register failed") ;
18342
        disable main ;
18343
    end
18344
 
18345
    // check statuses after this situation - none should be set
18346
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18347
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18348
    if ( ok !== 1 )
18349
    begin
18350
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18351
        test_fail("read from pci device status register failed") ;
18352
        disable main ;
18353
    end
18354
 
18355
    if ( temp_val1[31] )
18356
    begin
18357
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18358
        test_fail("detected parity error bit was set for no reason") ;
18359
    end
18360
 
18361
    if ( temp_val1[30] )
18362
    begin
18363
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18364
        test_fail("signaled system error bit was set for no reason") ;
18365
    end
18366
 
18367
    if ( temp_val1[29] )
18368
    begin
18369
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18370
        test_fail("received master abort bit was set for no reason") ;
18371
    end
18372
 
18373
    if ( temp_val1[28] )
18374
    begin
18375
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18376
        test_fail("received target abort bit was set for no reason") ;
18377
    end
18378
 
18379
    if ( temp_val1[27] )
18380
    begin
18381
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18382
        test_fail("signaled target abort bit was set for no reason") ;
18383
    end
18384
 
18385
    if ( temp_val1[24] )
18386
    begin
18387
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18388
        test_fail("Master Data parity error bit was set for no reason") ;
18389
    end
18390
 
18391
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18392
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18393
    if ( temp_val1[8] !== 0 )
18394
    begin
18395
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18396
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18397
    end
18398
    // test target retry counter expiration
18399
    // set wb slave to retry response
18400
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18401
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18402
    ok_pci = 1 ;
18403
 
18404
    fork
18405
    begin
18406
        if ( test_mem == 1 )
18407
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18408
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18409
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18410
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18411
        else
18412
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18413
 
18414
        do_pause(1) ;
18415
 
18416
        // do another write with same address and different data
18417
        if ( test_mem == 1 )
18418
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18419
                        pci_image_base, 32'h8765_4321, 4'h0,
18420
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18421
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18422
        else
18423
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18424
 
18425
        do_pause(1) ;
18426
    end
18427
    begin
18428
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18429
        begin
18430
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18431
            if ( ok_wb !== 1 )
18432
            begin
18433
                $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) ;
18434
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18435
                disable main ;
18436
            end
18437
        end
18438
 
18439
        // set WB slave to normal completion
18440
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18441
 
18442
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18443
        if ( ok_wb !== 1 )
18444
        begin
18445
            $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) ;
18446
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18447
            disable main ;
18448
        end
18449
 
18450 35 mihad
        #1 ;
18451
        if ( !error_monitor_done )
18452 33 mihad
            disable error_monitor3 ;
18453
    end
18454
    begin:error_monitor3
18455 35 mihad
        error_monitor_done = 0 ;
18456 33 mihad
        @(error_event_int) ;
18457
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18458
        ok_pci = 0 ;
18459 35 mihad
        error_monitor_done = 1 ;
18460 33 mihad
    end
18461
    join
18462
 
18463
    if ( ok_wb && ok_pci )
18464
    begin
18465
        test_ok ;
18466
    end
18467
 
18468
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18469
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18470
    if ( temp_val1[8] !== 1'b1 )
18471
    begin
18472
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18473
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18474
    end
18475
 
18476
    if ( temp_val1[9] !== 1 )
18477
    begin
18478
        $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) ;
18479
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18480
    end
18481
 
18482
    if ( temp_val1[10] !== 1 )
18483
    begin
18484
        $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) ;
18485
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18486
    end
18487
 
18488
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18489
    begin
18490
        $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) ;
18491
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18492
    end
18493
 
18494
    if ( temp_val1[31:28] !== 4'hA )
18495
    begin
18496
        $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) ;
18497
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18498
    end
18499
 
18500
    // clear error status register
18501
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18502
 
18503
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18504
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18505
    if ( temp_val1 !== pci_image_base )
18506
    begin
18507
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18508
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18509
    end
18510
 
18511
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18512
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18513
    if ( temp_val1 !== 32'hDEAD_BEAF )
18514
    begin
18515
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18516
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18517
    end
18518
 
18519
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18520
    ok_pci = 1 ;
18521
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18522
 
18523
    i = 0 ;
18524
    fork
18525
    begin
18526
        if ( test_mem )
18527
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18528
                          pci_image_base + 4, 32'h1234_5678,
18529
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18530
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18531
        else
18532
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18533
 
18534
        do_pause( 1 ) ;
18535
 
18536
    end
18537
    begin
18538
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18539
        begin
18540
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18541
            if ( ok_wb !== 1 )
18542
            begin
18543
                $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) ;
18544
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18545
                disable main ;
18546
            end
18547
        end
18548
 
18549
        // set WB slave to normal completion
18550
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18551
 
18552
        fork
18553
        begin
18554
            repeat(4)
18555
                @(posedge pci_clock) ;
18556
 
18557
            if ( test_mem )
18558
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18559
                              pci_image_base, 32'h8765_4321,
18560
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18561
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18562
            else
18563
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18564
 
18565
            do_pause(1) ;
18566
        end
18567
        begin
18568
 
18569
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18570
            if ( ok_wb !== 1 )
18571
            begin
18572
                $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) ;
18573
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18574
                disable main ;
18575
            end
18576
        end
18577
        join
18578
 
18579
        repeat( 4 )
18580
            @(posedge pci_clock) ;
18581
 
18582
        if ( test_mem )
18583
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18584
                          pci_image_base, 32'h8765_4321,
18585
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18586
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18587
        else
18588
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18589
 
18590
        do_pause(1) ;
18591
 
18592 35 mihad
        #1 ;
18593
        if ( !error_monitor_done )
18594 33 mihad
            disable error_monitor4 ;
18595
    end
18596
    begin:error_monitor4
18597 35 mihad
        error_monitor_done = 0 ;
18598 33 mihad
        @(error_event_int) ;
18599
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18600
        ok_pci = 0 ;
18601 35 mihad
        error_monitor_done = 1 ;
18602 33 mihad
    end
18603
    join
18604
 
18605
    if ( ok_wb && ok_pci )
18606
        test_ok ;
18607
 
18608
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18609
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18610
    if ( temp_val1[8] !== 1'b0 )
18611
    begin
18612
        $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) ;
18613
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18614
    end
18615
 
18616
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18617 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18618
    $fdisplay(pciu_mon_log_file_desc,
18619
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18620 33 mihad
    ok_pci = 1 ;
18621
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18622
 
18623
    fork
18624
    begin
18625
        if ( test_mem )
18626
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18627
                          pci_image_base + 4, 32'h1234_5678,
18628
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18629
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18630
        else
18631
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18632
 
18633
        do_pause( 1 ) ;
18634
 
18635
    end
18636
    begin
18637
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18638
        if ( ok_wb !== 1 )
18639
        begin
18640
            $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) ;
18641
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18642
            disable main ;
18643
        end
18644
 
18645
        repeat(4)
18646
            @(posedge pci_clock) ;
18647
 
18648
        fork
18649
        begin
18650
 
18651
            if ( test_mem )
18652
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18653
                              pci_image_base + 4, 32'h8765_4321,
18654
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18655
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18656
            else
18657
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18658
 
18659
            do_pause(1) ;
18660
 
18661
        end
18662
        begin
18663
 
18664
            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 ) ;
18665
            if ( ok !== 1 )
18666
            begin
18667
                $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) ;
18668
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18669
                disable main ;
18670
            end
18671
        end
18672
        join
18673
 
18674 35 mihad
        #1 ;
18675
        if ( !error_monitor_done )
18676 33 mihad
            disable error_monitor5 ;
18677
    end
18678
    begin:error_monitor5
18679 35 mihad
        error_monitor_done = 0 ;
18680 33 mihad
        @(error_event_int) ;
18681
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18682
        ok_pci = 0 ;
18683 35 mihad
        error_monitor_done = 1 ;
18684 33 mihad
    end
18685
    join
18686
 
18687
    if ( ok_wb && ok_pci )
18688
        test_ok ;
18689
 
18690
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18691
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18692
    if ( temp_val1[8] !== 1'b0 )
18693
    begin
18694
        $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) ;
18695
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18696
    end
18697
 
18698
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18699
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18700
    if ( temp_val1[25] !== 1'b1 )
18701
    begin
18702
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18703
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18704
    end
18705
 
18706
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18707
 
18708
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18709
    ok_pci = 1 ;
18710
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18711
 
18712
    fork
18713
    begin
18714
        if ( test_mem == 1 )
18715
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18716
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18717
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18718
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18719
        else
18720
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18721
 
18722
        do_pause(1) ;
18723
 
18724
        // do another write with same address and different data
18725
        if ( test_mem == 1 )
18726
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18727
                        pci_image_base, 32'h8765_6789, 4'h0,
18728
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18729
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18730
        else
18731
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18732
 
18733
        do_pause(1) ;
18734
    end
18735
    begin
18736
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18737
        if ( ok_wb !== 1 )
18738
        begin
18739
            $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) ;
18740
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18741
            disable main ;
18742
        end
18743
 
18744
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18745
 
18746
        if ( test_mem )
18747
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18748
        else
18749
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18750
 
18751
        if ( ok_wb !== 1 )
18752
        begin
18753
            $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) ;
18754
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18755
            disable main ;
18756
        end
18757
 
18758 35 mihad
        #1 ;
18759
        if ( !error_monitor_done )
18760 33 mihad
            disable error_monitor6 ;
18761
    end
18762
    begin:error_monitor6
18763 35 mihad
        error_monitor_done = 0 ;
18764 33 mihad
        @(error_event_int) ;
18765
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18766
        ok_pci = 0 ;
18767 35 mihad
        error_monitor_done = 1 ;
18768 33 mihad
    end
18769
    join
18770
 
18771
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18772
    $fdisplay(pciu_mon_log_file_desc,
18773
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18774
 
18775
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18776
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18777
    if ( temp_val1[8] !== 1'b1 )
18778
    begin
18779
        $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) ;
18780
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18781
    end
18782
 
18783
    if ( temp_val1[9] !== 0 )
18784
    begin
18785
        $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) ;
18786
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18787
    end
18788
 
18789
    if ( temp_val1[10] !== 1 )
18790
    begin
18791
        $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) ;
18792
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18793
    end
18794
 
18795
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18796
    begin
18797
        $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) ;
18798
        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") ;
18799
    end
18800
 
18801
    if ( temp_val1[31:28] !== 4'h0 )
18802
    begin
18803
        $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) ;
18804
        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") ;
18805
    end
18806
 
18807
    // clear error status register
18808
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18809
 
18810
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18811
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18812
    if ( temp_val1 !== pci_image_base )
18813
    begin
18814
        $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) ;
18815
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18816
    end
18817
 
18818
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18819
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18820
    if ( temp_val1 !== 32'hBEAF_DEAD )
18821
    begin
18822
        $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) ;
18823
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18824
    end
18825
 
18826
    // disable current image - write address mask register
18827 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18828 15 mihad
end
18829 57 mihad
endtask // target_completion_expiration
18830 15 mihad
 
18831 57 mihad
task master_completion_expiration ;
18832
    reg   [11:0] ctrl_offset ;
18833
    reg   [11:0] ba_offset ;
18834
    reg   [11:0] am_offset ;
18835
    reg `WRITE_STIM_TYPE write_data ;
18836
    reg `READ_STIM_TYPE  read_data ;
18837
    reg `READ_RETURN_TYPE read_status ;
18838
 
18839
    reg `WRITE_RETURN_TYPE write_status ;
18840
    reg `WB_TRANSFER_FLAGS write_flags ;
18841
    reg        ok   ;
18842
    reg [11:0] pci_ctrl_offset ;
18843
    reg [31:0] image_base ;
18844
    reg [31:0] target_address ;
18845
begin:main
18846
    pci_ctrl_offset = 12'h4 ;
18847
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
18848
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
18849
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
18850
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
18851
 
18852
    target_address  = `BEH_TAR1_MEM_START ;
18853
    image_base      = 0 ;
18854
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
18855
 
18856
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
18857
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
18858
    write_flags                      = 0 ;
18859
    write_flags`INIT_WAITS           = tb_init_waits ;
18860
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
18861
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18862
 
18863
    // enable master & target operation
18864
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
18865
    if ( ok !== 1 )
18866
    begin
18867
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18868
        test_fail("write to PCI Device Control register didn't succeede");
18869
        disable main ;
18870
    end
18871
 
18872
    // prepare image control register
18873
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
18874
    if ( ok !== 1 )
18875
    begin
18876
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
18877
        test_fail("write to WB Image Control register didn't succeede");
18878
        disable main ;
18879
    end
18880
 
18881
    // prepare base address register
18882
    config_write( ba_offset, image_base, 4'hF, ok ) ;
18883
    if ( ok !== 1 )
18884
    begin
18885
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
18886
        test_fail("write to WB Base Address register didn't succeede");
18887
        disable main ;
18888
    end
18889
 
18890
    // write address mask register
18891
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18892
    if ( ok !== 1 )
18893
    begin
18894
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18895
        test_fail("write to WB Address Mask register didn't succeede");
18896
        disable main ;
18897
    end
18898
 
18899
    fork
18900
    begin
18901
        // do not handle retries
18902
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
18903
 
18904
        // initiate a read request
18905
        read_data`READ_ADDRESS  = target_address ;
18906
        read_data`READ_SEL      = 4'hF ;
18907
        read_data`READ_TAG_STIM = 0 ;
18908
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18909
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
18910
        begin
18911
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18912
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
18913
            disable main ;
18914
        end
18915
 
18916
        // handle retries from now on
18917
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
18918
 
18919
        write_data`WRITE_ADDRESS = target_address + 4 ;
18920
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
18921
        write_data`WRITE_SEL     = 4'hF ;
18922
 
18923
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18924
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18925
        begin
18926
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
18927
            test_fail("WB Slave state machine failed to post single memory write");
18928
            disable main ;
18929
        end
18930
 
18931 81 mihad
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 110
18932
        repeat('h1_0000 - 110)
18933 57 mihad
            @(posedge wb_clock) ;
18934
 
18935
        // now perform a read
18936
        read_data`READ_ADDRESS  = target_address + 4 ;
18937
        read_data`READ_SEL      = 4'hF ;
18938
        read_data`READ_TAG_STIM = 0 ;
18939
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18940
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18941
        begin
18942
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18943
            test_fail("PCI bridge didn't process the read as expected");
18944
            disable main ;
18945
        end
18946
 
18947
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
18948
        begin
18949
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
18950
            test_fail("PCI bridge returned unexpected Read Data");
18951
        end
18952
        else if (ok === 1'b1)
18953
            test_ok ;
18954
    end
18955
    begin:monitors
18956
        // monitor first read, which will expire
18957
        pci_transaction_progress_monitor
18958
        (
18959
            target_address, // expected address
18960
            `BC_MEM_READ,   // expected bus command
18961
            1,              // expected number of transfers
18962
            0,              // expected number of cycles
18963
            1,              // check number of transfers true/false
18964
            0,              // check number of cycles true/false
18965
            0,              // is this fast B2B true/false
18966
            ok              // return 1 if as expected, anything else on error
18967
        ) ;
18968
 
18969
        if ( ok !== 1 )
18970
        begin
18971
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18972
            #1 disable monitors ;
18973
        end
18974
 
18975
        // monitor normal single write
18976
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
18977
        if ( ok !== 1 )
18978
        begin
18979
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18980
            #1 disable monitors ;
18981
        end
18982
 
18983
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
18984 81 mihad
        repeat('h1_0000 - 100)
18985 57 mihad
            @(posedge wb_clock) ;
18986
 
18987
        // monitor normal single memory read
18988
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
18989
        if ( ok !== 1 )
18990
        begin
18991
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
18992
        end
18993
    end
18994
    join
18995
 
18996
    // disable the image
18997
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
18998
    if ( ok !== 1 )
18999
    begin
19000
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
19001
        test_fail("write to WB Address Mask register didn't succeede");
19002
    end
19003
end
19004
endtask // master_completion_expiration
19005 63 mihad
`endif
19006 57 mihad
 
19007 15 mihad
task config_write ;
19008
    input [11:0] offset ;
19009
    input [31:0] data ;
19010
    input [3:0]  byte_enable ;
19011
    output       ok ;
19012
    `ifdef HOST
19013
    reg   `WRITE_STIM_TYPE   write_data ;
19014
    reg   `WB_TRANSFER_FLAGS write_flags ;
19015
    reg   `WRITE_RETURN_TYPE write_status ;
19016
    `else
19017
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
19018
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
19019
    `endif
19020
    reg in_use ;
19021
    reg [31:0] temp_var ;
19022
begin
19023
    if ( in_use === 1 )
19024
    begin
19025
        $display("config_read task re-entered! Time %t ", $time) ;
19026
        ok = 0 ;
19027
        #20 $stop ;
19028
    end
19029
    else
19030
    begin
19031
        ok = 1 ;
19032
        in_use = 1 ;
19033
    end
19034
    `ifdef HOST
19035
    write_flags                    = 0 ;
19036
    write_flags`INIT_WAITS         = tb_init_waits ;
19037
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19038
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19039
 
19040
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19041
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19042
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
19043
    write_data`WRITE_SEL                         = byte_enable ;
19044
    write_data`WRITE_TAG_STIM                    = 0 ;
19045
    write_data`WRITE_DATA                        = data ;
19046
 
19047
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
19048
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
19049
    begin
19050
        $display("Write to configuration space failed! Time %t ", $time) ;
19051
        ok = 0 ;
19052
    end
19053
 
19054
    @(posedge wb_clock) ;
19055
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
19056
    // here we just wait for two guest cycles for conf space bits to synchronize
19057
    repeat( 2 )
19058
        @(posedge pci_clock) ;
19059
 
19060
    `else // GUEST
19061
    byte_enables_l = ~byte_enable ;
19062
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19063
 
19064
    fork
19065
    begin
19066
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19067
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
19068
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
19069
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19070
              8'h0_0, `Test_One_Zero_Target_WS,
19071
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
19072
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19073
    do_pause( 1 ) ;
19074
    end
19075
    begin
19076
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
19077
        @(posedge pci_clock) ;
19078
    end
19079
    join
19080
 
19081
     repeat( 2 )
19082
         @(posedge wb_clock) ;
19083
 
19084
    `endif
19085
    in_use = 0 ;
19086
end
19087
endtask // config_write
19088
 
19089
task config_read ;
19090
    input [11:0] offset ;
19091
    input [3:0]  byte_enable ;
19092
    output [31:0] data ;
19093
 
19094
    reg `READ_STIM_TYPE    read_data ;
19095
    reg `WB_TRANSFER_FLAGS read_flags ;
19096
    reg `READ_RETURN_TYPE  read_status ;
19097
 
19098
    reg [31:0] pci_address ;
19099
    reg [3:0] byte_enables_l ;
19100
 
19101
    reg master_check_data_prev ;
19102
    reg in_use ;
19103
    reg [31:0] temp_var ;
19104
begin:main
19105
    if ( in_use === 1 )
19106
    begin
19107
        $display("config_read task re-entered! Time %t ", $time) ;
19108
        data = 32'hxxxx_xxxx ;
19109
        disable main ;
19110
    end
19111
 
19112
    in_use = 1 ;
19113
 
19114
`ifdef HOST
19115 26 mihad
    repeat(4)
19116
        @(posedge pci_clock) ;
19117
    repeat(4)
19118
        @(posedge wb_clock) ;
19119 15 mihad
    read_flags                    = 0 ;
19120
    read_flags`INIT_WAITS         = tb_init_waits ;
19121
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19122
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19123
 
19124
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19125
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19126
 
19127
    read_data`READ_ADDRESS  = temp_var + offset ;
19128
    read_data`READ_SEL      = byte_enable ;
19129
    read_data`READ_TAG_STIM = 0 ;
19130
 
19131
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
19132
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19133
    begin
19134
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
19135
        #20 $stop ;
19136
    end
19137
    data = read_status`READ_DATA ;
19138
`else
19139
  `ifdef GUEST
19140 26 mihad
    repeat(4)
19141
        @(posedge wb_clock) ;
19142
    repeat(4)
19143
        @(posedge pci_clock) ;
19144 15 mihad
    master_check_data_prev = master2_check_received_data ;
19145
    master2_check_received_data = 0 ;
19146
 
19147
    byte_enables_l = ~byte_enable ;
19148
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19149
 
19150
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19151
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
19152
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19153
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19154
             8'h4_0, `Test_One_Zero_Target_WS,
19155
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19156
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19157
    do_pause( 1 ) ;
19158
 
19159
    @(master2_received_data_valid) ;
19160
    data = master2_received_data ;
19161
 
19162
    master2_check_received_data = master_check_data_prev ;
19163
  `endif
19164
`endif
19165
    in_use = 0 ;
19166
end
19167
endtask //config_read
19168
 
19169 62 mihad
`ifdef PCI_BIST
19170
`ifdef WB_RAM_DONT_SHARE
19171
    `ifdef PCI_RAM_DONT_SHARE
19172
        parameter bist_chain_length = 8 ;
19173
    `else
19174
        parameter bist_chain_length = 6 ;
19175
    `endif
19176
`else
19177
    `ifdef PCI_RAM_DONT_SHARE
19178 69 mihad
        parameter bist_chain_length = 6 ;
19179 62 mihad
    `else
19180 69 mihad
        parameter bist_chain_length = 4 ;
19181 62 mihad
    `endif
19182
`endif
19183
 
19184
task run_bist_test ;
19185
    reg [(bist_chain_length - 1):0] bist_result_vector ;
19186
    integer count ;
19187
    integer deadlock_count ;
19188
begin
19189
 
19190
    test_name = "BIST FOR RAMS RUN" ;
19191
 
19192 69 mihad
    scanb_en  = 0 ;
19193
    scanb_si  = 0 ;
19194
    scanb_rst = 0 ;
19195
    scanb_clk = 0 ;
19196 62 mihad
 
19197
    fork
19198
    begin
19199
        repeat(2)
19200
            @(posedge wb_clock) ;
19201
    end
19202
    begin
19203
        repeat(2)
19204
            @(posedge pci_clock) ;
19205
    end
19206
    join
19207
 
19208 69 mihad
    // test is run by reseting the test logic
19209
    scanb_rst <= 1'b1 ;
19210
 
19211
    // toggle scan clock for a few times
19212
    repeat (20)
19213
        #50 scanb_clk = !scanb_clk ;
19214
 
19215
    // release bist reset
19216
    scanb_rst <= 1'b0 ;
19217 62 mihad
 
19218
    bist_result_vector = 0 ;
19219
 
19220
    // result vector must be all 1s, because in RTL there cannot be a reason for BIST to fail
19221
    fork
19222
    begin:scan
19223
        while (bist_result_vector !== {bist_chain_length{1'b1}})
19224
        begin
19225 69 mihad
            #1 ;
19226
            @(posedge scanb_clk) ;
19227
            scanb_en <= #1 1'b1 ;
19228 62 mihad
            for (count = 0 ; count < bist_chain_length ; count = count + 1'b1)
19229
            begin
19230 69 mihad
                @(posedge scanb_clk) ;
19231
                bist_result_vector[count] = scanb_so ;
19232 62 mihad
            end
19233
 
19234 69 mihad
            scanb_en <= #1 1'b0 ;
19235 62 mihad
        end
19236
        #1 disable deadlock ;
19237 69 mihad
        @(negedge scanb_clk) ;
19238
        #1 disable scanb_clk_gen ;
19239 62 mihad
        test_ok ;
19240
    end
19241
    begin:deadlock
19242
        for (deadlock_count = 0; deadlock_count <= 100000; deadlock_count = deadlock_count + 1'b1)
19243
        begin
19244
            @(posedge pci_clock) ;
19245
            @(posedge wb_clock) ;
19246
        end
19247
 
19248
        test_fail("BIST Test didn't finish as expected") ;
19249 69 mihad
        scanb_en <= #1 1'b0 ;
19250 62 mihad
        disable scan ;
19251 69 mihad
        @(negedge scanb_clk) ;
19252 62 mihad
        #1 ;
19253 69 mihad
        disable scanb_clk_gen ;
19254 62 mihad
    end
19255 69 mihad
    begin:scanb_clk_gen
19256 62 mihad
        forever
19257 69 mihad
            #50 scanb_clk = !scanb_clk ;
19258 62 mihad
    end
19259
    join
19260
end
19261
endtask // run_bist_test
19262
`endif
19263
 
19264 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
19265
task target_special_corner_case_test ;
19266
    reg   [11:0]    pci_ctrl_offset ;
19267
    reg   [11:0]    ctrl_offset ;
19268
    reg   [11:0]    ba_offset ;
19269
    reg   [11:0]    am_offset ;
19270
    reg             ok_wb ;
19271
    reg             ok_pci ;
19272
    reg             test_mem ;
19273
    reg             master_check_data_previous ;
19274
begin:main
19275
    master_check_data_previous  = master1_check_received_data ;
19276
    master1_check_received_data = 1'b1 ;
19277
    pci_ctrl_offset = 12'h4 ;
19278
    // use image 1 for this test
19279
    ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
19280
    ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
19281
    am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
19282
 
19283
    // set behavioral slave cycle response
19284
    `ifdef REGISTER_WBM_OUTPUTS
19285
    wishbone_slave.cycle_response
19286
    (
19287
        3'b100,         // {ACK, ERR, RTY}
19288
        0,              // wait cycles
19289
        8'h0            // num of retries before termination
19290
    );
19291
    `else
19292
    wishbone_slave.cycle_response
19293
    (
19294
        3'b100,         // {ACK, ERR, RTY}
19295
        1,              // wait cycles
19296
        8'h0            // num of retries before termination
19297
    );
19298
    `endif
19299
 
19300
    `ifdef HOST
19301
        test_mem = 1 ;
19302
    `else
19303
        test_mem = `PCI_BA1_MEM_IO ;
19304
        test_mem = !test_mem ;
19305
    `endif
19306
 
19307
    test_name = "PCI TARGET UNIT SPECIAL CORNER CASE" ;
19308
 
19309
    // Set Base Address of IMAGE
19310
    config_write( ba_offset, Target_Base_Addr_R[1], 4'hF, ok_wb ) ;
19311
    if ( ok_wb !== 1 )
19312
    begin
19313 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19314 63 mihad
        test_fail("PCI Base Address register 1 could not be written") ;
19315
        #1 ;
19316
        disable main ;
19317
    end
19318
 
19319
    // Set Address Mask of IMAGE
19320
    config_write( am_offset, Target_Addr_Mask_R[1], 4'hF, ok_wb ) ;
19321
    if ( ok_wb !== 1 )
19322
    begin
19323 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_AM1 register! Time %t ", $time);
19324 63 mihad
        test_fail("PCI Address Mask register 1 could not be written") ;
19325
        #1 ;
19326
        disable main ;
19327
    end
19328
 
19329
    // Disable all the features of the PCI Image 1
19330
    config_write( ctrl_offset, 0, 4'hF, ok_wb ) ;
19331
    if ( ok_wb !== 1 )
19332
    begin
19333 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_CTRL1 register! Time %t ", $time);
19334 63 mihad
        test_fail("PCI Image Control register 1 could not be written") ;
19335
        #1 ;
19336
        disable main ;
19337
    end
19338
 
19339
    // set waits to max, which means 0 on PCI
19340
    tb_init_waits   = 4 ;
19341
    tb_subseq_waits = 4 ;
19342
 
19343
    // do one dummy write, to receive a GNT park
19344
    if (test_mem)
19345
    begin
19346
        PCIU_MEM_WRITE
19347
        (
19348
            "MEM_WRITE ",                       // just the name
19349
            `Test_Master_1,                     // Behavioral Master to use for reference
19350
            Target_Base_Addr_R[1],              // Address of this transaction
19351
            32'hAAAA_AAAA,                      // Data For the transaction
19352
            4'h0,                               // Byte enables
19353
            1,                                  // length of transfer
19354
            `Test_One_Zero_Master_WS,           // Master Waits - don't care
19355
            `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19356
            `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19357
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19358
        );
19359
    end
19360
    else
19361
    begin
19362
        PCIU_IO_WRITE
19363
        (
19364
            `Test_Master_1,                     // Behavioral Master to use for reference
19365
            Target_Base_Addr_R[1],              // Address of this transaction
19366
            32'hAAAA_AAAA,                      // Data For the transaction
19367
            4'h0,                               // Byte enables
19368
            1,                                  // Size of transfer
19369
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19370
        ) ;
19371
    end
19372
 
19373
    do_pause( 1 ) ;
19374
    wb_transaction_progress_monitor
19375
    (
19376
        Target_Base_Addr_R[1],          // expected address
19377
        1'b1,                           // expected operation R/W
19378
        1,                              // 1
19379
        1'b1,                           // turn checking of transfers ON/OFF
19380
        ok_wb                           // succeeded/failed
19381
    ) ;
19382
 
19383
    if (ok_wb !== 1'b1)
19384
    begin
19385
        test_fail("WB Transaction Monitor detected invalid transaction on WB bus after posted memory write through target") ;
19386
        #1 ;
19387
        disable main ;
19388
    end
19389
 
19390
    fork
19391
    begin
19392
        if (test_mem)
19393
        begin
19394
            PCIU_MEM_WRITE
19395
            (
19396
                "MEM_WRITE ",                       // just the name
19397
                `Test_Master_1,                     // Behavioral Master to use for reference
19398
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19399
                32'hF0F0_F0F0,                      // Data For the transaction
19400
                4'h0,                               // Byte enables       
19401
                1,                                  // length of transfer
19402
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19403
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19404
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19405
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19406
            );
19407
        end
19408
        else
19409
        begin
19410
            PCIU_IO_WRITE
19411
            (
19412
                `Test_Master_1,                     // Behavioral Master to use for reference
19413
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19414
                32'hF0F0_F0F0,                      // Data For the transaction
19415
                4'h0,                               // Byte enables
19416
                1,                                  // Size of transfer
19417
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19418
            ) ;
19419
        end
19420
 
19421
        do_pause( 1 ) ;
19422
 
19423
        if (test_mem)
19424
        begin
19425
            PCIU_MEM_WRITE
19426
            (
19427
                "MEM_WRITE ",                       // just the name
19428
                `Test_Master_1,                     // Behavioral Master to use for reference
19429
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19430
                32'h0F0F_0F0F,                      // Data For the transaction
19431
                4'h0,                               // Byte enables
19432
                1,                                  // length of transfer
19433
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19434
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19435
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19436
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19437
            );
19438
        end
19439
        else
19440
        begin
19441
            PCIU_IO_WRITE
19442
            (
19443
                `Test_Master_1,                     // Behavioral Master to use for reference
19444
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19445
                32'h0F0F_0F0F,                      // Data For the transaction
19446
                4'h0,                               // Byte enables
19447
                1,                                  // Size of transfer
19448
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19449
            ) ;
19450
        end
19451
 
19452
        do_pause( 1 ) ;
19453
    end
19454
    begin
19455
        wb_transaction_progress_monitor
19456
        (
19457
            Target_Base_Addr_R[1] + 64,     // expected address
19458
            1'b1,                           // expected operation R/W
19459
            1,                              // expected number of transfers
19460
            1'b1,                           // turn checking of transfers ON/OFF
19461
            ok_wb                           // succeeded/failed
19462
        ) ;
19463
 
19464
        if ( ok_wb === 1 )
19465
        begin
19466
 
19467
            wb_transaction_progress_monitor
19468
            (
19469
                Target_Base_Addr_R[1] + 128,    // expected address
19470
                1'b1,                           // expected operation R/W
19471
                1,                              // expected number of transfers
19472
                1'b1,                           // turn checking of transfers ON/OFF
19473
                ok_wb                           // succeeded/failed
19474
            ) ;
19475
        end
19476
 
19477
        @(posedge pci_clock) ;
19478
        #1 ;
19479
        disable pci_error_mon1 ;
19480
    end
19481
    begin:pci_error_mon1
19482
        ok_pci = 1 ;
19483
        @(error_event_int) ;
19484
        ok_pci = 0 ;
19485
    end
19486
    join
19487
 
19488
    if ( ok_wb !== 1'b1 )
19489
    begin
19490
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19491
    end
19492
 
19493
    if ( ok_pci !== 1'b1)
19494
    begin
19495
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19496
    end
19497
 
19498
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19499
    begin
19500
        #1 ;
19501
        disable main ;
19502
    end
19503
 
19504
    if ( test_mem )
19505
    begin
19506
        PCIU_MEM_READ
19507
        (
19508
            "MEM_READ  ",                   // description
19509
            `Test_Master_1,                 // behavioral master selection
19510
            Target_Base_Addr_R[1] + 64,     // address of access
19511
            32'hF0F0_F0F0,                  // expected read data
19512
            1,                              // number of transfers
19513
            8'h7_0,                         // don't care (wait cycles)
19514
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19515
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19516
            `Test_Target_Retry_On           // expected Target termination
19517
        );
19518
    end
19519
    else
19520
    begin
19521
        PCIU_IO_READ
19522
        (
19523
            `Test_Master_1,                 // behavioral master selection
19524
            Target_Base_Addr_R[1] + 64,     // address of access
19525
            32'hF0F0_F0F0,                  // expected read data
19526
            4'h0,                           // byte enables
19527
            1,                              // number of transfers
19528
            `Test_Target_Retry_On           // expected target termination
19529
        ) ;
19530
    end
19531
 
19532 64 mihad
    do_pause(1) ;
19533
 
19534 63 mihad
    wb_transaction_progress_monitor
19535
    (
19536
            Target_Base_Addr_R[1] + 64,     // expected address
19537
            1'b0,                           // expected operation R/W
19538
            1,                              // expected number transfers
19539
            1'b1,                           // turn checking of transfers ON/OFF
19540
            ok_wb                           // succeeded/failed
19541
    ) ;
19542
 
19543
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19544
    repeat(3)
19545
        @(posedge pci_clock) ;
19546
 
19547
    // now read data
19548
    fork
19549
    begin
19550
        if ( test_mem )
19551
        begin
19552
            PCIU_MEM_READ
19553
            (
19554
                "MEM_READ  ",                   // description
19555
                `Test_Master_1,                 // behavioral master selection
19556
                Target_Base_Addr_R[1] + 64,     // address of access
19557
                32'hF0F0_F0F0,                  // expected read data
19558
                1,                              // number of transfers
19559
                8'h7_0,                         // don't care (wait cycles)
19560
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19561
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19562
                `Test_Target_Normal_Completion  // expected Target termination
19563
            );
19564
        end
19565
        else
19566
        begin
19567
            PCIU_IO_READ
19568
            (
19569
                `Test_Master_1,                 // behavioral master selection
19570
                Target_Base_Addr_R[1] + 64,     // address of access
19571
                32'hF0F0_F0F0,                  // expected read data
19572
                4'h0,                           // byte enables
19573
                1,                              // number of transfers
19574
                `Test_Target_Normal_Completion  // expected target termination
19575
            ) ;
19576
        end
19577
 
19578 64 mihad
        do_pause(1) ;
19579 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19580
            @(posedge pci_clock) ;
19581
 
19582
        @(posedge pci_clock) ;
19583
        #1 ;
19584
        disable pci_error_mon2 ;
19585
    end
19586
    begin:pci_error_mon2
19587
        ok_pci = 1 ;
19588
        @(error_event_int) ;
19589
        ok_pci = 0 ;
19590
    end
19591
    join
19592
 
19593
    if ( ok_wb !== 1'b1 )
19594
    begin
19595
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19596
    end
19597
 
19598
    if ( ok_pci !== 1'b1)
19599
    begin
19600
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19601
    end
19602
 
19603
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19604
    begin
19605
        #1 ;
19606
        disable main ;
19607
    end
19608
 
19609
    if ( test_mem )
19610
    begin
19611
        PCIU_MEM_READ
19612
        (
19613
            "MEM_READ  ",                   // description
19614
            `Test_Master_1,                 // behavioral master selection
19615
            Target_Base_Addr_R[1] + 128,    // address of access
19616
            32'h0F0F_0F0F,                  // expected read data
19617
            1,                              // number of transfers
19618
            8'h7_0,                         // don't care (wait cycles)
19619
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19620
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19621
            `Test_Target_Retry_On           // expected Target termination
19622
        );
19623
    end
19624
    else
19625
    begin
19626
        PCIU_IO_READ
19627
        (
19628
            `Test_Master_1,                 // behavioral master selection
19629
            Target_Base_Addr_R[1] + 128,    // address of access
19630
            32'h0F0F_0F0F,                  // expected read data
19631
            4'h0,                           // byte enables
19632
            1,                              // number of transfers
19633
            `Test_Target_Retry_On           // expected target termination
19634
        ) ;
19635
    end
19636
 
19637 64 mihad
    do_pause(1) ;
19638 63 mihad
    wb_transaction_progress_monitor
19639
    (
19640
            Target_Base_Addr_R[1] + 128,    // expected address
19641
            1'b0,                           // expected operation R/W
19642
            1,                              // expected number transfers
19643
            1'b1,                           // turn checking of transfers ON/OFF
19644
            ok_wb                           // succeeded/failed
19645
    ) ;
19646
 
19647
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19648
    repeat(3)
19649
        @(posedge pci_clock) ;
19650
 
19651
    // now read data
19652
    fork
19653
    begin
19654
        if ( test_mem )
19655
        begin
19656
            PCIU_MEM_READ
19657
            (
19658
                "MEM_READ  ",                   // description
19659
                `Test_Master_1,                 // behavioral master selection
19660
                Target_Base_Addr_R[1] + 128,    // address of access
19661
                32'h0F0F_0F0F,                  // expected read data
19662
                1,                              // number of transfers
19663
                8'h7_0,                         // don't care (wait cycles)
19664
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19665
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19666
                `Test_Target_Normal_Completion  // expected Target termination
19667
            );
19668
        end
19669
        else
19670
        begin
19671
            PCIU_IO_READ
19672
            (
19673
                `Test_Master_1,                 // behavioral master selection
19674
                Target_Base_Addr_R[1] + 128,    // address of access
19675
                32'h0F0F_0F0F,                  // expected read data
19676
                4'h0,                           // byte enables
19677
                1,                              // number of transfers
19678
                `Test_Target_Normal_Completion  // expected target termination
19679
            ) ;
19680
        end
19681
 
19682 64 mihad
        do_pause(1) ;
19683 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19684
            @(posedge pci_clock) ;
19685
 
19686
        @(posedge pci_clock) ;
19687
        #1 ;
19688
        disable pci_error_mon3 ;
19689
    end
19690
    begin:pci_error_mon3
19691
        ok_pci = 1 ;
19692
        @(error_event_int) ;
19693
        ok_pci = 0 ;
19694
    end
19695
    join
19696
 
19697
    if ((ok_wb === 1'b1) && (ok_pci === 1'b1))
19698
        test_ok ;
19699
 
19700
    if ( ok_wb !== 1'b1 )
19701
    begin
19702
        test_fail("WB Master started invalid transaction or none at all after Target read was requested") ;
19703
    end
19704
 
19705
    if ( ok_pci !== 1'b1)
19706
    begin
19707
        test_fail("PCI Behavioral Master or Monitor signaled an error during read from PCI Bridge Target") ;
19708
    end
19709
 
19710 69 mihad
    // Disable used image
19711
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
19712
    if ( ok_wb !== 1 )
19713
    begin
19714
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19715
        test_fail("PCI Base Address register 1 could not be written") ;
19716
        #1 ;
19717
        disable main ;
19718
    end
19719
 
19720 63 mihad
    master1_check_received_data = master_check_data_previous ;
19721
end
19722
endtask // target_special_corner_case_test
19723
`endif
19724
 
19725 69 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
19726
task master_special_corner_case_test ;
19727
    reg   [11:0] ctrl_offset ;
19728
    reg   [11:0] ba_offset ;
19729
    reg   [11:0] am_offset ;
19730
    reg `WRITE_STIM_TYPE write_data ;
19731
    reg `READ_STIM_TYPE  read_data ;
19732
    reg `READ_RETURN_TYPE read_status ;
19733
 
19734
    reg `WRITE_RETURN_TYPE write_status ;
19735
    reg `WB_TRANSFER_FLAGS flags ;
19736
    reg ok_pci   ;
19737
    reg ok_wb ;
19738
 
19739
    reg [31:0] target_address ;
19740
 
19741
    reg [11:0] pci_ctrl_offset ;
19742
 
19743
    reg [31:0] image_base ;
19744
begin:main
19745
    test_name = "WISHBONE SLAVE UNIT SPECIAL CORNER CASE" ;
19746
    pci_ctrl_offset = 12'h4 ;
19747
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
19748
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
19749
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
19750
 
19751
    target_address  = `BEH_TAR1_MEM_START ;
19752
    image_base      = 0 ;
19753
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
19754
 
19755
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
19756
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
19757
 
19758
    flags                      = 0 ;
19759
    flags`INIT_WAITS           = 0 ;
19760
    flags`SUBSEQ_WAITS         = 0 ;
19761
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
19762
 
19763
    test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = `Test_Devsel_Fast ;
19764
    test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
19765
    test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
19766
 
19767
    // enable master & target operation
19768
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok_wb) ;
19769
    if ( ok_wb !== 1 )
19770
    begin
19771
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write PCI Device Control register! Time %t ", $time) ;
19772
        test_fail("write to PCI Device Control register didn't succeede");
19773
        disable main ;
19774
    end
19775
 
19776
    // prepare image control register
19777
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok_wb) ;
19778
    if ( ok_wb !== 1 )
19779
    begin
19780
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
19781
        test_fail("write to WB Image Control register didn't succeede");
19782
        disable main ;
19783
    end
19784
 
19785
    // prepare base address register
19786
    config_write( ba_offset, image_base, 4'hF, ok_wb ) ;
19787
    if ( ok_wb !== 1 )
19788
    begin
19789
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
19790
        test_fail("write to WB Base Address register didn't succeede");
19791
        disable main ;
19792
    end
19793
 
19794
    // write address mask register
19795
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok_wb ) ;
19796
    if ( ok_wb !== 1 )
19797
    begin
19798
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_AM1 register! Time %t ", $time) ;
19799
        test_fail("write to WB Address Mask register didn't succeede");
19800
        disable main ;
19801
    end
19802
 
19803
    fork
19804
    begin
19805
 
19806
        // do one dummy read, to receive bus gnt
19807
        read_data`READ_ADDRESS  = target_address ;
19808
        read_data`READ_SEL      = 4'hF ;
19809
        read_data`READ_TAG_STIM = 0 ;
19810
 
19811
        // handle retries
19812
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19813
 
19814
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19815
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19816
        begin
19817
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19818
            test_fail("PCI bridge didn't process the delayed read as expected");
19819
            disable main ;
19820
        end
19821
 
19822
        write_data`WRITE_ADDRESS = target_address + 64;
19823
        write_data`WRITE_DATA    = 32'hABCD_EF12 ;
19824
        write_data`WRITE_SEL     = 4'hF ;
19825
 
19826
        wishbone_master.blk_write_data[0] = write_data ;
19827
 
19828
        write_data`WRITE_ADDRESS = target_address + 128 ;
19829
        write_data`WRITE_DATA    = ~write_data`WRITE_DATA ;
19830
        write_data`WRITE_SEL     = 4'hF ;
19831
 
19832
        wishbone_master.blk_write_data[1] = write_data ;
19833
 
19834
        // no retries should happen
19835
        flags`WB_TRANSFER_AUTO_RTY = 0 ;
19836
 
19837
        flags`WB_TRANSFER_SIZE = 2 ;
19838
 
19839
        wishbone_master.wb_block_write( flags, write_status ) ;
19840
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
19841
        begin
19842
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process block memory write! Time %t ", $time) ;
19843
            test_fail("WB Slave state machine failed to post block memory write");
19844
            disable main ;
19845
        end
19846
 
19847
        // read data back
19848
        read_data`READ_ADDRESS  = target_address + 64 ;
19849
        read_data`READ_SEL      = 4'hF ;
19850
        read_data`READ_TAG_STIM = 0 ;
19851
 
19852
        // handle retries
19853
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19854
 
19855
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19856
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19857
        begin
19858
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19859
            test_fail("PCI bridge didn't process the delayed read as expected");
19860
            disable main ;
19861
        end
19862
 
19863
        if (read_status`READ_DATA !== 32'hABCD_EF12)
19864
        begin
19865
            display_warning(target_address + 64, 32'hABCD_EF12, read_status`READ_DATA) ;
19866
            test_fail("PCI bridge returned unexpected Read Data");
19867
            ok_wb = 0 ;
19868
        end
19869
 
19870
        // read second data back
19871
        read_data`READ_ADDRESS  = target_address + 128 ;
19872
        read_data`READ_SEL      = 4'hF ;
19873
        read_data`READ_TAG_STIM = 0 ;
19874
 
19875
        // handle retries
19876
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19877
 
19878
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19879
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19880
        begin
19881
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19882
            test_fail("PCI bridge didn't process the delayed read as expected");
19883
            disable main ;
19884
        end
19885
 
19886
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
19887
        begin
19888
            display_warning(target_address + 128, write_data`WRITE_DATA, read_status`READ_DATA) ;
19889
            test_fail("PCI bridge returned unexpected Read Data");
19890
            ok_wb = 0 ;
19891
        end
19892
    end
19893
    begin
19894
 
19895
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19896
        if ( ok_pci !== 1 )
19897
        begin
19898
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19899
        end
19900
 
19901
        if(ok_pci)
19902
        begin
19903
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
19904
            if ( ok_pci !== 1 )
19905
            begin
19906
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19907
            end
19908
        end
19909
 
19910
        if (ok_pci)
19911
        begin
19912
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
19913
            if ( ok_pci !== 1 )
19914
            begin
19915
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19916
            end
19917
        end
19918
 
19919
        if (ok_pci)
19920
        begin
19921
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19922
            if ( ok_pci !== 1 )
19923
            begin
19924
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19925
            end
19926
        end
19927
 
19928
        if (ok_pci)
19929
        begin
19930
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19931
            if ( ok_pci !== 1 )
19932
            begin
19933
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19934
            end
19935
        end
19936
    end
19937
    join
19938
 
19939
    if (ok_wb && ok_pci)
19940
        test_ok ;
19941
 
19942
    // disable the image
19943
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
19944
    if ( ok_wb !== 1 )
19945
    begin
19946
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
19947
        test_fail("write to WB Base Address register didn't succeede");
19948
        disable main ;
19949
    end
19950
end
19951
endtask // master_special_corner_case_test
19952
`endif
19953
 
19954 73 mihad
task test_target_overload ;
19955
    reg ok_pci ;
19956
    reg ok_wb  ;
19957
    reg ok ;
19958
    reg [2:0] test_image_num ;
19959
    reg addr_translated ;
19960
    integer transfered ;
19961
    reg [2:0] received_termination ;
19962
    integer total_transfers ;
19963
    reg [31:0] transaction_sizes [0:1024] ;
19964
    integer pci_transaction_num ;
19965
    integer wb_transaction_num ;
19966
    reg [31:0] current_wb_address ;
19967
    reg io_mapped ;
19968
    integer init_waits_backup ;
19969
    integer current_size ;
19970
begin:main
19971
    init_waits_backup = tb_init_waits ;
19972
    tb_init_waits = 0 ;
19973
 
19974
    `ifdef HOST
19975
    io_mapped = 1'b0 ;
19976
    `endif
19977
 
19978
    test_image_num = 'd1 ;
19979
    `ifdef GUEST
19980
    io_mapped = `PCI_BA1_MEM_IO ;
19981
    `endif
19982
 
19983
    `ifdef PCI_IMAGE2
19984
        test_image_num = 'd2 ;
19985
        `ifdef GUEST
19986
            io_mapped = `PCI_BA2_MEM_IO ;
19987
        `endif
19988
    `endif
19989
 
19990
    `ifdef PCI_IMAGE3
19991
        test_image_num = 'd3 ;
19992
        `ifdef GUEST
19993
            io_mapped = `PCI_BA3_MEM_IO ;
19994
        `endif
19995
    `endif
19996
 
19997
    `ifdef PCI_IMAGE4
19998
        test_image_num = 'd4 ;
19999
        `ifdef GUEST
20000
            io_mapped = `PCI_BA4_MEM_IO ;
20001
        `endif
20002
    `endif
20003
 
20004
    `ifdef PCI_IMAGE5
20005
        test_image_num = 'd5 ;
20006
        `ifdef GUEST
20007
            io_mapped = `PCI_BA5_MEM_IO ;
20008
        `endif
20009
    `endif
20010
 
20011
    test_name = "PCI TARGET OVERLOAD" ;
20012
    // configure target image 1 via bus accesses
20013
    pci_configure_pci_target_image
20014
    (
20015
        1'b1,                               // selects whether to configure image with bus accesses or directly with dot notation in the configuration space
20016
        test_image_num,                     // image number
20017
        Target_Base_Addr_R[test_image_num], // base address
20018
        Target_Addr_Mask_R[test_image_num], // address mask
20019
        Target_Tran_Addr_R[test_image_num], // translation address
20020
        1'b0,                               // io/mem mapping select
20021
        1'b0,                               // prefetch enable
20022
        1'b1,                               // address translation enable
20023
        ok                                  // finished succesfully
20024
    );
20025
    if (ok !== 1'b1)
20026
    begin
20027
        test_fail("configuration of PCI Target Image didn't succeede") ;
20028
        tb_init_waits = init_waits_backup ;
20029
        #1 disable main ;
20030
    end
20031
 
20032
    `ifdef ADDR_TRAN_IMPL
20033
        addr_translated = 1'b1 ;
20034
    `else
20035
        addr_translated = 1'b0 ;
20036
    `endif
20037
 
20038
    // set wb slave's response to max wait cycles
20039
    wishbone_slave.cycle_response
20040
    (
20041
        3'b100,          // ACK, ERR, RTY termination
20042
        tb_subseq_waits, // wait cycles before response
20043
 
20044
    ) ;
20045
 
20046
    ok_pci = 1 ;
20047
    ok_wb  = 1 ;
20048
    current_wb_address = pci_to_wb_addr_convert
20049
                               (
20050
                                    Target_Base_Addr_R[test_image_num], // pci address
20051
                                    Target_Tran_Addr_R[test_image_num], // translation address
20052
                                    addr_translated
20053
                               );
20054
    current_wb_address = current_wb_address & Target_Addr_Mask_R[test_image_num] ;
20055
 
20056
    for (current_size = 2 ; (current_size <= 1024) && ok_pci && ok_wb && ok ; current_size = current_size * 2)
20057
    begin
20058
 
20059
        total_transfers = 0 ;
20060
        pci_transaction_num = 0 ;
20061
        wb_transaction_num = 0 ;
20062
 
20063
        current_wb_address = current_wb_address & Target_Addr_Mask_R[test_image_num] ;
20064
        current_wb_address = current_wb_address + (('d1024 - current_size) * 4) ;
20065
        fork
20066
        begin
20067
            while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20068
            begin
20069
                // try transfering 4kB with no wait cycles through the target
20070
                ipci_unsupported_commands_master.normal_write_transfer
20071
                (
20072
                    // always write to the end of the 4kB window
20073
                    (('d1024 - current_size) * 4) + Target_Base_Addr_R[test_image_num] + (4 * total_transfers), // start_address
20074
                    io_mapped ? `BC_IO_WRITE : `BC_MEM_WRITE,                                                   // bus_command
20075
                    (current_size - total_transfers),                                                           // size
20076
                    4 - tb_subseq_waits[2:0],                                                                   // subsequent wait cycles
20077
                    transfered,                                                                                 // actual_transfer
20078
                    received_termination                                                                        // received_termination
20079
                );
20080
                if (transfered > 0)
20081
                begin
20082
                    transaction_sizes[pci_transaction_num] = transfered ;
20083
                    pci_transaction_num = pci_transaction_num + 1'b1 ;
20084
                end
20085
                total_transfers = total_transfers + transfered ;
20086
                if (received_termination > 2) // terminations with numbers 3(Target Abort), 4(Master Abort) and 5(Error) are not allowed
20087
                begin
20088
                    ok_pci = 0 ;
20089
                    if (received_termination == 3)
20090
                        test_fail("PCI Target signalled Target Abort") ;
20091
 
20092
                    if (received_termination == 4)
20093
                        test_fail("PCI Master generated Master Abort") ;
20094
 
20095
                    if (received_termination == 5)
20096
                        test_fail("PCI behavioral master signaled severe error") ;
20097
                end
20098
            end
20099
        end
20100
        begin:wb_monitoring
20101
            while (((total_transfers < current_size) || (pci_transaction_num > wb_transaction_num)) && ok_pci && ok_wb && ok)
20102
            begin
20103
                wait(pci_transaction_num > wb_transaction_num) ;
20104
                wb_transaction_progress_monitor
20105
                (
20106
                    current_wb_address,                     //address
20107
                    1'b1,                                   //write/read
20108
                    transaction_sizes[wb_transaction_num],  //num_of_transfers
20109
                    1'b1,                                   //check_transfers
20110
                    ok_wb                                   // success/fail
20111
                );
20112
                current_wb_address = current_wb_address + (transaction_sizes[wb_transaction_num] * 4) ;
20113
                wb_transaction_num = wb_transaction_num + 1'b1 ;
20114
                if (ok_wb !== 1'b1)
20115
                begin
20116
                    test_fail("WB Transaction progress monitor detected invalid transaction or none at all on WB bus");
20117
                end
20118
            end
20119
 
20120
            wb_transaction_num = wb_transaction_num - 1'b1 ;
20121
            current_wb_address = current_wb_address - (transaction_sizes[wb_transaction_num] * 4) ;
20122
 
20123
            if (ok)
20124
                #1 disable pci_monitoring ;
20125
        end
20126
        begin:pci_monitoring
20127
            @(error_event_int) ;
20128
            test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20129
            ok = 0 ;
20130
            ok_pci = 0 ;
20131
            ok_wb  = 0 ;
20132
        end
20133
        join
20134
    end
20135
 
20136
    if ((ok && ok_wb && ok_pci) === 1'b1)
20137
        test_ok ;
20138
 
20139
    tb_init_waits = init_waits_backup ;
20140
end
20141
endtask // test_target_overload
20142
 
20143
task test_master_overload ;
20144
    reg ok_pci ;
20145
    reg ok_wb  ;
20146
    reg ok ;
20147
    reg [2:0] test_image_num ;
20148
    integer transfered ;
20149
    reg [2:0] received_termination ;
20150
    integer total_transfers ;
20151
    reg [31:0] transaction_sizes [0:1024] ;
20152
    integer pci_transaction_num ;
20153
    integer wb_transaction_num ;
20154
    reg [31:0] current_pci_address ;
20155
    integer init_waits_backup ;
20156
    integer current_size ;
20157
 
20158
    reg `WRITE_STIM_TYPE write_data ;
20159
 
20160
    reg `WRITE_RETURN_TYPE write_status ;
20161
    reg `WB_TRANSFER_FLAGS write_flags ;
20162
 
20163
    reg [31:0] image_base ;
20164
    reg [31:0] target_address ;
20165
 
20166
    integer i ;
20167
begin:main
20168
 
20169
    // set behavioral target to respond normally
20170
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
20171
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
20172
 
20173
    test_image_num = 'd1 ;
20174
 
20175
    `ifdef WB_IMAGE2
20176
        test_image_num = 'd2 ;
20177
    `endif
20178
 
20179
    `ifdef WB_IMAGE3
20180
        test_image_num = 'd3 ;
20181
    `endif
20182
 
20183
    `ifdef WB_IMAGE4
20184
        test_image_num = 'd4 ;
20185
    `endif
20186
 
20187
    `ifdef WB_IMAGE5
20188
        test_image_num = 'd5 ;
20189
    `endif
20190
 
20191
    test_name = "MASTER OVERLOAD" ;
20192
 
20193
    target_address  = `BEH_TAR1_MEM_START ;
20194
    image_base      = 0 ;
20195
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
20196
 
20197
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
20198
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
20199
 
20200
    write_flags                      = 0 ;
20201
    write_flags`INIT_WAITS           = tb_init_waits ;
20202
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
20203
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
20204
    write_flags`WB_TRANSFER_CAB      = 1'b1 ;
20205
 
20206
    pci_configure_wb_slave_image
20207
    (
20208
        1'b1,           // use_bus
20209
        test_image_num, // image_num
20210
        image_base,     // base address
20211
        32'hFFFF_FFFF,  //  address mask
20212
        32'h0000_0000,  // translation address
20213
        1'b0,           // io/mem mapping select
20214
        1'b1,           // prefetch enable
20215
        1'b0,           // address translation enable
20216
        1'b1,           // memory read line enable
20217
        ok              // finished succesfully
20218
    ) ;
20219
 
20220
    if (ok !== 1'b1)
20221
    begin
20222
        test_fail("WB image configuration failed") ;
20223
        disable main ;
20224
    end
20225
 
20226
    // fill wishbone master's memory with data - inverted addresses
20227
    write_data = 0 ;
20228
    for (i = 0 ; i < 1024 ; i = i + 1)
20229
    begin
20230
        write_data`WRITE_ADDRESS = image_base + (4 * i) ;
20231
        write_data`WRITE_DATA    = ~(write_data`WRITE_ADDRESS);
20232
        wishbone_master.blk_write_data[i] = write_data ;
20233
    end
20234
 
20235
    ok_wb  = 1 ;
20236
    ok_pci = 1 ;
20237
 
20238
    total_transfers = 0 ;
20239
 
20240
    for (current_size = 2 ; (current_size <= 1024) && ok_pci && ok_wb && ok ; current_size = current_size * 2)
20241
    begin
20242
 
20243
        total_transfers = 0 ;
20244
        pci_transaction_num = 0 ;
20245
        wb_transaction_num = 0 ;
20246
 
20247
        current_pci_address = image_base ;
20248
        fork
20249
        begin
20250
            while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20251
            begin
20252
                // try transfering 4kB with no wait cycles through the wb slave unit
20253
                write_flags`WB_TRANSFER_SIZE = current_size - total_transfers ;
20254
                wishbone_master.wb_block_write(write_flags, write_status) ;
20255
                if (write_status`CYC_ERR || ((write_status`CYC_ERR !== 1'b1) && (write_status`CYC_RTY !== 1'b1) && (write_status`CYC_ACK !== 1'b1)))
20256
                begin
20257
                    test_fail("Wishbone slave signaled an error or did not respond to normal write access") ;
20258
                    ok_wb = 0 ;
20259
                end
20260
 
20261
                transfered = write_status`CYC_ACTUAL_TRANSFER ;
20262
                if (transfered > 0)
20263
                begin
20264
                    transaction_sizes[wb_transaction_num] = transfered ;
20265
                    wb_transaction_num = wb_transaction_num + 1'b1 ;
20266
                end
20267
                total_transfers = total_transfers + transfered ;
20268
            end
20269
        end
20270
        begin:pci_models_monitoring
20271
            while (((total_transfers < current_size) || (wb_transaction_num > pci_transaction_num)) && ok_pci && ok_wb && ok)
20272
            begin
20273
                wait(wb_transaction_num > pci_transaction_num) ;
20274
                pci_transaction_progress_monitor
20275
                (
20276
                    current_pci_address,                        // address
20277
                    `BC_MEM_WRITE,                              // bus_command
20278
                    transaction_sizes[pci_transaction_num],     // num_of_transfers
20279
                    0,                                          // num_of_cycles
20280
                    1'b1,                                       // check_transfers
20281
                    1'b0,                                       // check_cycles
20282
                    1'b0,                                       // doing_fast_back_to_back
20283
                    ok_pci                                      // ok
20284
                ) ;
20285
 
20286
                pci_transaction_num = pci_transaction_num + 1'b1 ;
20287
                if (ok_pci !== 1'b1)
20288
                begin
20289
                    test_fail("PCI Transaction progress monitor detected invalid transaction or none at all on PCI bus");
20290
                end
20291
            end
20292
 
20293
            if (ok)
20294
                #1 disable pci_monitoring ;
20295
        end
20296
        begin:pci_monitoring
20297
            @(error_event_int) ;
20298
            test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20299
            ok = 0 ;
20300
            ok_pci = 0 ;
20301
            ok_wb  = 0 ;
20302
        end
20303
        join
20304
    end
20305
 
20306
    // disable the image
20307
    pci_configure_wb_slave_image
20308
    (
20309
        1'b1,           // use_bus
20310
        test_image_num, // image_num
20311
        image_base,     // base address
20312
        32'h0000_0000,  //  address mask
20313
        32'h0000_0000,  // translation address
20314
        1'b0,           // io/mem mapping select
20315
        1'b1,           // prefetch enable
20316
        1'b0,           // address translation enable
20317
        1'b1,           // memory read line enable
20318
        ok              // finished succesfully
20319
    ) ;
20320
 
20321
    if (ok !== 1'b1)
20322
    begin
20323
        test_fail("WB image configuration failed") ;
20324
        disable main ;
20325
    end
20326
 
20327
    if ((ok && ok_wb && ok_pci) === 1'b1)
20328
        test_ok ;
20329
end
20330
endtask // test_master_overload
20331
 
20332 15 mihad
task test_fail ;
20333
    input [7999:0] failure_reason ;
20334
    reg   [8007:0] display_failure ;
20335
    reg   [799:0] display_test ;
20336
begin
20337
    tests_failed = tests_failed + 1 ;
20338
 
20339
    display_failure = {failure_reason, "!"} ;
20340
    while ( display_failure[7999:7992] == 0 )
20341
        display_failure = display_failure << 8 ;
20342
 
20343
    display_test = test_name ;
20344
    while ( display_test[799:792] == 0 )
20345
       display_test = display_test << 8 ;
20346
 
20347 63 mihad
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20348 15 mihad
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
20349
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
20350
    $fdisplay( tb_log_file, " *FAILED* because") ;
20351
    $fdisplay( tb_log_file, " %s", display_failure ) ;
20352 63 mihad
    current_test_parameters ;
20353
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20354 15 mihad
    $fdisplay( tb_log_file, " " ) ;
20355
 
20356
    `ifdef STOP_ON_FAILURE
20357
    #20 $stop ;
20358
    `endif
20359
end
20360
endtask // test_fail
20361
 
20362
task test_ok ;
20363
    reg [799:0] display_test ;
20364
begin
20365
   tests_successfull = tests_successfull + 1 ;
20366
 
20367
   display_test = test_name ;
20368
   while ( display_test[799:792] == 0 )
20369
       display_test = display_test << 8 ;
20370
 
20371 63 mihad
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20372 15 mihad
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
20373
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
20374
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
20375 63 mihad
   current_test_parameters ;
20376
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20377 15 mihad
   $fdisplay( tb_log_file, " " ) ;
20378
end
20379
endtask // test_ok
20380
 
20381
task test_summary;
20382
begin
20383 63 mihad
    $fdisplay(tb_log_file, "\n \n");
20384 15 mihad
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
20385
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
20386
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
20387
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
20388
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
20389
    $fclose(tb_log_file) ;
20390
end
20391
endtask
20392
 
20393 63 mihad
task current_test_parameters ;
20394
    reg [87:0] decode_speed_text ;
20395
begin
20396
    case (tb_target_decode_speed)
20397
        3'b000: decode_speed_text = "FAST       " ;
20398
        3'b001: decode_speed_text = "MEDIUM     " ;
20399
        3'b010: decode_speed_text = "SLOW       " ;
20400
        3'b011: decode_speed_text = "SUBTRACTIVE" ;
20401
    endcase
20402
 
20403
    $fdisplay( tb_log_file, "TEST PARAMETERS:") ;
20404
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Initial Wait States         = %d", (3'd4 - tb_init_waits)) ;
20405
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Subsequent Wait States      = %d", (3'd4 - tb_subseq_waits)) ;
20406
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' DEVSEL speed                = %s", decode_speed_text) ;
20407
 
20408
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Initial Wait States    = %d", tb_init_waits) ;
20409
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Subsequent Wait States = %d", tb_subseq_waits) ;
20410
end
20411
endtask
20412
 
20413 73 mihad
`include "pci_bench_common_tasks.v"
20414 15 mihad
endmodule

powered by: WebSVN 2.1.0

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