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

Subversion Repositories pci

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 52 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "system.v"                                        ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Miha Dolenc (mihad@opencores.org)                     ////
10
////      - Tadej Markovic (tadej@opencores.org)                  ////
11
////                                                              ////
12
//////////////////////////////////////////////////////////////////////
13
////                                                              ////
14
//// Copyright (C) 2000 Miha Dolenc, mihad@opencores.org          ////
15
////                                                              ////
16
//// This source file may be used and distributed without         ////
17
//// restriction provided that this copyright statement is not    ////
18
//// removed from the file and that any derivative work contains  ////
19
//// the original copyright notice and the associated disclaimer. ////
20
////                                                              ////
21
//// This source file is free software; you can redistribute it   ////
22
//// and/or modify it under the terms of the GNU Lesser General   ////
23
//// Public License as published by the Free Software Foundation; ////
24
//// either version 2.1 of the License, or (at your option) any   ////
25
//// later version.                                               ////
26
////                                                              ////
27
//// This source is distributed in the hope that it will be       ////
28
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
29
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
30
//// PURPOSE.  See the GNU Lesser General Public License for more ////
31
//// details.                                                     ////
32
////                                                              ////
33
//// You should have received a copy of the GNU Lesser General    ////
34
//// Public License along with this source; if not, download it   ////
35
//// from http://www.opencores.org/lgpl.shtml                     ////
36
////                                                              ////
37
//////////////////////////////////////////////////////////////////////
38
//
39
// CVS Revision History
40
//
41
// $Log: not supported by cvs2svn $
42 69 mihad
// Revision 1.11  2002/10/11 12:03:12  mihad
43
// The testcase I just added in previous revision repaired
44
//
45 64 mihad
// Revision 1.10  2002/10/11 10:08:57  mihad
46
// Added additional testcase and changed rst name in BIST to trst
47
//
48 63 mihad
// Revision 1.9  2002/10/08 17:17:02  mihad
49
// Added BIST signals for RAMs.
50
//
51 62 mihad
// Revision 1.8  2002/09/25 09:54:47  mihad
52
// Added completion expiration test for WB Slave unit. Changed expiration signalling
53
//
54 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
55
// Oops, never before noticed that OC header is missing
56 52 mihad
//
57 57 mihad
//
58 52 mihad
 
59 15 mihad
`include "pci_constants.v"
60
`include "bus_commands.v"
61
`include "pci_testbench_defines.v"
62
`include "timescale.v"
63
 
64 51 mihad
`ifdef HOST
65
    `ifdef NO_CNF_IMAGE
66
    `else
67
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
68
    `endif
69
`else
70
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
71
`endif
72
 
73 15 mihad
module SYSTEM ;
74
 
75
`include "pci_blue_constants.vh"
76
`include "pci_blue_options.vh"
77
 
78
integer tests_successfull ;
79
integer tests_failed ;
80
integer tb_log_file ;
81
reg [799:0] test_name ;
82
 
83
reg pci_clock ;
84
reg wb_clock ;
85
reg reset ;
86
 
87
wire [4:0] arb_grant_out ;
88
 
89
wire [31:0] AD ;
90
wire [3:0]  CBE ;
91
pullup(INTA) ;
92
pullup(MAS0_REQ) ;
93
pullup(MAS1_REQ) ;
94
pullup(MAS2_REQ) ;
95
pullup(MAS3_REQ) ;
96
 
97
wire MAS0_GNT = ~arb_grant_out[0];
98
wire MAS1_GNT = ~arb_grant_out[1] ;
99
wire MAS2_GNT = ~arb_grant_out[2] ;
100
wire MAS3_GNT = ~arb_grant_out[3] ;
101
 
102
pullup(FRAME) ;
103
pullup(IRDY) ;
104 45 mihad
 
105
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
106
 
107 15 mihad
pullup(DEVSEL) ;
108
pullup(TRDY) ;
109
pullup(STOP) ;
110
wire   PAR ;
111
pullup(PERR) ;
112
pullup(SERR) ;
113
wire [3:0] MAS1_IDSEL ;
114
 
115
pullup lockpu ( LOCK ) ;
116
 
117
wire        RST_O ;
118
wire        INT_O ;
119
reg         INT_I ;
120
wire [31:0] ADR_I ;
121
wire [31:0] SDAT_I ;
122
wire [31:0] SDAT_O ;
123
wire [3:0]  SEL_I ;
124
wire        CYC_I ;
125
wire        STB_I ;
126
wire        WE_I ;
127
wire        CAB_I ;
128
wire        ACK_O ;
129
wire        RTY_O ;
130
wire        ERR_O ;
131
 
132
wire [31:0] ADR_O ;
133
wire [31:0] MDAT_I ;
134
wire [31:0] MDAT_O ;
135
wire [3:0]  SEL_O ;
136
wire        CYC_O ;
137
wire        STB_O ;
138
wire        WE_O ;
139
wire        CAB_O ;
140
wire        ACK_I ;
141
wire        RTY_I ;
142
wire        ERR_I ;
143
 
144 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
145
 
146
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
147
 
148 15 mihad
wire        reset_wb ; // reset to Wb devices
149
 
150 62 mihad
`ifdef PCI_BIST
151 69 mihad
wire scanb_so ;
152
reg  scanb_si ;
153
reg  scanb_rst ;
154
reg  scanb_en ;
155
reg  scanb_clk ;
156 62 mihad
`endif
157
 
158 15 mihad
`ifdef GUEST
159
    wire    RST = ~reset ;
160
    assign  reset_wb = RST_O ;
161
`else
162
    pullup(RST) ;
163
    assign  reset_wb = reset ;
164
`endif
165
 
166
`define PCI_BRIDGE_INSTANCE bridge32_top
167
 
168
TOP `PCI_BRIDGE_INSTANCE
169
(
170
    .CLK    ( pci_clock),
171
    .AD     ( AD ),
172
    .CBE    ( CBE ),
173
    .RST    ( RST ),
174
    .INTA   ( INTA ),
175
    .REQ    ( MAS0_REQ ),
176
    .GNT    ( MAS0_GNT ),
177
    .FRAME  ( FRAME ),
178
    .IRDY   ( IRDY ),
179
    .IDSEL  ( TAR0_IDSEL),
180
    .DEVSEL ( DEVSEL ),
181
    .TRDY   ( TRDY ),
182
    .STOP   ( STOP ),
183
    .PAR    ( PAR ),
184
    .PERR   ( PERR ),
185
    .SERR   ( SERR ),
186
 
187
    .CLK_I  ( wb_clock ),
188
    .RST_I  ( reset ),
189
    .RST_O  ( RST_O ),
190
    .INT_I  ( INT_I ),
191
    .INT_O  ( INT_O ),
192
 
193
    // WISHBONE slave interface
194
    .ADR_I  ( ADR_I ),
195
    .SDAT_I ( SDAT_I ),
196
    .SDAT_O ( SDAT_O ),
197
    .SEL_I  ( SEL_I ),
198
    .CYC_I  ( CYC_I ),
199
    .STB_I  ( STB_I ),
200
    .WE_I   ( WE_I ),
201
    .CAB_I  ( CAB_I),
202
    .ACK_O  ( ACK_O ),
203
    .RTY_O  ( RTY_O ),
204
    .ERR_O  ( ERR_O ),
205
 
206
    // WISHBONE master interface
207
    .ADR_O  ( ADR_O ),
208
    .MDAT_I ( MDAT_I ),
209
    .MDAT_O ( MDAT_O ),
210
    .SEL_O  ( SEL_O ),
211
    .CYC_O  ( CYC_O ),
212
    .STB_O  ( STB_O ),
213
    .WE_O   ( WE_O ),
214
    .CAB_O  ( CAB_O ),
215
    .ACK_I  ( ACK_I ),
216
    .RTY_I  ( RTY_I ),
217
    .ERR_I  ( ERR_I )
218 62 mihad
 
219
`ifdef PCI_BIST
220
    ,
221 69 mihad
    // bist chain signals
222
    .scanb_rst  (scanb_rst),
223
    .scanb_clk  (scanb_clk),
224
    .scanb_si   (scanb_si),
225
    .scanb_so   (scanb_so),
226
    .scanb_en   (scanb_en)
227 62 mihad
`endif
228 15 mihad
) ;
229
 
230
WB_MASTER_BEHAVIORAL wishbone_master
231
(
232
    .CLK_I(wb_clock),
233
    .RST_I(reset_wb),
234
    .TAG_I(4'b0000),
235
    .TAG_O(),
236
    .ACK_I(ACK_O),
237
    .ADR_O(ADR_I),
238
    .CYC_O(CYC_I),
239
    .DAT_I(SDAT_O),
240
    .DAT_O(SDAT_I),
241
    .ERR_I(ERR_O),
242
    .RTY_I(RTY_O),
243
    .SEL_O(SEL_I),
244
    .STB_O(STB_I),
245
    .WE_O (WE_I),
246
    .CAB_O(CAB_I)
247
);
248
 
249
WB_SLAVE_BEHAVIORAL wishbone_slave
250
(
251
    .CLK_I              (wb_clock),
252
    .RST_I              (reset_wb),
253
    .ACK_O              (ACK_I),
254
    .ADR_I              (ADR_O),
255
    .CYC_I              (CYC_O),
256
    .DAT_O              (MDAT_I),
257
    .DAT_I              (MDAT_O),
258
    .ERR_O              (ERR_I),
259
    .RTY_O              (RTY_I),
260
    .SEL_I              (SEL_O),
261
    .STB_I              (STB_O),
262
    .WE_I               (WE_O),
263
    .CAB_I              (CAB_O)
264
);
265
 
266
integer wbu_mon_log_file_desc ;
267
integer pciu_mon_log_file_desc ;
268
WB_BUS_MON wbu_wb_mon(
269
                    .CLK_I(wb_clock),
270
                    .RST_I(reset_wb),
271
                    .ACK_I(ACK_O),
272
                    .ADDR_O(ADR_I),
273
                    .CYC_O(CYC_I),
274
                    .DAT_I(SDAT_O),
275
                    .DAT_O(SDAT_I),
276
                    .ERR_I(ERR_O),
277
                    .RTY_I(RTY_O),
278
                    .SEL_O(SEL_I),
279
                    .STB_O(STB_I),
280
                    .WE_O (WE_I),
281
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
282
                    .TAG_O(),
283
                    .CAB_O(CAB_I),
284
                    .log_file_desc ( wbu_mon_log_file_desc )
285
                  ) ;
286
 
287
WB_BUS_MON pciu_wb_mon(
288
                    .CLK_I(wb_clock),
289
                    .RST_I(reset_wb),
290
                    .ACK_I(ACK_I),
291
                    .ADDR_O(ADR_O),
292
                    .CYC_O(CYC_O),
293
                    .DAT_I(MDAT_I),
294
                    .DAT_O(MDAT_O),
295
                    .ERR_I(ERR_I),
296
                    .RTY_I(RTY_I),
297
                    .SEL_O(SEL_O),
298
                    .STB_O(STB_O),
299
                    .WE_O (WE_O),
300
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
301
                    .TAG_O(),
302
                    .CAB_O(CAB_O),
303
                    .log_file_desc( pciu_mon_log_file_desc )
304
                  ) ;
305
 
306
// some aditional signals are needed here because of the arbiter
307
reg [3:0] pci_ext_req_prev ;
308
always@(posedge pci_clock)
309
begin
310
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
311
end
312
reg pci_frame_prev ;
313
always@(posedge pci_clock)
314
begin
315
    pci_frame_prev <= FRAME ;
316
end
317
reg pci_irdy_prev ;
318
always@(posedge pci_clock)
319
begin
320
    pci_irdy_prev <= IRDY ;
321
end
322
 
323
pci_blue_arbiter pci_arbiter
324
(
325
  .pci_int_req_direct(1'b0),
326
  .pci_ext_req_prev(pci_ext_req_prev),
327
  .pci_int_gnt_direct_out(arb_grant_out[4]),
328
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
329
  .pci_frame_prev(~pci_frame_prev),
330
  .pci_irdy_prev(~pci_irdy_prev),
331
  .pci_irdy_now(~IRDY),
332
  .arbitration_enable(1'b1),
333
  .pci_clk(pci_clock),
334
  .pci_reset_comb(~RST)
335
);
336
 
337
reg [31:0] target_message ;
338
 
339
// define output enable signals for monitor inputs
340
// real output enable signals
341
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
342
`ifdef ACTIVE_LOW_OE
343
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
344
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
345
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
346
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
347
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
348
                        !devsel_t_s_oe,
349
                        !ad_oe,
350
                        !cbe_oe,
351
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
352
                        ;
353
`else
354
`ifdef ACTIVE_HIGH_OE
355
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
356
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
357
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
358
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
359
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
360
                        devsel_t_s_oe,
361
                        ad_oe,
362
                        cbe_oe,
363
                        `PCI_BRIDGE_INSTANCE.PERR_en}
364
                        ;
365
`endif
366
`endif
367
/*wire [5:0] oe_sigs_0 = {1'b0,
368
                        1'b0,
369
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
370
                        pci_target32.ad_enable,
371
                        1'b0,
372
                        pci_target32.err_enable | pci_target32.r_err_enable
373
                       } ;
374
*/
375
 
376
wire [5:0] oe_sigs_2 ;
377
wire [5:0] oe_sigs_1 ;
378
 
379
// signals which are used by test modules to know what to do
380
triand  test_accepted_l_int, error_event_int;
381
pullup  (test_accepted_l_int), (error_event_int);
382
 
383
wire    pci_reset_comb  = ~RST;
384
wire    pci_ext_clk     = pci_clock;
385
 
386
integer pci_mon_log_file_desc ;
387
pci_bus_monitor monitor32
388
(
389
    .pci_ext_ad                 (AD),
390
    .pci_ext_cbe_l              (CBE),
391
    .pci_ext_par                (PAR),
392
    .pci_ext_frame_l            (FRAME),
393
    .pci_ext_irdy_l             (IRDY),
394
    .pci_ext_devsel_l           (DEVSEL),
395
    .pci_ext_trdy_l             (TRDY),
396
    .pci_ext_stop_l             (STOP),
397
    .pci_ext_perr_l             (PERR),
398
    .pci_ext_serr_l             (SERR),
399
    .pci_real_req_l             (MAS0_REQ),
400
    .pci_real_gnt_l             (MAS0_GNT),
401
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
402
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
403
    .test_error_event           (error_event_int),
404
    .test_observe_r_oe_sigs     (r_oe_sigs),
405
    .test_observe_0_oe_sigs     (6'h00),
406
    .test_observe_1_oe_sigs     (oe_sigs_1),
407
    .test_observe_2_oe_sigs     (oe_sigs_2),
408
    .test_observe_3_oe_sigs     (6'h00),
409
    .pci_ext_reset_l            (RST),
410
    .pci_ext_clk                (pci_clock),
411
    .log_file_desc              (pci_mon_log_file_desc)
412
) ;
413
 
414
reg [2:0]  test_master_number ;
415
reg [31:0] test_address ;
416
reg [3:0]  test_command ;
417
reg [31:0] test_data ;
418
reg [3:0]  test_byte_enables_l ;
419
reg [9:0]  test_size ;
420
reg        test_make_addr_par_error ;
421
reg        test_make_data_par_error ;
422
reg [3:0]  test_master_initial_wait_states ;
423
reg [3:0]  test_master_subsequent_wait_states ;
424
reg [3:0]  test_target_initial_wait_states ;
425
reg [3:0]  test_target_subsequent_wait_states ;
426
reg [1:0]  test_target_devsel_speed ;
427
reg        test_fast_back_to_back ;
428
reg [2:0]  test_target_termination ;
429
reg        test_expect_master_abort ;
430
reg        test_start ;
431
reg [25:0] test_target_response ;
432
 
433
wire [31:0] master2_received_data ;
434
wire        master2_received_data_valid ;
435
reg         master2_check_received_data ;
436
pci_behaviorial_device pci_behaviorial_device2
437
(
438
    .pci_ext_ad(AD),
439
    .pci_ext_cbe_l(CBE),
440
    .pci_ext_par(PAR),
441
    .pci_ext_frame_l(FRAME),
442
    .pci_ext_irdy_l(IRDY),
443
    .pci_ext_devsel_l(DEVSEL),
444
    .pci_ext_trdy_l(TRDY),
445
    .pci_ext_stop_l(STOP),
446
    .pci_ext_perr_l(PERR),
447
    .pci_ext_serr_l(SERR),
448
    .pci_ext_idsel(TAR2_IDSEL),
449
    .pci_ext_inta_l(INTA),
450
    .pci_ext_req_l(MAS2_REQ),
451
    .pci_ext_gnt_l(MAS2_GNT),
452
    .pci_ext_reset_l(RST),
453
    .pci_ext_clk(pci_clock),
454
 
455
// Signals used by the test bench instead of using "." notation
456
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
457
    .test_master_number                 (test_master_number[2:0]),
458
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
459
    .test_command                       (test_command[3:0]),
460
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
461
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
462
    .test_size                          (test_size),
463
    .test_make_addr_par_error           (test_make_addr_par_error),
464
    .test_make_data_par_error           (test_make_data_par_error),
465
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
466
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
467
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
468
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
469
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
470
    .test_fast_back_to_back             (test_fast_back_to_back),
471
    .test_target_termination            (test_target_termination[2:0]),
472
    .test_expect_master_abort           (test_expect_master_abort),
473
    .test_start                         (test_start),
474
    .test_accepted_l                    (test_accepted_l_int),
475
    .test_error_event                   (error_event_int),
476
    .test_device_id                     (`Test_Master_2),
477
    .test_target_response               (test_target_response),
478
 
479
    .master_received_data               (master2_received_data),
480
    .master_received_data_valid         (master2_received_data_valid),
481
    .master_check_received_data         (master2_check_received_data)
482
);
483
 
484
wire [31:0] master1_received_data ;
485
wire        master1_received_data_valid ;
486
reg         master1_check_received_data ;
487
pci_behaviorial_device pci_behaviorial_device1
488
(
489
    .pci_ext_ad(AD),
490
    .pci_ext_cbe_l(CBE),
491
    .pci_ext_par(PAR),
492
    .pci_ext_frame_l(FRAME),
493
    .pci_ext_irdy_l(IRDY),
494
    .pci_ext_devsel_l(DEVSEL),
495
    .pci_ext_trdy_l(TRDY),
496
    .pci_ext_stop_l(STOP),
497
    .pci_ext_perr_l(PERR),
498
    .pci_ext_serr_l(SERR),
499
    .pci_ext_idsel(TAR1_IDSEL),
500
    .pci_ext_inta_l(INTA),
501
    .pci_ext_req_l(MAS1_REQ),
502
    .pci_ext_gnt_l(MAS1_GNT),
503
    .pci_ext_reset_l(RST),
504
    .pci_ext_clk(pci_clock),
505
 
506
// Signals used by the test bench instead of using "." notation
507
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
508
    .test_master_number                 (test_master_number[2:0]),
509
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
510
    .test_command                       (test_command[3:0]),
511
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
512
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
513
    .test_size                          (test_size),
514
    .test_make_addr_par_error           (test_make_addr_par_error),
515
    .test_make_data_par_error           (test_make_data_par_error),
516
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
517
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
518
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
519
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
520
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
521
    .test_fast_back_to_back             (test_fast_back_to_back),
522
    .test_target_termination            (test_target_termination[2:0]),
523
    .test_expect_master_abort           (test_expect_master_abort),
524
    .test_start                         (test_start),
525
    .test_accepted_l                    (test_accepted_l_int),
526
    .test_error_event                   (error_event_int),
527
    .test_device_id                     (`Test_Master_1),
528
    .test_target_response               (test_target_response),
529
 
530
    .master_received_data               (master1_received_data),
531
    .master_received_data_valid         (master1_received_data_valid),
532
    .master_check_received_data         (master1_check_received_data)
533
);
534
 
535
pci_unsupported_commands_master ipci_unsupported_commands_master
536
(
537
    .CLK    ( pci_clock),
538
    .AD     ( AD ),
539
    .CBE    ( CBE ),
540
    .RST    ( RST ),
541
    .REQ    ( MAS3_REQ ),
542
    .GNT    ( MAS3_GNT ),
543
    .FRAME  ( FRAME ),
544
    .IRDY   ( IRDY ),
545
    .DEVSEL ( DEVSEL ),
546
    .TRDY   ( TRDY ),
547
    .STOP   ( STOP ),
548
    .PAR    ( PAR )
549
) ;
550
 
551 45 mihad
`ifdef HOST
552
 
553
reg     [1:0]   conf_cyc_type1_target_response ;
554
reg     [31:0]  conf_cyc_type1_target_data ;
555
reg     [7:0]   conf_cyc_type1_target_bus_num ;
556
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
557
 
558
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
559
(
560
    .CLK              ( pci_clock),
561
    .AD               ( AD ),
562
    .CBE              ( CBE ),
563
    .RST              ( RST ),
564
    .FRAME            ( FRAME ),
565
    .IRDY             ( IRDY ),
566
    .DEVSEL           ( DEVSEL ),
567
    .TRDY             ( TRDY ),
568
    .STOP             ( STOP ),
569
    .PAR              ( PAR ),
570
 
571
    .response         ( conf_cyc_type1_target_response ),
572
    .data_out         ( conf_cyc_type1_target_data ),
573
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
574
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
575
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
576
    .bus_number       ( conf_cyc_type1_target_bus_num )
577
);
578
`endif
579
 
580 15 mihad
// pci clock generator
581 63 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
582
    always@(posedge wb_clock)
583
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b1 ;
584
 
585
    always@(negedge wb_clock)
586
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b0 ;
587 15 mihad
`else
588 63 mihad
    always
589
    `ifdef PCI33
590
        #15 pci_clock = ~pci_clock ;
591
    `else
592
    `ifdef PCI66
593
        #7.5 pci_clock = ~pci_clock ;
594
    `endif
595
    `endif
596 15 mihad
`endif
597
 
598
// WISHBONE clock generation
599 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
600
always@(posedge pci_clock)
601
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b1 ;
602 15 mihad
 
603 63 mihad
always@(negedge pci_clock)
604
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b0 ;
605
 
606
`else
607
    always
608
        #(((1/`WB_FREQ)/2)) wb_clock = !wb_clock ;
609
`endif
610
 
611 15 mihad
// Make test name visible when the Master starts working on it
612
reg     [79:0] present_test_name;
613
reg     [79:0] next_test_name;
614
wire    test_accepted = ~test_accepted_l_int;
615
always @(posedge test_accepted)
616
begin
617
    present_test_name <= next_test_name;
618
end
619
 
620
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
621
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
622
 
623
// basic configuration parameters for both behavioral devices
624
parameter [2:0] Master_ID_A                           = `Test_Master_1;
625
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
626
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
627
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
628
 
629
parameter [2:0] Master_ID_B                           = `Test_Master_2;
630
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
631
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
632
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
633
 
634
// basic configuration parameters for REAL device
635
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
636
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
637
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
638
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
639
 
640
// reg  [2:0]   ack_err_rty_termination ;
641
// reg          wait_cycles ;
642
// reg  [7:0]   num_of_retries ;
643
 
644
//reg [19:0] pci_config_base ;
645
reg [7:0] system_burst_size ;
646
reg [7:0] bridge_latency ;
647
integer   target_mem_image ;
648
integer   target_io_image ;
649
 
650
initial
651
begin
652 62 mihad
 
653
`ifdef PCI_BIST
654 69 mihad
    scanb_si    = 0 ;
655
    scanb_en    = 0 ;
656
    scanb_clk   = 0 ;
657
    scanb_rst   = 0 ;
658 62 mihad
`endif
659 15 mihad
    next_test_name[79:0] <= "Nowhere___";
660
    reset = 1'b1 ;
661
    pci_clock = 1'b0 ;
662
    wb_clock  = 1'b1 ;
663
    target_message = 32'h0000_0000 ;
664
//  num_of_retries = 8'h01 ;
665
//  ack_err_rty_termination = 3'b100 ;
666
//  wait_cycles = 1'b0 ;
667
 
668
    // system paameters
669
    system_burst_size = 16 ;
670
    bridge_latency    = 8 ;
671
 
672
    // set initial values for controling the behavioral PCI master
673
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
674
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
675
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
676
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
677
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
678
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
679
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
680
 
681
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
682
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
683
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
684
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
685
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
686
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
687
 
688
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
689
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
690
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
691
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
692
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
693
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
694
 
695
    test_master_number = `Test_Master_2 ;
696
    test_address = 32'h0000_0000 ;
697
    test_command = `BC_RESERVED0 ;
698
    test_data = 32'h0000_0000 ;
699
    test_byte_enables_l   = 4'hF ;
700
    test_size = 0 ;
701
    test_make_addr_par_error = 0 ;
702
    test_make_data_par_error = 0;
703
    test_master_initial_wait_states = 0 ;
704
    test_master_subsequent_wait_states = 0 ;
705
    test_target_initial_wait_states = 0 ;
706
    test_target_subsequent_wait_states = 0;
707
    test_target_devsel_speed = `Test_Devsel_Fast ;
708
    test_fast_back_to_back = 0 ;
709
    test_target_termination = `Test_Target_Normal_Completion ;
710
    test_expect_master_abort = 0 ;
711
    test_start = 0 ;
712
    test_target_response = 0 ;
713
 
714
    master1_check_received_data = 0 ;
715
    master2_check_received_data = 0 ;
716
 
717 45 mihad
    `ifdef HOST
718
        conf_cyc_type1_target_response = 0 ;
719
        conf_cyc_type1_target_data = 0 ;
720
        conf_cyc_type1_target_bus_num = 255 ;
721
    `endif
722 15 mihad
 
723
    // fill memory and IO data with random values
724
    fill_memory ;
725
 
726
    INT_I = 0 ;
727
 
728
    // extract from constants which target image can be used as IO and which as memory
729
    `ifdef HOST
730
        target_mem_image = 1 ;
731
        target_io_image  = 1 ;
732
    `else
733
        target_mem_image = -1 ;
734
        target_io_image     = -1 ;
735
        if ( `PCI_BA1_MEM_IO === 0 )
736
            target_mem_image = 1 ;
737
        else
738
            target_io_image = 1 ;
739
 
740
        if ( target_mem_image === -1 )
741
        begin
742
            `ifdef PCI_IMAGE2
743
                if ( `PCI_BA2_MEM_IO === 0 )
744
                    target_mem_image = 2 ;
745
                else if ( target_io_image === -1 )
746
                    target_io_image = 2 ;
747
            `endif
748
        end
749
 
750
        if ( target_mem_image === -1 )
751
        begin
752
            `ifdef PCI_IMAGE3
753
                if ( `PCI_BA3_MEM_IO === 0 )
754
                    target_mem_image = 3 ;
755
                else if ( target_io_image === -1 )
756
                    target_io_image = 3 ;
757
            `endif
758
        end
759
 
760
        if ( target_mem_image === -1 )
761
        begin
762
            `ifdef PCI_IMAGE4
763
                if ( `PCI_BA4_MEM_IO === 0 )
764
                    target_mem_image = 4 ;
765
                else if ( target_io_image === -1 )
766
                    target_io_image = 4 ;
767
            `endif
768
        end
769
 
770
        if ( target_mem_image === -1 )
771
        begin
772
            `ifdef PCI_IMAGE5
773
                if ( `PCI_BA5_MEM_IO === 0 )
774
                    target_mem_image = 5 ;
775
                else if ( target_io_image === -1 )
776
                    target_io_image = 5 ;
777
            `endif
778
        end
779
    `endif
780
 
781
    tests_successfull = 0 ;
782
    tests_failed = 0 ;
783
 
784
    tb_log_file = $fopen("../log/pci_tb.log") ;
785
 
786
    if ( tb_log_file < 2 )
787
    begin
788
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
789
        $finish ;
790
    end
791
 
792
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
793
    $fdisplay( tb_log_file,"" ) ;
794
 
795
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
796
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
797
 
798
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
799
    begin
800
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
801
        $finish ;
802
    end
803
 
804
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
805
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
806
 
807
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
808
    if ( pci_mon_log_file_desc < 2 )
809
    begin
810
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
811
        $finish ;
812
    end
813
 
814
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
815
 
816
    run_tests ;
817
end
818
 
819
task fill_memory ;
820
    integer temp_index ;
821
begin
822
    // fill write memories with random data
823
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
824
    begin
825
        wmem_data[temp_index[9:0]] = $random ;
826 26 mihad
        # 1;
827 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
828 26 mihad
        # 1;
829 15 mihad
    end
830
    // fill WB slave behavioral MEMORY
831
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
832
    begin
833
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
834
        # 1;
835
    end
836
end
837
endtask // fill_memory
838
 
839
reg [2:0] tb_init_waits ;
840
reg [2:0] tb_subseq_waits ;
841
reg [2:0] tb_target_decode_speed ;
842
 
843
task run_tests ;
844
begin
845
    // first - reset logic
846
    do_reset ;
847 62 mihad
 
848
    // if BIST is implemented, give it a go
849
`ifdef PCI_BIST
850
    run_bist_test ;
851
`endif
852 45 mihad
    test_initial_conf_values ;
853
 
854 15 mihad
    next_test_name[79:0] <= "Initing...";
855
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
856
 
857
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
858
    begin
859
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
860
        begin
861
 
862
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
863
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
864
 
865
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
866
            begin
867
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
868
 
869
                `ifdef HOST
870
                    configure_bridge_target ;
871
                    find_pci_devices ;
872 45 mihad
                    test_configuration_cycle_target_abort ;
873
                    test_configuration_cycle_type1_generation ;
874 15 mihad
                `endif
875
 
876
                @(posedge pci_clock) ;
877
                configure_target(1) ;
878
                @(posedge pci_clock) ;
879
                configure_target(2) ;
880
 
881
                `ifdef GUEST
882
                    configure_bridge_target ;
883
                `endif
884
 
885
               next_test_name[79:0] <= "WB_SLAVE..";
886
 
887
                $display("Testing WISHBONE slave images' features!") ;
888
                test_wb_image(1) ;
889
 
890
                `ifdef WB_IMAGE2
891
                    test_wb_image(2) ;
892
                `else
893
                    $display(" WB IMAGE 2 not implemented! ") ;
894
                `endif
895
 
896
                `ifdef WB_IMAGE3
897
                    test_wb_image(3) ;
898
                `else
899
                    $display(" WB IMAGE 3 not implemented! ") ;
900
                `endif
901
 
902
                `ifdef WB_IMAGE4
903
                    test_wb_image(4) ;
904
                `else
905
                    $display(" WB IMAGE 4 not implemented! ") ;
906
                `endif
907
 
908
                `ifdef WB_IMAGE5
909
                    test_wb_image(5) ;
910
                `else
911
                    $display(" WB IMAGE 5 not implemented! ") ;
912
                `endif
913
 
914
                wb_slave_errors ;
915
                wb_to_pci_error_handling ;
916
 
917
                parity_checking ;
918
 
919
                wb_to_pci_transactions ;
920
 
921
                `ifdef HOST
922
                iack_cycle ;
923
                `endif
924
 
925
            end
926 57 mihad
 
927 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
928
        `else
929 57 mihad
            master_completion_expiration ;
930 63 mihad
        `endif
931 57 mihad
 
932 69 mihad
        `ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
933
            master_special_corner_case_test ;
934
        `endif
935
 
936 15 mihad
            $display(" ") ;
937
            $display("WB slave images' tests finished!") ;
938
 
939
            $display("########################################################################") ;
940
            $display("########################################################################") ;
941
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
942
            $display("########################################################################") ;
943
            $display("########################################################################") ;
944
 
945
            $display("Testing PCI target images' features!") ;
946
            configure_bridge_target_base_addresses ;
947
 
948 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
949
                test_conf_cycle_type1_reference ;
950
            `endif
951
 
952 15 mihad
            `ifdef HOST
953
             `ifdef NO_CNF_IMAGE
954
              `ifdef PCI_IMAGE0
955
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
956
            test_pci_image(0) ;
957
              `else
958
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
959
              `endif
960
             `else
961
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
962
             `endif
963
            `endif
964
 
965
            $display("PCI image 1 is ALWAYS implemented!") ;
966
            test_pci_image(1) ;
967
 
968
            `ifdef PCI_IMAGE2
969
            $display("PCI image 2 is implemented!") ;
970
            test_pci_image(2) ;
971
            `else
972
            $display("PCI image 2 is NOT implemented!") ;
973
            `endif
974
 
975
            `ifdef PCI_IMAGE3
976
            $display("PCI image 3 is implemented!") ;
977
            test_pci_image(3) ;
978
            `else
979
            $display("PCI image 3 is NOT implemented!") ;
980
            `endif
981
 
982
            `ifdef PCI_IMAGE4
983
            $display("PCI image 4 is implemented!") ;
984
            test_pci_image(4) ;
985
            `else
986
            $display("PCI image 4 is NOT implemented!") ;
987
            `endif
988
 
989
            `ifdef PCI_IMAGE5
990
            $display("PCI image 5 is implemented!") ;
991
            test_pci_image(5) ;
992
            `else
993
            $display("PCI image 5 is NOT implemented!") ;
994
            `endif
995
 
996
            test_wb_error_rd ;
997
 
998
            target_fast_back_to_back ;
999
            target_disconnects ;
1000
 
1001
            if ( target_io_image !== -1 )
1002
                test_target_abort( target_io_image ) ;
1003
            $display(" ") ;
1004
            $display("PCI target images' tests finished!") ;
1005
 
1006
            transaction_ordering ;
1007 33 mihad
 
1008 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
1009
        `else
1010 33 mihad
            target_completion_expiration ;
1011 63 mihad
        `endif
1012
 
1013 15 mihad
            $display(" ") ;
1014
            $display("PCI transaction ordering tests finished!") ;
1015
        end
1016
    end
1017
 
1018 63 mihad
    `ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
1019
        test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
1020
        test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
1021
        test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
1022
        test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = 0 ;
1023
 
1024
        `ifdef HOST
1025
            configure_bridge_target ;
1026
        `endif
1027
 
1028
        @(posedge pci_clock) ;
1029
        configure_target(1) ;
1030
        @(posedge pci_clock) ;
1031
        configure_target(2) ;
1032
 
1033
        `ifdef GUEST
1034
            configure_bridge_target ;
1035
        `endif
1036
 
1037
        target_special_corner_case_test ;
1038
    `endif
1039
 
1040 15 mihad
    test_summary ;
1041
 
1042
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
1043
    $stop ;
1044
end
1045
endtask // run_tests
1046
 
1047
task do_reset;
1048
begin
1049
    next_test_name[79:0] <= "Reset.....";
1050
 
1051
    reset = 1'b1 ;
1052
    #100 ;
1053
    `ifdef HOST
1054
        @(posedge wb_clock) ;
1055
    `else
1056
    `ifdef GUEST
1057
        @(posedge pci_clock) ;
1058
    `endif
1059
    `endif
1060
 
1061
    reset <= 1'b0 ;
1062
 
1063 45 mihad
    `ifdef HOST
1064
        @(posedge wb_clock) ;
1065
    `else
1066
    `ifdef GUEST
1067
        @(posedge pci_clock) ;
1068
    `endif
1069
    `endif
1070
 
1071 15 mihad
end
1072
endtask
1073
 
1074
/*############################################################################
1075
WB SLAVE UNIT tasks
1076
===================
1077
############################################################################*/
1078
 
1079
task configure_target ;
1080 45 mihad
    input [1:0]  beh_dev_num ;
1081 15 mihad
    reg   [31:0] base_address1 ;
1082
    reg   [31:0] base_address2 ;
1083
    reg   [2:0]  Master_ID;
1084
    reg   [31:0] Target_Config_Addr;
1085 45 mihad
    reg   [4:0]  device_num ;
1086 15 mihad
begin
1087 45 mihad
    if (beh_dev_num === 1)
1088 15 mihad
    begin
1089
        base_address1       = `BEH_TAR1_MEM_START ;
1090
        base_address2       = `BEH_TAR1_IO_START  ;
1091
        Master_ID           = `Test_Master_2 ;
1092
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1093 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1094 15 mihad
    end
1095
    else
1096 45 mihad
    if (beh_dev_num === 2)
1097 15 mihad
    begin
1098
        base_address1       = `BEH_TAR2_MEM_START ;
1099
        base_address2       = `BEH_TAR2_IO_START  ;
1100
        Master_ID           = `Test_Master_1 ;
1101
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1102 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1103 15 mihad
    end
1104
 
1105
    // write target's base addresses
1106
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1107
    // type 0 cycle, byte enables, base address
1108
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1109
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1110
 
1111
    // enable target's response and master
1112
    // enable parity errors, disable system error
1113
 
1114
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1115
 
1116
end
1117
endtask //configure_target
1118
 
1119
task test_wb_image ;
1120
    input [2:0]  image_num ;
1121
    reg   [11:0] ctrl_offset ;
1122
    reg   [11:0] ba_offset ;
1123
    reg   [11:0] am_offset ;
1124
    reg   [11:0] ta_offset ;
1125
    reg   [11:0] err_cs_offset ;
1126
    reg `WRITE_STIM_TYPE write_data ;
1127
    reg `READ_STIM_TYPE  read_data ;
1128
    reg `READ_RETURN_TYPE read_status ;
1129
 
1130
    reg `WRITE_RETURN_TYPE write_status ;
1131
    reg `WB_TRANSFER_FLAGS write_flags ;
1132
    reg [31:0] temp_val ;
1133
    reg        ok   ;
1134
    reg [11:0] pci_ctrl_offset ;
1135
    reg [31:0] image_base ;
1136
    reg [31:0] target_address ;
1137
    reg [31:0] translation_address ;
1138
    integer    i ;
1139
    integer    j ;
1140
begin:main
1141
    pci_ctrl_offset = 12'h4 ;
1142
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1143
    // image 0 can only be configuration image - start with 1
1144
    if (image_num === 1)
1145
    begin
1146
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1147
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1148
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1149
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1150
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1151
    end
1152
    else if (image_num === 2)
1153
    begin
1154
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1155
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1156
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1157
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1158
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1159
    end
1160
    else if (image_num === 3)
1161
    begin
1162
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1163
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1164
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1165
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1166
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1167
    end
1168
    else if (image_num === 4)
1169
    begin
1170
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1171
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1172
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1173
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1174
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1175
    end
1176
    else if (image_num === 5)
1177
    begin
1178
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1179
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1180
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1181
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1182
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1183
    end
1184
    else
1185
    begin
1186
        test_name   = "WB IMAGES' FEATURES TEST" ;
1187
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1188
        disable main ;
1189
    end
1190
 
1191
    target_address  = `BEH_TAR1_MEM_START ;
1192
    image_base      = 0 ;
1193
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1194
 
1195
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1196
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1197
    write_flags                      = 0 ;
1198
    write_flags`INIT_WAITS           = tb_init_waits ;
1199
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1200
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1201
 
1202
    test_name = "WB IMAGE CONFIGURATION" ;
1203
    // enable master & target operation
1204
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1205
    if ( ok !== 1 )
1206
    begin
1207 69 mihad
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1208 15 mihad
        test_fail("write to PCI Device Control register didn't succeede");
1209
        disable main ;
1210
    end
1211
 
1212
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1213
    if ( ok !== 1 )
1214
    begin
1215 69 mihad
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", $time) ;
1216 15 mihad
        test_fail("write to WB Error Control and Status register didn't succeede");
1217
        disable main ;
1218
    end
1219
 
1220
    // prepare image control register
1221
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1222
    if ( ok !== 1 )
1223
    begin
1224
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1225
        test_fail("write to WB Image Control register didn't succeede");
1226
        disable main ;
1227
    end
1228
 
1229
    // prepare base address register
1230
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1231
    if ( ok !== 1 )
1232
    begin
1233
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1234
        test_fail("write to WB Base Address register didn't succeede");
1235
        disable main ;
1236
    end
1237
 
1238
    // write address mask register
1239
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1240
    if ( ok !== 1 )
1241
    begin
1242
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1243
        test_fail("write to WB Address Mask register didn't succeede");
1244
        disable main ;
1245
    end
1246
 
1247
    fork
1248
    begin
1249
        write_data`WRITE_ADDRESS = target_address ;
1250
        write_data`WRITE_DATA    = wmem_data[0] ;
1251
        write_data`WRITE_SEL     = 4'hF ;
1252
 
1253
        // handle retries from now on
1254
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1255
 
1256
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1257
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1258
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1259
        begin
1260
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1261
            test_fail("WB Slave state machine failed to post single memory write");
1262
            disable main ;
1263
        end
1264
 
1265
        // read written data back
1266
        read_data`READ_ADDRESS  = target_address ;
1267
        read_data`READ_SEL      = 4'hF ;
1268
        read_data`READ_TAG_STIM = 0 ;
1269
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1270
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1271
        begin
1272
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1273
            test_fail("PCI bridge didn't process the read as expected");
1274
            disable main ;
1275
        end
1276
 
1277
        if (read_status`READ_DATA !== wmem_data[0])
1278
        begin
1279
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1280
            test_fail("PCI bridge returned unexpected Read Data");
1281
        end
1282
        else
1283
            test_ok ;
1284
    end
1285
    begin
1286
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1287
        if ( ok !== 1 )
1288
        begin
1289
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1290
        end
1291
        else
1292
            test_ok ;
1293
 
1294
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1295
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1296
        if ( ok !== 1 )
1297
        begin
1298
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1299
        end
1300
    end
1301
    join
1302
 
1303
    // if address translation is implemented - try it out
1304
    translation_address = image_base ;
1305
    `ifdef ADDR_TRAN_IMPL
1306
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1307
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1308
    if ( ok !== 1 )
1309
    begin
1310
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1311
        test_fail("write to WB Image Translation Address Register failed") ;
1312
        disable main ;
1313
    end
1314
 
1315
    target_address  = `BEH_TAR2_MEM_START ;
1316
    image_base      = 0 ;
1317
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1318
 
1319
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1320
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1321
 
1322
    write_flags                      = 0 ;
1323
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1324
 
1325
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1326
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1327
    if ( ok !== 1 )
1328
    begin
1329
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1330
        test_fail("write to WB Image Base Address Register failed") ;
1331
        disable main ;
1332
    end
1333
 
1334
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1335
    // enable address translation
1336
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1337
    if ( ok !== 1 )
1338
    begin
1339
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1340
        test_fail("write to WB Image Control Register failed") ;
1341
        disable main ;
1342
    end
1343
 
1344
    `endif
1345
 
1346
    fork
1347
    begin
1348
        write_data`WRITE_ADDRESS = target_address + 4 ;
1349
        write_data`WRITE_DATA    = wmem_data[1] ;
1350
        write_data`WRITE_SEL     = 4'hF ;
1351
 
1352
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1353
 
1354
        `ifdef ADDR_TRAN_IMPL
1355
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1356
        `else
1357
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1358
        `endif
1359
 
1360
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1361
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1362
        begin
1363
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1364
            test_fail("WB Slave state machine failed to post single memory write") ;
1365
            disable main ;
1366
        end
1367
 
1368
        // read written data back
1369
        read_data`READ_ADDRESS  = target_address + 4 ;
1370
        read_data`READ_SEL      = 4'hF ;
1371
        read_data`READ_TAG_STIM = 0 ;
1372
 
1373
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1374
 
1375
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1376
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1377
        begin
1378
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1379
            test_fail("PCI bridge failed to process single delayed memory read") ;
1380
            disable main ;
1381
        end
1382
 
1383
        if (read_status`READ_DATA !== wmem_data[1])
1384
        begin
1385
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1386
            test_fail("PCI bridge returned unexpected Read Data");
1387
        end
1388
        else
1389
            test_ok ;
1390
    end
1391
    begin
1392
        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 ) ;
1393
        if ( ok !== 1 )
1394
        begin
1395
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1396
        end
1397
        else
1398
            test_ok ;
1399
 
1400
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1401
        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 ) ;
1402
        if ( ok !== 1 )
1403
        begin
1404
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1405
        end
1406
    end
1407
    join
1408
 
1409
    // 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
1410
    // prepare write data
1411
    for ( i = 0 ; i < 6 ; i = i + 1 )
1412
    begin
1413
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1414
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1415
        write_data`WRITE_SEL     = 4'hF ;
1416
        wishbone_master.blk_write_data[i] = write_data ;
1417
    end
1418
 
1419
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1420
    write_flags`WB_TRANSFER_CAB    = 1 ;
1421
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1422
 
1423
    fork
1424
    begin
1425
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1426
        wishbone_master.wb_block_write(write_flags, write_status) ;
1427
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1428
        begin
1429
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1430
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1431
            disable main ;
1432
        end
1433
    end
1434
    begin
1435
        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 ) ;
1436
        if ( ok !== 1 )
1437
        begin
1438
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1439
        end
1440
        else
1441
            test_ok ;
1442
    end
1443
    join
1444
 
1445
    // set burst size and latency timer
1446
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1447
 
1448
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1449
    write_flags`WB_TRANSFER_CAB    = 1 ;
1450
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1451
 
1452
    // prepare read data
1453
    for ( i = 0 ; i < 4 ; i = i + 1 )
1454
    begin
1455
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1456
        read_data`READ_SEL     = 4'hF ;
1457
        wishbone_master.blk_read_data_in[i] = read_data ;
1458
    end
1459
 
1460
    fork
1461
    begin
1462
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1463
        wishbone_master.wb_block_read(write_flags, read_status) ;
1464
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1465
        begin
1466
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1467
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1468
            disable main ;
1469
        end
1470
 
1471
        // check data read from target
1472
        for ( i = 0 ; i < 4 ; i = i + 1 )
1473
        begin
1474
            read_status = wishbone_master.blk_read_data_out[i] ;
1475
            if (read_status`READ_DATA !== wmem_data[2 + i])
1476
            begin
1477
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1478
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1479
            end
1480
        end
1481
    end
1482
    begin
1483
        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 ) ;
1484
        if ( ok !== 1 )
1485
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1486
        else
1487
            test_ok ;
1488
 
1489
        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 ) ;
1490
        if ( ok !== 1 )
1491
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1492
        else
1493
            test_ok ;
1494
 
1495
        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 ) ;
1496
        if ( ok !== 1 )
1497
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1498
        else
1499
            test_ok ;
1500
 
1501
        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 ) ;
1502
        if ( ok !== 1 )
1503
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1504
        else
1505
            test_ok ;
1506
 
1507
    end
1508
    join
1509
 
1510
    // now repeat this same burst read with various image features enabled or disabled
1511
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1512
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1513
    if (ok !== 1)
1514
    begin
1515
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1516
        test_fail("write to WB Image control register failed") ;
1517
        disable main ;
1518
    end
1519
 
1520
    fork
1521
    begin
1522
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1523
        wishbone_master.wb_block_read(write_flags, read_status) ;
1524
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1525
        begin
1526
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1527
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1528
            disable main ;
1529
        end
1530
 
1531
        // check data read from target
1532
        for ( i = 0 ; i < 4 ; i = i + 1 )
1533
        begin
1534
            read_status = wishbone_master.blk_read_data_out[i] ;
1535
            if (read_status`READ_DATA !== wmem_data[2 + i])
1536
            begin
1537
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1538
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1539
            end
1540
            else
1541
                test_ok ;
1542
        end
1543
    end
1544
    begin
1545
        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 ) ;
1546
        if ( ok !== 1 )
1547
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1548
    end
1549
    join
1550
 
1551
    read_data`READ_ADDRESS  = target_address ;
1552
    read_data`READ_SEL      = 4'hF ;
1553
    read_data`READ_TAG_STIM = 0 ;
1554
 
1555
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1556
    fork
1557
    begin
1558
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1559
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1560
        begin
1561
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1562
            test_fail("delayed single memory read wasn't processed as expected") ;
1563
            disable main ;
1564
        end
1565
 
1566
        if (read_status`READ_DATA !== wmem_data[0])
1567
        begin
1568
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1569
            test_fail("delayed single memory read data value returned was not as expected") ;
1570
        end
1571
        else
1572
            test_ok ;
1573
    end
1574
    begin
1575
        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 ) ;
1576
        if ( ok !== 1 )
1577
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1578
    end
1579
    join
1580
 
1581
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1582
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1583
    if (ok !== 1)
1584
    begin
1585
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1586
        test_fail("write to WB Image control register failed") ;
1587
        disable main ;
1588
    end
1589
 
1590
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1591
    fork
1592
    begin
1593
        wishbone_master.wb_block_read(write_flags, read_status) ;
1594
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1595
        begin
1596
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1597
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1598
            disable main ;
1599
        end
1600
 
1601
        // check data read from target
1602
        for ( i = 0 ; i < 4 ; i = i + 1 )
1603
        begin
1604
            read_status = wishbone_master.blk_read_data_out[i] ;
1605
            if (read_status`READ_DATA !== wmem_data[2 + i])
1606
            begin
1607
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1608
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1609
            end
1610
            else
1611
                test_ok ;
1612
        end
1613
    end
1614
    begin
1615
        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 ) ;
1616
        if ( ok !== 1 )
1617
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1618
    end
1619
    join
1620
 
1621
    read_data`READ_ADDRESS  = target_address + 4 ;
1622
    read_data`READ_SEL      = 4'hF ;
1623
    read_data`READ_TAG_STIM = 0 ;
1624
 
1625
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1626
    fork
1627
    begin
1628
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1629
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1630
        begin
1631
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1632
            test_fail("delayed single memory read wasn't processed as expected") ;
1633
            disable main ;
1634
        end
1635
 
1636
        if (read_status`READ_DATA !== wmem_data[1])
1637
        begin
1638
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1639
            test_fail("delayed single memory read data value returned was not as expected") ;
1640
        end
1641
        else
1642
            test_ok ;
1643
    end
1644
    begin
1645
        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 ) ;
1646
        if ( ok !== 1 )
1647
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1648
    end
1649
    join
1650
 
1651
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1652
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1653
    if (ok !== 1)
1654
    begin
1655
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1656
        test_fail("write to WB Image control register failed") ;
1657
        disable main ;
1658
    end
1659
 
1660
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1661
    fork
1662
    begin
1663
        wishbone_master.wb_block_read(write_flags, read_status) ;
1664
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1665
        begin
1666
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1667
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1668
            disable main ;
1669
        end
1670
 
1671
        // check data read from target
1672
        for ( i = 0 ; i < 4 ; i = i + 1 )
1673
        begin
1674
            read_status = wishbone_master.blk_read_data_out[i] ;
1675
            if (read_status`READ_DATA !== wmem_data[2 + i])
1676
            begin
1677
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1678
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1679
            end
1680
            else
1681
                test_ok ;
1682
        end
1683
    end
1684
    begin
1685
        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 ) ;
1686
        if ( ok !== 1 )
1687
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1688
    end
1689
    join
1690
 
1691
    read_data`READ_ADDRESS  = target_address + 8 ;
1692
    read_data`READ_SEL      = 4'hF ;
1693
    read_data`READ_TAG_STIM = 0 ;
1694
 
1695
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1696
    fork
1697
    begin
1698
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1699
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1700
        begin
1701
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1702
            test_fail("delayed single memory read wasn't processed as expected") ;
1703
            disable main ;
1704
        end
1705
 
1706
        if (read_status`READ_DATA !== wmem_data[2])
1707
        begin
1708
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1709
            test_fail("delayed single memory read data value returned was not as expected") ;
1710
        end
1711
        else
1712
            test_ok ;
1713
    end
1714
    begin
1715
        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 ) ;
1716
        if ( ok !== 1 )
1717
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1718
    end
1719
    join
1720
 
1721
    // map image to IO space
1722
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1723
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1724
    if ( ok !== 1 )
1725
    begin
1726
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1727
        test_fail("write to WB Image Base Address register failed") ;
1728
        disable main ;
1729
    end
1730
 
1731
    write_data`WRITE_ADDRESS = target_address ;
1732
    write_data`WRITE_DATA    = wmem_data[11] ;
1733
    write_data`WRITE_SEL     = 4'hF ;
1734
 
1735
    // handle retries from now on
1736
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1737
 
1738
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1739
    fork
1740
    begin
1741
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1742
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1743
        begin
1744
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1745
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1746
            disable main ;
1747
        end
1748
    end
1749
    begin
1750
        // currently IO commands not supported in behavioral models - master abort
1751
        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 ) ;
1752
        if ( ok !== 1 )
1753
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1754
        else
1755
            test_ok ;
1756
    end
1757
    join
1758
 
1759
    read_data`READ_ADDRESS  = target_address ;
1760
    read_data`READ_SEL      = 4'hF ;
1761
    read_data`READ_TAG_STIM = 0 ;
1762
 
1763
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1764
 
1765
    // currently io commands are not supported by behavioral target - transfer should not be completed
1766
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1767
    fork
1768
    begin
1769
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1770
        if (read_status`CYC_ERR !== 1)
1771
        begin
1772
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1773
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1774
            disable main ;
1775
        end
1776
        else
1777
            test_ok ;
1778
    end
1779
    begin
1780
        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 ) ;
1781
        if ( ok !== 1 )
1782
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1783
    end
1784
    join
1785
 
1786
    // test byte addressing
1787
    read_data`READ_ADDRESS = target_address + 2 ;
1788
    read_data`READ_SEL     = 4'b1100 ;
1789
 
1790
    fork
1791
    begin
1792
        // currently io commands are not supported by behavioral target - transfer should not be completed
1793
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1794
        if (read_status`CYC_ERR !== 1)
1795
        begin
1796
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1797
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1798
            disable main ;
1799
        end
1800
        else test_ok ;
1801
    end
1802
    begin
1803
        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 ) ;
1804
        if ( ok !== 1 )
1805
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1806
    end
1807
    join
1808
 
1809
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1810
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1811
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1812
    if ( ok !== 1 )
1813
    begin
1814
        test_fail("WB Base address register could not be written") ;
1815
        disable main ;
1816
    end
1817
 
1818
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1819
    if ( ok !== 1 )
1820
    begin
1821
        test_fail("WB Address Mask register could not be written") ;
1822
        disable main ;
1823
    end
1824
 
1825
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1826
    if ( ok !== 1 )
1827
    begin
1828
        test_fail("WB Image Control register could not be written") ;
1829
        disable main ;
1830
    end
1831
 
1832
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1833
    write_data`WRITE_DATA    = wmem_data[11] ;
1834
    write_data`WRITE_SEL     = 4'b1000 ;
1835
 
1836
    // handle retries from now on
1837
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1838
 
1839
    fork
1840
    begin
1841
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1842
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1843
        begin
1844
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1845
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1846
            disable main ;
1847
        end
1848
    end
1849
    begin
1850
        // currently IO commands not supported in behavioral models - master abort
1851
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1852
        if ( ok !== 1 )
1853
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1854
        else
1855
            test_ok ;
1856
    end
1857
    join
1858
 
1859
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1860
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1861
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1862
 
1863
    fork
1864
    begin
1865
        // currently io commands are not supported by behavioral target - transfer should not be completed
1866
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1867
        if (read_status`CYC_ERR !== 1)
1868
        begin
1869
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1870
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1871
            disable main ;
1872
        end
1873
        else test_ok ;
1874
    end
1875
    begin
1876
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1877
        if ( ok !== 1 )
1878
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1879
    end
1880
    join
1881
 
1882
    test_name = "DISABLING WB IMAGE" ;
1883
 
1884
    // disable current image
1885
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1886
    if ( ok !== 1 )
1887
    begin
1888
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1889
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1890
        disable main ;
1891
    end
1892
 
1893
    // clear master abort status bit
1894
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1895
    if ( ok !== 1 )
1896
    begin
1897
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1898
        test_fail("write to PCI Device Status register not accepted as expected") ;
1899
        disable main ;
1900
    end
1901
 
1902
end //main
1903
endtask //test_wb_image
1904
 
1905
task wb_slave_errors ;
1906
    reg   [11:0] ctrl_offset ;
1907
    reg   [11:0] ba_offset ;
1908
    reg   [11:0] am_offset ;
1909
    reg   [11:0] ta_offset ;
1910
    reg `WRITE_STIM_TYPE write_data ;
1911
    reg `READ_STIM_TYPE  read_data ;
1912
    reg `READ_RETURN_TYPE read_status ;
1913
 
1914
    reg `WRITE_RETURN_TYPE write_status ;
1915
    reg `WB_TRANSFER_FLAGS write_flags ;
1916
    reg [31:0] temp_val1 ;
1917
    reg [31:0] temp_val2 ;
1918
    reg        ok   ;
1919
    reg [11:0] pci_ctrl_offset ;
1920
    reg [31:0] image_base ;
1921
    reg [31:0] target_address ;
1922
    integer    i ;
1923
    reg skip ;
1924
fork
1925
begin:main
1926
 
1927
    `ifdef GUEST
1928
        skip = 1 ;
1929
    `else
1930
        skip = 0 ;
1931
    `endif
1932
 
1933
    pci_ctrl_offset = 12'h4 ;
1934
 
1935
    // image 1 is used for error testing, since it is always implemented
1936
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1937
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1938
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1939
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1940
 
1941
    target_address  = `BEH_TAR1_MEM_START ;
1942
    image_base      = 0 ;
1943
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1944
 
1945
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1946
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1947
    write_flags                    = 0 ;
1948
    write_flags`INIT_WAITS         = tb_init_waits ;
1949
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1950
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1951
 
1952
    // enable master & target operation
1953
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1954
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1955
    if ( ok !== 1 )
1956
    begin
1957
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1958
        test_fail("PCI Device Control register couldn't be written") ;
1959
        disable no_transaction ;
1960
        disable main ;
1961
    end
1962
 
1963
    // prepare image control register
1964
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1965
    if ( ok !== 1 )
1966
    begin
1967
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1968
        test_fail("WB Image Control register couldn't be written") ;
1969
        disable no_transaction ;
1970
        disable main ;
1971
    end
1972
 
1973
    // prepare base address register
1974
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1975
    if ( ok !== 1 )
1976
    begin
1977
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1978
        test_fail("WB Base Address register couldn't be written") ;
1979
        disable no_transaction ;
1980
        disable main ;
1981
    end
1982
 
1983
    // write address mask register
1984
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1985
    if ( ok !== 1 )
1986
    begin
1987
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1988
        test_fail("WB Address Mask register couldn't be written") ;
1989
        disable no_transaction ;
1990
        disable main ;
1991
    end
1992
 
1993
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1994
 
1995
    skip = 0 ;
1996
 
1997
    // memory mapped image - access is erroneous when address is not alligned
1998
    write_data`WRITE_ADDRESS = target_address + 1 ;
1999
    write_data`WRITE_DATA    = wmem_data[0] ;
2000
    write_data`WRITE_SEL     = 4'hF ;
2001
 
2002
    // handle retries from now on
2003
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2004
 
2005
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
2006
 
2007
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2008
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2009
    begin
2010
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2011
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2012
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2013
        disable no_transaction ;
2014
        disable main ;
2015
    end
2016
 
2017
    write_data`WRITE_ADDRESS = target_address + 2 ;
2018
 
2019
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2020
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2021
    begin
2022
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2023
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2024
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2025
        disable no_transaction ;
2026
        disable main ;
2027
 
2028
    end
2029
 
2030
    write_data`WRITE_ADDRESS = target_address + 3 ;
2031
 
2032
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2033
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2034
    begin
2035
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2036
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2037
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2038
        disable no_transaction ;
2039
        disable main ;
2040
    end
2041
 
2042
    test_ok ;
2043
 
2044
    // perform same tests for read accesses
2045
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
2046
 
2047
    read_data`READ_ADDRESS  = target_address + 2 ;
2048
    read_data`READ_SEL      = 4'hF ;
2049
    read_data`READ_TAG_STIM = 0 ;
2050
 
2051
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2052
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2053
    begin
2054
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2055
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2056
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
2057
        disable no_transaction ;
2058
        disable main ;
2059
    end
2060
 
2061
    test_ok ;
2062
 
2063
    // prepare write data
2064
    for ( i = 0 ; i < 6 ; i = i + 1 )
2065
    begin
2066
        write_data`WRITE_DATA    = wmem_data[i] ;
2067
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
2068
        write_data`WRITE_SEL     = 4'hF ;
2069
        wishbone_master.blk_write_data[i] = write_data ;
2070
    end
2071
 
2072
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2073
    write_flags`WB_TRANSFER_CAB    = 1 ;
2074
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2075
 
2076
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
2077
    wishbone_master.wb_block_write(write_flags, write_status) ;
2078
 
2079
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2080
    begin
2081
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2082
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2083
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
2084
        disable no_transaction ;
2085
        disable main ;
2086
    end
2087
 
2088
    // prepare read data
2089
    for ( i = 0 ; i < 6 ; i = i + 1 )
2090
    begin
2091
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2092
        read_data`READ_SEL     = 4'hF ;
2093
        wishbone_master.blk_read_data_in[i] = read_data ;
2094
    end
2095
 
2096
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2097
    wishbone_master.wb_block_read(write_flags, read_status) ;
2098
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2099
    begin
2100
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2101
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2102
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2103
        disable no_transaction ;
2104
        disable main ;
2105
    end
2106
 
2107
    test_ok ;
2108
 
2109
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2110
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2111
 
2112
    // map image to IO space
2113
    `ifdef GUEST
2114
        skip = 1 ;
2115
    `endif
2116
 
2117
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2118
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2119
    if ( ok !== 1 )
2120
    begin
2121
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2122
        test_fail("WB Image Base Address register couldn't be written") ;
2123
        disable no_transaction ;
2124
        disable main ;
2125
    end
2126
 
2127
    skip = 0 ;
2128
 
2129
    write_data`WRITE_ADDRESS = target_address ;
2130
    write_data`WRITE_DATA    = wmem_data[0] ;
2131
    write_data`WRITE_SEL     = 4'b1010 ;
2132
 
2133
    // don't handle retries
2134
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2135
 
2136
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2137
 
2138
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2139
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2140
    begin
2141
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2142
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2143
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2144
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2145
        disable no_transaction ;
2146
        disable main ;
2147
    end
2148
 
2149
    write_data`WRITE_ADDRESS = target_address + 1 ;
2150
    write_data`WRITE_SEL     = 4'b0011 ;
2151
 
2152
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2153
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2154
    begin
2155
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2156
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2157
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2158
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2159
        disable no_transaction ;
2160
        disable main ;
2161
    end
2162
 
2163
    write_data`WRITE_SEL     = 4'b1100 ;
2164
 
2165
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2166
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2167
    begin
2168
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2169
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2170
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2171
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2172
        disable no_transaction ;
2173
        disable main ;
2174
    end
2175
 
2176
    write_data`WRITE_ADDRESS = target_address + 2 ;
2177
    write_data`WRITE_SEL     = 4'b0101 ;
2178
 
2179
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2180
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2181
    begin
2182
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2183
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2184
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2185
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2186
        disable no_transaction ;
2187
        disable main ;
2188
    end
2189
 
2190
    write_data`WRITE_SEL     = 4'b1000 ;
2191
 
2192
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2193
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2194
    begin
2195
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2196
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2197
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2198
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2199
        disable no_transaction ;
2200
        disable main ;
2201
    end
2202
 
2203
    write_data`WRITE_ADDRESS = target_address + 3 ;
2204
    write_data`WRITE_SEL     = 4'b1010 ;
2205
 
2206
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2207
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2208
    begin
2209
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2210
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2211
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2212
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2213
        disable no_transaction ;
2214
        disable main ;
2215
    end
2216
 
2217
    write_data`WRITE_SEL     = 4'b0110 ;
2218
 
2219
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2220
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2221
    begin
2222
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2223
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2224
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2225
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2226
        disable no_transaction ;
2227
        disable main ;
2228
    end
2229
 
2230
    test_ok ;
2231
 
2232
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2233
 
2234
    read_data`READ_ADDRESS  = target_address + 3 ;
2235
    read_data`READ_SEL      = 4'hF ;
2236
    read_data`READ_TAG_STIM = 0 ;
2237
 
2238
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2239
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2240
    begin
2241
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2242
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2243
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2244
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2245
        disable no_transaction ;
2246
        disable main ;
2247
    end
2248
 
2249
    test_ok ;
2250
 
2251
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2252
    // prepare write data
2253
    for ( i = 0 ; i < 6 ; i = i + 1 )
2254
    begin
2255
        write_data`WRITE_DATA    = wmem_data[i] ;
2256
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2257
        write_data`WRITE_SEL     = 4'hF ;
2258
        wishbone_master.blk_write_data[i] = write_data ;
2259
    end
2260
 
2261
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2262
    write_flags`WB_TRANSFER_CAB    = 1 ;
2263
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2264
 
2265
    wishbone_master.wb_block_write(write_flags, write_status) ;
2266
 
2267
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2268
    begin
2269
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2270
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2271
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2272
        disable no_transaction ;
2273
        disable main ;
2274
    end
2275
 
2276
    test_ok ;
2277
 
2278
    test_name = "CAB I/O READ TO WB SLAVE" ;
2279
    // prepare read data
2280
    for ( i = 0 ; i < 6 ; i = i + 1 )
2281
    begin
2282
        read_data`READ_ADDRESS = target_address + 4*i ;
2283
        read_data`READ_SEL     = 4'hF ;
2284
        wishbone_master.blk_read_data_in[i] = read_data ;
2285
    end
2286
 
2287
    wishbone_master.wb_block_read(write_flags, read_status) ;
2288
 
2289
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2290
    begin
2291
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2292
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2293
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2294
        disable no_transaction ;
2295
        disable main ;
2296
    end
2297
 
2298
    test_ok ;
2299
 
2300
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2301
 
2302
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2303
 
2304
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2305
    write_data`WRITE_ADDRESS = target_address + 1 ;
2306
    write_data`WRITE_DATA    = wmem_data[0] ;
2307
    write_data`WRITE_SEL     = 4'hF ;
2308
 
2309
    // don't handle retries
2310
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2311
 
2312
    `ifdef HOST
2313
        `define DO_W_CONF_TEST
2314
        `define DO_R_CONF_TEST
2315
    `else
2316
        `ifdef WB_CNF_IMAGE
2317
             `define DO_R_CONF_TEST
2318
        `endif
2319
    `endif
2320
 
2321
    `ifdef DO_W_CONF_TEST
2322
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2323
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2324
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2325
    begin
2326
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2327
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2328
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2329
        disable no_transaction ;
2330
        disable main ;
2331
    end
2332
 
2333
    write_data`WRITE_ADDRESS = target_address + 2 ;
2334
 
2335
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2336
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2337
    begin
2338
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2339
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2340
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2341
        disable no_transaction ;
2342
        disable main ;
2343
    end
2344
 
2345
    write_data`WRITE_ADDRESS = target_address + 3 ;
2346
 
2347
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2348
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2349
    begin
2350
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2351
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2352
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2353
        disable no_transaction ;
2354
        disable main ;
2355
    end
2356
 
2357
    test_ok ;
2358
    `endif
2359
 
2360
    `ifdef DO_R_CONF_TEST
2361
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2362
    read_data`READ_ADDRESS  = target_address + 3 ;
2363
    read_data`READ_SEL      = 4'hF ;
2364
    read_data`READ_TAG_STIM = 0 ;
2365
 
2366
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2367
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2368
    begin
2369
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2370
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2371
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2372
        disable no_transaction ;
2373
        disable main ;
2374
    end
2375
 
2376
    test_ok ;
2377
    `endif
2378
 
2379
    `ifdef DO_W_CONF_TEST
2380
    // prepare write data
2381
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2382
    for ( i = 0 ; i < 6 ; i = i + 1 )
2383
    begin
2384
        write_data`WRITE_DATA    = wmem_data[i] ;
2385
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2386
        write_data`WRITE_SEL     = 4'hF ;
2387
        wishbone_master.blk_write_data[i] = write_data ;
2388
    end
2389
 
2390
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2391
    write_flags`WB_TRANSFER_CAB    = 1 ;
2392
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2393
 
2394
    wishbone_master.wb_block_write(write_flags, write_status) ;
2395
 
2396
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2397
    begin
2398
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2399
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2400
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2401
        disable no_transaction ;
2402
        disable main ;
2403
    end
2404
    test_ok ;
2405
    `endif
2406
 
2407
    `ifdef DO_R_CONF_TEST
2408
    // prepare read data
2409
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2410
    for ( i = 0 ; i < 6 ; i = i + 1 )
2411
    begin
2412
        read_data`READ_ADDRESS = target_address + 4*i ;
2413
        read_data`READ_SEL     = 4'hF ;
2414
        wishbone_master.blk_read_data_in[i] = read_data ;
2415
    end
2416
 
2417
    wishbone_master.wb_block_read(write_flags, read_status) ;
2418
 
2419
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2420
    begin
2421
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2422
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2423
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2424
        disable no_transaction ;
2425
        disable main ;
2426
    end
2427
    test_ok ;
2428
    `endif
2429
 
2430
    `ifdef GUEST
2431
        skip = 1 ;
2432
    `endif
2433
 
2434
    // disable image
2435
    test_name = "DISABLE IMAGE" ;
2436
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2437
    if ( ok !== 1 )
2438
    begin
2439
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2440
        test_fail("WB Address Mask register couldn't be written") ;
2441
        disable no_transaction ;
2442
        disable main ;
2443
    end
2444
 
2445
    skip = 0 ;
2446
 
2447
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2448
 
2449
    disable no_transaction ;
2450
end
2451
begin:no_transaction
2452
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2453
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2454
    forever
2455
    begin
2456
        @(posedge pci_clock) ;
2457
        if ( skip !== 1 )
2458
        begin
2459
            if ( FRAME !== 1 )
2460
            begin
2461
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2462
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2463
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2464
            end
2465
        end
2466
    end
2467
end
2468
join
2469
endtask //wb_slave_errors
2470
 
2471
task wb_to_pci_error_handling ;
2472
    reg   [11:0] ctrl_offset ;
2473
    reg   [11:0] ba_offset ;
2474
    reg   [11:0] am_offset ;
2475
    reg   [11:0] ta_offset ;
2476
    reg   [11:0] err_cs_offset ;
2477
    reg `WRITE_STIM_TYPE write_data ;
2478
    reg `READ_STIM_TYPE  read_data ;
2479
    reg `READ_RETURN_TYPE read_status ;
2480
 
2481
    reg `WRITE_RETURN_TYPE write_status ;
2482
    reg `WB_TRANSFER_FLAGS write_flags ;
2483
    reg [31:0] temp_val1 ;
2484
    reg [31:0] temp_val2 ;
2485
    reg        ok   ;
2486
    reg [11:0] pci_ctrl_offset ;
2487
    reg [31:0] image_base ;
2488
    reg [31:0] target_address ;
2489
    integer    num_of_trans ;
2490
    integer    current ;
2491
    integer    i ;
2492
begin:main
2493
 
2494
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2495
 
2496
    pci_ctrl_offset = 12'h4 ;
2497
 
2498
    // disable error interrupts and disable error reporting
2499
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2500
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2501
    if ( ok !== 1 )
2502
    begin
2503
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2504
        test_fail("PCI Device Control register couldn't be written") ;
2505
        disable main ;
2506
    end
2507
 
2508
    // image 1 is used for error testing, since it is always implemented
2509
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2510
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2511
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2512
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2513
 
2514
    // set master abort testing address to address that goes out of target's range
2515
    target_address  = `BEH_TAR1_MEM_START ;
2516
    image_base      = 0 ;
2517
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2518
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2519
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2520
 
2521
    write_flags                    = 0 ;
2522
    write_flags`INIT_WAITS         = tb_init_waits ;
2523
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2524
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2525
 
2526
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2527
 
2528
    // enable master & target operation
2529
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2530
    if ( ok !== 1 )
2531
    begin
2532
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2533
        test_fail("PCI Device Control register couldn't be written") ;
2534
        disable main ;
2535
    end
2536
 
2537
    // prepare image control register
2538
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2539
    if ( ok !== 1 )
2540
    begin
2541
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2542
        test_fail("WB Image Control register couldn't be written") ;
2543
        disable main ;
2544
    end
2545
 
2546
    // prepare base address register
2547
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2548
    if ( ok !== 1 )
2549
    begin
2550
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2551
        test_fail("WB Image Base Address register couldn't be written") ;
2552
        disable main ;
2553
    end
2554
 
2555
    // write address mask register
2556
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2557
    if ( ok !== 1 )
2558
    begin
2559
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2560
        test_fail("WB Image Address Mask register couldn't be written") ;
2561
        disable main ;
2562
    end
2563
 
2564
    // disable error reporting
2565
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2566
    if ( ~ok )
2567
    begin
2568
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2569
        test_fail("WB Error Control and Status register couldn't be written") ;
2570
        disable main ;
2571
    end
2572
 
2573
    // perform two writes - one to error address and one to OK address
2574
    // prepare write buffer
2575
 
2576
    write_data`WRITE_ADDRESS = target_address ;
2577
    write_data`WRITE_DATA    = wmem_data[100] ;
2578
    write_data`WRITE_SEL     = 4'hF ;
2579
 
2580
    wishbone_master.blk_write_data[0] = write_data ;
2581
 
2582
    write_flags`WB_TRANSFER_SIZE = 2 ;
2583
 
2584
    // don't handle retries
2585
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2586
    write_flags`WB_TRANSFER_CAB    = 0 ;
2587
 
2588
    $display("Introducing master abort error on single WB to PCI write!") ;
2589
 
2590
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2591
    // first disable target 1
2592
 
2593 45 mihad
    configuration_cycle_write(0,                        // bus number
2594
                              `TAR1_IDSEL_INDEX - 11,   // device number
2595
                              0,                        // function number
2596
                              1,                        // register number
2597
                              0,                        // type of configuration cycle
2598
                              4'b0001,                  // byte enables
2599
                              32'h0000_0000             // data
2600 15 mihad
                             ) ;
2601
 
2602
    fork
2603
    begin
2604
        // start no response monitor in parallel with writes
2605
        musnt_respond(ok) ;
2606
        if ( ok !== 1 )
2607
        begin
2608
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2609
            $display("Testbench is configured wrong!") ;
2610
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2611
        end
2612
        else
2613
            test_ok ;
2614
    end
2615
    begin
2616
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2617
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2618
       begin
2619
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2620
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2621
           test_fail("WB Slave state machine failed to post single memory write");
2622
           disable main ;
2623
       end
2624
    end
2625
    join
2626
 
2627
    /*// read data from second write
2628
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2629
    read_data`READ_ADDRESS = target_address ;
2630
    read_data`READ_SEL     = 4'hF ;
2631
    read_data`READ_TAG_STIM = 0 ;
2632
 
2633
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2634
 
2635
    if ( read_status`READ_DATA !== wmem_data[101] )
2636
    begin
2637
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2638
    end
2639
    */
2640
 
2641
    // read error status register - no errors should be reported since reporting was disabled
2642
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2643
 
2644
    @(posedge pci_clock) ;
2645
    // wait for two WB clocks for synchronization to be finished
2646
    repeat (2)
2647
        @(posedge wb_clock) ;
2648
 
2649
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2650
    if ( temp_val1[8] !== 0 )
2651
    begin
2652
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2653
        $display("Error reporting was disabled, but error was reported anyway!") ;
2654
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2655
        disable main ;
2656
    end
2657
    test_ok ;
2658
 
2659
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2660
    // check for interrupts - there should be no interrupt requests active
2661
    `ifdef HOST
2662
        repeat(4)
2663
            @(posedge wb_clock) ;
2664
 
2665
        if ( INT_O !== 0 )
2666
        begin
2667
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2668
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2669
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2670
        end
2671
        else
2672
            test_ok ;
2673
    `else
2674
    `ifdef GUEST
2675
        repeat( 4 )
2676
            @(posedge pci_clock) ;
2677
 
2678
        if ( INTA !== 1 )
2679
        begin
2680
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2681
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2682
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2683
        end
2684
        else
2685
            test_ok ;
2686
    `endif
2687
    `endif
2688
 
2689
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2690
    // check PCI status register
2691
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2692
    if ( temp_val1[29] !== 1 )
2693
    begin
2694
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2695
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2696
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2697
    end
2698
    else
2699
        test_ok ;
2700
 
2701
    // clear
2702
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2703
 
2704
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2705
 
2706
    $display("Introducing master abort error to CAB write!") ;
2707
    // now enable error reporting mechanism
2708
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2709
    // enable error interrupts
2710
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2711
 
2712
    // configure flags for CAB transfer
2713
    write_flags`WB_TRANSFER_CAB = 1 ;
2714
    write_flags`WB_TRANSFER_SIZE = 3 ;
2715
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2716
 
2717
    // prepare data for erroneous write
2718
    for ( i = 0 ; i < 3 ; i = i + 1 )
2719
    begin
2720
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2721
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2722
        write_data`WRITE_SEL     = 4'hF ;
2723
        wishbone_master.blk_write_data[i] = write_data ;
2724
    end
2725
 
2726
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2727
    fork
2728
    begin
2729
        wishbone_master.wb_block_write(write_flags, write_status) ;
2730
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2731
        begin
2732
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2733
            $display("Complete burst write through WB slave didn't succeed!") ;
2734
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2735
            disable main ;
2736
        end
2737
    end
2738
    begin
2739
        musnt_respond(ok) ;
2740
        if ( ok !== 1 )
2741
        begin
2742
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2743
            $display("Testbench is configured wrong!") ;
2744
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2745
        end
2746
        else
2747
            test_ok ;
2748
    end
2749
    join
2750
 
2751
    // check error status address, data, byte enables and bus command
2752
    // error status bit is signalled on PCI clock and synchronized to WB clock
2753
    // wait one PCI clock cycle
2754
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2755
    ok = 1 ;
2756
    @(posedge pci_clock) ;
2757
 
2758
    // wait for two WB clocks for synchronization to be finished
2759
    repeat (2)
2760
        @(posedge wb_clock) ;
2761
 
2762
    // read registers
2763
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2764
    if ( temp_val1[8] !== 1 )
2765
    begin
2766
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2767
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2768
        ok = 0 ;
2769
    end
2770
 
2771
    if ( temp_val1[9] !== 1 )
2772
    begin
2773
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2774
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2775
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2776
        ok = 0 ;
2777
    end
2778
 
2779
    if ( temp_val1[31:28] !== 0 )
2780
    begin
2781
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2782
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2783
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2784
        ok = 0 ;
2785
    end
2786
 
2787
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2788
    begin
2789
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2790
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2791
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2792
        ok = 0 ;
2793
    end
2794
 
2795
    // read error address register
2796
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2797
    if ( temp_val1 !== target_address )
2798
    begin
2799
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2800
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2801
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2802
        ok = 0 ;
2803
    end
2804
 
2805
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2806
    if ( temp_val1 !== wmem_data[110] )
2807
    begin
2808
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2809
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2810
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2811
        ok = 0 ;
2812
    end
2813
 
2814
    // check PCI status register
2815
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2816
    if ( temp_val1[29] !== 1 )
2817
    begin
2818
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2819
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2820
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2821
        ok = 0 ;
2822
    end
2823
 
2824
    if ( temp_val1[28] !== 0 )
2825
    begin
2826
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2827
        $display("Received Target Abort bit was set for no reason!") ;
2828
        test_fail("Received Target Abort bit was set for no reason") ;
2829
        ok = 0 ;
2830
    end
2831
 
2832
    if ( ok )
2833
        test_ok ;
2834
 
2835
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2836
 
2837
    // clear error status bit
2838
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2839
 
2840
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2841
 
2842
    ok = 1 ;
2843
 
2844
    `ifdef HOST
2845
        repeat(4)
2846
        @(posedge wb_clock) ;
2847
        if ( INT_O !== 1 )
2848
        begin
2849
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2850
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2851
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2852
            ok = 0 ;
2853
        end
2854
    `else
2855
    `ifdef GUEST
2856
        repeat(4)
2857
        @(posedge pci_clock) ;
2858
        if ( INTA !== 0 )
2859
        begin
2860
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2861
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2862
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2863
            ok = 0 ;
2864
        end
2865
    `endif
2866
    `endif
2867
 
2868
    // read interrupt status register
2869
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2870
    if ( temp_val1 !== 32'h0000_0002 )
2871
    begin
2872
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2873
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2874
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2875
        test_fail("Interrupt Status register returned wrong value") ;
2876
        ok = 0 ;
2877
    end
2878
 
2879
    if ( ok )
2880
        test_ok ;
2881
    // clear interrupt status bits
2882
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2883
 
2884
    ok = 1 ;
2885
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2886
    // wait for two clock cycles before checking interrupt request deassertion
2887
    `ifdef HOST
2888
        repeat (4)
2889
            @(posedge wb_clock) ;
2890
 
2891
        if ( INT_O !== 0 )
2892
        begin
2893
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2894
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2895
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2896
            ok = 0 ;
2897
        end
2898
    `else
2899
    `ifdef GUEST
2900
        repeat (4)
2901
            @(posedge pci_clock) ;
2902
 
2903
        if ( INTA !== 1 )
2904
        begin
2905
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2906
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2907
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2908
            ok = 0 ;
2909
        end
2910
    `endif
2911
    `endif
2912
 
2913
    if ( ok )
2914
        test_ok ;
2915
 
2916
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2917
    ok = 1 ;
2918
    // enable target
2919 45 mihad
    configuration_cycle_write(0,                        // bus number
2920
                              `TAR1_IDSEL_INDEX - 11,   // device number
2921
                              0,                        // function number
2922
                              1,                        // register number
2923
                              0,                        // type of configuration cycle
2924
                              4'b0001,                  // byte enables
2925
                              32'h0000_0007             // data
2926 15 mihad
                             ) ;
2927
    // prepare data for ok write
2928
    for ( i = 0 ; i < 3 ; i = i + 1 )
2929
    begin
2930
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2931
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2932
        write_data`WRITE_SEL     = 4'hF ;
2933
        wishbone_master.blk_write_data[i] = write_data ;
2934
    end
2935
 
2936
    wishbone_master.wb_block_write(write_flags, write_status) ;
2937
 
2938
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2939
    begin
2940
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2941
        $display("Complete burst write through WB slave didn't succeed!") ;
2942
        test_fail("WB Slave state machine failed to post CAB write") ;
2943
        disable main ;
2944
    end
2945
 
2946
    // do a read
2947
    for ( i = 0 ; i < 3 ; i = i + 1 )
2948
    begin
2949
        read_data`READ_ADDRESS = target_address + 4*i ;
2950
        read_data`READ_SEL     = 4'hF ;
2951
        wishbone_master.blk_read_data_in[i] = read_data ;
2952
    end
2953
 
2954
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2955
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2956
    write_flags`WB_TRANSFER_CAB    = 1 ;
2957
 
2958
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2959
 
2960
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2961
    begin
2962
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2963
        $display("Complete burst read through WB slave didn't succeed!") ;
2964
        test_fail("Delayed CAB write was not processed as expected") ;
2965
        disable main ;
2966
    end
2967
 
2968
    for ( i = 0 ; i < 3 ; i = i + 1 )
2969
    begin
2970
        read_status = wishbone_master.blk_read_data_out[i] ;
2971
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2972
        begin
2973
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2974
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2975
        end
2976
    end
2977
 
2978
    $display("Introducing master abort error to single read!") ;
2979
    // disable target
2980 45 mihad
    configuration_cycle_write(0,                        // bus number
2981
                              `TAR1_IDSEL_INDEX - 11,   // device number
2982
                              0,                        // function number
2983
                              1,                        // register number
2984
                              0,                        // type of configuration cycle
2985
                              4'b0001,                  // byte enables
2986
                              32'h0000_0000             // data
2987 15 mihad
                             ) ;
2988
    // set read data
2989
    read_data`READ_ADDRESS = target_address ;
2990
    read_data`READ_SEL     = 4'hF ;
2991
 
2992
    // enable automatic retry handling
2993
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2994
    write_flags`WB_TRANSFER_CAB    = 0 ;
2995
 
2996
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2997
    fork
2998
    begin
2999
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3000
    end
3001
    begin
3002
        musnt_respond(ok) ;
3003
        if ( ok !== 1 )
3004
        begin
3005
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3006
            $display("Testbench is configured wrong!") ;
3007
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3008
        end
3009
    end
3010
    join
3011
 
3012
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3013
    begin
3014
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3015
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3016
        $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) ;
3017
        test_fail("read didn't finish on WB bus as expected") ;
3018
        disable main ;
3019
    end
3020
 
3021
    test_ok ;
3022
 
3023
 
3024
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
3025
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
3026
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3027
    if ( temp_val1[8] !== 0 )
3028
    begin
3029
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3030
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
3031
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
3032
    end
3033
    else
3034
        test_ok ;
3035
 
3036
    // now check normal read operation
3037 45 mihad
    configuration_cycle_write(0,                        // bus number
3038
                              `TAR1_IDSEL_INDEX - 11,   // device number
3039
                              0,                        // function number
3040
                              1,                        // register number
3041
                              0,                        // type of configuration cycle
3042
                              4'b0001,                  // byte enables
3043
                              32'h0000_0007             // data
3044 15 mihad
                             ) ;
3045
 
3046 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
3047 15 mihad
    read_data`READ_ADDRESS = target_address ;
3048
    read_data`READ_SEL     = 4'hF ;
3049
 
3050
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3051
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3052
    begin
3053
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3054
        $display("WB slave failed to process single read!") ;
3055
        $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) ;
3056
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
3057
        disable main ;
3058
    end
3059
 
3060
    if ( read_status`READ_DATA !== wmem_data[113] )
3061
    begin
3062
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
3063
        test_fail("when read finished on WB bus, wrong data was provided") ;
3064
    end
3065
    else
3066
        test_ok ;
3067
 
3068
    // check PCI status register
3069 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
3070 15 mihad
    ok = 1 ;
3071
 
3072
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3073
    if ( temp_val1[29] !== 1 )
3074
    begin
3075
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3076
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3077
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3078
        ok = 0 ;
3079
    end
3080
 
3081
    if ( temp_val1[28] !== 0 )
3082
    begin
3083
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3084
        $display("Received Target Abort bit was set for no reason!") ;
3085
        test_fail("Received Target Abort bit was set for no reason") ;
3086
        ok = 0 ;
3087
    end
3088
    if ( ok )
3089
        test_ok ;
3090
 
3091
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3092
 
3093
    $display("Introducing master abort error to CAB read!") ;
3094
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3095
 
3096 45 mihad
    configuration_cycle_write(0,                        // bus number
3097
                              `TAR1_IDSEL_INDEX - 11,   // device number
3098
                              0,                        // function number
3099
                              1,                        // register number
3100
                              0,                        // type of configuration cycle
3101
                              4'b0001,                  // byte enables
3102
                              32'h0000_0000             // data
3103 15 mihad
                             ) ;
3104
 
3105
    for ( i = 0 ; i < 3 ; i = i + 1 )
3106
    begin
3107
        read_data`READ_ADDRESS = target_address + 4*i ;
3108
        read_data`READ_SEL     = 4'hF ;
3109
        wishbone_master.blk_read_data_in[i] = read_data ;
3110
    end
3111
 
3112
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3113
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3114
    write_flags`WB_TRANSFER_CAB    = 1 ;
3115
 
3116
    fork
3117
    begin
3118
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3119
    end
3120
    begin
3121
        musnt_respond(ok) ;
3122
        if ( ok !== 1 )
3123
        begin
3124
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3125
            $display("Testbench is configured wrong!") ;
3126
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3127
        end
3128
    end
3129
    join
3130
 
3131
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3132
    begin
3133
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3134
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3135
        $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) ;
3136
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3137
        disable main ;
3138
    end
3139
    else
3140
        test_ok ;
3141
 
3142
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3143
    ok = 1 ;
3144
    // check PCI status register
3145
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3146
    if ( temp_val1[29] !== 1 )
3147
    begin
3148
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3149
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3150
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3151
        ok = 0 ;
3152
    end
3153
 
3154
    if ( temp_val1[28] !== 0 )
3155
    begin
3156
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3157
        $display("Received Target Abort bit was set for no reason!") ;
3158
        test_fail("Received Target Abort bit was set for no reason") ;
3159
        ok = 0 ;
3160
    end
3161
 
3162
    if ( ok )
3163
        test_ok ;
3164
 
3165
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3166
 
3167
    $display("Introducing target abort termination to single write!") ;
3168
 
3169
    // disable error reporting and interrupts
3170
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3171
 
3172 45 mihad
    configuration_cycle_write(0,                        // bus number
3173
                              `TAR1_IDSEL_INDEX - 11,   // device number
3174
                              0,                        // function number
3175
                              1,                        // register number
3176
                              0,                        // type of configuration cycle
3177
                              4'b0001,                  // byte enables
3178
                              32'h0000_0007             // data
3179 15 mihad
                             ) ;
3180
 
3181
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3182
    if ( ok !== 1 )
3183
    begin
3184
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3185
        test_fail("WB Error Control and Status register couldn't be written to") ;
3186
        disable main ;
3187
    end
3188
 
3189
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3190
    if ( ok !== 1 )
3191
    begin
3192
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3193
        test_fail("Interrupt Control register couldn't be written to") ;
3194
        disable main ;
3195
    end
3196
 
3197
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3198
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3199
 
3200
    write_data`WRITE_ADDRESS = target_address ;
3201
    write_data`WRITE_DATA    = wmem_data[0] ;
3202
    write_data`WRITE_SEL     = 4'hF ;
3203
 
3204
    wishbone_master.blk_write_data[0] = write_data ;
3205
 
3206
    write_data`WRITE_ADDRESS = target_address + 4;
3207
    write_data`WRITE_DATA    = wmem_data[1] ;
3208
    write_data`WRITE_SEL     = 4'hF ;
3209
 
3210
    wishbone_master.blk_write_data[1] = write_data ;
3211
 
3212
    write_flags`WB_TRANSFER_SIZE = 2 ;
3213
 
3214
    // don't handle retries
3215
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3216
    write_flags`WB_TRANSFER_CAB    = 0 ;
3217
 
3218
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3219
    fork
3220
    begin
3221
        wishbone_master.wb_block_write(write_flags, write_status) ;
3222
 
3223
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3224
        begin
3225
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3226
            $display("Image writes were not accepted as expected!") ;
3227
            $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) ;
3228
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3229
            disable main ;
3230
        end
3231
 
3232
        // read data back to see, if it was written OK
3233
        read_data`READ_ADDRESS         = target_address + 4;
3234
        read_data`READ_SEL             = 4'hF ;
3235
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3236
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3237
    end
3238
    begin
3239
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3240
        if ( ok !== 1 )
3241
        begin
3242
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3243
        end
3244
        else
3245
            test_ok ;
3246
 
3247
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3248
 
3249
        // when first transaction finishes - enable normal target response!
3250
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3251
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3252
 
3253
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3254
        if ( ok !== 1 )
3255
        begin
3256
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3257
        end
3258
        else
3259
            test_ok ;
3260
 
3261
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3262
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3263
        if ( ok !== 1 )
3264
        begin
3265
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3266
        end
3267
    end
3268
    join
3269
 
3270
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3271
    begin
3272
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3273
        $display("Bridge failed to process single read after target abort terminated write!") ;
3274
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3275
        disable main ;
3276
    end
3277
 
3278
    if ( read_status`READ_DATA !== wmem_data[1] )
3279
    begin
3280
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3281
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3282
    end
3283
    else
3284
        test_ok ;
3285
 
3286
    // check interrupt and error statuses!
3287
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3288
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3289
    if ( temp_val1[8] !== 0 )
3290
    begin
3291
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3292
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3293
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3294
    end
3295
    else
3296
        test_ok ;
3297
 
3298
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3299
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3300
    if ( temp_val1[1] !== 0 )
3301
    begin
3302
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3303
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3304
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3305
    end
3306
    else
3307
        test_ok ;
3308
 
3309
    // check PCI status register
3310
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3311
    ok = 1 ;
3312
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3313
    if ( temp_val1[29] !== 0 )
3314
    begin
3315
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3316
        $display("Received Master Abort bit was set with no reason!") ;
3317
        test_fail("Received Master Abort bit was set with no reason") ;
3318
        ok = 0 ;
3319
    end
3320
 
3321
    if ( temp_val1[28] !== 1 )
3322
    begin
3323
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3324
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3325
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3326
        ok = 0 ;
3327
    end
3328
 
3329
    if ( ok )
3330
        test_ok ;
3331
 
3332
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3333
 
3334
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3335
 
3336
    $display("Introducing target abort termination to CAB write!") ;
3337
    // enable error reporting mechanism
3338
 
3339
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3340
    if ( ok !== 1 )
3341
    begin
3342
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3343
        test_fail("WB Error Control and Status register could not be written to") ;
3344
        disable main ;
3345
    end
3346
 
3347
    for ( i = 0 ; i < 3 ; i = i + 1 )
3348
    begin
3349
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3350
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3351
        write_data`WRITE_SEL     = 4'b1010 ;
3352
        wishbone_master.blk_write_data[i] = write_data ;
3353
    end
3354
 
3355
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3356
    write_flags`WB_TRANSFER_CAB    = 1 ;
3357
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3358
 
3359
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3360
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3361
 
3362
    fork
3363
    begin
3364
        wishbone_master.wb_block_write(write_flags, write_status) ;
3365
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3366
        begin
3367
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3368
            $display("Bridge failed to process complete CAB write!") ;
3369
            test_fail("bridge failed to post CAB Memory Write") ;
3370
            disable main ;
3371
        end
3372
    end
3373
    begin
3374
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3375
        if ( ok !== 1 )
3376
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3377
        else
3378
            test_ok ;
3379
    end
3380
    join
3381
 
3382
    // check statuses and data from error
3383
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3384
    ok = 1 ;
3385
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3386
    if ( temp_val1[8] !== 1 )
3387
    begin
3388
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3389
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3390
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3391
        ok = 0 ;
3392
    end
3393
 
3394
    if ( temp_val1[9] !== 0 )
3395
    begin
3396
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3397
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3398
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3399
        ok = 0 ;
3400
    end
3401
 
3402
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3403
    begin
3404
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3405
        $display("Value in W_ERR_CS register was wrong!") ;
3406
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3407
        test_fail("BE Field didn't provided expected value") ;
3408
        ok = 0 ;
3409
    end
3410
 
3411
    if ( ok )
3412
        test_ok ;
3413
 
3414
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3415
    ok = 1 ;
3416
    // check erroneous address and data
3417
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3418
    if ( temp_val1 !== (target_address + 8) )
3419
    begin
3420
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3421
        $display("Value in W_ERR_ADDR register was wrong!") ;
3422
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3423
        test_fail("Value in WB Erroneous Address register was wrong") ;
3424
        ok = 0 ;
3425
    end
3426
 
3427
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3428
    if ( temp_val1 !== wmem_data[120] )
3429
    begin
3430
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3431
        $display("Value in W_ERR_DATA register was wrong!") ;
3432
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3433
        test_fail("Value in WB Erroneous Data register was wrong") ;
3434
        ok = 0 ;
3435
    end
3436
 
3437
    if ( ok )
3438
        test_ok ;
3439
 
3440
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3441
    ok = 1 ;
3442
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3443
    if ( temp_val1[29] !== 0 )
3444
    begin
3445
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3446
        $display("Received Master Abort bit was set with no reason!") ;
3447
        test_fail("Received Master Abort bit was set for no reason") ;
3448
        ok = 0 ;
3449
    end
3450
 
3451
    if ( temp_val1[28] !== 1 )
3452
    begin
3453
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3454
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3455
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3456
        ok = 0 ;
3457
    end
3458
 
3459
    if ( ok )
3460
        test_ok ;
3461
 
3462
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3463
 
3464
    // clear error status bit and enable error interrupts
3465
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3466
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3467
 
3468
    // check if error bit was cleared
3469
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3470
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3471
    if ( temp_val1[8] !== 0 )
3472
    begin
3473
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3474
        $display("Error bit was not cleared even though one was written to its location!") ;
3475
        test_fail("Error bit was not cleared even though one was written to its location") ;
3476
    end
3477
 
3478
    // repeat same write with different target configuration
3479
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3480
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3481
 
3482
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3483
    fork
3484
    begin
3485
        write_flags`WB_TRANSFER_SIZE = 2 ;
3486
        wishbone_master.wb_block_write(write_flags, write_status) ;
3487
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3488
        begin
3489
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3490
            $display("Bridge failed to process complete CAB write!") ;
3491
            test_fail("bridge failed to post CAB Memory Write") ;
3492
            disable main ;
3493
        end
3494
 
3495
        write_flags`WB_TRANSFER_SIZE = 3 ;
3496
        wishbone_master.wb_block_write(write_flags, write_status) ;
3497
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3498
        begin
3499
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3500
            $display("Bridge failed to process complete CAB write!") ;
3501
            test_fail("bridge failed to post CAB Memory Write") ;
3502
            disable main ;
3503
        end
3504
    end
3505
    begin
3506
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3507
        if ( ok !== 1 )
3508
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3509
        else
3510
        begin
3511
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3512
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3513
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3514
            if ( ok !== 1 )
3515
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3516
            else
3517
                test_ok ;
3518
        end
3519
    end
3520
    join
3521
 
3522
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3523
    ok = 1 ;
3524
    // check statuses and data from error
3525
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3526
    if ( temp_val1[8] !== 1 )
3527
    begin
3528
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3529
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3530
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3531
        ok = 0 ;
3532
    end
3533
 
3534
    if ( temp_val1[9] !== 0 )
3535
    begin
3536
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3537
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3538
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3539
        ok = 0 ;
3540
    end
3541
 
3542
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3543
    begin
3544
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3545
        $display("Value in W_ERR_CS register was wrong!") ;
3546
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3547
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3548
        ok = 0 ;
3549
    end
3550
 
3551
    if ( ok )
3552
        test_ok ;
3553
 
3554
    // check erroneous address and data
3555
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3556
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3557
    ok = 1 ;
3558
    if ( temp_val1 !== (target_address + 8 + 4) )
3559
    begin
3560
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3561
        $display("Value in W_ERR_ADDR register was wrong!") ;
3562
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3563
        test_fail("Value in WB Erroneous Address register was wrong") ;
3564
        ok = 0 ;
3565
 
3566
    end
3567
 
3568
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3569
    if ( temp_val1 !== wmem_data[121] )
3570
    begin
3571
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3572
        $display("Value in W_ERR_DATA register was wrong!") ;
3573
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3574
        test_fail("Value in WB Erroneous Data register was wrong") ;
3575
        ok = 0 ;
3576
    end
3577
 
3578
    if ( ok )
3579
        test_ok ;
3580
 
3581
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3582
    `ifdef HOST
3583
        repeat(4)
3584
            @(posedge wb_clock) ;
3585
        if ( INT_O !== 1 )
3586
        begin
3587
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3588
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3589
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3590
        end
3591
        else
3592
            test_ok ;
3593
    `else
3594
    `ifdef GUEST
3595
        repeat(4)
3596
            @(posedge pci_clock) ;
3597
        if ( INTA !== 0 )
3598
        begin
3599
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3600
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3601
            test_fail("interrupt request was not presented on PCI bus") ;
3602
        end
3603
        else
3604
            test_ok ;
3605
    `endif
3606
    `endif
3607
 
3608
    // read interrupt status register
3609
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3610
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3611
    if ( temp_val1[1] !== 1 )
3612
    begin
3613
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3614
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3615
        test_fail("Expected Interrupt status bit wasn't set") ;
3616
    end
3617
 
3618
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3619
 
3620
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3621
    ok = 1 ;
3622
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3623
    if ( temp_val1[29] !== 0 )
3624
    begin
3625
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3626
        $display("Received Master Abort bit was set with no reason!") ;
3627
        test_fail("Received Master Abort bit was set with no reason") ;
3628
        ok = 0 ;
3629
    end
3630
 
3631
    if ( temp_val1[28] !== 1 )
3632
    begin
3633
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3634
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3635
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3636
        ok = 0 ;
3637
    end
3638
 
3639
    if ( ok )
3640
        test_ok ;
3641
 
3642
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3643
 
3644
    // clear interrupts and errors
3645
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3646
    repeat( 3 )
3647
        @(posedge pci_clock) ;
3648
 
3649
    repeat( 2 )
3650
        @(posedge wb_clock) ;
3651
 
3652
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3653
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3654
    if ( temp_val1[1] !== 0 )
3655
    begin
3656
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3657
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3658
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3659
    end
3660
    else
3661
        test_ok ;
3662
 
3663
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3664
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3665
    if ( temp_val1[8] !== 0 )
3666
    begin
3667
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3668
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3669
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3670
    end
3671
 
3672
 
3673
    $display("Introducing Target Abort error to single read!") ;
3674
    // set read data
3675
    read_data`READ_ADDRESS = target_address + 8 ;
3676
    read_data`READ_SEL     = 4'hF ;
3677
 
3678
    // enable automatic retry handling
3679
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3680
    write_flags`WB_TRANSFER_CAB    = 0 ;
3681
 
3682
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3683
 
3684
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3685
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3686
 
3687
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3688
 
3689
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3690
    begin
3691
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3692
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3693
        $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) ;
3694
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3695
        disable main ;
3696
    end
3697
    else
3698
        test_ok ;
3699
 
3700
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3701
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3702
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3703
    if ( temp_val1[8] !== 0 )
3704
    begin
3705
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3706
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3707
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3708
    end
3709
    else
3710
        test_ok ;
3711
 
3712
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3713
    ok = 1 ;
3714
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3715
    if ( temp_val1[29] !== 0 )
3716
    begin
3717
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3718
        $display("Received Master Abort bit was set with no reason!") ;
3719
        test_fail("Received Master Abort bit was set with no reason") ;
3720
        ok = 0 ;
3721
    end
3722
 
3723
    if ( temp_val1[28] !== 1 )
3724
    begin
3725
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3726
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3727
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3728
        ok = 0 ;
3729
    end
3730
 
3731
    if ( ok )
3732
        test_ok ;
3733
 
3734
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3735
 
3736
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3737
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3738
    if ( temp_val1[1] !== 0 )
3739
    begin
3740
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3741
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3742
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3743
    end
3744
    else
3745
        test_ok ;
3746
 
3747
    $display("Introducing Target Abort error to CAB read!") ;
3748
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3749
 
3750
    for ( i = 0 ; i < 4 ; i = i + 1 )
3751
    begin
3752
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3753
        read_data`READ_SEL     = 4'b1010 ;
3754
        wishbone_master.blk_read_data_in[i] = read_data ;
3755
    end
3756
 
3757
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3758
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3759
    write_flags`WB_TRANSFER_CAB    = 1 ;
3760
 
3761
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3762
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3763
 
3764
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3765
 
3766
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3767
    begin
3768
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3769
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3770
        $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) ;
3771
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3772
        disable main ;
3773
    end
3774
 
3775
    read_status = wishbone_master.blk_read_data_out[0] ;
3776
    temp_val1 = read_status`READ_DATA ;
3777
    temp_val2 = wmem_data[120] ;
3778
 
3779
    // last write to this address was with only two byte enables - check only those
3780
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3781
    begin
3782
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3783
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3784
    end
3785
    else
3786
        test_ok ;
3787
 
3788
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3789
    ok = 1 ;
3790
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3791
    if ( temp_val1[29] !== 0 )
3792
    begin
3793
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3794
        $display("Received Master Abort bit was set with no reason!") ;
3795
        test_fail("Received Master Abort bit was set with no reason") ;
3796
        ok = 0 ;
3797
    end
3798
 
3799
    if ( temp_val1[28] !== 1 )
3800
    begin
3801
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3802
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3803
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3804
        ok = 0 ;
3805
    end
3806
 
3807
    if ( ok )
3808
       test_ok ;
3809
 
3810
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3811
 
3812
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3813
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3814
 
3815
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3816
    for ( i = 0 ; i < 3 ; i = i + 1 )
3817
    begin
3818
        read_data`READ_ADDRESS = target_address + 4*i ;
3819
        read_data`READ_SEL     = 4'b1111 ;
3820
        wishbone_master.blk_read_data_in[i] = read_data ;
3821
    end
3822
 
3823
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3824
 
3825
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3826
 
3827
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3828
    begin
3829
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3830
        $display("Complete burst read through WB slave didn't succeed!") ;
3831
        test_fail("bridge didn't process Burst Read in an expected way") ;
3832
        disable main ;
3833
    end
3834
    else
3835
        test_ok ;
3836
 
3837
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3838
 
3839
    for ( i = 0 ; i < 3 ; i = i + 1 )
3840
    begin
3841
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3842
        read_data`READ_SEL     = 4'b1111 ;
3843
        wishbone_master.blk_read_data_in[i] = read_data ;
3844
    end
3845
 
3846
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3847
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3848
    write_flags`WB_TRANSFER_CAB    = 1 ;
3849
 
3850
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3851
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3852
 
3853
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3854
 
3855
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3856
    begin
3857
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3858
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3859
        $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) ;
3860
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3861
        disable main ;
3862
    end
3863
 
3864
    for ( i = 0 ; i < 3 ; i = i + 1 )
3865
    begin
3866
        ok = 1 ;
3867
        read_status = wishbone_master.blk_read_data_out[i] ;
3868
        temp_val1 = read_status`READ_DATA ;
3869
        temp_val2 = wmem_data[120 + i] ;
3870
 
3871
        // last write to this address was with only two byte enables - check only those
3872
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3873
        begin
3874
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3875
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3876
            ok = 0 ;
3877
        end
3878
    end
3879
 
3880
    if ( ok )
3881
        test_ok ;
3882
 
3883
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3884
    ok = 1 ;
3885
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3886
    if ( temp_val1[29] !== 0 )
3887
    begin
3888
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3889
        $display("Received Master Abort bit was set with no reason!") ;
3890
        test_fail("Received Master Abort bit was set with no reason") ;
3891
        ok = 0 ;
3892
    end
3893
 
3894
    if ( temp_val1[28] !== 1 )
3895
    begin
3896
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3897
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3898
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3899
        ok = 0 ;
3900
    end
3901
 
3902
    if ( ok )
3903
       test_ok ;
3904
 
3905
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3906
 
3907
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3908
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3909
 
3910
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3911
    for ( i = 0 ; i < 3 ; i = i + 1 )
3912
    begin
3913
        read_data`READ_ADDRESS = target_address + 4*i ;
3914
        read_data`READ_SEL     = 4'b1111 ;
3915
        wishbone_master.blk_read_data_in[i] = read_data ;
3916
    end
3917
 
3918
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3919
 
3920
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3921
 
3922
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3923
    begin
3924
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3925
        $display("Complete burst read through WB slave didn't succeed!") ;
3926
        test_fail("bridge didn't process Burst Read in an expected way") ;
3927
        disable main ;
3928
    end
3929
    else
3930
        test_ok ;
3931
 
3932
    // test error on IO write
3933
    // change base address
3934
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3935
    write_data`WRITE_SEL     = 4'b0101 ;
3936
    write_data`WRITE_ADDRESS = target_address ;
3937
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3938
 
3939
    write_flags`WB_TRANSFER_CAB    = 0 ;
3940
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3941
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3942
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3943
    fork
3944
    begin
3945
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3946
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3947
        begin
3948
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3949
            $display("WB slave failed to accept IO write!") ;
3950
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3951
            disable main ;
3952
        end
3953
    end
3954
    begin
3955
        musnt_respond(ok) ;
3956
        if ( ok !== 1 )
3957
        begin
3958
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3959
            $display("Testbench is configured wrong!") ;
3960
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3961
        end
3962
        else
3963
            test_ok ;
3964
    end
3965
    join
3966
 
3967
    // check statuses and everything else
3968
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3969
    ok = 1 ;
3970
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3971
    if ( temp_val1[8] !== 1 )
3972
    begin
3973
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3974
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3975
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3976
        ok = 0 ;
3977
    end
3978
 
3979
    if ( temp_val1[9] !== 1 )
3980
    begin
3981
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3982
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3983
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3984
        ok = 0 ;
3985
    end
3986
 
3987
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3988
    begin
3989
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3990
        $display("Value in W_ERR_CS register was wrong!") ;
3991
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3992
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3993
        ok = 0 ;
3994
    end
3995
 
3996
    if ( ok )
3997
        test_ok ;
3998
 
3999
    // check erroneous address and data
4000
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
4001
    ok = 1 ;
4002
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4003
    if ( temp_val1 !== target_address )
4004
    begin
4005
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4006
        $display("Value in W_ERR_ADDR register was wrong!") ;
4007
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
4008
        test_fail("WB Erroneous Address register didn't provide right value") ;
4009
        ok = 0 ;
4010
    end
4011
 
4012
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4013
    if ( temp_val1 !== 32'hAAAA_AAAA )
4014
    begin
4015
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4016
        $display("Value in W_ERR_DATA register was wrong!") ;
4017
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
4018
        test_fail("WB Erroneous Data register didn't provide right value") ;
4019
        ok = 0 ;
4020
    end
4021
 
4022
    if ( ok )
4023
        test_ok ;
4024
 
4025
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4026
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
4027
    if ( temp_val1[1] !== 1 )
4028
    begin
4029
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4030
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
4031
        test_fail("expected interrupt status bit was not set") ;
4032
    end
4033
    else
4034
        test_ok ;
4035
 
4036
    // clear interrupts and errors
4037
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
4038
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
4039
 
4040
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4041
    ok = 1 ;
4042
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4043
    if ( temp_val1[29] !== 1 )
4044
    begin
4045
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4046
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
4047
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
4048
        ok = 0 ;
4049
    end
4050
 
4051
    if ( temp_val1[28] !== 0 )
4052
    begin
4053
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4054
        $display("Received Target Abort bit was set for no reason!") ;
4055
        test_fail("Received Target Abort bit was set for no reason") ;
4056
        ok = 0 ;
4057
    end
4058
 
4059
    if ( ok )
4060
        test_ok ;
4061
 
4062
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4063
 
4064
    // disable image
4065
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4066
    if ( ok !== 1 )
4067
    begin
4068
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4069
        test_fail("WB Image Address Mask register couldn't be written") ;
4070
        disable main ;
4071
    end
4072
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
4073
 
4074
end
4075
endtask
4076
 
4077
task parity_checking ;
4078
    reg   [11:0] ctrl_offset ;
4079
    reg   [11:0] ba_offset ;
4080
    reg   [11:0] am_offset ;
4081
    reg   [11:0] ta_offset ;
4082
    reg `WRITE_STIM_TYPE write_data ;
4083
    reg `READ_STIM_TYPE  read_data ;
4084
    reg `READ_RETURN_TYPE read_status ;
4085
 
4086
    reg `WRITE_RETURN_TYPE write_status ;
4087
    reg `WB_TRANSFER_FLAGS write_flags ;
4088
    reg [31:0] temp_val1 ;
4089
    reg [31:0] temp_val2 ;
4090
    reg        ok   ;
4091
    reg [11:0] pci_ctrl_offset ;
4092
    reg [31:0] image_base ;
4093
    reg [31:0] target_address ;
4094
    reg [11:0] icr_offset ;
4095
    reg [11:0] isr_offset ;
4096
    reg [11:0] p_ba_offset ;
4097
    reg [11:0] p_am_offset ;
4098
    reg [11:0] p_ctrl_offset ;
4099
    integer    i ;
4100
    reg        perr_asserted ;
4101
begin:main
4102
    $display("******************************* Testing Parity Checker functions ********************************") ;
4103
    $display("Testing Parity Errors during Master Transactions!") ;
4104
    $display("Introducing Parity Erros to Master Writes!") ;
4105
    $fdisplay(pci_mon_log_file_desc,
4106
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4107
 
4108
    // image 1 is used for error testing, since it is always implemented
4109
    pci_ctrl_offset = 12'h004 ;
4110
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4111
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4112
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4113
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4114
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4115
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4116
 
4117
    // image 1 for PCI target
4118
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4119
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4120
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4121
 
4122
    target_address  = `BEH_TAR1_MEM_START ;
4123
    image_base      = 0 ;
4124
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4125
 
4126
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4127
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4128
    write_flags                    = 0 ;
4129
    write_flags`INIT_WAITS         = tb_init_waits ;
4130
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
4131
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4132
 
4133
    // enable master & target operation and disable parity functions
4134
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4135
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4136
    if ( ok !== 1 )
4137
    begin
4138
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4139
        test_fail("PCI Device Control register could not be written to") ;
4140
        disable main ;
4141
    end
4142
 
4143
    // prepare image control register
4144
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4145
    if ( ok !== 1 )
4146
    begin
4147
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4148
        test_fail("WB Image Control register could not be written to") ;
4149
        disable main ;
4150
    end
4151
 
4152
    // prepare base address register
4153
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4154
    if ( ok !== 1 )
4155
    begin
4156
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4157
        test_fail("WB Image Base Address register could not be written to") ;
4158
        disable main ;
4159
    end
4160
 
4161
    // write address mask register
4162
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4163
    if ( ok !== 1 )
4164
    begin
4165
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4166
        test_fail("WB Image Address Mask register could not be written to") ;
4167
        disable main ;
4168
    end
4169
 
4170
    // disable parity interrupts
4171
    config_write( icr_offset, 0, 4'hF, ok ) ;
4172
    if ( ok !== 1 )
4173
    begin
4174
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4175
        test_fail("Interrupt Control register could not be written to") ;
4176
        disable main ;
4177
    end
4178
 
4179
    write_data`WRITE_ADDRESS = target_address ;
4180
    write_data`WRITE_DATA    = wmem_data[0] ;
4181
    write_data`WRITE_SEL     = 4'b1111 ;
4182
 
4183
    // enable target's 1 response to parity errors
4184 45 mihad
    configuration_cycle_write(0,                        // bus number
4185
                              `TAR1_IDSEL_INDEX - 11,   // device number
4186
                              0,                        // function number
4187
                              1,                        // register number
4188
                              0,                        // type of configuration cycle
4189
                              4'b0001,                  // byte enables
4190
                              32'h0000_0047             // data
4191 15 mihad
                             ) ;
4192
 
4193
    // disable target's 2 response to parity errors
4194 45 mihad
    configuration_cycle_write(0,                        // bus number
4195
                              `TAR2_IDSEL_INDEX - 11,   // device number
4196
                              0,                        // function number
4197
                              1,                        // register number
4198
                              0,                        // type of configuration cycle
4199
                              4'b0001,                  // byte enables
4200
                              32'h0000_0007             // data
4201 15 mihad
                             ) ;
4202
 
4203
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4204
 
4205
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4206
    fork
4207
    begin
4208
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4209
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4210
        begin
4211
            $display("Parity checker testing failed! Time %t ", $time) ;
4212
            $display("Bridge failed to process single memory write!") ;
4213
            test_fail("bridge failed to post single WB memory write") ;
4214
            disable main ;
4215
        end
4216
    end
4217
    begin:wait_perr1
4218
        perr_asserted = 0 ;
4219
        @(posedge pci_clock) ;
4220
 
4221 35 mihad
        while ( PERR !== 0 )
4222 15 mihad
            @(posedge pci_clock) ;
4223
 
4224 35 mihad
        perr_asserted = 1 ;
4225 15 mihad
 
4226
    end
4227
    begin
4228
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4229
 
4230
        if ( ok !== 1 )
4231
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4232
 
4233 35 mihad
        repeat(2)
4234 15 mihad
            @(posedge pci_clock) ;
4235
 
4236 35 mihad
        #1 ;
4237
        if ( !perr_asserted )
4238
            disable wait_perr1 ;
4239 15 mihad
    end
4240
    join
4241
 
4242
    if ( perr_asserted && ok )
4243
    begin
4244
        test_ok ;
4245
    end
4246
    else
4247
    if ( ~perr_asserted )
4248
    begin
4249
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4250
        disable main ;
4251
    end
4252
 
4253
    // check all the statuses - if HOST is defined, wait for them to be synced
4254
    `ifdef HOST
4255
    repeat(4)
4256
        @(posedge wb_clock) ;
4257
    `endif
4258
 
4259
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4260
    ok = 1 ;
4261
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4262 45 mihad
    if ( temp_val1[31] !== 0 )
4263 15 mihad
    begin
4264
        $display("Parity checker testing failed! Time %t ", $time) ;
4265 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4266
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4267 15 mihad
        ok = 0 ;
4268
    end
4269
 
4270
    if ( temp_val1[30] !== 0 )
4271
    begin
4272
        $display("Parity checker testing failed! Time %t ", $time) ;
4273
        $display("Signalled System Error bit was set for no reason!") ;
4274
        test_fail("Signalled System Error bit was set for no reason") ;
4275
        ok = 0 ;
4276
    end
4277
 
4278
    if ( temp_val1[24] !== 0 )
4279
    begin
4280
        $display("Parity checker testing failed! Time %t ", $time) ;
4281
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4282
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4283
        ok = 0 ;
4284
    end
4285
 
4286
    if ( ok )
4287
        test_ok ;
4288
 
4289
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4290
    // clear parity bits and enable parity response
4291
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4292
    if ( ok !== 1 )
4293
    begin
4294
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4295
        test_fail("write to PCI Status Register failed") ;
4296
        disable main ;
4297
    end
4298
 
4299
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4300
    fork
4301
    begin
4302
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4303
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4304
        begin
4305
            $display("Parity checker testing failed! Time %t ", $time) ;
4306
            $display("Bridge failed to process single memory write!") ;
4307
            test_fail("bridge failed to post single memory write") ;
4308
            disable main ;
4309
        end
4310
    end
4311
    begin:wait_perr2
4312
        perr_asserted = 0 ;
4313
        @(posedge pci_clock) ;
4314
 
4315 35 mihad
        while ( PERR !== 0 )
4316 15 mihad
            @(posedge pci_clock) ;
4317
 
4318 35 mihad
        perr_asserted = 1 ;
4319 15 mihad
 
4320
    end
4321
    begin
4322
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4323
 
4324
        if ( ok !== 1 )
4325
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4326
 
4327 35 mihad
        repeat(2)
4328 15 mihad
            @(posedge pci_clock) ;
4329
 
4330 35 mihad
        #1 ;
4331
        if (!perr_asserted)
4332
            disable wait_perr2 ;
4333 15 mihad
    end
4334
    join
4335
 
4336
    if ( perr_asserted && ok )
4337
    begin
4338
        test_ok ;
4339
    end
4340
    else
4341
    if ( ~perr_asserted )
4342
    begin
4343
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4344
        disable main ;
4345
    end
4346
 
4347
    // check all the statuses - if HOST is defined, wait for them to be synced
4348
    `ifdef HOST
4349
    repeat(4)
4350
        @(posedge wb_clock) ;
4351
    `endif
4352
 
4353
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4354
    ok = 1 ;
4355
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4356 45 mihad
    if ( temp_val1[31] !== 0 )
4357 15 mihad
    begin
4358
        $display("Parity checker testing failed! Time %t ", $time) ;
4359 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4360
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4361 15 mihad
        ok = 0 ;
4362
    end
4363
 
4364
    if ( temp_val1[30] !== 0 )
4365
    begin
4366
        $display("Parity checker testing failed! Time %t ", $time) ;
4367
        $display("Signalled System Error bit was set for no reason!") ;
4368
        test_fail("Signalled System Error bit was set for no reason") ;
4369
        ok = 0 ;
4370
    end
4371
 
4372
    if ( temp_val1[24] !== 1 )
4373
    begin
4374
        $display("Parity checker testing failed! Time %t ", $time) ;
4375 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!") ;
4376
        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") ;
4377 15 mihad
        ok = 0 ;
4378
    end
4379
 
4380
    if ( ok )
4381
        test_ok ;
4382
 
4383
    // clear status bits and disable parity error response
4384
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4385
 
4386
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4387
 
4388
    // disable perr generation and perform a write - no bits should be set
4389
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4390
    fork
4391
    begin
4392
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4393
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4394
        begin
4395
            $display("Parity checker testing failed! Time %t ", $time) ;
4396
            $display("Bridge failed to process single memory write!") ;
4397
            test_fail("bridge failed to post single memory write") ;
4398
            disable main ;
4399
        end
4400
    end
4401
    begin
4402
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4403
 
4404
        if ( ok !== 1 )
4405
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4406
        else
4407
            test_ok ;
4408
 
4409
        repeat(3)
4410
            @(posedge pci_clock) ;
4411
    end
4412
    join
4413
 
4414
    `ifdef HOST
4415
    repeat(4)
4416
        @(posedge wb_clock) ;
4417
    `endif
4418
 
4419
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4420
    ok = 1 ;
4421
 
4422
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4423
    if ( temp_val1[31] !== 0 )
4424
    begin
4425
        $display("Parity checker testing failed! Time %t ", $time) ;
4426
        $display("Detected Parity Error bit was set for no reason!") ;
4427
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4428
        ok = 0 ;
4429
    end
4430
 
4431
    if ( temp_val1[30] !== 0 )
4432
    begin
4433
        $display("Parity checker testing failed! Time %t ", $time) ;
4434
        $display("Signalled System Error bit was set for no reason!") ;
4435
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4436
        ok = 0 ;
4437
    end
4438
 
4439
    if ( temp_val1[24] !== 0 )
4440
    begin
4441
        $display("Parity checker testing failed! Time %t ", $time) ;
4442
        $display("Master Data Parity Error bit was set for no reason!") ;
4443
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4444
        ok = 0 ;
4445
    end
4446
 
4447
    if ( ok )
4448
        test_ok ;
4449
 
4450
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4451
 
4452
    read_data = 0 ;
4453
    read_data`READ_ADDRESS  = target_address ;
4454
    read_data`READ_SEL      = 4'hF ;
4455
    read_data`READ_TAG_STIM = 0 ;
4456
 
4457
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4458
 
4459
    // enable parity and system error interrupts
4460
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4461
 
4462
    // enable parity error response
4463
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4464
 
4465
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4466
 
4467
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4468
    fork
4469
    begin
4470
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4471
    end
4472
    begin:wait_perr4
4473
        perr_asserted = 0 ;
4474
        @(posedge pci_clock) ;
4475 35 mihad
        while ( PERR !== 0 )
4476 15 mihad
            @(posedge pci_clock) ;
4477
 
4478 35 mihad
        perr_asserted = 1 ;
4479 15 mihad
 
4480
    end
4481
    begin
4482
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4483
 
4484
        if ( ok !== 1 )
4485
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4486
 
4487
        repeat(2)
4488
            @(posedge pci_clock) ;
4489
 
4490 35 mihad
        #1 ;
4491
        if ( !perr_asserted )
4492
            disable wait_perr4 ;
4493 15 mihad
    end
4494
    join
4495
 
4496
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4497
    begin
4498
        $display("Parity checker testing failed! Time %t ", $time) ;
4499
        $display("Bridge failed to process single memory read!") ;
4500
        test_fail("bridge didn't process single memory read correctly") ;
4501
        ok = 0 ;
4502
    end
4503
 
4504
    if ( perr_asserted && ok )
4505
    begin
4506
        test_ok ;
4507
    end
4508
    else
4509
    if ( ~perr_asserted )
4510
    begin
4511
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4512
        disable main ;
4513
    end
4514
 
4515
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4516
    // interrupt should also be present
4517
    `ifdef HOST
4518
        repeat(4)
4519 26 mihad
            @(posedge pci_clock) ;
4520
        repeat(4)
4521 15 mihad
            @(posedge wb_clock) ;
4522
 
4523
        if ( INT_O !== 1 )
4524
        begin
4525
            $display("Parity checker testing failed! Time %t ", $time) ;
4526
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4527
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4528
        end
4529
        else
4530
            test_ok ;
4531
    `else
4532
    `ifdef GUEST
4533 26 mihad
        repeat(4)
4534
            @(posedge wb_clock) ;
4535
        repeat(4)
4536 15 mihad
            @(posedge pci_clock) ;
4537
 
4538
        if ( INTA !== 1 )
4539
        begin
4540
            $display("Parity checker testing failed! Time %t ", $time) ;
4541
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4542
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4543
        end
4544
        else
4545
            test_ok ;
4546
    `endif
4547
    `endif
4548
 
4549
    // check statuses!
4550
 
4551
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4552
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4553
    ok = 1 ;
4554
 
4555
    if ( temp_val1[31] !== 1 )
4556
    begin
4557
        $display("Parity checker testing failed! Time %t ", $time) ;
4558 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4559
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4560 15 mihad
        ok = 0 ;
4561
    end
4562
 
4563
    if ( temp_val1[30] !== 0 )
4564
    begin
4565
        $display("Parity checker testing failed! Time %t ", $time) ;
4566
        $display("Signalled System Error bit was set for no reason!") ;
4567
        test_fail("Signalled System Error bit was set for no reason") ;
4568
        ok = 0 ;
4569
    end
4570
 
4571
    if ( temp_val1[24] !== 1 )
4572
    begin
4573
        $display("Parity checker testing failed! Time %t ", $time) ;
4574 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4575
        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") ;
4576 15 mihad
        ok = 0 ;
4577
    end
4578
 
4579
    if ( ok )
4580
        test_ok ;
4581
 
4582
    // clear statuses and disable parity error response
4583
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4584
 
4585
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4586
    ok = 1 ;
4587
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4588
 
4589
    if ( temp_val1[4] !== 0 )
4590
    begin
4591
        $display("Parity checker testing failed! Time %t ", $time) ;
4592
        $display("System error interrupt status bit set for no reason!") ;
4593
        test_fail("System error interrupt status bit set for no reason") ;
4594
        ok = 0 ;
4595
    end
4596
 
4597
    `ifdef HOST
4598
    if ( temp_val1[3] !== 1 )
4599
    begin
4600
        $display("Parity checker testing failed! Time %t ", $time) ;
4601
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4602
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4603
        ok = 0 ;
4604
    end
4605
    `else
4606
    if ( temp_val1[3] !== 0 )
4607
    begin
4608
        $display("Parity checker testing failed! Time %t ", $time) ;
4609
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4610
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4611
        ok = 0 ;
4612
    end
4613
    `endif
4614
 
4615
    if ( ok )
4616
        test_ok ;
4617
 
4618
    // clear int statuses
4619
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4620
 
4621
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4622
 
4623
    `ifdef HOST
4624
        repeat(4)
4625 26 mihad
            @(posedge pci_clock) ;
4626
        repeat(4)
4627 15 mihad
            @(posedge wb_clock) ;
4628
 
4629
        if ( INT_O !== 0 )
4630
        begin
4631
            $display("Parity checker testing failed! Time %t ", $time) ;
4632
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4633
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4634
        end
4635
        else
4636
            test_ok ;
4637
    `else
4638
    `ifdef GUEST
4639 26 mihad
        repeat(4)
4640
            @(posedge wb_clock) ;
4641
        repeat(4)
4642 15 mihad
            @(posedge pci_clock) ;
4643
 
4644
        if ( INTA !== 1 )
4645
        begin
4646
            $display("Parity checker testing failed! Time %t ", $time) ;
4647
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4648
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4649
        end
4650
        else
4651
            test_ok ;
4652
    `endif
4653
    `endif
4654
 
4655
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4656
 
4657
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4658
    fork
4659
    begin
4660
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4661
    end
4662
    begin:wait_perr5
4663
        perr_asserted = 0 ;
4664
        @(posedge pci_clock) ;
4665
        while ( PERR === 1 )
4666
            @(posedge pci_clock) ;
4667
 
4668
        perr_asserted = 1 ;
4669
        $display("Parity checker testing failed! Time %t ", $time) ;
4670 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4671
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4672 15 mihad
    end
4673
    begin
4674
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4675
        if ( ok !== 1 )
4676
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4677
 
4678
        // perr can be asserted on idle or next PCI address phase
4679
        repeat(2)
4680
            @(posedge pci_clock) ;
4681
 
4682 35 mihad
        #1 ;
4683
        if ( !perr_asserted )
4684
            disable wait_perr5 ;
4685 15 mihad
    end
4686
    join
4687
 
4688
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4689
    begin
4690
        $display("Parity checker testing failed! Time %t ", $time) ;
4691
        $display("Bridge failed to process single memory read!") ;
4692
        test_fail("bridge failed to process single memory read correctly") ;
4693
        ok = 0 ;
4694
    end
4695
 
4696
    if ( ok && !perr_asserted)
4697
        test_ok ;
4698
 
4699
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4700
 
4701
    // interrupts should not be present
4702
    `ifdef HOST
4703
        repeat( 4 )
4704 26 mihad
            @(posedge pci_clock) ;
4705
        repeat( 4 )
4706 15 mihad
            @(posedge wb_clock) ;
4707
        if ( INT_O !== 0 )
4708
        begin
4709
            $display("Parity checker testing failed! Time %t ", $time) ;
4710
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4711
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4712
        end
4713
        else
4714
            test_ok ;
4715
    `else
4716
    `ifdef GUEST
4717
        repeat( 4 )
4718 26 mihad
            @(posedge wb_clock) ;
4719
        repeat( 4 )
4720 15 mihad
            @(posedge pci_clock) ;
4721
        if ( INTA !== 1 )
4722
        begin
4723
            $display("Parity checker testing failed! Time %t ", $time) ;
4724
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4725
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4726
        end
4727
        else
4728
            test_ok ;
4729
    `endif
4730
    `endif
4731
 
4732
    // check statuses!
4733
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4734
    ok = 1 ;
4735
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4736
    if ( temp_val1[31] !== 1 )
4737
    begin
4738
        $display("Parity checker testing failed! Time %t ", $time) ;
4739 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4740 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4741
        ok = 0 ;
4742
    end
4743
 
4744
    if ( temp_val1[30] !== 0 )
4745
    begin
4746
        $display("Parity checker testing failed! Time %t ", $time) ;
4747
        $display("Signalled System Error bit was set for no reason!") ;
4748
        test_fail("Signalled System Error bit was set for no reason") ;
4749
        ok = 0 ;
4750
    end
4751
 
4752
    if ( temp_val1[24] !== 0 )
4753
    begin
4754
        $display("Parity checker testing failed! Time %t ", $time) ;
4755 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4756 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4757
        ok = 0 ;
4758
    end
4759
 
4760
    if ( ok )
4761
        test_ok ;
4762
 
4763
    // clear statuses
4764
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4765
 
4766
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4767
    ok = 1 ;
4768
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4769
 
4770
    if ( temp_val1[4] !== 0 )
4771
    begin
4772
        $display("Parity checker testing failed! Time %t ", $time) ;
4773
        $display("System error interrupt status bit set for no reason!") ;
4774
        test_fail("System error interrupt status bit set for no reason") ;
4775
        ok = 0 ;
4776
    end
4777
 
4778
    if ( temp_val1[3] !== 0 )
4779
    begin
4780
        $display("Parity checker testing failed! Time %t ", $time) ;
4781
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4782
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4783
        ok = 0 ;
4784
    end
4785
 
4786
    if ( ok )
4787
        test_ok ;
4788
 
4789
    // enable all responses to parity errors!
4790
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4791
 
4792
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4793
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4794
 
4795
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4796
 
4797
    // repeat a read
4798
    fork
4799
    begin
4800
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4801
    end
4802
    begin:wait_perr6
4803
        perr_asserted = 0 ;
4804
        @(posedge pci_clock) ;
4805
        while ( PERR === 1 )
4806
            @(posedge pci_clock) ;
4807
 
4808
        perr_asserted = 1 ;
4809
        $display("Parity checker testing failed! Time %t ", $time) ;
4810
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4811
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4812
    end
4813
    begin
4814
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4815
        if ( ok !== 1 )
4816
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4817
 
4818
        repeat(2)
4819
            @(posedge pci_clock) ;
4820
 
4821 35 mihad
        #1 ;
4822
        if ( !perr_asserted )
4823
            disable wait_perr6 ;
4824 15 mihad
    end
4825
    join
4826
 
4827
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4828
    begin
4829
        $display("Parity checker testing failed! Time %t ", $time) ;
4830
        $display("Bridge failed to process single memory read!") ;
4831
        test_fail("bridge didn't process single memory read as expected") ;
4832
        ok = 0 ;
4833
    end
4834
 
4835
    if ( ok && !perr_asserted)
4836
        test_ok ;
4837
 
4838
    // check statuses!
4839
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4840
    ok = 1 ;
4841
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4842
    if ( temp_val1[31] !== 0 )
4843
    begin
4844
        $display("Parity checker testing failed! Time %t ", $time) ;
4845
        $display("Detected Parity Error bit was set for no reason!") ;
4846
        test_fail("Detected Parity Error bit was set for no reason") ;
4847
        ok = 0 ;
4848
    end
4849
 
4850
    if ( temp_val1[30] !== 0 )
4851
    begin
4852
        $display("Parity checker testing failed! Time %t ", $time) ;
4853
        $display("Signalled System Error bit was set for no reason!") ;
4854
        test_fail("Signalled System Error bit was set for no reason") ;
4855
        ok = 0 ;
4856
    end
4857
 
4858
    if ( temp_val1[24] !== 0 )
4859
    begin
4860
        $display("Parity checker testing failed! Time %t ", $time) ;
4861
        $display("Master Data Parity Error bit was set for no reason!") ;
4862
        test_fail("Master Data Parity Error bit was set for no reason") ;
4863
        ok = 0 ;
4864
    end
4865
 
4866
    if ( ok )
4867
        test_ok ;
4868
 
4869
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4870
    ok = 1 ;
4871
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4872
 
4873
    if ( temp_val1[4] !== 0 )
4874
    begin
4875
        $display("Parity checker testing failed! Time %t ", $time) ;
4876
        $display("System error interrupt status bit set for no reason!") ;
4877
        test_fail("System error interrupt status bit set for no reason") ;
4878
        ok = 0 ;
4879
    end
4880
 
4881
    if ( temp_val1[3] !== 0 )
4882
    begin
4883
        $display("Parity checker testing failed! Time %t ", $time) ;
4884
        $display("Parity error interrupt status bit set for no reason!") ;
4885
        test_fail("Parity error interrupt status bit set for no reason") ;
4886
        ok = 0 ;
4887
    end
4888
 
4889
    if ( ok )
4890
        test_ok ;
4891
 
4892
    $display("Presenting address parity error on PCI bus!") ;
4893
    // enable parity errors - this should not affect system errors
4894
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4895
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4896
 
4897
    // perform PCI write
4898
    // check transaction progress
4899
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4900
    fork
4901
    begin
4902
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4903
               target_address, 32'h1234_5678,
4904
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4905
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4906
        do_pause( 1 ) ;
4907
    end
4908
    begin:wait_serr7
4909
        perr_asserted = 0 ;
4910
        @(posedge pci_clock) ;
4911
        while( SERR === 1 )
4912
            @(posedge pci_clock) ;
4913
 
4914
        perr_asserted = 1 ;
4915
        $display("Parity checker testing failed! Time %t ", $time) ;
4916
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4917
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4918
    end
4919
    begin
4920
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4921
        if ( ok !== 1 )
4922
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4923
 
4924 35 mihad
        if ( !perr_asserted )
4925
            disable wait_serr7 ;
4926 15 mihad
    end
4927
    join
4928
 
4929
    if ( ok && !perr_asserted)
4930
        test_ok ;
4931
 
4932
    // check statuses!
4933
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4934
    ok = 1 ;
4935
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4936
    if ( temp_val1[31] !== 1 )
4937
    begin
4938
        $display("Parity checker testing failed! Time %t ", $time) ;
4939
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4940
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4941
        ok = 0 ;
4942
    end
4943
 
4944
    if ( temp_val1[30] !== 0 )
4945
    begin
4946
        $display("Parity checker testing failed! Time %t ", $time) ;
4947
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4948
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4949
        ok = 0 ;
4950
    end
4951
 
4952
    if ( temp_val1[24] !== 0 )
4953
    begin
4954
        $display("Parity checker testing failed! Time %t ", $time) ;
4955
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4956
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4957
        ok = 0 ;
4958
    end
4959
 
4960
    if ( ok )
4961
        test_ok ;
4962
 
4963
    // clear statuses
4964
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4965
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4966
    fork
4967
    begin
4968
        ipci_unsupported_commands_master.master_reference
4969
        (
4970
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4971
            32'h5555_5555,      // second part of address in dual address cycle
4972
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4973
            `BC_MEM_WRITE,      // normal command
4974
            4'h0,               // byte enables
4975
            32'h1234_5678,      // data
4976
            1'b1,               // make address parity error on first phase of dual address
4977
            1'b0,               // make address parity error on second phase of dual address
4978
            ok                  // result of operation
4979
        ) ;
4980 35 mihad
        if ( !perr_asserted )
4981
            disable wait_serr8 ;
4982 15 mihad
    end
4983
    begin:wait_serr8
4984
        perr_asserted = 0 ;
4985
        @(posedge pci_clock) ;
4986
        while( SERR === 1 )
4987
            @(posedge pci_clock) ;
4988
 
4989
        perr_asserted = 1 ;
4990
        $display("Parity checker testing failed! Time %t ", $time) ;
4991
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4992
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4993
    end
4994
    join
4995
 
4996
    if ( ok && !perr_asserted)
4997
        test_ok ;
4998
 
4999
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5000
    fork
5001
    begin
5002
        ipci_unsupported_commands_master.master_reference
5003
        (
5004
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5005
            32'h5555_5555,      // second part of address in dual address cycle
5006
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5007
            `BC_MEM_WRITE,      // normal command
5008
            4'h0,               // byte enables
5009
            32'h1234_5678,      // data
5010
            1'b0,               // make address parity error on first phase of dual address
5011
            1'b1,               // make address parity error on second phase of dual address
5012
            ok                  // result of operation
5013
        ) ;
5014 35 mihad
        if ( !perr_asserted )
5015
            disable wait_serr9 ;
5016 15 mihad
    end
5017
    begin:wait_serr9
5018
        perr_asserted = 0 ;
5019
        @(posedge pci_clock) ;
5020
        while( SERR === 1 )
5021
            @(posedge pci_clock) ;
5022
 
5023
        perr_asserted = 1 ;
5024
        $display("Parity checker testing failed! Time %t ", $time) ;
5025
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5026
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5027
    end
5028
    join
5029
 
5030
    if ( ok && !perr_asserted)
5031
        test_ok ;
5032
 
5033
    // check statuses!
5034
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5035
    ok = 1 ;
5036
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5037
    if ( temp_val1[31] !== 1 )
5038
    begin
5039
        $display("Parity checker testing failed! Time %t ", $time) ;
5040
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5041
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5042
        ok = 0 ;
5043
    end
5044
 
5045
    if ( temp_val1[30] !== 0 )
5046
    begin
5047
        $display("Parity checker testing failed! Time %t ", $time) ;
5048
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5049
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5050
        ok = 0 ;
5051
    end
5052
 
5053
    if ( temp_val1[24] !== 0 )
5054
    begin
5055
        $display("Parity checker testing failed! Time %t ", $time) ;
5056
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5057
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5058
        ok = 0 ;
5059
    end
5060
 
5061
    if ( ok )
5062
        test_ok ;
5063
 
5064
    // clear statuses
5065
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5066
 
5067
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5068
    fork
5069
    begin
5070
        ipci_unsupported_commands_master.master_reference
5071
        (
5072
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5073
            32'h5555_5555,      // second part of address in dual address cycle
5074
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5075
            `BC_MEM_WRITE,      // normal command
5076
            4'h0,               // byte enables
5077
            32'h1234_5678,      // data
5078
            1'b1,               // make address parity error on first phase of dual address
5079
            1'b1,               // make address parity error on second phase of dual address
5080
            ok                  // result of operation
5081
        ) ;
5082 35 mihad
        if ( !perr_asserted )
5083
            disable wait_serr10 ;
5084 15 mihad
    end
5085
    begin:wait_serr10
5086
        perr_asserted = 0 ;
5087
        @(posedge pci_clock) ;
5088
        while( SERR === 1 )
5089
            @(posedge pci_clock) ;
5090
 
5091
        perr_asserted = 1 ;
5092
        $display("Parity checker testing failed! Time %t ", $time) ;
5093
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5094
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5095
    end
5096
    join
5097
 
5098
    if ( ok && !perr_asserted)
5099
        test_ok ;
5100
 
5101
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5102
 
5103
    `ifdef HOST
5104
        repeat(4)
5105 26 mihad
            @(posedge pci_clock) ;
5106
        repeat(4)
5107 15 mihad
            @(posedge wb_clock) ;
5108
        if ( INT_O !== 0 )
5109
        begin
5110
            $display("Parity checker testing failed! Time %t ", $time) ;
5111
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5112
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5113
        end
5114
        else
5115
            test_ok ;
5116
    `else
5117
    `ifdef GUEST
5118 26 mihad
        repeat(4)
5119
            @(posedge wb_clock) ;
5120
        repeat(4)
5121 15 mihad
            @(posedge pci_clock) ;
5122
 
5123
        if ( INTA !== 1 )
5124
        begin
5125
            $display("Parity checker testing failed! Time %t ", $time) ;
5126
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5127
            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") ;
5128
        end
5129
        else
5130
            test_ok ;
5131
    `endif
5132
    `endif
5133
 
5134
    // check statuses!
5135
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5136
    ok = 1 ;
5137
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5138
    if ( temp_val1[31] !== 1 )
5139
    begin
5140
        $display("Parity checker testing failed! Time %t ", $time) ;
5141
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5142
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5143
        ok = 0 ;
5144
    end
5145
 
5146
    if ( temp_val1[30] !== 0 )
5147
    begin
5148
        $display("Parity checker testing failed! Time %t ", $time) ;
5149
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5150
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5151
        ok = 0 ;
5152
    end
5153
 
5154
    if ( temp_val1[24] !== 0 )
5155
    begin
5156
        $display("Parity checker testing failed! Time %t ", $time) ;
5157
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5158
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5159
        ok = 0 ;
5160
    end
5161
 
5162
    if ( ok )
5163
        test_ok ;
5164
 
5165
    // clear statuses
5166
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5167
 
5168
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5169
    ok = 1 ;
5170
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5171
 
5172
    if ( temp_val1[4] !== 0 )
5173
    begin
5174
        $display("Parity checker testing failed! Time %t ", $time) ;
5175
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5176
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5177
        ok = 0 ;
5178
    end
5179
 
5180
    if ( temp_val1[3] !== 0 )
5181
    begin
5182
        $display("Parity checker testing failed! Time %t ", $time) ;
5183
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5184
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5185
        ok = 0 ;
5186
    end
5187
 
5188
    if ( ok )
5189
        test_ok ;
5190
 
5191
    // now enable system error signaling and test response
5192
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5193
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5194
 
5195
    fork
5196
    begin
5197
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5198
               target_address, 32'h1234_5678,
5199
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5200
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5201
        do_pause( 1 ) ;
5202
    end
5203
    begin:wait_serr11
5204
        perr_asserted = 0 ;
5205
        @(posedge pci_clock) ;
5206 35 mihad
        while( SERR !== 0 )
5207 15 mihad
            @(posedge pci_clock) ;
5208
 
5209 35 mihad
        perr_asserted = 1 ;
5210 15 mihad
    end
5211
    begin
5212
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5213
        if ( ok !== 1 )
5214
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5215
 
5216
        @(posedge pci_clock) ;
5217 35 mihad
        #1 ;
5218
        if ( !perr_asserted )
5219
            disable wait_serr11 ;
5220 15 mihad
    end
5221
    join
5222
 
5223
    if ( ok && perr_asserted)
5224
        test_ok ;
5225
    else
5226
    if ( !perr_asserted )
5227
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5228
 
5229
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5230
 
5231
    `ifdef HOST
5232
        repeat(4)
5233 26 mihad
            @(posedge pci_clock) ;
5234
        repeat(4)
5235 15 mihad
            @(posedge wb_clock) ;
5236
        if ( INT_O !== 1 )
5237
        begin
5238
            $display("Parity checker testing failed! Time %t ", $time) ;
5239
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5240
            test_fail("Interrupt Request was not triggered as expected") ;
5241
        end
5242
        else
5243
            test_ok ;
5244
    `else
5245
    `ifdef GUEST
5246 26 mihad
        repeat(4)
5247
            @(posedge wb_clock) ;
5248
        repeat(4)
5249 15 mihad
            @(posedge pci_clock) ;
5250
 
5251
        if ( INTA !== 1 )
5252
        begin
5253
            $display("Parity checker testing failed! Time %t ", $time) ;
5254
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5255
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5256
        end
5257
        else
5258
            test_ok ;
5259
    `endif
5260
    `endif
5261
 
5262
    // check statuses!
5263
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5264
    ok = 1 ;
5265
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5266
    if ( temp_val1[31] !== 1 )
5267
    begin
5268
        $display("Parity checker testing failed! Time %t ", $time) ;
5269
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5270
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5271
        ok = 0 ;
5272
    end
5273
 
5274
    if ( temp_val1[30] !== 1 )
5275
    begin
5276
        $display("Parity checker testing failed! Time %t ", $time) ;
5277
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5278
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5279
        ok = 0 ;
5280
    end
5281
 
5282
    if ( temp_val1[24] !== 0 )
5283
    begin
5284
        $display("Parity checker testing failed! Time %t ", $time) ;
5285
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5286
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5287
        ok = 0 ;
5288
    end
5289
 
5290
    if ( ok )
5291
        test_ok ;
5292
 
5293
    // clear statuses
5294
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5295
 
5296
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5297
 
5298
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5299
    ok = 1 ;
5300
 
5301
    `ifdef HOST
5302
    if ( temp_val1[4] !== 1 )
5303
    begin
5304
        $display("Parity checker testing failed! Time %t ", $time) ;
5305
        $display("System error interrupt status bit not set when expected!") ;
5306
        test_fail("System error interrupt status bit not set when expected") ;
5307
        ok = 0 ;
5308
    end
5309
    `else
5310
    if ( temp_val1[4] !== 0 )
5311
    begin
5312
        $display("Parity checker testing failed! Time %t ", $time) ;
5313
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5314
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5315
        ok = 0 ;
5316
    end
5317
    `endif
5318
 
5319
    if ( temp_val1[3] !== 0 )
5320
    begin
5321
        $display("Parity checker testing failed! Time %t ", $time) ;
5322
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5323
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5324
        ok = 0 ;
5325
    end
5326
 
5327
    if ( ok )
5328
        test_ok ;
5329
 
5330
    // clear statuses
5331
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5332
 
5333
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5334
    fork
5335
    begin
5336
        ipci_unsupported_commands_master.master_reference
5337
        (
5338
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5339
            32'h5555_5555,      // second part of address in dual address cycle
5340
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5341
            `BC_MEM_WRITE,      // normal command
5342
            4'h0,               // byte enables
5343
            32'h1234_5678,      // data
5344
            1'b1,               // make address parity error on first phase of dual address
5345
            1'b0,               // make address parity error on second phase of dual address
5346
            ok                  // result of operation
5347
        ) ;
5348 35 mihad
        if ( !perr_asserted )
5349
            disable wait_serr14 ;
5350 15 mihad
    end
5351
    begin:wait_serr14
5352
        perr_asserted = 0 ;
5353
        @(posedge pci_clock) ;
5354 35 mihad
        while( SERR !== 0 )
5355 15 mihad
            @(posedge pci_clock) ;
5356
 
5357 35 mihad
        perr_asserted = 1 ;
5358 15 mihad
    end
5359
    join
5360
 
5361
    if ( ok && perr_asserted)
5362
        test_ok ;
5363
    else
5364
    if ( !perr_asserted )
5365
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5366
 
5367
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5368
 
5369
    `ifdef HOST
5370
        repeat(4)
5371 26 mihad
            @(posedge pci_clock) ;
5372
        repeat(4)
5373 15 mihad
            @(posedge wb_clock) ;
5374
        if ( INT_O !== 1 )
5375
        begin
5376
            $display("Parity checker testing failed! Time %t ", $time) ;
5377
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5378
            test_fail("Interrupt Request was not triggered as expected") ;
5379
        end
5380
        else
5381
            test_ok ;
5382
    `else
5383
    `ifdef GUEST
5384 26 mihad
        repeat(4)
5385
            @(posedge wb_clock) ;
5386
        repeat(4)
5387 15 mihad
            @(posedge pci_clock) ;
5388
 
5389
        if ( INTA !== 1 )
5390
        begin
5391
            $display("Parity checker testing failed! Time %t ", $time) ;
5392
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5393
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5394
        end
5395
        else
5396
            test_ok ;
5397
    `endif
5398
    `endif
5399
 
5400
    // check statuses!
5401
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5402
    ok = 1 ;
5403
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5404
    if ( temp_val1[31] !== 1 )
5405
    begin
5406
        $display("Parity checker testing failed! Time %t ", $time) ;
5407
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5408
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5409
        ok = 0 ;
5410
    end
5411
 
5412
    if ( temp_val1[30] !== 1 )
5413
    begin
5414
        $display("Parity checker testing failed! Time %t ", $time) ;
5415
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5416
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5417
        ok = 0 ;
5418
    end
5419
 
5420
    if ( temp_val1[24] !== 0 )
5421
    begin
5422
        $display("Parity checker testing failed! Time %t ", $time) ;
5423
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5424
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5425
        ok = 0 ;
5426
    end
5427
 
5428
    if ( ok )
5429
        test_ok ;
5430
 
5431
    // clear statuses
5432
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5433
 
5434
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5435
 
5436
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5437
    ok = 1 ;
5438
 
5439
    `ifdef HOST
5440
    if ( temp_val1[4] !== 1 )
5441
    begin
5442
        $display("Parity checker testing failed! Time %t ", $time) ;
5443
        $display("System error interrupt status bit not set when expected!") ;
5444
        test_fail("System error interrupt status bit not set when expected") ;
5445
        ok = 0 ;
5446
    end
5447
    `else
5448
    if ( temp_val1[4] !== 0 )
5449
    begin
5450
        $display("Parity checker testing failed! Time %t ", $time) ;
5451
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5452
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5453
        ok = 0 ;
5454
    end
5455
    `endif
5456
 
5457
    if ( temp_val1[3] !== 0 )
5458
    begin
5459
        $display("Parity checker testing failed! Time %t ", $time) ;
5460
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5461
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5462
        ok = 0 ;
5463
    end
5464
 
5465
    if ( ok )
5466
        test_ok ;
5467
 
5468
    // clear statuses
5469
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5470
 
5471
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5472
    fork
5473
    begin
5474
        ipci_unsupported_commands_master.master_reference
5475
        (
5476
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5477
            32'h5555_5555,      // second part of address in dual address cycle
5478
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5479
            `BC_MEM_WRITE,      // normal command
5480
            4'h0,               // byte enables
5481
            32'h1234_5678,      // data
5482
            1'b0,               // make address parity error on first phase of dual address
5483
            1'b1,               // make address parity error on second phase of dual address
5484
            ok                  // result of operation
5485
        ) ;
5486 35 mihad
        if ( !perr_asserted )
5487
            disable wait_serr15 ;
5488 15 mihad
    end
5489
    begin:wait_serr15
5490
        perr_asserted = 0 ;
5491
        @(posedge pci_clock) ;
5492 35 mihad
        while( SERR !== 0 )
5493 15 mihad
            @(posedge pci_clock) ;
5494
 
5495 35 mihad
        perr_asserted = 1 ;
5496 15 mihad
    end
5497
    join
5498
 
5499
    if ( ok && perr_asserted)
5500
        test_ok ;
5501
    else
5502
    if ( !perr_asserted )
5503
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5504
 
5505
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5506
 
5507
    `ifdef HOST
5508
        repeat(4)
5509 26 mihad
            @(posedge pci_clock) ;
5510
        repeat(4)
5511 15 mihad
            @(posedge wb_clock) ;
5512
        if ( INT_O !== 1 )
5513
        begin
5514
            $display("Parity checker testing failed! Time %t ", $time) ;
5515
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5516
            test_fail("Interrupt Request was not triggered as expected") ;
5517
        end
5518
        else
5519
            test_ok ;
5520
    `else
5521
    `ifdef GUEST
5522 26 mihad
        repeat(4)
5523
            @(posedge wb_clock) ;
5524
        repeat(4)
5525 15 mihad
            @(posedge pci_clock) ;
5526
 
5527
        if ( INTA !== 1 )
5528
        begin
5529
            $display("Parity checker testing failed! Time %t ", $time) ;
5530
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5531
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5532
        end
5533
        else
5534
            test_ok ;
5535
    `endif
5536
    `endif
5537
 
5538
    // check statuses!
5539
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5540
    ok = 1 ;
5541
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5542
    if ( temp_val1[31] !== 1 )
5543
    begin
5544
        $display("Parity checker testing failed! Time %t ", $time) ;
5545
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5546
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5547
        ok = 0 ;
5548
    end
5549
 
5550
    if ( temp_val1[30] !== 1 )
5551
    begin
5552
        $display("Parity checker testing failed! Time %t ", $time) ;
5553
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5554
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5555
        ok = 0 ;
5556
    end
5557
 
5558
    if ( temp_val1[24] !== 0 )
5559
    begin
5560
        $display("Parity checker testing failed! Time %t ", $time) ;
5561
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5562
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5563
        ok = 0 ;
5564
    end
5565
 
5566
    if ( ok )
5567
        test_ok ;
5568
 
5569
    // clear statuses
5570
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5571
 
5572
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5573
 
5574
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5575
    ok = 1 ;
5576
 
5577
    `ifdef HOST
5578
    if ( temp_val1[4] !== 1 )
5579
    begin
5580
        $display("Parity checker testing failed! Time %t ", $time) ;
5581
        $display("System error interrupt status bit not set when expected!") ;
5582
        test_fail("System error interrupt status bit not set when expected") ;
5583
        ok = 0 ;
5584
    end
5585
    `else
5586
    if ( temp_val1[4] !== 0 )
5587
    begin
5588
        $display("Parity checker testing failed! Time %t ", $time) ;
5589
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5590
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5591
        ok = 0 ;
5592
    end
5593
    `endif
5594
 
5595
    if ( temp_val1[3] !== 0 )
5596
    begin
5597
        $display("Parity checker testing failed! Time %t ", $time) ;
5598
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5599
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5600
        ok = 0 ;
5601
    end
5602
 
5603
    if ( ok )
5604
        test_ok ;
5605
 
5606
    // clear statuses
5607
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5608
 
5609
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5610
    fork
5611
    begin
5612
        ipci_unsupported_commands_master.master_reference
5613
        (
5614
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5615
            32'h5555_5555,      // second part of address in dual address cycle
5616
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5617
            `BC_MEM_WRITE,      // normal command
5618
            4'h0,               // byte enables
5619
            32'h1234_5678,      // data
5620
            1'b1,               // make address parity error on first phase of dual address
5621
            1'b1,               // make address parity error on second phase of dual address
5622
            ok                  // result of operation
5623
        ) ;
5624 35 mihad
        if ( !perr_asserted )
5625
            disable wait_serr16 ;
5626 15 mihad
    end
5627
    begin:wait_serr16
5628
        perr_asserted = 0 ;
5629
        @(posedge pci_clock) ;
5630 35 mihad
        while( SERR !== 0 )
5631 15 mihad
            @(posedge pci_clock) ;
5632
 
5633 35 mihad
        perr_asserted = 1 ;
5634 15 mihad
    end
5635
    join
5636
 
5637
    if ( ok && perr_asserted)
5638
        test_ok ;
5639
    else
5640
    if ( !perr_asserted )
5641
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5642
 
5643
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5644
 
5645
    `ifdef HOST
5646
        repeat(4)
5647 26 mihad
            @(posedge pci_clock) ;
5648
        repeat(4)
5649 15 mihad
            @(posedge wb_clock) ;
5650
        if ( INT_O !== 1 )
5651
        begin
5652
            $display("Parity checker testing failed! Time %t ", $time) ;
5653
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5654
            test_fail("Interrupt Request was not triggered as expected") ;
5655
        end
5656
        else
5657
            test_ok ;
5658
    `else
5659
    `ifdef GUEST
5660 26 mihad
        repeat(4)
5661
            @(posedge wb_clock) ;
5662
        repeat(4)
5663 15 mihad
            @(posedge pci_clock) ;
5664
 
5665
        if ( INTA !== 1 )
5666
        begin
5667
            $display("Parity checker testing failed! Time %t ", $time) ;
5668
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5669
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5670
        end
5671
        else
5672
            test_ok ;
5673
    `endif
5674
    `endif
5675
 
5676
    // check statuses!
5677
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5678
    ok = 1 ;
5679
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5680
    if ( temp_val1[31] !== 1 )
5681
    begin
5682
        $display("Parity checker testing failed! Time %t ", $time) ;
5683
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5684
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5685
        ok = 0 ;
5686
    end
5687
 
5688
    if ( temp_val1[30] !== 1 )
5689
    begin
5690
        $display("Parity checker testing failed! Time %t ", $time) ;
5691
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5692
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5693
        ok = 0 ;
5694
    end
5695
 
5696
    if ( temp_val1[24] !== 0 )
5697
    begin
5698
        $display("Parity checker testing failed! Time %t ", $time) ;
5699
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5700
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5701
        ok = 0 ;
5702
    end
5703
 
5704
    if ( ok )
5705
        test_ok ;
5706
 
5707
    // clear statuses
5708
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5709
 
5710
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5711
 
5712
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5713
    ok = 1 ;
5714
 
5715
    `ifdef HOST
5716
    if ( temp_val1[4] !== 1 )
5717
    begin
5718
        $display("Parity checker testing failed! Time %t ", $time) ;
5719
        $display("System error interrupt status bit not set when expected!") ;
5720
        test_fail("System error interrupt status bit not set when expected") ;
5721
        ok = 0 ;
5722
    end
5723
    `else
5724
    if ( temp_val1[4] !== 0 )
5725
    begin
5726
        $display("Parity checker testing failed! Time %t ", $time) ;
5727
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5728
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5729
        ok = 0 ;
5730
    end
5731
    `endif
5732
 
5733
    if ( temp_val1[3] !== 0 )
5734
    begin
5735
        $display("Parity checker testing failed! Time %t ", $time) ;
5736
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5737
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5738
        ok = 0 ;
5739
    end
5740
 
5741
    if ( ok )
5742
        test_ok ;
5743
 
5744
    // clear statuses
5745
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5746
 
5747
    // now just disable Parity Error response - on Address par errors nothing should happen
5748
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5749
 
5750
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5751
    fork
5752
    begin
5753
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5754
               target_address, 32'h1234_5678,
5755
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5756
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5757
        do_pause( 1 ) ;
5758
    end
5759
    begin:wait_serr12
5760
        perr_asserted = 0 ;
5761
        @(posedge pci_clock) ;
5762
        while( SERR === 1 )
5763
            @(posedge pci_clock) ;
5764
 
5765
        perr_asserted = 1 ;
5766
        $display("Parity checker testing failed! Time %t ", $time) ;
5767
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5768
        test_fail("SERR asserted when parity error response was disabled") ;
5769
    end
5770
    begin
5771
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5772
        if ( ok !== 1 )
5773
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5774
 
5775 35 mihad
        @(posedge pci_clock) ;
5776
        #1 ;
5777
        if ( !perr_asserted )
5778
            disable wait_serr12 ;
5779 15 mihad
    end
5780
    join
5781
 
5782
    if ( ok && !perr_asserted )
5783
        test_ok ;
5784
 
5785
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5786
    `ifdef HOST
5787 26 mihad
        repeat (4)
5788
            @(posedge pci_clock) ;
5789 15 mihad
        repeat(4)
5790
            @(posedge wb_clock) ;
5791
        if ( INT_O !== 0 )
5792
        begin
5793
            $display("Parity checker testing failed! Time %t ", $time) ;
5794
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5795
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5796
        end
5797
        else
5798
            test_ok ;
5799
    `else
5800
    `ifdef GUEST
5801 26 mihad
        repeat(4)
5802
            @(posedge wb_clock) ;
5803
        repeat (4)
5804 15 mihad
            @(posedge pci_clock) ;
5805
 
5806
        if ( INTA !== 1 )
5807
        begin
5808
            $display("Parity checker testing failed! Time %t ", $time) ;
5809
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5810
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5811
        end
5812
        else
5813
            test_ok ;
5814
    `endif
5815
    `endif
5816
 
5817
    // check statuses!
5818
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5819
    ok = 1 ;
5820
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5821
    if ( temp_val1[31] !== 1 )
5822
    begin
5823
        $display("Parity checker testing failed! Time %t ", $time) ;
5824
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5825
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5826
        ok = 0 ;
5827
    end
5828
 
5829
    if ( temp_val1[30] !== 0 )
5830
    begin
5831
        $display("Parity checker testing failed! Time %t ", $time) ;
5832
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5833
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5834
        ok = 0 ;
5835
    end
5836
 
5837
    if ( temp_val1[24] !== 0 )
5838
    begin
5839
        $display("Parity checker testing failed! Time %t ", $time) ;
5840
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5841
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5842
        ok = 0 ;
5843
    end
5844
 
5845
    if ( ok )
5846
        test_ok ;
5847
 
5848
    // clear statuses
5849
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5850
 
5851
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5852
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5853
    ok = 1 ;
5854
    if ( temp_val1[4] !== 0 )
5855
    begin
5856
        $display("Parity checker testing failed! Time %t ", $time) ;
5857
        $display("System error interrupt status bit set when not expected!") ;
5858
        test_fail("System error interrupt status bit set when not expected") ;
5859
        ok = 0 ;
5860
    end
5861
 
5862
    if ( temp_val1[3] !== 0 )
5863
    begin
5864
        $display("Parity checker testing failed! Time %t ", $time) ;
5865
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5866
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5867
        ok = 0 ;
5868
    end
5869
 
5870
    if ( ok )
5871
        test_ok ;
5872
 
5873
    // clear statuses
5874
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5875
 
5876
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5877
    fork
5878
    begin
5879
        ipci_unsupported_commands_master.master_reference
5880
        (
5881
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5882
            32'h5555_5555,      // second part of address in dual address cycle
5883
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5884
            `BC_MEM_WRITE,      // normal command
5885
            4'h0,               // byte enables
5886
            32'h1234_5678,      // data
5887
            1'b1,               // make address parity error on first phase of dual address
5888
            1'b0,               // make address parity error on second phase of dual address
5889
            ok                  // result of operation
5890
        ) ;
5891 35 mihad
        if ( !perr_asserted )
5892
            disable wait_serr17 ;
5893 15 mihad
    end
5894
    begin:wait_serr17
5895
        perr_asserted = 0 ;
5896
        @(posedge pci_clock) ;
5897
        while( SERR === 1 )
5898
            @(posedge pci_clock) ;
5899
 
5900
        perr_asserted = 1 ;
5901
        $display("Parity checker testing failed! Time %t ", $time) ;
5902
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5903
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5904
    end
5905
    join
5906
 
5907
    if ( ok && !perr_asserted)
5908
        test_ok ;
5909
 
5910
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5911
    fork
5912
    begin
5913
        ipci_unsupported_commands_master.master_reference
5914
        (
5915
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5916
            32'h5555_5555,      // second part of address in dual address cycle
5917
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5918
            `BC_MEM_WRITE,      // normal command
5919
            4'h0,               // byte enables
5920
            32'h1234_5678,      // data
5921
            1'b0,               // make address parity error on first phase of dual address
5922
            1'b1,               // make address parity error on second phase of dual address
5923
            ok                  // result of operation
5924
        ) ;
5925 35 mihad
        if ( !perr_asserted )
5926
            disable wait_serr18 ;
5927 15 mihad
    end
5928
    begin:wait_serr18
5929
        perr_asserted = 0 ;
5930
        @(posedge pci_clock) ;
5931
        while( SERR === 1 )
5932
            @(posedge pci_clock) ;
5933
 
5934
        perr_asserted = 1 ;
5935
        $display("Parity checker testing failed! Time %t ", $time) ;
5936
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5937
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5938
    end
5939
    join
5940
 
5941
    if ( ok && !perr_asserted)
5942
        test_ok ;
5943
 
5944
    // check statuses!
5945
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5946
    ok = 1 ;
5947
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5948
    if ( temp_val1[31] !== 1 )
5949
    begin
5950
        $display("Parity checker testing failed! Time %t ", $time) ;
5951
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5952
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5953
        ok = 0 ;
5954
    end
5955
 
5956
    if ( temp_val1[30] !== 0 )
5957
    begin
5958
        $display("Parity checker testing failed! Time %t ", $time) ;
5959
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5960
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5961
        ok = 0 ;
5962
    end
5963
 
5964
    if ( temp_val1[24] !== 0 )
5965
    begin
5966
        $display("Parity checker testing failed! Time %t ", $time) ;
5967
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5968
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5969
        ok = 0 ;
5970
    end
5971
 
5972
    if ( ok )
5973
        test_ok ;
5974
 
5975
    // clear statuses
5976
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5977
 
5978
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5979
    fork
5980
    begin
5981
        ipci_unsupported_commands_master.master_reference
5982
        (
5983
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5984
            32'h5555_5555,      // second part of address in dual address cycle
5985
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5986
            `BC_MEM_WRITE,      // normal command
5987
            4'h0,               // byte enables
5988
            32'h1234_5678,      // data
5989
            1'b1,               // make address parity error on first phase of dual address
5990
            1'b1,               // make address parity error on second phase of dual address
5991
            ok                  // result of operation
5992
        ) ;
5993 35 mihad
        if ( !perr_asserted )
5994
            disable wait_serr19 ;
5995 15 mihad
    end
5996
    begin:wait_serr19
5997
        perr_asserted = 0 ;
5998
        @(posedge pci_clock) ;
5999
        while( SERR === 1 )
6000
            @(posedge pci_clock) ;
6001
 
6002
        perr_asserted = 1 ;
6003
        $display("Parity checker testing failed! Time %t ", $time) ;
6004
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
6005
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6006
    end
6007
    join
6008
 
6009
    if ( ok && !perr_asserted)
6010
        test_ok ;
6011
 
6012
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
6013
 
6014
    `ifdef HOST
6015
        repeat(4)
6016 26 mihad
            @(posedge pci_clock) ;
6017
        repeat(4)
6018 15 mihad
            @(posedge wb_clock) ;
6019
        if ( INT_O !== 0 )
6020
        begin
6021
            $display("Parity checker testing failed! Time %t ", $time) ;
6022
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
6023
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
6024
        end
6025
        else
6026
            test_ok ;
6027
    `else
6028
    `ifdef GUEST
6029 26 mihad
        repeat(4)
6030
            @(posedge wb_clock) ;
6031
        repeat(4)
6032 15 mihad
            @(posedge pci_clock) ;
6033
 
6034
        if ( INTA !== 1 )
6035
        begin
6036
            $display("Parity checker testing failed! Time %t ", $time) ;
6037
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
6038
            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") ;
6039
        end
6040
        else
6041
            test_ok ;
6042
    `endif
6043
    `endif
6044
 
6045
    // check statuses!
6046
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6047
    ok = 1 ;
6048
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6049
    if ( temp_val1[31] !== 1 )
6050
    begin
6051
        $display("Parity checker testing failed! Time %t ", $time) ;
6052
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6053
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6054
        ok = 0 ;
6055
    end
6056
 
6057
    if ( temp_val1[30] !== 0 )
6058
    begin
6059
        $display("Parity checker testing failed! Time %t ", $time) ;
6060
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6061
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6062
        ok = 0 ;
6063
    end
6064
 
6065
    if ( temp_val1[24] !== 0 )
6066
    begin
6067
        $display("Parity checker testing failed! Time %t ", $time) ;
6068
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6069
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6070
        ok = 0 ;
6071
    end
6072
 
6073
    if ( ok )
6074
        test_ok ;
6075
 
6076
    // clear statuses
6077
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6078
 
6079
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
6080
 
6081
    // do normal write
6082
    fork
6083
    begin
6084
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
6085
               target_address, 32'h1234_5678, `Test_All_Bytes,
6086
               1, 8'h3_0, `Test_One_Zero_Target_WS,
6087
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6088
        do_pause( 1 ) ;
6089
    end
6090
    begin:wait_serr13
6091
        perr_asserted = 0 ;
6092
        @(posedge pci_clock) ;
6093
        while( SERR === 1 )
6094
            @(posedge pci_clock) ;
6095
 
6096
        perr_asserted = 1 ;
6097
        $display("Parity checker testing failed! Time %t ", $time) ;
6098
        $display("SERR asserted for no reason!") ;
6099
        test_fail("SERR was asserted for no reason") ;
6100
    end
6101
    begin
6102
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6103
        if ( ok !== 1 )
6104
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6105
 
6106 35 mihad
        @(posedge pci_clock) ;
6107
        #1 ;
6108
        if ( !perr_asserted )
6109
            disable wait_serr13 ;
6110 15 mihad
    end
6111
    join
6112
 
6113
    if ( ok && !perr_asserted )
6114
        test_ok ;
6115
 
6116
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6117
    `ifdef HOST
6118 26 mihad
        repeat( 4 )
6119
            @(posedge pci_clock) ;
6120 15 mihad
        repeat(4)
6121
            @(posedge wb_clock) ;
6122
        if ( INT_O !== 0 )
6123
        begin
6124
            $display("Parity checker testing failed! Time %t ", $time) ;
6125
            $display("Interrupt request asserted for no reason!") ;
6126
            test_fail("Interrupt request was asserted for no reason") ;
6127
        end
6128
        else
6129
            test_ok ;
6130
    `else
6131
    `ifdef GUEST
6132 26 mihad
        repeat(4)
6133
            @(posedge wb_clock) ;
6134
        repeat(4)
6135 15 mihad
            @(posedge pci_clock) ;
6136
 
6137
        if ( INTA !== 1 )
6138
        begin
6139
            $display("Parity checker testing failed! Time %t ", $time) ;
6140
            $display("Interrupt request asserted for no reason!") ;
6141
            test_fail("Interrupt request was asserted for no reason") ;
6142
        end
6143
        else
6144
            test_ok ;
6145
    `endif
6146
    `endif
6147
 
6148
    // check statuses!
6149
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6150
    ok = 1 ;
6151
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6152
    if ( temp_val1[31] !== 0 )
6153
    begin
6154
        $display("Parity checker testing failed! Time %t ", $time) ;
6155
        $display("Detected Parity Error bit was set for no reason!") ;
6156
        test_fail("Detected Parity Error bit was set for no reason") ;
6157
        ok = 0 ;
6158
    end
6159
 
6160
    if ( temp_val1[30] !== 0 )
6161
    begin
6162
        $display("Parity checker testing failed! Time %t ", $time) ;
6163
        $display("Signalled System Error bit was set for no reason!") ;
6164
        test_fail("Signalled System Error bit was set for no reason") ;
6165
        ok = 0 ;
6166
    end
6167
 
6168
    if ( temp_val1[24] !== 0 )
6169
    begin
6170
        $display("Parity checker testing failed! Time %t ", $time) ;
6171
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6172
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6173
        ok = 0 ;
6174
    end
6175
 
6176
    if ( ok )
6177
        test_ok ;
6178
 
6179
    // clear statuses
6180
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6181
 
6182
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6183
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6184
    ok = 1 ;
6185
 
6186
    if ( temp_val1[4] !== 0 )
6187
    begin
6188
        $display("Parity checker testing failed! Time %t ", $time) ;
6189
        $display("System error interrupt status bit set when not expected!") ;
6190
        test_fail("System error interrupt status bit set when not expected") ;
6191
        ok = 0 ;
6192
    end
6193
 
6194
    if ( temp_val1[3] !== 0 )
6195
    begin
6196
        $display("Parity checker testing failed! Time %t ", $time) ;
6197
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6198
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6199
        ok = 0 ;
6200
    end
6201
 
6202
    if ( ok )
6203
        test_ok ;
6204
 
6205
    // clear statuses
6206
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6207
 
6208
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6209
 
6210
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6211
 
6212
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6213
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6214
 
6215
    // setup target's image!
6216
    target_address  = Target_Base_Addr_R[1] ;
6217
 
6218
    // base address
6219
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6220
 
6221
    // address mask
6222
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6223
 
6224
    // image control
6225
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6226
 
6227
    // enable everything possible for parity checking
6228
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6229
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6230
 
6231
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6232
 
6233
    fork
6234
    begin
6235
        if ( target_mem_image === 1 )
6236
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6237
                   target_address, 32'h1234_5678,
6238
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6239
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6240
        else
6241
            PCIU_IO_WRITE_MAKE_PERR (
6242
                                    `Test_Master_1,
6243
                                    target_address,
6244
                                    32'h1234_5678,
6245
                                    4'h0,
6246
                                    1,
6247
                                    `Test_Target_Normal_Completion
6248
                                    );
6249
 
6250
        do_pause( 1 ) ;
6251
    end
6252
    begin:wait_perr11
6253
        perr_asserted = 0 ;
6254
        @(posedge pci_clock) ;
6255 35 mihad
        while ( PERR !== 0 )
6256 15 mihad
            @(posedge pci_clock) ;
6257
 
6258 35 mihad
        perr_asserted = 1 ;
6259 15 mihad
 
6260
    end
6261
    begin
6262
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6263
 
6264
        if ( ok !== 1 )
6265
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6266
 
6267
        repeat(2)
6268
            @(posedge pci_clock) ;
6269
 
6270 35 mihad
        #1 ;
6271
        if ( !perr_asserted )
6272
            disable wait_perr11 ;
6273 15 mihad
    end
6274
    join
6275
 
6276
    if ( ok && perr_asserted )
6277
        test_ok ;
6278
    else
6279
    if ( !perr_asserted )
6280
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6281
 
6282
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6283
    `ifdef HOST
6284 26 mihad
        repeat (4)
6285
            @(posedge pci_clock) ;
6286 15 mihad
        repeat(4)
6287
            @(posedge wb_clock) ;
6288
        if ( INT_O !== 0 )
6289
        begin
6290
            $display("Parity checker testing failed! Time %t ", $time) ;
6291
            $display("Interrupt request asserted for no reason!") ;
6292
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6293
        end
6294
        else
6295
            test_ok ;
6296
    `else
6297
    `ifdef GUEST
6298 26 mihad
        repeat(4)
6299
            @(posedge wb_clock) ;
6300
        repeat (4)
6301 15 mihad
            @(posedge pci_clock) ;
6302
 
6303
        if ( INTA !== 1 )
6304
        begin
6305
            $display("Parity checker testing failed! Time %t ", $time) ;
6306
            $display("Interrupt request asserted for no reason!") ;
6307
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6308
        end
6309
        else
6310
            test_ok ;
6311
 
6312
    `endif
6313
    `endif
6314
 
6315
    // check statuses!
6316
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6317
    ok = 1 ;
6318
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6319
    if ( temp_val1[31] !== 1 )
6320
    begin
6321
        $display("Parity checker testing failed! Time %t ", $time) ;
6322 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6323
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6324 15 mihad
        ok = 0 ;
6325
    end
6326
 
6327
    if ( temp_val1[30] !== 0 )
6328
    begin
6329
        $display("Parity checker testing failed! Time %t ", $time) ;
6330
        $display("Signalled System Error bit was set for no reason!") ;
6331
        test_fail("Signalled System Error bit was set for no reason") ;
6332
        ok = 0 ;
6333
    end
6334
 
6335
    if ( temp_val1[24] !== 0 )
6336
    begin
6337
        $display("Parity checker testing failed! Time %t ", $time) ;
6338
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6339
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6340
        ok = 0 ;
6341
    end
6342
 
6343
    if ( ok )
6344
        test_ok ;
6345
 
6346
    // clear statuses
6347
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6348
 
6349
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6350
 
6351
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6352
    ok = 1 ;
6353
    if ( temp_val1[4] !== 0 )
6354
    begin
6355
        $display("Parity checker testing failed! Time %t ", $time) ;
6356
        $display("System error interrupt status bit set when not expected!") ;
6357
        test_fail("System error interrupt status bit set when not expected") ;
6358
        ok = 0 ;
6359
    end
6360
 
6361
    if ( temp_val1[3] !== 0 )
6362
    begin
6363
        $display("Parity checker testing failed! Time %t ", $time) ;
6364
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6365
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6366
        ok = 0 ;
6367
    end
6368
 
6369
    if ( ok )
6370
        test_ok ;
6371
 
6372
    // clear statuses
6373
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6374
 
6375
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6376
 
6377
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6378
    fork
6379
    begin
6380
        if ( target_mem_image === 1 )
6381
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6382
                          target_address, 32'h1234_5678,
6383
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6384
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6385
        else
6386
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6387
 
6388
        do_pause( 1 ) ;
6389
    end
6390
    begin:wait_perr12
6391
        perr_asserted = 0 ;
6392
        @(posedge pci_clock) ;
6393 35 mihad
        while ( PERR !== 0 )
6394 15 mihad
            @(posedge pci_clock) ;
6395
 
6396 35 mihad
        perr_asserted = 1 ;
6397 15 mihad
    end
6398
    begin
6399
 
6400
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6401
        if ( ok !== 1 )
6402
        begin
6403
            test_fail("Bridge failed to process Target Memory read correctly") ;
6404
            disable main ;
6405
        end
6406
 
6407
        repeat(3)
6408
            @(posedge pci_clock) ;
6409
 
6410
        if ( target_mem_image === 1 )
6411
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6412
                    target_address, 32'h1234_5678,
6413
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6414
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6415
        else
6416
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6417
 
6418
        do_pause( 1 ) ;
6419
 
6420
    end
6421
    begin
6422
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6423
        if ( ok !== 1 )
6424
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6425
        else
6426
        begin
6427
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6428
            if ( ok !== 1 )
6429
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6430
        end
6431
 
6432 35 mihad
        repeat(2)
6433 15 mihad
            @(posedge pci_clock) ;
6434
 
6435 35 mihad
        #1 ;
6436
        if ( !perr_asserted )
6437
            disable wait_perr12 ;
6438 15 mihad
    end
6439
    join
6440
 
6441
    if ( ok && perr_asserted )
6442
        test_ok ;
6443
    else
6444
    if ( !perr_asserted )
6445
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6446
 
6447
 
6448
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6449
    `ifdef HOST
6450
        repeat(4)
6451 26 mihad
            @(posedge pci_clock) ;
6452
        repeat(4)
6453 15 mihad
            @(posedge wb_clock) ;
6454
        if ( INT_O !== 0 )
6455
        begin
6456
            $display("Parity checker testing failed! Time %t ", $time) ;
6457
            $display("Interrupt request asserted for no reason!") ;
6458
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6459
        end
6460
        else
6461
            test_ok ;
6462
    `else
6463
    `ifdef GUEST
6464 26 mihad
        repeat(4)
6465
            @(posedge wb_clock) ;
6466
        repeat(4)
6467 15 mihad
            @(posedge pci_clock) ;
6468
 
6469
        if ( INTA !== 1 )
6470
        begin
6471
            $display("Parity checker testing failed! Time %t ", $time) ;
6472
            $display("Interrupt request asserted for no reason!") ;
6473
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6474
        end
6475
        else
6476
            test_ok ;
6477
    `endif
6478
    `endif
6479
 
6480
    // check statuses!
6481
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6482
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6483
    ok = 1 ;
6484 45 mihad
    if ( temp_val1[31] !== 0 )
6485 15 mihad
    begin
6486
        $display("Parity checker testing failed! Time %t ", $time) ;
6487 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6488
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6489 15 mihad
        ok = 0 ;
6490
    end
6491
 
6492
    if ( temp_val1[30] !== 0 )
6493
    begin
6494
        $display("Parity checker testing failed! Time %t ", $time) ;
6495
        $display("Signalled System Error bit was set for no reason!") ;
6496
        test_fail("Signalled System Error bit was set for no reason") ;
6497
        ok = 0 ;
6498
    end
6499
 
6500
    if ( temp_val1[24] !== 0 )
6501
    begin
6502
        $display("Parity checker testing failed! Time %t ", $time) ;
6503
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6504
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6505
        ok = 0 ;
6506
    end
6507
 
6508
    if ( ok )
6509
        test_ok ;
6510
 
6511
    // clear statuses
6512
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6513
 
6514
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6515
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6516
    ok = 1 ;
6517
    if ( temp_val1[4] !== 0 )
6518
    begin
6519
        $display("Parity checker testing failed! Time %t ", $time) ;
6520
        $display("System error interrupt status bit set when not expected!") ;
6521
        test_fail("System error interrupt status bit set when not expected") ;
6522
        ok = 0 ;
6523
    end
6524
 
6525
    if ( temp_val1[3] !== 0 )
6526
    begin
6527
        $display("Parity checker testing failed! Time %t ", $time) ;
6528
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6529
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6530
        ok = 0 ;
6531
    end
6532
 
6533
    if ( ok )
6534
        test_ok ;
6535
    // clear statuses
6536
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6537
 
6538
    $fdisplay(pci_mon_log_file_desc,
6539
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6540
    test_name = "DISABLE USED IMAGES" ;
6541
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6542
    if ( ok !== 1 )
6543
    begin
6544
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6545
        test_fail("WB Image Address Mask register could not be written to") ;
6546
        disable main ;
6547
    end
6548
 
6549 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6550 15 mihad
    if ( ok !== 1 )
6551
    begin
6552
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6553
        test_fail("PCI Image Address Mask register could not be written to") ;
6554
        disable main ;
6555
    end
6556
 
6557
    // disable target's 1 response to parity errors
6558 45 mihad
    configuration_cycle_write(0,                        // bus number
6559
                              `TAR1_IDSEL_INDEX - 11,   // device number
6560
                              0,                        // function number
6561
                              1,                        // register number
6562
                              0,                        // type of configuration cycle
6563
                              4'b0001,                  // byte enables
6564
                              32'h0000_0007             // data
6565 15 mihad
                             ) ;
6566
 
6567
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6568
end
6569
endtask // parity_checking
6570
 
6571
task wb_to_pci_transactions ;
6572
    reg   [11:0] ctrl_offset ;
6573
    reg   [11:0] ba_offset ;
6574
    reg   [11:0] am_offset ;
6575
    reg   [11:0] pci_ctrl_offset ;
6576
    reg   [11:0] err_cs_offset ;
6577
    reg   [11:0] icr_offset ;
6578
    reg   [11:0] isr_offset ;
6579
    reg   [11:0] lat_tim_cls_offset ;
6580
 
6581
    reg `WRITE_STIM_TYPE  write_data ;
6582
    reg `READ_STIM_TYPE   read_data ;
6583
    reg `READ_RETURN_TYPE read_status ;
6584
 
6585
    reg `WRITE_RETURN_TYPE write_status ;
6586
    reg `WB_TRANSFER_FLAGS write_flags ;
6587
    reg [31:0] temp_val1 ;
6588
    reg [31:0] temp_val2 ;
6589
    reg        ok   ;
6590
 
6591
    reg [31:0] image_base ;
6592
    reg [31:0] target_address ;
6593
    integer i ;
6594
    integer required_reads ;
6595
    integer writes_left ;
6596
 
6597
begin:main
6598
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6599
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6600
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6601
    pci_ctrl_offset    = 12'h4 ;
6602
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6603
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6604
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6605
    lat_tim_cls_offset = 12'hC ;
6606
 
6607
    $display("Checking WB to PCI transaction lengths!") ;
6608
    target_address  = `BEH_TAR1_MEM_START ;
6609
    image_base      = 0 ;
6610
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6611
 
6612
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6613
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6614
    write_flags                    = 0 ;
6615
    write_flags`INIT_WAITS         = tb_init_waits ;
6616
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6617
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6618
 
6619
    // enable master & target operation
6620
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6621
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6622
    if ( ok !== 1 )
6623
    begin
6624
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6625
        test_fail("write to PCI Device Control register failed") ;
6626
        disable main ;
6627
    end
6628
 
6629
    // prepare image control register
6630
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6631
    if ( ok !== 1 )
6632
    begin
6633
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6634
        test_fail("write to WB Image Control register failed") ;
6635
        disable main ;
6636
    end
6637
 
6638
    // prepare base address register
6639
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6640
    if ( ok !== 1 )
6641
    begin
6642
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6643
        test_fail("write to WB Base Address register failed") ;
6644
        disable main ;
6645
    end
6646
 
6647
    // write address mask register
6648
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6649
    if ( ok !== 1 )
6650
    begin
6651
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6652
        test_fail("write to WB Address Mask register failed") ;
6653
        disable main ;
6654
    end
6655
 
6656
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6657
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6658
    if ( ok !== 1 )
6659
    begin
6660
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6661
        test_fail("write to WB Error Control and Status register failed") ;
6662
        disable main ;
6663
    end
6664
 
6665
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6666
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6667
    if ( ok !== 1 )
6668
    begin
6669
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6670
        test_fail("write to Interrupt Control register failed") ;
6671
        disable main ;
6672
    end
6673
 
6674
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6675
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6676
    if ( ok !== 1 )
6677
    begin
6678
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6679
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6680
        disable main ;
6681
    end
6682
 
6683
    $display("Testing single write transaction progress from WB to PCI!") ;
6684
    write_data`WRITE_ADDRESS = target_address ;
6685
    write_data`WRITE_DATA    = wmem_data[0] ;
6686
    write_data`WRITE_SEL     = 4'hF ;
6687
 
6688
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6689
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6690
 
6691
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6692
    fork
6693
    begin
6694
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6695
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6696
        begin
6697
            $display("Transaction progress testing failed! Time %t ", $time) ;
6698
            $display("Bridge failed to process single memory write!") ;
6699
            test_fail("bridge failed to post single memory write") ;
6700
            disable main ;
6701
        end
6702
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6703
    end
6704
    begin
6705
        // wait two retries, then enable target response
6706
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6707
        if ( ok !== 1 )
6708
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6709
        else
6710
            test_ok ;
6711
 
6712
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6713
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6714
        if ( ok !== 1 )
6715
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6716
        else
6717
            test_ok ;
6718
 
6719
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6720
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6721
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6722
 
6723
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6724
        if ( ok !== 1 )
6725
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6726
        else
6727
            test_ok ;
6728
    end
6729
    join
6730
 
6731
    $display("Testing burst write transaction progress from WB to PCI!") ;
6732
    write_data`WRITE_ADDRESS = target_address ;
6733
    write_data`WRITE_DATA    = wmem_data[0] ;
6734
    write_data`WRITE_SEL     = 4'hF ;
6735
 
6736
    wishbone_master.blk_write_data[0] = write_data ;
6737
 
6738
    write_data`WRITE_ADDRESS = target_address + 4 ;
6739
    write_data`WRITE_DATA    = wmem_data[1] ;
6740
    write_data`WRITE_SEL     = 4'hF ;
6741
 
6742
    wishbone_master.blk_write_data[1] = write_data ;
6743
 
6744
    write_flags`WB_TRANSFER_SIZE = 2 ;
6745
    write_flags`WB_TRANSFER_CAB  = 1 ;
6746
 
6747
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6748
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6749
 
6750
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6751
 
6752
    fork
6753
    begin
6754
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6755
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6756
        begin
6757
            $display("Transaction progress testing failed! Time %t ", $time) ;
6758
            $display("Bridge failed to process whole CAB memory write!") ;
6759
            test_fail("bridge failed to post whole CAB memory write") ;
6760
            disable main ;
6761
        end
6762
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6763
    end
6764
    begin
6765
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6766
        if ( ok !== 1 )
6767
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6768
        else
6769
            test_ok ;
6770
 
6771
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6772
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6773
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6774
 
6775
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6776
        if ( ok !== 1 )
6777
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6778
        else
6779
            test_ok ;
6780
 
6781
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6782
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6783
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6784
 
6785
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6786
        if ( ok !== 1 )
6787
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6788
        else
6789
            test_ok ;
6790
    end
6791
    join
6792
 
6793
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6794
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6795
 
6796
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6797
    // try same write with other terminations
6798
    fork
6799
    begin
6800
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6801
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6802
        begin
6803
            $display("Transaction progress testing failed! Time %t ", $time) ;
6804
            $display("Bridge failed to process whole CAB memory write!") ;
6805
            test_fail("bridge failed to post whole CAB memory write") ;
6806
            disable main ;
6807
        end
6808
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6809
    end
6810
    begin
6811
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6812
        if ( ok !== 1 )
6813
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6814
        else
6815
            test_ok ;
6816
 
6817
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6818
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6819
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6820
 
6821
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6822
        if ( ok !== 1 )
6823
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6824
        else
6825
            test_ok ;
6826
    end
6827
    join
6828
 
6829
    // repeat the write with normal completion
6830
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6831
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6832
 
6833
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6834
    fork
6835
    begin
6836
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6837
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6838
        begin
6839
            $display("Transaction progress testing failed! Time %t ", $time) ;
6840
            $display("Bridge failed to process whole CAB memory write!") ;
6841
            test_fail("bridge failed to post whole CAB memory write") ;
6842
            disable main ;
6843
        end
6844
    end
6845
    begin
6846
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6847
        if ( ok !== 1 )
6848
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6849
        else
6850
            test_ok ;
6851
    end
6852
    join
6853
 
6854
    // do the same thing with burst length of 3
6855
    write_data`WRITE_ADDRESS = target_address + 8 ;
6856
    write_data`WRITE_DATA    = wmem_data[2] ;
6857
    write_data`WRITE_SEL     = 4'hF ;
6858
 
6859
    wishbone_master.blk_write_data[2] = write_data ;
6860
 
6861
    write_flags`WB_TRANSFER_SIZE = 3 ;
6862
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6863
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6864
 
6865
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6866
 
6867
    fork
6868
    begin
6869
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6870
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6871
        begin
6872
            $display("Transaction progress testing failed! Time %t ", $time) ;
6873
            $display("Bridge failed to process whole CAB memory write!") ;
6874
            test_fail("bridge failed to post whole CAB memory write") ;
6875
            disable main ;
6876
        end
6877
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6878
    end
6879
    begin
6880
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6881
        if ( ok !== 1 )
6882
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6883
        else
6884
            test_ok ;
6885
 
6886
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6887
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6888
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6889
 
6890
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6891
        if ( ok !== 1 )
6892
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6893
        else
6894
            test_ok ;
6895
    end
6896
    join
6897
 
6898
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6899
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6900
 
6901
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6902
    fork
6903
    begin
6904
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6905
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6906
        begin
6907
            $display("Transaction progress testing failed! Time %t ", $time) ;
6908
            $display("Bridge failed to process whole CAB memory write!") ;
6909
            test_fail("bridge failed to post whole CAB memory write") ;
6910
            disable main ;
6911
        end
6912
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6913
    end
6914
    begin
6915
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6916
        if ( ok !== 1 )
6917
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6918
        else
6919
            test_ok ;
6920
 
6921
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6922
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6923
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6924
 
6925
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6926
        if ( ok !== 1 )
6927
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6928
        else
6929
            test_ok ;
6930
 
6931
    end
6932
    join
6933
 
6934
    // repeat with normal completion
6935
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6936
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6937
 
6938
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6939
    fork
6940
    begin
6941
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6942
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6943
        begin
6944
            $display("Transaction progress testing failed! Time %t ", $time) ;
6945
            $display("Bridge failed to process whole CAB memory write!") ;
6946
            test_fail("bridge failed to post whole CAB memory write") ;
6947
            disable main ;
6948
        end
6949
    end
6950
    begin
6951
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6952
        if ( ok !== 1 )
6953
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6954
        else
6955
            test_ok ;
6956
 
6957
    end
6958
    join
6959
 
6960
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6961
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6962
    begin
6963
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6964
        write_data`WRITE_DATA    = wmem_data[i] ;
6965
        write_data`WRITE_SEL     = 4'hF ;
6966
 
6967
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6968
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6969
 
6970
        wishbone_master.blk_write_data[i]   = write_data ;
6971
        wishbone_master.blk_read_data_in[i] = read_data ;
6972
    end
6973
 
6974
    write_flags`WB_TRANSFER_CAB      = 1 ;
6975
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6976
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6977
 
6978
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6979
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6980
 
6981
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6982
    fork
6983
    begin
6984
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6985
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6986
        begin
6987
            $display("Transaction progress testing failed! Time %t ", $time) ;
6988
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6989
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6990
            test_fail("bridge failed to post whole CAB memory write") ;
6991
            disable main ;
6992
        end
6993
 
6994
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6995
 
6996
        // read here just checks if data was transfered OK
6997
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6998
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6999
 
7000
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7001
 
7002
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7003
        begin
7004
            $display("Transaction progress testing failed! Time %t ", $time) ;
7005
            $display("Bridge processed CAB read wrong!") ;
7006
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
7007
        end
7008
 
7009
    end
7010
    begin
7011
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7012
        if ( ok !== 1 )
7013
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7014
        else
7015
            test_ok ;
7016
 
7017
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
7018
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7019
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7020
 
7021
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7022
        if ( ok !== 1 )
7023
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7024
        else
7025
            test_ok ;
7026
 
7027
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
7028
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
7029
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7030
 
7031
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7032
        if ( ok !== 1 )
7033
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7034
        else
7035
            test_ok ;
7036
 
7037
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
7038
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7039
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7040
 
7041
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7042
        if ( ok !== 1 )
7043
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7044
        else
7045
            test_ok ;
7046
 
7047
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
7048
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7049
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7050
 
7051
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
7052
        if ( ok !== 1 )
7053
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7054
        else
7055
            test_ok ;
7056
 
7057
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
7058
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
7059
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
7060
        for ( i = 0 ; i < required_reads ; i = i + 1 )
7061
        begin
7062
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7063
            if ( ok !== 1 )
7064
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7065
        end
7066
    end
7067
    join
7068
 
7069
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
7070
    begin
7071
        read_status = wishbone_master.blk_read_data_out[i] ;
7072
        if (read_status`READ_DATA !== wmem_data[i])
7073
        begin
7074
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
7075
            test_fail("data read from target wasn't the same as data written to it") ;
7076
            ok = 0 ;
7077
        end
7078
    end
7079
 
7080
    if ( ok )
7081
        test_ok ;
7082
 
7083
    $display("Testing single read transaction progress from WB to PCI!") ;
7084
    read_data`READ_ADDRESS = target_address + 8 ;
7085
    read_data`READ_SEL     = 4'hF ;
7086
 
7087
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7088
 
7089
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
7090
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7091
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7092
 
7093
    fork
7094
    begin
7095
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7096
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7097
        begin
7098
            $display("Transaction progress testing failed! Time %t ", $time) ;
7099
            $display("Bridge processed single read wrong!") ;
7100
            test_fail("bridge processed single read wrong") ;
7101
            disable main ;
7102
        end
7103
 
7104
        if (read_status`READ_DATA !== wmem_data[2])
7105
        begin
7106
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7107
            test_fail("data returned from single read was not as expected") ;
7108
        end
7109
        else
7110
        if ( ok )
7111
            test_ok ;
7112
    end
7113
    begin
7114
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7115
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7116
 
7117
        if ( ok !== 1 )
7118
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7119
 
7120
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7121
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7122
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7123
 
7124
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7125
        if ( ok !== 1 )
7126
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7127
    end
7128
    join
7129
 
7130
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7131
 
7132
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7133
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7134
 
7135
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7136
    // first fill target's memory with enough data to fill WBR_FIFO
7137
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7138
    begin
7139
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7140
        write_data`WRITE_DATA    = wmem_data[i] ;
7141
        write_data`WRITE_SEL     = 4'hF ;
7142
 
7143
        wishbone_master.blk_write_data[i] = write_data ;
7144
    end
7145
 
7146
    write_flags`WB_TRANSFER_CAB = 1 ;
7147
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7148
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7149
 
7150
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7151
 
7152
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7153
    begin
7154
        $display("Transaction progress testing failed! Time %t ", $time) ;
7155
        $display("Bridge processed CAB write wrong!") ;
7156
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7157
        disable main ;
7158
    end
7159
 
7160
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7161
    // perform single read to force write data to pci
7162
    read_data`READ_ADDRESS = target_address + 8;
7163
    read_data`READ_SEL     = 4'hF ;
7164
 
7165
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7166
 
7167
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7168
    begin
7169
        $display("Transaction progress testing failed! Time %t ", $time) ;
7170
        $display("Bridge processed single read wrong!") ;
7171
        test_fail("bridge didn't process single memory read as expected") ;
7172
        disable main ;
7173
    end
7174
 
7175
    wishbone_master.blk_read_data_in[0] = read_data ;
7176
 
7177
    read_data`READ_ADDRESS = target_address + 12 ;
7178
    read_data`READ_SEL     = 4'hF ;
7179
 
7180
    wishbone_master.blk_read_data_in[1] = read_data ;
7181
 
7182
    read_data`READ_ADDRESS = target_address + 16 ;
7183
    read_data`READ_SEL     = 4'hF ;
7184
 
7185
    wishbone_master.blk_read_data_in[2] = read_data ;
7186
 
7187
    write_flags`WB_TRANSFER_CAB  = 1 ;
7188
    write_flags`WB_TRANSFER_SIZE = 2 ;
7189
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7190
    read_status = 0 ;
7191
 
7192
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7193
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7194
 
7195
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7196
 
7197
    ok = 1 ;
7198
    fork
7199
    begin
7200
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7201
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7202
 
7203
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7204
        begin
7205
            $display("Transaction progress testing failed! Time %t ", $time) ;
7206
            $display("Bridge processed CAB read wrong!") ;
7207
            test_fail("bridge didn't process disconnected burst read as expected") ;
7208
        end
7209
        else
7210
        begin
7211
 
7212
            read_status = wishbone_master.blk_read_data_out[0] ;
7213
 
7214
            if (read_status`READ_DATA !== wmem_data[2])
7215
            begin
7216
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7217
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7218
            end
7219
            else
7220
                test_ok ;
7221
        end
7222
 
7223
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7224
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7225
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7226
 
7227
        read_status = 0 ;
7228
 
7229
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7230
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7231
 
7232
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7233
        begin
7234
            $display("Transaction progress testing failed! Time %t ", $time) ;
7235
            $display("Bridge processed CAB read wrong!") ;
7236
            test_fail("bridge didn't process disconnected burst read as expected") ;
7237
        end
7238
        else
7239
        begin
7240
 
7241
            read_status = wishbone_master.blk_read_data_out[0] ;
7242
 
7243
            if (read_status`READ_DATA !== wmem_data[3])
7244
            begin
7245
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7246
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7247
            end
7248
            else
7249
                test_ok ;
7250
        end
7251
 
7252
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7253
        // complete delayed read which was requested
7254
        read_data = wishbone_master.blk_read_data_in[2] ;
7255
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7256
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7257
 
7258
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7259
        begin
7260
            $display("Transaction progress testing failed! Time %t ", $time) ;
7261
            $display("Bridge processed single out of burst read wrong!") ;
7262
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7263
        end
7264
        else
7265
        begin
7266
 
7267
            if (read_status`READ_DATA !== wmem_data[4])
7268
            begin
7269
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7270
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7271
            end
7272
            else
7273
                test_ok ;
7274
        end
7275
 
7276
    end
7277
    begin
7278
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7279
 
7280
        if ( ok !== 1 )
7281
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7282
 
7283
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7284
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7285
 
7286
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7287
        if ( ok !== 1 )
7288
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7289
 
7290
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7291
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7292
 
7293
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7294
        if ( ok !== 1 )
7295
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7296
    end
7297
    join
7298
 
7299
    // now try burst read with normal termination
7300
    read_data`READ_ADDRESS = target_address + 12 ;
7301
    read_data`READ_SEL     = 4'hF ;
7302
 
7303
    wishbone_master.blk_read_data_in[0] = read_data ;
7304
 
7305
    read_data`READ_ADDRESS = target_address + 16 ;
7306
    read_data`READ_SEL     = 4'hF ;
7307
 
7308
    wishbone_master.blk_read_data_in[1] = read_data ;
7309
 
7310
    write_flags`WB_TRANSFER_SIZE = 2 ;
7311
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7312
    write_flags`WB_TRANSFER_CAB = 1 ;
7313
 
7314
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7315
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7316
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7317
 
7318
    fork
7319
    begin
7320
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7321
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7322
        begin
7323
            $display("Transaction progress testing failed! Time %t ", $time) ;
7324
            $display("Bridge processed CAB read wrong!") ;
7325
            test_fail("bridge didn't process burst read as expected") ;
7326
            ok = 0 ;
7327
        end
7328
    end
7329
    begin
7330
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7331
        if ( ok !== 1 )
7332
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7333
    end
7334
    join
7335
 
7336
    if ( ok )
7337
    begin
7338
        read_status = wishbone_master.blk_read_data_out[0] ;
7339
        if ( read_status`READ_DATA !== wmem_data[3] )
7340
        begin
7341
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7342
            test_fail("data provided from normaly terminated read was wrong") ;
7343
            ok = 0 ;
7344
        end
7345
 
7346
        read_status = wishbone_master.blk_read_data_out[1] ;
7347
        if ( read_status`READ_DATA !== wmem_data[4] )
7348
        begin
7349
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7350
            test_fail("data provided from normaly terminated read was wrong") ;
7351
            ok = 0 ;
7352
        end
7353
    end
7354
 
7355
    if ( ok )
7356
        test_ok ;
7357
 
7358
    // disable memory read line command and enable prefetch
7359
    // prepare image control register
7360
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7361
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7362
    if ( ok !== 1 )
7363
    begin
7364
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7365
        test_fail("WB Image Control register couldn't be written to") ;
7366
        disable main ;
7367
    end
7368
 
7369
    write_flags`WB_TRANSFER_SIZE = 4 ;
7370
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7371
    write_flags`WB_TRANSFER_CAB = 1 ;
7372
 
7373
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7374
 
7375
    for ( i = 0 ; i < 4 ; i = i + 1 )
7376
    begin
7377
        read_data`READ_ADDRESS = target_address + i*4 ;
7378
        read_data`READ_SEL     = 4'b1010 ;
7379
 
7380
        wishbone_master.blk_read_data_in[i] = read_data ;
7381
    end
7382
 
7383
    fork
7384
    begin
7385
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7386
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7387
        begin
7388
            $display("Transaction progress testing failed! Time %t ", $time) ;
7389
            $display("Bridge processed CAB read wrong!") ;
7390
            test_fail("bridge didn't process prefetched burst read as expected") ;
7391
            ok = 0 ;
7392
        end
7393
    end
7394
    begin
7395
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7396
        if ( ok !== 1 )
7397
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7398
    end
7399
    join
7400
 
7401
    if ( ok )
7402
    begin
7403
        for ( i = 0 ; i < 4 ; i = i + 1 )
7404
        begin
7405
            read_status = wishbone_master.blk_read_data_out[i] ;
7406
            if ( read_status`READ_DATA !== wmem_data[i] )
7407
            begin
7408
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7409
                test_fail("burst read returned unexpected data") ;
7410
                ok = 0 ;
7411
            end
7412
        end
7413
    end
7414
 
7415
    if ( ok )
7416
        test_ok ;
7417
 
7418
    // do one single read with different byte enables
7419
    read_data`READ_ADDRESS = target_address + 4 ;
7420
    read_data`READ_SEL     = 4'b1010 ;
7421
 
7422
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7423
    fork
7424
    begin
7425
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7426
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7427
        begin
7428
            $display("Transaction progress testing failed! Time %t ", $time) ;
7429
            $display("Bridge processed single read wrong!") ;
7430
            test_fail("bridge didn't process single memory read as expected") ;
7431
            ok = 0 ;
7432
        end
7433
    end
7434
    begin
7435
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7436
        if ( ok !== 1 )
7437
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7438
    end
7439
    join
7440
 
7441
    // check read data
7442
    if ( ok )
7443
    begin
7444
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7445
        begin
7446
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7447
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7448
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7449
            ok = 0 ;
7450
            test_fail("unexpected data received from single read") ;
7451
        end
7452
    end
7453
 
7454
    if ( ok )
7455
         test_ok ;
7456
 
7457
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7458
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7459
 
7460
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7461
    if ( ok !== 1 )
7462
    begin
7463
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7464
        test_fail("WB Image Control register could not be written") ;
7465
        disable main ;
7466
    end
7467
 
7468
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7469
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7470
    begin
7471
        read_data`READ_ADDRESS = target_address + i*4 ;
7472
        read_data`READ_SEL     = 4'b1111 ;
7473
 
7474
        wishbone_master.blk_read_data_in[i] = read_data ;
7475
    end
7476
 
7477
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7478
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7479
    write_flags`WB_TRANSFER_CAB = 1 ;
7480
 
7481
    fork
7482
    begin
7483
        read_status         = 0 ;
7484
        read_status`CYC_RTY = 1 ;
7485
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7486
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7487
 
7488
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7489
        begin
7490
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7491
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7492
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7493
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7494
            ok = 0 ;
7495
        end
7496
    end
7497
    begin
7498
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7499
        if ( ok !== 1 )
7500
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7501
    end
7502
    join
7503
 
7504
    // now repeat single read to flush redundant read initiated
7505
    write_flags`WB_TRANSFER_SIZE = 1 ;
7506
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7507
    write_flags`WB_TRANSFER_CAB = 1 ;
7508
 
7509
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7510
    read_data`READ_SEL     = 4'hF ;
7511
 
7512
    wishbone_master.blk_read_data_in[0] = read_data ;
7513
 
7514
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7515
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7516
 
7517
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7518
    begin
7519
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7520
        $display(" PCI bridge failed to process single CAB read!") ;
7521
        test_fail("single CAB write was not processed as expected") ;
7522
    end
7523
 
7524
    // because last read could be very long on PCI - delete target abort status
7525
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7526
 
7527
    // write unsupported value to cache line size register
7528
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7529
 
7530
    read_data`READ_ADDRESS = target_address ;
7531
    read_data`READ_SEL     = 4'hF ;
7532
    wishbone_master.blk_read_data_in[0] = read_data ;
7533
 
7534
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7535
    // perform a read
7536
    fork
7537
    begin
7538
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7539
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7540
        begin
7541
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7542
            $display(" PCI bridge failed to process single CAB read!") ;
7543
            test_fail("burst read was not processed as expected") ;
7544
            ok = 0 ;
7545
        end
7546
    end
7547
    begin
7548
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7549
        if ( ok !== 1 )
7550
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7551
    end
7552
    join
7553
 
7554
    if ( ok )
7555
        test_ok ;
7556
 
7557
    // write 2 to cache line size register
7558
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7559
 
7560
    // perform a read
7561
    fork
7562
    begin
7563
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7564
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7565
        begin
7566
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7567
            $display(" PCI bridge failed to process single CAB read!") ;
7568
            test_fail("burst read was not processed as expected") ;
7569
            ok = 0 ;
7570
        end
7571
    end
7572
    begin
7573
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7574
        if ( ok !== 1 )
7575
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7576
    end
7577
    join
7578
 
7579
    if ( ok )
7580
        test_ok ;
7581
 
7582
    // write 0 to cache line size
7583
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7584
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7585
 
7586
    // perform a read
7587
    fork
7588
    begin
7589
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7590
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7591
        begin
7592
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7593
            $display(" PCI bridge failed to process single CAB read!") ;
7594
            test_fail("burst read was not processed as expected") ;
7595
            ok = 0 ;
7596
        end
7597
    end
7598
    begin
7599
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7600
        if ( ok !== 1 )
7601
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7602
    end
7603
    join
7604
 
7605
    if ( ok )
7606
        test_ok ;
7607
 
7608
    // write normal value to cls register
7609
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7610
 
7611
    $display("Testing Master's latency timer operation!") ;
7612
    $display("Testing Latency timer during Master Writes!") ;
7613
 
7614
    for ( i = 0 ; i < 6 ; i = i + 1 )
7615
    begin
7616
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7617
        write_data`WRITE_SEL     = 4'b1111 ;
7618
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7619
 
7620
        wishbone_master.blk_write_data[i] = write_data ;
7621
    end
7622
 
7623
    write_flags`WB_TRANSFER_SIZE = 6 ;
7624
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7625
    write_flags`WB_TRANSFER_CAB = 1 ;
7626
 
7627
    // start wb write, pci write and monitor in parallel
7628
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7629
    fork
7630
    begin
7631
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7632
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7633
        begin
7634
            $display("Transaction progress testing failed! Time %t ", $time) ;
7635
            $display("Bridge failed to process CAB write!") ;
7636
            test_fail("bridge didn't post whole burst memory write") ;
7637
            disable main ;
7638
        end
7639
    end
7640
    begin
7641
        // wait for bridge's master to start transaction
7642
        @(posedge pci_clock) ;
7643
        while ( FRAME === 1 )
7644
            @(posedge pci_clock) ;
7645
 
7646
        // start behavioral master request
7647
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7648
               target_address, wmem_data[1023], `Test_All_Bytes,
7649
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7650
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7651
 
7652
        do_pause ( 1 ) ;
7653
    end
7654
    begin
7655
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7656
        if ( ok !== 1 )
7657
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7658
        else
7659
            test_ok ;
7660
    end
7661
    join
7662
 
7663
    // perform a read to check data
7664
    for ( i = 0 ; i < 6 ; i = i + 1 )
7665
    begin
7666
        read_data`READ_ADDRESS = target_address + i*4 ;
7667
        read_data`READ_SEL     = 4'b1111 ;
7668
 
7669
        wishbone_master.blk_read_data_in[i] = read_data ;
7670
    end
7671
 
7672
    write_flags`WB_TRANSFER_SIZE = 6 ;
7673
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7674
    write_flags`WB_TRANSFER_CAB = 1 ;
7675
 
7676
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7677
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7678
 
7679
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7680
    begin
7681
        $display("Transaction progress testing failed! Time %t ", $time) ;
7682
        $display("Bridge failed to process CAB read!") ;
7683
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7684
        disable main ;
7685
    end
7686
 
7687
    ok = 1 ;
7688
    for ( i = 0 ; i < 6 ; i = i + 1 )
7689
    begin
7690
        read_status = wishbone_master.blk_read_data_out[i] ;
7691
 
7692
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7693
        begin
7694
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7695
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7696
            test_fail("unexpected data read back from PCI") ;
7697
            ok = 0 ;
7698
        end
7699
    end
7700
 
7701
    if ( ok )
7702
        test_ok ;
7703
 
7704
    $display("Testing Latency timer during Master Reads!") ;
7705
 
7706
    // at least 2 words are transfered during Master Reads terminated with timeout
7707
    write_flags`WB_TRANSFER_SIZE = 2 ;
7708
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7709
    fork
7710
    begin
7711
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7712
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7713
        begin
7714
            $display("Transaction progress testing failed! Time %t ", $time) ;
7715
            $display("Bridge failed to process CAB read!") ;
7716
            test_fail("bridge didn't process burst read as expected") ;
7717
            ok = 0 ;
7718
        end
7719
    end
7720
    begin
7721
        // wait for bridge's master to start transaction
7722
        @(posedge pci_clock) ;
7723
        while ( FRAME === 1 )
7724
            @(posedge pci_clock) ;
7725
 
7726
        // start behavioral master request
7727
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7728
               target_address, wmem_data[0], `Test_All_Bytes,
7729
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7730
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7731
 
7732
        do_pause ( 1 ) ;
7733
    end
7734
    begin
7735
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7736
        if ( ok !== 1 )
7737
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7738
    end
7739
    join
7740
 
7741
    // check data provided by target
7742
    if ( ok )
7743
    begin
7744
        for ( i = 0 ; i < 2 ; i = i + 1 )
7745
        begin
7746
            read_status = wishbone_master.blk_read_data_out[i] ;
7747
 
7748
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7749
            begin
7750
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7751
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7752
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7753
                ok = 0 ;
7754
            end
7755
        end
7756
    end
7757
    if ( ok )
7758
        test_ok ;
7759
 
7760
    test_name = "DISABLE_IMAGE" ;
7761
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7762
    if ( ok !== 1 )
7763
    begin
7764
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7765
        test_fail("write to WB Address Mask register failed") ;
7766
        disable main ;
7767
    end
7768
 
7769
end
7770
endtask //wb_to_pci_transactions
7771
 
7772
task iack_cycle ;
7773
    reg `READ_STIM_TYPE   read_data ;
7774
    reg `READ_RETURN_TYPE read_status ;
7775
    reg `WB_TRANSFER_FLAGS flags ;
7776
 
7777
    reg [31:0] temp_var ;
7778
    reg ok ;
7779 45 mihad
    reg ok_wb ;
7780
    reg ok_pci ;
7781
 
7782
    reg [31:0] irq_vector ;
7783 15 mihad
begin
7784
 
7785 45 mihad
    ok     = 1 ;
7786
    ok_wb  = 1 ;
7787
    ok_pci = 1 ;
7788
 
7789 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7790
 
7791
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7792
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7793
 
7794
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7795
    read_data`READ_SEL     = 4'hF ;
7796
 
7797
    flags = 0 ;
7798
 
7799
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7800
 
7801
    irq_vector  = 32'hAAAA_AAAA ;
7802
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7803
 
7804 45 mihad
    // disable both pci blue behavioral targets
7805
    configuration_cycle_write
7806
    (
7807
        0,                          // bus number [7:0]
7808
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7809
        0,                          // function number [2:0]
7810
        1,                          // register number [5:0]
7811
        0,                          // type [1:0]
7812
        4'h1,                       // byte enables [3:0]
7813
        32'h0000_0044               // data to write [31:0]
7814
    ) ;
7815
 
7816
    configuration_cycle_write
7817
    (
7818
        0,                          // bus number [7:0]
7819
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7820
        0,                          // function number [2:0]
7821
        1,                          // register number [5:0]
7822
        0,                          // type [1:0]
7823
        4'h1,                       // byte enables [3:0]
7824
        32'h0000_0044               // data to write [31:0]
7825
    ) ;
7826
 
7827 15 mihad
    fork
7828
    begin
7829
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7830
    end
7831
    begin
7832 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7833
        if ( ok_pci !== 1 )
7834 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7835
    end
7836
    join
7837
 
7838
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7839
    begin
7840 45 mihad
        ok_wb = 0 ;
7841 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7842
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7843
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7844
    end
7845 45 mihad
 
7846
    if ( ok_pci && ok_wb )
7847 15 mihad
        test_ok ;
7848 45 mihad
 
7849
    ok_wb = 1 ;
7850
    ok_pci = 1 ;
7851
    ok = 1 ;
7852 15 mihad
 
7853 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7854
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7855 15 mihad
 
7856
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7857 45 mihad
    // enable pci blue behavioral target 1
7858
    configuration_cycle_write
7859
    (
7860
        0,                          // bus number [7:0]
7861
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7862
        0,                          // function number [2:0]
7863
        1,                          // register number [5:0]
7864
        0,                          // type [1:0]
7865
        4'h1,                       // byte enables [3:0]
7866
        32'h0000_0047               // data to write [31:0]
7867
    ) ;
7868 15 mihad
    fork
7869
    begin
7870
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7871
    end
7872
    begin
7873 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7874
        if ( ok_pci !== 1 )
7875 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7876
    end
7877
    join
7878
 
7879
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7880
    begin
7881 45 mihad
        ok_wb = 0 ;
7882 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7883
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7884
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7885
    end
7886
 
7887
    if ( read_status`READ_DATA !== irq_vector )
7888
    begin
7889
        $display(" Time %t ", $time ) ;
7890
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7891
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7892 45 mihad
        ok_wb = 0 ;
7893 15 mihad
    end
7894
 
7895 45 mihad
    if ( ok_pci && ok_wb )
7896 15 mihad
        test_ok ;
7897
 
7898 45 mihad
    ok_pci = 1 ;
7899
    ok_wb  = 1 ;
7900
    ok     = 1 ;
7901
 
7902 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7903 45 mihad
    irq_vector  = 32'h5555_5555 ;
7904
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7905
 
7906 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7907
    fork
7908
    begin
7909
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7910
    end
7911
    begin
7912 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7913
        if ( ok_pci !== 1 )
7914 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7915
    end
7916
    join
7917
 
7918
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7919
    begin
7920
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7921
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7922
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7923 45 mihad
        ok_wb = 0 ;
7924 15 mihad
    end
7925
 
7926 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7927 15 mihad
    begin
7928
        $display(" Time %t ", $time ) ;
7929 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7930 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7931 45 mihad
        ok_wb = 0 ;
7932 15 mihad
    end
7933
 
7934 45 mihad
    if (ok_pci && ok_wb)
7935 15 mihad
        test_ok ;
7936
 
7937 45 mihad
    ok_pci = 1 ;
7938
    ok_wb  = 1 ;
7939
    ok     = 1 ;
7940 15 mihad
 
7941 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7942
 
7943
    // set target to terminate with target abort
7944
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7945
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7946
 
7947
    fork
7948
    begin
7949
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7950
    end
7951
    begin
7952
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7953
        if ( ok_pci !== 1 )
7954
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7955
    end
7956
    join
7957
 
7958
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7959
    begin
7960
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7961
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7962
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7963
        ok_wb = 0 ;
7964
    end
7965
 
7966
    // set target to terminate with target abort
7967
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7968
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7969
 
7970
    // enable pci blue behavioral target 2
7971
    configuration_cycle_write
7972
    (
7973
        0,                          // bus number [7:0]
7974
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7975
        0,                          // function number [2:0]
7976
        1,                          // register number [5:0]
7977
        0,                          // type [1:0]
7978
        4'h1,                       // byte enables [3:0]
7979
        32'h0000_0047               // data to write [31:0]
7980
    ) ;
7981
 
7982
    // read PCI Device status
7983
    config_read(12'h4, 4'hC, temp_var) ;
7984
    if (temp_var[29] !== 1)
7985
    begin
7986
        $display("Time %t", $time) ;
7987
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
7988
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
7989
        ok_wb = 0 ;
7990
    end
7991
 
7992
    if (temp_var[28] !== 1)
7993
    begin
7994
        $display("Time %t", $time) ;
7995
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
7996
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
7997
        ok_wb = 0 ;
7998
    end
7999
 
8000
    // clearing the status bits
8001
        config_write(12'h4, temp_var, 4'hC, ok);
8002
 
8003
    if ( ok && ok_pci && ok_wb )
8004
        test_ok ;
8005
 
8006 15 mihad
end
8007
endtask //iack_cycle
8008
 
8009
task transaction_ordering ;
8010
    reg   [11:0] wb_ctrl_offset ;
8011
    reg   [11:0] wb_ba_offset ;
8012
    reg   [11:0] wb_am_offset ;
8013
    reg   [11:0] pci_ctrl_offset ;
8014
    reg   [11:0] pci_ba_offset ;
8015
    reg   [11:0] pci_am_offset ;
8016
    reg   [11:0] pci_device_ctrl_offset ;
8017
    reg   [11:0] wb_err_cs_offset ;
8018
    reg   [11:0] pci_err_cs_offset ;
8019
    reg   [11:0] icr_offset ;
8020
    reg   [11:0] isr_offset ;
8021
    reg   [11:0] lat_tim_cls_offset ;
8022
 
8023
    reg `WRITE_STIM_TYPE  write_data ;
8024
    reg `READ_STIM_TYPE   read_data ;
8025
    reg `READ_RETURN_TYPE read_status ;
8026
 
8027
    reg `WRITE_RETURN_TYPE write_status ;
8028
    reg `WB_TRANSFER_FLAGS write_flags ;
8029
    reg [31:0] temp_val1 ;
8030
    reg [31:0] temp_val2 ;
8031
    reg        ok   ;
8032
 
8033
    reg [31:0] wb_image_base ;
8034
    reg [31:0] wb_target_address ;
8035
    reg [31:0] pci_image_base ;
8036
    integer i ;
8037
 
8038
    reg     error_monitor_done ;
8039
begin:main
8040
    write_flags`INIT_WAITS = tb_init_waits ;
8041
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
8042
 
8043
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
8044
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
8045
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
8046
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
8047
 
8048
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
8049
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
8050
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
8051
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
8052
 
8053
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
8054
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
8055
    lat_tim_cls_offset = 12'hC ;
8056
    pci_device_ctrl_offset    = 12'h4 ;
8057
 
8058
    wb_target_address  = `BEH_TAR1_MEM_START ;
8059
    wb_image_base      = 0 ;
8060
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
8061
 
8062
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
8063
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
8064
    write_flags                    = 0 ;
8065
    write_flags`INIT_WAITS         = 0 ;
8066
    write_flags`SUBSEQ_WAITS       = 0 ;
8067
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8068
 
8069
    pci_image_base = Target_Base_Addr_R[1] ;
8070
 
8071
    // enable master & target operation
8072
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
8073
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
8074
    if ( ok !== 1 )
8075
    begin
8076
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
8077
        test_fail("write to PCI Device Control register failed") ;
8078
        disable main ;
8079
    end
8080
 
8081
    // prepare image control register
8082
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8083
    if ( ok !== 1 )
8084
    begin
8085
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
8086
        test_fail("write to WB Image Control register failed") ;
8087
        disable main ;
8088
    end
8089
 
8090
    // prepare base address register
8091
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8092
    if ( ok !== 1 )
8093
    begin
8094
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8095
        test_fail("write to WB Base Address register failed") ;
8096
        disable main ;
8097
    end
8098
 
8099
    // write address mask register
8100
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8101
    if ( ok !== 1 )
8102
    begin
8103
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8104
        test_fail("write to WB Address Mask register failed") ;
8105
        disable main ;
8106
    end
8107
 
8108
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8109
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8110
    if ( ok !== 1 )
8111
    begin
8112
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8113
        test_fail("write to WB Error Control and Status register failed") ;
8114
        disable main ;
8115
    end
8116
 
8117
    // prepare image control register
8118
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8119
    if ( ok !== 1 )
8120
    begin
8121
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8122
        test_fail("write to PCI Image Control register failed") ;
8123
        disable main ;
8124
    end
8125
 
8126
    // prepare base address register
8127
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8128
    if ( ok !== 1 )
8129
    begin
8130
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8131
        test_fail("write to PCI Base Address register failed") ;
8132
        disable main ;
8133
    end
8134
 
8135
    // write address mask register
8136
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8137
    if ( ok !== 1 )
8138
    begin
8139
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8140
        test_fail("write to PCI Address Mask register failed") ;
8141
        disable main ;
8142
    end
8143
 
8144
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8145
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8146
    if ( ok !== 1 )
8147
    begin
8148
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8149
        test_fail("write to PCI Error Control and Status register failed") ;
8150
        disable main ;
8151
    end
8152
 
8153
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8154
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8155
    if ( ok !== 1 )
8156
    begin
8157
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8158
        test_fail("write to Interrupt Control register failed") ;
8159
        disable main ;
8160
    end
8161
 
8162
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8163
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8164
    if ( ok !== 1 )
8165
    begin
8166
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8167
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8168
        disable main ;
8169
    end
8170
 
8171
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8172
 
8173
    // prepare wb_master write and read data
8174
    for ( i = 0 ; i < 4 ; i = i + 1 )
8175
    begin
8176
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8177
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8178
        write_data`WRITE_SEL     = 4'hF ;
8179
 
8180
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8181
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8182
 
8183
        wishbone_master.blk_write_data[i]   = write_data ;
8184
        wishbone_master.blk_read_data_in[i] = read_data ;
8185
    end
8186
 
8187
    // put wishbone slave in acknowledge and pci target in retry mode
8188
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8189
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8190
 
8191
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8192
 
8193
    fork
8194
    begin
8195
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8196
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8197
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8198
        begin
8199
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8200
            test_fail("Bridge didn't post single memory write as expected") ;
8201
        end
8202
 
8203
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8204
        if ( ok !== 1 )
8205
        begin
8206
            $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) ;
8207
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8208
            ok = 0 ;
8209
        end
8210
 
8211
        // now post single write to target - normal progress
8212
        if ( target_mem_image == 1 )
8213
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8214
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8215
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8216
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8217
        else
8218
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8219
 
8220
        do_pause( 1 ) ;
8221
 
8222
    end
8223
    begin:error_monitor_1
8224 35 mihad
        error_monitor_done = 0 ;
8225 15 mihad
        @(error_event_int) ;
8226
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8227
        ok = 0 ;
8228 35 mihad
        error_monitor_done = 1 ;
8229 15 mihad
    end
8230
    begin
8231
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8232
        if ( ok !== 1 )
8233
        begin
8234
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8235
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8236
        end
8237
        else
8238
        begin
8239 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8240
//            while ( FRAME === 0 || IRDY === 0 )
8241
//                @(posedge pci_clock) ;
8242 15 mihad
 
8243
            // enable response in PCI target
8244
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8245
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8246
 
8247
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8248
            if ( ok !== 1 )
8249
            begin
8250
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8251
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8252
            end
8253
        end
8254
 
8255 35 mihad
        #1 ;
8256
        if ( !error_monitor_done )
8257
            disable error_monitor_1 ;
8258 15 mihad
    end
8259
    join
8260
 
8261
    if ( ok )
8262
        test_ok ;
8263
 
8264
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8265
 
8266
    // put WISHBONE slave in retry mode
8267
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8268
 
8269
    fork
8270
    begin
8271
        // now post single write to target - normal progress
8272
        if ( target_mem_image == 1 )
8273
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8274
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8275
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8276
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8277
        else
8278
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8279
 
8280
        do_pause( 1 ) ;
8281
 
8282
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8283
        if ( ok !== 1 )
8284
        begin
8285
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8286
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8287
        end
8288
 
8289
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8290
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8291
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8292
        begin
8293
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8294
            test_fail("Bridge didn't post single memory write as expected") ;
8295
        end
8296
 
8297
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8298
        if ( ok !== 1 )
8299
        begin
8300
            $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) ;
8301
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8302
            ok = 0 ;
8303
        end
8304
 
8305
        wait ( CYC_O === 0 ) ;
8306
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8307
 
8308
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8309
        if ( ok !== 1 )
8310
        begin
8311
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8312
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8313
        end
8314
 
8315 35 mihad
        #1 ;
8316
        if ( !error_monitor_done )
8317
            disable error_monitor_2 ;
8318 15 mihad
    end
8319
    begin:error_monitor_2
8320 35 mihad
        error_monitor_done = 0 ;
8321 15 mihad
        @(error_event_int) ;
8322
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8323
        ok = 0 ;
8324 35 mihad
        error_monitor_done = 1 ;
8325 15 mihad
    end
8326
    join
8327
 
8328
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8329
 
8330
    // put wishbone slave in acknowledge and pci target in retry mode
8331
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8332
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8333
 
8334
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8335
 
8336
    fork
8337
    begin
8338
        write_flags`WB_TRANSFER_SIZE = 3 ;
8339
        write_flags`WB_TRANSFER_CAB  = 1 ;
8340
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8341
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8342
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8343
        begin
8344
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8345
            test_fail("Bridge didn't post burst memory write as expected") ;
8346
        end
8347
 
8348
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8349
        if ( ok !== 1 )
8350
        begin
8351
            $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) ;
8352
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8353
            ok = 0 ;
8354
        end
8355
 
8356
        // now post single write to target - normal progress
8357
        if ( target_mem_image == 1 )
8358
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8359
                        pci_image_base, 32'h5555_5555, 4'h0,
8360
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8361
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8362
        else
8363
        begin
8364
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8365
            do_pause( 1 ) ;
8366
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8367
        end
8368
 
8369
        do_pause( 1 ) ;
8370
 
8371
    end
8372
    begin:error_monitor_3
8373 35 mihad
        error_monitor_done = 0 ;
8374 15 mihad
        @(error_event_int) ;
8375
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8376
        ok = 0 ;
8377 35 mihad
        error_monitor_done = 1 ;
8378 15 mihad
    end
8379
    begin
8380
        if ( target_mem_image == 1 )
8381
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8382
        else
8383
        begin
8384
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8385
            if ( ok )
8386
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8387
        end
8388
 
8389
        if ( ok !== 1 )
8390
        begin
8391
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8392
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8393
        end
8394
        else
8395
        begin
8396 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8397
//            while ( FRAME === 0 || IRDY === 0 )
8398
//                @(posedge pci_clock) ;
8399 15 mihad
 
8400
            // enable response in PCI target
8401
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8402
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8403
 
8404
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8405
            if ( ok !== 1 )
8406
            begin
8407
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8408
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8409
            end
8410
        end
8411
 
8412 35 mihad
        #1 ;
8413
        if ( !error_monitor_done )
8414
            disable error_monitor_3 ;
8415 15 mihad
    end
8416
    join
8417
 
8418
    if ( ok )
8419
        test_ok ;
8420
 
8421
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8422
 
8423
    // put WISHBONE slave in retry mode
8424
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8425
 
8426
    fork
8427
    begin
8428
        // now post single write to target - normal progress
8429
        if ( target_mem_image == 1 )
8430
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8431
                        pci_image_base, 32'h5555_5555, 4'h0,
8432
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8433
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8434
        else
8435
        begin
8436
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8437
            do_pause( 1 ) ;
8438
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8439
        end
8440
 
8441
        do_pause( 1 ) ;
8442
 
8443
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8444
 
8445
        if ( ok !== 1 )
8446
        begin
8447
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8448
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8449
        end
8450
 
8451
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8452
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8453
        write_flags`WB_TRANSFER_CAB      = 1 ;
8454
 
8455
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8456
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8457
        begin
8458
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8459
            test_fail("Bridge didn't post burst memory write as expected") ;
8460
        end
8461
 
8462
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8463
        if ( ok !== 1 )
8464
        begin
8465
            $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) ;
8466
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8467
            ok = 0 ;
8468
        end
8469
 
8470
        @(posedge wb_clock) ;
8471
        while ( CYC_O === 1 )
8472
            @(posedge wb_clock) ;
8473
 
8474
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8475
 
8476
        if ( target_mem_image == 1 )
8477
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8478
        else
8479
        begin
8480
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8481
            if ( ok )
8482
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8483
        end
8484
 
8485 35 mihad
        #1 ;
8486
        if ( !error_monitor_done )
8487
            disable error_monitor_4 ;
8488 15 mihad
    end
8489
    begin:error_monitor_4
8490 35 mihad
        error_monitor_done = 0 ;
8491 15 mihad
        @(error_event_int) ;
8492
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8493
        ok = 0 ;
8494 35 mihad
        error_monitor_done = 1 ;
8495 15 mihad
    end
8496
    join
8497
 
8498
    if ( ok )
8499
        test_ok ;
8500
 
8501
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8502
 
8503
    // put wishbone slave in acknowledge and pci target in retry mode
8504
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8505
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8506
 
8507
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8508
 
8509
    master1_check_received_data = 1 ;
8510
 
8511
    error_monitor_done = 0 ;
8512
    fork
8513
    begin:error_monitor_5
8514
        @(error_event_int or error_monitor_done) ;
8515
        if ( !error_monitor_done )
8516
        begin
8517
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8518
            ok = 0 ;
8519
        end
8520
    end
8521
    begin
8522
 
8523
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8524
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8525
        begin
8526
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8527
            test_fail("Bridge didn't post single memory write as expected") ;
8528
        end
8529
 
8530
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8531
        if ( ok !== 1 )
8532
        begin
8533
            $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) ;
8534
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8535
            ok = 0 ;
8536
        end
8537
 
8538
        // start Read Through pci target
8539
        if ( target_mem_image == 1 )
8540
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8541
                          pci_image_base, 32'h5555_5555,
8542
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8543
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8544
        else
8545
            PCIU_IO_READ
8546
             (
8547
                `Test_Master_1,
8548
                pci_image_base,
8549
                32'h5555_5555,
8550
                4'h0,
8551
                1,
8552
                `Test_Target_Retry_On
8553
             );
8554
 
8555
         do_pause( 1 ) ;
8556
 
8557
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8558
         if ( ok !== 1 )
8559
         begin
8560
            $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) ;
8561
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8562
         end
8563
 
8564
         // repeat the read 4 times - it should be retried all the time by pci target
8565
        for ( i = 0 ; i < 4 ; i = i + 1 )
8566
        begin
8567
            if ( target_mem_image == 1 )
8568
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8569
                            pci_image_base, 32'h5555_5555,
8570
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8571
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8572
            else
8573
                PCIU_IO_READ
8574
                (
8575
                    `Test_Master_1,
8576
                    pci_image_base,
8577
                    32'h5555_5555,
8578
                    4'h0,
8579
                    1,
8580
                    `Test_Target_Retry_On
8581
                );
8582
 
8583
            do_pause( 1 ) ;
8584
        end
8585
 
8586
        // now do posted write through target - it must go through OK
8587
        if ( target_mem_image == 1 )
8588
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8589
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8590
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8591
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8592
        else
8593
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8594
 
8595
        do_pause( 1 ) ;
8596
 
8597
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8598
        if ( ok !== 1 )
8599
        begin
8600
           $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) ;
8601
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8602
        end
8603
 
8604
        // start a read through wb_slave
8605
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8606
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8607
        begin
8608
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8609
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8610
            ok = 0 ;
8611
        end
8612
 
8613 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8614
//        while ( FRAME === 0 || IRDY === 0 )
8615
//            @(posedge pci_clock) ;
8616 15 mihad
 
8617
        // set the target to normal completion
8618
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8619
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8620
 
8621
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8622
        if ( ok !== 1 )
8623
        begin
8624
            $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) ;
8625
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8626
            ok = 0 ;
8627
        end
8628
 
8629
        // now wait for delayed read to finish
8630
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8631
        if ( ok !== 1 )
8632
        begin
8633
            $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) ;
8634
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8635
            ok = 0 ;
8636
        end
8637
 
8638
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8639
        fork
8640
        begin
8641
                if ( target_mem_image == 1 )
8642
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8643
                                pci_image_base, 32'h5555_5555, 4'h0,
8644
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8645
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8646
                else
8647
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8648
 
8649
                do_pause( 1 ) ;
8650
                end
8651
                begin
8652
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8653
                end
8654
                join
8655
 
8656
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8657
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8658
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8659
        begin
8660
            $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) ;
8661
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8662
            ok = 0 ;
8663
        end
8664
 
8665
        fork
8666
        begin
8667
        // now complete a read from PCI Target
8668
            if ( target_mem_image == 1 )
8669
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8670
                            pci_image_base, 32'h5555_5555,
8671
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8672
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8673
            else
8674
                PCIU_IO_READ
8675
                (
8676
                    `Test_Master_1,
8677
                    pci_image_base,
8678
                    32'h5555_5555,
8679
                    4'h0,
8680
                    1,
8681
                    `Test_Target_Normal_Completion
8682
                );
8683
 
8684
            do_pause( 1 ) ;
8685
        end
8686
        begin
8687
            if ( target_mem_image == 1 )
8688
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8689
            else
8690
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8691
        end
8692
        join
8693
 
8694
        @(posedge pci_clock) ;
8695
        repeat( 4 )
8696
            @(posedge wb_clock) ;
8697
 
8698
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8699
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8700
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8701
        begin
8702
            $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) ;
8703
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8704
            ok = 0 ;
8705
        end
8706
 
8707
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8708
        if ( ok !== 1 )
8709
        begin
8710
            $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) ;
8711
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8712
            ok = 0 ;
8713
        end
8714
 
8715
        // finish a read on WISHBONE also
8716
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8717
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8718
        begin
8719
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8720
            test_fail("WB Slave didn't process single delayed read as expected") ;
8721
        end
8722
 
8723
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8724
        begin
8725
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8726
            ok = 0 ;
8727
        end
8728
 
8729
 
8730
        error_monitor_done = 1 ;
8731
    end
8732
    join
8733
 
8734
    if ( ok )
8735
        test_ok ;
8736
 
8737
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8738
 
8739
    // put wishbone slave in retry and pci target in completion mode
8740
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8741
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8742
 
8743
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8744
 
8745
    master1_check_received_data = 1 ;
8746
 
8747
    error_monitor_done = 0 ;
8748
    fork
8749
    begin:error_monitor_6
8750
        @(error_event_int or error_monitor_done) ;
8751
        if ( !error_monitor_done )
8752
        begin
8753
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8754
            ok = 0 ;
8755
        end
8756
    end
8757
    begin
8758
 
8759
        // do a write through Target
8760
        fork
8761
        begin
8762
            if ( target_mem_image == 1 )
8763
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8764
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8765
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8766
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8767
            else
8768
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8769
 
8770
            do_pause( 1 ) ;
8771
        end
8772
        begin
8773
            if ( target_mem_image == 1 )
8774
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8775
            else
8776
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8777
        end
8778
        join
8779
 
8780
        // start a read through WB slave
8781
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8782
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8783
        begin
8784
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8785
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8786
            ok = 0 ;
8787
        end
8788
 
8789
        // now wait for this read to finish on pci
8790
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8791
        if ( ok !== 1 )
8792
        begin
8793
            $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) ;
8794
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8795
            ok = 0 ;
8796
        end
8797
 
8798
        // repeat the read four times - it should be retried
8799
        for ( i = 0 ; i < 4 ; i = i + 1 )
8800
        begin
8801
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8802
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8803
            begin
8804
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8805
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8806
                ok = 0 ;
8807
            end
8808
        end
8809
 
8810
        // posted write through WB Slave - must go through
8811
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8812
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8813
        begin
8814
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8815
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8816
            ok = 0 ;
8817
        end
8818
 
8819
        // write must come through
8820
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8821
        if ( ok !== 1 )
8822
        begin
8823
            $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) ;
8824
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8825
            ok = 0 ;
8826
        end
8827
 
8828
        // do a read through pci target
8829
        if ( target_mem_image == 1 )
8830
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8831
                          pci_image_base + 12, 32'hDEAD_BEAF,
8832
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8833
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8834
        else
8835
            PCIU_IO_READ
8836
             (
8837
                `Test_Master_1,
8838
                pci_image_base + 12,
8839
                32'hDEAD_BEAF,
8840
                4'h0,
8841
                1,
8842
                `Test_Target_Retry_On
8843
             );
8844
 
8845
         do_pause( 1 ) ;
8846
 
8847
        // wait for current cycle to finish on WB
8848 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8849
//        @(posedge wb_clock) ;
8850
//        while( CYC_O === 1 )
8851
//            @(posedge wb_clock) ;
8852 15 mihad
 
8853
        // set slave response to acknowledge
8854
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8855
 
8856
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8857
        if ( ok !== 1 )
8858
        begin
8859
            $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) ;
8860
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8861
        end
8862
 
8863
        // check the read to finish on wb
8864
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8865
        if ( ok !== 1 )
8866
        begin
8867
            $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) ;
8868
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8869
        end
8870
 
8871
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8872
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8873
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8874
        begin
8875
            $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) ;
8876
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8877
            ok = 0 ;
8878
        end
8879
 
8880
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8881
        fork
8882
        begin
8883
            if ( target_mem_image == 1 )
8884
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8885
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8886
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8887
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8888
            else
8889
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8890
        end
8891
        begin
8892
            if ( target_mem_image == 1 )
8893
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8894
            else
8895
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8896
        end
8897
        join
8898
 
8899
        do_pause( 1 ) ;
8900
 
8901
        // complete a read in WB Slave Unit
8902
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8903
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8904
        begin
8905
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8906
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8907
            ok = 0 ;
8908
        end
8909
 
8910
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8911
        begin
8912
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8913
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8914
            ok = 0 ;
8915
        end
8916
 
8917
        // wait for statuses to be propagated from one side of bridge to another
8918
        repeat( 4 )
8919
            @(posedge pci_clock) ;
8920
 
8921
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8922
        fork
8923
        begin
8924
            if ( target_mem_image == 1 )
8925
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8926
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8927
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8928
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8929
            else
8930
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8931
 
8932
            do_pause( 1 ) ;
8933
        end
8934
        begin
8935
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8936
            if ( ok !== 1 )
8937
            begin
8938
                $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) ;
8939
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8940
            end
8941
        end
8942
        join
8943
 
8944
        // finish the last read in PCI Target Unit
8945
        if ( target_mem_image == 1 )
8946
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8947
                          pci_image_base + 12, 32'hDEAD_BEAF,
8948
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8949
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8950
        else
8951
            PCIU_IO_READ
8952
             (
8953
                `Test_Master_1,
8954
                pci_image_base + 12,
8955
                32'hDEAD_BEAF,
8956
                4'h0,
8957
                1,
8958
                `Test_Target_Normal_Completion
8959
             );
8960
 
8961
         do_pause( 1 ) ;
8962
 
8963
         error_monitor_done = 1 ;
8964
    end
8965
    join
8966
 
8967
    if ( ok )
8968
        test_ok ;
8969
 
8970
end
8971
endtask // transaction_ordering
8972
 
8973
task pci_transaction_progress_monitor ;
8974
    input [31:0] address ;
8975
    input [3:0]  bus_command ;
8976
    input [31:0] num_of_transfers ;
8977
    input [31:0] num_of_cycles ;
8978
    input check_transfers ;
8979
    input check_cycles ;
8980
    input doing_fast_back_to_back ;
8981
    output ok ;
8982
    reg in_use ;
8983
    integer deadlock_counter ;
8984
    integer transfer_counter ;
8985
    integer cycle_counter ;
8986
    integer deadlock_max_val ;
8987
begin:main
8988
 
8989
    if ( in_use === 1 )
8990
    begin
8991
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8992
        ok = 0 ;
8993
        disable main ;
8994
    end
8995
 
8996
    // approximate number of cycles on WB bus for maximum transaction length
8997
    deadlock_max_val = tb_init_waits + 100 +
8998
                       `WBW_DEPTH *
8999
                       (tb_subseq_waits + 1 +
9000
                       `ifdef REGISTER_WBS_OUTPUTS
9001
                       1) ;
9002
                       `else
9003
                       0) ;
9004
                       `endif
9005
 
9006
    // time used for maximum transaction length on WB
9007
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
9008
 
9009
    // maximum pci clock cycles
9010
    `ifdef PCI33
9011
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
9012
    `else
9013
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
9014
    `endif
9015
 
9016
    in_use = 1 ;
9017
    ok     = 1 ;
9018
 
9019
    fork
9020
    begin:wait_start
9021
 
9022
        deadlock_counter = 0 ;
9023
 
9024
        @(posedge pci_clock) ;
9025
 
9026
        if ( doing_fast_back_to_back !== 1 )
9027
        begin
9028
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
9029
            begin
9030 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
9031
                    deadlock_counter = 0 ;
9032
                else
9033
                    deadlock_counter = deadlock_counter + 1 ;
9034 15 mihad
                @(posedge pci_clock) ;
9035
            end
9036
            if ( FRAME !== 1 )
9037
            begin
9038
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9039
                in_use = 0 ;
9040
                ok     = 0 ;
9041
                disable main ;
9042
            end
9043
        end
9044
 
9045
        deadlock_counter = 0 ;
9046
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
9047
        begin
9048
            deadlock_counter = deadlock_counter + 1 ;
9049
            @(posedge pci_clock) ;
9050
        end
9051
 
9052
        if ( FRAME !== 0 )
9053
        begin
9054
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9055
            in_use = 0 ;
9056
            ok     = 0 ;
9057
            disable main ;
9058
        end
9059
    end //wait_start
9060
 
9061
    begin:addr_bc_monitor
9062
 
9063
        @(posedge pci_clock) ;
9064
 
9065
        if ( doing_fast_back_to_back !== 1 )
9066
        begin
9067
            while ( FRAME !== 1 )
9068
                @(posedge pci_clock) ;
9069
        end
9070
 
9071
        while( FRAME !== 0 )
9072
            @(posedge pci_clock) ;
9073
 
9074
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
9075
        if ( bus_command !== `BC_IACK )
9076
        begin
9077
            if ( AD !== address )
9078
            begin
9079
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
9080
                $display("Expected address = %h, detected address = %h ", address, AD) ;
9081
                ok = 0 ;
9082
            end
9083
        end
9084
 
9085
        if ( CBE !== bus_command )
9086
        begin
9087
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
9088
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
9089
            ok = 0 ;
9090
        end
9091
    end //addr_bc_monitor
9092
 
9093
    begin:transfer_checker
9094
        transfer_counter = 0 ;
9095
 
9096
        @(posedge pci_clock) ;
9097
 
9098
        if ( doing_fast_back_to_back !== 1 )
9099
        begin
9100
            while ( FRAME !== 1 )
9101
                @(posedge pci_clock) ;
9102
        end
9103
 
9104
        while( FRAME !== 0 )
9105
            @(posedge pci_clock) ;
9106
 
9107
        while( FRAME === 0 )
9108
        begin
9109
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
9110
                transfer_counter = transfer_counter + 1 ;
9111
            @(posedge pci_clock) ;
9112
        end
9113
 
9114
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
9115
        begin
9116
            @(posedge pci_clock) ;
9117
        end
9118
 
9119
        if ( (TRDY === 0) && (DEVSEL === 0) )
9120
                transfer_counter = transfer_counter + 1 ;
9121
 
9122
        if ( check_transfers === 1 )
9123
        begin
9124
            if ( transfer_counter !== num_of_transfers )
9125
            begin
9126
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9127
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9128
                ok = 0 ;
9129
            end
9130
        end
9131
    end //transfer_checker
9132
    begin:cycle_checker
9133
        if ( check_cycles )
9134
        begin
9135
            cycle_counter = 0 ;
9136
            @(posedge pci_clock) ;
9137
 
9138
            if ( doing_fast_back_to_back !== 1)
9139
            begin
9140
                while ( FRAME !== 1 )
9141
                    @(posedge pci_clock) ;
9142
            end
9143
 
9144
            while( FRAME !== 0 )
9145
                @(posedge pci_clock) ;
9146
 
9147
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9148
            begin
9149
                cycle_counter = cycle_counter + 1 ;
9150
                @(posedge pci_clock) ;
9151
            end
9152
 
9153
            if ( FRAME !== 1 )
9154
            begin
9155
                while ((FRAME === 0) && (MAS0_GNT === 0))
9156
                    @(posedge pci_clock) ;
9157
 
9158
                if ( FRAME !== 1 )
9159
                begin
9160
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9161
                        @(posedge pci_clock) ;
9162
 
9163
                    @(posedge pci_clock) ;
9164
 
9165
                    if ( FRAME !== 1 )
9166
                    begin
9167
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9168
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9169
                        ok = 0 ;
9170
                    end
9171
                end
9172
            end
9173
        end
9174
    end // cycle_checker
9175
    join
9176
 
9177
    in_use = 0 ;
9178
end
9179
endtask //pci_transaction_progress_monitor
9180
 
9181
reg CYC_O_previous ;
9182
always@(posedge wb_clock or posedge reset)
9183
begin
9184
    if ( reset )
9185
        CYC_O_previous <= #1 1'b0 ;
9186
    else
9187
        CYC_O_previous <= #1 CYC_O ;
9188
end
9189
 
9190
task wb_transaction_progress_monitor ;
9191
    input [31:0] address ;
9192
    input        write ;
9193
    input [31:0] num_of_transfers ;
9194
    input check_transfers ;
9195
    output ok ;
9196
    reg in_use ;
9197
    integer deadlock_counter ;
9198
    integer transfer_counter ;
9199
    integer deadlock_max_val ;
9200
begin:main
9201
    if ( in_use === 1 )
9202
    begin
9203
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9204
        ok = 0 ;
9205
        disable main ;
9206
    end
9207
 
9208
    // number of cycles on WB bus for maximum transaction length
9209
    deadlock_max_val = 4 - tb_init_waits + 100 +
9210
                       `PCIW_DEPTH *
9211
                       (4 - tb_subseq_waits + 1) ;
9212
 
9213
    // time used for maximum transaction length on PCI
9214
    `ifdef PCI33
9215
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9216
    `else
9217
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9218
    `endif
9219
 
9220
    // maximum wb clock cycles
9221
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9222
 
9223
    in_use = 1 ;
9224
    ok     = 1 ;
9225
 
9226
    fork
9227
    begin:wait_start
9228
        deadlock_counter = 0 ;
9229
        @(posedge wb_clock) ;
9230
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9231
        begin
9232 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9233
                deadlock_counter = deadlock_counter + 1 ;
9234
            else
9235
                deadlock_counter = 0;
9236 15 mihad
            @(posedge wb_clock) ;
9237
        end
9238
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9239
        begin
9240
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9241
            in_use = 0 ;
9242
            ok     = 0 ;
9243
            disable main ;
9244
        end
9245
 
9246
        deadlock_counter = 0 ;
9247
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9248
        begin
9249
            deadlock_counter = deadlock_counter + 1 ;
9250
            @(posedge wb_clock) ;
9251
        end
9252
 
9253
        if ( CYC_O !== 1 )
9254
        begin
9255
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9256
            in_use = 0 ;
9257
            ok     = 0 ;
9258
            disable main ;
9259
        end
9260
    end //wait_start
9261
    begin:addr_monitor
9262
        @(posedge wb_clock) ;
9263
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9264
            @(posedge wb_clock) ;
9265
 
9266
        while( CYC_O !== 1 )
9267
            @(posedge wb_clock) ;
9268
 
9269
        while (STB_O !== 1 )
9270
            @(posedge wb_clock) ;
9271
 
9272
        if ( WE_O !== write )
9273
        begin
9274
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9275
            if ( write !== 1 )
9276
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9277
            else
9278
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9279
        end
9280
 
9281
        if ( ADR_O !== address )
9282
        begin
9283
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9284
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9285
            ok = 0 ;
9286
        end
9287
    end
9288
    begin:transfer_checker
9289
        transfer_counter = 0 ;
9290
        @(posedge wb_clock) ;
9291
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9292
            @(posedge wb_clock) ;
9293
 
9294
        while( CYC_O !== 1 )
9295
            @(posedge wb_clock) ;
9296
 
9297 63 mihad
        while( (CYC_O === 1) && ((transfer_counter <= `PCIW_DEPTH) || (transfer_counter <= `PCIR_DEPTH)) )
9298 15 mihad
        begin
9299
            if ( (STB_O === 1) && (ACK_I === 1) )
9300
                transfer_counter = transfer_counter + 1 ;
9301
            @(posedge wb_clock) ;
9302
        end
9303
 
9304
        if ( check_transfers === 1 )
9305
        begin
9306
            if ( transfer_counter !== num_of_transfers )
9307
            begin
9308
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9309
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9310
                ok = 0 ;
9311
            end
9312
        end
9313
    end //transfer_checker
9314
    join
9315
 
9316
    in_use = 0 ;
9317
end
9318
endtask // wb_transaction_progress_monitor
9319
 
9320
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9321
// so they are not re-entered
9322
task wb_transaction_progress_monitor_backup ;
9323
    input [31:0] address ;
9324
    input        write ;
9325
    input [31:0] num_of_transfers ;
9326
    input check_transfers ;
9327
    output ok ;
9328
    reg in_use ;
9329
    integer deadlock_counter ;
9330
    integer transfer_counter ;
9331
    integer deadlock_max_val ;
9332
begin:main
9333
    if ( in_use === 1 )
9334
    begin
9335
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9336
        ok = 0 ;
9337
        disable main ;
9338
    end
9339
 
9340
    // number of cycles on WB bus for maximum transaction length
9341
    deadlock_max_val = 4 - tb_init_waits + 100 +
9342
                       `PCIW_DEPTH *
9343
                       (4 - tb_subseq_waits + 1) ;
9344
 
9345
    // time used for maximum transaction length on PCI
9346
    `ifdef PCI33
9347
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9348
    `else
9349
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9350
    `endif
9351
 
9352
    // maximum wb clock cycles
9353
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9354
 
9355
    in_use = 1 ;
9356
    ok     = 1 ;
9357
 
9358
    fork
9359
    begin:wait_start
9360
        deadlock_counter = 0 ;
9361
        @(posedge wb_clock) ;
9362
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9363
        begin
9364 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9365
                deadlock_counter = deadlock_counter + 1 ;
9366
            else
9367
                deadlock_counter = 0;
9368 15 mihad
            @(posedge wb_clock) ;
9369
        end
9370
        if ( CYC_O !== 0 )
9371
        begin
9372
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9373
            in_use = 0 ;
9374
            ok     = 0 ;
9375
            disable main ;
9376
        end
9377
 
9378
        deadlock_counter = 0 ;
9379
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9380
        begin
9381
            deadlock_counter = deadlock_counter + 1 ;
9382
            @(posedge wb_clock) ;
9383
        end
9384
 
9385
        if ( CYC_O !== 1 )
9386
        begin
9387
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9388
            in_use = 0 ;
9389
            ok     = 0 ;
9390
            disable main ;
9391
        end
9392
    end //wait_start
9393
    begin:addr_monitor
9394
        @(posedge wb_clock) ;
9395
        while ( CYC_O !== 0 )
9396
            @(posedge wb_clock) ;
9397
 
9398
        while( CYC_O !== 1 )
9399
            @(posedge wb_clock) ;
9400
 
9401
        while (STB_O !== 1 )
9402
            @(posedge wb_clock) ;
9403
 
9404
        if ( WE_O !== write )
9405
        begin
9406
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9407
            if ( write !== 1 )
9408
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9409
            else
9410
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9411
        end
9412
 
9413
        if ( ADR_O !== address )
9414
        begin
9415
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9416
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9417
            ok = 0 ;
9418
        end
9419
    end
9420
    begin:transfer_checker
9421
        transfer_counter = 0 ;
9422
        @(posedge wb_clock) ;
9423
        while ( CYC_O !== 0 )
9424
            @(posedge wb_clock) ;
9425
 
9426
        while( CYC_O !== 1 )
9427
            @(posedge wb_clock) ;
9428
 
9429
        while( CYC_O === 1 )
9430
        begin
9431
            if ( (STB_O === 1) && (ACK_I === 1) )
9432
                transfer_counter = transfer_counter + 1 ;
9433
            @(posedge wb_clock) ;
9434
        end
9435
 
9436
        if ( check_transfers === 1 )
9437
        begin
9438
            if ( transfer_counter !== num_of_transfers )
9439
            begin
9440
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9441
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9442
                ok = 0 ;
9443
            end
9444
        end
9445
    end //transfer_checker
9446
    join
9447
 
9448
    in_use = 0 ;
9449
end
9450
endtask // wb_transaction_progress_monitor_backup
9451
 
9452
task wb_transaction_stop ;
9453
    input [31:0] num_of_transfers ;
9454
    integer transfer_counter ;
9455
begin:main
9456
    begin:transfer_checker
9457
        transfer_counter = 0 ;
9458
        @(posedge wb_clock) ;
9459
        while ( CYC_O !== 0 )
9460
            @(posedge wb_clock) ;
9461
 
9462
        while( CYC_O !== 1 )
9463
            @(posedge wb_clock) ;
9464
 
9465
        if ( (STB_O === 1) && (ACK_I === 1) )
9466
            transfer_counter = transfer_counter + 1 ;
9467
 
9468
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9469
        begin
9470
            @(posedge wb_clock) ;
9471
            if ( (STB_O === 1) && (ACK_I === 1) )
9472
                transfer_counter = transfer_counter + 1 ;
9473
        end
9474
    end //transfer_checker
9475
end
9476
endtask // wb_transaction_stop
9477
 
9478
task musnt_respond ;
9479
    output ok ;
9480
    reg in_use ;
9481
    integer i ;
9482
begin:main
9483
    if ( in_use === 1 )
9484
    begin
9485
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9486
        #20 $stop ;
9487
        ok = 0 ;
9488
        disable main ;
9489
    end
9490
 
9491
    in_use = 1 ;
9492
    ok = 1 ;
9493
 
9494
    fork
9495
    begin:wait_start
9496
        @(negedge FRAME) ;
9497
        disable count ;
9498
    end
9499
    begin:count
9500
        i = 0 ;
9501
        while ( i < 1000 )
9502
        begin
9503
            @(posedge pci_clock) ;
9504
            i = i + 1 ;
9505
        end
9506
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9507
        ok = 0 ;
9508
        disable wait_start ;
9509
    end
9510
    join
9511
 
9512
    @(posedge pci_clock) ;
9513
    while ( FRAME === 0 && ok )
9514
    begin
9515
        if ( DEVSEL !== 1 )
9516
        begin
9517
            ok = 0 ;
9518
        end
9519
        @(posedge pci_clock) ;
9520
    end
9521
 
9522
    while ( IRDY === 0 && ok )
9523
    begin
9524
        if ( DEVSEL !== 1 )
9525
        begin
9526
            ok = 0 ;
9527
        end
9528
        @(posedge pci_clock) ;
9529
    end
9530
    in_use = 0 ;
9531
end
9532
endtask
9533
 
9534
function [31:0] wb_to_pci_addr_convert ;
9535
    input [31:0] wb_address ;
9536
    input [31:0] translation_address ;
9537
    input [31:0] translate ;
9538
 
9539
    reg   [31:0] temp_address ;
9540
begin
9541
    if ( translate !== 1 )
9542
    begin
9543
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9544
    end
9545
    else
9546
    begin
9547
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9548
    end
9549
 
9550
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9551
    wb_to_pci_addr_convert = temp_address ;
9552
end
9553
endfunction //wb_to_pci_addr_convert
9554
 
9555 45 mihad
`ifdef HOST
9556 15 mihad
task find_pci_devices ;
9557
    integer device_num ;
9558
    reg     found ;
9559
    reg [11:0] pci_ctrl_offset ;
9560
    reg ok ;
9561
    reg [31:0] data ;
9562 45 mihad
    reg [31:0] expected_data ;
9563
 
9564
    reg [5:0]  reg_num ;
9565 15 mihad
begin:main
9566 45 mihad
 
9567
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9568 15 mihad
    pci_ctrl_offset = 12'h004 ;
9569
 
9570
    // enable master & target operation
9571
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9572
 
9573
    if ( ok !== 1 )
9574
    begin
9575
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9576 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9577 15 mihad
        disable main ;
9578
    end
9579
    // find all possible devices on pci bus by performing configuration cycles
9580 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9581 15 mihad
    begin
9582
        find_device ( device_num, found ) ;
9583
 
9584
        // check pci status register - if device is not present, Received Master Abort bit must be set
9585
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9586
 
9587
        if ( (data[29] !== 0) && (found !== 0) )
9588 45 mihad
        begin
9589 15 mihad
            $display( "Time %t ", $time ) ;
9590
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9591
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9592 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9593
            ok = 0 ;
9594 15 mihad
        end
9595
 
9596
        if ( (data[29] !== 1) && (found !== 1) )
9597
        begin
9598
            $display( "Time %t ", $time ) ;
9599
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9600
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9601 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9602
            ok = 0 ;
9603 15 mihad
        end
9604
 
9605
        // clear Master Abort status if set
9606
        if ( data[29] !== 0 )
9607
        begin
9608
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9609
        end
9610 45 mihad
 
9611
        if (found === 1)
9612
        begin
9613
            // first check if found target is supposed to exist
9614
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9615
            begin
9616
                $display("Time %t", $time) ;
9617
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9618
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9619
                ok = 0 ;
9620
            end
9621
            else
9622
            begin
9623
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9624
                begin
9625
 
9626
                    data = 32'hFFFF_FFFF ;
9627
 
9628
                    expected_data = 0 ;
9629
 
9630
                    if (reg_num == 4)
9631
                    begin
9632
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9633
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9634
                    end
9635
                    else if (reg_num == 5)
9636
                    begin
9637
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9638
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9639
                    end
9640
 
9641
                    // write base address 0
9642
                    generate_configuration_cycle
9643
                    (
9644
                        'h0,            //bus_num
9645
                        device_num,     //device_num
9646
                        'h0,            //func_num
9647
                        reg_num,        //reg_num
9648
                        'h0,            //type
9649
                        4'hF,           // byte_enables
9650
                        data,           //data
9651
                        1'b1            //read0_write1
9652
                    );
9653
 
9654
                    // read data back
9655
                    generate_configuration_cycle
9656
                    (
9657
                        'h0,            //bus_num
9658
                        device_num,     //device_num
9659
                        'h0,            //func_num
9660
                        reg_num,        //reg_num
9661
                        'h0,            //type
9662
                        4'hF,           // byte_enables
9663
                        data,           //data
9664
                        1'b0            //read0_write1
9665
                    );
9666
 
9667
                    if (data !== expected_data)
9668
                    begin
9669
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9670
                        $display("Data read back not as expected!");
9671
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9672
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9673
                        ok = 0 ;
9674
                    end
9675
                end
9676
            end
9677
        end
9678 15 mihad
    end
9679 45 mihad
 
9680
    if (ok)
9681
        test_ok ;
9682 15 mihad
end //main
9683
endtask //find_pci_devices
9684
 
9685
task find_device ;
9686
    input [31:0] device_num ;
9687
    output  found ;
9688
 
9689
    reg [31:0] read_data ;
9690
begin
9691
    found = 1'b0 ;
9692
 
9693
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9694 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9695 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9696
    else
9697
    begin
9698
        $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]) ;
9699
        found = 1'b1 ;
9700
    end
9701
end
9702
endtask //find_device
9703 45 mihad
`endif
9704 15 mihad
 
9705
/*task set_bridge_parameters ;
9706
    reg [11:0] current_offset ;
9707
    reg [2:0] result ;
9708
    reg [31:0] write_data ;
9709
begin
9710
    // set burst size
9711
    // set latency timer
9712
    current_offset = 12'h00C ;
9713
    // set burst size to 16 and latency timer to 8
9714
    write_data     = {24'h0000_08, system_burst_size} ;
9715
    config_write(current_offset, write_data, 4'b1111) ;
9716
 
9717
    // set io image
9718
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9719
    write_data = 32'h0000_000_3 ;
9720
    config_write(current_offset, write_data, 4'b1111) ;
9721
 
9722
 
9723
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9724
    write_data = 32'h0001_000_1 ;
9725
    config_write(current_offset, write_data, 4'b1111) ;
9726
 
9727
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9728
    write_data = 32'hFFFF_0000 ;
9729
    config_write(current_offset, write_data, 4'b1111) ;
9730
 
9731
    // set memory image
9732
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9733
    write_data = 32'h0000_000_7 ;
9734
    config_write(current_offset, write_data, 4'b1111) ;
9735
 
9736
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9737
    write_data = 32'h0002_000_0 ;
9738
    config_write(current_offset, write_data, 4'b1111) ;
9739
 
9740
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9741
    write_data = 32'h0001_0000 ;
9742
    config_write(current_offset, write_data, 4'b1111) ;
9743
 
9744
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9745
    write_data = 32'hFFFF_0000 ;
9746
    config_write(current_offset, write_data, 4'b1111) ;
9747
 
9748
    // set parameters for bridge's target unit
9749
    // image control 0
9750
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9751
    write_data     = 32'h0000_0002 ;
9752
    config_write(current_offset, write_data, 4'b0001) ;
9753
 
9754
    // base_address 0
9755
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9756
    write_data      = 32'h2000_0000 ;
9757
    config_write(current_offset, write_data, 4'b1111) ;
9758
 
9759
    // address mask 0
9760
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9761
    write_data     = 32'hFFFF_F000 ;
9762
    config_write(current_offset, write_data, 4'b1111) ;
9763
 
9764
    // command register - enable response to io and mem space and PCI master
9765
    current_offset = 12'h004 ;
9766
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9767
    config_write(current_offset, write_data, 4'b1111) ;
9768
end
9769
endtask // set_bridge_parameters
9770
*/
9771
 
9772
task configuration_cycle_write ;
9773
    input [7:0]  bus_num ;
9774
    input [4:0]  device_num ;
9775
    input [2:0]  func_num ;
9776
    input [5:0]  reg_num ;
9777
    input [1:0]  type ;
9778
    input [3:0]  byte_enables ;
9779
    input [31:0] data ;
9780
 
9781
    reg [31:0] write_address ;
9782
    reg in_use ;
9783
    reg ok ;
9784
begin:main
9785
 
9786
    if ( in_use === 1 )
9787
    begin
9788 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9789 15 mihad
        disable main ;
9790
    end
9791
 
9792 45 mihad
    if ( (device_num > 20) && (type === 0) )
9793 15 mihad
    begin
9794
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9795
        disable main ;
9796
    end
9797
 
9798
    in_use = 1 ;
9799
 
9800 45 mihad
 
9801
`ifdef HOST
9802
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9803
`else
9804
`ifdef GUEST
9805
 
9806 15 mihad
    if ( type )
9807
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9808
    else
9809
    begin
9810
        write_address = 0 ;
9811
        write_address[10:0] = { func_num, reg_num, type } ;
9812
        write_address[11 + device_num] = 1'b1 ;
9813
    end
9814 45 mihad
 
9815
    fork
9816 15 mihad
    begin
9817 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9818
                            write_address,
9819
                            data, ~byte_enables,
9820
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9821
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9822
        do_pause(1) ;
9823 15 mihad
    end
9824 45 mihad
    begin
9825
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9826
    end
9827
    join
9828
`endif
9829
`endif
9830
 
9831
    in_use = 0 ;
9832
end
9833
endtask // configuration_cycle_write
9834 15 mihad
 
9835 45 mihad
task configuration_cycle_read ;
9836
    input [7:0]  bus_num ;
9837
    input [4:0]  device_num ;
9838
    input [2:0]  func_num ;
9839
    input [5:0]  reg_num ;
9840
    input [1:0]  type ;
9841
    input [3:0]  byte_enables ;
9842
    output [31:0] data ;
9843 15 mihad
 
9844 45 mihad
    reg [31:0] read_address ;
9845
    reg in_use ;
9846 15 mihad
 
9847 45 mihad
    reg master_check_data_prev ;
9848
begin:main
9849 15 mihad
 
9850 45 mihad
    if ( in_use === 1 )
9851 15 mihad
    begin
9852 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9853
        data = 32'hxxxx_xxxx ;
9854
        disable main ;
9855 15 mihad
    end
9856
 
9857 45 mihad
    in_use = 1 ;
9858 15 mihad
 
9859 45 mihad
`ifdef HOST
9860
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9861
`else
9862
`ifdef GUEST
9863
     master_check_data_prev = master1_check_received_data ;
9864 15 mihad
     if ( type )
9865 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9866 15 mihad
     else
9867
     begin
9868 45 mihad
         read_address = 0 ;
9869
         read_address[10:0] = { func_num, reg_num, type } ;
9870
         read_address[11 + device_num] = 1'b1 ;
9871 15 mihad
     end
9872 45 mihad
 
9873
     fork
9874
     begin
9875
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9876
                 read_address,
9877 15 mihad
                 data, ~byte_enables,
9878
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9879
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9880 45 mihad
         do_pause(1) ;
9881
     end
9882
     begin
9883
         @(master1_received_data_valid) ;
9884
         data = master1_received_data ;
9885
     end
9886
     join
9887 15 mihad
 
9888 45 mihad
    master1_check_received_data = master_check_data_prev ;
9889
`endif
9890
`endif
9891
 
9892 15 mihad
    in_use = 0 ;
9893
 
9894 45 mihad
end //main
9895
endtask // configuration_cycle_read
9896
 
9897 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9898
task test_conf_cycle_type1_reference ;
9899
    reg [31:0] address ;
9900
    reg in_use ;
9901
 
9902
    reg master_check_data_prev ;
9903
    reg [31:0] data ;
9904
    reg monitor_ok ;
9905
    reg master_ok ;
9906
begin:main
9907
 
9908
    if ( in_use === 1 )
9909
    begin
9910
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9911
        disable main ;
9912
    end
9913
 
9914
    in_use = 1 ;
9915
 
9916
    master_check_data_prev = master1_check_received_data ;
9917
 
9918
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9919
    address = `TAR0_IDSEL_ADDR ;
9920
 
9921
    address[1:0] = 2'b01 ;
9922
 
9923
    `ifdef HOST
9924
        conf_cyc_type1_target_bus_num = 255 ;
9925
    `endif
9926
    master_ok = 1 ;
9927
    fork
9928
    begin
9929
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9930
        do_pause(1) ;
9931
    end
9932
    begin:error_monitor1
9933
        @(error_event_int) ;
9934
        master_ok = 0 ;
9935
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9936
    end
9937
    begin
9938
        pci_transaction_progress_monitor
9939
        (
9940
            address,                                                // expected address on PCI bus
9941
            `BC_CONF_READ,                                          // expected bus command on PCI bus
9942
            0,                                                      // expected number of succesfull data phases
9943
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9944
            1'b1,                                                   // monitor checking/not checking number of transfers
9945
            1'b0,                                                   // monitor checking/not checking number of cycles
9946
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9947
            monitor_ok                                              // status - 1 success, 0 failure
9948
        ) ;
9949
 
9950
        @(posedge pci_clock);
9951
        #1 ;
9952
 
9953
        if (master_ok)
9954
            disable error_monitor1 ;
9955
 
9956
        if (!monitor_ok)
9957
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9958
    end
9959
    join
9960
 
9961
    if (monitor_ok && master_ok)
9962
        test_ok ;
9963
 
9964
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
9965
    master_ok = 1 ;
9966
    fork
9967
    begin
9968
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
9969
        do_pause(1) ;
9970
    end
9971
    begin:error_monitor2
9972
        @(error_event_int) ;
9973
        master_ok = 0 ;
9974
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9975
    end
9976
    begin
9977
        pci_transaction_progress_monitor
9978
        (
9979
            address,                                                // expected address on PCI bus
9980
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
9981
            0,                                                      // expected number of succesfull data phases
9982
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9983
            1'b1,                                                   // monitor checking/not checking number of transfers
9984
            1'b0,                                                   // monitor checking/not checking number of cycles
9985
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9986
            monitor_ok                                              // status - 1 success, 0 failure
9987
        ) ;
9988
 
9989
        @(posedge pci_clock);
9990
        #1 ;
9991
 
9992
        if (master_ok)
9993
            disable error_monitor2 ;
9994
 
9995
        if (!monitor_ok)
9996
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9997
    end
9998
    join
9999
 
10000
    master1_check_received_data = master_check_data_prev ;
10001
 
10002
    if (monitor_ok && master_ok)
10003
        test_ok ;
10004
 
10005
    in_use = 0 ;
10006
 
10007
end //main
10008
endtask // test_conf_cycle_type1_reference
10009
`endif
10010
 
10011 45 mihad
`ifdef HOST
10012
task generate_configuration_cycle ;
10013 15 mihad
    input [7:0]  bus_num ;
10014
    input [4:0]  device_num ;
10015
    input [2:0]  func_num ;
10016
    input [5:0]  reg_num ;
10017
    input [1:0]  type ;
10018
    input [3:0]  byte_enables ;
10019 45 mihad
    inout [31:0] data ;
10020
    input        read0_write1 ;
10021 15 mihad
 
10022
    reg `READ_STIM_TYPE read_data ;
10023
    reg `WB_TRANSFER_FLAGS  flags ;
10024
    reg `READ_RETURN_TYPE   read_status ;
10025
 
10026
    reg `WRITE_STIM_TYPE   write_data ;
10027
    reg `WRITE_RETURN_TYPE write_status ;
10028
 
10029 45 mihad
    reg [31:0] pci_address ;
10030 15 mihad
    reg in_use ;
10031 45 mihad
    reg ok ;
10032 15 mihad
 
10033
    reg [31:0] temp_var ;
10034
begin:main
10035
 
10036
    if ( in_use === 1 )
10037
    begin
10038 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
10039 15 mihad
        data = 32'hxxxx_xxxx ;
10040
        disable main ;
10041
    end
10042
 
10043 45 mihad
    in_use = 1 ;
10044
 
10045
    if ( type )
10046
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10047
    else
10048 15 mihad
    begin
10049 45 mihad
        pci_address = 0 ;
10050
        pci_address[10:0] = { func_num, reg_num, type } ;
10051
        if (device_num <= 20)
10052
            pci_address[11 + device_num] = 1'b1 ;
10053
    end
10054
 
10055
    // setup flags
10056
    flags = 0 ;
10057
    flags`INIT_WAITS   = tb_init_waits ;
10058
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10059
 
10060
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10061
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10062
 
10063
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10064
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10065
    write_data`WRITE_SEL      = 4'hF ;
10066
    write_data`WRITE_TAG_STIM = 0 ;
10067
 
10068
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10069
 
10070
    // check if write succeeded
10071
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10072
    begin
10073
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10074 15 mihad
        data = 32'hxxxx_xxxx ;
10075 45 mihad
        in_use = 0 ;
10076 15 mihad
        disable main ;
10077
    end
10078
 
10079 45 mihad
    // setup flags for wb master to handle retries and read and write data
10080
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10081
 
10082
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10083
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10084
    read_data`READ_SEL          = byte_enables ;
10085
    write_data`WRITE_SEL        = byte_enables ;
10086
    read_data`READ_TAG_STIM     = 0 ;
10087
    write_data`WRITE_TAG_STIM   = 0 ;
10088
    write_data`WRITE_DATA       = data ;
10089
 
10090
    ok = 0 ;
10091
 
10092
    fork
10093
    begin
10094
        if (read0_write1 === 0)
10095
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
10096
        else
10097
        if (read0_write1 === 1)
10098
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
10099
    end
10100
    begin
10101
        pci_transaction_progress_monitor
10102
        (
10103
            pci_address,                                            // expected address on PCI bus
10104
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10105
            1,                                                      // expected number of succesfull data phases
10106
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10107
            1'b0,                                                   // monitor checking/not checking number of transfers
10108
            1'b0,                                                   // monitor checking/not checking number of cycles
10109
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10110
            ok                                                      // status - 1 success, 0 failure
10111
        ) ;
10112
    end
10113
    join
10114
 
10115
    // check if transfer succeeded
10116
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10117
    begin
10118
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10119
        data = 32'hxxxx_xxxx ;
10120
        in_use = 0 ;
10121
        disable main ;
10122
    end
10123
 
10124
    if (!ok)
10125
    begin
10126
        data = 32'hxxxx_xxxx ;
10127
        in_use = 0 ;
10128
        disable main ;
10129
    end
10130
 
10131
    if (read0_write1 === 0)
10132
        data = read_status`READ_DATA ;
10133
 
10134
    in_use = 0 ;
10135
end
10136
endtask // generate_configuration_cycle
10137
 
10138
task test_configuration_cycle_target_abort ;
10139
    reg `READ_STIM_TYPE read_data ;
10140
    reg `WB_TRANSFER_FLAGS  flags ;
10141
    reg `READ_RETURN_TYPE   read_status ;
10142
 
10143
    reg `WRITE_STIM_TYPE   write_data ;
10144
    reg `WRITE_RETURN_TYPE write_status ;
10145
 
10146
    reg [31:0] pci_address ;
10147
    reg in_use ;
10148
    reg ok_pci ;
10149
    reg ok_wb  ;
10150
    reg ok     ;
10151
 
10152
    reg [31:0] temp_var ;
10153
 
10154
begin:main
10155
 
10156
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10157
 
10158
    if ( in_use === 1 )
10159
    begin
10160
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10161
        disable main ;
10162
    end
10163
 
10164 15 mihad
    in_use = 1 ;
10165
 
10166 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10167
 
10168 15 mihad
    // setup flags
10169
    flags = 0 ;
10170 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10171
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10172 15 mihad
 
10173
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10174
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10175
 
10176
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10177 45 mihad
    temp_var                  = 0 ;
10178
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10179
    write_data`WRITE_DATA     = temp_var ;
10180 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10181
    write_data`WRITE_TAG_STIM = 0 ;
10182
 
10183
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10184
 
10185
    // check if write succeeded
10186
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10187
    begin
10188
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10189 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10190
        in_use = 0 ;
10191 15 mihad
        disable main ;
10192
    end
10193
 
10194 45 mihad
    // setup flags for wb master to handle retries and read and write data
10195 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10196
 
10197 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10198
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10199 15 mihad
 
10200 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10201
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10202
    read_data`READ_SEL          = 4'hF ;
10203
    write_data`WRITE_SEL        = 4'hF ;
10204
    read_data`READ_TAG_STIM     = 0 ;
10205
    write_data`WRITE_TAG_STIM   = 0 ;
10206
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10207
 
10208
    ok_pci = 0 ;
10209
    ok_wb  = 1 ;
10210
 
10211
    // set target to terminate with target abort
10212
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10213
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10214
    fork
10215
    begin
10216
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10217
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10218
        begin
10219
            $display("Time %t", $time) ;
10220
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10221
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10222
            ok_wb = 0 ;
10223
        end
10224
 
10225
        config_read( 12'h4, 4'hF, temp_var ) ;
10226
        if ( temp_var[29] !== 0 )
10227
        begin
10228
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10229
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10230
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10231
            ok_wb = 0 ;
10232
        end
10233
 
10234
        if ( temp_var[28] !== 1 )
10235
        begin
10236
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10237
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10238
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10239
            ok_wb = 0 ;
10240
        end
10241
 
10242
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10243
 
10244
        if (ok !== 1)
10245
        begin
10246
            ok_wb = 0 ;
10247
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10248
            $display("Write to PCI Device Status Register failed") ;
10249
            test_fail("Write to PCI Device Status Register failed") ;
10250
        end
10251
 
10252
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10253
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10254
        begin
10255
            $display("Time %t", $time) ;
10256
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10257
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10258
            ok_wb = 0 ;
10259
        end
10260
 
10261
        config_read( 12'h4, 4'hF, temp_var ) ;
10262
        if ( temp_var[29] !== 0 )
10263
        begin
10264
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10265
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10266
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10267
            ok_wb = 0 ;
10268
        end
10269
 
10270
        if ( temp_var[28] !== 1 )
10271
        begin
10272
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10273
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10274
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10275
            ok_wb = 0 ;
10276
        end
10277
 
10278
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10279
 
10280
        if (ok !== 1)
10281
        begin
10282
            ok_wb = 0 ;
10283
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10284
            $display("Write to PCI Device Status Register failed") ;
10285
            test_fail("Write to PCI Device Status Register failed") ;
10286
        end
10287
    end
10288
    begin
10289
        pci_transaction_progress_monitor
10290
        (
10291
            pci_address,                                            // expected address on PCI bus
10292
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10293
            0,                                                      // expected number of succesfull data phases
10294
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10295
            1'b1,                                                   // monitor checking/not checking number of transfers
10296
            1'b0,                                                   // monitor checking/not checking number of cycles
10297
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10298
            ok_pci                                                  // status - 1 success, 0 failure
10299
        ) ;
10300
 
10301
        if (ok_pci)
10302
        begin
10303
            pci_transaction_progress_monitor
10304
            (
10305
                pci_address,                                            // expected address on PCI bus
10306
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10307
                0,                                                      // expected number of succesfull data phases
10308
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10309
                1'b1,                                                   // monitor checking/not checking number of transfers
10310
                1'b0,                                                   // monitor checking/not checking number of cycles
10311
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10312
                ok_pci                                                  // status - 1 success, 0 failure
10313
            ) ;
10314
        end
10315
 
10316
        if (!ok_pci)
10317
        begin
10318
            $display("Time %t", $time) ;
10319
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10320
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10321
        end
10322
    end
10323
    join
10324
 
10325
    if (ok_pci && ok_wb)
10326
    begin
10327
        test_ok ;
10328
    end
10329
 
10330
    in_use = 0 ;
10331
 
10332
    // set target to terminate normally
10333
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10334
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10335
end
10336
endtask // test_configuration_cycle_target_abort
10337
 
10338
task test_configuration_cycle_type1_generation ;
10339
    reg `READ_STIM_TYPE read_data ;
10340
    reg `WB_TRANSFER_FLAGS  flags ;
10341
    reg `READ_RETURN_TYPE   read_status ;
10342
 
10343
    reg `WRITE_STIM_TYPE   write_data ;
10344
    reg `WRITE_RETURN_TYPE write_status ;
10345
 
10346
    reg [31:0] pci_address ;
10347
    reg in_use ;
10348
    reg ok_pci ;
10349
    reg ok_wb  ;
10350
    reg ok     ;
10351
 
10352
    reg [31:0] temp_var ;
10353
 
10354
begin:main
10355
 
10356
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10357
    conf_cyc_type1_target_data = 0 ;
10358
    conf_cyc_type1_target_bus_num = 0;
10359
 
10360
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10361
 
10362
    if ( in_use === 1 )
10363
    begin
10364
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10365
        disable main ;
10366
    end
10367
 
10368
    in_use = 1 ;
10369
 
10370
    pci_address        = 32'hAAAA_AAAA ;
10371
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10372
 
10373
    // setup flags
10374
    flags = 0 ;
10375
    flags`INIT_WAITS   = tb_init_waits ;
10376
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10377
 
10378
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10379
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10380
 
10381
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10382
    write_data`WRITE_DATA     = pci_address ;
10383
    write_data`WRITE_SEL      = 4'hF ;
10384
    write_data`WRITE_TAG_STIM = 0 ;
10385
 
10386
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10387
 
10388
    // check if write succeeded
10389
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10390
    begin
10391
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10392
        test_fail("write to configuration cycle address register was not possible") ;
10393
        in_use = 0 ;
10394
        disable main ;
10395
    end
10396
 
10397
    // setup flags for wb master to handle retries and read and write data
10398
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10399
 
10400
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10401
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10402
 
10403
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10404
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10405
    read_data`READ_SEL          = 4'hF ;
10406
    write_data`WRITE_SEL        = 4'hF ;
10407
    read_data`READ_TAG_STIM     = 0 ;
10408
    write_data`WRITE_TAG_STIM   = 0 ;
10409
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10410
 
10411
    ok_pci = 0 ;
10412
    ok_wb  = 1 ;
10413
 
10414
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10415
    pci_address[31:24] = 0 ;
10416
    fork
10417
    begin
10418
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10419
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10420
        begin
10421
            $display("Time %t", $time) ;
10422
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10423
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10424
            ok_wb = 0 ;
10425
        end
10426
 
10427
        config_read( 12'h4, 4'hF, temp_var ) ;
10428
        if ( temp_var[29] !== 1 )
10429
        begin
10430
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10431
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10432
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10433
            ok_wb = 0 ;
10434
        end
10435
 
10436
        if ( temp_var[28] !== 0 )
10437
        begin
10438
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10439
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10440
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10441
            ok_wb = 0 ;
10442
        end
10443
 
10444
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10445
 
10446
        if (ok !== 1)
10447
        begin
10448
            ok_wb = 0 ;
10449
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10450
            $display("Write to PCI Device Status Register failed") ;
10451
            test_fail("Write to PCI Device Status Register failed") ;
10452
        end
10453
 
10454
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10455
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10456
        begin
10457
            $display("Time %t", $time) ;
10458
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10459
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10460
            ok_wb = 0 ;
10461
        end
10462
 
10463
        config_read( 12'h4, 4'hF, temp_var ) ;
10464
        if ( temp_var[29] !== 1 )
10465
        begin
10466
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10467
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10468
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10469
            ok_wb = 0 ;
10470
        end
10471
 
10472
        if ( temp_var[28] !== 0 )
10473
        begin
10474
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10475
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10476
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10477
            ok_wb = 0 ;
10478
        end
10479
 
10480
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10481
 
10482
        if (ok !== 1)
10483
        begin
10484
            ok_wb = 0 ;
10485
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10486
            $display("Write to PCI Device Status Register failed") ;
10487
            test_fail("Write to PCI Device Status Register failed") ;
10488
        end
10489
    end
10490
    begin
10491
        pci_transaction_progress_monitor
10492
        (
10493
            pci_address,                                            // expected address on PCI bus
10494
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10495
            0,                                                      // expected number of succesfull data phases
10496
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10497
            1'b1,                                                   // monitor checking/not checking number of transfers
10498
            1'b0,                                                   // monitor checking/not checking number of cycles
10499
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10500
            ok_pci                                                  // status - 1 success, 0 failure
10501
        ) ;
10502
 
10503
        if (ok_pci)
10504
        begin
10505
            pci_transaction_progress_monitor
10506
            (
10507
                pci_address,                                            // expected address on PCI bus
10508
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10509
                0,                                                      // expected number of succesfull data phases
10510
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10511
                1'b1,                                                   // monitor checking/not checking number of transfers
10512
                1'b0,                                                   // monitor checking/not checking number of cycles
10513
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10514
                ok_pci                                                  // status - 1 success, 0 failure
10515
            ) ;
10516
        end
10517
 
10518
        if (!ok_pci)
10519
        begin
10520
            $display("Time %t", $time) ;
10521
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10522
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10523
        end
10524
    end
10525
    join
10526
 
10527
    if (ok_pci && ok_wb)
10528
    begin
10529
        test_ok ;
10530
    end
10531
 
10532
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10533
    conf_cyc_type1_target_data = 0 ;
10534
    conf_cyc_type1_target_bus_num = 8'h55;
10535
 
10536
    pci_address      = 32'h5555_5555 ;
10537
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10538
 
10539
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10540
 
10541
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10542
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10543
 
10544
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10545
    write_data`WRITE_DATA     = pci_address ;
10546
    write_data`WRITE_SEL      = 4'hF ;
10547
    write_data`WRITE_TAG_STIM = 0 ;
10548
 
10549
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10550
 
10551
    // check if write succeeded
10552
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10553
    begin
10554
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10555
        test_fail("write to configuration cycle address register was not possible") ;
10556
        in_use = 0 ;
10557
        disable main ;
10558
    end
10559
 
10560
    // setup flags for wb master to handle retries and read and write data
10561
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10562
 
10563
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10564
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10565
 
10566
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10567
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10568
    read_data`READ_SEL          = 4'hF ;
10569
    write_data`WRITE_SEL        = 4'hF ;
10570
    read_data`READ_TAG_STIM     = 0 ;
10571
    write_data`WRITE_TAG_STIM   = 0 ;
10572
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10573
 
10574
    ok_pci = 0 ;
10575
    ok_wb  = 1 ;
10576
 
10577
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10578
    pci_address[31:24] = 0 ;
10579
    fork
10580
    begin
10581
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10582
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10583
        begin
10584
            $display("Time %t", $time) ;
10585
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10586
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10587
            ok_wb = 0 ;
10588
        end
10589
 
10590
        config_read( 12'h4, 4'hF, temp_var ) ;
10591
        if ( temp_var[29] !== 0 )
10592
        begin
10593
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10594
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10595
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10596
            ok_wb = 0 ;
10597
        end
10598
 
10599
        if ( temp_var[28] !== 1 )
10600
        begin
10601
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10602
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10603
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10604
            ok_wb = 0 ;
10605
        end
10606
 
10607
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10608
 
10609
        if (ok !== 1)
10610
        begin
10611
            ok_wb = 0 ;
10612
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10613
            $display("Write to PCI Device Status Register failed") ;
10614
            test_fail("Write to PCI Device Status Register failed") ;
10615
        end
10616
 
10617
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10618
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10619
        begin
10620
            $display("Time %t", $time) ;
10621
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10622
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10623
            ok_wb = 0 ;
10624
        end
10625
 
10626
        config_read( 12'h4, 4'hF, temp_var ) ;
10627
        if ( temp_var[29] !== 0 )
10628
        begin
10629
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10630
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10631
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10632
            ok_wb = 0 ;
10633
        end
10634
 
10635
        if ( temp_var[28] !== 1 )
10636
        begin
10637
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10638
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10639
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10640
            ok_wb = 0 ;
10641
        end
10642
 
10643
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10644
 
10645
        if (ok !== 1)
10646
        begin
10647
            ok_wb = 0 ;
10648
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10649
            $display("Write to PCI Device Status Register failed") ;
10650
            test_fail("Write to PCI Device Status Register failed") ;
10651
        end
10652
    end
10653
    begin
10654
        pci_transaction_progress_monitor
10655
        (
10656
            pci_address,                                            // expected address on PCI bus
10657
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10658
            0,                                                      // expected number of succesfull data phases
10659
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10660
            1'b1,                                                   // monitor checking/not checking number of transfers
10661
            1'b0,                                                   // monitor checking/not checking number of cycles
10662
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10663
            ok_pci                                                  // status - 1 success, 0 failure
10664
        ) ;
10665
 
10666
        if (ok_pci)
10667
        begin
10668
            pci_transaction_progress_monitor
10669
            (
10670
                pci_address,                                            // expected address on PCI bus
10671
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10672
                0,                                                      // expected number of succesfull data phases
10673
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10674
                1'b1,                                                   // monitor checking/not checking number of transfers
10675
                1'b0,                                                   // monitor checking/not checking number of cycles
10676
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10677
                ok_pci                                                  // status - 1 success, 0 failure
10678
            ) ;
10679
        end
10680
 
10681
        if (!ok_pci)
10682
        begin
10683
            $display("Time %t", $time) ;
10684
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10685
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10686
        end
10687
    end
10688
    join
10689
 
10690
    if (ok_pci && ok_wb)
10691
    begin
10692
        test_ok ;
10693
    end
10694
 
10695
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10696
 
10697
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10698
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10699
    conf_cyc_type1_target_bus_num = 8'hAA;
10700
 
10701
    pci_address      = 32'hAAAA_AAAA ;
10702
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10703
 
10704
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10705
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10706
 
10707
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10708
    write_data`WRITE_DATA     = pci_address ;
10709
    write_data`WRITE_SEL      = 4'hF ;
10710
    write_data`WRITE_TAG_STIM = 0 ;
10711
 
10712
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10713
 
10714
    // check if write succeeded
10715
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10716
    begin
10717
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10718
        test_fail("write to configuration cycle address register was not possible") ;
10719
        in_use = 0 ;
10720
        disable main ;
10721
    end
10722
 
10723
    // setup flags for wb master to handle retries and read and write data
10724
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10725
 
10726
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10727
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10728
 
10729
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10730
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10731
    read_data`READ_SEL          = 4'b0101 ;
10732
    write_data`WRITE_SEL        = 4'b1010 ;
10733
    read_data`READ_TAG_STIM     = 0 ;
10734
    write_data`WRITE_TAG_STIM   = 0 ;
10735
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10736
 
10737
    ok_pci = 0 ;
10738
    ok_wb  = 1 ;
10739
 
10740
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10741
    pci_address[31:24] = 0 ;
10742
 
10743
    fork
10744
    begin
10745
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10746
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10747
        begin
10748
            $display("Time %t", $time) ;
10749
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10750
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10751
            ok_wb = 0 ;
10752
        end
10753
 
10754
        config_read( 12'h4, 4'hF, temp_var ) ;
10755
        if ( temp_var[29] !== 0 )
10756
        begin
10757
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10758
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10759
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10760
            ok_wb = 0 ;
10761
        end
10762
 
10763
        if ( temp_var[28] !== 0 )
10764
        begin
10765
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10766
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10767
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10768
            ok_wb = 0 ;
10769
        end
10770
 
10771
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10772
 
10773
        if (ok !== 1)
10774
        begin
10775
            ok_wb = 0 ;
10776
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10777
            $display("Write to PCI Device Status Register failed") ;
10778
            test_fail("Write to PCI Device Status Register failed") ;
10779
        end
10780
 
10781
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10782
        begin
10783
            ok_wb = 0 ;
10784
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10785
            $display("Read Data provided by the bridge was not as expected!") ;
10786
            test_fail("Read Data provided by the bridge was not as expected") ;
10787
        end
10788
 
10789
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10790
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10791
        begin
10792
            $display("Time %t", $time) ;
10793
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10794
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10795
            ok_wb = 0 ;
10796
        end
10797
 
10798
        config_read( 12'h4, 4'hF, temp_var ) ;
10799
        if ( temp_var[29] !== 0 )
10800
        begin
10801
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10802
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10803
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10804
            ok_wb = 0 ;
10805
        end
10806
 
10807
        if ( temp_var[28] !== 0 )
10808
        begin
10809
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10810
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10811
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10812
            ok_wb = 0 ;
10813
        end
10814
 
10815
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10816
 
10817
        if (ok !== 1)
10818
        begin
10819
            ok_wb = 0 ;
10820
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10821
            $display("Write to PCI Device Status Register failed") ;
10822
            test_fail("Write to PCI Device Status Register failed") ;
10823
        end
10824
 
10825
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10826
        begin
10827
            ok_wb = 0 ;
10828
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10829
            $display("Data written by the bridge was not as expected!") ;
10830
            test_fail("Data written by the bridge was not as expected") ;
10831
        end
10832
 
10833
    end
10834
    begin
10835
        ok = 1 ;
10836
        repeat(8)
10837
        begin
10838
            pci_transaction_progress_monitor
10839
            (
10840
                pci_address,                                            // expected address on PCI bus
10841
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10842
                0,                                                      // expected number of succesfull data phases
10843
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10844
                1'b1,                                                   // monitor checking/not checking number of transfers
10845
                1'b0,                                                   // monitor checking/not checking number of cycles
10846
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10847
                ok_pci                                                  // status - 1 success, 0 failure
10848
            ) ;
10849
 
10850
            if (!ok_pci)
10851
            begin
10852
                ok = 0 ;
10853
                $display("Time %t", $time) ;
10854
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10855
            end
10856
        end
10857
 
10858
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10859
 
10860
        pci_transaction_progress_monitor
10861
        (
10862
            pci_address,                                            // expected address on PCI bus
10863
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10864
            1,                                                      // expected number of succesfull data phases
10865
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10866
            1'b1,                                                   // monitor checking/not checking number of transfers
10867
            1'b0,                                                   // monitor checking/not checking number of cycles
10868
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10869
            ok_pci                                                  // status - 1 success, 0 failure
10870
        ) ;
10871
 
10872
        if (!ok_pci)
10873
        begin
10874
            ok = 0 ;
10875
            $display("Time %t", $time) ;
10876
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10877
        end
10878
 
10879
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10880
        repeat(8)
10881
        begin
10882
            pci_transaction_progress_monitor
10883
            (
10884
                pci_address,                                            // expected address on PCI bus
10885
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10886
                0,                                                      // expected number of succesfull data phases
10887
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10888
                1'b1,                                                   // monitor checking/not checking number of transfers
10889
                1'b0,                                                   // monitor checking/not checking number of cycles
10890
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10891
                ok_pci                                                  // status - 1 success, 0 failure
10892
            ) ;
10893
 
10894
            if (!ok_pci)
10895
            begin
10896
                ok = 0 ;
10897
                $display("Time %t", $time) ;
10898
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10899
            end
10900
        end
10901
 
10902
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10903
        pci_transaction_progress_monitor
10904
        (
10905
            pci_address,                                            // expected address on PCI bus
10906
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10907
            1,                                                      // expected number of succesfull data phases
10908
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10909
            1'b1,                                                   // monitor checking/not checking number of transfers
10910
            1'b0,                                                   // monitor checking/not checking number of cycles
10911
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10912
            ok_pci                                                  // status - 1 success, 0 failure
10913
        ) ;
10914
 
10915
        if (!ok_pci)
10916
        begin
10917
            ok = 0 ;
10918
            $display("Time %t", $time) ;
10919
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10920
        end
10921
 
10922
        if (!ok)
10923
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10924
    end
10925
    join
10926
 
10927
    if (ok_pci && ok_wb)
10928
    begin
10929
        test_ok ;
10930
    end
10931
 
10932
    in_use = 0 ;
10933
end
10934
endtask // test_configuration_cycle_type1_generation
10935
`endif
10936
 
10937
task test_initial_conf_values ;
10938
    reg [11:0] register_offset ;
10939
    reg [31:0] expected_value ;
10940
    reg        failed ;
10941
`ifdef HOST
10942
    reg `READ_STIM_TYPE    read_data ;
10943
    reg `WB_TRANSFER_FLAGS flags ;
10944
    reg `READ_RETURN_TYPE  read_status ;
10945
 
10946
    reg `WRITE_STIM_TYPE   write_data ;
10947
    reg `WRITE_RETURN_TYPE write_status ;
10948
begin
10949
    failed     = 0 ;
10950
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
10951
    flags      = 0 ;
10952
    read_data  = 0 ;
10953
    write_data = 0 ;
10954
 
10955
    read_data`READ_SEL = 4'hF ;
10956
 
10957
    flags`INIT_WAITS           = tb_init_waits ;
10958
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10959
 
10960
    // test MEM/IO map bit initial value in each PCI BAR
10961
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
10962
 
10963
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10964
 
10965 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10966
 
10967 45 mihad
    `ifdef NO_CNF_IMAGE
10968
        `ifdef PCI_IMAGE0
10969
            if (`PCI_AM0)
10970
                expected_value = `PCI_BA0_MEM_IO ;
10971
            else
10972
                expected_value = 32'h0000_0000 ;
10973
        `else
10974
            expected_value = 32'h0000_0000 ;
10975
        `endif
10976
    `else
10977
        expected_value = 32'h0000_0000 ;
10978
    `endif
10979
 
10980 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10981
    begin
10982 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
10983
        failed = 1 ;
10984 15 mihad
    end
10985 45 mihad
    else
10986
    begin
10987
        if (read_status`READ_DATA !== expected_value)
10988
        begin
10989
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
10990
            failed = 1 ;
10991
        end
10992
    end
10993 15 mihad
 
10994 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
10995 15 mihad
 
10996 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10997
 
10998
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10999
 
11000
    if (`PCI_AM1)
11001
        expected_value = `PCI_BA1_MEM_IO ;
11002
    else
11003
        expected_value = 32'h0000_0000 ;
11004
 
11005
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11006
    begin
11007
        test_fail("read from P_BA1 register didn't succeede") ;
11008
        failed = 1 ;
11009
    end
11010
    else
11011
    begin
11012
        if (read_status`READ_DATA !== expected_value)
11013
        begin
11014
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
11015
            failed = 1 ;
11016
        end
11017
    end
11018
 
11019
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
11020
 
11021
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11022
 
11023
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11024
 
11025
    `ifdef PCI_IMAGE2
11026
        if (`PCI_AM2)
11027
            expected_value = `PCI_BA2_MEM_IO ;
11028
        else
11029
            expected_value = 32'h0000_0000 ;
11030 15 mihad
    `else
11031 45 mihad
        expected_value = 32'h0000_0000 ;
11032
    `endif
11033 15 mihad
 
11034 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11035
    begin
11036
        test_fail("read from P_BA2 register didn't succeede") ;
11037
        failed = 1 ;
11038
    end
11039
    else
11040
    begin
11041
        if (read_status`READ_DATA !== expected_value)
11042
        begin
11043
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
11044
            failed = 1 ;
11045
        end
11046
    end
11047 15 mihad
 
11048 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
11049
 
11050
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11051
 
11052
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11053
 
11054
    `ifdef PCI_IMAGE3
11055
        if (`PCI_AM3)
11056
            expected_value = `PCI_BA3_MEM_IO ;
11057
        else
11058
            expected_value = 32'h0000_0000 ;
11059
    `else
11060
        expected_value = 32'h0000_0000 ;
11061 15 mihad
    `endif
11062 45 mihad
 
11063
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11064
    begin
11065
        test_fail("read from P_BA3 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("BA3 MEM/IO initial bit value was not set as defined");
11073
            failed = 1 ;
11074
        end
11075
    end
11076
 
11077
    register_offset = {1'b1, `P_BA4_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_IMAGE4
11084
        if (`PCI_AM4)
11085
            expected_value = `PCI_BA4_MEM_IO ;
11086
        else
11087
            expected_value = 32'h0000_0000 ;
11088
    `else
11089
        expected_value = 32'h0000_0000 ;
11090 15 mihad
    `endif
11091
 
11092 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11093
    begin
11094
        test_fail("read from P_BA4 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("BA4 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_BA5_ADDR, 2'b00} ;
11107 15 mihad
 
11108 45 mihad
    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_IMAGE5
11113
        if(`PCI_AM5)
11114
            expected_value = `PCI_BA5_MEM_IO ;
11115
        else
11116
            expected_value = 32'h0000_0000 ;
11117
    `else
11118
        expected_value = 32'h0000_0000 ;
11119
    `endif
11120
 
11121
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11122
    begin
11123
        test_fail("read from P_BA5 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("BA5 MEM/IO initial bit value was not set as defined");
11131
            failed = 1 ;
11132
        end
11133
    end
11134
 
11135
    // test Address Mask initial values
11136
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11137
 
11138
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11139
 
11140
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11141
 
11142
    `ifdef NO_CNF_IMAGE
11143
        `ifdef PCI_IMAGE0
11144
            expected_value = {`PCI_AM0, 12'h000};
11145
 
11146
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11147
        `else
11148
            expected_value = 32'h0000_0000 ;
11149
        `endif
11150
    `else
11151
        expected_value = 32'hFFFF_FFFF ;
11152
 
11153
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11154
    `endif
11155
 
11156
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11157
    begin
11158
        test_fail("read from P_AM0 register didn't succeede") ;
11159
        failed = 1 ;
11160
    end
11161
    else
11162
    begin
11163
        if (read_status`READ_DATA !== expected_value)
11164
        begin
11165
            test_fail("AM0 initial value was not set as defined");
11166
            failed = 1 ;
11167
        end
11168
    end
11169
 
11170
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11171
 
11172
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11173
 
11174
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11175
 
11176
    expected_value = {`PCI_AM1, 12'h000};
11177
 
11178
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11179
 
11180
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11181
    begin
11182
        test_fail("read from P_AM1 register didn't succeede") ;
11183
        failed = 1 ;
11184
    end
11185
    else
11186
    begin
11187
        if (read_status`READ_DATA !== expected_value)
11188
        begin
11189
            test_fail("AM1 initial value was not set as defined");
11190
            failed = 1 ;
11191
        end
11192
    end
11193
 
11194
    register_offset = {1'b1, `P_AM2_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 PCI_IMAGE2
11201
        expected_value = {`PCI_AM2, 12'h000};
11202
 
11203
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11204
    `else
11205
        expected_value = 32'h0000_0000 ;
11206
    `endif
11207
 
11208
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11209
    begin
11210
        test_fail("read from P_AM2 register didn't succeede") ;
11211
        failed = 1 ;
11212
    end
11213
    else
11214
    begin
11215
        if (read_status`READ_DATA !== expected_value)
11216
        begin
11217
            test_fail("AM2 initial value was not set as defined");
11218
            failed = 1 ;
11219
        end
11220
    end
11221
 
11222
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11223
 
11224
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11225
 
11226
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11227
 
11228
    `ifdef PCI_IMAGE3
11229
        expected_value = {`PCI_AM3, 12'h000};
11230
 
11231
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11232
    `else
11233
        expected_value = 32'h0000_0000 ;
11234
    `endif
11235
 
11236
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11237
    begin
11238
        test_fail("read from P_AM3 register didn't succeede") ;
11239
        failed = 1 ;
11240
    end
11241
    else
11242
    begin
11243
        if (read_status`READ_DATA !== expected_value)
11244
        begin
11245
            test_fail("AM3 initial value was not set as defined");
11246
            failed = 1 ;
11247
        end
11248
    end
11249
 
11250
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11251
 
11252
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11253
 
11254
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11255
 
11256
    `ifdef PCI_IMAGE4
11257
        expected_value = {`PCI_AM4, 12'h000};
11258
 
11259
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11260
    `else
11261
        expected_value = 32'h0000_0000 ;
11262
    `endif
11263
 
11264
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11265
    begin
11266
        test_fail("read from P_AM4 register didn't succeede") ;
11267
        failed = 1 ;
11268
    end
11269
    else
11270
    begin
11271
        if (read_status`READ_DATA !== expected_value)
11272
        begin
11273
            test_fail("AM4 initial value was not set as defined");
11274
            failed = 1 ;
11275
        end
11276
    end
11277
 
11278
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11279
 
11280
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11281
 
11282
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11283
 
11284
    `ifdef PCI_IMAGE5
11285
        expected_value = {`PCI_AM5, 12'h000};
11286
 
11287
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11288
    `else
11289
        expected_value = 32'h0000_0000 ;
11290
    `endif
11291
 
11292
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11293
    begin
11294
        test_fail("read from P_AM5 register didn't succeede") ;
11295
        failed = 1 ;
11296
    end
11297
    else
11298
    begin
11299
        if (read_status`READ_DATA !== expected_value)
11300
        begin
11301
            test_fail("AM5 initial value was not set as defined");
11302
            failed = 1 ;
11303
        end
11304
    end
11305
 
11306
`endif
11307
 
11308
`ifdef GUEST
11309
    reg [31:0] read_data ;
11310
begin
11311
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11312
    failed    = 0 ;
11313
 
11314
    // check all images' BARs
11315
 
11316
    // BAR0
11317
    configuration_cycle_read
11318
    (
11319
        8'h00,                          // bus number [7:0]
11320
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11321
        3'h0,                           // function number [2:0]
11322
        6'h4,                           // register number [5:0]
11323
        2'h0,                           // type [1:0]
11324
        4'hF,                           // byte enables [3:0]
11325
        read_data                       // data returned from configuration read [31:0]
11326
    ) ;
11327
 
11328
    expected_value = 32'h0000_0000 ;
11329
 
11330
    if( read_data !== expected_value)
11331
    begin
11332
        test_fail("initial value of BAR0 register not as expected") ;
11333
        failed = 1 ;
11334
    end
11335
 
11336
    // BAR1
11337
    configuration_cycle_read
11338
    (
11339
        8'h00,                          // bus number [7:0]
11340
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11341
        3'h0,                           // function number [2:0]
11342
        6'h5,                           // register number [5:0]
11343
        2'h0,                           // type [1:0]
11344
        4'hF,                           // byte enables [3:0]
11345
        read_data                       // data returned from configuration read [31:0]
11346
    ) ;
11347
 
11348
    if (`PCI_AM1)
11349
        expected_value = `PCI_BA1_MEM_IO ;
11350
    else
11351
        expected_value = 32'h0000_0000 ;
11352
 
11353
    if( read_data !== expected_value)
11354
    begin
11355
        test_fail("initial value of BAR1 register not as expected") ;
11356
        failed = 1 ;
11357
    end
11358
 
11359
    // BAR2
11360
    configuration_cycle_read
11361
    (
11362
        8'h00,                          // bus number [7:0]
11363
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11364
        3'h0,                           // function number [2:0]
11365
        6'h6,                           // register number [5:0]
11366
        2'h0,                           // type [1:0]
11367
        4'hF,                           // byte enables [3:0]
11368
        read_data                       // data returned from configuration read [31:0]
11369
    ) ;
11370
 
11371
    `ifdef PCI_IMAGE2
11372
    if (`PCI_AM2)
11373
        expected_value = `PCI_BA2_MEM_IO ;
11374
    else
11375
        expected_value = 32'h0000_0000 ;
11376
    `else
11377
    expected_value = 32'h0 ;
11378
    `endif
11379
 
11380
    if( read_data !== expected_value)
11381
    begin
11382
        test_fail("initial value of BAR2 register not as expected") ;
11383
        failed = 1 ;
11384
    end
11385
 
11386
    // BAR3
11387
    configuration_cycle_read
11388
    (
11389
        8'h00,                          // bus number [7:0]
11390
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11391
        3'h0,                           // function number [2:0]
11392
        6'h7,                           // register number [5:0]
11393
        2'h0,                           // type [1:0]
11394
        4'hF,                           // byte enables [3:0]
11395
        read_data                       // data returned from configuration read [31:0]
11396
    ) ;
11397
 
11398
    `ifdef PCI_IMAGE3
11399
    if(`PCI_AM3)
11400
        expected_value = `PCI_BA3_MEM_IO ;
11401
    else
11402
        expected_value = 32'h0000_0000 ;
11403
    `else
11404
    expected_value = 32'h0 ;
11405
    `endif
11406
 
11407
    if( read_data !== expected_value)
11408
    begin
11409
        test_fail("initial value of BAR3 register not as expected") ;
11410
        failed = 1 ;
11411
    end
11412
 
11413
    // BAR4
11414
    configuration_cycle_read
11415
    (
11416
        8'h00,                          // bus number [7:0]
11417
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11418
        3'h0,                           // function number [2:0]
11419
        6'h8,                           // register number [5:0]
11420
        2'h0,                           // type [1:0]
11421
        4'hF,                           // byte enables [3:0]
11422
        read_data                       // data returned from configuration read [31:0]
11423
    ) ;
11424
 
11425
    `ifdef PCI_IMAGE4
11426
    if (`PCI_AM4)
11427
        expected_value = `PCI_BA4_MEM_IO ;
11428
    else
11429
        expected_value = 32'h0000_0000 ;
11430
    `else
11431
    expected_value = 32'h0 ;
11432
    `endif
11433
 
11434
    if( read_data !== expected_value)
11435
    begin
11436
        test_fail("initial value of BAR4 register not as expected") ;
11437
        failed = 1 ;
11438
    end
11439
 
11440
    // BAR5
11441
    configuration_cycle_read
11442
    (
11443
        8'h00,                          // bus number [7:0]
11444
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11445
        3'h0,                           // function number [2:0]
11446
        6'h9,                           // register number [5:0]
11447
        2'h0,                           // type [1:0]
11448
        4'hF,                           // byte enables [3:0]
11449
        read_data                       // data returned from configuration read [31:0]
11450
    ) ;
11451
 
11452
    `ifdef PCI_IMAGE5
11453
    if(`PCI_AM5)
11454
        expected_value = `PCI_BA5_MEM_IO ;
11455
    else
11456
        expected_value = 32'h0000_0000 ;
11457
    `else
11458
    expected_value = 32'h0 ;
11459
    `endif
11460
 
11461
    if( read_data !== expected_value)
11462
    begin
11463
        test_fail("initial value of BAR5 register not as expected") ;
11464
        failed = 1 ;
11465
    end
11466
 
11467
    // write all 1s to BAR0
11468
    read_data = 32'hFFFF_FFFF ;
11469
 
11470
    // BAR0
11471
    configuration_cycle_write
11472
    (
11473
        8'h00,                          // bus number [7:0]
11474
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11475
        3'h0,                           // function number [2:0]
11476
        6'h4,                           // register number [5:0]
11477
        2'h0,                           // type [1:0]
11478
        4'hF,                           // byte enables [3:0]
11479
        read_data                       // data to write [31:0]
11480
    ) ;
11481
 
11482
    expected_value = 32'hFFFF_FFFF ;
11483
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11484
 
11485
    configuration_cycle_read
11486
    (
11487
        8'h00,                          // bus number [7:0]
11488
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11489
        3'h0,                           // function number [2:0]
11490
        6'h4,                           // register number [5:0]
11491
        2'h0,                           // type [1:0]
11492
        4'hF,                           // byte enables [3:0]
11493
        read_data                       // data to write [31:0]
11494
    ) ;
11495
 
11496
    if ( read_data !== expected_value )
11497
    begin
11498
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11499
        failed = 1 ;
11500
    end
11501
 
11502
    // write all 1s to BAR1
11503
    read_data = 32'hFFFF_FFFF ;
11504
 
11505
    // BAR1
11506
    configuration_cycle_write
11507
    (
11508
        8'h00,                          // bus number [7:0]
11509
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11510
        3'h0,                           // function number [2:0]
11511
        6'h5,                           // register number [5:0]
11512
        2'h0,                           // type [1:0]
11513
        4'hF,                           // byte enables [3:0]
11514
        read_data                       // data to write [31:0]
11515
    ) ;
11516
 
11517
    expected_value = {`PCI_AM1, 12'h000} ;
11518
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11519
    if (`PCI_AM1)
11520
        expected_value[0] = `PCI_BA1_MEM_IO ;
11521
 
11522
    configuration_cycle_read
11523
    (
11524
        8'h00,                          // bus number [7:0]
11525
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11526
        3'h0,                           // function number [2:0]
11527
        6'h5,                           // register number [5:0]
11528
        2'h0,                           // type [1:0]
11529
        4'hF,                           // byte enables [3:0]
11530
        read_data                       // data to write [31:0]
11531
    ) ;
11532
 
11533
    if ( read_data !== expected_value )
11534
    begin
11535
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11536
        failed = 1 ;
11537
    end
11538
 
11539
    // write all 1s to BAR2
11540
    read_data = 32'hFFFF_FFFF ;
11541
 
11542
    // BAR2
11543
    configuration_cycle_write
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'h6,                           // 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
`ifdef PCI_IMAGE2
11555
    expected_value = {`PCI_AM2, 12'h000} ;
11556
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11557
    if (`PCI_AM2)
11558
        expected_value[0] = `PCI_BA2_MEM_IO ;
11559
`else
11560
    expected_value = 0 ;
11561
`endif
11562
 
11563
    configuration_cycle_read
11564
    (
11565
        8'h00,                          // bus number [7:0]
11566
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11567
        3'h0,                           // function number [2:0]
11568
        6'h6,                           // register number [5:0]
11569
        2'h0,                           // type [1:0]
11570
        4'hF,                           // byte enables [3:0]
11571
        read_data                       // data to write [31:0]
11572
    ) ;
11573
 
11574
    if ( read_data !== expected_value )
11575
    begin
11576
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11577
        failed = 1 ;
11578
    end
11579
 
11580
    // write all 1s to BAR3
11581
    read_data = 32'hFFFF_FFFF ;
11582
 
11583
    // BAR3
11584
    configuration_cycle_write
11585
    (
11586
        8'h00,                          // bus number [7:0]
11587
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11588
        3'h0,                           // function number [2:0]
11589
        6'h7,                           // register number [5:0]
11590
        2'h0,                           // type [1:0]
11591
        4'hF,                           // byte enables [3:0]
11592
        read_data                       // data to write [31:0]
11593
    ) ;
11594
 
11595
`ifdef PCI_IMAGE3
11596
    expected_value = {`PCI_AM3, 12'h000} ;
11597
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11598
    if(`PCI_AM3)
11599
        expected_value[0] = `PCI_BA3_MEM_IO ;
11600
`else
11601
    expected_value = 0 ;
11602
`endif
11603
 
11604
    configuration_cycle_read
11605
    (
11606
        8'h00,                          // bus number [7:0]
11607
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11608
        3'h0,                           // function number [2:0]
11609
        6'h7,                           // register number [5:0]
11610
        2'h0,                           // type [1:0]
11611
        4'hF,                           // byte enables [3:0]
11612
        read_data                       // data to write [31:0]
11613
    ) ;
11614
 
11615
    if ( read_data !== expected_value )
11616
    begin
11617
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11618
        failed = 1 ;
11619
    end
11620
 
11621
    // write all 1s to BAR4
11622
    read_data = 32'hFFFF_FFFF ;
11623
 
11624
    // BAR4
11625
    configuration_cycle_write
11626
    (
11627
        8'h00,                          // bus number [7:0]
11628
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11629
        3'h0,                           // function number [2:0]
11630
        6'h8,                           // register number [5:0]
11631
        2'h0,                           // type [1:0]
11632
        4'hF,                           // byte enables [3:0]
11633
        read_data                       // data to write [31:0]
11634
    ) ;
11635
 
11636
`ifdef PCI_IMAGE4
11637
    expected_value = {`PCI_AM4, 12'h000} ;
11638
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11639
    if(`PCI_AM4)
11640
        expected_value[0] = `PCI_BA4_MEM_IO ;
11641
`else
11642
    expected_value = 0 ;
11643
`endif
11644
 
11645
    configuration_cycle_read
11646
    (
11647
        8'h00,                          // bus number [7:0]
11648
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11649
        3'h0,                           // function number [2:0]
11650
        6'h8,                           // register number [5:0]
11651
        2'h0,                           // type [1:0]
11652
        4'hF,                           // byte enables [3:0]
11653
        read_data                       // data to write [31:0]
11654
    ) ;
11655
 
11656
    if ( read_data !== expected_value )
11657
    begin
11658
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11659
        failed = 1 ;
11660
    end
11661
 
11662
    // write all 1s to BAR5
11663
    read_data = 32'hFFFF_FFFF ;
11664
 
11665
    // BAR5
11666
    configuration_cycle_write
11667
    (
11668
        8'h00,                          // bus number [7:0]
11669
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11670
        3'h0,                           // function number [2:0]
11671
        6'h9,                           // register number [5:0]
11672
        2'h0,                           // type [1:0]
11673
        4'hF,                           // byte enables [3:0]
11674
        read_data                       // data to write [31:0]
11675
    ) ;
11676
 
11677
`ifdef PCI_IMAGE5
11678
    expected_value = {`PCI_AM5, 12'h000} ;
11679
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11680
    if(`PCI_AM5)
11681
        expected_value[0] = `PCI_BA5_MEM_IO ;
11682
`else
11683
    expected_value = 0 ;
11684
`endif
11685
 
11686
    configuration_cycle_read
11687
    (
11688
        8'h00,                          // bus number [7:0]
11689
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11690
        3'h0,                           // function number [2:0]
11691
        6'h9,                           // register number [5:0]
11692
        2'h0,                           // type [1:0]
11693
        4'hF,                           // byte enables [3:0]
11694
        read_data                       // data to write [31:0]
11695
    ) ;
11696
 
11697
    if ( read_data !== expected_value )
11698
    begin
11699
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11700
        failed = 1 ;
11701
    end
11702
`endif
11703
 
11704
    if (!failed)
11705
        test_ok ;
11706
end
11707
endtask
11708
 
11709 15 mihad
task display_warning;
11710
    input [31:0] error_address ;
11711
    input [31:0] expected_data ;
11712
    input [31:0] actual ;
11713
begin
11714
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11715
end
11716
endtask // display warning
11717
 
11718
/*############################################################################
11719
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11720
=====================
11721
############################################################################*/
11722
 
11723
// Task reslease the PCI bus for 'delay' clocks
11724
task do_pause;
11725
  input  [15:0] delay;
11726
  reg    [15:0] cnt;
11727
  begin
11728
    test_start <= 1'b0;  // no device is allowed to take this
11729
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11730
    begin
11731
      if (~pci_reset_comb)
11732
      begin
11733
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11734
      end
11735
      `NO_ELSE;
11736
    end
11737
  end
11738
endtask // do_pause
11739
 
11740
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11741
task DO_REF;
11742
  input  [79:0] name;
11743
  input  [2:0] master_number;
11744
  input  [PCI_BUS_DATA_RANGE:0] address;
11745
  input  [3:0] command;
11746
  input  [PCI_BUS_DATA_RANGE:0] data;
11747
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11748
  input  [9:0] size;
11749
  input   make_addr_par_error, make_data_par_error;
11750
  input  [7:0] master_wait_states;
11751
  input  [7:0] target_wait_states;
11752
  input  [1:0] target_devsel_speed;
11753
  input   fast_back_to_back;
11754
  input  [2:0] target_termination;
11755
  input   expect_master_abort;
11756
  reg     waiting;
11757
  begin
11758
// Cautiously wait for previous command to be done
11759
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11760
    begin
11761
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11762
      begin
11763
        if (~pci_reset_comb)
11764
        begin
11765
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11766
        end
11767
        `NO_ELSE;
11768
      end
11769
      else
11770
      begin
11771
        waiting = 1'b0;  // ready to do next command
11772
      end
11773
    end
11774
    next_test_name[79:0] <= name[79:0];
11775
    test_master_number <= master_number[2:0];
11776
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11777
    test_command[3:0] <= command[3:0] ;
11778
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11779
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11780
    test_size <= size;
11781
    test_make_addr_par_error <= make_addr_par_error;
11782
    test_make_data_par_error <= make_data_par_error;
11783
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11784
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11785
    test_target_initial_wait_states <= target_wait_states[7:4];
11786
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11787
    test_target_devsel_speed <= target_devsel_speed[1:0];
11788
    test_fast_back_to_back <= fast_back_to_back;
11789
    test_target_termination <= target_termination[2:0];
11790
    test_expect_master_abort <= expect_master_abort;
11791
    test_start <= 1'b1;
11792
    if (~pci_reset_comb)
11793
    begin
11794
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11795
    end
11796
    `NO_ELSE;
11797
// wait for new command to start
11798
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11799
    begin
11800
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11801
      begin
11802
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11803
      end
11804
      else
11805
      begin
11806
        waiting = 1'b0;  // ready to do next command
11807
      end
11808
    end
11809
  end
11810
endtask // DO_REF
11811
 
11812
// Use Macros defined in pci_defines.vh as paramaters
11813
 
11814
// DO_REF (name[79:0], master_number[2:0],
11815
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11816
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11817
//          make_addr_par_error, make_data_par_error,
11818
//          master_wait_states[8:0], target_wait_states[8:0],
11819
//          target_devsel_speed[1:0], fast_back_to_back,
11820
//          target_termination[2:0],
11821
//          expect_master_abort);
11822
//
11823
// Example:
11824
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11825
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11826
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11827
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11828
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11829
 
11830
// Access a location with no high-order bits set, assuring that no device responds
11831
task PCIU_CONFIG_READ_MASTER_ABORT;
11832
  input  [79:0] name;
11833
  input  [2:0] master_number;
11834 51 mihad
  input  [31:0] address ;
11835
  input  [3:0] be ;
11836 15 mihad
  begin
11837 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11838
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11839
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11840 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11841
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11842
  end
11843
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11844
 
11845
// Access a location with no high-order bits set, assuring that no device responds
11846
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11847
  input  [79:0] name;
11848
  input  [2:0] master_number;
11849 51 mihad
  input  [31:0] address ;
11850
  input  [3:0] be ;
11851 15 mihad
  begin
11852 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11853
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11854
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11855 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11856
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11857
  end
11858
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11859
 
11860
// Access a location with no high-order bits set, assuring that no device responds
11861
task PCIU_MEM_READ_MASTER_ABORT;
11862
  input  [79:0] name;
11863
  input  [2:0] master_number;
11864
  input  [9:0] size;
11865
  begin
11866
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11867
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11868
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11869
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11870
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11871
  end
11872
endtask // PCIU_MEM_READ_MASTER_ABORT
11873
 
11874
// Access a location with no high-order bits set, assuring that no device responds
11875
task PCIU_MEM_WRITE_MASTER_ABORT;
11876
  input  [79:0] name;
11877
  input  [2:0] master_number;
11878
  input  [9:0] size;
11879
  begin
11880
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11881
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11882
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11883
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11884
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11885
  end
11886
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11887
 
11888
// Do variable length transfers with various paramaters
11889
task PCIU_CONFIG_READ;
11890
  input  [79:0] name;
11891
  input  [2:0] master_number;
11892
  input  [PCI_BUS_DATA_RANGE:0] address;
11893
  input  [PCI_BUS_DATA_RANGE:0] data;
11894
  input  [3:0] be ;
11895
  input  [9:0] size;
11896
  input  [7:0] master_wait_states;
11897
  input  [7:0] target_wait_states;
11898
  input  [1:0] target_devsel_speed;
11899
  input  [2:0] target_termination;
11900
  begin
11901
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11902
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11903
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11904
              8'h0_0, target_wait_states[7:0],
11905
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11906
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11907
  end
11908
endtask // PCIU_CONFIG_READ
11909
 
11910
task PCIU_CONFIG_WRITE;
11911
  input  [79:0] name;
11912
  input  [2:0] master_number;
11913
  input  [PCI_BUS_DATA_RANGE:0] address;
11914
  input  [PCI_BUS_DATA_RANGE:0] data;
11915
  input  [3:0] be ;
11916
  input  [9:0] size;
11917
  input  [7:0] master_wait_states;
11918
  input  [7:0] target_wait_states;
11919
  input  [1:0] target_devsel_speed;
11920
  input  [2:0] target_termination;
11921
  begin
11922
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11923
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11924
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11925
              8'h0_0, target_wait_states[7:0],
11926
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11927
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11928
  end
11929
endtask // PCIU_CONFIG_WRITE
11930
 
11931
task PCIU_READ;
11932
  input  [2:0] master_number;
11933
  input  [PCI_BUS_DATA_RANGE:0] address;
11934
  input  [3:0] command;
11935
  input  [PCI_BUS_DATA_RANGE:0] data;
11936
  input  [3:0] byte_en;
11937
  input  [9:0] size;
11938
  input  [7:0] master_wait_states;
11939
  input  [7:0] target_wait_states;
11940
  input  [1:0] target_devsel_speed;
11941
  input  [2:0] target_termination;
11942
  reg    [79:0] name;
11943
  begin
11944
    if (command == `BC_MEM_READ)
11945
        name = "MEM_READ  " ;
11946
    else if (command == `BC_MEM_READ_LN)
11947
        name = "MEM_RD_LN " ;
11948
    else if (command == `BC_MEM_READ_MUL )
11949
        name = "MEM_RD_MUL" ;
11950
    else
11951
        name = "WRONG_READ" ;
11952
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11953
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11954
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11955
              8'h0_0, target_wait_states[7:0],
11956
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11957
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11958
  end
11959
endtask // PCIU_READ
11960
 
11961
task PCIU_MEM_READ;
11962
  input  [79:0] name;
11963
  input  [2:0] master_number;
11964
  input  [PCI_BUS_DATA_RANGE:0] address;
11965
  input  [PCI_BUS_DATA_RANGE:0] data;
11966
  input  [9:0] size;
11967
  input  [7:0] master_wait_states;
11968
  input  [7:0] target_wait_states;
11969
  input  [1:0] target_devsel_speed;
11970
  input  [2:0] target_termination;
11971
  begin
11972
 
11973
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11974
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11975
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11976
              8'h0_0, target_wait_states[7:0],
11977
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11978
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11979
  end
11980
endtask // PCIU_MEM_READ
11981
 
11982
task PCIU_IO_READ;
11983
  input  [2:0] master_number;
11984
  input  [PCI_BUS_DATA_RANGE:0] address;
11985
  input  [PCI_BUS_DATA_RANGE:0] data;
11986
  input  [3:0] byte_en ;
11987
  input  [9:0] size;
11988
  input  [2:0] target_termination ;
11989
  begin
11990
 
11991
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11992
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11993
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11994
              8'h0_0, `Test_One_Zero_Target_WS,
11995
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11996
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11997
  end
11998
endtask // PCIU_IO_READ
11999
 
12000
task PCIU_IO_READ_MAKE_PERR;
12001
  input  [2:0] master_number;
12002
  input  [PCI_BUS_DATA_RANGE:0] address;
12003
  input  [PCI_BUS_DATA_RANGE:0] data;
12004
  input  [3:0] byte_en ;
12005
  input  [9:0] size;
12006
  input  [2:0] target_termination ;
12007
  begin
12008
 
12009
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12010
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12011
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12012
              8'h0_0, `Test_One_Zero_Target_WS,
12013
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12014
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12015
  end
12016
endtask // PCIU_IO_READ_MAKE_PERR
12017
 
12018
task PCIU_MEM_READ_LN;
12019
  input  [79:0] name;
12020
  input  [2:0] master_number;
12021
  input  [PCI_BUS_DATA_RANGE:0] address;
12022
  input  [PCI_BUS_DATA_RANGE:0] data;
12023
  input  [9:0] size;
12024
  input  [7:0] master_wait_states;
12025
  input  [7:0] target_wait_states;
12026
  input  [1:0] target_devsel_speed;
12027
  input  [2:0] target_termination;
12028
  begin
12029
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12030
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12031
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12032
              8'h0_0, target_wait_states[7:0],
12033
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12034
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12035
  end
12036
endtask // PCIU_MEM_READ_LN
12037
 
12038
task PCIU_MEM_READ_MUL;
12039
  input  [79:0] name;
12040
  input  [2:0] master_number;
12041
  input  [PCI_BUS_DATA_RANGE:0] address;
12042
  input  [PCI_BUS_DATA_RANGE:0] data;
12043
  input  [9:0] size;
12044
  input  [7:0] master_wait_states;
12045
  input  [7:0] target_wait_states;
12046
  input  [1:0] target_devsel_speed;
12047
  input  [2:0] target_termination;
12048
  begin
12049
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12050
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12051
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12052
              8'h0_0, target_wait_states[7:0],
12053
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12054
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12055
  end
12056
endtask // PCIU_MEM_READ_MUL
12057
 
12058
task PCIU_MEM_READ_MAKE_PERR;
12059
  input  [79:0] name;
12060
  input  [2:0] master_number;
12061
  input  [PCI_BUS_DATA_RANGE:0] address;
12062
  input  [PCI_BUS_DATA_RANGE:0] data;
12063
  input  [9:0] size;
12064
  input  [7:0] master_wait_states;
12065
  input  [7:0] target_wait_states;
12066
  input  [1:0] target_devsel_speed;
12067
  input  [2:0] target_termination;
12068
  begin
12069
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12070
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12071
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12072
              8'h0_0, target_wait_states[7:0],
12073
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12074
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12075
  end
12076
endtask // PCIU_MEM_READ_MAKE_PERR
12077
 
12078
task PCIU_MEM_WRITE;
12079
  input  [79:0] name;
12080
  input  [2:0] master_number;
12081
  input  [PCI_BUS_DATA_RANGE:0] address;
12082
  input  [PCI_BUS_DATA_RANGE:0] data;
12083
  input  [3:0] byte_en;
12084
  input  [9:0] size;
12085
  input  [7:0] master_wait_states;
12086
  input  [7:0] target_wait_states;
12087
  input  [1:0] target_devsel_speed;
12088
  input  [2:0] target_termination;
12089
  begin
12090
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12091
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12092
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12093
              8'h0_0, target_wait_states[7:0],
12094
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12095
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12096
  end
12097
endtask // PCIU_MEM_WRITE
12098
 
12099
task PCIU_IO_WRITE;
12100
  input  [2:0] master_number;
12101
  input  [PCI_BUS_DATA_RANGE:0] address;
12102
  input  [PCI_BUS_DATA_RANGE:0] data;
12103
  input  [3:0] byte_en;
12104
  input  [9:0] size;
12105
  input  [2:0] target_termination ;
12106
  begin
12107
 
12108
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12109
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12110
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12111
              8'h0_0, `Test_One_Zero_Target_WS,
12112
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12113
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12114
  end
12115
endtask // PCIU_IO_WRITE
12116
 
12117
task PCIU_IO_WRITE_MAKE_PERR ;
12118
  input  [2:0] master_number;
12119
  input  [PCI_BUS_DATA_RANGE:0] address;
12120
  input  [PCI_BUS_DATA_RANGE:0] data;
12121
  input  [3:0] byte_en;
12122
  input  [9:0] size;
12123
  input  [2:0] target_termination ;
12124
  begin
12125
 
12126
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12127
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12128
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12129
              8'h0_0, `Test_One_Zero_Target_WS,
12130
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12131
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12132
  end
12133
endtask // PCIU_IO_WRITE
12134
 
12135
task PCIU_MEM_WRITE_MAKE_SERR;
12136
  input  [79:0] name;
12137
  input  [2:0] master_number;
12138
  input  [PCI_BUS_DATA_RANGE:0] address;
12139
  input  [PCI_BUS_DATA_RANGE:0] data;
12140
  input  [9:0] size;
12141
  input  [7:0] master_wait_states;
12142
  input  [7:0] target_wait_states;
12143
  input  [1:0] target_devsel_speed;
12144
  input  [2:0] target_termination;
12145
  begin
12146
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12147
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12148
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12149
              8'h0_0, target_wait_states[7:0],
12150
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12151
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12152
  end
12153
endtask // PCIU_MEM_WRITE_MAKE_SERR
12154
 
12155
task PCIU_MEM_WRITE_MAKE_PERR;
12156
  input  [79:0] name;
12157
  input  [2:0] master_number;
12158
  input  [PCI_BUS_DATA_RANGE:0] address;
12159
  input  [PCI_BUS_DATA_RANGE:0] data;
12160
  input  [9:0] size;
12161
  input  [7:0] master_wait_states;
12162
  input  [7:0] target_wait_states;
12163
  input  [1:0] target_devsel_speed;
12164
  input  [2:0] target_termination;
12165
  begin
12166
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12167
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12168
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12169
              8'h0_0, target_wait_states[7:0],
12170
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12171
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12172
  end
12173
endtask // PCIU_MEM_WRITE
12174
 
12175
/*--------------------------------------------------------------------------
12176
Initialization CASES
12177
--------------------------------------------------------------------------*/
12178
 
12179
// Initialize the basic Config Registers of the PCI bridge target device
12180
task configure_bridge_target;
12181
    reg [11:0] offset ;
12182
    reg [31:0] data ;
12183
    `ifdef HOST
12184
    reg `WRITE_STIM_TYPE   write_data ;
12185
    reg `WB_TRANSFER_FLAGS write_flags ;
12186
    reg `WRITE_RETURN_TYPE write_status ;
12187
    `else
12188
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12189
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12190
    `endif
12191
 
12192
    reg [31:0] temp_var ;
12193
begin
12194
`ifdef HOST //  set Header
12195
    offset  = 12'h4 ; // PCI Header Command register
12196
    data    = 32'h0000_0007 ; // enable master & target operation
12197
 
12198
    write_flags                      = 0 ;
12199
    write_flags`INIT_WAITS           = tb_init_waits ;
12200
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12201
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12202
 
12203
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12204
    write_data`WRITE_SEL      = 4'h1 ;
12205
    write_data`WRITE_TAG_STIM = 0 ;
12206
    write_data`WRITE_DATA     = data ;
12207
 
12208
    next_test_name[79:0] <= "Init_Tar_R";
12209
 
12210
    $display(" bridge target - Enabling master and target operation!");
12211
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12212
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12213
    begin
12214
        $display("Write to configuration space failed! Time %t ", $time) ;
12215
    end
12216
 
12217
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12218
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12219
 
12220
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12221
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12222
 
12223
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12224
    write_data`WRITE_SEL      = 4'hf ;
12225
    write_data`WRITE_TAG_STIM = 0 ;
12226
    write_data`WRITE_DATA     = data ;
12227
 
12228
 `ifdef  NO_CNF_IMAGE
12229
  `ifdef PCI_IMAGE0 //      set P_BA0
12230
 
12231
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12232
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12233
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12234
    begin
12235
        $display("Write to configuration space failed! Time %t ", $time) ;
12236
    end
12237
  `endif
12238
 `else //      set P_BA0
12239
 
12240
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12241
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12242
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12243
    begin
12244
        $display("Write to configuration space failed! Time %t ", $time) ;
12245
    end
12246
 `endif
12247
 
12248
`else // GUEST, set Header, set P_BA0
12249
    data            = 32'h0000_0007 ; // enable master & target operation
12250
    byte_enables    = 4'hF ;
12251
    $display(" bridge target - Enabling master and target operation!");
12252 45 mihad
    configuration_cycle_write(0,                        // bus number
12253
                              `TAR0_IDSEL_INDEX - 11,   // device number
12254
                              0,                        // function number
12255
                              1,                        // register number
12256
                              0,                        // type of configuration cycle
12257
                              byte_enables,             // byte enables
12258
                              data                      // data
12259 15 mihad
                             ) ;
12260
 
12261
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12262
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12263
    byte_enables = 4'hf ;
12264 45 mihad
    configuration_cycle_write(0,                        // bus number
12265
                              `TAR0_IDSEL_INDEX - 11,   // device number
12266
                              0,                        // function number
12267
                              4,                        // register number
12268
                              0,                        // type of configuration cycle
12269
                              byte_enables,             // byte enables
12270
                              data                      // data
12271 15 mihad
                             ) ;
12272
 
12273
`endif
12274
end
12275
endtask // configure_bridge_target
12276
 
12277
// Initialize the basic Config Registers of the PCI bridge target device
12278
task configure_bridge_target_base_addresses;
12279
    reg [11:0] offset ;
12280
    reg [31:0] data ;
12281
    `ifdef HOST
12282
    reg `WRITE_STIM_TYPE   write_data ;
12283
    reg `WB_TRANSFER_FLAGS write_flags ;
12284
    reg `WRITE_RETURN_TYPE write_status ;
12285
    `else
12286
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12287
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12288
    `endif
12289
 
12290
    reg [31:0] temp_var ;
12291
begin
12292
`ifdef HOST //  set Header
12293
    offset  = 12'h4 ; // PCI Header Command register
12294
    data    = 32'h0000_0007 ; // enable master & target operation
12295
 
12296
    write_flags                    = 0 ;
12297
    write_flags`INIT_WAITS         = tb_init_waits ;
12298
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12299
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12300
 
12301
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12302
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12303
 
12304
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12305
    write_data`WRITE_SEL      = 4'h1 ;
12306
    write_data`WRITE_TAG_STIM = 0 ;
12307
    write_data`WRITE_DATA     = data ;
12308
 
12309
    next_test_name[79:0] <= "Init_Tar_R";
12310
 
12311
    $display(" bridge target - Enabling master and target operation!");
12312
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12313
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12314
    begin
12315
        $display("Write to configuration space failed! Time %t ", $time) ;
12316
    end
12317
 
12318
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12319
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12320
 
12321
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12322
    write_data`WRITE_SEL      = 4'hf ;
12323
    write_data`WRITE_TAG_STIM = 0 ;
12324
    write_data`WRITE_DATA     = data ;
12325
 
12326
 `ifdef  NO_CNF_IMAGE
12327
  `ifdef PCI_IMAGE0 //      set P_BA0
12328
 
12329
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12330
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12331
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12332
    begin
12333
        $display("Write to configuration space failed! Time %t ", $time) ;
12334
    end
12335
  `endif
12336
 `else //      set P_BA0
12337
 
12338
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12339
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12340
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12341
    begin
12342
        $display("Write to configuration space failed! Time %t ", $time) ;
12343
    end
12344
 `endif
12345
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12346
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12347
 
12348
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12349
    write_data`WRITE_SEL      = 4'hf ;
12350
    write_data`WRITE_TAG_STIM = 0 ;
12351
    write_data`WRITE_DATA     = data ;
12352
 
12353
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12354
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12355
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12356
    begin
12357
        $display("Write to configuration space failed! Time %t ", $time) ;
12358
    end
12359
 `ifdef PCI_IMAGE2
12360
 
12361
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12362
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12363
 
12364
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12365
    write_data`WRITE_SEL      = 4'hf ;
12366
    write_data`WRITE_TAG_STIM = 0 ;
12367
    write_data`WRITE_DATA     = data ;
12368
 
12369
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
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
 `endif
12376
 `ifdef PCI_IMAGE3
12377
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12378
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12379
 
12380
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12381
    write_data`WRITE_SEL      = 4'hf ;
12382
    write_data`WRITE_TAG_STIM = 0 ;
12383
    write_data`WRITE_DATA     = data ;
12384
 
12385
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12386
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12387
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12388
    begin
12389
        $display("Write to configuration space failed! Time %t ", $time) ;
12390
    end
12391
 `endif
12392
 `ifdef PCI_IMAGE4
12393
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12394
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12395
 
12396
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12397
    write_data`WRITE_SEL      = 4'hf ;
12398
    write_data`WRITE_TAG_STIM = 0 ;
12399
    write_data`WRITE_DATA     = data ;
12400
 
12401
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12402
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12403
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12404
    begin
12405
        $display("Write to configuration space failed! Time %t ", $time) ;
12406
    end
12407
 `endif
12408
 `ifdef PCI_IMAGE5
12409
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12410
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12411
 
12412
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12413
    write_data`WRITE_SEL      = 4'hf ;
12414
    write_data`WRITE_TAG_STIM = 0 ;
12415
    write_data`WRITE_DATA     = data ;
12416
 
12417
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12418
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12419
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12420
    begin
12421
        $display("Write to configuration space failed! Time %t ", $time) ;
12422
    end
12423
 `endif
12424
 
12425
`else // GUEST, set Header, set P_BA0
12426
    data            = 32'h0000_0007 ; // enable master & target operation
12427
    byte_enables    = 4'hF ;
12428
    $display(" bridge target - Enabling master and target operation!");
12429 45 mihad
    configuration_cycle_write(0,                        // bus number
12430
                              `TAR0_IDSEL_INDEX - 11,   // device number
12431
                              0,                        // function number
12432
                              1,                        // register number
12433
                              0,                        // type of configuration cycle
12434
                              byte_enables,             // byte enables
12435
                              data                      // data
12436 15 mihad
                             ) ;
12437
 
12438
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12439
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12440
    byte_enables = 4'hf ;
12441 45 mihad
    configuration_cycle_write(0,                        // bus number
12442
                              `TAR0_IDSEL_INDEX - 11,   // device number
12443
                              0,                        // function number
12444
                              4,                        // register number
12445
                              0,                        // type of configuration cycle
12446
                              byte_enables,             // byte enables
12447
                              data                      // data
12448 15 mihad
                             ) ;
12449
 
12450
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12451
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12452
    byte_enables = 4'hf ;
12453 45 mihad
    configuration_cycle_write(0,                        // bus number
12454
                              `TAR0_IDSEL_INDEX - 11,   // device number
12455
                              0,                        // function number
12456
                              5,                        // register number
12457
                              0,                        // type of configuration cycle
12458
                              byte_enables,             // byte enables
12459
                              data                      // data
12460 15 mihad
                             ) ;
12461
 `ifdef PCI_IMAGE2
12462
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12463
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12464
    byte_enables = 4'hf ;
12465 45 mihad
    configuration_cycle_write(0,                        // bus number
12466
                              `TAR0_IDSEL_INDEX - 11,   // device number
12467
                              0,                        // function number
12468
                              6,                        // register number
12469
                              0,                        // type of configuration cycle
12470
                              byte_enables,             // byte enables
12471
                              data                      // data
12472 15 mihad
                             ) ;
12473
 `endif
12474
 `ifdef PCI_IMAGE3
12475
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12476
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12477
    byte_enables = 4'hf ;
12478 45 mihad
    configuration_cycle_write(0,                        // bus number
12479
                              `TAR0_IDSEL_INDEX - 11,   // device number
12480
                              0,                        // function number
12481
                              7,                        // register number
12482
                              0,                        // type of configuration cycle
12483
                              byte_enables,             // byte enables
12484
                              data                      // data
12485 15 mihad
                             ) ;
12486
 `endif
12487
 `ifdef PCI_IMAGE4
12488
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12489
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12490
    byte_enables = 4'hf ;
12491 45 mihad
    configuration_cycle_write(0,                        // bus number
12492
                              `TAR0_IDSEL_INDEX - 11,   // device number
12493
                              0,                        // function number
12494
                              8,                        // register number
12495
                              0,                        // type of configuration cycle
12496
                              byte_enables,             // byte enables
12497
                              data                      // data
12498 15 mihad
                             ) ;
12499
 `endif
12500
 `ifdef PCI_IMAGE5
12501
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12502
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12503
    byte_enables = 4'hf ;
12504 45 mihad
    configuration_cycle_write(0,                        // bus number
12505
                              `TAR0_IDSEL_INDEX - 11,   // device number
12506
                              0,                        // function number
12507
                              9,                        // register number
12508
                              0,                        // type of configuration cycle
12509
                              byte_enables,             // byte enables
12510
                              data                      // data
12511 15 mihad
                             ) ;
12512
 `endif
12513
`endif
12514
end
12515
endtask // configure_bridge_target_base_addresses
12516
 
12517
/*--------------------------------------------------------------------------
12518
Test CASES
12519
--------------------------------------------------------------------------*/
12520
 
12521
// function converts PCI address to WB with the same data as the pci_decoder does
12522
function [31:0] pci_to_wb_addr_convert ;
12523
 
12524
    input [31:0] pci_address ;
12525
    input [31:0] translation_address ;
12526
    input [31:0] translate ;
12527
 
12528
    reg   [31:0] temp_address ;
12529
begin
12530
    if ( translate !== 1 )
12531
    begin
12532
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12533
    end
12534
    else
12535
    begin
12536
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12537
    end
12538
 
12539
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12540
    pci_to_wb_addr_convert = temp_address ;
12541
end
12542
endfunction // pci_to_wb_addr_convert
12543
 
12544
// Test normal write and read to WB slave
12545
task test_normal_wr_rd;
12546
  input  [2:0]  Master_ID;
12547
  input  [PCI_BUS_DATA_RANGE:0] Address;
12548
  input  [PCI_BUS_DATA_RANGE:0] Data;
12549
  input  [3:0]  Be;
12550
  input  [2:0]  Image_num;
12551
  input  [9:0]  Set_size;
12552
  input         Set_addr_translation;
12553
  input         Set_prefetch_enable;
12554
  input  [7:0]  Cache_lsize;
12555
  input         Set_wb_wait_states;
12556
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12557
 
12558
  reg    [31:0] rd_address;
12559
  reg    [31:0] rd_data;
12560
  reg    [3:0]  rd_be;
12561
  reg    [11:0] addr_offset;
12562
  reg    [31:0] read_data;
12563
  reg           continue ;
12564
  reg           ok   ;
12565
  reg    [31:0] expect_address ;
12566
  reg    [31:0] expect_rd_address ;
12567
  reg           expect_we ;
12568
  reg    [9:0]  expect_length_wr ;
12569
  reg    [9:0]  expect_length_rd ;
12570
  reg    [9:0]  expect_length_rd1 ;
12571
  reg    [9:0]  expect_length_rd2 ;
12572
  reg    [3:0]  use_rd_cmd ;
12573
  integer       i ;
12574 35 mihad
  reg           error_monitor_done ;
12575 15 mihad
begin:main
12576
 
12577
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12578
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12579
    $display(" - errors will be reported, but they should not occur!");
12580
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12581
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12582
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12583
    if ( ok !== 1 )
12584
    begin
12585
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12586
        test_fail("write to P_ERR_CS register didn't succeede") ;
12587
        disable main;
12588
    end
12589
 
12590
    `ifdef  ADDR_TRAN_IMPL
12591
 
12592
    // set or clear address translation
12593
    if (Set_addr_translation)
12594
    begin
12595
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12596
        $display(" - address translation will be performed!");
12597
    end
12598
    else
12599
    begin
12600
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12601
        $display(" - address translation will not be performed!");
12602
    end
12603
    // set or clear pre-fetch enable
12604
    if (Set_prefetch_enable)
12605
    begin
12606
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12607
        $display(" - bursts can be performed!");
12608
    end
12609
    else
12610
    begin
12611
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12612
        $display(" - bursts can not be performed!");
12613
    end
12614
 
12615
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12616
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12617
    if ( ok !== 1 )
12618
    begin
12619
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12620
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12621
        disable main;
12622
    end
12623
 
12624
    // predict the address and control signals on WB bus
12625
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12626
    expect_we      = 1'b1 ; // WRITE
12627
 
12628
    `else
12629
 
12630
    // address translation is not implemented
12631
    $display("Address translation is NOT implemented for PCI images!");
12632
    // set or clear pre-fetch enable
12633
    if (Set_prefetch_enable)
12634
    begin
12635
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12636
        $display(" - bursts can be performed!");
12637
    end
12638
    else
12639
    begin
12640
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12641
        $display(" - bursts can not be performed!");
12642
    end
12643
 
12644
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12645
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12646
    if ( ok !== 1 )
12647
    begin
12648
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12649
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12650
        disable main;
12651
    end
12652
 
12653
    // predict the address and control signals on WB bus
12654
    expect_address = Address ;
12655
    expect_we      = 1'b1 ; // WRITE
12656
 
12657
    `endif
12658
 
12659
    // set WB SLAVE parameters
12660
    if (Set_wb_wait_states)
12661
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12662
    else
12663
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12664
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12665
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12666
 
12667
    if ( Set_size > (`PCIW_DEPTH - 2) )
12668
    begin
12669
        expect_length_wr = `PCIW_DEPTH - 2 ;
12670
    end
12671
    else
12672
    begin
12673
        expect_length_wr = Set_size ;
12674
    end
12675
    // write through the PCI bridge to WB slave
12676
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12677
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12678
 
12679
    fork
12680
    begin
12681
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12682
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12683
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12684
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12685
        do_pause( 1 ) ;
12686
    end
12687
    begin
12688
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12689
       if ( ok !== 1 )
12690
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12691
       else
12692
           test_ok ;
12693
    end
12694
    join
12695
 
12696
    // predict the address and control signals on WB bus
12697
    expect_we      = 1'b0 ; // READ
12698
 
12699
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12700
    $display("Memory read through PCI bridge to WB slave!");
12701
 
12702
    if ( expect_length_wr == 1 )
12703
    begin
12704
        if (Set_prefetch_enable)
12705
        begin
12706
            expect_length_rd1 = Cache_lsize ;
12707
            expect_length_rd2 = 0 ;
12708
                // If PCI behavioral master must check received DATA
12709
                master2_check_received_data = 0 ;
12710
                    master1_check_received_data = 0 ;
12711
        end
12712
        else
12713
        begin
12714
            expect_length_rd1 = 1 ;
12715
            expect_length_rd2 = 0 ;
12716
                // If PCI behavioral master must check received DATA
12717
                master2_check_received_data = 1 ;
12718
                    master1_check_received_data = 1 ;
12719
        end
12720
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12721
        expect_length_rd  = expect_length_rd1 ;
12722
    end
12723
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12724
    begin
12725
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12726
        expect_length_rd2 = 0 ;
12727
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12728
        expect_length_rd  = expect_length_rd1 ;
12729
                // If PCI behavioral master must check received DATA
12730
        master2_check_received_data = 1 ;
12731
            master1_check_received_data = 1 ;
12732
    end
12733
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12734
    begin
12735
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12736
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12737
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12738
        expect_length_rd  = expect_length_rd1 ;
12739
                // If PCI behavioral master must check received DATA
12740
                master2_check_received_data = 1 ;
12741
            master1_check_received_data = 1 ;
12742
    end
12743
    else
12744
    begin
12745
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12746
        begin
12747
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12748
            expect_length_rd2 = 0 ;
12749
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12750
            expect_length_rd  = expect_length_rd1 ;
12751
                // If PCI behavioral master must check received DATA
12752
                master2_check_received_data = 0 ;
12753
                    master1_check_received_data = 0 ;
12754
        end
12755
        else
12756
        begin
12757
            if ( expect_length_wr > Cache_lsize )
12758
            begin
12759
                expect_length_rd1 = Cache_lsize ;
12760
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12761
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12762
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12763
                else
12764
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12765
                expect_length_rd  = expect_length_rd1 ;
12766
                        // If PCI behavioral master must check received DATA
12767
                        master2_check_received_data = 1 ;
12768
                            master1_check_received_data = 1 ;
12769
            end
12770
            else
12771
            begin
12772
                expect_length_rd1 = Cache_lsize ;
12773
                expect_length_rd2 = 0 ;
12774
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12775
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12776
                else
12777
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12778
                expect_length_rd  = expect_length_wr ;
12779
                                if ( expect_length_wr == Cache_lsize )
12780
                        begin
12781
                                // If PCI behavioral master must check received DATA
12782
                                master2_check_received_data = 1 ;
12783
                                    master1_check_received_data = 1 ;
12784
                                end
12785
                                else
12786
                                begin
12787
                                // If PCI behavioral master must check received DATA
12788
                                master2_check_received_data = 0 ;
12789
                                    master1_check_received_data = 0 ;
12790
                end
12791
            end
12792
        end
12793
    end
12794
 
12795
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12796
    expect_rd_address = expect_address ;
12797
    rd_data[31:0] = Data[31:0];
12798
    rd_be[3:0] = Be[3:0];
12799
 
12800
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12801
    while (expect_length_rd2 > 0)
12802
    begin
12803
        // do read
12804
        $display("Read %d words!", expect_length_rd);
12805
 
12806
        fork
12807
        begin
12808
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12809
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12810
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12811
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12812
 
12813
            wb_transaction_stop( expect_length_rd - 1) ;
12814
 
12815
            do_pause( 1 ) ;
12816
        end
12817
        begin
12818
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12819
            if ( ok !== 1 )
12820
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12821
 
12822
            repeat( 3 )
12823
                @(posedge pci_clock) ;
12824
 
12825
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12826
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12827
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12828
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12829
 
12830
            do_pause( 1 ) ;
12831
            while ( FRAME === 0 )
12832
                @(posedge pci_clock) ;
12833
 
12834
            while ( IRDY === 0 )
12835
                @(posedge pci_clock) ;
12836
 
12837 35 mihad
            #1 ;
12838
            if ( !error_monitor_done )
12839
                disable monitor_error_event1 ;
12840 15 mihad
        end
12841
        begin:monitor_error_event1
12842 35 mihad
            error_monitor_done = 0 ;
12843 15 mihad
            @(error_event_int) ;
12844
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12845
            ok = 0 ;
12846 35 mihad
            error_monitor_done = 1 ;
12847 15 mihad
        end
12848
        join
12849
 
12850
        // increasing the starting address for PCI master and for WB transaction monitor
12851
        rd_address = rd_address + (4 * expect_length_rd) ;
12852
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12853
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12854
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12855
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12856
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12857
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12858
        for (i=0; i<expect_length_rd; i=i+1)
12859
            rd_be[3:0] = {Be[2:0], Be[3]};
12860
 
12861
        // set parameters for next read
12862
        if ( expect_length_rd2 == 1 )
12863
        begin
12864
                if (Set_prefetch_enable)
12865
                begin
12866
                    expect_length_rd1 = Cache_lsize ;
12867
                    expect_length_rd2 = 0 ;
12868
                        // If PCI behavioral master must check received DATA
12869
                        master2_check_received_data = 0 ;
12870
                            master1_check_received_data = 0 ;
12871
                end
12872
                else
12873
                begin
12874
                    expect_length_rd1 = 1 ;
12875
                    expect_length_rd2 = 0 ;
12876
                        // If PCI behavioral master must check received DATA
12877
                        master2_check_received_data = 1 ;
12878
                            master1_check_received_data = 1 ;
12879
                end
12880
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12881
            expect_length_rd  = expect_length_rd1 ;
12882
        end
12883
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12884
        begin
12885
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12886
            expect_length_rd2 = 0 ;
12887
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12888
            expect_length_rd  = expect_length_rd1 ;
12889
                        // If PCI behavioral master must check received DATA
12890
                        master2_check_received_data = 1 ;
12891
                    master1_check_received_data = 1 ;
12892
        end
12893
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12894
        begin
12895
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12896
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12897
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12898
            expect_length_rd  = expect_length_rd1 ;
12899
                        // If PCI behavioral master must check received DATA
12900
                        master2_check_received_data = 1 ;
12901
                    master1_check_received_data = 1 ;
12902
        end
12903
        else
12904
        begin
12905
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12906
            begin
12907
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12908
                expect_length_rd2 = 0 ;
12909
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12910
                expect_length_rd  = expect_length_rd1 ;
12911
                        // If PCI behavioral master must check received DATA
12912
                        master2_check_received_data = 0 ;
12913
                            master1_check_received_data = 0 ;
12914
            end
12915
            else
12916
            begin
12917
                if ( expect_length_rd2 > Cache_lsize )
12918
                begin
12919
                    expect_length_rd1 = Cache_lsize ;
12920
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12921
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12922
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12923
                    else
12924
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12925
                    expect_length_rd  = expect_length_rd1 ;
12926
                                // If PCI behavioral master must check received DATA
12927
                                master2_check_received_data = 1 ;
12928
                                    master1_check_received_data = 1 ;
12929
                end
12930
                else
12931
                begin
12932
                    expect_length_rd  = expect_length_rd2 ;
12933
                    expect_length_rd1 = Cache_lsize ;
12934
                    expect_length_rd2 = 0 ;
12935
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12936
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12937
                    else
12938
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12939
                                        if ( expect_length_rd2 == Cache_lsize )
12940
                                begin
12941
                                        // If PCI behavioral master must check received DATA
12942
                                        master2_check_received_data = 1 ;
12943
                                            master1_check_received_data = 1 ;
12944
                                        end
12945
                                        else
12946
                                        begin
12947
                                        // If PCI behavioral master must check received DATA
12948
                                        master2_check_received_data = 0 ;
12949
                                            master1_check_received_data = 0 ;
12950
                        end
12951
                end
12952
            end
12953
        end
12954
    end
12955
    // do last read
12956
    $display("Read %d words!", expect_length_rd);
12957
 
12958
    fork
12959
    begin
12960
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12961
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12962
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12963
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12964
 
12965
        wb_transaction_stop(expect_length_rd - 1) ;
12966
        do_pause( 1 ) ;
12967
    end
12968
    begin
12969
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12970
 
12971
        do_pause(3) ;
12972
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12973
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12974
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12975
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12976
        do_pause(1) ;
12977
 
12978
        while ( FRAME === 0 )
12979
            @(posedge pci_clock) ;
12980
 
12981
        while ( IRDY === 0 )
12982
            @(posedge pci_clock) ;
12983
 
12984 35 mihad
        #1 ;
12985
        if ( !error_monitor_done )
12986
            disable monitor_error_event2 ;
12987 15 mihad
    end
12988
    begin:monitor_error_event2
12989 35 mihad
        error_monitor_done = 0 ;
12990 15 mihad
        @(error_event_int) ;
12991
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12992
        ok = 0 ;
12993 35 mihad
        error_monitor_done = 1 ;
12994 15 mihad
    end
12995
    join
12996
 
12997
    if ( ok )
12998
        test_ok ;
12999
 
13000
    // Check that no ERRORs were reported
13001
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
13002
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
13003
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13004
    config_read( addr_offset, 4'hF, read_data ) ;
13005
    if ( read_data[8] !== 0 )
13006
    begin
13007
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
13008
        test_fail("error status was set even though no errors occured on WB bus") ;
13009
    end
13010
    else
13011
    begin
13012
        $display("No error was signaled, as expected!");
13013
        test_ok ;
13014
    end
13015
 
13016
end // main
13017
endtask // test_normal_wr_rd
13018
 
13019
// Test erroneous write to WB slave
13020
task test_wb_error_wr;
13021
  input  [2:0]  Master_ID;
13022
  input  [PCI_BUS_DATA_RANGE:0] Address;
13023
  input  [PCI_BUS_DATA_RANGE:0] Data;
13024
  input  [3:0]  Be;
13025
  input  [2:0]  Image_num;
13026
  input  [9:0]  Set_size;
13027
  input         Set_err_and_int_report;
13028
  input         Set_wb_wait_states;
13029
  input  [1:0]  Imm_BefLast_Last_error;
13030
 
13031
  reg    [11:0] addr_offset;
13032
  reg    [31:0] read_data;
13033
  reg           continue ;
13034
  reg           ok   ;
13035
  reg    [9:0]  expect_length ;
13036
  reg    [31:0] expect_address ;
13037
  reg    [0:0]  expect_we ;
13038
  reg    [31:0] rd_address;
13039
  reg    [31:0] rd_data;
13040
  reg    [3:0]  rd_be;
13041
  integer       i ;
13042
begin:main
13043
    if (Set_err_and_int_report)
13044
    begin
13045
        // enable ERROR reporting, because error must be reported and interrupt if required!
13046
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13047
        $display(" - errors will be reported when they will occur!");
13048
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
13049
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13050
        $display(" - interrupt will be reported when error will occur!");
13051
    end
13052
    else
13053
    begin
13054
        // disable ERROR reporting, because error and interrupt must not be reported!
13055
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13056
        $display(" - errors will NOT be reported when they will occur!");
13057
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
13058
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13059
        $display(" - interrupt will NOT be reported when error will occur!");
13060
    end
13061
    // enable/disable ERROR reporting
13062
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
13063
 
13064
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13065
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
13066
    if ( ok !== 1 )
13067
    begin
13068
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13069
        test_fail("PCI Error Control and Status register could not be written") ;
13070
        disable main;
13071
    end
13072
    // enable/disable INTERRUPT reporting
13073
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13074
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
13075
    if ( ok !== 1 )
13076
    begin
13077
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
13078
        test_fail("Interrupt Control register could not be written") ;
13079
        disable main;
13080
    end
13081
 
13082
    `ifdef  ADDR_TRAN_IMPL
13083
 
13084
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
13085
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13086
    config_read( addr_offset, 4'hF, read_data ) ;
13087
    if ( read_data[2] !== 0 )
13088
    begin
13089
        $display("Address translation is set for PCI image%d!", Image_num);
13090
        // predict the address and control signals on WB bus
13091
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13092
        expect_we      = 1'b1 ; // WRITE
13093
    end
13094
    else
13095
    begin
13096
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13097
        // predict the address and control signals on WB bus
13098
        expect_address = Address ;
13099
        expect_we      = 1'b1 ; // WRITE
13100
    end
13101
 
13102
    `else
13103
 
13104
    // address translation is not implemented
13105
    $display("Address translation is NOT implemented for PCI images!");
13106
    // predict the address and control signals on WB bus
13107
    expect_address = Address ;
13108
    expect_we      = 1'b1 ; // WRITE
13109
 
13110
    `endif
13111
 
13112
    if ( Set_size > (`PCIW_DEPTH - 2) )
13113
    begin
13114
        expect_length = `PCIW_DEPTH - 2 ;
13115
    end
13116
    else
13117
    begin
13118
        expect_length = Set_size ;
13119
    end
13120
 
13121
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13122
    begin
13123
        $display("ERR termination with first data!");
13124
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13125
    end
13126
    else if (Imm_BefLast_Last_error == 1)
13127
    begin
13128
        $display("ERR termination before last data!");
13129
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13130
    end
13131
    else
13132
    begin
13133
        $display("ERR termination with last data!");
13134
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13135
    end
13136
 
13137
    // write through the PCI bridge to WB slave
13138
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13139
    fork
13140
    begin
13141
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13142
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13143
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13144
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13145
        do_pause( 1 ) ;
13146
    end
13147
    begin
13148
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13149
        begin
13150
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13151
            if ( ok !== 1 )
13152
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13153
        end
13154
        else if (Imm_BefLast_Last_error == 1)
13155
        begin
13156
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13157
            if ( ok !== 1 )
13158
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13159
        end
13160
        else
13161
        begin
13162
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13163
            if ( ok !== 1 )
13164
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13165
        end
13166
    end
13167
    begin
13168
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13169
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13170
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13171
        else if (Imm_BefLast_Last_error == 1)
13172
        begin
13173
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13174
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13175
            wb_transaction_stop(expect_length-2) ;
13176
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13177
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13178
        end
13179
        else
13180
        begin
13181
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13182
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13183
            wb_transaction_stop(expect_length-1) ;
13184
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13185
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13186
        end
13187
    end
13188
    join
13189
 
13190
    if ( ok )
13191
        test_ok ;
13192
 
13193
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13194
    begin
13195
        rd_data[31:0] = Data[31:0];
13196
        rd_address[31:0] = expect_address;
13197
        rd_be[3:0] = Be[3:0];
13198
    end
13199
    else if (Imm_BefLast_Last_error == 1)
13200
    begin
13201
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13202
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13203
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13204
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13205
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13206
        rd_be[3:0] = Be[3:0];
13207
        for (i=0; i<(expect_length-2); i=i+1)
13208
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13209
    end
13210
    else
13211
    begin
13212
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13213
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13214
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13215
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13216
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13217
        rd_be[3:0] = Be[3:0];
13218
        for (i=0; i<(expect_length-1); i=i+1)
13219
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13220
    end
13221
 
13222
    master2_check_received_data = 0 ;
13223
    master1_check_received_data = 0 ;
13224
 
13225
    // Check if ERRORs were reported
13226
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13227
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13228
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13229
 
13230
    ok = 1 ;
13231
    config_read( addr_offset, 4'hF, read_data ) ;
13232
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13233
    begin
13234
        $display("Error was signaled and reported, as expected!");
13235
        if (read_data[31:28] === rd_be)
13236
            $display("Byte enables written into P_ERR_CS register are as expected!");
13237
        else
13238
        begin
13239
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13240
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13241
            ok = 0 ;
13242
        end
13243
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13244
            $display("Bus command written into P_ERR_CS register is as expected!");
13245
        else
13246
        begin
13247
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13248
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13249
            ok = 0 ;
13250
        end
13251
 
13252
        if ( ok )
13253
            test_ok ;
13254
 
13255
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13256
 
13257
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13258
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13259
        config_read( addr_offset, 4'hF, read_data ) ;
13260
        if (read_data === rd_data)
13261
        begin
13262
            $display("Data written into P_ERR_DATA register is as expected!");
13263
            test_ok ;
13264
        end
13265
        else
13266
        begin
13267
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13268
            test_fail("PCI Erroneous Data register value was wrong") ;
13269
        end
13270
 
13271
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13272
 
13273
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13274
 
13275
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13276
        config_read( addr_offset, 4'hF, read_data ) ;
13277
        if (read_data === rd_address)
13278
        begin
13279
            $display("Address written into P_ERR_ADDR register is as expected!");
13280
            test_ok ;
13281
        end
13282
        else
13283
        begin
13284
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13285
            test_fail("PCI Erroneous Address register value was wrong") ;
13286
        end
13287
    end
13288
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13289
    begin
13290
        $display("Error was signaled and not reported, as expected!");
13291
        test_ok ;
13292
    end
13293
    else
13294
    begin
13295
        $display("Error was signaled and reported, as NOT expected!");
13296
        test_fail("Error status bit was set event though error reporting was disabled") ;
13297
    end
13298
 
13299
    // Check if Interrupts were reported
13300
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13301
 
13302
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13303
    ok = 1 ;
13304
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13305
    config_read( addr_offset, 4'hF, read_data ) ;
13306
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13307
    begin
13308
        $display("Interrupts was signaled and reported, as expected!");
13309
    end
13310
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13311
    begin
13312
        $display("Interrupts was signaled and not reported, as expected!");
13313
    end
13314
    else
13315
    begin
13316
        $display("Interrupt was signaled and reported, as NOT expected!");
13317
        test_fail("PCI Error Interrupt status was set when not expected") ;
13318
        ok = 0 ;
13319
    end
13320
 
13321
    `ifdef HOST
13322
    repeat( 4 )
13323
        @(posedge wb_clock) ;
13324
 
13325
    if ( INT_O === Set_err_and_int_report )
13326
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13327
    else
13328
    begin
13329
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13330
        test_fail("Interrupt request didn't have expected value") ;
13331
        ok = 0 ;
13332
    end
13333
 
13334
    `else // GUEST
13335
    repeat( 4 )
13336
        @(posedge pci_clock) ;
13337
 
13338
    if ( INTA === !Set_err_and_int_report )
13339
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13340
    else
13341
    begin
13342
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13343
        test_fail("Interrupt request didn't have expected value") ;
13344
        ok = 0 ;
13345
    end
13346
 
13347
    `endif
13348
 
13349
    if ( ok )
13350
        test_ok ;
13351
 
13352
    if (Set_err_and_int_report)
13353
    begin
13354
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13355
        $display("Error and Interrupt must be cleared!");
13356
        // clear  ERROR reporting bit
13357
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13358
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13359
        if ( ok !== 1 )
13360
        begin
13361
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13362
            test_fail("PCI Error Control and Status register could not be written to") ;
13363
            disable main;
13364
        end
13365
 
13366
        // clear INTERRUPT reporting bit
13367
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13368
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13369
        if ( ok !== 1 )
13370
        begin
13371
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13372
            test_fail("Interrupt Status register could not be written to") ;
13373
            disable main;
13374
        end
13375
 
13376
        test_ok ;
13377
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13378
        `ifdef HOST
13379
 
13380
        repeat(4)
13381
            @(posedge wb_clock) ;
13382
        if ( INT_O === 1'b0 )
13383
        begin
13384
            $display("Interrupt pin INT_O was correctly cleared!");
13385
            test_ok ;
13386
        end
13387
        else
13388
        begin
13389
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13390
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13391
            disable main;
13392
        end
13393
 
13394
        `else // GUEST
13395
 
13396
        repeat(4)
13397
            @(posedge pci_clock) ;
13398
        if ( INTA === 1'b1 )
13399
        begin
13400
            $display("Interrupt pin INTA was correctly cleared!");
13401
            test_ok ;
13402
        end
13403
        else
13404
        begin
13405
            $display("Interrupt pin INTA was NOT correctly cleared!");
13406
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13407
            disable main;
13408
        end
13409
 
13410
        `endif
13411
 
13412
    end
13413
    else
13414
    begin
13415
        $display("Error and Interrupt don't need to be cleared!");
13416
    end
13417
end // main
13418
endtask // test_wb_error_wr
13419
 
13420
task test_wb_error_rd;
13421
    reg    [11:0] addr_offset ;
13422
    reg    [11:0] ctrl_offset ;
13423
    reg    [11:0] ba_offset ;
13424
    reg    [11:0] am_offset ;
13425
    reg    [11:0] ta_offset ;
13426
    reg    [31:0] read_data;
13427
    reg           ok   ;
13428
    reg    [9:0]  expect_length ;
13429
    reg    [31:0] expect_address ;
13430
    reg    [0:0]  expect_we ;
13431
    reg    [31:0] rd_address;
13432
    reg    [31:0] rd_data;
13433
    reg    [3:0]  rd_be;
13434
    integer       i ;
13435
    reg           do_mem_aborts ;
13436
    reg           do_io_aborts ;
13437 35 mihad
    reg           error_monitor_done ;
13438 15 mihad
begin:main
13439
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13440
 
13441
    if ( target_mem_image !== -1 )
13442
    begin
13443
        do_mem_aborts = 1 ;
13444
 
13445
        if (target_mem_image === 1)
13446
        begin
13447
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13448
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13449
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13450
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13451
        end
13452
        else if (target_mem_image === 2)
13453
        begin
13454
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13455
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13456
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13457
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13458
        end
13459
        else if (target_mem_image === 3)
13460
        begin
13461
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13462
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13463
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13464
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13465
        end
13466
        else if (target_mem_image === 4)
13467
        begin
13468
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13469
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13470
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13471
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13472
        end
13473
        else if (target_mem_image === 5)
13474
        begin
13475
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13476
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13477
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13478
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13479
        end
13480
    end
13481
    else
13482
        do_mem_aborts = 0 ;
13483
 
13484
    if ( do_mem_aborts )
13485
    begin
13486
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13487
 
13488
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13489
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13490
        if ( ok !== 1 )
13491
        begin
13492
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13493
            test_fail("PCI Error Control and Status register could not be written") ;
13494
            disable main;
13495
        end
13496
 
13497
        // enable INTERRUPT reporting
13498
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13499
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13500
        if ( ok !== 1 )
13501
        begin
13502
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13503
            test_fail("Interrupt Control register could not be written") ;
13504
            disable main;
13505
        end
13506
 
13507
        addr_offset = 12'h010 + (4*target_mem_image) ;
13508
 
13509
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13510
        if ( ok !== 1 )
13511
        begin
13512
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13513
            test_fail("PCI Base Address register could not be written") ;
13514
            disable main;
13515
        end
13516
 
13517
        // disable address translation and enable prefetch so read bursts can be performed
13518
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13519
        if ( ok !== 1 )
13520
        begin
13521
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13522
            test_fail("PCI Image Control register could not be written") ;
13523
            disable main;
13524
        end
13525
 
13526
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13527
        if ( ok !== 1 )
13528
        begin
13529
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13530
            test_fail("PCI Address Mask register could not be written") ;
13531
            disable main;
13532
        end
13533
 
13534
        addr_offset = 12'h00C ;
13535
 
13536
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13537
        if ( ok !== 1 )
13538
        begin
13539
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13540
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13541
            disable main;
13542
        end
13543
 
13544
        // disable PCI master data checking
13545
        master1_check_received_data = 0 ;
13546
 
13547
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13548
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13549
 
13550
 
13551
        // do a single read error terminated on WB bus
13552
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13553
 
13554
        fork
13555
        begin
13556
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13557
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13558
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13559
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13560
 
13561
            do_pause( 1 ) ;
13562
        end
13563
        begin
13564
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13565
 
13566
            if ( ok !== 1 )
13567
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13568
 
13569
            do_pause(3) ;
13570
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13571
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13572
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13573
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13574
            do_pause(1) ;
13575
 
13576
            while ( FRAME === 0 )
13577
                @(posedge pci_clock) ;
13578
 
13579
            while ( IRDY === 0 )
13580
                @(posedge pci_clock) ;
13581
 
13582 35 mihad
            #1 ;
13583
            if ( !error_monitor_done )
13584
                disable monitor_error_event1 ;
13585 15 mihad
        end
13586
        begin:monitor_error_event1
13587 35 mihad
            error_monitor_done = 0 ;
13588 15 mihad
            @(error_event_int) ;
13589
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13590
            ok = 0 ;
13591 35 mihad
            error_monitor_done = 1 ;
13592 15 mihad
        end
13593
        join
13594
 
13595
        if ( ok )
13596
            test_ok ;
13597 26 mihad
 
13598
        @(posedge pci_clock) ;
13599
        @(posedge pci_clock) ;
13600
        @(posedge wb_clock) ;
13601
        @(posedge wb_clock) ;
13602 15 mihad
 
13603
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13604
        addr_offset = 12'h004 ;
13605
        config_read(addr_offset, 4'hF, read_data) ;
13606
        ok = 1 ;
13607
        if ( read_data[27] !== 1 )
13608
        begin
13609
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13610
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13611
            ok = 0 ;
13612
        end
13613
        if ( read_data[28] !== 0 )
13614
        begin
13615
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13616
            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") ;
13617
            ok = 0 ;
13618
        end
13619
        if ( read_data[29] !== 0 )
13620
        begin
13621
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13622
            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") ;
13623
            ok = 0 ;
13624
        end
13625
 
13626
        // clear statuses
13627
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13628
        if ( !ok )
13629
        begin
13630
            test_fail("write to PCI Device Status register failed") ;
13631
            $display("Couldn't write PCI Device Status register") ;
13632
            disable main ;
13633
        end
13634
 
13635
        if ( ok )
13636
            test_ok ;
13637
 
13638
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13639
 
13640
        ok = 1 ;
13641
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13642
 
13643
        config_read(addr_offset, 4'hF, read_data) ;
13644
        if (read_data[8] !== 0)
13645
        begin
13646
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13647
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13648
            ok = 0 ;
13649
        end
13650
        else
13651
            test_ok ;
13652
 
13653
        if ( ok !== 1 )
13654
        begin
13655
            config_write(addr_offset, read_data, 4'hF, ok) ;
13656
            if ( !ok )
13657
            begin
13658
                test_fail("PCI Error Control and Status register could not be written") ;
13659
                disable main ;
13660
            end
13661
        end
13662
 
13663
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13664
        fork
13665
        begin
13666
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13667
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13668
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13669
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13670
 
13671
            do_pause( 1 ) ;
13672
        end
13673
        begin
13674
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13675
 
13676
            if ( ok !== 1 )
13677
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13678
 
13679
            do_pause(3) ;
13680
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13681
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13682
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13683
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13684
            do_pause(1) ;
13685
 
13686
            while ( FRAME === 0 )
13687
                @(posedge pci_clock) ;
13688
 
13689
            while ( IRDY === 0 )
13690
                @(posedge pci_clock) ;
13691
 
13692 35 mihad
            #1 ;
13693
            if ( !error_monitor_done )
13694
                disable monitor_error_event2 ;
13695 15 mihad
        end
13696
        begin:monitor_error_event2
13697 35 mihad
            error_monitor_done = 0 ;
13698 15 mihad
            @(error_event_int) ;
13699
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13700
            ok = 0 ;
13701 35 mihad
            error_monitor_done = 1 ;
13702 15 mihad
        end
13703
        join
13704
 
13705
        if ( ok )
13706
            test_ok ;
13707
 
13708 26 mihad
        @(posedge pci_clock) ;
13709
        @(posedge pci_clock) ;
13710
        @(posedge wb_clock) ;
13711
        @(posedge wb_clock) ;
13712
 
13713 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13714
        addr_offset = 12'h004 ;
13715
        config_read(addr_offset, 4'hF, read_data) ;
13716
        ok = 1 ;
13717
        if ( read_data[27] !== 1 )
13718
        begin
13719
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13720
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13721
            ok = 0 ;
13722
        end
13723
        if ( read_data[28] !== 0 )
13724
        begin
13725
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13726
            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") ;
13727
            ok = 0 ;
13728
        end
13729
        if ( read_data[29] !== 0 )
13730
        begin
13731
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13732
            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") ;
13733
            ok = 0 ;
13734
        end
13735
 
13736
        // clear statuses
13737
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13738
        if ( !ok )
13739
        begin
13740
            test_fail("write to PCI Device Status register failed") ;
13741
            $display("Couldn't write PCI Device Status register") ;
13742
            disable main ;
13743
        end
13744
 
13745
        if ( ok )
13746
            test_ok ;
13747
 
13748
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13749
 
13750
        ok = 1 ;
13751
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13752
 
13753
        config_read(addr_offset, 4'hF, read_data) ;
13754
        if (read_data[8] !== 0)
13755
        begin
13756
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13757
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13758
            ok = 0 ;
13759
        end
13760
        else
13761
            test_ok ;
13762
 
13763
        if ( ok !== 1 )
13764
        begin
13765
            config_write(addr_offset, read_data, 4'hF, ok) ;
13766
            if ( !ok )
13767
            begin
13768
                test_fail("PCI Error Control and Status register could not be written") ;
13769
                disable main ;
13770
            end
13771
        end
13772
 
13773
        // do a single read error terminated on WB bus
13774
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13775
 
13776
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13777
 
13778
        fork
13779
        begin
13780
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13781
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13782
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13783
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13784
 
13785
            do_pause( 1 ) ;
13786
        end
13787
        begin
13788
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13789
 
13790
            if ( ok !== 1 )
13791
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13792
 
13793
            do_pause(3) ;
13794
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13795
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13796
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13797
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13798
            do_pause(1) ;
13799
 
13800
            while ( FRAME === 0 )
13801
                @(posedge pci_clock) ;
13802
 
13803
            while ( IRDY === 0 )
13804
                @(posedge pci_clock) ;
13805
 
13806 35 mihad
            if ( !error_monitor_done )
13807
                disable monitor_error_event3 ;
13808 15 mihad
        end
13809
        begin:monitor_error_event3
13810 35 mihad
            error_monitor_done = 0 ;
13811 15 mihad
            @(error_event_int) ;
13812
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13813
            ok = 0 ;
13814 35 mihad
            error_monitor_done = 1 ;
13815 15 mihad
        end
13816
        join
13817
 
13818
        if ( ok )
13819
            test_ok ;
13820
 
13821 26 mihad
        @(posedge pci_clock) ;
13822
        @(posedge pci_clock) ;
13823
        @(posedge wb_clock) ;
13824
        @(posedge wb_clock) ;
13825
 
13826 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13827
        addr_offset = 12'h004 ;
13828
        config_read(addr_offset, 4'hF, read_data) ;
13829
        ok = 1 ;
13830
        if ( read_data[27] !== 1 )
13831
        begin
13832
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13833
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13834
            ok = 0 ;
13835
        end
13836
        if ( read_data[28] !== 0 )
13837
        begin
13838
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13839
            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") ;
13840
            ok = 0 ;
13841
        end
13842
        if ( read_data[29] !== 0 )
13843
        begin
13844
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13845
            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") ;
13846
            ok = 0 ;
13847
        end
13848
 
13849
        // clear statuses
13850
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13851
        if ( !ok )
13852
        begin
13853
            test_fail("write to PCI Device Status register failed") ;
13854
            $display("Couldn't write PCI Device Status register") ;
13855
            disable main ;
13856
        end
13857
 
13858
        if ( ok )
13859
            test_ok ;
13860
 
13861
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13862
 
13863
        ok = 1 ;
13864
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13865
 
13866
        config_read(addr_offset, 4'hF, read_data) ;
13867
        if (read_data[8] !== 0)
13868
        begin
13869
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13870
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13871
            ok = 0 ;
13872
        end
13873
        else
13874
            test_ok ;
13875
 
13876
        if ( ok !== 1 )
13877
        begin
13878
            config_write(addr_offset, read_data, 4'hF, ok) ;
13879
            if ( !ok )
13880
            begin
13881
                test_fail("PCI Error Control and Status register could not be written") ;
13882
                disable main ;
13883
            end
13884
        end
13885
 
13886
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13887
 
13888
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13889
 
13890
        fork
13891
        begin
13892
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13893
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13894
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13895
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13896
 
13897
            do_pause( 1 ) ;
13898
        end
13899
        begin
13900
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13901
 
13902
            if ( ok !== 1 )
13903
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13904
 
13905
            do_pause(3) ;
13906
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13907
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13908
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13909
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13910
            do_pause(1) ;
13911
 
13912
            while ( FRAME === 0 )
13913
                @(posedge pci_clock) ;
13914
 
13915
            while ( IRDY === 0 )
13916
                @(posedge pci_clock) ;
13917
 
13918 35 mihad
            #1 ;
13919
            if ( !error_monitor_done )
13920
                disable monitor_error_event4 ;
13921 15 mihad
        end
13922
        begin:monitor_error_event4
13923 35 mihad
            error_monitor_done = 0 ;
13924 15 mihad
            @(error_event_int) ;
13925
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13926
            ok = 0 ;
13927 35 mihad
            error_monitor_done = 1 ;
13928 15 mihad
        end
13929
        begin
13930
            wb_transaction_stop( 1 ) ;
13931
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13932
        end
13933
        join
13934
 
13935
        if ( ok )
13936
            test_ok ;
13937
 
13938 26 mihad
        @(posedge pci_clock) ;
13939
        @(posedge pci_clock) ;
13940
        @(posedge wb_clock) ;
13941
        @(posedge wb_clock) ;
13942
 
13943 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13944
        addr_offset = 12'h004 ;
13945
        config_read(addr_offset, 4'hF, read_data) ;
13946
        ok = 1 ;
13947
        if ( read_data[27] !== 1 )
13948
        begin
13949
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13950
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13951
            ok = 0 ;
13952
        end
13953
        if ( read_data[28] !== 0 )
13954
        begin
13955
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13956
            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") ;
13957
            ok = 0 ;
13958
        end
13959
        if ( read_data[29] !== 0 )
13960
        begin
13961
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13962
            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") ;
13963
            ok = 0 ;
13964
        end
13965
 
13966
        // clear statuses
13967
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13968
        if ( !ok )
13969
        begin
13970
            test_fail("write to PCI Device Status register failed") ;
13971
            $display("Couldn't write PCI Device Status register") ;
13972
            disable main ;
13973
        end
13974
 
13975
        if ( ok )
13976
            test_ok ;
13977
 
13978
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13979
 
13980
        ok = 1 ;
13981
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13982
 
13983
        config_read(addr_offset, 4'hF, read_data) ;
13984
        if (read_data[8] !== 0)
13985
        begin
13986
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13987
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13988
            ok = 0 ;
13989
        end
13990
        else
13991
            test_ok ;
13992
 
13993
        if ( ok !== 1 )
13994
        begin
13995
            config_write(addr_offset, read_data, 4'hF, ok) ;
13996
            if ( !ok )
13997
            begin
13998
                test_fail("PCI Error Control and Status register could not be written") ;
13999
                disable main ;
14000
            end
14001
        end
14002
 
14003
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14004
 
14005
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14006
 
14007
        fork
14008
        begin
14009
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14010
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14011
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14012
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14013
 
14014
            do_pause( 1 ) ;
14015
        end
14016
        begin
14017
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14018
 
14019
            if ( ok !== 1 )
14020
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14021
 
14022
            do_pause(3) ;
14023
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14024
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14025
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14026
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14027
            do_pause(1) ;
14028
 
14029
            while ( FRAME === 0 )
14030
                @(posedge pci_clock) ;
14031
 
14032
            while ( IRDY === 0 )
14033
                @(posedge pci_clock) ;
14034
 
14035 35 mihad
            #1 ;
14036
            if ( !error_monitor_done )
14037
                disable monitor_error_event5 ;
14038 15 mihad
        end
14039
        begin:monitor_error_event5
14040 35 mihad
            error_monitor_done = 0 ;
14041 15 mihad
            @(error_event_int) ;
14042
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14043
            ok = 0 ;
14044 35 mihad
            error_monitor_done = 1 ;
14045 15 mihad
        end
14046
        begin
14047
            wb_transaction_stop( 3 ) ;
14048
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14049
        end
14050
        join
14051
 
14052
        if ( ok )
14053
            test_ok ;
14054
 
14055 26 mihad
        @(posedge pci_clock) ;
14056
        @(posedge pci_clock) ;
14057
        @(posedge wb_clock) ;
14058
        @(posedge wb_clock) ;
14059
 
14060 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14061
        addr_offset = 12'h004 ;
14062
        config_read(addr_offset, 4'hF, read_data) ;
14063
        ok = 1 ;
14064
        if ( read_data[27] !== 1 )
14065
        begin
14066
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14067
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14068
            ok = 0 ;
14069
        end
14070
        if ( read_data[28] !== 0 )
14071
        begin
14072
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14073
            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") ;
14074
            ok = 0 ;
14075
        end
14076
        if ( read_data[29] !== 0 )
14077
        begin
14078
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14079
            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") ;
14080
            ok = 0 ;
14081
        end
14082
 
14083
        // clear statuses
14084
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14085
        if ( !ok )
14086
        begin
14087
            test_fail("write to PCI Device Status register failed") ;
14088
            $display("Couldn't write PCI Device Status register") ;
14089
            disable main ;
14090
        end
14091
 
14092
        if ( ok )
14093
            test_ok ;
14094
 
14095
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14096
 
14097
        ok = 1 ;
14098
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14099
 
14100
        config_read(addr_offset, 4'hF, read_data) ;
14101
        if (read_data[8] !== 0)
14102
        begin
14103
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14104
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14105
            ok = 0 ;
14106
        end
14107
        else
14108
            test_ok ;
14109
 
14110
        if ( ok !== 1 )
14111
        begin
14112
            config_write(addr_offset, read_data, 4'hF, ok) ;
14113
            if ( !ok )
14114
            begin
14115
                test_fail("PCI Error Control and Status register could not be written") ;
14116
                disable main ;
14117
            end
14118
        end
14119
 
14120
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14121
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14122
        fork
14123
        begin
14124
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14125
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14126
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14127
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14128
 
14129
            do_pause( 1 ) ;
14130
        end
14131
        begin
14132
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14133
 
14134
            if ( ok !== 1 )
14135
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14136
 
14137
            do_pause(3) ;
14138
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14139
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14140
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14141
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14142
            do_pause(1) ;
14143
 
14144
            while ( FRAME === 0 )
14145
                @(posedge pci_clock) ;
14146
 
14147
            while ( IRDY === 0 )
14148
                @(posedge pci_clock) ;
14149
 
14150 35 mihad
            #1 ;
14151
            if ( !error_monitor_done )
14152
                disable monitor_error_event6 ;
14153 15 mihad
        end
14154
        begin:monitor_error_event6
14155 35 mihad
            error_monitor_done = 0 ;
14156 15 mihad
            @(error_event_int) ;
14157
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14158
            ok = 0 ;
14159 35 mihad
            error_monitor_done = 1 ;
14160 15 mihad
        end
14161
        begin
14162
            wb_transaction_stop( 3 ) ;
14163
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14164
        end
14165
        join
14166
 
14167
        if ( ok )
14168
            test_ok ;
14169
 
14170 26 mihad
        @(posedge pci_clock) ;
14171
        @(posedge pci_clock) ;
14172
        @(posedge wb_clock) ;
14173
        @(posedge wb_clock) ;
14174
 
14175 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14176
        addr_offset = 12'h004 ;
14177
        config_read(addr_offset, 4'hF, read_data) ;
14178
        ok = 1 ;
14179
        if ( read_data[27] !== 1 )
14180
        begin
14181
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14182
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14183
            ok = 0 ;
14184
        end
14185
        if ( read_data[28] !== 0 )
14186
        begin
14187
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14188
            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") ;
14189
            ok = 0 ;
14190
        end
14191
        if ( read_data[29] !== 0 )
14192
        begin
14193
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14194
            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") ;
14195
            ok = 0 ;
14196
        end
14197
 
14198
        // clear statuses
14199
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14200
        if ( !ok )
14201
        begin
14202
            test_fail("write to PCI Device Status register failed") ;
14203
            $display("Couldn't write PCI Device Status register") ;
14204
            disable main ;
14205
        end
14206
 
14207
        if ( ok )
14208
            test_ok ;
14209
 
14210
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14211
 
14212
        ok = 1 ;
14213
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14214
 
14215
        config_read(addr_offset, 4'hF, read_data) ;
14216
        if (read_data[8] !== 0)
14217
        begin
14218
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14219
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14220
            ok = 0 ;
14221
        end
14222
        else
14223
            test_ok ;
14224
 
14225
        if ( ok !== 1 )
14226
        begin
14227
            config_write(addr_offset, read_data, 4'hF, ok) ;
14228
            if ( !ok )
14229
            begin
14230
                test_fail("PCI Error Control and Status register could not be written") ;
14231
                disable main ;
14232
            end
14233
        end
14234
 
14235
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14236
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14237
        fork
14238
        begin
14239
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14240
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14241
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14242
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14243
 
14244
            do_pause( 1 ) ;
14245
        end
14246
        begin
14247
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14248
 
14249
            if ( ok !== 1 )
14250
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14251
 
14252
            do_pause(3) ;
14253
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14254
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14255
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14256
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14257
            do_pause(1) ;
14258
 
14259
            while ( FRAME === 0 )
14260
                @(posedge pci_clock) ;
14261
 
14262
            while ( IRDY === 0 )
14263
                @(posedge pci_clock) ;
14264
 
14265 35 mihad
            #1 ;
14266
            if ( !error_monitor_done )
14267
                disable monitor_error_event7 ;
14268 15 mihad
        end
14269
        begin:monitor_error_event7
14270 35 mihad
            error_monitor_done = 0 ;
14271 15 mihad
            @(error_event_int) ;
14272
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14273
            ok = 0 ;
14274 35 mihad
            error_monitor_done = 1 ;
14275 15 mihad
        end
14276
        begin
14277
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14278
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14279
        end
14280
        join
14281
 
14282
        if ( ok )
14283
            test_ok ;
14284
 
14285 26 mihad
        @(posedge pci_clock) ;
14286
        @(posedge pci_clock) ;
14287
        @(posedge wb_clock) ;
14288
        @(posedge wb_clock) ;
14289
 
14290 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14291
        addr_offset = 12'h004 ;
14292
        config_read(addr_offset, 4'hF, read_data) ;
14293
        ok = 1 ;
14294
        if ( read_data[27] !== 1 )
14295
        begin
14296
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14297
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14298
            ok = 0 ;
14299
        end
14300
        if ( read_data[28] !== 0 )
14301
        begin
14302
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14303
            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") ;
14304
            ok = 0 ;
14305
        end
14306
        if ( read_data[29] !== 0 )
14307
        begin
14308
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14309
            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") ;
14310
            ok = 0 ;
14311
        end
14312
 
14313
        // clear statuses
14314
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14315
        if ( !ok )
14316
        begin
14317
            test_fail("write to PCI Device Status register failed") ;
14318
            $display("Couldn't write PCI Device Status register") ;
14319
            disable main ;
14320
        end
14321
 
14322
        if ( ok )
14323
            test_ok ;
14324
 
14325
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14326
 
14327
        ok = 1 ;
14328
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14329
 
14330
        config_read(addr_offset, 4'hF, read_data) ;
14331
        if (read_data[8] !== 0)
14332
        begin
14333
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14334
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14335
            ok = 0 ;
14336
        end
14337
        else
14338
            test_ok ;
14339
 
14340
        if ( ok !== 1 )
14341
        begin
14342
            config_write(addr_offset, read_data, 4'hF, ok) ;
14343
            if ( !ok )
14344
            begin
14345
                test_fail("PCI Error Control and Status register could not be written") ;
14346
                disable main ;
14347
            end
14348
        end
14349
 
14350
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14351
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14352
        fork
14353
        begin
14354
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14355
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14356
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14357
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14358
 
14359
            do_pause( 1 ) ;
14360
        end
14361
        begin
14362
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14363
 
14364
            if ( ok !== 1 )
14365
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14366
 
14367
            do_pause(3) ;
14368
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14369
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14370
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14371
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14372
            do_pause(1) ;
14373
 
14374
            while ( FRAME === 0 )
14375
                @(posedge pci_clock) ;
14376
 
14377
            while ( IRDY === 0 )
14378
                @(posedge pci_clock) ;
14379
 
14380 35 mihad
            #1 ;
14381
            if ( !error_monitor_done )
14382
                disable monitor_error_event8 ;
14383 15 mihad
        end
14384
        begin:monitor_error_event8
14385 35 mihad
            error_monitor_done = 0 ;
14386 15 mihad
            @(error_event_int) ;
14387
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14388
            ok = 0 ;
14389 35 mihad
            error_monitor_done = 1 ;
14390 15 mihad
        end
14391
        begin
14392
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14393
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14394
        end
14395
        join
14396
 
14397
        if ( ok )
14398
            test_ok ;
14399
 
14400 26 mihad
        @(posedge pci_clock) ;
14401
        @(posedge pci_clock) ;
14402
        @(posedge wb_clock) ;
14403
        @(posedge wb_clock) ;
14404
 
14405 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14406
 
14407
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14408
        addr_offset = 12'h004 ;
14409
        config_read(addr_offset, 4'hF, read_data) ;
14410
        ok = 1 ;
14411
        if ( read_data[27] !== 1 )
14412
        begin
14413
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14414
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14415
            ok = 0 ;
14416
        end
14417
        if ( read_data[28] !== 0 )
14418
        begin
14419
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14420
            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") ;
14421
            ok = 0 ;
14422
        end
14423
        if ( read_data[29] !== 0 )
14424
        begin
14425
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14426
            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") ;
14427
            ok = 0 ;
14428
        end
14429
 
14430
        // clear statuses
14431
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14432
        if ( !ok )
14433
        begin
14434
            test_fail("write to PCI Device Status register failed") ;
14435
            $display("Couldn't write PCI Device Status register") ;
14436
            disable main ;
14437
        end
14438
 
14439
        if ( ok )
14440
            test_ok ;
14441
 
14442
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14443
 
14444
        ok = 1 ;
14445
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14446
 
14447
        config_read(addr_offset, 4'hF, read_data) ;
14448
        if (read_data[8] !== 0)
14449
        begin
14450
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14451
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14452
            ok = 0 ;
14453
        end
14454
        else
14455
            test_ok ;
14456
 
14457
        if ( ok !== 1 )
14458
        begin
14459
            config_write(addr_offset, read_data, 4'hF, ok) ;
14460
            if ( !ok )
14461
            begin
14462
                test_fail("PCI Error Control and Status register could not be written") ;
14463
                disable main ;
14464
            end
14465
        end
14466
 
14467
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14468
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14469
        fork
14470
        begin
14471
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14472
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14473
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14474
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14475
 
14476
            do_pause( 1 ) ;
14477
        end
14478
        begin
14479
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14480
 
14481
            if ( ok !== 1 )
14482
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14483
 
14484
            do_pause(3) ;
14485
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14486
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14487
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14488
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14489
            do_pause(1) ;
14490
 
14491
            while ( FRAME === 0 )
14492
                @(posedge pci_clock) ;
14493
 
14494
            while ( IRDY === 0 )
14495
                @(posedge pci_clock) ;
14496
 
14497 35 mihad
            #1 ;
14498
            if ( !error_monitor_done )
14499
                disable monitor_error_event9 ;
14500 15 mihad
        end
14501
        begin:monitor_error_event9
14502 35 mihad
            error_monitor_done = 0 ;
14503 15 mihad
            @(error_event_int) ;
14504
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14505
            ok = 0 ;
14506 35 mihad
            error_monitor_done = 1 ;
14507 15 mihad
        end
14508
        begin
14509
            wb_transaction_stop( 3 ) ;
14510
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14511
        end
14512
        join
14513
 
14514
        if ( ok )
14515
            test_ok ;
14516
 
14517
        // now check all other statuses too
14518
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14519
        ok = 1 ;
14520
 
14521
        addr_offset = 12'h004 ;
14522
        config_read(addr_offset, 4'hF, read_data) ;
14523
        if (read_data[31] !== 0)
14524
        begin
14525
            $display("Detected Parity Error bit set for no reason") ;
14526
            test_fail("Detected Parity Error bit was set for no reason") ;
14527
            ok = 0 ;
14528
        end
14529
 
14530
        if (read_data[30] !== 0)
14531
        begin
14532
            $display("Signaled System Error bit set for no reason") ;
14533
            test_fail("Signaled System Error bit was set for no reason") ;
14534
            ok = 0 ;
14535
        end
14536
 
14537
        if (read_data[29] !== 0)
14538
        begin
14539
            $display("Received Master Abort bit set for no reason") ;
14540
            test_fail("Received Master Abort bit was set for no reason") ;
14541
            ok = 0 ;
14542
        end
14543
 
14544
        if (read_data[28] !== 0)
14545
        begin
14546
            $display("Received Target Abort bit set for no reason");
14547
            test_fail("Received Target Abort bit was set for no reason") ;
14548
            ok = 0 ;
14549
        end
14550
 
14551
        if (read_data[27] !== 0)
14552
        begin
14553
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14554
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14555
            ok = 0 ;
14556
        end
14557
 
14558
        if (read_data[24] !== 0)
14559
        begin
14560
            $display("Master Data Parity Error bit set for no reason") ;
14561
            test_fail("Master Data Parity Error bit was set for no reason") ;
14562
            ok = 0 ;
14563
        end
14564
 
14565
        if ( ok )
14566
            test_ok ;
14567
 
14568
        test_name = "DISABLE IMAGE" ;
14569 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14570 15 mihad
        if ( ok !== 1 )
14571
        begin
14572
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14573
            test_fail("PCI Address Mask register could not be written") ;
14574
            disable main;
14575
        end
14576
    end
14577
 
14578
    if ( target_io_image !== -1 )
14579
    begin
14580
        do_io_aborts = 1 ;
14581
 
14582
        if (target_io_image === 1)
14583
        begin
14584
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14585
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14586
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14587
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14588
        end
14589
        else if (target_io_image === 2)
14590
        begin
14591
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14592
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14593
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14594
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14595
        end
14596
        else if (target_io_image === 3)
14597
        begin
14598
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14599
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14600
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14601
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14602
        end
14603
        else if (target_io_image === 4)
14604
        begin
14605
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14606
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14607
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14608
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14609
        end
14610
        else if (target_io_image === 5)
14611
        begin
14612
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14613
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14614
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14615
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14616
        end
14617
    end
14618
    else
14619
        do_io_aborts = 0 ;
14620
 
14621
    if ( do_io_aborts )
14622
    begin
14623
 
14624
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14625
 
14626
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14627
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14628
        if ( ok !== 1 )
14629
        begin
14630
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14631
            test_fail("PCI Error Control and Status register could not be written") ;
14632
            disable main;
14633
        end
14634
 
14635
        // enable INTERRUPT reporting
14636
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14637
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14638
        if ( ok !== 1 )
14639
        begin
14640
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14641
            test_fail("Interrupt Control register could not be written") ;
14642
            disable main;
14643
        end
14644
 
14645
        addr_offset = 12'h010 + (4*target_io_image) ;
14646
 
14647
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14648
        if ( ok !== 1 )
14649
        begin
14650
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14651
            test_fail("PCI Base Address register could not be written") ;
14652
            disable main;
14653
        end
14654
 
14655
        // disable address translation and enable prefetch so read bursts can be performed
14656
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14657
        if ( ok !== 1 )
14658
        begin
14659
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14660
            test_fail("PCI Image Control register could not be written") ;
14661
            disable main;
14662
        end
14663
 
14664
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14665
        if ( ok !== 1 )
14666
        begin
14667
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14668
            test_fail("PCI Address Mask register could not be written") ;
14669
            disable main;
14670
        end
14671
 
14672
        addr_offset = 12'h00C ;
14673
 
14674
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14675
        if ( ok !== 1 )
14676
        begin
14677
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14678
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14679
            disable main;
14680
        end
14681
 
14682
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14683
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14684
 
14685
        // do a single read error terminated on WB bus
14686
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14687
 
14688
        fork
14689
        begin
14690
            PCIU_IO_READ
14691
             (
14692
                `Test_Master_1,
14693
                Target_Base_Addr_R[target_io_image],
14694
                32'hAAAA_5555,
14695
                4'h0,
14696
                1,
14697
                `Test_Target_Retry_On
14698
             );
14699
 
14700
            do_pause( 1 ) ;
14701
        end
14702
        begin
14703
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14704
 
14705
            if ( ok !== 1 )
14706
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14707
 
14708
            do_pause(3) ;
14709
 
14710
            PCIU_IO_READ
14711
             (
14712
                `Test_Master_1,
14713
                Target_Base_Addr_R[target_io_image],
14714
                32'hAAAA_5555,
14715
                4'h0,
14716
                1,
14717
                `Test_Target_Abort_On
14718
             );
14719
 
14720
            do_pause( 1 ) ;
14721
 
14722
            while ( FRAME === 0 )
14723
                @(posedge pci_clock) ;
14724
 
14725
            while ( IRDY === 0 )
14726
                @(posedge pci_clock) ;
14727
 
14728 35 mihad
            #1 ;
14729
            if ( !error_monitor_done )
14730
                disable monitor_error_event10 ;
14731 15 mihad
        end
14732
        begin:monitor_error_event10
14733 35 mihad
            error_monitor_done = 0 ;
14734 15 mihad
            @(error_event_int) ;
14735
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14736
            ok = 0 ;
14737 35 mihad
            error_monitor_done = 1 ;
14738 15 mihad
        end
14739
        join
14740
 
14741
        if ( ok )
14742
            test_ok ;
14743
 
14744 26 mihad
        @(posedge pci_clock) ;
14745
        @(posedge pci_clock) ;
14746
        @(posedge wb_clock) ;
14747
        @(posedge wb_clock) ;
14748
 
14749 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14750
        addr_offset = 12'h004 ;
14751
        config_read(addr_offset, 4'hF, read_data) ;
14752
        ok = 1 ;
14753
        if ( read_data[27] !== 1 )
14754
        begin
14755
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14756
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14757
            ok = 0 ;
14758
        end
14759
        if ( read_data[28] !== 0 )
14760
        begin
14761
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14762
            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") ;
14763
            ok = 0 ;
14764
        end
14765
        if ( read_data[29] !== 0 )
14766
        begin
14767
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14768
            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") ;
14769
            ok = 0 ;
14770
        end
14771
 
14772
        // clear statuses
14773
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14774
        if ( !ok )
14775
        begin
14776
            test_fail("write to PCI Device Status register failed") ;
14777
            $display("Couldn't write PCI Device Status register") ;
14778
            disable main ;
14779
        end
14780
 
14781
        if ( ok )
14782
            test_ok ;
14783
 
14784
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14785
 
14786
        ok = 1 ;
14787
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14788
 
14789
        config_read(addr_offset, 4'hF, read_data) ;
14790
        if (read_data[8] !== 0)
14791
        begin
14792
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14793
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14794
            ok = 0 ;
14795
        end
14796
        else
14797
            test_ok ;
14798
 
14799
        if ( ok !== 1 )
14800
        begin
14801
            config_write(addr_offset, read_data, 4'hF, ok) ;
14802
            if ( !ok )
14803
            begin
14804
                test_fail("PCI Error Control and Status register could not be written") ;
14805
                disable main ;
14806
            end
14807
        end
14808
 
14809
        test_name = "DISABLE IMAGE" ;
14810 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14811 15 mihad
        if ( ok !== 1 )
14812
        begin
14813
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14814
            test_fail("PCI Address Mask register could not be written") ;
14815
            disable main;
14816
        end
14817
 
14818
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14819
 
14820
    end
14821
end // main
14822
endtask // test_wb_error_rd
14823
 
14824
task test_target_abort ;
14825
    input [2:0]  image_num ;
14826
    reg   [11:0] pci_ctrl_offset ;
14827
    reg   [11:0] ctrl_offset ;
14828
    reg   [11:0] ba_offset ;
14829
    reg   [11:0] am_offset ;
14830
    reg   [11:0] ta_offset ;
14831
    reg   [31:0] pci_address ;
14832
    reg   [3:0]  byte_enables ;
14833
    reg          ok ;
14834 35 mihad
    reg          error_monitor_done ;
14835 15 mihad
begin:main
14836
    pci_ctrl_offset = 12'h4 ;
14837
    if (image_num === 0)
14838
    begin
14839
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14840
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14841
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14842
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14843
    end
14844
    else if (image_num === 1)
14845
    begin
14846
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14847
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14848
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14849
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14850
    end
14851
    else if (image_num === 2)
14852
    begin
14853
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14854
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14855
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14856
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14857
    end
14858
    else if (image_num === 3)
14859
    begin
14860
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14861
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14862
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14863
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14864
    end
14865
    else if (image_num === 4)
14866
    begin
14867
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14868
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14869
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14870
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14871
    end
14872
    else if (image_num === 5)
14873
    begin
14874
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14875
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14876
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14877
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14878
    end
14879
 
14880
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14881
 
14882
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14883
    if ( ok !== 1 )
14884
    begin
14885
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14886
        test_fail("PCI Base Address register could not be written") ;
14887
        disable main ;
14888
    end
14889
 
14890
    // Set Address Mask of IMAGE
14891
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14892
    if ( ok !== 1 )
14893
    begin
14894
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14895
        test_fail("PCI Address Mask register could not be written") ;
14896
        disable main ;
14897
    end
14898
 
14899
    // Set Translation Address of IMAGE
14900
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14901
    if ( ok !== 1 )
14902
    begin
14903
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14904
        test_fail("PCI Translation Address Register could not be written") ;
14905
        disable main ;
14906
    end
14907
 
14908
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14909
    if ( ok !== 1 )
14910
    begin
14911
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14912
        test_fail("PCI Image Control register could not be written") ;
14913
        disable main ;
14914
    end
14915
 
14916
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14917
 
14918
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14919
 
14920
    pci_address  = Target_Base_Addr_R[image_num] ;
14921
    byte_enables = 4'b0001 ;
14922
 
14923
    fork
14924
    begin
14925
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14926
        do_pause ( 1 ) ;
14927
    end
14928
    begin:monitor_error_event1
14929 35 mihad
        error_monitor_done = 0 ;
14930 15 mihad
        @(error_event_int) ;
14931
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14932
        ok = 0 ;
14933 35 mihad
        error_monitor_done = 1 ;
14934 15 mihad
    end
14935
    begin
14936
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14937
        @(posedge pci_clock) ;
14938 35 mihad
        #1 ;
14939
        if ( !error_monitor_done )
14940
            disable monitor_error_event1 ;
14941 15 mihad
    end
14942
    join
14943
 
14944
    if ( ok )
14945
        test_ok ;
14946
 
14947
    ok = 1 ;
14948
 
14949
    fork
14950
    begin
14951
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14952
        do_pause ( 1 ) ;
14953
    end
14954
    begin:monitor_error_event2
14955 35 mihad
        error_monitor_done = 0 ;
14956 15 mihad
        @(error_event_int) ;
14957
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14958
        ok = 0 ;
14959 35 mihad
        error_monitor_done = 1 ;
14960 15 mihad
    end
14961
    begin
14962
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14963
        @(posedge pci_clock) ;
14964 35 mihad
        #1 ;
14965
        if ( !error_monitor_done )
14966
            disable monitor_error_event2 ;
14967 15 mihad
    end
14968
    join
14969
 
14970
    if ( ok )
14971
        test_ok ;
14972
 
14973
    ok = 1 ;
14974
 
14975
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
14976
    byte_enables = 4'b0011 ;
14977
 
14978
    fork
14979
    begin
14980
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14981
        do_pause ( 1 ) ;
14982
    end
14983
    begin:monitor_error_event3
14984 35 mihad
        error_monitor_done = 0 ;
14985 15 mihad
        @(error_event_int) ;
14986
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14987
        ok = 0 ;
14988 35 mihad
        error_monitor_done = 1 ;
14989 15 mihad
    end
14990
    begin
14991
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14992
        @(posedge pci_clock) ;
14993 35 mihad
        if ( !error_monitor_done )
14994
            disable monitor_error_event3 ;
14995 15 mihad
    end
14996
    join
14997
 
14998
    if ( ok )
14999
        test_ok ;
15000
 
15001
    ok = 1 ;
15002
 
15003
    byte_enables = 4'b0000 ;
15004
 
15005
    fork
15006
    begin
15007
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15008
        do_pause ( 1 ) ;
15009
    end
15010
    begin:monitor_error_event4
15011 35 mihad
        error_monitor_done = 0 ;
15012 15 mihad
        @(error_event_int) ;
15013
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15014
        ok = 0 ;
15015 35 mihad
        error_monitor_done = 1 ;
15016 15 mihad
    end
15017
    begin
15018
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15019
        @(posedge pci_clock) ;
15020 35 mihad
        #1 ;
15021
        if ( !error_monitor_done )
15022
            disable monitor_error_event4 ;
15023 15 mihad
    end
15024
    join
15025
 
15026
    if ( ok )
15027
        test_ok ;
15028
 
15029
    ok = 1 ;
15030
 
15031
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
15032
    byte_enables = 4'b0111 ;
15033
 
15034
    fork
15035
    begin
15036
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15037
        do_pause ( 1 ) ;
15038
    end
15039
    begin:monitor_error_event5
15040 35 mihad
        error_monitor_done = 0 ;
15041 15 mihad
        @(error_event_int) ;
15042
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15043
        ok = 0 ;
15044 35 mihad
        error_monitor_done = 1 ;
15045 15 mihad
    end
15046
    begin
15047
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15048
        @(posedge pci_clock) ;
15049 35 mihad
        #1 ;
15050
        if ( !error_monitor_done )
15051
            disable monitor_error_event5 ;
15052 15 mihad
    end
15053
    join
15054
 
15055
    if ( ok )
15056
        test_ok ;
15057
 
15058
    ok = 1 ;
15059
 
15060
    byte_enables = 4'b0010 ;
15061
 
15062
    fork
15063
    begin
15064
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15065
        do_pause ( 1 ) ;
15066
    end
15067
    begin:monitor_error_event6
15068 35 mihad
        error_monitor_done = 0 ;
15069 15 mihad
        @(error_event_int) ;
15070
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15071
        ok = 0 ;
15072 35 mihad
        error_monitor_done = 1 ;
15073 15 mihad
    end
15074
    begin
15075
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15076
        @(posedge pci_clock) ;
15077 35 mihad
        #1 ;
15078
        if ( !error_monitor_done )
15079
            disable monitor_error_event6 ;
15080 15 mihad
    end
15081
    join
15082
 
15083
    if ( ok )
15084
        test_ok ;
15085
 
15086
    ok = 1 ;
15087
    byte_enables = 4'b0001 ;
15088
 
15089
    fork
15090
    begin
15091
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15092
        do_pause ( 1 ) ;
15093
    end
15094
    begin:monitor_error_event7
15095 35 mihad
        error_monitor_done = 0 ;
15096 15 mihad
        @(error_event_int) ;
15097
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15098
        ok = 0 ;
15099 35 mihad
        error_monitor_done = 1 ;
15100 15 mihad
    end
15101
    begin
15102
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15103
        @(posedge pci_clock) ;
15104 35 mihad
        #1 ;
15105
        if ( !error_monitor_done )
15106
            disable monitor_error_event7 ;
15107 15 mihad
    end
15108
    join
15109
 
15110
    if ( ok )
15111
        test_ok ;
15112
 
15113
    ok = 1 ;
15114
    byte_enables = 4'b0000 ;
15115
 
15116
    fork
15117
    begin
15118
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15119
        do_pause ( 1 ) ;
15120
    end
15121
    begin:monitor_error_event8
15122 35 mihad
        error_monitor_done = 0 ;
15123 15 mihad
        @(error_event_int) ;
15124
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15125
        ok = 0 ;
15126 35 mihad
        error_monitor_done = 1 ;
15127 15 mihad
    end
15128
    begin
15129
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15130
        @(posedge pci_clock) ;
15131 35 mihad
        #1 ;
15132
        if ( !error_monitor_done )
15133
            disable monitor_error_event8 ;
15134 15 mihad
    end
15135
    join
15136
 
15137
    if ( ok )
15138
        test_ok ;
15139
 
15140
    ok = 1 ;
15141
 
15142
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15143
    byte_enables = 4'b0110 ;
15144
 
15145
    fork
15146
    begin
15147
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15148
        do_pause ( 1 ) ;
15149
    end
15150
    begin:monitor_error_event9
15151 35 mihad
        error_monitor_done = 0 ;
15152 15 mihad
        @(error_event_int) ;
15153
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15154
        ok = 0 ;
15155 35 mihad
        error_monitor_done = 1 ;
15156 15 mihad
    end
15157
    begin
15158
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15159
        @(posedge pci_clock) ;
15160 35 mihad
        #1 ;
15161
        if ( !error_monitor_done )
15162
            disable monitor_error_event9 ;
15163 15 mihad
    end
15164
    join
15165
 
15166
    if ( ok )
15167
        test_ok ;
15168
 
15169
    ok = 1 ;
15170
    fork
15171
    begin
15172
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15173
        do_pause ( 1 ) ;
15174
    end
15175
    begin:monitor_error_event10
15176 35 mihad
        error_monitor_done = 0 ;
15177 15 mihad
        @(error_event_int) ;
15178
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15179
        ok = 0 ;
15180 35 mihad
        error_monitor_done = 1 ;
15181 15 mihad
    end
15182
    begin
15183
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15184
        @(posedge pci_clock) ;
15185 35 mihad
 
15186
        #1 ;
15187
        if ( !error_monitor_done )
15188
            disable monitor_error_event10 ;
15189 15 mihad
    end
15190
    join
15191
 
15192
    if ( ok )
15193
        test_ok ;
15194
 
15195
    ok = 1 ;
15196
 
15197
    byte_enables = 4'b0001 ;
15198
 
15199
    fork
15200
    begin
15201
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15202
        do_pause ( 1 ) ;
15203
    end
15204
    begin:monitor_error_event11
15205 35 mihad
        error_monitor_done = 0 ;
15206 15 mihad
        @(error_event_int) ;
15207
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15208
        ok = 0 ;
15209 35 mihad
        error_monitor_done = 1 ;
15210 15 mihad
    end
15211
    begin
15212
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15213
        @(posedge pci_clock) ;
15214 35 mihad
        #1 ;
15215
        if ( !error_monitor_done )
15216
            disable monitor_error_event11 ;
15217 15 mihad
    end
15218
    join
15219
 
15220
    if ( ok )
15221
        test_ok ;
15222
 
15223
    ok = 1 ;
15224
 
15225
    byte_enables = 4'b0101 ;
15226
 
15227
    fork
15228
    begin
15229
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15230
        do_pause ( 1 ) ;
15231
    end
15232
    begin:monitor_error_event12
15233 35 mihad
        error_monitor_done = 0 ;
15234 15 mihad
        @(error_event_int) ;
15235
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15236
        ok = 0 ;
15237 35 mihad
        error_monitor_done = 1 ;
15238 15 mihad
    end
15239
    begin
15240
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15241
        @(posedge pci_clock) ;
15242 35 mihad
        #1 ;
15243
        if ( !error_monitor_done )
15244
            disable monitor_error_event12 ;
15245 15 mihad
    end
15246
    join
15247
 
15248
    if ( ok )
15249
        test_ok ;
15250
 
15251
    ok = 1 ;
15252
 
15253
    byte_enables = 4'b0011 ;
15254
 
15255
    fork
15256
    begin
15257
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15258
        do_pause ( 1 ) ;
15259
    end
15260
    begin:monitor_error_event13
15261 35 mihad
        error_monitor_done = 0 ;
15262 15 mihad
        @(error_event_int) ;
15263
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15264
        ok = 0 ;
15265 35 mihad
        error_monitor_done = 1 ;
15266 15 mihad
    end
15267
    begin
15268
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15269
        @(posedge pci_clock) ;
15270 35 mihad
        #1 ;
15271
        if ( !error_monitor_done )
15272
            disable monitor_error_event13 ;
15273 15 mihad
    end
15274
    join
15275
 
15276
    if ( ok )
15277
        test_ok ;
15278
 
15279
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15280
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15281
    ok = 1 ;
15282
    if ( pci_address[27] !== 1 )
15283
    begin
15284
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15285
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15286
        ok = 0 ;
15287
    end
15288
    if ( pci_address[28] !== 0 )
15289
    begin
15290
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15291
        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") ;
15292
        ok = 0 ;
15293
    end
15294
    if ( pci_address[29] !== 0 )
15295
    begin
15296
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15297
        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") ;
15298
        ok = 0 ;
15299
    end
15300
 
15301
    // clear statuses
15302
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15303
    if ( !ok )
15304
    begin
15305
        test_fail("write to PCI Device Status register failed") ;
15306
        $display("Couldn't write PCI Device Status register") ;
15307
        disable main ;
15308
    end
15309
 
15310
    if ( ok )
15311
        test_ok ;
15312
 
15313
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15314
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15315
    if ( pci_address[8] !== 0 )
15316
    begin
15317
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15318
    end
15319
    else
15320
        test_ok ;
15321
 
15322
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15323
 
15324
    test_name = "DISABLE IMAGE" ;
15325
 
15326 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15327 15 mihad
    if ( ok !== 1 )
15328
    begin
15329
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15330
        test_fail("PCI Address Mask register could not be written") ;
15331
        disable main ;
15332
    end
15333
end
15334
endtask // test_target_abort
15335
 
15336
task test_target_io_wr_rd ;
15337
    input [2:0]  image_num ;
15338
    input        translate_address ;
15339
    input [11:0] img_ctrl_offset ;
15340
    reg   [31:0] expect_address ;
15341
    reg   [31:0] pci_address ;
15342
    reg          translation ;
15343
    reg   [31:0] read_data ;
15344
    reg   [3:0]  byte_enables ;
15345
    reg          ok ;
15346
    reg          pci_ok ;
15347
    reg          wb_ok ;
15348
    integer      i ;
15349 35 mihad
    reg          error_monitor_done ;
15350 15 mihad
begin:main
15351
    `ifdef ADDR_TRAN_IMPL
15352
        translation = translate_address ;
15353
    `else
15354
        translation = 0 ;
15355
    `endif
15356
 
15357
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15358
 
15359
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15360
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15361
    if ( translation )
15362
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15363
    else
15364
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15365
 
15366
    if ( !ok )
15367
    begin
15368
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15369
        test_fail("PCI Image Control register could not be written") ;
15370
    end
15371
 
15372
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15373
    pci_address  = Target_Base_Addr_R[image_num] ;
15374
    byte_enables = 4'b0000 ;
15375
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15376
 
15377
    fork
15378
    begin
15379
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15380
        do_pause ( 1 ) ;
15381
    end
15382
    begin
15383
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15384
        if ( wb_ok !== 1 )
15385
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15386
 
15387 35 mihad
        #1 ;
15388
        if ( !error_monitor_done )
15389
            disable monitor_pci_error_1 ;
15390 15 mihad
    end
15391
    begin:monitor_pci_error_1
15392 35 mihad
        error_monitor_done = 0 ;
15393 15 mihad
        pci_ok = 1 ;
15394
        @(error_event_int) ;
15395
        pci_ok = 0 ;
15396
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15397 35 mihad
        error_monitor_done = 1 ;
15398 15 mihad
    end
15399
    join
15400
 
15401
    byte_enables = 4'b1111 ;
15402
    for ( i = 0 ; i < 4 ; i = i + 1 )
15403
    begin:loop_1
15404
        byte_enables[i] = 0 ;
15405
        if ( i > 0 )
15406
            byte_enables[i - 1] = 1 ;
15407
        fork
15408
        begin
15409
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15410
            do_pause ( 1 ) ;
15411
        end
15412
        begin
15413
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15414
            if ( wb_ok !== 1 )
15415
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15416
 
15417 35 mihad
            #1 ;
15418
            if ( !error_monitor_done )
15419
                disable monitor_pci_error_2 ;
15420 15 mihad
        end
15421
        begin:monitor_pci_error_2
15422 35 mihad
            error_monitor_done = 0 ;
15423 15 mihad
            pci_ok = 1 ;
15424
            @(error_event_int) ;
15425
            pci_ok = 0 ;
15426
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15427 35 mihad
            error_monitor_done = 1 ;
15428 15 mihad
        end
15429
        join
15430
 
15431
        if ( !pci_ok || !wb_ok )
15432
            disable loop_1 ;
15433
 
15434
        pci_address = pci_address + 1 ;
15435
        expect_address = expect_address + 1 ;
15436
    end
15437
 
15438
    if ( pci_ok && wb_ok )
15439
        test_ok ;
15440
 
15441
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15442
    pci_address  = Target_Base_Addr_R[image_num] ;
15443
    byte_enables = 4'b1100 ;
15444
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15445
 
15446
    master1_check_received_data = 1 ;
15447
    fork
15448
    begin
15449
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15450
        do_pause( 1 ) ;
15451
    end
15452
    begin
15453
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15454
        if ( wb_ok !== 1 )
15455
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15456
 
15457
        do_pause ( 2 ) ;
15458
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15459
        do_pause ( 16 ) ;
15460
 
15461 35 mihad
        #1 ;
15462
        if ( !error_monitor_done )
15463
            disable monitor_pci_error_3 ;
15464 15 mihad
    end
15465
    begin:monitor_pci_error_3
15466 35 mihad
        error_monitor_done = 0 ;
15467 15 mihad
        pci_ok = 1 ;
15468
        @(error_event_int) ;
15469
        pci_ok = 0 ;
15470
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15471 35 mihad
        error_monitor_done = 1 ;
15472 15 mihad
    end
15473
    join
15474
 
15475
    if ( !pci_ok || !wb_ok )
15476
    begin
15477
        disable main ;
15478
    end
15479
 
15480
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15481
    byte_enables = 4'b0011 ;
15482
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15483
 
15484
    master1_check_received_data = 1 ;
15485
    fork
15486
    begin
15487
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15488
        do_pause( 1 ) ;
15489
    end
15490
    begin
15491
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15492
        if ( wb_ok !== 1 )
15493
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15494
 
15495
        do_pause ( 2 ) ;
15496
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15497
        do_pause ( 16 ) ;
15498
 
15499 35 mihad
        #1 ;
15500
        if ( !error_monitor_done )
15501
            disable monitor_pci_error_4 ;
15502 15 mihad
    end
15503
    begin:monitor_pci_error_4
15504 35 mihad
        error_monitor_done = 0 ;
15505 15 mihad
        pci_ok = 1 ;
15506
        @(error_event_int) ;
15507
        pci_ok = 0 ;
15508
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15509 35 mihad
        error_monitor_done = 1 ;
15510 15 mihad
    end
15511
    join
15512
 
15513
    if ( !pci_ok || !wb_ok )
15514
    begin
15515
        disable main ;
15516
    end
15517
 
15518
    pci_address  = Target_Base_Addr_R[image_num] ;
15519
    byte_enables = 4'b0000 ;
15520
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15521
 
15522
    master1_check_received_data = 1 ;
15523
    fork
15524
    begin
15525
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15526
        do_pause( 1 ) ;
15527
    end
15528
    begin
15529
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15530
        if ( wb_ok !== 1 )
15531
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15532
 
15533
        do_pause ( 2 ) ;
15534
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15535
        do_pause ( 16 ) ;
15536
 
15537 35 mihad
        #1 ;
15538
        if ( !error_monitor_done )
15539
            disable monitor_pci_error_5 ;
15540 15 mihad
    end
15541
    begin:monitor_pci_error_5
15542 35 mihad
        error_monitor_done = 0 ;
15543 15 mihad
        pci_ok = 1 ;
15544
        @(error_event_int) ;
15545
        pci_ok = 0 ;
15546
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15547 35 mihad
        error_monitor_done = 1 ;
15548 15 mihad
    end
15549
    join
15550
 
15551
    if ( pci_ok && wb_ok )
15552
        test_ok ;
15553
end
15554
endtask // test_target_io_wr_rd
15555
 
15556
task test_target_io_err_wr ;
15557
    input [2:0]  image_num ;
15558
    input        translate_address ;
15559
    input [11:0] img_ctrl_offset ;
15560
    input        enable_error_report ;
15561
    input        enable_error_interrupt ;
15562
 
15563
    reg   [31:0] expect_address ;
15564
    reg   [31:0] pci_address ;
15565
    reg          translation ;
15566
    reg   [31:0] read_data ;
15567
    reg   [3:0]  byte_enables ;
15568
    reg          ok ;
15569
    reg          pci_ok ;
15570
    reg          wb_ok ;
15571
    integer      i ;
15572
    reg   [11:0] offset ;
15573 35 mihad
    reg          error_monitor_done ;
15574 15 mihad
begin:main
15575
    `ifdef ADDR_TRAN_IMPL
15576
        translation = translate_address ;
15577
    `else
15578
        translation = 0 ;
15579
    `endif
15580
 
15581
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15582
 
15583
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15584
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15585
    if ( translation )
15586
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15587
    else
15588
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15589
 
15590
    if ( !ok )
15591
    begin
15592
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15593
        test_fail("PCI Image Control register could not be written") ;
15594
    end
15595
 
15596
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15597
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15598
    if ( enable_error_report )
15599
    begin
15600
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15601
        if ( !ok )
15602
        begin
15603
            test_fail("PCI Error Control and Status register could not be written") ;
15604
            disable main ;
15605
        end
15606
    end
15607
    else
15608
    begin
15609
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15610
        if ( !ok )
15611
        begin
15612
            test_fail("PCI Error Control and Status register could not be written") ;
15613
            disable main ;
15614
        end
15615
    end
15616
 
15617
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15618
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15619
    if ( enable_error_interrupt )
15620
    begin
15621
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15622
        if ( !ok )
15623
        begin
15624
            test_fail("Interrupt Control register could not be written") ;
15625
            disable main ;
15626
        end
15627
    end
15628
    else
15629
    begin
15630
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15631
        if ( !ok )
15632
        begin
15633
            test_fail("Interrupt Control register could not be written") ;
15634
            disable main ;
15635
        end
15636
    end
15637
 
15638
    pci_address  = Target_Base_Addr_R[image_num] ;
15639
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15640
 
15641
    byte_enables = 4'b1111 ;
15642
 
15643
    for ( i = 0 ; i < 4 ; i = i + 1 )
15644
    begin:loop_1
15645
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15646
        byte_enables[i] = 0 ;
15647
        if ( i > 0 )
15648
            byte_enables[i - 1] = 1 ;
15649
 
15650
        fork
15651
        begin
15652
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15653
            do_pause ( 1 ) ;
15654
        end
15655
        begin
15656
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15657
            if ( wb_ok !== 1 )
15658
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15659
 
15660 35 mihad
            #1 ;
15661
            if ( !error_monitor_done )
15662
                disable monitor_pci_error_2 ;
15663 15 mihad
        end
15664
        begin:monitor_pci_error_2
15665 35 mihad
            error_monitor_done = 0 ;
15666 15 mihad
            pci_ok = 1 ;
15667
            @(error_event_int) ;
15668
            pci_ok = 0 ;
15669
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15670 35 mihad
            error_monitor_done = 1 ;
15671 15 mihad
        end
15672
        join
15673
 
15674
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15675
        `ifdef HOST
15676
 
15677
            repeat ( 4 )
15678
                @( posedge wb_clock ) ;
15679
 
15680
            if ( enable_error_interrupt && enable_error_report )
15681
            begin
15682
                if ( INT_O !== 1 )
15683
                begin
15684
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15685
                end
15686
            end
15687
            else
15688
            begin
15689
                if ( INT_O !== 0 )
15690
                begin
15691
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15692
                end
15693
            end
15694
        `else
15695
            repeat ( 4 )
15696
                @( posedge pci_clock ) ;
15697
 
15698
            if ( enable_error_interrupt && enable_error_report )
15699
            begin
15700
                if ( INTA !== 0 )
15701
                begin
15702
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15703
                end
15704
            end
15705
            else
15706
            begin
15707
                if ( INTA !== 1 )
15708
                begin
15709
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15710
                end
15711
            end
15712
        `endif
15713
 
15714
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15715
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15716
        config_read( offset, 4'hF, read_data ) ;
15717
        ok = 1 ;
15718
        if ( enable_error_report )
15719
        begin
15720
            if ( read_data[8] !== 1 )
15721
            begin
15722
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15723
                ok = 0 ;
15724
            end
15725
 
15726
            if ( read_data[9] !== 0 )
15727
            begin
15728
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15729
                ok = 0 ;
15730
            end
15731
 
15732
            if ( read_data[31:28] !== byte_enables )
15733
            begin
15734
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15735
                ok = 0 ;
15736
            end
15737
 
15738
            if ( read_data[27:24] !== `BC_IO_WRITE )
15739
            begin
15740
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15741
                ok = 0 ;
15742
            end
15743
 
15744
            if ( ok )
15745
                test_ok ;
15746
 
15747
            test_name = "CLEAR ERROR STATUS" ;
15748
            config_write( offset, read_data, 4'hF, ok ) ;
15749
            if ( !ok )
15750
                test_fail("PCI Error Control and Status register could not be written") ;
15751
 
15752
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15753
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15754
            config_read ( offset, 4'hf, read_data ) ;
15755
 
15756
            if ( read_data !== expect_address )
15757
            begin
15758
                test_fail("value in Erroneous Address register was incorrect") ;
15759
                ok = 0 ;
15760
            end
15761
 
15762
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15763
            config_read ( offset, 4'hf, read_data ) ;
15764
 
15765
            if ( read_data !== 32'hAAAA_AAAA )
15766
            begin
15767
                test_fail("value in Erroneous Data register was incorrect") ;
15768
                ok = 0 ;
15769
            end
15770
 
15771
            if ( ok )
15772
                test_ok ;
15773
 
15774
        end
15775
        else
15776
        begin
15777
            if ( read_data[8] !== 0 )
15778
            begin
15779
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15780
                ok = 0 ;
15781
            end
15782
            else
15783
                test_ok ;
15784
        end
15785
 
15786
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15787
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15788
        ok = 1 ;
15789
 
15790
        config_read ( offset, 4'hF, read_data ) ;
15791
        if ( enable_error_report && enable_error_interrupt )
15792
        begin
15793
            if ( read_data[2] !== 1 )
15794
            begin
15795
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15796
                ok = 0 ;
15797
            end
15798
 
15799
            test_name = "CLEARING INTERRUPT STATUS" ;
15800
            config_write( offset, read_data, 4'hF, ok ) ;
15801
            if ( !ok )
15802
                test_fail("Interrupt Status register could not be written") ;
15803
        end
15804
        else
15805
        begin
15806
            if ( read_data[2] !== 0 )
15807
            begin
15808
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15809
                ok = 0 ;
15810
            end
15811
        end
15812
 
15813
        if ( ok )
15814
            test_ok ;
15815
 
15816
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15817
        `ifdef HOST
15818
 
15819
            repeat ( 4 )
15820
                @( posedge wb_clock ) ;
15821
 
15822
            if ( INT_O !== 0 )
15823
            begin
15824
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15825
            end
15826
            else
15827
                test_ok ;
15828
 
15829
        `else
15830
            repeat ( 4 )
15831
                @( posedge pci_clock ) ;
15832
 
15833
            if ( INTA !== 1 )
15834
            begin
15835
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15836
            end
15837
            else
15838
                test_ok ;
15839
 
15840
        `endif
15841
 
15842
        pci_address = pci_address + 1 ;
15843
        expect_address = expect_address + 1 ;
15844
    end
15845
 
15846
end
15847
endtask // test_target_io_err_wr
15848
 
15849
task test_pci_image ;
15850
    input [2:0]  image_num ;
15851
    reg   [11:0] pci_ctrl_offset ;
15852
    reg   [11:0] ctrl_offset ;
15853
    reg   [11:0] ba_offset ;
15854
    reg   [11:0] am_offset ;
15855
    reg   [11:0] ta_offset ;
15856
    reg   [7:0]  cache_lsize ;
15857
    reg          ok ;
15858
    reg          test_io ;
15859
    reg          test_mem ;
15860
begin
15861
    pci_ctrl_offset = 12'h4 ;
15862
    if (image_num === 0)
15863
    begin
15864
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15865
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15866
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15867
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15868
    end
15869
    else if (image_num === 1)
15870
    begin
15871
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15872
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15873
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15874
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15875
    end
15876
    else if (image_num === 2)
15877
    begin
15878
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15879
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15880
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15881
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15882
    end
15883
    else if (image_num === 3)
15884
    begin
15885
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15886
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15887
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15888
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15889
    end
15890
    else if (image_num === 4)
15891
    begin
15892
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15893
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15894
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15895
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15896
    end
15897
    else if (image_num === 5)
15898
    begin
15899
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15900
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15901
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15902
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15903
    end
15904
 
15905
    `ifdef HOST
15906
        test_io  = 1 ;
15907
        test_mem = 1 ;
15908
    `else
15909
        if (image_num == 1)
15910
            test_io = `PCI_BA1_MEM_IO ;
15911
        else if ( image_num == 2 )
15912
            test_io = `PCI_BA2_MEM_IO ;
15913
        else if ( image_num == 3 )
15914
            test_io = `PCI_BA3_MEM_IO ;
15915
        else if ( image_num == 4 )
15916
            test_io = `PCI_BA4_MEM_IO ;
15917
        else if ( image_num == 5 )
15918
            test_io = `PCI_BA5_MEM_IO ;
15919
 
15920
        test_mem = !test_io ;
15921
    `endif
15922
 
15923
    $display(" ");
15924
    $display("########################################################################") ;
15925
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15926
    test_name = "PCI IMAGE SETTINGS" ;
15927
 
15928
    // Set Base Address of IMAGE
15929
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15930
    if ( ok !== 1 )
15931
    begin
15932
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15933
        test_fail("PCI Base Address register could not be written") ;
15934
    end
15935
 
15936
    // Set Address Mask of IMAGE
15937
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15938
    if ( ok !== 1 )
15939
    begin
15940
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15941
        test_fail("PCI Address Mask register could not be written") ;
15942
    end
15943
 
15944
    // Set Translation Address of IMAGE
15945
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15946
    if ( ok !== 1 )
15947
    begin
15948
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15949
        test_fail("PCI Translation Address register could not be written") ;
15950
    end
15951
 
15952
// Following are defines for byte enable signals !
15953
//      Byte Masks
15954
//      `Test_Byte_0                            (4'b1110)
15955
//      `Test_Byte_1                            (4'b1101)
15956
//      `Test_Byte_2                            (4'b1011)
15957
//      `Test_Byte_3                            (4'b0111)
15958
//      `Test_Half_0                            (4'b1100)
15959
//      `Test_Half_1                            (4'b0011)
15960
//      `Test_All_Bytes                         (4'b0000)
15961
 
15962
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
15963
    // Set Cache Line Size
15964
    cache_lsize = 8'h4 ;
15965
 
15966
    $display(" ");
15967
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15968
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15969
    if ( ok !== 1 )
15970
    begin
15971
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15972
        test_fail("PCI Device Control and Status register could not be written") ;
15973
    end
15974
 
15975
    if (test_mem)
15976
    begin
15977
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
15978
        // Task test_normal_wr_rd has the following parameters:
15979
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15980
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15981
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15982
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
15983
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
15984
 
15985
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15986
        // Set Cache Line Size
15987
        cache_lsize = 8'h4 ;
15988
 
15989
        $display(" ");
15990
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15991
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15992
        if ( ok !== 1 )
15993
        begin
15994
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15995
            test_fail("Cache Line Size register could not be written" ) ;
15996
        end
15997
 
15998
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
15999
        // Task test_normal_wr_rd has the following parameters:
16000
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16001
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16002
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16003
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
16004
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
16005
 
16006
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16007
        // Set Cache Line Size
16008
        cache_lsize = 8'h8 ;
16009
 
16010
        $display(" ");
16011
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16012
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16013
        if ( ok !== 1 )
16014
        begin
16015
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16016
            test_fail("Cache Line Size register could not be written" ) ;
16017
        end
16018
 
16019
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
16020
        // Task test_normal_wr_rd has the following parameters:
16021
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16022
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16023
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16024
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
16025
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16026
 
16027
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16028
        // Set Cache Line Size
16029
        cache_lsize = 8'h4 ;
16030
 
16031
        $display(" ");
16032
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16033
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16034
        if ( ok !== 1 )
16035
        begin
16036
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16037
            test_fail("Cache Line Size register could not be written" ) ;
16038
        end
16039
 
16040
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
16041
        // Task test_normal_wr_rd has the following parameters:
16042
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16043
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16044
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16045
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
16046
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16047
 
16048
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16049
        $display(" ");
16050
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
16051
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16052
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16053
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
16054
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
16055
 
16056
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16057
        $display(" ");
16058
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
16059
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16060
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16061
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
16062
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
16063
 
16064
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16065
        $display(" ");
16066
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
16067
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16068
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16069
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
16070
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
16071
 
16072
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16073
        $display(" ");
16074
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
16075
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16076
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16077
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
16078
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
16079
    end
16080
 
16081
    if ( test_io )
16082
    begin
16083
        test_name = "PCI IMAGE SETTINGS" ;
16084
 
16085
        // Set Base Address of IMAGE
16086
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
16087
        if ( ok !== 1 )
16088
        begin
16089
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16090
            test_fail("PCI Base Address register could not be written") ;
16091
        end
16092
 
16093
        // Set Address Mask of IMAGE
16094
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16095
        if ( ok !== 1 )
16096
        begin
16097
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16098
            test_fail("PCI Address Mask register could not be written") ;
16099
        end
16100
 
16101
        // Set Translation Address of IMAGE
16102
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16103
        if ( ok !== 1 )
16104
        begin
16105
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16106
            test_fail("PCI Translation Address register could not be written") ;
16107
        end
16108
 
16109
        // Set Cache Line Size
16110
        cache_lsize = 8'h4 ;
16111
 
16112
        $display(" ");
16113
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16114
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16115
        if ( ok !== 1 )
16116
        begin
16117
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16118
            test_fail("Cache Line Size register could not be written" ) ;
16119
        end
16120
 
16121
        test_target_io_wr_rd
16122
        (
16123
            image_num,    // image number
16124
            0,            // test with address translation
16125
            ctrl_offset   // image control register offset
16126
        ) ;
16127
 
16128
        test_target_io_wr_rd
16129
        (
16130
            image_num,    // image number
16131
            1,            // test with address translation
16132
            ctrl_offset   // image control register offset
16133
        ) ;
16134
 
16135
        test_target_io_err_wr
16136
        (
16137
            image_num,      // image number
16138
            0,              // address translation on/off
16139
            ctrl_offset,    // image control register offset
16140
            0,              // enable error reporting
16141
 
16142
        ) ;
16143
 
16144
        test_target_io_err_wr
16145
        (
16146
            image_num,      // image number
16147
            1,              // address translation on/off
16148
            ctrl_offset,    // image control register offset
16149
            0,              // enable error reporting
16150
            1               // enable error interrupts
16151
        ) ;
16152
 
16153
        test_target_io_err_wr
16154
        (
16155
            image_num,      // image number
16156
            0,              // address translation on/off
16157
            ctrl_offset,    // image control register offset
16158
            1,              // enable error reporting
16159
 
16160
        ) ;
16161
 
16162
        test_target_io_err_wr
16163
        (
16164
            image_num,      // image number
16165
            1,              // address translation on/off
16166
            ctrl_offset,    // image control register offset
16167
            1,              // enable error reporting
16168
            1               // enable error interrupts
16169
        ) ;
16170
    end
16171
 
16172
    // Test master abort with NON supported commands
16173
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16174
 
16175
    // disable the image
16176 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16177 15 mihad
end
16178
endtask //test_pci_image
16179
 
16180
task target_fast_back_to_back ;
16181
    reg   [11:0] pci_ctrl_offset ;
16182
    reg   [11:0] ctrl_offset ;
16183
    reg   [11:0] ba_offset ;
16184
    reg   [11:0] am_offset ;
16185
    reg   [11:0] ta_offset ;
16186
    reg   [11:0] cls_offset ;
16187
    reg          do_mem_fb2b ;
16188
    reg          do_io_fb2b ;
16189
    reg          ok ;
16190
begin:main
16191
 
16192
    if ( target_mem_image !== -1 )
16193
    begin
16194
        do_mem_fb2b = 1 ;
16195
 
16196
        if (target_mem_image === 1)
16197
        begin
16198
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16199
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16200
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16201
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16202
        end
16203
        else if (target_mem_image === 2)
16204
        begin
16205
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16206
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16207
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16208
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16209
        end
16210
        else if (target_mem_image === 3)
16211
        begin
16212
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16213
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16214
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16215
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16216
        end
16217
        else if (target_mem_image === 4)
16218
        begin
16219
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16220
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16221
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16222
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16223
        end
16224
        else if (target_mem_image === 5)
16225
        begin
16226
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16227
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16228
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16229
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16230
        end
16231
    end
16232
    else
16233
        do_mem_fb2b = 0 ;
16234
 
16235
    pci_ctrl_offset = 12'h4 ;
16236
    cls_offset      = 12'h00C ;
16237
 
16238
    if ( do_mem_fb2b )
16239
    begin
16240
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16241
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16242
        if ( ok !== 1 )
16243
        begin
16244
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16245
            test_fail("PCI Base Address register could not be written") ;
16246
            disable main ;
16247
        end
16248
 
16249
        // Set Address Mask of IMAGE
16250
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16251
        if ( ok !== 1 )
16252
        begin
16253
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16254
            test_fail("PCI Address Mask register could not be written") ;
16255
            disable main ;
16256
        end
16257
 
16258
        // Set Translation Address of IMAGE
16259
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16260
        if ( ok !== 1 )
16261
        begin
16262
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16263
            test_fail("PCI Translation Address Register could not be written") ;
16264
            disable main ;
16265
        end
16266
 
16267
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16268
        if ( ok !== 1 )
16269
        begin
16270
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16271
            test_fail("PCI Image Control register could not be written") ;
16272
            disable main ;
16273
        end
16274
 
16275
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16276
        if ( ok !== 1 )
16277
        begin
16278
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16279
            test_fail("Cache Line Size register could not be written") ;
16280
            disable main ;
16281
        end
16282
 
16283
        // enable master 1 fast_b2b
16284 45 mihad
        configuration_cycle_write(0,                        // bus number
16285
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16286
                                  0,                        // function number
16287
                                  1,                        // register number
16288
                                  0,                        // type of configuration cycle
16289
                                  4'b1111,                  // byte enables
16290
                                  32'hFFFF_FFFF             // data
16291 15 mihad
                                 ) ;
16292
 
16293
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16294
 
16295
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16296
        fork
16297
        begin
16298
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16299
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16300
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16301
                  0, `Test_One_Zero_Target_WS,
16302
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16303
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16304
 
16305
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16306
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16307
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16308
                  0, `Test_One_Zero_Target_WS,
16309
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16310
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16311
            do_pause(5) ;
16312
 
16313
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16314
        end
16315
        begin:wb_monitor1
16316
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16317
            if ( ok !== 1 )
16318
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16319
 
16320
            disable monitor_error_event1 ;
16321
        end
16322
        begin:monitor_error_event1
16323
            @(error_event_int) ;
16324
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16325
            ok = 0 ;
16326
            disable wb_monitor1 ;
16327
        end
16328
        join
16329
 
16330
        if ( ok )
16331
            test_ok ;
16332
 
16333
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16334
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16335
        fork
16336
        begin
16337
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16338
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16339
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16340
                  0, `Test_One_Zero_Target_WS,
16341
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16342
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16343
 
16344
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16345
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16346
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16347
                  0, `Test_One_Zero_Target_WS,
16348
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16349
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16350
            do_pause(5) ;
16351
 
16352
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16353
 
16354
        end
16355
        begin:wb_monitor2
16356
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16357
            if ( ok !== 1 )
16358
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16359
            else
16360
            begin
16361
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16362
                if ( ok !== 1 )
16363
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16364
            end
16365
 
16366
            disable monitor_error_event2 ;
16367
        end
16368
        begin:monitor_error_event2
16369
            @(error_event_int) ;
16370
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16371
            ok = 0 ;
16372
            disable wb_monitor2 ;
16373
        end
16374
        join
16375
 
16376
        if ( ok )
16377
            test_ok ;
16378
 
16379
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16380
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16381
        fork
16382
        begin
16383
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16384
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16385
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16386
                  0, `Test_One_Zero_Target_WS,
16387
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16388
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16389
 
16390
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16391
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16392
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16393
                  0, `Test_One_Zero_Target_WS,
16394
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16395
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16396
            do_pause(5) ;
16397
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16398
 
16399
        end
16400
        begin:wb_monitor3
16401
            fork
16402
            begin
16403
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16404
                if ( ok !== 1 )
16405
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16406
            end
16407
            begin
16408
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16409
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16410
                if ( ok !== 1 )
16411
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16412
            end
16413
            join
16414
 
16415
            if ( ok )
16416
            begin
16417
                fork
16418
                begin
16419
                    do_pause(3) ;
16420
 
16421
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16422
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16423
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16424
                        0, `Test_One_Zero_Target_WS,
16425
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16426
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16427
 
16428
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16429
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16430
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16431
                            0, `Test_One_Zero_Target_WS,
16432
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16433
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16434
 
16435
                    do_pause(1) ;
16436
                end
16437
                begin
16438
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16439
                    if ( ok !== 1 )
16440
                    begin
16441
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16442
                        disable monitor_error_event3 ;
16443
                    end
16444
                    else
16445
                    begin
16446
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16447
                        if ( ok !== 1 )
16448
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16449
                    end
16450
                end
16451 26 mihad
                begin
16452
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16453
                        if ( ok !== 1 )
16454
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16455
                end
16456 15 mihad
                join
16457
            end
16458
            disable monitor_error_event3 ;
16459
        end
16460
        begin:monitor_error_event3
16461
            @(error_event_int) ;
16462
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16463
            ok = 0 ;
16464
            disable wb_monitor3 ;
16465
        end
16466
        join
16467
 
16468
        if ( ok )
16469
            test_ok ;
16470
 
16471
        test_name = "DISABLING MEM IMAGE" ;
16472 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16473 15 mihad
        if ( ok !== 1 )
16474
        begin
16475
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16476
            test_fail("PCI Address Mask register could not be written") ;
16477
            disable main ;
16478
        end
16479
    end
16480
 
16481
    if ( target_io_image !== -1 )
16482
    begin
16483
        do_io_fb2b = 1 ;
16484
 
16485
        if (target_io_image === 1)
16486
        begin
16487
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16488
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16489
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16490
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16491
        end
16492
        else if (target_io_image === 2)
16493
        begin
16494
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16495
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16496
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16497
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16498
        end
16499
        else if (target_io_image === 3)
16500
        begin
16501
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16502
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16503
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16504
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16505
        end
16506
        else if (target_io_image === 4)
16507
        begin
16508
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16509
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16510
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16511
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16512
        end
16513
        else if (target_io_image === 5)
16514
        begin
16515
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16516
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16517
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16518
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16519
        end
16520
    end
16521
    else
16522
        do_io_fb2b = 0 ;
16523
 
16524
    if ( do_io_fb2b )
16525
    begin
16526
 
16527
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16528
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16529
        if ( ok !== 1 )
16530
        begin
16531
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16532
            test_fail("PCI Base Address register could not be written") ;
16533
            disable main ;
16534
        end
16535
 
16536
        // Set Address Mask of IMAGE
16537
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16538
        if ( ok !== 1 )
16539
        begin
16540
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16541
            test_fail("PCI Address Mask register could not be written") ;
16542
            disable main ;
16543
        end
16544
 
16545
        // Set Translation Address of IMAGE
16546
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16547
        if ( ok !== 1 )
16548
        begin
16549
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16550
            test_fail("PCI Translation Address Register could not be written") ;
16551
            disable main ;
16552
        end
16553
 
16554
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16555
        if ( ok !== 1 )
16556
        begin
16557
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16558
            test_fail("PCI Image Control register could not be written") ;
16559
            disable main ;
16560
        end
16561
 
16562
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16563
        if ( ok !== 1 )
16564
        begin
16565
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16566
            test_fail("Cache Line Size register could not be written") ;
16567
            disable main ;
16568
        end
16569
 
16570
        // enable master 1 fast_b2b
16571 45 mihad
        configuration_cycle_write(0,                        // bus number
16572
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16573
                                  0,                        // function number
16574
                                  1,                        // register number
16575
                                  0,                        // type of configuration cycle
16576
                                  4'b1111,                  // byte enables
16577
                                  32'hFFFF_FFFF             // data
16578 15 mihad
                                 ) ;
16579
 
16580
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16581
 
16582
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16583
        fork
16584
        begin
16585
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16586
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16587
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16588
                  0, `Test_One_Zero_Target_WS,
16589
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16590
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16591
 
16592
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16593
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16594
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16595
                  0, `Test_One_Zero_Target_WS,
16596
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16597
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16598
            do_pause(5) ;
16599
 
16600
        end
16601
        begin:wb_monitor4
16602
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16603
            if ( ok !== 1 )
16604
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16605
 
16606
            if ( ok )
16607
            begin
16608
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16609
                if ( ok !== 1 )
16610
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16611
            end
16612
 
16613
            disable monitor_error_event4 ;
16614
        end
16615
        begin:monitor_error_event4
16616
            @(error_event_int) ;
16617
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16618
            ok = 0 ;
16619
            disable wb_monitor4 ;
16620
        end
16621
        join
16622
 
16623
        if ( ok )
16624
            test_ok ;
16625
 
16626
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16627
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16628
        fork
16629
        begin
16630
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16631
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16632
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16633
                  0, `Test_One_Zero_Target_WS,
16634
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16635
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16636
 
16637
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16638
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16639
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16640
                  0, `Test_One_Zero_Target_WS,
16641
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16642
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16643
            do_pause(5) ;
16644
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16645
        end
16646
        begin:wb_monitor5
16647
            fork
16648
            begin
16649
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16650
                if ( ok !== 1 )
16651
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16652
            end
16653
            begin
16654
                wb_transaction_stop( 1 ) ;
16655
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16656
                if ( ok !== 1 )
16657
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16658
            end
16659
            join
16660
 
16661
            if ( ok )
16662
            begin
16663
                fork
16664
                begin
16665
                    do_pause(3) ;
16666
 
16667
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16668
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16669
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16670
                            0, `Test_One_Zero_Target_WS,
16671
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16672
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16673
 
16674
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16675
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16676
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16677
                            0, `Test_One_Zero_Target_WS,
16678
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16679
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16680
 
16681
                    do_pause(1) ;
16682
                end
16683
                begin
16684
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16685
                    if ( ok !== 1 )
16686
                    begin
16687
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16688
                        disable monitor_error_event5 ;
16689
                    end
16690
                    else
16691
                    begin
16692
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16693
                        if ( ok !== 1 )
16694
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16695
                    end
16696
                end
16697
                join
16698
            end
16699
            disable monitor_error_event5 ;
16700
        end
16701
        begin:monitor_error_event5
16702
            @(error_event_int) ;
16703
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16704
            ok = 0 ;
16705
            disable wb_monitor5 ;
16706
        end
16707
        join
16708
 
16709
        if ( ok )
16710
            test_ok ;
16711
 
16712
        test_name = "DISABLING IO IMAGE" ;
16713 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16714 15 mihad
        if ( ok !== 1 )
16715
        begin
16716
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16717
            test_fail("PCI Address Mask register could not be written") ;
16718
            disable main ;
16719
        end
16720
    end
16721
 
16722
end
16723
endtask //target_fast_back_to_back
16724
 
16725
task target_disconnects ;
16726
    reg   [11:0] pci_ctrl_offset ;
16727
    reg   [11:0] ctrl_offset ;
16728
    reg   [11:0] ba_offset ;
16729
    reg   [11:0] am_offset ;
16730
    reg   [11:0] ta_offset ;
16731
    reg   [11:0] cls_offset ;
16732
    reg          pci_ok ;
16733
    reg          wb_ok ;
16734
    reg          ok ;
16735
    reg   [31:0] pci_address ;
16736
    reg   [31:0] data ;
16737
    reg   [3:0]  byte_enables ;
16738
    reg   [9:0]  expect_length ;
16739
 
16740
    reg          do_mem_disconnects ;
16741
    reg          do_io_disconnects ;
16742 35 mihad
    reg          error_monitor_done ;
16743 15 mihad
begin:main
16744
    if ( target_mem_image !== -1 )
16745
    begin
16746
        do_mem_disconnects = 1 ;
16747
 
16748
        if (target_mem_image === 1)
16749
        begin
16750
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16751
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16752
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16753
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16754
        end
16755
        else if (target_mem_image === 2)
16756
        begin
16757
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16758
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16759
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16760
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16761
        end
16762
        else if (target_mem_image === 3)
16763
        begin
16764
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16765
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16766
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16767
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16768
        end
16769
        else if (target_mem_image === 4)
16770
        begin
16771
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16772
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16773
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16774
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16775
        end
16776
        else if (target_mem_image === 5)
16777
        begin
16778
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16779
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16780
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16781
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16782
        end
16783
    end
16784
    else
16785
        do_mem_disconnects = 0 ;
16786
 
16787
    pci_ctrl_offset = 12'h4 ;
16788
    cls_offset = 12'h00C ;
16789
 
16790
    master1_check_received_data = 0 ;
16791
    master2_check_received_data = 0 ;
16792
 
16793
    `ifdef HOST
16794
        `ifdef NO_CNF_IMAGE
16795
        `else
16796
            `define TEST_BURST_CONFIG_READ
16797
        `endif
16798
    `else
16799
        `define TEST_BURST_CONFIG_READ
16800
        `define TEST_BURST_CONFIG_WRITE
16801
    `endif
16802
 
16803
    `ifdef TEST_BURST_CONFIG_WRITE
16804
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16805
 
16806
        data = 32'h0000_08_08 ;
16807
 
16808 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16809 15 mihad
        byte_enables = 4'b0000 ;
16810
 
16811
        fork
16812
        begin
16813
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16814
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16815
                    byte_enables,
16816
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16817
                    8'h0_0, `Test_One_Zero_Target_WS,
16818
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16819
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16820
 
16821
            data = 32'h0000_04_04 ;
16822
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16823
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16824
                    byte_enables,
16825
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16826
                    8'h0_0, `Test_One_Zero_Target_WS,
16827
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16828
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16829
            do_pause( 1 ) ;
16830
            while ( FRAME !== 1 || IRDY !== 1 )
16831
                @(posedge pci_clock) ;
16832
 
16833 35 mihad
            #1 ;
16834
            if ( !error_monitor_done )
16835
                disable monitor_error_event1 ;
16836 15 mihad
        end
16837
        begin:monitor_error_event1
16838 35 mihad
            error_monitor_done = 0 ;
16839 15 mihad
            ok = 1 ;
16840
            @(error_event_int) ;
16841
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16842
            ok = 0 ;
16843 35 mihad
            error_monitor_done = 1 ;
16844 15 mihad
        end
16845
        join
16846
 
16847
        config_read(pci_address, 4'hF, data) ;
16848
        if ( data [15:0] !== 16'h04_04 )
16849
        begin
16850
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16851
        end
16852
        else if ( ok )
16853
            test_ok ;
16854
 
16855 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16856
 
16857
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16858 15 mihad
        data         = 32'h0000_0808 ;
16859
        byte_enables = 4'h0 ;
16860
        fork
16861
        begin
16862
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16863
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16864
                    byte_enables,
16865
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16866
                    8'h0_0, `Test_One_Zero_Target_WS,
16867
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16868
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16869
 
16870
            data = 32'h0000_04_04 ;
16871
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16872
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16873
                    byte_enables,
16874
                    3, `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_Before, `Test_Expect_No_Master_Abort);
16878
 
16879
            do_pause( 1 ) ;
16880
            while ( FRAME !== 1 || IRDY !== 1 )
16881
                @(posedge pci_clock) ;
16882
 
16883 35 mihad
            #1 ;
16884
            if ( !error_monitor_done )
16885
                disable monitor_error_event2 ;
16886 15 mihad
        end
16887
        begin:monitor_error_event2
16888 35 mihad
            error_monitor_done = 0 ;
16889 15 mihad
            ok = 1 ;
16890
            @(error_event_int) ;
16891
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16892
            ok = 0 ;
16893 35 mihad
            error_monitor_done = 1 ;
16894 15 mihad
        end
16895
        join
16896
 
16897
        config_read(pci_address, 4'hF, data) ;
16898
        if ( data [15:0] !== 16'h04_04 )
16899
        begin
16900
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16901
        end
16902
        else if ( ok )
16903
            test_ok ;
16904
    `endif
16905
 
16906
    `ifdef TEST_BURST_CONFIG_READ
16907
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16908
 
16909
        data = 32'h0000_04_04 ;
16910
 
16911 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16912 15 mihad
        byte_enables = 4'b0000 ;
16913
 
16914
        fork
16915
        begin
16916
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16917
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16918
                    byte_enables,
16919
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16920
                    8'h0_0, `Test_One_Zero_Target_WS,
16921
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16922
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16923
            do_pause( 1 ) ;
16924
 
16925
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16926
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16927
                    byte_enables,
16928
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16929
                    8'h0_0, `Test_One_Zero_Target_WS,
16930
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16931
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16932
            do_pause( 1 ) ;
16933
 
16934
            while ( FRAME !== 1 || IRDY !== 1 )
16935
                @(posedge pci_clock) ;
16936
 
16937 35 mihad
            if ( !error_monitor_done )
16938
                disable monitor_error_event3 ;
16939 15 mihad
        end
16940
        begin:monitor_error_event3
16941 35 mihad
            error_monitor_done = 0 ;
16942 15 mihad
            ok = 1 ;
16943
            @(error_event_int) ;
16944
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16945
            ok = 0 ;
16946 35 mihad
            error_monitor_done = 1 ;
16947 15 mihad
        end
16948
        join
16949
 
16950
        if ( ok )
16951
            test_ok ;
16952
 
16953 45 mihad
 
16954
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
16955
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16956 15 mihad
        fork
16957
        begin
16958
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16959
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16960
                    byte_enables,
16961
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16962
                    8'h0_0, `Test_One_Zero_Target_WS,
16963
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16964
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16965
            do_pause( 1 ) ;
16966
 
16967
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16968
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16969
                    byte_enables,
16970
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16971
                    8'h0_0, `Test_One_Zero_Target_WS,
16972
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16973
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16974
            do_pause( 1 ) ;
16975
 
16976
            while ( FRAME !== 1 || IRDY !== 1 )
16977
                @(posedge pci_clock) ;
16978
 
16979 35 mihad
            #1 ;
16980
            if ( !error_monitor_done )
16981
                disable monitor_error_event4 ;
16982 15 mihad
        end
16983
        begin:monitor_error_event4
16984 35 mihad
            error_monitor_done = 0 ;
16985 15 mihad
            ok = 1 ;
16986
            @(error_event_int) ;
16987
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16988
            ok = 0 ;
16989 35 mihad
            error_monitor_done = 1 ;
16990 15 mihad
        end
16991
        join
16992
 
16993
        if ( ok )
16994
            test_ok ;
16995
    `endif
16996
 
16997
    `ifdef TEST_BURST_CONFIG_READ
16998
        `undef TEST_BURST_CONFIG_READ
16999
    `endif
17000
 
17001
    `ifdef TEST_BURST_CONFIG_WRITE
17002
        `undef TEST_BURST_CONFIG_WRITE
17003
    `endif
17004
 
17005
    master1_check_received_data = 1 ;
17006
    master2_check_received_data = 1 ;
17007
 
17008
    if ( do_mem_disconnects )
17009
    begin
17010
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17011
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
17012
        if ( ok !== 1 )
17013
        begin
17014
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17015
            test_fail("PCI Base Address register could not be written") ;
17016
            disable main ;
17017
        end
17018
 
17019
        // Set Address Mask of IMAGE
17020
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
17021
        if ( ok !== 1 )
17022
        begin
17023
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17024
            test_fail("PCI Address Mask register could not be written") ;
17025
            disable main ;
17026
        end
17027
 
17028
        // Set Translation Address of IMAGE
17029
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
17030
        if ( ok !== 1 )
17031
        begin
17032
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17033
            test_fail("PCI Translation Address Register could not be written") ;
17034
            disable main ;
17035
        end
17036
 
17037
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17038
        if ( ok !== 1 )
17039
        begin
17040
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17041
            test_fail("PCI Image Control register could not be written") ;
17042
            disable main ;
17043
        end
17044
 
17045
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17046
        if ( ok !== 1 )
17047
        begin
17048
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17049
            test_fail("Cache Line Size register could not be written") ;
17050
            disable main ;
17051
        end
17052
 
17053
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17054
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17055
        data = 32'hAAAA_AAAA ;
17056
        byte_enables = 4'h0 ;
17057
        expect_length = `PCIW_DEPTH - 2 ;
17058
 
17059
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17060
        fork
17061
        begin
17062
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17063
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17064
                        byte_enables,
17065
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
17066
                        8'h0_0, `Test_One_Zero_Target_WS,
17067
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17068
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17069
            do_pause( 3 ) ;
17070
 
17071
            while ( FRAME !== 1 || IRDY !== 1 )
17072
                @(posedge pci_clock) ;
17073
 
17074 35 mihad
            #1 ;
17075
            if ( !error_monitor_done )
17076
                disable monitor_error_event5 ;
17077 15 mihad
        end
17078
        begin:monitor_error_event5
17079 35 mihad
            error_monitor_done = 0 ;
17080 15 mihad
            pci_ok = 1 ;
17081
            @(error_event_int) ;
17082
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17083
            pci_ok = 0 ;
17084 35 mihad
            error_monitor_done = 1 ;
17085 15 mihad
        end
17086
        begin
17087
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17088
            if ( wb_ok !== 1 )
17089
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17090
        end
17091
        join
17092
 
17093
        if ( wb_ok && pci_ok )
17094
            test_ok ;
17095
 
17096
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17097
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17098
        data = 32'hAAAA_AAAA ;
17099
        byte_enables = 4'h0 ;
17100
        expect_length = `PCIW_DEPTH - 2 ;
17101
 
17102
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17103
        fork
17104
        begin
17105
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17106
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17107
                        byte_enables,
17108
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
17109
                        8'h0_0, `Test_One_Zero_Target_WS,
17110
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17111
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17112
            do_pause( 3 ) ;
17113
 
17114
            while ( FRAME !== 1 || IRDY !== 1 )
17115
                @(posedge pci_clock) ;
17116
 
17117 35 mihad
            #1 ;
17118
            if ( !error_monitor_done )
17119
                disable monitor_error_event6 ;
17120 15 mihad
        end
17121
        begin:monitor_error_event6
17122 35 mihad
            error_monitor_done = 0 ;
17123 15 mihad
            pci_ok = 1 ;
17124
            @(error_event_int) ;
17125
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17126
            pci_ok = 0 ;
17127 35 mihad
            error_monitor_done = 1 ;
17128 15 mihad
        end
17129
        begin
17130
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17131
            if ( wb_ok !== 1 )
17132
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17133
        end
17134
        join
17135
 
17136
        if ( wb_ok && pci_ok )
17137
            test_ok ;
17138
 
17139
        master1_check_received_data = 1 ;
17140
//        master2_check_received_data = 0 ;
17141
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17142
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17143
        data = 32'hAAAA_AAAA ;
17144
        byte_enables = 4'h0 ;
17145
        expect_length = 4 ;
17146
 
17147
        fork
17148
        begin
17149
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17150
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17151
                        byte_enables,
17152
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17153
                        8'h0_0, `Test_One_Zero_Target_WS,
17154
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17155
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17156
            do_pause( 1 ) ;
17157
 
17158
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17159
            if ( wb_ok !== 1 )
17160
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17161
 
17162
            do_pause(2) ;
17163
 
17164
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17165
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17166
                        byte_enables,
17167
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17168
                        8'h0_0, `Test_One_Zero_Target_WS,
17169
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17170
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17171
            do_pause( 3 ) ;
17172
 
17173
            while ( FRAME !== 1 || IRDY !== 1 )
17174
                @(posedge pci_clock) ;
17175
 
17176 35 mihad
            #1 ;
17177
            if ( !error_monitor_done )
17178
                disable monitor_error_event7 ;
17179 15 mihad
        end
17180
        begin:monitor_error_event7
17181 35 mihad
            error_monitor_done = 0 ;
17182 15 mihad
            pci_ok = 1 ;
17183
            @(error_event_int) ;
17184
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17185
            pci_ok = 0 ;
17186 35 mihad
            error_monitor_done = 1 ;
17187 15 mihad
        end
17188
        join
17189
 
17190
        if ( wb_ok && pci_ok )
17191
            test_ok ;
17192
 
17193
        master1_check_received_data = 1 ;
17194
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17195
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17196
        data = 32'hAAAA_AAAA ;
17197
        byte_enables = 4'h0 ;
17198
        expect_length = 4 ;
17199
 
17200
        fork
17201
        begin
17202
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17203
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17204
                        byte_enables,
17205
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17206
                        8'h0_0, `Test_One_Zero_Target_WS,
17207
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17208
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17209
            do_pause( 1 ) ;
17210
 
17211
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17212
            if ( wb_ok !== 1 )
17213
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17214
 
17215
            do_pause(2) ;
17216
 
17217
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17218
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17219
                        byte_enables,
17220
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17221
                        8'h0_0, `Test_One_Zero_Target_WS,
17222
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17223
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17224
            do_pause( 3 ) ;
17225
 
17226
            while ( FRAME !== 1 || IRDY !== 1 )
17227
                @(posedge pci_clock) ;
17228
 
17229 35 mihad
            #1 ;
17230
            if ( !error_monitor_done )
17231
                disable monitor_error_event8 ;
17232 15 mihad
        end
17233
        begin:monitor_error_event8
17234 35 mihad
            error_monitor_done = 0 ;
17235 15 mihad
            pci_ok = 1 ;
17236
            @(error_event_int) ;
17237
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17238
            pci_ok = 0 ;
17239 35 mihad
            error_monitor_done = 1 ;
17240 15 mihad
        end
17241
        join
17242
 
17243
        if ( wb_ok && pci_ok )
17244
            test_ok ;
17245
 
17246
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17247
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17248
        data = 32'hDEAF_BEAF ;
17249
        byte_enables = 4'h0 ;
17250
        expect_length = 1 ;
17251
 
17252
        fork
17253
        begin
17254
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17255
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17256
                        byte_enables,
17257
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17258
                        8'h0_0, `Test_One_Zero_Target_WS,
17259
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17260
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17261
            do_pause( 3 ) ;
17262
 
17263
            while ( FRAME !== 1 || IRDY !== 1 )
17264
                @(posedge pci_clock) ;
17265
 
17266 35 mihad
            #1 ;
17267
            if ( !error_monitor_done )
17268
                disable monitor_error_event9 ;
17269 15 mihad
        end
17270
        begin:monitor_error_event9
17271 35 mihad
            error_monitor_done = 0 ;
17272 15 mihad
            pci_ok = 1 ;
17273
            @(error_event_int) ;
17274
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17275
            pci_ok = 0 ;
17276 35 mihad
            error_monitor_done = 1 ;
17277 15 mihad
        end
17278
        begin
17279
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17280
            if ( wb_ok !== 1 )
17281
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17282
        end
17283
        join
17284
 
17285
        if ( wb_ok && pci_ok )
17286
            test_ok ;
17287
 
17288
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17289
        data = 32'hDEAD_BEAF ;
17290
        byte_enables = 4'h0 ;
17291
        expect_length = 1 ;
17292
 
17293
        fork
17294
        begin
17295
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17296
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17297
                        byte_enables,
17298
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17299
                        8'h0_0, `Test_One_Zero_Target_WS,
17300
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17301
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17302
            do_pause( 3 ) ;
17303
 
17304
            while ( FRAME !== 1 || IRDY !== 1 )
17305
                @(posedge pci_clock) ;
17306
 
17307 35 mihad
            #1 ;
17308
            if ( !error_monitor_done )
17309
                disable monitor_error_event10 ;
17310 15 mihad
        end
17311
        begin:monitor_error_event10
17312 35 mihad
            error_monitor_done = 0 ;
17313 15 mihad
            pci_ok = 1 ;
17314
            @(error_event_int) ;
17315
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17316
            pci_ok = 0 ;
17317 35 mihad
            error_monitor_done = 1 ;
17318 15 mihad
        end
17319
        begin
17320
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17321
            if ( wb_ok !== 1 )
17322
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17323
        end
17324
        join
17325
 
17326
        if ( wb_ok && pci_ok )
17327
            test_ok ;
17328
 
17329
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17330
        data = 32'hAAAA_AAAA ;
17331
        byte_enables = 4'h0 ;
17332
        expect_length = 1 ;
17333
 
17334
        fork
17335
        begin
17336
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17337
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17338
                        byte_enables,
17339
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17340
                        8'h0_0, `Test_One_Zero_Target_WS,
17341
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17342
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17343
            do_pause( 3 ) ;
17344
 
17345
            while ( FRAME !== 1 || IRDY !== 1 )
17346
                @(posedge pci_clock) ;
17347
 
17348 35 mihad
            #1 ;
17349
            if ( !error_monitor_done )
17350
                disable monitor_error_event11 ;
17351 15 mihad
        end
17352
        begin:monitor_error_event11
17353 35 mihad
            error_monitor_done = 0 ;
17354 15 mihad
            pci_ok = 1 ;
17355
            @(error_event_int) ;
17356
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17357
            pci_ok = 0 ;
17358 35 mihad
            error_monitor_done = 1 ;
17359 15 mihad
        end
17360
        begin
17361
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17362
            if ( wb_ok !== 1 )
17363
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17364
        end
17365
        join
17366
 
17367
        if ( wb_ok && pci_ok )
17368
            test_ok ;
17369
 
17370
        master1_check_received_data = 1 ;
17371
 
17372
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17373
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17374
        data = 32'hDEAF_BEAF ;
17375
        byte_enables = 4'h0 ;
17376
        expect_length = 1 ;
17377
 
17378
        fork
17379
        begin
17380
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17381
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17382
                        byte_enables,
17383
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17384
                        8'h0_0, `Test_One_Zero_Target_WS,
17385
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17386
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17387
            do_pause( 1 ) ;
17388
 
17389
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17390
            if ( wb_ok !== 1 )
17391
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17392
 
17393
            do_pause(3) ;
17394
 
17395
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17396
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17397
                        byte_enables,
17398
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17399
                        8'h0_0, `Test_One_Zero_Target_WS,
17400
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17401
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17402
            do_pause( 3 ) ;
17403
 
17404
            while ( FRAME !== 1 || IRDY !== 1 )
17405
                @(posedge pci_clock) ;
17406
 
17407 35 mihad
            #1 ;
17408
            if ( !error_monitor_done )
17409
                disable monitor_error_event12 ;
17410 15 mihad
        end
17411
        begin:monitor_error_event12
17412 35 mihad
            error_monitor_done = 0 ;
17413 15 mihad
            pci_ok = 1 ;
17414
            @(error_event_int) ;
17415
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17416
            pci_ok = 0 ;
17417 35 mihad
            error_monitor_done = 1 ;
17418 15 mihad
        end
17419
        join
17420
 
17421
        if ( wb_ok && pci_ok )
17422
            test_ok ;
17423
 
17424
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17425
        data = 32'hDEAD_BEAF ;
17426
        byte_enables = 4'h0 ;
17427
        expect_length = 1 ;
17428
 
17429
        fork
17430
        begin
17431
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17432
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17433
                        byte_enables,
17434
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17435
                        8'h0_0, `Test_One_Zero_Target_WS,
17436
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17437
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17438
            do_pause( 1 ) ;
17439
 
17440
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17441
            if ( wb_ok !== 1 )
17442
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17443
 
17444
            do_pause(3) ;
17445
 
17446
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17447
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17448
                        byte_enables,
17449
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17450
                        8'h0_0, `Test_One_Zero_Target_WS,
17451
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17452
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17453
            do_pause( 3 ) ;
17454
 
17455
            while ( FRAME !== 1 || IRDY !== 1 )
17456
                @(posedge pci_clock) ;
17457
 
17458 35 mihad
            #1 ;
17459
            if ( !error_monitor_done )
17460
                disable monitor_error_event13 ;
17461 15 mihad
        end
17462
        begin:monitor_error_event13
17463 35 mihad
            error_monitor_done = 0 ;
17464 15 mihad
            pci_ok = 1 ;
17465
            @(error_event_int) ;
17466
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17467
            pci_ok = 0 ;
17468 35 mihad
            error_monitor_done = 1 ;
17469 15 mihad
        end
17470
        join
17471
 
17472
        if ( wb_ok && pci_ok )
17473
            test_ok ;
17474
 
17475
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17476
        data = 32'hAAAA_AAAA ;
17477
        byte_enables = 4'h0 ;
17478
        expect_length = 1 ;
17479
 
17480
        fork
17481
        begin
17482
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17483
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17484
                        byte_enables,
17485
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17486
                        8'h0_0, `Test_One_Zero_Target_WS,
17487
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17488
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17489
            do_pause( 1 ) ;
17490
 
17491
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17492
            if ( wb_ok !== 1 )
17493
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17494
 
17495
            do_pause(3) ;
17496
 
17497
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17498
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17499
                        byte_enables,
17500
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17501
                        8'h0_0, `Test_One_Zero_Target_WS,
17502
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17503
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17504
            do_pause( 3 ) ;
17505
 
17506
            while ( FRAME !== 1 || IRDY !== 1 )
17507
                @(posedge pci_clock) ;
17508
 
17509 35 mihad
            #1 ;
17510
            if ( !error_monitor_done )
17511
                disable monitor_error_event14 ;
17512 15 mihad
        end
17513
        begin:monitor_error_event14
17514 35 mihad
            error_monitor_done = 0 ;
17515 15 mihad
            pci_ok = 1 ;
17516
            @(error_event_int) ;
17517
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17518
            pci_ok = 0 ;
17519 35 mihad
            error_monitor_done = 1 ;
17520 15 mihad
        end
17521
        join
17522
 
17523
        if ( wb_ok && pci_ok )
17524
            test_ok ;
17525
 
17526
        // disable the image
17527
        test_name = "DISABLING MEMORY IMAGE" ;
17528 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17529 15 mihad
        if ( ok !== 1 )
17530
        begin
17531
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17532
            test_fail("PCI Address Mask register could not be written") ;
17533
            disable main ;
17534
        end
17535
    end
17536
//*
17537
    if ( target_io_image !== -1 )
17538
    begin
17539
        do_io_disconnects = 1 ;
17540
 
17541
        if (target_io_image === 1)
17542
        begin
17543
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17544
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17545
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17546
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17547
        end
17548
        else if (target_io_image === 2)
17549
        begin
17550
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17551
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17552
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17553
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17554
        end
17555
        else if (target_io_image === 3)
17556
        begin
17557
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17558
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17559
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17560
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17561
        end
17562
        else if (target_io_image === 4)
17563
        begin
17564
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17565
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17566
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17567
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17568
        end
17569
        else if (target_io_image === 5)
17570
        begin
17571
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17572
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17573
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17574
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17575
        end
17576
    end
17577
    else
17578
        do_io_disconnects = 0 ;
17579
 
17580
    if ( do_io_disconnects )
17581
    begin
17582
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17583
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17584
        if ( ok !== 1 )
17585
        begin
17586
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17587
            test_fail("PCI Base Address register could not be written") ;
17588
            disable main ;
17589
        end
17590
 
17591
        // Set Address Mask of IMAGE
17592
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17593
        if ( ok !== 1 )
17594
        begin
17595
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17596
            test_fail("PCI Address Mask register could not be written") ;
17597
            disable main ;
17598
        end
17599
 
17600
        // Set Translation Address of IMAGE
17601
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17602
        if ( ok !== 1 )
17603
        begin
17604
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17605
            test_fail("PCI Translation Address Register could not be written") ;
17606
            disable main ;
17607
        end
17608
 
17609
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17610
        if ( ok !== 1 )
17611
        begin
17612
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17613
            test_fail("PCI Image Control register could not be written") ;
17614
            disable main ;
17615
        end
17616
 
17617
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17618
        if ( ok !== 1 )
17619
        begin
17620
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17621
            test_fail("Cache Line Size register could not be written") ;
17622
            disable main ;
17623
        end
17624
 
17625
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17626
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17627
        data = 32'h5555_5555 ;
17628
        byte_enables = 4'h0 ;
17629
        expect_length = 1 ;
17630
 
17631
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17632
 
17633
        fork
17634
        begin
17635
            PCIU_IO_WRITE
17636
            (
17637
                `Test_Master_1,             // which master
17638
                pci_address,                // to what address
17639
                data,                       // data
17640
                byte_enables,               // byte enable
17641
                expect_length + 1,          // length to request
17642
                `Test_Target_Retry_On       // expected target termination
17643
            ) ;
17644
 
17645
            do_pause( 3 ) ;
17646
 
17647
            while ( FRAME !== 1 || IRDY !== 1 )
17648
                @(posedge pci_clock) ;
17649
 
17650 35 mihad
            #1 ;
17651
            if ( !error_monitor_done )
17652
                disable monitor_error_event15 ;
17653 15 mihad
        end
17654
        begin:monitor_error_event15
17655 35 mihad
            error_monitor_done = 0 ;
17656 15 mihad
            pci_ok = 1 ;
17657
            @(error_event_int) ;
17658
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17659
            pci_ok = 0 ;
17660 35 mihad
            error_monitor_done = 1 ;
17661 15 mihad
        end
17662
        begin
17663
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17664
            if ( wb_ok !== 1 )
17665
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17666
        end
17667
        join
17668
 
17669
        if ( wb_ok && pci_ok )
17670
            test_ok ;
17671
 
17672
        data = 32'hAAAA_AAAA ;
17673
        fork
17674
        begin
17675
            PCIU_IO_WRITE
17676
            (
17677
                `Test_Master_1,             // which master
17678
                pci_address,                // to what address
17679
                data,                       // data
17680
                byte_enables,               // byte enable
17681
                expect_length + 2,          // length to request
17682
                `Test_Target_Retry_Before   // expected target termination
17683
            ) ;
17684
 
17685
            do_pause( 3 ) ;
17686
 
17687
            while ( FRAME !== 1 || IRDY !== 1 )
17688
                @(posedge pci_clock) ;
17689
 
17690 35 mihad
            #1 ;
17691
            if ( !error_monitor_done )
17692
                disable monitor_error_event16 ;
17693 15 mihad
        end
17694
        begin:monitor_error_event16
17695 35 mihad
            error_monitor_done = 0 ;
17696 15 mihad
            pci_ok = 1 ;
17697
            @(error_event_int) ;
17698
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17699
            pci_ok = 0 ;
17700 35 mihad
            error_monitor_done = 1 ;
17701 15 mihad
        end
17702
        begin
17703
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17704
            if ( wb_ok !== 1 )
17705
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17706
        end
17707
        join
17708
 
17709
        if ( wb_ok && pci_ok )
17710
            test_ok ;
17711
 
17712
        master2_check_received_data = 1 ;
17713
 
17714
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17715
 
17716
        fork
17717
        begin
17718
 
17719
             PCIU_IO_READ
17720
             (
17721
                `Test_Master_2,
17722
                pci_address[PCI_BUS_DATA_RANGE:0],
17723
                data,
17724
                byte_enables,
17725
                2,
17726
                `Test_Target_Retry_Before
17727
             );
17728
 
17729
            do_pause( 1 ) ;
17730
 
17731
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17732
            if ( wb_ok !== 1 )
17733
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17734
 
17735
            do_pause(3) ;
17736
 
17737
            PCIU_IO_READ
17738
             (
17739
                `Test_Master_2,
17740
                pci_address[PCI_BUS_DATA_RANGE:0],
17741
                data,
17742
                byte_enables,
17743
                expect_length + 1,
17744
                `Test_Target_Retry_On
17745
             );
17746
 
17747
            do_pause( 3 ) ;
17748
 
17749
            while ( FRAME !== 1 || IRDY !== 1 )
17750
                @(posedge pci_clock) ;
17751
 
17752 35 mihad
            #1 ;
17753
            if ( !error_monitor_done )
17754
                disable monitor_error_event17 ;
17755 15 mihad
        end
17756
        begin:monitor_error_event17
17757 35 mihad
            error_monitor_done = 0 ;
17758 15 mihad
            pci_ok = 1 ;
17759
            @(error_event_int) ;
17760
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17761
            pci_ok = 0 ;
17762 35 mihad
            error_monitor_done = 1 ;
17763 15 mihad
        end
17764
        join
17765
 
17766
        if ( wb_ok && pci_ok )
17767
            test_ok ;
17768
 
17769
        fork
17770
        begin
17771
 
17772
             PCIU_IO_READ
17773
             (
17774
                `Test_Master_2,
17775
                pci_address[PCI_BUS_DATA_RANGE:0],
17776
                data,
17777
                byte_enables,
17778
                2,
17779
                `Test_Target_Retry_Before
17780
             );
17781
 
17782
            do_pause( 1 ) ;
17783
 
17784
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17785
            if ( wb_ok !== 1 )
17786
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17787
 
17788
            do_pause(3) ;
17789
 
17790
            PCIU_IO_READ
17791
             (
17792
                `Test_Master_2,
17793
                pci_address[PCI_BUS_DATA_RANGE:0],
17794
                data,
17795
                byte_enables,
17796
                expect_length + 2,
17797
                `Test_Target_Retry_Before
17798
             );
17799
 
17800
            do_pause( 3 ) ;
17801
 
17802
            while ( FRAME !== 1 || IRDY !== 1 )
17803
                @(posedge pci_clock) ;
17804
 
17805 35 mihad
            #1 ;
17806
            if ( !error_monitor_done )
17807
                disable monitor_error_event18 ;
17808 15 mihad
        end
17809
        begin:monitor_error_event18
17810 35 mihad
            error_monitor_done = 0 ;
17811 15 mihad
            pci_ok = 1 ;
17812
            @(error_event_int) ;
17813
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17814
            pci_ok = 0 ;
17815 35 mihad
            error_monitor_done = 1 ;
17816 15 mihad
        end
17817
        join
17818
 
17819
        if ( wb_ok && pci_ok )
17820
            test_ok ;
17821
 
17822
        test_name = "DISABLING IO IMAGE" ;
17823 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17824 15 mihad
        if ( ok !== 1 )
17825
        begin
17826
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17827
            test_fail("PCI Address Mask register could not be written") ;
17828
            disable main ;
17829
        end
17830
    end
17831
//*/
17832
end
17833
endtask // target_disconnects
17834
 
17835
task target_unsupported_cmds ;
17836
        input [31:0] Address;
17837
        input [2:0]  image_num ;
17838
    reg          ok ;
17839
begin:main
17840
 
17841
    $display("  ") ;
17842
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17843
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17844 45 mihad
 
17845
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17846
    configuration_cycle_write
17847
    (
17848
        0,                        // bus number
17849
        `TAR1_IDSEL_INDEX - 11,   // device number
17850
        0,                        // function number
17851
        1,                        // register number
17852
        0,                        // type of configuration cycle
17853
        4'b0001,                  // byte enables
17854
        32'h0000_0044             // data
17855
    ) ;
17856
 
17857
    configuration_cycle_write
17858
    (
17859
        0,                        // bus number
17860
        `TAR2_IDSEL_INDEX - 11,   // device number
17861
        0,                        // function number
17862
        1,                        // register number
17863
        0,                        // type of configuration cycle
17864
        4'b0001,                  // byte enables
17865
        32'h0000_0044             // data
17866
    ) ;
17867
 
17868 15 mihad
    ipci_unsupported_commands_master.master_reference
17869
    (
17870
        Address,                // first part of address in dual address cycle
17871
        Address,                // second part of address in dual address cycle
17872
        `BC_IACK,                       // dual address cycle command
17873
        `BC_IACK,               // normal command
17874
        4'h0,               // byte enables
17875
        32'h1234_5678,      // data
17876
        1'b0,               // make address parity error on first phase of dual address
17877
        1'b0,               // make address parity error on second phase of dual address
17878
        ok                  // result of operation
17879
    ) ;
17880
    if ( ok )
17881
        test_ok ;
17882
    else
17883
    begin
17884
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17885
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17886
    end
17887
 
17888
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17889
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17890
    ipci_unsupported_commands_master.master_reference
17891
    (
17892
        Address,                // first part of address in dual address cycle
17893
        Address,                // second part of address in dual address cycle
17894
        `BC_SPECIAL,            // dual address cycle command
17895
        `BC_SPECIAL,            // normal command
17896
        4'h0,               // byte enables
17897
        32'h1234_5678,      // data
17898
        1'b0,               // make address parity error on first phase of dual address
17899
        1'b0,               // make address parity error on second phase of dual address
17900
        ok                  // result of operation
17901
    ) ;
17902
    if ( ok )
17903
        test_ok ;
17904
    else
17905
    begin
17906
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17907
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17908
    end
17909
 
17910
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17911
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17912
    ipci_unsupported_commands_master.master_reference
17913
    (
17914
        Address,                // first part of address in dual address cycle
17915
        Address,                // second part of address in dual address cycle
17916
        `BC_RESERVED0,          // dual address cycle command
17917
        `BC_RESERVED0,      // normal command
17918
        4'h0,               // byte enables
17919
        32'h1234_5678,      // data
17920
        1'b0,               // make address parity error on first phase of dual address
17921
        1'b0,               // make address parity error on second phase of dual address
17922
        ok                  // result of operation
17923
    ) ;
17924
    if ( ok )
17925
        test_ok ;
17926
    else
17927
    begin
17928
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17929
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17930
    end
17931
 
17932
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17933
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17934
    ipci_unsupported_commands_master.master_reference
17935
    (
17936
        Address,                // first part of address in dual address cycle
17937
        Address,                // second part of address in dual address cycle
17938
        `BC_RESERVED1,          // dual address cycle command
17939
        `BC_RESERVED1,      // normal command
17940
        4'h0,               // byte enables
17941
        32'h1234_5678,      // data
17942
        1'b0,               // make address parity error on first phase of dual address
17943
        1'b0,               // make address parity error on second phase of dual address
17944
        ok                  // result of operation
17945
    ) ;
17946
    if ( ok )
17947
        test_ok ;
17948
    else
17949
    begin
17950
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17951
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
17952
    end
17953
 
17954
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
17955
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
17956
    ipci_unsupported_commands_master.master_reference
17957
    (
17958
        Address,                // first part of address in dual address cycle
17959
        Address,                // second part of address in dual address cycle
17960
        `BC_RESERVED2,          // dual address cycle command
17961
        `BC_RESERVED2,      // normal command
17962
        4'h0,               // byte enables
17963
        32'h1234_5678,      // data
17964
        1'b0,               // make address parity error on first phase of dual address
17965
        1'b0,               // make address parity error on second phase of dual address
17966
        ok                  // result of operation
17967
    ) ;
17968
    if ( ok )
17969
        test_ok ;
17970
    else
17971
    begin
17972
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17973
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
17974
    end
17975
 
17976
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
17977
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
17978
    ipci_unsupported_commands_master.master_reference
17979
    (
17980
        Address,                // first part of address in dual address cycle
17981
        Address,                // second part of address in dual address cycle
17982
        `BC_RESERVED3,          // dual address cycle command
17983
        `BC_RESERVED3,      // normal command
17984
        4'h0,               // byte enables
17985
        32'h1234_5678,      // data
17986
        1'b0,               // make address parity error on first phase of dual address
17987
        1'b0,               // make address parity error on second phase of dual address
17988
        ok                  // result of operation
17989
    ) ;
17990
    if ( ok )
17991
        test_ok ;
17992
    else
17993
    begin
17994
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17995
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
17996
    end
17997
 
17998
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
17999
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
18000
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
18001
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
18002
    ipci_unsupported_commands_master.master_reference
18003
    (
18004
        Address,                // first part of address in dual address cycle
18005
        Address,                // second part of address in dual address cycle
18006
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
18007
        `BC_MEM_WRITE,      // normal command
18008
        4'h0,               // byte enables;
18009
        32'h1234_5678,      // data
18010
        1'b0,               // make address parity error on first phase of dual address
18011
        1'b0,               // make address parity error on second phase of dual address
18012
        ok                  // result of operation
18013
    ) ;
18014
    if ( ok )
18015
        test_ok ;
18016
    else
18017
    begin
18018
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18019
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
18020
    end
18021
 
18022 45 mihad
    // enable pci blue behavioral targets 1 and 2
18023
    configuration_cycle_write
18024
    (
18025
        0,                        // bus number
18026
        `TAR1_IDSEL_INDEX - 11,   // device number
18027
        0,                        // function number
18028
        1,                        // register number
18029
        0,                        // type of configuration cycle
18030
        4'b0001,                  // byte enables
18031
        32'h0000_0047             // data
18032
    ) ;
18033
 
18034
    configuration_cycle_write
18035
    (
18036
        0,                        // bus number
18037
        `TAR2_IDSEL_INDEX - 11,   // device number
18038
        0,                        // function number
18039
        1,                        // register number
18040
        0,                        // type of configuration cycle
18041
        4'b0001,                  // byte enables
18042
        32'h0000_0047             // data
18043
    ) ;
18044 15 mihad
end
18045
endtask // target_unsupported_cmds
18046
 
18047 63 mihad
`ifdef DISABLE_COMPLETION_EXPIRED_TESTS
18048
`else
18049 15 mihad
task target_completion_expiration ;
18050
    reg   [11:0] pci_ctrl_offset ;
18051
    reg   [11:0] pci_ba_offset ;
18052
    reg   [11:0] pci_am_offset ;
18053
    reg   [11:0] pci_device_ctrl_offset ;
18054
    reg   [11:0] pci_err_cs_offset ;
18055
    reg   [11:0] icr_offset ;
18056
    reg   [11:0] isr_offset ;
18057
    reg   [11:0] lat_tim_cls_offset ;
18058
 
18059
    reg [31:0] temp_val1 ;
18060
    reg [31:0] temp_val2 ;
18061
    reg        ok   ;
18062 33 mihad
    reg        ok_wb ;
18063
    reg        ok_pci ;
18064 15 mihad
 
18065
    reg [31:0] pci_image_base ;
18066
    integer i ;
18067 33 mihad
    integer clocks_after_completion ;
18068
    reg     error_monitor_done ;
18069
    reg     test_mem ;
18070 15 mihad
 
18071
begin:main
18072
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18073
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
18074
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
18075
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
18076
 
18077
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
18078
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
18079
    lat_tim_cls_offset = 12'hC ;
18080
    pci_device_ctrl_offset    = 12'h4 ;
18081
 
18082 33 mihad
    `ifdef HOST
18083
        test_mem = 1'b1 ;
18084
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
18085
    `else
18086
        test_mem = !`PCI_BA1_MEM_IO ;
18087
        pci_image_base = Target_Base_Addr_R[1] ;
18088
    `endif
18089 15 mihad
 
18090
    // enable master & target operation
18091
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
18092
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
18093
    if ( ok !== 1 )
18094
    begin
18095
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18096
        test_fail("write to PCI Device Control register failed") ;
18097
        disable main ;
18098
    end
18099
 
18100
    // prepare image control register
18101 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18102 15 mihad
    if ( ok !== 1 )
18103
    begin
18104
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18105
        test_fail("write to PCI Image Control register failed") ;
18106
        disable main ;
18107
    end
18108
 
18109
    // prepare base address register
18110
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18111
    if ( ok !== 1 )
18112
    begin
18113
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18114
        test_fail("write to PCI Base Address register failed") ;
18115
        disable main ;
18116
    end
18117
 
18118
    // write address mask register
18119
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18120
    if ( ok !== 1 )
18121
    begin
18122
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18123
        test_fail("write to PCI Address Mask register failed") ;
18124
        disable main ;
18125
    end
18126
 
18127
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18128
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18129
    if ( ok !== 1 )
18130
    begin
18131
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18132
        test_fail("write to PCI Error Control and Status register failed") ;
18133
        disable main ;
18134
    end
18135
 
18136 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18137 15 mihad
    if ( ok !== 1 )
18138
    begin
18139
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18140
        test_fail("write to Interrupt Control register failed") ;
18141
        disable main ;
18142
    end
18143
 
18144
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18145
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18146
    if ( ok !== 1 )
18147
    begin
18148
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18149
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18150
        disable main ;
18151
    end
18152
 
18153
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18154
 
18155
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18156 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18157
    master1_check_received_data = 0 ;
18158 15 mihad
 
18159 33 mihad
    ok_pci = 1 ;
18160
    // start a delayed read request
18161
    fork
18162
    begin
18163
        if ( test_mem )
18164
 
18165
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18166
                          pci_image_base, 32'h1234_5678,
18167
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18168
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18169
        else
18170
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18171
 
18172
        do_pause( 1 ) ;
18173
    end
18174
    begin:error_monitor1
18175 35 mihad
        error_monitor_done = 0 ;
18176 33 mihad
        @(error_event_int) ;
18177
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18178
        ok_pci = 0 ;
18179 35 mihad
        error_monitor_done = 1 ;
18180 33 mihad
    end
18181
    begin
18182
        if ( test_mem )
18183
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18184
        else
18185
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18186 15 mihad
 
18187 33 mihad
        if ( ok_wb !== 1 )
18188
        begin
18189
            test_fail("Bridge failed to process Target Memory read correctly") ;
18190
            disable main ;
18191
        end
18192
 
18193 35 mihad
        #1 ;
18194
        if ( !error_monitor_done )
18195 33 mihad
            disable error_monitor1 ;
18196
    end
18197
    join
18198
 
18199
    clocks_after_completion = 0 ;
18200
    // now do another - different transaction
18201
    fork
18202
    begin
18203
        if ( test_mem )
18204
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18205
                          pci_image_base + 4, 32'h1234_5678,
18206
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18207
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18208
        else
18209
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18210
 
18211
        while ( clocks_after_completion < 32'h0000_FFF0 )
18212
        begin
18213
            @(posedge pci_clock) ;
18214
            clocks_after_completion = clocks_after_completion + 1 ;
18215
        end
18216
 
18217
        do_pause('hFF) ;
18218
 
18219
        if ( test_mem )
18220
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18221
                          pci_image_base + 4, 32'h1234_5678,
18222
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18223
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18224
        else
18225
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18226
 
18227
        do_pause( 1 ) ;
18228
    end
18229
    begin:error_monitor2
18230 35 mihad
        error_monitor_done = 0 ;
18231 33 mihad
        @(error_event_int) ;
18232
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18233
        ok_pci = 0 ;
18234 35 mihad
        error_monitor_done = 1 ;
18235 33 mihad
    end
18236
    begin
18237
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18238
        repeat( 'hFF )
18239
            @(posedge pci_clock) ;
18240
 
18241
        if ( test_mem )
18242
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18243
        else
18244
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18245
 
18246
        if ( ok_wb !== 1 )
18247
        begin
18248
            test_fail("Bridge failed to process Target Memory read correctly") ;
18249
            disable main ;
18250
        end
18251
 
18252
        repeat(4)
18253
            @(posedge pci_clock) ;
18254
 
18255
        fork
18256
        begin
18257
            if ( test_mem )
18258
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18259
                              pci_image_base + 4, 32'h1234_5678,
18260
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18261
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18262
            else
18263
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18264
 
18265
            do_pause(1) ;
18266
        end
18267
        begin
18268
           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 ) ;
18269 35 mihad
           #1 ;
18270
           if ( !error_monitor_done )
18271 33 mihad
               disable error_monitor2 ;
18272
        end
18273
        join
18274
    end
18275
    join
18276
 
18277
    if ( ok && ok_pci && ok_wb )
18278
        test_ok ;
18279
 
18280
    if ( ok !== 1 )
18281
    begin
18282
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18283
        test_fail("write to PCI Address Mask register failed") ;
18284
        disable main ;
18285
    end
18286
 
18287
    // check statuses after this situation - none should be set
18288
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18289
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18290
    if ( ok !== 1 )
18291
    begin
18292
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18293
        test_fail("read from pci device status register failed") ;
18294
        disable main ;
18295
    end
18296
 
18297
    if ( temp_val1[31] )
18298
    begin
18299
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18300
        test_fail("detected parity error bit was set for no reason") ;
18301
    end
18302
 
18303
    if ( temp_val1[30] )
18304
    begin
18305
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18306
        test_fail("signaled system error bit was set for no reason") ;
18307
    end
18308
 
18309
    if ( temp_val1[29] )
18310
    begin
18311
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18312
        test_fail("received master abort bit was set for no reason") ;
18313
    end
18314
 
18315
    if ( temp_val1[28] )
18316
    begin
18317
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18318
        test_fail("received target abort bit was set for no reason") ;
18319
    end
18320
 
18321
    if ( temp_val1[27] )
18322
    begin
18323
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18324
        test_fail("signaled target abort bit was set for no reason") ;
18325
    end
18326
 
18327
    if ( temp_val1[24] )
18328
    begin
18329
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18330
        test_fail("Master Data parity error bit was set for no reason") ;
18331
    end
18332
 
18333
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18334
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18335
    if ( temp_val1[8] !== 0 )
18336
    begin
18337
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18338
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18339
    end
18340
    // test target retry counter expiration
18341
    // set wb slave to retry response
18342
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18343
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18344
    ok_pci = 1 ;
18345
 
18346
    fork
18347
    begin
18348
        if ( test_mem == 1 )
18349
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18350
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18351
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18352
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18353
        else
18354
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18355
 
18356
        do_pause(1) ;
18357
 
18358
        // do another write with same address and different data
18359
        if ( test_mem == 1 )
18360
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18361
                        pci_image_base, 32'h8765_4321, 4'h0,
18362
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18363
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18364
        else
18365
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18366
 
18367
        do_pause(1) ;
18368
    end
18369
    begin
18370
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18371
        begin
18372
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18373
            if ( ok_wb !== 1 )
18374
            begin
18375
                $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) ;
18376
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18377
                disable main ;
18378
            end
18379
        end
18380
 
18381
        // set WB slave to normal completion
18382
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18383
 
18384
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18385
        if ( ok_wb !== 1 )
18386
        begin
18387
            $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) ;
18388
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18389
            disable main ;
18390
        end
18391
 
18392 35 mihad
        #1 ;
18393
        if ( !error_monitor_done )
18394 33 mihad
            disable error_monitor3 ;
18395
    end
18396
    begin:error_monitor3
18397 35 mihad
        error_monitor_done = 0 ;
18398 33 mihad
        @(error_event_int) ;
18399
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18400
        ok_pci = 0 ;
18401 35 mihad
        error_monitor_done = 1 ;
18402 33 mihad
    end
18403
    join
18404
 
18405
    if ( ok_wb && ok_pci )
18406
    begin
18407
        test_ok ;
18408
    end
18409
 
18410
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18411
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18412
    if ( temp_val1[8] !== 1'b1 )
18413
    begin
18414
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18415
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18416
    end
18417
 
18418
    if ( temp_val1[9] !== 1 )
18419
    begin
18420
        $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) ;
18421
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18422
    end
18423
 
18424
    if ( temp_val1[10] !== 1 )
18425
    begin
18426
        $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) ;
18427
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18428
    end
18429
 
18430
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18431
    begin
18432
        $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) ;
18433
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18434
    end
18435
 
18436
    if ( temp_val1[31:28] !== 4'hA )
18437
    begin
18438
        $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) ;
18439
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18440
    end
18441
 
18442
    // clear error status register
18443
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18444
 
18445
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18446
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18447
    if ( temp_val1 !== pci_image_base )
18448
    begin
18449
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18450
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18451
    end
18452
 
18453
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18454
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18455
    if ( temp_val1 !== 32'hDEAD_BEAF )
18456
    begin
18457
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18458
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18459
    end
18460
 
18461
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18462
    ok_pci = 1 ;
18463
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18464
 
18465
    i = 0 ;
18466
    fork
18467
    begin
18468
        if ( test_mem )
18469
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18470
                          pci_image_base + 4, 32'h1234_5678,
18471
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18472
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18473
        else
18474
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18475
 
18476
        do_pause( 1 ) ;
18477
 
18478
    end
18479
    begin
18480
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18481
        begin
18482
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18483
            if ( ok_wb !== 1 )
18484
            begin
18485
                $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) ;
18486
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18487
                disable main ;
18488
            end
18489
        end
18490
 
18491
        // set WB slave to normal completion
18492
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18493
 
18494
        fork
18495
        begin
18496
            repeat(4)
18497
                @(posedge pci_clock) ;
18498
 
18499
            if ( test_mem )
18500
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18501
                              pci_image_base, 32'h8765_4321,
18502
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18503
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18504
            else
18505
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18506
 
18507
            do_pause(1) ;
18508
        end
18509
        begin
18510
 
18511
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18512
            if ( ok_wb !== 1 )
18513
            begin
18514
                $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) ;
18515
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18516
                disable main ;
18517
            end
18518
        end
18519
        join
18520
 
18521
        repeat( 4 )
18522
            @(posedge pci_clock) ;
18523
 
18524
        if ( test_mem )
18525
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18526
                          pci_image_base, 32'h8765_4321,
18527
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18528
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18529
        else
18530
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18531
 
18532
        do_pause(1) ;
18533
 
18534 35 mihad
        #1 ;
18535
        if ( !error_monitor_done )
18536 33 mihad
            disable error_monitor4 ;
18537
    end
18538
    begin:error_monitor4
18539 35 mihad
        error_monitor_done = 0 ;
18540 33 mihad
        @(error_event_int) ;
18541
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18542
        ok_pci = 0 ;
18543 35 mihad
        error_monitor_done = 1 ;
18544 33 mihad
    end
18545
    join
18546
 
18547
    if ( ok_wb && ok_pci )
18548
        test_ok ;
18549
 
18550
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18551
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18552
    if ( temp_val1[8] !== 1'b0 )
18553
    begin
18554
        $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) ;
18555
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18556
    end
18557
 
18558
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18559 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18560
    $fdisplay(pciu_mon_log_file_desc,
18561
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18562 33 mihad
    ok_pci = 1 ;
18563
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18564
 
18565
    fork
18566
    begin
18567
        if ( test_mem )
18568
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18569
                          pci_image_base + 4, 32'h1234_5678,
18570
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18571
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18572
        else
18573
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18574
 
18575
        do_pause( 1 ) ;
18576
 
18577
    end
18578
    begin
18579
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18580
        if ( ok_wb !== 1 )
18581
        begin
18582
            $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) ;
18583
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18584
            disable main ;
18585
        end
18586
 
18587
        repeat(4)
18588
            @(posedge pci_clock) ;
18589
 
18590
        fork
18591
        begin
18592
 
18593
            if ( test_mem )
18594
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18595
                              pci_image_base + 4, 32'h8765_4321,
18596
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18597
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18598
            else
18599
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18600
 
18601
            do_pause(1) ;
18602
 
18603
        end
18604
        begin
18605
 
18606
            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 ) ;
18607
            if ( ok !== 1 )
18608
            begin
18609
                $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) ;
18610
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18611
                disable main ;
18612
            end
18613
        end
18614
        join
18615
 
18616 35 mihad
        #1 ;
18617
        if ( !error_monitor_done )
18618 33 mihad
            disable error_monitor5 ;
18619
    end
18620
    begin:error_monitor5
18621 35 mihad
        error_monitor_done = 0 ;
18622 33 mihad
        @(error_event_int) ;
18623
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18624
        ok_pci = 0 ;
18625 35 mihad
        error_monitor_done = 1 ;
18626 33 mihad
    end
18627
    join
18628
 
18629
    if ( ok_wb && ok_pci )
18630
        test_ok ;
18631
 
18632
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18633
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18634
    if ( temp_val1[8] !== 1'b0 )
18635
    begin
18636
        $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) ;
18637
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18638
    end
18639
 
18640
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18641
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18642
    if ( temp_val1[25] !== 1'b1 )
18643
    begin
18644
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18645
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18646
    end
18647
 
18648
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18649
 
18650
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18651
    ok_pci = 1 ;
18652
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18653
 
18654
    fork
18655
    begin
18656
        if ( test_mem == 1 )
18657
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18658
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18659
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18660
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18661
        else
18662
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18663
 
18664
        do_pause(1) ;
18665
 
18666
        // do another write with same address and different data
18667
        if ( test_mem == 1 )
18668
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18669
                        pci_image_base, 32'h8765_6789, 4'h0,
18670
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18671
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18672
        else
18673
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18674
 
18675
        do_pause(1) ;
18676
    end
18677
    begin
18678
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18679
        if ( ok_wb !== 1 )
18680
        begin
18681
            $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) ;
18682
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18683
            disable main ;
18684
        end
18685
 
18686
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18687
 
18688
        if ( test_mem )
18689
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18690
        else
18691
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18692
 
18693
        if ( ok_wb !== 1 )
18694
        begin
18695
            $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) ;
18696
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18697
            disable main ;
18698
        end
18699
 
18700 35 mihad
        #1 ;
18701
        if ( !error_monitor_done )
18702 33 mihad
            disable error_monitor6 ;
18703
    end
18704
    begin:error_monitor6
18705 35 mihad
        error_monitor_done = 0 ;
18706 33 mihad
        @(error_event_int) ;
18707
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18708
        ok_pci = 0 ;
18709 35 mihad
        error_monitor_done = 1 ;
18710 33 mihad
    end
18711
    join
18712
 
18713
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18714
    $fdisplay(pciu_mon_log_file_desc,
18715
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18716
 
18717
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18718
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18719
    if ( temp_val1[8] !== 1'b1 )
18720
    begin
18721
        $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) ;
18722
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18723
    end
18724
 
18725
    if ( temp_val1[9] !== 0 )
18726
    begin
18727
        $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) ;
18728
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18729
    end
18730
 
18731
    if ( temp_val1[10] !== 1 )
18732
    begin
18733
        $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) ;
18734
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18735
    end
18736
 
18737
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18738
    begin
18739
        $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) ;
18740
        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") ;
18741
    end
18742
 
18743
    if ( temp_val1[31:28] !== 4'h0 )
18744
    begin
18745
        $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) ;
18746
        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") ;
18747
    end
18748
 
18749
    // clear error status register
18750
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18751
 
18752
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18753
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18754
    if ( temp_val1 !== pci_image_base )
18755
    begin
18756
        $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) ;
18757
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18758
    end
18759
 
18760
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18761
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18762
    if ( temp_val1 !== 32'hBEAF_DEAD )
18763
    begin
18764
        $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) ;
18765
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18766
    end
18767
 
18768
    // disable current image - write address mask register
18769 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18770 15 mihad
end
18771 57 mihad
endtask // target_completion_expiration
18772 15 mihad
 
18773 57 mihad
task master_completion_expiration ;
18774
    reg   [11:0] ctrl_offset ;
18775
    reg   [11:0] ba_offset ;
18776
    reg   [11:0] am_offset ;
18777
    reg `WRITE_STIM_TYPE write_data ;
18778
    reg `READ_STIM_TYPE  read_data ;
18779
    reg `READ_RETURN_TYPE read_status ;
18780
 
18781
    reg `WRITE_RETURN_TYPE write_status ;
18782
    reg `WB_TRANSFER_FLAGS write_flags ;
18783
    reg        ok   ;
18784
    reg [11:0] pci_ctrl_offset ;
18785
    reg [31:0] image_base ;
18786
    reg [31:0] target_address ;
18787
begin:main
18788
    pci_ctrl_offset = 12'h4 ;
18789
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
18790
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
18791
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
18792
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
18793
 
18794
    target_address  = `BEH_TAR1_MEM_START ;
18795
    image_base      = 0 ;
18796
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
18797
 
18798
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
18799
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
18800
    write_flags                      = 0 ;
18801
    write_flags`INIT_WAITS           = tb_init_waits ;
18802
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
18803
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18804
 
18805
    // enable master & target operation
18806
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
18807
    if ( ok !== 1 )
18808
    begin
18809
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18810
        test_fail("write to PCI Device Control register didn't succeede");
18811
        disable main ;
18812
    end
18813
 
18814
    // prepare image control register
18815
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
18816
    if ( ok !== 1 )
18817
    begin
18818
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
18819
        test_fail("write to WB Image Control register didn't succeede");
18820
        disable main ;
18821
    end
18822
 
18823
    // prepare base address register
18824
    config_write( ba_offset, image_base, 4'hF, ok ) ;
18825
    if ( ok !== 1 )
18826
    begin
18827
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
18828
        test_fail("write to WB Base Address register didn't succeede");
18829
        disable main ;
18830
    end
18831
 
18832
    // write address mask register
18833
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18834
    if ( ok !== 1 )
18835
    begin
18836
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18837
        test_fail("write to WB Address Mask register didn't succeede");
18838
        disable main ;
18839
    end
18840
 
18841
    fork
18842
    begin
18843
        // do not handle retries
18844
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
18845
 
18846
        // initiate a read request
18847
        read_data`READ_ADDRESS  = target_address ;
18848
        read_data`READ_SEL      = 4'hF ;
18849
        read_data`READ_TAG_STIM = 0 ;
18850
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18851
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
18852
        begin
18853
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18854
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
18855
            disable main ;
18856
        end
18857
 
18858
        // handle retries from now on
18859
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
18860
 
18861
        write_data`WRITE_ADDRESS = target_address + 4 ;
18862
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
18863
        write_data`WRITE_SEL     = 4'hF ;
18864
 
18865
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18866
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18867
        begin
18868
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
18869
            test_fail("WB Slave state machine failed to post single memory write");
18870
            disable main ;
18871
        end
18872
 
18873
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 100
18874
        repeat('h1_0000 - 100)
18875
            @(posedge wb_clock) ;
18876
 
18877
        // now perform a read
18878
        read_data`READ_ADDRESS  = target_address + 4 ;
18879
        read_data`READ_SEL      = 4'hF ;
18880
        read_data`READ_TAG_STIM = 0 ;
18881
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18882
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18883
        begin
18884
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18885
            test_fail("PCI bridge didn't process the read as expected");
18886
            disable main ;
18887
        end
18888
 
18889
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
18890
        begin
18891
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
18892
            test_fail("PCI bridge returned unexpected Read Data");
18893
        end
18894
        else if (ok === 1'b1)
18895
            test_ok ;
18896
    end
18897
    begin:monitors
18898
        // monitor first read, which will expire
18899
        pci_transaction_progress_monitor
18900
        (
18901
            target_address, // expected address
18902
            `BC_MEM_READ,   // expected bus command
18903
            1,              // expected number of transfers
18904
            0,              // expected number of cycles
18905
            1,              // check number of transfers true/false
18906
            0,              // check number of cycles true/false
18907
            0,              // is this fast B2B true/false
18908
            ok              // return 1 if as expected, anything else on error
18909
        ) ;
18910
 
18911
        if ( ok !== 1 )
18912
        begin
18913
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18914
            #1 disable monitors ;
18915
        end
18916
 
18917
        // monitor normal single write
18918
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
18919
        if ( ok !== 1 )
18920
        begin
18921
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18922
            #1 disable monitors ;
18923
        end
18924
 
18925
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
18926
        repeat('h1_0000 - 50)
18927
            @(posedge wb_clock) ;
18928
 
18929
        // monitor normal single memory read
18930
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
18931
        if ( ok !== 1 )
18932
        begin
18933
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
18934
        end
18935
    end
18936
    join
18937
 
18938
    // disable the image
18939
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
18940
    if ( ok !== 1 )
18941
    begin
18942
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18943
        test_fail("write to WB Address Mask register didn't succeede");
18944
    end
18945
end
18946
endtask // master_completion_expiration
18947 63 mihad
`endif
18948 57 mihad
 
18949 15 mihad
task config_write ;
18950
    input [11:0] offset ;
18951
    input [31:0] data ;
18952
    input [3:0]  byte_enable ;
18953
    output       ok ;
18954
    `ifdef HOST
18955
    reg   `WRITE_STIM_TYPE   write_data ;
18956
    reg   `WB_TRANSFER_FLAGS write_flags ;
18957
    reg   `WRITE_RETURN_TYPE write_status ;
18958
    `else
18959
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
18960
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
18961
    `endif
18962
    reg in_use ;
18963
    reg [31:0] temp_var ;
18964
begin
18965
    if ( in_use === 1 )
18966
    begin
18967
        $display("config_read task re-entered! Time %t ", $time) ;
18968
        ok = 0 ;
18969
        #20 $stop ;
18970
    end
18971
    else
18972
    begin
18973
        ok = 1 ;
18974
        in_use = 1 ;
18975
    end
18976
    `ifdef HOST
18977
    write_flags                    = 0 ;
18978
    write_flags`INIT_WAITS         = tb_init_waits ;
18979
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18980
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18981
 
18982
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18983
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18984
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
18985
    write_data`WRITE_SEL                         = byte_enable ;
18986
    write_data`WRITE_TAG_STIM                    = 0 ;
18987
    write_data`WRITE_DATA                        = data ;
18988
 
18989
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18990
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18991
    begin
18992
        $display("Write to configuration space failed! Time %t ", $time) ;
18993
        ok = 0 ;
18994
    end
18995
 
18996
    @(posedge wb_clock) ;
18997
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
18998
    // here we just wait for two guest cycles for conf space bits to synchronize
18999
    repeat( 2 )
19000
        @(posedge pci_clock) ;
19001
 
19002
    `else // GUEST
19003
    byte_enables_l = ~byte_enable ;
19004
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19005
 
19006
    fork
19007
    begin
19008
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19009
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
19010
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
19011
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19012
              8'h0_0, `Test_One_Zero_Target_WS,
19013
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
19014
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19015
    do_pause( 1 ) ;
19016
    end
19017
    begin
19018
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
19019
        @(posedge pci_clock) ;
19020
    end
19021
    join
19022
 
19023
     repeat( 2 )
19024
         @(posedge wb_clock) ;
19025
 
19026
    `endif
19027
    in_use = 0 ;
19028
end
19029
endtask // config_write
19030
 
19031
task config_read ;
19032
    input [11:0] offset ;
19033
    input [3:0]  byte_enable ;
19034
    output [31:0] data ;
19035
 
19036
    reg `READ_STIM_TYPE    read_data ;
19037
    reg `WB_TRANSFER_FLAGS read_flags ;
19038
    reg `READ_RETURN_TYPE  read_status ;
19039
 
19040
    reg [31:0] pci_address ;
19041
    reg [3:0] byte_enables_l ;
19042
 
19043
    reg master_check_data_prev ;
19044
    reg in_use ;
19045
    reg [31:0] temp_var ;
19046
begin:main
19047
    if ( in_use === 1 )
19048
    begin
19049
        $display("config_read task re-entered! Time %t ", $time) ;
19050
        data = 32'hxxxx_xxxx ;
19051
        disable main ;
19052
    end
19053
 
19054
    in_use = 1 ;
19055
 
19056
`ifdef HOST
19057 26 mihad
    repeat(4)
19058
        @(posedge pci_clock) ;
19059
    repeat(4)
19060
        @(posedge wb_clock) ;
19061 15 mihad
    read_flags                    = 0 ;
19062
    read_flags`INIT_WAITS         = tb_init_waits ;
19063
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19064
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19065
 
19066
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19067
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19068
 
19069
    read_data`READ_ADDRESS  = temp_var + offset ;
19070
    read_data`READ_SEL      = byte_enable ;
19071
    read_data`READ_TAG_STIM = 0 ;
19072
 
19073
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
19074
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19075
    begin
19076
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
19077
        #20 $stop ;
19078
    end
19079
    data = read_status`READ_DATA ;
19080
`else
19081
  `ifdef GUEST
19082 26 mihad
    repeat(4)
19083
        @(posedge wb_clock) ;
19084
    repeat(4)
19085
        @(posedge pci_clock) ;
19086 15 mihad
    master_check_data_prev = master2_check_received_data ;
19087
    master2_check_received_data = 0 ;
19088
 
19089
    byte_enables_l = ~byte_enable ;
19090
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19091
 
19092
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19093
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
19094
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19095
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19096
             8'h4_0, `Test_One_Zero_Target_WS,
19097
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19098
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19099
    do_pause( 1 ) ;
19100
 
19101
    @(master2_received_data_valid) ;
19102
    data = master2_received_data ;
19103
 
19104
    master2_check_received_data = master_check_data_prev ;
19105
  `endif
19106
`endif
19107
    in_use = 0 ;
19108
end
19109
endtask //config_read
19110
 
19111 62 mihad
`ifdef PCI_BIST
19112
`ifdef WB_RAM_DONT_SHARE
19113
    `ifdef PCI_RAM_DONT_SHARE
19114
        parameter bist_chain_length = 8 ;
19115
    `else
19116
        parameter bist_chain_length = 6 ;
19117
    `endif
19118
`else
19119
    `ifdef PCI_RAM_DONT_SHARE
19120 69 mihad
        parameter bist_chain_length = 6 ;
19121 62 mihad
    `else
19122 69 mihad
        parameter bist_chain_length = 4 ;
19123 62 mihad
    `endif
19124
`endif
19125
 
19126
task run_bist_test ;
19127
    reg [(bist_chain_length - 1):0] bist_result_vector ;
19128
    integer count ;
19129
    integer deadlock_count ;
19130
begin
19131
 
19132
    test_name = "BIST FOR RAMS RUN" ;
19133
 
19134 69 mihad
    scanb_en  = 0 ;
19135
    scanb_si  = 0 ;
19136
    scanb_rst = 0 ;
19137
    scanb_clk = 0 ;
19138 62 mihad
 
19139
    fork
19140
    begin
19141
        repeat(2)
19142
            @(posedge wb_clock) ;
19143
    end
19144
    begin
19145
        repeat(2)
19146
            @(posedge pci_clock) ;
19147
    end
19148
    join
19149
 
19150 69 mihad
    // test is run by reseting the test logic
19151
    scanb_rst <= 1'b1 ;
19152
 
19153
    // toggle scan clock for a few times
19154
    repeat (20)
19155
        #50 scanb_clk = !scanb_clk ;
19156
 
19157
    // release bist reset
19158
    scanb_rst <= 1'b0 ;
19159 62 mihad
 
19160
    bist_result_vector = 0 ;
19161
 
19162
    // result vector must be all 1s, because in RTL there cannot be a reason for BIST to fail
19163
    fork
19164
    begin:scan
19165
        while (bist_result_vector !== {bist_chain_length{1'b1}})
19166
        begin
19167 69 mihad
            #1 ;
19168
            @(posedge scanb_clk) ;
19169
            scanb_en <= #1 1'b1 ;
19170 62 mihad
            for (count = 0 ; count < bist_chain_length ; count = count + 1'b1)
19171
            begin
19172 69 mihad
                @(posedge scanb_clk) ;
19173
                bist_result_vector[count] = scanb_so ;
19174 62 mihad
            end
19175
 
19176 69 mihad
            scanb_en <= #1 1'b0 ;
19177 62 mihad
        end
19178
        #1 disable deadlock ;
19179 69 mihad
        @(negedge scanb_clk) ;
19180
        #1 disable scanb_clk_gen ;
19181 62 mihad
        test_ok ;
19182
    end
19183
    begin:deadlock
19184
        for (deadlock_count = 0; deadlock_count <= 100000; deadlock_count = deadlock_count + 1'b1)
19185
        begin
19186
            @(posedge pci_clock) ;
19187
            @(posedge wb_clock) ;
19188
        end
19189
 
19190
        test_fail("BIST Test didn't finish as expected") ;
19191 69 mihad
        scanb_en <= #1 1'b0 ;
19192 62 mihad
        disable scan ;
19193 69 mihad
        @(negedge scanb_clk) ;
19194 62 mihad
        #1 ;
19195 69 mihad
        disable scanb_clk_gen ;
19196 62 mihad
    end
19197 69 mihad
    begin:scanb_clk_gen
19198 62 mihad
        forever
19199 69 mihad
            #50 scanb_clk = !scanb_clk ;
19200 62 mihad
    end
19201
    join
19202
end
19203
endtask // run_bist_test
19204
`endif
19205
 
19206 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
19207
task target_special_corner_case_test ;
19208
    reg   [11:0]    pci_ctrl_offset ;
19209
    reg   [11:0]    ctrl_offset ;
19210
    reg   [11:0]    ba_offset ;
19211
    reg   [11:0]    am_offset ;
19212
    reg             ok_wb ;
19213
    reg             ok_pci ;
19214
    reg             test_mem ;
19215
    reg             master_check_data_previous ;
19216
begin:main
19217
    master_check_data_previous  = master1_check_received_data ;
19218
    master1_check_received_data = 1'b1 ;
19219
    pci_ctrl_offset = 12'h4 ;
19220
    // use image 1 for this test
19221
    ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
19222
    ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
19223
    am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
19224
 
19225
    // set behavioral slave cycle response
19226
    `ifdef REGISTER_WBM_OUTPUTS
19227
    wishbone_slave.cycle_response
19228
    (
19229
        3'b100,         // {ACK, ERR, RTY}
19230
        0,              // wait cycles
19231
        8'h0            // num of retries before termination
19232
    );
19233
    `else
19234
    wishbone_slave.cycle_response
19235
    (
19236
        3'b100,         // {ACK, ERR, RTY}
19237
        1,              // wait cycles
19238
        8'h0            // num of retries before termination
19239
    );
19240
    `endif
19241
 
19242
    `ifdef HOST
19243
        test_mem = 1 ;
19244
    `else
19245
        test_mem = `PCI_BA1_MEM_IO ;
19246
        test_mem = !test_mem ;
19247
    `endif
19248
 
19249
    test_name = "PCI TARGET UNIT SPECIAL CORNER CASE" ;
19250
 
19251
    // Set Base Address of IMAGE
19252
    config_write( ba_offset, Target_Base_Addr_R[1], 4'hF, ok_wb ) ;
19253
    if ( ok_wb !== 1 )
19254
    begin
19255 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19256 63 mihad
        test_fail("PCI Base Address register 1 could not be written") ;
19257
        #1 ;
19258
        disable main ;
19259
    end
19260
 
19261
    // Set Address Mask of IMAGE
19262
    config_write( am_offset, Target_Addr_Mask_R[1], 4'hF, ok_wb ) ;
19263
    if ( ok_wb !== 1 )
19264
    begin
19265 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_AM1 register! Time %t ", $time);
19266 63 mihad
        test_fail("PCI Address Mask register 1 could not be written") ;
19267
        #1 ;
19268
        disable main ;
19269
    end
19270
 
19271
    // Disable all the features of the PCI Image 1
19272
    config_write( ctrl_offset, 0, 4'hF, ok_wb ) ;
19273
    if ( ok_wb !== 1 )
19274
    begin
19275 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_CTRL1 register! Time %t ", $time);
19276 63 mihad
        test_fail("PCI Image Control register 1 could not be written") ;
19277
        #1 ;
19278
        disable main ;
19279
    end
19280
 
19281
    // set waits to max, which means 0 on PCI
19282
    tb_init_waits   = 4 ;
19283
    tb_subseq_waits = 4 ;
19284
 
19285
    // do one dummy write, to receive a GNT park
19286
    if (test_mem)
19287
    begin
19288
        PCIU_MEM_WRITE
19289
        (
19290
            "MEM_WRITE ",                       // just the name
19291
            `Test_Master_1,                     // Behavioral Master to use for reference
19292
            Target_Base_Addr_R[1],              // Address of this transaction
19293
            32'hAAAA_AAAA,                      // Data For the transaction
19294
            4'h0,                               // Byte enables
19295
            1,                                  // length of transfer
19296
            `Test_One_Zero_Master_WS,           // Master Waits - don't care
19297
            `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19298
            `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19299
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19300
        );
19301
    end
19302
    else
19303
    begin
19304
        PCIU_IO_WRITE
19305
        (
19306
            `Test_Master_1,                     // Behavioral Master to use for reference
19307
            Target_Base_Addr_R[1],              // Address of this transaction
19308
            32'hAAAA_AAAA,                      // Data For the transaction
19309
            4'h0,                               // Byte enables
19310
            1,                                  // Size of transfer
19311
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19312
        ) ;
19313
    end
19314
 
19315
    do_pause( 1 ) ;
19316
    wb_transaction_progress_monitor
19317
    (
19318
        Target_Base_Addr_R[1],          // expected address
19319
        1'b1,                           // expected operation R/W
19320
        1,                              // 1
19321
        1'b1,                           // turn checking of transfers ON/OFF
19322
        ok_wb                           // succeeded/failed
19323
    ) ;
19324
 
19325
    if (ok_wb !== 1'b1)
19326
    begin
19327
        test_fail("WB Transaction Monitor detected invalid transaction on WB bus after posted memory write through target") ;
19328
        #1 ;
19329
        disable main ;
19330
    end
19331
 
19332
    fork
19333
    begin
19334
        if (test_mem)
19335
        begin
19336
            PCIU_MEM_WRITE
19337
            (
19338
                "MEM_WRITE ",                       // just the name
19339
                `Test_Master_1,                     // Behavioral Master to use for reference
19340
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19341
                32'hF0F0_F0F0,                      // Data For the transaction
19342
                4'h0,                               // Byte enables       
19343
                1,                                  // length of transfer
19344
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19345
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19346
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19347
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19348
            );
19349
        end
19350
        else
19351
        begin
19352
            PCIU_IO_WRITE
19353
            (
19354
                `Test_Master_1,                     // Behavioral Master to use for reference
19355
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19356
                32'hF0F0_F0F0,                      // Data For the transaction
19357
                4'h0,                               // Byte enables
19358
                1,                                  // Size of transfer
19359
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19360
            ) ;
19361
        end
19362
 
19363
        do_pause( 1 ) ;
19364
 
19365
        if (test_mem)
19366
        begin
19367
            PCIU_MEM_WRITE
19368
            (
19369
                "MEM_WRITE ",                       // just the name
19370
                `Test_Master_1,                     // Behavioral Master to use for reference
19371
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19372
                32'h0F0F_0F0F,                      // Data For the transaction
19373
                4'h0,                               // Byte enables
19374
                1,                                  // length of transfer
19375
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19376
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19377
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19378
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19379
            );
19380
        end
19381
        else
19382
        begin
19383
            PCIU_IO_WRITE
19384
            (
19385
                `Test_Master_1,                     // Behavioral Master to use for reference
19386
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19387
                32'h0F0F_0F0F,                      // Data For the transaction
19388
                4'h0,                               // Byte enables
19389
                1,                                  // Size of transfer
19390
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19391
            ) ;
19392
        end
19393
 
19394
        do_pause( 1 ) ;
19395
    end
19396
    begin
19397
        wb_transaction_progress_monitor
19398
        (
19399
            Target_Base_Addr_R[1] + 64,     // expected address
19400
            1'b1,                           // expected operation R/W
19401
            1,                              // expected number of transfers
19402
            1'b1,                           // turn checking of transfers ON/OFF
19403
            ok_wb                           // succeeded/failed
19404
        ) ;
19405
 
19406
        if ( ok_wb === 1 )
19407
        begin
19408
 
19409
            wb_transaction_progress_monitor
19410
            (
19411
                Target_Base_Addr_R[1] + 128,    // expected address
19412
                1'b1,                           // expected operation R/W
19413
                1,                              // expected number of transfers
19414
                1'b1,                           // turn checking of transfers ON/OFF
19415
                ok_wb                           // succeeded/failed
19416
            ) ;
19417
        end
19418
 
19419
        @(posedge pci_clock) ;
19420
        #1 ;
19421
        disable pci_error_mon1 ;
19422
    end
19423
    begin:pci_error_mon1
19424
        ok_pci = 1 ;
19425
        @(error_event_int) ;
19426
        ok_pci = 0 ;
19427
    end
19428
    join
19429
 
19430
    if ( ok_wb !== 1'b1 )
19431
    begin
19432
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19433
    end
19434
 
19435
    if ( ok_pci !== 1'b1)
19436
    begin
19437
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19438
    end
19439
 
19440
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19441
    begin
19442
        #1 ;
19443
        disable main ;
19444
    end
19445
 
19446
    if ( test_mem )
19447
    begin
19448
        PCIU_MEM_READ
19449
        (
19450
            "MEM_READ  ",                   // description
19451
            `Test_Master_1,                 // behavioral master selection
19452
            Target_Base_Addr_R[1] + 64,     // address of access
19453
            32'hF0F0_F0F0,                  // expected read data
19454
            1,                              // number of transfers
19455
            8'h7_0,                         // don't care (wait cycles)
19456
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19457
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19458
            `Test_Target_Retry_On           // expected Target termination
19459
        );
19460
    end
19461
    else
19462
    begin
19463
        PCIU_IO_READ
19464
        (
19465
            `Test_Master_1,                 // behavioral master selection
19466
            Target_Base_Addr_R[1] + 64,     // address of access
19467
            32'hF0F0_F0F0,                  // expected read data
19468
            4'h0,                           // byte enables
19469
            1,                              // number of transfers
19470
            `Test_Target_Retry_On           // expected target termination
19471
        ) ;
19472
    end
19473
 
19474 64 mihad
    do_pause(1) ;
19475
 
19476 63 mihad
    wb_transaction_progress_monitor
19477
    (
19478
            Target_Base_Addr_R[1] + 64,     // expected address
19479
            1'b0,                           // expected operation R/W
19480
            1,                              // expected number transfers
19481
            1'b1,                           // turn checking of transfers ON/OFF
19482
            ok_wb                           // succeeded/failed
19483
    ) ;
19484
 
19485
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19486
    repeat(3)
19487
        @(posedge pci_clock) ;
19488
 
19489
    // now read data
19490
    fork
19491
    begin
19492
        if ( test_mem )
19493
        begin
19494
            PCIU_MEM_READ
19495
            (
19496
                "MEM_READ  ",                   // description
19497
                `Test_Master_1,                 // behavioral master selection
19498
                Target_Base_Addr_R[1] + 64,     // address of access
19499
                32'hF0F0_F0F0,                  // expected read data
19500
                1,                              // number of transfers
19501
                8'h7_0,                         // don't care (wait cycles)
19502
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19503
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19504
                `Test_Target_Normal_Completion  // expected Target termination
19505
            );
19506
        end
19507
        else
19508
        begin
19509
            PCIU_IO_READ
19510
            (
19511
                `Test_Master_1,                 // behavioral master selection
19512
                Target_Base_Addr_R[1] + 64,     // address of access
19513
                32'hF0F0_F0F0,                  // expected read data
19514
                4'h0,                           // byte enables
19515
                1,                              // number of transfers
19516
                `Test_Target_Normal_Completion  // expected target termination
19517
            ) ;
19518
        end
19519
 
19520 64 mihad
        do_pause(1) ;
19521 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19522
            @(posedge pci_clock) ;
19523
 
19524
        @(posedge pci_clock) ;
19525
        #1 ;
19526
        disable pci_error_mon2 ;
19527
    end
19528
    begin:pci_error_mon2
19529
        ok_pci = 1 ;
19530
        @(error_event_int) ;
19531
        ok_pci = 0 ;
19532
    end
19533
    join
19534
 
19535
    if ( ok_wb !== 1'b1 )
19536
    begin
19537
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19538
    end
19539
 
19540
    if ( ok_pci !== 1'b1)
19541
    begin
19542
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19543
    end
19544
 
19545
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19546
    begin
19547
        #1 ;
19548
        disable main ;
19549
    end
19550
 
19551
    if ( test_mem )
19552
    begin
19553
        PCIU_MEM_READ
19554
        (
19555
            "MEM_READ  ",                   // description
19556
            `Test_Master_1,                 // behavioral master selection
19557
            Target_Base_Addr_R[1] + 128,    // address of access
19558
            32'h0F0F_0F0F,                  // expected read data
19559
            1,                              // number of transfers
19560
            8'h7_0,                         // don't care (wait cycles)
19561
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19562
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19563
            `Test_Target_Retry_On           // expected Target termination
19564
        );
19565
    end
19566
    else
19567
    begin
19568
        PCIU_IO_READ
19569
        (
19570
            `Test_Master_1,                 // behavioral master selection
19571
            Target_Base_Addr_R[1] + 128,    // address of access
19572
            32'h0F0F_0F0F,                  // expected read data
19573
            4'h0,                           // byte enables
19574
            1,                              // number of transfers
19575
            `Test_Target_Retry_On           // expected target termination
19576
        ) ;
19577
    end
19578
 
19579 64 mihad
    do_pause(1) ;
19580 63 mihad
    wb_transaction_progress_monitor
19581
    (
19582
            Target_Base_Addr_R[1] + 128,    // expected address
19583
            1'b0,                           // expected operation R/W
19584
            1,                              // expected number transfers
19585
            1'b1,                           // turn checking of transfers ON/OFF
19586
            ok_wb                           // succeeded/failed
19587
    ) ;
19588
 
19589
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19590
    repeat(3)
19591
        @(posedge pci_clock) ;
19592
 
19593
    // now read data
19594
    fork
19595
    begin
19596
        if ( test_mem )
19597
        begin
19598
            PCIU_MEM_READ
19599
            (
19600
                "MEM_READ  ",                   // description
19601
                `Test_Master_1,                 // behavioral master selection
19602
                Target_Base_Addr_R[1] + 128,    // address of access
19603
                32'h0F0F_0F0F,                  // expected read data
19604
                1,                              // number of transfers
19605
                8'h7_0,                         // don't care (wait cycles)
19606
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19607
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19608
                `Test_Target_Normal_Completion  // expected Target termination
19609
            );
19610
        end
19611
        else
19612
        begin
19613
            PCIU_IO_READ
19614
            (
19615
                `Test_Master_1,                 // behavioral master selection
19616
                Target_Base_Addr_R[1] + 128,    // address of access
19617
                32'h0F0F_0F0F,                  // expected read data
19618
                4'h0,                           // byte enables
19619
                1,                              // number of transfers
19620
                `Test_Target_Normal_Completion  // expected target termination
19621
            ) ;
19622
        end
19623
 
19624 64 mihad
        do_pause(1) ;
19625 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19626
            @(posedge pci_clock) ;
19627
 
19628
        @(posedge pci_clock) ;
19629
        #1 ;
19630
        disable pci_error_mon3 ;
19631
    end
19632
    begin:pci_error_mon3
19633
        ok_pci = 1 ;
19634
        @(error_event_int) ;
19635
        ok_pci = 0 ;
19636
    end
19637
    join
19638
 
19639
    if ((ok_wb === 1'b1) && (ok_pci === 1'b1))
19640
        test_ok ;
19641
 
19642
    if ( ok_wb !== 1'b1 )
19643
    begin
19644
        test_fail("WB Master started invalid transaction or none at all after Target read was requested") ;
19645
    end
19646
 
19647
    if ( ok_pci !== 1'b1)
19648
    begin
19649
        test_fail("PCI Behavioral Master or Monitor signaled an error during read from PCI Bridge Target") ;
19650
    end
19651
 
19652 69 mihad
    // Disable used image
19653
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
19654
    if ( ok_wb !== 1 )
19655
    begin
19656
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19657
        test_fail("PCI Base Address register 1 could not be written") ;
19658
        #1 ;
19659
        disable main ;
19660
    end
19661
 
19662 63 mihad
    master1_check_received_data = master_check_data_previous ;
19663
end
19664
endtask // target_special_corner_case_test
19665
`endif
19666
 
19667 69 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
19668
task master_special_corner_case_test ;
19669
    reg   [11:0] ctrl_offset ;
19670
    reg   [11:0] ba_offset ;
19671
    reg   [11:0] am_offset ;
19672
    reg `WRITE_STIM_TYPE write_data ;
19673
    reg `READ_STIM_TYPE  read_data ;
19674
    reg `READ_RETURN_TYPE read_status ;
19675
 
19676
    reg `WRITE_RETURN_TYPE write_status ;
19677
    reg `WB_TRANSFER_FLAGS flags ;
19678
    reg ok_pci   ;
19679
    reg ok_wb ;
19680
 
19681
    reg [31:0] target_address ;
19682
 
19683
    reg [11:0] pci_ctrl_offset ;
19684
 
19685
    reg [31:0] image_base ;
19686
begin:main
19687
    test_name = "WISHBONE SLAVE UNIT SPECIAL CORNER CASE" ;
19688
    pci_ctrl_offset = 12'h4 ;
19689
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
19690
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
19691
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
19692
 
19693
    target_address  = `BEH_TAR1_MEM_START ;
19694
    image_base      = 0 ;
19695
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
19696
 
19697
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
19698
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
19699
 
19700
    flags                      = 0 ;
19701
    flags`INIT_WAITS           = 0 ;
19702
    flags`SUBSEQ_WAITS         = 0 ;
19703
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
19704
 
19705
    test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = `Test_Devsel_Fast ;
19706
    test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
19707
    test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
19708
 
19709
    // enable master & target operation
19710
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok_wb) ;
19711
    if ( ok_wb !== 1 )
19712
    begin
19713
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write PCI Device Control register! Time %t ", $time) ;
19714
        test_fail("write to PCI Device Control register didn't succeede");
19715
        disable main ;
19716
    end
19717
 
19718
    // prepare image control register
19719
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok_wb) ;
19720
    if ( ok_wb !== 1 )
19721
    begin
19722
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
19723
        test_fail("write to WB Image Control register didn't succeede");
19724
        disable main ;
19725
    end
19726
 
19727
    // prepare base address register
19728
    config_write( ba_offset, image_base, 4'hF, ok_wb ) ;
19729
    if ( ok_wb !== 1 )
19730
    begin
19731
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
19732
        test_fail("write to WB Base Address register didn't succeede");
19733
        disable main ;
19734
    end
19735
 
19736
    // write address mask register
19737
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok_wb ) ;
19738
    if ( ok_wb !== 1 )
19739
    begin
19740
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_AM1 register! Time %t ", $time) ;
19741
        test_fail("write to WB Address Mask register didn't succeede");
19742
        disable main ;
19743
    end
19744
 
19745
    fork
19746
    begin
19747
 
19748
        // do one dummy read, to receive bus gnt
19749
        read_data`READ_ADDRESS  = target_address ;
19750
        read_data`READ_SEL      = 4'hF ;
19751
        read_data`READ_TAG_STIM = 0 ;
19752
 
19753
        // handle retries
19754
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19755
 
19756
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19757
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19758
        begin
19759
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19760
            test_fail("PCI bridge didn't process the delayed read as expected");
19761
            disable main ;
19762
        end
19763
 
19764
        write_data`WRITE_ADDRESS = target_address + 64;
19765
        write_data`WRITE_DATA    = 32'hABCD_EF12 ;
19766
        write_data`WRITE_SEL     = 4'hF ;
19767
 
19768
        wishbone_master.blk_write_data[0] = write_data ;
19769
 
19770
        write_data`WRITE_ADDRESS = target_address + 128 ;
19771
        write_data`WRITE_DATA    = ~write_data`WRITE_DATA ;
19772
        write_data`WRITE_SEL     = 4'hF ;
19773
 
19774
        wishbone_master.blk_write_data[1] = write_data ;
19775
 
19776
        // no retries should happen
19777
        flags`WB_TRANSFER_AUTO_RTY = 0 ;
19778
 
19779
        flags`WB_TRANSFER_SIZE = 2 ;
19780
 
19781
        wishbone_master.wb_block_write( flags, write_status ) ;
19782
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
19783
        begin
19784
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process block memory write! Time %t ", $time) ;
19785
            test_fail("WB Slave state machine failed to post block memory write");
19786
            disable main ;
19787
        end
19788
 
19789
        // read data back
19790
        read_data`READ_ADDRESS  = target_address + 64 ;
19791
        read_data`READ_SEL      = 4'hF ;
19792
        read_data`READ_TAG_STIM = 0 ;
19793
 
19794
        // handle retries
19795
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19796
 
19797
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19798
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19799
        begin
19800
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19801
            test_fail("PCI bridge didn't process the delayed read as expected");
19802
            disable main ;
19803
        end
19804
 
19805
        if (read_status`READ_DATA !== 32'hABCD_EF12)
19806
        begin
19807
            display_warning(target_address + 64, 32'hABCD_EF12, read_status`READ_DATA) ;
19808
            test_fail("PCI bridge returned unexpected Read Data");
19809
            ok_wb = 0 ;
19810
        end
19811
 
19812
        // read second data back
19813
        read_data`READ_ADDRESS  = target_address + 128 ;
19814
        read_data`READ_SEL      = 4'hF ;
19815
        read_data`READ_TAG_STIM = 0 ;
19816
 
19817
        // handle retries
19818
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19819
 
19820
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19821
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19822
        begin
19823
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19824
            test_fail("PCI bridge didn't process the delayed read as expected");
19825
            disable main ;
19826
        end
19827
 
19828
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
19829
        begin
19830
            display_warning(target_address + 128, write_data`WRITE_DATA, read_status`READ_DATA) ;
19831
            test_fail("PCI bridge returned unexpected Read Data");
19832
            ok_wb = 0 ;
19833
        end
19834
    end
19835
    begin
19836
 
19837
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19838
        if ( ok_pci !== 1 )
19839
        begin
19840
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19841
        end
19842
 
19843
        if(ok_pci)
19844
        begin
19845
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
19846
            if ( ok_pci !== 1 )
19847
            begin
19848
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19849
            end
19850
        end
19851
 
19852
        if (ok_pci)
19853
        begin
19854
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
19855
            if ( ok_pci !== 1 )
19856
            begin
19857
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19858
            end
19859
        end
19860
 
19861
        if (ok_pci)
19862
        begin
19863
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19864
            if ( ok_pci !== 1 )
19865
            begin
19866
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19867
            end
19868
        end
19869
 
19870
        if (ok_pci)
19871
        begin
19872
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19873
            if ( ok_pci !== 1 )
19874
            begin
19875
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19876
            end
19877
        end
19878
    end
19879
    join
19880
 
19881
    if (ok_wb && ok_pci)
19882
        test_ok ;
19883
 
19884
    // disable the image
19885
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
19886
    if ( ok_wb !== 1 )
19887
    begin
19888
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
19889
        test_fail("write to WB Base Address register didn't succeede");
19890
        disable main ;
19891
    end
19892
end
19893
endtask // master_special_corner_case_test
19894
`endif
19895
 
19896 15 mihad
task test_fail ;
19897
    input [7999:0] failure_reason ;
19898
    reg   [8007:0] display_failure ;
19899
    reg   [799:0] display_test ;
19900
begin
19901
    tests_failed = tests_failed + 1 ;
19902
 
19903
    display_failure = {failure_reason, "!"} ;
19904
    while ( display_failure[7999:7992] == 0 )
19905
        display_failure = display_failure << 8 ;
19906
 
19907
    display_test = test_name ;
19908
    while ( display_test[799:792] == 0 )
19909
       display_test = display_test << 8 ;
19910
 
19911 63 mihad
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19912 15 mihad
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
19913
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
19914
    $fdisplay( tb_log_file, " *FAILED* because") ;
19915
    $fdisplay( tb_log_file, " %s", display_failure ) ;
19916 63 mihad
    current_test_parameters ;
19917
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19918 15 mihad
    $fdisplay( tb_log_file, " " ) ;
19919
 
19920
    `ifdef STOP_ON_FAILURE
19921
    #20 $stop ;
19922
    `endif
19923
end
19924
endtask // test_fail
19925
 
19926
task test_ok ;
19927
    reg [799:0] display_test ;
19928
begin
19929
   tests_successfull = tests_successfull + 1 ;
19930
 
19931
   display_test = test_name ;
19932
   while ( display_test[799:792] == 0 )
19933
       display_test = display_test << 8 ;
19934
 
19935 63 mihad
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19936 15 mihad
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
19937
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
19938
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
19939 63 mihad
   current_test_parameters ;
19940
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19941 15 mihad
   $fdisplay( tb_log_file, " " ) ;
19942
end
19943
endtask // test_ok
19944
 
19945
task test_summary;
19946
begin
19947 63 mihad
    $fdisplay(tb_log_file, "\n \n");
19948 15 mihad
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19949
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
19950
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
19951
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
19952
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19953
    $fclose(tb_log_file) ;
19954
end
19955
endtask
19956
 
19957 63 mihad
task current_test_parameters ;
19958
    reg [87:0] decode_speed_text ;
19959
begin
19960
    case (tb_target_decode_speed)
19961
        3'b000: decode_speed_text = "FAST       " ;
19962
        3'b001: decode_speed_text = "MEDIUM     " ;
19963
        3'b010: decode_speed_text = "SLOW       " ;
19964
        3'b011: decode_speed_text = "SUBTRACTIVE" ;
19965
    endcase
19966
 
19967
    $fdisplay( tb_log_file, "TEST PARAMETERS:") ;
19968
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Initial Wait States         = %d", (3'd4 - tb_init_waits)) ;
19969
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Subsequent Wait States      = %d", (3'd4 - tb_subseq_waits)) ;
19970
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' DEVSEL speed                = %s", decode_speed_text) ;
19971
 
19972
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Initial Wait States    = %d", tb_init_waits) ;
19973
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Subsequent Wait States = %d", tb_subseq_waits) ;
19974
end
19975
endtask
19976
 
19977 15 mihad
endmodule

powered by: WebSVN 2.1.0

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