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

Subversion Repositories pci

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

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 87 mihad
// Revision 1.14  2003/01/30 22:01:33  mihad
43
// Updated synchronization in top level fifo modules.
44
//
45 81 mihad
// Revision 1.13  2003/01/21 16:06:50  mihad
46
// Bug fixes, testcases added.
47
//
48 73 mihad
// Revision 1.12  2002/10/21 13:04:30  mihad
49
// Changed BIST signal names etc..
50
//
51 69 mihad
// Revision 1.11  2002/10/11 12:03:12  mihad
52
// The testcase I just added in previous revision repaired
53
//
54 64 mihad
// Revision 1.10  2002/10/11 10:08:57  mihad
55
// Added additional testcase and changed rst name in BIST to trst
56
//
57 63 mihad
// Revision 1.9  2002/10/08 17:17:02  mihad
58
// Added BIST signals for RAMs.
59
//
60 62 mihad
// Revision 1.8  2002/09/25 09:54:47  mihad
61
// Added completion expiration test for WB Slave unit. Changed expiration signalling
62
//
63 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
64
// Oops, never before noticed that OC header is missing
65 52 mihad
//
66 57 mihad
//
67 52 mihad
 
68 15 mihad
`include "pci_constants.v"
69
`include "bus_commands.v"
70
`include "pci_testbench_defines.v"
71
`include "timescale.v"
72
 
73 51 mihad
`ifdef HOST
74
    `ifdef NO_CNF_IMAGE
75
    `else
76
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
77
    `endif
78
`else
79
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
80
`endif
81
 
82 15 mihad
module SYSTEM ;
83
 
84
`include "pci_blue_constants.vh"
85
`include "pci_blue_options.vh"
86
 
87
integer tests_successfull ;
88
integer tests_failed ;
89
integer tb_log_file ;
90
reg [799:0] test_name ;
91
 
92
reg pci_clock ;
93
reg wb_clock ;
94
reg reset ;
95
 
96
wire [4:0] arb_grant_out ;
97
 
98
wire [31:0] AD ;
99
wire [3:0]  CBE ;
100
pullup(INTA) ;
101
pullup(MAS0_REQ) ;
102
pullup(MAS1_REQ) ;
103
pullup(MAS2_REQ) ;
104
pullup(MAS3_REQ) ;
105
 
106
wire MAS0_GNT = ~arb_grant_out[0];
107
wire MAS1_GNT = ~arb_grant_out[1] ;
108
wire MAS2_GNT = ~arb_grant_out[2] ;
109
wire MAS3_GNT = ~arb_grant_out[3] ;
110
 
111
pullup(FRAME) ;
112
pullup(IRDY) ;
113 45 mihad
 
114
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
115
 
116 15 mihad
pullup(DEVSEL) ;
117
pullup(TRDY) ;
118
pullup(STOP) ;
119
wire   PAR ;
120
pullup(PERR) ;
121
pullup(SERR) ;
122
wire [3:0] MAS1_IDSEL ;
123
 
124
pullup lockpu ( LOCK ) ;
125
 
126
wire        RST_O ;
127
wire        INT_O ;
128
reg         INT_I ;
129
wire [31:0] ADR_I ;
130
wire [31:0] SDAT_I ;
131
wire [31:0] SDAT_O ;
132
wire [3:0]  SEL_I ;
133
wire        CYC_I ;
134
wire        STB_I ;
135
wire        WE_I ;
136
wire        CAB_I ;
137
wire        ACK_O ;
138
wire        RTY_O ;
139
wire        ERR_O ;
140
 
141
wire [31:0] ADR_O ;
142
wire [31:0] MDAT_I ;
143
wire [31:0] MDAT_O ;
144
wire [3:0]  SEL_O ;
145
wire        CYC_O ;
146
wire        STB_O ;
147
wire        WE_O ;
148
wire        CAB_O ;
149
wire        ACK_I ;
150
wire        RTY_I ;
151
wire        ERR_I ;
152
 
153 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
154
 
155
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
156
 
157 15 mihad
wire        reset_wb ; // reset to Wb devices
158
 
159 62 mihad
`ifdef PCI_BIST
160 69 mihad
wire scanb_so ;
161
reg  scanb_si ;
162
reg  scanb_rst ;
163
reg  scanb_en ;
164
reg  scanb_clk ;
165 62 mihad
`endif
166
 
167 15 mihad
`ifdef GUEST
168
    wire    RST = ~reset ;
169
    assign  reset_wb = RST_O ;
170
`else
171
    pullup(RST) ;
172
    assign  reset_wb = reset ;
173
`endif
174
 
175
`define PCI_BRIDGE_INSTANCE bridge32_top
176
 
177
TOP `PCI_BRIDGE_INSTANCE
178
(
179
    .CLK    ( pci_clock),
180
    .AD     ( AD ),
181
    .CBE    ( CBE ),
182
    .RST    ( RST ),
183
    .INTA   ( INTA ),
184
    .REQ    ( MAS0_REQ ),
185
    .GNT    ( MAS0_GNT ),
186
    .FRAME  ( FRAME ),
187
    .IRDY   ( IRDY ),
188
    .IDSEL  ( TAR0_IDSEL),
189
    .DEVSEL ( DEVSEL ),
190
    .TRDY   ( TRDY ),
191
    .STOP   ( STOP ),
192
    .PAR    ( PAR ),
193
    .PERR   ( PERR ),
194
    .SERR   ( SERR ),
195
 
196
    .CLK_I  ( wb_clock ),
197
    .RST_I  ( reset ),
198
    .RST_O  ( RST_O ),
199
    .INT_I  ( INT_I ),
200
    .INT_O  ( INT_O ),
201
 
202
    // WISHBONE slave interface
203
    .ADR_I  ( ADR_I ),
204
    .SDAT_I ( SDAT_I ),
205
    .SDAT_O ( SDAT_O ),
206
    .SEL_I  ( SEL_I ),
207
    .CYC_I  ( CYC_I ),
208
    .STB_I  ( STB_I ),
209
    .WE_I   ( WE_I ),
210
    .CAB_I  ( CAB_I),
211
    .ACK_O  ( ACK_O ),
212
    .RTY_O  ( RTY_O ),
213
    .ERR_O  ( ERR_O ),
214
 
215
    // WISHBONE master interface
216
    .ADR_O  ( ADR_O ),
217
    .MDAT_I ( MDAT_I ),
218
    .MDAT_O ( MDAT_O ),
219
    .SEL_O  ( SEL_O ),
220
    .CYC_O  ( CYC_O ),
221
    .STB_O  ( STB_O ),
222
    .WE_O   ( WE_O ),
223
    .CAB_O  ( CAB_O ),
224
    .ACK_I  ( ACK_I ),
225
    .RTY_I  ( RTY_I ),
226
    .ERR_I  ( ERR_I )
227 62 mihad
 
228
`ifdef PCI_BIST
229
    ,
230 69 mihad
    // bist chain signals
231
    .scanb_rst  (scanb_rst),
232
    .scanb_clk  (scanb_clk),
233
    .scanb_si   (scanb_si),
234
    .scanb_so   (scanb_so),
235
    .scanb_en   (scanb_en)
236 62 mihad
`endif
237 15 mihad
) ;
238
 
239
WB_MASTER_BEHAVIORAL wishbone_master
240
(
241
    .CLK_I(wb_clock),
242
    .RST_I(reset_wb),
243
    .TAG_I(4'b0000),
244
    .TAG_O(),
245
    .ACK_I(ACK_O),
246
    .ADR_O(ADR_I),
247
    .CYC_O(CYC_I),
248
    .DAT_I(SDAT_O),
249
    .DAT_O(SDAT_I),
250
    .ERR_I(ERR_O),
251
    .RTY_I(RTY_O),
252
    .SEL_O(SEL_I),
253
    .STB_O(STB_I),
254
    .WE_O (WE_I),
255
    .CAB_O(CAB_I)
256
);
257
 
258
WB_SLAVE_BEHAVIORAL wishbone_slave
259
(
260
    .CLK_I              (wb_clock),
261
    .RST_I              (reset_wb),
262
    .ACK_O              (ACK_I),
263
    .ADR_I              (ADR_O),
264
    .CYC_I              (CYC_O),
265
    .DAT_O              (MDAT_I),
266
    .DAT_I              (MDAT_O),
267
    .ERR_O              (ERR_I),
268
    .RTY_O              (RTY_I),
269
    .SEL_I              (SEL_O),
270
    .STB_I              (STB_O),
271
    .WE_I               (WE_O),
272
    .CAB_I              (CAB_O)
273
);
274
 
275
integer wbu_mon_log_file_desc ;
276
integer pciu_mon_log_file_desc ;
277
WB_BUS_MON wbu_wb_mon(
278
                    .CLK_I(wb_clock),
279
                    .RST_I(reset_wb),
280
                    .ACK_I(ACK_O),
281
                    .ADDR_O(ADR_I),
282
                    .CYC_O(CYC_I),
283
                    .DAT_I(SDAT_O),
284
                    .DAT_O(SDAT_I),
285
                    .ERR_I(ERR_O),
286
                    .RTY_I(RTY_O),
287
                    .SEL_O(SEL_I),
288
                    .STB_O(STB_I),
289
                    .WE_O (WE_I),
290
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
291
                    .TAG_O(),
292
                    .CAB_O(CAB_I),
293
                    .log_file_desc ( wbu_mon_log_file_desc )
294
                  ) ;
295
 
296
WB_BUS_MON pciu_wb_mon(
297
                    .CLK_I(wb_clock),
298
                    .RST_I(reset_wb),
299
                    .ACK_I(ACK_I),
300
                    .ADDR_O(ADR_O),
301
                    .CYC_O(CYC_O),
302
                    .DAT_I(MDAT_I),
303
                    .DAT_O(MDAT_O),
304
                    .ERR_I(ERR_I),
305
                    .RTY_I(RTY_I),
306
                    .SEL_O(SEL_O),
307
                    .STB_O(STB_O),
308
                    .WE_O (WE_O),
309
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
310
                    .TAG_O(),
311
                    .CAB_O(CAB_O),
312
                    .log_file_desc( pciu_mon_log_file_desc )
313
                  ) ;
314
 
315
// some aditional signals are needed here because of the arbiter
316
reg [3:0] pci_ext_req_prev ;
317
always@(posedge pci_clock)
318
begin
319
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
320
end
321
reg pci_frame_prev ;
322
always@(posedge pci_clock)
323
begin
324
    pci_frame_prev <= FRAME ;
325
end
326
reg pci_irdy_prev ;
327
always@(posedge pci_clock)
328
begin
329
    pci_irdy_prev <= IRDY ;
330
end
331
 
332
pci_blue_arbiter pci_arbiter
333
(
334
  .pci_int_req_direct(1'b0),
335
  .pci_ext_req_prev(pci_ext_req_prev),
336
  .pci_int_gnt_direct_out(arb_grant_out[4]),
337
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
338
  .pci_frame_prev(~pci_frame_prev),
339
  .pci_irdy_prev(~pci_irdy_prev),
340
  .pci_irdy_now(~IRDY),
341
  .arbitration_enable(1'b1),
342
  .pci_clk(pci_clock),
343
  .pci_reset_comb(~RST)
344
);
345
 
346
reg [31:0] target_message ;
347
 
348
// define output enable signals for monitor inputs
349
// real output enable signals
350
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
351
`ifdef ACTIVE_LOW_OE
352
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
353
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
354
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
355
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
356
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
357
                        !devsel_t_s_oe,
358
                        !ad_oe,
359
                        !cbe_oe,
360
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
361
                        ;
362
`else
363
`ifdef ACTIVE_HIGH_OE
364
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
365
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
366
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
367
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
368
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
369
                        devsel_t_s_oe,
370
                        ad_oe,
371
                        cbe_oe,
372
                        `PCI_BRIDGE_INSTANCE.PERR_en}
373
                        ;
374
`endif
375
`endif
376
/*wire [5:0] oe_sigs_0 = {1'b0,
377
                        1'b0,
378
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
379
                        pci_target32.ad_enable,
380
                        1'b0,
381
                        pci_target32.err_enable | pci_target32.r_err_enable
382
                       } ;
383
*/
384
 
385
wire [5:0] oe_sigs_2 ;
386
wire [5:0] oe_sigs_1 ;
387
 
388
// signals which are used by test modules to know what to do
389
triand  test_accepted_l_int, error_event_int;
390
pullup  (test_accepted_l_int), (error_event_int);
391
 
392
wire    pci_reset_comb  = ~RST;
393
wire    pci_ext_clk     = pci_clock;
394
 
395
integer pci_mon_log_file_desc ;
396
pci_bus_monitor monitor32
397
(
398
    .pci_ext_ad                 (AD),
399
    .pci_ext_cbe_l              (CBE),
400
    .pci_ext_par                (PAR),
401
    .pci_ext_frame_l            (FRAME),
402
    .pci_ext_irdy_l             (IRDY),
403
    .pci_ext_devsel_l           (DEVSEL),
404
    .pci_ext_trdy_l             (TRDY),
405
    .pci_ext_stop_l             (STOP),
406
    .pci_ext_perr_l             (PERR),
407
    .pci_ext_serr_l             (SERR),
408
    .pci_real_req_l             (MAS0_REQ),
409
    .pci_real_gnt_l             (MAS0_GNT),
410
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
411
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
412
    .test_error_event           (error_event_int),
413
    .test_observe_r_oe_sigs     (r_oe_sigs),
414
    .test_observe_0_oe_sigs     (6'h00),
415
    .test_observe_1_oe_sigs     (oe_sigs_1),
416
    .test_observe_2_oe_sigs     (oe_sigs_2),
417
    .test_observe_3_oe_sigs     (6'h00),
418
    .pci_ext_reset_l            (RST),
419
    .pci_ext_clk                (pci_clock),
420
    .log_file_desc              (pci_mon_log_file_desc)
421
) ;
422
 
423
reg [2:0]  test_master_number ;
424
reg [31:0] test_address ;
425
reg [3:0]  test_command ;
426
reg [31:0] test_data ;
427
reg [3:0]  test_byte_enables_l ;
428
reg [9:0]  test_size ;
429
reg        test_make_addr_par_error ;
430
reg        test_make_data_par_error ;
431
reg [3:0]  test_master_initial_wait_states ;
432
reg [3:0]  test_master_subsequent_wait_states ;
433
reg [3:0]  test_target_initial_wait_states ;
434
reg [3:0]  test_target_subsequent_wait_states ;
435
reg [1:0]  test_target_devsel_speed ;
436
reg        test_fast_back_to_back ;
437
reg [2:0]  test_target_termination ;
438
reg        test_expect_master_abort ;
439
reg        test_start ;
440
reg [25:0] test_target_response ;
441
 
442
wire [31:0] master2_received_data ;
443
wire        master2_received_data_valid ;
444
reg         master2_check_received_data ;
445
pci_behaviorial_device pci_behaviorial_device2
446
(
447
    .pci_ext_ad(AD),
448
    .pci_ext_cbe_l(CBE),
449
    .pci_ext_par(PAR),
450
    .pci_ext_frame_l(FRAME),
451
    .pci_ext_irdy_l(IRDY),
452
    .pci_ext_devsel_l(DEVSEL),
453
    .pci_ext_trdy_l(TRDY),
454
    .pci_ext_stop_l(STOP),
455
    .pci_ext_perr_l(PERR),
456
    .pci_ext_serr_l(SERR),
457
    .pci_ext_idsel(TAR2_IDSEL),
458
    .pci_ext_inta_l(INTA),
459
    .pci_ext_req_l(MAS2_REQ),
460
    .pci_ext_gnt_l(MAS2_GNT),
461
    .pci_ext_reset_l(RST),
462
    .pci_ext_clk(pci_clock),
463
 
464
// Signals used by the test bench instead of using "." notation
465
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
466
    .test_master_number                 (test_master_number[2:0]),
467
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
468
    .test_command                       (test_command[3:0]),
469
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
470
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
471
    .test_size                          (test_size),
472
    .test_make_addr_par_error           (test_make_addr_par_error),
473
    .test_make_data_par_error           (test_make_data_par_error),
474
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
475
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
476
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
477
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
478
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
479
    .test_fast_back_to_back             (test_fast_back_to_back),
480
    .test_target_termination            (test_target_termination[2:0]),
481
    .test_expect_master_abort           (test_expect_master_abort),
482
    .test_start                         (test_start),
483
    .test_accepted_l                    (test_accepted_l_int),
484
    .test_error_event                   (error_event_int),
485
    .test_device_id                     (`Test_Master_2),
486
    .test_target_response               (test_target_response),
487
 
488
    .master_received_data               (master2_received_data),
489
    .master_received_data_valid         (master2_received_data_valid),
490
    .master_check_received_data         (master2_check_received_data)
491
);
492
 
493
wire [31:0] master1_received_data ;
494
wire        master1_received_data_valid ;
495
reg         master1_check_received_data ;
496
pci_behaviorial_device pci_behaviorial_device1
497
(
498
    .pci_ext_ad(AD),
499
    .pci_ext_cbe_l(CBE),
500
    .pci_ext_par(PAR),
501
    .pci_ext_frame_l(FRAME),
502
    .pci_ext_irdy_l(IRDY),
503
    .pci_ext_devsel_l(DEVSEL),
504
    .pci_ext_trdy_l(TRDY),
505
    .pci_ext_stop_l(STOP),
506
    .pci_ext_perr_l(PERR),
507
    .pci_ext_serr_l(SERR),
508
    .pci_ext_idsel(TAR1_IDSEL),
509
    .pci_ext_inta_l(INTA),
510
    .pci_ext_req_l(MAS1_REQ),
511
    .pci_ext_gnt_l(MAS1_GNT),
512
    .pci_ext_reset_l(RST),
513
    .pci_ext_clk(pci_clock),
514
 
515
// Signals used by the test bench instead of using "." notation
516
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
517
    .test_master_number                 (test_master_number[2:0]),
518
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
519
    .test_command                       (test_command[3:0]),
520
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
521
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
522
    .test_size                          (test_size),
523
    .test_make_addr_par_error           (test_make_addr_par_error),
524
    .test_make_data_par_error           (test_make_data_par_error),
525
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
526
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
527
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
528
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
529
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
530
    .test_fast_back_to_back             (test_fast_back_to_back),
531
    .test_target_termination            (test_target_termination[2:0]),
532
    .test_expect_master_abort           (test_expect_master_abort),
533
    .test_start                         (test_start),
534
    .test_accepted_l                    (test_accepted_l_int),
535
    .test_error_event                   (error_event_int),
536
    .test_device_id                     (`Test_Master_1),
537
    .test_target_response               (test_target_response),
538
 
539
    .master_received_data               (master1_received_data),
540
    .master_received_data_valid         (master1_received_data_valid),
541
    .master_check_received_data         (master1_check_received_data)
542
);
543
 
544
pci_unsupported_commands_master ipci_unsupported_commands_master
545
(
546
    .CLK    ( pci_clock),
547
    .AD     ( AD ),
548
    .CBE    ( CBE ),
549
    .RST    ( RST ),
550
    .REQ    ( MAS3_REQ ),
551
    .GNT    ( MAS3_GNT ),
552
    .FRAME  ( FRAME ),
553
    .IRDY   ( IRDY ),
554
    .DEVSEL ( DEVSEL ),
555
    .TRDY   ( TRDY ),
556
    .STOP   ( STOP ),
557
    .PAR    ( PAR )
558
) ;
559
 
560 45 mihad
`ifdef HOST
561
 
562
reg     [1:0]   conf_cyc_type1_target_response ;
563
reg     [31:0]  conf_cyc_type1_target_data ;
564
reg     [7:0]   conf_cyc_type1_target_bus_num ;
565
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
566
 
567
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
568
(
569
    .CLK              ( pci_clock),
570
    .AD               ( AD ),
571
    .CBE              ( CBE ),
572
    .RST              ( RST ),
573
    .FRAME            ( FRAME ),
574
    .IRDY             ( IRDY ),
575
    .DEVSEL           ( DEVSEL ),
576
    .TRDY             ( TRDY ),
577
    .STOP             ( STOP ),
578
    .PAR              ( PAR ),
579
 
580
    .response         ( conf_cyc_type1_target_response ),
581
    .data_out         ( conf_cyc_type1_target_data ),
582
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
583
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
584
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
585
    .bus_number       ( conf_cyc_type1_target_bus_num )
586
);
587
`endif
588
 
589 15 mihad
// pci clock generator
590 63 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
591
    always@(posedge wb_clock)
592
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b1 ;
593
 
594
    always@(negedge wb_clock)
595
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b0 ;
596 15 mihad
`else
597 63 mihad
    always
598
    `ifdef PCI33
599
        #15 pci_clock = ~pci_clock ;
600
    `else
601
    `ifdef PCI66
602
        #7.5 pci_clock = ~pci_clock ;
603
    `endif
604
    `endif
605 15 mihad
`endif
606
 
607
// WISHBONE clock generation
608 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
609
always@(posedge pci_clock)
610
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b1 ;
611 15 mihad
 
612 63 mihad
always@(negedge pci_clock)
613
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b0 ;
614
 
615
`else
616
    always
617
        #(((1/`WB_FREQ)/2)) wb_clock = !wb_clock ;
618
`endif
619
 
620 15 mihad
// Make test name visible when the Master starts working on it
621
reg     [79:0] present_test_name;
622
reg     [79:0] next_test_name;
623
wire    test_accepted = ~test_accepted_l_int;
624
always @(posedge test_accepted)
625
begin
626
    present_test_name <= next_test_name;
627
end
628
 
629
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
630
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
631
 
632
// basic configuration parameters for both behavioral devices
633
parameter [2:0] Master_ID_A                           = `Test_Master_1;
634
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
635
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
636
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
637
 
638
parameter [2:0] Master_ID_B                           = `Test_Master_2;
639
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
640
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
641
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
642
 
643
// basic configuration parameters for REAL device
644
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
645
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
646
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
647
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
648
 
649
// reg  [2:0]   ack_err_rty_termination ;
650
// reg          wait_cycles ;
651
// reg  [7:0]   num_of_retries ;
652
 
653
//reg [19:0] pci_config_base ;
654
reg [7:0] system_burst_size ;
655
reg [7:0] bridge_latency ;
656
integer   target_mem_image ;
657
integer   target_io_image ;
658
 
659
initial
660
begin
661 62 mihad
 
662
`ifdef PCI_BIST
663 69 mihad
    scanb_si    = 0 ;
664
    scanb_en    = 0 ;
665
    scanb_clk   = 0 ;
666
    scanb_rst   = 0 ;
667 62 mihad
`endif
668 15 mihad
    next_test_name[79:0] <= "Nowhere___";
669
    reset = 1'b1 ;
670
    pci_clock = 1'b0 ;
671
    wb_clock  = 1'b1 ;
672
    target_message = 32'h0000_0000 ;
673
//  num_of_retries = 8'h01 ;
674
//  ack_err_rty_termination = 3'b100 ;
675
//  wait_cycles = 1'b0 ;
676
 
677
    // system paameters
678
    system_burst_size = 16 ;
679
    bridge_latency    = 8 ;
680
 
681
    // set initial values for controling the behavioral PCI master
682
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
683
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
684
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
685
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
686
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
687
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
688
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
689
 
690
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
691
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
692
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
693
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
694
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
695
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
696
 
697
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
698
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
699
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
700
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
701
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
702
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
703
 
704
    test_master_number = `Test_Master_2 ;
705
    test_address = 32'h0000_0000 ;
706
    test_command = `BC_RESERVED0 ;
707
    test_data = 32'h0000_0000 ;
708
    test_byte_enables_l   = 4'hF ;
709
    test_size = 0 ;
710
    test_make_addr_par_error = 0 ;
711
    test_make_data_par_error = 0;
712
    test_master_initial_wait_states = 0 ;
713
    test_master_subsequent_wait_states = 0 ;
714
    test_target_initial_wait_states = 0 ;
715
    test_target_subsequent_wait_states = 0;
716
    test_target_devsel_speed = `Test_Devsel_Fast ;
717
    test_fast_back_to_back = 0 ;
718
    test_target_termination = `Test_Target_Normal_Completion ;
719
    test_expect_master_abort = 0 ;
720
    test_start = 0 ;
721
    test_target_response = 0 ;
722
 
723
    master1_check_received_data = 0 ;
724
    master2_check_received_data = 0 ;
725
 
726 45 mihad
    `ifdef HOST
727
        conf_cyc_type1_target_response = 0 ;
728
        conf_cyc_type1_target_data = 0 ;
729
        conf_cyc_type1_target_bus_num = 255 ;
730
    `endif
731 15 mihad
 
732
    // fill memory and IO data with random values
733
    fill_memory ;
734
 
735
    INT_I = 0 ;
736
 
737
    // extract from constants which target image can be used as IO and which as memory
738
    `ifdef HOST
739
        target_mem_image = 1 ;
740
        target_io_image  = 1 ;
741
    `else
742
        target_mem_image = -1 ;
743
        target_io_image     = -1 ;
744
        if ( `PCI_BA1_MEM_IO === 0 )
745
            target_mem_image = 1 ;
746
        else
747
            target_io_image = 1 ;
748
 
749
        if ( target_mem_image === -1 )
750
        begin
751
            `ifdef PCI_IMAGE2
752
                if ( `PCI_BA2_MEM_IO === 0 )
753
                    target_mem_image = 2 ;
754
                else if ( target_io_image === -1 )
755
                    target_io_image = 2 ;
756
            `endif
757
        end
758
 
759
        if ( target_mem_image === -1 )
760
        begin
761
            `ifdef PCI_IMAGE3
762
                if ( `PCI_BA3_MEM_IO === 0 )
763
                    target_mem_image = 3 ;
764
                else if ( target_io_image === -1 )
765
                    target_io_image = 3 ;
766
            `endif
767
        end
768
 
769
        if ( target_mem_image === -1 )
770
        begin
771
            `ifdef PCI_IMAGE4
772
                if ( `PCI_BA4_MEM_IO === 0 )
773
                    target_mem_image = 4 ;
774
                else if ( target_io_image === -1 )
775
                    target_io_image = 4 ;
776
            `endif
777
        end
778
 
779
        if ( target_mem_image === -1 )
780
        begin
781
            `ifdef PCI_IMAGE5
782
                if ( `PCI_BA5_MEM_IO === 0 )
783
                    target_mem_image = 5 ;
784
                else if ( target_io_image === -1 )
785
                    target_io_image = 5 ;
786
            `endif
787
        end
788
    `endif
789
 
790
    tests_successfull = 0 ;
791
    tests_failed = 0 ;
792
 
793
    tb_log_file = $fopen("../log/pci_tb.log") ;
794
 
795
    if ( tb_log_file < 2 )
796
    begin
797
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
798
        $finish ;
799
    end
800
 
801
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
802
    $fdisplay( tb_log_file,"" ) ;
803
 
804
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
805
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
806
 
807
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
808
    begin
809
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
810
        $finish ;
811
    end
812
 
813
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
814
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
815
 
816
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
817
    if ( pci_mon_log_file_desc < 2 )
818
    begin
819
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
820
        $finish ;
821
    end
822
 
823
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
824
 
825
    run_tests ;
826
end
827
 
828
task fill_memory ;
829
    integer temp_index ;
830
begin
831
    // fill write memories with random data
832
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
833
    begin
834
        wmem_data[temp_index[9:0]] = $random ;
835 26 mihad
        # 1;
836 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
837 26 mihad
        # 1;
838 15 mihad
    end
839
    // fill WB slave behavioral MEMORY
840
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
841
    begin
842
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
843
        # 1;
844
    end
845
end
846
endtask // fill_memory
847
 
848
reg [2:0] tb_init_waits ;
849
reg [2:0] tb_subseq_waits ;
850
reg [2:0] tb_target_decode_speed ;
851
 
852
task run_tests ;
853
begin
854
    // first - reset logic
855
    do_reset ;
856 62 mihad
 
857
    // if BIST is implemented, give it a go
858
`ifdef PCI_BIST
859 73 mihad
//    run_bist_test ;
860
scanb_rst <= #1 1'b1 ;
861 62 mihad
`endif
862 45 mihad
    test_initial_conf_values ;
863
 
864 15 mihad
    next_test_name[79:0] <= "Initing...";
865
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
866
 
867
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
868
    begin
869
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
870
        begin
871
 
872
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
873
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
874
 
875
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
876
            begin
877
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
878
 
879
                `ifdef HOST
880
                    configure_bridge_target ;
881
                    find_pci_devices ;
882 45 mihad
                    test_configuration_cycle_target_abort ;
883
                    test_configuration_cycle_type1_generation ;
884 15 mihad
                `endif
885
 
886
                @(posedge pci_clock) ;
887
                configure_target(1) ;
888
                @(posedge pci_clock) ;
889
                configure_target(2) ;
890
 
891
                `ifdef GUEST
892
                    configure_bridge_target ;
893
                `endif
894
 
895
               next_test_name[79:0] <= "WB_SLAVE..";
896
 
897
                $display("Testing WISHBONE slave images' features!") ;
898
                test_wb_image(1) ;
899
 
900
                `ifdef WB_IMAGE2
901
                    test_wb_image(2) ;
902
                `else
903
                    $display(" WB IMAGE 2 not implemented! ") ;
904
                `endif
905
 
906
                `ifdef WB_IMAGE3
907
                    test_wb_image(3) ;
908
                `else
909
                    $display(" WB IMAGE 3 not implemented! ") ;
910
                `endif
911
 
912
                `ifdef WB_IMAGE4
913
                    test_wb_image(4) ;
914
                `else
915
                    $display(" WB IMAGE 4 not implemented! ") ;
916
                `endif
917
 
918
                `ifdef WB_IMAGE5
919
                    test_wb_image(5) ;
920
                `else
921
                    $display(" WB IMAGE 5 not implemented! ") ;
922
                `endif
923
 
924
                wb_slave_errors ;
925
                wb_to_pci_error_handling ;
926
 
927
                parity_checking ;
928
 
929
                wb_to_pci_transactions ;
930
 
931
                `ifdef HOST
932
                iack_cycle ;
933
                `endif
934
 
935 73 mihad
                test_master_overload ;
936
 
937 15 mihad
            end
938 57 mihad
 
939 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
940
        `else
941 57 mihad
            master_completion_expiration ;
942 63 mihad
        `endif
943 57 mihad
 
944 69 mihad
        `ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
945
            master_special_corner_case_test ;
946
        `endif
947
 
948 15 mihad
            $display(" ") ;
949
            $display("WB slave images' tests finished!") ;
950
 
951
            $display("########################################################################") ;
952
            $display("########################################################################") ;
953
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
954
            $display("########################################################################") ;
955
            $display("########################################################################") ;
956
 
957
            $display("Testing PCI target images' features!") ;
958
            configure_bridge_target_base_addresses ;
959 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
960
                test_conf_cycle_type1_reference ;
961
            `endif
962
 
963 15 mihad
            `ifdef HOST
964
             `ifdef NO_CNF_IMAGE
965
              `ifdef PCI_IMAGE0
966
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
967
            test_pci_image(0) ;
968
              `else
969
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
970
              `endif
971
             `else
972
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
973
             `endif
974
            `endif
975
 
976
            $display("PCI image 1 is ALWAYS implemented!") ;
977
            test_pci_image(1) ;
978
 
979
            `ifdef PCI_IMAGE2
980
            $display("PCI image 2 is implemented!") ;
981
            test_pci_image(2) ;
982
            `else
983
            $display("PCI image 2 is NOT implemented!") ;
984
            `endif
985
 
986
            `ifdef PCI_IMAGE3
987
            $display("PCI image 3 is implemented!") ;
988
            test_pci_image(3) ;
989
            `else
990
            $display("PCI image 3 is NOT implemented!") ;
991
            `endif
992
 
993
            `ifdef PCI_IMAGE4
994
            $display("PCI image 4 is implemented!") ;
995
            test_pci_image(4) ;
996
            `else
997
            $display("PCI image 4 is NOT implemented!") ;
998
            `endif
999
 
1000
            `ifdef PCI_IMAGE5
1001
            $display("PCI image 5 is implemented!") ;
1002
            test_pci_image(5) ;
1003
            `else
1004
            $display("PCI image 5 is NOT implemented!") ;
1005
            `endif
1006
 
1007
            test_wb_error_rd ;
1008
 
1009
            target_fast_back_to_back ;
1010
            target_disconnects ;
1011
 
1012 73 mihad
            test_target_overload ;
1013
 
1014 15 mihad
            if ( target_io_image !== -1 )
1015
                test_target_abort( target_io_image ) ;
1016
            $display(" ") ;
1017
            $display("PCI target images' tests finished!") ;
1018
 
1019
            transaction_ordering ;
1020 33 mihad
 
1021 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
1022
        `else
1023 33 mihad
            target_completion_expiration ;
1024 63 mihad
        `endif
1025
 
1026 15 mihad
            $display(" ") ;
1027
            $display("PCI transaction ordering tests finished!") ;
1028
        end
1029
    end
1030
 
1031 73 mihad
    tb_init_waits   = 0 ;
1032
    tb_subseq_waits = 0 ;
1033
 
1034 63 mihad
    `ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
1035
        test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
1036
        test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
1037
        test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
1038
        test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = 0 ;
1039
 
1040
        `ifdef HOST
1041
            configure_bridge_target ;
1042
        `endif
1043
 
1044
        @(posedge pci_clock) ;
1045
        configure_target(1) ;
1046
        @(posedge pci_clock) ;
1047
        configure_target(2) ;
1048
 
1049
        `ifdef GUEST
1050
            configure_bridge_target ;
1051
        `endif
1052
 
1053
        target_special_corner_case_test ;
1054
    `endif
1055
 
1056 73 mihad
    tb_init_waits   = 0 ;
1057
    tb_subseq_waits = 0 ;
1058
 
1059 15 mihad
    test_summary ;
1060
 
1061
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
1062
    $stop ;
1063
end
1064
endtask // run_tests
1065
 
1066
task do_reset;
1067
begin
1068
    next_test_name[79:0] <= "Reset.....";
1069
 
1070
    reset = 1'b1 ;
1071
    #100 ;
1072
    `ifdef HOST
1073
        @(posedge wb_clock) ;
1074
    `else
1075
    `ifdef GUEST
1076
        @(posedge pci_clock) ;
1077
    `endif
1078
    `endif
1079
 
1080
    reset <= 1'b0 ;
1081
 
1082 45 mihad
    `ifdef HOST
1083
        @(posedge wb_clock) ;
1084
    `else
1085
    `ifdef GUEST
1086
        @(posedge pci_clock) ;
1087
    `endif
1088
    `endif
1089
 
1090 15 mihad
end
1091
endtask
1092
 
1093
/*############################################################################
1094
WB SLAVE UNIT tasks
1095
===================
1096
############################################################################*/
1097
 
1098
task configure_target ;
1099 45 mihad
    input [1:0]  beh_dev_num ;
1100 15 mihad
    reg   [31:0] base_address1 ;
1101
    reg   [31:0] base_address2 ;
1102
    reg   [2:0]  Master_ID;
1103
    reg   [31:0] Target_Config_Addr;
1104 45 mihad
    reg   [4:0]  device_num ;
1105 15 mihad
begin
1106 45 mihad
    if (beh_dev_num === 1)
1107 15 mihad
    begin
1108
        base_address1       = `BEH_TAR1_MEM_START ;
1109
        base_address2       = `BEH_TAR1_IO_START  ;
1110
        Master_ID           = `Test_Master_2 ;
1111
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1112 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1113 15 mihad
    end
1114
    else
1115 45 mihad
    if (beh_dev_num === 2)
1116 15 mihad
    begin
1117
        base_address1       = `BEH_TAR2_MEM_START ;
1118
        base_address2       = `BEH_TAR2_IO_START  ;
1119
        Master_ID           = `Test_Master_1 ;
1120
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1121 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1122 15 mihad
    end
1123
 
1124
    // write target's base addresses
1125
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1126
    // type 0 cycle, byte enables, base address
1127
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1128
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1129
 
1130
    // enable target's response and master
1131
    // enable parity errors, disable system error
1132
 
1133
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1134
 
1135
end
1136
endtask //configure_target
1137
 
1138
task test_wb_image ;
1139
    input [2:0]  image_num ;
1140
    reg   [11:0] ctrl_offset ;
1141
    reg   [11:0] ba_offset ;
1142
    reg   [11:0] am_offset ;
1143
    reg   [11:0] ta_offset ;
1144
    reg   [11:0] err_cs_offset ;
1145
    reg `WRITE_STIM_TYPE write_data ;
1146
    reg `READ_STIM_TYPE  read_data ;
1147
    reg `READ_RETURN_TYPE read_status ;
1148
 
1149
    reg `WRITE_RETURN_TYPE write_status ;
1150
    reg `WB_TRANSFER_FLAGS write_flags ;
1151
    reg [31:0] temp_val ;
1152
    reg        ok   ;
1153
    reg [11:0] pci_ctrl_offset ;
1154
    reg [31:0] image_base ;
1155
    reg [31:0] target_address ;
1156
    reg [31:0] translation_address ;
1157
    integer    i ;
1158
    integer    j ;
1159
begin:main
1160
    pci_ctrl_offset = 12'h4 ;
1161
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1162
    // image 0 can only be configuration image - start with 1
1163
    if (image_num === 1)
1164
    begin
1165
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1166
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1167
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1168
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1169
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1170
    end
1171
    else if (image_num === 2)
1172
    begin
1173
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1174
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1175
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1176
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1177
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1178
    end
1179
    else if (image_num === 3)
1180
    begin
1181
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1182
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1183
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1184
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1185
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1186
    end
1187
    else if (image_num === 4)
1188
    begin
1189
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1190
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1191
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1192
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1193
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1194
    end
1195
    else if (image_num === 5)
1196
    begin
1197
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1198
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1199
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1200
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1201
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1202
    end
1203
    else
1204
    begin
1205
        test_name   = "WB IMAGES' FEATURES TEST" ;
1206
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1207
        disable main ;
1208
    end
1209
 
1210
    target_address  = `BEH_TAR1_MEM_START ;
1211
    image_base      = 0 ;
1212
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1213
 
1214
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1215
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1216
    write_flags                      = 0 ;
1217
    write_flags`INIT_WAITS           = tb_init_waits ;
1218
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1219
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1220
 
1221
    test_name = "WB IMAGE CONFIGURATION" ;
1222
    // enable master & target operation
1223
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1224
    if ( ok !== 1 )
1225
    begin
1226 69 mihad
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1227 15 mihad
        test_fail("write to PCI Device Control register didn't succeede");
1228
        disable main ;
1229
    end
1230
 
1231
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1232
    if ( ok !== 1 )
1233
    begin
1234 69 mihad
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", $time) ;
1235 15 mihad
        test_fail("write to WB Error Control and Status register didn't succeede");
1236
        disable main ;
1237
    end
1238
 
1239
    // prepare image control register
1240
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1241
    if ( ok !== 1 )
1242
    begin
1243
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1244
        test_fail("write to WB Image Control register didn't succeede");
1245
        disable main ;
1246
    end
1247
 
1248
    // prepare base address register
1249
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1250
    if ( ok !== 1 )
1251
    begin
1252
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1253
        test_fail("write to WB Base Address register didn't succeede");
1254
        disable main ;
1255
    end
1256
 
1257
    // write address mask register
1258
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1259
    if ( ok !== 1 )
1260
    begin
1261
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1262
        test_fail("write to WB Address Mask register didn't succeede");
1263
        disable main ;
1264
    end
1265
 
1266
    fork
1267
    begin
1268
        write_data`WRITE_ADDRESS = target_address ;
1269
        write_data`WRITE_DATA    = wmem_data[0] ;
1270
        write_data`WRITE_SEL     = 4'hF ;
1271
 
1272
        // handle retries from now on
1273
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1274
 
1275
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1276
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1277
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1278
        begin
1279
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1280
            test_fail("WB Slave state machine failed to post single memory write");
1281
            disable main ;
1282
        end
1283
 
1284
        // read written data back
1285
        read_data`READ_ADDRESS  = target_address ;
1286
        read_data`READ_SEL      = 4'hF ;
1287
        read_data`READ_TAG_STIM = 0 ;
1288
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1289
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1290
        begin
1291
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1292
            test_fail("PCI bridge didn't process the read as expected");
1293
            disable main ;
1294
        end
1295
 
1296
        if (read_status`READ_DATA !== wmem_data[0])
1297
        begin
1298
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1299
            test_fail("PCI bridge returned unexpected Read Data");
1300
        end
1301
        else
1302
            test_ok ;
1303
    end
1304
    begin
1305
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1306
        if ( ok !== 1 )
1307
        begin
1308
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1309
        end
1310
        else
1311
            test_ok ;
1312
 
1313
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1314
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1315
        if ( ok !== 1 )
1316
        begin
1317
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1318
        end
1319
    end
1320
    join
1321
 
1322
    // if address translation is implemented - try it out
1323
    translation_address = image_base ;
1324
    `ifdef ADDR_TRAN_IMPL
1325
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1326
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1327
    if ( ok !== 1 )
1328
    begin
1329
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1330
        test_fail("write to WB Image Translation Address Register failed") ;
1331
        disable main ;
1332
    end
1333
 
1334
    target_address  = `BEH_TAR2_MEM_START ;
1335
    image_base      = 0 ;
1336
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1337
 
1338
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1339
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1340
 
1341
    write_flags                      = 0 ;
1342
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1343
 
1344
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1345
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1346
    if ( ok !== 1 )
1347
    begin
1348
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1349
        test_fail("write to WB Image Base Address Register failed") ;
1350
        disable main ;
1351
    end
1352
 
1353
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1354
    // enable address translation
1355
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1356
    if ( ok !== 1 )
1357
    begin
1358
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1359
        test_fail("write to WB Image Control Register failed") ;
1360
        disable main ;
1361
    end
1362
 
1363
    `endif
1364
 
1365
    fork
1366
    begin
1367
        write_data`WRITE_ADDRESS = target_address + 4 ;
1368
        write_data`WRITE_DATA    = wmem_data[1] ;
1369
        write_data`WRITE_SEL     = 4'hF ;
1370
 
1371
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1372
 
1373
        `ifdef ADDR_TRAN_IMPL
1374
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1375
        `else
1376
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1377
        `endif
1378
 
1379
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1380
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1381
        begin
1382
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1383
            test_fail("WB Slave state machine failed to post single memory write") ;
1384
            disable main ;
1385
        end
1386
 
1387
        // read written data back
1388
        read_data`READ_ADDRESS  = target_address + 4 ;
1389
        read_data`READ_SEL      = 4'hF ;
1390
        read_data`READ_TAG_STIM = 0 ;
1391
 
1392
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1393
 
1394
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1395
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1396
        begin
1397
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1398
            test_fail("PCI bridge failed to process single delayed memory read") ;
1399
            disable main ;
1400
        end
1401
 
1402
        if (read_status`READ_DATA !== wmem_data[1])
1403
        begin
1404
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1405
            test_fail("PCI bridge returned unexpected Read Data");
1406
        end
1407
        else
1408
            test_ok ;
1409
    end
1410
    begin
1411
        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 ) ;
1412
        if ( ok !== 1 )
1413
        begin
1414
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1415
        end
1416
        else
1417
            test_ok ;
1418
 
1419
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1420
        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 ) ;
1421
        if ( ok !== 1 )
1422
        begin
1423
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1424
        end
1425
    end
1426
    join
1427
 
1428
    // 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
1429
    // prepare write data
1430
    for ( i = 0 ; i < 6 ; i = i + 1 )
1431
    begin
1432
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1433
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1434
        write_data`WRITE_SEL     = 4'hF ;
1435
        wishbone_master.blk_write_data[i] = write_data ;
1436
    end
1437
 
1438
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1439
    write_flags`WB_TRANSFER_CAB    = 1 ;
1440
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1441
 
1442
    fork
1443
    begin
1444
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1445
        wishbone_master.wb_block_write(write_flags, write_status) ;
1446
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1447
        begin
1448
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1449
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1450
            disable main ;
1451
        end
1452
    end
1453
    begin
1454
        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 ) ;
1455
        if ( ok !== 1 )
1456
        begin
1457
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1458
        end
1459
        else
1460
            test_ok ;
1461
    end
1462
    join
1463
 
1464
    // set burst size and latency timer
1465
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1466
 
1467
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1468
    write_flags`WB_TRANSFER_CAB    = 1 ;
1469
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1470
 
1471
    // prepare read data
1472
    for ( i = 0 ; i < 4 ; i = i + 1 )
1473
    begin
1474
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1475
        read_data`READ_SEL     = 4'hF ;
1476
        wishbone_master.blk_read_data_in[i] = read_data ;
1477
    end
1478
 
1479
    fork
1480
    begin
1481
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1482
        wishbone_master.wb_block_read(write_flags, read_status) ;
1483
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1484
        begin
1485
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1486
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1487
            disable main ;
1488
        end
1489
 
1490
        // check data read from target
1491
        for ( i = 0 ; i < 4 ; i = i + 1 )
1492
        begin
1493
            read_status = wishbone_master.blk_read_data_out[i] ;
1494
            if (read_status`READ_DATA !== wmem_data[2 + i])
1495
            begin
1496
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1497
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1498
            end
1499
        end
1500
    end
1501
    begin
1502
        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 ) ;
1503
        if ( ok !== 1 )
1504
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1505
        else
1506
            test_ok ;
1507
 
1508
        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 ) ;
1509
        if ( ok !== 1 )
1510
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1511
        else
1512
            test_ok ;
1513
 
1514
        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 ) ;
1515
        if ( ok !== 1 )
1516
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1517
        else
1518
            test_ok ;
1519
 
1520
        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 ) ;
1521
        if ( ok !== 1 )
1522
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1523
        else
1524
            test_ok ;
1525
 
1526
    end
1527
    join
1528
 
1529
    // now repeat this same burst read with various image features enabled or disabled
1530
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1531
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1532
    if (ok !== 1)
1533
    begin
1534
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1535
        test_fail("write to WB Image control register failed") ;
1536
        disable main ;
1537
    end
1538
 
1539
    fork
1540
    begin
1541
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1542
        wishbone_master.wb_block_read(write_flags, read_status) ;
1543
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1544
        begin
1545
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1546
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1547
            disable main ;
1548
        end
1549
 
1550
        // check data read from target
1551
        for ( i = 0 ; i < 4 ; i = i + 1 )
1552
        begin
1553
            read_status = wishbone_master.blk_read_data_out[i] ;
1554
            if (read_status`READ_DATA !== wmem_data[2 + i])
1555
            begin
1556
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1557
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1558
            end
1559
            else
1560
                test_ok ;
1561
        end
1562
    end
1563
    begin
1564
        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 ) ;
1565
        if ( ok !== 1 )
1566
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1567
    end
1568
    join
1569
 
1570
    read_data`READ_ADDRESS  = target_address ;
1571
    read_data`READ_SEL      = 4'hF ;
1572
    read_data`READ_TAG_STIM = 0 ;
1573
 
1574
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1575
    fork
1576
    begin
1577
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1578
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1579
        begin
1580
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1581
            test_fail("delayed single memory read wasn't processed as expected") ;
1582
            disable main ;
1583
        end
1584
 
1585
        if (read_status`READ_DATA !== wmem_data[0])
1586
        begin
1587
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1588
            test_fail("delayed single memory read data value returned was not as expected") ;
1589
        end
1590
        else
1591
            test_ok ;
1592
    end
1593
    begin
1594
        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 ) ;
1595
        if ( ok !== 1 )
1596
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1597
    end
1598
    join
1599
 
1600
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1601
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1602
    if (ok !== 1)
1603
    begin
1604
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1605
        test_fail("write to WB Image control register failed") ;
1606
        disable main ;
1607
    end
1608
 
1609
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1610
    fork
1611
    begin
1612
        wishbone_master.wb_block_read(write_flags, read_status) ;
1613
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1614
        begin
1615
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1616
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1617
            disable main ;
1618
        end
1619
 
1620
        // check data read from target
1621
        for ( i = 0 ; i < 4 ; i = i + 1 )
1622
        begin
1623
            read_status = wishbone_master.blk_read_data_out[i] ;
1624
            if (read_status`READ_DATA !== wmem_data[2 + i])
1625
            begin
1626
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1627
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1628
            end
1629
            else
1630
                test_ok ;
1631
        end
1632
    end
1633
    begin
1634
        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 ) ;
1635
        if ( ok !== 1 )
1636
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1637
    end
1638
    join
1639
 
1640
    read_data`READ_ADDRESS  = target_address + 4 ;
1641
    read_data`READ_SEL      = 4'hF ;
1642
    read_data`READ_TAG_STIM = 0 ;
1643
 
1644
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1645
    fork
1646
    begin
1647
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1648
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1649
        begin
1650
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1651
            test_fail("delayed single memory read wasn't processed as expected") ;
1652
            disable main ;
1653
        end
1654
 
1655
        if (read_status`READ_DATA !== wmem_data[1])
1656
        begin
1657
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1658
            test_fail("delayed single memory read data value returned was not as expected") ;
1659
        end
1660
        else
1661
            test_ok ;
1662
    end
1663
    begin
1664
        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 ) ;
1665
        if ( ok !== 1 )
1666
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1667
    end
1668
    join
1669
 
1670
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1671
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1672
    if (ok !== 1)
1673
    begin
1674
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1675
        test_fail("write to WB Image control register failed") ;
1676
        disable main ;
1677
    end
1678
 
1679
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1680
    fork
1681
    begin
1682
        wishbone_master.wb_block_read(write_flags, read_status) ;
1683
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1684
        begin
1685
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1686
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1687
            disable main ;
1688
        end
1689
 
1690
        // check data read from target
1691
        for ( i = 0 ; i < 4 ; i = i + 1 )
1692
        begin
1693
            read_status = wishbone_master.blk_read_data_out[i] ;
1694
            if (read_status`READ_DATA !== wmem_data[2 + i])
1695
            begin
1696
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1697
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1698
            end
1699
            else
1700
                test_ok ;
1701
        end
1702
    end
1703
    begin
1704
        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 ) ;
1705
        if ( ok !== 1 )
1706
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1707
    end
1708
    join
1709
 
1710
    read_data`READ_ADDRESS  = target_address + 8 ;
1711
    read_data`READ_SEL      = 4'hF ;
1712
    read_data`READ_TAG_STIM = 0 ;
1713
 
1714
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1715
    fork
1716
    begin
1717
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1718
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1719
        begin
1720
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1721
            test_fail("delayed single memory read wasn't processed as expected") ;
1722
            disable main ;
1723
        end
1724
 
1725
        if (read_status`READ_DATA !== wmem_data[2])
1726
        begin
1727
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1728
            test_fail("delayed single memory read data value returned was not as expected") ;
1729
        end
1730
        else
1731
            test_ok ;
1732
    end
1733
    begin
1734
        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 ) ;
1735
        if ( ok !== 1 )
1736
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1737
    end
1738
    join
1739
 
1740
    // map image to IO space
1741
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1742
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1743
    if ( ok !== 1 )
1744
    begin
1745
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1746
        test_fail("write to WB Image Base Address register failed") ;
1747
        disable main ;
1748
    end
1749
 
1750
    write_data`WRITE_ADDRESS = target_address ;
1751
    write_data`WRITE_DATA    = wmem_data[11] ;
1752
    write_data`WRITE_SEL     = 4'hF ;
1753
 
1754
    // handle retries from now on
1755
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1756
 
1757
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1758
    fork
1759
    begin
1760
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1761
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1762
        begin
1763
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1764
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1765
            disable main ;
1766
        end
1767
    end
1768
    begin
1769
        // currently IO commands not supported in behavioral models - master abort
1770
        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 ) ;
1771
        if ( ok !== 1 )
1772
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1773
        else
1774
            test_ok ;
1775
    end
1776
    join
1777
 
1778
    read_data`READ_ADDRESS  = target_address ;
1779
    read_data`READ_SEL      = 4'hF ;
1780
    read_data`READ_TAG_STIM = 0 ;
1781
 
1782
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1783
 
1784
    // currently io commands are not supported by behavioral target - transfer should not be completed
1785
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1786
    fork
1787
    begin
1788
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1789
        if (read_status`CYC_ERR !== 1)
1790
        begin
1791
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1792
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1793
            disable main ;
1794
        end
1795
        else
1796
            test_ok ;
1797
    end
1798
    begin
1799
        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 ) ;
1800
        if ( ok !== 1 )
1801
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1802
    end
1803
    join
1804
 
1805
    // test byte addressing
1806
    read_data`READ_ADDRESS = target_address + 2 ;
1807
    read_data`READ_SEL     = 4'b1100 ;
1808
 
1809
    fork
1810
    begin
1811
        // currently io commands are not supported by behavioral target - transfer should not be completed
1812
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1813
        if (read_status`CYC_ERR !== 1)
1814
        begin
1815
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1816
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1817
            disable main ;
1818
        end
1819
        else test_ok ;
1820
    end
1821
    begin
1822
        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 ) ;
1823
        if ( ok !== 1 )
1824
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1825
    end
1826
    join
1827
 
1828
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1829
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1830
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1831
    if ( ok !== 1 )
1832
    begin
1833
        test_fail("WB Base address register could not be written") ;
1834
        disable main ;
1835
    end
1836
 
1837
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1838
    if ( ok !== 1 )
1839
    begin
1840
        test_fail("WB Address Mask register could not be written") ;
1841
        disable main ;
1842
    end
1843
 
1844
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1845
    if ( ok !== 1 )
1846
    begin
1847
        test_fail("WB Image Control register could not be written") ;
1848
        disable main ;
1849
    end
1850
 
1851
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1852
    write_data`WRITE_DATA    = wmem_data[11] ;
1853
    write_data`WRITE_SEL     = 4'b1000 ;
1854
 
1855
    // handle retries from now on
1856
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1857
 
1858
    fork
1859
    begin
1860
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1861
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1862
        begin
1863
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1864
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1865
            disable main ;
1866
        end
1867
    end
1868
    begin
1869
        // currently IO commands not supported in behavioral models - master abort
1870
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1871
        if ( ok !== 1 )
1872
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1873
        else
1874
            test_ok ;
1875
    end
1876
    join
1877
 
1878
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1879
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1880
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1881
 
1882
    fork
1883
    begin
1884
        // currently io commands are not supported by behavioral target - transfer should not be completed
1885
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1886
        if (read_status`CYC_ERR !== 1)
1887
        begin
1888
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1889
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1890
            disable main ;
1891
        end
1892
        else test_ok ;
1893
    end
1894
    begin
1895
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1896
        if ( ok !== 1 )
1897
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1898
    end
1899
    join
1900
 
1901
    test_name = "DISABLING WB IMAGE" ;
1902
 
1903
    // disable current image
1904
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1905
    if ( ok !== 1 )
1906
    begin
1907
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1908
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1909
        disable main ;
1910
    end
1911
 
1912
    // clear master abort status bit
1913
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1914
    if ( ok !== 1 )
1915
    begin
1916
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1917
        test_fail("write to PCI Device Status register not accepted as expected") ;
1918
        disable main ;
1919
    end
1920
 
1921
end //main
1922
endtask //test_wb_image
1923
 
1924
task wb_slave_errors ;
1925
    reg   [11:0] ctrl_offset ;
1926
    reg   [11:0] ba_offset ;
1927
    reg   [11:0] am_offset ;
1928
    reg   [11:0] ta_offset ;
1929
    reg `WRITE_STIM_TYPE write_data ;
1930
    reg `READ_STIM_TYPE  read_data ;
1931
    reg `READ_RETURN_TYPE read_status ;
1932
 
1933
    reg `WRITE_RETURN_TYPE write_status ;
1934
    reg `WB_TRANSFER_FLAGS write_flags ;
1935
    reg [31:0] temp_val1 ;
1936
    reg [31:0] temp_val2 ;
1937
    reg        ok   ;
1938
    reg [11:0] pci_ctrl_offset ;
1939
    reg [31:0] image_base ;
1940
    reg [31:0] target_address ;
1941
    integer    i ;
1942
    reg skip ;
1943
fork
1944
begin:main
1945
 
1946
    `ifdef GUEST
1947
        skip = 1 ;
1948
    `else
1949
        skip = 0 ;
1950
    `endif
1951
 
1952
    pci_ctrl_offset = 12'h4 ;
1953
 
1954
    // image 1 is used for error testing, since it is always implemented
1955
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1956
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1957
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1958
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1959
 
1960
    target_address  = `BEH_TAR1_MEM_START ;
1961
    image_base      = 0 ;
1962
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1963
 
1964
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1965
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1966
    write_flags                    = 0 ;
1967
    write_flags`INIT_WAITS         = tb_init_waits ;
1968
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1969
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1970
 
1971
    // enable master & target operation
1972
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1973
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1974
    if ( ok !== 1 )
1975
    begin
1976
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1977
        test_fail("PCI Device Control register couldn't be written") ;
1978
        disable no_transaction ;
1979
        disable main ;
1980
    end
1981
 
1982
    // prepare image control register
1983
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1984
    if ( ok !== 1 )
1985
    begin
1986
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1987
        test_fail("WB Image Control register couldn't be written") ;
1988
        disable no_transaction ;
1989
        disable main ;
1990
    end
1991
 
1992
    // prepare base address register
1993
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1994
    if ( ok !== 1 )
1995
    begin
1996
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1997
        test_fail("WB Base Address register couldn't be written") ;
1998
        disable no_transaction ;
1999
        disable main ;
2000
    end
2001
 
2002
    // write address mask register
2003
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2004
    if ( ok !== 1 )
2005
    begin
2006
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2007
        test_fail("WB Address Mask register couldn't be written") ;
2008
        disable no_transaction ;
2009
        disable main ;
2010
    end
2011
 
2012
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2013
 
2014
    skip = 0 ;
2015
 
2016
    // memory mapped image - access is erroneous when address is not alligned
2017
    write_data`WRITE_ADDRESS = target_address + 1 ;
2018
    write_data`WRITE_DATA    = wmem_data[0] ;
2019
    write_data`WRITE_SEL     = 4'hF ;
2020
 
2021
    // handle retries from now on
2022
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2023
 
2024
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
2025
 
2026
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2027
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2028
    begin
2029
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2030
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2031
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2032
        disable no_transaction ;
2033
        disable main ;
2034
    end
2035
 
2036
    write_data`WRITE_ADDRESS = target_address + 2 ;
2037
 
2038
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2039
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2040
    begin
2041
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2042
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2043
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2044
        disable no_transaction ;
2045
        disable main ;
2046
 
2047
    end
2048
 
2049
    write_data`WRITE_ADDRESS = target_address + 3 ;
2050
 
2051
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2052
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_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 write as expected") ;
2057
        disable no_transaction ;
2058
        disable main ;
2059
    end
2060
 
2061
    test_ok ;
2062
 
2063
    // perform same tests for read accesses
2064
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
2065
 
2066
    read_data`READ_ADDRESS  = target_address + 2 ;
2067
    read_data`READ_SEL      = 4'hF ;
2068
    read_data`READ_TAG_STIM = 0 ;
2069
 
2070
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2071
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2072
    begin
2073
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2074
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2075
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
2076
        disable no_transaction ;
2077
        disable main ;
2078
    end
2079
 
2080
    test_ok ;
2081
 
2082
    // prepare write data
2083
    for ( i = 0 ; i < 6 ; i = i + 1 )
2084
    begin
2085
        write_data`WRITE_DATA    = wmem_data[i] ;
2086
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
2087
        write_data`WRITE_SEL     = 4'hF ;
2088
        wishbone_master.blk_write_data[i] = write_data ;
2089
    end
2090
 
2091
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2092
    write_flags`WB_TRANSFER_CAB    = 1 ;
2093
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2094
 
2095
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
2096
    wishbone_master.wb_block_write(write_flags, write_status) ;
2097
 
2098
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2099
    begin
2100
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2101
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2102
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
2103
        disable no_transaction ;
2104
        disable main ;
2105
    end
2106
 
2107
    // prepare read data
2108
    for ( i = 0 ; i < 6 ; i = i + 1 )
2109
    begin
2110
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2111
        read_data`READ_SEL     = 4'hF ;
2112
        wishbone_master.blk_read_data_in[i] = read_data ;
2113
    end
2114
 
2115
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2116
    wishbone_master.wb_block_read(write_flags, read_status) ;
2117
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2118
    begin
2119
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2120
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2121
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2122
        disable no_transaction ;
2123
        disable main ;
2124
    end
2125
 
2126
    test_ok ;
2127
 
2128
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2129
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2130
 
2131
    // map image to IO space
2132
    `ifdef GUEST
2133
        skip = 1 ;
2134
    `endif
2135
 
2136
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2137
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2138
    if ( ok !== 1 )
2139
    begin
2140
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2141
        test_fail("WB Image Base Address register couldn't be written") ;
2142
        disable no_transaction ;
2143
        disable main ;
2144
    end
2145
 
2146
    skip = 0 ;
2147
 
2148
    write_data`WRITE_ADDRESS = target_address ;
2149
    write_data`WRITE_DATA    = wmem_data[0] ;
2150
    write_data`WRITE_SEL     = 4'b1010 ;
2151
 
2152
    // don't handle retries
2153
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2154
 
2155
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2156
 
2157
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2158
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2159
    begin
2160
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2161
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2162
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2163
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2164
        disable no_transaction ;
2165
        disable main ;
2166
    end
2167
 
2168
    write_data`WRITE_ADDRESS = target_address + 1 ;
2169
    write_data`WRITE_SEL     = 4'b0011 ;
2170
 
2171
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2172
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2173
    begin
2174
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2175
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2176
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2177
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2178
        disable no_transaction ;
2179
        disable main ;
2180
    end
2181
 
2182
    write_data`WRITE_SEL     = 4'b1100 ;
2183
 
2184
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2185
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2186
    begin
2187
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2188
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2189
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2190
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2191
        disable no_transaction ;
2192
        disable main ;
2193
    end
2194
 
2195
    write_data`WRITE_ADDRESS = target_address + 2 ;
2196
    write_data`WRITE_SEL     = 4'b0101 ;
2197
 
2198
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2199
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2200
    begin
2201
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2202
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2203
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2204
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2205
        disable no_transaction ;
2206
        disable main ;
2207
    end
2208
 
2209
    write_data`WRITE_SEL     = 4'b1000 ;
2210
 
2211
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2212
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2213
    begin
2214
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2215
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2216
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2217
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2218
        disable no_transaction ;
2219
        disable main ;
2220
    end
2221
 
2222
    write_data`WRITE_ADDRESS = target_address + 3 ;
2223
    write_data`WRITE_SEL     = 4'b1010 ;
2224
 
2225
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2226
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2227
    begin
2228
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2229
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2230
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2231
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2232
        disable no_transaction ;
2233
        disable main ;
2234
    end
2235
 
2236
    write_data`WRITE_SEL     = 4'b0110 ;
2237
 
2238
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2239
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_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 write as expected") ;
2245
        disable no_transaction ;
2246
        disable main ;
2247
    end
2248
 
2249
    test_ok ;
2250
 
2251
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2252
 
2253
    read_data`READ_ADDRESS  = target_address + 3 ;
2254
    read_data`READ_SEL      = 4'hF ;
2255
    read_data`READ_TAG_STIM = 0 ;
2256
 
2257
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2258
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2259
    begin
2260
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2261
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2262
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2263
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2264
        disable no_transaction ;
2265
        disable main ;
2266
    end
2267
 
2268
    test_ok ;
2269
 
2270
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2271
    // prepare write data
2272
    for ( i = 0 ; i < 6 ; i = i + 1 )
2273
    begin
2274
        write_data`WRITE_DATA    = wmem_data[i] ;
2275
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2276
        write_data`WRITE_SEL     = 4'hF ;
2277
        wishbone_master.blk_write_data[i] = write_data ;
2278
    end
2279
 
2280
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2281
    write_flags`WB_TRANSFER_CAB    = 1 ;
2282
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2283
 
2284
    wishbone_master.wb_block_write(write_flags, write_status) ;
2285
 
2286
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2287
    begin
2288
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2289
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2290
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2291
        disable no_transaction ;
2292
        disable main ;
2293
    end
2294
 
2295
    test_ok ;
2296
 
2297
    test_name = "CAB I/O READ TO WB SLAVE" ;
2298
    // prepare read data
2299
    for ( i = 0 ; i < 6 ; i = i + 1 )
2300
    begin
2301
        read_data`READ_ADDRESS = target_address + 4*i ;
2302
        read_data`READ_SEL     = 4'hF ;
2303
        wishbone_master.blk_read_data_in[i] = read_data ;
2304
    end
2305
 
2306
    wishbone_master.wb_block_read(write_flags, read_status) ;
2307
 
2308
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2309
    begin
2310
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2311
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2312
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2313
        disable no_transaction ;
2314
        disable main ;
2315
    end
2316
 
2317
    test_ok ;
2318
 
2319
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2320
 
2321
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2322
 
2323
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2324
    write_data`WRITE_ADDRESS = target_address + 1 ;
2325
    write_data`WRITE_DATA    = wmem_data[0] ;
2326
    write_data`WRITE_SEL     = 4'hF ;
2327
 
2328
    // don't handle retries
2329
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2330
 
2331
    `ifdef HOST
2332
        `define DO_W_CONF_TEST
2333
        `define DO_R_CONF_TEST
2334
    `else
2335
        `ifdef WB_CNF_IMAGE
2336
             `define DO_R_CONF_TEST
2337
        `endif
2338
    `endif
2339
 
2340
    `ifdef DO_W_CONF_TEST
2341
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2342
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2343
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2344
    begin
2345
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2346
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2347
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2348
        disable no_transaction ;
2349
        disable main ;
2350
    end
2351
 
2352
    write_data`WRITE_ADDRESS = target_address + 2 ;
2353
 
2354
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2355
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2356
    begin
2357
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2358
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2359
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2360
        disable no_transaction ;
2361
        disable main ;
2362
    end
2363
 
2364
    write_data`WRITE_ADDRESS = target_address + 3 ;
2365
 
2366
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2367
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_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 write as expected") ;
2372
        disable no_transaction ;
2373
        disable main ;
2374
    end
2375
 
2376
    test_ok ;
2377
    `endif
2378
 
2379
    `ifdef DO_R_CONF_TEST
2380
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2381
    read_data`READ_ADDRESS  = target_address + 3 ;
2382
    read_data`READ_SEL      = 4'hF ;
2383
    read_data`READ_TAG_STIM = 0 ;
2384
 
2385
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2386
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2387
    begin
2388
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2389
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2390
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2391
        disable no_transaction ;
2392
        disable main ;
2393
    end
2394
 
2395
    test_ok ;
2396
    `endif
2397
 
2398
    `ifdef DO_W_CONF_TEST
2399
    // prepare write data
2400
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2401
    for ( i = 0 ; i < 6 ; i = i + 1 )
2402
    begin
2403
        write_data`WRITE_DATA    = wmem_data[i] ;
2404
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2405
        write_data`WRITE_SEL     = 4'hF ;
2406
        wishbone_master.blk_write_data[i] = write_data ;
2407
    end
2408
 
2409
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2410
    write_flags`WB_TRANSFER_CAB    = 1 ;
2411
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2412
 
2413
    wishbone_master.wb_block_write(write_flags, write_status) ;
2414
 
2415
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2416
    begin
2417
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2418
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2419
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2420
        disable no_transaction ;
2421
        disable main ;
2422
    end
2423
    test_ok ;
2424
    `endif
2425
 
2426
    `ifdef DO_R_CONF_TEST
2427
    // prepare read data
2428
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2429
    for ( i = 0 ; i < 6 ; i = i + 1 )
2430
    begin
2431
        read_data`READ_ADDRESS = target_address + 4*i ;
2432
        read_data`READ_SEL     = 4'hF ;
2433
        wishbone_master.blk_read_data_in[i] = read_data ;
2434
    end
2435
 
2436
    wishbone_master.wb_block_read(write_flags, read_status) ;
2437
 
2438
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2439
    begin
2440
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2441
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2442
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2443
        disable no_transaction ;
2444
        disable main ;
2445
    end
2446
    test_ok ;
2447
    `endif
2448
 
2449
    `ifdef GUEST
2450
        skip = 1 ;
2451
    `endif
2452
 
2453
    // disable image
2454
    test_name = "DISABLE IMAGE" ;
2455
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2456
    if ( ok !== 1 )
2457
    begin
2458
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2459
        test_fail("WB Address Mask register couldn't be written") ;
2460
        disable no_transaction ;
2461
        disable main ;
2462
    end
2463
 
2464
    skip = 0 ;
2465
 
2466
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2467
 
2468
    disable no_transaction ;
2469
end
2470
begin:no_transaction
2471
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2472
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2473
    forever
2474
    begin
2475
        @(posedge pci_clock) ;
2476
        if ( skip !== 1 )
2477
        begin
2478
            if ( FRAME !== 1 )
2479
            begin
2480
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2481
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2482
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2483
            end
2484
        end
2485
    end
2486
end
2487
join
2488
endtask //wb_slave_errors
2489
 
2490
task wb_to_pci_error_handling ;
2491
    reg   [11:0] ctrl_offset ;
2492
    reg   [11:0] ba_offset ;
2493
    reg   [11:0] am_offset ;
2494
    reg   [11:0] ta_offset ;
2495
    reg   [11:0] err_cs_offset ;
2496
    reg `WRITE_STIM_TYPE write_data ;
2497
    reg `READ_STIM_TYPE  read_data ;
2498
    reg `READ_RETURN_TYPE read_status ;
2499
 
2500
    reg `WRITE_RETURN_TYPE write_status ;
2501
    reg `WB_TRANSFER_FLAGS write_flags ;
2502
    reg [31:0] temp_val1 ;
2503
    reg [31:0] temp_val2 ;
2504
    reg        ok   ;
2505
    reg [11:0] pci_ctrl_offset ;
2506
    reg [31:0] image_base ;
2507
    reg [31:0] target_address ;
2508
    integer    num_of_trans ;
2509
    integer    current ;
2510
    integer    i ;
2511
begin:main
2512
 
2513
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2514
 
2515
    pci_ctrl_offset = 12'h4 ;
2516
 
2517
    // disable error interrupts and disable error reporting
2518
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2519
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2520
    if ( ok !== 1 )
2521
    begin
2522
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2523
        test_fail("PCI Device Control register couldn't be written") ;
2524
        disable main ;
2525
    end
2526
 
2527
    // image 1 is used for error testing, since it is always implemented
2528
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2529
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2530
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2531
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2532
 
2533
    // set master abort testing address to address that goes out of target's range
2534
    target_address  = `BEH_TAR1_MEM_START ;
2535
    image_base      = 0 ;
2536
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2537
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2538
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2539
 
2540
    write_flags                    = 0 ;
2541
    write_flags`INIT_WAITS         = tb_init_waits ;
2542
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2543
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2544
 
2545
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2546
 
2547
    // enable master & target operation
2548
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2549
    if ( ok !== 1 )
2550
    begin
2551
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2552
        test_fail("PCI Device Control register couldn't be written") ;
2553
        disable main ;
2554
    end
2555
 
2556
    // prepare image control register
2557
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2558
    if ( ok !== 1 )
2559
    begin
2560
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2561
        test_fail("WB Image Control register couldn't be written") ;
2562
        disable main ;
2563
    end
2564
 
2565
    // prepare base address register
2566
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2567
    if ( ok !== 1 )
2568
    begin
2569
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2570
        test_fail("WB Image Base Address register couldn't be written") ;
2571
        disable main ;
2572
    end
2573
 
2574
    // write address mask register
2575
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2576
    if ( ok !== 1 )
2577
    begin
2578
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2579
        test_fail("WB Image Address Mask register couldn't be written") ;
2580
        disable main ;
2581
    end
2582
 
2583
    // disable error reporting
2584
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2585
    if ( ~ok )
2586
    begin
2587
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2588
        test_fail("WB Error Control and Status register couldn't be written") ;
2589
        disable main ;
2590
    end
2591
 
2592
    // perform two writes - one to error address and one to OK address
2593
    // prepare write buffer
2594
 
2595
    write_data`WRITE_ADDRESS = target_address ;
2596
    write_data`WRITE_DATA    = wmem_data[100] ;
2597
    write_data`WRITE_SEL     = 4'hF ;
2598
 
2599
    wishbone_master.blk_write_data[0] = write_data ;
2600
 
2601
    write_flags`WB_TRANSFER_SIZE = 2 ;
2602
 
2603
    // don't handle retries
2604
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2605
    write_flags`WB_TRANSFER_CAB    = 0 ;
2606
 
2607
    $display("Introducing master abort error on single WB to PCI write!") ;
2608
 
2609
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2610
    // first disable target 1
2611
 
2612 45 mihad
    configuration_cycle_write(0,                        // bus number
2613
                              `TAR1_IDSEL_INDEX - 11,   // device number
2614
                              0,                        // function number
2615
                              1,                        // register number
2616
                              0,                        // type of configuration cycle
2617
                              4'b0001,                  // byte enables
2618
                              32'h0000_0000             // data
2619 15 mihad
                             ) ;
2620
 
2621
    fork
2622
    begin
2623
        // start no response monitor in parallel with writes
2624
        musnt_respond(ok) ;
2625
        if ( ok !== 1 )
2626
        begin
2627
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2628
            $display("Testbench is configured wrong!") ;
2629
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2630
        end
2631
        else
2632
            test_ok ;
2633
    end
2634
    begin
2635
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2636
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2637
       begin
2638
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2639
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2640
           test_fail("WB Slave state machine failed to post single memory write");
2641
           disable main ;
2642
       end
2643
    end
2644
    join
2645
 
2646
    /*// read data from second write
2647
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2648
    read_data`READ_ADDRESS = target_address ;
2649
    read_data`READ_SEL     = 4'hF ;
2650
    read_data`READ_TAG_STIM = 0 ;
2651
 
2652
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2653
 
2654
    if ( read_status`READ_DATA !== wmem_data[101] )
2655
    begin
2656
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2657
    end
2658
    */
2659
 
2660
    // read error status register - no errors should be reported since reporting was disabled
2661
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2662
 
2663
    @(posedge pci_clock) ;
2664
    // wait for two WB clocks for synchronization to be finished
2665
    repeat (2)
2666
        @(posedge wb_clock) ;
2667
 
2668
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2669
    if ( temp_val1[8] !== 0 )
2670
    begin
2671
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2672
        $display("Error reporting was disabled, but error was reported anyway!") ;
2673
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2674
        disable main ;
2675
    end
2676
    test_ok ;
2677
 
2678
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2679
    // check for interrupts - there should be no interrupt requests active
2680
    `ifdef HOST
2681
        repeat(4)
2682
            @(posedge wb_clock) ;
2683
 
2684
        if ( INT_O !== 0 )
2685
        begin
2686
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2687
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2688
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2689
        end
2690
        else
2691
            test_ok ;
2692
    `else
2693
    `ifdef GUEST
2694
        repeat( 4 )
2695
            @(posedge pci_clock) ;
2696
 
2697
        if ( INTA !== 1 )
2698
        begin
2699
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2700
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2701
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2702
        end
2703
        else
2704
            test_ok ;
2705
    `endif
2706
    `endif
2707
 
2708
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2709
    // check PCI status register
2710
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2711
    if ( temp_val1[29] !== 1 )
2712
    begin
2713
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2714
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2715
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2716
    end
2717
    else
2718
        test_ok ;
2719
 
2720
    // clear
2721
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2722
 
2723
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2724
 
2725
    $display("Introducing master abort error to CAB write!") ;
2726
    // now enable error reporting mechanism
2727
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2728
    // enable error interrupts
2729
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2730
 
2731
    // configure flags for CAB transfer
2732
    write_flags`WB_TRANSFER_CAB = 1 ;
2733
    write_flags`WB_TRANSFER_SIZE = 3 ;
2734
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2735
 
2736
    // prepare data for erroneous write
2737
    for ( i = 0 ; i < 3 ; i = i + 1 )
2738
    begin
2739
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2740
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2741
        write_data`WRITE_SEL     = 4'hF ;
2742
        wishbone_master.blk_write_data[i] = write_data ;
2743
    end
2744
 
2745
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2746
    fork
2747
    begin
2748
        wishbone_master.wb_block_write(write_flags, write_status) ;
2749
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2750
        begin
2751
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2752
            $display("Complete burst write through WB slave didn't succeed!") ;
2753
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2754
            disable main ;
2755
        end
2756
    end
2757
    begin
2758
        musnt_respond(ok) ;
2759
        if ( ok !== 1 )
2760
        begin
2761
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2762
            $display("Testbench is configured wrong!") ;
2763
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2764
        end
2765
        else
2766
            test_ok ;
2767
    end
2768
    join
2769
 
2770
    // check error status address, data, byte enables and bus command
2771
    // error status bit is signalled on PCI clock and synchronized to WB clock
2772
    // wait one PCI clock cycle
2773
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2774
    ok = 1 ;
2775
    @(posedge pci_clock) ;
2776
 
2777
    // wait for two WB clocks for synchronization to be finished
2778
    repeat (2)
2779
        @(posedge wb_clock) ;
2780
 
2781
    // read registers
2782
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2783
    if ( temp_val1[8] !== 1 )
2784
    begin
2785
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2786
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2787
        ok = 0 ;
2788
    end
2789
 
2790
    if ( temp_val1[9] !== 1 )
2791
    begin
2792
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2793
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2794
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2795
        ok = 0 ;
2796
    end
2797
 
2798
    if ( temp_val1[31:28] !== 0 )
2799
    begin
2800
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2801
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2802
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2803
        ok = 0 ;
2804
    end
2805
 
2806
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2807
    begin
2808
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2809
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2810
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2811
        ok = 0 ;
2812
    end
2813
 
2814
    // read error address register
2815
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2816
    if ( temp_val1 !== target_address )
2817
    begin
2818
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2819
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2820
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2821
        ok = 0 ;
2822
    end
2823
 
2824
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2825
    if ( temp_val1 !== wmem_data[110] )
2826
    begin
2827
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2828
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2829
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2830
        ok = 0 ;
2831
    end
2832
 
2833
    // check PCI status register
2834
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2835
    if ( temp_val1[29] !== 1 )
2836
    begin
2837
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2838
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2839
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2840
        ok = 0 ;
2841
    end
2842
 
2843
    if ( temp_val1[28] !== 0 )
2844
    begin
2845
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2846
        $display("Received Target Abort bit was set for no reason!") ;
2847
        test_fail("Received Target Abort bit was set for no reason") ;
2848
        ok = 0 ;
2849
    end
2850
 
2851
    if ( ok )
2852
        test_ok ;
2853
 
2854
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2855
 
2856
    // clear error status bit
2857
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2858
 
2859
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2860
 
2861
    ok = 1 ;
2862
 
2863
    `ifdef HOST
2864
        repeat(4)
2865
        @(posedge wb_clock) ;
2866
        if ( INT_O !== 1 )
2867
        begin
2868
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2869
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2870
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2871
            ok = 0 ;
2872
        end
2873
    `else
2874
    `ifdef GUEST
2875
        repeat(4)
2876
        @(posedge pci_clock) ;
2877
        if ( INTA !== 0 )
2878
        begin
2879
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2880
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2881
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2882
            ok = 0 ;
2883
        end
2884
    `endif
2885
    `endif
2886
 
2887
    // read interrupt status register
2888
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2889
    if ( temp_val1 !== 32'h0000_0002 )
2890
    begin
2891
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2892
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2893
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2894
        test_fail("Interrupt Status register returned wrong value") ;
2895
        ok = 0 ;
2896
    end
2897
 
2898
    if ( ok )
2899
        test_ok ;
2900
    // clear interrupt status bits
2901
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2902
 
2903
    ok = 1 ;
2904
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2905
    // wait for two clock cycles before checking interrupt request deassertion
2906
    `ifdef HOST
2907
        repeat (4)
2908
            @(posedge wb_clock) ;
2909
 
2910
        if ( INT_O !== 0 )
2911
        begin
2912
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2913
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2914
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2915
            ok = 0 ;
2916
        end
2917
    `else
2918
    `ifdef GUEST
2919
        repeat (4)
2920
            @(posedge pci_clock) ;
2921
 
2922
        if ( INTA !== 1 )
2923
        begin
2924
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2925
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2926
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2927
            ok = 0 ;
2928
        end
2929
    `endif
2930
    `endif
2931
 
2932
    if ( ok )
2933
        test_ok ;
2934
 
2935
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2936
    ok = 1 ;
2937
    // enable target
2938 45 mihad
    configuration_cycle_write(0,                        // bus number
2939
                              `TAR1_IDSEL_INDEX - 11,   // device number
2940
                              0,                        // function number
2941
                              1,                        // register number
2942
                              0,                        // type of configuration cycle
2943
                              4'b0001,                  // byte enables
2944
                              32'h0000_0007             // data
2945 15 mihad
                             ) ;
2946
    // prepare data for ok write
2947
    for ( i = 0 ; i < 3 ; i = i + 1 )
2948
    begin
2949
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2950
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2951
        write_data`WRITE_SEL     = 4'hF ;
2952
        wishbone_master.blk_write_data[i] = write_data ;
2953
    end
2954
 
2955
    wishbone_master.wb_block_write(write_flags, write_status) ;
2956
 
2957
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2958
    begin
2959
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2960
        $display("Complete burst write through WB slave didn't succeed!") ;
2961
        test_fail("WB Slave state machine failed to post CAB write") ;
2962
        disable main ;
2963
    end
2964
 
2965
    // do a read
2966
    for ( i = 0 ; i < 3 ; i = i + 1 )
2967
    begin
2968
        read_data`READ_ADDRESS = target_address + 4*i ;
2969
        read_data`READ_SEL     = 4'hF ;
2970
        wishbone_master.blk_read_data_in[i] = read_data ;
2971
    end
2972
 
2973
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2974
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2975
    write_flags`WB_TRANSFER_CAB    = 1 ;
2976
 
2977
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2978
 
2979
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2980
    begin
2981
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2982
        $display("Complete burst read through WB slave didn't succeed!") ;
2983
        test_fail("Delayed CAB write was not processed as expected") ;
2984
        disable main ;
2985
    end
2986
 
2987
    for ( i = 0 ; i < 3 ; i = i + 1 )
2988
    begin
2989
        read_status = wishbone_master.blk_read_data_out[i] ;
2990
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2991
        begin
2992
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2993
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2994
        end
2995
    end
2996
 
2997
    $display("Introducing master abort error to single read!") ;
2998
    // disable target
2999 45 mihad
    configuration_cycle_write(0,                        // bus number
3000
                              `TAR1_IDSEL_INDEX - 11,   // device number
3001
                              0,                        // function number
3002
                              1,                        // register number
3003
                              0,                        // type of configuration cycle
3004
                              4'b0001,                  // byte enables
3005
                              32'h0000_0000             // data
3006 15 mihad
                             ) ;
3007
    // set read data
3008
    read_data`READ_ADDRESS = target_address ;
3009
    read_data`READ_SEL     = 4'hF ;
3010
 
3011
    // enable automatic retry handling
3012
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3013
    write_flags`WB_TRANSFER_CAB    = 0 ;
3014
 
3015
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
3016
    fork
3017
    begin
3018
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3019
    end
3020
    begin
3021
        musnt_respond(ok) ;
3022
        if ( ok !== 1 )
3023
        begin
3024
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3025
            $display("Testbench is configured wrong!") ;
3026
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3027
        end
3028
    end
3029
    join
3030
 
3031
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3032
    begin
3033
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3034
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3035
        $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) ;
3036
        test_fail("read didn't finish on WB bus as expected") ;
3037
        disable main ;
3038
    end
3039
 
3040
    test_ok ;
3041
 
3042
 
3043
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
3044
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
3045
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3046
    if ( temp_val1[8] !== 0 )
3047
    begin
3048
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3049
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
3050
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
3051
    end
3052
    else
3053
        test_ok ;
3054
 
3055
    // now check normal read operation
3056 45 mihad
    configuration_cycle_write(0,                        // bus number
3057
                              `TAR1_IDSEL_INDEX - 11,   // device number
3058
                              0,                        // function number
3059
                              1,                        // register number
3060
                              0,                        // type of configuration cycle
3061
                              4'b0001,                  // byte enables
3062
                              32'h0000_0007             // data
3063 15 mihad
                             ) ;
3064
 
3065 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
3066 15 mihad
    read_data`READ_ADDRESS = target_address ;
3067
    read_data`READ_SEL     = 4'hF ;
3068
 
3069
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3070
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3071
    begin
3072
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3073
        $display("WB slave failed to process single read!") ;
3074
        $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) ;
3075
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
3076
        disable main ;
3077
    end
3078
 
3079
    if ( read_status`READ_DATA !== wmem_data[113] )
3080
    begin
3081
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
3082
        test_fail("when read finished on WB bus, wrong data was provided") ;
3083
    end
3084
    else
3085
        test_ok ;
3086
 
3087
    // check PCI status register
3088 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
3089 15 mihad
    ok = 1 ;
3090
 
3091
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3092
    if ( temp_val1[29] !== 1 )
3093
    begin
3094
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3095
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3096
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3097
        ok = 0 ;
3098
    end
3099
 
3100
    if ( temp_val1[28] !== 0 )
3101
    begin
3102
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3103
        $display("Received Target Abort bit was set for no reason!") ;
3104
        test_fail("Received Target Abort bit was set for no reason") ;
3105
        ok = 0 ;
3106
    end
3107
    if ( ok )
3108
        test_ok ;
3109
 
3110
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3111
 
3112
    $display("Introducing master abort error to CAB read!") ;
3113
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3114
 
3115 45 mihad
    configuration_cycle_write(0,                        // bus number
3116
                              `TAR1_IDSEL_INDEX - 11,   // device number
3117
                              0,                        // function number
3118
                              1,                        // register number
3119
                              0,                        // type of configuration cycle
3120
                              4'b0001,                  // byte enables
3121
                              32'h0000_0000             // data
3122 15 mihad
                             ) ;
3123
 
3124
    for ( i = 0 ; i < 3 ; i = i + 1 )
3125
    begin
3126
        read_data`READ_ADDRESS = target_address + 4*i ;
3127
        read_data`READ_SEL     = 4'hF ;
3128
        wishbone_master.blk_read_data_in[i] = read_data ;
3129
    end
3130
 
3131
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3132
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3133
    write_flags`WB_TRANSFER_CAB    = 1 ;
3134
 
3135
    fork
3136
    begin
3137
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3138
    end
3139
    begin
3140
        musnt_respond(ok) ;
3141
        if ( ok !== 1 )
3142
        begin
3143
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3144
            $display("Testbench is configured wrong!") ;
3145
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3146
        end
3147
    end
3148
    join
3149
 
3150
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3151
    begin
3152
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3153
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3154
        $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) ;
3155
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3156
        disable main ;
3157
    end
3158
    else
3159
        test_ok ;
3160
 
3161
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3162
    ok = 1 ;
3163
    // check PCI status register
3164
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3165
    if ( temp_val1[29] !== 1 )
3166
    begin
3167
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3168
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3169
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3170
        ok = 0 ;
3171
    end
3172
 
3173
    if ( temp_val1[28] !== 0 )
3174
    begin
3175
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3176
        $display("Received Target Abort bit was set for no reason!") ;
3177
        test_fail("Received Target Abort bit was set for no reason") ;
3178
        ok = 0 ;
3179
    end
3180
 
3181
    if ( ok )
3182
        test_ok ;
3183
 
3184
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3185
 
3186
    $display("Introducing target abort termination to single write!") ;
3187
 
3188
    // disable error reporting and interrupts
3189
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3190
 
3191 45 mihad
    configuration_cycle_write(0,                        // bus number
3192
                              `TAR1_IDSEL_INDEX - 11,   // device number
3193
                              0,                        // function number
3194
                              1,                        // register number
3195
                              0,                        // type of configuration cycle
3196
                              4'b0001,                  // byte enables
3197
                              32'h0000_0007             // data
3198 15 mihad
                             ) ;
3199
 
3200
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3201
    if ( ok !== 1 )
3202
    begin
3203
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3204
        test_fail("WB Error Control and Status register couldn't be written to") ;
3205
        disable main ;
3206
    end
3207
 
3208
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3209
    if ( ok !== 1 )
3210
    begin
3211
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3212
        test_fail("Interrupt Control register couldn't be written to") ;
3213
        disable main ;
3214
    end
3215
 
3216
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3217
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3218
 
3219
    write_data`WRITE_ADDRESS = target_address ;
3220
    write_data`WRITE_DATA    = wmem_data[0] ;
3221
    write_data`WRITE_SEL     = 4'hF ;
3222
 
3223
    wishbone_master.blk_write_data[0] = write_data ;
3224
 
3225
    write_data`WRITE_ADDRESS = target_address + 4;
3226
    write_data`WRITE_DATA    = wmem_data[1] ;
3227
    write_data`WRITE_SEL     = 4'hF ;
3228
 
3229
    wishbone_master.blk_write_data[1] = write_data ;
3230
 
3231
    write_flags`WB_TRANSFER_SIZE = 2 ;
3232
 
3233
    // don't handle retries
3234
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3235
    write_flags`WB_TRANSFER_CAB    = 0 ;
3236
 
3237
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3238
    fork
3239
    begin
3240
        wishbone_master.wb_block_write(write_flags, write_status) ;
3241
 
3242
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3243
        begin
3244
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3245
            $display("Image writes were not accepted as expected!") ;
3246
            $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) ;
3247
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3248
            disable main ;
3249
        end
3250
 
3251
        // read data back to see, if it was written OK
3252
        read_data`READ_ADDRESS         = target_address + 4;
3253
        read_data`READ_SEL             = 4'hF ;
3254
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3255
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3256
    end
3257
    begin
3258
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3259
        if ( ok !== 1 )
3260
        begin
3261
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3262
        end
3263
        else
3264
            test_ok ;
3265
 
3266
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3267
 
3268
        // when first transaction finishes - enable normal target response!
3269
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3270
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3271
 
3272
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3273
        if ( ok !== 1 )
3274
        begin
3275
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3276
        end
3277
        else
3278
            test_ok ;
3279
 
3280
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3281
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3282
        if ( ok !== 1 )
3283
        begin
3284
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3285
        end
3286
    end
3287
    join
3288
 
3289
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3290
    begin
3291
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3292
        $display("Bridge failed to process single read after target abort terminated write!") ;
3293
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3294
        disable main ;
3295
    end
3296
 
3297
    if ( read_status`READ_DATA !== wmem_data[1] )
3298
    begin
3299
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3300
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3301
    end
3302
    else
3303
        test_ok ;
3304
 
3305
    // check interrupt and error statuses!
3306
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3307
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3308
    if ( temp_val1[8] !== 0 )
3309
    begin
3310
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3311
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3312
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3313
    end
3314
    else
3315
        test_ok ;
3316
 
3317
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3318
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3319
    if ( temp_val1[1] !== 0 )
3320
    begin
3321
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3322
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3323
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3324
    end
3325
    else
3326
        test_ok ;
3327
 
3328
    // check PCI status register
3329
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3330
    ok = 1 ;
3331
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3332
    if ( temp_val1[29] !== 0 )
3333
    begin
3334
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3335
        $display("Received Master Abort bit was set with no reason!") ;
3336
        test_fail("Received Master Abort bit was set with no reason") ;
3337
        ok = 0 ;
3338
    end
3339
 
3340
    if ( temp_val1[28] !== 1 )
3341
    begin
3342
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3343
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3344
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3345
        ok = 0 ;
3346
    end
3347
 
3348
    if ( ok )
3349
        test_ok ;
3350
 
3351
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3352
 
3353
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3354
 
3355
    $display("Introducing target abort termination to CAB write!") ;
3356
    // enable error reporting mechanism
3357
 
3358
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3359
    if ( ok !== 1 )
3360
    begin
3361
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3362
        test_fail("WB Error Control and Status register could not be written to") ;
3363
        disable main ;
3364
    end
3365
 
3366
    for ( i = 0 ; i < 3 ; i = i + 1 )
3367
    begin
3368
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3369
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3370
        write_data`WRITE_SEL     = 4'b1010 ;
3371
        wishbone_master.blk_write_data[i] = write_data ;
3372
    end
3373
 
3374
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3375
    write_flags`WB_TRANSFER_CAB    = 1 ;
3376
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3377
 
3378
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3379
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3380
 
3381
    fork
3382
    begin
3383
        wishbone_master.wb_block_write(write_flags, write_status) ;
3384
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3385
        begin
3386
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3387
            $display("Bridge failed to process complete CAB write!") ;
3388
            test_fail("bridge failed to post CAB Memory Write") ;
3389
            disable main ;
3390
        end
3391
    end
3392
    begin
3393
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3394
        if ( ok !== 1 )
3395
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3396
        else
3397
            test_ok ;
3398
    end
3399
    join
3400
 
3401
    // check statuses and data from error
3402
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3403
    ok = 1 ;
3404
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3405
    if ( temp_val1[8] !== 1 )
3406
    begin
3407
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3408
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3409
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3410
        ok = 0 ;
3411
    end
3412
 
3413
    if ( temp_val1[9] !== 0 )
3414
    begin
3415
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3416
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3417
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3418
        ok = 0 ;
3419
    end
3420
 
3421
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3422
    begin
3423
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3424
        $display("Value in W_ERR_CS register was wrong!") ;
3425
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3426
        test_fail("BE Field didn't provided expected value") ;
3427
        ok = 0 ;
3428
    end
3429
 
3430
    if ( ok )
3431
        test_ok ;
3432
 
3433
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3434
    ok = 1 ;
3435
    // check erroneous address and data
3436
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3437
    if ( temp_val1 !== (target_address + 8) )
3438
    begin
3439
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3440
        $display("Value in W_ERR_ADDR register was wrong!") ;
3441
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3442
        test_fail("Value in WB Erroneous Address register was wrong") ;
3443
        ok = 0 ;
3444
    end
3445
 
3446
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3447
    if ( temp_val1 !== wmem_data[120] )
3448
    begin
3449
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3450
        $display("Value in W_ERR_DATA register was wrong!") ;
3451
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3452
        test_fail("Value in WB Erroneous Data register was wrong") ;
3453
        ok = 0 ;
3454
    end
3455
 
3456
    if ( ok )
3457
        test_ok ;
3458
 
3459
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3460
    ok = 1 ;
3461
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3462
    if ( temp_val1[29] !== 0 )
3463
    begin
3464
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3465
        $display("Received Master Abort bit was set with no reason!") ;
3466
        test_fail("Received Master Abort bit was set for no reason") ;
3467
        ok = 0 ;
3468
    end
3469
 
3470
    if ( temp_val1[28] !== 1 )
3471
    begin
3472
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3473
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3474
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3475
        ok = 0 ;
3476
    end
3477
 
3478
    if ( ok )
3479
        test_ok ;
3480
 
3481
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3482
 
3483
    // clear error status bit and enable error interrupts
3484
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3485
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3486
 
3487
    // check if error bit was cleared
3488
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3489
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3490
    if ( temp_val1[8] !== 0 )
3491
    begin
3492
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3493
        $display("Error bit was not cleared even though one was written to its location!") ;
3494
        test_fail("Error bit was not cleared even though one was written to its location") ;
3495
    end
3496
 
3497
    // repeat same write with different target configuration
3498
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3499
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3500
 
3501
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3502
    fork
3503
    begin
3504
        write_flags`WB_TRANSFER_SIZE = 2 ;
3505
        wishbone_master.wb_block_write(write_flags, write_status) ;
3506
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3507
        begin
3508
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3509
            $display("Bridge failed to process complete CAB write!") ;
3510
            test_fail("bridge failed to post CAB Memory Write") ;
3511
            disable main ;
3512
        end
3513
 
3514
        write_flags`WB_TRANSFER_SIZE = 3 ;
3515
        wishbone_master.wb_block_write(write_flags, write_status) ;
3516
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3517
        begin
3518
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3519
            $display("Bridge failed to process complete CAB write!") ;
3520
            test_fail("bridge failed to post CAB Memory Write") ;
3521
            disable main ;
3522
        end
3523
    end
3524
    begin
3525
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3526
        if ( ok !== 1 )
3527
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3528
        else
3529
        begin
3530
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3531
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3532
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3533
            if ( ok !== 1 )
3534
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3535
            else
3536
                test_ok ;
3537
        end
3538
    end
3539
    join
3540
 
3541
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3542
    ok = 1 ;
3543
    // check statuses and data from error
3544
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3545
    if ( temp_val1[8] !== 1 )
3546
    begin
3547
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3548
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3549
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3550
        ok = 0 ;
3551
    end
3552
 
3553
    if ( temp_val1[9] !== 0 )
3554
    begin
3555
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3556
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3557
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3558
        ok = 0 ;
3559
    end
3560
 
3561
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3562
    begin
3563
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3564
        $display("Value in W_ERR_CS register was wrong!") ;
3565
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3566
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3567
        ok = 0 ;
3568
    end
3569
 
3570
    if ( ok )
3571
        test_ok ;
3572
 
3573
    // check erroneous address and data
3574
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3575
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3576
    ok = 1 ;
3577
    if ( temp_val1 !== (target_address + 8 + 4) )
3578
    begin
3579
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3580
        $display("Value in W_ERR_ADDR register was wrong!") ;
3581
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3582
        test_fail("Value in WB Erroneous Address register was wrong") ;
3583
        ok = 0 ;
3584
 
3585
    end
3586
 
3587
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3588
    if ( temp_val1 !== wmem_data[121] )
3589
    begin
3590
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3591
        $display("Value in W_ERR_DATA register was wrong!") ;
3592
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3593
        test_fail("Value in WB Erroneous Data register was wrong") ;
3594
        ok = 0 ;
3595
    end
3596
 
3597
    if ( ok )
3598
        test_ok ;
3599
 
3600
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3601
    `ifdef HOST
3602
        repeat(4)
3603
            @(posedge wb_clock) ;
3604
        if ( INT_O !== 1 )
3605
        begin
3606
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3607
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3608
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3609
        end
3610
        else
3611
            test_ok ;
3612
    `else
3613
    `ifdef GUEST
3614
        repeat(4)
3615
            @(posedge pci_clock) ;
3616
        if ( INTA !== 0 )
3617
        begin
3618
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3619
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3620
            test_fail("interrupt request was not presented on PCI bus") ;
3621
        end
3622
        else
3623
            test_ok ;
3624
    `endif
3625
    `endif
3626
 
3627
    // read interrupt status register
3628
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3629
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3630
    if ( temp_val1[1] !== 1 )
3631
    begin
3632
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3633
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3634
        test_fail("Expected Interrupt status bit wasn't set") ;
3635
    end
3636
 
3637
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3638
 
3639
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3640
    ok = 1 ;
3641
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3642
    if ( temp_val1[29] !== 0 )
3643
    begin
3644
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3645
        $display("Received Master Abort bit was set with no reason!") ;
3646
        test_fail("Received Master Abort bit was set with no reason") ;
3647
        ok = 0 ;
3648
    end
3649
 
3650
    if ( temp_val1[28] !== 1 )
3651
    begin
3652
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3653
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3654
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3655
        ok = 0 ;
3656
    end
3657
 
3658
    if ( ok )
3659
        test_ok ;
3660
 
3661
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3662
 
3663
    // clear interrupts and errors
3664
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3665
    repeat( 3 )
3666
        @(posedge pci_clock) ;
3667
 
3668
    repeat( 2 )
3669
        @(posedge wb_clock) ;
3670
 
3671
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3672
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3673
    if ( temp_val1[1] !== 0 )
3674
    begin
3675
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3676
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3677
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3678
    end
3679
    else
3680
        test_ok ;
3681
 
3682
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3683
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3684
    if ( temp_val1[8] !== 0 )
3685
    begin
3686
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3687
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3688
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3689
    end
3690
 
3691
 
3692
    $display("Introducing Target Abort error to single read!") ;
3693
    // set read data
3694
    read_data`READ_ADDRESS = target_address + 8 ;
3695
    read_data`READ_SEL     = 4'hF ;
3696
 
3697
    // enable automatic retry handling
3698
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3699
    write_flags`WB_TRANSFER_CAB    = 0 ;
3700
 
3701
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3702
 
3703
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3704
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3705
 
3706
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3707
 
3708
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3709
    begin
3710
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3711
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3712
        $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) ;
3713
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3714
        disable main ;
3715
    end
3716
    else
3717
        test_ok ;
3718
 
3719
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3720
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3721
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3722
    if ( temp_val1[8] !== 0 )
3723
    begin
3724
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3725
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3726
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3727
    end
3728
    else
3729
        test_ok ;
3730
 
3731
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3732
    ok = 1 ;
3733
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3734
    if ( temp_val1[29] !== 0 )
3735
    begin
3736
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3737
        $display("Received Master Abort bit was set with no reason!") ;
3738
        test_fail("Received Master Abort bit was set with no reason") ;
3739
        ok = 0 ;
3740
    end
3741
 
3742
    if ( temp_val1[28] !== 1 )
3743
    begin
3744
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3745
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3746
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3747
        ok = 0 ;
3748
    end
3749
 
3750
    if ( ok )
3751
        test_ok ;
3752
 
3753
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3754
 
3755
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3756
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3757
    if ( temp_val1[1] !== 0 )
3758
    begin
3759
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3760
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3761
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3762
    end
3763
    else
3764
        test_ok ;
3765
 
3766
    $display("Introducing Target Abort error to CAB read!") ;
3767
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3768
 
3769
    for ( i = 0 ; i < 4 ; i = i + 1 )
3770
    begin
3771
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3772
        read_data`READ_SEL     = 4'b1010 ;
3773
        wishbone_master.blk_read_data_in[i] = read_data ;
3774
    end
3775
 
3776
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3777
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3778
    write_flags`WB_TRANSFER_CAB    = 1 ;
3779
 
3780
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3781
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3782
 
3783
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3784
 
3785
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3786
    begin
3787
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3788
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3789
        $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) ;
3790
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3791
        disable main ;
3792
    end
3793
 
3794
    read_status = wishbone_master.blk_read_data_out[0] ;
3795
    temp_val1 = read_status`READ_DATA ;
3796
    temp_val2 = wmem_data[120] ;
3797
 
3798
    // last write to this address was with only two byte enables - check only those
3799
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3800
    begin
3801
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3802
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3803
    end
3804
    else
3805
        test_ok ;
3806
 
3807
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3808
    ok = 1 ;
3809
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3810
    if ( temp_val1[29] !== 0 )
3811
    begin
3812
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3813
        $display("Received Master Abort bit was set with no reason!") ;
3814
        test_fail("Received Master Abort bit was set with no reason") ;
3815
        ok = 0 ;
3816
    end
3817
 
3818
    if ( temp_val1[28] !== 1 )
3819
    begin
3820
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3821
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3822
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3823
        ok = 0 ;
3824
    end
3825
 
3826
    if ( ok )
3827
       test_ok ;
3828
 
3829
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3830
 
3831
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3832
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3833
 
3834
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3835
    for ( i = 0 ; i < 3 ; i = i + 1 )
3836
    begin
3837
        read_data`READ_ADDRESS = target_address + 4*i ;
3838
        read_data`READ_SEL     = 4'b1111 ;
3839
        wishbone_master.blk_read_data_in[i] = read_data ;
3840
    end
3841
 
3842
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3843
 
3844
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3845
 
3846
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3847
    begin
3848
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3849
        $display("Complete burst read through WB slave didn't succeed!") ;
3850
        test_fail("bridge didn't process Burst Read in an expected way") ;
3851
        disable main ;
3852
    end
3853
    else
3854
        test_ok ;
3855
 
3856
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3857
 
3858
    for ( i = 0 ; i < 3 ; i = i + 1 )
3859
    begin
3860
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3861
        read_data`READ_SEL     = 4'b1111 ;
3862
        wishbone_master.blk_read_data_in[i] = read_data ;
3863
    end
3864
 
3865
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3866
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3867
    write_flags`WB_TRANSFER_CAB    = 1 ;
3868
 
3869
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3870
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3871
 
3872
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3873
 
3874
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3875
    begin
3876
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3877
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3878
        $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) ;
3879
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3880
        disable main ;
3881
    end
3882
 
3883
    for ( i = 0 ; i < 3 ; i = i + 1 )
3884
    begin
3885
        ok = 1 ;
3886
        read_status = wishbone_master.blk_read_data_out[i] ;
3887
        temp_val1 = read_status`READ_DATA ;
3888
        temp_val2 = wmem_data[120 + i] ;
3889
 
3890
        // last write to this address was with only two byte enables - check only those
3891
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3892
        begin
3893
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3894
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3895
            ok = 0 ;
3896
        end
3897
    end
3898
 
3899
    if ( ok )
3900
        test_ok ;
3901
 
3902
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3903
    ok = 1 ;
3904
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3905
    if ( temp_val1[29] !== 0 )
3906
    begin
3907
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3908
        $display("Received Master Abort bit was set with no reason!") ;
3909
        test_fail("Received Master Abort bit was set with no reason") ;
3910
        ok = 0 ;
3911
    end
3912
 
3913
    if ( temp_val1[28] !== 1 )
3914
    begin
3915
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3916
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3917
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3918
        ok = 0 ;
3919
    end
3920
 
3921
    if ( ok )
3922
       test_ok ;
3923
 
3924
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3925
 
3926
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3927
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3928
 
3929
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3930
    for ( i = 0 ; i < 3 ; i = i + 1 )
3931
    begin
3932
        read_data`READ_ADDRESS = target_address + 4*i ;
3933
        read_data`READ_SEL     = 4'b1111 ;
3934
        wishbone_master.blk_read_data_in[i] = read_data ;
3935
    end
3936
 
3937
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3938
 
3939
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3940
 
3941
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3942
    begin
3943
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3944
        $display("Complete burst read through WB slave didn't succeed!") ;
3945
        test_fail("bridge didn't process Burst Read in an expected way") ;
3946
        disable main ;
3947
    end
3948
    else
3949
        test_ok ;
3950
 
3951
    // test error on IO write
3952
    // change base address
3953
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3954
    write_data`WRITE_SEL     = 4'b0101 ;
3955
    write_data`WRITE_ADDRESS = target_address ;
3956
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3957
 
3958
    write_flags`WB_TRANSFER_CAB    = 0 ;
3959
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3960
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3961
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3962
    fork
3963
    begin
3964
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3965
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3966
        begin
3967
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3968
            $display("WB slave failed to accept IO write!") ;
3969
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3970
            disable main ;
3971
        end
3972
    end
3973
    begin
3974
        musnt_respond(ok) ;
3975
        if ( ok !== 1 )
3976
        begin
3977
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3978
            $display("Testbench is configured wrong!") ;
3979
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3980
        end
3981
        else
3982
            test_ok ;
3983
    end
3984
    join
3985
 
3986
    // check statuses and everything else
3987
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3988
    ok = 1 ;
3989
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3990
    if ( temp_val1[8] !== 1 )
3991
    begin
3992
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3993
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3994
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3995
        ok = 0 ;
3996
    end
3997
 
3998
    if ( temp_val1[9] !== 1 )
3999
    begin
4000
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4001
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
4002
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
4003
        ok = 0 ;
4004
    end
4005
 
4006
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
4007
    begin
4008
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4009
        $display("Value in W_ERR_CS register was wrong!") ;
4010
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
4011
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
4012
        ok = 0 ;
4013
    end
4014
 
4015
    if ( ok )
4016
        test_ok ;
4017
 
4018
    // check erroneous address and data
4019
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
4020
    ok = 1 ;
4021
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4022
    if ( temp_val1 !== target_address )
4023
    begin
4024
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4025
        $display("Value in W_ERR_ADDR register was wrong!") ;
4026
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
4027
        test_fail("WB Erroneous Address register didn't provide right value") ;
4028
        ok = 0 ;
4029
    end
4030
 
4031
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4032
    if ( temp_val1 !== 32'hAAAA_AAAA )
4033
    begin
4034
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4035
        $display("Value in W_ERR_DATA register was wrong!") ;
4036
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
4037
        test_fail("WB Erroneous Data register didn't provide right value") ;
4038
        ok = 0 ;
4039
    end
4040
 
4041
    if ( ok )
4042
        test_ok ;
4043
 
4044
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4045
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
4046
    if ( temp_val1[1] !== 1 )
4047
    begin
4048
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4049
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
4050
        test_fail("expected interrupt status bit was not set") ;
4051
    end
4052
    else
4053
        test_ok ;
4054
 
4055
    // clear interrupts and errors
4056
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
4057
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
4058
 
4059
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4060
    ok = 1 ;
4061
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4062
    if ( temp_val1[29] !== 1 )
4063
    begin
4064
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4065
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
4066
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
4067
        ok = 0 ;
4068
    end
4069
 
4070
    if ( temp_val1[28] !== 0 )
4071
    begin
4072
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4073
        $display("Received Target Abort bit was set for no reason!") ;
4074
        test_fail("Received Target Abort bit was set for no reason") ;
4075
        ok = 0 ;
4076
    end
4077
 
4078
    if ( ok )
4079
        test_ok ;
4080
 
4081
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4082
 
4083
    // disable image
4084
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4085
    if ( ok !== 1 )
4086
    begin
4087
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4088
        test_fail("WB Image Address Mask register couldn't be written") ;
4089
        disable main ;
4090
    end
4091
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
4092
 
4093
end
4094
endtask
4095
 
4096
task parity_checking ;
4097
    reg   [11:0] ctrl_offset ;
4098
    reg   [11:0] ba_offset ;
4099
    reg   [11:0] am_offset ;
4100
    reg   [11:0] ta_offset ;
4101
    reg `WRITE_STIM_TYPE write_data ;
4102
    reg `READ_STIM_TYPE  read_data ;
4103
    reg `READ_RETURN_TYPE read_status ;
4104
 
4105
    reg `WRITE_RETURN_TYPE write_status ;
4106
    reg `WB_TRANSFER_FLAGS write_flags ;
4107
    reg [31:0] temp_val1 ;
4108
    reg [31:0] temp_val2 ;
4109
    reg        ok   ;
4110
    reg [11:0] pci_ctrl_offset ;
4111
    reg [31:0] image_base ;
4112
    reg [31:0] target_address ;
4113
    reg [11:0] icr_offset ;
4114
    reg [11:0] isr_offset ;
4115
    reg [11:0] p_ba_offset ;
4116
    reg [11:0] p_am_offset ;
4117
    reg [11:0] p_ctrl_offset ;
4118
    integer    i ;
4119
    reg        perr_asserted ;
4120
begin:main
4121
    $display("******************************* Testing Parity Checker functions ********************************") ;
4122
    $display("Testing Parity Errors during Master Transactions!") ;
4123
    $display("Introducing Parity Erros to Master Writes!") ;
4124
    $fdisplay(pci_mon_log_file_desc,
4125
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4126
 
4127
    // image 1 is used for error testing, since it is always implemented
4128
    pci_ctrl_offset = 12'h004 ;
4129
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4130
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4131
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4132
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4133
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4134
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4135
 
4136
    // image 1 for PCI target
4137
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4138
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4139
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4140
 
4141
    target_address  = `BEH_TAR1_MEM_START ;
4142
    image_base      = 0 ;
4143
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4144
 
4145
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4146
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4147
    write_flags                    = 0 ;
4148
    write_flags`INIT_WAITS         = tb_init_waits ;
4149
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
4150
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4151
 
4152
    // enable master & target operation and disable parity functions
4153
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4154
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4155
    if ( ok !== 1 )
4156
    begin
4157
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4158
        test_fail("PCI Device Control register could not be written to") ;
4159
        disable main ;
4160
    end
4161
 
4162
    // prepare image control register
4163
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4164
    if ( ok !== 1 )
4165
    begin
4166
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4167
        test_fail("WB Image Control register could not be written to") ;
4168
        disable main ;
4169
    end
4170
 
4171
    // prepare base address register
4172
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4173
    if ( ok !== 1 )
4174
    begin
4175
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4176
        test_fail("WB Image Base Address register could not be written to") ;
4177
        disable main ;
4178
    end
4179
 
4180
    // write address mask register
4181
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4182
    if ( ok !== 1 )
4183
    begin
4184
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4185
        test_fail("WB Image Address Mask register could not be written to") ;
4186
        disable main ;
4187
    end
4188
 
4189
    // disable parity interrupts
4190
    config_write( icr_offset, 0, 4'hF, ok ) ;
4191
    if ( ok !== 1 )
4192
    begin
4193
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4194
        test_fail("Interrupt Control register could not be written to") ;
4195
        disable main ;
4196
    end
4197
 
4198
    write_data`WRITE_ADDRESS = target_address ;
4199
    write_data`WRITE_DATA    = wmem_data[0] ;
4200
    write_data`WRITE_SEL     = 4'b1111 ;
4201
 
4202
    // enable target's 1 response to parity errors
4203 45 mihad
    configuration_cycle_write(0,                        // bus number
4204
                              `TAR1_IDSEL_INDEX - 11,   // device number
4205
                              0,                        // function number
4206
                              1,                        // register number
4207
                              0,                        // type of configuration cycle
4208
                              4'b0001,                  // byte enables
4209
                              32'h0000_0047             // data
4210 15 mihad
                             ) ;
4211
 
4212
    // disable target's 2 response to parity errors
4213 45 mihad
    configuration_cycle_write(0,                        // bus number
4214
                              `TAR2_IDSEL_INDEX - 11,   // device number
4215
                              0,                        // function number
4216
                              1,                        // register number
4217
                              0,                        // type of configuration cycle
4218
                              4'b0001,                  // byte enables
4219
                              32'h0000_0007             // data
4220 15 mihad
                             ) ;
4221
 
4222
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4223
 
4224
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4225
    fork
4226
    begin
4227
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4228
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4229
        begin
4230
            $display("Parity checker testing failed! Time %t ", $time) ;
4231
            $display("Bridge failed to process single memory write!") ;
4232
            test_fail("bridge failed to post single WB memory write") ;
4233
            disable main ;
4234
        end
4235
    end
4236
    begin:wait_perr1
4237
        perr_asserted = 0 ;
4238
        @(posedge pci_clock) ;
4239
 
4240 35 mihad
        while ( PERR !== 0 )
4241 15 mihad
            @(posedge pci_clock) ;
4242
 
4243 35 mihad
        perr_asserted = 1 ;
4244 15 mihad
 
4245
    end
4246
    begin
4247
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4248
 
4249
        if ( ok !== 1 )
4250
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4251
 
4252 35 mihad
        repeat(2)
4253 15 mihad
            @(posedge pci_clock) ;
4254
 
4255 35 mihad
        #1 ;
4256
        if ( !perr_asserted )
4257
            disable wait_perr1 ;
4258 15 mihad
    end
4259
    join
4260
 
4261
    if ( perr_asserted && ok )
4262
    begin
4263
        test_ok ;
4264
    end
4265
    else
4266
    if ( ~perr_asserted )
4267
    begin
4268
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4269
        disable main ;
4270
    end
4271
 
4272
    // check all the statuses - if HOST is defined, wait for them to be synced
4273
    `ifdef HOST
4274
    repeat(4)
4275
        @(posedge wb_clock) ;
4276
    `endif
4277
 
4278
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4279
    ok = 1 ;
4280
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4281 45 mihad
    if ( temp_val1[31] !== 0 )
4282 15 mihad
    begin
4283
        $display("Parity checker testing failed! Time %t ", $time) ;
4284 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4285
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4286 15 mihad
        ok = 0 ;
4287
    end
4288
 
4289
    if ( temp_val1[30] !== 0 )
4290
    begin
4291
        $display("Parity checker testing failed! Time %t ", $time) ;
4292
        $display("Signalled System Error bit was set for no reason!") ;
4293
        test_fail("Signalled System Error bit was set for no reason") ;
4294
        ok = 0 ;
4295
    end
4296
 
4297
    if ( temp_val1[24] !== 0 )
4298
    begin
4299
        $display("Parity checker testing failed! Time %t ", $time) ;
4300
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4301
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4302
        ok = 0 ;
4303
    end
4304
 
4305
    if ( ok )
4306
        test_ok ;
4307
 
4308
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4309
    // clear parity bits and enable parity response
4310
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4311
    if ( ok !== 1 )
4312
    begin
4313
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4314
        test_fail("write to PCI Status Register failed") ;
4315
        disable main ;
4316
    end
4317
 
4318
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4319
    fork
4320
    begin
4321
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4322
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4323
        begin
4324
            $display("Parity checker testing failed! Time %t ", $time) ;
4325
            $display("Bridge failed to process single memory write!") ;
4326
            test_fail("bridge failed to post single memory write") ;
4327
            disable main ;
4328
        end
4329
    end
4330
    begin:wait_perr2
4331
        perr_asserted = 0 ;
4332
        @(posedge pci_clock) ;
4333
 
4334 35 mihad
        while ( PERR !== 0 )
4335 15 mihad
            @(posedge pci_clock) ;
4336
 
4337 35 mihad
        perr_asserted = 1 ;
4338 15 mihad
 
4339
    end
4340
    begin
4341
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4342
 
4343
        if ( ok !== 1 )
4344
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4345
 
4346 35 mihad
        repeat(2)
4347 15 mihad
            @(posedge pci_clock) ;
4348
 
4349 35 mihad
        #1 ;
4350
        if (!perr_asserted)
4351
            disable wait_perr2 ;
4352 15 mihad
    end
4353
    join
4354
 
4355
    if ( perr_asserted && ok )
4356
    begin
4357
        test_ok ;
4358
    end
4359
    else
4360
    if ( ~perr_asserted )
4361
    begin
4362
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4363
        disable main ;
4364
    end
4365
 
4366
    // check all the statuses - if HOST is defined, wait for them to be synced
4367
    `ifdef HOST
4368
    repeat(4)
4369
        @(posedge wb_clock) ;
4370
    `endif
4371
 
4372
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4373
    ok = 1 ;
4374
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4375 45 mihad
    if ( temp_val1[31] !== 0 )
4376 15 mihad
    begin
4377
        $display("Parity checker testing failed! Time %t ", $time) ;
4378 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4379
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4380 15 mihad
        ok = 0 ;
4381
    end
4382
 
4383
    if ( temp_val1[30] !== 0 )
4384
    begin
4385
        $display("Parity checker testing failed! Time %t ", $time) ;
4386
        $display("Signalled System Error bit was set for no reason!") ;
4387
        test_fail("Signalled System Error bit was set for no reason") ;
4388
        ok = 0 ;
4389
    end
4390
 
4391
    if ( temp_val1[24] !== 1 )
4392
    begin
4393
        $display("Parity checker testing failed! Time %t ", $time) ;
4394 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!") ;
4395
        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") ;
4396 15 mihad
        ok = 0 ;
4397
    end
4398
 
4399
    if ( ok )
4400
        test_ok ;
4401
 
4402
    // clear status bits and disable parity error response
4403
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4404
 
4405
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4406
 
4407
    // disable perr generation and perform a write - no bits should be set
4408
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4409
    fork
4410
    begin
4411
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4412
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4413
        begin
4414
            $display("Parity checker testing failed! Time %t ", $time) ;
4415
            $display("Bridge failed to process single memory write!") ;
4416
            test_fail("bridge failed to post single memory write") ;
4417
            disable main ;
4418
        end
4419
    end
4420
    begin
4421
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4422
 
4423
        if ( ok !== 1 )
4424
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4425
        else
4426
            test_ok ;
4427
 
4428
        repeat(3)
4429
            @(posedge pci_clock) ;
4430
    end
4431
    join
4432
 
4433
    `ifdef HOST
4434
    repeat(4)
4435
        @(posedge wb_clock) ;
4436
    `endif
4437
 
4438
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4439
    ok = 1 ;
4440
 
4441
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4442
    if ( temp_val1[31] !== 0 )
4443
    begin
4444
        $display("Parity checker testing failed! Time %t ", $time) ;
4445
        $display("Detected Parity Error bit was set for no reason!") ;
4446
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4447
        ok = 0 ;
4448
    end
4449
 
4450
    if ( temp_val1[30] !== 0 )
4451
    begin
4452
        $display("Parity checker testing failed! Time %t ", $time) ;
4453
        $display("Signalled System Error bit was set for no reason!") ;
4454
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4455
        ok = 0 ;
4456
    end
4457
 
4458
    if ( temp_val1[24] !== 0 )
4459
    begin
4460
        $display("Parity checker testing failed! Time %t ", $time) ;
4461
        $display("Master Data Parity Error bit was set for no reason!") ;
4462
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4463
        ok = 0 ;
4464
    end
4465
 
4466
    if ( ok )
4467
        test_ok ;
4468
 
4469
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4470
 
4471
    read_data = 0 ;
4472
    read_data`READ_ADDRESS  = target_address ;
4473
    read_data`READ_SEL      = 4'hF ;
4474
    read_data`READ_TAG_STIM = 0 ;
4475
 
4476
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4477
 
4478
    // enable parity and system error interrupts
4479
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4480
 
4481
    // enable parity error response
4482
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4483
 
4484
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4485
 
4486
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4487
    fork
4488
    begin
4489
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4490
    end
4491
    begin:wait_perr4
4492
        perr_asserted = 0 ;
4493
        @(posedge pci_clock) ;
4494 35 mihad
        while ( PERR !== 0 )
4495 15 mihad
            @(posedge pci_clock) ;
4496
 
4497 35 mihad
        perr_asserted = 1 ;
4498 15 mihad
 
4499
    end
4500
    begin
4501
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4502
 
4503
        if ( ok !== 1 )
4504
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4505
 
4506
        repeat(2)
4507
            @(posedge pci_clock) ;
4508
 
4509 35 mihad
        #1 ;
4510
        if ( !perr_asserted )
4511
            disable wait_perr4 ;
4512 15 mihad
    end
4513
    join
4514
 
4515
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4516
    begin
4517
        $display("Parity checker testing failed! Time %t ", $time) ;
4518
        $display("Bridge failed to process single memory read!") ;
4519
        test_fail("bridge didn't process single memory read correctly") ;
4520
        ok = 0 ;
4521
    end
4522
 
4523
    if ( perr_asserted && ok )
4524
    begin
4525
        test_ok ;
4526
    end
4527
    else
4528
    if ( ~perr_asserted )
4529
    begin
4530
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4531
        disable main ;
4532
    end
4533
 
4534
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4535
    // interrupt should also be present
4536
    `ifdef HOST
4537
        repeat(4)
4538 26 mihad
            @(posedge pci_clock) ;
4539
        repeat(4)
4540 15 mihad
            @(posedge wb_clock) ;
4541
 
4542
        if ( INT_O !== 1 )
4543
        begin
4544
            $display("Parity checker testing failed! Time %t ", $time) ;
4545
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4546
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4547
        end
4548
        else
4549
            test_ok ;
4550
    `else
4551
    `ifdef GUEST
4552 26 mihad
        repeat(4)
4553
            @(posedge wb_clock) ;
4554
        repeat(4)
4555 15 mihad
            @(posedge pci_clock) ;
4556
 
4557
        if ( INTA !== 1 )
4558
        begin
4559
            $display("Parity checker testing failed! Time %t ", $time) ;
4560
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4561
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4562
        end
4563
        else
4564
            test_ok ;
4565
    `endif
4566
    `endif
4567
 
4568
    // check statuses!
4569
 
4570
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4571
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4572
    ok = 1 ;
4573
 
4574
    if ( temp_val1[31] !== 1 )
4575
    begin
4576
        $display("Parity checker testing failed! Time %t ", $time) ;
4577 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4578
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4579 15 mihad
        ok = 0 ;
4580
    end
4581
 
4582
    if ( temp_val1[30] !== 0 )
4583
    begin
4584
        $display("Parity checker testing failed! Time %t ", $time) ;
4585
        $display("Signalled System Error bit was set for no reason!") ;
4586
        test_fail("Signalled System Error bit was set for no reason") ;
4587
        ok = 0 ;
4588
    end
4589
 
4590
    if ( temp_val1[24] !== 1 )
4591
    begin
4592
        $display("Parity checker testing failed! Time %t ", $time) ;
4593 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4594
        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") ;
4595 15 mihad
        ok = 0 ;
4596
    end
4597
 
4598
    if ( ok )
4599
        test_ok ;
4600
 
4601
    // clear statuses and disable parity error response
4602
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4603
 
4604
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4605
    ok = 1 ;
4606
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4607
 
4608
    if ( temp_val1[4] !== 0 )
4609
    begin
4610
        $display("Parity checker testing failed! Time %t ", $time) ;
4611
        $display("System error interrupt status bit set for no reason!") ;
4612
        test_fail("System error interrupt status bit set for no reason") ;
4613
        ok = 0 ;
4614
    end
4615
 
4616
    `ifdef HOST
4617
    if ( temp_val1[3] !== 1 )
4618
    begin
4619
        $display("Parity checker testing failed! Time %t ", $time) ;
4620
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4621
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4622
        ok = 0 ;
4623
    end
4624
    `else
4625
    if ( temp_val1[3] !== 0 )
4626
    begin
4627
        $display("Parity checker testing failed! Time %t ", $time) ;
4628
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4629
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4630
        ok = 0 ;
4631
    end
4632
    `endif
4633
 
4634
    if ( ok )
4635
        test_ok ;
4636
 
4637
    // clear int statuses
4638
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4639
 
4640
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4641
 
4642
    `ifdef HOST
4643
        repeat(4)
4644 26 mihad
            @(posedge pci_clock) ;
4645
        repeat(4)
4646 15 mihad
            @(posedge wb_clock) ;
4647
 
4648
        if ( INT_O !== 0 )
4649
        begin
4650
            $display("Parity checker testing failed! Time %t ", $time) ;
4651
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4652
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4653
        end
4654
        else
4655
            test_ok ;
4656
    `else
4657
    `ifdef GUEST
4658 26 mihad
        repeat(4)
4659
            @(posedge wb_clock) ;
4660
        repeat(4)
4661 15 mihad
            @(posedge pci_clock) ;
4662
 
4663
        if ( INTA !== 1 )
4664
        begin
4665
            $display("Parity checker testing failed! Time %t ", $time) ;
4666
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4667
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4668
        end
4669
        else
4670
            test_ok ;
4671
    `endif
4672
    `endif
4673
 
4674
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4675
 
4676
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4677
    fork
4678
    begin
4679
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4680
    end
4681
    begin:wait_perr5
4682
        perr_asserted = 0 ;
4683
        @(posedge pci_clock) ;
4684
        while ( PERR === 1 )
4685
            @(posedge pci_clock) ;
4686
 
4687
        perr_asserted = 1 ;
4688
        $display("Parity checker testing failed! Time %t ", $time) ;
4689 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4690
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4691 15 mihad
    end
4692
    begin
4693
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4694
        if ( ok !== 1 )
4695
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4696
 
4697
        // perr can be asserted on idle or next PCI address phase
4698
        repeat(2)
4699
            @(posedge pci_clock) ;
4700
 
4701 35 mihad
        #1 ;
4702
        if ( !perr_asserted )
4703
            disable wait_perr5 ;
4704 15 mihad
    end
4705
    join
4706
 
4707
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4708
    begin
4709
        $display("Parity checker testing failed! Time %t ", $time) ;
4710
        $display("Bridge failed to process single memory read!") ;
4711
        test_fail("bridge failed to process single memory read correctly") ;
4712
        ok = 0 ;
4713
    end
4714
 
4715
    if ( ok && !perr_asserted)
4716
        test_ok ;
4717
 
4718
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4719
 
4720
    // interrupts should not be present
4721
    `ifdef HOST
4722
        repeat( 4 )
4723 26 mihad
            @(posedge pci_clock) ;
4724
        repeat( 4 )
4725 15 mihad
            @(posedge wb_clock) ;
4726
        if ( INT_O !== 0 )
4727
        begin
4728
            $display("Parity checker testing failed! Time %t ", $time) ;
4729
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4730
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4731
        end
4732
        else
4733
            test_ok ;
4734
    `else
4735
    `ifdef GUEST
4736
        repeat( 4 )
4737 26 mihad
            @(posedge wb_clock) ;
4738
        repeat( 4 )
4739 15 mihad
            @(posedge pci_clock) ;
4740
        if ( INTA !== 1 )
4741
        begin
4742
            $display("Parity checker testing failed! Time %t ", $time) ;
4743
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4744
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4745
        end
4746
        else
4747
            test_ok ;
4748
    `endif
4749
    `endif
4750
 
4751
    // check statuses!
4752
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4753
    ok = 1 ;
4754
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4755
    if ( temp_val1[31] !== 1 )
4756
    begin
4757
        $display("Parity checker testing failed! Time %t ", $time) ;
4758 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4759 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4760
        ok = 0 ;
4761
    end
4762
 
4763
    if ( temp_val1[30] !== 0 )
4764
    begin
4765
        $display("Parity checker testing failed! Time %t ", $time) ;
4766
        $display("Signalled System Error bit was set for no reason!") ;
4767
        test_fail("Signalled System Error bit was set for no reason") ;
4768
        ok = 0 ;
4769
    end
4770
 
4771
    if ( temp_val1[24] !== 0 )
4772
    begin
4773
        $display("Parity checker testing failed! Time %t ", $time) ;
4774 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4775 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4776
        ok = 0 ;
4777
    end
4778
 
4779
    if ( ok )
4780
        test_ok ;
4781
 
4782
    // clear statuses
4783
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4784
 
4785
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4786
    ok = 1 ;
4787
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4788
 
4789
    if ( temp_val1[4] !== 0 )
4790
    begin
4791
        $display("Parity checker testing failed! Time %t ", $time) ;
4792
        $display("System error interrupt status bit set for no reason!") ;
4793
        test_fail("System error interrupt status bit set for no reason") ;
4794
        ok = 0 ;
4795
    end
4796
 
4797
    if ( temp_val1[3] !== 0 )
4798
    begin
4799
        $display("Parity checker testing failed! Time %t ", $time) ;
4800
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4801
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4802
        ok = 0 ;
4803
    end
4804
 
4805
    if ( ok )
4806
        test_ok ;
4807
 
4808
    // enable all responses to parity errors!
4809
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4810
 
4811
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4812
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4813
 
4814
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4815
 
4816
    // repeat a read
4817
    fork
4818
    begin
4819
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4820
    end
4821
    begin:wait_perr6
4822
        perr_asserted = 0 ;
4823
        @(posedge pci_clock) ;
4824
        while ( PERR === 1 )
4825
            @(posedge pci_clock) ;
4826
 
4827
        perr_asserted = 1 ;
4828
        $display("Parity checker testing failed! Time %t ", $time) ;
4829
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4830
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4831
    end
4832
    begin
4833
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4834
        if ( ok !== 1 )
4835
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4836
 
4837
        repeat(2)
4838
            @(posedge pci_clock) ;
4839
 
4840 35 mihad
        #1 ;
4841
        if ( !perr_asserted )
4842
            disable wait_perr6 ;
4843 15 mihad
    end
4844
    join
4845
 
4846
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4847
    begin
4848
        $display("Parity checker testing failed! Time %t ", $time) ;
4849
        $display("Bridge failed to process single memory read!") ;
4850
        test_fail("bridge didn't process single memory read as expected") ;
4851
        ok = 0 ;
4852
    end
4853
 
4854
    if ( ok && !perr_asserted)
4855
        test_ok ;
4856
 
4857
    // check statuses!
4858
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4859
    ok = 1 ;
4860
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4861
    if ( temp_val1[31] !== 0 )
4862
    begin
4863
        $display("Parity checker testing failed! Time %t ", $time) ;
4864
        $display("Detected Parity Error bit was set for no reason!") ;
4865
        test_fail("Detected Parity Error bit was set for no reason") ;
4866
        ok = 0 ;
4867
    end
4868
 
4869
    if ( temp_val1[30] !== 0 )
4870
    begin
4871
        $display("Parity checker testing failed! Time %t ", $time) ;
4872
        $display("Signalled System Error bit was set for no reason!") ;
4873
        test_fail("Signalled System Error bit was set for no reason") ;
4874
        ok = 0 ;
4875
    end
4876
 
4877
    if ( temp_val1[24] !== 0 )
4878
    begin
4879
        $display("Parity checker testing failed! Time %t ", $time) ;
4880
        $display("Master Data Parity Error bit was set for no reason!") ;
4881
        test_fail("Master Data Parity Error bit was set for no reason") ;
4882
        ok = 0 ;
4883
    end
4884
 
4885
    if ( ok )
4886
        test_ok ;
4887
 
4888
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4889
    ok = 1 ;
4890
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4891
 
4892
    if ( temp_val1[4] !== 0 )
4893
    begin
4894
        $display("Parity checker testing failed! Time %t ", $time) ;
4895
        $display("System error interrupt status bit set for no reason!") ;
4896
        test_fail("System error interrupt status bit set for no reason") ;
4897
        ok = 0 ;
4898
    end
4899
 
4900
    if ( temp_val1[3] !== 0 )
4901
    begin
4902
        $display("Parity checker testing failed! Time %t ", $time) ;
4903
        $display("Parity error interrupt status bit set for no reason!") ;
4904
        test_fail("Parity error interrupt status bit set for no reason") ;
4905
        ok = 0 ;
4906
    end
4907
 
4908
    if ( ok )
4909
        test_ok ;
4910
 
4911
    $display("Presenting address parity error on PCI bus!") ;
4912
    // enable parity errors - this should not affect system errors
4913
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4914
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4915
 
4916
    // perform PCI write
4917
    // check transaction progress
4918
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4919
    fork
4920
    begin
4921
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4922
               target_address, 32'h1234_5678,
4923
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4924
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4925
        do_pause( 1 ) ;
4926
    end
4927
    begin:wait_serr7
4928
        perr_asserted = 0 ;
4929
        @(posedge pci_clock) ;
4930
        while( SERR === 1 )
4931
            @(posedge pci_clock) ;
4932
 
4933
        perr_asserted = 1 ;
4934
        $display("Parity checker testing failed! Time %t ", $time) ;
4935
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4936
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4937
    end
4938
    begin
4939
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4940
        if ( ok !== 1 )
4941
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4942
 
4943 35 mihad
        if ( !perr_asserted )
4944
            disable wait_serr7 ;
4945 15 mihad
    end
4946
    join
4947
 
4948
    if ( ok && !perr_asserted)
4949
        test_ok ;
4950
 
4951
    // check statuses!
4952
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4953
    ok = 1 ;
4954
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4955
    if ( temp_val1[31] !== 1 )
4956
    begin
4957
        $display("Parity checker testing failed! Time %t ", $time) ;
4958
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4959
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4960
        ok = 0 ;
4961
    end
4962
 
4963
    if ( temp_val1[30] !== 0 )
4964
    begin
4965
        $display("Parity checker testing failed! Time %t ", $time) ;
4966
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4967
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4968
        ok = 0 ;
4969
    end
4970
 
4971
    if ( temp_val1[24] !== 0 )
4972
    begin
4973
        $display("Parity checker testing failed! Time %t ", $time) ;
4974
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4975
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4976
        ok = 0 ;
4977
    end
4978
 
4979
    if ( ok )
4980
        test_ok ;
4981
 
4982
    // clear statuses
4983
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4984
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4985
    fork
4986
    begin
4987 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
4988 15 mihad
        (
4989
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4990
            32'h5555_5555,      // second part of address in dual address cycle
4991
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4992
            `BC_MEM_WRITE,      // normal command
4993
            4'h0,               // byte enables
4994
            32'h1234_5678,      // data
4995
            1'b1,               // make address parity error on first phase of dual address
4996
            1'b0,               // make address parity error on second phase of dual address
4997
            ok                  // result of operation
4998
        ) ;
4999 35 mihad
        if ( !perr_asserted )
5000
            disable wait_serr8 ;
5001 15 mihad
    end
5002
    begin:wait_serr8
5003
        perr_asserted = 0 ;
5004
        @(posedge pci_clock) ;
5005
        while( SERR === 1 )
5006
            @(posedge pci_clock) ;
5007
 
5008
        perr_asserted = 1 ;
5009
        $display("Parity checker testing failed! Time %t ", $time) ;
5010
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5011
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5012
    end
5013
    join
5014
 
5015
    if ( ok && !perr_asserted)
5016
        test_ok ;
5017
 
5018
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5019
    fork
5020
    begin
5021 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5022 15 mihad
        (
5023
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5024
            32'h5555_5555,      // second part of address in dual address cycle
5025
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5026
            `BC_MEM_WRITE,      // normal command
5027
            4'h0,               // byte enables
5028
            32'h1234_5678,      // data
5029
            1'b0,               // make address parity error on first phase of dual address
5030
            1'b1,               // make address parity error on second phase of dual address
5031
            ok                  // result of operation
5032
        ) ;
5033 35 mihad
        if ( !perr_asserted )
5034
            disable wait_serr9 ;
5035 15 mihad
    end
5036
    begin:wait_serr9
5037
        perr_asserted = 0 ;
5038
        @(posedge pci_clock) ;
5039
        while( SERR === 1 )
5040
            @(posedge pci_clock) ;
5041
 
5042
        perr_asserted = 1 ;
5043
        $display("Parity checker testing failed! Time %t ", $time) ;
5044
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5045
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5046
    end
5047
    join
5048
 
5049
    if ( ok && !perr_asserted)
5050
        test_ok ;
5051
 
5052
    // check statuses!
5053
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5054
    ok = 1 ;
5055
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5056
    if ( temp_val1[31] !== 1 )
5057
    begin
5058
        $display("Parity checker testing failed! Time %t ", $time) ;
5059
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5060
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5061
        ok = 0 ;
5062
    end
5063
 
5064
    if ( temp_val1[30] !== 0 )
5065
    begin
5066
        $display("Parity checker testing failed! Time %t ", $time) ;
5067
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5068
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5069
        ok = 0 ;
5070
    end
5071
 
5072
    if ( temp_val1[24] !== 0 )
5073
    begin
5074
        $display("Parity checker testing failed! Time %t ", $time) ;
5075
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5076
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5077
        ok = 0 ;
5078
    end
5079
 
5080
    if ( ok )
5081
        test_ok ;
5082
 
5083
    // clear statuses
5084
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5085
 
5086
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5087
    fork
5088
    begin
5089 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5090 15 mihad
        (
5091
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5092
            32'h5555_5555,      // second part of address in dual address cycle
5093
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5094
            `BC_MEM_WRITE,      // normal command
5095
            4'h0,               // byte enables
5096
            32'h1234_5678,      // data
5097
            1'b1,               // make address parity error on first phase of dual address
5098
            1'b1,               // make address parity error on second phase of dual address
5099
            ok                  // result of operation
5100
        ) ;
5101 35 mihad
        if ( !perr_asserted )
5102
            disable wait_serr10 ;
5103 15 mihad
    end
5104
    begin:wait_serr10
5105
        perr_asserted = 0 ;
5106
        @(posedge pci_clock) ;
5107
        while( SERR === 1 )
5108
            @(posedge pci_clock) ;
5109
 
5110
        perr_asserted = 1 ;
5111
        $display("Parity checker testing failed! Time %t ", $time) ;
5112
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5113
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5114
    end
5115
    join
5116
 
5117
    if ( ok && !perr_asserted)
5118
        test_ok ;
5119
 
5120
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5121
 
5122
    `ifdef HOST
5123
        repeat(4)
5124 26 mihad
            @(posedge pci_clock) ;
5125
        repeat(4)
5126 15 mihad
            @(posedge wb_clock) ;
5127
        if ( INT_O !== 0 )
5128
        begin
5129
            $display("Parity checker testing failed! Time %t ", $time) ;
5130
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5131
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5132
        end
5133
        else
5134
            test_ok ;
5135
    `else
5136
    `ifdef GUEST
5137 26 mihad
        repeat(4)
5138
            @(posedge wb_clock) ;
5139
        repeat(4)
5140 15 mihad
            @(posedge pci_clock) ;
5141
 
5142
        if ( INTA !== 1 )
5143
        begin
5144
            $display("Parity checker testing failed! Time %t ", $time) ;
5145
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5146
            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") ;
5147
        end
5148
        else
5149
            test_ok ;
5150
    `endif
5151
    `endif
5152
 
5153
    // check statuses!
5154
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5155
    ok = 1 ;
5156
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5157
    if ( temp_val1[31] !== 1 )
5158
    begin
5159
        $display("Parity checker testing failed! Time %t ", $time) ;
5160
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5161
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5162
        ok = 0 ;
5163
    end
5164
 
5165
    if ( temp_val1[30] !== 0 )
5166
    begin
5167
        $display("Parity checker testing failed! Time %t ", $time) ;
5168
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5169
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5170
        ok = 0 ;
5171
    end
5172
 
5173
    if ( temp_val1[24] !== 0 )
5174
    begin
5175
        $display("Parity checker testing failed! Time %t ", $time) ;
5176
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5177
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5178
        ok = 0 ;
5179
    end
5180
 
5181
    if ( ok )
5182
        test_ok ;
5183
 
5184
    // clear statuses
5185
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5186
 
5187
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5188
    ok = 1 ;
5189
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5190
 
5191
    if ( temp_val1[4] !== 0 )
5192
    begin
5193
        $display("Parity checker testing failed! Time %t ", $time) ;
5194
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5195
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5196
        ok = 0 ;
5197
    end
5198
 
5199
    if ( temp_val1[3] !== 0 )
5200
    begin
5201
        $display("Parity checker testing failed! Time %t ", $time) ;
5202
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5203
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5204
        ok = 0 ;
5205
    end
5206
 
5207
    if ( ok )
5208
        test_ok ;
5209
 
5210
    // now enable system error signaling and test response
5211
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5212
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5213
 
5214
    fork
5215
    begin
5216
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5217
               target_address, 32'h1234_5678,
5218
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5219
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5220
        do_pause( 1 ) ;
5221
    end
5222
    begin:wait_serr11
5223
        perr_asserted = 0 ;
5224
        @(posedge pci_clock) ;
5225 35 mihad
        while( SERR !== 0 )
5226 15 mihad
            @(posedge pci_clock) ;
5227
 
5228 35 mihad
        perr_asserted = 1 ;
5229 15 mihad
    end
5230
    begin
5231
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5232
        if ( ok !== 1 )
5233
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5234
 
5235
        @(posedge pci_clock) ;
5236 35 mihad
        #1 ;
5237
        if ( !perr_asserted )
5238
            disable wait_serr11 ;
5239 15 mihad
    end
5240
    join
5241
 
5242
    if ( ok && perr_asserted)
5243
        test_ok ;
5244
    else
5245
    if ( !perr_asserted )
5246
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5247
 
5248
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5249
 
5250
    `ifdef HOST
5251
        repeat(4)
5252 26 mihad
            @(posedge pci_clock) ;
5253
        repeat(4)
5254 15 mihad
            @(posedge wb_clock) ;
5255
        if ( INT_O !== 1 )
5256
        begin
5257
            $display("Parity checker testing failed! Time %t ", $time) ;
5258
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5259
            test_fail("Interrupt Request was not triggered as expected") ;
5260
        end
5261
        else
5262
            test_ok ;
5263
    `else
5264
    `ifdef GUEST
5265 26 mihad
        repeat(4)
5266
            @(posedge wb_clock) ;
5267
        repeat(4)
5268 15 mihad
            @(posedge pci_clock) ;
5269
 
5270
        if ( INTA !== 1 )
5271
        begin
5272
            $display("Parity checker testing failed! Time %t ", $time) ;
5273
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5274
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5275
        end
5276
        else
5277
            test_ok ;
5278
    `endif
5279
    `endif
5280
 
5281
    // check statuses!
5282
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5283
    ok = 1 ;
5284
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5285
    if ( temp_val1[31] !== 1 )
5286
    begin
5287
        $display("Parity checker testing failed! Time %t ", $time) ;
5288
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5289
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5290
        ok = 0 ;
5291
    end
5292
 
5293
    if ( temp_val1[30] !== 1 )
5294
    begin
5295
        $display("Parity checker testing failed! Time %t ", $time) ;
5296
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5297
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5298
        ok = 0 ;
5299
    end
5300
 
5301
    if ( temp_val1[24] !== 0 )
5302
    begin
5303
        $display("Parity checker testing failed! Time %t ", $time) ;
5304
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5305
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5306
        ok = 0 ;
5307
    end
5308
 
5309
    if ( ok )
5310
        test_ok ;
5311
 
5312
    // clear statuses
5313
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5314
 
5315
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5316
 
5317
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5318
    ok = 1 ;
5319
 
5320
    `ifdef HOST
5321
    if ( temp_val1[4] !== 1 )
5322
    begin
5323
        $display("Parity checker testing failed! Time %t ", $time) ;
5324
        $display("System error interrupt status bit not set when expected!") ;
5325
        test_fail("System error interrupt status bit not set when expected") ;
5326
        ok = 0 ;
5327
    end
5328
    `else
5329
    if ( temp_val1[4] !== 0 )
5330
    begin
5331
        $display("Parity checker testing failed! Time %t ", $time) ;
5332
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5333
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5334
        ok = 0 ;
5335
    end
5336
    `endif
5337
 
5338
    if ( temp_val1[3] !== 0 )
5339
    begin
5340
        $display("Parity checker testing failed! Time %t ", $time) ;
5341
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5342
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5343
        ok = 0 ;
5344
    end
5345
 
5346
    if ( ok )
5347
        test_ok ;
5348
 
5349
    // clear statuses
5350
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5351
 
5352
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5353
    fork
5354
    begin
5355 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5356 15 mihad
        (
5357
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5358
            32'h5555_5555,      // second part of address in dual address cycle
5359
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5360
            `BC_MEM_WRITE,      // normal command
5361
            4'h0,               // byte enables
5362
            32'h1234_5678,      // data
5363
            1'b1,               // make address parity error on first phase of dual address
5364
            1'b0,               // make address parity error on second phase of dual address
5365
            ok                  // result of operation
5366
        ) ;
5367 35 mihad
        if ( !perr_asserted )
5368
            disable wait_serr14 ;
5369 15 mihad
    end
5370
    begin:wait_serr14
5371
        perr_asserted = 0 ;
5372
        @(posedge pci_clock) ;
5373 35 mihad
        while( SERR !== 0 )
5374 15 mihad
            @(posedge pci_clock) ;
5375
 
5376 35 mihad
        perr_asserted = 1 ;
5377 15 mihad
    end
5378
    join
5379
 
5380
    if ( ok && perr_asserted)
5381
        test_ok ;
5382
    else
5383
    if ( !perr_asserted )
5384
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5385
 
5386
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5387
 
5388
    `ifdef HOST
5389
        repeat(4)
5390 26 mihad
            @(posedge pci_clock) ;
5391
        repeat(4)
5392 15 mihad
            @(posedge wb_clock) ;
5393
        if ( INT_O !== 1 )
5394
        begin
5395
            $display("Parity checker testing failed! Time %t ", $time) ;
5396
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5397
            test_fail("Interrupt Request was not triggered as expected") ;
5398
        end
5399
        else
5400
            test_ok ;
5401
    `else
5402
    `ifdef GUEST
5403 26 mihad
        repeat(4)
5404
            @(posedge wb_clock) ;
5405
        repeat(4)
5406 15 mihad
            @(posedge pci_clock) ;
5407
 
5408
        if ( INTA !== 1 )
5409
        begin
5410
            $display("Parity checker testing failed! Time %t ", $time) ;
5411
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5412
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5413
        end
5414
        else
5415
            test_ok ;
5416
    `endif
5417
    `endif
5418
 
5419
    // check statuses!
5420
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5421
    ok = 1 ;
5422
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5423
    if ( temp_val1[31] !== 1 )
5424
    begin
5425
        $display("Parity checker testing failed! Time %t ", $time) ;
5426
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5427
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5428
        ok = 0 ;
5429
    end
5430
 
5431
    if ( temp_val1[30] !== 1 )
5432
    begin
5433
        $display("Parity checker testing failed! Time %t ", $time) ;
5434
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5435
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5436
        ok = 0 ;
5437
    end
5438
 
5439
    if ( temp_val1[24] !== 0 )
5440
    begin
5441
        $display("Parity checker testing failed! Time %t ", $time) ;
5442
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5443
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5444
        ok = 0 ;
5445
    end
5446
 
5447
    if ( ok )
5448
        test_ok ;
5449
 
5450
    // clear statuses
5451
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5452
 
5453
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5454
 
5455
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5456
    ok = 1 ;
5457
 
5458
    `ifdef HOST
5459
    if ( temp_val1[4] !== 1 )
5460
    begin
5461
        $display("Parity checker testing failed! Time %t ", $time) ;
5462
        $display("System error interrupt status bit not set when expected!") ;
5463
        test_fail("System error interrupt status bit not set when expected") ;
5464
        ok = 0 ;
5465
    end
5466
    `else
5467
    if ( temp_val1[4] !== 0 )
5468
    begin
5469
        $display("Parity checker testing failed! Time %t ", $time) ;
5470
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5471
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5472
        ok = 0 ;
5473
    end
5474
    `endif
5475
 
5476
    if ( temp_val1[3] !== 0 )
5477
    begin
5478
        $display("Parity checker testing failed! Time %t ", $time) ;
5479
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5480
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5481
        ok = 0 ;
5482
    end
5483
 
5484
    if ( ok )
5485
        test_ok ;
5486
 
5487
    // clear statuses
5488
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5489
 
5490
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5491
    fork
5492
    begin
5493 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5494 15 mihad
        (
5495
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5496
            32'h5555_5555,      // second part of address in dual address cycle
5497
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5498
            `BC_MEM_WRITE,      // normal command
5499
            4'h0,               // byte enables
5500
            32'h1234_5678,      // data
5501
            1'b0,               // make address parity error on first phase of dual address
5502
            1'b1,               // make address parity error on second phase of dual address
5503
            ok                  // result of operation
5504
        ) ;
5505 35 mihad
        if ( !perr_asserted )
5506
            disable wait_serr15 ;
5507 15 mihad
    end
5508
    begin:wait_serr15
5509
        perr_asserted = 0 ;
5510
        @(posedge pci_clock) ;
5511 35 mihad
        while( SERR !== 0 )
5512 15 mihad
            @(posedge pci_clock) ;
5513
 
5514 35 mihad
        perr_asserted = 1 ;
5515 15 mihad
    end
5516
    join
5517
 
5518
    if ( ok && perr_asserted)
5519
        test_ok ;
5520
    else
5521
    if ( !perr_asserted )
5522
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5523
 
5524
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5525
 
5526
    `ifdef HOST
5527
        repeat(4)
5528 26 mihad
            @(posedge pci_clock) ;
5529
        repeat(4)
5530 15 mihad
            @(posedge wb_clock) ;
5531
        if ( INT_O !== 1 )
5532
        begin
5533
            $display("Parity checker testing failed! Time %t ", $time) ;
5534
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5535
            test_fail("Interrupt Request was not triggered as expected") ;
5536
        end
5537
        else
5538
            test_ok ;
5539
    `else
5540
    `ifdef GUEST
5541 26 mihad
        repeat(4)
5542
            @(posedge wb_clock) ;
5543
        repeat(4)
5544 15 mihad
            @(posedge pci_clock) ;
5545
 
5546
        if ( INTA !== 1 )
5547
        begin
5548
            $display("Parity checker testing failed! Time %t ", $time) ;
5549
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5550
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5551
        end
5552
        else
5553
            test_ok ;
5554
    `endif
5555
    `endif
5556
 
5557
    // check statuses!
5558
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5559
    ok = 1 ;
5560
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5561
    if ( temp_val1[31] !== 1 )
5562
    begin
5563
        $display("Parity checker testing failed! Time %t ", $time) ;
5564
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5565
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5566
        ok = 0 ;
5567
    end
5568
 
5569
    if ( temp_val1[30] !== 1 )
5570
    begin
5571
        $display("Parity checker testing failed! Time %t ", $time) ;
5572
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5573
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5574
        ok = 0 ;
5575
    end
5576
 
5577
    if ( temp_val1[24] !== 0 )
5578
    begin
5579
        $display("Parity checker testing failed! Time %t ", $time) ;
5580
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5581
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5582
        ok = 0 ;
5583
    end
5584
 
5585
    if ( ok )
5586
        test_ok ;
5587
 
5588
    // clear statuses
5589
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5590
 
5591
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5592
 
5593
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5594
    ok = 1 ;
5595
 
5596
    `ifdef HOST
5597
    if ( temp_val1[4] !== 1 )
5598
    begin
5599
        $display("Parity checker testing failed! Time %t ", $time) ;
5600
        $display("System error interrupt status bit not set when expected!") ;
5601
        test_fail("System error interrupt status bit not set when expected") ;
5602
        ok = 0 ;
5603
    end
5604
    `else
5605
    if ( temp_val1[4] !== 0 )
5606
    begin
5607
        $display("Parity checker testing failed! Time %t ", $time) ;
5608
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5609
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5610
        ok = 0 ;
5611
    end
5612
    `endif
5613
 
5614
    if ( temp_val1[3] !== 0 )
5615
    begin
5616
        $display("Parity checker testing failed! Time %t ", $time) ;
5617
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5618
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5619
        ok = 0 ;
5620
    end
5621
 
5622
    if ( ok )
5623
        test_ok ;
5624
 
5625
    // clear statuses
5626
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5627
 
5628
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5629
    fork
5630
    begin
5631 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5632 15 mihad
        (
5633
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5634
            32'h5555_5555,      // second part of address in dual address cycle
5635
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5636
            `BC_MEM_WRITE,      // normal command
5637
            4'h0,               // byte enables
5638
            32'h1234_5678,      // data
5639
            1'b1,               // make address parity error on first phase of dual address
5640
            1'b1,               // make address parity error on second phase of dual address
5641
            ok                  // result of operation
5642
        ) ;
5643 35 mihad
        if ( !perr_asserted )
5644
            disable wait_serr16 ;
5645 15 mihad
    end
5646
    begin:wait_serr16
5647
        perr_asserted = 0 ;
5648
        @(posedge pci_clock) ;
5649 35 mihad
        while( SERR !== 0 )
5650 15 mihad
            @(posedge pci_clock) ;
5651
 
5652 35 mihad
        perr_asserted = 1 ;
5653 15 mihad
    end
5654
    join
5655
 
5656
    if ( ok && perr_asserted)
5657
        test_ok ;
5658
    else
5659
    if ( !perr_asserted )
5660
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5661
 
5662
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5663
 
5664
    `ifdef HOST
5665
        repeat(4)
5666 26 mihad
            @(posedge pci_clock) ;
5667
        repeat(4)
5668 15 mihad
            @(posedge wb_clock) ;
5669
        if ( INT_O !== 1 )
5670
        begin
5671
            $display("Parity checker testing failed! Time %t ", $time) ;
5672
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5673
            test_fail("Interrupt Request was not triggered as expected") ;
5674
        end
5675
        else
5676
            test_ok ;
5677
    `else
5678
    `ifdef GUEST
5679 26 mihad
        repeat(4)
5680
            @(posedge wb_clock) ;
5681
        repeat(4)
5682 15 mihad
            @(posedge pci_clock) ;
5683
 
5684
        if ( INTA !== 1 )
5685
        begin
5686
            $display("Parity checker testing failed! Time %t ", $time) ;
5687
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5688
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5689
        end
5690
        else
5691
            test_ok ;
5692
    `endif
5693
    `endif
5694
 
5695
    // check statuses!
5696
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5697
    ok = 1 ;
5698
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5699
    if ( temp_val1[31] !== 1 )
5700
    begin
5701
        $display("Parity checker testing failed! Time %t ", $time) ;
5702
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5703
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5704
        ok = 0 ;
5705
    end
5706
 
5707
    if ( temp_val1[30] !== 1 )
5708
    begin
5709
        $display("Parity checker testing failed! Time %t ", $time) ;
5710
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5711
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5712
        ok = 0 ;
5713
    end
5714
 
5715
    if ( temp_val1[24] !== 0 )
5716
    begin
5717
        $display("Parity checker testing failed! Time %t ", $time) ;
5718
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5719
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5720
        ok = 0 ;
5721
    end
5722
 
5723
    if ( ok )
5724
        test_ok ;
5725
 
5726
    // clear statuses
5727
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5728
 
5729
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5730
 
5731
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5732
    ok = 1 ;
5733
 
5734
    `ifdef HOST
5735
    if ( temp_val1[4] !== 1 )
5736
    begin
5737
        $display("Parity checker testing failed! Time %t ", $time) ;
5738
        $display("System error interrupt status bit not set when expected!") ;
5739
        test_fail("System error interrupt status bit not set when expected") ;
5740
        ok = 0 ;
5741
    end
5742
    `else
5743
    if ( temp_val1[4] !== 0 )
5744
    begin
5745
        $display("Parity checker testing failed! Time %t ", $time) ;
5746
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5747
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5748
        ok = 0 ;
5749
    end
5750
    `endif
5751
 
5752
    if ( temp_val1[3] !== 0 )
5753
    begin
5754
        $display("Parity checker testing failed! Time %t ", $time) ;
5755
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5756
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5757
        ok = 0 ;
5758
    end
5759
 
5760
    if ( ok )
5761
        test_ok ;
5762
 
5763
    // clear statuses
5764
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5765
 
5766
    // now just disable Parity Error response - on Address par errors nothing should happen
5767
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5768
 
5769
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5770
    fork
5771
    begin
5772
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5773
               target_address, 32'h1234_5678,
5774
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5775
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5776
        do_pause( 1 ) ;
5777
    end
5778
    begin:wait_serr12
5779
        perr_asserted = 0 ;
5780
        @(posedge pci_clock) ;
5781
        while( SERR === 1 )
5782
            @(posedge pci_clock) ;
5783
 
5784
        perr_asserted = 1 ;
5785
        $display("Parity checker testing failed! Time %t ", $time) ;
5786
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5787
        test_fail("SERR asserted when parity error response was disabled") ;
5788
    end
5789
    begin
5790
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5791
        if ( ok !== 1 )
5792
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5793
 
5794 35 mihad
        @(posedge pci_clock) ;
5795
        #1 ;
5796
        if ( !perr_asserted )
5797
            disable wait_serr12 ;
5798 15 mihad
    end
5799
    join
5800
 
5801
    if ( ok && !perr_asserted )
5802
        test_ok ;
5803
 
5804
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5805
    `ifdef HOST
5806 26 mihad
        repeat (4)
5807
            @(posedge pci_clock) ;
5808 15 mihad
        repeat(4)
5809
            @(posedge wb_clock) ;
5810
        if ( INT_O !== 0 )
5811
        begin
5812
            $display("Parity checker testing failed! Time %t ", $time) ;
5813
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5814
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5815
        end
5816
        else
5817
            test_ok ;
5818
    `else
5819
    `ifdef GUEST
5820 26 mihad
        repeat(4)
5821
            @(posedge wb_clock) ;
5822
        repeat (4)
5823 15 mihad
            @(posedge pci_clock) ;
5824
 
5825
        if ( INTA !== 1 )
5826
        begin
5827
            $display("Parity checker testing failed! Time %t ", $time) ;
5828
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5829
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5830
        end
5831
        else
5832
            test_ok ;
5833
    `endif
5834
    `endif
5835
 
5836
    // check statuses!
5837
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5838
    ok = 1 ;
5839
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5840
    if ( temp_val1[31] !== 1 )
5841
    begin
5842
        $display("Parity checker testing failed! Time %t ", $time) ;
5843
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5844
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5845
        ok = 0 ;
5846
    end
5847
 
5848
    if ( temp_val1[30] !== 0 )
5849
    begin
5850
        $display("Parity checker testing failed! Time %t ", $time) ;
5851
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5852
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5853
        ok = 0 ;
5854
    end
5855
 
5856
    if ( temp_val1[24] !== 0 )
5857
    begin
5858
        $display("Parity checker testing failed! Time %t ", $time) ;
5859
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5860
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5861
        ok = 0 ;
5862
    end
5863
 
5864
    if ( ok )
5865
        test_ok ;
5866
 
5867
    // clear statuses
5868
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5869
 
5870
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5871
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5872
    ok = 1 ;
5873
    if ( temp_val1[4] !== 0 )
5874
    begin
5875
        $display("Parity checker testing failed! Time %t ", $time) ;
5876
        $display("System error interrupt status bit set when not expected!") ;
5877
        test_fail("System error interrupt status bit set when not expected") ;
5878
        ok = 0 ;
5879
    end
5880
 
5881
    if ( temp_val1[3] !== 0 )
5882
    begin
5883
        $display("Parity checker testing failed! Time %t ", $time) ;
5884
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5885
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5886
        ok = 0 ;
5887
    end
5888
 
5889
    if ( ok )
5890
        test_ok ;
5891
 
5892
    // clear statuses
5893
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5894
 
5895
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5896
    fork
5897
    begin
5898 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5899 15 mihad
        (
5900
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5901
            32'h5555_5555,      // second part of address in dual address cycle
5902
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5903
            `BC_MEM_WRITE,      // normal command
5904
            4'h0,               // byte enables
5905
            32'h1234_5678,      // data
5906
            1'b1,               // make address parity error on first phase of dual address
5907
            1'b0,               // make address parity error on second phase of dual address
5908
            ok                  // result of operation
5909
        ) ;
5910 35 mihad
        if ( !perr_asserted )
5911
            disable wait_serr17 ;
5912 15 mihad
    end
5913
    begin:wait_serr17
5914
        perr_asserted = 0 ;
5915
        @(posedge pci_clock) ;
5916
        while( SERR === 1 )
5917
            @(posedge pci_clock) ;
5918
 
5919
        perr_asserted = 1 ;
5920
        $display("Parity checker testing failed! Time %t ", $time) ;
5921
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5922
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5923
    end
5924
    join
5925
 
5926
    if ( ok && !perr_asserted)
5927
        test_ok ;
5928
 
5929
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5930
    fork
5931
    begin
5932 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5933 15 mihad
        (
5934
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5935
            32'h5555_5555,      // second part of address in dual address cycle
5936
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5937
            `BC_MEM_WRITE,      // normal command
5938
            4'h0,               // byte enables
5939
            32'h1234_5678,      // data
5940
            1'b0,               // make address parity error on first phase of dual address
5941
            1'b1,               // make address parity error on second phase of dual address
5942
            ok                  // result of operation
5943
        ) ;
5944 35 mihad
        if ( !perr_asserted )
5945
            disable wait_serr18 ;
5946 15 mihad
    end
5947
    begin:wait_serr18
5948
        perr_asserted = 0 ;
5949
        @(posedge pci_clock) ;
5950
        while( SERR === 1 )
5951
            @(posedge pci_clock) ;
5952
 
5953
        perr_asserted = 1 ;
5954
        $display("Parity checker testing failed! Time %t ", $time) ;
5955
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5956
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5957
    end
5958
    join
5959
 
5960
    if ( ok && !perr_asserted)
5961
        test_ok ;
5962
 
5963
    // check statuses!
5964
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5965
    ok = 1 ;
5966
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5967
    if ( temp_val1[31] !== 1 )
5968
    begin
5969
        $display("Parity checker testing failed! Time %t ", $time) ;
5970
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5971
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5972
        ok = 0 ;
5973
    end
5974
 
5975
    if ( temp_val1[30] !== 0 )
5976
    begin
5977
        $display("Parity checker testing failed! Time %t ", $time) ;
5978
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5979
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5980
        ok = 0 ;
5981
    end
5982
 
5983
    if ( temp_val1[24] !== 0 )
5984
    begin
5985
        $display("Parity checker testing failed! Time %t ", $time) ;
5986
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5987
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5988
        ok = 0 ;
5989
    end
5990
 
5991
    if ( ok )
5992
        test_ok ;
5993
 
5994
    // clear statuses
5995
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5996
 
5997
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5998
    fork
5999
    begin
6000 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
6001 15 mihad
        (
6002
            32'hAAAA_AAAA,      // first part of address in dual address cycle
6003
            32'h5555_5555,      // second part of address in dual address cycle
6004
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
6005
            `BC_MEM_WRITE,      // normal command
6006
            4'h0,               // byte enables
6007
            32'h1234_5678,      // data
6008
            1'b1,               // make address parity error on first phase of dual address
6009
            1'b1,               // make address parity error on second phase of dual address
6010
            ok                  // result of operation
6011
        ) ;
6012 35 mihad
        if ( !perr_asserted )
6013
            disable wait_serr19 ;
6014 15 mihad
    end
6015
    begin:wait_serr19
6016
        perr_asserted = 0 ;
6017
        @(posedge pci_clock) ;
6018
        while( SERR === 1 )
6019
            @(posedge pci_clock) ;
6020
 
6021
        perr_asserted = 1 ;
6022
        $display("Parity checker testing failed! Time %t ", $time) ;
6023
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
6024
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6025
    end
6026
    join
6027
 
6028
    if ( ok && !perr_asserted)
6029
        test_ok ;
6030
 
6031
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
6032
 
6033
    `ifdef HOST
6034
        repeat(4)
6035 26 mihad
            @(posedge pci_clock) ;
6036
        repeat(4)
6037 15 mihad
            @(posedge wb_clock) ;
6038
        if ( INT_O !== 0 )
6039
        begin
6040
            $display("Parity checker testing failed! Time %t ", $time) ;
6041
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
6042
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
6043
        end
6044
        else
6045
            test_ok ;
6046
    `else
6047
    `ifdef GUEST
6048 26 mihad
        repeat(4)
6049
            @(posedge wb_clock) ;
6050
        repeat(4)
6051 15 mihad
            @(posedge pci_clock) ;
6052
 
6053
        if ( INTA !== 1 )
6054
        begin
6055
            $display("Parity checker testing failed! Time %t ", $time) ;
6056
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
6057
            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") ;
6058
        end
6059
        else
6060
            test_ok ;
6061
    `endif
6062
    `endif
6063
 
6064
    // check statuses!
6065
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6066
    ok = 1 ;
6067
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6068
    if ( temp_val1[31] !== 1 )
6069
    begin
6070
        $display("Parity checker testing failed! Time %t ", $time) ;
6071
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6072
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6073
        ok = 0 ;
6074
    end
6075
 
6076
    if ( temp_val1[30] !== 0 )
6077
    begin
6078
        $display("Parity checker testing failed! Time %t ", $time) ;
6079
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6080
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6081
        ok = 0 ;
6082
    end
6083
 
6084
    if ( temp_val1[24] !== 0 )
6085
    begin
6086
        $display("Parity checker testing failed! Time %t ", $time) ;
6087
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6088
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6089
        ok = 0 ;
6090
    end
6091
 
6092
    if ( ok )
6093
        test_ok ;
6094
 
6095
    // clear statuses
6096
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6097
 
6098
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
6099
 
6100
    // do normal write
6101
    fork
6102
    begin
6103
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
6104
               target_address, 32'h1234_5678, `Test_All_Bytes,
6105
               1, 8'h3_0, `Test_One_Zero_Target_WS,
6106
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6107
        do_pause( 1 ) ;
6108
    end
6109
    begin:wait_serr13
6110
        perr_asserted = 0 ;
6111
        @(posedge pci_clock) ;
6112
        while( SERR === 1 )
6113
            @(posedge pci_clock) ;
6114
 
6115
        perr_asserted = 1 ;
6116
        $display("Parity checker testing failed! Time %t ", $time) ;
6117
        $display("SERR asserted for no reason!") ;
6118
        test_fail("SERR was asserted for no reason") ;
6119
    end
6120
    begin
6121
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6122
        if ( ok !== 1 )
6123
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6124
 
6125 35 mihad
        @(posedge pci_clock) ;
6126
        #1 ;
6127
        if ( !perr_asserted )
6128
            disable wait_serr13 ;
6129 15 mihad
    end
6130
    join
6131
 
6132
    if ( ok && !perr_asserted )
6133
        test_ok ;
6134
 
6135
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6136
    `ifdef HOST
6137 26 mihad
        repeat( 4 )
6138
            @(posedge pci_clock) ;
6139 15 mihad
        repeat(4)
6140
            @(posedge wb_clock) ;
6141
        if ( INT_O !== 0 )
6142
        begin
6143
            $display("Parity checker testing failed! Time %t ", $time) ;
6144
            $display("Interrupt request asserted for no reason!") ;
6145
            test_fail("Interrupt request was asserted for no reason") ;
6146
        end
6147
        else
6148
            test_ok ;
6149
    `else
6150
    `ifdef GUEST
6151 26 mihad
        repeat(4)
6152
            @(posedge wb_clock) ;
6153
        repeat(4)
6154 15 mihad
            @(posedge pci_clock) ;
6155
 
6156
        if ( INTA !== 1 )
6157
        begin
6158
            $display("Parity checker testing failed! Time %t ", $time) ;
6159
            $display("Interrupt request asserted for no reason!") ;
6160
            test_fail("Interrupt request was asserted for no reason") ;
6161
        end
6162
        else
6163
            test_ok ;
6164
    `endif
6165
    `endif
6166
 
6167
    // check statuses!
6168
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6169
    ok = 1 ;
6170
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6171
    if ( temp_val1[31] !== 0 )
6172
    begin
6173
        $display("Parity checker testing failed! Time %t ", $time) ;
6174
        $display("Detected Parity Error bit was set for no reason!") ;
6175
        test_fail("Detected Parity Error bit was set for no reason") ;
6176
        ok = 0 ;
6177
    end
6178
 
6179
    if ( temp_val1[30] !== 0 )
6180
    begin
6181
        $display("Parity checker testing failed! Time %t ", $time) ;
6182
        $display("Signalled System Error bit was set for no reason!") ;
6183
        test_fail("Signalled System Error bit was set for no reason") ;
6184
        ok = 0 ;
6185
    end
6186
 
6187
    if ( temp_val1[24] !== 0 )
6188
    begin
6189
        $display("Parity checker testing failed! Time %t ", $time) ;
6190
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6191
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6192
        ok = 0 ;
6193
    end
6194
 
6195
    if ( ok )
6196
        test_ok ;
6197
 
6198
    // clear statuses
6199
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6200
 
6201
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6202
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6203
    ok = 1 ;
6204
 
6205
    if ( temp_val1[4] !== 0 )
6206
    begin
6207
        $display("Parity checker testing failed! Time %t ", $time) ;
6208
        $display("System error interrupt status bit set when not expected!") ;
6209
        test_fail("System error interrupt status bit set when not expected") ;
6210
        ok = 0 ;
6211
    end
6212
 
6213
    if ( temp_val1[3] !== 0 )
6214
    begin
6215
        $display("Parity checker testing failed! Time %t ", $time) ;
6216
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6217
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6218
        ok = 0 ;
6219
    end
6220
 
6221
    if ( ok )
6222
        test_ok ;
6223
 
6224
    // clear statuses
6225
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6226
 
6227
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6228
 
6229
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6230
 
6231
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6232
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6233
 
6234
    // setup target's image!
6235
    target_address  = Target_Base_Addr_R[1] ;
6236
 
6237
    // base address
6238
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6239
 
6240
    // address mask
6241
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6242
 
6243
    // image control
6244
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6245
 
6246
    // enable everything possible for parity checking
6247
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6248
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6249
 
6250
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6251
 
6252
    fork
6253
    begin
6254
        if ( target_mem_image === 1 )
6255
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6256
                   target_address, 32'h1234_5678,
6257
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6258
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6259
        else
6260
            PCIU_IO_WRITE_MAKE_PERR (
6261
                                    `Test_Master_1,
6262
                                    target_address,
6263
                                    32'h1234_5678,
6264
                                    4'h0,
6265
                                    1,
6266
                                    `Test_Target_Normal_Completion
6267
                                    );
6268
 
6269
        do_pause( 1 ) ;
6270
    end
6271
    begin:wait_perr11
6272
        perr_asserted = 0 ;
6273
        @(posedge pci_clock) ;
6274 35 mihad
        while ( PERR !== 0 )
6275 15 mihad
            @(posedge pci_clock) ;
6276
 
6277 35 mihad
        perr_asserted = 1 ;
6278 15 mihad
 
6279
    end
6280
    begin
6281
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6282
 
6283
        if ( ok !== 1 )
6284
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6285
 
6286
        repeat(2)
6287
            @(posedge pci_clock) ;
6288
 
6289 35 mihad
        #1 ;
6290
        if ( !perr_asserted )
6291
            disable wait_perr11 ;
6292 15 mihad
    end
6293
    join
6294
 
6295
    if ( ok && perr_asserted )
6296
        test_ok ;
6297
    else
6298
    if ( !perr_asserted )
6299
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6300
 
6301
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6302
    `ifdef HOST
6303 26 mihad
        repeat (4)
6304
            @(posedge pci_clock) ;
6305 15 mihad
        repeat(4)
6306
            @(posedge wb_clock) ;
6307
        if ( INT_O !== 0 )
6308
        begin
6309
            $display("Parity checker testing failed! Time %t ", $time) ;
6310
            $display("Interrupt request asserted for no reason!") ;
6311
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6312
        end
6313
        else
6314
            test_ok ;
6315
    `else
6316
    `ifdef GUEST
6317 26 mihad
        repeat(4)
6318
            @(posedge wb_clock) ;
6319
        repeat (4)
6320 15 mihad
            @(posedge pci_clock) ;
6321
 
6322
        if ( INTA !== 1 )
6323
        begin
6324
            $display("Parity checker testing failed! Time %t ", $time) ;
6325
            $display("Interrupt request asserted for no reason!") ;
6326
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6327
        end
6328
        else
6329
            test_ok ;
6330
 
6331
    `endif
6332
    `endif
6333
 
6334
    // check statuses!
6335
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6336
    ok = 1 ;
6337
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6338
    if ( temp_val1[31] !== 1 )
6339
    begin
6340
        $display("Parity checker testing failed! Time %t ", $time) ;
6341 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6342
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6343 15 mihad
        ok = 0 ;
6344
    end
6345
 
6346
    if ( temp_val1[30] !== 0 )
6347
    begin
6348
        $display("Parity checker testing failed! Time %t ", $time) ;
6349
        $display("Signalled System Error bit was set for no reason!") ;
6350
        test_fail("Signalled System Error bit was set for no reason") ;
6351
        ok = 0 ;
6352
    end
6353
 
6354
    if ( temp_val1[24] !== 0 )
6355
    begin
6356
        $display("Parity checker testing failed! Time %t ", $time) ;
6357
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6358
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6359
        ok = 0 ;
6360
    end
6361
 
6362
    if ( ok )
6363
        test_ok ;
6364
 
6365
    // clear statuses
6366
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6367
 
6368
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6369
 
6370
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6371
    ok = 1 ;
6372
    if ( temp_val1[4] !== 0 )
6373
    begin
6374
        $display("Parity checker testing failed! Time %t ", $time) ;
6375
        $display("System error interrupt status bit set when not expected!") ;
6376
        test_fail("System error interrupt status bit set when not expected") ;
6377
        ok = 0 ;
6378
    end
6379
 
6380
    if ( temp_val1[3] !== 0 )
6381
    begin
6382
        $display("Parity checker testing failed! Time %t ", $time) ;
6383
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6384
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6385
        ok = 0 ;
6386
    end
6387
 
6388
    if ( ok )
6389
        test_ok ;
6390
 
6391
    // clear statuses
6392
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6393
 
6394
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6395
 
6396
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6397
    fork
6398
    begin
6399
        if ( target_mem_image === 1 )
6400
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6401
                          target_address, 32'h1234_5678,
6402
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6403
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6404
        else
6405
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6406
 
6407
        do_pause( 1 ) ;
6408
    end
6409
    begin:wait_perr12
6410
        perr_asserted = 0 ;
6411
        @(posedge pci_clock) ;
6412 35 mihad
        while ( PERR !== 0 )
6413 15 mihad
            @(posedge pci_clock) ;
6414
 
6415 35 mihad
        perr_asserted = 1 ;
6416 15 mihad
    end
6417
    begin
6418
 
6419
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6420
        if ( ok !== 1 )
6421
        begin
6422
            test_fail("Bridge failed to process Target Memory read correctly") ;
6423
            disable main ;
6424
        end
6425
 
6426
        repeat(3)
6427
            @(posedge pci_clock) ;
6428
 
6429
        if ( target_mem_image === 1 )
6430
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6431
                    target_address, 32'h1234_5678,
6432
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6433
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6434
        else
6435
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6436
 
6437
        do_pause( 1 ) ;
6438
 
6439
    end
6440
    begin
6441
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6442
        if ( ok !== 1 )
6443
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6444
        else
6445
        begin
6446
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6447
            if ( ok !== 1 )
6448
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6449
        end
6450
 
6451 35 mihad
        repeat(2)
6452 15 mihad
            @(posedge pci_clock) ;
6453
 
6454 35 mihad
        #1 ;
6455
        if ( !perr_asserted )
6456
            disable wait_perr12 ;
6457 15 mihad
    end
6458
    join
6459
 
6460
    if ( ok && perr_asserted )
6461
        test_ok ;
6462
    else
6463
    if ( !perr_asserted )
6464
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6465
 
6466
 
6467
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6468
    `ifdef HOST
6469
        repeat(4)
6470 26 mihad
            @(posedge pci_clock) ;
6471
        repeat(4)
6472 15 mihad
            @(posedge wb_clock) ;
6473
        if ( INT_O !== 0 )
6474
        begin
6475
            $display("Parity checker testing failed! Time %t ", $time) ;
6476
            $display("Interrupt request asserted for no reason!") ;
6477
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6478
        end
6479
        else
6480
            test_ok ;
6481
    `else
6482
    `ifdef GUEST
6483 26 mihad
        repeat(4)
6484
            @(posedge wb_clock) ;
6485
        repeat(4)
6486 15 mihad
            @(posedge pci_clock) ;
6487
 
6488
        if ( INTA !== 1 )
6489
        begin
6490
            $display("Parity checker testing failed! Time %t ", $time) ;
6491
            $display("Interrupt request asserted for no reason!") ;
6492
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6493
        end
6494
        else
6495
            test_ok ;
6496
    `endif
6497
    `endif
6498
 
6499
    // check statuses!
6500
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6501
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6502
    ok = 1 ;
6503 45 mihad
    if ( temp_val1[31] !== 0 )
6504 15 mihad
    begin
6505
        $display("Parity checker testing failed! Time %t ", $time) ;
6506 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6507
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6508 15 mihad
        ok = 0 ;
6509
    end
6510
 
6511
    if ( temp_val1[30] !== 0 )
6512
    begin
6513
        $display("Parity checker testing failed! Time %t ", $time) ;
6514
        $display("Signalled System Error bit was set for no reason!") ;
6515
        test_fail("Signalled System Error bit was set for no reason") ;
6516
        ok = 0 ;
6517
    end
6518
 
6519
    if ( temp_val1[24] !== 0 )
6520
    begin
6521
        $display("Parity checker testing failed! Time %t ", $time) ;
6522
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6523
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6524
        ok = 0 ;
6525
    end
6526
 
6527
    if ( ok )
6528
        test_ok ;
6529
 
6530
    // clear statuses
6531
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6532
 
6533
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6534
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6535
    ok = 1 ;
6536
    if ( temp_val1[4] !== 0 )
6537
    begin
6538
        $display("Parity checker testing failed! Time %t ", $time) ;
6539
        $display("System error interrupt status bit set when not expected!") ;
6540
        test_fail("System error interrupt status bit set when not expected") ;
6541
        ok = 0 ;
6542
    end
6543
 
6544
    if ( temp_val1[3] !== 0 )
6545
    begin
6546
        $display("Parity checker testing failed! Time %t ", $time) ;
6547
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6548
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6549
        ok = 0 ;
6550
    end
6551
 
6552
    if ( ok )
6553
        test_ok ;
6554
    // clear statuses
6555
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6556
 
6557
    $fdisplay(pci_mon_log_file_desc,
6558
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6559
    test_name = "DISABLE USED IMAGES" ;
6560
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6561
    if ( ok !== 1 )
6562
    begin
6563
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6564
        test_fail("WB Image Address Mask register could not be written to") ;
6565
        disable main ;
6566
    end
6567
 
6568 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6569 15 mihad
    if ( ok !== 1 )
6570
    begin
6571
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6572
        test_fail("PCI Image Address Mask register could not be written to") ;
6573
        disable main ;
6574
    end
6575
 
6576
    // disable target's 1 response to parity errors
6577 45 mihad
    configuration_cycle_write(0,                        // bus number
6578
                              `TAR1_IDSEL_INDEX - 11,   // device number
6579
                              0,                        // function number
6580
                              1,                        // register number
6581
                              0,                        // type of configuration cycle
6582
                              4'b0001,                  // byte enables
6583
                              32'h0000_0007             // data
6584 15 mihad
                             ) ;
6585
 
6586
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6587
end
6588
endtask // parity_checking
6589
 
6590
task wb_to_pci_transactions ;
6591
    reg   [11:0] ctrl_offset ;
6592
    reg   [11:0] ba_offset ;
6593
    reg   [11:0] am_offset ;
6594
    reg   [11:0] pci_ctrl_offset ;
6595
    reg   [11:0] err_cs_offset ;
6596
    reg   [11:0] icr_offset ;
6597
    reg   [11:0] isr_offset ;
6598
    reg   [11:0] lat_tim_cls_offset ;
6599
 
6600
    reg `WRITE_STIM_TYPE  write_data ;
6601
    reg `READ_STIM_TYPE   read_data ;
6602
    reg `READ_RETURN_TYPE read_status ;
6603
 
6604
    reg `WRITE_RETURN_TYPE write_status ;
6605
    reg `WB_TRANSFER_FLAGS write_flags ;
6606
    reg [31:0] temp_val1 ;
6607
    reg [31:0] temp_val2 ;
6608
    reg        ok   ;
6609
 
6610
    reg [31:0] image_base ;
6611
    reg [31:0] target_address ;
6612
    integer i ;
6613
    integer required_reads ;
6614
    integer writes_left ;
6615
 
6616
begin:main
6617
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6618
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6619
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6620
    pci_ctrl_offset    = 12'h4 ;
6621
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6622
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6623
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6624
    lat_tim_cls_offset = 12'hC ;
6625
 
6626
    $display("Checking WB to PCI transaction lengths!") ;
6627
    target_address  = `BEH_TAR1_MEM_START ;
6628
    image_base      = 0 ;
6629
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6630
 
6631
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6632
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6633
    write_flags                    = 0 ;
6634
    write_flags`INIT_WAITS         = tb_init_waits ;
6635
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6636
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6637
 
6638
    // enable master & target operation
6639
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6640
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6641
    if ( ok !== 1 )
6642
    begin
6643
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6644
        test_fail("write to PCI Device Control register failed") ;
6645
        disable main ;
6646
    end
6647
 
6648
    // prepare image control register
6649
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6650
    if ( ok !== 1 )
6651
    begin
6652
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6653
        test_fail("write to WB Image Control register failed") ;
6654
        disable main ;
6655
    end
6656
 
6657
    // prepare base address register
6658
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6659
    if ( ok !== 1 )
6660
    begin
6661
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6662
        test_fail("write to WB Base Address register failed") ;
6663
        disable main ;
6664
    end
6665
 
6666
    // write address mask register
6667
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6668
    if ( ok !== 1 )
6669
    begin
6670
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6671
        test_fail("write to WB Address Mask register failed") ;
6672
        disable main ;
6673
    end
6674
 
6675
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6676
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6677
    if ( ok !== 1 )
6678
    begin
6679
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6680
        test_fail("write to WB Error Control and Status register failed") ;
6681
        disable main ;
6682
    end
6683
 
6684
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6685
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6686
    if ( ok !== 1 )
6687
    begin
6688
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6689
        test_fail("write to Interrupt Control register failed") ;
6690
        disable main ;
6691
    end
6692
 
6693
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6694
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6695
    if ( ok !== 1 )
6696
    begin
6697
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6698
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6699
        disable main ;
6700
    end
6701
 
6702
    $display("Testing single write transaction progress from WB to PCI!") ;
6703
    write_data`WRITE_ADDRESS = target_address ;
6704
    write_data`WRITE_DATA    = wmem_data[0] ;
6705
    write_data`WRITE_SEL     = 4'hF ;
6706
 
6707
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6708
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6709
 
6710
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6711
    fork
6712
    begin
6713
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6714
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6715
        begin
6716
            $display("Transaction progress testing failed! Time %t ", $time) ;
6717
            $display("Bridge failed to process single memory write!") ;
6718
            test_fail("bridge failed to post single memory write") ;
6719
            disable main ;
6720
        end
6721
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6722
    end
6723
    begin
6724
        // wait two retries, then enable target response
6725
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6726
        if ( ok !== 1 )
6727
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6728
        else
6729
            test_ok ;
6730
 
6731
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6732
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6733
        if ( ok !== 1 )
6734
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6735
        else
6736
            test_ok ;
6737
 
6738
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6739
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6740
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6741
 
6742
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6743
        if ( ok !== 1 )
6744
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6745
        else
6746
            test_ok ;
6747
    end
6748
    join
6749
 
6750
    $display("Testing burst write transaction progress from WB to PCI!") ;
6751
    write_data`WRITE_ADDRESS = target_address ;
6752
    write_data`WRITE_DATA    = wmem_data[0] ;
6753
    write_data`WRITE_SEL     = 4'hF ;
6754
 
6755
    wishbone_master.blk_write_data[0] = write_data ;
6756
 
6757
    write_data`WRITE_ADDRESS = target_address + 4 ;
6758
    write_data`WRITE_DATA    = wmem_data[1] ;
6759
    write_data`WRITE_SEL     = 4'hF ;
6760
 
6761
    wishbone_master.blk_write_data[1] = write_data ;
6762
 
6763
    write_flags`WB_TRANSFER_SIZE = 2 ;
6764
    write_flags`WB_TRANSFER_CAB  = 1 ;
6765
 
6766
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6767
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6768
 
6769
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6770
 
6771
    fork
6772
    begin
6773
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6774
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6775
        begin
6776
            $display("Transaction progress testing failed! Time %t ", $time) ;
6777
            $display("Bridge failed to process whole CAB memory write!") ;
6778
            test_fail("bridge failed to post whole CAB memory write") ;
6779
            disable main ;
6780
        end
6781
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6782
    end
6783
    begin
6784
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6785
        if ( ok !== 1 )
6786
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6787
        else
6788
            test_ok ;
6789
 
6790
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6791
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6792
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6793
 
6794
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6795
        if ( ok !== 1 )
6796
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6797
        else
6798
            test_ok ;
6799
 
6800
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6801
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6802
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6803
 
6804
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6805
        if ( ok !== 1 )
6806
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6807
        else
6808
            test_ok ;
6809
    end
6810
    join
6811
 
6812
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6813
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6814
 
6815
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6816
    // try same write with other terminations
6817
    fork
6818
    begin
6819
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6820
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6821
        begin
6822
            $display("Transaction progress testing failed! Time %t ", $time) ;
6823
            $display("Bridge failed to process whole CAB memory write!") ;
6824
            test_fail("bridge failed to post whole CAB memory write") ;
6825
            disable main ;
6826
        end
6827
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6828
    end
6829
    begin
6830
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6831
        if ( ok !== 1 )
6832
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6833
        else
6834
            test_ok ;
6835
 
6836
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6837
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6838
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6839
 
6840
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6841
        if ( ok !== 1 )
6842
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6843
        else
6844
            test_ok ;
6845
    end
6846
    join
6847
 
6848
    // repeat the write with normal completion
6849
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6850
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6851
 
6852
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6853
    fork
6854
    begin
6855
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6856
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6857
        begin
6858
            $display("Transaction progress testing failed! Time %t ", $time) ;
6859
            $display("Bridge failed to process whole CAB memory write!") ;
6860
            test_fail("bridge failed to post whole CAB memory write") ;
6861
            disable main ;
6862
        end
6863
    end
6864
    begin
6865
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6866
        if ( ok !== 1 )
6867
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6868
        else
6869
            test_ok ;
6870
    end
6871
    join
6872
 
6873
    // do the same thing with burst length of 3
6874
    write_data`WRITE_ADDRESS = target_address + 8 ;
6875
    write_data`WRITE_DATA    = wmem_data[2] ;
6876
    write_data`WRITE_SEL     = 4'hF ;
6877
 
6878
    wishbone_master.blk_write_data[2] = write_data ;
6879
 
6880
    write_flags`WB_TRANSFER_SIZE = 3 ;
6881
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6882
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6883
 
6884
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6885
 
6886
    fork
6887
    begin
6888
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6889
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6890
        begin
6891
            $display("Transaction progress testing failed! Time %t ", $time) ;
6892
            $display("Bridge failed to process whole CAB memory write!") ;
6893
            test_fail("bridge failed to post whole CAB memory write") ;
6894
            disable main ;
6895
        end
6896
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6897
    end
6898
    begin
6899
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6900
        if ( ok !== 1 )
6901
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6902
        else
6903
            test_ok ;
6904
 
6905
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6906
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6907
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6908
 
6909
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6910
        if ( ok !== 1 )
6911
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6912
        else
6913
            test_ok ;
6914
    end
6915
    join
6916
 
6917
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6918
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6919
 
6920
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6921
    fork
6922
    begin
6923
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6924
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6925
        begin
6926
            $display("Transaction progress testing failed! Time %t ", $time) ;
6927
            $display("Bridge failed to process whole CAB memory write!") ;
6928
            test_fail("bridge failed to post whole CAB memory write") ;
6929
            disable main ;
6930
        end
6931
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6932
    end
6933
    begin
6934
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6935
        if ( ok !== 1 )
6936
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6937
        else
6938
            test_ok ;
6939
 
6940
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6941
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6942
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6943
 
6944
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6945
        if ( ok !== 1 )
6946
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6947
        else
6948
            test_ok ;
6949
 
6950
    end
6951
    join
6952
 
6953
    // repeat with normal completion
6954
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6955
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6956
 
6957
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6958
    fork
6959
    begin
6960
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6961
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6962
        begin
6963
            $display("Transaction progress testing failed! Time %t ", $time) ;
6964
            $display("Bridge failed to process whole CAB memory write!") ;
6965
            test_fail("bridge failed to post whole CAB memory write") ;
6966
            disable main ;
6967
        end
6968
    end
6969
    begin
6970
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6971
        if ( ok !== 1 )
6972
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6973
        else
6974
            test_ok ;
6975
 
6976
    end
6977
    join
6978
 
6979
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6980
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6981
    begin
6982
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6983
        write_data`WRITE_DATA    = wmem_data[i] ;
6984
        write_data`WRITE_SEL     = 4'hF ;
6985
 
6986
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6987
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6988
 
6989
        wishbone_master.blk_write_data[i]   = write_data ;
6990
        wishbone_master.blk_read_data_in[i] = read_data ;
6991
    end
6992
 
6993
    write_flags`WB_TRANSFER_CAB      = 1 ;
6994
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6995
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6996
 
6997
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6998
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6999
 
7000
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
7001
    fork
7002
    begin
7003
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7004
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7005
        begin
7006
            $display("Transaction progress testing failed! Time %t ", $time) ;
7007
            $display("Bridge failed to process right number of databeats in CAB write!") ;
7008
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
7009
            test_fail("bridge failed to post whole CAB memory write") ;
7010
            disable main ;
7011
        end
7012
 
7013
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
7014
 
7015
        // read here just checks if data was transfered OK
7016
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7017
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
7018
 
7019
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7020
 
7021
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7022
        begin
7023
            $display("Transaction progress testing failed! Time %t ", $time) ;
7024
            $display("Bridge processed CAB read wrong!") ;
7025
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
7026
        end
7027
 
7028
    end
7029
    begin
7030
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7031
        if ( ok !== 1 )
7032
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7033
        else
7034
            test_ok ;
7035
 
7036
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
7037
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7038
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7039
 
7040
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7041
        if ( ok !== 1 )
7042
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7043
        else
7044
            test_ok ;
7045
 
7046
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
7047
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
7048
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7049
 
7050
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7051
        if ( ok !== 1 )
7052
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7053
        else
7054
            test_ok ;
7055
 
7056
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
7057
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7058
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7059
 
7060
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7061
        if ( ok !== 1 )
7062
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7063
        else
7064
            test_ok ;
7065
 
7066
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
7067
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7068
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7069
 
7070
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
7071
        if ( ok !== 1 )
7072
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7073
        else
7074
            test_ok ;
7075
 
7076
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
7077
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
7078
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
7079
        for ( i = 0 ; i < required_reads ; i = i + 1 )
7080
        begin
7081
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7082
            if ( ok !== 1 )
7083
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7084
        end
7085
    end
7086
    join
7087
 
7088
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
7089
    begin
7090
        read_status = wishbone_master.blk_read_data_out[i] ;
7091
        if (read_status`READ_DATA !== wmem_data[i])
7092
        begin
7093
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
7094
            test_fail("data read from target wasn't the same as data written to it") ;
7095
            ok = 0 ;
7096
        end
7097
    end
7098
 
7099
    if ( ok )
7100
        test_ok ;
7101
 
7102
    $display("Testing single read transaction progress from WB to PCI!") ;
7103
    read_data`READ_ADDRESS = target_address + 8 ;
7104
    read_data`READ_SEL     = 4'hF ;
7105
 
7106
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7107
 
7108
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
7109
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7110
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7111
 
7112
    fork
7113
    begin
7114
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7115
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7116
        begin
7117
            $display("Transaction progress testing failed! Time %t ", $time) ;
7118
            $display("Bridge processed single read wrong!") ;
7119
            test_fail("bridge processed single read wrong") ;
7120
            disable main ;
7121
        end
7122
 
7123
        if (read_status`READ_DATA !== wmem_data[2])
7124
        begin
7125
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7126
            test_fail("data returned from single read was not as expected") ;
7127
        end
7128
        else
7129
        if ( ok )
7130
            test_ok ;
7131
    end
7132
    begin
7133
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7134
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7135
 
7136
        if ( ok !== 1 )
7137
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7138
 
7139
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7140
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7141
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7142
 
7143
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7144
        if ( ok !== 1 )
7145
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7146
    end
7147
    join
7148
 
7149
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7150
 
7151
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7152
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7153
 
7154
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7155
    // first fill target's memory with enough data to fill WBR_FIFO
7156
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7157
    begin
7158
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7159
        write_data`WRITE_DATA    = wmem_data[i] ;
7160
        write_data`WRITE_SEL     = 4'hF ;
7161
 
7162
        wishbone_master.blk_write_data[i] = write_data ;
7163
    end
7164
 
7165
    write_flags`WB_TRANSFER_CAB = 1 ;
7166
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7167
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7168
 
7169
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7170
 
7171
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7172
    begin
7173
        $display("Transaction progress testing failed! Time %t ", $time) ;
7174
        $display("Bridge processed CAB write wrong!") ;
7175
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7176
        disable main ;
7177
    end
7178
 
7179
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7180
    // perform single read to force write data to pci
7181
    read_data`READ_ADDRESS = target_address + 8;
7182
    read_data`READ_SEL     = 4'hF ;
7183
 
7184
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7185
 
7186
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7187
    begin
7188
        $display("Transaction progress testing failed! Time %t ", $time) ;
7189
        $display("Bridge processed single read wrong!") ;
7190
        test_fail("bridge didn't process single memory read as expected") ;
7191
        disable main ;
7192
    end
7193
 
7194
    wishbone_master.blk_read_data_in[0] = read_data ;
7195
 
7196
    read_data`READ_ADDRESS = target_address + 12 ;
7197
    read_data`READ_SEL     = 4'hF ;
7198
 
7199
    wishbone_master.blk_read_data_in[1] = read_data ;
7200
 
7201
    read_data`READ_ADDRESS = target_address + 16 ;
7202
    read_data`READ_SEL     = 4'hF ;
7203
 
7204
    wishbone_master.blk_read_data_in[2] = read_data ;
7205
 
7206
    write_flags`WB_TRANSFER_CAB  = 1 ;
7207
    write_flags`WB_TRANSFER_SIZE = 2 ;
7208
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7209
    read_status = 0 ;
7210
 
7211
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7212
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7213
 
7214
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7215
 
7216
    ok = 1 ;
7217
    fork
7218
    begin
7219
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7220
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7221
 
7222
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7223
        begin
7224
            $display("Transaction progress testing failed! Time %t ", $time) ;
7225
            $display("Bridge processed CAB read wrong!") ;
7226
            test_fail("bridge didn't process disconnected burst read as expected") ;
7227
        end
7228
        else
7229
        begin
7230
 
7231
            read_status = wishbone_master.blk_read_data_out[0] ;
7232
 
7233
            if (read_status`READ_DATA !== wmem_data[2])
7234
            begin
7235
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7236
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7237
            end
7238
            else
7239
                test_ok ;
7240
        end
7241
 
7242
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7243
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7244
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7245
 
7246
        read_status = 0 ;
7247
 
7248
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7249
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7250
 
7251
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7252
        begin
7253
            $display("Transaction progress testing failed! Time %t ", $time) ;
7254
            $display("Bridge processed CAB read wrong!") ;
7255
            test_fail("bridge didn't process disconnected burst read as expected") ;
7256
        end
7257
        else
7258
        begin
7259
 
7260
            read_status = wishbone_master.blk_read_data_out[0] ;
7261
 
7262
            if (read_status`READ_DATA !== wmem_data[3])
7263
            begin
7264
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7265
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7266
            end
7267
            else
7268
                test_ok ;
7269
        end
7270
 
7271
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7272
        // complete delayed read which was requested
7273
        read_data = wishbone_master.blk_read_data_in[2] ;
7274
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7275
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7276
 
7277
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7278
        begin
7279
            $display("Transaction progress testing failed! Time %t ", $time) ;
7280
            $display("Bridge processed single out of burst read wrong!") ;
7281
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7282
        end
7283
        else
7284
        begin
7285
 
7286
            if (read_status`READ_DATA !== wmem_data[4])
7287
            begin
7288
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7289
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7290
            end
7291
            else
7292
                test_ok ;
7293
        end
7294
 
7295
    end
7296
    begin
7297
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7298
 
7299
        if ( ok !== 1 )
7300
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7301
 
7302
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7303
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7304
 
7305
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7306
        if ( ok !== 1 )
7307
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7308
 
7309
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7310
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7311
 
7312
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7313
        if ( ok !== 1 )
7314
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7315
    end
7316
    join
7317
 
7318
    // now try burst read with normal termination
7319
    read_data`READ_ADDRESS = target_address + 12 ;
7320
    read_data`READ_SEL     = 4'hF ;
7321
 
7322
    wishbone_master.blk_read_data_in[0] = read_data ;
7323
 
7324
    read_data`READ_ADDRESS = target_address + 16 ;
7325
    read_data`READ_SEL     = 4'hF ;
7326
 
7327
    wishbone_master.blk_read_data_in[1] = read_data ;
7328
 
7329
    write_flags`WB_TRANSFER_SIZE = 2 ;
7330
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7331
    write_flags`WB_TRANSFER_CAB = 1 ;
7332
 
7333
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7334
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7335
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7336
 
7337
    fork
7338
    begin
7339
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7340
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7341
        begin
7342
            $display("Transaction progress testing failed! Time %t ", $time) ;
7343
            $display("Bridge processed CAB read wrong!") ;
7344
            test_fail("bridge didn't process burst read as expected") ;
7345
            ok = 0 ;
7346
        end
7347
    end
7348
    begin
7349
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7350
        if ( ok !== 1 )
7351
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7352
    end
7353
    join
7354
 
7355
    if ( ok )
7356
    begin
7357
        read_status = wishbone_master.blk_read_data_out[0] ;
7358
        if ( read_status`READ_DATA !== wmem_data[3] )
7359
        begin
7360
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7361
            test_fail("data provided from normaly terminated read was wrong") ;
7362
            ok = 0 ;
7363
        end
7364
 
7365
        read_status = wishbone_master.blk_read_data_out[1] ;
7366
        if ( read_status`READ_DATA !== wmem_data[4] )
7367
        begin
7368
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7369
            test_fail("data provided from normaly terminated read was wrong") ;
7370
            ok = 0 ;
7371
        end
7372
    end
7373
 
7374
    if ( ok )
7375
        test_ok ;
7376
 
7377
    // disable memory read line command and enable prefetch
7378
    // prepare image control register
7379
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7380
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7381
    if ( ok !== 1 )
7382
    begin
7383
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7384
        test_fail("WB Image Control register couldn't be written to") ;
7385
        disable main ;
7386
    end
7387
 
7388
    write_flags`WB_TRANSFER_SIZE = 4 ;
7389
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7390
    write_flags`WB_TRANSFER_CAB = 1 ;
7391
 
7392
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7393
 
7394
    for ( i = 0 ; i < 4 ; i = i + 1 )
7395
    begin
7396
        read_data`READ_ADDRESS = target_address + i*4 ;
7397
        read_data`READ_SEL     = 4'b1010 ;
7398
 
7399
        wishbone_master.blk_read_data_in[i] = read_data ;
7400
    end
7401
 
7402
    fork
7403
    begin
7404
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7405
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7406
        begin
7407
            $display("Transaction progress testing failed! Time %t ", $time) ;
7408
            $display("Bridge processed CAB read wrong!") ;
7409
            test_fail("bridge didn't process prefetched burst read as expected") ;
7410
            ok = 0 ;
7411
        end
7412
    end
7413
    begin
7414
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7415
        if ( ok !== 1 )
7416
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7417
    end
7418
    join
7419
 
7420
    if ( ok )
7421
    begin
7422
        for ( i = 0 ; i < 4 ; i = i + 1 )
7423
        begin
7424
            read_status = wishbone_master.blk_read_data_out[i] ;
7425
            if ( read_status`READ_DATA !== wmem_data[i] )
7426
            begin
7427
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7428
                test_fail("burst read returned unexpected data") ;
7429
                ok = 0 ;
7430
            end
7431
        end
7432
    end
7433
 
7434
    if ( ok )
7435
        test_ok ;
7436
 
7437
    // do one single read with different byte enables
7438
    read_data`READ_ADDRESS = target_address + 4 ;
7439
    read_data`READ_SEL     = 4'b1010 ;
7440
 
7441
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7442
    fork
7443
    begin
7444
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7445
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7446
        begin
7447
            $display("Transaction progress testing failed! Time %t ", $time) ;
7448
            $display("Bridge processed single read wrong!") ;
7449
            test_fail("bridge didn't process single memory read as expected") ;
7450
            ok = 0 ;
7451
        end
7452
    end
7453
    begin
7454
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7455
        if ( ok !== 1 )
7456
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7457
    end
7458
    join
7459
 
7460
    // check read data
7461
    if ( ok )
7462
    begin
7463
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7464
        begin
7465
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7466
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7467
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7468
            ok = 0 ;
7469
            test_fail("unexpected data received from single read") ;
7470
        end
7471
    end
7472
 
7473
    if ( ok )
7474
         test_ok ;
7475
 
7476
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7477
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7478
 
7479
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7480
    if ( ok !== 1 )
7481
    begin
7482
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7483
        test_fail("WB Image Control register could not be written") ;
7484
        disable main ;
7485
    end
7486
 
7487
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7488
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7489
    begin
7490
        read_data`READ_ADDRESS = target_address + i*4 ;
7491
        read_data`READ_SEL     = 4'b1111 ;
7492
 
7493
        wishbone_master.blk_read_data_in[i] = read_data ;
7494
    end
7495
 
7496
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7497
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7498
    write_flags`WB_TRANSFER_CAB = 1 ;
7499
 
7500
    fork
7501
    begin
7502
        read_status         = 0 ;
7503
        read_status`CYC_RTY = 1 ;
7504
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7505
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7506
 
7507
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7508
        begin
7509
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7510
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7511
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7512
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7513
            ok = 0 ;
7514
        end
7515
    end
7516
    begin
7517
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7518
        if ( ok !== 1 )
7519
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7520
    end
7521
    join
7522
 
7523
    // now repeat single read to flush redundant read initiated
7524
    write_flags`WB_TRANSFER_SIZE = 1 ;
7525
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7526
    write_flags`WB_TRANSFER_CAB = 1 ;
7527
 
7528
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7529
    read_data`READ_SEL     = 4'hF ;
7530
 
7531
    wishbone_master.blk_read_data_in[0] = read_data ;
7532
 
7533
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7534
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7535
 
7536
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7537
    begin
7538
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7539
        $display(" PCI bridge failed to process single CAB read!") ;
7540
        test_fail("single CAB write was not processed as expected") ;
7541
    end
7542
 
7543
    // because last read could be very long on PCI - delete target abort status
7544
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7545
 
7546
    // write unsupported value to cache line size register
7547
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7548
 
7549
    read_data`READ_ADDRESS = target_address ;
7550
    read_data`READ_SEL     = 4'hF ;
7551
    wishbone_master.blk_read_data_in[0] = read_data ;
7552
 
7553
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7554
    // perform a read
7555
    fork
7556
    begin
7557
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7558
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7559
        begin
7560
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7561
            $display(" PCI bridge failed to process single CAB read!") ;
7562
            test_fail("burst read was not processed as expected") ;
7563
            ok = 0 ;
7564
        end
7565
    end
7566
    begin
7567
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7568
        if ( ok !== 1 )
7569
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7570
    end
7571
    join
7572
 
7573
    if ( ok )
7574
        test_ok ;
7575
 
7576
    // write 2 to cache line size register
7577
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7578
 
7579
    // perform a read
7580
    fork
7581
    begin
7582
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7583
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7584
        begin
7585
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7586
            $display(" PCI bridge failed to process single CAB read!") ;
7587
            test_fail("burst read was not processed as expected") ;
7588
            ok = 0 ;
7589
        end
7590
    end
7591
    begin
7592
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7593
        if ( ok !== 1 )
7594
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7595
    end
7596
    join
7597
 
7598
    if ( ok )
7599
        test_ok ;
7600
 
7601
    // write 0 to cache line size
7602
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7603
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7604
 
7605
    // perform a read
7606
    fork
7607
    begin
7608
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7609
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7610
        begin
7611
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7612
            $display(" PCI bridge failed to process single CAB read!") ;
7613
            test_fail("burst read was not processed as expected") ;
7614
            ok = 0 ;
7615
        end
7616
    end
7617
    begin
7618
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7619
        if ( ok !== 1 )
7620
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7621
    end
7622
    join
7623
 
7624
    if ( ok )
7625
        test_ok ;
7626
 
7627
    // write normal value to cls register
7628
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7629
 
7630
    $display("Testing Master's latency timer operation!") ;
7631
    $display("Testing Latency timer during Master Writes!") ;
7632
 
7633
    for ( i = 0 ; i < 6 ; i = i + 1 )
7634
    begin
7635
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7636
        write_data`WRITE_SEL     = 4'b1111 ;
7637
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7638
 
7639
        wishbone_master.blk_write_data[i] = write_data ;
7640
    end
7641
 
7642
    write_flags`WB_TRANSFER_SIZE = 6 ;
7643
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7644
    write_flags`WB_TRANSFER_CAB = 1 ;
7645
 
7646
    // start wb write, pci write and monitor in parallel
7647
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7648
    fork
7649
    begin
7650
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7651
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7652
        begin
7653
            $display("Transaction progress testing failed! Time %t ", $time) ;
7654
            $display("Bridge failed to process CAB write!") ;
7655
            test_fail("bridge didn't post whole burst memory write") ;
7656
            disable main ;
7657
        end
7658
    end
7659
    begin
7660
        // wait for bridge's master to start transaction
7661
        @(posedge pci_clock) ;
7662
        while ( FRAME === 1 )
7663
            @(posedge pci_clock) ;
7664
 
7665
        // start behavioral master request
7666
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7667
               target_address, wmem_data[1023], `Test_All_Bytes,
7668
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7669
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7670
 
7671
        do_pause ( 1 ) ;
7672
    end
7673
    begin
7674
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7675
        if ( ok !== 1 )
7676
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7677
        else
7678
            test_ok ;
7679
    end
7680
    join
7681
 
7682
    // perform a read to check data
7683
    for ( i = 0 ; i < 6 ; i = i + 1 )
7684
    begin
7685
        read_data`READ_ADDRESS = target_address + i*4 ;
7686
        read_data`READ_SEL     = 4'b1111 ;
7687
 
7688
        wishbone_master.blk_read_data_in[i] = read_data ;
7689
    end
7690
 
7691
    write_flags`WB_TRANSFER_SIZE = 6 ;
7692
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7693
    write_flags`WB_TRANSFER_CAB = 1 ;
7694
 
7695
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7696
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7697
 
7698
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7699
    begin
7700
        $display("Transaction progress testing failed! Time %t ", $time) ;
7701
        $display("Bridge failed to process CAB read!") ;
7702
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7703
        disable main ;
7704
    end
7705
 
7706
    ok = 1 ;
7707
    for ( i = 0 ; i < 6 ; i = i + 1 )
7708
    begin
7709
        read_status = wishbone_master.blk_read_data_out[i] ;
7710
 
7711
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7712
        begin
7713
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7714
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7715
            test_fail("unexpected data read back from PCI") ;
7716
            ok = 0 ;
7717
        end
7718
    end
7719
 
7720
    if ( ok )
7721
        test_ok ;
7722
 
7723
    $display("Testing Latency timer during Master Reads!") ;
7724
 
7725
    // at least 2 words are transfered during Master Reads terminated with timeout
7726
    write_flags`WB_TRANSFER_SIZE = 2 ;
7727
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7728
    fork
7729
    begin
7730
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7731
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7732
        begin
7733
            $display("Transaction progress testing failed! Time %t ", $time) ;
7734
            $display("Bridge failed to process CAB read!") ;
7735
            test_fail("bridge didn't process burst read as expected") ;
7736
            ok = 0 ;
7737
        end
7738
    end
7739
    begin
7740
        // wait for bridge's master to start transaction
7741
        @(posedge pci_clock) ;
7742
        while ( FRAME === 1 )
7743
            @(posedge pci_clock) ;
7744
 
7745
        // start behavioral master request
7746
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7747
               target_address, wmem_data[0], `Test_All_Bytes,
7748
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7749
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7750
 
7751
        do_pause ( 1 ) ;
7752
    end
7753
    begin
7754
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7755
        if ( ok !== 1 )
7756
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7757
    end
7758
    join
7759
 
7760
    // check data provided by target
7761
    if ( ok )
7762
    begin
7763
        for ( i = 0 ; i < 2 ; i = i + 1 )
7764
        begin
7765
            read_status = wishbone_master.blk_read_data_out[i] ;
7766
 
7767
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7768
            begin
7769
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7770
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7771
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7772
                ok = 0 ;
7773
            end
7774
        end
7775
    end
7776
    if ( ok )
7777
        test_ok ;
7778
 
7779
    test_name = "DISABLE_IMAGE" ;
7780
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7781
    if ( ok !== 1 )
7782
    begin
7783
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7784
        test_fail("write to WB Address Mask register failed") ;
7785
        disable main ;
7786
    end
7787
 
7788
end
7789
endtask //wb_to_pci_transactions
7790
 
7791
task iack_cycle ;
7792
    reg `READ_STIM_TYPE   read_data ;
7793
    reg `READ_RETURN_TYPE read_status ;
7794
    reg `WB_TRANSFER_FLAGS flags ;
7795
 
7796
    reg [31:0] temp_var ;
7797
    reg ok ;
7798 45 mihad
    reg ok_wb ;
7799
    reg ok_pci ;
7800
 
7801
    reg [31:0] irq_vector ;
7802 15 mihad
begin
7803
 
7804 45 mihad
    ok     = 1 ;
7805
    ok_wb  = 1 ;
7806
    ok_pci = 1 ;
7807
 
7808 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7809
 
7810
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7811
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7812
 
7813
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7814
    read_data`READ_SEL     = 4'hF ;
7815
 
7816
    flags = 0 ;
7817
 
7818
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7819
 
7820
    irq_vector  = 32'hAAAA_AAAA ;
7821
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7822
 
7823 45 mihad
    // disable both pci blue behavioral targets
7824
    configuration_cycle_write
7825
    (
7826
        0,                          // bus number [7:0]
7827
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7828
        0,                          // function number [2:0]
7829
        1,                          // register number [5:0]
7830
        0,                          // type [1:0]
7831
        4'h1,                       // byte enables [3:0]
7832
        32'h0000_0044               // data to write [31:0]
7833
    ) ;
7834
 
7835
    configuration_cycle_write
7836
    (
7837
        0,                          // bus number [7:0]
7838
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7839
        0,                          // function number [2:0]
7840
        1,                          // register number [5:0]
7841
        0,                          // type [1:0]
7842
        4'h1,                       // byte enables [3:0]
7843
        32'h0000_0044               // data to write [31:0]
7844
    ) ;
7845
 
7846 15 mihad
    fork
7847
    begin
7848
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7849
    end
7850
    begin
7851 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7852
        if ( ok_pci !== 1 )
7853 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7854
    end
7855
    join
7856
 
7857
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7858
    begin
7859 45 mihad
        ok_wb = 0 ;
7860 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7861
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7862
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7863
    end
7864 45 mihad
 
7865
    if ( ok_pci && ok_wb )
7866 15 mihad
        test_ok ;
7867 45 mihad
 
7868
    ok_wb = 1 ;
7869
    ok_pci = 1 ;
7870
    ok = 1 ;
7871 15 mihad
 
7872 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7873
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7874 15 mihad
 
7875
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7876 45 mihad
    // enable pci blue behavioral target 1
7877
    configuration_cycle_write
7878
    (
7879
        0,                          // bus number [7:0]
7880
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7881
        0,                          // function number [2:0]
7882
        1,                          // register number [5:0]
7883
        0,                          // type [1:0]
7884
        4'h1,                       // byte enables [3:0]
7885
        32'h0000_0047               // data to write [31:0]
7886
    ) ;
7887 15 mihad
    fork
7888
    begin
7889
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7890
    end
7891
    begin
7892 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7893
        if ( ok_pci !== 1 )
7894 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7895
    end
7896
    join
7897
 
7898
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7899
    begin
7900 45 mihad
        ok_wb = 0 ;
7901 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7902
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7903
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7904
    end
7905
 
7906
    if ( read_status`READ_DATA !== irq_vector )
7907
    begin
7908
        $display(" Time %t ", $time ) ;
7909
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7910
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7911 45 mihad
        ok_wb = 0 ;
7912 15 mihad
    end
7913
 
7914 45 mihad
    if ( ok_pci && ok_wb )
7915 15 mihad
        test_ok ;
7916
 
7917 45 mihad
    ok_pci = 1 ;
7918
    ok_wb  = 1 ;
7919
    ok     = 1 ;
7920
 
7921 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7922 45 mihad
    irq_vector  = 32'h5555_5555 ;
7923
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7924
 
7925 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7926
    fork
7927
    begin
7928
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7929
    end
7930
    begin
7931 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7932
        if ( ok_pci !== 1 )
7933 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7934
    end
7935
    join
7936
 
7937
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7938
    begin
7939
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7940
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7941
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7942 45 mihad
        ok_wb = 0 ;
7943 15 mihad
    end
7944
 
7945 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7946 15 mihad
    begin
7947
        $display(" Time %t ", $time ) ;
7948 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7949 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7950 45 mihad
        ok_wb = 0 ;
7951 15 mihad
    end
7952
 
7953 45 mihad
    if (ok_pci && ok_wb)
7954 15 mihad
        test_ok ;
7955
 
7956 45 mihad
    ok_pci = 1 ;
7957
    ok_wb  = 1 ;
7958
    ok     = 1 ;
7959 15 mihad
 
7960 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7961
 
7962
    // set target to terminate with target abort
7963
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7964
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7965
 
7966
    fork
7967
    begin
7968
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7969
    end
7970
    begin
7971
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7972
        if ( ok_pci !== 1 )
7973
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7974
    end
7975
    join
7976
 
7977
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7978
    begin
7979
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7980
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7981
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7982
        ok_wb = 0 ;
7983
    end
7984
 
7985
    // set target to terminate with target abort
7986
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7987
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7988
 
7989
    // enable pci blue behavioral target 2
7990
    configuration_cycle_write
7991
    (
7992
        0,                          // bus number [7:0]
7993
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7994
        0,                          // function number [2:0]
7995
        1,                          // register number [5:0]
7996
        0,                          // type [1:0]
7997
        4'h1,                       // byte enables [3:0]
7998
        32'h0000_0047               // data to write [31:0]
7999
    ) ;
8000
 
8001
    // read PCI Device status
8002
    config_read(12'h4, 4'hC, temp_var) ;
8003
    if (temp_var[29] !== 1)
8004
    begin
8005
        $display("Time %t", $time) ;
8006
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
8007
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
8008
        ok_wb = 0 ;
8009
    end
8010
 
8011
    if (temp_var[28] !== 1)
8012
    begin
8013
        $display("Time %t", $time) ;
8014
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
8015
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
8016
        ok_wb = 0 ;
8017
    end
8018
 
8019
    // clearing the status bits
8020
        config_write(12'h4, temp_var, 4'hC, ok);
8021
 
8022
    if ( ok && ok_pci && ok_wb )
8023
        test_ok ;
8024
 
8025 15 mihad
end
8026
endtask //iack_cycle
8027
 
8028
task transaction_ordering ;
8029
    reg   [11:0] wb_ctrl_offset ;
8030
    reg   [11:0] wb_ba_offset ;
8031
    reg   [11:0] wb_am_offset ;
8032
    reg   [11:0] pci_ctrl_offset ;
8033
    reg   [11:0] pci_ba_offset ;
8034
    reg   [11:0] pci_am_offset ;
8035
    reg   [11:0] pci_device_ctrl_offset ;
8036
    reg   [11:0] wb_err_cs_offset ;
8037
    reg   [11:0] pci_err_cs_offset ;
8038
    reg   [11:0] icr_offset ;
8039
    reg   [11:0] isr_offset ;
8040
    reg   [11:0] lat_tim_cls_offset ;
8041
 
8042
    reg `WRITE_STIM_TYPE  write_data ;
8043
    reg `READ_STIM_TYPE   read_data ;
8044
    reg `READ_RETURN_TYPE read_status ;
8045
 
8046
    reg `WRITE_RETURN_TYPE write_status ;
8047
    reg `WB_TRANSFER_FLAGS write_flags ;
8048
    reg [31:0] temp_val1 ;
8049
    reg [31:0] temp_val2 ;
8050
    reg        ok   ;
8051
 
8052
    reg [31:0] wb_image_base ;
8053
    reg [31:0] wb_target_address ;
8054
    reg [31:0] pci_image_base ;
8055
    integer i ;
8056
 
8057
    reg     error_monitor_done ;
8058
begin:main
8059
    write_flags`INIT_WAITS = tb_init_waits ;
8060
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
8061
 
8062
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
8063
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
8064
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
8065
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
8066
 
8067
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
8068
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
8069
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
8070
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
8071
 
8072
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
8073
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
8074
    lat_tim_cls_offset = 12'hC ;
8075
    pci_device_ctrl_offset    = 12'h4 ;
8076
 
8077
    wb_target_address  = `BEH_TAR1_MEM_START ;
8078
    wb_image_base      = 0 ;
8079
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
8080
 
8081
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
8082
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
8083
    write_flags                    = 0 ;
8084
    write_flags`INIT_WAITS         = 0 ;
8085
    write_flags`SUBSEQ_WAITS       = 0 ;
8086
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8087
 
8088
    pci_image_base = Target_Base_Addr_R[1] ;
8089
 
8090
    // enable master & target operation
8091
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
8092
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
8093
    if ( ok !== 1 )
8094
    begin
8095
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
8096
        test_fail("write to PCI Device Control register failed") ;
8097
        disable main ;
8098
    end
8099
 
8100
    // prepare image control register
8101
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8102
    if ( ok !== 1 )
8103
    begin
8104
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
8105
        test_fail("write to WB Image Control register failed") ;
8106
        disable main ;
8107
    end
8108
 
8109
    // prepare base address register
8110
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8111
    if ( ok !== 1 )
8112
    begin
8113
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8114
        test_fail("write to WB Base Address register failed") ;
8115
        disable main ;
8116
    end
8117
 
8118
    // write address mask register
8119
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8120
    if ( ok !== 1 )
8121
    begin
8122
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8123
        test_fail("write to WB Address Mask register failed") ;
8124
        disable main ;
8125
    end
8126
 
8127
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8128
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8129
    if ( ok !== 1 )
8130
    begin
8131
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8132
        test_fail("write to WB Error Control and Status register failed") ;
8133
        disable main ;
8134
    end
8135
 
8136
    // prepare image control register
8137
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8138
    if ( ok !== 1 )
8139
    begin
8140
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8141
        test_fail("write to PCI Image Control register failed") ;
8142
        disable main ;
8143
    end
8144
 
8145
    // prepare base address register
8146
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8147
    if ( ok !== 1 )
8148
    begin
8149
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8150
        test_fail("write to PCI Base Address register failed") ;
8151
        disable main ;
8152
    end
8153
 
8154
    // write address mask register
8155
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8156
    if ( ok !== 1 )
8157
    begin
8158
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8159
        test_fail("write to PCI Address Mask register failed") ;
8160
        disable main ;
8161
    end
8162
 
8163
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8164
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8165
    if ( ok !== 1 )
8166
    begin
8167
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8168
        test_fail("write to PCI Error Control and Status register failed") ;
8169
        disable main ;
8170
    end
8171
 
8172
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8173
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8174
    if ( ok !== 1 )
8175
    begin
8176
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8177
        test_fail("write to Interrupt Control register failed") ;
8178
        disable main ;
8179
    end
8180
 
8181
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8182
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8183
    if ( ok !== 1 )
8184
    begin
8185
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8186
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8187
        disable main ;
8188
    end
8189
 
8190
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8191
 
8192
    // prepare wb_master write and read data
8193
    for ( i = 0 ; i < 4 ; i = i + 1 )
8194
    begin
8195
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8196
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8197
        write_data`WRITE_SEL     = 4'hF ;
8198
 
8199
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8200
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8201
 
8202
        wishbone_master.blk_write_data[i]   = write_data ;
8203
        wishbone_master.blk_read_data_in[i] = read_data ;
8204
    end
8205
 
8206
    // put wishbone slave in acknowledge and pci target in retry mode
8207
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8208
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8209
 
8210
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8211
 
8212
    fork
8213
    begin
8214
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8215
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8216
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8217
        begin
8218
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8219
            test_fail("Bridge didn't post single memory write as expected") ;
8220
        end
8221
 
8222
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8223
        if ( ok !== 1 )
8224
        begin
8225
            $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) ;
8226
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8227
            ok = 0 ;
8228
        end
8229
 
8230
        // now post single write to target - normal progress
8231
        if ( target_mem_image == 1 )
8232
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8233
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8234
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8235
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8236
        else
8237
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8238
 
8239
        do_pause( 1 ) ;
8240
 
8241
    end
8242
    begin:error_monitor_1
8243 35 mihad
        error_monitor_done = 0 ;
8244 15 mihad
        @(error_event_int) ;
8245
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8246
        ok = 0 ;
8247 35 mihad
        error_monitor_done = 1 ;
8248 15 mihad
    end
8249
    begin
8250
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8251
        if ( ok !== 1 )
8252
        begin
8253
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8254
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8255
        end
8256
        else
8257
        begin
8258 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8259
//            while ( FRAME === 0 || IRDY === 0 )
8260
//                @(posedge pci_clock) ;
8261 15 mihad
 
8262
            // enable response in PCI target
8263
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8264
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8265
 
8266
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8267
            if ( ok !== 1 )
8268
            begin
8269
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8270
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8271
            end
8272
        end
8273
 
8274 35 mihad
        #1 ;
8275
        if ( !error_monitor_done )
8276
            disable error_monitor_1 ;
8277 15 mihad
    end
8278
    join
8279
 
8280
    if ( ok )
8281
        test_ok ;
8282
 
8283
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8284
 
8285
    // put WISHBONE slave in retry mode
8286
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8287
 
8288
    fork
8289
    begin
8290
        // now post single write to target - normal progress
8291
        if ( target_mem_image == 1 )
8292
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8293
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8294
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8295
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8296
        else
8297
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8298
 
8299
        do_pause( 1 ) ;
8300
 
8301
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8302
        if ( ok !== 1 )
8303
        begin
8304
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8305
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8306
        end
8307
 
8308
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8309
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8310
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8311
        begin
8312
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8313
            test_fail("Bridge didn't post single memory write as expected") ;
8314
        end
8315
 
8316
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8317
        if ( ok !== 1 )
8318
        begin
8319
            $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) ;
8320
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8321
            ok = 0 ;
8322
        end
8323
 
8324
        wait ( CYC_O === 0 ) ;
8325
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8326
 
8327
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8328
        if ( ok !== 1 )
8329
        begin
8330
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8331
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8332
        end
8333
 
8334 35 mihad
        #1 ;
8335
        if ( !error_monitor_done )
8336
            disable error_monitor_2 ;
8337 15 mihad
    end
8338
    begin:error_monitor_2
8339 35 mihad
        error_monitor_done = 0 ;
8340 15 mihad
        @(error_event_int) ;
8341
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8342
        ok = 0 ;
8343 35 mihad
        error_monitor_done = 1 ;
8344 15 mihad
    end
8345
    join
8346
 
8347
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8348
 
8349
    // put wishbone slave in acknowledge and pci target in retry mode
8350
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8351
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8352
 
8353
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8354
 
8355
    fork
8356
    begin
8357
        write_flags`WB_TRANSFER_SIZE = 3 ;
8358
        write_flags`WB_TRANSFER_CAB  = 1 ;
8359
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8360
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8361
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8362
        begin
8363
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8364
            test_fail("Bridge didn't post burst memory write as expected") ;
8365
        end
8366
 
8367
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8368
        if ( ok !== 1 )
8369
        begin
8370
            $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) ;
8371
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8372
            ok = 0 ;
8373
        end
8374
 
8375
        // now post single write to target - normal progress
8376
        if ( target_mem_image == 1 )
8377
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8378
                        pci_image_base, 32'h5555_5555, 4'h0,
8379
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8380
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8381
        else
8382
        begin
8383
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8384
            do_pause( 1 ) ;
8385
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8386
        end
8387
 
8388
        do_pause( 1 ) ;
8389
 
8390
    end
8391
    begin:error_monitor_3
8392 35 mihad
        error_monitor_done = 0 ;
8393 15 mihad
        @(error_event_int) ;
8394
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8395
        ok = 0 ;
8396 35 mihad
        error_monitor_done = 1 ;
8397 15 mihad
    end
8398
    begin
8399
        if ( target_mem_image == 1 )
8400
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8401
        else
8402
        begin
8403
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8404
            if ( ok )
8405
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8406
        end
8407
 
8408
        if ( ok !== 1 )
8409
        begin
8410
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8411
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8412
        end
8413
        else
8414
        begin
8415 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8416
//            while ( FRAME === 0 || IRDY === 0 )
8417
//                @(posedge pci_clock) ;
8418 15 mihad
 
8419
            // enable response in PCI target
8420
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8421
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8422
 
8423
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8424
            if ( ok !== 1 )
8425
            begin
8426
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8427
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8428
            end
8429
        end
8430
 
8431 35 mihad
        #1 ;
8432
        if ( !error_monitor_done )
8433
            disable error_monitor_3 ;
8434 15 mihad
    end
8435
    join
8436
 
8437
    if ( ok )
8438
        test_ok ;
8439
 
8440
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8441
 
8442
    // put WISHBONE slave in retry mode
8443
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8444
 
8445
    fork
8446
    begin
8447
        // now post single write to target - normal progress
8448
        if ( target_mem_image == 1 )
8449
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8450
                        pci_image_base, 32'h5555_5555, 4'h0,
8451
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8452
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8453
        else
8454
        begin
8455
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8456
            do_pause( 1 ) ;
8457
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8458
        end
8459
 
8460
        do_pause( 1 ) ;
8461
 
8462
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8463
 
8464
        if ( ok !== 1 )
8465
        begin
8466
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8467
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8468
        end
8469
 
8470
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8471
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8472
        write_flags`WB_TRANSFER_CAB      = 1 ;
8473
 
8474
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8475
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8476
        begin
8477
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8478
            test_fail("Bridge didn't post burst memory write as expected") ;
8479
        end
8480
 
8481
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8482
        if ( ok !== 1 )
8483
        begin
8484
            $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) ;
8485
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8486
            ok = 0 ;
8487
        end
8488
 
8489
        @(posedge wb_clock) ;
8490
        while ( CYC_O === 1 )
8491
            @(posedge wb_clock) ;
8492
 
8493
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8494
 
8495
        if ( target_mem_image == 1 )
8496
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8497
        else
8498
        begin
8499
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8500
            if ( ok )
8501
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8502
        end
8503
 
8504 35 mihad
        #1 ;
8505
        if ( !error_monitor_done )
8506
            disable error_monitor_4 ;
8507 15 mihad
    end
8508
    begin:error_monitor_4
8509 35 mihad
        error_monitor_done = 0 ;
8510 15 mihad
        @(error_event_int) ;
8511
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8512
        ok = 0 ;
8513 35 mihad
        error_monitor_done = 1 ;
8514 15 mihad
    end
8515
    join
8516
 
8517
    if ( ok )
8518
        test_ok ;
8519
 
8520
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8521
 
8522
    // put wishbone slave in acknowledge and pci target in retry mode
8523
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8524
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8525
 
8526
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8527
 
8528
    master1_check_received_data = 1 ;
8529
 
8530
    error_monitor_done = 0 ;
8531
    fork
8532
    begin:error_monitor_5
8533
        @(error_event_int or error_monitor_done) ;
8534
        if ( !error_monitor_done )
8535
        begin
8536
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8537
            ok = 0 ;
8538
        end
8539
    end
8540
    begin
8541
 
8542
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8543
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8544
        begin
8545
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8546
            test_fail("Bridge didn't post single memory write as expected") ;
8547
        end
8548
 
8549
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8550
        if ( ok !== 1 )
8551
        begin
8552
            $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) ;
8553
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8554
            ok = 0 ;
8555
        end
8556
 
8557
        // start Read Through pci target
8558
        if ( target_mem_image == 1 )
8559
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8560
                          pci_image_base, 32'h5555_5555,
8561
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8562
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8563
        else
8564
            PCIU_IO_READ
8565
             (
8566
                `Test_Master_1,
8567
                pci_image_base,
8568
                32'h5555_5555,
8569
                4'h0,
8570
                1,
8571
                `Test_Target_Retry_On
8572
             );
8573
 
8574
         do_pause( 1 ) ;
8575
 
8576
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8577
         if ( ok !== 1 )
8578
         begin
8579
            $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) ;
8580
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8581
         end
8582
 
8583
         // repeat the read 4 times - it should be retried all the time by pci target
8584
        for ( i = 0 ; i < 4 ; i = i + 1 )
8585
        begin
8586
            if ( target_mem_image == 1 )
8587
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8588
                            pci_image_base, 32'h5555_5555,
8589
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8590
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8591
            else
8592
                PCIU_IO_READ
8593
                (
8594
                    `Test_Master_1,
8595
                    pci_image_base,
8596
                    32'h5555_5555,
8597
                    4'h0,
8598
                    1,
8599
                    `Test_Target_Retry_On
8600
                );
8601
 
8602
            do_pause( 1 ) ;
8603
        end
8604
 
8605
        // now do posted write through target - it must go through OK
8606
        if ( target_mem_image == 1 )
8607
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8608
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8609
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8610
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8611
        else
8612
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8613
 
8614
        do_pause( 1 ) ;
8615
 
8616
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8617
        if ( ok !== 1 )
8618
        begin
8619
           $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) ;
8620
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8621
        end
8622
 
8623
        // start a read through wb_slave
8624
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8625
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8626
        begin
8627
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8628
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8629
            ok = 0 ;
8630
        end
8631
 
8632 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8633
//        while ( FRAME === 0 || IRDY === 0 )
8634
//            @(posedge pci_clock) ;
8635 15 mihad
 
8636
        // set the target to normal completion
8637
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8638
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8639
 
8640
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8641
        if ( ok !== 1 )
8642
        begin
8643
            $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) ;
8644
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8645
            ok = 0 ;
8646
        end
8647
 
8648
        // now wait for delayed read to finish
8649
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8650
        if ( ok !== 1 )
8651
        begin
8652
            $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) ;
8653
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8654
            ok = 0 ;
8655
        end
8656
 
8657
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8658
        fork
8659
        begin
8660
                if ( target_mem_image == 1 )
8661
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8662
                                pci_image_base, 32'h5555_5555, 4'h0,
8663
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8664
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8665
                else
8666
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8667
 
8668
                do_pause( 1 ) ;
8669
                end
8670
                begin
8671 73 mihad
            pci_transaction_progress_monitor( pci_image_base, ((target_mem_image == 1) ? `BC_MEM_WRITE : `BC_IO_WRITE), 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8672 15 mihad
                end
8673
                join
8674
 
8675
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8676
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8677
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8678
        begin
8679
            $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) ;
8680
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8681
            ok = 0 ;
8682
        end
8683
 
8684
        fork
8685
        begin
8686
        // now complete a read from PCI Target
8687
            if ( target_mem_image == 1 )
8688
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8689
                            pci_image_base, 32'h5555_5555,
8690
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8691
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8692
            else
8693
                PCIU_IO_READ
8694
                (
8695
                    `Test_Master_1,
8696
                    pci_image_base,
8697
                    32'h5555_5555,
8698
                    4'h0,
8699
                    1,
8700
                    `Test_Target_Normal_Completion
8701
                );
8702
 
8703
            do_pause( 1 ) ;
8704
        end
8705
        begin
8706
            if ( target_mem_image == 1 )
8707
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8708
            else
8709
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8710
        end
8711
        join
8712
 
8713
        @(posedge pci_clock) ;
8714
        repeat( 4 )
8715
            @(posedge wb_clock) ;
8716
 
8717
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8718
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8719
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8720
        begin
8721
            $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) ;
8722
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8723
            ok = 0 ;
8724
        end
8725
 
8726
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8727
        if ( ok !== 1 )
8728
        begin
8729
            $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) ;
8730
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8731
            ok = 0 ;
8732
        end
8733
 
8734
        // finish a read on WISHBONE also
8735
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8736
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8737
        begin
8738
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8739
            test_fail("WB Slave didn't process single delayed read as expected") ;
8740
        end
8741
 
8742
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8743
        begin
8744
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8745
            ok = 0 ;
8746
        end
8747
 
8748
 
8749
        error_monitor_done = 1 ;
8750
    end
8751
    join
8752
 
8753
    if ( ok )
8754
        test_ok ;
8755
 
8756
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8757
 
8758
    // put wishbone slave in retry and pci target in completion mode
8759
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8760
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8761
 
8762
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8763
 
8764
    master1_check_received_data = 1 ;
8765
 
8766
    error_monitor_done = 0 ;
8767
    fork
8768
    begin:error_monitor_6
8769
        @(error_event_int or error_monitor_done) ;
8770
        if ( !error_monitor_done )
8771
        begin
8772
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8773
            ok = 0 ;
8774
        end
8775
    end
8776
    begin
8777
 
8778
        // do a write through Target
8779
        fork
8780
        begin
8781
            if ( target_mem_image == 1 )
8782
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8783
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8784
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8785
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8786
            else
8787
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8788
 
8789
            do_pause( 1 ) ;
8790
        end
8791
        begin
8792
            if ( target_mem_image == 1 )
8793
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8794
            else
8795
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8796
        end
8797
        join
8798
 
8799
        // start a read through WB slave
8800
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8801
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8802
        begin
8803
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8804
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8805
            ok = 0 ;
8806
        end
8807
 
8808
        // now wait for this read to finish on pci
8809
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8810
        if ( ok !== 1 )
8811
        begin
8812
            $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) ;
8813
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8814
            ok = 0 ;
8815
        end
8816
 
8817
        // repeat the read four times - it should be retried
8818
        for ( i = 0 ; i < 4 ; i = i + 1 )
8819
        begin
8820
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8821
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8822
            begin
8823
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8824
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8825
                ok = 0 ;
8826
            end
8827
        end
8828
 
8829
        // posted write through WB Slave - must go through
8830
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8831
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8832
        begin
8833
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8834
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8835
            ok = 0 ;
8836
        end
8837
 
8838
        // write must come through
8839
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8840
        if ( ok !== 1 )
8841
        begin
8842
            $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) ;
8843
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8844
            ok = 0 ;
8845
        end
8846
 
8847
        // do a read through pci target
8848
        if ( target_mem_image == 1 )
8849
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8850
                          pci_image_base + 12, 32'hDEAD_BEAF,
8851
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8852
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8853
        else
8854
            PCIU_IO_READ
8855
             (
8856
                `Test_Master_1,
8857
                pci_image_base + 12,
8858
                32'hDEAD_BEAF,
8859
                4'h0,
8860
                1,
8861
                `Test_Target_Retry_On
8862
             );
8863
 
8864
         do_pause( 1 ) ;
8865
 
8866
        // wait for current cycle to finish on WB
8867 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8868
//        @(posedge wb_clock) ;
8869
//        while( CYC_O === 1 )
8870
//            @(posedge wb_clock) ;
8871 15 mihad
 
8872
        // set slave response to acknowledge
8873
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8874
 
8875
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8876
        if ( ok !== 1 )
8877
        begin
8878
            $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) ;
8879
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8880
        end
8881
 
8882
        // check the read to finish on wb
8883
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8884
        if ( ok !== 1 )
8885
        begin
8886
            $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) ;
8887
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8888
        end
8889
 
8890
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8891
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8892
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8893
        begin
8894
            $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) ;
8895
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8896
            ok = 0 ;
8897
        end
8898
 
8899
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8900
        fork
8901
        begin
8902
            if ( target_mem_image == 1 )
8903
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8904
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8905
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8906
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8907
            else
8908
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8909
        end
8910
        begin
8911
            if ( target_mem_image == 1 )
8912
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8913
            else
8914
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8915
        end
8916
        join
8917
 
8918
        do_pause( 1 ) ;
8919
 
8920
        // complete a read in WB Slave Unit
8921
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8922
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8923
        begin
8924
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8925
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8926
            ok = 0 ;
8927
        end
8928
 
8929
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8930
        begin
8931
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8932
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8933
            ok = 0 ;
8934
        end
8935
 
8936
        // wait for statuses to be propagated from one side of bridge to another
8937
        repeat( 4 )
8938
            @(posedge pci_clock) ;
8939
 
8940
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8941
        fork
8942
        begin
8943
            if ( target_mem_image == 1 )
8944
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8945
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8946
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8947
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8948
            else
8949
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8950
 
8951
            do_pause( 1 ) ;
8952
        end
8953
        begin
8954
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8955
            if ( ok !== 1 )
8956
            begin
8957
                $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) ;
8958
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8959
            end
8960
        end
8961
        join
8962
 
8963
        // finish the last read in PCI Target Unit
8964
        if ( target_mem_image == 1 )
8965
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8966
                          pci_image_base + 12, 32'hDEAD_BEAF,
8967
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8968
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8969
        else
8970
            PCIU_IO_READ
8971
             (
8972
                `Test_Master_1,
8973
                pci_image_base + 12,
8974
                32'hDEAD_BEAF,
8975
                4'h0,
8976
                1,
8977
                `Test_Target_Normal_Completion
8978
             );
8979
 
8980
         do_pause( 1 ) ;
8981
 
8982
         error_monitor_done = 1 ;
8983
    end
8984
    join
8985
 
8986
    if ( ok )
8987
        test_ok ;
8988
 
8989
end
8990
endtask // transaction_ordering
8991
 
8992
task pci_transaction_progress_monitor ;
8993
    input [31:0] address ;
8994
    input [3:0]  bus_command ;
8995
    input [31:0] num_of_transfers ;
8996
    input [31:0] num_of_cycles ;
8997
    input check_transfers ;
8998
    input check_cycles ;
8999
    input doing_fast_back_to_back ;
9000
    output ok ;
9001
    reg in_use ;
9002
    integer deadlock_counter ;
9003
    integer transfer_counter ;
9004
    integer cycle_counter ;
9005
    integer deadlock_max_val ;
9006
begin:main
9007
 
9008
    if ( in_use === 1 )
9009
    begin
9010
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9011
        ok = 0 ;
9012
        disable main ;
9013
    end
9014
 
9015
    // approximate number of cycles on WB bus for maximum transaction length
9016
    deadlock_max_val = tb_init_waits + 100 +
9017
                       `WBW_DEPTH *
9018
                       (tb_subseq_waits + 1 +
9019
                       `ifdef REGISTER_WBS_OUTPUTS
9020
                       1) ;
9021
                       `else
9022
                       0) ;
9023
                       `endif
9024
 
9025
    // time used for maximum transaction length on WB
9026
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
9027
 
9028
    // maximum pci clock cycles
9029
    `ifdef PCI33
9030
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
9031
    `else
9032
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
9033
    `endif
9034
 
9035
    in_use = 1 ;
9036
    ok     = 1 ;
9037
 
9038
    fork
9039
    begin:wait_start
9040
 
9041
        deadlock_counter = 0 ;
9042
 
9043
        @(posedge pci_clock) ;
9044
 
9045
        if ( doing_fast_back_to_back !== 1 )
9046
        begin
9047
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
9048
            begin
9049 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
9050
                    deadlock_counter = 0 ;
9051
                else
9052
                    deadlock_counter = deadlock_counter + 1 ;
9053 15 mihad
                @(posedge pci_clock) ;
9054
            end
9055
            if ( FRAME !== 1 )
9056
            begin
9057
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9058
                in_use = 0 ;
9059
                ok     = 0 ;
9060
                disable main ;
9061
            end
9062
        end
9063
 
9064
        deadlock_counter = 0 ;
9065
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
9066
        begin
9067
            deadlock_counter = deadlock_counter + 1 ;
9068
            @(posedge pci_clock) ;
9069
        end
9070
 
9071
        if ( FRAME !== 0 )
9072
        begin
9073
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9074
            in_use = 0 ;
9075
            ok     = 0 ;
9076
            disable main ;
9077
        end
9078
    end //wait_start
9079
 
9080
    begin:addr_bc_monitor
9081
 
9082
        @(posedge pci_clock) ;
9083
 
9084
        if ( doing_fast_back_to_back !== 1 )
9085
        begin
9086
            while ( FRAME !== 1 )
9087
                @(posedge pci_clock) ;
9088
        end
9089
 
9090
        while( FRAME !== 0 )
9091
            @(posedge pci_clock) ;
9092
 
9093
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
9094
        if ( bus_command !== `BC_IACK )
9095
        begin
9096
            if ( AD !== address )
9097
            begin
9098
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
9099
                $display("Expected address = %h, detected address = %h ", address, AD) ;
9100
                ok = 0 ;
9101
            end
9102
        end
9103
 
9104
        if ( CBE !== bus_command )
9105
        begin
9106
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
9107
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
9108
            ok = 0 ;
9109
        end
9110
    end //addr_bc_monitor
9111
 
9112
    begin:transfer_checker
9113
        transfer_counter = 0 ;
9114
 
9115
        @(posedge pci_clock) ;
9116
 
9117
        if ( doing_fast_back_to_back !== 1 )
9118
        begin
9119
            while ( FRAME !== 1 )
9120
                @(posedge pci_clock) ;
9121
        end
9122
 
9123
        while( FRAME !== 0 )
9124
            @(posedge pci_clock) ;
9125
 
9126
        while( FRAME === 0 )
9127
        begin
9128
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
9129
                transfer_counter = transfer_counter + 1 ;
9130
            @(posedge pci_clock) ;
9131
        end
9132
 
9133
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
9134
        begin
9135
            @(posedge pci_clock) ;
9136
        end
9137
 
9138
        if ( (TRDY === 0) && (DEVSEL === 0) )
9139
                transfer_counter = transfer_counter + 1 ;
9140
 
9141
        if ( check_transfers === 1 )
9142
        begin
9143
            if ( transfer_counter !== num_of_transfers )
9144
            begin
9145
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9146
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9147
                ok = 0 ;
9148
            end
9149
        end
9150
    end //transfer_checker
9151
    begin:cycle_checker
9152
        if ( check_cycles )
9153
        begin
9154
            cycle_counter = 0 ;
9155
            @(posedge pci_clock) ;
9156
 
9157
            if ( doing_fast_back_to_back !== 1)
9158
            begin
9159
                while ( FRAME !== 1 )
9160
                    @(posedge pci_clock) ;
9161
            end
9162
 
9163
            while( FRAME !== 0 )
9164
                @(posedge pci_clock) ;
9165
 
9166
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9167
            begin
9168
                cycle_counter = cycle_counter + 1 ;
9169
                @(posedge pci_clock) ;
9170
            end
9171
 
9172
            if ( FRAME !== 1 )
9173
            begin
9174
                while ((FRAME === 0) && (MAS0_GNT === 0))
9175
                    @(posedge pci_clock) ;
9176
 
9177
                if ( FRAME !== 1 )
9178
                begin
9179
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9180
                        @(posedge pci_clock) ;
9181
 
9182
                    @(posedge pci_clock) ;
9183
 
9184
                    if ( FRAME !== 1 )
9185
                    begin
9186
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9187
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9188
                        ok = 0 ;
9189
                    end
9190
                end
9191
            end
9192
        end
9193
    end // cycle_checker
9194
    join
9195
 
9196
    in_use = 0 ;
9197
end
9198
endtask //pci_transaction_progress_monitor
9199
 
9200
reg CYC_O_previous ;
9201
always@(posedge wb_clock or posedge reset)
9202
begin
9203
    if ( reset )
9204
        CYC_O_previous <= #1 1'b0 ;
9205
    else
9206
        CYC_O_previous <= #1 CYC_O ;
9207
end
9208
 
9209
task wb_transaction_progress_monitor ;
9210
    input [31:0] address ;
9211
    input        write ;
9212
    input [31:0] num_of_transfers ;
9213
    input check_transfers ;
9214
    output ok ;
9215
    reg in_use ;
9216
    integer deadlock_counter ;
9217
    integer transfer_counter ;
9218
    integer deadlock_max_val ;
9219 73 mihad
    reg [2:0] slave_termination ;
9220
    reg       cab_asserted ;
9221 15 mihad
begin:main
9222
    if ( in_use === 1 )
9223
    begin
9224
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9225
        ok = 0 ;
9226
        disable main ;
9227
    end
9228
 
9229
    // number of cycles on WB bus for maximum transaction length
9230
    deadlock_max_val = 4 - tb_init_waits + 100 +
9231
                       `PCIW_DEPTH *
9232
                       (4 - tb_subseq_waits + 1) ;
9233
 
9234
    // time used for maximum transaction length on PCI
9235
    `ifdef PCI33
9236
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9237
    `else
9238
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9239
    `endif
9240
 
9241
    // maximum wb clock cycles
9242
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9243
 
9244 73 mihad
    in_use       = 1 ;
9245
    ok           = 1 ;
9246
    cab_asserted = 0 ;
9247 15 mihad
 
9248
    fork
9249
    begin:wait_start
9250
        deadlock_counter = 0 ;
9251
        @(posedge wb_clock) ;
9252
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9253
        begin
9254 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9255
                deadlock_counter = deadlock_counter + 1 ;
9256
            else
9257
                deadlock_counter = 0;
9258 15 mihad
            @(posedge wb_clock) ;
9259
        end
9260
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9261
        begin
9262
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9263
            in_use = 0 ;
9264
            ok     = 0 ;
9265
            disable main ;
9266
        end
9267
 
9268
        deadlock_counter = 0 ;
9269
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9270
        begin
9271
            deadlock_counter = deadlock_counter + 1 ;
9272
            @(posedge wb_clock) ;
9273
        end
9274
 
9275
        if ( CYC_O !== 1 )
9276
        begin
9277
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9278
            in_use = 0 ;
9279
            ok     = 0 ;
9280
            disable main ;
9281
        end
9282
    end //wait_start
9283
    begin:addr_monitor
9284
        @(posedge wb_clock) ;
9285
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9286
            @(posedge wb_clock) ;
9287
 
9288
        while( CYC_O !== 1 )
9289
            @(posedge wb_clock) ;
9290
 
9291
        while (STB_O !== 1 )
9292
            @(posedge wb_clock) ;
9293
 
9294
        if ( WE_O !== write )
9295
        begin
9296
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9297
            if ( write !== 1 )
9298
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9299
            else
9300
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9301
        end
9302
 
9303
        if ( ADR_O !== address )
9304
        begin
9305
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9306
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9307
            ok = 0 ;
9308
        end
9309
    end
9310
    begin:transfer_checker
9311
        transfer_counter = 0 ;
9312
        @(posedge wb_clock) ;
9313
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9314
            @(posedge wb_clock) ;
9315
 
9316
        while( CYC_O !== 1 )
9317
            @(posedge wb_clock) ;
9318
 
9319 63 mihad
        while( (CYC_O === 1) && ((transfer_counter <= `PCIW_DEPTH) || (transfer_counter <= `PCIR_DEPTH)) )
9320 15 mihad
        begin
9321 73 mihad
 
9322
            if (!cab_asserted)
9323
                cab_asserted = (CAB_O !== 1'b0) ;
9324
 
9325
            if (STB_O === 1)
9326
            begin
9327
                slave_termination = {ACK_I, ERR_I, RTY_I} ;
9328
                if (ACK_I)
9329
                    transfer_counter = transfer_counter + 1 ;
9330
            end
9331 15 mihad
            @(posedge wb_clock) ;
9332
        end
9333
 
9334 73 mihad
        if (cab_asserted)
9335
        begin
9336
            // cab was sampled asserted
9337
            // if number of transfers was less than 2 - check for extraordinary terminations
9338
            if (transfer_counter < 2)
9339
            begin
9340
                // if cycle was terminated because of no response, error or retry, than it is OK to have CAB_O asserted while transfering 0 or 1 data.
9341
                // any other cases are wrong
9342
                case (slave_termination)
9343
                3'b000:begin end
9344
                3'b001:begin end
9345
                3'b010:begin end
9346
                default:begin
9347
                            ok = 0 ;
9348
                            $display("Time %t", $time) ;
9349
                            $display("WB_MASTER asserted CAB_O for single transfer") ;
9350
                        end
9351
                endcase
9352
            end
9353
        end
9354
        else
9355
        begin
9356
            // if cab is not asserted, then WB_MASTER should not read more than one data.
9357
            if (transfer_counter > 1)
9358
            begin
9359
                ok = 0 ;
9360
                $display("Time %t", $time) ;
9361
                $display("WB_MASTER didn't assert CAB_O for consecutive block transfer") ;
9362
            end
9363
        end
9364
 
9365 15 mihad
        if ( check_transfers === 1 )
9366
        begin
9367
            if ( transfer_counter !== num_of_transfers )
9368
            begin
9369
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9370
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9371
                ok = 0 ;
9372
            end
9373
        end
9374
    end //transfer_checker
9375
    join
9376
 
9377
    in_use = 0 ;
9378
end
9379
endtask // wb_transaction_progress_monitor
9380
 
9381
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9382
// so they are not re-entered
9383
task wb_transaction_progress_monitor_backup ;
9384
    input [31:0] address ;
9385
    input        write ;
9386
    input [31:0] num_of_transfers ;
9387
    input check_transfers ;
9388
    output ok ;
9389
    reg in_use ;
9390
    integer deadlock_counter ;
9391
    integer transfer_counter ;
9392
    integer deadlock_max_val ;
9393
begin:main
9394
    if ( in_use === 1 )
9395
    begin
9396
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9397
        ok = 0 ;
9398
        disable main ;
9399
    end
9400
 
9401
    // number of cycles on WB bus for maximum transaction length
9402
    deadlock_max_val = 4 - tb_init_waits + 100 +
9403
                       `PCIW_DEPTH *
9404
                       (4 - tb_subseq_waits + 1) ;
9405
 
9406
    // time used for maximum transaction length on PCI
9407
    `ifdef PCI33
9408
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9409
    `else
9410
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9411
    `endif
9412
 
9413
    // maximum wb clock cycles
9414
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9415
 
9416
    in_use = 1 ;
9417
    ok     = 1 ;
9418
 
9419
    fork
9420
    begin:wait_start
9421
        deadlock_counter = 0 ;
9422
        @(posedge wb_clock) ;
9423
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9424
        begin
9425 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9426
                deadlock_counter = deadlock_counter + 1 ;
9427
            else
9428
                deadlock_counter = 0;
9429 15 mihad
            @(posedge wb_clock) ;
9430
        end
9431
        if ( CYC_O !== 0 )
9432
        begin
9433
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9434
            in_use = 0 ;
9435
            ok     = 0 ;
9436
            disable main ;
9437
        end
9438
 
9439
        deadlock_counter = 0 ;
9440
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9441
        begin
9442
            deadlock_counter = deadlock_counter + 1 ;
9443
            @(posedge wb_clock) ;
9444
        end
9445
 
9446
        if ( CYC_O !== 1 )
9447
        begin
9448
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9449
            in_use = 0 ;
9450
            ok     = 0 ;
9451
            disable main ;
9452
        end
9453
    end //wait_start
9454
    begin:addr_monitor
9455
        @(posedge wb_clock) ;
9456
        while ( CYC_O !== 0 )
9457
            @(posedge wb_clock) ;
9458
 
9459
        while( CYC_O !== 1 )
9460
            @(posedge wb_clock) ;
9461
 
9462
        while (STB_O !== 1 )
9463
            @(posedge wb_clock) ;
9464
 
9465
        if ( WE_O !== write )
9466
        begin
9467
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9468
            if ( write !== 1 )
9469
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9470
            else
9471
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9472
        end
9473
 
9474
        if ( ADR_O !== address )
9475
        begin
9476
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9477
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9478
            ok = 0 ;
9479
        end
9480
    end
9481
    begin:transfer_checker
9482
        transfer_counter = 0 ;
9483
        @(posedge wb_clock) ;
9484
        while ( CYC_O !== 0 )
9485
            @(posedge wb_clock) ;
9486
 
9487
        while( CYC_O !== 1 )
9488
            @(posedge wb_clock) ;
9489
 
9490
        while( CYC_O === 1 )
9491
        begin
9492
            if ( (STB_O === 1) && (ACK_I === 1) )
9493
                transfer_counter = transfer_counter + 1 ;
9494
            @(posedge wb_clock) ;
9495
        end
9496
 
9497
        if ( check_transfers === 1 )
9498
        begin
9499
            if ( transfer_counter !== num_of_transfers )
9500
            begin
9501
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9502
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9503
                ok = 0 ;
9504
            end
9505
        end
9506
    end //transfer_checker
9507
    join
9508
 
9509
    in_use = 0 ;
9510
end
9511
endtask // wb_transaction_progress_monitor_backup
9512
 
9513
task wb_transaction_stop ;
9514
    input [31:0] num_of_transfers ;
9515
    integer transfer_counter ;
9516
begin:main
9517
    begin:transfer_checker
9518
        transfer_counter = 0 ;
9519
        @(posedge wb_clock) ;
9520
        while ( CYC_O !== 0 )
9521
            @(posedge wb_clock) ;
9522
 
9523
        while( CYC_O !== 1 )
9524
            @(posedge wb_clock) ;
9525
 
9526
        if ( (STB_O === 1) && (ACK_I === 1) )
9527
            transfer_counter = transfer_counter + 1 ;
9528
 
9529
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9530
        begin
9531
            @(posedge wb_clock) ;
9532
            if ( (STB_O === 1) && (ACK_I === 1) )
9533
                transfer_counter = transfer_counter + 1 ;
9534
        end
9535
    end //transfer_checker
9536
end
9537
endtask // wb_transaction_stop
9538
 
9539
task musnt_respond ;
9540
    output ok ;
9541
    reg in_use ;
9542
    integer i ;
9543
begin:main
9544
    if ( in_use === 1 )
9545
    begin
9546
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9547
        #20 $stop ;
9548
        ok = 0 ;
9549
        disable main ;
9550
    end
9551
 
9552
    in_use = 1 ;
9553
    ok = 1 ;
9554
 
9555
    fork
9556
    begin:wait_start
9557
        @(negedge FRAME) ;
9558
        disable count ;
9559
    end
9560
    begin:count
9561
        i = 0 ;
9562
        while ( i < 1000 )
9563
        begin
9564
            @(posedge pci_clock) ;
9565
            i = i + 1 ;
9566
        end
9567
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9568
        ok = 0 ;
9569
        disable wait_start ;
9570
    end
9571
    join
9572
 
9573
    @(posedge pci_clock) ;
9574
    while ( FRAME === 0 && ok )
9575
    begin
9576
        if ( DEVSEL !== 1 )
9577
        begin
9578
            ok = 0 ;
9579
        end
9580
        @(posedge pci_clock) ;
9581
    end
9582
 
9583
    while ( IRDY === 0 && ok )
9584
    begin
9585
        if ( DEVSEL !== 1 )
9586
        begin
9587
            ok = 0 ;
9588
        end
9589
        @(posedge pci_clock) ;
9590
    end
9591
    in_use = 0 ;
9592
end
9593
endtask
9594
 
9595
function [31:0] wb_to_pci_addr_convert ;
9596
    input [31:0] wb_address ;
9597
    input [31:0] translation_address ;
9598
    input [31:0] translate ;
9599
 
9600
    reg   [31:0] temp_address ;
9601
begin
9602
    if ( translate !== 1 )
9603
    begin
9604
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9605
    end
9606
    else
9607
    begin
9608
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9609
    end
9610
 
9611
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9612
    wb_to_pci_addr_convert = temp_address ;
9613
end
9614
endfunction //wb_to_pci_addr_convert
9615
 
9616 45 mihad
`ifdef HOST
9617 15 mihad
task find_pci_devices ;
9618
    integer device_num ;
9619
    reg     found ;
9620
    reg [11:0] pci_ctrl_offset ;
9621
    reg ok ;
9622
    reg [31:0] data ;
9623 45 mihad
    reg [31:0] expected_data ;
9624
 
9625
    reg [5:0]  reg_num ;
9626 15 mihad
begin:main
9627 45 mihad
 
9628
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9629 15 mihad
    pci_ctrl_offset = 12'h004 ;
9630
 
9631
    // enable master & target operation
9632
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9633
 
9634
    if ( ok !== 1 )
9635
    begin
9636
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9637 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9638 15 mihad
        disable main ;
9639
    end
9640
    // find all possible devices on pci bus by performing configuration cycles
9641 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9642 15 mihad
    begin
9643
        find_device ( device_num, found ) ;
9644
 
9645
        // check pci status register - if device is not present, Received Master Abort bit must be set
9646
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9647
 
9648
        if ( (data[29] !== 0) && (found !== 0) )
9649 45 mihad
        begin
9650 15 mihad
            $display( "Time %t ", $time ) ;
9651
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9652
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9653 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9654
            ok = 0 ;
9655 15 mihad
        end
9656
 
9657
        if ( (data[29] !== 1) && (found !== 1) )
9658
        begin
9659
            $display( "Time %t ", $time ) ;
9660
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9661
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9662 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9663
            ok = 0 ;
9664 15 mihad
        end
9665
 
9666
        // clear Master Abort status if set
9667
        if ( data[29] !== 0 )
9668
        begin
9669
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9670
        end
9671 45 mihad
 
9672
        if (found === 1)
9673
        begin
9674
            // first check if found target is supposed to exist
9675
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9676
            begin
9677
                $display("Time %t", $time) ;
9678
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9679
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9680
                ok = 0 ;
9681
            end
9682
            else
9683
            begin
9684
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9685
                begin
9686
 
9687
                    data = 32'hFFFF_FFFF ;
9688
 
9689
                    expected_data = 0 ;
9690
 
9691
                    if (reg_num == 4)
9692
                    begin
9693
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9694
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9695
                    end
9696
                    else if (reg_num == 5)
9697
                    begin
9698
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9699
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9700
                    end
9701
 
9702
                    // write base address 0
9703
                    generate_configuration_cycle
9704
                    (
9705
                        'h0,            //bus_num
9706
                        device_num,     //device_num
9707
                        'h0,            //func_num
9708
                        reg_num,        //reg_num
9709
                        'h0,            //type
9710
                        4'hF,           // byte_enables
9711
                        data,           //data
9712
                        1'b1            //read0_write1
9713
                    );
9714
 
9715
                    // read data back
9716
                    generate_configuration_cycle
9717
                    (
9718
                        'h0,            //bus_num
9719
                        device_num,     //device_num
9720
                        'h0,            //func_num
9721
                        reg_num,        //reg_num
9722
                        'h0,            //type
9723
                        4'hF,           // byte_enables
9724
                        data,           //data
9725
                        1'b0            //read0_write1
9726
                    );
9727
 
9728
                    if (data !== expected_data)
9729
                    begin
9730
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9731
                        $display("Data read back not as expected!");
9732
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9733
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9734
                        ok = 0 ;
9735
                    end
9736
                end
9737
            end
9738
        end
9739 15 mihad
    end
9740 45 mihad
 
9741
    if (ok)
9742
        test_ok ;
9743 15 mihad
end //main
9744
endtask //find_pci_devices
9745
 
9746
task find_device ;
9747
    input [31:0] device_num ;
9748
    output  found ;
9749
 
9750
    reg [31:0] read_data ;
9751
begin
9752
    found = 1'b0 ;
9753
 
9754
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9755 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9756 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9757
    else
9758
    begin
9759
        $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]) ;
9760
        found = 1'b1 ;
9761
    end
9762
end
9763
endtask //find_device
9764 45 mihad
`endif
9765 15 mihad
 
9766
/*task set_bridge_parameters ;
9767
    reg [11:0] current_offset ;
9768
    reg [2:0] result ;
9769
    reg [31:0] write_data ;
9770
begin
9771
    // set burst size
9772
    // set latency timer
9773
    current_offset = 12'h00C ;
9774
    // set burst size to 16 and latency timer to 8
9775
    write_data     = {24'h0000_08, system_burst_size} ;
9776
    config_write(current_offset, write_data, 4'b1111) ;
9777
 
9778
    // set io image
9779
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9780
    write_data = 32'h0000_000_3 ;
9781
    config_write(current_offset, write_data, 4'b1111) ;
9782
 
9783
 
9784
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9785
    write_data = 32'h0001_000_1 ;
9786
    config_write(current_offset, write_data, 4'b1111) ;
9787
 
9788
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9789
    write_data = 32'hFFFF_0000 ;
9790
    config_write(current_offset, write_data, 4'b1111) ;
9791
 
9792
    // set memory image
9793
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9794
    write_data = 32'h0000_000_7 ;
9795
    config_write(current_offset, write_data, 4'b1111) ;
9796
 
9797
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9798
    write_data = 32'h0002_000_0 ;
9799
    config_write(current_offset, write_data, 4'b1111) ;
9800
 
9801
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9802
    write_data = 32'h0001_0000 ;
9803
    config_write(current_offset, write_data, 4'b1111) ;
9804
 
9805
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9806
    write_data = 32'hFFFF_0000 ;
9807
    config_write(current_offset, write_data, 4'b1111) ;
9808
 
9809
    // set parameters for bridge's target unit
9810
    // image control 0
9811
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9812
    write_data     = 32'h0000_0002 ;
9813
    config_write(current_offset, write_data, 4'b0001) ;
9814
 
9815
    // base_address 0
9816
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9817
    write_data      = 32'h2000_0000 ;
9818
    config_write(current_offset, write_data, 4'b1111) ;
9819
 
9820
    // address mask 0
9821
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9822
    write_data     = 32'hFFFF_F000 ;
9823
    config_write(current_offset, write_data, 4'b1111) ;
9824
 
9825
    // command register - enable response to io and mem space and PCI master
9826
    current_offset = 12'h004 ;
9827
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9828
    config_write(current_offset, write_data, 4'b1111) ;
9829
end
9830
endtask // set_bridge_parameters
9831
*/
9832
 
9833
task configuration_cycle_write ;
9834
    input [7:0]  bus_num ;
9835
    input [4:0]  device_num ;
9836
    input [2:0]  func_num ;
9837
    input [5:0]  reg_num ;
9838
    input [1:0]  type ;
9839
    input [3:0]  byte_enables ;
9840
    input [31:0] data ;
9841
 
9842
    reg [31:0] write_address ;
9843
    reg in_use ;
9844
    reg ok ;
9845
begin:main
9846
 
9847
    if ( in_use === 1 )
9848
    begin
9849 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9850 15 mihad
        disable main ;
9851
    end
9852
 
9853 45 mihad
    if ( (device_num > 20) && (type === 0) )
9854 15 mihad
    begin
9855
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9856
        disable main ;
9857
    end
9858
 
9859
    in_use = 1 ;
9860
 
9861 45 mihad
 
9862
`ifdef HOST
9863
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9864
`else
9865
`ifdef GUEST
9866
 
9867 15 mihad
    if ( type )
9868
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9869
    else
9870
    begin
9871
        write_address = 0 ;
9872
        write_address[10:0] = { func_num, reg_num, type } ;
9873
        write_address[11 + device_num] = 1'b1 ;
9874
    end
9875 45 mihad
 
9876
    fork
9877 15 mihad
    begin
9878 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9879
                            write_address,
9880
                            data, ~byte_enables,
9881
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9882
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9883
        do_pause(1) ;
9884 15 mihad
    end
9885 45 mihad
    begin
9886
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9887
    end
9888
    join
9889
`endif
9890
`endif
9891
 
9892
    in_use = 0 ;
9893
end
9894
endtask // configuration_cycle_write
9895 15 mihad
 
9896 45 mihad
task configuration_cycle_read ;
9897
    input [7:0]  bus_num ;
9898
    input [4:0]  device_num ;
9899
    input [2:0]  func_num ;
9900
    input [5:0]  reg_num ;
9901
    input [1:0]  type ;
9902
    input [3:0]  byte_enables ;
9903
    output [31:0] data ;
9904 15 mihad
 
9905 45 mihad
    reg [31:0] read_address ;
9906
    reg in_use ;
9907 15 mihad
 
9908 45 mihad
    reg master_check_data_prev ;
9909
begin:main
9910 15 mihad
 
9911 45 mihad
    if ( in_use === 1 )
9912 15 mihad
    begin
9913 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9914
        data = 32'hxxxx_xxxx ;
9915
        disable main ;
9916 15 mihad
    end
9917
 
9918 45 mihad
    in_use = 1 ;
9919 15 mihad
 
9920 45 mihad
`ifdef HOST
9921
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9922
`else
9923
`ifdef GUEST
9924
     master_check_data_prev = master1_check_received_data ;
9925 15 mihad
     if ( type )
9926 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9927 15 mihad
     else
9928
     begin
9929 45 mihad
         read_address = 0 ;
9930
         read_address[10:0] = { func_num, reg_num, type } ;
9931
         read_address[11 + device_num] = 1'b1 ;
9932 15 mihad
     end
9933 45 mihad
 
9934
     fork
9935
     begin
9936
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9937
                 read_address,
9938 15 mihad
                 data, ~byte_enables,
9939
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9940
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9941 45 mihad
         do_pause(1) ;
9942
     end
9943
     begin
9944
         @(master1_received_data_valid) ;
9945
         data = master1_received_data ;
9946
     end
9947
     join
9948 15 mihad
 
9949 45 mihad
    master1_check_received_data = master_check_data_prev ;
9950
`endif
9951
`endif
9952
 
9953 15 mihad
    in_use = 0 ;
9954
 
9955 45 mihad
end //main
9956
endtask // configuration_cycle_read
9957
 
9958 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9959
task test_conf_cycle_type1_reference ;
9960
    reg [31:0] address ;
9961
    reg in_use ;
9962
 
9963
    reg master_check_data_prev ;
9964
    reg [31:0] data ;
9965
    reg monitor_ok ;
9966
    reg master_ok ;
9967
begin:main
9968
 
9969
    if ( in_use === 1 )
9970
    begin
9971
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9972
        disable main ;
9973
    end
9974
 
9975
    in_use = 1 ;
9976
 
9977
    master_check_data_prev = master1_check_received_data ;
9978
 
9979
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9980
    address = `TAR0_IDSEL_ADDR ;
9981
 
9982
    address[1:0] = 2'b01 ;
9983
 
9984
    `ifdef HOST
9985
        conf_cyc_type1_target_bus_num = 255 ;
9986
    `endif
9987
    master_ok = 1 ;
9988
    fork
9989
    begin
9990
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9991
        do_pause(1) ;
9992
    end
9993
    begin:error_monitor1
9994
        @(error_event_int) ;
9995
        master_ok = 0 ;
9996
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9997
    end
9998
    begin
9999
        pci_transaction_progress_monitor
10000
        (
10001
            address,                                                // expected address on PCI bus
10002
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10003
            0,                                                      // expected number of succesfull data phases
10004
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10005
            1'b1,                                                   // monitor checking/not checking number of transfers
10006
            1'b0,                                                   // monitor checking/not checking number of cycles
10007
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10008
            monitor_ok                                              // status - 1 success, 0 failure
10009
        ) ;
10010
 
10011
        @(posedge pci_clock);
10012
        #1 ;
10013
 
10014
        if (master_ok)
10015
            disable error_monitor1 ;
10016
 
10017
        if (!monitor_ok)
10018
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10019
    end
10020
    join
10021
 
10022
    if (monitor_ok && master_ok)
10023
        test_ok ;
10024
 
10025
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
10026
    master_ok = 1 ;
10027
    fork
10028
    begin
10029
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
10030
        do_pause(1) ;
10031
    end
10032
    begin:error_monitor2
10033
        @(error_event_int) ;
10034
        master_ok = 0 ;
10035
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
10036
    end
10037
    begin
10038
        pci_transaction_progress_monitor
10039
        (
10040
            address,                                                // expected address on PCI bus
10041
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10042
            0,                                                      // expected number of succesfull data phases
10043
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10044
            1'b1,                                                   // monitor checking/not checking number of transfers
10045
            1'b0,                                                   // monitor checking/not checking number of cycles
10046
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10047
            monitor_ok                                              // status - 1 success, 0 failure
10048
        ) ;
10049
 
10050
        @(posedge pci_clock);
10051
        #1 ;
10052
 
10053
        if (master_ok)
10054
            disable error_monitor2 ;
10055
 
10056
        if (!monitor_ok)
10057
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10058
    end
10059
    join
10060
 
10061
    master1_check_received_data = master_check_data_prev ;
10062
 
10063
    if (monitor_ok && master_ok)
10064
        test_ok ;
10065
 
10066
    in_use = 0 ;
10067
 
10068
end //main
10069
endtask // test_conf_cycle_type1_reference
10070
`endif
10071
 
10072 45 mihad
`ifdef HOST
10073
task generate_configuration_cycle ;
10074 15 mihad
    input [7:0]  bus_num ;
10075
    input [4:0]  device_num ;
10076
    input [2:0]  func_num ;
10077
    input [5:0]  reg_num ;
10078
    input [1:0]  type ;
10079
    input [3:0]  byte_enables ;
10080 45 mihad
    inout [31:0] data ;
10081
    input        read0_write1 ;
10082 15 mihad
 
10083
    reg `READ_STIM_TYPE read_data ;
10084
    reg `WB_TRANSFER_FLAGS  flags ;
10085
    reg `READ_RETURN_TYPE   read_status ;
10086
 
10087
    reg `WRITE_STIM_TYPE   write_data ;
10088
    reg `WRITE_RETURN_TYPE write_status ;
10089
 
10090 45 mihad
    reg [31:0] pci_address ;
10091 15 mihad
    reg in_use ;
10092 45 mihad
    reg ok ;
10093 15 mihad
 
10094
    reg [31:0] temp_var ;
10095
begin:main
10096
 
10097
    if ( in_use === 1 )
10098
    begin
10099 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
10100 15 mihad
        data = 32'hxxxx_xxxx ;
10101
        disable main ;
10102
    end
10103
 
10104 45 mihad
    in_use = 1 ;
10105
 
10106
    if ( type )
10107
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10108
    else
10109 15 mihad
    begin
10110 45 mihad
        pci_address = 0 ;
10111
        pci_address[10:0] = { func_num, reg_num, type } ;
10112
        if (device_num <= 20)
10113
            pci_address[11 + device_num] = 1'b1 ;
10114
    end
10115
 
10116
    // setup flags
10117
    flags = 0 ;
10118
    flags`INIT_WAITS   = tb_init_waits ;
10119
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10120
 
10121
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10122
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10123
 
10124
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10125
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10126
    write_data`WRITE_SEL      = 4'hF ;
10127
    write_data`WRITE_TAG_STIM = 0 ;
10128
 
10129
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10130
 
10131
    // check if write succeeded
10132
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10133
    begin
10134
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10135 15 mihad
        data = 32'hxxxx_xxxx ;
10136 45 mihad
        in_use = 0 ;
10137 15 mihad
        disable main ;
10138
    end
10139
 
10140 45 mihad
    // setup flags for wb master to handle retries and read and write data
10141
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10142
 
10143
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10144
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10145
    read_data`READ_SEL          = byte_enables ;
10146
    write_data`WRITE_SEL        = byte_enables ;
10147
    read_data`READ_TAG_STIM     = 0 ;
10148
    write_data`WRITE_TAG_STIM   = 0 ;
10149
    write_data`WRITE_DATA       = data ;
10150
 
10151
    ok = 0 ;
10152
 
10153
    fork
10154
    begin
10155
        if (read0_write1 === 0)
10156
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
10157
        else
10158
        if (read0_write1 === 1)
10159
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
10160
    end
10161
    begin
10162
        pci_transaction_progress_monitor
10163
        (
10164
            pci_address,                                            // expected address on PCI bus
10165
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10166
            1,                                                      // expected number of succesfull data phases
10167
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10168
            1'b0,                                                   // monitor checking/not checking number of transfers
10169
            1'b0,                                                   // monitor checking/not checking number of cycles
10170
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10171
            ok                                                      // status - 1 success, 0 failure
10172
        ) ;
10173
    end
10174
    join
10175
 
10176
    // check if transfer succeeded
10177
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10178
    begin
10179
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10180
        data = 32'hxxxx_xxxx ;
10181
        in_use = 0 ;
10182
        disable main ;
10183
    end
10184
 
10185
    if (!ok)
10186
    begin
10187
        data = 32'hxxxx_xxxx ;
10188
        in_use = 0 ;
10189
        disable main ;
10190
    end
10191
 
10192
    if (read0_write1 === 0)
10193
        data = read_status`READ_DATA ;
10194
 
10195
    in_use = 0 ;
10196
end
10197
endtask // generate_configuration_cycle
10198
 
10199
task test_configuration_cycle_target_abort ;
10200
    reg `READ_STIM_TYPE read_data ;
10201
    reg `WB_TRANSFER_FLAGS  flags ;
10202
    reg `READ_RETURN_TYPE   read_status ;
10203
 
10204
    reg `WRITE_STIM_TYPE   write_data ;
10205
    reg `WRITE_RETURN_TYPE write_status ;
10206
 
10207
    reg [31:0] pci_address ;
10208
    reg in_use ;
10209
    reg ok_pci ;
10210
    reg ok_wb  ;
10211
    reg ok     ;
10212
 
10213
    reg [31:0] temp_var ;
10214
 
10215
begin:main
10216
 
10217
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10218
 
10219
    if ( in_use === 1 )
10220
    begin
10221
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10222
        disable main ;
10223
    end
10224
 
10225 15 mihad
    in_use = 1 ;
10226
 
10227 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10228
 
10229 15 mihad
    // setup flags
10230
    flags = 0 ;
10231 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10232
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10233 15 mihad
 
10234
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10235
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10236
 
10237
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10238 45 mihad
    temp_var                  = 0 ;
10239
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10240
    write_data`WRITE_DATA     = temp_var ;
10241 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10242
    write_data`WRITE_TAG_STIM = 0 ;
10243
 
10244
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10245
 
10246
    // check if write succeeded
10247
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10248
    begin
10249
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10250 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10251
        in_use = 0 ;
10252 15 mihad
        disable main ;
10253
    end
10254
 
10255 45 mihad
    // setup flags for wb master to handle retries and read and write data
10256 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10257
 
10258 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10259
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10260 15 mihad
 
10261 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10262
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10263
    read_data`READ_SEL          = 4'hF ;
10264
    write_data`WRITE_SEL        = 4'hF ;
10265
    read_data`READ_TAG_STIM     = 0 ;
10266
    write_data`WRITE_TAG_STIM   = 0 ;
10267
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10268
 
10269
    ok_pci = 0 ;
10270
    ok_wb  = 1 ;
10271
 
10272
    // set target to terminate with target abort
10273
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10274
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10275
    fork
10276
    begin
10277
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10278
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10279
        begin
10280
            $display("Time %t", $time) ;
10281
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10282
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10283
            ok_wb = 0 ;
10284
        end
10285
 
10286
        config_read( 12'h4, 4'hF, temp_var ) ;
10287
        if ( temp_var[29] !== 0 )
10288
        begin
10289
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10290
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10291
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10292
            ok_wb = 0 ;
10293
        end
10294
 
10295
        if ( temp_var[28] !== 1 )
10296
        begin
10297
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10298
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10299
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10300
            ok_wb = 0 ;
10301
        end
10302
 
10303
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10304
 
10305
        if (ok !== 1)
10306
        begin
10307
            ok_wb = 0 ;
10308
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10309
            $display("Write to PCI Device Status Register failed") ;
10310
            test_fail("Write to PCI Device Status Register failed") ;
10311
        end
10312
 
10313
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10314
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10315
        begin
10316
            $display("Time %t", $time) ;
10317
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10318
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10319
            ok_wb = 0 ;
10320
        end
10321
 
10322
        config_read( 12'h4, 4'hF, temp_var ) ;
10323
        if ( temp_var[29] !== 0 )
10324
        begin
10325
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10326
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10327
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10328
            ok_wb = 0 ;
10329
        end
10330
 
10331
        if ( temp_var[28] !== 1 )
10332
        begin
10333
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10334
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10335
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10336
            ok_wb = 0 ;
10337
        end
10338
 
10339
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10340
 
10341
        if (ok !== 1)
10342
        begin
10343
            ok_wb = 0 ;
10344
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10345
            $display("Write to PCI Device Status Register failed") ;
10346
            test_fail("Write to PCI Device Status Register failed") ;
10347
        end
10348
    end
10349
    begin
10350
        pci_transaction_progress_monitor
10351
        (
10352
            pci_address,                                            // expected address on PCI bus
10353
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10354
            0,                                                      // expected number of succesfull data phases
10355
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10356
            1'b1,                                                   // monitor checking/not checking number of transfers
10357
            1'b0,                                                   // monitor checking/not checking number of cycles
10358
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10359
            ok_pci                                                  // status - 1 success, 0 failure
10360
        ) ;
10361
 
10362
        if (ok_pci)
10363
        begin
10364
            pci_transaction_progress_monitor
10365
            (
10366
                pci_address,                                            // expected address on PCI bus
10367
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10368
                0,                                                      // expected number of succesfull data phases
10369
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10370
                1'b1,                                                   // monitor checking/not checking number of transfers
10371
                1'b0,                                                   // monitor checking/not checking number of cycles
10372
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10373
                ok_pci                                                  // status - 1 success, 0 failure
10374
            ) ;
10375
        end
10376
 
10377
        if (!ok_pci)
10378
        begin
10379
            $display("Time %t", $time) ;
10380
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10381
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10382
        end
10383
    end
10384
    join
10385
 
10386
    if (ok_pci && ok_wb)
10387
    begin
10388
        test_ok ;
10389
    end
10390
 
10391
    in_use = 0 ;
10392
 
10393
    // set target to terminate normally
10394
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10395
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10396
end
10397
endtask // test_configuration_cycle_target_abort
10398
 
10399
task test_configuration_cycle_type1_generation ;
10400
    reg `READ_STIM_TYPE read_data ;
10401
    reg `WB_TRANSFER_FLAGS  flags ;
10402
    reg `READ_RETURN_TYPE   read_status ;
10403
 
10404
    reg `WRITE_STIM_TYPE   write_data ;
10405
    reg `WRITE_RETURN_TYPE write_status ;
10406
 
10407
    reg [31:0] pci_address ;
10408
    reg in_use ;
10409
    reg ok_pci ;
10410
    reg ok_wb  ;
10411
    reg ok     ;
10412
 
10413
    reg [31:0] temp_var ;
10414
 
10415
begin:main
10416
 
10417
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10418
    conf_cyc_type1_target_data = 0 ;
10419
    conf_cyc_type1_target_bus_num = 0;
10420
 
10421
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10422
 
10423
    if ( in_use === 1 )
10424
    begin
10425
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10426
        disable main ;
10427
    end
10428
 
10429
    in_use = 1 ;
10430
 
10431
    pci_address        = 32'hAAAA_AAAA ;
10432
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10433
 
10434
    // setup flags
10435
    flags = 0 ;
10436
    flags`INIT_WAITS   = tb_init_waits ;
10437
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10438
 
10439
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10440
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10441
 
10442
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10443
    write_data`WRITE_DATA     = pci_address ;
10444
    write_data`WRITE_SEL      = 4'hF ;
10445
    write_data`WRITE_TAG_STIM = 0 ;
10446
 
10447
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10448
 
10449
    // check if write succeeded
10450
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10451
    begin
10452
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10453
        test_fail("write to configuration cycle address register was not possible") ;
10454
        in_use = 0 ;
10455
        disable main ;
10456
    end
10457
 
10458
    // setup flags for wb master to handle retries and read and write data
10459
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10460
 
10461
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10462
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10463
 
10464
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10465
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10466
    read_data`READ_SEL          = 4'hF ;
10467
    write_data`WRITE_SEL        = 4'hF ;
10468
    read_data`READ_TAG_STIM     = 0 ;
10469
    write_data`WRITE_TAG_STIM   = 0 ;
10470
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10471
 
10472
    ok_pci = 0 ;
10473
    ok_wb  = 1 ;
10474
 
10475
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10476
    pci_address[31:24] = 0 ;
10477
    fork
10478
    begin
10479
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10480
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10481
        begin
10482
            $display("Time %t", $time) ;
10483
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10484
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10485
            ok_wb = 0 ;
10486
        end
10487
 
10488
        config_read( 12'h4, 4'hF, temp_var ) ;
10489
        if ( temp_var[29] !== 1 )
10490
        begin
10491
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10492
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10493
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10494
            ok_wb = 0 ;
10495
        end
10496
 
10497
        if ( temp_var[28] !== 0 )
10498
        begin
10499
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10500
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10501
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10502
            ok_wb = 0 ;
10503
        end
10504
 
10505
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10506
 
10507
        if (ok !== 1)
10508
        begin
10509
            ok_wb = 0 ;
10510
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10511
            $display("Write to PCI Device Status Register failed") ;
10512
            test_fail("Write to PCI Device Status Register failed") ;
10513
        end
10514
 
10515
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10516
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10517
        begin
10518
            $display("Time %t", $time) ;
10519
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10520
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10521
            ok_wb = 0 ;
10522
        end
10523
 
10524
        config_read( 12'h4, 4'hF, temp_var ) ;
10525
        if ( temp_var[29] !== 1 )
10526
        begin
10527
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10528
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10529
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10530
            ok_wb = 0 ;
10531
        end
10532
 
10533
        if ( temp_var[28] !== 0 )
10534
        begin
10535
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10536
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10537
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10538
            ok_wb = 0 ;
10539
        end
10540
 
10541
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10542
 
10543
        if (ok !== 1)
10544
        begin
10545
            ok_wb = 0 ;
10546
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10547
            $display("Write to PCI Device Status Register failed") ;
10548
            test_fail("Write to PCI Device Status Register failed") ;
10549
        end
10550
    end
10551
    begin
10552
        pci_transaction_progress_monitor
10553
        (
10554
            pci_address,                                            // expected address on PCI bus
10555
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10556
            0,                                                      // expected number of succesfull data phases
10557
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10558
            1'b1,                                                   // monitor checking/not checking number of transfers
10559
            1'b0,                                                   // monitor checking/not checking number of cycles
10560
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10561
            ok_pci                                                  // status - 1 success, 0 failure
10562
        ) ;
10563
 
10564
        if (ok_pci)
10565
        begin
10566
            pci_transaction_progress_monitor
10567
            (
10568
                pci_address,                                            // expected address on PCI bus
10569
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10570
                0,                                                      // expected number of succesfull data phases
10571
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10572
                1'b1,                                                   // monitor checking/not checking number of transfers
10573
                1'b0,                                                   // monitor checking/not checking number of cycles
10574
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10575
                ok_pci                                                  // status - 1 success, 0 failure
10576
            ) ;
10577
        end
10578
 
10579
        if (!ok_pci)
10580
        begin
10581
            $display("Time %t", $time) ;
10582
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10583
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10584
        end
10585
    end
10586
    join
10587
 
10588
    if (ok_pci && ok_wb)
10589
    begin
10590
        test_ok ;
10591
    end
10592
 
10593
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10594
    conf_cyc_type1_target_data = 0 ;
10595
    conf_cyc_type1_target_bus_num = 8'h55;
10596
 
10597
    pci_address      = 32'h5555_5555 ;
10598
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10599
 
10600
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10601
 
10602
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10603
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10604
 
10605
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10606
    write_data`WRITE_DATA     = pci_address ;
10607
    write_data`WRITE_SEL      = 4'hF ;
10608
    write_data`WRITE_TAG_STIM = 0 ;
10609
 
10610
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10611
 
10612
    // check if write succeeded
10613
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10614
    begin
10615
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10616
        test_fail("write to configuration cycle address register was not possible") ;
10617
        in_use = 0 ;
10618
        disable main ;
10619
    end
10620
 
10621
    // setup flags for wb master to handle retries and read and write data
10622
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10623
 
10624
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10625
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10626
 
10627
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10628
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10629
    read_data`READ_SEL          = 4'hF ;
10630
    write_data`WRITE_SEL        = 4'hF ;
10631
    read_data`READ_TAG_STIM     = 0 ;
10632
    write_data`WRITE_TAG_STIM   = 0 ;
10633
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10634
 
10635
    ok_pci = 0 ;
10636
    ok_wb  = 1 ;
10637
 
10638
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10639
    pci_address[31:24] = 0 ;
10640
    fork
10641
    begin
10642
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10643
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10644
        begin
10645
            $display("Time %t", $time) ;
10646
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10647
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10648
            ok_wb = 0 ;
10649
        end
10650
 
10651
        config_read( 12'h4, 4'hF, temp_var ) ;
10652
        if ( temp_var[29] !== 0 )
10653
        begin
10654
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10655
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10656
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10657
            ok_wb = 0 ;
10658
        end
10659
 
10660
        if ( temp_var[28] !== 1 )
10661
        begin
10662
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10663
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10664
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10665
            ok_wb = 0 ;
10666
        end
10667
 
10668
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10669
 
10670
        if (ok !== 1)
10671
        begin
10672
            ok_wb = 0 ;
10673
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10674
            $display("Write to PCI Device Status Register failed") ;
10675
            test_fail("Write to PCI Device Status Register failed") ;
10676
        end
10677
 
10678
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10679
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10680
        begin
10681
            $display("Time %t", $time) ;
10682
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10683
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10684
            ok_wb = 0 ;
10685
        end
10686
 
10687
        config_read( 12'h4, 4'hF, temp_var ) ;
10688
        if ( temp_var[29] !== 0 )
10689
        begin
10690
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10691
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10692
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10693
            ok_wb = 0 ;
10694
        end
10695
 
10696
        if ( temp_var[28] !== 1 )
10697
        begin
10698
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10699
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10700
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10701
            ok_wb = 0 ;
10702
        end
10703
 
10704
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10705
 
10706
        if (ok !== 1)
10707
        begin
10708
            ok_wb = 0 ;
10709
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10710
            $display("Write to PCI Device Status Register failed") ;
10711
            test_fail("Write to PCI Device Status Register failed") ;
10712
        end
10713
    end
10714
    begin
10715
        pci_transaction_progress_monitor
10716
        (
10717
            pci_address,                                            // expected address on PCI bus
10718
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10719
            0,                                                      // expected number of succesfull data phases
10720
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10721
            1'b1,                                                   // monitor checking/not checking number of transfers
10722
            1'b0,                                                   // monitor checking/not checking number of cycles
10723
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10724
            ok_pci                                                  // status - 1 success, 0 failure
10725
        ) ;
10726
 
10727
        if (ok_pci)
10728
        begin
10729
            pci_transaction_progress_monitor
10730
            (
10731
                pci_address,                                            // expected address on PCI bus
10732
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10733
                0,                                                      // expected number of succesfull data phases
10734
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10735
                1'b1,                                                   // monitor checking/not checking number of transfers
10736
                1'b0,                                                   // monitor checking/not checking number of cycles
10737
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10738
                ok_pci                                                  // status - 1 success, 0 failure
10739
            ) ;
10740
        end
10741
 
10742
        if (!ok_pci)
10743
        begin
10744
            $display("Time %t", $time) ;
10745
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10746
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10747
        end
10748
    end
10749
    join
10750
 
10751
    if (ok_pci && ok_wb)
10752
    begin
10753
        test_ok ;
10754
    end
10755
 
10756
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10757
 
10758
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10759
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10760
    conf_cyc_type1_target_bus_num = 8'hAA;
10761
 
10762
    pci_address      = 32'hAAAA_AAAA ;
10763
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10764
 
10765
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10766
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10767
 
10768
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10769
    write_data`WRITE_DATA     = pci_address ;
10770
    write_data`WRITE_SEL      = 4'hF ;
10771
    write_data`WRITE_TAG_STIM = 0 ;
10772
 
10773
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10774
 
10775
    // check if write succeeded
10776
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10777
    begin
10778
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10779
        test_fail("write to configuration cycle address register was not possible") ;
10780
        in_use = 0 ;
10781
        disable main ;
10782
    end
10783
 
10784
    // setup flags for wb master to handle retries and read and write data
10785
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10786
 
10787
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10788
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10789
 
10790
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10791
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10792
    read_data`READ_SEL          = 4'b0101 ;
10793
    write_data`WRITE_SEL        = 4'b1010 ;
10794
    read_data`READ_TAG_STIM     = 0 ;
10795
    write_data`WRITE_TAG_STIM   = 0 ;
10796
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10797
 
10798
    ok_pci = 0 ;
10799
    ok_wb  = 1 ;
10800
 
10801
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10802
    pci_address[31:24] = 0 ;
10803
 
10804
    fork
10805
    begin
10806
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10807
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10808
        begin
10809
            $display("Time %t", $time) ;
10810
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10811
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10812
            ok_wb = 0 ;
10813
        end
10814
 
10815
        config_read( 12'h4, 4'hF, temp_var ) ;
10816
        if ( temp_var[29] !== 0 )
10817
        begin
10818
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10819
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10820
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10821
            ok_wb = 0 ;
10822
        end
10823
 
10824
        if ( temp_var[28] !== 0 )
10825
        begin
10826
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10827
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10828
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10829
            ok_wb = 0 ;
10830
        end
10831
 
10832
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10833
 
10834
        if (ok !== 1)
10835
        begin
10836
            ok_wb = 0 ;
10837
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10838
            $display("Write to PCI Device Status Register failed") ;
10839
            test_fail("Write to PCI Device Status Register failed") ;
10840
        end
10841
 
10842
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10843
        begin
10844
            ok_wb = 0 ;
10845
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10846
            $display("Read Data provided by the bridge was not as expected!") ;
10847
            test_fail("Read Data provided by the bridge was not as expected") ;
10848
        end
10849
 
10850
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10851
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10852
        begin
10853
            $display("Time %t", $time) ;
10854
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10855
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10856
            ok_wb = 0 ;
10857
        end
10858
 
10859
        config_read( 12'h4, 4'hF, temp_var ) ;
10860
        if ( temp_var[29] !== 0 )
10861
        begin
10862
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10863
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10864
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10865
            ok_wb = 0 ;
10866
        end
10867
 
10868
        if ( temp_var[28] !== 0 )
10869
        begin
10870
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10871
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10872
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10873
            ok_wb = 0 ;
10874
        end
10875
 
10876
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10877
 
10878
        if (ok !== 1)
10879
        begin
10880
            ok_wb = 0 ;
10881
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10882
            $display("Write to PCI Device Status Register failed") ;
10883
            test_fail("Write to PCI Device Status Register failed") ;
10884
        end
10885
 
10886
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10887
        begin
10888
            ok_wb = 0 ;
10889
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10890
            $display("Data written by the bridge was not as expected!") ;
10891
            test_fail("Data written by the bridge was not as expected") ;
10892
        end
10893
 
10894
    end
10895
    begin
10896
        ok = 1 ;
10897
        repeat(8)
10898
        begin
10899
            pci_transaction_progress_monitor
10900
            (
10901
                pci_address,                                            // expected address on PCI bus
10902
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10903
                0,                                                      // expected number of succesfull data phases
10904
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10905
                1'b1,                                                   // monitor checking/not checking number of transfers
10906
                1'b0,                                                   // monitor checking/not checking number of cycles
10907
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10908
                ok_pci                                                  // status - 1 success, 0 failure
10909
            ) ;
10910
 
10911
            if (!ok_pci)
10912
            begin
10913
                ok = 0 ;
10914
                $display("Time %t", $time) ;
10915
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10916
            end
10917
        end
10918
 
10919
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10920
 
10921
        pci_transaction_progress_monitor
10922
        (
10923
            pci_address,                                            // expected address on PCI bus
10924
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10925
            1,                                                      // expected number of succesfull data phases
10926
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10927
            1'b1,                                                   // monitor checking/not checking number of transfers
10928
            1'b0,                                                   // monitor checking/not checking number of cycles
10929
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10930
            ok_pci                                                  // status - 1 success, 0 failure
10931
        ) ;
10932
 
10933
        if (!ok_pci)
10934
        begin
10935
            ok = 0 ;
10936
            $display("Time %t", $time) ;
10937
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10938
        end
10939
 
10940
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10941
        repeat(8)
10942
        begin
10943
            pci_transaction_progress_monitor
10944
            (
10945
                pci_address,                                            // expected address on PCI bus
10946
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10947
                0,                                                      // expected number of succesfull data phases
10948
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10949
                1'b1,                                                   // monitor checking/not checking number of transfers
10950
                1'b0,                                                   // monitor checking/not checking number of cycles
10951
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10952
                ok_pci                                                  // status - 1 success, 0 failure
10953
            ) ;
10954
 
10955
            if (!ok_pci)
10956
            begin
10957
                ok = 0 ;
10958
                $display("Time %t", $time) ;
10959
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10960
            end
10961
        end
10962
 
10963
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10964
        pci_transaction_progress_monitor
10965
        (
10966
            pci_address,                                            // expected address on PCI bus
10967
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10968
            1,                                                      // expected number of succesfull data phases
10969
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10970
            1'b1,                                                   // monitor checking/not checking number of transfers
10971
            1'b0,                                                   // monitor checking/not checking number of cycles
10972
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10973
            ok_pci                                                  // status - 1 success, 0 failure
10974
        ) ;
10975
 
10976
        if (!ok_pci)
10977
        begin
10978
            ok = 0 ;
10979
            $display("Time %t", $time) ;
10980
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10981
        end
10982
 
10983
        if (!ok)
10984
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10985
    end
10986
    join
10987
 
10988
    if (ok_pci && ok_wb)
10989
    begin
10990
        test_ok ;
10991
    end
10992
 
10993
    in_use = 0 ;
10994
end
10995
endtask // test_configuration_cycle_type1_generation
10996
`endif
10997
 
10998
task test_initial_conf_values ;
10999
    reg [11:0] register_offset ;
11000
    reg [31:0] expected_value ;
11001
    reg        failed ;
11002
`ifdef HOST
11003
    reg `READ_STIM_TYPE    read_data ;
11004
    reg `WB_TRANSFER_FLAGS flags ;
11005
    reg `READ_RETURN_TYPE  read_status ;
11006
 
11007
    reg `WRITE_STIM_TYPE   write_data ;
11008
    reg `WRITE_RETURN_TYPE write_status ;
11009
begin
11010
    failed     = 0 ;
11011
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11012
    flags      = 0 ;
11013
    read_data  = 0 ;
11014
    write_data = 0 ;
11015
 
11016
    read_data`READ_SEL = 4'hF ;
11017
 
11018
    flags`INIT_WAITS           = tb_init_waits ;
11019
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
11020
 
11021
    // test MEM/IO map bit initial value in each PCI BAR
11022
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
11023
 
11024
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11025
 
11026 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11027
 
11028 45 mihad
    `ifdef NO_CNF_IMAGE
11029
        `ifdef PCI_IMAGE0
11030
            if (`PCI_AM0)
11031
                expected_value = `PCI_BA0_MEM_IO ;
11032
            else
11033
                expected_value = 32'h0000_0000 ;
11034
        `else
11035
            expected_value = 32'h0000_0000 ;
11036
        `endif
11037
    `else
11038
        expected_value = 32'h0000_0000 ;
11039
    `endif
11040
 
11041 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11042
    begin
11043 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
11044
        failed = 1 ;
11045 15 mihad
    end
11046 45 mihad
    else
11047
    begin
11048
        if (read_status`READ_DATA !== expected_value)
11049
        begin
11050
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
11051
            failed = 1 ;
11052
        end
11053
    end
11054 15 mihad
 
11055 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
11056 15 mihad
 
11057 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11058
 
11059
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11060
 
11061
    if (`PCI_AM1)
11062
        expected_value = `PCI_BA1_MEM_IO ;
11063
    else
11064
        expected_value = 32'h0000_0000 ;
11065
 
11066
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11067
    begin
11068
        test_fail("read from P_BA1 register didn't succeede") ;
11069
        failed = 1 ;
11070
    end
11071
    else
11072
    begin
11073
        if (read_status`READ_DATA !== expected_value)
11074
        begin
11075
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
11076
            failed = 1 ;
11077
        end
11078
    end
11079
 
11080
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
11081
 
11082
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11083
 
11084
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11085
 
11086
    `ifdef PCI_IMAGE2
11087
        if (`PCI_AM2)
11088
            expected_value = `PCI_BA2_MEM_IO ;
11089
        else
11090
            expected_value = 32'h0000_0000 ;
11091 15 mihad
    `else
11092 45 mihad
        expected_value = 32'h0000_0000 ;
11093
    `endif
11094 15 mihad
 
11095 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11096
    begin
11097
        test_fail("read from P_BA2 register didn't succeede") ;
11098
        failed = 1 ;
11099
    end
11100
    else
11101
    begin
11102
        if (read_status`READ_DATA !== expected_value)
11103
        begin
11104
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
11105
            failed = 1 ;
11106
        end
11107
    end
11108 15 mihad
 
11109 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
11110
 
11111
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11112
 
11113
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11114
 
11115
    `ifdef PCI_IMAGE3
11116
        if (`PCI_AM3)
11117
            expected_value = `PCI_BA3_MEM_IO ;
11118
        else
11119
            expected_value = 32'h0000_0000 ;
11120
    `else
11121
        expected_value = 32'h0000_0000 ;
11122 15 mihad
    `endif
11123 45 mihad
 
11124
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11125
    begin
11126
        test_fail("read from P_BA3 register didn't succeede") ;
11127
        failed = 1 ;
11128
    end
11129
    else
11130
    begin
11131
        if (read_status`READ_DATA !== expected_value)
11132
        begin
11133
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
11134
            failed = 1 ;
11135
        end
11136
    end
11137
 
11138
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
11139
 
11140
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11141
 
11142
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11143
 
11144
    `ifdef PCI_IMAGE4
11145
        if (`PCI_AM4)
11146
            expected_value = `PCI_BA4_MEM_IO ;
11147
        else
11148
            expected_value = 32'h0000_0000 ;
11149
    `else
11150
        expected_value = 32'h0000_0000 ;
11151 15 mihad
    `endif
11152
 
11153 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11154
    begin
11155
        test_fail("read from P_BA4 register didn't succeede") ;
11156
        failed = 1 ;
11157
    end
11158
    else
11159
    begin
11160
        if (read_status`READ_DATA !== expected_value)
11161
        begin
11162
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11163
            failed = 1 ;
11164
        end
11165
    end
11166 15 mihad
 
11167 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11168 15 mihad
 
11169 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11170
 
11171
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11172
 
11173
    `ifdef PCI_IMAGE5
11174
        if(`PCI_AM5)
11175
            expected_value = `PCI_BA5_MEM_IO ;
11176
        else
11177
            expected_value = 32'h0000_0000 ;
11178
    `else
11179
        expected_value = 32'h0000_0000 ;
11180
    `endif
11181
 
11182
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11183
    begin
11184
        test_fail("read from P_BA5 register didn't succeede") ;
11185
        failed = 1 ;
11186
    end
11187
    else
11188
    begin
11189
        if (read_status`READ_DATA !== expected_value)
11190
        begin
11191
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11192
            failed = 1 ;
11193
        end
11194
    end
11195
 
11196
    // test Address Mask initial values
11197
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11198
 
11199
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11200
 
11201
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11202
 
11203
    `ifdef NO_CNF_IMAGE
11204
        `ifdef PCI_IMAGE0
11205
            expected_value = {`PCI_AM0, 12'h000};
11206
 
11207
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11208
        `else
11209
            expected_value = 32'h0000_0000 ;
11210
        `endif
11211
    `else
11212
        expected_value = 32'hFFFF_FFFF ;
11213
 
11214
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11215
    `endif
11216
 
11217
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11218
    begin
11219
        test_fail("read from P_AM0 register didn't succeede") ;
11220
        failed = 1 ;
11221
    end
11222
    else
11223
    begin
11224
        if (read_status`READ_DATA !== expected_value)
11225
        begin
11226
            test_fail("AM0 initial value was not set as defined");
11227
            failed = 1 ;
11228
        end
11229
    end
11230
 
11231
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11232
 
11233
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11234
 
11235
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11236
 
11237
    expected_value = {`PCI_AM1, 12'h000};
11238
 
11239
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11240
 
11241
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11242
    begin
11243
        test_fail("read from P_AM1 register didn't succeede") ;
11244
        failed = 1 ;
11245
    end
11246
    else
11247
    begin
11248
        if (read_status`READ_DATA !== expected_value)
11249
        begin
11250
            test_fail("AM1 initial value was not set as defined");
11251
            failed = 1 ;
11252
        end
11253
    end
11254
 
11255
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11256
 
11257
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11258
 
11259
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11260
 
11261
    `ifdef PCI_IMAGE2
11262
        expected_value = {`PCI_AM2, 12'h000};
11263
 
11264
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11265
    `else
11266
        expected_value = 32'h0000_0000 ;
11267
    `endif
11268
 
11269
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11270
    begin
11271
        test_fail("read from P_AM2 register didn't succeede") ;
11272
        failed = 1 ;
11273
    end
11274
    else
11275
    begin
11276
        if (read_status`READ_DATA !== expected_value)
11277
        begin
11278
            test_fail("AM2 initial value was not set as defined");
11279
            failed = 1 ;
11280
        end
11281
    end
11282
 
11283
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11284
 
11285
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11286
 
11287
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11288
 
11289
    `ifdef PCI_IMAGE3
11290
        expected_value = {`PCI_AM3, 12'h000};
11291
 
11292
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11293
    `else
11294
        expected_value = 32'h0000_0000 ;
11295
    `endif
11296
 
11297
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11298
    begin
11299
        test_fail("read from P_AM3 register didn't succeede") ;
11300
        failed = 1 ;
11301
    end
11302
    else
11303
    begin
11304
        if (read_status`READ_DATA !== expected_value)
11305
        begin
11306
            test_fail("AM3 initial value was not set as defined");
11307
            failed = 1 ;
11308
        end
11309
    end
11310
 
11311
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11312
 
11313
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11314
 
11315
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11316
 
11317
    `ifdef PCI_IMAGE4
11318
        expected_value = {`PCI_AM4, 12'h000};
11319
 
11320
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11321
    `else
11322
        expected_value = 32'h0000_0000 ;
11323
    `endif
11324
 
11325
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11326
    begin
11327
        test_fail("read from P_AM4 register didn't succeede") ;
11328
        failed = 1 ;
11329
    end
11330
    else
11331
    begin
11332
        if (read_status`READ_DATA !== expected_value)
11333
        begin
11334
            test_fail("AM4 initial value was not set as defined");
11335
            failed = 1 ;
11336
        end
11337
    end
11338
 
11339
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11340
 
11341
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11342
 
11343
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11344
 
11345
    `ifdef PCI_IMAGE5
11346
        expected_value = {`PCI_AM5, 12'h000};
11347
 
11348
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11349
    `else
11350
        expected_value = 32'h0000_0000 ;
11351
    `endif
11352
 
11353
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11354
    begin
11355
        test_fail("read from P_AM5 register didn't succeede") ;
11356
        failed = 1 ;
11357
    end
11358
    else
11359
    begin
11360
        if (read_status`READ_DATA !== expected_value)
11361
        begin
11362
            test_fail("AM5 initial value was not set as defined");
11363
            failed = 1 ;
11364
        end
11365
    end
11366
 
11367
`endif
11368
 
11369
`ifdef GUEST
11370
    reg [31:0] read_data ;
11371
begin
11372
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11373
    failed    = 0 ;
11374
 
11375
    // check all images' BARs
11376
 
11377
    // BAR0
11378
    configuration_cycle_read
11379
    (
11380
        8'h00,                          // bus number [7:0]
11381
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11382
        3'h0,                           // function number [2:0]
11383
        6'h4,                           // register number [5:0]
11384
        2'h0,                           // type [1:0]
11385
        4'hF,                           // byte enables [3:0]
11386
        read_data                       // data returned from configuration read [31:0]
11387
    ) ;
11388
 
11389
    expected_value = 32'h0000_0000 ;
11390
 
11391
    if( read_data !== expected_value)
11392
    begin
11393
        test_fail("initial value of BAR0 register not as expected") ;
11394
        failed = 1 ;
11395
    end
11396
 
11397
    // BAR1
11398
    configuration_cycle_read
11399
    (
11400
        8'h00,                          // bus number [7:0]
11401
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11402
        3'h0,                           // function number [2:0]
11403
        6'h5,                           // register number [5:0]
11404
        2'h0,                           // type [1:0]
11405
        4'hF,                           // byte enables [3:0]
11406
        read_data                       // data returned from configuration read [31:0]
11407
    ) ;
11408
 
11409
    if (`PCI_AM1)
11410
        expected_value = `PCI_BA1_MEM_IO ;
11411
    else
11412
        expected_value = 32'h0000_0000 ;
11413
 
11414
    if( read_data !== expected_value)
11415
    begin
11416
        test_fail("initial value of BAR1 register not as expected") ;
11417
        failed = 1 ;
11418
    end
11419
 
11420
    // BAR2
11421
    configuration_cycle_read
11422
    (
11423
        8'h00,                          // bus number [7:0]
11424
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11425
        3'h0,                           // function number [2:0]
11426
        6'h6,                           // register number [5:0]
11427
        2'h0,                           // type [1:0]
11428
        4'hF,                           // byte enables [3:0]
11429
        read_data                       // data returned from configuration read [31:0]
11430
    ) ;
11431
 
11432
    `ifdef PCI_IMAGE2
11433
    if (`PCI_AM2)
11434
        expected_value = `PCI_BA2_MEM_IO ;
11435
    else
11436
        expected_value = 32'h0000_0000 ;
11437
    `else
11438
    expected_value = 32'h0 ;
11439
    `endif
11440
 
11441
    if( read_data !== expected_value)
11442
    begin
11443
        test_fail("initial value of BAR2 register not as expected") ;
11444
        failed = 1 ;
11445
    end
11446
 
11447
    // BAR3
11448
    configuration_cycle_read
11449
    (
11450
        8'h00,                          // bus number [7:0]
11451
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11452
        3'h0,                           // function number [2:0]
11453
        6'h7,                           // register number [5:0]
11454
        2'h0,                           // type [1:0]
11455
        4'hF,                           // byte enables [3:0]
11456
        read_data                       // data returned from configuration read [31:0]
11457
    ) ;
11458
 
11459
    `ifdef PCI_IMAGE3
11460
    if(`PCI_AM3)
11461
        expected_value = `PCI_BA3_MEM_IO ;
11462
    else
11463
        expected_value = 32'h0000_0000 ;
11464
    `else
11465
    expected_value = 32'h0 ;
11466
    `endif
11467
 
11468
    if( read_data !== expected_value)
11469
    begin
11470
        test_fail("initial value of BAR3 register not as expected") ;
11471
        failed = 1 ;
11472
    end
11473
 
11474
    // BAR4
11475
    configuration_cycle_read
11476
    (
11477
        8'h00,                          // bus number [7:0]
11478
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11479
        3'h0,                           // function number [2:0]
11480
        6'h8,                           // register number [5:0]
11481
        2'h0,                           // type [1:0]
11482
        4'hF,                           // byte enables [3:0]
11483
        read_data                       // data returned from configuration read [31:0]
11484
    ) ;
11485
 
11486
    `ifdef PCI_IMAGE4
11487
    if (`PCI_AM4)
11488
        expected_value = `PCI_BA4_MEM_IO ;
11489
    else
11490
        expected_value = 32'h0000_0000 ;
11491
    `else
11492
    expected_value = 32'h0 ;
11493
    `endif
11494
 
11495
    if( read_data !== expected_value)
11496
    begin
11497
        test_fail("initial value of BAR4 register not as expected") ;
11498
        failed = 1 ;
11499
    end
11500
 
11501
    // BAR5
11502
    configuration_cycle_read
11503
    (
11504
        8'h00,                          // bus number [7:0]
11505
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11506
        3'h0,                           // function number [2:0]
11507
        6'h9,                           // register number [5:0]
11508
        2'h0,                           // type [1:0]
11509
        4'hF,                           // byte enables [3:0]
11510
        read_data                       // data returned from configuration read [31:0]
11511
    ) ;
11512
 
11513
    `ifdef PCI_IMAGE5
11514
    if(`PCI_AM5)
11515
        expected_value = `PCI_BA5_MEM_IO ;
11516
    else
11517
        expected_value = 32'h0000_0000 ;
11518
    `else
11519
    expected_value = 32'h0 ;
11520
    `endif
11521
 
11522
    if( read_data !== expected_value)
11523
    begin
11524
        test_fail("initial value of BAR5 register not as expected") ;
11525
        failed = 1 ;
11526
    end
11527
 
11528
    // write all 1s to BAR0
11529
    read_data = 32'hFFFF_FFFF ;
11530
 
11531
    // BAR0
11532
    configuration_cycle_write
11533
    (
11534
        8'h00,                          // bus number [7:0]
11535
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11536
        3'h0,                           // function number [2:0]
11537
        6'h4,                           // register number [5:0]
11538
        2'h0,                           // type [1:0]
11539
        4'hF,                           // byte enables [3:0]
11540
        read_data                       // data to write [31:0]
11541
    ) ;
11542
 
11543
    expected_value = 32'hFFFF_FFFF ;
11544
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11545
 
11546
    configuration_cycle_read
11547
    (
11548
        8'h00,                          // bus number [7:0]
11549
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11550
        3'h0,                           // function number [2:0]
11551
        6'h4,                           // register number [5:0]
11552
        2'h0,                           // type [1:0]
11553
        4'hF,                           // byte enables [3:0]
11554
        read_data                       // data to write [31:0]
11555
    ) ;
11556
 
11557
    if ( read_data !== expected_value )
11558
    begin
11559
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11560
        failed = 1 ;
11561
    end
11562
 
11563
    // write all 1s to BAR1
11564
    read_data = 32'hFFFF_FFFF ;
11565
 
11566
    // BAR1
11567
    configuration_cycle_write
11568
    (
11569
        8'h00,                          // bus number [7:0]
11570
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11571
        3'h0,                           // function number [2:0]
11572
        6'h5,                           // register number [5:0]
11573
        2'h0,                           // type [1:0]
11574
        4'hF,                           // byte enables [3:0]
11575
        read_data                       // data to write [31:0]
11576
    ) ;
11577
 
11578
    expected_value = {`PCI_AM1, 12'h000} ;
11579
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11580
    if (`PCI_AM1)
11581
        expected_value[0] = `PCI_BA1_MEM_IO ;
11582
 
11583
    configuration_cycle_read
11584
    (
11585
        8'h00,                          // bus number [7:0]
11586
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11587
        3'h0,                           // function number [2:0]
11588
        6'h5,                           // register number [5:0]
11589
        2'h0,                           // type [1:0]
11590
        4'hF,                           // byte enables [3:0]
11591
        read_data                       // data to write [31:0]
11592
    ) ;
11593
 
11594
    if ( read_data !== expected_value )
11595
    begin
11596
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11597
        failed = 1 ;
11598
    end
11599
 
11600
    // write all 1s to BAR2
11601
    read_data = 32'hFFFF_FFFF ;
11602
 
11603
    // BAR2
11604
    configuration_cycle_write
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'h6,                           // 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
`ifdef PCI_IMAGE2
11616
    expected_value = {`PCI_AM2, 12'h000} ;
11617
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11618
    if (`PCI_AM2)
11619
        expected_value[0] = `PCI_BA2_MEM_IO ;
11620
`else
11621
    expected_value = 0 ;
11622
`endif
11623
 
11624
    configuration_cycle_read
11625
    (
11626
        8'h00,                          // bus number [7:0]
11627
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11628
        3'h0,                           // function number [2:0]
11629
        6'h6,                           // register number [5:0]
11630
        2'h0,                           // type [1:0]
11631
        4'hF,                           // byte enables [3:0]
11632
        read_data                       // data to write [31:0]
11633
    ) ;
11634
 
11635
    if ( read_data !== expected_value )
11636
    begin
11637
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11638
        failed = 1 ;
11639
    end
11640
 
11641
    // write all 1s to BAR3
11642
    read_data = 32'hFFFF_FFFF ;
11643
 
11644
    // BAR3
11645
    configuration_cycle_write
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'h7,                           // 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
`ifdef PCI_IMAGE3
11657
    expected_value = {`PCI_AM3, 12'h000} ;
11658
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11659
    if(`PCI_AM3)
11660
        expected_value[0] = `PCI_BA3_MEM_IO ;
11661
`else
11662
    expected_value = 0 ;
11663
`endif
11664
 
11665
    configuration_cycle_read
11666
    (
11667
        8'h00,                          // bus number [7:0]
11668
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11669
        3'h0,                           // function number [2:0]
11670
        6'h7,                           // register number [5:0]
11671
        2'h0,                           // type [1:0]
11672
        4'hF,                           // byte enables [3:0]
11673
        read_data                       // data to write [31:0]
11674
    ) ;
11675
 
11676
    if ( read_data !== expected_value )
11677
    begin
11678
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11679
        failed = 1 ;
11680
    end
11681
 
11682
    // write all 1s to BAR4
11683
    read_data = 32'hFFFF_FFFF ;
11684
 
11685
    // BAR4
11686
    configuration_cycle_write
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'h8,                           // 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
`ifdef PCI_IMAGE4
11698
    expected_value = {`PCI_AM4, 12'h000} ;
11699
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11700
    if(`PCI_AM4)
11701
        expected_value[0] = `PCI_BA4_MEM_IO ;
11702
`else
11703
    expected_value = 0 ;
11704
`endif
11705
 
11706
    configuration_cycle_read
11707
    (
11708
        8'h00,                          // bus number [7:0]
11709
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11710
        3'h0,                           // function number [2:0]
11711
        6'h8,                           // register number [5:0]
11712
        2'h0,                           // type [1:0]
11713
        4'hF,                           // byte enables [3:0]
11714
        read_data                       // data to write [31:0]
11715
    ) ;
11716
 
11717
    if ( read_data !== expected_value )
11718
    begin
11719
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11720
        failed = 1 ;
11721
    end
11722
 
11723
    // write all 1s to BAR5
11724
    read_data = 32'hFFFF_FFFF ;
11725
 
11726
    // BAR5
11727
    configuration_cycle_write
11728
    (
11729
        8'h00,                          // bus number [7:0]
11730
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11731
        3'h0,                           // function number [2:0]
11732
        6'h9,                           // register number [5:0]
11733
        2'h0,                           // type [1:0]
11734
        4'hF,                           // byte enables [3:0]
11735
        read_data                       // data to write [31:0]
11736
    ) ;
11737
 
11738
`ifdef PCI_IMAGE5
11739
    expected_value = {`PCI_AM5, 12'h000} ;
11740
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11741
    if(`PCI_AM5)
11742
        expected_value[0] = `PCI_BA5_MEM_IO ;
11743
`else
11744
    expected_value = 0 ;
11745
`endif
11746
 
11747
    configuration_cycle_read
11748
    (
11749
        8'h00,                          // bus number [7:0]
11750
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11751
        3'h0,                           // function number [2:0]
11752
        6'h9,                           // register number [5:0]
11753
        2'h0,                           // type [1:0]
11754
        4'hF,                           // byte enables [3:0]
11755
        read_data                       // data to write [31:0]
11756
    ) ;
11757
 
11758
    if ( read_data !== expected_value )
11759
    begin
11760
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11761
        failed = 1 ;
11762
    end
11763
`endif
11764
 
11765
    if (!failed)
11766
        test_ok ;
11767
end
11768
endtask
11769
 
11770 15 mihad
task display_warning;
11771
    input [31:0] error_address ;
11772
    input [31:0] expected_data ;
11773
    input [31:0] actual ;
11774
begin
11775
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11776
end
11777
endtask // display warning
11778
 
11779
/*############################################################################
11780
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11781
=====================
11782
############################################################################*/
11783
 
11784
// Task reslease the PCI bus for 'delay' clocks
11785
task do_pause;
11786
  input  [15:0] delay;
11787
  reg    [15:0] cnt;
11788
  begin
11789
    test_start <= 1'b0;  // no device is allowed to take this
11790
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11791
    begin
11792
      if (~pci_reset_comb)
11793
      begin
11794
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11795
      end
11796
      `NO_ELSE;
11797
    end
11798
  end
11799
endtask // do_pause
11800
 
11801
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11802
task DO_REF;
11803
  input  [79:0] name;
11804
  input  [2:0] master_number;
11805
  input  [PCI_BUS_DATA_RANGE:0] address;
11806
  input  [3:0] command;
11807
  input  [PCI_BUS_DATA_RANGE:0] data;
11808
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11809
  input  [9:0] size;
11810
  input   make_addr_par_error, make_data_par_error;
11811
  input  [7:0] master_wait_states;
11812
  input  [7:0] target_wait_states;
11813
  input  [1:0] target_devsel_speed;
11814
  input   fast_back_to_back;
11815
  input  [2:0] target_termination;
11816
  input   expect_master_abort;
11817
  reg     waiting;
11818
  begin
11819
// Cautiously wait for previous command to be done
11820
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11821
    begin
11822
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11823
      begin
11824
        if (~pci_reset_comb)
11825
        begin
11826
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11827
        end
11828
        `NO_ELSE;
11829
      end
11830
      else
11831
      begin
11832
        waiting = 1'b0;  // ready to do next command
11833
      end
11834
    end
11835
    next_test_name[79:0] <= name[79:0];
11836
    test_master_number <= master_number[2:0];
11837
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11838
    test_command[3:0] <= command[3:0] ;
11839
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11840
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11841
    test_size <= size;
11842
    test_make_addr_par_error <= make_addr_par_error;
11843
    test_make_data_par_error <= make_data_par_error;
11844
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11845
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11846
    test_target_initial_wait_states <= target_wait_states[7:4];
11847
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11848
    test_target_devsel_speed <= target_devsel_speed[1:0];
11849
    test_fast_back_to_back <= fast_back_to_back;
11850
    test_target_termination <= target_termination[2:0];
11851
    test_expect_master_abort <= expect_master_abort;
11852
    test_start <= 1'b1;
11853
    if (~pci_reset_comb)
11854
    begin
11855
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11856
    end
11857
    `NO_ELSE;
11858
// wait for new command to start
11859
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11860
    begin
11861
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11862
      begin
11863
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11864
      end
11865
      else
11866
      begin
11867
        waiting = 1'b0;  // ready to do next command
11868
      end
11869
    end
11870
  end
11871
endtask // DO_REF
11872
 
11873
// Use Macros defined in pci_defines.vh as paramaters
11874
 
11875
// DO_REF (name[79:0], master_number[2:0],
11876
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11877
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11878
//          make_addr_par_error, make_data_par_error,
11879
//          master_wait_states[8:0], target_wait_states[8:0],
11880
//          target_devsel_speed[1:0], fast_back_to_back,
11881
//          target_termination[2:0],
11882
//          expect_master_abort);
11883
//
11884
// Example:
11885
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11886
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11887
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11888
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11889
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11890
 
11891
// Access a location with no high-order bits set, assuring that no device responds
11892
task PCIU_CONFIG_READ_MASTER_ABORT;
11893
  input  [79:0] name;
11894
  input  [2:0] master_number;
11895 51 mihad
  input  [31:0] address ;
11896
  input  [3:0] be ;
11897 15 mihad
  begin
11898 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11899
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11900
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11901 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11902
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11903
  end
11904
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11905
 
11906
// Access a location with no high-order bits set, assuring that no device responds
11907
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11908
  input  [79:0] name;
11909
  input  [2:0] master_number;
11910 51 mihad
  input  [31:0] address ;
11911
  input  [3:0] be ;
11912 15 mihad
  begin
11913 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11914
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11915
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11916 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11917
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11918
  end
11919
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11920
 
11921
// Access a location with no high-order bits set, assuring that no device responds
11922
task PCIU_MEM_READ_MASTER_ABORT;
11923
  input  [79:0] name;
11924
  input  [2:0] master_number;
11925
  input  [9:0] size;
11926
  begin
11927
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11928
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11929
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11930
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11931
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11932
  end
11933
endtask // PCIU_MEM_READ_MASTER_ABORT
11934
 
11935
// Access a location with no high-order bits set, assuring that no device responds
11936
task PCIU_MEM_WRITE_MASTER_ABORT;
11937
  input  [79:0] name;
11938
  input  [2:0] master_number;
11939
  input  [9:0] size;
11940
  begin
11941
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11942
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11943
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11944
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11945
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11946
  end
11947
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11948
 
11949
// Do variable length transfers with various paramaters
11950
task PCIU_CONFIG_READ;
11951
  input  [79:0] name;
11952
  input  [2:0] master_number;
11953
  input  [PCI_BUS_DATA_RANGE:0] address;
11954
  input  [PCI_BUS_DATA_RANGE:0] data;
11955
  input  [3:0] be ;
11956
  input  [9:0] size;
11957
  input  [7:0] master_wait_states;
11958
  input  [7:0] target_wait_states;
11959
  input  [1:0] target_devsel_speed;
11960
  input  [2:0] target_termination;
11961
  begin
11962
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11963
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11964
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11965
              8'h0_0, target_wait_states[7:0],
11966
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11967
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11968
  end
11969
endtask // PCIU_CONFIG_READ
11970
 
11971
task PCIU_CONFIG_WRITE;
11972
  input  [79:0] name;
11973
  input  [2:0] master_number;
11974
  input  [PCI_BUS_DATA_RANGE:0] address;
11975
  input  [PCI_BUS_DATA_RANGE:0] data;
11976
  input  [3:0] be ;
11977
  input  [9:0] size;
11978
  input  [7:0] master_wait_states;
11979
  input  [7:0] target_wait_states;
11980
  input  [1:0] target_devsel_speed;
11981
  input  [2:0] target_termination;
11982
  begin
11983
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11984
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11985
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11986
              8'h0_0, target_wait_states[7:0],
11987
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11988
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11989
  end
11990
endtask // PCIU_CONFIG_WRITE
11991
 
11992
task PCIU_READ;
11993
  input  [2:0] master_number;
11994
  input  [PCI_BUS_DATA_RANGE:0] address;
11995
  input  [3:0] command;
11996
  input  [PCI_BUS_DATA_RANGE:0] data;
11997
  input  [3:0] byte_en;
11998
  input  [9:0] size;
11999
  input  [7:0] master_wait_states;
12000
  input  [7:0] target_wait_states;
12001
  input  [1:0] target_devsel_speed;
12002
  input  [2:0] target_termination;
12003
  reg    [79:0] name;
12004
  begin
12005
    if (command == `BC_MEM_READ)
12006
        name = "MEM_READ  " ;
12007
    else if (command == `BC_MEM_READ_LN)
12008
        name = "MEM_RD_LN " ;
12009
    else if (command == `BC_MEM_READ_MUL )
12010
        name = "MEM_RD_MUL" ;
12011
    else
12012
        name = "WRONG_READ" ;
12013
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12014
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12015
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12016
              8'h0_0, target_wait_states[7:0],
12017
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12018
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12019
  end
12020
endtask // PCIU_READ
12021
 
12022
task PCIU_MEM_READ;
12023
  input  [79:0] name;
12024
  input  [2:0] master_number;
12025
  input  [PCI_BUS_DATA_RANGE:0] address;
12026
  input  [PCI_BUS_DATA_RANGE:0] data;
12027
  input  [9:0] size;
12028
  input  [7:0] master_wait_states;
12029
  input  [7:0] target_wait_states;
12030
  input  [1:0] target_devsel_speed;
12031
  input  [2:0] target_termination;
12032
  begin
12033
 
12034
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12035
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12036
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12037
              8'h0_0, target_wait_states[7:0],
12038
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12039
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12040
  end
12041
endtask // PCIU_MEM_READ
12042
 
12043
task PCIU_IO_READ;
12044
  input  [2:0] master_number;
12045
  input  [PCI_BUS_DATA_RANGE:0] address;
12046
  input  [PCI_BUS_DATA_RANGE:0] data;
12047
  input  [3:0] byte_en ;
12048
  input  [9:0] size;
12049
  input  [2:0] target_termination ;
12050
  begin
12051
 
12052
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12053
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12054
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12055
              8'h0_0, `Test_One_Zero_Target_WS,
12056
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12057
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12058
  end
12059
endtask // PCIU_IO_READ
12060
 
12061
task PCIU_IO_READ_MAKE_PERR;
12062
  input  [2:0] master_number;
12063
  input  [PCI_BUS_DATA_RANGE:0] address;
12064
  input  [PCI_BUS_DATA_RANGE:0] data;
12065
  input  [3:0] byte_en ;
12066
  input  [9:0] size;
12067
  input  [2:0] target_termination ;
12068
  begin
12069
 
12070
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12071
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12072
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12073
              8'h0_0, `Test_One_Zero_Target_WS,
12074
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12075
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12076
  end
12077
endtask // PCIU_IO_READ_MAKE_PERR
12078
 
12079
task PCIU_MEM_READ_LN;
12080
  input  [79:0] name;
12081
  input  [2:0] master_number;
12082
  input  [PCI_BUS_DATA_RANGE:0] address;
12083
  input  [PCI_BUS_DATA_RANGE:0] data;
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_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
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_READ_LN
12098
 
12099
task PCIU_MEM_READ_MUL;
12100
  input  [79:0] name;
12101
  input  [2:0] master_number;
12102
  input  [PCI_BUS_DATA_RANGE:0] address;
12103
  input  [PCI_BUS_DATA_RANGE:0] data;
12104
  input  [9:0] size;
12105
  input  [7:0] master_wait_states;
12106
  input  [7:0] target_wait_states;
12107
  input  [1:0] target_devsel_speed;
12108
  input  [2:0] target_termination;
12109
  begin
12110
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12111
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12112
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12113
              8'h0_0, target_wait_states[7:0],
12114
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12115
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12116
  end
12117
endtask // PCIU_MEM_READ_MUL
12118
 
12119
task PCIU_MEM_READ_MAKE_PERR;
12120
  input  [79:0] name;
12121
  input  [2:0] master_number;
12122
  input  [PCI_BUS_DATA_RANGE:0] address;
12123
  input  [PCI_BUS_DATA_RANGE:0] data;
12124
  input  [9:0] size;
12125
  input  [7:0] master_wait_states;
12126
  input  [7:0] target_wait_states;
12127
  input  [1:0] target_devsel_speed;
12128
  input  [2:0] target_termination;
12129
  begin
12130
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12131
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12132
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12133
              8'h0_0, target_wait_states[7:0],
12134
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12135
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12136
  end
12137
endtask // PCIU_MEM_READ_MAKE_PERR
12138
 
12139
task PCIU_MEM_WRITE;
12140
  input  [79:0] name;
12141
  input  [2:0] master_number;
12142
  input  [PCI_BUS_DATA_RANGE:0] address;
12143
  input  [PCI_BUS_DATA_RANGE:0] data;
12144
  input  [3:0] byte_en;
12145
  input  [9:0] size;
12146
  input  [7:0] master_wait_states;
12147
  input  [7:0] target_wait_states;
12148
  input  [1:0] target_devsel_speed;
12149
  input  [2:0] target_termination;
12150
  begin
12151
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12152
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12153
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12154
              8'h0_0, target_wait_states[7:0],
12155
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12156
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12157
  end
12158
endtask // PCIU_MEM_WRITE
12159
 
12160
task PCIU_IO_WRITE;
12161
  input  [2:0] master_number;
12162
  input  [PCI_BUS_DATA_RANGE:0] address;
12163
  input  [PCI_BUS_DATA_RANGE:0] data;
12164
  input  [3:0] byte_en;
12165
  input  [9:0] size;
12166
  input  [2:0] target_termination ;
12167
  begin
12168
 
12169
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12170
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12171
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12172
              8'h0_0, `Test_One_Zero_Target_WS,
12173
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12174
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12175
  end
12176
endtask // PCIU_IO_WRITE
12177
 
12178
task PCIU_IO_WRITE_MAKE_PERR ;
12179
  input  [2:0] master_number;
12180
  input  [PCI_BUS_DATA_RANGE:0] address;
12181
  input  [PCI_BUS_DATA_RANGE:0] data;
12182
  input  [3:0] byte_en;
12183
  input  [9:0] size;
12184
  input  [2:0] target_termination ;
12185
  begin
12186
 
12187
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12188
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12189
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12190
              8'h0_0, `Test_One_Zero_Target_WS,
12191
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12192
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12193
  end
12194
endtask // PCIU_IO_WRITE
12195
 
12196
task PCIU_MEM_WRITE_MAKE_SERR;
12197
  input  [79:0] name;
12198
  input  [2:0] master_number;
12199
  input  [PCI_BUS_DATA_RANGE:0] address;
12200
  input  [PCI_BUS_DATA_RANGE:0] data;
12201
  input  [9:0] size;
12202
  input  [7:0] master_wait_states;
12203
  input  [7:0] target_wait_states;
12204
  input  [1:0] target_devsel_speed;
12205
  input  [2:0] target_termination;
12206
  begin
12207
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12208
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12209
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12210
              8'h0_0, target_wait_states[7:0],
12211
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12212
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12213
  end
12214
endtask // PCIU_MEM_WRITE_MAKE_SERR
12215
 
12216
task PCIU_MEM_WRITE_MAKE_PERR;
12217
  input  [79:0] name;
12218
  input  [2:0] master_number;
12219
  input  [PCI_BUS_DATA_RANGE:0] address;
12220
  input  [PCI_BUS_DATA_RANGE:0] data;
12221
  input  [9:0] size;
12222
  input  [7:0] master_wait_states;
12223
  input  [7:0] target_wait_states;
12224
  input  [1:0] target_devsel_speed;
12225
  input  [2:0] target_termination;
12226
  begin
12227
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12228
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12229
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12230
              8'h0_0, target_wait_states[7:0],
12231
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12232
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12233
  end
12234
endtask // PCIU_MEM_WRITE
12235
 
12236
/*--------------------------------------------------------------------------
12237
Initialization CASES
12238
--------------------------------------------------------------------------*/
12239
 
12240
// Initialize the basic Config Registers of the PCI bridge target device
12241
task configure_bridge_target;
12242
    reg [11:0] offset ;
12243
    reg [31:0] data ;
12244
    `ifdef HOST
12245
    reg `WRITE_STIM_TYPE   write_data ;
12246
    reg `WB_TRANSFER_FLAGS write_flags ;
12247
    reg `WRITE_RETURN_TYPE write_status ;
12248
    `else
12249
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12250
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12251
    `endif
12252
 
12253
    reg [31:0] temp_var ;
12254
begin
12255
`ifdef HOST //  set Header
12256
    offset  = 12'h4 ; // PCI Header Command register
12257
    data    = 32'h0000_0007 ; // enable master & target operation
12258
 
12259
    write_flags                      = 0 ;
12260
    write_flags`INIT_WAITS           = tb_init_waits ;
12261
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12262
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12263
 
12264
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12265
    write_data`WRITE_SEL      = 4'h1 ;
12266
    write_data`WRITE_TAG_STIM = 0 ;
12267
    write_data`WRITE_DATA     = data ;
12268
 
12269
    next_test_name[79:0] <= "Init_Tar_R";
12270
 
12271
    $display(" bridge target - Enabling master and target operation!");
12272
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12273
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12274
    begin
12275
        $display("Write to configuration space failed! Time %t ", $time) ;
12276
    end
12277
 
12278
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12279
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12280
 
12281
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12282
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12283
 
12284
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12285
    write_data`WRITE_SEL      = 4'hf ;
12286
    write_data`WRITE_TAG_STIM = 0 ;
12287
    write_data`WRITE_DATA     = data ;
12288
 
12289
 `ifdef  NO_CNF_IMAGE
12290
  `ifdef PCI_IMAGE0 //      set P_BA0
12291
 
12292
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12293
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12294
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12295
    begin
12296
        $display("Write to configuration space failed! Time %t ", $time) ;
12297
    end
12298
  `endif
12299
 `else //      set P_BA0
12300
 
12301
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12302
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12303
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12304
    begin
12305
        $display("Write to configuration space failed! Time %t ", $time) ;
12306
    end
12307
 `endif
12308
 
12309
`else // GUEST, set Header, set P_BA0
12310
    data            = 32'h0000_0007 ; // enable master & target operation
12311
    byte_enables    = 4'hF ;
12312
    $display(" bridge target - Enabling master and target operation!");
12313 45 mihad
    configuration_cycle_write(0,                        // bus number
12314
                              `TAR0_IDSEL_INDEX - 11,   // device number
12315
                              0,                        // function number
12316
                              1,                        // register number
12317
                              0,                        // type of configuration cycle
12318
                              byte_enables,             // byte enables
12319
                              data                      // data
12320 15 mihad
                             ) ;
12321
 
12322
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12323
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12324
    byte_enables = 4'hf ;
12325 45 mihad
    configuration_cycle_write(0,                        // bus number
12326
                              `TAR0_IDSEL_INDEX - 11,   // device number
12327
                              0,                        // function number
12328
                              4,                        // register number
12329
                              0,                        // type of configuration cycle
12330
                              byte_enables,             // byte enables
12331
                              data                      // data
12332 15 mihad
                             ) ;
12333
 
12334
`endif
12335
end
12336
endtask // configure_bridge_target
12337
 
12338
// Initialize the basic Config Registers of the PCI bridge target device
12339
task configure_bridge_target_base_addresses;
12340
    reg [11:0] offset ;
12341
    reg [31:0] data ;
12342
    `ifdef HOST
12343
    reg `WRITE_STIM_TYPE   write_data ;
12344
    reg `WB_TRANSFER_FLAGS write_flags ;
12345
    reg `WRITE_RETURN_TYPE write_status ;
12346
    `else
12347
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12348
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12349
    `endif
12350
 
12351
    reg [31:0] temp_var ;
12352
begin
12353
`ifdef HOST //  set Header
12354
    offset  = 12'h4 ; // PCI Header Command register
12355
    data    = 32'h0000_0007 ; // enable master & target operation
12356
 
12357
    write_flags                    = 0 ;
12358
    write_flags`INIT_WAITS         = tb_init_waits ;
12359
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12360
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12361
 
12362
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12363
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12364
 
12365
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12366
    write_data`WRITE_SEL      = 4'h1 ;
12367
    write_data`WRITE_TAG_STIM = 0 ;
12368
    write_data`WRITE_DATA     = data ;
12369
 
12370
    next_test_name[79:0] <= "Init_Tar_R";
12371
 
12372
    $display(" bridge target - Enabling master and target operation!");
12373
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12374
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12375
    begin
12376
        $display("Write to configuration space failed! Time %t ", $time) ;
12377
    end
12378
 
12379
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12380
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12381
 
12382
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12383
    write_data`WRITE_SEL      = 4'hf ;
12384
    write_data`WRITE_TAG_STIM = 0 ;
12385
    write_data`WRITE_DATA     = data ;
12386
 
12387
 `ifdef  NO_CNF_IMAGE
12388
  `ifdef PCI_IMAGE0 //      set P_BA0
12389
 
12390
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12391
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12392
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12393
    begin
12394
        $display("Write to configuration space failed! Time %t ", $time) ;
12395
    end
12396
  `endif
12397
 `else //      set P_BA0
12398
 
12399
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12400
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12401
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12402
    begin
12403
        $display("Write to configuration space failed! Time %t ", $time) ;
12404
    end
12405
 `endif
12406
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12407
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12408
 
12409
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12410
    write_data`WRITE_SEL      = 4'hf ;
12411
    write_data`WRITE_TAG_STIM = 0 ;
12412
    write_data`WRITE_DATA     = data ;
12413
 
12414
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12415
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12416
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12417
    begin
12418
        $display("Write to configuration space failed! Time %t ", $time) ;
12419
    end
12420
 `ifdef PCI_IMAGE2
12421
 
12422
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12423
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12424
 
12425
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12426
    write_data`WRITE_SEL      = 4'hf ;
12427
    write_data`WRITE_TAG_STIM = 0 ;
12428
    write_data`WRITE_DATA     = data ;
12429
 
12430
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12431
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12432
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12433
    begin
12434
        $display("Write to configuration space failed! Time %t ", $time) ;
12435
    end
12436
 `endif
12437
 `ifdef PCI_IMAGE3
12438
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12439
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12440
 
12441
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12442
    write_data`WRITE_SEL      = 4'hf ;
12443
    write_data`WRITE_TAG_STIM = 0 ;
12444
    write_data`WRITE_DATA     = data ;
12445
 
12446
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12447
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12448
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12449
    begin
12450
        $display("Write to configuration space failed! Time %t ", $time) ;
12451
    end
12452
 `endif
12453
 `ifdef PCI_IMAGE4
12454
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12455
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12456
 
12457
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12458
    write_data`WRITE_SEL      = 4'hf ;
12459
    write_data`WRITE_TAG_STIM = 0 ;
12460
    write_data`WRITE_DATA     = data ;
12461
 
12462
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12463
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12464
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12465
    begin
12466
        $display("Write to configuration space failed! Time %t ", $time) ;
12467
    end
12468
 `endif
12469
 `ifdef PCI_IMAGE5
12470
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12471
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12472
 
12473
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12474
    write_data`WRITE_SEL      = 4'hf ;
12475
    write_data`WRITE_TAG_STIM = 0 ;
12476
    write_data`WRITE_DATA     = data ;
12477
 
12478
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12479
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12480
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12481
    begin
12482
        $display("Write to configuration space failed! Time %t ", $time) ;
12483
    end
12484
 `endif
12485
 
12486
`else // GUEST, set Header, set P_BA0
12487
    data            = 32'h0000_0007 ; // enable master & target operation
12488
    byte_enables    = 4'hF ;
12489
    $display(" bridge target - Enabling master and target operation!");
12490 45 mihad
    configuration_cycle_write(0,                        // bus number
12491
                              `TAR0_IDSEL_INDEX - 11,   // device number
12492
                              0,                        // function number
12493
                              1,                        // register number
12494
                              0,                        // type of configuration cycle
12495
                              byte_enables,             // byte enables
12496
                              data                      // data
12497 15 mihad
                             ) ;
12498
 
12499
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12500
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12501
    byte_enables = 4'hf ;
12502 45 mihad
    configuration_cycle_write(0,                        // bus number
12503
                              `TAR0_IDSEL_INDEX - 11,   // device number
12504
                              0,                        // function number
12505
                              4,                        // register number
12506
                              0,                        // type of configuration cycle
12507
                              byte_enables,             // byte enables
12508
                              data                      // data
12509 15 mihad
                             ) ;
12510
 
12511
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12512
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12513
    byte_enables = 4'hf ;
12514 45 mihad
    configuration_cycle_write(0,                        // bus number
12515
                              `TAR0_IDSEL_INDEX - 11,   // device number
12516
                              0,                        // function number
12517
                              5,                        // register number
12518
                              0,                        // type of configuration cycle
12519
                              byte_enables,             // byte enables
12520
                              data                      // data
12521 15 mihad
                             ) ;
12522
 `ifdef PCI_IMAGE2
12523
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12524
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12525
    byte_enables = 4'hf ;
12526 45 mihad
    configuration_cycle_write(0,                        // bus number
12527
                              `TAR0_IDSEL_INDEX - 11,   // device number
12528
                              0,                        // function number
12529
                              6,                        // register number
12530
                              0,                        // type of configuration cycle
12531
                              byte_enables,             // byte enables
12532
                              data                      // data
12533 15 mihad
                             ) ;
12534
 `endif
12535
 `ifdef PCI_IMAGE3
12536
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12537
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12538
    byte_enables = 4'hf ;
12539 45 mihad
    configuration_cycle_write(0,                        // bus number
12540
                              `TAR0_IDSEL_INDEX - 11,   // device number
12541
                              0,                        // function number
12542
                              7,                        // register number
12543
                              0,                        // type of configuration cycle
12544
                              byte_enables,             // byte enables
12545
                              data                      // data
12546 15 mihad
                             ) ;
12547
 `endif
12548
 `ifdef PCI_IMAGE4
12549
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12550
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12551
    byte_enables = 4'hf ;
12552 45 mihad
    configuration_cycle_write(0,                        // bus number
12553
                              `TAR0_IDSEL_INDEX - 11,   // device number
12554
                              0,                        // function number
12555
                              8,                        // register number
12556
                              0,                        // type of configuration cycle
12557
                              byte_enables,             // byte enables
12558
                              data                      // data
12559 15 mihad
                             ) ;
12560
 `endif
12561
 `ifdef PCI_IMAGE5
12562
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12563
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12564
    byte_enables = 4'hf ;
12565 45 mihad
    configuration_cycle_write(0,                        // bus number
12566
                              `TAR0_IDSEL_INDEX - 11,   // device number
12567
                              0,                        // function number
12568
                              9,                        // register number
12569
                              0,                        // type of configuration cycle
12570
                              byte_enables,             // byte enables
12571
                              data                      // data
12572 15 mihad
                             ) ;
12573
 `endif
12574
`endif
12575
end
12576
endtask // configure_bridge_target_base_addresses
12577
 
12578
/*--------------------------------------------------------------------------
12579
Test CASES
12580
--------------------------------------------------------------------------*/
12581
 
12582
// function converts PCI address to WB with the same data as the pci_decoder does
12583
function [31:0] pci_to_wb_addr_convert ;
12584
 
12585
    input [31:0] pci_address ;
12586
    input [31:0] translation_address ;
12587
    input [31:0] translate ;
12588
 
12589
    reg   [31:0] temp_address ;
12590
begin
12591
    if ( translate !== 1 )
12592
    begin
12593
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12594
    end
12595
    else
12596
    begin
12597
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12598
    end
12599
 
12600
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12601
    pci_to_wb_addr_convert = temp_address ;
12602
end
12603
endfunction // pci_to_wb_addr_convert
12604
 
12605
// Test normal write and read to WB slave
12606
task test_normal_wr_rd;
12607
  input  [2:0]  Master_ID;
12608
  input  [PCI_BUS_DATA_RANGE:0] Address;
12609
  input  [PCI_BUS_DATA_RANGE:0] Data;
12610
  input  [3:0]  Be;
12611
  input  [2:0]  Image_num;
12612
  input  [9:0]  Set_size;
12613
  input         Set_addr_translation;
12614
  input         Set_prefetch_enable;
12615
  input  [7:0]  Cache_lsize;
12616
  input         Set_wb_wait_states;
12617
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12618
 
12619
  reg    [31:0] rd_address;
12620
  reg    [31:0] rd_data;
12621
  reg    [3:0]  rd_be;
12622
  reg    [11:0] addr_offset;
12623
  reg    [31:0] read_data;
12624
  reg           continue ;
12625
  reg           ok   ;
12626
  reg    [31:0] expect_address ;
12627
  reg    [31:0] expect_rd_address ;
12628
  reg           expect_we ;
12629
  reg    [9:0]  expect_length_wr ;
12630
  reg    [9:0]  expect_length_rd ;
12631
  reg    [9:0]  expect_length_rd1 ;
12632
  reg    [9:0]  expect_length_rd2 ;
12633
  reg    [3:0]  use_rd_cmd ;
12634
  integer       i ;
12635 35 mihad
  reg           error_monitor_done ;
12636 15 mihad
begin:main
12637
 
12638
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12639
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12640
    $display(" - errors will be reported, but they should not occur!");
12641
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12642
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12643
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12644
    if ( ok !== 1 )
12645
    begin
12646
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12647
        test_fail("write to P_ERR_CS register didn't succeede") ;
12648
        disable main;
12649
    end
12650
 
12651
    `ifdef  ADDR_TRAN_IMPL
12652
 
12653
    // set or clear address translation
12654
    if (Set_addr_translation)
12655
    begin
12656
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12657
        $display(" - address translation will be performed!");
12658
    end
12659
    else
12660
    begin
12661
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12662
        $display(" - address translation will not be performed!");
12663
    end
12664
    // set or clear pre-fetch enable
12665
    if (Set_prefetch_enable)
12666
    begin
12667
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12668
        $display(" - bursts can be performed!");
12669
    end
12670
    else
12671
    begin
12672
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12673
        $display(" - bursts can not be performed!");
12674
    end
12675
 
12676
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12677
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12678
    if ( ok !== 1 )
12679
    begin
12680
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12681
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12682
        disable main;
12683
    end
12684
 
12685
    // predict the address and control signals on WB bus
12686
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12687
    expect_we      = 1'b1 ; // WRITE
12688
 
12689
    `else
12690
 
12691
    // address translation is not implemented
12692
    $display("Address translation is NOT implemented for PCI images!");
12693
    // set or clear pre-fetch enable
12694
    if (Set_prefetch_enable)
12695
    begin
12696
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12697
        $display(" - bursts can be performed!");
12698
    end
12699
    else
12700
    begin
12701
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12702
        $display(" - bursts can not be performed!");
12703
    end
12704
 
12705
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12706
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12707
    if ( ok !== 1 )
12708
    begin
12709
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12710
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12711
        disable main;
12712
    end
12713
 
12714
    // predict the address and control signals on WB bus
12715
    expect_address = Address ;
12716
    expect_we      = 1'b1 ; // WRITE
12717
 
12718
    `endif
12719
 
12720
    // set WB SLAVE parameters
12721
    if (Set_wb_wait_states)
12722
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12723
    else
12724
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12725
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12726
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12727
 
12728
    if ( Set_size > (`PCIW_DEPTH - 2) )
12729
    begin
12730
        expect_length_wr = `PCIW_DEPTH - 2 ;
12731
    end
12732
    else
12733
    begin
12734
        expect_length_wr = Set_size ;
12735
    end
12736
    // write through the PCI bridge to WB slave
12737
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12738
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12739
 
12740
    fork
12741
    begin
12742
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12743
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12744
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12745
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12746
        do_pause( 1 ) ;
12747
    end
12748
    begin
12749
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12750
       if ( ok !== 1 )
12751
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12752
       else
12753
           test_ok ;
12754
    end
12755
    join
12756
 
12757
    // predict the address and control signals on WB bus
12758
    expect_we      = 1'b0 ; // READ
12759
 
12760
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12761
    $display("Memory read through PCI bridge to WB slave!");
12762
 
12763
    if ( expect_length_wr == 1 )
12764
    begin
12765
        if (Set_prefetch_enable)
12766
        begin
12767
            expect_length_rd1 = Cache_lsize ;
12768
            expect_length_rd2 = 0 ;
12769
                // If PCI behavioral master must check received DATA
12770
                master2_check_received_data = 0 ;
12771
                    master1_check_received_data = 0 ;
12772
        end
12773
        else
12774
        begin
12775
            expect_length_rd1 = 1 ;
12776
            expect_length_rd2 = 0 ;
12777
                // If PCI behavioral master must check received DATA
12778
                master2_check_received_data = 1 ;
12779
                    master1_check_received_data = 1 ;
12780
        end
12781
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12782
        expect_length_rd  = expect_length_rd1 ;
12783
    end
12784
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12785
    begin
12786
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12787
        expect_length_rd2 = 0 ;
12788
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12789
        expect_length_rd  = expect_length_rd1 ;
12790
                // If PCI behavioral master must check received DATA
12791
        master2_check_received_data = 1 ;
12792
            master1_check_received_data = 1 ;
12793
    end
12794
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12795
    begin
12796
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12797
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12798
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12799
        expect_length_rd  = expect_length_rd1 ;
12800
                // If PCI behavioral master must check received DATA
12801
                master2_check_received_data = 1 ;
12802
            master1_check_received_data = 1 ;
12803
    end
12804
    else
12805
    begin
12806
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12807
        begin
12808
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12809
            expect_length_rd2 = 0 ;
12810
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12811
            expect_length_rd  = expect_length_rd1 ;
12812
                // If PCI behavioral master must check received DATA
12813
                master2_check_received_data = 0 ;
12814
                    master1_check_received_data = 0 ;
12815
        end
12816
        else
12817
        begin
12818
            if ( expect_length_wr > Cache_lsize )
12819
            begin
12820
                expect_length_rd1 = Cache_lsize ;
12821
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12822
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12823
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12824
                else
12825
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12826
                expect_length_rd  = expect_length_rd1 ;
12827
                        // If PCI behavioral master must check received DATA
12828
                        master2_check_received_data = 1 ;
12829
                            master1_check_received_data = 1 ;
12830
            end
12831
            else
12832
            begin
12833
                expect_length_rd1 = Cache_lsize ;
12834
                expect_length_rd2 = 0 ;
12835
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12836
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12837
                else
12838
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12839
                expect_length_rd  = expect_length_wr ;
12840
                                if ( expect_length_wr == Cache_lsize )
12841
                        begin
12842
                                // If PCI behavioral master must check received DATA
12843
                                master2_check_received_data = 1 ;
12844
                                    master1_check_received_data = 1 ;
12845
                                end
12846
                                else
12847
                                begin
12848
                                // If PCI behavioral master must check received DATA
12849
                                master2_check_received_data = 0 ;
12850
                                    master1_check_received_data = 0 ;
12851
                end
12852
            end
12853
        end
12854
    end
12855
 
12856
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12857
    expect_rd_address = expect_address ;
12858
    rd_data[31:0] = Data[31:0];
12859
    rd_be[3:0] = Be[3:0];
12860
 
12861
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12862
    while (expect_length_rd2 > 0)
12863
    begin
12864
        // do read
12865
        $display("Read %d words!", expect_length_rd);
12866
 
12867
        fork
12868
        begin
12869
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12870
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12871
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12872
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12873
 
12874
            wb_transaction_stop( expect_length_rd - 1) ;
12875
 
12876
            do_pause( 1 ) ;
12877
        end
12878
        begin
12879
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12880
            if ( ok !== 1 )
12881
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12882
 
12883
            repeat( 3 )
12884
                @(posedge pci_clock) ;
12885
 
12886
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12887
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12888
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12889
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12890
 
12891
            do_pause( 1 ) ;
12892
            while ( FRAME === 0 )
12893
                @(posedge pci_clock) ;
12894
 
12895
            while ( IRDY === 0 )
12896
                @(posedge pci_clock) ;
12897
 
12898 35 mihad
            #1 ;
12899
            if ( !error_monitor_done )
12900
                disable monitor_error_event1 ;
12901 15 mihad
        end
12902
        begin:monitor_error_event1
12903 35 mihad
            error_monitor_done = 0 ;
12904 15 mihad
            @(error_event_int) ;
12905
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12906
            ok = 0 ;
12907 35 mihad
            error_monitor_done = 1 ;
12908 15 mihad
        end
12909
        join
12910
 
12911
        // increasing the starting address for PCI master and for WB transaction monitor
12912
        rd_address = rd_address + (4 * expect_length_rd) ;
12913
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12914
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12915
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12916
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12917
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12918
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12919
        for (i=0; i<expect_length_rd; i=i+1)
12920
            rd_be[3:0] = {Be[2:0], Be[3]};
12921
 
12922
        // set parameters for next read
12923
        if ( expect_length_rd2 == 1 )
12924
        begin
12925
                if (Set_prefetch_enable)
12926
                begin
12927
                    expect_length_rd1 = Cache_lsize ;
12928
                    expect_length_rd2 = 0 ;
12929
                        // If PCI behavioral master must check received DATA
12930
                        master2_check_received_data = 0 ;
12931
                            master1_check_received_data = 0 ;
12932
                end
12933
                else
12934
                begin
12935
                    expect_length_rd1 = 1 ;
12936
                    expect_length_rd2 = 0 ;
12937
                        // If PCI behavioral master must check received DATA
12938
                        master2_check_received_data = 1 ;
12939
                            master1_check_received_data = 1 ;
12940
                end
12941
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12942
            expect_length_rd  = expect_length_rd1 ;
12943
        end
12944
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12945
        begin
12946
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12947
            expect_length_rd2 = 0 ;
12948
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12949
            expect_length_rd  = expect_length_rd1 ;
12950
                        // If PCI behavioral master must check received DATA
12951
                        master2_check_received_data = 1 ;
12952
                    master1_check_received_data = 1 ;
12953
        end
12954
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12955
        begin
12956
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12957
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12958
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12959
            expect_length_rd  = expect_length_rd1 ;
12960
                        // If PCI behavioral master must check received DATA
12961
                        master2_check_received_data = 1 ;
12962
                    master1_check_received_data = 1 ;
12963
        end
12964
        else
12965
        begin
12966
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12967
            begin
12968
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12969
                expect_length_rd2 = 0 ;
12970
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12971
                expect_length_rd  = expect_length_rd1 ;
12972
                        // If PCI behavioral master must check received DATA
12973
                        master2_check_received_data = 0 ;
12974
                            master1_check_received_data = 0 ;
12975
            end
12976
            else
12977
            begin
12978
                if ( expect_length_rd2 > Cache_lsize )
12979
                begin
12980
                    expect_length_rd1 = Cache_lsize ;
12981
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12982
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12983
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12984
                    else
12985
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12986
                    expect_length_rd  = expect_length_rd1 ;
12987
                                // If PCI behavioral master must check received DATA
12988
                                master2_check_received_data = 1 ;
12989
                                    master1_check_received_data = 1 ;
12990
                end
12991
                else
12992
                begin
12993
                    expect_length_rd  = expect_length_rd2 ;
12994
                    expect_length_rd1 = Cache_lsize ;
12995
                    expect_length_rd2 = 0 ;
12996
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12997
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12998
                    else
12999
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
13000
                                        if ( expect_length_rd2 == Cache_lsize )
13001
                                begin
13002
                                        // If PCI behavioral master must check received DATA
13003
                                        master2_check_received_data = 1 ;
13004
                                            master1_check_received_data = 1 ;
13005
                                        end
13006
                                        else
13007
                                        begin
13008
                                        // If PCI behavioral master must check received DATA
13009
                                        master2_check_received_data = 0 ;
13010
                                            master1_check_received_data = 0 ;
13011
                        end
13012
                end
13013
            end
13014
        end
13015
    end
13016
    // do last read
13017
    $display("Read %d words!", expect_length_rd);
13018
 
13019
    fork
13020
    begin
13021
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13022
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13023
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13024
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
13025
 
13026
        wb_transaction_stop(expect_length_rd - 1) ;
13027
        do_pause( 1 ) ;
13028
    end
13029
    begin
13030
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
13031
 
13032
        do_pause(3) ;
13033
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13034
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13035
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13036
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13037
        do_pause(1) ;
13038
 
13039
        while ( FRAME === 0 )
13040
            @(posedge pci_clock) ;
13041
 
13042
        while ( IRDY === 0 )
13043
            @(posedge pci_clock) ;
13044
 
13045 35 mihad
        #1 ;
13046
        if ( !error_monitor_done )
13047
            disable monitor_error_event2 ;
13048 15 mihad
    end
13049
    begin:monitor_error_event2
13050 35 mihad
        error_monitor_done = 0 ;
13051 15 mihad
        @(error_event_int) ;
13052
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13053
        ok = 0 ;
13054 35 mihad
        error_monitor_done = 1 ;
13055 15 mihad
    end
13056
    join
13057
 
13058
    if ( ok )
13059
        test_ok ;
13060
 
13061
    // Check that no ERRORs were reported
13062
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
13063
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
13064
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13065
    config_read( addr_offset, 4'hF, read_data ) ;
13066
    if ( read_data[8] !== 0 )
13067
    begin
13068
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
13069
        test_fail("error status was set even though no errors occured on WB bus") ;
13070
    end
13071
    else
13072
    begin
13073
        $display("No error was signaled, as expected!");
13074
        test_ok ;
13075
    end
13076
 
13077
end // main
13078
endtask // test_normal_wr_rd
13079
 
13080
// Test erroneous write to WB slave
13081
task test_wb_error_wr;
13082
  input  [2:0]  Master_ID;
13083
  input  [PCI_BUS_DATA_RANGE:0] Address;
13084
  input  [PCI_BUS_DATA_RANGE:0] Data;
13085
  input  [3:0]  Be;
13086
  input  [2:0]  Image_num;
13087
  input  [9:0]  Set_size;
13088
  input         Set_err_and_int_report;
13089
  input         Set_wb_wait_states;
13090
  input  [1:0]  Imm_BefLast_Last_error;
13091
 
13092
  reg    [11:0] addr_offset;
13093
  reg    [31:0] read_data;
13094
  reg           continue ;
13095
  reg           ok   ;
13096
  reg    [9:0]  expect_length ;
13097
  reg    [31:0] expect_address ;
13098
  reg    [0:0]  expect_we ;
13099
  reg    [31:0] rd_address;
13100
  reg    [31:0] rd_data;
13101
  reg    [3:0]  rd_be;
13102
  integer       i ;
13103
begin:main
13104
    if (Set_err_and_int_report)
13105
    begin
13106
        // enable ERROR reporting, because error must be reported and interrupt if required!
13107
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13108
        $display(" - errors will be reported when they will occur!");
13109
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
13110
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13111
        $display(" - interrupt will be reported when error will occur!");
13112
    end
13113
    else
13114
    begin
13115
        // disable ERROR reporting, because error and interrupt must not be reported!
13116
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13117
        $display(" - errors will NOT be reported when they will occur!");
13118
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
13119
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13120
        $display(" - interrupt will NOT be reported when error will occur!");
13121
    end
13122
    // enable/disable ERROR reporting
13123
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
13124
 
13125
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13126
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
13127
    if ( ok !== 1 )
13128
    begin
13129
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13130
        test_fail("PCI Error Control and Status register could not be written") ;
13131
        disable main;
13132
    end
13133
    // enable/disable INTERRUPT reporting
13134
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13135
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
13136
    if ( ok !== 1 )
13137
    begin
13138
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
13139
        test_fail("Interrupt Control register could not be written") ;
13140
        disable main;
13141
    end
13142
 
13143
    `ifdef  ADDR_TRAN_IMPL
13144
 
13145
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
13146
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13147
    config_read( addr_offset, 4'hF, read_data ) ;
13148
    if ( read_data[2] !== 0 )
13149
    begin
13150
        $display("Address translation is set for PCI image%d!", Image_num);
13151
        // predict the address and control signals on WB bus
13152
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13153
        expect_we      = 1'b1 ; // WRITE
13154
    end
13155
    else
13156
    begin
13157
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13158
        // predict the address and control signals on WB bus
13159
        expect_address = Address ;
13160
        expect_we      = 1'b1 ; // WRITE
13161
    end
13162
 
13163
    `else
13164
 
13165
    // address translation is not implemented
13166
    $display("Address translation is NOT implemented for PCI images!");
13167
    // predict the address and control signals on WB bus
13168
    expect_address = Address ;
13169
    expect_we      = 1'b1 ; // WRITE
13170
 
13171
    `endif
13172
 
13173
    if ( Set_size > (`PCIW_DEPTH - 2) )
13174
    begin
13175
        expect_length = `PCIW_DEPTH - 2 ;
13176
    end
13177
    else
13178
    begin
13179
        expect_length = Set_size ;
13180
    end
13181
 
13182
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13183
    begin
13184
        $display("ERR termination with first data!");
13185
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13186
    end
13187
    else if (Imm_BefLast_Last_error == 1)
13188
    begin
13189
        $display("ERR termination before last data!");
13190
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13191
    end
13192
    else
13193
    begin
13194
        $display("ERR termination with last data!");
13195
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13196
    end
13197
 
13198
    // write through the PCI bridge to WB slave
13199
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13200
    fork
13201
    begin
13202
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13203
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13204
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13205
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13206
        do_pause( 1 ) ;
13207
    end
13208
    begin
13209
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13210
        begin
13211
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13212
            if ( ok !== 1 )
13213
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13214
        end
13215
        else if (Imm_BefLast_Last_error == 1)
13216
        begin
13217
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13218
            if ( ok !== 1 )
13219
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13220
        end
13221
        else
13222
        begin
13223
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13224
            if ( ok !== 1 )
13225
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13226
        end
13227
    end
13228
    begin
13229
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13230
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13231
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13232
        else if (Imm_BefLast_Last_error == 1)
13233
        begin
13234
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13235
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13236
            wb_transaction_stop(expect_length-2) ;
13237
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13238
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13239
        end
13240
        else
13241
        begin
13242
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13243
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13244
            wb_transaction_stop(expect_length-1) ;
13245
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13246
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13247
        end
13248
    end
13249
    join
13250
 
13251
    if ( ok )
13252
        test_ok ;
13253
 
13254
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13255
    begin
13256
        rd_data[31:0] = Data[31:0];
13257
        rd_address[31:0] = expect_address;
13258
        rd_be[3:0] = Be[3:0];
13259
    end
13260
    else if (Imm_BefLast_Last_error == 1)
13261
    begin
13262
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13263
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13264
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13265
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13266
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13267
        rd_be[3:0] = Be[3:0];
13268
        for (i=0; i<(expect_length-2); i=i+1)
13269
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13270
    end
13271
    else
13272
    begin
13273
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13274
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13275
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13276
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13277
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13278
        rd_be[3:0] = Be[3:0];
13279
        for (i=0; i<(expect_length-1); i=i+1)
13280
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13281
    end
13282
 
13283
    master2_check_received_data = 0 ;
13284
    master1_check_received_data = 0 ;
13285
 
13286
    // Check if ERRORs were reported
13287
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13288
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13289
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13290
 
13291
    ok = 1 ;
13292
    config_read( addr_offset, 4'hF, read_data ) ;
13293
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13294
    begin
13295
        $display("Error was signaled and reported, as expected!");
13296
        if (read_data[31:28] === rd_be)
13297
            $display("Byte enables written into P_ERR_CS register are as expected!");
13298
        else
13299
        begin
13300
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13301
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13302
            ok = 0 ;
13303
        end
13304
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13305
            $display("Bus command written into P_ERR_CS register is as expected!");
13306
        else
13307
        begin
13308
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13309
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13310
            ok = 0 ;
13311
        end
13312
 
13313
        if ( ok )
13314
            test_ok ;
13315
 
13316
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13317
 
13318
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13319
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13320
        config_read( addr_offset, 4'hF, read_data ) ;
13321
        if (read_data === rd_data)
13322
        begin
13323
            $display("Data written into P_ERR_DATA register is as expected!");
13324
            test_ok ;
13325
        end
13326
        else
13327
        begin
13328
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13329
            test_fail("PCI Erroneous Data register value was wrong") ;
13330
        end
13331
 
13332
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13333
 
13334
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13335
 
13336
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13337
        config_read( addr_offset, 4'hF, read_data ) ;
13338
        if (read_data === rd_address)
13339
        begin
13340
            $display("Address written into P_ERR_ADDR register is as expected!");
13341
            test_ok ;
13342
        end
13343
        else
13344
        begin
13345
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13346
            test_fail("PCI Erroneous Address register value was wrong") ;
13347
        end
13348
    end
13349
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13350
    begin
13351
        $display("Error was signaled and not reported, as expected!");
13352
        test_ok ;
13353
    end
13354
    else
13355
    begin
13356
        $display("Error was signaled and reported, as NOT expected!");
13357
        test_fail("Error status bit was set event though error reporting was disabled") ;
13358
    end
13359
 
13360
    // Check if Interrupts were reported
13361
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13362
 
13363
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13364
    ok = 1 ;
13365
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13366
    config_read( addr_offset, 4'hF, read_data ) ;
13367
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13368
    begin
13369
        $display("Interrupts was signaled and reported, as expected!");
13370
    end
13371
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13372
    begin
13373
        $display("Interrupts was signaled and not reported, as expected!");
13374
    end
13375
    else
13376
    begin
13377
        $display("Interrupt was signaled and reported, as NOT expected!");
13378
        test_fail("PCI Error Interrupt status was set when not expected") ;
13379
        ok = 0 ;
13380
    end
13381
 
13382
    `ifdef HOST
13383
    repeat( 4 )
13384
        @(posedge wb_clock) ;
13385
 
13386
    if ( INT_O === Set_err_and_int_report )
13387
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13388
    else
13389
    begin
13390
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13391
        test_fail("Interrupt request didn't have expected value") ;
13392
        ok = 0 ;
13393
    end
13394
 
13395
    `else // GUEST
13396
    repeat( 4 )
13397
        @(posedge pci_clock) ;
13398
 
13399
    if ( INTA === !Set_err_and_int_report )
13400
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13401
    else
13402
    begin
13403
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13404
        test_fail("Interrupt request didn't have expected value") ;
13405
        ok = 0 ;
13406
    end
13407
 
13408
    `endif
13409
 
13410
    if ( ok )
13411
        test_ok ;
13412
 
13413
    if (Set_err_and_int_report)
13414
    begin
13415
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13416
        $display("Error and Interrupt must be cleared!");
13417
        // clear  ERROR reporting bit
13418
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13419
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13420
        if ( ok !== 1 )
13421
        begin
13422
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13423
            test_fail("PCI Error Control and Status register could not be written to") ;
13424
            disable main;
13425
        end
13426
 
13427
        // clear INTERRUPT reporting bit
13428
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13429
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13430
        if ( ok !== 1 )
13431
        begin
13432
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13433
            test_fail("Interrupt Status register could not be written to") ;
13434
            disable main;
13435
        end
13436
 
13437
        test_ok ;
13438
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13439
        `ifdef HOST
13440
 
13441
        repeat(4)
13442
            @(posedge wb_clock) ;
13443
        if ( INT_O === 1'b0 )
13444
        begin
13445
            $display("Interrupt pin INT_O was correctly cleared!");
13446
            test_ok ;
13447
        end
13448
        else
13449
        begin
13450
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13451
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13452
            disable main;
13453
        end
13454
 
13455
        `else // GUEST
13456
 
13457
        repeat(4)
13458
            @(posedge pci_clock) ;
13459
        if ( INTA === 1'b1 )
13460
        begin
13461
            $display("Interrupt pin INTA was correctly cleared!");
13462
            test_ok ;
13463
        end
13464
        else
13465
        begin
13466
            $display("Interrupt pin INTA was NOT correctly cleared!");
13467
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13468
            disable main;
13469
        end
13470
 
13471
        `endif
13472
 
13473
    end
13474
    else
13475
    begin
13476
        $display("Error and Interrupt don't need to be cleared!");
13477
    end
13478
end // main
13479
endtask // test_wb_error_wr
13480
 
13481
task test_wb_error_rd;
13482
    reg    [11:0] addr_offset ;
13483
    reg    [11:0] ctrl_offset ;
13484
    reg    [11:0] ba_offset ;
13485
    reg    [11:0] am_offset ;
13486
    reg    [11:0] ta_offset ;
13487
    reg    [31:0] read_data;
13488
    reg           ok   ;
13489
    reg    [9:0]  expect_length ;
13490
    reg    [31:0] expect_address ;
13491
    reg    [0:0]  expect_we ;
13492
    reg    [31:0] rd_address;
13493
    reg    [31:0] rd_data;
13494
    reg    [3:0]  rd_be;
13495
    integer       i ;
13496
    reg           do_mem_aborts ;
13497
    reg           do_io_aborts ;
13498 35 mihad
    reg           error_monitor_done ;
13499 15 mihad
begin:main
13500
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13501
 
13502
    if ( target_mem_image !== -1 )
13503
    begin
13504
        do_mem_aborts = 1 ;
13505
 
13506
        if (target_mem_image === 1)
13507
        begin
13508
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13509
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13510
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13511
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13512
        end
13513
        else if (target_mem_image === 2)
13514
        begin
13515
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13516
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13517
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13518
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13519
        end
13520
        else if (target_mem_image === 3)
13521
        begin
13522
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13523
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13524
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13525
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13526
        end
13527
        else if (target_mem_image === 4)
13528
        begin
13529
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13530
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13531
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13532
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13533
        end
13534
        else if (target_mem_image === 5)
13535
        begin
13536
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13537
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13538
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13539
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13540
        end
13541
    end
13542
    else
13543
        do_mem_aborts = 0 ;
13544
 
13545
    if ( do_mem_aborts )
13546
    begin
13547
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13548
 
13549
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13550
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13551
        if ( ok !== 1 )
13552
        begin
13553
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13554
            test_fail("PCI Error Control and Status register could not be written") ;
13555
            disable main;
13556
        end
13557
 
13558
        // enable INTERRUPT reporting
13559
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13560
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13561
        if ( ok !== 1 )
13562
        begin
13563
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13564
            test_fail("Interrupt Control register could not be written") ;
13565
            disable main;
13566
        end
13567
 
13568
        addr_offset = 12'h010 + (4*target_mem_image) ;
13569
 
13570
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13571
        if ( ok !== 1 )
13572
        begin
13573
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13574
            test_fail("PCI Base Address register could not be written") ;
13575
            disable main;
13576
        end
13577
 
13578
        // disable address translation and enable prefetch so read bursts can be performed
13579
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13580
        if ( ok !== 1 )
13581
        begin
13582
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13583
            test_fail("PCI Image Control register could not be written") ;
13584
            disable main;
13585
        end
13586
 
13587
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13588
        if ( ok !== 1 )
13589
        begin
13590
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13591
            test_fail("PCI Address Mask register could not be written") ;
13592
            disable main;
13593
        end
13594
 
13595
        addr_offset = 12'h00C ;
13596
 
13597
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13598
        if ( ok !== 1 )
13599
        begin
13600
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13601
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13602
            disable main;
13603
        end
13604
 
13605
        // disable PCI master data checking
13606
        master1_check_received_data = 0 ;
13607
 
13608
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13609
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13610
 
13611
 
13612
        // do a single read error terminated on WB bus
13613
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13614
 
13615
        fork
13616
        begin
13617
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13618
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13619
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13620
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13621
 
13622
            do_pause( 1 ) ;
13623
        end
13624
        begin
13625
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13626
 
13627
            if ( ok !== 1 )
13628
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13629
 
13630
            do_pause(3) ;
13631
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13632
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13633
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13634
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13635
            do_pause(1) ;
13636
 
13637
            while ( FRAME === 0 )
13638
                @(posedge pci_clock) ;
13639
 
13640
            while ( IRDY === 0 )
13641
                @(posedge pci_clock) ;
13642
 
13643 35 mihad
            #1 ;
13644
            if ( !error_monitor_done )
13645
                disable monitor_error_event1 ;
13646 15 mihad
        end
13647
        begin:monitor_error_event1
13648 35 mihad
            error_monitor_done = 0 ;
13649 15 mihad
            @(error_event_int) ;
13650
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13651
            ok = 0 ;
13652 35 mihad
            error_monitor_done = 1 ;
13653 15 mihad
        end
13654
        join
13655
 
13656
        if ( ok )
13657
            test_ok ;
13658 26 mihad
 
13659
        @(posedge pci_clock) ;
13660
        @(posedge pci_clock) ;
13661
        @(posedge wb_clock) ;
13662
        @(posedge wb_clock) ;
13663 15 mihad
 
13664
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13665
        addr_offset = 12'h004 ;
13666
        config_read(addr_offset, 4'hF, read_data) ;
13667
        ok = 1 ;
13668
        if ( read_data[27] !== 1 )
13669
        begin
13670
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13671
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13672
            ok = 0 ;
13673
        end
13674
        if ( read_data[28] !== 0 )
13675
        begin
13676
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13677
            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") ;
13678
            ok = 0 ;
13679
        end
13680
        if ( read_data[29] !== 0 )
13681
        begin
13682
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13683
            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") ;
13684
            ok = 0 ;
13685
        end
13686
 
13687
        // clear statuses
13688
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13689
        if ( !ok )
13690
        begin
13691
            test_fail("write to PCI Device Status register failed") ;
13692
            $display("Couldn't write PCI Device Status register") ;
13693
            disable main ;
13694
        end
13695
 
13696
        if ( ok )
13697
            test_ok ;
13698
 
13699
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13700
 
13701
        ok = 1 ;
13702
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13703
 
13704
        config_read(addr_offset, 4'hF, read_data) ;
13705
        if (read_data[8] !== 0)
13706
        begin
13707
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13708
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13709
            ok = 0 ;
13710
        end
13711
        else
13712
            test_ok ;
13713
 
13714
        if ( ok !== 1 )
13715
        begin
13716
            config_write(addr_offset, read_data, 4'hF, ok) ;
13717
            if ( !ok )
13718
            begin
13719
                test_fail("PCI Error Control and Status register could not be written") ;
13720
                disable main ;
13721
            end
13722
        end
13723
 
13724
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13725
        fork
13726
        begin
13727
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13728
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13729
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13730
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13731
 
13732
            do_pause( 1 ) ;
13733
        end
13734
        begin
13735
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13736
 
13737
            if ( ok !== 1 )
13738
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13739
 
13740
            do_pause(3) ;
13741
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13742
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13743
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13744
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13745
            do_pause(1) ;
13746
 
13747
            while ( FRAME === 0 )
13748
                @(posedge pci_clock) ;
13749
 
13750
            while ( IRDY === 0 )
13751
                @(posedge pci_clock) ;
13752
 
13753 35 mihad
            #1 ;
13754
            if ( !error_monitor_done )
13755
                disable monitor_error_event2 ;
13756 15 mihad
        end
13757
        begin:monitor_error_event2
13758 35 mihad
            error_monitor_done = 0 ;
13759 15 mihad
            @(error_event_int) ;
13760
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13761
            ok = 0 ;
13762 35 mihad
            error_monitor_done = 1 ;
13763 15 mihad
        end
13764
        join
13765
 
13766
        if ( ok )
13767
            test_ok ;
13768
 
13769 26 mihad
        @(posedge pci_clock) ;
13770
        @(posedge pci_clock) ;
13771
        @(posedge wb_clock) ;
13772
        @(posedge wb_clock) ;
13773
 
13774 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13775
        addr_offset = 12'h004 ;
13776
        config_read(addr_offset, 4'hF, read_data) ;
13777
        ok = 1 ;
13778
        if ( read_data[27] !== 1 )
13779
        begin
13780
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13781
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13782
            ok = 0 ;
13783
        end
13784
        if ( read_data[28] !== 0 )
13785
        begin
13786
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13787
            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") ;
13788
            ok = 0 ;
13789
        end
13790
        if ( read_data[29] !== 0 )
13791
        begin
13792
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13793
            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") ;
13794
            ok = 0 ;
13795
        end
13796
 
13797
        // clear statuses
13798
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13799
        if ( !ok )
13800
        begin
13801
            test_fail("write to PCI Device Status register failed") ;
13802
            $display("Couldn't write PCI Device Status register") ;
13803
            disable main ;
13804
        end
13805
 
13806
        if ( ok )
13807
            test_ok ;
13808
 
13809
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13810
 
13811
        ok = 1 ;
13812
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13813
 
13814
        config_read(addr_offset, 4'hF, read_data) ;
13815
        if (read_data[8] !== 0)
13816
        begin
13817
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13818
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13819
            ok = 0 ;
13820
        end
13821
        else
13822
            test_ok ;
13823
 
13824
        if ( ok !== 1 )
13825
        begin
13826
            config_write(addr_offset, read_data, 4'hF, ok) ;
13827
            if ( !ok )
13828
            begin
13829
                test_fail("PCI Error Control and Status register could not be written") ;
13830
                disable main ;
13831
            end
13832
        end
13833
 
13834
        // do a single read error terminated on WB bus
13835
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13836
 
13837
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13838
 
13839
        fork
13840
        begin
13841
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13842
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13843
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13844
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13845
 
13846
            do_pause( 1 ) ;
13847
        end
13848
        begin
13849
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13850
 
13851
            if ( ok !== 1 )
13852
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13853
 
13854
            do_pause(3) ;
13855
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13856
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13857
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13858
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13859
            do_pause(1) ;
13860
 
13861
            while ( FRAME === 0 )
13862
                @(posedge pci_clock) ;
13863
 
13864
            while ( IRDY === 0 )
13865
                @(posedge pci_clock) ;
13866
 
13867 35 mihad
            if ( !error_monitor_done )
13868
                disable monitor_error_event3 ;
13869 15 mihad
        end
13870
        begin:monitor_error_event3
13871 35 mihad
            error_monitor_done = 0 ;
13872 15 mihad
            @(error_event_int) ;
13873
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13874
            ok = 0 ;
13875 35 mihad
            error_monitor_done = 1 ;
13876 15 mihad
        end
13877
        join
13878
 
13879
        if ( ok )
13880
            test_ok ;
13881
 
13882 26 mihad
        @(posedge pci_clock) ;
13883
        @(posedge pci_clock) ;
13884
        @(posedge wb_clock) ;
13885
        @(posedge wb_clock) ;
13886
 
13887 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13888
        addr_offset = 12'h004 ;
13889
        config_read(addr_offset, 4'hF, read_data) ;
13890
        ok = 1 ;
13891
        if ( read_data[27] !== 1 )
13892
        begin
13893
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13894
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13895
            ok = 0 ;
13896
        end
13897
        if ( read_data[28] !== 0 )
13898
        begin
13899
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13900
            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") ;
13901
            ok = 0 ;
13902
        end
13903
        if ( read_data[29] !== 0 )
13904
        begin
13905
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13906
            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") ;
13907
            ok = 0 ;
13908
        end
13909
 
13910
        // clear statuses
13911
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13912
        if ( !ok )
13913
        begin
13914
            test_fail("write to PCI Device Status register failed") ;
13915
            $display("Couldn't write PCI Device Status register") ;
13916
            disable main ;
13917
        end
13918
 
13919
        if ( ok )
13920
            test_ok ;
13921
 
13922
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13923
 
13924
        ok = 1 ;
13925
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13926
 
13927
        config_read(addr_offset, 4'hF, read_data) ;
13928
        if (read_data[8] !== 0)
13929
        begin
13930
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13931
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13932
            ok = 0 ;
13933
        end
13934
        else
13935
            test_ok ;
13936
 
13937
        if ( ok !== 1 )
13938
        begin
13939
            config_write(addr_offset, read_data, 4'hF, ok) ;
13940
            if ( !ok )
13941
            begin
13942
                test_fail("PCI Error Control and Status register could not be written") ;
13943
                disable main ;
13944
            end
13945
        end
13946
 
13947
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13948
 
13949
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13950
 
13951
        fork
13952
        begin
13953
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13954
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13955
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13956
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13957
 
13958
            do_pause( 1 ) ;
13959
        end
13960
        begin
13961
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13962
 
13963
            if ( ok !== 1 )
13964
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13965
 
13966
            do_pause(3) ;
13967
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13968
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13969
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13970
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13971
            do_pause(1) ;
13972
 
13973
            while ( FRAME === 0 )
13974
                @(posedge pci_clock) ;
13975
 
13976
            while ( IRDY === 0 )
13977
                @(posedge pci_clock) ;
13978
 
13979 35 mihad
            #1 ;
13980
            if ( !error_monitor_done )
13981
                disable monitor_error_event4 ;
13982 15 mihad
        end
13983
        begin:monitor_error_event4
13984 35 mihad
            error_monitor_done = 0 ;
13985 15 mihad
            @(error_event_int) ;
13986
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13987
            ok = 0 ;
13988 35 mihad
            error_monitor_done = 1 ;
13989 15 mihad
        end
13990
        begin
13991
            wb_transaction_stop( 1 ) ;
13992
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13993
        end
13994
        join
13995
 
13996
        if ( ok )
13997
            test_ok ;
13998
 
13999 26 mihad
        @(posedge pci_clock) ;
14000
        @(posedge pci_clock) ;
14001
        @(posedge wb_clock) ;
14002
        @(posedge wb_clock) ;
14003
 
14004 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14005
        addr_offset = 12'h004 ;
14006
        config_read(addr_offset, 4'hF, read_data) ;
14007
        ok = 1 ;
14008
        if ( read_data[27] !== 1 )
14009
        begin
14010
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14011
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14012
            ok = 0 ;
14013
        end
14014
        if ( read_data[28] !== 0 )
14015
        begin
14016
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14017
            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") ;
14018
            ok = 0 ;
14019
        end
14020
        if ( read_data[29] !== 0 )
14021
        begin
14022
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14023
            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") ;
14024
            ok = 0 ;
14025
        end
14026
 
14027
        // clear statuses
14028
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14029
        if ( !ok )
14030
        begin
14031
            test_fail("write to PCI Device Status register failed") ;
14032
            $display("Couldn't write PCI Device Status register") ;
14033
            disable main ;
14034
        end
14035
 
14036
        if ( ok )
14037
            test_ok ;
14038
 
14039
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14040
 
14041
        ok = 1 ;
14042
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14043
 
14044
        config_read(addr_offset, 4'hF, read_data) ;
14045
        if (read_data[8] !== 0)
14046
        begin
14047
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14048
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14049
            ok = 0 ;
14050
        end
14051
        else
14052
            test_ok ;
14053
 
14054
        if ( ok !== 1 )
14055
        begin
14056
            config_write(addr_offset, read_data, 4'hF, ok) ;
14057
            if ( !ok )
14058
            begin
14059
                test_fail("PCI Error Control and Status register could not be written") ;
14060
                disable main ;
14061
            end
14062
        end
14063
 
14064
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14065
 
14066
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14067
 
14068
        fork
14069
        begin
14070
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14071
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14072
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14073
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14074
 
14075
            do_pause( 1 ) ;
14076
        end
14077
        begin
14078
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14079
 
14080
            if ( ok !== 1 )
14081
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14082
 
14083
            do_pause(3) ;
14084
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14085
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14086
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14087
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14088
            do_pause(1) ;
14089
 
14090
            while ( FRAME === 0 )
14091
                @(posedge pci_clock) ;
14092
 
14093
            while ( IRDY === 0 )
14094
                @(posedge pci_clock) ;
14095
 
14096 35 mihad
            #1 ;
14097
            if ( !error_monitor_done )
14098
                disable monitor_error_event5 ;
14099 15 mihad
        end
14100
        begin:monitor_error_event5
14101 35 mihad
            error_monitor_done = 0 ;
14102 15 mihad
            @(error_event_int) ;
14103
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14104
            ok = 0 ;
14105 35 mihad
            error_monitor_done = 1 ;
14106 15 mihad
        end
14107
        begin
14108
            wb_transaction_stop( 3 ) ;
14109
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14110
        end
14111
        join
14112
 
14113
        if ( ok )
14114
            test_ok ;
14115
 
14116 26 mihad
        @(posedge pci_clock) ;
14117
        @(posedge pci_clock) ;
14118
        @(posedge wb_clock) ;
14119
        @(posedge wb_clock) ;
14120
 
14121 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14122
        addr_offset = 12'h004 ;
14123
        config_read(addr_offset, 4'hF, read_data) ;
14124
        ok = 1 ;
14125
        if ( read_data[27] !== 1 )
14126
        begin
14127
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14128
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14129
            ok = 0 ;
14130
        end
14131
        if ( read_data[28] !== 0 )
14132
        begin
14133
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14134
            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") ;
14135
            ok = 0 ;
14136
        end
14137
        if ( read_data[29] !== 0 )
14138
        begin
14139
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14140
            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") ;
14141
            ok = 0 ;
14142
        end
14143
 
14144
        // clear statuses
14145
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14146
        if ( !ok )
14147
        begin
14148
            test_fail("write to PCI Device Status register failed") ;
14149
            $display("Couldn't write PCI Device Status register") ;
14150
            disable main ;
14151
        end
14152
 
14153
        if ( ok )
14154
            test_ok ;
14155
 
14156
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14157
 
14158
        ok = 1 ;
14159
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14160
 
14161
        config_read(addr_offset, 4'hF, read_data) ;
14162
        if (read_data[8] !== 0)
14163
        begin
14164
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14165
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14166
            ok = 0 ;
14167
        end
14168
        else
14169
            test_ok ;
14170
 
14171
        if ( ok !== 1 )
14172
        begin
14173
            config_write(addr_offset, read_data, 4'hF, ok) ;
14174
            if ( !ok )
14175
            begin
14176
                test_fail("PCI Error Control and Status register could not be written") ;
14177
                disable main ;
14178
            end
14179
        end
14180
 
14181
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14182
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14183
        fork
14184
        begin
14185
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14186
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14187
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14188
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14189
 
14190
            do_pause( 1 ) ;
14191
        end
14192
        begin
14193
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14194
 
14195
            if ( ok !== 1 )
14196
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14197
 
14198
            do_pause(3) ;
14199
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14200
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14201
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14202
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14203
            do_pause(1) ;
14204
 
14205
            while ( FRAME === 0 )
14206
                @(posedge pci_clock) ;
14207
 
14208
            while ( IRDY === 0 )
14209
                @(posedge pci_clock) ;
14210
 
14211 35 mihad
            #1 ;
14212
            if ( !error_monitor_done )
14213
                disable monitor_error_event6 ;
14214 15 mihad
        end
14215
        begin:monitor_error_event6
14216 35 mihad
            error_monitor_done = 0 ;
14217 15 mihad
            @(error_event_int) ;
14218
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14219
            ok = 0 ;
14220 35 mihad
            error_monitor_done = 1 ;
14221 15 mihad
        end
14222
        begin
14223
            wb_transaction_stop( 3 ) ;
14224
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14225
        end
14226
        join
14227
 
14228
        if ( ok )
14229
            test_ok ;
14230
 
14231 26 mihad
        @(posedge pci_clock) ;
14232
        @(posedge pci_clock) ;
14233
        @(posedge wb_clock) ;
14234
        @(posedge wb_clock) ;
14235
 
14236 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14237
        addr_offset = 12'h004 ;
14238
        config_read(addr_offset, 4'hF, read_data) ;
14239
        ok = 1 ;
14240
        if ( read_data[27] !== 1 )
14241
        begin
14242
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14243
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14244
            ok = 0 ;
14245
        end
14246
        if ( read_data[28] !== 0 )
14247
        begin
14248
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14249
            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") ;
14250
            ok = 0 ;
14251
        end
14252
        if ( read_data[29] !== 0 )
14253
        begin
14254
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14255
            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") ;
14256
            ok = 0 ;
14257
        end
14258
 
14259
        // clear statuses
14260
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14261
        if ( !ok )
14262
        begin
14263
            test_fail("write to PCI Device Status register failed") ;
14264
            $display("Couldn't write PCI Device Status register") ;
14265
            disable main ;
14266
        end
14267
 
14268
        if ( ok )
14269
            test_ok ;
14270
 
14271
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14272
 
14273
        ok = 1 ;
14274
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14275
 
14276
        config_read(addr_offset, 4'hF, read_data) ;
14277
        if (read_data[8] !== 0)
14278
        begin
14279
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14280
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14281
            ok = 0 ;
14282
        end
14283
        else
14284
            test_ok ;
14285
 
14286
        if ( ok !== 1 )
14287
        begin
14288
            config_write(addr_offset, read_data, 4'hF, ok) ;
14289
            if ( !ok )
14290
            begin
14291
                test_fail("PCI Error Control and Status register could not be written") ;
14292
                disable main ;
14293
            end
14294
        end
14295
 
14296
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14297
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14298
        fork
14299
        begin
14300
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14301
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14302
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14303
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14304
 
14305
            do_pause( 1 ) ;
14306
        end
14307
        begin
14308
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14309
 
14310
            if ( ok !== 1 )
14311
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14312
 
14313
            do_pause(3) ;
14314
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14315
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14316
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14317
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14318
            do_pause(1) ;
14319
 
14320
            while ( FRAME === 0 )
14321
                @(posedge pci_clock) ;
14322
 
14323
            while ( IRDY === 0 )
14324
                @(posedge pci_clock) ;
14325
 
14326 35 mihad
            #1 ;
14327
            if ( !error_monitor_done )
14328
                disable monitor_error_event7 ;
14329 15 mihad
        end
14330
        begin:monitor_error_event7
14331 35 mihad
            error_monitor_done = 0 ;
14332 15 mihad
            @(error_event_int) ;
14333
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14334
            ok = 0 ;
14335 35 mihad
            error_monitor_done = 1 ;
14336 15 mihad
        end
14337
        begin
14338
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14339
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14340
        end
14341
        join
14342
 
14343
        if ( ok )
14344
            test_ok ;
14345
 
14346 26 mihad
        @(posedge pci_clock) ;
14347
        @(posedge pci_clock) ;
14348
        @(posedge wb_clock) ;
14349
        @(posedge wb_clock) ;
14350
 
14351 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14352
        addr_offset = 12'h004 ;
14353
        config_read(addr_offset, 4'hF, read_data) ;
14354
        ok = 1 ;
14355
        if ( read_data[27] !== 1 )
14356
        begin
14357
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14358
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14359
            ok = 0 ;
14360
        end
14361
        if ( read_data[28] !== 0 )
14362
        begin
14363
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14364
            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") ;
14365
            ok = 0 ;
14366
        end
14367
        if ( read_data[29] !== 0 )
14368
        begin
14369
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14370
            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") ;
14371
            ok = 0 ;
14372
        end
14373
 
14374
        // clear statuses
14375
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14376
        if ( !ok )
14377
        begin
14378
            test_fail("write to PCI Device Status register failed") ;
14379
            $display("Couldn't write PCI Device Status register") ;
14380
            disable main ;
14381
        end
14382
 
14383
        if ( ok )
14384
            test_ok ;
14385
 
14386
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14387
 
14388
        ok = 1 ;
14389
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14390
 
14391
        config_read(addr_offset, 4'hF, read_data) ;
14392
        if (read_data[8] !== 0)
14393
        begin
14394
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14395
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14396
            ok = 0 ;
14397
        end
14398
        else
14399
            test_ok ;
14400
 
14401
        if ( ok !== 1 )
14402
        begin
14403
            config_write(addr_offset, read_data, 4'hF, ok) ;
14404
            if ( !ok )
14405
            begin
14406
                test_fail("PCI Error Control and Status register could not be written") ;
14407
                disable main ;
14408
            end
14409
        end
14410
 
14411
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14412
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14413
        fork
14414
        begin
14415
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14416
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14417
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14418
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14419
 
14420
            do_pause( 1 ) ;
14421
        end
14422
        begin
14423
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14424
 
14425
            if ( ok !== 1 )
14426
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14427
 
14428
            do_pause(3) ;
14429
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14430
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14431
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14432
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14433
            do_pause(1) ;
14434
 
14435
            while ( FRAME === 0 )
14436
                @(posedge pci_clock) ;
14437
 
14438
            while ( IRDY === 0 )
14439
                @(posedge pci_clock) ;
14440
 
14441 35 mihad
            #1 ;
14442
            if ( !error_monitor_done )
14443
                disable monitor_error_event8 ;
14444 15 mihad
        end
14445
        begin:monitor_error_event8
14446 35 mihad
            error_monitor_done = 0 ;
14447 15 mihad
            @(error_event_int) ;
14448
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14449
            ok = 0 ;
14450 35 mihad
            error_monitor_done = 1 ;
14451 15 mihad
        end
14452
        begin
14453
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14454
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14455
        end
14456
        join
14457
 
14458
        if ( ok )
14459
            test_ok ;
14460
 
14461 26 mihad
        @(posedge pci_clock) ;
14462
        @(posedge pci_clock) ;
14463
        @(posedge wb_clock) ;
14464
        @(posedge wb_clock) ;
14465
 
14466 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14467
 
14468
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14469
        addr_offset = 12'h004 ;
14470
        config_read(addr_offset, 4'hF, read_data) ;
14471
        ok = 1 ;
14472
        if ( read_data[27] !== 1 )
14473
        begin
14474
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14475
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14476
            ok = 0 ;
14477
        end
14478
        if ( read_data[28] !== 0 )
14479
        begin
14480
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14481
            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") ;
14482
            ok = 0 ;
14483
        end
14484
        if ( read_data[29] !== 0 )
14485
        begin
14486
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14487
            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") ;
14488
            ok = 0 ;
14489
        end
14490
 
14491
        // clear statuses
14492
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14493
        if ( !ok )
14494
        begin
14495
            test_fail("write to PCI Device Status register failed") ;
14496
            $display("Couldn't write PCI Device Status register") ;
14497
            disable main ;
14498
        end
14499
 
14500
        if ( ok )
14501
            test_ok ;
14502
 
14503
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14504
 
14505
        ok = 1 ;
14506
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14507
 
14508
        config_read(addr_offset, 4'hF, read_data) ;
14509
        if (read_data[8] !== 0)
14510
        begin
14511
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14512
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14513
            ok = 0 ;
14514
        end
14515
        else
14516
            test_ok ;
14517
 
14518
        if ( ok !== 1 )
14519
        begin
14520
            config_write(addr_offset, read_data, 4'hF, ok) ;
14521
            if ( !ok )
14522
            begin
14523
                test_fail("PCI Error Control and Status register could not be written") ;
14524
                disable main ;
14525
            end
14526
        end
14527
 
14528
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14529
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14530
        fork
14531
        begin
14532
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14533
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14534
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14535
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14536
 
14537
            do_pause( 1 ) ;
14538
        end
14539
        begin
14540
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14541
 
14542
            if ( ok !== 1 )
14543
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14544
 
14545
            do_pause(3) ;
14546
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14547
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14548
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14549
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14550
            do_pause(1) ;
14551
 
14552
            while ( FRAME === 0 )
14553
                @(posedge pci_clock) ;
14554
 
14555
            while ( IRDY === 0 )
14556
                @(posedge pci_clock) ;
14557
 
14558 35 mihad
            #1 ;
14559
            if ( !error_monitor_done )
14560
                disable monitor_error_event9 ;
14561 15 mihad
        end
14562
        begin:monitor_error_event9
14563 35 mihad
            error_monitor_done = 0 ;
14564 15 mihad
            @(error_event_int) ;
14565
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14566
            ok = 0 ;
14567 35 mihad
            error_monitor_done = 1 ;
14568 15 mihad
        end
14569
        begin
14570
            wb_transaction_stop( 3 ) ;
14571
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14572
        end
14573
        join
14574
 
14575
        if ( ok )
14576
            test_ok ;
14577
 
14578
        // now check all other statuses too
14579
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14580
        ok = 1 ;
14581
 
14582
        addr_offset = 12'h004 ;
14583
        config_read(addr_offset, 4'hF, read_data) ;
14584
        if (read_data[31] !== 0)
14585
        begin
14586
            $display("Detected Parity Error bit set for no reason") ;
14587
            test_fail("Detected Parity Error bit was set for no reason") ;
14588
            ok = 0 ;
14589
        end
14590
 
14591
        if (read_data[30] !== 0)
14592
        begin
14593
            $display("Signaled System Error bit set for no reason") ;
14594
            test_fail("Signaled System Error bit was set for no reason") ;
14595
            ok = 0 ;
14596
        end
14597
 
14598
        if (read_data[29] !== 0)
14599
        begin
14600
            $display("Received Master Abort bit set for no reason") ;
14601
            test_fail("Received Master Abort bit was set for no reason") ;
14602
            ok = 0 ;
14603
        end
14604
 
14605
        if (read_data[28] !== 0)
14606
        begin
14607
            $display("Received Target Abort bit set for no reason");
14608
            test_fail("Received Target Abort bit was set for no reason") ;
14609
            ok = 0 ;
14610
        end
14611
 
14612
        if (read_data[27] !== 0)
14613
        begin
14614
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14615
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14616
            ok = 0 ;
14617
        end
14618
 
14619
        if (read_data[24] !== 0)
14620
        begin
14621
            $display("Master Data Parity Error bit set for no reason") ;
14622
            test_fail("Master Data Parity Error bit was set for no reason") ;
14623
            ok = 0 ;
14624
        end
14625
 
14626
        if ( ok )
14627
            test_ok ;
14628
 
14629
        test_name = "DISABLE IMAGE" ;
14630 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14631 15 mihad
        if ( ok !== 1 )
14632
        begin
14633
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14634
            test_fail("PCI Address Mask register could not be written") ;
14635
            disable main;
14636
        end
14637
    end
14638
 
14639
    if ( target_io_image !== -1 )
14640
    begin
14641
        do_io_aborts = 1 ;
14642
 
14643
        if (target_io_image === 1)
14644
        begin
14645
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14646
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14647
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14648
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14649
        end
14650
        else if (target_io_image === 2)
14651
        begin
14652
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14653
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14654
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14655
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14656
        end
14657
        else if (target_io_image === 3)
14658
        begin
14659
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14660
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14661
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14662
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14663
        end
14664
        else if (target_io_image === 4)
14665
        begin
14666
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14667
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14668
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14669
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14670
        end
14671
        else if (target_io_image === 5)
14672
        begin
14673
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14674
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14675
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14676
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14677
        end
14678
    end
14679
    else
14680
        do_io_aborts = 0 ;
14681
 
14682
    if ( do_io_aborts )
14683
    begin
14684
 
14685
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14686
 
14687
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14688
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14689
        if ( ok !== 1 )
14690
        begin
14691
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14692
            test_fail("PCI Error Control and Status register could not be written") ;
14693
            disable main;
14694
        end
14695
 
14696
        // enable INTERRUPT reporting
14697
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14698
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14699
        if ( ok !== 1 )
14700
        begin
14701
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14702
            test_fail("Interrupt Control register could not be written") ;
14703
            disable main;
14704
        end
14705
 
14706
        addr_offset = 12'h010 + (4*target_io_image) ;
14707
 
14708
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14709
        if ( ok !== 1 )
14710
        begin
14711
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14712
            test_fail("PCI Base Address register could not be written") ;
14713
            disable main;
14714
        end
14715
 
14716
        // disable address translation and enable prefetch so read bursts can be performed
14717
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14718
        if ( ok !== 1 )
14719
        begin
14720
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14721
            test_fail("PCI Image Control register could not be written") ;
14722
            disable main;
14723
        end
14724
 
14725
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14726
        if ( ok !== 1 )
14727
        begin
14728
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14729
            test_fail("PCI Address Mask register could not be written") ;
14730
            disable main;
14731
        end
14732
 
14733
        addr_offset = 12'h00C ;
14734
 
14735
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14736
        if ( ok !== 1 )
14737
        begin
14738
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14739
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14740
            disable main;
14741
        end
14742
 
14743
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14744
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14745
 
14746
        // do a single read error terminated on WB bus
14747
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14748
 
14749
        fork
14750
        begin
14751
            PCIU_IO_READ
14752
             (
14753
                `Test_Master_1,
14754
                Target_Base_Addr_R[target_io_image],
14755
                32'hAAAA_5555,
14756
                4'h0,
14757
                1,
14758
                `Test_Target_Retry_On
14759
             );
14760
 
14761
            do_pause( 1 ) ;
14762
        end
14763
        begin
14764
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14765
 
14766
            if ( ok !== 1 )
14767
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14768
 
14769
            do_pause(3) ;
14770
 
14771
            PCIU_IO_READ
14772
             (
14773
                `Test_Master_1,
14774
                Target_Base_Addr_R[target_io_image],
14775
                32'hAAAA_5555,
14776
                4'h0,
14777
                1,
14778
                `Test_Target_Abort_On
14779
             );
14780
 
14781
            do_pause( 1 ) ;
14782
 
14783
            while ( FRAME === 0 )
14784
                @(posedge pci_clock) ;
14785
 
14786
            while ( IRDY === 0 )
14787
                @(posedge pci_clock) ;
14788
 
14789 35 mihad
            #1 ;
14790
            if ( !error_monitor_done )
14791
                disable monitor_error_event10 ;
14792 15 mihad
        end
14793
        begin:monitor_error_event10
14794 35 mihad
            error_monitor_done = 0 ;
14795 15 mihad
            @(error_event_int) ;
14796
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14797
            ok = 0 ;
14798 35 mihad
            error_monitor_done = 1 ;
14799 15 mihad
        end
14800
        join
14801
 
14802
        if ( ok )
14803
            test_ok ;
14804
 
14805 26 mihad
        @(posedge pci_clock) ;
14806
        @(posedge pci_clock) ;
14807
        @(posedge wb_clock) ;
14808
        @(posedge wb_clock) ;
14809
 
14810 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14811
        addr_offset = 12'h004 ;
14812
        config_read(addr_offset, 4'hF, read_data) ;
14813
        ok = 1 ;
14814
        if ( read_data[27] !== 1 )
14815
        begin
14816
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14817
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14818
            ok = 0 ;
14819
        end
14820
        if ( read_data[28] !== 0 )
14821
        begin
14822
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14823
            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") ;
14824
            ok = 0 ;
14825
        end
14826
        if ( read_data[29] !== 0 )
14827
        begin
14828
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14829
            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") ;
14830
            ok = 0 ;
14831
        end
14832
 
14833
        // clear statuses
14834
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14835
        if ( !ok )
14836
        begin
14837
            test_fail("write to PCI Device Status register failed") ;
14838
            $display("Couldn't write PCI Device Status register") ;
14839
            disable main ;
14840
        end
14841
 
14842
        if ( ok )
14843
            test_ok ;
14844
 
14845
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14846
 
14847
        ok = 1 ;
14848
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14849
 
14850
        config_read(addr_offset, 4'hF, read_data) ;
14851
        if (read_data[8] !== 0)
14852
        begin
14853
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14854
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14855
            ok = 0 ;
14856
        end
14857
        else
14858
            test_ok ;
14859
 
14860
        if ( ok !== 1 )
14861
        begin
14862
            config_write(addr_offset, read_data, 4'hF, ok) ;
14863
            if ( !ok )
14864
            begin
14865
                test_fail("PCI Error Control and Status register could not be written") ;
14866
                disable main ;
14867
            end
14868
        end
14869
 
14870
        test_name = "DISABLE IMAGE" ;
14871 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14872 15 mihad
        if ( ok !== 1 )
14873
        begin
14874
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14875
            test_fail("PCI Address Mask register could not be written") ;
14876
            disable main;
14877
        end
14878
 
14879
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14880
 
14881
    end
14882
end // main
14883
endtask // test_wb_error_rd
14884
 
14885
task test_target_abort ;
14886
    input [2:0]  image_num ;
14887
    reg   [11:0] pci_ctrl_offset ;
14888
    reg   [11:0] ctrl_offset ;
14889
    reg   [11:0] ba_offset ;
14890
    reg   [11:0] am_offset ;
14891
    reg   [11:0] ta_offset ;
14892
    reg   [31:0] pci_address ;
14893
    reg   [3:0]  byte_enables ;
14894
    reg          ok ;
14895 35 mihad
    reg          error_monitor_done ;
14896 15 mihad
begin:main
14897
    pci_ctrl_offset = 12'h4 ;
14898
    if (image_num === 0)
14899
    begin
14900
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14901
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14902
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14903
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14904
    end
14905
    else if (image_num === 1)
14906
    begin
14907
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14908
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14909
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14910
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14911
    end
14912
    else if (image_num === 2)
14913
    begin
14914
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14915
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14916
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14917
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14918
    end
14919
    else if (image_num === 3)
14920
    begin
14921
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14922
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14923
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14924
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14925
    end
14926
    else if (image_num === 4)
14927
    begin
14928
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14929
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14930
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14931
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14932
    end
14933
    else if (image_num === 5)
14934
    begin
14935
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14936
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14937
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14938
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14939
    end
14940
 
14941
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14942
 
14943
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14944
    if ( ok !== 1 )
14945
    begin
14946
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14947
        test_fail("PCI Base Address register could not be written") ;
14948
        disable main ;
14949
    end
14950
 
14951
    // Set Address Mask of IMAGE
14952
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14953
    if ( ok !== 1 )
14954
    begin
14955
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14956
        test_fail("PCI Address Mask register could not be written") ;
14957
        disable main ;
14958
    end
14959
 
14960
    // Set Translation Address of IMAGE
14961
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14962
    if ( ok !== 1 )
14963
    begin
14964
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14965
        test_fail("PCI Translation Address Register could not be written") ;
14966
        disable main ;
14967
    end
14968
 
14969
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14970
    if ( ok !== 1 )
14971
    begin
14972
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14973
        test_fail("PCI Image Control register could not be written") ;
14974
        disable main ;
14975
    end
14976
 
14977
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14978
 
14979
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14980
 
14981
    pci_address  = Target_Base_Addr_R[image_num] ;
14982
    byte_enables = 4'b0001 ;
14983
 
14984
    fork
14985
    begin
14986
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14987
        do_pause ( 1 ) ;
14988
    end
14989
    begin:monitor_error_event1
14990 35 mihad
        error_monitor_done = 0 ;
14991 15 mihad
        @(error_event_int) ;
14992
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14993
        ok = 0 ;
14994 35 mihad
        error_monitor_done = 1 ;
14995 15 mihad
    end
14996
    begin
14997
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14998
        @(posedge pci_clock) ;
14999 35 mihad
        #1 ;
15000
        if ( !error_monitor_done )
15001
            disable monitor_error_event1 ;
15002 15 mihad
    end
15003
    join
15004
 
15005
    if ( ok )
15006
        test_ok ;
15007
 
15008
    ok = 1 ;
15009
 
15010
    fork
15011
    begin
15012
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15013
        do_pause ( 1 ) ;
15014
    end
15015
    begin:monitor_error_event2
15016 35 mihad
        error_monitor_done = 0 ;
15017 15 mihad
        @(error_event_int) ;
15018
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15019
        ok = 0 ;
15020 35 mihad
        error_monitor_done = 1 ;
15021 15 mihad
    end
15022
    begin
15023
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15024
        @(posedge pci_clock) ;
15025 35 mihad
        #1 ;
15026
        if ( !error_monitor_done )
15027
            disable monitor_error_event2 ;
15028 15 mihad
    end
15029
    join
15030
 
15031
    if ( ok )
15032
        test_ok ;
15033
 
15034
    ok = 1 ;
15035
 
15036
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
15037
    byte_enables = 4'b0011 ;
15038
 
15039
    fork
15040
    begin
15041
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15042
        do_pause ( 1 ) ;
15043
    end
15044
    begin:monitor_error_event3
15045 35 mihad
        error_monitor_done = 0 ;
15046 15 mihad
        @(error_event_int) ;
15047
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15048
        ok = 0 ;
15049 35 mihad
        error_monitor_done = 1 ;
15050 15 mihad
    end
15051
    begin
15052
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15053
        @(posedge pci_clock) ;
15054 35 mihad
        if ( !error_monitor_done )
15055
            disable monitor_error_event3 ;
15056 15 mihad
    end
15057
    join
15058
 
15059
    if ( ok )
15060
        test_ok ;
15061
 
15062
    ok = 1 ;
15063
 
15064
    byte_enables = 4'b0000 ;
15065
 
15066
    fork
15067
    begin
15068
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15069
        do_pause ( 1 ) ;
15070
    end
15071
    begin:monitor_error_event4
15072 35 mihad
        error_monitor_done = 0 ;
15073 15 mihad
        @(error_event_int) ;
15074
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15075
        ok = 0 ;
15076 35 mihad
        error_monitor_done = 1 ;
15077 15 mihad
    end
15078
    begin
15079
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15080
        @(posedge pci_clock) ;
15081 35 mihad
        #1 ;
15082
        if ( !error_monitor_done )
15083
            disable monitor_error_event4 ;
15084 15 mihad
    end
15085
    join
15086
 
15087
    if ( ok )
15088
        test_ok ;
15089
 
15090
    ok = 1 ;
15091
 
15092
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
15093
    byte_enables = 4'b0111 ;
15094
 
15095
    fork
15096
    begin
15097
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15098
        do_pause ( 1 ) ;
15099
    end
15100
    begin:monitor_error_event5
15101 35 mihad
        error_monitor_done = 0 ;
15102 15 mihad
        @(error_event_int) ;
15103
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15104
        ok = 0 ;
15105 35 mihad
        error_monitor_done = 1 ;
15106 15 mihad
    end
15107
    begin
15108
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15109
        @(posedge pci_clock) ;
15110 35 mihad
        #1 ;
15111
        if ( !error_monitor_done )
15112
            disable monitor_error_event5 ;
15113 15 mihad
    end
15114
    join
15115
 
15116
    if ( ok )
15117
        test_ok ;
15118
 
15119
    ok = 1 ;
15120
 
15121
    byte_enables = 4'b0010 ;
15122
 
15123
    fork
15124
    begin
15125
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15126
        do_pause ( 1 ) ;
15127
    end
15128
    begin:monitor_error_event6
15129 35 mihad
        error_monitor_done = 0 ;
15130 15 mihad
        @(error_event_int) ;
15131
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15132
        ok = 0 ;
15133 35 mihad
        error_monitor_done = 1 ;
15134 15 mihad
    end
15135
    begin
15136
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15137
        @(posedge pci_clock) ;
15138 35 mihad
        #1 ;
15139
        if ( !error_monitor_done )
15140
            disable monitor_error_event6 ;
15141 15 mihad
    end
15142
    join
15143
 
15144
    if ( ok )
15145
        test_ok ;
15146
 
15147
    ok = 1 ;
15148
    byte_enables = 4'b0001 ;
15149
 
15150
    fork
15151
    begin
15152
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15153
        do_pause ( 1 ) ;
15154
    end
15155
    begin:monitor_error_event7
15156 35 mihad
        error_monitor_done = 0 ;
15157 15 mihad
        @(error_event_int) ;
15158
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15159
        ok = 0 ;
15160 35 mihad
        error_monitor_done = 1 ;
15161 15 mihad
    end
15162
    begin
15163
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15164
        @(posedge pci_clock) ;
15165 35 mihad
        #1 ;
15166
        if ( !error_monitor_done )
15167
            disable monitor_error_event7 ;
15168 15 mihad
    end
15169
    join
15170
 
15171
    if ( ok )
15172
        test_ok ;
15173
 
15174
    ok = 1 ;
15175
    byte_enables = 4'b0000 ;
15176
 
15177
    fork
15178
    begin
15179
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15180
        do_pause ( 1 ) ;
15181
    end
15182
    begin:monitor_error_event8
15183 35 mihad
        error_monitor_done = 0 ;
15184 15 mihad
        @(error_event_int) ;
15185
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15186
        ok = 0 ;
15187 35 mihad
        error_monitor_done = 1 ;
15188 15 mihad
    end
15189
    begin
15190
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15191
        @(posedge pci_clock) ;
15192 35 mihad
        #1 ;
15193
        if ( !error_monitor_done )
15194
            disable monitor_error_event8 ;
15195 15 mihad
    end
15196
    join
15197
 
15198
    if ( ok )
15199
        test_ok ;
15200
 
15201
    ok = 1 ;
15202
 
15203
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15204
    byte_enables = 4'b0110 ;
15205
 
15206
    fork
15207
    begin
15208
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15209
        do_pause ( 1 ) ;
15210
    end
15211
    begin:monitor_error_event9
15212 35 mihad
        error_monitor_done = 0 ;
15213 15 mihad
        @(error_event_int) ;
15214
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15215
        ok = 0 ;
15216 35 mihad
        error_monitor_done = 1 ;
15217 15 mihad
    end
15218
    begin
15219
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15220
        @(posedge pci_clock) ;
15221 35 mihad
        #1 ;
15222
        if ( !error_monitor_done )
15223
            disable monitor_error_event9 ;
15224 15 mihad
    end
15225
    join
15226
 
15227
    if ( ok )
15228
        test_ok ;
15229
 
15230
    ok = 1 ;
15231
    fork
15232
    begin
15233
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15234
        do_pause ( 1 ) ;
15235
    end
15236
    begin:monitor_error_event10
15237 35 mihad
        error_monitor_done = 0 ;
15238 15 mihad
        @(error_event_int) ;
15239
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15240
        ok = 0 ;
15241 35 mihad
        error_monitor_done = 1 ;
15242 15 mihad
    end
15243
    begin
15244
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15245
        @(posedge pci_clock) ;
15246 35 mihad
 
15247
        #1 ;
15248
        if ( !error_monitor_done )
15249
            disable monitor_error_event10 ;
15250 15 mihad
    end
15251
    join
15252
 
15253
    if ( ok )
15254
        test_ok ;
15255
 
15256
    ok = 1 ;
15257
 
15258
    byte_enables = 4'b0001 ;
15259
 
15260
    fork
15261
    begin
15262
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15263
        do_pause ( 1 ) ;
15264
    end
15265
    begin:monitor_error_event11
15266 35 mihad
        error_monitor_done = 0 ;
15267 15 mihad
        @(error_event_int) ;
15268
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15269
        ok = 0 ;
15270 35 mihad
        error_monitor_done = 1 ;
15271 15 mihad
    end
15272
    begin
15273
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15274
        @(posedge pci_clock) ;
15275 35 mihad
        #1 ;
15276
        if ( !error_monitor_done )
15277
            disable monitor_error_event11 ;
15278 15 mihad
    end
15279
    join
15280
 
15281
    if ( ok )
15282
        test_ok ;
15283
 
15284
    ok = 1 ;
15285
 
15286
    byte_enables = 4'b0101 ;
15287
 
15288
    fork
15289
    begin
15290
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15291
        do_pause ( 1 ) ;
15292
    end
15293
    begin:monitor_error_event12
15294 35 mihad
        error_monitor_done = 0 ;
15295 15 mihad
        @(error_event_int) ;
15296
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15297
        ok = 0 ;
15298 35 mihad
        error_monitor_done = 1 ;
15299 15 mihad
    end
15300
    begin
15301
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15302
        @(posedge pci_clock) ;
15303 35 mihad
        #1 ;
15304
        if ( !error_monitor_done )
15305
            disable monitor_error_event12 ;
15306 15 mihad
    end
15307
    join
15308
 
15309
    if ( ok )
15310
        test_ok ;
15311
 
15312
    ok = 1 ;
15313
 
15314
    byte_enables = 4'b0011 ;
15315
 
15316
    fork
15317
    begin
15318
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15319
        do_pause ( 1 ) ;
15320
    end
15321
    begin:monitor_error_event13
15322 35 mihad
        error_monitor_done = 0 ;
15323 15 mihad
        @(error_event_int) ;
15324
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15325
        ok = 0 ;
15326 35 mihad
        error_monitor_done = 1 ;
15327 15 mihad
    end
15328
    begin
15329
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15330
        @(posedge pci_clock) ;
15331 35 mihad
        #1 ;
15332
        if ( !error_monitor_done )
15333
            disable monitor_error_event13 ;
15334 15 mihad
    end
15335
    join
15336
 
15337
    if ( ok )
15338
        test_ok ;
15339
 
15340
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15341
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15342
    ok = 1 ;
15343
    if ( pci_address[27] !== 1 )
15344
    begin
15345
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15346
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15347
        ok = 0 ;
15348
    end
15349
    if ( pci_address[28] !== 0 )
15350
    begin
15351
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15352
        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") ;
15353
        ok = 0 ;
15354
    end
15355
    if ( pci_address[29] !== 0 )
15356
    begin
15357
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15358
        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") ;
15359
        ok = 0 ;
15360
    end
15361
 
15362
    // clear statuses
15363
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15364
    if ( !ok )
15365
    begin
15366
        test_fail("write to PCI Device Status register failed") ;
15367
        $display("Couldn't write PCI Device Status register") ;
15368
        disable main ;
15369
    end
15370
 
15371
    if ( ok )
15372
        test_ok ;
15373
 
15374
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15375
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15376
    if ( pci_address[8] !== 0 )
15377
    begin
15378
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15379
    end
15380
    else
15381
        test_ok ;
15382
 
15383
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15384
 
15385
    test_name = "DISABLE IMAGE" ;
15386
 
15387 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15388 15 mihad
    if ( ok !== 1 )
15389
    begin
15390
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15391
        test_fail("PCI Address Mask register could not be written") ;
15392
        disable main ;
15393
    end
15394
end
15395
endtask // test_target_abort
15396
 
15397
task test_target_io_wr_rd ;
15398
    input [2:0]  image_num ;
15399
    input        translate_address ;
15400
    input [11:0] img_ctrl_offset ;
15401
    reg   [31:0] expect_address ;
15402
    reg   [31:0] pci_address ;
15403
    reg          translation ;
15404
    reg   [31:0] read_data ;
15405
    reg   [3:0]  byte_enables ;
15406
    reg          ok ;
15407
    reg          pci_ok ;
15408
    reg          wb_ok ;
15409
    integer      i ;
15410 35 mihad
    reg          error_monitor_done ;
15411 15 mihad
begin:main
15412
    `ifdef ADDR_TRAN_IMPL
15413
        translation = translate_address ;
15414
    `else
15415
        translation = 0 ;
15416
    `endif
15417
 
15418
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15419
 
15420
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15421
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15422
    if ( translation )
15423
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15424
    else
15425
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15426
 
15427
    if ( !ok )
15428
    begin
15429
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15430
        test_fail("PCI Image Control register could not be written") ;
15431
    end
15432
 
15433
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15434
    pci_address  = Target_Base_Addr_R[image_num] ;
15435
    byte_enables = 4'b0000 ;
15436
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15437
 
15438
    fork
15439
    begin
15440
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15441
        do_pause ( 1 ) ;
15442
    end
15443
    begin
15444
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15445
        if ( wb_ok !== 1 )
15446
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15447
 
15448 35 mihad
        #1 ;
15449
        if ( !error_monitor_done )
15450
            disable monitor_pci_error_1 ;
15451 15 mihad
    end
15452
    begin:monitor_pci_error_1
15453 35 mihad
        error_monitor_done = 0 ;
15454 15 mihad
        pci_ok = 1 ;
15455
        @(error_event_int) ;
15456
        pci_ok = 0 ;
15457
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15458 35 mihad
        error_monitor_done = 1 ;
15459 15 mihad
    end
15460
    join
15461
 
15462
    byte_enables = 4'b1111 ;
15463
    for ( i = 0 ; i < 4 ; i = i + 1 )
15464
    begin:loop_1
15465
        byte_enables[i] = 0 ;
15466
        if ( i > 0 )
15467
            byte_enables[i - 1] = 1 ;
15468
        fork
15469
        begin
15470
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15471
            do_pause ( 1 ) ;
15472
        end
15473
        begin
15474
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15475
            if ( wb_ok !== 1 )
15476
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15477
 
15478 35 mihad
            #1 ;
15479
            if ( !error_monitor_done )
15480
                disable monitor_pci_error_2 ;
15481 15 mihad
        end
15482
        begin:monitor_pci_error_2
15483 35 mihad
            error_monitor_done = 0 ;
15484 15 mihad
            pci_ok = 1 ;
15485
            @(error_event_int) ;
15486
            pci_ok = 0 ;
15487
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15488 35 mihad
            error_monitor_done = 1 ;
15489 15 mihad
        end
15490
        join
15491
 
15492
        if ( !pci_ok || !wb_ok )
15493
            disable loop_1 ;
15494
 
15495
        pci_address = pci_address + 1 ;
15496
        expect_address = expect_address + 1 ;
15497
    end
15498
 
15499
    if ( pci_ok && wb_ok )
15500
        test_ok ;
15501
 
15502
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15503
    pci_address  = Target_Base_Addr_R[image_num] ;
15504
    byte_enables = 4'b1100 ;
15505
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15506
 
15507
    master1_check_received_data = 1 ;
15508
    fork
15509
    begin
15510
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15511
        do_pause( 1 ) ;
15512
    end
15513
    begin
15514
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15515
        if ( wb_ok !== 1 )
15516
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15517
 
15518
        do_pause ( 2 ) ;
15519
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15520
        do_pause ( 16 ) ;
15521
 
15522 35 mihad
        #1 ;
15523
        if ( !error_monitor_done )
15524
            disable monitor_pci_error_3 ;
15525 15 mihad
    end
15526
    begin:monitor_pci_error_3
15527 35 mihad
        error_monitor_done = 0 ;
15528 15 mihad
        pci_ok = 1 ;
15529
        @(error_event_int) ;
15530
        pci_ok = 0 ;
15531
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15532 35 mihad
        error_monitor_done = 1 ;
15533 15 mihad
    end
15534
    join
15535
 
15536
    if ( !pci_ok || !wb_ok )
15537
    begin
15538
        disable main ;
15539
    end
15540
 
15541
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15542
    byte_enables = 4'b0011 ;
15543
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15544
 
15545
    master1_check_received_data = 1 ;
15546
    fork
15547
    begin
15548
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15549
        do_pause( 1 ) ;
15550
    end
15551
    begin
15552
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15553
        if ( wb_ok !== 1 )
15554
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15555
 
15556
        do_pause ( 2 ) ;
15557
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15558
        do_pause ( 16 ) ;
15559
 
15560 35 mihad
        #1 ;
15561
        if ( !error_monitor_done )
15562
            disable monitor_pci_error_4 ;
15563 15 mihad
    end
15564
    begin:monitor_pci_error_4
15565 35 mihad
        error_monitor_done = 0 ;
15566 15 mihad
        pci_ok = 1 ;
15567
        @(error_event_int) ;
15568
        pci_ok = 0 ;
15569
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15570 35 mihad
        error_monitor_done = 1 ;
15571 15 mihad
    end
15572
    join
15573
 
15574
    if ( !pci_ok || !wb_ok )
15575
    begin
15576
        disable main ;
15577
    end
15578
 
15579
    pci_address  = Target_Base_Addr_R[image_num] ;
15580
    byte_enables = 4'b0000 ;
15581
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15582
 
15583
    master1_check_received_data = 1 ;
15584
    fork
15585
    begin
15586
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15587
        do_pause( 1 ) ;
15588
    end
15589
    begin
15590
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15591
        if ( wb_ok !== 1 )
15592
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15593
 
15594
        do_pause ( 2 ) ;
15595
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15596
        do_pause ( 16 ) ;
15597
 
15598 35 mihad
        #1 ;
15599
        if ( !error_monitor_done )
15600
            disable monitor_pci_error_5 ;
15601 15 mihad
    end
15602
    begin:monitor_pci_error_5
15603 35 mihad
        error_monitor_done = 0 ;
15604 15 mihad
        pci_ok = 1 ;
15605
        @(error_event_int) ;
15606
        pci_ok = 0 ;
15607
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15608 35 mihad
        error_monitor_done = 1 ;
15609 15 mihad
    end
15610
    join
15611
 
15612
    if ( pci_ok && wb_ok )
15613
        test_ok ;
15614
end
15615
endtask // test_target_io_wr_rd
15616
 
15617
task test_target_io_err_wr ;
15618
    input [2:0]  image_num ;
15619
    input        translate_address ;
15620
    input [11:0] img_ctrl_offset ;
15621
    input        enable_error_report ;
15622
    input        enable_error_interrupt ;
15623
 
15624
    reg   [31:0] expect_address ;
15625
    reg   [31:0] pci_address ;
15626
    reg          translation ;
15627
    reg   [31:0] read_data ;
15628
    reg   [3:0]  byte_enables ;
15629
    reg          ok ;
15630
    reg          pci_ok ;
15631
    reg          wb_ok ;
15632
    integer      i ;
15633
    reg   [11:0] offset ;
15634 35 mihad
    reg          error_monitor_done ;
15635 15 mihad
begin:main
15636
    `ifdef ADDR_TRAN_IMPL
15637
        translation = translate_address ;
15638
    `else
15639
        translation = 0 ;
15640
    `endif
15641
 
15642
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15643
 
15644
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15645
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15646
    if ( translation )
15647
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15648
    else
15649
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15650
 
15651
    if ( !ok )
15652
    begin
15653
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15654
        test_fail("PCI Image Control register could not be written") ;
15655
    end
15656
 
15657
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15658
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15659
    if ( enable_error_report )
15660
    begin
15661
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15662
        if ( !ok )
15663
        begin
15664
            test_fail("PCI Error Control and Status register could not be written") ;
15665
            disable main ;
15666
        end
15667
    end
15668
    else
15669
    begin
15670
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15671
        if ( !ok )
15672
        begin
15673
            test_fail("PCI Error Control and Status register could not be written") ;
15674
            disable main ;
15675
        end
15676
    end
15677
 
15678
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15679
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15680
    if ( enable_error_interrupt )
15681
    begin
15682
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15683
        if ( !ok )
15684
        begin
15685
            test_fail("Interrupt Control register could not be written") ;
15686
            disable main ;
15687
        end
15688
    end
15689
    else
15690
    begin
15691
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15692
        if ( !ok )
15693
        begin
15694
            test_fail("Interrupt Control register could not be written") ;
15695
            disable main ;
15696
        end
15697
    end
15698
 
15699
    pci_address  = Target_Base_Addr_R[image_num] ;
15700
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15701
 
15702
    byte_enables = 4'b1111 ;
15703
 
15704
    for ( i = 0 ; i < 4 ; i = i + 1 )
15705
    begin:loop_1
15706
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15707
        byte_enables[i] = 0 ;
15708
        if ( i > 0 )
15709
            byte_enables[i - 1] = 1 ;
15710
 
15711
        fork
15712
        begin
15713
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15714
            do_pause ( 1 ) ;
15715
        end
15716
        begin
15717
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15718
            if ( wb_ok !== 1 )
15719
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15720
 
15721 35 mihad
            #1 ;
15722
            if ( !error_monitor_done )
15723
                disable monitor_pci_error_2 ;
15724 15 mihad
        end
15725
        begin:monitor_pci_error_2
15726 35 mihad
            error_monitor_done = 0 ;
15727 15 mihad
            pci_ok = 1 ;
15728
            @(error_event_int) ;
15729
            pci_ok = 0 ;
15730
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15731 35 mihad
            error_monitor_done = 1 ;
15732 15 mihad
        end
15733
        join
15734
 
15735
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15736
        `ifdef HOST
15737
 
15738
            repeat ( 4 )
15739
                @( posedge wb_clock ) ;
15740
 
15741
            if ( enable_error_interrupt && enable_error_report )
15742
            begin
15743
                if ( INT_O !== 1 )
15744
                begin
15745
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15746
                end
15747
            end
15748
            else
15749
            begin
15750
                if ( INT_O !== 0 )
15751
                begin
15752
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15753
                end
15754
            end
15755
        `else
15756
            repeat ( 4 )
15757
                @( posedge pci_clock ) ;
15758
 
15759
            if ( enable_error_interrupt && enable_error_report )
15760
            begin
15761
                if ( INTA !== 0 )
15762
                begin
15763
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15764
                end
15765
            end
15766
            else
15767
            begin
15768
                if ( INTA !== 1 )
15769
                begin
15770
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15771
                end
15772
            end
15773
        `endif
15774
 
15775
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15776
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15777
        config_read( offset, 4'hF, read_data ) ;
15778
        ok = 1 ;
15779
        if ( enable_error_report )
15780
        begin
15781
            if ( read_data[8] !== 1 )
15782
            begin
15783
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15784
                ok = 0 ;
15785
            end
15786
 
15787
            if ( read_data[9] !== 0 )
15788
            begin
15789
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15790
                ok = 0 ;
15791
            end
15792
 
15793
            if ( read_data[31:28] !== byte_enables )
15794
            begin
15795
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15796
                ok = 0 ;
15797
            end
15798
 
15799
            if ( read_data[27:24] !== `BC_IO_WRITE )
15800
            begin
15801
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15802
                ok = 0 ;
15803
            end
15804
 
15805
            if ( ok )
15806
                test_ok ;
15807
 
15808
            test_name = "CLEAR ERROR STATUS" ;
15809
            config_write( offset, read_data, 4'hF, ok ) ;
15810
            if ( !ok )
15811
                test_fail("PCI Error Control and Status register could not be written") ;
15812
 
15813
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15814
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15815
            config_read ( offset, 4'hf, read_data ) ;
15816
 
15817
            if ( read_data !== expect_address )
15818
            begin
15819
                test_fail("value in Erroneous Address register was incorrect") ;
15820
                ok = 0 ;
15821
            end
15822
 
15823
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15824
            config_read ( offset, 4'hf, read_data ) ;
15825
 
15826
            if ( read_data !== 32'hAAAA_AAAA )
15827
            begin
15828
                test_fail("value in Erroneous Data register was incorrect") ;
15829
                ok = 0 ;
15830
            end
15831
 
15832
            if ( ok )
15833
                test_ok ;
15834
 
15835
        end
15836
        else
15837
        begin
15838
            if ( read_data[8] !== 0 )
15839
            begin
15840
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15841
                ok = 0 ;
15842
            end
15843
            else
15844
                test_ok ;
15845
        end
15846
 
15847
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15848
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15849
        ok = 1 ;
15850
 
15851
        config_read ( offset, 4'hF, read_data ) ;
15852
        if ( enable_error_report && enable_error_interrupt )
15853
        begin
15854
            if ( read_data[2] !== 1 )
15855
            begin
15856
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15857
                ok = 0 ;
15858
            end
15859
 
15860
            test_name = "CLEARING INTERRUPT STATUS" ;
15861
            config_write( offset, read_data, 4'hF, ok ) ;
15862
            if ( !ok )
15863
                test_fail("Interrupt Status register could not be written") ;
15864
        end
15865
        else
15866
        begin
15867
            if ( read_data[2] !== 0 )
15868
            begin
15869
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15870
                ok = 0 ;
15871
            end
15872
        end
15873
 
15874
        if ( ok )
15875
            test_ok ;
15876
 
15877
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15878
        `ifdef HOST
15879
 
15880
            repeat ( 4 )
15881
                @( posedge wb_clock ) ;
15882
 
15883
            if ( INT_O !== 0 )
15884
            begin
15885
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15886
            end
15887
            else
15888
                test_ok ;
15889
 
15890
        `else
15891
            repeat ( 4 )
15892
                @( posedge pci_clock ) ;
15893
 
15894
            if ( INTA !== 1 )
15895
            begin
15896
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15897
            end
15898
            else
15899
                test_ok ;
15900
 
15901
        `endif
15902
 
15903
        pci_address = pci_address + 1 ;
15904
        expect_address = expect_address + 1 ;
15905
    end
15906
 
15907
end
15908
endtask // test_target_io_err_wr
15909
 
15910
task test_pci_image ;
15911
    input [2:0]  image_num ;
15912
    reg   [11:0] pci_ctrl_offset ;
15913
    reg   [11:0] ctrl_offset ;
15914
    reg   [11:0] ba_offset ;
15915
    reg   [11:0] am_offset ;
15916
    reg   [11:0] ta_offset ;
15917
    reg   [7:0]  cache_lsize ;
15918
    reg          ok ;
15919
    reg          test_io ;
15920
    reg          test_mem ;
15921
begin
15922
    pci_ctrl_offset = 12'h4 ;
15923
    if (image_num === 0)
15924
    begin
15925
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15926
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15927
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15928
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15929
    end
15930
    else if (image_num === 1)
15931
    begin
15932
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15933
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15934
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15935
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15936
    end
15937
    else if (image_num === 2)
15938
    begin
15939
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15940
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15941
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15942
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15943
    end
15944
    else if (image_num === 3)
15945
    begin
15946
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15947
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15948
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15949
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15950
    end
15951
    else if (image_num === 4)
15952
    begin
15953
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15954
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15955
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15956
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15957
    end
15958
    else if (image_num === 5)
15959
    begin
15960
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15961
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15962
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15963
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15964
    end
15965
 
15966
    `ifdef HOST
15967
        test_io  = 1 ;
15968
        test_mem = 1 ;
15969
    `else
15970
        if (image_num == 1)
15971
            test_io = `PCI_BA1_MEM_IO ;
15972
        else if ( image_num == 2 )
15973
            test_io = `PCI_BA2_MEM_IO ;
15974
        else if ( image_num == 3 )
15975
            test_io = `PCI_BA3_MEM_IO ;
15976
        else if ( image_num == 4 )
15977
            test_io = `PCI_BA4_MEM_IO ;
15978
        else if ( image_num == 5 )
15979
            test_io = `PCI_BA5_MEM_IO ;
15980
 
15981
        test_mem = !test_io ;
15982
    `endif
15983
 
15984
    $display(" ");
15985
    $display("########################################################################") ;
15986
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15987
    test_name = "PCI IMAGE SETTINGS" ;
15988
 
15989
    // Set Base Address of IMAGE
15990
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15991
    if ( ok !== 1 )
15992
    begin
15993
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15994
        test_fail("PCI Base Address register could not be written") ;
15995
    end
15996
 
15997
    // Set Address Mask of IMAGE
15998
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15999
    if ( ok !== 1 )
16000
    begin
16001
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16002
        test_fail("PCI Address Mask register could not be written") ;
16003
    end
16004
 
16005
    // Set Translation Address of IMAGE
16006
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16007
    if ( ok !== 1 )
16008
    begin
16009
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16010
        test_fail("PCI Translation Address register could not be written") ;
16011
    end
16012
 
16013
// Following are defines for byte enable signals !
16014
//      Byte Masks
16015
//      `Test_Byte_0                            (4'b1110)
16016
//      `Test_Byte_1                            (4'b1101)
16017
//      `Test_Byte_2                            (4'b1011)
16018
//      `Test_Byte_3                            (4'b0111)
16019
//      `Test_Half_0                            (4'b1100)
16020
//      `Test_Half_1                            (4'b0011)
16021
//      `Test_All_Bytes                         (4'b0000)
16022
 
16023
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
16024
    // Set Cache Line Size
16025
    cache_lsize = 8'h4 ;
16026
 
16027
    $display(" ");
16028
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16029
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16030
    if ( ok !== 1 )
16031
    begin
16032
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16033
        test_fail("PCI Device Control and Status register could not be written") ;
16034
    end
16035
 
16036
    if (test_mem)
16037
    begin
16038
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
16039
        // Task test_normal_wr_rd has the following parameters:
16040
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16041
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16042
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16043
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
16044
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
16045
 
16046
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16047
        // Set Cache Line Size
16048
        cache_lsize = 8'h4 ;
16049
 
16050
        $display(" ");
16051
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16052
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16053
        if ( ok !== 1 )
16054
        begin
16055
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16056
            test_fail("Cache Line Size register could not be written" ) ;
16057
        end
16058
 
16059
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
16060
        // Task test_normal_wr_rd has the following parameters:
16061
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16062
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16063
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16064
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
16065
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
16066
 
16067
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16068
        // Set Cache Line Size
16069
        cache_lsize = 8'h8 ;
16070
 
16071
        $display(" ");
16072
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16073
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16074
        if ( ok !== 1 )
16075
        begin
16076
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16077
            test_fail("Cache Line Size register could not be written" ) ;
16078
        end
16079
 
16080
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
16081
        // Task test_normal_wr_rd has the following parameters:
16082
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16083
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16084
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16085
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
16086
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16087
 
16088
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16089
        // Set Cache Line Size
16090
        cache_lsize = 8'h4 ;
16091
 
16092
        $display(" ");
16093
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16094
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16095
        if ( ok !== 1 )
16096
        begin
16097
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16098
            test_fail("Cache Line Size register could not be written" ) ;
16099
        end
16100
 
16101
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
16102
        // Task test_normal_wr_rd has the following parameters:
16103
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16104
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16105
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16106
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
16107
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16108
 
16109
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16110
        $display(" ");
16111
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
16112
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16113
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16114
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
16115
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
16116
 
16117
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16118
        $display(" ");
16119
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
16120
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16121
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16122
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
16123
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
16124
 
16125
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16126
        $display(" ");
16127
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
16128
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16129
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16130
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
16131
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
16132
 
16133
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16134
        $display(" ");
16135
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
16136
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16137
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16138
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
16139
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
16140
    end
16141
 
16142
    if ( test_io )
16143
    begin
16144
        test_name = "PCI IMAGE SETTINGS" ;
16145
 
16146
        // Set Base Address of IMAGE
16147
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
16148
        if ( ok !== 1 )
16149
        begin
16150
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16151
            test_fail("PCI Base Address register could not be written") ;
16152
        end
16153
 
16154
        // Set Address Mask of IMAGE
16155
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16156
        if ( ok !== 1 )
16157
        begin
16158
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16159
            test_fail("PCI Address Mask register could not be written") ;
16160
        end
16161
 
16162
        // Set Translation Address of IMAGE
16163
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16164
        if ( ok !== 1 )
16165
        begin
16166
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16167
            test_fail("PCI Translation Address register could not be written") ;
16168
        end
16169
 
16170
        // Set Cache Line Size
16171
        cache_lsize = 8'h4 ;
16172
 
16173
        $display(" ");
16174
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16175
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16176
        if ( ok !== 1 )
16177
        begin
16178
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16179
            test_fail("Cache Line Size register could not be written" ) ;
16180
        end
16181
 
16182
        test_target_io_wr_rd
16183
        (
16184
            image_num,    // image number
16185
            0,            // test with address translation
16186
            ctrl_offset   // image control register offset
16187
        ) ;
16188
 
16189
        test_target_io_wr_rd
16190
        (
16191
            image_num,    // image number
16192
            1,            // test with address translation
16193
            ctrl_offset   // image control register offset
16194
        ) ;
16195
 
16196
        test_target_io_err_wr
16197
        (
16198
            image_num,      // image number
16199
            0,              // address translation on/off
16200
            ctrl_offset,    // image control register offset
16201
            0,              // enable error reporting
16202
 
16203
        ) ;
16204
 
16205
        test_target_io_err_wr
16206
        (
16207
            image_num,      // image number
16208
            1,              // address translation on/off
16209
            ctrl_offset,    // image control register offset
16210
            0,              // enable error reporting
16211
            1               // enable error interrupts
16212
        ) ;
16213
 
16214
        test_target_io_err_wr
16215
        (
16216
            image_num,      // image number
16217
            0,              // address translation on/off
16218
            ctrl_offset,    // image control register offset
16219
            1,              // enable error reporting
16220
 
16221
        ) ;
16222
 
16223
        test_target_io_err_wr
16224
        (
16225
            image_num,      // image number
16226
            1,              // address translation on/off
16227
            ctrl_offset,    // image control register offset
16228
            1,              // enable error reporting
16229
            1               // enable error interrupts
16230
        ) ;
16231
    end
16232
 
16233
    // Test master abort with NON supported commands
16234
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16235
 
16236
    // disable the image
16237 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16238 15 mihad
end
16239
endtask //test_pci_image
16240
 
16241
task target_fast_back_to_back ;
16242
    reg   [11:0] pci_ctrl_offset ;
16243
    reg   [11:0] ctrl_offset ;
16244
    reg   [11:0] ba_offset ;
16245
    reg   [11:0] am_offset ;
16246
    reg   [11:0] ta_offset ;
16247
    reg   [11:0] cls_offset ;
16248
    reg          do_mem_fb2b ;
16249
    reg          do_io_fb2b ;
16250
    reg          ok ;
16251
begin:main
16252
 
16253
    if ( target_mem_image !== -1 )
16254
    begin
16255
        do_mem_fb2b = 1 ;
16256
 
16257
        if (target_mem_image === 1)
16258
        begin
16259
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16260
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16261
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16262
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16263
        end
16264
        else if (target_mem_image === 2)
16265
        begin
16266
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16267
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16268
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16269
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16270
        end
16271
        else if (target_mem_image === 3)
16272
        begin
16273
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16274
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16275
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16276
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16277
        end
16278
        else if (target_mem_image === 4)
16279
        begin
16280
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16281
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16282
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16283
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16284
        end
16285
        else if (target_mem_image === 5)
16286
        begin
16287
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16288
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16289
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16290
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16291
        end
16292
    end
16293
    else
16294
        do_mem_fb2b = 0 ;
16295
 
16296
    pci_ctrl_offset = 12'h4 ;
16297
    cls_offset      = 12'h00C ;
16298
 
16299
    if ( do_mem_fb2b )
16300
    begin
16301
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16302
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16303
        if ( ok !== 1 )
16304
        begin
16305
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16306
            test_fail("PCI Base Address register could not be written") ;
16307
            disable main ;
16308
        end
16309
 
16310
        // Set Address Mask of IMAGE
16311
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16312
        if ( ok !== 1 )
16313
        begin
16314
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16315
            test_fail("PCI Address Mask register could not be written") ;
16316
            disable main ;
16317
        end
16318
 
16319
        // Set Translation Address of IMAGE
16320
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16321
        if ( ok !== 1 )
16322
        begin
16323
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16324
            test_fail("PCI Translation Address Register could not be written") ;
16325
            disable main ;
16326
        end
16327
 
16328
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16329
        if ( ok !== 1 )
16330
        begin
16331
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16332
            test_fail("PCI Image Control register could not be written") ;
16333
            disable main ;
16334
        end
16335
 
16336
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16337
        if ( ok !== 1 )
16338
        begin
16339
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16340
            test_fail("Cache Line Size register could not be written") ;
16341
            disable main ;
16342
        end
16343
 
16344
        // enable master 1 fast_b2b
16345 45 mihad
        configuration_cycle_write(0,                        // bus number
16346
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16347
                                  0,                        // function number
16348
                                  1,                        // register number
16349
                                  0,                        // type of configuration cycle
16350
                                  4'b1111,                  // byte enables
16351
                                  32'hFFFF_FFFF             // data
16352 15 mihad
                                 ) ;
16353
 
16354
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16355
 
16356
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16357
        fork
16358
        begin
16359
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16360
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16361
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16362
                  0, `Test_One_Zero_Target_WS,
16363
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16364
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16365
 
16366
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16367
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16368
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16369
                  0, `Test_One_Zero_Target_WS,
16370
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16371
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16372
            do_pause(5) ;
16373
 
16374
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16375
        end
16376
        begin:wb_monitor1
16377
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16378
            if ( ok !== 1 )
16379
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16380
 
16381
            disable monitor_error_event1 ;
16382
        end
16383
        begin:monitor_error_event1
16384
            @(error_event_int) ;
16385
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16386
            ok = 0 ;
16387
            disable wb_monitor1 ;
16388
        end
16389
        join
16390
 
16391
        if ( ok )
16392
            test_ok ;
16393
 
16394
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16395
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16396
        fork
16397
        begin
16398
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16399
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16400
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16401
                  0, `Test_One_Zero_Target_WS,
16402
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16403
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16404
 
16405
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16406
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16407
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16408
                  0, `Test_One_Zero_Target_WS,
16409
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16410
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16411
            do_pause(5) ;
16412
 
16413
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16414
 
16415
        end
16416
        begin:wb_monitor2
16417
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16418
            if ( ok !== 1 )
16419
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16420
            else
16421
            begin
16422
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16423
                if ( ok !== 1 )
16424
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16425
            end
16426
 
16427
            disable monitor_error_event2 ;
16428
        end
16429
        begin:monitor_error_event2
16430
            @(error_event_int) ;
16431
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16432
            ok = 0 ;
16433
            disable wb_monitor2 ;
16434
        end
16435
        join
16436
 
16437
        if ( ok )
16438
            test_ok ;
16439
 
16440
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16441
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16442
        fork
16443
        begin
16444
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16445
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16446
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16447
                  0, `Test_One_Zero_Target_WS,
16448
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16449
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16450
 
16451
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16452
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16453
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16454
                  0, `Test_One_Zero_Target_WS,
16455
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16456
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16457
            do_pause(5) ;
16458
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16459
 
16460
        end
16461
        begin:wb_monitor3
16462
            fork
16463
            begin
16464
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16465
                if ( ok !== 1 )
16466
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16467
            end
16468
            begin
16469
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16470
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16471
                if ( ok !== 1 )
16472
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16473
            end
16474
            join
16475
 
16476
            if ( ok )
16477
            begin
16478
                fork
16479
                begin
16480
                    do_pause(3) ;
16481
 
16482
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16483
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16484
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16485
                        0, `Test_One_Zero_Target_WS,
16486
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16487
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16488
 
16489
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16490
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16491
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16492
                            0, `Test_One_Zero_Target_WS,
16493
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16494
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16495
 
16496
                    do_pause(1) ;
16497
                end
16498
                begin
16499
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16500
                    if ( ok !== 1 )
16501
                    begin
16502
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16503
                        disable monitor_error_event3 ;
16504
                    end
16505
                    else
16506
                    begin
16507
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16508
                        if ( ok !== 1 )
16509
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16510
                    end
16511
                end
16512 26 mihad
                begin
16513
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16514
                        if ( ok !== 1 )
16515
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16516
                end
16517 15 mihad
                join
16518
            end
16519
            disable monitor_error_event3 ;
16520
        end
16521
        begin:monitor_error_event3
16522
            @(error_event_int) ;
16523
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16524
            ok = 0 ;
16525
            disable wb_monitor3 ;
16526
        end
16527
        join
16528
 
16529
        if ( ok )
16530
            test_ok ;
16531
 
16532
        test_name = "DISABLING MEM IMAGE" ;
16533 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16534 15 mihad
        if ( ok !== 1 )
16535
        begin
16536
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16537
            test_fail("PCI Address Mask register could not be written") ;
16538
            disable main ;
16539
        end
16540
    end
16541
 
16542
    if ( target_io_image !== -1 )
16543
    begin
16544
        do_io_fb2b = 1 ;
16545
 
16546
        if (target_io_image === 1)
16547
        begin
16548
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16549
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16550
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16551
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16552
        end
16553
        else if (target_io_image === 2)
16554
        begin
16555
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16556
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16557
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16558
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16559
        end
16560
        else if (target_io_image === 3)
16561
        begin
16562
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16563
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16564
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16565
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16566
        end
16567
        else if (target_io_image === 4)
16568
        begin
16569
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16570
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16571
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16572
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16573
        end
16574
        else if (target_io_image === 5)
16575
        begin
16576
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16577
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16578
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16579
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16580
        end
16581
    end
16582
    else
16583
        do_io_fb2b = 0 ;
16584
 
16585
    if ( do_io_fb2b )
16586
    begin
16587
 
16588
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16589
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16590
        if ( ok !== 1 )
16591
        begin
16592
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16593
            test_fail("PCI Base Address register could not be written") ;
16594
            disable main ;
16595
        end
16596
 
16597
        // Set Address Mask of IMAGE
16598
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16599
        if ( ok !== 1 )
16600
        begin
16601
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16602
            test_fail("PCI Address Mask register could not be written") ;
16603
            disable main ;
16604
        end
16605
 
16606
        // Set Translation Address of IMAGE
16607
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16608
        if ( ok !== 1 )
16609
        begin
16610
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16611
            test_fail("PCI Translation Address Register could not be written") ;
16612
            disable main ;
16613
        end
16614
 
16615
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16616
        if ( ok !== 1 )
16617
        begin
16618
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16619
            test_fail("PCI Image Control register could not be written") ;
16620
            disable main ;
16621
        end
16622
 
16623
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16624
        if ( ok !== 1 )
16625
        begin
16626
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16627
            test_fail("Cache Line Size register could not be written") ;
16628
            disable main ;
16629
        end
16630
 
16631
        // enable master 1 fast_b2b
16632 45 mihad
        configuration_cycle_write(0,                        // bus number
16633
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16634
                                  0,                        // function number
16635
                                  1,                        // register number
16636
                                  0,                        // type of configuration cycle
16637
                                  4'b1111,                  // byte enables
16638
                                  32'hFFFF_FFFF             // data
16639 15 mihad
                                 ) ;
16640
 
16641
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16642
 
16643
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16644
        fork
16645
        begin
16646
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16647
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16648
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16649
                  0, `Test_One_Zero_Target_WS,
16650
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16651
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16652
 
16653
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16654
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16655
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16656
                  0, `Test_One_Zero_Target_WS,
16657
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16658
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16659
            do_pause(5) ;
16660
 
16661
        end
16662
        begin:wb_monitor4
16663
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16664
            if ( ok !== 1 )
16665
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16666
 
16667
            if ( ok )
16668
            begin
16669
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16670
                if ( ok !== 1 )
16671
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16672
            end
16673
 
16674
            disable monitor_error_event4 ;
16675
        end
16676
        begin:monitor_error_event4
16677
            @(error_event_int) ;
16678
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16679
            ok = 0 ;
16680
            disable wb_monitor4 ;
16681
        end
16682
        join
16683
 
16684
        if ( ok )
16685
            test_ok ;
16686
 
16687
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16688
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16689
        fork
16690
        begin
16691
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16692
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16693
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16694
                  0, `Test_One_Zero_Target_WS,
16695
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16696
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16697
 
16698
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16699
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16700
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16701
                  0, `Test_One_Zero_Target_WS,
16702
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16703
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16704
            do_pause(5) ;
16705
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16706
        end
16707
        begin:wb_monitor5
16708
            fork
16709
            begin
16710
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16711
                if ( ok !== 1 )
16712
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16713
            end
16714
            begin
16715
                wb_transaction_stop( 1 ) ;
16716
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16717
                if ( ok !== 1 )
16718
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16719
            end
16720
            join
16721
 
16722
            if ( ok )
16723
            begin
16724
                fork
16725
                begin
16726
                    do_pause(3) ;
16727
 
16728
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16729
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16730
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16731
                            0, `Test_One_Zero_Target_WS,
16732
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16733
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16734
 
16735
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16736
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16737
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16738
                            0, `Test_One_Zero_Target_WS,
16739
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16740
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16741
 
16742
                    do_pause(1) ;
16743
                end
16744
                begin
16745
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16746
                    if ( ok !== 1 )
16747
                    begin
16748
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16749
                        disable monitor_error_event5 ;
16750
                    end
16751
                    else
16752
                    begin
16753
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16754
                        if ( ok !== 1 )
16755
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16756
                    end
16757
                end
16758
                join
16759
            end
16760
            disable monitor_error_event5 ;
16761
        end
16762
        begin:monitor_error_event5
16763
            @(error_event_int) ;
16764
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16765
            ok = 0 ;
16766
            disable wb_monitor5 ;
16767
        end
16768
        join
16769
 
16770
        if ( ok )
16771
            test_ok ;
16772
 
16773
        test_name = "DISABLING IO IMAGE" ;
16774 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16775 15 mihad
        if ( ok !== 1 )
16776
        begin
16777
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16778
            test_fail("PCI Address Mask register could not be written") ;
16779
            disable main ;
16780
        end
16781
    end
16782
 
16783
end
16784
endtask //target_fast_back_to_back
16785
 
16786
task target_disconnects ;
16787
    reg   [11:0] pci_ctrl_offset ;
16788
    reg   [11:0] ctrl_offset ;
16789
    reg   [11:0] ba_offset ;
16790
    reg   [11:0] am_offset ;
16791
    reg   [11:0] ta_offset ;
16792
    reg   [11:0] cls_offset ;
16793
    reg          pci_ok ;
16794
    reg          wb_ok ;
16795
    reg          ok ;
16796
    reg   [31:0] pci_address ;
16797
    reg   [31:0] data ;
16798
    reg   [3:0]  byte_enables ;
16799
    reg   [9:0]  expect_length ;
16800
 
16801
    reg          do_mem_disconnects ;
16802
    reg          do_io_disconnects ;
16803 35 mihad
    reg          error_monitor_done ;
16804 15 mihad
begin:main
16805
    if ( target_mem_image !== -1 )
16806
    begin
16807
        do_mem_disconnects = 1 ;
16808
 
16809
        if (target_mem_image === 1)
16810
        begin
16811
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16812
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16813
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16814
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16815
        end
16816
        else if (target_mem_image === 2)
16817
        begin
16818
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16819
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16820
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16821
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16822
        end
16823
        else if (target_mem_image === 3)
16824
        begin
16825
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16826
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16827
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16828
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16829
        end
16830
        else if (target_mem_image === 4)
16831
        begin
16832
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16833
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16834
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16835
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16836
        end
16837
        else if (target_mem_image === 5)
16838
        begin
16839
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16840
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16841
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16842
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16843
        end
16844
    end
16845
    else
16846
        do_mem_disconnects = 0 ;
16847
 
16848
    pci_ctrl_offset = 12'h4 ;
16849
    cls_offset = 12'h00C ;
16850
 
16851
    master1_check_received_data = 0 ;
16852
    master2_check_received_data = 0 ;
16853
 
16854
    `ifdef HOST
16855
        `ifdef NO_CNF_IMAGE
16856
        `else
16857
            `define TEST_BURST_CONFIG_READ
16858
        `endif
16859
    `else
16860
        `define TEST_BURST_CONFIG_READ
16861
        `define TEST_BURST_CONFIG_WRITE
16862
    `endif
16863
 
16864
    `ifdef TEST_BURST_CONFIG_WRITE
16865
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16866
 
16867
        data = 32'h0000_08_08 ;
16868
 
16869 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16870 15 mihad
        byte_enables = 4'b0000 ;
16871
 
16872
        fork
16873
        begin
16874
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16875
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16876
                    byte_enables,
16877
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16878
                    8'h0_0, `Test_One_Zero_Target_WS,
16879
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16880
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16881
 
16882
            data = 32'h0000_04_04 ;
16883
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16884
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16885
                    byte_enables,
16886
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16887
                    8'h0_0, `Test_One_Zero_Target_WS,
16888
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16889
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16890
            do_pause( 1 ) ;
16891
            while ( FRAME !== 1 || IRDY !== 1 )
16892
                @(posedge pci_clock) ;
16893
 
16894 35 mihad
            #1 ;
16895
            if ( !error_monitor_done )
16896
                disable monitor_error_event1 ;
16897 15 mihad
        end
16898
        begin:monitor_error_event1
16899 35 mihad
            error_monitor_done = 0 ;
16900 15 mihad
            ok = 1 ;
16901
            @(error_event_int) ;
16902
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16903
            ok = 0 ;
16904 35 mihad
            error_monitor_done = 1 ;
16905 15 mihad
        end
16906
        join
16907
 
16908
        config_read(pci_address, 4'hF, data) ;
16909
        if ( data [15:0] !== 16'h04_04 )
16910
        begin
16911
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16912
        end
16913
        else if ( ok )
16914
            test_ok ;
16915
 
16916 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16917
 
16918
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16919 15 mihad
        data         = 32'h0000_0808 ;
16920
        byte_enables = 4'h0 ;
16921
        fork
16922
        begin
16923
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16924
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16925
                    byte_enables,
16926
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16927
                    8'h0_0, `Test_One_Zero_Target_WS,
16928
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16929
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16930
 
16931
            data = 32'h0000_04_04 ;
16932
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16933
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16934
                    byte_enables,
16935
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16936
                    8'h0_0, `Test_One_Zero_Target_WS,
16937
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16938
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16939
 
16940
            do_pause( 1 ) ;
16941
            while ( FRAME !== 1 || IRDY !== 1 )
16942
                @(posedge pci_clock) ;
16943
 
16944 35 mihad
            #1 ;
16945
            if ( !error_monitor_done )
16946
                disable monitor_error_event2 ;
16947 15 mihad
        end
16948
        begin:monitor_error_event2
16949 35 mihad
            error_monitor_done = 0 ;
16950 15 mihad
            ok = 1 ;
16951
            @(error_event_int) ;
16952
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16953
            ok = 0 ;
16954 35 mihad
            error_monitor_done = 1 ;
16955 15 mihad
        end
16956
        join
16957
 
16958
        config_read(pci_address, 4'hF, data) ;
16959
        if ( data [15:0] !== 16'h04_04 )
16960
        begin
16961
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16962
        end
16963
        else if ( ok )
16964
            test_ok ;
16965
    `endif
16966
 
16967
    `ifdef TEST_BURST_CONFIG_READ
16968
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16969
 
16970
        data = 32'h0000_04_04 ;
16971
 
16972 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16973 15 mihad
        byte_enables = 4'b0000 ;
16974
 
16975
        fork
16976
        begin
16977
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16978
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16979
                    byte_enables,
16980
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16981
                    8'h0_0, `Test_One_Zero_Target_WS,
16982
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16983
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16984
            do_pause( 1 ) ;
16985
 
16986
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16987
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16988
                    byte_enables,
16989
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16990
                    8'h0_0, `Test_One_Zero_Target_WS,
16991
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16992
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16993
            do_pause( 1 ) ;
16994
 
16995
            while ( FRAME !== 1 || IRDY !== 1 )
16996
                @(posedge pci_clock) ;
16997
 
16998 35 mihad
            if ( !error_monitor_done )
16999
                disable monitor_error_event3 ;
17000 15 mihad
        end
17001
        begin:monitor_error_event3
17002 35 mihad
            error_monitor_done = 0 ;
17003 15 mihad
            ok = 1 ;
17004
            @(error_event_int) ;
17005
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17006
            ok = 0 ;
17007 35 mihad
            error_monitor_done = 1 ;
17008 15 mihad
        end
17009
        join
17010
 
17011
        if ( ok )
17012
            test_ok ;
17013
 
17014 45 mihad
 
17015
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
17016
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
17017 15 mihad
        fork
17018
        begin
17019
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17020
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17021
                    byte_enables,
17022
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17023
                    8'h0_0, `Test_One_Zero_Target_WS,
17024
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17025
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17026
            do_pause( 1 ) ;
17027
 
17028
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17029
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17030
                    byte_enables,
17031
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17032
                    8'h0_0, `Test_One_Zero_Target_WS,
17033
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17034
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17035
            do_pause( 1 ) ;
17036
 
17037
            while ( FRAME !== 1 || IRDY !== 1 )
17038
                @(posedge pci_clock) ;
17039
 
17040 35 mihad
            #1 ;
17041
            if ( !error_monitor_done )
17042
                disable monitor_error_event4 ;
17043 15 mihad
        end
17044
        begin:monitor_error_event4
17045 35 mihad
            error_monitor_done = 0 ;
17046 15 mihad
            ok = 1 ;
17047
            @(error_event_int) ;
17048
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17049
            ok = 0 ;
17050 35 mihad
            error_monitor_done = 1 ;
17051 15 mihad
        end
17052
        join
17053
 
17054
        if ( ok )
17055
            test_ok ;
17056
    `endif
17057
 
17058
    `ifdef TEST_BURST_CONFIG_READ
17059
        `undef TEST_BURST_CONFIG_READ
17060
    `endif
17061
 
17062
    `ifdef TEST_BURST_CONFIG_WRITE
17063
        `undef TEST_BURST_CONFIG_WRITE
17064
    `endif
17065
 
17066
    master1_check_received_data = 1 ;
17067
    master2_check_received_data = 1 ;
17068
 
17069
    if ( do_mem_disconnects )
17070
    begin
17071
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17072
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
17073
        if ( ok !== 1 )
17074
        begin
17075
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17076
            test_fail("PCI Base Address register could not be written") ;
17077
            disable main ;
17078
        end
17079
 
17080
        // Set Address Mask of IMAGE
17081
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
17082
        if ( ok !== 1 )
17083
        begin
17084
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17085
            test_fail("PCI Address Mask register could not be written") ;
17086
            disable main ;
17087
        end
17088
 
17089
        // Set Translation Address of IMAGE
17090
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
17091
        if ( ok !== 1 )
17092
        begin
17093
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17094
            test_fail("PCI Translation Address Register could not be written") ;
17095
            disable main ;
17096
        end
17097
 
17098
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17099
        if ( ok !== 1 )
17100
        begin
17101
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17102
            test_fail("PCI Image Control register could not be written") ;
17103
            disable main ;
17104
        end
17105
 
17106
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17107
        if ( ok !== 1 )
17108
        begin
17109
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17110
            test_fail("Cache Line Size register could not be written") ;
17111
            disable main ;
17112
        end
17113
 
17114
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17115
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17116
        data = 32'hAAAA_AAAA ;
17117
        byte_enables = 4'h0 ;
17118
        expect_length = `PCIW_DEPTH - 2 ;
17119
 
17120
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17121
        fork
17122
        begin
17123
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17124
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17125
                        byte_enables,
17126 73 mihad
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17127 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17128
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17129 73 mihad
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17130 15 mihad
            do_pause( 3 ) ;
17131
 
17132
            while ( FRAME !== 1 || IRDY !== 1 )
17133
                @(posedge pci_clock) ;
17134
 
17135 35 mihad
            #1 ;
17136
            if ( !error_monitor_done )
17137
                disable monitor_error_event5 ;
17138 15 mihad
        end
17139
        begin:monitor_error_event5
17140 35 mihad
            error_monitor_done = 0 ;
17141 15 mihad
            pci_ok = 1 ;
17142
            @(error_event_int) ;
17143
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17144
            pci_ok = 0 ;
17145 35 mihad
            error_monitor_done = 1 ;
17146 15 mihad
        end
17147
        begin
17148
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17149
            if ( wb_ok !== 1 )
17150
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17151
        end
17152
        join
17153
 
17154
        if ( wb_ok && pci_ok )
17155
            test_ok ;
17156
 
17157
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17158
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17159
        data = 32'hAAAA_AAAA ;
17160
        byte_enables = 4'h0 ;
17161
        expect_length = `PCIW_DEPTH - 2 ;
17162
 
17163
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17164
        fork
17165
        begin
17166
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17167
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17168
                        byte_enables,
17169 73 mihad
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17170 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17171
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17172 73 mihad
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17173 15 mihad
            do_pause( 3 ) ;
17174
 
17175
            while ( FRAME !== 1 || IRDY !== 1 )
17176
                @(posedge pci_clock) ;
17177
 
17178 35 mihad
            #1 ;
17179
            if ( !error_monitor_done )
17180
                disable monitor_error_event6 ;
17181 15 mihad
        end
17182
        begin:monitor_error_event6
17183 35 mihad
            error_monitor_done = 0 ;
17184 15 mihad
            pci_ok = 1 ;
17185
            @(error_event_int) ;
17186
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17187
            pci_ok = 0 ;
17188 35 mihad
            error_monitor_done = 1 ;
17189 15 mihad
        end
17190
        begin
17191
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17192
            if ( wb_ok !== 1 )
17193
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17194
        end
17195
        join
17196
 
17197
        if ( wb_ok && pci_ok )
17198
            test_ok ;
17199
 
17200
        master1_check_received_data = 1 ;
17201
//        master2_check_received_data = 0 ;
17202
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17203
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17204
        data = 32'hAAAA_AAAA ;
17205
        byte_enables = 4'h0 ;
17206
        expect_length = 4 ;
17207
 
17208
        fork
17209
        begin
17210
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17211
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17212
                        byte_enables,
17213
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17214
                        8'h0_0, `Test_One_Zero_Target_WS,
17215
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17216
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17217
            do_pause( 1 ) ;
17218
 
17219
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17220
            if ( wb_ok !== 1 )
17221
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17222
 
17223
            do_pause(2) ;
17224
 
17225
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17226
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17227
                        byte_enables,
17228
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17229
                        8'h0_0, `Test_One_Zero_Target_WS,
17230
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17231
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17232
            do_pause( 3 ) ;
17233
 
17234
            while ( FRAME !== 1 || IRDY !== 1 )
17235
                @(posedge pci_clock) ;
17236
 
17237 35 mihad
            #1 ;
17238
            if ( !error_monitor_done )
17239
                disable monitor_error_event7 ;
17240 15 mihad
        end
17241
        begin:monitor_error_event7
17242 35 mihad
            error_monitor_done = 0 ;
17243 15 mihad
            pci_ok = 1 ;
17244
            @(error_event_int) ;
17245
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17246
            pci_ok = 0 ;
17247 35 mihad
            error_monitor_done = 1 ;
17248 15 mihad
        end
17249
        join
17250
 
17251
        if ( wb_ok && pci_ok )
17252
            test_ok ;
17253
 
17254
        master1_check_received_data = 1 ;
17255
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17256
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17257
        data = 32'hAAAA_AAAA ;
17258
        byte_enables = 4'h0 ;
17259
        expect_length = 4 ;
17260
 
17261
        fork
17262
        begin
17263
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17264
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17265
                        byte_enables,
17266
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17267
                        8'h0_0, `Test_One_Zero_Target_WS,
17268
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17269
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17270
            do_pause( 1 ) ;
17271
 
17272
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17273
            if ( wb_ok !== 1 )
17274
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17275
 
17276
            do_pause(2) ;
17277
 
17278
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17279
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17280
                        byte_enables,
17281
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17282
                        8'h0_0, `Test_One_Zero_Target_WS,
17283
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17284
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17285
            do_pause( 3 ) ;
17286
 
17287
            while ( FRAME !== 1 || IRDY !== 1 )
17288
                @(posedge pci_clock) ;
17289
 
17290 35 mihad
            #1 ;
17291
            if ( !error_monitor_done )
17292
                disable monitor_error_event8 ;
17293 15 mihad
        end
17294
        begin:monitor_error_event8
17295 35 mihad
            error_monitor_done = 0 ;
17296 15 mihad
            pci_ok = 1 ;
17297
            @(error_event_int) ;
17298
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17299
            pci_ok = 0 ;
17300 35 mihad
            error_monitor_done = 1 ;
17301 15 mihad
        end
17302
        join
17303
 
17304
        if ( wb_ok && pci_ok )
17305
            test_ok ;
17306
 
17307
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17308
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17309
        data = 32'hDEAF_BEAF ;
17310
        byte_enables = 4'h0 ;
17311
        expect_length = 1 ;
17312
 
17313
        fork
17314
        begin
17315
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17316
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17317
                        byte_enables,
17318
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17319
                        8'h0_0, `Test_One_Zero_Target_WS,
17320
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17321
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17322
            do_pause( 3 ) ;
17323
 
17324
            while ( FRAME !== 1 || IRDY !== 1 )
17325
                @(posedge pci_clock) ;
17326
 
17327 35 mihad
            #1 ;
17328
            if ( !error_monitor_done )
17329
                disable monitor_error_event9 ;
17330 15 mihad
        end
17331
        begin:monitor_error_event9
17332 35 mihad
            error_monitor_done = 0 ;
17333 15 mihad
            pci_ok = 1 ;
17334
            @(error_event_int) ;
17335
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17336
            pci_ok = 0 ;
17337 35 mihad
            error_monitor_done = 1 ;
17338 15 mihad
        end
17339
        begin
17340
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17341
            if ( wb_ok !== 1 )
17342
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17343
        end
17344
        join
17345
 
17346
        if ( wb_ok && pci_ok )
17347
            test_ok ;
17348
 
17349
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17350
        data = 32'hDEAD_BEAF ;
17351
        byte_enables = 4'h0 ;
17352
        expect_length = 1 ;
17353
 
17354
        fork
17355
        begin
17356
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17357
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17358
                        byte_enables,
17359
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17360
                        8'h0_0, `Test_One_Zero_Target_WS,
17361
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17362
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17363
            do_pause( 3 ) ;
17364
 
17365
            while ( FRAME !== 1 || IRDY !== 1 )
17366
                @(posedge pci_clock) ;
17367
 
17368 35 mihad
            #1 ;
17369
            if ( !error_monitor_done )
17370
                disable monitor_error_event10 ;
17371 15 mihad
        end
17372
        begin:monitor_error_event10
17373 35 mihad
            error_monitor_done = 0 ;
17374 15 mihad
            pci_ok = 1 ;
17375
            @(error_event_int) ;
17376
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17377
            pci_ok = 0 ;
17378 35 mihad
            error_monitor_done = 1 ;
17379 15 mihad
        end
17380
        begin
17381
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17382
            if ( wb_ok !== 1 )
17383
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17384
        end
17385
        join
17386
 
17387
        if ( wb_ok && pci_ok )
17388
            test_ok ;
17389
 
17390
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17391
        data = 32'hAAAA_AAAA ;
17392
        byte_enables = 4'h0 ;
17393
        expect_length = 1 ;
17394
 
17395
        fork
17396
        begin
17397
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17398
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17399
                        byte_enables,
17400
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17401
                        8'h0_0, `Test_One_Zero_Target_WS,
17402
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17403
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17404
            do_pause( 3 ) ;
17405
 
17406
            while ( FRAME !== 1 || IRDY !== 1 )
17407
                @(posedge pci_clock) ;
17408
 
17409 35 mihad
            #1 ;
17410
            if ( !error_monitor_done )
17411
                disable monitor_error_event11 ;
17412 15 mihad
        end
17413
        begin:monitor_error_event11
17414 35 mihad
            error_monitor_done = 0 ;
17415 15 mihad
            pci_ok = 1 ;
17416
            @(error_event_int) ;
17417
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17418
            pci_ok = 0 ;
17419 35 mihad
            error_monitor_done = 1 ;
17420 15 mihad
        end
17421
        begin
17422
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17423
            if ( wb_ok !== 1 )
17424
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17425
        end
17426
        join
17427
 
17428
        if ( wb_ok && pci_ok )
17429
            test_ok ;
17430
 
17431
        master1_check_received_data = 1 ;
17432
 
17433
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17434
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17435
        data = 32'hDEAF_BEAF ;
17436
        byte_enables = 4'h0 ;
17437
        expect_length = 1 ;
17438
 
17439
        fork
17440
        begin
17441
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17442
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17443
                        byte_enables,
17444
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17445
                        8'h0_0, `Test_One_Zero_Target_WS,
17446
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17447
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17448
            do_pause( 1 ) ;
17449
 
17450
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17451
            if ( wb_ok !== 1 )
17452
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17453
 
17454
            do_pause(3) ;
17455
 
17456
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17457
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17458
                        byte_enables,
17459
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17460
                        8'h0_0, `Test_One_Zero_Target_WS,
17461
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17462
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17463
            do_pause( 3 ) ;
17464
 
17465
            while ( FRAME !== 1 || IRDY !== 1 )
17466
                @(posedge pci_clock) ;
17467
 
17468 35 mihad
            #1 ;
17469
            if ( !error_monitor_done )
17470
                disable monitor_error_event12 ;
17471 15 mihad
        end
17472
        begin:monitor_error_event12
17473 35 mihad
            error_monitor_done = 0 ;
17474 15 mihad
            pci_ok = 1 ;
17475
            @(error_event_int) ;
17476
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17477
            pci_ok = 0 ;
17478 35 mihad
            error_monitor_done = 1 ;
17479 15 mihad
        end
17480
        join
17481
 
17482
        if ( wb_ok && pci_ok )
17483
            test_ok ;
17484
 
17485
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17486
        data = 32'hDEAD_BEAF ;
17487
        byte_enables = 4'h0 ;
17488
        expect_length = 1 ;
17489
 
17490
        fork
17491
        begin
17492
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17493
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17494
                        byte_enables,
17495
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17496
                        8'h0_0, `Test_One_Zero_Target_WS,
17497
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17498
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17499
            do_pause( 1 ) ;
17500
 
17501
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17502
            if ( wb_ok !== 1 )
17503
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17504
 
17505
            do_pause(3) ;
17506
 
17507
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17508
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17509
                        byte_enables,
17510
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17511
                        8'h0_0, `Test_One_Zero_Target_WS,
17512
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17513
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17514
            do_pause( 3 ) ;
17515
 
17516
            while ( FRAME !== 1 || IRDY !== 1 )
17517
                @(posedge pci_clock) ;
17518
 
17519 35 mihad
            #1 ;
17520
            if ( !error_monitor_done )
17521
                disable monitor_error_event13 ;
17522 15 mihad
        end
17523
        begin:monitor_error_event13
17524 35 mihad
            error_monitor_done = 0 ;
17525 15 mihad
            pci_ok = 1 ;
17526
            @(error_event_int) ;
17527
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17528
            pci_ok = 0 ;
17529 35 mihad
            error_monitor_done = 1 ;
17530 15 mihad
        end
17531
        join
17532
 
17533
        if ( wb_ok && pci_ok )
17534
            test_ok ;
17535
 
17536
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17537
        data = 32'hAAAA_AAAA ;
17538
        byte_enables = 4'h0 ;
17539
        expect_length = 1 ;
17540
 
17541
        fork
17542
        begin
17543
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17544
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17545
                        byte_enables,
17546
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17547
                        8'h0_0, `Test_One_Zero_Target_WS,
17548
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17549
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17550
            do_pause( 1 ) ;
17551
 
17552
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17553
            if ( wb_ok !== 1 )
17554
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17555
 
17556
            do_pause(3) ;
17557
 
17558
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17559
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17560
                        byte_enables,
17561
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17562
                        8'h0_0, `Test_One_Zero_Target_WS,
17563
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17564
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17565
            do_pause( 3 ) ;
17566
 
17567
            while ( FRAME !== 1 || IRDY !== 1 )
17568
                @(posedge pci_clock) ;
17569
 
17570 35 mihad
            #1 ;
17571
            if ( !error_monitor_done )
17572
                disable monitor_error_event14 ;
17573 15 mihad
        end
17574
        begin:monitor_error_event14
17575 35 mihad
            error_monitor_done = 0 ;
17576 15 mihad
            pci_ok = 1 ;
17577
            @(error_event_int) ;
17578
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17579
            pci_ok = 0 ;
17580 35 mihad
            error_monitor_done = 1 ;
17581 15 mihad
        end
17582
        join
17583
 
17584
        if ( wb_ok && pci_ok )
17585
            test_ok ;
17586
 
17587
        // disable the image
17588
        test_name = "DISABLING MEMORY IMAGE" ;
17589 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17590 15 mihad
        if ( ok !== 1 )
17591
        begin
17592
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17593
            test_fail("PCI Address Mask register could not be written") ;
17594
            disable main ;
17595
        end
17596
    end
17597
//*
17598
    if ( target_io_image !== -1 )
17599
    begin
17600
        do_io_disconnects = 1 ;
17601
 
17602
        if (target_io_image === 1)
17603
        begin
17604
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17605
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17606
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17607
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17608
        end
17609
        else if (target_io_image === 2)
17610
        begin
17611
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17612
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17613
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17614
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17615
        end
17616
        else if (target_io_image === 3)
17617
        begin
17618
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17619
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17620
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17621
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17622
        end
17623
        else if (target_io_image === 4)
17624
        begin
17625
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17626
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17627
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17628
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17629
        end
17630
        else if (target_io_image === 5)
17631
        begin
17632
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17633
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17634
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17635
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17636
        end
17637
    end
17638
    else
17639
        do_io_disconnects = 0 ;
17640
 
17641
    if ( do_io_disconnects )
17642
    begin
17643
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17644
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17645
        if ( ok !== 1 )
17646
        begin
17647
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17648
            test_fail("PCI Base Address register could not be written") ;
17649
            disable main ;
17650
        end
17651
 
17652
        // Set Address Mask of IMAGE
17653
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17654
        if ( ok !== 1 )
17655
        begin
17656
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17657
            test_fail("PCI Address Mask register could not be written") ;
17658
            disable main ;
17659
        end
17660
 
17661
        // Set Translation Address of IMAGE
17662
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17663
        if ( ok !== 1 )
17664
        begin
17665
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17666
            test_fail("PCI Translation Address Register could not be written") ;
17667
            disable main ;
17668
        end
17669
 
17670
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17671
        if ( ok !== 1 )
17672
        begin
17673
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17674
            test_fail("PCI Image Control register could not be written") ;
17675
            disable main ;
17676
        end
17677
 
17678
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17679
        if ( ok !== 1 )
17680
        begin
17681
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17682
            test_fail("Cache Line Size register could not be written") ;
17683
            disable main ;
17684
        end
17685
 
17686
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17687
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17688
        data = 32'h5555_5555 ;
17689
        byte_enables = 4'h0 ;
17690
        expect_length = 1 ;
17691
 
17692
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17693
 
17694
        fork
17695
        begin
17696
            PCIU_IO_WRITE
17697
            (
17698
                `Test_Master_1,             // which master
17699
                pci_address,                // to what address
17700
                data,                       // data
17701
                byte_enables,               // byte enable
17702
                expect_length + 1,          // length to request
17703
                `Test_Target_Retry_On       // expected target termination
17704
            ) ;
17705
 
17706
            do_pause( 3 ) ;
17707
 
17708
            while ( FRAME !== 1 || IRDY !== 1 )
17709
                @(posedge pci_clock) ;
17710
 
17711 35 mihad
            #1 ;
17712
            if ( !error_monitor_done )
17713
                disable monitor_error_event15 ;
17714 15 mihad
        end
17715
        begin:monitor_error_event15
17716 35 mihad
            error_monitor_done = 0 ;
17717 15 mihad
            pci_ok = 1 ;
17718
            @(error_event_int) ;
17719
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17720
            pci_ok = 0 ;
17721 35 mihad
            error_monitor_done = 1 ;
17722 15 mihad
        end
17723
        begin
17724
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17725
            if ( wb_ok !== 1 )
17726
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17727
        end
17728
        join
17729
 
17730
        if ( wb_ok && pci_ok )
17731
            test_ok ;
17732
 
17733
        data = 32'hAAAA_AAAA ;
17734
        fork
17735
        begin
17736
            PCIU_IO_WRITE
17737
            (
17738
                `Test_Master_1,             // which master
17739
                pci_address,                // to what address
17740
                data,                       // data
17741
                byte_enables,               // byte enable
17742
                expect_length + 2,          // length to request
17743
                `Test_Target_Retry_Before   // expected target termination
17744
            ) ;
17745
 
17746
            do_pause( 3 ) ;
17747
 
17748
            while ( FRAME !== 1 || IRDY !== 1 )
17749
                @(posedge pci_clock) ;
17750
 
17751 35 mihad
            #1 ;
17752
            if ( !error_monitor_done )
17753
                disable monitor_error_event16 ;
17754 15 mihad
        end
17755
        begin:monitor_error_event16
17756 35 mihad
            error_monitor_done = 0 ;
17757 15 mihad
            pci_ok = 1 ;
17758
            @(error_event_int) ;
17759
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17760
            pci_ok = 0 ;
17761 35 mihad
            error_monitor_done = 1 ;
17762 15 mihad
        end
17763
        begin
17764
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17765
            if ( wb_ok !== 1 )
17766
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17767
        end
17768
        join
17769
 
17770
        if ( wb_ok && pci_ok )
17771
            test_ok ;
17772
 
17773
        master2_check_received_data = 1 ;
17774
 
17775
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17776
 
17777
        fork
17778
        begin
17779
 
17780
             PCIU_IO_READ
17781
             (
17782
                `Test_Master_2,
17783
                pci_address[PCI_BUS_DATA_RANGE:0],
17784
                data,
17785
                byte_enables,
17786
                2,
17787
                `Test_Target_Retry_Before
17788
             );
17789
 
17790
            do_pause( 1 ) ;
17791
 
17792
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17793
            if ( wb_ok !== 1 )
17794
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17795
 
17796
            do_pause(3) ;
17797
 
17798
            PCIU_IO_READ
17799
             (
17800
                `Test_Master_2,
17801
                pci_address[PCI_BUS_DATA_RANGE:0],
17802
                data,
17803
                byte_enables,
17804
                expect_length + 1,
17805
                `Test_Target_Retry_On
17806
             );
17807
 
17808
            do_pause( 3 ) ;
17809
 
17810
            while ( FRAME !== 1 || IRDY !== 1 )
17811
                @(posedge pci_clock) ;
17812
 
17813 35 mihad
            #1 ;
17814
            if ( !error_monitor_done )
17815
                disable monitor_error_event17 ;
17816 15 mihad
        end
17817
        begin:monitor_error_event17
17818 35 mihad
            error_monitor_done = 0 ;
17819 15 mihad
            pci_ok = 1 ;
17820
            @(error_event_int) ;
17821
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17822
            pci_ok = 0 ;
17823 35 mihad
            error_monitor_done = 1 ;
17824 15 mihad
        end
17825
        join
17826
 
17827
        if ( wb_ok && pci_ok )
17828
            test_ok ;
17829
 
17830
        fork
17831
        begin
17832
 
17833
             PCIU_IO_READ
17834
             (
17835
                `Test_Master_2,
17836
                pci_address[PCI_BUS_DATA_RANGE:0],
17837
                data,
17838
                byte_enables,
17839
                2,
17840
                `Test_Target_Retry_Before
17841
             );
17842
 
17843
            do_pause( 1 ) ;
17844
 
17845
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17846
            if ( wb_ok !== 1 )
17847
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17848
 
17849
            do_pause(3) ;
17850
 
17851
            PCIU_IO_READ
17852
             (
17853
                `Test_Master_2,
17854
                pci_address[PCI_BUS_DATA_RANGE:0],
17855
                data,
17856
                byte_enables,
17857
                expect_length + 2,
17858
                `Test_Target_Retry_Before
17859
             );
17860
 
17861
            do_pause( 3 ) ;
17862
 
17863
            while ( FRAME !== 1 || IRDY !== 1 )
17864
                @(posedge pci_clock) ;
17865
 
17866 35 mihad
            #1 ;
17867
            if ( !error_monitor_done )
17868
                disable monitor_error_event18 ;
17869 15 mihad
        end
17870
        begin:monitor_error_event18
17871 35 mihad
            error_monitor_done = 0 ;
17872 15 mihad
            pci_ok = 1 ;
17873
            @(error_event_int) ;
17874
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17875
            pci_ok = 0 ;
17876 35 mihad
            error_monitor_done = 1 ;
17877 15 mihad
        end
17878
        join
17879
 
17880
        if ( wb_ok && pci_ok )
17881
            test_ok ;
17882
 
17883
        test_name = "DISABLING IO IMAGE" ;
17884 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17885 15 mihad
        if ( ok !== 1 )
17886
        begin
17887
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17888
            test_fail("PCI Address Mask register could not be written") ;
17889
            disable main ;
17890
        end
17891
    end
17892
//*/
17893
end
17894
endtask // target_disconnects
17895
 
17896
task target_unsupported_cmds ;
17897
        input [31:0] Address;
17898
        input [2:0]  image_num ;
17899
    reg          ok ;
17900
begin:main
17901
 
17902
    $display("  ") ;
17903
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17904
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17905 45 mihad
 
17906
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17907
    configuration_cycle_write
17908
    (
17909
        0,                        // bus number
17910
        `TAR1_IDSEL_INDEX - 11,   // device number
17911
        0,                        // function number
17912
        1,                        // register number
17913
        0,                        // type of configuration cycle
17914
        4'b0001,                  // byte enables
17915
        32'h0000_0044             // data
17916
    ) ;
17917
 
17918
    configuration_cycle_write
17919
    (
17920
        0,                        // bus number
17921
        `TAR2_IDSEL_INDEX - 11,   // device number
17922
        0,                        // function number
17923
        1,                        // register number
17924
        0,                        // type of configuration cycle
17925
        4'b0001,                  // byte enables
17926
        32'h0000_0044             // data
17927
    ) ;
17928
 
17929 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17930 15 mihad
    (
17931
        Address,                // first part of address in dual address cycle
17932
        Address,                // second part of address in dual address cycle
17933
        `BC_IACK,                       // dual address cycle command
17934
        `BC_IACK,               // normal command
17935
        4'h0,               // byte enables
17936
        32'h1234_5678,      // data
17937
        1'b0,               // make address parity error on first phase of dual address
17938
        1'b0,               // make address parity error on second phase of dual address
17939
        ok                  // result of operation
17940
    ) ;
17941
    if ( ok )
17942
        test_ok ;
17943
    else
17944
    begin
17945
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17946
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17947
    end
17948
 
17949
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17950
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17951 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17952 15 mihad
    (
17953
        Address,                // first part of address in dual address cycle
17954
        Address,                // second part of address in dual address cycle
17955
        `BC_SPECIAL,            // dual address cycle command
17956
        `BC_SPECIAL,            // normal command
17957
        4'h0,               // byte enables
17958
        32'h1234_5678,      // data
17959
        1'b0,               // make address parity error on first phase of dual address
17960
        1'b0,               // make address parity error on second phase of dual address
17961
        ok                  // result of operation
17962
    ) ;
17963
    if ( ok )
17964
        test_ok ;
17965
    else
17966
    begin
17967
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17968
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17969
    end
17970
 
17971
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17972
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17973 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17974 15 mihad
    (
17975
        Address,                // first part of address in dual address cycle
17976
        Address,                // second part of address in dual address cycle
17977
        `BC_RESERVED0,          // dual address cycle command
17978
        `BC_RESERVED0,      // normal command
17979
        4'h0,               // byte enables
17980
        32'h1234_5678,      // data
17981
        1'b0,               // make address parity error on first phase of dual address
17982
        1'b0,               // make address parity error on second phase of dual address
17983
        ok                  // result of operation
17984
    ) ;
17985
    if ( ok )
17986
        test_ok ;
17987
    else
17988
    begin
17989
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17990
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17991
    end
17992
 
17993
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17994
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17995 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17996 15 mihad
    (
17997
        Address,                // first part of address in dual address cycle
17998
        Address,                // second part of address in dual address cycle
17999
        `BC_RESERVED1,          // dual address cycle command
18000
        `BC_RESERVED1,      // normal command
18001
        4'h0,               // byte enables
18002
        32'h1234_5678,      // data
18003
        1'b0,               // make address parity error on first phase of dual address
18004
        1'b0,               // make address parity error on second phase of dual address
18005
        ok                  // result of operation
18006
    ) ;
18007
    if ( ok )
18008
        test_ok ;
18009
    else
18010
    begin
18011
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18012
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
18013
    end
18014
 
18015
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
18016
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
18017 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18018 15 mihad
    (
18019
        Address,                // first part of address in dual address cycle
18020
        Address,                // second part of address in dual address cycle
18021
        `BC_RESERVED2,          // dual address cycle command
18022
        `BC_RESERVED2,      // normal command
18023
        4'h0,               // byte enables
18024
        32'h1234_5678,      // data
18025
        1'b0,               // make address parity error on first phase of dual address
18026
        1'b0,               // make address parity error on second phase of dual address
18027
        ok                  // result of operation
18028
    ) ;
18029
    if ( ok )
18030
        test_ok ;
18031
    else
18032
    begin
18033
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18034
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
18035
    end
18036
 
18037
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
18038
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
18039 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18040 15 mihad
    (
18041
        Address,                // first part of address in dual address cycle
18042
        Address,                // second part of address in dual address cycle
18043
        `BC_RESERVED3,          // dual address cycle command
18044
        `BC_RESERVED3,      // normal command
18045
        4'h0,               // byte enables
18046
        32'h1234_5678,      // data
18047
        1'b0,               // make address parity error on first phase of dual address
18048
        1'b0,               // make address parity error on second phase of dual address
18049
        ok                  // result of operation
18050
    ) ;
18051
    if ( ok )
18052
        test_ok ;
18053
    else
18054
    begin
18055
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18056
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
18057
    end
18058
 
18059
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
18060
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
18061
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
18062
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
18063 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18064 15 mihad
    (
18065
        Address,                // first part of address in dual address cycle
18066
        Address,                // second part of address in dual address cycle
18067
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
18068
        `BC_MEM_WRITE,      // normal command
18069
        4'h0,               // byte enables;
18070
        32'h1234_5678,      // data
18071
        1'b0,               // make address parity error on first phase of dual address
18072
        1'b0,               // make address parity error on second phase of dual address
18073
        ok                  // result of operation
18074
    ) ;
18075
    if ( ok )
18076
        test_ok ;
18077
    else
18078
    begin
18079
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18080
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
18081
    end
18082
 
18083 45 mihad
    // enable pci blue behavioral targets 1 and 2
18084
    configuration_cycle_write
18085
    (
18086
        0,                        // bus number
18087
        `TAR1_IDSEL_INDEX - 11,   // device number
18088
        0,                        // function number
18089
        1,                        // register number
18090
        0,                        // type of configuration cycle
18091
        4'b0001,                  // byte enables
18092
        32'h0000_0047             // data
18093
    ) ;
18094
 
18095
    configuration_cycle_write
18096
    (
18097
        0,                        // bus number
18098
        `TAR2_IDSEL_INDEX - 11,   // device number
18099
        0,                        // function number
18100
        1,                        // register number
18101
        0,                        // type of configuration cycle
18102
        4'b0001,                  // byte enables
18103
        32'h0000_0047             // data
18104
    ) ;
18105 15 mihad
end
18106
endtask // target_unsupported_cmds
18107
 
18108 63 mihad
`ifdef DISABLE_COMPLETION_EXPIRED_TESTS
18109
`else
18110 15 mihad
task target_completion_expiration ;
18111
    reg   [11:0] pci_ctrl_offset ;
18112
    reg   [11:0] pci_ba_offset ;
18113
    reg   [11:0] pci_am_offset ;
18114
    reg   [11:0] pci_device_ctrl_offset ;
18115
    reg   [11:0] pci_err_cs_offset ;
18116
    reg   [11:0] icr_offset ;
18117
    reg   [11:0] isr_offset ;
18118
    reg   [11:0] lat_tim_cls_offset ;
18119
 
18120
    reg [31:0] temp_val1 ;
18121
    reg [31:0] temp_val2 ;
18122
    reg        ok   ;
18123 33 mihad
    reg        ok_wb ;
18124
    reg        ok_pci ;
18125 15 mihad
 
18126
    reg [31:0] pci_image_base ;
18127
    integer i ;
18128 33 mihad
    integer clocks_after_completion ;
18129
    reg     error_monitor_done ;
18130
    reg     test_mem ;
18131 15 mihad
 
18132
begin:main
18133
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18134
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
18135
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
18136
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
18137
 
18138
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
18139
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
18140
    lat_tim_cls_offset = 12'hC ;
18141
    pci_device_ctrl_offset    = 12'h4 ;
18142
 
18143 33 mihad
    `ifdef HOST
18144
        test_mem = 1'b1 ;
18145
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
18146
    `else
18147
        test_mem = !`PCI_BA1_MEM_IO ;
18148
        pci_image_base = Target_Base_Addr_R[1] ;
18149
    `endif
18150 15 mihad
 
18151
    // enable master & target operation
18152
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
18153
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
18154
    if ( ok !== 1 )
18155
    begin
18156
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18157
        test_fail("write to PCI Device Control register failed") ;
18158
        disable main ;
18159
    end
18160
 
18161
    // prepare image control register
18162 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18163 15 mihad
    if ( ok !== 1 )
18164
    begin
18165
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18166
        test_fail("write to PCI Image Control register failed") ;
18167
        disable main ;
18168
    end
18169
 
18170
    // prepare base address register
18171
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18172
    if ( ok !== 1 )
18173
    begin
18174
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18175
        test_fail("write to PCI Base Address register failed") ;
18176
        disable main ;
18177
    end
18178
 
18179
    // write address mask register
18180
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18181
    if ( ok !== 1 )
18182
    begin
18183
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18184
        test_fail("write to PCI Address Mask register failed") ;
18185
        disable main ;
18186
    end
18187
 
18188
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18189
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18190
    if ( ok !== 1 )
18191
    begin
18192
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18193
        test_fail("write to PCI Error Control and Status register failed") ;
18194
        disable main ;
18195
    end
18196
 
18197 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18198 15 mihad
    if ( ok !== 1 )
18199
    begin
18200
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18201
        test_fail("write to Interrupt Control register failed") ;
18202
        disable main ;
18203
    end
18204
 
18205
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18206
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18207
    if ( ok !== 1 )
18208
    begin
18209
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18210
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18211
        disable main ;
18212
    end
18213
 
18214
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18215
 
18216
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18217 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18218
    master1_check_received_data = 0 ;
18219 15 mihad
 
18220 33 mihad
    ok_pci = 1 ;
18221
    // start a delayed read request
18222
    fork
18223
    begin
18224
        if ( test_mem )
18225
 
18226
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18227
                          pci_image_base, 32'h1234_5678,
18228
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18229
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18230
        else
18231
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18232
 
18233
        do_pause( 1 ) ;
18234
    end
18235
    begin:error_monitor1
18236 35 mihad
        error_monitor_done = 0 ;
18237 33 mihad
        @(error_event_int) ;
18238
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18239
        ok_pci = 0 ;
18240 35 mihad
        error_monitor_done = 1 ;
18241 33 mihad
    end
18242
    begin
18243
        if ( test_mem )
18244
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18245
        else
18246
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18247 15 mihad
 
18248 33 mihad
        if ( ok_wb !== 1 )
18249
        begin
18250
            test_fail("Bridge failed to process Target Memory read correctly") ;
18251
            disable main ;
18252
        end
18253
 
18254 35 mihad
        #1 ;
18255
        if ( !error_monitor_done )
18256 33 mihad
            disable error_monitor1 ;
18257
    end
18258
    join
18259
 
18260
    clocks_after_completion = 0 ;
18261
    // now do another - different transaction
18262
    fork
18263
    begin
18264
        if ( test_mem )
18265
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18266
                          pci_image_base + 4, 32'h1234_5678,
18267
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18268
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18269
        else
18270
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18271
 
18272
        while ( clocks_after_completion < 32'h0000_FFF0 )
18273
        begin
18274
            @(posedge pci_clock) ;
18275
            clocks_after_completion = clocks_after_completion + 1 ;
18276
        end
18277
 
18278
        do_pause('hFF) ;
18279
 
18280
        if ( test_mem )
18281
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18282
                          pci_image_base + 4, 32'h1234_5678,
18283
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18284
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18285
        else
18286
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18287
 
18288
        do_pause( 1 ) ;
18289
    end
18290
    begin:error_monitor2
18291 35 mihad
        error_monitor_done = 0 ;
18292 33 mihad
        @(error_event_int) ;
18293
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18294
        ok_pci = 0 ;
18295 35 mihad
        error_monitor_done = 1 ;
18296 33 mihad
    end
18297
    begin
18298
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18299
        repeat( 'hFF )
18300
            @(posedge pci_clock) ;
18301
 
18302
        if ( test_mem )
18303
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18304
        else
18305
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18306
 
18307
        if ( ok_wb !== 1 )
18308
        begin
18309
            test_fail("Bridge failed to process Target Memory read correctly") ;
18310
            disable main ;
18311
        end
18312
 
18313
        repeat(4)
18314
            @(posedge pci_clock) ;
18315
 
18316
        fork
18317
        begin
18318
            if ( test_mem )
18319
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18320
                              pci_image_base + 4, 32'h1234_5678,
18321
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18322
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18323
            else
18324
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18325
 
18326
            do_pause(1) ;
18327
        end
18328
        begin
18329
           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 ) ;
18330 35 mihad
           #1 ;
18331
           if ( !error_monitor_done )
18332 33 mihad
               disable error_monitor2 ;
18333
        end
18334
        join
18335
    end
18336
    join
18337
 
18338
    if ( ok && ok_pci && ok_wb )
18339
        test_ok ;
18340
 
18341
    if ( ok !== 1 )
18342
    begin
18343
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18344
        test_fail("write to PCI Address Mask register failed") ;
18345
        disable main ;
18346
    end
18347
 
18348
    // check statuses after this situation - none should be set
18349
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18350
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18351
    if ( ok !== 1 )
18352
    begin
18353
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18354
        test_fail("read from pci device status register failed") ;
18355
        disable main ;
18356
    end
18357
 
18358
    if ( temp_val1[31] )
18359
    begin
18360
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18361
        test_fail("detected parity error bit was set for no reason") ;
18362
    end
18363
 
18364
    if ( temp_val1[30] )
18365
    begin
18366
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18367
        test_fail("signaled system error bit was set for no reason") ;
18368
    end
18369
 
18370
    if ( temp_val1[29] )
18371
    begin
18372
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18373
        test_fail("received master abort bit was set for no reason") ;
18374
    end
18375
 
18376
    if ( temp_val1[28] )
18377
    begin
18378
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18379
        test_fail("received target abort bit was set for no reason") ;
18380
    end
18381
 
18382
    if ( temp_val1[27] )
18383
    begin
18384
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18385
        test_fail("signaled target abort bit was set for no reason") ;
18386
    end
18387
 
18388
    if ( temp_val1[24] )
18389
    begin
18390
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18391
        test_fail("Master Data parity error bit was set for no reason") ;
18392
    end
18393
 
18394
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18395
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18396
    if ( temp_val1[8] !== 0 )
18397
    begin
18398
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18399
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18400
    end
18401 87 mihad
 
18402 33 mihad
    // set wb slave to retry response
18403
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18404
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18405
    ok_pci = 1 ;
18406
 
18407
    fork
18408
    begin
18409
        if ( test_mem == 1 )
18410
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18411 87 mihad
                        pci_image_base, 32'hBEAF_DEAD, 4'h5,
18412 33 mihad
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18413
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18414
        else
18415 87 mihad
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h5, 1, `Test_Target_Normal_Completion) ;
18416 33 mihad
 
18417
        do_pause(1) ;
18418
 
18419
        // do another write with same address and different data
18420
        if ( test_mem == 1 )
18421
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18422 87 mihad
                        pci_image_base, 32'h1234_5678, 4'h0,
18423 33 mihad
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18424
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18425
        else
18426 87 mihad
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion) ;
18427 33 mihad
 
18428
        do_pause(1) ;
18429
    end
18430
    begin
18431
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18432
        begin
18433
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18434
            if ( ok_wb !== 1 )
18435
            begin
18436
                $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) ;
18437
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18438
                disable main ;
18439
            end
18440
        end
18441
 
18442
        // set WB slave to normal completion
18443
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18444
 
18445
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18446
        if ( ok_wb !== 1 )
18447
        begin
18448
            $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) ;
18449
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18450
            disable main ;
18451
        end
18452
 
18453 35 mihad
        #1 ;
18454
        if ( !error_monitor_done )
18455 33 mihad
            disable error_monitor3 ;
18456
    end
18457
    begin:error_monitor3
18458 35 mihad
        error_monitor_done = 0 ;
18459 33 mihad
        @(error_event_int) ;
18460
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18461
        ok_pci = 0 ;
18462 35 mihad
        error_monitor_done = 1 ;
18463 33 mihad
    end
18464
    join
18465
 
18466
    if ( ok_wb && ok_pci )
18467
    begin
18468
        test_ok ;
18469
    end
18470
 
18471
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18472
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18473
    if ( temp_val1[8] !== 1'b1 )
18474
    begin
18475
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18476
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18477
    end
18478
 
18479
    if ( temp_val1[9] !== 1 )
18480
    begin
18481
        $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) ;
18482
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18483
    end
18484
 
18485
    if ( temp_val1[10] !== 1 )
18486
    begin
18487
        $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) ;
18488
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18489
    end
18490
 
18491
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18492
    begin
18493
        $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) ;
18494
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18495
    end
18496
 
18497 87 mihad
    if ( temp_val1[31:28] !== 4'h5 )
18498 33 mihad
    begin
18499
        $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) ;
18500 87 mihad
        $display("Expected value: %h, actual value %h", 4'h5, temp_val1[31:28]) ;
18501 33 mihad
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18502
    end
18503
 
18504
    // clear error status register
18505
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18506
 
18507
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18508
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18509
    if ( temp_val1 !== pci_image_base )
18510
    begin
18511
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18512
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18513
    end
18514
 
18515
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18516
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18517 87 mihad
    if ( temp_val1 !== (32'hBEAF_DEAD) )
18518 33 mihad
    begin
18519
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18520 87 mihad
        $display("Expected value %h, actual %h", 32'hBEAF_DEAD, temp_val1) ;
18521 33 mihad
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18522
    end
18523
 
18524
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18525
    ok_pci = 1 ;
18526
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18527
 
18528
    i = 0 ;
18529
    fork
18530
    begin
18531
        if ( test_mem )
18532
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18533
                          pci_image_base + 4, 32'h1234_5678,
18534
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18535
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18536
        else
18537
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18538
 
18539
        do_pause( 1 ) ;
18540
 
18541
    end
18542
    begin
18543
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18544
        begin
18545
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18546
            if ( ok_wb !== 1 )
18547
            begin
18548
                $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) ;
18549
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18550
                disable main ;
18551
            end
18552
        end
18553
 
18554
        // set WB slave to normal completion
18555
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18556
 
18557
        fork
18558
        begin
18559
            repeat(4)
18560
                @(posedge pci_clock) ;
18561
 
18562
            if ( test_mem )
18563
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18564
                              pci_image_base, 32'h8765_4321,
18565
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18566
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18567
            else
18568
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18569
 
18570
            do_pause(1) ;
18571
        end
18572
        begin
18573
 
18574
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18575
            if ( ok_wb !== 1 )
18576
            begin
18577
                $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) ;
18578
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18579
                disable main ;
18580
            end
18581
        end
18582
        join
18583
 
18584
        repeat( 4 )
18585
            @(posedge pci_clock) ;
18586
 
18587
        if ( test_mem )
18588
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18589
                          pci_image_base, 32'h8765_4321,
18590
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18591
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18592
        else
18593
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18594
 
18595
        do_pause(1) ;
18596
 
18597 35 mihad
        #1 ;
18598
        if ( !error_monitor_done )
18599 33 mihad
            disable error_monitor4 ;
18600
    end
18601
    begin:error_monitor4
18602 35 mihad
        error_monitor_done = 0 ;
18603 33 mihad
        @(error_event_int) ;
18604
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18605
        ok_pci = 0 ;
18606 35 mihad
        error_monitor_done = 1 ;
18607 33 mihad
    end
18608
    join
18609
 
18610
    if ( ok_wb && ok_pci )
18611
        test_ok ;
18612
 
18613
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18614
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18615
    if ( temp_val1[8] !== 1'b0 )
18616
    begin
18617
        $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) ;
18618
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18619
    end
18620 87 mihad
 
18621
`ifdef PCI_WBM_NO_RESPONSE_CNT_DISABLE
18622
`else
18623 33 mihad
 
18624
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18625 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18626
    $fdisplay(pciu_mon_log_file_desc,
18627
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18628 33 mihad
    ok_pci = 1 ;
18629
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18630
 
18631
    fork
18632
    begin
18633
        if ( test_mem )
18634
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18635
                          pci_image_base + 4, 32'h1234_5678,
18636
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18637
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18638
        else
18639
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18640
 
18641
        do_pause( 1 ) ;
18642
 
18643
    end
18644
    begin
18645
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18646
        if ( ok_wb !== 1 )
18647
        begin
18648
            $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) ;
18649
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18650
            disable main ;
18651
        end
18652
 
18653
        repeat(4)
18654
            @(posedge pci_clock) ;
18655
 
18656
        fork
18657
        begin
18658
 
18659
            if ( test_mem )
18660
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18661
                              pci_image_base + 4, 32'h8765_4321,
18662
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18663
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18664
            else
18665
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18666
 
18667
            do_pause(1) ;
18668
 
18669
        end
18670
        begin
18671
 
18672
            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 ) ;
18673
            if ( ok !== 1 )
18674
            begin
18675
                $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) ;
18676
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18677
                disable main ;
18678
            end
18679
        end
18680
        join
18681
 
18682 35 mihad
        #1 ;
18683
        if ( !error_monitor_done )
18684 33 mihad
            disable error_monitor5 ;
18685
    end
18686
    begin:error_monitor5
18687 35 mihad
        error_monitor_done = 0 ;
18688 33 mihad
        @(error_event_int) ;
18689
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18690
        ok_pci = 0 ;
18691 35 mihad
        error_monitor_done = 1 ;
18692 33 mihad
    end
18693
    join
18694
 
18695
    if ( ok_wb && ok_pci )
18696
        test_ok ;
18697
 
18698
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18699
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18700
    if ( temp_val1[8] !== 1'b0 )
18701
    begin
18702
        $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) ;
18703
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18704
    end
18705
 
18706
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18707
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18708
    if ( temp_val1[25] !== 1'b1 )
18709
    begin
18710
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18711
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18712
    end
18713
 
18714
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18715
 
18716
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18717
    ok_pci = 1 ;
18718
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18719
 
18720
    fork
18721
    begin
18722
        if ( test_mem == 1 )
18723
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18724 87 mihad
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18725 33 mihad
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18726
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18727
        else
18728 87 mihad
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
18729 33 mihad
 
18730
        do_pause(1) ;
18731
 
18732
        // do another write with same address and different data
18733
        if ( test_mem == 1 )
18734
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18735
                        pci_image_base, 32'h8765_6789, 4'h0,
18736
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18737
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18738
        else
18739
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18740
 
18741
        do_pause(1) ;
18742
    end
18743
    begin
18744
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18745
        if ( ok_wb !== 1 )
18746
        begin
18747
            $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) ;
18748
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18749
            disable main ;
18750
        end
18751
 
18752
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18753
 
18754
        if ( test_mem )
18755
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18756
        else
18757
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18758
 
18759
        if ( ok_wb !== 1 )
18760
        begin
18761
            $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) ;
18762
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18763
            disable main ;
18764
        end
18765
 
18766 35 mihad
        #1 ;
18767
        if ( !error_monitor_done )
18768 33 mihad
            disable error_monitor6 ;
18769
    end
18770
    begin:error_monitor6
18771 35 mihad
        error_monitor_done = 0 ;
18772 33 mihad
        @(error_event_int) ;
18773
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18774
        ok_pci = 0 ;
18775 35 mihad
        error_monitor_done = 1 ;
18776 33 mihad
    end
18777
    join
18778
 
18779
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18780
    $fdisplay(pciu_mon_log_file_desc,
18781
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18782
 
18783
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18784
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18785
    if ( temp_val1[8] !== 1'b1 )
18786
    begin
18787
        $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) ;
18788
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18789
    end
18790
 
18791
    if ( temp_val1[9] !== 0 )
18792
    begin
18793
        $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) ;
18794
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18795
    end
18796
 
18797
    if ( temp_val1[10] !== 1 )
18798
    begin
18799
        $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) ;
18800
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18801
    end
18802
 
18803
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18804
    begin
18805
        $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) ;
18806
        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") ;
18807
    end
18808
 
18809 87 mihad
    if ( temp_val1[31:28] !== 4'hA )
18810 33 mihad
    begin
18811
        $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) ;
18812
        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") ;
18813
    end
18814
 
18815
    // clear error status register
18816
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18817
 
18818
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18819
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18820
    if ( temp_val1 !== pci_image_base )
18821
    begin
18822
        $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) ;
18823
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18824
    end
18825
 
18826
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18827
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18828 87 mihad
    if ( temp_val1 !== 32'hDEAD_BEAF )
18829 33 mihad
    begin
18830
        $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) ;
18831
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18832
    end
18833 87 mihad
`endif
18834 33 mihad
 
18835
    // disable current image - write address mask register
18836 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18837 15 mihad
end
18838 57 mihad
endtask // target_completion_expiration
18839 15 mihad
 
18840 57 mihad
task master_completion_expiration ;
18841
    reg   [11:0] ctrl_offset ;
18842
    reg   [11:0] ba_offset ;
18843
    reg   [11:0] am_offset ;
18844
    reg `WRITE_STIM_TYPE write_data ;
18845
    reg `READ_STIM_TYPE  read_data ;
18846
    reg `READ_RETURN_TYPE read_status ;
18847
 
18848
    reg `WRITE_RETURN_TYPE write_status ;
18849
    reg `WB_TRANSFER_FLAGS write_flags ;
18850
    reg        ok   ;
18851
    reg [11:0] pci_ctrl_offset ;
18852
    reg [31:0] image_base ;
18853
    reg [31:0] target_address ;
18854
begin:main
18855
    pci_ctrl_offset = 12'h4 ;
18856
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
18857
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
18858
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
18859
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
18860
 
18861
    target_address  = `BEH_TAR1_MEM_START ;
18862
    image_base      = 0 ;
18863
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
18864
 
18865
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
18866
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
18867
    write_flags                      = 0 ;
18868
    write_flags`INIT_WAITS           = tb_init_waits ;
18869
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
18870
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18871
 
18872
    // enable master & target operation
18873
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
18874
    if ( ok !== 1 )
18875
    begin
18876
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18877
        test_fail("write to PCI Device Control register didn't succeede");
18878
        disable main ;
18879
    end
18880
 
18881
    // prepare image control register
18882
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
18883
    if ( ok !== 1 )
18884
    begin
18885
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
18886
        test_fail("write to WB Image Control register didn't succeede");
18887
        disable main ;
18888
    end
18889
 
18890
    // prepare base address register
18891
    config_write( ba_offset, image_base, 4'hF, ok ) ;
18892
    if ( ok !== 1 )
18893
    begin
18894
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
18895
        test_fail("write to WB Base Address register didn't succeede");
18896
        disable main ;
18897
    end
18898
 
18899
    // write address mask register
18900
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18901
    if ( ok !== 1 )
18902
    begin
18903
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18904
        test_fail("write to WB Address Mask register didn't succeede");
18905
        disable main ;
18906
    end
18907
 
18908
    fork
18909
    begin
18910
        // do not handle retries
18911
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
18912
 
18913
        // initiate a read request
18914
        read_data`READ_ADDRESS  = target_address ;
18915
        read_data`READ_SEL      = 4'hF ;
18916
        read_data`READ_TAG_STIM = 0 ;
18917
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18918
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
18919
        begin
18920
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18921
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
18922
            disable main ;
18923
        end
18924
 
18925
        // handle retries from now on
18926
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
18927
 
18928
        write_data`WRITE_ADDRESS = target_address + 4 ;
18929
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
18930
        write_data`WRITE_SEL     = 4'hF ;
18931
 
18932
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18933
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18934
        begin
18935
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
18936
            test_fail("WB Slave state machine failed to post single memory write");
18937
            disable main ;
18938
        end
18939
 
18940 81 mihad
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 110
18941
        repeat('h1_0000 - 110)
18942 57 mihad
            @(posedge wb_clock) ;
18943
 
18944
        // now perform a read
18945
        read_data`READ_ADDRESS  = target_address + 4 ;
18946
        read_data`READ_SEL      = 4'hF ;
18947
        read_data`READ_TAG_STIM = 0 ;
18948
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18949
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18950
        begin
18951
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18952
            test_fail("PCI bridge didn't process the read as expected");
18953
            disable main ;
18954
        end
18955
 
18956
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
18957
        begin
18958
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
18959
            test_fail("PCI bridge returned unexpected Read Data");
18960
        end
18961
        else if (ok === 1'b1)
18962
            test_ok ;
18963
    end
18964
    begin:monitors
18965
        // monitor first read, which will expire
18966
        pci_transaction_progress_monitor
18967
        (
18968
            target_address, // expected address
18969
            `BC_MEM_READ,   // expected bus command
18970
            1,              // expected number of transfers
18971
            0,              // expected number of cycles
18972
            1,              // check number of transfers true/false
18973
            0,              // check number of cycles true/false
18974
            0,              // is this fast B2B true/false
18975
            ok              // return 1 if as expected, anything else on error
18976
        ) ;
18977
 
18978
        if ( ok !== 1 )
18979
        begin
18980
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18981
            #1 disable monitors ;
18982
        end
18983
 
18984
        // monitor normal single write
18985
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
18986
        if ( ok !== 1 )
18987
        begin
18988
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18989
            #1 disable monitors ;
18990
        end
18991
 
18992
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
18993 81 mihad
        repeat('h1_0000 - 100)
18994 57 mihad
            @(posedge wb_clock) ;
18995
 
18996
        // monitor normal single memory read
18997
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
18998
        if ( ok !== 1 )
18999
        begin
19000
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19001
        end
19002
    end
19003
    join
19004
 
19005
    // disable the image
19006
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
19007
    if ( ok !== 1 )
19008
    begin
19009
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
19010
        test_fail("write to WB Address Mask register didn't succeede");
19011
    end
19012
end
19013
endtask // master_completion_expiration
19014 63 mihad
`endif
19015 57 mihad
 
19016 15 mihad
task config_write ;
19017
    input [11:0] offset ;
19018
    input [31:0] data ;
19019
    input [3:0]  byte_enable ;
19020
    output       ok ;
19021
    `ifdef HOST
19022
    reg   `WRITE_STIM_TYPE   write_data ;
19023
    reg   `WB_TRANSFER_FLAGS write_flags ;
19024
    reg   `WRITE_RETURN_TYPE write_status ;
19025
    `else
19026
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
19027
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
19028
    `endif
19029
    reg in_use ;
19030
    reg [31:0] temp_var ;
19031
begin
19032
    if ( in_use === 1 )
19033
    begin
19034
        $display("config_read task re-entered! Time %t ", $time) ;
19035
        ok = 0 ;
19036
        #20 $stop ;
19037
    end
19038
    else
19039
    begin
19040
        ok = 1 ;
19041
        in_use = 1 ;
19042
    end
19043
    `ifdef HOST
19044
    write_flags                    = 0 ;
19045
    write_flags`INIT_WAITS         = tb_init_waits ;
19046
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19047
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19048
 
19049
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19050
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19051
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
19052
    write_data`WRITE_SEL                         = byte_enable ;
19053
    write_data`WRITE_TAG_STIM                    = 0 ;
19054
    write_data`WRITE_DATA                        = data ;
19055
 
19056
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
19057
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
19058
    begin
19059
        $display("Write to configuration space failed! Time %t ", $time) ;
19060
        ok = 0 ;
19061
    end
19062
 
19063
    @(posedge wb_clock) ;
19064
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
19065
    // here we just wait for two guest cycles for conf space bits to synchronize
19066
    repeat( 2 )
19067
        @(posedge pci_clock) ;
19068
 
19069
    `else // GUEST
19070
    byte_enables_l = ~byte_enable ;
19071
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19072
 
19073
    fork
19074
    begin
19075
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19076
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
19077
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
19078
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19079
              8'h0_0, `Test_One_Zero_Target_WS,
19080
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
19081
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19082
    do_pause( 1 ) ;
19083
    end
19084
    begin
19085
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
19086
        @(posedge pci_clock) ;
19087
    end
19088
    join
19089
 
19090
     repeat( 2 )
19091
         @(posedge wb_clock) ;
19092
 
19093
    `endif
19094
    in_use = 0 ;
19095
end
19096
endtask // config_write
19097
 
19098
task config_read ;
19099
    input [11:0] offset ;
19100
    input [3:0]  byte_enable ;
19101
    output [31:0] data ;
19102
 
19103
    reg `READ_STIM_TYPE    read_data ;
19104
    reg `WB_TRANSFER_FLAGS read_flags ;
19105
    reg `READ_RETURN_TYPE  read_status ;
19106
 
19107
    reg [31:0] pci_address ;
19108
    reg [3:0] byte_enables_l ;
19109
 
19110
    reg master_check_data_prev ;
19111
    reg in_use ;
19112
    reg [31:0] temp_var ;
19113
begin:main
19114
    if ( in_use === 1 )
19115
    begin
19116
        $display("config_read task re-entered! Time %t ", $time) ;
19117
        data = 32'hxxxx_xxxx ;
19118
        disable main ;
19119
    end
19120
 
19121
    in_use = 1 ;
19122
 
19123
`ifdef HOST
19124 26 mihad
    repeat(4)
19125
        @(posedge pci_clock) ;
19126
    repeat(4)
19127
        @(posedge wb_clock) ;
19128 15 mihad
    read_flags                    = 0 ;
19129
    read_flags`INIT_WAITS         = tb_init_waits ;
19130
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19131
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19132
 
19133
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19134
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19135
 
19136
    read_data`READ_ADDRESS  = temp_var + offset ;
19137
    read_data`READ_SEL      = byte_enable ;
19138
    read_data`READ_TAG_STIM = 0 ;
19139
 
19140
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
19141
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19142
    begin
19143
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
19144
        #20 $stop ;
19145
    end
19146
    data = read_status`READ_DATA ;
19147
`else
19148
  `ifdef GUEST
19149 26 mihad
    repeat(4)
19150
        @(posedge wb_clock) ;
19151
    repeat(4)
19152
        @(posedge pci_clock) ;
19153 15 mihad
    master_check_data_prev = master2_check_received_data ;
19154
    master2_check_received_data = 0 ;
19155
 
19156
    byte_enables_l = ~byte_enable ;
19157
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19158
 
19159
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19160
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
19161
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19162
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19163
             8'h4_0, `Test_One_Zero_Target_WS,
19164
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19165
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19166
    do_pause( 1 ) ;
19167
 
19168
    @(master2_received_data_valid) ;
19169
    data = master2_received_data ;
19170
 
19171
    master2_check_received_data = master_check_data_prev ;
19172
  `endif
19173
`endif
19174
    in_use = 0 ;
19175
end
19176
endtask //config_read
19177
 
19178 62 mihad
`ifdef PCI_BIST
19179
`ifdef WB_RAM_DONT_SHARE
19180
    `ifdef PCI_RAM_DONT_SHARE
19181
        parameter bist_chain_length = 8 ;
19182
    `else
19183
        parameter bist_chain_length = 6 ;
19184
    `endif
19185
`else
19186
    `ifdef PCI_RAM_DONT_SHARE
19187 69 mihad
        parameter bist_chain_length = 6 ;
19188 62 mihad
    `else
19189 69 mihad
        parameter bist_chain_length = 4 ;
19190 62 mihad
    `endif
19191
`endif
19192
 
19193
task run_bist_test ;
19194
    reg [(bist_chain_length - 1):0] bist_result_vector ;
19195
    integer count ;
19196
    integer deadlock_count ;
19197
begin
19198
 
19199
    test_name = "BIST FOR RAMS RUN" ;
19200
 
19201 69 mihad
    scanb_en  = 0 ;
19202
    scanb_si  = 0 ;
19203
    scanb_rst = 0 ;
19204
    scanb_clk = 0 ;
19205 62 mihad
 
19206
    fork
19207
    begin
19208
        repeat(2)
19209
            @(posedge wb_clock) ;
19210
    end
19211
    begin
19212
        repeat(2)
19213
            @(posedge pci_clock) ;
19214
    end
19215
    join
19216
 
19217 69 mihad
    // test is run by reseting the test logic
19218
    scanb_rst <= 1'b1 ;
19219
 
19220
    // toggle scan clock for a few times
19221
    repeat (20)
19222
        #50 scanb_clk = !scanb_clk ;
19223
 
19224
    // release bist reset
19225
    scanb_rst <= 1'b0 ;
19226 62 mihad
 
19227
    bist_result_vector = 0 ;
19228
 
19229
    // result vector must be all 1s, because in RTL there cannot be a reason for BIST to fail
19230
    fork
19231
    begin:scan
19232
        while (bist_result_vector !== {bist_chain_length{1'b1}})
19233
        begin
19234 69 mihad
            #1 ;
19235
            @(posedge scanb_clk) ;
19236
            scanb_en <= #1 1'b1 ;
19237 62 mihad
            for (count = 0 ; count < bist_chain_length ; count = count + 1'b1)
19238
            begin
19239 69 mihad
                @(posedge scanb_clk) ;
19240
                bist_result_vector[count] = scanb_so ;
19241 62 mihad
            end
19242
 
19243 69 mihad
            scanb_en <= #1 1'b0 ;
19244 62 mihad
        end
19245
        #1 disable deadlock ;
19246 69 mihad
        @(negedge scanb_clk) ;
19247
        #1 disable scanb_clk_gen ;
19248 62 mihad
        test_ok ;
19249
    end
19250
    begin:deadlock
19251
        for (deadlock_count = 0; deadlock_count <= 100000; deadlock_count = deadlock_count + 1'b1)
19252
        begin
19253
            @(posedge pci_clock) ;
19254
            @(posedge wb_clock) ;
19255
        end
19256
 
19257
        test_fail("BIST Test didn't finish as expected") ;
19258 69 mihad
        scanb_en <= #1 1'b0 ;
19259 62 mihad
        disable scan ;
19260 69 mihad
        @(negedge scanb_clk) ;
19261 62 mihad
        #1 ;
19262 69 mihad
        disable scanb_clk_gen ;
19263 62 mihad
    end
19264 69 mihad
    begin:scanb_clk_gen
19265 62 mihad
        forever
19266 69 mihad
            #50 scanb_clk = !scanb_clk ;
19267 62 mihad
    end
19268
    join
19269
end
19270
endtask // run_bist_test
19271
`endif
19272
 
19273 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
19274
task target_special_corner_case_test ;
19275
    reg   [11:0]    pci_ctrl_offset ;
19276
    reg   [11:0]    ctrl_offset ;
19277
    reg   [11:0]    ba_offset ;
19278
    reg   [11:0]    am_offset ;
19279
    reg             ok_wb ;
19280
    reg             ok_pci ;
19281
    reg             test_mem ;
19282
    reg             master_check_data_previous ;
19283
begin:main
19284
    master_check_data_previous  = master1_check_received_data ;
19285
    master1_check_received_data = 1'b1 ;
19286
    pci_ctrl_offset = 12'h4 ;
19287
    // use image 1 for this test
19288
    ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
19289
    ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
19290
    am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
19291
 
19292
    // set behavioral slave cycle response
19293
    `ifdef REGISTER_WBM_OUTPUTS
19294
    wishbone_slave.cycle_response
19295
    (
19296
        3'b100,         // {ACK, ERR, RTY}
19297
        0,              // wait cycles
19298
        8'h0            // num of retries before termination
19299
    );
19300
    `else
19301
    wishbone_slave.cycle_response
19302
    (
19303
        3'b100,         // {ACK, ERR, RTY}
19304
        1,              // wait cycles
19305
        8'h0            // num of retries before termination
19306
    );
19307
    `endif
19308
 
19309
    `ifdef HOST
19310
        test_mem = 1 ;
19311
    `else
19312
        test_mem = `PCI_BA1_MEM_IO ;
19313
        test_mem = !test_mem ;
19314
    `endif
19315
 
19316
    test_name = "PCI TARGET UNIT SPECIAL CORNER CASE" ;
19317
 
19318
    // Set Base Address of IMAGE
19319
    config_write( ba_offset, Target_Base_Addr_R[1], 4'hF, ok_wb ) ;
19320
    if ( ok_wb !== 1 )
19321
    begin
19322 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19323 63 mihad
        test_fail("PCI Base Address register 1 could not be written") ;
19324
        #1 ;
19325
        disable main ;
19326
    end
19327
 
19328
    // Set Address Mask of IMAGE
19329
    config_write( am_offset, Target_Addr_Mask_R[1], 4'hF, ok_wb ) ;
19330
    if ( ok_wb !== 1 )
19331
    begin
19332 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_AM1 register! Time %t ", $time);
19333 63 mihad
        test_fail("PCI Address Mask register 1 could not be written") ;
19334
        #1 ;
19335
        disable main ;
19336
    end
19337
 
19338
    // Disable all the features of the PCI Image 1
19339
    config_write( ctrl_offset, 0, 4'hF, ok_wb ) ;
19340
    if ( ok_wb !== 1 )
19341
    begin
19342 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_CTRL1 register! Time %t ", $time);
19343 63 mihad
        test_fail("PCI Image Control register 1 could not be written") ;
19344
        #1 ;
19345
        disable main ;
19346
    end
19347
 
19348
    // set waits to max, which means 0 on PCI
19349
    tb_init_waits   = 4 ;
19350
    tb_subseq_waits = 4 ;
19351
 
19352
    // do one dummy write, to receive a GNT park
19353
    if (test_mem)
19354
    begin
19355
        PCIU_MEM_WRITE
19356
        (
19357
            "MEM_WRITE ",                       // just the name
19358
            `Test_Master_1,                     // Behavioral Master to use for reference
19359
            Target_Base_Addr_R[1],              // Address of this transaction
19360
            32'hAAAA_AAAA,                      // Data For the transaction
19361
            4'h0,                               // Byte enables
19362
            1,                                  // length of transfer
19363
            `Test_One_Zero_Master_WS,           // Master Waits - don't care
19364
            `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19365
            `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19366
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19367
        );
19368
    end
19369
    else
19370
    begin
19371
        PCIU_IO_WRITE
19372
        (
19373
            `Test_Master_1,                     // Behavioral Master to use for reference
19374
            Target_Base_Addr_R[1],              // Address of this transaction
19375
            32'hAAAA_AAAA,                      // Data For the transaction
19376
            4'h0,                               // Byte enables
19377
            1,                                  // Size of transfer
19378
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19379
        ) ;
19380
    end
19381
 
19382
    do_pause( 1 ) ;
19383
    wb_transaction_progress_monitor
19384
    (
19385
        Target_Base_Addr_R[1],          // expected address
19386
        1'b1,                           // expected operation R/W
19387
        1,                              // 1
19388
        1'b1,                           // turn checking of transfers ON/OFF
19389
        ok_wb                           // succeeded/failed
19390
    ) ;
19391
 
19392
    if (ok_wb !== 1'b1)
19393
    begin
19394
        test_fail("WB Transaction Monitor detected invalid transaction on WB bus after posted memory write through target") ;
19395
        #1 ;
19396
        disable main ;
19397
    end
19398
 
19399
    fork
19400
    begin
19401
        if (test_mem)
19402
        begin
19403
            PCIU_MEM_WRITE
19404
            (
19405
                "MEM_WRITE ",                       // just the name
19406
                `Test_Master_1,                     // Behavioral Master to use for reference
19407
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19408
                32'hF0F0_F0F0,                      // Data For the transaction
19409
                4'h0,                               // Byte enables       
19410
                1,                                  // length of transfer
19411
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19412
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19413
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19414
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19415
            );
19416
        end
19417
        else
19418
        begin
19419
            PCIU_IO_WRITE
19420
            (
19421
                `Test_Master_1,                     // Behavioral Master to use for reference
19422
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19423
                32'hF0F0_F0F0,                      // Data For the transaction
19424
                4'h0,                               // Byte enables
19425
                1,                                  // Size of transfer
19426
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19427
            ) ;
19428
        end
19429
 
19430
        do_pause( 1 ) ;
19431
 
19432
        if (test_mem)
19433
        begin
19434
            PCIU_MEM_WRITE
19435
            (
19436
                "MEM_WRITE ",                       // just the name
19437
                `Test_Master_1,                     // Behavioral Master to use for reference
19438
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19439
                32'h0F0F_0F0F,                      // Data For the transaction
19440
                4'h0,                               // Byte enables
19441
                1,                                  // length of transfer
19442
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19443
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19444
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19445
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19446
            );
19447
        end
19448
        else
19449
        begin
19450
            PCIU_IO_WRITE
19451
            (
19452
                `Test_Master_1,                     // Behavioral Master to use for reference
19453
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19454
                32'h0F0F_0F0F,                      // Data For the transaction
19455
                4'h0,                               // Byte enables
19456
                1,                                  // Size of transfer
19457
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19458
            ) ;
19459
        end
19460
 
19461
        do_pause( 1 ) ;
19462
    end
19463
    begin
19464
        wb_transaction_progress_monitor
19465
        (
19466
            Target_Base_Addr_R[1] + 64,     // expected address
19467
            1'b1,                           // expected operation R/W
19468
            1,                              // expected number of transfers
19469
            1'b1,                           // turn checking of transfers ON/OFF
19470
            ok_wb                           // succeeded/failed
19471
        ) ;
19472
 
19473
        if ( ok_wb === 1 )
19474
        begin
19475
 
19476
            wb_transaction_progress_monitor
19477
            (
19478
                Target_Base_Addr_R[1] + 128,    // expected address
19479
                1'b1,                           // expected operation R/W
19480
                1,                              // expected number of transfers
19481
                1'b1,                           // turn checking of transfers ON/OFF
19482
                ok_wb                           // succeeded/failed
19483
            ) ;
19484
        end
19485
 
19486
        @(posedge pci_clock) ;
19487
        #1 ;
19488
        disable pci_error_mon1 ;
19489
    end
19490
    begin:pci_error_mon1
19491
        ok_pci = 1 ;
19492
        @(error_event_int) ;
19493
        ok_pci = 0 ;
19494
    end
19495
    join
19496
 
19497
    if ( ok_wb !== 1'b1 )
19498
    begin
19499
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19500
    end
19501
 
19502
    if ( ok_pci !== 1'b1)
19503
    begin
19504
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19505
    end
19506
 
19507
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19508
    begin
19509
        #1 ;
19510
        disable main ;
19511
    end
19512
 
19513
    if ( test_mem )
19514
    begin
19515
        PCIU_MEM_READ
19516
        (
19517
            "MEM_READ  ",                   // description
19518
            `Test_Master_1,                 // behavioral master selection
19519
            Target_Base_Addr_R[1] + 64,     // address of access
19520
            32'hF0F0_F0F0,                  // expected read data
19521
            1,                              // number of transfers
19522
            8'h7_0,                         // don't care (wait cycles)
19523
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19524
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19525
            `Test_Target_Retry_On           // expected Target termination
19526
        );
19527
    end
19528
    else
19529
    begin
19530
        PCIU_IO_READ
19531
        (
19532
            `Test_Master_1,                 // behavioral master selection
19533
            Target_Base_Addr_R[1] + 64,     // address of access
19534
            32'hF0F0_F0F0,                  // expected read data
19535
            4'h0,                           // byte enables
19536
            1,                              // number of transfers
19537
            `Test_Target_Retry_On           // expected target termination
19538
        ) ;
19539
    end
19540
 
19541 64 mihad
    do_pause(1) ;
19542
 
19543 63 mihad
    wb_transaction_progress_monitor
19544
    (
19545
            Target_Base_Addr_R[1] + 64,     // expected address
19546
            1'b0,                           // expected operation R/W
19547
            1,                              // expected number transfers
19548
            1'b1,                           // turn checking of transfers ON/OFF
19549
            ok_wb                           // succeeded/failed
19550
    ) ;
19551
 
19552
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19553
    repeat(3)
19554
        @(posedge pci_clock) ;
19555
 
19556
    // now read data
19557
    fork
19558
    begin
19559
        if ( test_mem )
19560
        begin
19561
            PCIU_MEM_READ
19562
            (
19563
                "MEM_READ  ",                   // description
19564
                `Test_Master_1,                 // behavioral master selection
19565
                Target_Base_Addr_R[1] + 64,     // address of access
19566
                32'hF0F0_F0F0,                  // expected read data
19567
                1,                              // number of transfers
19568
                8'h7_0,                         // don't care (wait cycles)
19569
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19570
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19571
                `Test_Target_Normal_Completion  // expected Target termination
19572
            );
19573
        end
19574
        else
19575
        begin
19576
            PCIU_IO_READ
19577
            (
19578
                `Test_Master_1,                 // behavioral master selection
19579
                Target_Base_Addr_R[1] + 64,     // address of access
19580
                32'hF0F0_F0F0,                  // expected read data
19581
                4'h0,                           // byte enables
19582
                1,                              // number of transfers
19583
                `Test_Target_Normal_Completion  // expected target termination
19584
            ) ;
19585
        end
19586
 
19587 64 mihad
        do_pause(1) ;
19588 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19589
            @(posedge pci_clock) ;
19590
 
19591
        @(posedge pci_clock) ;
19592
        #1 ;
19593
        disable pci_error_mon2 ;
19594
    end
19595
    begin:pci_error_mon2
19596
        ok_pci = 1 ;
19597
        @(error_event_int) ;
19598
        ok_pci = 0 ;
19599
    end
19600
    join
19601
 
19602
    if ( ok_wb !== 1'b1 )
19603
    begin
19604
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19605
    end
19606
 
19607
    if ( ok_pci !== 1'b1)
19608
    begin
19609
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19610
    end
19611
 
19612
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19613
    begin
19614
        #1 ;
19615
        disable main ;
19616
    end
19617
 
19618
    if ( test_mem )
19619
    begin
19620
        PCIU_MEM_READ
19621
        (
19622
            "MEM_READ  ",                   // description
19623
            `Test_Master_1,                 // behavioral master selection
19624
            Target_Base_Addr_R[1] + 128,    // address of access
19625
            32'h0F0F_0F0F,                  // expected read data
19626
            1,                              // number of transfers
19627
            8'h7_0,                         // don't care (wait cycles)
19628
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19629
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19630
            `Test_Target_Retry_On           // expected Target termination
19631
        );
19632
    end
19633
    else
19634
    begin
19635
        PCIU_IO_READ
19636
        (
19637
            `Test_Master_1,                 // behavioral master selection
19638
            Target_Base_Addr_R[1] + 128,    // address of access
19639
            32'h0F0F_0F0F,                  // expected read data
19640
            4'h0,                           // byte enables
19641
            1,                              // number of transfers
19642
            `Test_Target_Retry_On           // expected target termination
19643
        ) ;
19644
    end
19645
 
19646 64 mihad
    do_pause(1) ;
19647 63 mihad
    wb_transaction_progress_monitor
19648
    (
19649
            Target_Base_Addr_R[1] + 128,    // expected address
19650
            1'b0,                           // expected operation R/W
19651
            1,                              // expected number transfers
19652
            1'b1,                           // turn checking of transfers ON/OFF
19653
            ok_wb                           // succeeded/failed
19654
    ) ;
19655
 
19656
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19657
    repeat(3)
19658
        @(posedge pci_clock) ;
19659
 
19660
    // now read data
19661
    fork
19662
    begin
19663
        if ( test_mem )
19664
        begin
19665
            PCIU_MEM_READ
19666
            (
19667
                "MEM_READ  ",                   // description
19668
                `Test_Master_1,                 // behavioral master selection
19669
                Target_Base_Addr_R[1] + 128,    // address of access
19670
                32'h0F0F_0F0F,                  // expected read data
19671
                1,                              // number of transfers
19672
                8'h7_0,                         // don't care (wait cycles)
19673
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19674
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19675
                `Test_Target_Normal_Completion  // expected Target termination
19676
            );
19677
        end
19678
        else
19679
        begin
19680
            PCIU_IO_READ
19681
            (
19682
                `Test_Master_1,                 // behavioral master selection
19683
                Target_Base_Addr_R[1] + 128,    // address of access
19684
                32'h0F0F_0F0F,                  // expected read data
19685
                4'h0,                           // byte enables
19686
                1,                              // number of transfers
19687
                `Test_Target_Normal_Completion  // expected target termination
19688
            ) ;
19689
        end
19690
 
19691 64 mihad
        do_pause(1) ;
19692 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19693
            @(posedge pci_clock) ;
19694
 
19695
        @(posedge pci_clock) ;
19696
        #1 ;
19697
        disable pci_error_mon3 ;
19698
    end
19699
    begin:pci_error_mon3
19700
        ok_pci = 1 ;
19701
        @(error_event_int) ;
19702
        ok_pci = 0 ;
19703
    end
19704
    join
19705
 
19706
    if ((ok_wb === 1'b1) && (ok_pci === 1'b1))
19707
        test_ok ;
19708
 
19709
    if ( ok_wb !== 1'b1 )
19710
    begin
19711
        test_fail("WB Master started invalid transaction or none at all after Target read was requested") ;
19712
    end
19713
 
19714
    if ( ok_pci !== 1'b1)
19715
    begin
19716
        test_fail("PCI Behavioral Master or Monitor signaled an error during read from PCI Bridge Target") ;
19717
    end
19718
 
19719 69 mihad
    // Disable used image
19720
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
19721
    if ( ok_wb !== 1 )
19722
    begin
19723
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19724
        test_fail("PCI Base Address register 1 could not be written") ;
19725
        #1 ;
19726
        disable main ;
19727
    end
19728
 
19729 63 mihad
    master1_check_received_data = master_check_data_previous ;
19730
end
19731
endtask // target_special_corner_case_test
19732
`endif
19733
 
19734 69 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
19735
task master_special_corner_case_test ;
19736
    reg   [11:0] ctrl_offset ;
19737
    reg   [11:0] ba_offset ;
19738
    reg   [11:0] am_offset ;
19739
    reg `WRITE_STIM_TYPE write_data ;
19740
    reg `READ_STIM_TYPE  read_data ;
19741
    reg `READ_RETURN_TYPE read_status ;
19742
 
19743
    reg `WRITE_RETURN_TYPE write_status ;
19744
    reg `WB_TRANSFER_FLAGS flags ;
19745
    reg ok_pci   ;
19746
    reg ok_wb ;
19747
 
19748
    reg [31:0] target_address ;
19749
 
19750
    reg [11:0] pci_ctrl_offset ;
19751
 
19752
    reg [31:0] image_base ;
19753
begin:main
19754
    test_name = "WISHBONE SLAVE UNIT SPECIAL CORNER CASE" ;
19755
    pci_ctrl_offset = 12'h4 ;
19756
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
19757
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
19758
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
19759
 
19760
    target_address  = `BEH_TAR1_MEM_START ;
19761
    image_base      = 0 ;
19762
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
19763
 
19764
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
19765
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
19766
 
19767
    flags                      = 0 ;
19768
    flags`INIT_WAITS           = 0 ;
19769
    flags`SUBSEQ_WAITS         = 0 ;
19770
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
19771
 
19772
    test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = `Test_Devsel_Fast ;
19773
    test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
19774
    test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
19775
 
19776
    // enable master & target operation
19777
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok_wb) ;
19778
    if ( ok_wb !== 1 )
19779
    begin
19780
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write PCI Device Control register! Time %t ", $time) ;
19781
        test_fail("write to PCI Device Control register didn't succeede");
19782
        disable main ;
19783
    end
19784
 
19785
    // prepare image control register
19786
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok_wb) ;
19787
    if ( ok_wb !== 1 )
19788
    begin
19789
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
19790
        test_fail("write to WB Image Control register didn't succeede");
19791
        disable main ;
19792
    end
19793
 
19794
    // prepare base address register
19795
    config_write( ba_offset, image_base, 4'hF, ok_wb ) ;
19796
    if ( ok_wb !== 1 )
19797
    begin
19798
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
19799
        test_fail("write to WB Base Address register didn't succeede");
19800
        disable main ;
19801
    end
19802
 
19803
    // write address mask register
19804
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok_wb ) ;
19805
    if ( ok_wb !== 1 )
19806
    begin
19807
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_AM1 register! Time %t ", $time) ;
19808
        test_fail("write to WB Address Mask register didn't succeede");
19809
        disable main ;
19810
    end
19811
 
19812
    fork
19813
    begin
19814
 
19815
        // do one dummy read, to receive bus gnt
19816
        read_data`READ_ADDRESS  = target_address ;
19817
        read_data`READ_SEL      = 4'hF ;
19818
        read_data`READ_TAG_STIM = 0 ;
19819
 
19820
        // handle retries
19821
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19822
 
19823
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19824
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19825
        begin
19826
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19827
            test_fail("PCI bridge didn't process the delayed read as expected");
19828
            disable main ;
19829
        end
19830
 
19831
        write_data`WRITE_ADDRESS = target_address + 64;
19832
        write_data`WRITE_DATA    = 32'hABCD_EF12 ;
19833
        write_data`WRITE_SEL     = 4'hF ;
19834
 
19835
        wishbone_master.blk_write_data[0] = write_data ;
19836
 
19837
        write_data`WRITE_ADDRESS = target_address + 128 ;
19838
        write_data`WRITE_DATA    = ~write_data`WRITE_DATA ;
19839
        write_data`WRITE_SEL     = 4'hF ;
19840
 
19841
        wishbone_master.blk_write_data[1] = write_data ;
19842
 
19843
        // no retries should happen
19844
        flags`WB_TRANSFER_AUTO_RTY = 0 ;
19845
 
19846
        flags`WB_TRANSFER_SIZE = 2 ;
19847
 
19848
        wishbone_master.wb_block_write( flags, write_status ) ;
19849
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
19850
        begin
19851
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process block memory write! Time %t ", $time) ;
19852
            test_fail("WB Slave state machine failed to post block memory write");
19853
            disable main ;
19854
        end
19855
 
19856
        // read data back
19857
        read_data`READ_ADDRESS  = target_address + 64 ;
19858
        read_data`READ_SEL      = 4'hF ;
19859
        read_data`READ_TAG_STIM = 0 ;
19860
 
19861
        // handle retries
19862
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19863
 
19864
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19865
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19866
        begin
19867
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19868
            test_fail("PCI bridge didn't process the delayed read as expected");
19869
            disable main ;
19870
        end
19871
 
19872
        if (read_status`READ_DATA !== 32'hABCD_EF12)
19873
        begin
19874
            display_warning(target_address + 64, 32'hABCD_EF12, read_status`READ_DATA) ;
19875
            test_fail("PCI bridge returned unexpected Read Data");
19876
            ok_wb = 0 ;
19877
        end
19878
 
19879
        // read second data back
19880
        read_data`READ_ADDRESS  = target_address + 128 ;
19881
        read_data`READ_SEL      = 4'hF ;
19882
        read_data`READ_TAG_STIM = 0 ;
19883
 
19884
        // handle retries
19885
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19886
 
19887
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19888
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19889
        begin
19890
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19891
            test_fail("PCI bridge didn't process the delayed read as expected");
19892
            disable main ;
19893
        end
19894
 
19895
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
19896
        begin
19897
            display_warning(target_address + 128, write_data`WRITE_DATA, read_status`READ_DATA) ;
19898
            test_fail("PCI bridge returned unexpected Read Data");
19899
            ok_wb = 0 ;
19900
        end
19901
    end
19902
    begin
19903
 
19904
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19905
        if ( ok_pci !== 1 )
19906
        begin
19907
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19908
        end
19909
 
19910
        if(ok_pci)
19911
        begin
19912
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
19913
            if ( ok_pci !== 1 )
19914
            begin
19915
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19916
            end
19917
        end
19918
 
19919
        if (ok_pci)
19920
        begin
19921
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
19922
            if ( ok_pci !== 1 )
19923
            begin
19924
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19925
            end
19926
        end
19927
 
19928
        if (ok_pci)
19929
        begin
19930
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19931
            if ( ok_pci !== 1 )
19932
            begin
19933
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19934
            end
19935
        end
19936
 
19937
        if (ok_pci)
19938
        begin
19939
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19940
            if ( ok_pci !== 1 )
19941
            begin
19942
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19943
            end
19944
        end
19945
    end
19946
    join
19947
 
19948
    if (ok_wb && ok_pci)
19949
        test_ok ;
19950
 
19951
    // disable the image
19952
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
19953
    if ( ok_wb !== 1 )
19954
    begin
19955
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
19956
        test_fail("write to WB Base Address register didn't succeede");
19957
        disable main ;
19958
    end
19959
end
19960
endtask // master_special_corner_case_test
19961
`endif
19962
 
19963 73 mihad
task test_target_overload ;
19964
    reg ok_pci ;
19965
    reg ok_wb  ;
19966
    reg ok ;
19967
    reg [2:0] test_image_num ;
19968
    reg addr_translated ;
19969
    integer transfered ;
19970
    reg [2:0] received_termination ;
19971
    integer total_transfers ;
19972
    reg [31:0] transaction_sizes [0:1024] ;
19973
    integer pci_transaction_num ;
19974
    integer wb_transaction_num ;
19975
    reg [31:0] current_wb_address ;
19976
    reg io_mapped ;
19977
    integer init_waits_backup ;
19978
    integer current_size ;
19979
begin:main
19980
    init_waits_backup = tb_init_waits ;
19981
    tb_init_waits = 0 ;
19982
 
19983
    `ifdef HOST
19984
    io_mapped = 1'b0 ;
19985
    `endif
19986
 
19987
    test_image_num = 'd1 ;
19988
    `ifdef GUEST
19989
    io_mapped = `PCI_BA1_MEM_IO ;
19990
    `endif
19991
 
19992
    `ifdef PCI_IMAGE2
19993
        test_image_num = 'd2 ;
19994
        `ifdef GUEST
19995
            io_mapped = `PCI_BA2_MEM_IO ;
19996
        `endif
19997
    `endif
19998
 
19999
    `ifdef PCI_IMAGE3
20000
        test_image_num = 'd3 ;
20001
        `ifdef GUEST
20002
            io_mapped = `PCI_BA3_MEM_IO ;
20003
        `endif
20004
    `endif
20005
 
20006
    `ifdef PCI_IMAGE4
20007
        test_image_num = 'd4 ;
20008
        `ifdef GUEST
20009
            io_mapped = `PCI_BA4_MEM_IO ;
20010
        `endif
20011
    `endif
20012
 
20013
    `ifdef PCI_IMAGE5
20014
        test_image_num = 'd5 ;
20015
        `ifdef GUEST
20016
            io_mapped = `PCI_BA5_MEM_IO ;
20017
        `endif
20018
    `endif
20019
 
20020
    test_name = "PCI TARGET OVERLOAD" ;
20021
    // configure target image 1 via bus accesses
20022
    pci_configure_pci_target_image
20023
    (
20024
        1'b1,                               // selects whether to configure image with bus accesses or directly with dot notation in the configuration space
20025
        test_image_num,                     // image number
20026
        Target_Base_Addr_R[test_image_num], // base address
20027
        Target_Addr_Mask_R[test_image_num], // address mask
20028
        Target_Tran_Addr_R[test_image_num], // translation address
20029
        1'b0,                               // io/mem mapping select
20030
        1'b0,                               // prefetch enable
20031
        1'b1,                               // address translation enable
20032
        ok                                  // finished succesfully
20033
    );
20034
    if (ok !== 1'b1)
20035
    begin
20036
        test_fail("configuration of PCI Target Image didn't succeede") ;
20037
        tb_init_waits = init_waits_backup ;
20038
        #1 disable main ;
20039
    end
20040
 
20041
    `ifdef ADDR_TRAN_IMPL
20042
        addr_translated = 1'b1 ;
20043
    `else
20044
        addr_translated = 1'b0 ;
20045
    `endif
20046
 
20047
    // set wb slave's response to max wait cycles
20048
    wishbone_slave.cycle_response
20049
    (
20050
        3'b100,          // ACK, ERR, RTY termination
20051
        tb_subseq_waits, // wait cycles before response
20052
 
20053
    ) ;
20054
 
20055
    ok_pci = 1 ;
20056
    ok_wb  = 1 ;
20057
    current_wb_address = pci_to_wb_addr_convert
20058
                               (
20059
                                    Target_Base_Addr_R[test_image_num], // pci address
20060
                                    Target_Tran_Addr_R[test_image_num], // translation address
20061
                                    addr_translated
20062
                               );
20063
    current_wb_address = current_wb_address & Target_Addr_Mask_R[test_image_num] ;
20064
 
20065
    for (current_size = 2 ; (current_size <= 1024) && ok_pci && ok_wb && ok ; current_size = current_size * 2)
20066
    begin
20067
 
20068
        total_transfers = 0 ;
20069
        pci_transaction_num = 0 ;
20070
        wb_transaction_num = 0 ;
20071
 
20072
        current_wb_address = current_wb_address & Target_Addr_Mask_R[test_image_num] ;
20073
        current_wb_address = current_wb_address + (('d1024 - current_size) * 4) ;
20074
        fork
20075
        begin
20076
            while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20077
            begin
20078
                // try transfering 4kB with no wait cycles through the target
20079
                ipci_unsupported_commands_master.normal_write_transfer
20080
                (
20081
                    // always write to the end of the 4kB window
20082
                    (('d1024 - current_size) * 4) + Target_Base_Addr_R[test_image_num] + (4 * total_transfers), // start_address
20083
                    io_mapped ? `BC_IO_WRITE : `BC_MEM_WRITE,                                                   // bus_command
20084
                    (current_size - total_transfers),                                                           // size
20085
                    4 - tb_subseq_waits[2:0],                                                                   // subsequent wait cycles
20086
                    transfered,                                                                                 // actual_transfer
20087
                    received_termination                                                                        // received_termination
20088
                );
20089
                if (transfered > 0)
20090
                begin
20091
                    transaction_sizes[pci_transaction_num] = transfered ;
20092
                    pci_transaction_num = pci_transaction_num + 1'b1 ;
20093
                end
20094
                total_transfers = total_transfers + transfered ;
20095
                if (received_termination > 2) // terminations with numbers 3(Target Abort), 4(Master Abort) and 5(Error) are not allowed
20096
                begin
20097
                    ok_pci = 0 ;
20098
                    if (received_termination == 3)
20099
                        test_fail("PCI Target signalled Target Abort") ;
20100
 
20101
                    if (received_termination == 4)
20102
                        test_fail("PCI Master generated Master Abort") ;
20103
 
20104
                    if (received_termination == 5)
20105
                        test_fail("PCI behavioral master signaled severe error") ;
20106
                end
20107
            end
20108
        end
20109
        begin:wb_monitoring
20110
            while (((total_transfers < current_size) || (pci_transaction_num > wb_transaction_num)) && ok_pci && ok_wb && ok)
20111
            begin
20112
                wait(pci_transaction_num > wb_transaction_num) ;
20113
                wb_transaction_progress_monitor
20114
                (
20115
                    current_wb_address,                     //address
20116
                    1'b1,                                   //write/read
20117
                    transaction_sizes[wb_transaction_num],  //num_of_transfers
20118
                    1'b1,                                   //check_transfers
20119
                    ok_wb                                   // success/fail
20120
                );
20121
                current_wb_address = current_wb_address + (transaction_sizes[wb_transaction_num] * 4) ;
20122
                wb_transaction_num = wb_transaction_num + 1'b1 ;
20123
                if (ok_wb !== 1'b1)
20124
                begin
20125
                    test_fail("WB Transaction progress monitor detected invalid transaction or none at all on WB bus");
20126
                end
20127
            end
20128
 
20129
            wb_transaction_num = wb_transaction_num - 1'b1 ;
20130
            current_wb_address = current_wb_address - (transaction_sizes[wb_transaction_num] * 4) ;
20131
 
20132
            if (ok)
20133
                #1 disable pci_monitoring ;
20134
        end
20135
        begin:pci_monitoring
20136
            @(error_event_int) ;
20137
            test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20138
            ok = 0 ;
20139
            ok_pci = 0 ;
20140
            ok_wb  = 0 ;
20141
        end
20142
        join
20143
    end
20144
 
20145
    if ((ok && ok_wb && ok_pci) === 1'b1)
20146
        test_ok ;
20147
 
20148
    tb_init_waits = init_waits_backup ;
20149
end
20150
endtask // test_target_overload
20151
 
20152
task test_master_overload ;
20153
    reg ok_pci ;
20154
    reg ok_wb  ;
20155
    reg ok ;
20156
    reg [2:0] test_image_num ;
20157
    integer transfered ;
20158
    reg [2:0] received_termination ;
20159
    integer total_transfers ;
20160
    reg [31:0] transaction_sizes [0:1024] ;
20161
    integer pci_transaction_num ;
20162
    integer wb_transaction_num ;
20163
    reg [31:0] current_pci_address ;
20164
    integer init_waits_backup ;
20165
    integer current_size ;
20166
 
20167
    reg `WRITE_STIM_TYPE write_data ;
20168
 
20169
    reg `WRITE_RETURN_TYPE write_status ;
20170
    reg `WB_TRANSFER_FLAGS write_flags ;
20171
 
20172
    reg [31:0] image_base ;
20173
    reg [31:0] target_address ;
20174
 
20175
    integer i ;
20176
begin:main
20177
 
20178
    // set behavioral target to respond normally
20179
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
20180
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
20181
 
20182
    test_image_num = 'd1 ;
20183
 
20184
    `ifdef WB_IMAGE2
20185
        test_image_num = 'd2 ;
20186
    `endif
20187
 
20188
    `ifdef WB_IMAGE3
20189
        test_image_num = 'd3 ;
20190
    `endif
20191
 
20192
    `ifdef WB_IMAGE4
20193
        test_image_num = 'd4 ;
20194
    `endif
20195
 
20196
    `ifdef WB_IMAGE5
20197
        test_image_num = 'd5 ;
20198
    `endif
20199
 
20200
    test_name = "MASTER OVERLOAD" ;
20201
 
20202
    target_address  = `BEH_TAR1_MEM_START ;
20203
    image_base      = 0 ;
20204
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
20205
 
20206
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
20207
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
20208
 
20209
    write_flags                      = 0 ;
20210
    write_flags`INIT_WAITS           = tb_init_waits ;
20211
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
20212
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
20213
    write_flags`WB_TRANSFER_CAB      = 1'b1 ;
20214
 
20215
    pci_configure_wb_slave_image
20216
    (
20217
        1'b1,           // use_bus
20218
        test_image_num, // image_num
20219
        image_base,     // base address
20220
        32'hFFFF_FFFF,  //  address mask
20221
        32'h0000_0000,  // translation address
20222
        1'b0,           // io/mem mapping select
20223
        1'b1,           // prefetch enable
20224
        1'b0,           // address translation enable
20225
        1'b1,           // memory read line enable
20226
        ok              // finished succesfully
20227
    ) ;
20228
 
20229
    if (ok !== 1'b1)
20230
    begin
20231
        test_fail("WB image configuration failed") ;
20232
        disable main ;
20233
    end
20234
 
20235
    // fill wishbone master's memory with data - inverted addresses
20236
    write_data = 0 ;
20237
    for (i = 0 ; i < 1024 ; i = i + 1)
20238
    begin
20239
        write_data`WRITE_ADDRESS = image_base + (4 * i) ;
20240
        write_data`WRITE_DATA    = ~(write_data`WRITE_ADDRESS);
20241
        wishbone_master.blk_write_data[i] = write_data ;
20242
    end
20243
 
20244
    ok_wb  = 1 ;
20245
    ok_pci = 1 ;
20246
 
20247
    total_transfers = 0 ;
20248
 
20249
    for (current_size = 2 ; (current_size <= 1024) && ok_pci && ok_wb && ok ; current_size = current_size * 2)
20250
    begin
20251
 
20252
        total_transfers = 0 ;
20253
        pci_transaction_num = 0 ;
20254
        wb_transaction_num = 0 ;
20255
 
20256
        current_pci_address = image_base ;
20257
        fork
20258
        begin
20259
            while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20260
            begin
20261
                // try transfering 4kB with no wait cycles through the wb slave unit
20262
                write_flags`WB_TRANSFER_SIZE = current_size - total_transfers ;
20263
                wishbone_master.wb_block_write(write_flags, write_status) ;
20264
                if (write_status`CYC_ERR || ((write_status`CYC_ERR !== 1'b1) && (write_status`CYC_RTY !== 1'b1) && (write_status`CYC_ACK !== 1'b1)))
20265
                begin
20266
                    test_fail("Wishbone slave signaled an error or did not respond to normal write access") ;
20267
                    ok_wb = 0 ;
20268
                end
20269
 
20270
                transfered = write_status`CYC_ACTUAL_TRANSFER ;
20271
                if (transfered > 0)
20272
                begin
20273
                    transaction_sizes[wb_transaction_num] = transfered ;
20274
                    wb_transaction_num = wb_transaction_num + 1'b1 ;
20275
                end
20276
                total_transfers = total_transfers + transfered ;
20277
            end
20278
        end
20279
        begin:pci_models_monitoring
20280
            while (((total_transfers < current_size) || (wb_transaction_num > pci_transaction_num)) && ok_pci && ok_wb && ok)
20281
            begin
20282
                wait(wb_transaction_num > pci_transaction_num) ;
20283
                pci_transaction_progress_monitor
20284
                (
20285
                    current_pci_address,                        // address
20286
                    `BC_MEM_WRITE,                              // bus_command
20287
                    transaction_sizes[pci_transaction_num],     // num_of_transfers
20288
                    0,                                          // num_of_cycles
20289
                    1'b1,                                       // check_transfers
20290
                    1'b0,                                       // check_cycles
20291
                    1'b0,                                       // doing_fast_back_to_back
20292
                    ok_pci                                      // ok
20293
                ) ;
20294
 
20295
                pci_transaction_num = pci_transaction_num + 1'b1 ;
20296
                if (ok_pci !== 1'b1)
20297
                begin
20298
                    test_fail("PCI Transaction progress monitor detected invalid transaction or none at all on PCI bus");
20299
                end
20300
            end
20301
 
20302
            if (ok)
20303
                #1 disable pci_monitoring ;
20304
        end
20305
        begin:pci_monitoring
20306
            @(error_event_int) ;
20307
            test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20308
            ok = 0 ;
20309
            ok_pci = 0 ;
20310
            ok_wb  = 0 ;
20311
        end
20312
        join
20313
    end
20314
 
20315
    // disable the image
20316
    pci_configure_wb_slave_image
20317
    (
20318
        1'b1,           // use_bus
20319
        test_image_num, // image_num
20320
        image_base,     // base address
20321
        32'h0000_0000,  //  address mask
20322
        32'h0000_0000,  // translation address
20323
        1'b0,           // io/mem mapping select
20324
        1'b1,           // prefetch enable
20325
        1'b0,           // address translation enable
20326
        1'b1,           // memory read line enable
20327
        ok              // finished succesfully
20328
    ) ;
20329
 
20330
    if (ok !== 1'b1)
20331
    begin
20332
        test_fail("WB image configuration failed") ;
20333
        disable main ;
20334
    end
20335
 
20336
    if ((ok && ok_wb && ok_pci) === 1'b1)
20337
        test_ok ;
20338
end
20339
endtask // test_master_overload
20340
 
20341 15 mihad
task test_fail ;
20342
    input [7999:0] failure_reason ;
20343
    reg   [8007:0] display_failure ;
20344
    reg   [799:0] display_test ;
20345
begin
20346
    tests_failed = tests_failed + 1 ;
20347
 
20348
    display_failure = {failure_reason, "!"} ;
20349
    while ( display_failure[7999:7992] == 0 )
20350
        display_failure = display_failure << 8 ;
20351
 
20352
    display_test = test_name ;
20353
    while ( display_test[799:792] == 0 )
20354
       display_test = display_test << 8 ;
20355
 
20356 63 mihad
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20357 15 mihad
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
20358
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
20359
    $fdisplay( tb_log_file, " *FAILED* because") ;
20360
    $fdisplay( tb_log_file, " %s", display_failure ) ;
20361 63 mihad
    current_test_parameters ;
20362
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20363 15 mihad
    $fdisplay( tb_log_file, " " ) ;
20364
 
20365
    `ifdef STOP_ON_FAILURE
20366
    #20 $stop ;
20367
    `endif
20368
end
20369
endtask // test_fail
20370
 
20371
task test_ok ;
20372
    reg [799:0] display_test ;
20373
begin
20374
   tests_successfull = tests_successfull + 1 ;
20375
 
20376
   display_test = test_name ;
20377
   while ( display_test[799:792] == 0 )
20378
       display_test = display_test << 8 ;
20379
 
20380 63 mihad
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20381 15 mihad
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
20382
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
20383
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
20384 63 mihad
   current_test_parameters ;
20385
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20386 15 mihad
   $fdisplay( tb_log_file, " " ) ;
20387
end
20388
endtask // test_ok
20389
 
20390
task test_summary;
20391
begin
20392 63 mihad
    $fdisplay(tb_log_file, "\n \n");
20393 15 mihad
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
20394
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
20395
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
20396
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
20397
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
20398
    $fclose(tb_log_file) ;
20399
end
20400
endtask
20401
 
20402 63 mihad
task current_test_parameters ;
20403
    reg [87:0] decode_speed_text ;
20404
begin
20405
    case (tb_target_decode_speed)
20406
        3'b000: decode_speed_text = "FAST       " ;
20407
        3'b001: decode_speed_text = "MEDIUM     " ;
20408
        3'b010: decode_speed_text = "SLOW       " ;
20409
        3'b011: decode_speed_text = "SUBTRACTIVE" ;
20410
    endcase
20411
 
20412
    $fdisplay( tb_log_file, "TEST PARAMETERS:") ;
20413
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Initial Wait States         = %d", (3'd4 - tb_init_waits)) ;
20414
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Subsequent Wait States      = %d", (3'd4 - tb_subseq_waits)) ;
20415
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' DEVSEL speed                = %s", decode_speed_text) ;
20416
 
20417
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Initial Wait States    = %d", tb_init_waits) ;
20418
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Subsequent Wait States = %d", tb_subseq_waits) ;
20419
end
20420
endtask
20421
 
20422 73 mihad
`include "pci_bench_common_tasks.v"
20423 15 mihad
endmodule

powered by: WebSVN 2.1.0

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