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

Subversion Repositories pci

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

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 73 mihad
// Revision 1.12  2002/10/21 13:04:30  mihad
43
// Changed BIST signal names etc..
44
//
45 69 mihad
// Revision 1.11  2002/10/11 12:03:12  mihad
46
// The testcase I just added in previous revision repaired
47
//
48 64 mihad
// Revision 1.10  2002/10/11 10:08:57  mihad
49
// Added additional testcase and changed rst name in BIST to trst
50
//
51 63 mihad
// Revision 1.9  2002/10/08 17:17:02  mihad
52
// Added BIST signals for RAMs.
53
//
54 62 mihad
// Revision 1.8  2002/09/25 09:54:47  mihad
55
// Added completion expiration test for WB Slave unit. Changed expiration signalling
56
//
57 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
58
// Oops, never before noticed that OC header is missing
59 52 mihad
//
60 57 mihad
//
61 52 mihad
 
62 15 mihad
`include "pci_constants.v"
63
`include "bus_commands.v"
64
`include "pci_testbench_defines.v"
65
`include "timescale.v"
66
 
67 51 mihad
`ifdef HOST
68
    `ifdef NO_CNF_IMAGE
69
    `else
70
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
71
    `endif
72
`else
73
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
74
`endif
75
 
76 15 mihad
module SYSTEM ;
77
 
78
`include "pci_blue_constants.vh"
79
`include "pci_blue_options.vh"
80
 
81
integer tests_successfull ;
82
integer tests_failed ;
83
integer tb_log_file ;
84
reg [799:0] test_name ;
85
 
86
reg pci_clock ;
87
reg wb_clock ;
88
reg reset ;
89
 
90
wire [4:0] arb_grant_out ;
91
 
92
wire [31:0] AD ;
93
wire [3:0]  CBE ;
94
pullup(INTA) ;
95
pullup(MAS0_REQ) ;
96
pullup(MAS1_REQ) ;
97
pullup(MAS2_REQ) ;
98
pullup(MAS3_REQ) ;
99
 
100
wire MAS0_GNT = ~arb_grant_out[0];
101
wire MAS1_GNT = ~arb_grant_out[1] ;
102
wire MAS2_GNT = ~arb_grant_out[2] ;
103
wire MAS3_GNT = ~arb_grant_out[3] ;
104
 
105
pullup(FRAME) ;
106
pullup(IRDY) ;
107 45 mihad
 
108
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
109
 
110 15 mihad
pullup(DEVSEL) ;
111
pullup(TRDY) ;
112
pullup(STOP) ;
113
wire   PAR ;
114
pullup(PERR) ;
115
pullup(SERR) ;
116
wire [3:0] MAS1_IDSEL ;
117
 
118
pullup lockpu ( LOCK ) ;
119
 
120
wire        RST_O ;
121
wire        INT_O ;
122
reg         INT_I ;
123
wire [31:0] ADR_I ;
124
wire [31:0] SDAT_I ;
125
wire [31:0] SDAT_O ;
126
wire [3:0]  SEL_I ;
127
wire        CYC_I ;
128
wire        STB_I ;
129
wire        WE_I ;
130
wire        CAB_I ;
131
wire        ACK_O ;
132
wire        RTY_O ;
133
wire        ERR_O ;
134
 
135
wire [31:0] ADR_O ;
136
wire [31:0] MDAT_I ;
137
wire [31:0] MDAT_O ;
138
wire [3:0]  SEL_O ;
139
wire        CYC_O ;
140
wire        STB_O ;
141
wire        WE_O ;
142
wire        CAB_O ;
143
wire        ACK_I ;
144
wire        RTY_I ;
145
wire        ERR_I ;
146
 
147 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
148
 
149
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
150
 
151 15 mihad
wire        reset_wb ; // reset to Wb devices
152
 
153 62 mihad
`ifdef PCI_BIST
154 69 mihad
wire scanb_so ;
155
reg  scanb_si ;
156
reg  scanb_rst ;
157
reg  scanb_en ;
158
reg  scanb_clk ;
159 62 mihad
`endif
160
 
161 15 mihad
`ifdef GUEST
162
    wire    RST = ~reset ;
163
    assign  reset_wb = RST_O ;
164
`else
165
    pullup(RST) ;
166
    assign  reset_wb = reset ;
167
`endif
168
 
169
`define PCI_BRIDGE_INSTANCE bridge32_top
170
 
171
TOP `PCI_BRIDGE_INSTANCE
172
(
173
    .CLK    ( pci_clock),
174
    .AD     ( AD ),
175
    .CBE    ( CBE ),
176
    .RST    ( RST ),
177
    .INTA   ( INTA ),
178
    .REQ    ( MAS0_REQ ),
179
    .GNT    ( MAS0_GNT ),
180
    .FRAME  ( FRAME ),
181
    .IRDY   ( IRDY ),
182
    .IDSEL  ( TAR0_IDSEL),
183
    .DEVSEL ( DEVSEL ),
184
    .TRDY   ( TRDY ),
185
    .STOP   ( STOP ),
186
    .PAR    ( PAR ),
187
    .PERR   ( PERR ),
188
    .SERR   ( SERR ),
189
 
190
    .CLK_I  ( wb_clock ),
191
    .RST_I  ( reset ),
192
    .RST_O  ( RST_O ),
193
    .INT_I  ( INT_I ),
194
    .INT_O  ( INT_O ),
195
 
196
    // WISHBONE slave interface
197
    .ADR_I  ( ADR_I ),
198
    .SDAT_I ( SDAT_I ),
199
    .SDAT_O ( SDAT_O ),
200
    .SEL_I  ( SEL_I ),
201
    .CYC_I  ( CYC_I ),
202
    .STB_I  ( STB_I ),
203
    .WE_I   ( WE_I ),
204
    .CAB_I  ( CAB_I),
205
    .ACK_O  ( ACK_O ),
206
    .RTY_O  ( RTY_O ),
207
    .ERR_O  ( ERR_O ),
208
 
209
    // WISHBONE master interface
210
    .ADR_O  ( ADR_O ),
211
    .MDAT_I ( MDAT_I ),
212
    .MDAT_O ( MDAT_O ),
213
    .SEL_O  ( SEL_O ),
214
    .CYC_O  ( CYC_O ),
215
    .STB_O  ( STB_O ),
216
    .WE_O   ( WE_O ),
217
    .CAB_O  ( CAB_O ),
218
    .ACK_I  ( ACK_I ),
219
    .RTY_I  ( RTY_I ),
220
    .ERR_I  ( ERR_I )
221 62 mihad
 
222
`ifdef PCI_BIST
223
    ,
224 69 mihad
    // bist chain signals
225
    .scanb_rst  (scanb_rst),
226
    .scanb_clk  (scanb_clk),
227
    .scanb_si   (scanb_si),
228
    .scanb_so   (scanb_so),
229
    .scanb_en   (scanb_en)
230 62 mihad
`endif
231 15 mihad
) ;
232
 
233
WB_MASTER_BEHAVIORAL wishbone_master
234
(
235
    .CLK_I(wb_clock),
236
    .RST_I(reset_wb),
237
    .TAG_I(4'b0000),
238
    .TAG_O(),
239
    .ACK_I(ACK_O),
240
    .ADR_O(ADR_I),
241
    .CYC_O(CYC_I),
242
    .DAT_I(SDAT_O),
243
    .DAT_O(SDAT_I),
244
    .ERR_I(ERR_O),
245
    .RTY_I(RTY_O),
246
    .SEL_O(SEL_I),
247
    .STB_O(STB_I),
248
    .WE_O (WE_I),
249
    .CAB_O(CAB_I)
250
);
251
 
252
WB_SLAVE_BEHAVIORAL wishbone_slave
253
(
254
    .CLK_I              (wb_clock),
255
    .RST_I              (reset_wb),
256
    .ACK_O              (ACK_I),
257
    .ADR_I              (ADR_O),
258
    .CYC_I              (CYC_O),
259
    .DAT_O              (MDAT_I),
260
    .DAT_I              (MDAT_O),
261
    .ERR_O              (ERR_I),
262
    .RTY_O              (RTY_I),
263
    .SEL_I              (SEL_O),
264
    .STB_I              (STB_O),
265
    .WE_I               (WE_O),
266
    .CAB_I              (CAB_O)
267
);
268
 
269
integer wbu_mon_log_file_desc ;
270
integer pciu_mon_log_file_desc ;
271
WB_BUS_MON wbu_wb_mon(
272
                    .CLK_I(wb_clock),
273
                    .RST_I(reset_wb),
274
                    .ACK_I(ACK_O),
275
                    .ADDR_O(ADR_I),
276
                    .CYC_O(CYC_I),
277
                    .DAT_I(SDAT_O),
278
                    .DAT_O(SDAT_I),
279
                    .ERR_I(ERR_O),
280
                    .RTY_I(RTY_O),
281
                    .SEL_O(SEL_I),
282
                    .STB_O(STB_I),
283
                    .WE_O (WE_I),
284
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
285
                    .TAG_O(),
286
                    .CAB_O(CAB_I),
287
                    .log_file_desc ( wbu_mon_log_file_desc )
288
                  ) ;
289
 
290
WB_BUS_MON pciu_wb_mon(
291
                    .CLK_I(wb_clock),
292
                    .RST_I(reset_wb),
293
                    .ACK_I(ACK_I),
294
                    .ADDR_O(ADR_O),
295
                    .CYC_O(CYC_O),
296
                    .DAT_I(MDAT_I),
297
                    .DAT_O(MDAT_O),
298
                    .ERR_I(ERR_I),
299
                    .RTY_I(RTY_I),
300
                    .SEL_O(SEL_O),
301
                    .STB_O(STB_O),
302
                    .WE_O (WE_O),
303
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
304
                    .TAG_O(),
305
                    .CAB_O(CAB_O),
306
                    .log_file_desc( pciu_mon_log_file_desc )
307
                  ) ;
308
 
309
// some aditional signals are needed here because of the arbiter
310
reg [3:0] pci_ext_req_prev ;
311
always@(posedge pci_clock)
312
begin
313
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
314
end
315
reg pci_frame_prev ;
316
always@(posedge pci_clock)
317
begin
318
    pci_frame_prev <= FRAME ;
319
end
320
reg pci_irdy_prev ;
321
always@(posedge pci_clock)
322
begin
323
    pci_irdy_prev <= IRDY ;
324
end
325
 
326
pci_blue_arbiter pci_arbiter
327
(
328
  .pci_int_req_direct(1'b0),
329
  .pci_ext_req_prev(pci_ext_req_prev),
330
  .pci_int_gnt_direct_out(arb_grant_out[4]),
331
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
332
  .pci_frame_prev(~pci_frame_prev),
333
  .pci_irdy_prev(~pci_irdy_prev),
334
  .pci_irdy_now(~IRDY),
335
  .arbitration_enable(1'b1),
336
  .pci_clk(pci_clock),
337
  .pci_reset_comb(~RST)
338
);
339
 
340
reg [31:0] target_message ;
341
 
342
// define output enable signals for monitor inputs
343
// real output enable signals
344
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
345
`ifdef ACTIVE_LOW_OE
346
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
347
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
348
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
349
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
350
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
351
                        !devsel_t_s_oe,
352
                        !ad_oe,
353
                        !cbe_oe,
354
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
355
                        ;
356
`else
357
`ifdef ACTIVE_HIGH_OE
358
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
359
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
360
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
361
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
362
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
363
                        devsel_t_s_oe,
364
                        ad_oe,
365
                        cbe_oe,
366
                        `PCI_BRIDGE_INSTANCE.PERR_en}
367
                        ;
368
`endif
369
`endif
370
/*wire [5:0] oe_sigs_0 = {1'b0,
371
                        1'b0,
372
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
373
                        pci_target32.ad_enable,
374
                        1'b0,
375
                        pci_target32.err_enable | pci_target32.r_err_enable
376
                       } ;
377
*/
378
 
379
wire [5:0] oe_sigs_2 ;
380
wire [5:0] oe_sigs_1 ;
381
 
382
// signals which are used by test modules to know what to do
383
triand  test_accepted_l_int, error_event_int;
384
pullup  (test_accepted_l_int), (error_event_int);
385
 
386
wire    pci_reset_comb  = ~RST;
387
wire    pci_ext_clk     = pci_clock;
388
 
389
integer pci_mon_log_file_desc ;
390
pci_bus_monitor monitor32
391
(
392
    .pci_ext_ad                 (AD),
393
    .pci_ext_cbe_l              (CBE),
394
    .pci_ext_par                (PAR),
395
    .pci_ext_frame_l            (FRAME),
396
    .pci_ext_irdy_l             (IRDY),
397
    .pci_ext_devsel_l           (DEVSEL),
398
    .pci_ext_trdy_l             (TRDY),
399
    .pci_ext_stop_l             (STOP),
400
    .pci_ext_perr_l             (PERR),
401
    .pci_ext_serr_l             (SERR),
402
    .pci_real_req_l             (MAS0_REQ),
403
    .pci_real_gnt_l             (MAS0_GNT),
404
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
405
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
406
    .test_error_event           (error_event_int),
407
    .test_observe_r_oe_sigs     (r_oe_sigs),
408
    .test_observe_0_oe_sigs     (6'h00),
409
    .test_observe_1_oe_sigs     (oe_sigs_1),
410
    .test_observe_2_oe_sigs     (oe_sigs_2),
411
    .test_observe_3_oe_sigs     (6'h00),
412
    .pci_ext_reset_l            (RST),
413
    .pci_ext_clk                (pci_clock),
414
    .log_file_desc              (pci_mon_log_file_desc)
415
) ;
416
 
417
reg [2:0]  test_master_number ;
418
reg [31:0] test_address ;
419
reg [3:0]  test_command ;
420
reg [31:0] test_data ;
421
reg [3:0]  test_byte_enables_l ;
422
reg [9:0]  test_size ;
423
reg        test_make_addr_par_error ;
424
reg        test_make_data_par_error ;
425
reg [3:0]  test_master_initial_wait_states ;
426
reg [3:0]  test_master_subsequent_wait_states ;
427
reg [3:0]  test_target_initial_wait_states ;
428
reg [3:0]  test_target_subsequent_wait_states ;
429
reg [1:0]  test_target_devsel_speed ;
430
reg        test_fast_back_to_back ;
431
reg [2:0]  test_target_termination ;
432
reg        test_expect_master_abort ;
433
reg        test_start ;
434
reg [25:0] test_target_response ;
435
 
436
wire [31:0] master2_received_data ;
437
wire        master2_received_data_valid ;
438
reg         master2_check_received_data ;
439
pci_behaviorial_device pci_behaviorial_device2
440
(
441
    .pci_ext_ad(AD),
442
    .pci_ext_cbe_l(CBE),
443
    .pci_ext_par(PAR),
444
    .pci_ext_frame_l(FRAME),
445
    .pci_ext_irdy_l(IRDY),
446
    .pci_ext_devsel_l(DEVSEL),
447
    .pci_ext_trdy_l(TRDY),
448
    .pci_ext_stop_l(STOP),
449
    .pci_ext_perr_l(PERR),
450
    .pci_ext_serr_l(SERR),
451
    .pci_ext_idsel(TAR2_IDSEL),
452
    .pci_ext_inta_l(INTA),
453
    .pci_ext_req_l(MAS2_REQ),
454
    .pci_ext_gnt_l(MAS2_GNT),
455
    .pci_ext_reset_l(RST),
456
    .pci_ext_clk(pci_clock),
457
 
458
// Signals used by the test bench instead of using "." notation
459
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
460
    .test_master_number                 (test_master_number[2:0]),
461
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
462
    .test_command                       (test_command[3:0]),
463
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
464
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
465
    .test_size                          (test_size),
466
    .test_make_addr_par_error           (test_make_addr_par_error),
467
    .test_make_data_par_error           (test_make_data_par_error),
468
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
469
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
470
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
471
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
472
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
473
    .test_fast_back_to_back             (test_fast_back_to_back),
474
    .test_target_termination            (test_target_termination[2:0]),
475
    .test_expect_master_abort           (test_expect_master_abort),
476
    .test_start                         (test_start),
477
    .test_accepted_l                    (test_accepted_l_int),
478
    .test_error_event                   (error_event_int),
479
    .test_device_id                     (`Test_Master_2),
480
    .test_target_response               (test_target_response),
481
 
482
    .master_received_data               (master2_received_data),
483
    .master_received_data_valid         (master2_received_data_valid),
484
    .master_check_received_data         (master2_check_received_data)
485
);
486
 
487
wire [31:0] master1_received_data ;
488
wire        master1_received_data_valid ;
489
reg         master1_check_received_data ;
490
pci_behaviorial_device pci_behaviorial_device1
491
(
492
    .pci_ext_ad(AD),
493
    .pci_ext_cbe_l(CBE),
494
    .pci_ext_par(PAR),
495
    .pci_ext_frame_l(FRAME),
496
    .pci_ext_irdy_l(IRDY),
497
    .pci_ext_devsel_l(DEVSEL),
498
    .pci_ext_trdy_l(TRDY),
499
    .pci_ext_stop_l(STOP),
500
    .pci_ext_perr_l(PERR),
501
    .pci_ext_serr_l(SERR),
502
    .pci_ext_idsel(TAR1_IDSEL),
503
    .pci_ext_inta_l(INTA),
504
    .pci_ext_req_l(MAS1_REQ),
505
    .pci_ext_gnt_l(MAS1_GNT),
506
    .pci_ext_reset_l(RST),
507
    .pci_ext_clk(pci_clock),
508
 
509
// Signals used by the test bench instead of using "." notation
510
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
511
    .test_master_number                 (test_master_number[2:0]),
512
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
513
    .test_command                       (test_command[3:0]),
514
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
515
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
516
    .test_size                          (test_size),
517
    .test_make_addr_par_error           (test_make_addr_par_error),
518
    .test_make_data_par_error           (test_make_data_par_error),
519
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
520
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
521
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
522
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
523
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
524
    .test_fast_back_to_back             (test_fast_back_to_back),
525
    .test_target_termination            (test_target_termination[2:0]),
526
    .test_expect_master_abort           (test_expect_master_abort),
527
    .test_start                         (test_start),
528
    .test_accepted_l                    (test_accepted_l_int),
529
    .test_error_event                   (error_event_int),
530
    .test_device_id                     (`Test_Master_1),
531
    .test_target_response               (test_target_response),
532
 
533
    .master_received_data               (master1_received_data),
534
    .master_received_data_valid         (master1_received_data_valid),
535
    .master_check_received_data         (master1_check_received_data)
536
);
537
 
538
pci_unsupported_commands_master ipci_unsupported_commands_master
539
(
540
    .CLK    ( pci_clock),
541
    .AD     ( AD ),
542
    .CBE    ( CBE ),
543
    .RST    ( RST ),
544
    .REQ    ( MAS3_REQ ),
545
    .GNT    ( MAS3_GNT ),
546
    .FRAME  ( FRAME ),
547
    .IRDY   ( IRDY ),
548
    .DEVSEL ( DEVSEL ),
549
    .TRDY   ( TRDY ),
550
    .STOP   ( STOP ),
551
    .PAR    ( PAR )
552
) ;
553
 
554 45 mihad
`ifdef HOST
555
 
556
reg     [1:0]   conf_cyc_type1_target_response ;
557
reg     [31:0]  conf_cyc_type1_target_data ;
558
reg     [7:0]   conf_cyc_type1_target_bus_num ;
559
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
560
 
561
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
562
(
563
    .CLK              ( pci_clock),
564
    .AD               ( AD ),
565
    .CBE              ( CBE ),
566
    .RST              ( RST ),
567
    .FRAME            ( FRAME ),
568
    .IRDY             ( IRDY ),
569
    .DEVSEL           ( DEVSEL ),
570
    .TRDY             ( TRDY ),
571
    .STOP             ( STOP ),
572
    .PAR              ( PAR ),
573
 
574
    .response         ( conf_cyc_type1_target_response ),
575
    .data_out         ( conf_cyc_type1_target_data ),
576
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
577
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
578
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
579
    .bus_number       ( conf_cyc_type1_target_bus_num )
580
);
581
`endif
582
 
583 15 mihad
// pci clock generator
584 63 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
585
    always@(posedge wb_clock)
586
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b1 ;
587
 
588
    always@(negedge wb_clock)
589
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b0 ;
590 15 mihad
`else
591 63 mihad
    always
592
    `ifdef PCI33
593
        #15 pci_clock = ~pci_clock ;
594
    `else
595
    `ifdef PCI66
596
        #7.5 pci_clock = ~pci_clock ;
597
    `endif
598
    `endif
599 15 mihad
`endif
600
 
601
// WISHBONE clock generation
602 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
603
always@(posedge pci_clock)
604
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b1 ;
605 15 mihad
 
606 63 mihad
always@(negedge pci_clock)
607
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b0 ;
608
 
609
`else
610
    always
611
        #(((1/`WB_FREQ)/2)) wb_clock = !wb_clock ;
612
`endif
613
 
614 15 mihad
// Make test name visible when the Master starts working on it
615
reg     [79:0] present_test_name;
616
reg     [79:0] next_test_name;
617
wire    test_accepted = ~test_accepted_l_int;
618
always @(posedge test_accepted)
619
begin
620
    present_test_name <= next_test_name;
621
end
622
 
623
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
624
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
625
 
626
// basic configuration parameters for both behavioral devices
627
parameter [2:0] Master_ID_A                           = `Test_Master_1;
628
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
629
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
630
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
631
 
632
parameter [2:0] Master_ID_B                           = `Test_Master_2;
633
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
634
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
635
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
636
 
637
// basic configuration parameters for REAL device
638
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
639
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
640
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
641
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
642
 
643
// reg  [2:0]   ack_err_rty_termination ;
644
// reg          wait_cycles ;
645
// reg  [7:0]   num_of_retries ;
646
 
647
//reg [19:0] pci_config_base ;
648
reg [7:0] system_burst_size ;
649
reg [7:0] bridge_latency ;
650
integer   target_mem_image ;
651
integer   target_io_image ;
652
 
653
initial
654
begin
655 62 mihad
 
656
`ifdef PCI_BIST
657 69 mihad
    scanb_si    = 0 ;
658
    scanb_en    = 0 ;
659
    scanb_clk   = 0 ;
660
    scanb_rst   = 0 ;
661 62 mihad
`endif
662 15 mihad
    next_test_name[79:0] <= "Nowhere___";
663
    reset = 1'b1 ;
664
    pci_clock = 1'b0 ;
665
    wb_clock  = 1'b1 ;
666
    target_message = 32'h0000_0000 ;
667
//  num_of_retries = 8'h01 ;
668
//  ack_err_rty_termination = 3'b100 ;
669
//  wait_cycles = 1'b0 ;
670
 
671
    // system paameters
672
    system_burst_size = 16 ;
673
    bridge_latency    = 8 ;
674
 
675
    // set initial values for controling the behavioral PCI master
676
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
677
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
678
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
679
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
680
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
681
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
682
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
683
 
684
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
685
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
686
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
687
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
688
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
689
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
690
 
691
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
692
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
693
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
694
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
695
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
696
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
697
 
698
    test_master_number = `Test_Master_2 ;
699
    test_address = 32'h0000_0000 ;
700
    test_command = `BC_RESERVED0 ;
701
    test_data = 32'h0000_0000 ;
702
    test_byte_enables_l   = 4'hF ;
703
    test_size = 0 ;
704
    test_make_addr_par_error = 0 ;
705
    test_make_data_par_error = 0;
706
    test_master_initial_wait_states = 0 ;
707
    test_master_subsequent_wait_states = 0 ;
708
    test_target_initial_wait_states = 0 ;
709
    test_target_subsequent_wait_states = 0;
710
    test_target_devsel_speed = `Test_Devsel_Fast ;
711
    test_fast_back_to_back = 0 ;
712
    test_target_termination = `Test_Target_Normal_Completion ;
713
    test_expect_master_abort = 0 ;
714
    test_start = 0 ;
715
    test_target_response = 0 ;
716
 
717
    master1_check_received_data = 0 ;
718
    master2_check_received_data = 0 ;
719
 
720 45 mihad
    `ifdef HOST
721
        conf_cyc_type1_target_response = 0 ;
722
        conf_cyc_type1_target_data = 0 ;
723
        conf_cyc_type1_target_bus_num = 255 ;
724
    `endif
725 15 mihad
 
726
    // fill memory and IO data with random values
727
    fill_memory ;
728
 
729
    INT_I = 0 ;
730
 
731
    // extract from constants which target image can be used as IO and which as memory
732
    `ifdef HOST
733
        target_mem_image = 1 ;
734
        target_io_image  = 1 ;
735
    `else
736
        target_mem_image = -1 ;
737
        target_io_image     = -1 ;
738
        if ( `PCI_BA1_MEM_IO === 0 )
739
            target_mem_image = 1 ;
740
        else
741
            target_io_image = 1 ;
742
 
743
        if ( target_mem_image === -1 )
744
        begin
745
            `ifdef PCI_IMAGE2
746
                if ( `PCI_BA2_MEM_IO === 0 )
747
                    target_mem_image = 2 ;
748
                else if ( target_io_image === -1 )
749
                    target_io_image = 2 ;
750
            `endif
751
        end
752
 
753
        if ( target_mem_image === -1 )
754
        begin
755
            `ifdef PCI_IMAGE3
756
                if ( `PCI_BA3_MEM_IO === 0 )
757
                    target_mem_image = 3 ;
758
                else if ( target_io_image === -1 )
759
                    target_io_image = 3 ;
760
            `endif
761
        end
762
 
763
        if ( target_mem_image === -1 )
764
        begin
765
            `ifdef PCI_IMAGE4
766
                if ( `PCI_BA4_MEM_IO === 0 )
767
                    target_mem_image = 4 ;
768
                else if ( target_io_image === -1 )
769
                    target_io_image = 4 ;
770
            `endif
771
        end
772
 
773
        if ( target_mem_image === -1 )
774
        begin
775
            `ifdef PCI_IMAGE5
776
                if ( `PCI_BA5_MEM_IO === 0 )
777
                    target_mem_image = 5 ;
778
                else if ( target_io_image === -1 )
779
                    target_io_image = 5 ;
780
            `endif
781
        end
782
    `endif
783
 
784
    tests_successfull = 0 ;
785
    tests_failed = 0 ;
786
 
787
    tb_log_file = $fopen("../log/pci_tb.log") ;
788
 
789
    if ( tb_log_file < 2 )
790
    begin
791
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
792
        $finish ;
793
    end
794
 
795
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
796
    $fdisplay( tb_log_file,"" ) ;
797
 
798
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
799
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
800
 
801
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
802
    begin
803
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
804
        $finish ;
805
    end
806
 
807
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
808
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
809
 
810
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
811
    if ( pci_mon_log_file_desc < 2 )
812
    begin
813
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
814
        $finish ;
815
    end
816
 
817
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
818
 
819
    run_tests ;
820
end
821
 
822
task fill_memory ;
823
    integer temp_index ;
824
begin
825
    // fill write memories with random data
826
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
827
    begin
828
        wmem_data[temp_index[9:0]] = $random ;
829 26 mihad
        # 1;
830 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
831 26 mihad
        # 1;
832 15 mihad
    end
833
    // fill WB slave behavioral MEMORY
834
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
835
    begin
836
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
837
        # 1;
838
    end
839
end
840
endtask // fill_memory
841
 
842
reg [2:0] tb_init_waits ;
843
reg [2:0] tb_subseq_waits ;
844
reg [2:0] tb_target_decode_speed ;
845
 
846
task run_tests ;
847
begin
848
    // first - reset logic
849
    do_reset ;
850 62 mihad
 
851
    // if BIST is implemented, give it a go
852
`ifdef PCI_BIST
853 73 mihad
//    run_bist_test ;
854
scanb_rst <= #1 1'b1 ;
855 62 mihad
`endif
856 45 mihad
    test_initial_conf_values ;
857
 
858 15 mihad
    next_test_name[79:0] <= "Initing...";
859
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
860
 
861
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
862
    begin
863
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
864
        begin
865
 
866
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
867
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
868
 
869
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
870
            begin
871
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
872
 
873
                `ifdef HOST
874
                    configure_bridge_target ;
875
                    find_pci_devices ;
876 45 mihad
                    test_configuration_cycle_target_abort ;
877
                    test_configuration_cycle_type1_generation ;
878 15 mihad
                `endif
879
 
880
                @(posedge pci_clock) ;
881
                configure_target(1) ;
882
                @(posedge pci_clock) ;
883
                configure_target(2) ;
884
 
885
                `ifdef GUEST
886
                    configure_bridge_target ;
887
                `endif
888
 
889
               next_test_name[79:0] <= "WB_SLAVE..";
890
 
891
                $display("Testing WISHBONE slave images' features!") ;
892
                test_wb_image(1) ;
893
 
894
                `ifdef WB_IMAGE2
895
                    test_wb_image(2) ;
896
                `else
897
                    $display(" WB IMAGE 2 not implemented! ") ;
898
                `endif
899
 
900
                `ifdef WB_IMAGE3
901
                    test_wb_image(3) ;
902
                `else
903
                    $display(" WB IMAGE 3 not implemented! ") ;
904
                `endif
905
 
906
                `ifdef WB_IMAGE4
907
                    test_wb_image(4) ;
908
                `else
909
                    $display(" WB IMAGE 4 not implemented! ") ;
910
                `endif
911
 
912
                `ifdef WB_IMAGE5
913
                    test_wb_image(5) ;
914
                `else
915
                    $display(" WB IMAGE 5 not implemented! ") ;
916
                `endif
917
 
918
                wb_slave_errors ;
919
                wb_to_pci_error_handling ;
920
 
921
                parity_checking ;
922
 
923
                wb_to_pci_transactions ;
924
 
925
                `ifdef HOST
926
                iack_cycle ;
927
                `endif
928
 
929 73 mihad
                test_master_overload ;
930
 
931 15 mihad
            end
932 57 mihad
 
933 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
934
        `else
935 57 mihad
            master_completion_expiration ;
936 63 mihad
        `endif
937 57 mihad
 
938 69 mihad
        `ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
939
            master_special_corner_case_test ;
940
        `endif
941
 
942 15 mihad
            $display(" ") ;
943
            $display("WB slave images' tests finished!") ;
944
 
945
            $display("########################################################################") ;
946
            $display("########################################################################") ;
947
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
948
            $display("########################################################################") ;
949
            $display("########################################################################") ;
950
 
951
            $display("Testing PCI target images' features!") ;
952
            configure_bridge_target_base_addresses ;
953 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
954
                test_conf_cycle_type1_reference ;
955
            `endif
956
 
957 15 mihad
            `ifdef HOST
958
             `ifdef NO_CNF_IMAGE
959
              `ifdef PCI_IMAGE0
960
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
961
            test_pci_image(0) ;
962
              `else
963
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
964
              `endif
965
             `else
966
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
967
             `endif
968
            `endif
969
 
970
            $display("PCI image 1 is ALWAYS implemented!") ;
971
            test_pci_image(1) ;
972
 
973
            `ifdef PCI_IMAGE2
974
            $display("PCI image 2 is implemented!") ;
975
            test_pci_image(2) ;
976
            `else
977
            $display("PCI image 2 is NOT implemented!") ;
978
            `endif
979
 
980
            `ifdef PCI_IMAGE3
981
            $display("PCI image 3 is implemented!") ;
982
            test_pci_image(3) ;
983
            `else
984
            $display("PCI image 3 is NOT implemented!") ;
985
            `endif
986
 
987
            `ifdef PCI_IMAGE4
988
            $display("PCI image 4 is implemented!") ;
989
            test_pci_image(4) ;
990
            `else
991
            $display("PCI image 4 is NOT implemented!") ;
992
            `endif
993
 
994
            `ifdef PCI_IMAGE5
995
            $display("PCI image 5 is implemented!") ;
996
            test_pci_image(5) ;
997
            `else
998
            $display("PCI image 5 is NOT implemented!") ;
999
            `endif
1000
 
1001
            test_wb_error_rd ;
1002
 
1003
            target_fast_back_to_back ;
1004
            target_disconnects ;
1005
 
1006 73 mihad
            test_target_overload ;
1007
 
1008 15 mihad
            if ( target_io_image !== -1 )
1009
                test_target_abort( target_io_image ) ;
1010
            $display(" ") ;
1011
            $display("PCI target images' tests finished!") ;
1012
 
1013
            transaction_ordering ;
1014 33 mihad
 
1015 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
1016
        `else
1017 33 mihad
            target_completion_expiration ;
1018 63 mihad
        `endif
1019
 
1020 15 mihad
            $display(" ") ;
1021
            $display("PCI transaction ordering tests finished!") ;
1022
        end
1023
    end
1024
 
1025 73 mihad
    tb_init_waits   = 0 ;
1026
    tb_subseq_waits = 0 ;
1027
 
1028 63 mihad
    `ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
1029
        test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
1030
        test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
1031
        test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
1032
        test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = 0 ;
1033
 
1034
        `ifdef HOST
1035
            configure_bridge_target ;
1036
        `endif
1037
 
1038
        @(posedge pci_clock) ;
1039
        configure_target(1) ;
1040
        @(posedge pci_clock) ;
1041
        configure_target(2) ;
1042
 
1043
        `ifdef GUEST
1044
            configure_bridge_target ;
1045
        `endif
1046
 
1047
        target_special_corner_case_test ;
1048
    `endif
1049
 
1050 73 mihad
    tb_init_waits   = 0 ;
1051
    tb_subseq_waits = 0 ;
1052
 
1053 15 mihad
    test_summary ;
1054
 
1055
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
1056
    $stop ;
1057
end
1058
endtask // run_tests
1059
 
1060
task do_reset;
1061
begin
1062
    next_test_name[79:0] <= "Reset.....";
1063
 
1064
    reset = 1'b1 ;
1065
    #100 ;
1066
    `ifdef HOST
1067
        @(posedge wb_clock) ;
1068
    `else
1069
    `ifdef GUEST
1070
        @(posedge pci_clock) ;
1071
    `endif
1072
    `endif
1073
 
1074
    reset <= 1'b0 ;
1075
 
1076 45 mihad
    `ifdef HOST
1077
        @(posedge wb_clock) ;
1078
    `else
1079
    `ifdef GUEST
1080
        @(posedge pci_clock) ;
1081
    `endif
1082
    `endif
1083
 
1084 15 mihad
end
1085
endtask
1086
 
1087
/*############################################################################
1088
WB SLAVE UNIT tasks
1089
===================
1090
############################################################################*/
1091
 
1092
task configure_target ;
1093 45 mihad
    input [1:0]  beh_dev_num ;
1094 15 mihad
    reg   [31:0] base_address1 ;
1095
    reg   [31:0] base_address2 ;
1096
    reg   [2:0]  Master_ID;
1097
    reg   [31:0] Target_Config_Addr;
1098 45 mihad
    reg   [4:0]  device_num ;
1099 15 mihad
begin
1100 45 mihad
    if (beh_dev_num === 1)
1101 15 mihad
    begin
1102
        base_address1       = `BEH_TAR1_MEM_START ;
1103
        base_address2       = `BEH_TAR1_IO_START  ;
1104
        Master_ID           = `Test_Master_2 ;
1105
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1106 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1107 15 mihad
    end
1108
    else
1109 45 mihad
    if (beh_dev_num === 2)
1110 15 mihad
    begin
1111
        base_address1       = `BEH_TAR2_MEM_START ;
1112
        base_address2       = `BEH_TAR2_IO_START  ;
1113
        Master_ID           = `Test_Master_1 ;
1114
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1115 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1116 15 mihad
    end
1117
 
1118
    // write target's base addresses
1119
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1120
    // type 0 cycle, byte enables, base address
1121
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1122
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1123
 
1124
    // enable target's response and master
1125
    // enable parity errors, disable system error
1126
 
1127
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1128
 
1129
end
1130
endtask //configure_target
1131
 
1132
task test_wb_image ;
1133
    input [2:0]  image_num ;
1134
    reg   [11:0] ctrl_offset ;
1135
    reg   [11:0] ba_offset ;
1136
    reg   [11:0] am_offset ;
1137
    reg   [11:0] ta_offset ;
1138
    reg   [11:0] err_cs_offset ;
1139
    reg `WRITE_STIM_TYPE write_data ;
1140
    reg `READ_STIM_TYPE  read_data ;
1141
    reg `READ_RETURN_TYPE read_status ;
1142
 
1143
    reg `WRITE_RETURN_TYPE write_status ;
1144
    reg `WB_TRANSFER_FLAGS write_flags ;
1145
    reg [31:0] temp_val ;
1146
    reg        ok   ;
1147
    reg [11:0] pci_ctrl_offset ;
1148
    reg [31:0] image_base ;
1149
    reg [31:0] target_address ;
1150
    reg [31:0] translation_address ;
1151
    integer    i ;
1152
    integer    j ;
1153
begin:main
1154
    pci_ctrl_offset = 12'h4 ;
1155
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1156
    // image 0 can only be configuration image - start with 1
1157
    if (image_num === 1)
1158
    begin
1159
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1160
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1161
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1162
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1163
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1164
    end
1165
    else if (image_num === 2)
1166
    begin
1167
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1168
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1169
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1170
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1171
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1172
    end
1173
    else if (image_num === 3)
1174
    begin
1175
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1176
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1177
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1178
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1179
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1180
    end
1181
    else if (image_num === 4)
1182
    begin
1183
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1184
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1185
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1186
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1187
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1188
    end
1189
    else if (image_num === 5)
1190
    begin
1191
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1192
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1193
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1194
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1195
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1196
    end
1197
    else
1198
    begin
1199
        test_name   = "WB IMAGES' FEATURES TEST" ;
1200
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1201
        disable main ;
1202
    end
1203
 
1204
    target_address  = `BEH_TAR1_MEM_START ;
1205
    image_base      = 0 ;
1206
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1207
 
1208
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1209
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1210
    write_flags                      = 0 ;
1211
    write_flags`INIT_WAITS           = tb_init_waits ;
1212
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1213
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1214
 
1215
    test_name = "WB IMAGE CONFIGURATION" ;
1216
    // enable master & target operation
1217
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1218
    if ( ok !== 1 )
1219
    begin
1220 69 mihad
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1221 15 mihad
        test_fail("write to PCI Device Control register didn't succeede");
1222
        disable main ;
1223
    end
1224
 
1225
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1226
    if ( ok !== 1 )
1227
    begin
1228 69 mihad
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", $time) ;
1229 15 mihad
        test_fail("write to WB Error Control and Status register didn't succeede");
1230
        disable main ;
1231
    end
1232
 
1233
    // prepare image control register
1234
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1235
    if ( ok !== 1 )
1236
    begin
1237
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1238
        test_fail("write to WB Image Control register didn't succeede");
1239
        disable main ;
1240
    end
1241
 
1242
    // prepare base address register
1243
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1244
    if ( ok !== 1 )
1245
    begin
1246
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1247
        test_fail("write to WB Base Address register didn't succeede");
1248
        disable main ;
1249
    end
1250
 
1251
    // write address mask register
1252
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1253
    if ( ok !== 1 )
1254
    begin
1255
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1256
        test_fail("write to WB Address Mask register didn't succeede");
1257
        disable main ;
1258
    end
1259
 
1260
    fork
1261
    begin
1262
        write_data`WRITE_ADDRESS = target_address ;
1263
        write_data`WRITE_DATA    = wmem_data[0] ;
1264
        write_data`WRITE_SEL     = 4'hF ;
1265
 
1266
        // handle retries from now on
1267
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1268
 
1269
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1270
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1271
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1272
        begin
1273
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1274
            test_fail("WB Slave state machine failed to post single memory write");
1275
            disable main ;
1276
        end
1277
 
1278
        // read written data back
1279
        read_data`READ_ADDRESS  = target_address ;
1280
        read_data`READ_SEL      = 4'hF ;
1281
        read_data`READ_TAG_STIM = 0 ;
1282
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1283
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1284
        begin
1285
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1286
            test_fail("PCI bridge didn't process the read as expected");
1287
            disable main ;
1288
        end
1289
 
1290
        if (read_status`READ_DATA !== wmem_data[0])
1291
        begin
1292
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1293
            test_fail("PCI bridge returned unexpected Read Data");
1294
        end
1295
        else
1296
            test_ok ;
1297
    end
1298
    begin
1299
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1300
        if ( ok !== 1 )
1301
        begin
1302
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1303
        end
1304
        else
1305
            test_ok ;
1306
 
1307
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1308
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1309
        if ( ok !== 1 )
1310
        begin
1311
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1312
        end
1313
    end
1314
    join
1315
 
1316
    // if address translation is implemented - try it out
1317
    translation_address = image_base ;
1318
    `ifdef ADDR_TRAN_IMPL
1319
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1320
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1321
    if ( ok !== 1 )
1322
    begin
1323
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1324
        test_fail("write to WB Image Translation Address Register failed") ;
1325
        disable main ;
1326
    end
1327
 
1328
    target_address  = `BEH_TAR2_MEM_START ;
1329
    image_base      = 0 ;
1330
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1331
 
1332
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1333
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1334
 
1335
    write_flags                      = 0 ;
1336
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1337
 
1338
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1339
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1340
    if ( ok !== 1 )
1341
    begin
1342
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1343
        test_fail("write to WB Image Base Address Register failed") ;
1344
        disable main ;
1345
    end
1346
 
1347
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1348
    // enable address translation
1349
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1350
    if ( ok !== 1 )
1351
    begin
1352
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1353
        test_fail("write to WB Image Control Register failed") ;
1354
        disable main ;
1355
    end
1356
 
1357
    `endif
1358
 
1359
    fork
1360
    begin
1361
        write_data`WRITE_ADDRESS = target_address + 4 ;
1362
        write_data`WRITE_DATA    = wmem_data[1] ;
1363
        write_data`WRITE_SEL     = 4'hF ;
1364
 
1365
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1366
 
1367
        `ifdef ADDR_TRAN_IMPL
1368
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1369
        `else
1370
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1371
        `endif
1372
 
1373
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1374
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1375
        begin
1376
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1377
            test_fail("WB Slave state machine failed to post single memory write") ;
1378
            disable main ;
1379
        end
1380
 
1381
        // read written data back
1382
        read_data`READ_ADDRESS  = target_address + 4 ;
1383
        read_data`READ_SEL      = 4'hF ;
1384
        read_data`READ_TAG_STIM = 0 ;
1385
 
1386
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1387
 
1388
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1389
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1390
        begin
1391
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1392
            test_fail("PCI bridge failed to process single delayed memory read") ;
1393
            disable main ;
1394
        end
1395
 
1396
        if (read_status`READ_DATA !== wmem_data[1])
1397
        begin
1398
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1399
            test_fail("PCI bridge returned unexpected Read Data");
1400
        end
1401
        else
1402
            test_ok ;
1403
    end
1404
    begin
1405
        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 ) ;
1406
        if ( ok !== 1 )
1407
        begin
1408
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1409
        end
1410
        else
1411
            test_ok ;
1412
 
1413
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1414
        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 ) ;
1415
        if ( ok !== 1 )
1416
        begin
1417
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1418
        end
1419
    end
1420
    join
1421
 
1422
    // 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
1423
    // prepare write data
1424
    for ( i = 0 ; i < 6 ; i = i + 1 )
1425
    begin
1426
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1427
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1428
        write_data`WRITE_SEL     = 4'hF ;
1429
        wishbone_master.blk_write_data[i] = write_data ;
1430
    end
1431
 
1432
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1433
    write_flags`WB_TRANSFER_CAB    = 1 ;
1434
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1435
 
1436
    fork
1437
    begin
1438
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1439
        wishbone_master.wb_block_write(write_flags, write_status) ;
1440
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1441
        begin
1442
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1443
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1444
            disable main ;
1445
        end
1446
    end
1447
    begin
1448
        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 ) ;
1449
        if ( ok !== 1 )
1450
        begin
1451
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1452
        end
1453
        else
1454
            test_ok ;
1455
    end
1456
    join
1457
 
1458
    // set burst size and latency timer
1459
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1460
 
1461
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1462
    write_flags`WB_TRANSFER_CAB    = 1 ;
1463
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1464
 
1465
    // prepare read data
1466
    for ( i = 0 ; i < 4 ; i = i + 1 )
1467
    begin
1468
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1469
        read_data`READ_SEL     = 4'hF ;
1470
        wishbone_master.blk_read_data_in[i] = read_data ;
1471
    end
1472
 
1473
    fork
1474
    begin
1475
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1476
        wishbone_master.wb_block_read(write_flags, read_status) ;
1477
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1478
        begin
1479
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1480
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1481
            disable main ;
1482
        end
1483
 
1484
        // check data read from target
1485
        for ( i = 0 ; i < 4 ; i = i + 1 )
1486
        begin
1487
            read_status = wishbone_master.blk_read_data_out[i] ;
1488
            if (read_status`READ_DATA !== wmem_data[2 + i])
1489
            begin
1490
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1491
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1492
            end
1493
        end
1494
    end
1495
    begin
1496
        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 ) ;
1497
        if ( ok !== 1 )
1498
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1499
        else
1500
            test_ok ;
1501
 
1502
        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 ) ;
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 + 16, 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 + 20, 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
    end
1521
    join
1522
 
1523
    // now repeat this same burst read with various image features enabled or disabled
1524
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1525
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1526
    if (ok !== 1)
1527
    begin
1528
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1529
        test_fail("write to WB Image control register failed") ;
1530
        disable main ;
1531
    end
1532
 
1533
    fork
1534
    begin
1535
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1536
        wishbone_master.wb_block_read(write_flags, read_status) ;
1537
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1538
        begin
1539
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1540
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1541
            disable main ;
1542
        end
1543
 
1544
        // check data read from target
1545
        for ( i = 0 ; i < 4 ; i = i + 1 )
1546
        begin
1547
            read_status = wishbone_master.blk_read_data_out[i] ;
1548
            if (read_status`READ_DATA !== wmem_data[2 + i])
1549
            begin
1550
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1551
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1552
            end
1553
            else
1554
                test_ok ;
1555
        end
1556
    end
1557
    begin
1558
        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 ) ;
1559
        if ( ok !== 1 )
1560
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1561
    end
1562
    join
1563
 
1564
    read_data`READ_ADDRESS  = target_address ;
1565
    read_data`READ_SEL      = 4'hF ;
1566
    read_data`READ_TAG_STIM = 0 ;
1567
 
1568
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1569
    fork
1570
    begin
1571
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1572
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1573
        begin
1574
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1575
            test_fail("delayed single memory read wasn't processed as expected") ;
1576
            disable main ;
1577
        end
1578
 
1579
        if (read_status`READ_DATA !== wmem_data[0])
1580
        begin
1581
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1582
            test_fail("delayed single memory read data value returned was not as expected") ;
1583
        end
1584
        else
1585
            test_ok ;
1586
    end
1587
    begin
1588
        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 ) ;
1589
        if ( ok !== 1 )
1590
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1591
    end
1592
    join
1593
 
1594
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1595
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1596
    if (ok !== 1)
1597
    begin
1598
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1599
        test_fail("write to WB Image control register failed") ;
1600
        disable main ;
1601
    end
1602
 
1603
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1604
    fork
1605
    begin
1606
        wishbone_master.wb_block_read(write_flags, read_status) ;
1607
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1608
        begin
1609
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1610
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1611
            disable main ;
1612
        end
1613
 
1614
        // check data read from target
1615
        for ( i = 0 ; i < 4 ; i = i + 1 )
1616
        begin
1617
            read_status = wishbone_master.blk_read_data_out[i] ;
1618
            if (read_status`READ_DATA !== wmem_data[2 + i])
1619
            begin
1620
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1621
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1622
            end
1623
            else
1624
                test_ok ;
1625
        end
1626
    end
1627
    begin
1628
        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 ) ;
1629
        if ( ok !== 1 )
1630
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1631
    end
1632
    join
1633
 
1634
    read_data`READ_ADDRESS  = target_address + 4 ;
1635
    read_data`READ_SEL      = 4'hF ;
1636
    read_data`READ_TAG_STIM = 0 ;
1637
 
1638
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1639
    fork
1640
    begin
1641
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1642
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1643
        begin
1644
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1645
            test_fail("delayed single memory read wasn't processed as expected") ;
1646
            disable main ;
1647
        end
1648
 
1649
        if (read_status`READ_DATA !== wmem_data[1])
1650
        begin
1651
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1652
            test_fail("delayed single memory read data value returned was not as expected") ;
1653
        end
1654
        else
1655
            test_ok ;
1656
    end
1657
    begin
1658
        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 ) ;
1659
        if ( ok !== 1 )
1660
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1661
    end
1662
    join
1663
 
1664
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1665
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1666
    if (ok !== 1)
1667
    begin
1668
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1669
        test_fail("write to WB Image control register failed") ;
1670
        disable main ;
1671
    end
1672
 
1673
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1674
    fork
1675
    begin
1676
        wishbone_master.wb_block_read(write_flags, read_status) ;
1677
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1678
        begin
1679
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1680
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1681
            disable main ;
1682
        end
1683
 
1684
        // check data read from target
1685
        for ( i = 0 ; i < 4 ; i = i + 1 )
1686
        begin
1687
            read_status = wishbone_master.blk_read_data_out[i] ;
1688
            if (read_status`READ_DATA !== wmem_data[2 + i])
1689
            begin
1690
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1691
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1692
            end
1693
            else
1694
                test_ok ;
1695
        end
1696
    end
1697
    begin
1698
        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 ) ;
1699
        if ( ok !== 1 )
1700
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1701
    end
1702
    join
1703
 
1704
    read_data`READ_ADDRESS  = target_address + 8 ;
1705
    read_data`READ_SEL      = 4'hF ;
1706
    read_data`READ_TAG_STIM = 0 ;
1707
 
1708
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1709
    fork
1710
    begin
1711
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1712
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1713
        begin
1714
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1715
            test_fail("delayed single memory read wasn't processed as expected") ;
1716
            disable main ;
1717
        end
1718
 
1719
        if (read_status`READ_DATA !== wmem_data[2])
1720
        begin
1721
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1722
            test_fail("delayed single memory read data value returned was not as expected") ;
1723
        end
1724
        else
1725
            test_ok ;
1726
    end
1727
    begin
1728
        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 ) ;
1729
        if ( ok !== 1 )
1730
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1731
    end
1732
    join
1733
 
1734
    // map image to IO space
1735
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1736
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1737
    if ( ok !== 1 )
1738
    begin
1739
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1740
        test_fail("write to WB Image Base Address register failed") ;
1741
        disable main ;
1742
    end
1743
 
1744
    write_data`WRITE_ADDRESS = target_address ;
1745
    write_data`WRITE_DATA    = wmem_data[11] ;
1746
    write_data`WRITE_SEL     = 4'hF ;
1747
 
1748
    // handle retries from now on
1749
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1750
 
1751
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1752
    fork
1753
    begin
1754
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1755
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1756
        begin
1757
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1758
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1759
            disable main ;
1760
        end
1761
    end
1762
    begin
1763
        // currently IO commands not supported in behavioral models - master abort
1764
        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 ) ;
1765
        if ( ok !== 1 )
1766
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1767
        else
1768
            test_ok ;
1769
    end
1770
    join
1771
 
1772
    read_data`READ_ADDRESS  = target_address ;
1773
    read_data`READ_SEL      = 4'hF ;
1774
    read_data`READ_TAG_STIM = 0 ;
1775
 
1776
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1777
 
1778
    // currently io commands are not supported by behavioral target - transfer should not be completed
1779
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1780
    fork
1781
    begin
1782
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1783
        if (read_status`CYC_ERR !== 1)
1784
        begin
1785
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1786
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1787
            disable main ;
1788
        end
1789
        else
1790
            test_ok ;
1791
    end
1792
    begin
1793
        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 ) ;
1794
        if ( ok !== 1 )
1795
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1796
    end
1797
    join
1798
 
1799
    // test byte addressing
1800
    read_data`READ_ADDRESS = target_address + 2 ;
1801
    read_data`READ_SEL     = 4'b1100 ;
1802
 
1803
    fork
1804
    begin
1805
        // currently io commands are not supported by behavioral target - transfer should not be completed
1806
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1807
        if (read_status`CYC_ERR !== 1)
1808
        begin
1809
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1810
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1811
            disable main ;
1812
        end
1813
        else test_ok ;
1814
    end
1815
    begin
1816
        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 ) ;
1817
        if ( ok !== 1 )
1818
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1819
    end
1820
    join
1821
 
1822
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1823
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1824
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1825
    if ( ok !== 1 )
1826
    begin
1827
        test_fail("WB Base address register could not be written") ;
1828
        disable main ;
1829
    end
1830
 
1831
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1832
    if ( ok !== 1 )
1833
    begin
1834
        test_fail("WB Address Mask register could not be written") ;
1835
        disable main ;
1836
    end
1837
 
1838
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1839
    if ( ok !== 1 )
1840
    begin
1841
        test_fail("WB Image Control register could not be written") ;
1842
        disable main ;
1843
    end
1844
 
1845
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1846
    write_data`WRITE_DATA    = wmem_data[11] ;
1847
    write_data`WRITE_SEL     = 4'b1000 ;
1848
 
1849
    // handle retries from now on
1850
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1851
 
1852
    fork
1853
    begin
1854
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1855
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1856
        begin
1857
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1858
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1859
            disable main ;
1860
        end
1861
    end
1862
    begin
1863
        // currently IO commands not supported in behavioral models - master abort
1864
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1865
        if ( ok !== 1 )
1866
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1867
        else
1868
            test_ok ;
1869
    end
1870
    join
1871
 
1872
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1873
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1874
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1875
 
1876
    fork
1877
    begin
1878
        // currently io commands are not supported by behavioral target - transfer should not be completed
1879
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1880
        if (read_status`CYC_ERR !== 1)
1881
        begin
1882
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1883
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1884
            disable main ;
1885
        end
1886
        else test_ok ;
1887
    end
1888
    begin
1889
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1890
        if ( ok !== 1 )
1891
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1892
    end
1893
    join
1894
 
1895
    test_name = "DISABLING WB IMAGE" ;
1896
 
1897
    // disable current image
1898
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1899
    if ( ok !== 1 )
1900
    begin
1901
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1902
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1903
        disable main ;
1904
    end
1905
 
1906
    // clear master abort status bit
1907
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1908
    if ( ok !== 1 )
1909
    begin
1910
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1911
        test_fail("write to PCI Device Status register not accepted as expected") ;
1912
        disable main ;
1913
    end
1914
 
1915
end //main
1916
endtask //test_wb_image
1917
 
1918
task wb_slave_errors ;
1919
    reg   [11:0] ctrl_offset ;
1920
    reg   [11:0] ba_offset ;
1921
    reg   [11:0] am_offset ;
1922
    reg   [11:0] ta_offset ;
1923
    reg `WRITE_STIM_TYPE write_data ;
1924
    reg `READ_STIM_TYPE  read_data ;
1925
    reg `READ_RETURN_TYPE read_status ;
1926
 
1927
    reg `WRITE_RETURN_TYPE write_status ;
1928
    reg `WB_TRANSFER_FLAGS write_flags ;
1929
    reg [31:0] temp_val1 ;
1930
    reg [31:0] temp_val2 ;
1931
    reg        ok   ;
1932
    reg [11:0] pci_ctrl_offset ;
1933
    reg [31:0] image_base ;
1934
    reg [31:0] target_address ;
1935
    integer    i ;
1936
    reg skip ;
1937
fork
1938
begin:main
1939
 
1940
    `ifdef GUEST
1941
        skip = 1 ;
1942
    `else
1943
        skip = 0 ;
1944
    `endif
1945
 
1946
    pci_ctrl_offset = 12'h4 ;
1947
 
1948
    // image 1 is used for error testing, since it is always implemented
1949
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1950
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1951
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1952
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1953
 
1954
    target_address  = `BEH_TAR1_MEM_START ;
1955
    image_base      = 0 ;
1956
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1957
 
1958
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1959
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1960
    write_flags                    = 0 ;
1961
    write_flags`INIT_WAITS         = tb_init_waits ;
1962
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1963
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1964
 
1965
    // enable master & target operation
1966
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1967
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1968
    if ( ok !== 1 )
1969
    begin
1970
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1971
        test_fail("PCI Device Control register couldn't be written") ;
1972
        disable no_transaction ;
1973
        disable main ;
1974
    end
1975
 
1976
    // prepare image control register
1977
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1978
    if ( ok !== 1 )
1979
    begin
1980
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1981
        test_fail("WB Image Control register couldn't be written") ;
1982
        disable no_transaction ;
1983
        disable main ;
1984
    end
1985
 
1986
    // prepare base address register
1987
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1988
    if ( ok !== 1 )
1989
    begin
1990
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1991
        test_fail("WB Base Address register couldn't be written") ;
1992
        disable no_transaction ;
1993
        disable main ;
1994
    end
1995
 
1996
    // write address mask register
1997
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1998
    if ( ok !== 1 )
1999
    begin
2000
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2001
        test_fail("WB Address Mask register couldn't be written") ;
2002
        disable no_transaction ;
2003
        disable main ;
2004
    end
2005
 
2006
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2007
 
2008
    skip = 0 ;
2009
 
2010
    // memory mapped image - access is erroneous when address is not alligned
2011
    write_data`WRITE_ADDRESS = target_address + 1 ;
2012
    write_data`WRITE_DATA    = wmem_data[0] ;
2013
    write_data`WRITE_SEL     = 4'hF ;
2014
 
2015
    // handle retries from now on
2016
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2017
 
2018
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
2019
 
2020
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2021
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2022
    begin
2023
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2024
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2025
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2026
        disable no_transaction ;
2027
        disable main ;
2028
    end
2029
 
2030
    write_data`WRITE_ADDRESS = target_address + 2 ;
2031
 
2032
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2033
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2034
    begin
2035
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2036
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2037
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2038
        disable no_transaction ;
2039
        disable main ;
2040
 
2041
    end
2042
 
2043
    write_data`WRITE_ADDRESS = target_address + 3 ;
2044
 
2045
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2046
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2047
    begin
2048
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2049
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2050
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2051
        disable no_transaction ;
2052
        disable main ;
2053
    end
2054
 
2055
    test_ok ;
2056
 
2057
    // perform same tests for read accesses
2058
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
2059
 
2060
    read_data`READ_ADDRESS  = target_address + 2 ;
2061
    read_data`READ_SEL      = 4'hF ;
2062
    read_data`READ_TAG_STIM = 0 ;
2063
 
2064
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2065
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2066
    begin
2067
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2068
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2069
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
2070
        disable no_transaction ;
2071
        disable main ;
2072
    end
2073
 
2074
    test_ok ;
2075
 
2076
    // prepare write data
2077
    for ( i = 0 ; i < 6 ; i = i + 1 )
2078
    begin
2079
        write_data`WRITE_DATA    = wmem_data[i] ;
2080
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
2081
        write_data`WRITE_SEL     = 4'hF ;
2082
        wishbone_master.blk_write_data[i] = write_data ;
2083
    end
2084
 
2085
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2086
    write_flags`WB_TRANSFER_CAB    = 1 ;
2087
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2088
 
2089
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
2090
    wishbone_master.wb_block_write(write_flags, write_status) ;
2091
 
2092
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2093
    begin
2094
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2095
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2096
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
2097
        disable no_transaction ;
2098
        disable main ;
2099
    end
2100
 
2101
    // prepare read data
2102
    for ( i = 0 ; i < 6 ; i = i + 1 )
2103
    begin
2104
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2105
        read_data`READ_SEL     = 4'hF ;
2106
        wishbone_master.blk_read_data_in[i] = read_data ;
2107
    end
2108
 
2109
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2110
    wishbone_master.wb_block_read(write_flags, read_status) ;
2111
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2112
    begin
2113
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2114
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2115
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2116
        disable no_transaction ;
2117
        disable main ;
2118
    end
2119
 
2120
    test_ok ;
2121
 
2122
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2123
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2124
 
2125
    // map image to IO space
2126
    `ifdef GUEST
2127
        skip = 1 ;
2128
    `endif
2129
 
2130
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2131
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2132
    if ( ok !== 1 )
2133
    begin
2134
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2135
        test_fail("WB Image Base Address register couldn't be written") ;
2136
        disable no_transaction ;
2137
        disable main ;
2138
    end
2139
 
2140
    skip = 0 ;
2141
 
2142
    write_data`WRITE_ADDRESS = target_address ;
2143
    write_data`WRITE_DATA    = wmem_data[0] ;
2144
    write_data`WRITE_SEL     = 4'b1010 ;
2145
 
2146
    // don't handle retries
2147
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2148
 
2149
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2150
 
2151
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2152
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2153
    begin
2154
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2155
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2156
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2157
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2158
        disable no_transaction ;
2159
        disable main ;
2160
    end
2161
 
2162
    write_data`WRITE_ADDRESS = target_address + 1 ;
2163
    write_data`WRITE_SEL     = 4'b0011 ;
2164
 
2165
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2166
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2167
    begin
2168
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2169
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2170
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2171
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2172
        disable no_transaction ;
2173
        disable main ;
2174
    end
2175
 
2176
    write_data`WRITE_SEL     = 4'b1100 ;
2177
 
2178
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2179
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2180
    begin
2181
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2182
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2183
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2184
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2185
        disable no_transaction ;
2186
        disable main ;
2187
    end
2188
 
2189
    write_data`WRITE_ADDRESS = target_address + 2 ;
2190
    write_data`WRITE_SEL     = 4'b0101 ;
2191
 
2192
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2193
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2194
    begin
2195
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2196
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2197
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2198
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2199
        disable no_transaction ;
2200
        disable main ;
2201
    end
2202
 
2203
    write_data`WRITE_SEL     = 4'b1000 ;
2204
 
2205
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2206
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2207
    begin
2208
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2209
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2210
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2211
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2212
        disable no_transaction ;
2213
        disable main ;
2214
    end
2215
 
2216
    write_data`WRITE_ADDRESS = target_address + 3 ;
2217
    write_data`WRITE_SEL     = 4'b1010 ;
2218
 
2219
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2220
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2221
    begin
2222
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2223
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2224
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2225
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2226
        disable no_transaction ;
2227
        disable main ;
2228
    end
2229
 
2230
    write_data`WRITE_SEL     = 4'b0110 ;
2231
 
2232
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2233
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2234
    begin
2235
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2236
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2237
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2238
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2239
        disable no_transaction ;
2240
        disable main ;
2241
    end
2242
 
2243
    test_ok ;
2244
 
2245
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2246
 
2247
    read_data`READ_ADDRESS  = target_address + 3 ;
2248
    read_data`READ_SEL      = 4'hF ;
2249
    read_data`READ_TAG_STIM = 0 ;
2250
 
2251
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2252
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2253
    begin
2254
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2255
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2256
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2257
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2258
        disable no_transaction ;
2259
        disable main ;
2260
    end
2261
 
2262
    test_ok ;
2263
 
2264
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2265
    // prepare write data
2266
    for ( i = 0 ; i < 6 ; i = i + 1 )
2267
    begin
2268
        write_data`WRITE_DATA    = wmem_data[i] ;
2269
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2270
        write_data`WRITE_SEL     = 4'hF ;
2271
        wishbone_master.blk_write_data[i] = write_data ;
2272
    end
2273
 
2274
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2275
    write_flags`WB_TRANSFER_CAB    = 1 ;
2276
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2277
 
2278
    wishbone_master.wb_block_write(write_flags, write_status) ;
2279
 
2280
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2281
    begin
2282
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2283
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2284
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2285
        disable no_transaction ;
2286
        disable main ;
2287
    end
2288
 
2289
    test_ok ;
2290
 
2291
    test_name = "CAB I/O READ TO WB SLAVE" ;
2292
    // prepare read data
2293
    for ( i = 0 ; i < 6 ; i = i + 1 )
2294
    begin
2295
        read_data`READ_ADDRESS = target_address + 4*i ;
2296
        read_data`READ_SEL     = 4'hF ;
2297
        wishbone_master.blk_read_data_in[i] = read_data ;
2298
    end
2299
 
2300
    wishbone_master.wb_block_read(write_flags, read_status) ;
2301
 
2302
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2303
    begin
2304
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2305
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2306
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2307
        disable no_transaction ;
2308
        disable main ;
2309
    end
2310
 
2311
    test_ok ;
2312
 
2313
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2314
 
2315
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2316
 
2317
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2318
    write_data`WRITE_ADDRESS = target_address + 1 ;
2319
    write_data`WRITE_DATA    = wmem_data[0] ;
2320
    write_data`WRITE_SEL     = 4'hF ;
2321
 
2322
    // don't handle retries
2323
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2324
 
2325
    `ifdef HOST
2326
        `define DO_W_CONF_TEST
2327
        `define DO_R_CONF_TEST
2328
    `else
2329
        `ifdef WB_CNF_IMAGE
2330
             `define DO_R_CONF_TEST
2331
        `endif
2332
    `endif
2333
 
2334
    `ifdef DO_W_CONF_TEST
2335
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2336
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2337
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2338
    begin
2339
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2340
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2341
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2342
        disable no_transaction ;
2343
        disable main ;
2344
    end
2345
 
2346
    write_data`WRITE_ADDRESS = target_address + 2 ;
2347
 
2348
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2349
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2350
    begin
2351
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2352
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2353
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2354
        disable no_transaction ;
2355
        disable main ;
2356
    end
2357
 
2358
    write_data`WRITE_ADDRESS = target_address + 3 ;
2359
 
2360
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2361
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2362
    begin
2363
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2364
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2365
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2366
        disable no_transaction ;
2367
        disable main ;
2368
    end
2369
 
2370
    test_ok ;
2371
    `endif
2372
 
2373
    `ifdef DO_R_CONF_TEST
2374
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2375
    read_data`READ_ADDRESS  = target_address + 3 ;
2376
    read_data`READ_SEL      = 4'hF ;
2377
    read_data`READ_TAG_STIM = 0 ;
2378
 
2379
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2380
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2381
    begin
2382
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2383
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2384
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2385
        disable no_transaction ;
2386
        disable main ;
2387
    end
2388
 
2389
    test_ok ;
2390
    `endif
2391
 
2392
    `ifdef DO_W_CONF_TEST
2393
    // prepare write data
2394
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2395
    for ( i = 0 ; i < 6 ; i = i + 1 )
2396
    begin
2397
        write_data`WRITE_DATA    = wmem_data[i] ;
2398
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2399
        write_data`WRITE_SEL     = 4'hF ;
2400
        wishbone_master.blk_write_data[i] = write_data ;
2401
    end
2402
 
2403
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2404
    write_flags`WB_TRANSFER_CAB    = 1 ;
2405
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2406
 
2407
    wishbone_master.wb_block_write(write_flags, write_status) ;
2408
 
2409
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2410
    begin
2411
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2412
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2413
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2414
        disable no_transaction ;
2415
        disable main ;
2416
    end
2417
    test_ok ;
2418
    `endif
2419
 
2420
    `ifdef DO_R_CONF_TEST
2421
    // prepare read data
2422
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2423
    for ( i = 0 ; i < 6 ; i = i + 1 )
2424
    begin
2425
        read_data`READ_ADDRESS = target_address + 4*i ;
2426
        read_data`READ_SEL     = 4'hF ;
2427
        wishbone_master.blk_read_data_in[i] = read_data ;
2428
    end
2429
 
2430
    wishbone_master.wb_block_read(write_flags, read_status) ;
2431
 
2432
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2433
    begin
2434
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2435
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2436
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2437
        disable no_transaction ;
2438
        disable main ;
2439
    end
2440
    test_ok ;
2441
    `endif
2442
 
2443
    `ifdef GUEST
2444
        skip = 1 ;
2445
    `endif
2446
 
2447
    // disable image
2448
    test_name = "DISABLE IMAGE" ;
2449
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2450
    if ( ok !== 1 )
2451
    begin
2452
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2453
        test_fail("WB Address Mask register couldn't be written") ;
2454
        disable no_transaction ;
2455
        disable main ;
2456
    end
2457
 
2458
    skip = 0 ;
2459
 
2460
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2461
 
2462
    disable no_transaction ;
2463
end
2464
begin:no_transaction
2465
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2466
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2467
    forever
2468
    begin
2469
        @(posedge pci_clock) ;
2470
        if ( skip !== 1 )
2471
        begin
2472
            if ( FRAME !== 1 )
2473
            begin
2474
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2475
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2476
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2477
            end
2478
        end
2479
    end
2480
end
2481
join
2482
endtask //wb_slave_errors
2483
 
2484
task wb_to_pci_error_handling ;
2485
    reg   [11:0] ctrl_offset ;
2486
    reg   [11:0] ba_offset ;
2487
    reg   [11:0] am_offset ;
2488
    reg   [11:0] ta_offset ;
2489
    reg   [11:0] err_cs_offset ;
2490
    reg `WRITE_STIM_TYPE write_data ;
2491
    reg `READ_STIM_TYPE  read_data ;
2492
    reg `READ_RETURN_TYPE read_status ;
2493
 
2494
    reg `WRITE_RETURN_TYPE write_status ;
2495
    reg `WB_TRANSFER_FLAGS write_flags ;
2496
    reg [31:0] temp_val1 ;
2497
    reg [31:0] temp_val2 ;
2498
    reg        ok   ;
2499
    reg [11:0] pci_ctrl_offset ;
2500
    reg [31:0] image_base ;
2501
    reg [31:0] target_address ;
2502
    integer    num_of_trans ;
2503
    integer    current ;
2504
    integer    i ;
2505
begin:main
2506
 
2507
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2508
 
2509
    pci_ctrl_offset = 12'h4 ;
2510
 
2511
    // disable error interrupts and disable error reporting
2512
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2513
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2514
    if ( ok !== 1 )
2515
    begin
2516
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2517
        test_fail("PCI Device Control register couldn't be written") ;
2518
        disable main ;
2519
    end
2520
 
2521
    // image 1 is used for error testing, since it is always implemented
2522
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2523
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2524
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2525
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2526
 
2527
    // set master abort testing address to address that goes out of target's range
2528
    target_address  = `BEH_TAR1_MEM_START ;
2529
    image_base      = 0 ;
2530
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2531
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2532
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2533
 
2534
    write_flags                    = 0 ;
2535
    write_flags`INIT_WAITS         = tb_init_waits ;
2536
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2537
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2538
 
2539
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2540
 
2541
    // enable master & target operation
2542
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2543
    if ( ok !== 1 )
2544
    begin
2545
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2546
        test_fail("PCI Device Control register couldn't be written") ;
2547
        disable main ;
2548
    end
2549
 
2550
    // prepare image control register
2551
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2552
    if ( ok !== 1 )
2553
    begin
2554
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2555
        test_fail("WB Image Control register couldn't be written") ;
2556
        disable main ;
2557
    end
2558
 
2559
    // prepare base address register
2560
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2561
    if ( ok !== 1 )
2562
    begin
2563
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2564
        test_fail("WB Image Base Address register couldn't be written") ;
2565
        disable main ;
2566
    end
2567
 
2568
    // write address mask register
2569
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2570
    if ( ok !== 1 )
2571
    begin
2572
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2573
        test_fail("WB Image Address Mask register couldn't be written") ;
2574
        disable main ;
2575
    end
2576
 
2577
    // disable error reporting
2578
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2579
    if ( ~ok )
2580
    begin
2581
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2582
        test_fail("WB Error Control and Status register couldn't be written") ;
2583
        disable main ;
2584
    end
2585
 
2586
    // perform two writes - one to error address and one to OK address
2587
    // prepare write buffer
2588
 
2589
    write_data`WRITE_ADDRESS = target_address ;
2590
    write_data`WRITE_DATA    = wmem_data[100] ;
2591
    write_data`WRITE_SEL     = 4'hF ;
2592
 
2593
    wishbone_master.blk_write_data[0] = write_data ;
2594
 
2595
    write_flags`WB_TRANSFER_SIZE = 2 ;
2596
 
2597
    // don't handle retries
2598
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2599
    write_flags`WB_TRANSFER_CAB    = 0 ;
2600
 
2601
    $display("Introducing master abort error on single WB to PCI write!") ;
2602
 
2603
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2604
    // first disable target 1
2605
 
2606 45 mihad
    configuration_cycle_write(0,                        // bus number
2607
                              `TAR1_IDSEL_INDEX - 11,   // device number
2608
                              0,                        // function number
2609
                              1,                        // register number
2610
                              0,                        // type of configuration cycle
2611
                              4'b0001,                  // byte enables
2612
                              32'h0000_0000             // data
2613 15 mihad
                             ) ;
2614
 
2615
    fork
2616
    begin
2617
        // start no response monitor in parallel with writes
2618
        musnt_respond(ok) ;
2619
        if ( ok !== 1 )
2620
        begin
2621
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2622
            $display("Testbench is configured wrong!") ;
2623
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2624
        end
2625
        else
2626
            test_ok ;
2627
    end
2628
    begin
2629
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2630
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2631
       begin
2632
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2633
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2634
           test_fail("WB Slave state machine failed to post single memory write");
2635
           disable main ;
2636
       end
2637
    end
2638
    join
2639
 
2640
    /*// read data from second write
2641
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2642
    read_data`READ_ADDRESS = target_address ;
2643
    read_data`READ_SEL     = 4'hF ;
2644
    read_data`READ_TAG_STIM = 0 ;
2645
 
2646
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2647
 
2648
    if ( read_status`READ_DATA !== wmem_data[101] )
2649
    begin
2650
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2651
    end
2652
    */
2653
 
2654
    // read error status register - no errors should be reported since reporting was disabled
2655
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2656
 
2657
    @(posedge pci_clock) ;
2658
    // wait for two WB clocks for synchronization to be finished
2659
    repeat (2)
2660
        @(posedge wb_clock) ;
2661
 
2662
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2663
    if ( temp_val1[8] !== 0 )
2664
    begin
2665
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2666
        $display("Error reporting was disabled, but error was reported anyway!") ;
2667
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2668
        disable main ;
2669
    end
2670
    test_ok ;
2671
 
2672
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2673
    // check for interrupts - there should be no interrupt requests active
2674
    `ifdef HOST
2675
        repeat(4)
2676
            @(posedge wb_clock) ;
2677
 
2678
        if ( INT_O !== 0 )
2679
        begin
2680
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2681
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2682
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2683
        end
2684
        else
2685
            test_ok ;
2686
    `else
2687
    `ifdef GUEST
2688
        repeat( 4 )
2689
            @(posedge pci_clock) ;
2690
 
2691
        if ( INTA !== 1 )
2692
        begin
2693
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2694
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2695
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2696
        end
2697
        else
2698
            test_ok ;
2699
    `endif
2700
    `endif
2701
 
2702
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2703
    // check PCI status register
2704
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2705
    if ( temp_val1[29] !== 1 )
2706
    begin
2707
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2708
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2709
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2710
    end
2711
    else
2712
        test_ok ;
2713
 
2714
    // clear
2715
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2716
 
2717
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2718
 
2719
    $display("Introducing master abort error to CAB write!") ;
2720
    // now enable error reporting mechanism
2721
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2722
    // enable error interrupts
2723
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2724
 
2725
    // configure flags for CAB transfer
2726
    write_flags`WB_TRANSFER_CAB = 1 ;
2727
    write_flags`WB_TRANSFER_SIZE = 3 ;
2728
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2729
 
2730
    // prepare data for erroneous write
2731
    for ( i = 0 ; i < 3 ; i = i + 1 )
2732
    begin
2733
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2734
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2735
        write_data`WRITE_SEL     = 4'hF ;
2736
        wishbone_master.blk_write_data[i] = write_data ;
2737
    end
2738
 
2739
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2740
    fork
2741
    begin
2742
        wishbone_master.wb_block_write(write_flags, write_status) ;
2743
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2744
        begin
2745
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2746
            $display("Complete burst write through WB slave didn't succeed!") ;
2747
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2748
            disable main ;
2749
        end
2750
    end
2751
    begin
2752
        musnt_respond(ok) ;
2753
        if ( ok !== 1 )
2754
        begin
2755
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2756
            $display("Testbench is configured wrong!") ;
2757
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2758
        end
2759
        else
2760
            test_ok ;
2761
    end
2762
    join
2763
 
2764
    // check error status address, data, byte enables and bus command
2765
    // error status bit is signalled on PCI clock and synchronized to WB clock
2766
    // wait one PCI clock cycle
2767
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2768
    ok = 1 ;
2769
    @(posedge pci_clock) ;
2770
 
2771
    // wait for two WB clocks for synchronization to be finished
2772
    repeat (2)
2773
        @(posedge wb_clock) ;
2774
 
2775
    // read registers
2776
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2777
    if ( temp_val1[8] !== 1 )
2778
    begin
2779
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2780
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2781
        ok = 0 ;
2782
    end
2783
 
2784
    if ( temp_val1[9] !== 1 )
2785
    begin
2786
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2787
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2788
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2789
        ok = 0 ;
2790
    end
2791
 
2792
    if ( temp_val1[31:28] !== 0 )
2793
    begin
2794
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2795
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2796
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2797
        ok = 0 ;
2798
    end
2799
 
2800
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2801
    begin
2802
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2803
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2804
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2805
        ok = 0 ;
2806
    end
2807
 
2808
    // read error address register
2809
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2810
    if ( temp_val1 !== target_address )
2811
    begin
2812
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2813
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2814
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2815
        ok = 0 ;
2816
    end
2817
 
2818
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2819
    if ( temp_val1 !== wmem_data[110] )
2820
    begin
2821
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2822
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2823
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2824
        ok = 0 ;
2825
    end
2826
 
2827
    // check PCI status register
2828
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2829
    if ( temp_val1[29] !== 1 )
2830
    begin
2831
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2832
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2833
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2834
        ok = 0 ;
2835
    end
2836
 
2837
    if ( temp_val1[28] !== 0 )
2838
    begin
2839
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2840
        $display("Received Target Abort bit was set for no reason!") ;
2841
        test_fail("Received Target Abort bit was set for no reason") ;
2842
        ok = 0 ;
2843
    end
2844
 
2845
    if ( ok )
2846
        test_ok ;
2847
 
2848
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2849
 
2850
    // clear error status bit
2851
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2852
 
2853
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2854
 
2855
    ok = 1 ;
2856
 
2857
    `ifdef HOST
2858
        repeat(4)
2859
        @(posedge wb_clock) ;
2860
        if ( INT_O !== 1 )
2861
        begin
2862
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2863
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2864
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2865
            ok = 0 ;
2866
        end
2867
    `else
2868
    `ifdef GUEST
2869
        repeat(4)
2870
        @(posedge pci_clock) ;
2871
        if ( INTA !== 0 )
2872
        begin
2873
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2874
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2875
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2876
            ok = 0 ;
2877
        end
2878
    `endif
2879
    `endif
2880
 
2881
    // read interrupt status register
2882
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2883
    if ( temp_val1 !== 32'h0000_0002 )
2884
    begin
2885
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2886
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2887
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2888
        test_fail("Interrupt Status register returned wrong value") ;
2889
        ok = 0 ;
2890
    end
2891
 
2892
    if ( ok )
2893
        test_ok ;
2894
    // clear interrupt status bits
2895
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2896
 
2897
    ok = 1 ;
2898
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2899
    // wait for two clock cycles before checking interrupt request deassertion
2900
    `ifdef HOST
2901
        repeat (4)
2902
            @(posedge wb_clock) ;
2903
 
2904
        if ( INT_O !== 0 )
2905
        begin
2906
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2907
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2908
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2909
            ok = 0 ;
2910
        end
2911
    `else
2912
    `ifdef GUEST
2913
        repeat (4)
2914
            @(posedge pci_clock) ;
2915
 
2916
        if ( INTA !== 1 )
2917
        begin
2918
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2919
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2920
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2921
            ok = 0 ;
2922
        end
2923
    `endif
2924
    `endif
2925
 
2926
    if ( ok )
2927
        test_ok ;
2928
 
2929
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2930
    ok = 1 ;
2931
    // enable target
2932 45 mihad
    configuration_cycle_write(0,                        // bus number
2933
                              `TAR1_IDSEL_INDEX - 11,   // device number
2934
                              0,                        // function number
2935
                              1,                        // register number
2936
                              0,                        // type of configuration cycle
2937
                              4'b0001,                  // byte enables
2938
                              32'h0000_0007             // data
2939 15 mihad
                             ) ;
2940
    // prepare data for ok write
2941
    for ( i = 0 ; i < 3 ; i = i + 1 )
2942
    begin
2943
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2944
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2945
        write_data`WRITE_SEL     = 4'hF ;
2946
        wishbone_master.blk_write_data[i] = write_data ;
2947
    end
2948
 
2949
    wishbone_master.wb_block_write(write_flags, write_status) ;
2950
 
2951
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2952
    begin
2953
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2954
        $display("Complete burst write through WB slave didn't succeed!") ;
2955
        test_fail("WB Slave state machine failed to post CAB write") ;
2956
        disable main ;
2957
    end
2958
 
2959
    // do a read
2960
    for ( i = 0 ; i < 3 ; i = i + 1 )
2961
    begin
2962
        read_data`READ_ADDRESS = target_address + 4*i ;
2963
        read_data`READ_SEL     = 4'hF ;
2964
        wishbone_master.blk_read_data_in[i] = read_data ;
2965
    end
2966
 
2967
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2968
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2969
    write_flags`WB_TRANSFER_CAB    = 1 ;
2970
 
2971
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2972
 
2973
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2974
    begin
2975
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2976
        $display("Complete burst read through WB slave didn't succeed!") ;
2977
        test_fail("Delayed CAB write was not processed as expected") ;
2978
        disable main ;
2979
    end
2980
 
2981
    for ( i = 0 ; i < 3 ; i = i + 1 )
2982
    begin
2983
        read_status = wishbone_master.blk_read_data_out[i] ;
2984
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2985
        begin
2986
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2987
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2988
        end
2989
    end
2990
 
2991
    $display("Introducing master abort error to single read!") ;
2992
    // disable target
2993 45 mihad
    configuration_cycle_write(0,                        // bus number
2994
                              `TAR1_IDSEL_INDEX - 11,   // device number
2995
                              0,                        // function number
2996
                              1,                        // register number
2997
                              0,                        // type of configuration cycle
2998
                              4'b0001,                  // byte enables
2999
                              32'h0000_0000             // data
3000 15 mihad
                             ) ;
3001
    // set read data
3002
    read_data`READ_ADDRESS = target_address ;
3003
    read_data`READ_SEL     = 4'hF ;
3004
 
3005
    // enable automatic retry handling
3006
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3007
    write_flags`WB_TRANSFER_CAB    = 0 ;
3008
 
3009
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
3010
    fork
3011
    begin
3012
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3013
    end
3014
    begin
3015
        musnt_respond(ok) ;
3016
        if ( ok !== 1 )
3017
        begin
3018
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3019
            $display("Testbench is configured wrong!") ;
3020
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3021
        end
3022
    end
3023
    join
3024
 
3025
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3026
    begin
3027
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3028
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3029
        $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) ;
3030
        test_fail("read didn't finish on WB bus as expected") ;
3031
        disable main ;
3032
    end
3033
 
3034
    test_ok ;
3035
 
3036
 
3037
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
3038
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
3039
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3040
    if ( temp_val1[8] !== 0 )
3041
    begin
3042
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3043
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
3044
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
3045
    end
3046
    else
3047
        test_ok ;
3048
 
3049
    // now check normal read operation
3050 45 mihad
    configuration_cycle_write(0,                        // bus number
3051
                              `TAR1_IDSEL_INDEX - 11,   // device number
3052
                              0,                        // function number
3053
                              1,                        // register number
3054
                              0,                        // type of configuration cycle
3055
                              4'b0001,                  // byte enables
3056
                              32'h0000_0007             // data
3057 15 mihad
                             ) ;
3058
 
3059 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
3060 15 mihad
    read_data`READ_ADDRESS = target_address ;
3061
    read_data`READ_SEL     = 4'hF ;
3062
 
3063
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3064
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3065
    begin
3066
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3067
        $display("WB slave failed to process single read!") ;
3068
        $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) ;
3069
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
3070
        disable main ;
3071
    end
3072
 
3073
    if ( read_status`READ_DATA !== wmem_data[113] )
3074
    begin
3075
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
3076
        test_fail("when read finished on WB bus, wrong data was provided") ;
3077
    end
3078
    else
3079
        test_ok ;
3080
 
3081
    // check PCI status register
3082 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
3083 15 mihad
    ok = 1 ;
3084
 
3085
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3086
    if ( temp_val1[29] !== 1 )
3087
    begin
3088
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3089
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3090
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3091
        ok = 0 ;
3092
    end
3093
 
3094
    if ( temp_val1[28] !== 0 )
3095
    begin
3096
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3097
        $display("Received Target Abort bit was set for no reason!") ;
3098
        test_fail("Received Target Abort bit was set for no reason") ;
3099
        ok = 0 ;
3100
    end
3101
    if ( ok )
3102
        test_ok ;
3103
 
3104
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3105
 
3106
    $display("Introducing master abort error to CAB read!") ;
3107
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3108
 
3109 45 mihad
    configuration_cycle_write(0,                        // bus number
3110
                              `TAR1_IDSEL_INDEX - 11,   // device number
3111
                              0,                        // function number
3112
                              1,                        // register number
3113
                              0,                        // type of configuration cycle
3114
                              4'b0001,                  // byte enables
3115
                              32'h0000_0000             // data
3116 15 mihad
                             ) ;
3117
 
3118
    for ( i = 0 ; i < 3 ; i = i + 1 )
3119
    begin
3120
        read_data`READ_ADDRESS = target_address + 4*i ;
3121
        read_data`READ_SEL     = 4'hF ;
3122
        wishbone_master.blk_read_data_in[i] = read_data ;
3123
    end
3124
 
3125
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3126
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3127
    write_flags`WB_TRANSFER_CAB    = 1 ;
3128
 
3129
    fork
3130
    begin
3131
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3132
    end
3133
    begin
3134
        musnt_respond(ok) ;
3135
        if ( ok !== 1 )
3136
        begin
3137
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3138
            $display("Testbench is configured wrong!") ;
3139
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3140
        end
3141
    end
3142
    join
3143
 
3144
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3145
    begin
3146
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3147
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3148
        $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) ;
3149
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3150
        disable main ;
3151
    end
3152
    else
3153
        test_ok ;
3154
 
3155
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3156
    ok = 1 ;
3157
    // check PCI status register
3158
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3159
    if ( temp_val1[29] !== 1 )
3160
    begin
3161
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3162
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3163
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3164
        ok = 0 ;
3165
    end
3166
 
3167
    if ( temp_val1[28] !== 0 )
3168
    begin
3169
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3170
        $display("Received Target Abort bit was set for no reason!") ;
3171
        test_fail("Received Target Abort bit was set for no reason") ;
3172
        ok = 0 ;
3173
    end
3174
 
3175
    if ( ok )
3176
        test_ok ;
3177
 
3178
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3179
 
3180
    $display("Introducing target abort termination to single write!") ;
3181
 
3182
    // disable error reporting and interrupts
3183
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3184
 
3185 45 mihad
    configuration_cycle_write(0,                        // bus number
3186
                              `TAR1_IDSEL_INDEX - 11,   // device number
3187
                              0,                        // function number
3188
                              1,                        // register number
3189
                              0,                        // type of configuration cycle
3190
                              4'b0001,                  // byte enables
3191
                              32'h0000_0007             // data
3192 15 mihad
                             ) ;
3193
 
3194
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3195
    if ( ok !== 1 )
3196
    begin
3197
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3198
        test_fail("WB Error Control and Status register couldn't be written to") ;
3199
        disable main ;
3200
    end
3201
 
3202
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3203
    if ( ok !== 1 )
3204
    begin
3205
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3206
        test_fail("Interrupt Control register couldn't be written to") ;
3207
        disable main ;
3208
    end
3209
 
3210
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3211
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3212
 
3213
    write_data`WRITE_ADDRESS = target_address ;
3214
    write_data`WRITE_DATA    = wmem_data[0] ;
3215
    write_data`WRITE_SEL     = 4'hF ;
3216
 
3217
    wishbone_master.blk_write_data[0] = write_data ;
3218
 
3219
    write_data`WRITE_ADDRESS = target_address + 4;
3220
    write_data`WRITE_DATA    = wmem_data[1] ;
3221
    write_data`WRITE_SEL     = 4'hF ;
3222
 
3223
    wishbone_master.blk_write_data[1] = write_data ;
3224
 
3225
    write_flags`WB_TRANSFER_SIZE = 2 ;
3226
 
3227
    // don't handle retries
3228
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3229
    write_flags`WB_TRANSFER_CAB    = 0 ;
3230
 
3231
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3232
    fork
3233
    begin
3234
        wishbone_master.wb_block_write(write_flags, write_status) ;
3235
 
3236
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3237
        begin
3238
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3239
            $display("Image writes were not accepted as expected!") ;
3240
            $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) ;
3241
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3242
            disable main ;
3243
        end
3244
 
3245
        // read data back to see, if it was written OK
3246
        read_data`READ_ADDRESS         = target_address + 4;
3247
        read_data`READ_SEL             = 4'hF ;
3248
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3249
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3250
    end
3251
    begin
3252
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3253
        if ( ok !== 1 )
3254
        begin
3255
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3256
        end
3257
        else
3258
            test_ok ;
3259
 
3260
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3261
 
3262
        // when first transaction finishes - enable normal target response!
3263
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3264
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3265
 
3266
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3267
        if ( ok !== 1 )
3268
        begin
3269
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3270
        end
3271
        else
3272
            test_ok ;
3273
 
3274
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3275
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3276
        if ( ok !== 1 )
3277
        begin
3278
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3279
        end
3280
    end
3281
    join
3282
 
3283
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3284
    begin
3285
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3286
        $display("Bridge failed to process single read after target abort terminated write!") ;
3287
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3288
        disable main ;
3289
    end
3290
 
3291
    if ( read_status`READ_DATA !== wmem_data[1] )
3292
    begin
3293
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3294
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3295
    end
3296
    else
3297
        test_ok ;
3298
 
3299
    // check interrupt and error statuses!
3300
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3301
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3302
    if ( temp_val1[8] !== 0 )
3303
    begin
3304
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3305
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3306
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3307
    end
3308
    else
3309
        test_ok ;
3310
 
3311
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3312
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3313
    if ( temp_val1[1] !== 0 )
3314
    begin
3315
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3316
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3317
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3318
    end
3319
    else
3320
        test_ok ;
3321
 
3322
    // check PCI status register
3323
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3324
    ok = 1 ;
3325
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3326
    if ( temp_val1[29] !== 0 )
3327
    begin
3328
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3329
        $display("Received Master Abort bit was set with no reason!") ;
3330
        test_fail("Received Master Abort bit was set with no reason") ;
3331
        ok = 0 ;
3332
    end
3333
 
3334
    if ( temp_val1[28] !== 1 )
3335
    begin
3336
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3337
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3338
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3339
        ok = 0 ;
3340
    end
3341
 
3342
    if ( ok )
3343
        test_ok ;
3344
 
3345
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3346
 
3347
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3348
 
3349
    $display("Introducing target abort termination to CAB write!") ;
3350
    // enable error reporting mechanism
3351
 
3352
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3353
    if ( ok !== 1 )
3354
    begin
3355
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3356
        test_fail("WB Error Control and Status register could not be written to") ;
3357
        disable main ;
3358
    end
3359
 
3360
    for ( i = 0 ; i < 3 ; i = i + 1 )
3361
    begin
3362
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3363
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3364
        write_data`WRITE_SEL     = 4'b1010 ;
3365
        wishbone_master.blk_write_data[i] = write_data ;
3366
    end
3367
 
3368
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3369
    write_flags`WB_TRANSFER_CAB    = 1 ;
3370
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3371
 
3372
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3373
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3374
 
3375
    fork
3376
    begin
3377
        wishbone_master.wb_block_write(write_flags, write_status) ;
3378
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3379
        begin
3380
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3381
            $display("Bridge failed to process complete CAB write!") ;
3382
            test_fail("bridge failed to post CAB Memory Write") ;
3383
            disable main ;
3384
        end
3385
    end
3386
    begin
3387
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3388
        if ( ok !== 1 )
3389
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3390
        else
3391
            test_ok ;
3392
    end
3393
    join
3394
 
3395
    // check statuses and data from error
3396
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3397
    ok = 1 ;
3398
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3399
    if ( temp_val1[8] !== 1 )
3400
    begin
3401
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3402
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3403
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3404
        ok = 0 ;
3405
    end
3406
 
3407
    if ( temp_val1[9] !== 0 )
3408
    begin
3409
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3410
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3411
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3412
        ok = 0 ;
3413
    end
3414
 
3415
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3416
    begin
3417
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3418
        $display("Value in W_ERR_CS register was wrong!") ;
3419
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3420
        test_fail("BE Field didn't provided expected value") ;
3421
        ok = 0 ;
3422
    end
3423
 
3424
    if ( ok )
3425
        test_ok ;
3426
 
3427
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3428
    ok = 1 ;
3429
    // check erroneous address and data
3430
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3431
    if ( temp_val1 !== (target_address + 8) )
3432
    begin
3433
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3434
        $display("Value in W_ERR_ADDR register was wrong!") ;
3435
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3436
        test_fail("Value in WB Erroneous Address register was wrong") ;
3437
        ok = 0 ;
3438
    end
3439
 
3440
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3441
    if ( temp_val1 !== wmem_data[120] )
3442
    begin
3443
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3444
        $display("Value in W_ERR_DATA register was wrong!") ;
3445
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3446
        test_fail("Value in WB Erroneous Data register was wrong") ;
3447
        ok = 0 ;
3448
    end
3449
 
3450
    if ( ok )
3451
        test_ok ;
3452
 
3453
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3454
    ok = 1 ;
3455
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3456
    if ( temp_val1[29] !== 0 )
3457
    begin
3458
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3459
        $display("Received Master Abort bit was set with no reason!") ;
3460
        test_fail("Received Master Abort bit was set for no reason") ;
3461
        ok = 0 ;
3462
    end
3463
 
3464
    if ( temp_val1[28] !== 1 )
3465
    begin
3466
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3467
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3468
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3469
        ok = 0 ;
3470
    end
3471
 
3472
    if ( ok )
3473
        test_ok ;
3474
 
3475
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3476
 
3477
    // clear error status bit and enable error interrupts
3478
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3479
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3480
 
3481
    // check if error bit was cleared
3482
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3483
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3484
    if ( temp_val1[8] !== 0 )
3485
    begin
3486
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3487
        $display("Error bit was not cleared even though one was written to its location!") ;
3488
        test_fail("Error bit was not cleared even though one was written to its location") ;
3489
    end
3490
 
3491
    // repeat same write with different target configuration
3492
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3493
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3494
 
3495
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3496
    fork
3497
    begin
3498
        write_flags`WB_TRANSFER_SIZE = 2 ;
3499
        wishbone_master.wb_block_write(write_flags, write_status) ;
3500
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3501
        begin
3502
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3503
            $display("Bridge failed to process complete CAB write!") ;
3504
            test_fail("bridge failed to post CAB Memory Write") ;
3505
            disable main ;
3506
        end
3507
 
3508
        write_flags`WB_TRANSFER_SIZE = 3 ;
3509
        wishbone_master.wb_block_write(write_flags, write_status) ;
3510
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3511
        begin
3512
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3513
            $display("Bridge failed to process complete CAB write!") ;
3514
            test_fail("bridge failed to post CAB Memory Write") ;
3515
            disable main ;
3516
        end
3517
    end
3518
    begin
3519
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3520
        if ( ok !== 1 )
3521
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3522
        else
3523
        begin
3524
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3525
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3526
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3527
            if ( ok !== 1 )
3528
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3529
            else
3530
                test_ok ;
3531
        end
3532
    end
3533
    join
3534
 
3535
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3536
    ok = 1 ;
3537
    // check statuses and data from error
3538
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3539
    if ( temp_val1[8] !== 1 )
3540
    begin
3541
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3542
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3543
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3544
        ok = 0 ;
3545
    end
3546
 
3547
    if ( temp_val1[9] !== 0 )
3548
    begin
3549
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3550
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3551
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3552
        ok = 0 ;
3553
    end
3554
 
3555
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3556
    begin
3557
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3558
        $display("Value in W_ERR_CS register was wrong!") ;
3559
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3560
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3561
        ok = 0 ;
3562
    end
3563
 
3564
    if ( ok )
3565
        test_ok ;
3566
 
3567
    // check erroneous address and data
3568
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3569
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3570
    ok = 1 ;
3571
    if ( temp_val1 !== (target_address + 8 + 4) )
3572
    begin
3573
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3574
        $display("Value in W_ERR_ADDR register was wrong!") ;
3575
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3576
        test_fail("Value in WB Erroneous Address register was wrong") ;
3577
        ok = 0 ;
3578
 
3579
    end
3580
 
3581
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3582
    if ( temp_val1 !== wmem_data[121] )
3583
    begin
3584
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3585
        $display("Value in W_ERR_DATA register was wrong!") ;
3586
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3587
        test_fail("Value in WB Erroneous Data register was wrong") ;
3588
        ok = 0 ;
3589
    end
3590
 
3591
    if ( ok )
3592
        test_ok ;
3593
 
3594
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3595
    `ifdef HOST
3596
        repeat(4)
3597
            @(posedge wb_clock) ;
3598
        if ( INT_O !== 1 )
3599
        begin
3600
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3601
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3602
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3603
        end
3604
        else
3605
            test_ok ;
3606
    `else
3607
    `ifdef GUEST
3608
        repeat(4)
3609
            @(posedge pci_clock) ;
3610
        if ( INTA !== 0 )
3611
        begin
3612
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3613
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3614
            test_fail("interrupt request was not presented on PCI bus") ;
3615
        end
3616
        else
3617
            test_ok ;
3618
    `endif
3619
    `endif
3620
 
3621
    // read interrupt status register
3622
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3623
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3624
    if ( temp_val1[1] !== 1 )
3625
    begin
3626
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3627
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3628
        test_fail("Expected Interrupt status bit wasn't set") ;
3629
    end
3630
 
3631
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3632
 
3633
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3634
    ok = 1 ;
3635
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3636
    if ( temp_val1[29] !== 0 )
3637
    begin
3638
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3639
        $display("Received Master Abort bit was set with no reason!") ;
3640
        test_fail("Received Master Abort bit was set with no reason") ;
3641
        ok = 0 ;
3642
    end
3643
 
3644
    if ( temp_val1[28] !== 1 )
3645
    begin
3646
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3647
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3648
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3649
        ok = 0 ;
3650
    end
3651
 
3652
    if ( ok )
3653
        test_ok ;
3654
 
3655
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3656
 
3657
    // clear interrupts and errors
3658
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3659
    repeat( 3 )
3660
        @(posedge pci_clock) ;
3661
 
3662
    repeat( 2 )
3663
        @(posedge wb_clock) ;
3664
 
3665
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3666
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3667
    if ( temp_val1[1] !== 0 )
3668
    begin
3669
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3670
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3671
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3672
    end
3673
    else
3674
        test_ok ;
3675
 
3676
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3677
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3678
    if ( temp_val1[8] !== 0 )
3679
    begin
3680
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3681
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3682
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3683
    end
3684
 
3685
 
3686
    $display("Introducing Target Abort error to single read!") ;
3687
    // set read data
3688
    read_data`READ_ADDRESS = target_address + 8 ;
3689
    read_data`READ_SEL     = 4'hF ;
3690
 
3691
    // enable automatic retry handling
3692
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3693
    write_flags`WB_TRANSFER_CAB    = 0 ;
3694
 
3695
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3696
 
3697
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3698
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3699
 
3700
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3701
 
3702
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3703
    begin
3704
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3705
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3706
        $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) ;
3707
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3708
        disable main ;
3709
    end
3710
    else
3711
        test_ok ;
3712
 
3713
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3714
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3715
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3716
    if ( temp_val1[8] !== 0 )
3717
    begin
3718
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3719
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3720
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3721
    end
3722
    else
3723
        test_ok ;
3724
 
3725
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3726
    ok = 1 ;
3727
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3728
    if ( temp_val1[29] !== 0 )
3729
    begin
3730
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3731
        $display("Received Master Abort bit was set with no reason!") ;
3732
        test_fail("Received Master Abort bit was set with no reason") ;
3733
        ok = 0 ;
3734
    end
3735
 
3736
    if ( temp_val1[28] !== 1 )
3737
    begin
3738
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3739
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3740
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3741
        ok = 0 ;
3742
    end
3743
 
3744
    if ( ok )
3745
        test_ok ;
3746
 
3747
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3748
 
3749
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3750
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3751
    if ( temp_val1[1] !== 0 )
3752
    begin
3753
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3754
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3755
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3756
    end
3757
    else
3758
        test_ok ;
3759
 
3760
    $display("Introducing Target Abort error to CAB read!") ;
3761
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3762
 
3763
    for ( i = 0 ; i < 4 ; i = i + 1 )
3764
    begin
3765
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3766
        read_data`READ_SEL     = 4'b1010 ;
3767
        wishbone_master.blk_read_data_in[i] = read_data ;
3768
    end
3769
 
3770
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3771
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3772
    write_flags`WB_TRANSFER_CAB    = 1 ;
3773
 
3774
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3775
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3776
 
3777
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3778
 
3779
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3780
    begin
3781
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3782
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3783
        $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) ;
3784
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3785
        disable main ;
3786
    end
3787
 
3788
    read_status = wishbone_master.blk_read_data_out[0] ;
3789
    temp_val1 = read_status`READ_DATA ;
3790
    temp_val2 = wmem_data[120] ;
3791
 
3792
    // last write to this address was with only two byte enables - check only those
3793
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3794
    begin
3795
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3796
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3797
    end
3798
    else
3799
        test_ok ;
3800
 
3801
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3802
    ok = 1 ;
3803
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3804
    if ( temp_val1[29] !== 0 )
3805
    begin
3806
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3807
        $display("Received Master Abort bit was set with no reason!") ;
3808
        test_fail("Received Master Abort bit was set with no reason") ;
3809
        ok = 0 ;
3810
    end
3811
 
3812
    if ( temp_val1[28] !== 1 )
3813
    begin
3814
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3815
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3816
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3817
        ok = 0 ;
3818
    end
3819
 
3820
    if ( ok )
3821
       test_ok ;
3822
 
3823
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3824
 
3825
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3826
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3827
 
3828
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3829
    for ( i = 0 ; i < 3 ; i = i + 1 )
3830
    begin
3831
        read_data`READ_ADDRESS = target_address + 4*i ;
3832
        read_data`READ_SEL     = 4'b1111 ;
3833
        wishbone_master.blk_read_data_in[i] = read_data ;
3834
    end
3835
 
3836
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3837
 
3838
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3839
 
3840
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3841
    begin
3842
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3843
        $display("Complete burst read through WB slave didn't succeed!") ;
3844
        test_fail("bridge didn't process Burst Read in an expected way") ;
3845
        disable main ;
3846
    end
3847
    else
3848
        test_ok ;
3849
 
3850
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3851
 
3852
    for ( i = 0 ; i < 3 ; i = i + 1 )
3853
    begin
3854
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3855
        read_data`READ_SEL     = 4'b1111 ;
3856
        wishbone_master.blk_read_data_in[i] = read_data ;
3857
    end
3858
 
3859
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3860
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3861
    write_flags`WB_TRANSFER_CAB    = 1 ;
3862
 
3863
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3864
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3865
 
3866
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3867
 
3868
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3869
    begin
3870
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3871
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3872
        $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) ;
3873
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3874
        disable main ;
3875
    end
3876
 
3877
    for ( i = 0 ; i < 3 ; i = i + 1 )
3878
    begin
3879
        ok = 1 ;
3880
        read_status = wishbone_master.blk_read_data_out[i] ;
3881
        temp_val1 = read_status`READ_DATA ;
3882
        temp_val2 = wmem_data[120 + i] ;
3883
 
3884
        // last write to this address was with only two byte enables - check only those
3885
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3886
        begin
3887
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3888
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3889
            ok = 0 ;
3890
        end
3891
    end
3892
 
3893
    if ( ok )
3894
        test_ok ;
3895
 
3896
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3897
    ok = 1 ;
3898
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3899
    if ( temp_val1[29] !== 0 )
3900
    begin
3901
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3902
        $display("Received Master Abort bit was set with no reason!") ;
3903
        test_fail("Received Master Abort bit was set with no reason") ;
3904
        ok = 0 ;
3905
    end
3906
 
3907
    if ( temp_val1[28] !== 1 )
3908
    begin
3909
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3910
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3911
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3912
        ok = 0 ;
3913
    end
3914
 
3915
    if ( ok )
3916
       test_ok ;
3917
 
3918
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3919
 
3920
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3921
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3922
 
3923
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3924
    for ( i = 0 ; i < 3 ; i = i + 1 )
3925
    begin
3926
        read_data`READ_ADDRESS = target_address + 4*i ;
3927
        read_data`READ_SEL     = 4'b1111 ;
3928
        wishbone_master.blk_read_data_in[i] = read_data ;
3929
    end
3930
 
3931
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3932
 
3933
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3934
 
3935
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3936
    begin
3937
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3938
        $display("Complete burst read through WB slave didn't succeed!") ;
3939
        test_fail("bridge didn't process Burst Read in an expected way") ;
3940
        disable main ;
3941
    end
3942
    else
3943
        test_ok ;
3944
 
3945
    // test error on IO write
3946
    // change base address
3947
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3948
    write_data`WRITE_SEL     = 4'b0101 ;
3949
    write_data`WRITE_ADDRESS = target_address ;
3950
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3951
 
3952
    write_flags`WB_TRANSFER_CAB    = 0 ;
3953
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3954
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3955
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3956
    fork
3957
    begin
3958
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3959
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3960
        begin
3961
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3962
            $display("WB slave failed to accept IO write!") ;
3963
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3964
            disable main ;
3965
        end
3966
    end
3967
    begin
3968
        musnt_respond(ok) ;
3969
        if ( ok !== 1 )
3970
        begin
3971
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3972
            $display("Testbench is configured wrong!") ;
3973
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3974
        end
3975
        else
3976
            test_ok ;
3977
    end
3978
    join
3979
 
3980
    // check statuses and everything else
3981
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3982
    ok = 1 ;
3983
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3984
    if ( temp_val1[8] !== 1 )
3985
    begin
3986
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3987
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3988
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3989
        ok = 0 ;
3990
    end
3991
 
3992
    if ( temp_val1[9] !== 1 )
3993
    begin
3994
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3995
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3996
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3997
        ok = 0 ;
3998
    end
3999
 
4000
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
4001
    begin
4002
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4003
        $display("Value in W_ERR_CS register was wrong!") ;
4004
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
4005
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
4006
        ok = 0 ;
4007
    end
4008
 
4009
    if ( ok )
4010
        test_ok ;
4011
 
4012
    // check erroneous address and data
4013
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
4014
    ok = 1 ;
4015
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4016
    if ( temp_val1 !== target_address )
4017
    begin
4018
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4019
        $display("Value in W_ERR_ADDR register was wrong!") ;
4020
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
4021
        test_fail("WB Erroneous Address register didn't provide right value") ;
4022
        ok = 0 ;
4023
    end
4024
 
4025
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4026
    if ( temp_val1 !== 32'hAAAA_AAAA )
4027
    begin
4028
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4029
        $display("Value in W_ERR_DATA register was wrong!") ;
4030
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
4031
        test_fail("WB Erroneous Data register didn't provide right value") ;
4032
        ok = 0 ;
4033
    end
4034
 
4035
    if ( ok )
4036
        test_ok ;
4037
 
4038
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4039
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
4040
    if ( temp_val1[1] !== 1 )
4041
    begin
4042
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4043
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
4044
        test_fail("expected interrupt status bit was not set") ;
4045
    end
4046
    else
4047
        test_ok ;
4048
 
4049
    // clear interrupts and errors
4050
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
4051
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
4052
 
4053
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4054
    ok = 1 ;
4055
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4056
    if ( temp_val1[29] !== 1 )
4057
    begin
4058
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4059
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
4060
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
4061
        ok = 0 ;
4062
    end
4063
 
4064
    if ( temp_val1[28] !== 0 )
4065
    begin
4066
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4067
        $display("Received Target Abort bit was set for no reason!") ;
4068
        test_fail("Received Target Abort bit was set for no reason") ;
4069
        ok = 0 ;
4070
    end
4071
 
4072
    if ( ok )
4073
        test_ok ;
4074
 
4075
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4076
 
4077
    // disable image
4078
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4079
    if ( ok !== 1 )
4080
    begin
4081
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4082
        test_fail("WB Image Address Mask register couldn't be written") ;
4083
        disable main ;
4084
    end
4085
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
4086
 
4087
end
4088
endtask
4089
 
4090
task parity_checking ;
4091
    reg   [11:0] ctrl_offset ;
4092
    reg   [11:0] ba_offset ;
4093
    reg   [11:0] am_offset ;
4094
    reg   [11:0] ta_offset ;
4095
    reg `WRITE_STIM_TYPE write_data ;
4096
    reg `READ_STIM_TYPE  read_data ;
4097
    reg `READ_RETURN_TYPE read_status ;
4098
 
4099
    reg `WRITE_RETURN_TYPE write_status ;
4100
    reg `WB_TRANSFER_FLAGS write_flags ;
4101
    reg [31:0] temp_val1 ;
4102
    reg [31:0] temp_val2 ;
4103
    reg        ok   ;
4104
    reg [11:0] pci_ctrl_offset ;
4105
    reg [31:0] image_base ;
4106
    reg [31:0] target_address ;
4107
    reg [11:0] icr_offset ;
4108
    reg [11:0] isr_offset ;
4109
    reg [11:0] p_ba_offset ;
4110
    reg [11:0] p_am_offset ;
4111
    reg [11:0] p_ctrl_offset ;
4112
    integer    i ;
4113
    reg        perr_asserted ;
4114
begin:main
4115
    $display("******************************* Testing Parity Checker functions ********************************") ;
4116
    $display("Testing Parity Errors during Master Transactions!") ;
4117
    $display("Introducing Parity Erros to Master Writes!") ;
4118
    $fdisplay(pci_mon_log_file_desc,
4119
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4120
 
4121
    // image 1 is used for error testing, since it is always implemented
4122
    pci_ctrl_offset = 12'h004 ;
4123
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4124
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4125
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4126
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4127
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4128
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4129
 
4130
    // image 1 for PCI target
4131
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4132
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4133
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4134
 
4135
    target_address  = `BEH_TAR1_MEM_START ;
4136
    image_base      = 0 ;
4137
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4138
 
4139
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4140
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4141
    write_flags                    = 0 ;
4142
    write_flags`INIT_WAITS         = tb_init_waits ;
4143
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
4144
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4145
 
4146
    // enable master & target operation and disable parity functions
4147
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4148
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4149
    if ( ok !== 1 )
4150
    begin
4151
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4152
        test_fail("PCI Device Control register could not be written to") ;
4153
        disable main ;
4154
    end
4155
 
4156
    // prepare image control register
4157
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4158
    if ( ok !== 1 )
4159
    begin
4160
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4161
        test_fail("WB Image Control register could not be written to") ;
4162
        disable main ;
4163
    end
4164
 
4165
    // prepare base address register
4166
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4167
    if ( ok !== 1 )
4168
    begin
4169
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4170
        test_fail("WB Image Base Address register could not be written to") ;
4171
        disable main ;
4172
    end
4173
 
4174
    // write address mask register
4175
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4176
    if ( ok !== 1 )
4177
    begin
4178
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4179
        test_fail("WB Image Address Mask register could not be written to") ;
4180
        disable main ;
4181
    end
4182
 
4183
    // disable parity interrupts
4184
    config_write( icr_offset, 0, 4'hF, ok ) ;
4185
    if ( ok !== 1 )
4186
    begin
4187
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4188
        test_fail("Interrupt Control register could not be written to") ;
4189
        disable main ;
4190
    end
4191
 
4192
    write_data`WRITE_ADDRESS = target_address ;
4193
    write_data`WRITE_DATA    = wmem_data[0] ;
4194
    write_data`WRITE_SEL     = 4'b1111 ;
4195
 
4196
    // enable target's 1 response to parity errors
4197 45 mihad
    configuration_cycle_write(0,                        // bus number
4198
                              `TAR1_IDSEL_INDEX - 11,   // device number
4199
                              0,                        // function number
4200
                              1,                        // register number
4201
                              0,                        // type of configuration cycle
4202
                              4'b0001,                  // byte enables
4203
                              32'h0000_0047             // data
4204 15 mihad
                             ) ;
4205
 
4206
    // disable target's 2 response to parity errors
4207 45 mihad
    configuration_cycle_write(0,                        // bus number
4208
                              `TAR2_IDSEL_INDEX - 11,   // device number
4209
                              0,                        // function number
4210
                              1,                        // register number
4211
                              0,                        // type of configuration cycle
4212
                              4'b0001,                  // byte enables
4213
                              32'h0000_0007             // data
4214 15 mihad
                             ) ;
4215
 
4216
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4217
 
4218
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4219
    fork
4220
    begin
4221
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4222
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4223
        begin
4224
            $display("Parity checker testing failed! Time %t ", $time) ;
4225
            $display("Bridge failed to process single memory write!") ;
4226
            test_fail("bridge failed to post single WB memory write") ;
4227
            disable main ;
4228
        end
4229
    end
4230
    begin:wait_perr1
4231
        perr_asserted = 0 ;
4232
        @(posedge pci_clock) ;
4233
 
4234 35 mihad
        while ( PERR !== 0 )
4235 15 mihad
            @(posedge pci_clock) ;
4236
 
4237 35 mihad
        perr_asserted = 1 ;
4238 15 mihad
 
4239
    end
4240
    begin
4241
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4242
 
4243
        if ( ok !== 1 )
4244
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4245
 
4246 35 mihad
        repeat(2)
4247 15 mihad
            @(posedge pci_clock) ;
4248
 
4249 35 mihad
        #1 ;
4250
        if ( !perr_asserted )
4251
            disable wait_perr1 ;
4252 15 mihad
    end
4253
    join
4254
 
4255
    if ( perr_asserted && ok )
4256
    begin
4257
        test_ok ;
4258
    end
4259
    else
4260
    if ( ~perr_asserted )
4261
    begin
4262
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4263
        disable main ;
4264
    end
4265
 
4266
    // check all the statuses - if HOST is defined, wait for them to be synced
4267
    `ifdef HOST
4268
    repeat(4)
4269
        @(posedge wb_clock) ;
4270
    `endif
4271
 
4272
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4273
    ok = 1 ;
4274
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4275 45 mihad
    if ( temp_val1[31] !== 0 )
4276 15 mihad
    begin
4277
        $display("Parity checker testing failed! Time %t ", $time) ;
4278 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4279
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4280 15 mihad
        ok = 0 ;
4281
    end
4282
 
4283
    if ( temp_val1[30] !== 0 )
4284
    begin
4285
        $display("Parity checker testing failed! Time %t ", $time) ;
4286
        $display("Signalled System Error bit was set for no reason!") ;
4287
        test_fail("Signalled System Error bit was set for no reason") ;
4288
        ok = 0 ;
4289
    end
4290
 
4291
    if ( temp_val1[24] !== 0 )
4292
    begin
4293
        $display("Parity checker testing failed! Time %t ", $time) ;
4294
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4295
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4296
        ok = 0 ;
4297
    end
4298
 
4299
    if ( ok )
4300
        test_ok ;
4301
 
4302
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4303
    // clear parity bits and enable parity response
4304
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4305
    if ( ok !== 1 )
4306
    begin
4307
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4308
        test_fail("write to PCI Status Register failed") ;
4309
        disable main ;
4310
    end
4311
 
4312
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4313
    fork
4314
    begin
4315
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4316
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4317
        begin
4318
            $display("Parity checker testing failed! Time %t ", $time) ;
4319
            $display("Bridge failed to process single memory write!") ;
4320
            test_fail("bridge failed to post single memory write") ;
4321
            disable main ;
4322
        end
4323
    end
4324
    begin:wait_perr2
4325
        perr_asserted = 0 ;
4326
        @(posedge pci_clock) ;
4327
 
4328 35 mihad
        while ( PERR !== 0 )
4329 15 mihad
            @(posedge pci_clock) ;
4330
 
4331 35 mihad
        perr_asserted = 1 ;
4332 15 mihad
 
4333
    end
4334
    begin
4335
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4336
 
4337
        if ( ok !== 1 )
4338
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4339
 
4340 35 mihad
        repeat(2)
4341 15 mihad
            @(posedge pci_clock) ;
4342
 
4343 35 mihad
        #1 ;
4344
        if (!perr_asserted)
4345
            disable wait_perr2 ;
4346 15 mihad
    end
4347
    join
4348
 
4349
    if ( perr_asserted && ok )
4350
    begin
4351
        test_ok ;
4352
    end
4353
    else
4354
    if ( ~perr_asserted )
4355
    begin
4356
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4357
        disable main ;
4358
    end
4359
 
4360
    // check all the statuses - if HOST is defined, wait for them to be synced
4361
    `ifdef HOST
4362
    repeat(4)
4363
        @(posedge wb_clock) ;
4364
    `endif
4365
 
4366
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4367
    ok = 1 ;
4368
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4369 45 mihad
    if ( temp_val1[31] !== 0 )
4370 15 mihad
    begin
4371
        $display("Parity checker testing failed! Time %t ", $time) ;
4372 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4373
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4374 15 mihad
        ok = 0 ;
4375
    end
4376
 
4377
    if ( temp_val1[30] !== 0 )
4378
    begin
4379
        $display("Parity checker testing failed! Time %t ", $time) ;
4380
        $display("Signalled System Error bit was set for no reason!") ;
4381
        test_fail("Signalled System Error bit was set for no reason") ;
4382
        ok = 0 ;
4383
    end
4384
 
4385
    if ( temp_val1[24] !== 1 )
4386
    begin
4387
        $display("Parity checker testing failed! Time %t ", $time) ;
4388 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!") ;
4389
        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") ;
4390 15 mihad
        ok = 0 ;
4391
    end
4392
 
4393
    if ( ok )
4394
        test_ok ;
4395
 
4396
    // clear status bits and disable parity error response
4397
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4398
 
4399
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4400
 
4401
    // disable perr generation and perform a write - no bits should be set
4402
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4403
    fork
4404
    begin
4405
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4406
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4407
        begin
4408
            $display("Parity checker testing failed! Time %t ", $time) ;
4409
            $display("Bridge failed to process single memory write!") ;
4410
            test_fail("bridge failed to post single memory write") ;
4411
            disable main ;
4412
        end
4413
    end
4414
    begin
4415
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4416
 
4417
        if ( ok !== 1 )
4418
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4419
        else
4420
            test_ok ;
4421
 
4422
        repeat(3)
4423
            @(posedge pci_clock) ;
4424
    end
4425
    join
4426
 
4427
    `ifdef HOST
4428
    repeat(4)
4429
        @(posedge wb_clock) ;
4430
    `endif
4431
 
4432
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4433
    ok = 1 ;
4434
 
4435
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4436
    if ( temp_val1[31] !== 0 )
4437
    begin
4438
        $display("Parity checker testing failed! Time %t ", $time) ;
4439
        $display("Detected Parity Error bit was set for no reason!") ;
4440
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4441
        ok = 0 ;
4442
    end
4443
 
4444
    if ( temp_val1[30] !== 0 )
4445
    begin
4446
        $display("Parity checker testing failed! Time %t ", $time) ;
4447
        $display("Signalled System Error bit was set for no reason!") ;
4448
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4449
        ok = 0 ;
4450
    end
4451
 
4452
    if ( temp_val1[24] !== 0 )
4453
    begin
4454
        $display("Parity checker testing failed! Time %t ", $time) ;
4455
        $display("Master Data Parity Error bit was set for no reason!") ;
4456
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4457
        ok = 0 ;
4458
    end
4459
 
4460
    if ( ok )
4461
        test_ok ;
4462
 
4463
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4464
 
4465
    read_data = 0 ;
4466
    read_data`READ_ADDRESS  = target_address ;
4467
    read_data`READ_SEL      = 4'hF ;
4468
    read_data`READ_TAG_STIM = 0 ;
4469
 
4470
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4471
 
4472
    // enable parity and system error interrupts
4473
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4474
 
4475
    // enable parity error response
4476
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4477
 
4478
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4479
 
4480
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4481
    fork
4482
    begin
4483
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4484
    end
4485
    begin:wait_perr4
4486
        perr_asserted = 0 ;
4487
        @(posedge pci_clock) ;
4488 35 mihad
        while ( PERR !== 0 )
4489 15 mihad
            @(posedge pci_clock) ;
4490
 
4491 35 mihad
        perr_asserted = 1 ;
4492 15 mihad
 
4493
    end
4494
    begin
4495
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4496
 
4497
        if ( ok !== 1 )
4498
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4499
 
4500
        repeat(2)
4501
            @(posedge pci_clock) ;
4502
 
4503 35 mihad
        #1 ;
4504
        if ( !perr_asserted )
4505
            disable wait_perr4 ;
4506 15 mihad
    end
4507
    join
4508
 
4509
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4510
    begin
4511
        $display("Parity checker testing failed! Time %t ", $time) ;
4512
        $display("Bridge failed to process single memory read!") ;
4513
        test_fail("bridge didn't process single memory read correctly") ;
4514
        ok = 0 ;
4515
    end
4516
 
4517
    if ( perr_asserted && ok )
4518
    begin
4519
        test_ok ;
4520
    end
4521
    else
4522
    if ( ~perr_asserted )
4523
    begin
4524
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4525
        disable main ;
4526
    end
4527
 
4528
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4529
    // interrupt should also be present
4530
    `ifdef HOST
4531
        repeat(4)
4532 26 mihad
            @(posedge pci_clock) ;
4533
        repeat(4)
4534 15 mihad
            @(posedge wb_clock) ;
4535
 
4536
        if ( INT_O !== 1 )
4537
        begin
4538
            $display("Parity checker testing failed! Time %t ", $time) ;
4539
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4540
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4541
        end
4542
        else
4543
            test_ok ;
4544
    `else
4545
    `ifdef GUEST
4546 26 mihad
        repeat(4)
4547
            @(posedge wb_clock) ;
4548
        repeat(4)
4549 15 mihad
            @(posedge pci_clock) ;
4550
 
4551
        if ( INTA !== 1 )
4552
        begin
4553
            $display("Parity checker testing failed! Time %t ", $time) ;
4554
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4555
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4556
        end
4557
        else
4558
            test_ok ;
4559
    `endif
4560
    `endif
4561
 
4562
    // check statuses!
4563
 
4564
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4565
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4566
    ok = 1 ;
4567
 
4568
    if ( temp_val1[31] !== 1 )
4569
    begin
4570
        $display("Parity checker testing failed! Time %t ", $time) ;
4571 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4572
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4573 15 mihad
        ok = 0 ;
4574
    end
4575
 
4576
    if ( temp_val1[30] !== 0 )
4577
    begin
4578
        $display("Parity checker testing failed! Time %t ", $time) ;
4579
        $display("Signalled System Error bit was set for no reason!") ;
4580
        test_fail("Signalled System Error bit was set for no reason") ;
4581
        ok = 0 ;
4582
    end
4583
 
4584
    if ( temp_val1[24] !== 1 )
4585
    begin
4586
        $display("Parity checker testing failed! Time %t ", $time) ;
4587 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4588
        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") ;
4589 15 mihad
        ok = 0 ;
4590
    end
4591
 
4592
    if ( ok )
4593
        test_ok ;
4594
 
4595
    // clear statuses and disable parity error response
4596
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4597
 
4598
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4599
    ok = 1 ;
4600
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4601
 
4602
    if ( temp_val1[4] !== 0 )
4603
    begin
4604
        $display("Parity checker testing failed! Time %t ", $time) ;
4605
        $display("System error interrupt status bit set for no reason!") ;
4606
        test_fail("System error interrupt status bit set for no reason") ;
4607
        ok = 0 ;
4608
    end
4609
 
4610
    `ifdef HOST
4611
    if ( temp_val1[3] !== 1 )
4612
    begin
4613
        $display("Parity checker testing failed! Time %t ", $time) ;
4614
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4615
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4616
        ok = 0 ;
4617
    end
4618
    `else
4619
    if ( temp_val1[3] !== 0 )
4620
    begin
4621
        $display("Parity checker testing failed! Time %t ", $time) ;
4622
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4623
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4624
        ok = 0 ;
4625
    end
4626
    `endif
4627
 
4628
    if ( ok )
4629
        test_ok ;
4630
 
4631
    // clear int statuses
4632
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4633
 
4634
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4635
 
4636
    `ifdef HOST
4637
        repeat(4)
4638 26 mihad
            @(posedge pci_clock) ;
4639
        repeat(4)
4640 15 mihad
            @(posedge wb_clock) ;
4641
 
4642
        if ( INT_O !== 0 )
4643
        begin
4644
            $display("Parity checker testing failed! Time %t ", $time) ;
4645
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4646
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4647
        end
4648
        else
4649
            test_ok ;
4650
    `else
4651
    `ifdef GUEST
4652 26 mihad
        repeat(4)
4653
            @(posedge wb_clock) ;
4654
        repeat(4)
4655 15 mihad
            @(posedge pci_clock) ;
4656
 
4657
        if ( INTA !== 1 )
4658
        begin
4659
            $display("Parity checker testing failed! Time %t ", $time) ;
4660
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4661
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4662
        end
4663
        else
4664
            test_ok ;
4665
    `endif
4666
    `endif
4667
 
4668
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4669
 
4670
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4671
    fork
4672
    begin
4673
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4674
    end
4675
    begin:wait_perr5
4676
        perr_asserted = 0 ;
4677
        @(posedge pci_clock) ;
4678
        while ( PERR === 1 )
4679
            @(posedge pci_clock) ;
4680
 
4681
        perr_asserted = 1 ;
4682
        $display("Parity checker testing failed! Time %t ", $time) ;
4683 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4684
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4685 15 mihad
    end
4686
    begin
4687
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4688
        if ( ok !== 1 )
4689
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4690
 
4691
        // perr can be asserted on idle or next PCI address phase
4692
        repeat(2)
4693
            @(posedge pci_clock) ;
4694
 
4695 35 mihad
        #1 ;
4696
        if ( !perr_asserted )
4697
            disable wait_perr5 ;
4698 15 mihad
    end
4699
    join
4700
 
4701
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4702
    begin
4703
        $display("Parity checker testing failed! Time %t ", $time) ;
4704
        $display("Bridge failed to process single memory read!") ;
4705
        test_fail("bridge failed to process single memory read correctly") ;
4706
        ok = 0 ;
4707
    end
4708
 
4709
    if ( ok && !perr_asserted)
4710
        test_ok ;
4711
 
4712
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4713
 
4714
    // interrupts should not be present
4715
    `ifdef HOST
4716
        repeat( 4 )
4717 26 mihad
            @(posedge pci_clock) ;
4718
        repeat( 4 )
4719 15 mihad
            @(posedge wb_clock) ;
4720
        if ( INT_O !== 0 )
4721
        begin
4722
            $display("Parity checker testing failed! Time %t ", $time) ;
4723
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4724
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4725
        end
4726
        else
4727
            test_ok ;
4728
    `else
4729
    `ifdef GUEST
4730
        repeat( 4 )
4731 26 mihad
            @(posedge wb_clock) ;
4732
        repeat( 4 )
4733 15 mihad
            @(posedge pci_clock) ;
4734
        if ( INTA !== 1 )
4735
        begin
4736
            $display("Parity checker testing failed! Time %t ", $time) ;
4737
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4738
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4739
        end
4740
        else
4741
            test_ok ;
4742
    `endif
4743
    `endif
4744
 
4745
    // check statuses!
4746
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4747
    ok = 1 ;
4748
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4749
    if ( temp_val1[31] !== 1 )
4750
    begin
4751
        $display("Parity checker testing failed! Time %t ", $time) ;
4752 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4753 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4754
        ok = 0 ;
4755
    end
4756
 
4757
    if ( temp_val1[30] !== 0 )
4758
    begin
4759
        $display("Parity checker testing failed! Time %t ", $time) ;
4760
        $display("Signalled System Error bit was set for no reason!") ;
4761
        test_fail("Signalled System Error bit was set for no reason") ;
4762
        ok = 0 ;
4763
    end
4764
 
4765
    if ( temp_val1[24] !== 0 )
4766
    begin
4767
        $display("Parity checker testing failed! Time %t ", $time) ;
4768 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4769 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4770
        ok = 0 ;
4771
    end
4772
 
4773
    if ( ok )
4774
        test_ok ;
4775
 
4776
    // clear statuses
4777
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4778
 
4779
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4780
    ok = 1 ;
4781
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4782
 
4783
    if ( temp_val1[4] !== 0 )
4784
    begin
4785
        $display("Parity checker testing failed! Time %t ", $time) ;
4786
        $display("System error interrupt status bit set for no reason!") ;
4787
        test_fail("System error interrupt status bit set for no reason") ;
4788
        ok = 0 ;
4789
    end
4790
 
4791
    if ( temp_val1[3] !== 0 )
4792
    begin
4793
        $display("Parity checker testing failed! Time %t ", $time) ;
4794
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4795
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4796
        ok = 0 ;
4797
    end
4798
 
4799
    if ( ok )
4800
        test_ok ;
4801
 
4802
    // enable all responses to parity errors!
4803
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4804
 
4805
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4806
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4807
 
4808
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4809
 
4810
    // repeat a read
4811
    fork
4812
    begin
4813
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4814
    end
4815
    begin:wait_perr6
4816
        perr_asserted = 0 ;
4817
        @(posedge pci_clock) ;
4818
        while ( PERR === 1 )
4819
            @(posedge pci_clock) ;
4820
 
4821
        perr_asserted = 1 ;
4822
        $display("Parity checker testing failed! Time %t ", $time) ;
4823
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4824
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4825
    end
4826
    begin
4827
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4828
        if ( ok !== 1 )
4829
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4830
 
4831
        repeat(2)
4832
            @(posedge pci_clock) ;
4833
 
4834 35 mihad
        #1 ;
4835
        if ( !perr_asserted )
4836
            disable wait_perr6 ;
4837 15 mihad
    end
4838
    join
4839
 
4840
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4841
    begin
4842
        $display("Parity checker testing failed! Time %t ", $time) ;
4843
        $display("Bridge failed to process single memory read!") ;
4844
        test_fail("bridge didn't process single memory read as expected") ;
4845
        ok = 0 ;
4846
    end
4847
 
4848
    if ( ok && !perr_asserted)
4849
        test_ok ;
4850
 
4851
    // check statuses!
4852
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4853
    ok = 1 ;
4854
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4855
    if ( temp_val1[31] !== 0 )
4856
    begin
4857
        $display("Parity checker testing failed! Time %t ", $time) ;
4858
        $display("Detected Parity Error bit was set for no reason!") ;
4859
        test_fail("Detected Parity Error bit was set for no reason") ;
4860
        ok = 0 ;
4861
    end
4862
 
4863
    if ( temp_val1[30] !== 0 )
4864
    begin
4865
        $display("Parity checker testing failed! Time %t ", $time) ;
4866
        $display("Signalled System Error bit was set for no reason!") ;
4867
        test_fail("Signalled System Error bit was set for no reason") ;
4868
        ok = 0 ;
4869
    end
4870
 
4871
    if ( temp_val1[24] !== 0 )
4872
    begin
4873
        $display("Parity checker testing failed! Time %t ", $time) ;
4874
        $display("Master Data Parity Error bit was set for no reason!") ;
4875
        test_fail("Master Data Parity Error bit was set for no reason") ;
4876
        ok = 0 ;
4877
    end
4878
 
4879
    if ( ok )
4880
        test_ok ;
4881
 
4882
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4883
    ok = 1 ;
4884
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4885
 
4886
    if ( temp_val1[4] !== 0 )
4887
    begin
4888
        $display("Parity checker testing failed! Time %t ", $time) ;
4889
        $display("System error interrupt status bit set for no reason!") ;
4890
        test_fail("System error interrupt status bit set for no reason") ;
4891
        ok = 0 ;
4892
    end
4893
 
4894
    if ( temp_val1[3] !== 0 )
4895
    begin
4896
        $display("Parity checker testing failed! Time %t ", $time) ;
4897
        $display("Parity error interrupt status bit set for no reason!") ;
4898
        test_fail("Parity error interrupt status bit set for no reason") ;
4899
        ok = 0 ;
4900
    end
4901
 
4902
    if ( ok )
4903
        test_ok ;
4904
 
4905
    $display("Presenting address parity error on PCI bus!") ;
4906
    // enable parity errors - this should not affect system errors
4907
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4908
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4909
 
4910
    // perform PCI write
4911
    // check transaction progress
4912
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4913
    fork
4914
    begin
4915
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4916
               target_address, 32'h1234_5678,
4917
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4918
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4919
        do_pause( 1 ) ;
4920
    end
4921
    begin:wait_serr7
4922
        perr_asserted = 0 ;
4923
        @(posedge pci_clock) ;
4924
        while( SERR === 1 )
4925
            @(posedge pci_clock) ;
4926
 
4927
        perr_asserted = 1 ;
4928
        $display("Parity checker testing failed! Time %t ", $time) ;
4929
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4930
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4931
    end
4932
    begin
4933
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4934
        if ( ok !== 1 )
4935
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4936
 
4937 35 mihad
        if ( !perr_asserted )
4938
            disable wait_serr7 ;
4939 15 mihad
    end
4940
    join
4941
 
4942
    if ( ok && !perr_asserted)
4943
        test_ok ;
4944
 
4945
    // check statuses!
4946
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4947
    ok = 1 ;
4948
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4949
    if ( temp_val1[31] !== 1 )
4950
    begin
4951
        $display("Parity checker testing failed! Time %t ", $time) ;
4952
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4953
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4954
        ok = 0 ;
4955
    end
4956
 
4957
    if ( temp_val1[30] !== 0 )
4958
    begin
4959
        $display("Parity checker testing failed! Time %t ", $time) ;
4960
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4961
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4962
        ok = 0 ;
4963
    end
4964
 
4965
    if ( temp_val1[24] !== 0 )
4966
    begin
4967
        $display("Parity checker testing failed! Time %t ", $time) ;
4968
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4969
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4970
        ok = 0 ;
4971
    end
4972
 
4973
    if ( ok )
4974
        test_ok ;
4975
 
4976
    // clear statuses
4977
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4978
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4979
    fork
4980
    begin
4981 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
4982 15 mihad
        (
4983
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4984
            32'h5555_5555,      // second part of address in dual address cycle
4985
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4986
            `BC_MEM_WRITE,      // normal command
4987
            4'h0,               // byte enables
4988
            32'h1234_5678,      // data
4989
            1'b1,               // make address parity error on first phase of dual address
4990
            1'b0,               // make address parity error on second phase of dual address
4991
            ok                  // result of operation
4992
        ) ;
4993 35 mihad
        if ( !perr_asserted )
4994
            disable wait_serr8 ;
4995 15 mihad
    end
4996
    begin:wait_serr8
4997
        perr_asserted = 0 ;
4998
        @(posedge pci_clock) ;
4999
        while( SERR === 1 )
5000
            @(posedge pci_clock) ;
5001
 
5002
        perr_asserted = 1 ;
5003
        $display("Parity checker testing failed! Time %t ", $time) ;
5004
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5005
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5006
    end
5007
    join
5008
 
5009
    if ( ok && !perr_asserted)
5010
        test_ok ;
5011
 
5012
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5013
    fork
5014
    begin
5015 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5016 15 mihad
        (
5017
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5018
            32'h5555_5555,      // second part of address in dual address cycle
5019
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5020
            `BC_MEM_WRITE,      // normal command
5021
            4'h0,               // byte enables
5022
            32'h1234_5678,      // data
5023
            1'b0,               // make address parity error on first phase of dual address
5024
            1'b1,               // make address parity error on second phase of dual address
5025
            ok                  // result of operation
5026
        ) ;
5027 35 mihad
        if ( !perr_asserted )
5028
            disable wait_serr9 ;
5029 15 mihad
    end
5030
    begin:wait_serr9
5031
        perr_asserted = 0 ;
5032
        @(posedge pci_clock) ;
5033
        while( SERR === 1 )
5034
            @(posedge pci_clock) ;
5035
 
5036
        perr_asserted = 1 ;
5037
        $display("Parity checker testing failed! Time %t ", $time) ;
5038
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5039
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5040
    end
5041
    join
5042
 
5043
    if ( ok && !perr_asserted)
5044
        test_ok ;
5045
 
5046
    // check statuses!
5047
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5048
    ok = 1 ;
5049
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5050
    if ( temp_val1[31] !== 1 )
5051
    begin
5052
        $display("Parity checker testing failed! Time %t ", $time) ;
5053
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5054
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5055
        ok = 0 ;
5056
    end
5057
 
5058
    if ( temp_val1[30] !== 0 )
5059
    begin
5060
        $display("Parity checker testing failed! Time %t ", $time) ;
5061
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5062
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5063
        ok = 0 ;
5064
    end
5065
 
5066
    if ( temp_val1[24] !== 0 )
5067
    begin
5068
        $display("Parity checker testing failed! Time %t ", $time) ;
5069
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5070
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5071
        ok = 0 ;
5072
    end
5073
 
5074
    if ( ok )
5075
        test_ok ;
5076
 
5077
    // clear statuses
5078
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5079
 
5080
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5081
    fork
5082
    begin
5083 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5084 15 mihad
        (
5085
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5086
            32'h5555_5555,      // second part of address in dual address cycle
5087
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5088
            `BC_MEM_WRITE,      // normal command
5089
            4'h0,               // byte enables
5090
            32'h1234_5678,      // data
5091
            1'b1,               // make address parity error on first phase of dual address
5092
            1'b1,               // make address parity error on second phase of dual address
5093
            ok                  // result of operation
5094
        ) ;
5095 35 mihad
        if ( !perr_asserted )
5096
            disable wait_serr10 ;
5097 15 mihad
    end
5098
    begin:wait_serr10
5099
        perr_asserted = 0 ;
5100
        @(posedge pci_clock) ;
5101
        while( SERR === 1 )
5102
            @(posedge pci_clock) ;
5103
 
5104
        perr_asserted = 1 ;
5105
        $display("Parity checker testing failed! Time %t ", $time) ;
5106
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5107
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5108
    end
5109
    join
5110
 
5111
    if ( ok && !perr_asserted)
5112
        test_ok ;
5113
 
5114
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5115
 
5116
    `ifdef HOST
5117
        repeat(4)
5118 26 mihad
            @(posedge pci_clock) ;
5119
        repeat(4)
5120 15 mihad
            @(posedge wb_clock) ;
5121
        if ( INT_O !== 0 )
5122
        begin
5123
            $display("Parity checker testing failed! Time %t ", $time) ;
5124
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5125
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5126
        end
5127
        else
5128
            test_ok ;
5129
    `else
5130
    `ifdef GUEST
5131 26 mihad
        repeat(4)
5132
            @(posedge wb_clock) ;
5133
        repeat(4)
5134 15 mihad
            @(posedge pci_clock) ;
5135
 
5136
        if ( INTA !== 1 )
5137
        begin
5138
            $display("Parity checker testing failed! Time %t ", $time) ;
5139
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5140
            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") ;
5141
        end
5142
        else
5143
            test_ok ;
5144
    `endif
5145
    `endif
5146
 
5147
    // check statuses!
5148
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5149
    ok = 1 ;
5150
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5151
    if ( temp_val1[31] !== 1 )
5152
    begin
5153
        $display("Parity checker testing failed! Time %t ", $time) ;
5154
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5155
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5156
        ok = 0 ;
5157
    end
5158
 
5159
    if ( temp_val1[30] !== 0 )
5160
    begin
5161
        $display("Parity checker testing failed! Time %t ", $time) ;
5162
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5163
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5164
        ok = 0 ;
5165
    end
5166
 
5167
    if ( temp_val1[24] !== 0 )
5168
    begin
5169
        $display("Parity checker testing failed! Time %t ", $time) ;
5170
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5171
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5172
        ok = 0 ;
5173
    end
5174
 
5175
    if ( ok )
5176
        test_ok ;
5177
 
5178
    // clear statuses
5179
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5180
 
5181
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5182
    ok = 1 ;
5183
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5184
 
5185
    if ( temp_val1[4] !== 0 )
5186
    begin
5187
        $display("Parity checker testing failed! Time %t ", $time) ;
5188
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5189
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5190
        ok = 0 ;
5191
    end
5192
 
5193
    if ( temp_val1[3] !== 0 )
5194
    begin
5195
        $display("Parity checker testing failed! Time %t ", $time) ;
5196
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5197
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5198
        ok = 0 ;
5199
    end
5200
 
5201
    if ( ok )
5202
        test_ok ;
5203
 
5204
    // now enable system error signaling and test response
5205
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5206
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5207
 
5208
    fork
5209
    begin
5210
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5211
               target_address, 32'h1234_5678,
5212
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5213
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5214
        do_pause( 1 ) ;
5215
    end
5216
    begin:wait_serr11
5217
        perr_asserted = 0 ;
5218
        @(posedge pci_clock) ;
5219 35 mihad
        while( SERR !== 0 )
5220 15 mihad
            @(posedge pci_clock) ;
5221
 
5222 35 mihad
        perr_asserted = 1 ;
5223 15 mihad
    end
5224
    begin
5225
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5226
        if ( ok !== 1 )
5227
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5228
 
5229
        @(posedge pci_clock) ;
5230 35 mihad
        #1 ;
5231
        if ( !perr_asserted )
5232
            disable wait_serr11 ;
5233 15 mihad
    end
5234
    join
5235
 
5236
    if ( ok && perr_asserted)
5237
        test_ok ;
5238
    else
5239
    if ( !perr_asserted )
5240
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5241
 
5242
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5243
 
5244
    `ifdef HOST
5245
        repeat(4)
5246 26 mihad
            @(posedge pci_clock) ;
5247
        repeat(4)
5248 15 mihad
            @(posedge wb_clock) ;
5249
        if ( INT_O !== 1 )
5250
        begin
5251
            $display("Parity checker testing failed! Time %t ", $time) ;
5252
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5253
            test_fail("Interrupt Request was not triggered as expected") ;
5254
        end
5255
        else
5256
            test_ok ;
5257
    `else
5258
    `ifdef GUEST
5259 26 mihad
        repeat(4)
5260
            @(posedge wb_clock) ;
5261
        repeat(4)
5262 15 mihad
            @(posedge pci_clock) ;
5263
 
5264
        if ( INTA !== 1 )
5265
        begin
5266
            $display("Parity checker testing failed! Time %t ", $time) ;
5267
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5268
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5269
        end
5270
        else
5271
            test_ok ;
5272
    `endif
5273
    `endif
5274
 
5275
    // check statuses!
5276
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5277
    ok = 1 ;
5278
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5279
    if ( temp_val1[31] !== 1 )
5280
    begin
5281
        $display("Parity checker testing failed! Time %t ", $time) ;
5282
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5283
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5284
        ok = 0 ;
5285
    end
5286
 
5287
    if ( temp_val1[30] !== 1 )
5288
    begin
5289
        $display("Parity checker testing failed! Time %t ", $time) ;
5290
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5291
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5292
        ok = 0 ;
5293
    end
5294
 
5295
    if ( temp_val1[24] !== 0 )
5296
    begin
5297
        $display("Parity checker testing failed! Time %t ", $time) ;
5298
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5299
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5300
        ok = 0 ;
5301
    end
5302
 
5303
    if ( ok )
5304
        test_ok ;
5305
 
5306
    // clear statuses
5307
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5308
 
5309
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5310
 
5311
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5312
    ok = 1 ;
5313
 
5314
    `ifdef HOST
5315
    if ( temp_val1[4] !== 1 )
5316
    begin
5317
        $display("Parity checker testing failed! Time %t ", $time) ;
5318
        $display("System error interrupt status bit not set when expected!") ;
5319
        test_fail("System error interrupt status bit not set when expected") ;
5320
        ok = 0 ;
5321
    end
5322
    `else
5323
    if ( temp_val1[4] !== 0 )
5324
    begin
5325
        $display("Parity checker testing failed! Time %t ", $time) ;
5326
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5327
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5328
        ok = 0 ;
5329
    end
5330
    `endif
5331
 
5332
    if ( temp_val1[3] !== 0 )
5333
    begin
5334
        $display("Parity checker testing failed! Time %t ", $time) ;
5335
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5336
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5337
        ok = 0 ;
5338
    end
5339
 
5340
    if ( ok )
5341
        test_ok ;
5342
 
5343
    // clear statuses
5344
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5345
 
5346
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5347
    fork
5348
    begin
5349 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5350 15 mihad
        (
5351
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5352
            32'h5555_5555,      // second part of address in dual address cycle
5353
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5354
            `BC_MEM_WRITE,      // normal command
5355
            4'h0,               // byte enables
5356
            32'h1234_5678,      // data
5357
            1'b1,               // make address parity error on first phase of dual address
5358
            1'b0,               // make address parity error on second phase of dual address
5359
            ok                  // result of operation
5360
        ) ;
5361 35 mihad
        if ( !perr_asserted )
5362
            disable wait_serr14 ;
5363 15 mihad
    end
5364
    begin:wait_serr14
5365
        perr_asserted = 0 ;
5366
        @(posedge pci_clock) ;
5367 35 mihad
        while( SERR !== 0 )
5368 15 mihad
            @(posedge pci_clock) ;
5369
 
5370 35 mihad
        perr_asserted = 1 ;
5371 15 mihad
    end
5372
    join
5373
 
5374
    if ( ok && perr_asserted)
5375
        test_ok ;
5376
    else
5377
    if ( !perr_asserted )
5378
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5379
 
5380
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5381
 
5382
    `ifdef HOST
5383
        repeat(4)
5384 26 mihad
            @(posedge pci_clock) ;
5385
        repeat(4)
5386 15 mihad
            @(posedge wb_clock) ;
5387
        if ( INT_O !== 1 )
5388
        begin
5389
            $display("Parity checker testing failed! Time %t ", $time) ;
5390
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5391
            test_fail("Interrupt Request was not triggered as expected") ;
5392
        end
5393
        else
5394
            test_ok ;
5395
    `else
5396
    `ifdef GUEST
5397 26 mihad
        repeat(4)
5398
            @(posedge wb_clock) ;
5399
        repeat(4)
5400 15 mihad
            @(posedge pci_clock) ;
5401
 
5402
        if ( INTA !== 1 )
5403
        begin
5404
            $display("Parity checker testing failed! Time %t ", $time) ;
5405
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5406
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5407
        end
5408
        else
5409
            test_ok ;
5410
    `endif
5411
    `endif
5412
 
5413
    // check statuses!
5414
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5415
    ok = 1 ;
5416
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5417
    if ( temp_val1[31] !== 1 )
5418
    begin
5419
        $display("Parity checker testing failed! Time %t ", $time) ;
5420
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5421
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5422
        ok = 0 ;
5423
    end
5424
 
5425
    if ( temp_val1[30] !== 1 )
5426
    begin
5427
        $display("Parity checker testing failed! Time %t ", $time) ;
5428
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5429
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5430
        ok = 0 ;
5431
    end
5432
 
5433
    if ( temp_val1[24] !== 0 )
5434
    begin
5435
        $display("Parity checker testing failed! Time %t ", $time) ;
5436
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5437
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5438
        ok = 0 ;
5439
    end
5440
 
5441
    if ( ok )
5442
        test_ok ;
5443
 
5444
    // clear statuses
5445
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5446
 
5447
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5448
 
5449
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5450
    ok = 1 ;
5451
 
5452
    `ifdef HOST
5453
    if ( temp_val1[4] !== 1 )
5454
    begin
5455
        $display("Parity checker testing failed! Time %t ", $time) ;
5456
        $display("System error interrupt status bit not set when expected!") ;
5457
        test_fail("System error interrupt status bit not set when expected") ;
5458
        ok = 0 ;
5459
    end
5460
    `else
5461
    if ( temp_val1[4] !== 0 )
5462
    begin
5463
        $display("Parity checker testing failed! Time %t ", $time) ;
5464
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5465
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5466
        ok = 0 ;
5467
    end
5468
    `endif
5469
 
5470
    if ( temp_val1[3] !== 0 )
5471
    begin
5472
        $display("Parity checker testing failed! Time %t ", $time) ;
5473
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5474
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5475
        ok = 0 ;
5476
    end
5477
 
5478
    if ( ok )
5479
        test_ok ;
5480
 
5481
    // clear statuses
5482
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5483
 
5484
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5485
    fork
5486
    begin
5487 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5488 15 mihad
        (
5489
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5490
            32'h5555_5555,      // second part of address in dual address cycle
5491
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5492
            `BC_MEM_WRITE,      // normal command
5493
            4'h0,               // byte enables
5494
            32'h1234_5678,      // data
5495
            1'b0,               // make address parity error on first phase of dual address
5496
            1'b1,               // make address parity error on second phase of dual address
5497
            ok                  // result of operation
5498
        ) ;
5499 35 mihad
        if ( !perr_asserted )
5500
            disable wait_serr15 ;
5501 15 mihad
    end
5502
    begin:wait_serr15
5503
        perr_asserted = 0 ;
5504
        @(posedge pci_clock) ;
5505 35 mihad
        while( SERR !== 0 )
5506 15 mihad
            @(posedge pci_clock) ;
5507
 
5508 35 mihad
        perr_asserted = 1 ;
5509 15 mihad
    end
5510
    join
5511
 
5512
    if ( ok && perr_asserted)
5513
        test_ok ;
5514
    else
5515
    if ( !perr_asserted )
5516
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5517
 
5518
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5519
 
5520
    `ifdef HOST
5521
        repeat(4)
5522 26 mihad
            @(posedge pci_clock) ;
5523
        repeat(4)
5524 15 mihad
            @(posedge wb_clock) ;
5525
        if ( INT_O !== 1 )
5526
        begin
5527
            $display("Parity checker testing failed! Time %t ", $time) ;
5528
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5529
            test_fail("Interrupt Request was not triggered as expected") ;
5530
        end
5531
        else
5532
            test_ok ;
5533
    `else
5534
    `ifdef GUEST
5535 26 mihad
        repeat(4)
5536
            @(posedge wb_clock) ;
5537
        repeat(4)
5538 15 mihad
            @(posedge pci_clock) ;
5539
 
5540
        if ( INTA !== 1 )
5541
        begin
5542
            $display("Parity checker testing failed! Time %t ", $time) ;
5543
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5544
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5545
        end
5546
        else
5547
            test_ok ;
5548
    `endif
5549
    `endif
5550
 
5551
    // check statuses!
5552
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5553
    ok = 1 ;
5554
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5555
    if ( temp_val1[31] !== 1 )
5556
    begin
5557
        $display("Parity checker testing failed! Time %t ", $time) ;
5558
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5559
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5560
        ok = 0 ;
5561
    end
5562
 
5563
    if ( temp_val1[30] !== 1 )
5564
    begin
5565
        $display("Parity checker testing failed! Time %t ", $time) ;
5566
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5567
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5568
        ok = 0 ;
5569
    end
5570
 
5571
    if ( temp_val1[24] !== 0 )
5572
    begin
5573
        $display("Parity checker testing failed! Time %t ", $time) ;
5574
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5575
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5576
        ok = 0 ;
5577
    end
5578
 
5579
    if ( ok )
5580
        test_ok ;
5581
 
5582
    // clear statuses
5583
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5584
 
5585
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5586
 
5587
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5588
    ok = 1 ;
5589
 
5590
    `ifdef HOST
5591
    if ( temp_val1[4] !== 1 )
5592
    begin
5593
        $display("Parity checker testing failed! Time %t ", $time) ;
5594
        $display("System error interrupt status bit not set when expected!") ;
5595
        test_fail("System error interrupt status bit not set when expected") ;
5596
        ok = 0 ;
5597
    end
5598
    `else
5599
    if ( temp_val1[4] !== 0 )
5600
    begin
5601
        $display("Parity checker testing failed! Time %t ", $time) ;
5602
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5603
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5604
        ok = 0 ;
5605
    end
5606
    `endif
5607
 
5608
    if ( temp_val1[3] !== 0 )
5609
    begin
5610
        $display("Parity checker testing failed! Time %t ", $time) ;
5611
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5612
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5613
        ok = 0 ;
5614
    end
5615
 
5616
    if ( ok )
5617
        test_ok ;
5618
 
5619
    // clear statuses
5620
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5621
 
5622
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5623
    fork
5624
    begin
5625 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5626 15 mihad
        (
5627
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5628
            32'h5555_5555,      // second part of address in dual address cycle
5629
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5630
            `BC_MEM_WRITE,      // normal command
5631
            4'h0,               // byte enables
5632
            32'h1234_5678,      // data
5633
            1'b1,               // make address parity error on first phase of dual address
5634
            1'b1,               // make address parity error on second phase of dual address
5635
            ok                  // result of operation
5636
        ) ;
5637 35 mihad
        if ( !perr_asserted )
5638
            disable wait_serr16 ;
5639 15 mihad
    end
5640
    begin:wait_serr16
5641
        perr_asserted = 0 ;
5642
        @(posedge pci_clock) ;
5643 35 mihad
        while( SERR !== 0 )
5644 15 mihad
            @(posedge pci_clock) ;
5645
 
5646 35 mihad
        perr_asserted = 1 ;
5647 15 mihad
    end
5648
    join
5649
 
5650
    if ( ok && perr_asserted)
5651
        test_ok ;
5652
    else
5653
    if ( !perr_asserted )
5654
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5655
 
5656
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5657
 
5658
    `ifdef HOST
5659
        repeat(4)
5660 26 mihad
            @(posedge pci_clock) ;
5661
        repeat(4)
5662 15 mihad
            @(posedge wb_clock) ;
5663
        if ( INT_O !== 1 )
5664
        begin
5665
            $display("Parity checker testing failed! Time %t ", $time) ;
5666
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5667
            test_fail("Interrupt Request was not triggered as expected") ;
5668
        end
5669
        else
5670
            test_ok ;
5671
    `else
5672
    `ifdef GUEST
5673 26 mihad
        repeat(4)
5674
            @(posedge wb_clock) ;
5675
        repeat(4)
5676 15 mihad
            @(posedge pci_clock) ;
5677
 
5678
        if ( INTA !== 1 )
5679
        begin
5680
            $display("Parity checker testing failed! Time %t ", $time) ;
5681
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5682
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5683
        end
5684
        else
5685
            test_ok ;
5686
    `endif
5687
    `endif
5688
 
5689
    // check statuses!
5690
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5691
    ok = 1 ;
5692
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5693
    if ( temp_val1[31] !== 1 )
5694
    begin
5695
        $display("Parity checker testing failed! Time %t ", $time) ;
5696
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5697
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5698
        ok = 0 ;
5699
    end
5700
 
5701
    if ( temp_val1[30] !== 1 )
5702
    begin
5703
        $display("Parity checker testing failed! Time %t ", $time) ;
5704
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5705
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5706
        ok = 0 ;
5707
    end
5708
 
5709
    if ( temp_val1[24] !== 0 )
5710
    begin
5711
        $display("Parity checker testing failed! Time %t ", $time) ;
5712
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5713
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5714
        ok = 0 ;
5715
    end
5716
 
5717
    if ( ok )
5718
        test_ok ;
5719
 
5720
    // clear statuses
5721
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5722
 
5723
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5724
 
5725
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5726
    ok = 1 ;
5727
 
5728
    `ifdef HOST
5729
    if ( temp_val1[4] !== 1 )
5730
    begin
5731
        $display("Parity checker testing failed! Time %t ", $time) ;
5732
        $display("System error interrupt status bit not set when expected!") ;
5733
        test_fail("System error interrupt status bit not set when expected") ;
5734
        ok = 0 ;
5735
    end
5736
    `else
5737
    if ( temp_val1[4] !== 0 )
5738
    begin
5739
        $display("Parity checker testing failed! Time %t ", $time) ;
5740
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5741
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5742
        ok = 0 ;
5743
    end
5744
    `endif
5745
 
5746
    if ( temp_val1[3] !== 0 )
5747
    begin
5748
        $display("Parity checker testing failed! Time %t ", $time) ;
5749
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5750
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5751
        ok = 0 ;
5752
    end
5753
 
5754
    if ( ok )
5755
        test_ok ;
5756
 
5757
    // clear statuses
5758
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5759
 
5760
    // now just disable Parity Error response - on Address par errors nothing should happen
5761
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5762
 
5763
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5764
    fork
5765
    begin
5766
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5767
               target_address, 32'h1234_5678,
5768
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5769
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5770
        do_pause( 1 ) ;
5771
    end
5772
    begin:wait_serr12
5773
        perr_asserted = 0 ;
5774
        @(posedge pci_clock) ;
5775
        while( SERR === 1 )
5776
            @(posedge pci_clock) ;
5777
 
5778
        perr_asserted = 1 ;
5779
        $display("Parity checker testing failed! Time %t ", $time) ;
5780
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5781
        test_fail("SERR asserted when parity error response was disabled") ;
5782
    end
5783
    begin
5784
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5785
        if ( ok !== 1 )
5786
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5787
 
5788 35 mihad
        @(posedge pci_clock) ;
5789
        #1 ;
5790
        if ( !perr_asserted )
5791
            disable wait_serr12 ;
5792 15 mihad
    end
5793
    join
5794
 
5795
    if ( ok && !perr_asserted )
5796
        test_ok ;
5797
 
5798
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5799
    `ifdef HOST
5800 26 mihad
        repeat (4)
5801
            @(posedge pci_clock) ;
5802 15 mihad
        repeat(4)
5803
            @(posedge wb_clock) ;
5804
        if ( INT_O !== 0 )
5805
        begin
5806
            $display("Parity checker testing failed! Time %t ", $time) ;
5807
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5808
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5809
        end
5810
        else
5811
            test_ok ;
5812
    `else
5813
    `ifdef GUEST
5814 26 mihad
        repeat(4)
5815
            @(posedge wb_clock) ;
5816
        repeat (4)
5817 15 mihad
            @(posedge pci_clock) ;
5818
 
5819
        if ( INTA !== 1 )
5820
        begin
5821
            $display("Parity checker testing failed! Time %t ", $time) ;
5822
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5823
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5824
        end
5825
        else
5826
            test_ok ;
5827
    `endif
5828
    `endif
5829
 
5830
    // check statuses!
5831
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5832
    ok = 1 ;
5833
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5834
    if ( temp_val1[31] !== 1 )
5835
    begin
5836
        $display("Parity checker testing failed! Time %t ", $time) ;
5837
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5838
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5839
        ok = 0 ;
5840
    end
5841
 
5842
    if ( temp_val1[30] !== 0 )
5843
    begin
5844
        $display("Parity checker testing failed! Time %t ", $time) ;
5845
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5846
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5847
        ok = 0 ;
5848
    end
5849
 
5850
    if ( temp_val1[24] !== 0 )
5851
    begin
5852
        $display("Parity checker testing failed! Time %t ", $time) ;
5853
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5854
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5855
        ok = 0 ;
5856
    end
5857
 
5858
    if ( ok )
5859
        test_ok ;
5860
 
5861
    // clear statuses
5862
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5863
 
5864
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5865
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5866
    ok = 1 ;
5867
    if ( temp_val1[4] !== 0 )
5868
    begin
5869
        $display("Parity checker testing failed! Time %t ", $time) ;
5870
        $display("System error interrupt status bit set when not expected!") ;
5871
        test_fail("System error interrupt status bit set when not expected") ;
5872
        ok = 0 ;
5873
    end
5874
 
5875
    if ( temp_val1[3] !== 0 )
5876
    begin
5877
        $display("Parity checker testing failed! Time %t ", $time) ;
5878
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5879
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5880
        ok = 0 ;
5881
    end
5882
 
5883
    if ( ok )
5884
        test_ok ;
5885
 
5886
    // clear statuses
5887
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5888
 
5889
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5890
    fork
5891
    begin
5892 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5893 15 mihad
        (
5894
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5895
            32'h5555_5555,      // second part of address in dual address cycle
5896
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5897
            `BC_MEM_WRITE,      // normal command
5898
            4'h0,               // byte enables
5899
            32'h1234_5678,      // data
5900
            1'b1,               // make address parity error on first phase of dual address
5901
            1'b0,               // make address parity error on second phase of dual address
5902
            ok                  // result of operation
5903
        ) ;
5904 35 mihad
        if ( !perr_asserted )
5905
            disable wait_serr17 ;
5906 15 mihad
    end
5907
    begin:wait_serr17
5908
        perr_asserted = 0 ;
5909
        @(posedge pci_clock) ;
5910
        while( SERR === 1 )
5911
            @(posedge pci_clock) ;
5912
 
5913
        perr_asserted = 1 ;
5914
        $display("Parity checker testing failed! Time %t ", $time) ;
5915
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5916
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5917
    end
5918
    join
5919
 
5920
    if ( ok && !perr_asserted)
5921
        test_ok ;
5922
 
5923
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5924
    fork
5925
    begin
5926 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5927 15 mihad
        (
5928
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5929
            32'h5555_5555,      // second part of address in dual address cycle
5930
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5931
            `BC_MEM_WRITE,      // normal command
5932
            4'h0,               // byte enables
5933
            32'h1234_5678,      // data
5934
            1'b0,               // make address parity error on first phase of dual address
5935
            1'b1,               // make address parity error on second phase of dual address
5936
            ok                  // result of operation
5937
        ) ;
5938 35 mihad
        if ( !perr_asserted )
5939
            disable wait_serr18 ;
5940 15 mihad
    end
5941
    begin:wait_serr18
5942
        perr_asserted = 0 ;
5943
        @(posedge pci_clock) ;
5944
        while( SERR === 1 )
5945
            @(posedge pci_clock) ;
5946
 
5947
        perr_asserted = 1 ;
5948
        $display("Parity checker testing failed! Time %t ", $time) ;
5949
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5950
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5951
    end
5952
    join
5953
 
5954
    if ( ok && !perr_asserted)
5955
        test_ok ;
5956
 
5957
    // check statuses!
5958
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5959
    ok = 1 ;
5960
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5961
    if ( temp_val1[31] !== 1 )
5962
    begin
5963
        $display("Parity checker testing failed! Time %t ", $time) ;
5964
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5965
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5966
        ok = 0 ;
5967
    end
5968
 
5969
    if ( temp_val1[30] !== 0 )
5970
    begin
5971
        $display("Parity checker testing failed! Time %t ", $time) ;
5972
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5973
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5974
        ok = 0 ;
5975
    end
5976
 
5977
    if ( temp_val1[24] !== 0 )
5978
    begin
5979
        $display("Parity checker testing failed! Time %t ", $time) ;
5980
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5981
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5982
        ok = 0 ;
5983
    end
5984
 
5985
    if ( ok )
5986
        test_ok ;
5987
 
5988
    // clear statuses
5989
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5990
 
5991
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5992
    fork
5993
    begin
5994 73 mihad
        ipci_unsupported_commands_master.unsupported_reference
5995 15 mihad
        (
5996
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5997
            32'h5555_5555,      // second part of address in dual address cycle
5998
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5999
            `BC_MEM_WRITE,      // normal command
6000
            4'h0,               // byte enables
6001
            32'h1234_5678,      // data
6002
            1'b1,               // make address parity error on first phase of dual address
6003
            1'b1,               // make address parity error on second phase of dual address
6004
            ok                  // result of operation
6005
        ) ;
6006 35 mihad
        if ( !perr_asserted )
6007
            disable wait_serr19 ;
6008 15 mihad
    end
6009
    begin:wait_serr19
6010
        perr_asserted = 0 ;
6011
        @(posedge pci_clock) ;
6012
        while( SERR === 1 )
6013
            @(posedge pci_clock) ;
6014
 
6015
        perr_asserted = 1 ;
6016
        $display("Parity checker testing failed! Time %t ", $time) ;
6017
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
6018
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6019
    end
6020
    join
6021
 
6022
    if ( ok && !perr_asserted)
6023
        test_ok ;
6024
 
6025
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
6026
 
6027
    `ifdef HOST
6028
        repeat(4)
6029 26 mihad
            @(posedge pci_clock) ;
6030
        repeat(4)
6031 15 mihad
            @(posedge wb_clock) ;
6032
        if ( INT_O !== 0 )
6033
        begin
6034
            $display("Parity checker testing failed! Time %t ", $time) ;
6035
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
6036
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
6037
        end
6038
        else
6039
            test_ok ;
6040
    `else
6041
    `ifdef GUEST
6042 26 mihad
        repeat(4)
6043
            @(posedge wb_clock) ;
6044
        repeat(4)
6045 15 mihad
            @(posedge pci_clock) ;
6046
 
6047
        if ( INTA !== 1 )
6048
        begin
6049
            $display("Parity checker testing failed! Time %t ", $time) ;
6050
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
6051
            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") ;
6052
        end
6053
        else
6054
            test_ok ;
6055
    `endif
6056
    `endif
6057
 
6058
    // check statuses!
6059
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6060
    ok = 1 ;
6061
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6062
    if ( temp_val1[31] !== 1 )
6063
    begin
6064
        $display("Parity checker testing failed! Time %t ", $time) ;
6065
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6066
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6067
        ok = 0 ;
6068
    end
6069
 
6070
    if ( temp_val1[30] !== 0 )
6071
    begin
6072
        $display("Parity checker testing failed! Time %t ", $time) ;
6073
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6074
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6075
        ok = 0 ;
6076
    end
6077
 
6078
    if ( temp_val1[24] !== 0 )
6079
    begin
6080
        $display("Parity checker testing failed! Time %t ", $time) ;
6081
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6082
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6083
        ok = 0 ;
6084
    end
6085
 
6086
    if ( ok )
6087
        test_ok ;
6088
 
6089
    // clear statuses
6090
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6091
 
6092
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
6093
 
6094
    // do normal write
6095
    fork
6096
    begin
6097
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
6098
               target_address, 32'h1234_5678, `Test_All_Bytes,
6099
               1, 8'h3_0, `Test_One_Zero_Target_WS,
6100
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6101
        do_pause( 1 ) ;
6102
    end
6103
    begin:wait_serr13
6104
        perr_asserted = 0 ;
6105
        @(posedge pci_clock) ;
6106
        while( SERR === 1 )
6107
            @(posedge pci_clock) ;
6108
 
6109
        perr_asserted = 1 ;
6110
        $display("Parity checker testing failed! Time %t ", $time) ;
6111
        $display("SERR asserted for no reason!") ;
6112
        test_fail("SERR was asserted for no reason") ;
6113
    end
6114
    begin
6115
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6116
        if ( ok !== 1 )
6117
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6118
 
6119 35 mihad
        @(posedge pci_clock) ;
6120
        #1 ;
6121
        if ( !perr_asserted )
6122
            disable wait_serr13 ;
6123 15 mihad
    end
6124
    join
6125
 
6126
    if ( ok && !perr_asserted )
6127
        test_ok ;
6128
 
6129
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6130
    `ifdef HOST
6131 26 mihad
        repeat( 4 )
6132
            @(posedge pci_clock) ;
6133 15 mihad
        repeat(4)
6134
            @(posedge wb_clock) ;
6135
        if ( INT_O !== 0 )
6136
        begin
6137
            $display("Parity checker testing failed! Time %t ", $time) ;
6138
            $display("Interrupt request asserted for no reason!") ;
6139
            test_fail("Interrupt request was asserted for no reason") ;
6140
        end
6141
        else
6142
            test_ok ;
6143
    `else
6144
    `ifdef GUEST
6145 26 mihad
        repeat(4)
6146
            @(posedge wb_clock) ;
6147
        repeat(4)
6148 15 mihad
            @(posedge pci_clock) ;
6149
 
6150
        if ( INTA !== 1 )
6151
        begin
6152
            $display("Parity checker testing failed! Time %t ", $time) ;
6153
            $display("Interrupt request asserted for no reason!") ;
6154
            test_fail("Interrupt request was asserted for no reason") ;
6155
        end
6156
        else
6157
            test_ok ;
6158
    `endif
6159
    `endif
6160
 
6161
    // check statuses!
6162
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6163
    ok = 1 ;
6164
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6165
    if ( temp_val1[31] !== 0 )
6166
    begin
6167
        $display("Parity checker testing failed! Time %t ", $time) ;
6168
        $display("Detected Parity Error bit was set for no reason!") ;
6169
        test_fail("Detected Parity Error bit was set for no reason") ;
6170
        ok = 0 ;
6171
    end
6172
 
6173
    if ( temp_val1[30] !== 0 )
6174
    begin
6175
        $display("Parity checker testing failed! Time %t ", $time) ;
6176
        $display("Signalled System Error bit was set for no reason!") ;
6177
        test_fail("Signalled System Error bit was set for no reason") ;
6178
        ok = 0 ;
6179
    end
6180
 
6181
    if ( temp_val1[24] !== 0 )
6182
    begin
6183
        $display("Parity checker testing failed! Time %t ", $time) ;
6184
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6185
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6186
        ok = 0 ;
6187
    end
6188
 
6189
    if ( ok )
6190
        test_ok ;
6191
 
6192
    // clear statuses
6193
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6194
 
6195
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6196
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6197
    ok = 1 ;
6198
 
6199
    if ( temp_val1[4] !== 0 )
6200
    begin
6201
        $display("Parity checker testing failed! Time %t ", $time) ;
6202
        $display("System error interrupt status bit set when not expected!") ;
6203
        test_fail("System error interrupt status bit set when not expected") ;
6204
        ok = 0 ;
6205
    end
6206
 
6207
    if ( temp_val1[3] !== 0 )
6208
    begin
6209
        $display("Parity checker testing failed! Time %t ", $time) ;
6210
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6211
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6212
        ok = 0 ;
6213
    end
6214
 
6215
    if ( ok )
6216
        test_ok ;
6217
 
6218
    // clear statuses
6219
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6220
 
6221
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6222
 
6223
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6224
 
6225
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6226
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6227
 
6228
    // setup target's image!
6229
    target_address  = Target_Base_Addr_R[1] ;
6230
 
6231
    // base address
6232
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6233
 
6234
    // address mask
6235
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6236
 
6237
    // image control
6238
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6239
 
6240
    // enable everything possible for parity checking
6241
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6242
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6243
 
6244
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6245
 
6246
    fork
6247
    begin
6248
        if ( target_mem_image === 1 )
6249
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6250
                   target_address, 32'h1234_5678,
6251
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6252
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6253
        else
6254
            PCIU_IO_WRITE_MAKE_PERR (
6255
                                    `Test_Master_1,
6256
                                    target_address,
6257
                                    32'h1234_5678,
6258
                                    4'h0,
6259
                                    1,
6260
                                    `Test_Target_Normal_Completion
6261
                                    );
6262
 
6263
        do_pause( 1 ) ;
6264
    end
6265
    begin:wait_perr11
6266
        perr_asserted = 0 ;
6267
        @(posedge pci_clock) ;
6268 35 mihad
        while ( PERR !== 0 )
6269 15 mihad
            @(posedge pci_clock) ;
6270
 
6271 35 mihad
        perr_asserted = 1 ;
6272 15 mihad
 
6273
    end
6274
    begin
6275
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6276
 
6277
        if ( ok !== 1 )
6278
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6279
 
6280
        repeat(2)
6281
            @(posedge pci_clock) ;
6282
 
6283 35 mihad
        #1 ;
6284
        if ( !perr_asserted )
6285
            disable wait_perr11 ;
6286 15 mihad
    end
6287
    join
6288
 
6289
    if ( ok && perr_asserted )
6290
        test_ok ;
6291
    else
6292
    if ( !perr_asserted )
6293
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6294
 
6295
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6296
    `ifdef HOST
6297 26 mihad
        repeat (4)
6298
            @(posedge pci_clock) ;
6299 15 mihad
        repeat(4)
6300
            @(posedge wb_clock) ;
6301
        if ( INT_O !== 0 )
6302
        begin
6303
            $display("Parity checker testing failed! Time %t ", $time) ;
6304
            $display("Interrupt request asserted for no reason!") ;
6305
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6306
        end
6307
        else
6308
            test_ok ;
6309
    `else
6310
    `ifdef GUEST
6311 26 mihad
        repeat(4)
6312
            @(posedge wb_clock) ;
6313
        repeat (4)
6314 15 mihad
            @(posedge pci_clock) ;
6315
 
6316
        if ( INTA !== 1 )
6317
        begin
6318
            $display("Parity checker testing failed! Time %t ", $time) ;
6319
            $display("Interrupt request asserted for no reason!") ;
6320
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6321
        end
6322
        else
6323
            test_ok ;
6324
 
6325
    `endif
6326
    `endif
6327
 
6328
    // check statuses!
6329
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6330
    ok = 1 ;
6331
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6332
    if ( temp_val1[31] !== 1 )
6333
    begin
6334
        $display("Parity checker testing failed! Time %t ", $time) ;
6335 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6336
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6337 15 mihad
        ok = 0 ;
6338
    end
6339
 
6340
    if ( temp_val1[30] !== 0 )
6341
    begin
6342
        $display("Parity checker testing failed! Time %t ", $time) ;
6343
        $display("Signalled System Error bit was set for no reason!") ;
6344
        test_fail("Signalled System Error bit was set for no reason") ;
6345
        ok = 0 ;
6346
    end
6347
 
6348
    if ( temp_val1[24] !== 0 )
6349
    begin
6350
        $display("Parity checker testing failed! Time %t ", $time) ;
6351
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6352
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6353
        ok = 0 ;
6354
    end
6355
 
6356
    if ( ok )
6357
        test_ok ;
6358
 
6359
    // clear statuses
6360
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6361
 
6362
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6363
 
6364
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6365
    ok = 1 ;
6366
    if ( temp_val1[4] !== 0 )
6367
    begin
6368
        $display("Parity checker testing failed! Time %t ", $time) ;
6369
        $display("System error interrupt status bit set when not expected!") ;
6370
        test_fail("System error interrupt status bit set when not expected") ;
6371
        ok = 0 ;
6372
    end
6373
 
6374
    if ( temp_val1[3] !== 0 )
6375
    begin
6376
        $display("Parity checker testing failed! Time %t ", $time) ;
6377
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6378
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6379
        ok = 0 ;
6380
    end
6381
 
6382
    if ( ok )
6383
        test_ok ;
6384
 
6385
    // clear statuses
6386
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6387
 
6388
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6389
 
6390
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6391
    fork
6392
    begin
6393
        if ( target_mem_image === 1 )
6394
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6395
                          target_address, 32'h1234_5678,
6396
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6397
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6398
        else
6399
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6400
 
6401
        do_pause( 1 ) ;
6402
    end
6403
    begin:wait_perr12
6404
        perr_asserted = 0 ;
6405
        @(posedge pci_clock) ;
6406 35 mihad
        while ( PERR !== 0 )
6407 15 mihad
            @(posedge pci_clock) ;
6408
 
6409 35 mihad
        perr_asserted = 1 ;
6410 15 mihad
    end
6411
    begin
6412
 
6413
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6414
        if ( ok !== 1 )
6415
        begin
6416
            test_fail("Bridge failed to process Target Memory read correctly") ;
6417
            disable main ;
6418
        end
6419
 
6420
        repeat(3)
6421
            @(posedge pci_clock) ;
6422
 
6423
        if ( target_mem_image === 1 )
6424
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6425
                    target_address, 32'h1234_5678,
6426
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6427
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6428
        else
6429
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6430
 
6431
        do_pause( 1 ) ;
6432
 
6433
    end
6434
    begin
6435
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6436
        if ( ok !== 1 )
6437
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6438
        else
6439
        begin
6440
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6441
            if ( ok !== 1 )
6442
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6443
        end
6444
 
6445 35 mihad
        repeat(2)
6446 15 mihad
            @(posedge pci_clock) ;
6447
 
6448 35 mihad
        #1 ;
6449
        if ( !perr_asserted )
6450
            disable wait_perr12 ;
6451 15 mihad
    end
6452
    join
6453
 
6454
    if ( ok && perr_asserted )
6455
        test_ok ;
6456
    else
6457
    if ( !perr_asserted )
6458
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6459
 
6460
 
6461
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6462
    `ifdef HOST
6463
        repeat(4)
6464 26 mihad
            @(posedge pci_clock) ;
6465
        repeat(4)
6466 15 mihad
            @(posedge wb_clock) ;
6467
        if ( INT_O !== 0 )
6468
        begin
6469
            $display("Parity checker testing failed! Time %t ", $time) ;
6470
            $display("Interrupt request asserted for no reason!") ;
6471
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6472
        end
6473
        else
6474
            test_ok ;
6475
    `else
6476
    `ifdef GUEST
6477 26 mihad
        repeat(4)
6478
            @(posedge wb_clock) ;
6479
        repeat(4)
6480 15 mihad
            @(posedge pci_clock) ;
6481
 
6482
        if ( INTA !== 1 )
6483
        begin
6484
            $display("Parity checker testing failed! Time %t ", $time) ;
6485
            $display("Interrupt request asserted for no reason!") ;
6486
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6487
        end
6488
        else
6489
            test_ok ;
6490
    `endif
6491
    `endif
6492
 
6493
    // check statuses!
6494
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6495
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6496
    ok = 1 ;
6497 45 mihad
    if ( temp_val1[31] !== 0 )
6498 15 mihad
    begin
6499
        $display("Parity checker testing failed! Time %t ", $time) ;
6500 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6501
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6502 15 mihad
        ok = 0 ;
6503
    end
6504
 
6505
    if ( temp_val1[30] !== 0 )
6506
    begin
6507
        $display("Parity checker testing failed! Time %t ", $time) ;
6508
        $display("Signalled System Error bit was set for no reason!") ;
6509
        test_fail("Signalled System Error bit was set for no reason") ;
6510
        ok = 0 ;
6511
    end
6512
 
6513
    if ( temp_val1[24] !== 0 )
6514
    begin
6515
        $display("Parity checker testing failed! Time %t ", $time) ;
6516
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6517
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6518
        ok = 0 ;
6519
    end
6520
 
6521
    if ( ok )
6522
        test_ok ;
6523
 
6524
    // clear statuses
6525
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6526
 
6527
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6528
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6529
    ok = 1 ;
6530
    if ( temp_val1[4] !== 0 )
6531
    begin
6532
        $display("Parity checker testing failed! Time %t ", $time) ;
6533
        $display("System error interrupt status bit set when not expected!") ;
6534
        test_fail("System error interrupt status bit set when not expected") ;
6535
        ok = 0 ;
6536
    end
6537
 
6538
    if ( temp_val1[3] !== 0 )
6539
    begin
6540
        $display("Parity checker testing failed! Time %t ", $time) ;
6541
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6542
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6543
        ok = 0 ;
6544
    end
6545
 
6546
    if ( ok )
6547
        test_ok ;
6548
    // clear statuses
6549
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6550
 
6551
    $fdisplay(pci_mon_log_file_desc,
6552
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6553
    test_name = "DISABLE USED IMAGES" ;
6554
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6555
    if ( ok !== 1 )
6556
    begin
6557
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6558
        test_fail("WB Image Address Mask register could not be written to") ;
6559
        disable main ;
6560
    end
6561
 
6562 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6563 15 mihad
    if ( ok !== 1 )
6564
    begin
6565
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6566
        test_fail("PCI Image Address Mask register could not be written to") ;
6567
        disable main ;
6568
    end
6569
 
6570
    // disable target's 1 response to parity errors
6571 45 mihad
    configuration_cycle_write(0,                        // bus number
6572
                              `TAR1_IDSEL_INDEX - 11,   // device number
6573
                              0,                        // function number
6574
                              1,                        // register number
6575
                              0,                        // type of configuration cycle
6576
                              4'b0001,                  // byte enables
6577
                              32'h0000_0007             // data
6578 15 mihad
                             ) ;
6579
 
6580
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6581
end
6582
endtask // parity_checking
6583
 
6584
task wb_to_pci_transactions ;
6585
    reg   [11:0] ctrl_offset ;
6586
    reg   [11:0] ba_offset ;
6587
    reg   [11:0] am_offset ;
6588
    reg   [11:0] pci_ctrl_offset ;
6589
    reg   [11:0] err_cs_offset ;
6590
    reg   [11:0] icr_offset ;
6591
    reg   [11:0] isr_offset ;
6592
    reg   [11:0] lat_tim_cls_offset ;
6593
 
6594
    reg `WRITE_STIM_TYPE  write_data ;
6595
    reg `READ_STIM_TYPE   read_data ;
6596
    reg `READ_RETURN_TYPE read_status ;
6597
 
6598
    reg `WRITE_RETURN_TYPE write_status ;
6599
    reg `WB_TRANSFER_FLAGS write_flags ;
6600
    reg [31:0] temp_val1 ;
6601
    reg [31:0] temp_val2 ;
6602
    reg        ok   ;
6603
 
6604
    reg [31:0] image_base ;
6605
    reg [31:0] target_address ;
6606
    integer i ;
6607
    integer required_reads ;
6608
    integer writes_left ;
6609
 
6610
begin:main
6611
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6612
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6613
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6614
    pci_ctrl_offset    = 12'h4 ;
6615
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6616
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6617
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6618
    lat_tim_cls_offset = 12'hC ;
6619
 
6620
    $display("Checking WB to PCI transaction lengths!") ;
6621
    target_address  = `BEH_TAR1_MEM_START ;
6622
    image_base      = 0 ;
6623
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6624
 
6625
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6626
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6627
    write_flags                    = 0 ;
6628
    write_flags`INIT_WAITS         = tb_init_waits ;
6629
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6630
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6631
 
6632
    // enable master & target operation
6633
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6634
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6635
    if ( ok !== 1 )
6636
    begin
6637
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6638
        test_fail("write to PCI Device Control register failed") ;
6639
        disable main ;
6640
    end
6641
 
6642
    // prepare image control register
6643
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6644
    if ( ok !== 1 )
6645
    begin
6646
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6647
        test_fail("write to WB Image Control register failed") ;
6648
        disable main ;
6649
    end
6650
 
6651
    // prepare base address register
6652
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6653
    if ( ok !== 1 )
6654
    begin
6655
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6656
        test_fail("write to WB Base Address register failed") ;
6657
        disable main ;
6658
    end
6659
 
6660
    // write address mask register
6661
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6662
    if ( ok !== 1 )
6663
    begin
6664
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6665
        test_fail("write to WB Address Mask register failed") ;
6666
        disable main ;
6667
    end
6668
 
6669
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6670
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6671
    if ( ok !== 1 )
6672
    begin
6673
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6674
        test_fail("write to WB Error Control and Status register failed") ;
6675
        disable main ;
6676
    end
6677
 
6678
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6679
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6680
    if ( ok !== 1 )
6681
    begin
6682
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6683
        test_fail("write to Interrupt Control register failed") ;
6684
        disable main ;
6685
    end
6686
 
6687
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6688
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6689
    if ( ok !== 1 )
6690
    begin
6691
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6692
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6693
        disable main ;
6694
    end
6695
 
6696
    $display("Testing single write transaction progress from WB to PCI!") ;
6697
    write_data`WRITE_ADDRESS = target_address ;
6698
    write_data`WRITE_DATA    = wmem_data[0] ;
6699
    write_data`WRITE_SEL     = 4'hF ;
6700
 
6701
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6702
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6703
 
6704
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6705
    fork
6706
    begin
6707
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6708
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6709
        begin
6710
            $display("Transaction progress testing failed! Time %t ", $time) ;
6711
            $display("Bridge failed to process single memory write!") ;
6712
            test_fail("bridge failed to post single memory write") ;
6713
            disable main ;
6714
        end
6715
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6716
    end
6717
    begin
6718
        // wait two retries, then enable target response
6719
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6720
        if ( ok !== 1 )
6721
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6722
        else
6723
            test_ok ;
6724
 
6725
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6726
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6727
        if ( ok !== 1 )
6728
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6729
        else
6730
            test_ok ;
6731
 
6732
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6733
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6734
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6735
 
6736
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6737
        if ( ok !== 1 )
6738
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6739
        else
6740
            test_ok ;
6741
    end
6742
    join
6743
 
6744
    $display("Testing burst write transaction progress from WB to PCI!") ;
6745
    write_data`WRITE_ADDRESS = target_address ;
6746
    write_data`WRITE_DATA    = wmem_data[0] ;
6747
    write_data`WRITE_SEL     = 4'hF ;
6748
 
6749
    wishbone_master.blk_write_data[0] = write_data ;
6750
 
6751
    write_data`WRITE_ADDRESS = target_address + 4 ;
6752
    write_data`WRITE_DATA    = wmem_data[1] ;
6753
    write_data`WRITE_SEL     = 4'hF ;
6754
 
6755
    wishbone_master.blk_write_data[1] = write_data ;
6756
 
6757
    write_flags`WB_TRANSFER_SIZE = 2 ;
6758
    write_flags`WB_TRANSFER_CAB  = 1 ;
6759
 
6760
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6761
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6762
 
6763
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6764
 
6765
    fork
6766
    begin
6767
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6768
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6769
        begin
6770
            $display("Transaction progress testing failed! Time %t ", $time) ;
6771
            $display("Bridge failed to process whole CAB memory write!") ;
6772
            test_fail("bridge failed to post whole CAB memory write") ;
6773
            disable main ;
6774
        end
6775
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6776
    end
6777
    begin
6778
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6779
        if ( ok !== 1 )
6780
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6781
        else
6782
            test_ok ;
6783
 
6784
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6785
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6786
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6787
 
6788
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6789
        if ( ok !== 1 )
6790
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6791
        else
6792
            test_ok ;
6793
 
6794
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6795
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6796
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6797
 
6798
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6799
        if ( ok !== 1 )
6800
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6801
        else
6802
            test_ok ;
6803
    end
6804
    join
6805
 
6806
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6807
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6808
 
6809
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6810
    // try same write with other terminations
6811
    fork
6812
    begin
6813
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6814
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6815
        begin
6816
            $display("Transaction progress testing failed! Time %t ", $time) ;
6817
            $display("Bridge failed to process whole CAB memory write!") ;
6818
            test_fail("bridge failed to post whole CAB memory write") ;
6819
            disable main ;
6820
        end
6821
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6822
    end
6823
    begin
6824
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6825
        if ( ok !== 1 )
6826
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6827
        else
6828
            test_ok ;
6829
 
6830
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6831
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6832
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6833
 
6834
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6835
        if ( ok !== 1 )
6836
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6837
        else
6838
            test_ok ;
6839
    end
6840
    join
6841
 
6842
    // repeat the write with normal completion
6843
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6844
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6845
 
6846
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6847
    fork
6848
    begin
6849
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6850
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6851
        begin
6852
            $display("Transaction progress testing failed! Time %t ", $time) ;
6853
            $display("Bridge failed to process whole CAB memory write!") ;
6854
            test_fail("bridge failed to post whole CAB memory write") ;
6855
            disable main ;
6856
        end
6857
    end
6858
    begin
6859
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6860
        if ( ok !== 1 )
6861
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6862
        else
6863
            test_ok ;
6864
    end
6865
    join
6866
 
6867
    // do the same thing with burst length of 3
6868
    write_data`WRITE_ADDRESS = target_address + 8 ;
6869
    write_data`WRITE_DATA    = wmem_data[2] ;
6870
    write_data`WRITE_SEL     = 4'hF ;
6871
 
6872
    wishbone_master.blk_write_data[2] = write_data ;
6873
 
6874
    write_flags`WB_TRANSFER_SIZE = 3 ;
6875
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6876
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6877
 
6878
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6879
 
6880
    fork
6881
    begin
6882
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6883
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6884
        begin
6885
            $display("Transaction progress testing failed! Time %t ", $time) ;
6886
            $display("Bridge failed to process whole CAB memory write!") ;
6887
            test_fail("bridge failed to post whole CAB memory write") ;
6888
            disable main ;
6889
        end
6890
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6891
    end
6892
    begin
6893
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6894
        if ( ok !== 1 )
6895
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6896
        else
6897
            test_ok ;
6898
 
6899
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6900
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6901
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6902
 
6903
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6904
        if ( ok !== 1 )
6905
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6906
        else
6907
            test_ok ;
6908
    end
6909
    join
6910
 
6911
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6912
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6913
 
6914
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6915
    fork
6916
    begin
6917
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6918
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6919
        begin
6920
            $display("Transaction progress testing failed! Time %t ", $time) ;
6921
            $display("Bridge failed to process whole CAB memory write!") ;
6922
            test_fail("bridge failed to post whole CAB memory write") ;
6923
            disable main ;
6924
        end
6925
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6926
    end
6927
    begin
6928
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6929
        if ( ok !== 1 )
6930
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6931
        else
6932
            test_ok ;
6933
 
6934
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6935
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6936
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6937
 
6938
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6939
        if ( ok !== 1 )
6940
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6941
        else
6942
            test_ok ;
6943
 
6944
    end
6945
    join
6946
 
6947
    // repeat with normal completion
6948
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6949
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6950
 
6951
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6952
    fork
6953
    begin
6954
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6955
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6956
        begin
6957
            $display("Transaction progress testing failed! Time %t ", $time) ;
6958
            $display("Bridge failed to process whole CAB memory write!") ;
6959
            test_fail("bridge failed to post whole CAB memory write") ;
6960
            disable main ;
6961
        end
6962
    end
6963
    begin
6964
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6965
        if ( ok !== 1 )
6966
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6967
        else
6968
            test_ok ;
6969
 
6970
    end
6971
    join
6972
 
6973
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6974
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6975
    begin
6976
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6977
        write_data`WRITE_DATA    = wmem_data[i] ;
6978
        write_data`WRITE_SEL     = 4'hF ;
6979
 
6980
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6981
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6982
 
6983
        wishbone_master.blk_write_data[i]   = write_data ;
6984
        wishbone_master.blk_read_data_in[i] = read_data ;
6985
    end
6986
 
6987
    write_flags`WB_TRANSFER_CAB      = 1 ;
6988
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6989
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6990
 
6991
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6992
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6993
 
6994
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6995
    fork
6996
    begin
6997
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6998
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6999
        begin
7000
            $display("Transaction progress testing failed! Time %t ", $time) ;
7001
            $display("Bridge failed to process right number of databeats in CAB write!") ;
7002
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
7003
            test_fail("bridge failed to post whole CAB memory write") ;
7004
            disable main ;
7005
        end
7006
 
7007
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
7008
 
7009
        // read here just checks if data was transfered OK
7010
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7011
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
7012
 
7013
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7014
 
7015
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7016
        begin
7017
            $display("Transaction progress testing failed! Time %t ", $time) ;
7018
            $display("Bridge processed CAB read wrong!") ;
7019
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
7020
        end
7021
 
7022
    end
7023
    begin
7024
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7025
        if ( ok !== 1 )
7026
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7027
        else
7028
            test_ok ;
7029
 
7030
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
7031
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7032
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7033
 
7034
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7035
        if ( ok !== 1 )
7036
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7037
        else
7038
            test_ok ;
7039
 
7040
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
7041
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
7042
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7043
 
7044
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7045
        if ( ok !== 1 )
7046
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7047
        else
7048
            test_ok ;
7049
 
7050
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
7051
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7052
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7053
 
7054
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7055
        if ( ok !== 1 )
7056
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7057
        else
7058
            test_ok ;
7059
 
7060
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
7061
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7062
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7063
 
7064
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
7065
        if ( ok !== 1 )
7066
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7067
        else
7068
            test_ok ;
7069
 
7070
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
7071
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
7072
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
7073
        for ( i = 0 ; i < required_reads ; i = i + 1 )
7074
        begin
7075
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7076
            if ( ok !== 1 )
7077
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7078
        end
7079
    end
7080
    join
7081
 
7082
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
7083
    begin
7084
        read_status = wishbone_master.blk_read_data_out[i] ;
7085
        if (read_status`READ_DATA !== wmem_data[i])
7086
        begin
7087
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
7088
            test_fail("data read from target wasn't the same as data written to it") ;
7089
            ok = 0 ;
7090
        end
7091
    end
7092
 
7093
    if ( ok )
7094
        test_ok ;
7095
 
7096
    $display("Testing single read transaction progress from WB to PCI!") ;
7097
    read_data`READ_ADDRESS = target_address + 8 ;
7098
    read_data`READ_SEL     = 4'hF ;
7099
 
7100
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7101
 
7102
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
7103
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7104
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7105
 
7106
    fork
7107
    begin
7108
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7109
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7110
        begin
7111
            $display("Transaction progress testing failed! Time %t ", $time) ;
7112
            $display("Bridge processed single read wrong!") ;
7113
            test_fail("bridge processed single read wrong") ;
7114
            disable main ;
7115
        end
7116
 
7117
        if (read_status`READ_DATA !== wmem_data[2])
7118
        begin
7119
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7120
            test_fail("data returned from single read was not as expected") ;
7121
        end
7122
        else
7123
        if ( ok )
7124
            test_ok ;
7125
    end
7126
    begin
7127
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7128
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7129
 
7130
        if ( ok !== 1 )
7131
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7132
 
7133
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7134
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7135
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7136
 
7137
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7138
        if ( ok !== 1 )
7139
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7140
    end
7141
    join
7142
 
7143
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7144
 
7145
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7146
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7147
 
7148
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7149
    // first fill target's memory with enough data to fill WBR_FIFO
7150
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7151
    begin
7152
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7153
        write_data`WRITE_DATA    = wmem_data[i] ;
7154
        write_data`WRITE_SEL     = 4'hF ;
7155
 
7156
        wishbone_master.blk_write_data[i] = write_data ;
7157
    end
7158
 
7159
    write_flags`WB_TRANSFER_CAB = 1 ;
7160
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7161
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7162
 
7163
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7164
 
7165
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7166
    begin
7167
        $display("Transaction progress testing failed! Time %t ", $time) ;
7168
        $display("Bridge processed CAB write wrong!") ;
7169
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7170
        disable main ;
7171
    end
7172
 
7173
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7174
    // perform single read to force write data to pci
7175
    read_data`READ_ADDRESS = target_address + 8;
7176
    read_data`READ_SEL     = 4'hF ;
7177
 
7178
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7179
 
7180
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7181
    begin
7182
        $display("Transaction progress testing failed! Time %t ", $time) ;
7183
        $display("Bridge processed single read wrong!") ;
7184
        test_fail("bridge didn't process single memory read as expected") ;
7185
        disable main ;
7186
    end
7187
 
7188
    wishbone_master.blk_read_data_in[0] = read_data ;
7189
 
7190
    read_data`READ_ADDRESS = target_address + 12 ;
7191
    read_data`READ_SEL     = 4'hF ;
7192
 
7193
    wishbone_master.blk_read_data_in[1] = read_data ;
7194
 
7195
    read_data`READ_ADDRESS = target_address + 16 ;
7196
    read_data`READ_SEL     = 4'hF ;
7197
 
7198
    wishbone_master.blk_read_data_in[2] = read_data ;
7199
 
7200
    write_flags`WB_TRANSFER_CAB  = 1 ;
7201
    write_flags`WB_TRANSFER_SIZE = 2 ;
7202
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7203
    read_status = 0 ;
7204
 
7205
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7206
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7207
 
7208
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7209
 
7210
    ok = 1 ;
7211
    fork
7212
    begin
7213
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7214
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7215
 
7216
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7217
        begin
7218
            $display("Transaction progress testing failed! Time %t ", $time) ;
7219
            $display("Bridge processed CAB read wrong!") ;
7220
            test_fail("bridge didn't process disconnected burst read as expected") ;
7221
        end
7222
        else
7223
        begin
7224
 
7225
            read_status = wishbone_master.blk_read_data_out[0] ;
7226
 
7227
            if (read_status`READ_DATA !== wmem_data[2])
7228
            begin
7229
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7230
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7231
            end
7232
            else
7233
                test_ok ;
7234
        end
7235
 
7236
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7237
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7238
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7239
 
7240
        read_status = 0 ;
7241
 
7242
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7243
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7244
 
7245
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7246
        begin
7247
            $display("Transaction progress testing failed! Time %t ", $time) ;
7248
            $display("Bridge processed CAB read wrong!") ;
7249
            test_fail("bridge didn't process disconnected burst read as expected") ;
7250
        end
7251
        else
7252
        begin
7253
 
7254
            read_status = wishbone_master.blk_read_data_out[0] ;
7255
 
7256
            if (read_status`READ_DATA !== wmem_data[3])
7257
            begin
7258
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7259
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7260
            end
7261
            else
7262
                test_ok ;
7263
        end
7264
 
7265
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7266
        // complete delayed read which was requested
7267
        read_data = wishbone_master.blk_read_data_in[2] ;
7268
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7269
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7270
 
7271
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7272
        begin
7273
            $display("Transaction progress testing failed! Time %t ", $time) ;
7274
            $display("Bridge processed single out of burst read wrong!") ;
7275
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7276
        end
7277
        else
7278
        begin
7279
 
7280
            if (read_status`READ_DATA !== wmem_data[4])
7281
            begin
7282
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7283
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7284
            end
7285
            else
7286
                test_ok ;
7287
        end
7288
 
7289
    end
7290
    begin
7291
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7292
 
7293
        if ( ok !== 1 )
7294
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7295
 
7296
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7297
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7298
 
7299
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7300
        if ( ok !== 1 )
7301
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7302
 
7303
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7304
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7305
 
7306
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7307
        if ( ok !== 1 )
7308
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7309
    end
7310
    join
7311
 
7312
    // now try burst read with normal termination
7313
    read_data`READ_ADDRESS = target_address + 12 ;
7314
    read_data`READ_SEL     = 4'hF ;
7315
 
7316
    wishbone_master.blk_read_data_in[0] = read_data ;
7317
 
7318
    read_data`READ_ADDRESS = target_address + 16 ;
7319
    read_data`READ_SEL     = 4'hF ;
7320
 
7321
    wishbone_master.blk_read_data_in[1] = read_data ;
7322
 
7323
    write_flags`WB_TRANSFER_SIZE = 2 ;
7324
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7325
    write_flags`WB_TRANSFER_CAB = 1 ;
7326
 
7327
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7328
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7329
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7330
 
7331
    fork
7332
    begin
7333
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7334
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7335
        begin
7336
            $display("Transaction progress testing failed! Time %t ", $time) ;
7337
            $display("Bridge processed CAB read wrong!") ;
7338
            test_fail("bridge didn't process burst read as expected") ;
7339
            ok = 0 ;
7340
        end
7341
    end
7342
    begin
7343
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7344
        if ( ok !== 1 )
7345
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7346
    end
7347
    join
7348
 
7349
    if ( ok )
7350
    begin
7351
        read_status = wishbone_master.blk_read_data_out[0] ;
7352
        if ( read_status`READ_DATA !== wmem_data[3] )
7353
        begin
7354
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7355
            test_fail("data provided from normaly terminated read was wrong") ;
7356
            ok = 0 ;
7357
        end
7358
 
7359
        read_status = wishbone_master.blk_read_data_out[1] ;
7360
        if ( read_status`READ_DATA !== wmem_data[4] )
7361
        begin
7362
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7363
            test_fail("data provided from normaly terminated read was wrong") ;
7364
            ok = 0 ;
7365
        end
7366
    end
7367
 
7368
    if ( ok )
7369
        test_ok ;
7370
 
7371
    // disable memory read line command and enable prefetch
7372
    // prepare image control register
7373
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7374
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7375
    if ( ok !== 1 )
7376
    begin
7377
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7378
        test_fail("WB Image Control register couldn't be written to") ;
7379
        disable main ;
7380
    end
7381
 
7382
    write_flags`WB_TRANSFER_SIZE = 4 ;
7383
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7384
    write_flags`WB_TRANSFER_CAB = 1 ;
7385
 
7386
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7387
 
7388
    for ( i = 0 ; i < 4 ; i = i + 1 )
7389
    begin
7390
        read_data`READ_ADDRESS = target_address + i*4 ;
7391
        read_data`READ_SEL     = 4'b1010 ;
7392
 
7393
        wishbone_master.blk_read_data_in[i] = read_data ;
7394
    end
7395
 
7396
    fork
7397
    begin
7398
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7399
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7400
        begin
7401
            $display("Transaction progress testing failed! Time %t ", $time) ;
7402
            $display("Bridge processed CAB read wrong!") ;
7403
            test_fail("bridge didn't process prefetched burst read as expected") ;
7404
            ok = 0 ;
7405
        end
7406
    end
7407
    begin
7408
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7409
        if ( ok !== 1 )
7410
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7411
    end
7412
    join
7413
 
7414
    if ( ok )
7415
    begin
7416
        for ( i = 0 ; i < 4 ; i = i + 1 )
7417
        begin
7418
            read_status = wishbone_master.blk_read_data_out[i] ;
7419
            if ( read_status`READ_DATA !== wmem_data[i] )
7420
            begin
7421
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7422
                test_fail("burst read returned unexpected data") ;
7423
                ok = 0 ;
7424
            end
7425
        end
7426
    end
7427
 
7428
    if ( ok )
7429
        test_ok ;
7430
 
7431
    // do one single read with different byte enables
7432
    read_data`READ_ADDRESS = target_address + 4 ;
7433
    read_data`READ_SEL     = 4'b1010 ;
7434
 
7435
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7436
    fork
7437
    begin
7438
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7439
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7440
        begin
7441
            $display("Transaction progress testing failed! Time %t ", $time) ;
7442
            $display("Bridge processed single read wrong!") ;
7443
            test_fail("bridge didn't process single memory read as expected") ;
7444
            ok = 0 ;
7445
        end
7446
    end
7447
    begin
7448
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7449
        if ( ok !== 1 )
7450
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7451
    end
7452
    join
7453
 
7454
    // check read data
7455
    if ( ok )
7456
    begin
7457
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7458
        begin
7459
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7460
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7461
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7462
            ok = 0 ;
7463
            test_fail("unexpected data received from single read") ;
7464
        end
7465
    end
7466
 
7467
    if ( ok )
7468
         test_ok ;
7469
 
7470
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7471
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7472
 
7473
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7474
    if ( ok !== 1 )
7475
    begin
7476
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7477
        test_fail("WB Image Control register could not be written") ;
7478
        disable main ;
7479
    end
7480
 
7481
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7482
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7483
    begin
7484
        read_data`READ_ADDRESS = target_address + i*4 ;
7485
        read_data`READ_SEL     = 4'b1111 ;
7486
 
7487
        wishbone_master.blk_read_data_in[i] = read_data ;
7488
    end
7489
 
7490
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7491
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7492
    write_flags`WB_TRANSFER_CAB = 1 ;
7493
 
7494
    fork
7495
    begin
7496
        read_status         = 0 ;
7497
        read_status`CYC_RTY = 1 ;
7498
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7499
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7500
 
7501
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7502
        begin
7503
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7504
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7505
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7506
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7507
            ok = 0 ;
7508
        end
7509
    end
7510
    begin
7511
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7512
        if ( ok !== 1 )
7513
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7514
    end
7515
    join
7516
 
7517
    // now repeat single read to flush redundant read initiated
7518
    write_flags`WB_TRANSFER_SIZE = 1 ;
7519
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7520
    write_flags`WB_TRANSFER_CAB = 1 ;
7521
 
7522
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7523
    read_data`READ_SEL     = 4'hF ;
7524
 
7525
    wishbone_master.blk_read_data_in[0] = read_data ;
7526
 
7527
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7528
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7529
 
7530
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7531
    begin
7532
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7533
        $display(" PCI bridge failed to process single CAB read!") ;
7534
        test_fail("single CAB write was not processed as expected") ;
7535
    end
7536
 
7537
    // because last read could be very long on PCI - delete target abort status
7538
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7539
 
7540
    // write unsupported value to cache line size register
7541
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7542
 
7543
    read_data`READ_ADDRESS = target_address ;
7544
    read_data`READ_SEL     = 4'hF ;
7545
    wishbone_master.blk_read_data_in[0] = read_data ;
7546
 
7547
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7548
    // perform a read
7549
    fork
7550
    begin
7551
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7552
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7553
        begin
7554
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7555
            $display(" PCI bridge failed to process single CAB read!") ;
7556
            test_fail("burst read was not processed as expected") ;
7557
            ok = 0 ;
7558
        end
7559
    end
7560
    begin
7561
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7562
        if ( ok !== 1 )
7563
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7564
    end
7565
    join
7566
 
7567
    if ( ok )
7568
        test_ok ;
7569
 
7570
    // write 2 to cache line size register
7571
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7572
 
7573
    // perform a read
7574
    fork
7575
    begin
7576
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7577
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7578
        begin
7579
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7580
            $display(" PCI bridge failed to process single CAB read!") ;
7581
            test_fail("burst read was not processed as expected") ;
7582
            ok = 0 ;
7583
        end
7584
    end
7585
    begin
7586
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7587
        if ( ok !== 1 )
7588
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7589
    end
7590
    join
7591
 
7592
    if ( ok )
7593
        test_ok ;
7594
 
7595
    // write 0 to cache line size
7596
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7597
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7598
 
7599
    // perform a read
7600
    fork
7601
    begin
7602
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7603
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7604
        begin
7605
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7606
            $display(" PCI bridge failed to process single CAB read!") ;
7607
            test_fail("burst read was not processed as expected") ;
7608
            ok = 0 ;
7609
        end
7610
    end
7611
    begin
7612
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7613
        if ( ok !== 1 )
7614
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7615
    end
7616
    join
7617
 
7618
    if ( ok )
7619
        test_ok ;
7620
 
7621
    // write normal value to cls register
7622
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7623
 
7624
    $display("Testing Master's latency timer operation!") ;
7625
    $display("Testing Latency timer during Master Writes!") ;
7626
 
7627
    for ( i = 0 ; i < 6 ; i = i + 1 )
7628
    begin
7629
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7630
        write_data`WRITE_SEL     = 4'b1111 ;
7631
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7632
 
7633
        wishbone_master.blk_write_data[i] = write_data ;
7634
    end
7635
 
7636
    write_flags`WB_TRANSFER_SIZE = 6 ;
7637
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7638
    write_flags`WB_TRANSFER_CAB = 1 ;
7639
 
7640
    // start wb write, pci write and monitor in parallel
7641
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7642
    fork
7643
    begin
7644
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7645
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7646
        begin
7647
            $display("Transaction progress testing failed! Time %t ", $time) ;
7648
            $display("Bridge failed to process CAB write!") ;
7649
            test_fail("bridge didn't post whole burst memory write") ;
7650
            disable main ;
7651
        end
7652
    end
7653
    begin
7654
        // wait for bridge's master to start transaction
7655
        @(posedge pci_clock) ;
7656
        while ( FRAME === 1 )
7657
            @(posedge pci_clock) ;
7658
 
7659
        // start behavioral master request
7660
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7661
               target_address, wmem_data[1023], `Test_All_Bytes,
7662
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7663
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7664
 
7665
        do_pause ( 1 ) ;
7666
    end
7667
    begin
7668
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7669
        if ( ok !== 1 )
7670
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7671
        else
7672
            test_ok ;
7673
    end
7674
    join
7675
 
7676
    // perform a read to check data
7677
    for ( i = 0 ; i < 6 ; i = i + 1 )
7678
    begin
7679
        read_data`READ_ADDRESS = target_address + i*4 ;
7680
        read_data`READ_SEL     = 4'b1111 ;
7681
 
7682
        wishbone_master.blk_read_data_in[i] = read_data ;
7683
    end
7684
 
7685
    write_flags`WB_TRANSFER_SIZE = 6 ;
7686
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7687
    write_flags`WB_TRANSFER_CAB = 1 ;
7688
 
7689
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7690
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7691
 
7692
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7693
    begin
7694
        $display("Transaction progress testing failed! Time %t ", $time) ;
7695
        $display("Bridge failed to process CAB read!") ;
7696
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7697
        disable main ;
7698
    end
7699
 
7700
    ok = 1 ;
7701
    for ( i = 0 ; i < 6 ; i = i + 1 )
7702
    begin
7703
        read_status = wishbone_master.blk_read_data_out[i] ;
7704
 
7705
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7706
        begin
7707
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7708
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7709
            test_fail("unexpected data read back from PCI") ;
7710
            ok = 0 ;
7711
        end
7712
    end
7713
 
7714
    if ( ok )
7715
        test_ok ;
7716
 
7717
    $display("Testing Latency timer during Master Reads!") ;
7718
 
7719
    // at least 2 words are transfered during Master Reads terminated with timeout
7720
    write_flags`WB_TRANSFER_SIZE = 2 ;
7721
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7722
    fork
7723
    begin
7724
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7725
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7726
        begin
7727
            $display("Transaction progress testing failed! Time %t ", $time) ;
7728
            $display("Bridge failed to process CAB read!") ;
7729
            test_fail("bridge didn't process burst read as expected") ;
7730
            ok = 0 ;
7731
        end
7732
    end
7733
    begin
7734
        // wait for bridge's master to start transaction
7735
        @(posedge pci_clock) ;
7736
        while ( FRAME === 1 )
7737
            @(posedge pci_clock) ;
7738
 
7739
        // start behavioral master request
7740
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7741
               target_address, wmem_data[0], `Test_All_Bytes,
7742
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7743
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7744
 
7745
        do_pause ( 1 ) ;
7746
    end
7747
    begin
7748
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7749
        if ( ok !== 1 )
7750
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7751
    end
7752
    join
7753
 
7754
    // check data provided by target
7755
    if ( ok )
7756
    begin
7757
        for ( i = 0 ; i < 2 ; i = i + 1 )
7758
        begin
7759
            read_status = wishbone_master.blk_read_data_out[i] ;
7760
 
7761
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7762
            begin
7763
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7764
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7765
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7766
                ok = 0 ;
7767
            end
7768
        end
7769
    end
7770
    if ( ok )
7771
        test_ok ;
7772
 
7773
    test_name = "DISABLE_IMAGE" ;
7774
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7775
    if ( ok !== 1 )
7776
    begin
7777
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7778
        test_fail("write to WB Address Mask register failed") ;
7779
        disable main ;
7780
    end
7781
 
7782
end
7783
endtask //wb_to_pci_transactions
7784
 
7785
task iack_cycle ;
7786
    reg `READ_STIM_TYPE   read_data ;
7787
    reg `READ_RETURN_TYPE read_status ;
7788
    reg `WB_TRANSFER_FLAGS flags ;
7789
 
7790
    reg [31:0] temp_var ;
7791
    reg ok ;
7792 45 mihad
    reg ok_wb ;
7793
    reg ok_pci ;
7794
 
7795
    reg [31:0] irq_vector ;
7796 15 mihad
begin
7797
 
7798 45 mihad
    ok     = 1 ;
7799
    ok_wb  = 1 ;
7800
    ok_pci = 1 ;
7801
 
7802 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7803
 
7804
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7805
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7806
 
7807
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7808
    read_data`READ_SEL     = 4'hF ;
7809
 
7810
    flags = 0 ;
7811
 
7812
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7813
 
7814
    irq_vector  = 32'hAAAA_AAAA ;
7815
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7816
 
7817 45 mihad
    // disable both pci blue behavioral targets
7818
    configuration_cycle_write
7819
    (
7820
        0,                          // bus number [7:0]
7821
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7822
        0,                          // function number [2:0]
7823
        1,                          // register number [5:0]
7824
        0,                          // type [1:0]
7825
        4'h1,                       // byte enables [3:0]
7826
        32'h0000_0044               // data to write [31:0]
7827
    ) ;
7828
 
7829
    configuration_cycle_write
7830
    (
7831
        0,                          // bus number [7:0]
7832
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7833
        0,                          // function number [2:0]
7834
        1,                          // register number [5:0]
7835
        0,                          // type [1:0]
7836
        4'h1,                       // byte enables [3:0]
7837
        32'h0000_0044               // data to write [31:0]
7838
    ) ;
7839
 
7840 15 mihad
    fork
7841
    begin
7842
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7843
    end
7844
    begin
7845 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7846
        if ( ok_pci !== 1 )
7847 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7848
    end
7849
    join
7850
 
7851
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7852
    begin
7853 45 mihad
        ok_wb = 0 ;
7854 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7855
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7856
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7857
    end
7858 45 mihad
 
7859
    if ( ok_pci && ok_wb )
7860 15 mihad
        test_ok ;
7861 45 mihad
 
7862
    ok_wb = 1 ;
7863
    ok_pci = 1 ;
7864
    ok = 1 ;
7865 15 mihad
 
7866 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7867
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7868 15 mihad
 
7869
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7870 45 mihad
    // enable pci blue behavioral target 1
7871
    configuration_cycle_write
7872
    (
7873
        0,                          // bus number [7:0]
7874
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7875
        0,                          // function number [2:0]
7876
        1,                          // register number [5:0]
7877
        0,                          // type [1:0]
7878
        4'h1,                       // byte enables [3:0]
7879
        32'h0000_0047               // data to write [31:0]
7880
    ) ;
7881 15 mihad
    fork
7882
    begin
7883
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7884
    end
7885
    begin
7886 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7887
        if ( ok_pci !== 1 )
7888 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7889
    end
7890
    join
7891
 
7892
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7893
    begin
7894 45 mihad
        ok_wb = 0 ;
7895 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7896
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7897
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7898
    end
7899
 
7900
    if ( read_status`READ_DATA !== irq_vector )
7901
    begin
7902
        $display(" Time %t ", $time ) ;
7903
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7904
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7905 45 mihad
        ok_wb = 0 ;
7906 15 mihad
    end
7907
 
7908 45 mihad
    if ( ok_pci && ok_wb )
7909 15 mihad
        test_ok ;
7910
 
7911 45 mihad
    ok_pci = 1 ;
7912
    ok_wb  = 1 ;
7913
    ok     = 1 ;
7914
 
7915 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7916 45 mihad
    irq_vector  = 32'h5555_5555 ;
7917
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7918
 
7919 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7920
    fork
7921
    begin
7922
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7923
    end
7924
    begin
7925 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7926
        if ( ok_pci !== 1 )
7927 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7928
    end
7929
    join
7930
 
7931
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7932
    begin
7933
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7934
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7935
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7936 45 mihad
        ok_wb = 0 ;
7937 15 mihad
    end
7938
 
7939 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7940 15 mihad
    begin
7941
        $display(" Time %t ", $time ) ;
7942 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7943 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7944 45 mihad
        ok_wb = 0 ;
7945 15 mihad
    end
7946
 
7947 45 mihad
    if (ok_pci && ok_wb)
7948 15 mihad
        test_ok ;
7949
 
7950 45 mihad
    ok_pci = 1 ;
7951
    ok_wb  = 1 ;
7952
    ok     = 1 ;
7953 15 mihad
 
7954 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7955
 
7956
    // set target to terminate with target abort
7957
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7958
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7959
 
7960
    fork
7961
    begin
7962
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7963
    end
7964
    begin
7965
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7966
        if ( ok_pci !== 1 )
7967
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7968
    end
7969
    join
7970
 
7971
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7972
    begin
7973
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7974
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7975
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7976
        ok_wb = 0 ;
7977
    end
7978
 
7979
    // set target to terminate with target abort
7980
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7981
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7982
 
7983
    // enable pci blue behavioral target 2
7984
    configuration_cycle_write
7985
    (
7986
        0,                          // bus number [7:0]
7987
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7988
        0,                          // function number [2:0]
7989
        1,                          // register number [5:0]
7990
        0,                          // type [1:0]
7991
        4'h1,                       // byte enables [3:0]
7992
        32'h0000_0047               // data to write [31:0]
7993
    ) ;
7994
 
7995
    // read PCI Device status
7996
    config_read(12'h4, 4'hC, temp_var) ;
7997
    if (temp_var[29] !== 1)
7998
    begin
7999
        $display("Time %t", $time) ;
8000
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
8001
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
8002
        ok_wb = 0 ;
8003
    end
8004
 
8005
    if (temp_var[28] !== 1)
8006
    begin
8007
        $display("Time %t", $time) ;
8008
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
8009
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
8010
        ok_wb = 0 ;
8011
    end
8012
 
8013
    // clearing the status bits
8014
        config_write(12'h4, temp_var, 4'hC, ok);
8015
 
8016
    if ( ok && ok_pci && ok_wb )
8017
        test_ok ;
8018
 
8019 15 mihad
end
8020
endtask //iack_cycle
8021
 
8022
task transaction_ordering ;
8023
    reg   [11:0] wb_ctrl_offset ;
8024
    reg   [11:0] wb_ba_offset ;
8025
    reg   [11:0] wb_am_offset ;
8026
    reg   [11:0] pci_ctrl_offset ;
8027
    reg   [11:0] pci_ba_offset ;
8028
    reg   [11:0] pci_am_offset ;
8029
    reg   [11:0] pci_device_ctrl_offset ;
8030
    reg   [11:0] wb_err_cs_offset ;
8031
    reg   [11:0] pci_err_cs_offset ;
8032
    reg   [11:0] icr_offset ;
8033
    reg   [11:0] isr_offset ;
8034
    reg   [11:0] lat_tim_cls_offset ;
8035
 
8036
    reg `WRITE_STIM_TYPE  write_data ;
8037
    reg `READ_STIM_TYPE   read_data ;
8038
    reg `READ_RETURN_TYPE read_status ;
8039
 
8040
    reg `WRITE_RETURN_TYPE write_status ;
8041
    reg `WB_TRANSFER_FLAGS write_flags ;
8042
    reg [31:0] temp_val1 ;
8043
    reg [31:0] temp_val2 ;
8044
    reg        ok   ;
8045
 
8046
    reg [31:0] wb_image_base ;
8047
    reg [31:0] wb_target_address ;
8048
    reg [31:0] pci_image_base ;
8049
    integer i ;
8050
 
8051
    reg     error_monitor_done ;
8052
begin:main
8053
    write_flags`INIT_WAITS = tb_init_waits ;
8054
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
8055
 
8056
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
8057
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
8058
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
8059
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
8060
 
8061
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
8062
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
8063
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
8064
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
8065
 
8066
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
8067
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
8068
    lat_tim_cls_offset = 12'hC ;
8069
    pci_device_ctrl_offset    = 12'h4 ;
8070
 
8071
    wb_target_address  = `BEH_TAR1_MEM_START ;
8072
    wb_image_base      = 0 ;
8073
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
8074
 
8075
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
8076
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
8077
    write_flags                    = 0 ;
8078
    write_flags`INIT_WAITS         = 0 ;
8079
    write_flags`SUBSEQ_WAITS       = 0 ;
8080
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8081
 
8082
    pci_image_base = Target_Base_Addr_R[1] ;
8083
 
8084
    // enable master & target operation
8085
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
8086
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
8087
    if ( ok !== 1 )
8088
    begin
8089
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
8090
        test_fail("write to PCI Device Control register failed") ;
8091
        disable main ;
8092
    end
8093
 
8094
    // prepare image control register
8095
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8096
    if ( ok !== 1 )
8097
    begin
8098
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
8099
        test_fail("write to WB Image Control register failed") ;
8100
        disable main ;
8101
    end
8102
 
8103
    // prepare base address register
8104
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8105
    if ( ok !== 1 )
8106
    begin
8107
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8108
        test_fail("write to WB Base Address register failed") ;
8109
        disable main ;
8110
    end
8111
 
8112
    // write address mask register
8113
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8114
    if ( ok !== 1 )
8115
    begin
8116
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8117
        test_fail("write to WB Address Mask register failed") ;
8118
        disable main ;
8119
    end
8120
 
8121
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8122
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8123
    if ( ok !== 1 )
8124
    begin
8125
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8126
        test_fail("write to WB Error Control and Status register failed") ;
8127
        disable main ;
8128
    end
8129
 
8130
    // prepare image control register
8131
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8132
    if ( ok !== 1 )
8133
    begin
8134
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8135
        test_fail("write to PCI Image Control register failed") ;
8136
        disable main ;
8137
    end
8138
 
8139
    // prepare base address register
8140
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8141
    if ( ok !== 1 )
8142
    begin
8143
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8144
        test_fail("write to PCI Base Address register failed") ;
8145
        disable main ;
8146
    end
8147
 
8148
    // write address mask register
8149
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8150
    if ( ok !== 1 )
8151
    begin
8152
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8153
        test_fail("write to PCI Address Mask register failed") ;
8154
        disable main ;
8155
    end
8156
 
8157
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8158
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8159
    if ( ok !== 1 )
8160
    begin
8161
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8162
        test_fail("write to PCI Error Control and Status register failed") ;
8163
        disable main ;
8164
    end
8165
 
8166
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8167
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8168
    if ( ok !== 1 )
8169
    begin
8170
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8171
        test_fail("write to Interrupt Control register failed") ;
8172
        disable main ;
8173
    end
8174
 
8175
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8176
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8177
    if ( ok !== 1 )
8178
    begin
8179
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8180
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8181
        disable main ;
8182
    end
8183
 
8184
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8185
 
8186
    // prepare wb_master write and read data
8187
    for ( i = 0 ; i < 4 ; i = i + 1 )
8188
    begin
8189
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8190
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8191
        write_data`WRITE_SEL     = 4'hF ;
8192
 
8193
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8194
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8195
 
8196
        wishbone_master.blk_write_data[i]   = write_data ;
8197
        wishbone_master.blk_read_data_in[i] = read_data ;
8198
    end
8199
 
8200
    // put wishbone slave in acknowledge and pci target in retry mode
8201
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8202
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8203
 
8204
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8205
 
8206
    fork
8207
    begin
8208
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8209
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8210
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8211
        begin
8212
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8213
            test_fail("Bridge didn't post single memory write as expected") ;
8214
        end
8215
 
8216
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8217
        if ( ok !== 1 )
8218
        begin
8219
            $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) ;
8220
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8221
            ok = 0 ;
8222
        end
8223
 
8224
        // now post single write to target - normal progress
8225
        if ( target_mem_image == 1 )
8226
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8227
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8228
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8229
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8230
        else
8231
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8232
 
8233
        do_pause( 1 ) ;
8234
 
8235
    end
8236
    begin:error_monitor_1
8237 35 mihad
        error_monitor_done = 0 ;
8238 15 mihad
        @(error_event_int) ;
8239
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8240
        ok = 0 ;
8241 35 mihad
        error_monitor_done = 1 ;
8242 15 mihad
    end
8243
    begin
8244
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8245
        if ( ok !== 1 )
8246
        begin
8247
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8248
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8249
        end
8250
        else
8251
        begin
8252 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8253
//            while ( FRAME === 0 || IRDY === 0 )
8254
//                @(posedge pci_clock) ;
8255 15 mihad
 
8256
            // enable response in PCI target
8257
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8258
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8259
 
8260
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8261
            if ( ok !== 1 )
8262
            begin
8263
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8264
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8265
            end
8266
        end
8267
 
8268 35 mihad
        #1 ;
8269
        if ( !error_monitor_done )
8270
            disable error_monitor_1 ;
8271 15 mihad
    end
8272
    join
8273
 
8274
    if ( ok )
8275
        test_ok ;
8276
 
8277
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8278
 
8279
    // put WISHBONE slave in retry mode
8280
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8281
 
8282
    fork
8283
    begin
8284
        // now post single write to target - normal progress
8285
        if ( target_mem_image == 1 )
8286
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8287
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8288
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8289
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8290
        else
8291
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8292
 
8293
        do_pause( 1 ) ;
8294
 
8295
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8296
        if ( ok !== 1 )
8297
        begin
8298
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8299
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8300
        end
8301
 
8302
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8303
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8304
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8305
        begin
8306
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8307
            test_fail("Bridge didn't post single memory write as expected") ;
8308
        end
8309
 
8310
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8311
        if ( ok !== 1 )
8312
        begin
8313
            $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) ;
8314
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8315
            ok = 0 ;
8316
        end
8317
 
8318
        wait ( CYC_O === 0 ) ;
8319
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8320
 
8321
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8322
        if ( ok !== 1 )
8323
        begin
8324
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8325
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8326
        end
8327
 
8328 35 mihad
        #1 ;
8329
        if ( !error_monitor_done )
8330
            disable error_monitor_2 ;
8331 15 mihad
    end
8332
    begin:error_monitor_2
8333 35 mihad
        error_monitor_done = 0 ;
8334 15 mihad
        @(error_event_int) ;
8335
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8336
        ok = 0 ;
8337 35 mihad
        error_monitor_done = 1 ;
8338 15 mihad
    end
8339
    join
8340
 
8341
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8342
 
8343
    // put wishbone slave in acknowledge and pci target in retry mode
8344
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8345
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8346
 
8347
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8348
 
8349
    fork
8350
    begin
8351
        write_flags`WB_TRANSFER_SIZE = 3 ;
8352
        write_flags`WB_TRANSFER_CAB  = 1 ;
8353
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8354
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8355
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8356
        begin
8357
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8358
            test_fail("Bridge didn't post burst memory write as expected") ;
8359
        end
8360
 
8361
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8362
        if ( ok !== 1 )
8363
        begin
8364
            $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) ;
8365
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8366
            ok = 0 ;
8367
        end
8368
 
8369
        // now post single write to target - normal progress
8370
        if ( target_mem_image == 1 )
8371
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8372
                        pci_image_base, 32'h5555_5555, 4'h0,
8373
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8374
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8375
        else
8376
        begin
8377
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8378
            do_pause( 1 ) ;
8379
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8380
        end
8381
 
8382
        do_pause( 1 ) ;
8383
 
8384
    end
8385
    begin:error_monitor_3
8386 35 mihad
        error_monitor_done = 0 ;
8387 15 mihad
        @(error_event_int) ;
8388
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8389
        ok = 0 ;
8390 35 mihad
        error_monitor_done = 1 ;
8391 15 mihad
    end
8392
    begin
8393
        if ( target_mem_image == 1 )
8394
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8395
        else
8396
        begin
8397
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8398
            if ( ok )
8399
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8400
        end
8401
 
8402
        if ( ok !== 1 )
8403
        begin
8404
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8405
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8406
        end
8407
        else
8408
        begin
8409 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8410
//            while ( FRAME === 0 || IRDY === 0 )
8411
//                @(posedge pci_clock) ;
8412 15 mihad
 
8413
            // enable response in PCI target
8414
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8415
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8416
 
8417
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8418
            if ( ok !== 1 )
8419
            begin
8420
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8421
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8422
            end
8423
        end
8424
 
8425 35 mihad
        #1 ;
8426
        if ( !error_monitor_done )
8427
            disable error_monitor_3 ;
8428 15 mihad
    end
8429
    join
8430
 
8431
    if ( ok )
8432
        test_ok ;
8433
 
8434
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8435
 
8436
    // put WISHBONE slave in retry mode
8437
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8438
 
8439
    fork
8440
    begin
8441
        // now post single write to target - normal progress
8442
        if ( target_mem_image == 1 )
8443
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8444
                        pci_image_base, 32'h5555_5555, 4'h0,
8445
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8446
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8447
        else
8448
        begin
8449
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8450
            do_pause( 1 ) ;
8451
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8452
        end
8453
 
8454
        do_pause( 1 ) ;
8455
 
8456
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8457
 
8458
        if ( ok !== 1 )
8459
        begin
8460
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8461
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8462
        end
8463
 
8464
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8465
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8466
        write_flags`WB_TRANSFER_CAB      = 1 ;
8467
 
8468
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8469
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8470
        begin
8471
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8472
            test_fail("Bridge didn't post burst memory write as expected") ;
8473
        end
8474
 
8475
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8476
        if ( ok !== 1 )
8477
        begin
8478
            $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) ;
8479
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8480
            ok = 0 ;
8481
        end
8482
 
8483
        @(posedge wb_clock) ;
8484
        while ( CYC_O === 1 )
8485
            @(posedge wb_clock) ;
8486
 
8487
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8488
 
8489
        if ( target_mem_image == 1 )
8490
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8491
        else
8492
        begin
8493
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8494
            if ( ok )
8495
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8496
        end
8497
 
8498 35 mihad
        #1 ;
8499
        if ( !error_monitor_done )
8500
            disable error_monitor_4 ;
8501 15 mihad
    end
8502
    begin:error_monitor_4
8503 35 mihad
        error_monitor_done = 0 ;
8504 15 mihad
        @(error_event_int) ;
8505
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8506
        ok = 0 ;
8507 35 mihad
        error_monitor_done = 1 ;
8508 15 mihad
    end
8509
    join
8510
 
8511
    if ( ok )
8512
        test_ok ;
8513
 
8514
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8515
 
8516
    // put wishbone slave in acknowledge and pci target in retry mode
8517
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8518
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8519
 
8520
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8521
 
8522
    master1_check_received_data = 1 ;
8523
 
8524
    error_monitor_done = 0 ;
8525
    fork
8526
    begin:error_monitor_5
8527
        @(error_event_int or error_monitor_done) ;
8528
        if ( !error_monitor_done )
8529
        begin
8530
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8531
            ok = 0 ;
8532
        end
8533
    end
8534
    begin
8535
 
8536
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8537
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8538
        begin
8539
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8540
            test_fail("Bridge didn't post single memory write as expected") ;
8541
        end
8542
 
8543
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8544
        if ( ok !== 1 )
8545
        begin
8546
            $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) ;
8547
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8548
            ok = 0 ;
8549
        end
8550
 
8551
        // start Read Through pci target
8552
        if ( target_mem_image == 1 )
8553
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8554
                          pci_image_base, 32'h5555_5555,
8555
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8556
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8557
        else
8558
            PCIU_IO_READ
8559
             (
8560
                `Test_Master_1,
8561
                pci_image_base,
8562
                32'h5555_5555,
8563
                4'h0,
8564
                1,
8565
                `Test_Target_Retry_On
8566
             );
8567
 
8568
         do_pause( 1 ) ;
8569
 
8570
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8571
         if ( ok !== 1 )
8572
         begin
8573
            $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) ;
8574
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8575
         end
8576
 
8577
         // repeat the read 4 times - it should be retried all the time by pci target
8578
        for ( i = 0 ; i < 4 ; i = i + 1 )
8579
        begin
8580
            if ( target_mem_image == 1 )
8581
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8582
                            pci_image_base, 32'h5555_5555,
8583
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8584
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8585
            else
8586
                PCIU_IO_READ
8587
                (
8588
                    `Test_Master_1,
8589
                    pci_image_base,
8590
                    32'h5555_5555,
8591
                    4'h0,
8592
                    1,
8593
                    `Test_Target_Retry_On
8594
                );
8595
 
8596
            do_pause( 1 ) ;
8597
        end
8598
 
8599
        // now do posted write through target - it must go through OK
8600
        if ( target_mem_image == 1 )
8601
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8602
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8603
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8604
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8605
        else
8606
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8607
 
8608
        do_pause( 1 ) ;
8609
 
8610
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8611
        if ( ok !== 1 )
8612
        begin
8613
           $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) ;
8614
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8615
        end
8616
 
8617
        // start a read through wb_slave
8618
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8619
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8620
        begin
8621
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8622
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8623
            ok = 0 ;
8624
        end
8625
 
8626 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8627
//        while ( FRAME === 0 || IRDY === 0 )
8628
//            @(posedge pci_clock) ;
8629 15 mihad
 
8630
        // set the target to normal completion
8631
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8632
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8633
 
8634
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8635
        if ( ok !== 1 )
8636
        begin
8637
            $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) ;
8638
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8639
            ok = 0 ;
8640
        end
8641
 
8642
        // now wait for delayed read to finish
8643
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8644
        if ( ok !== 1 )
8645
        begin
8646
            $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) ;
8647
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8648
            ok = 0 ;
8649
        end
8650
 
8651
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8652
        fork
8653
        begin
8654
                if ( target_mem_image == 1 )
8655
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8656
                                pci_image_base, 32'h5555_5555, 4'h0,
8657
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8658
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8659
                else
8660
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8661
 
8662
                do_pause( 1 ) ;
8663
                end
8664
                begin
8665 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 ) ;
8666 15 mihad
                end
8667
                join
8668
 
8669
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8670
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8671
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8672
        begin
8673
            $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) ;
8674
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8675
            ok = 0 ;
8676
        end
8677
 
8678
        fork
8679
        begin
8680
        // now complete a read from PCI Target
8681
            if ( target_mem_image == 1 )
8682
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8683
                            pci_image_base, 32'h5555_5555,
8684
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8685
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8686
            else
8687
                PCIU_IO_READ
8688
                (
8689
                    `Test_Master_1,
8690
                    pci_image_base,
8691
                    32'h5555_5555,
8692
                    4'h0,
8693
                    1,
8694
                    `Test_Target_Normal_Completion
8695
                );
8696
 
8697
            do_pause( 1 ) ;
8698
        end
8699
        begin
8700
            if ( target_mem_image == 1 )
8701
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8702
            else
8703
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8704
        end
8705
        join
8706
 
8707
        @(posedge pci_clock) ;
8708
        repeat( 4 )
8709
            @(posedge wb_clock) ;
8710
 
8711
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8712
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8713
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8714
        begin
8715
            $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) ;
8716
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8717
            ok = 0 ;
8718
        end
8719
 
8720
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8721
        if ( ok !== 1 )
8722
        begin
8723
            $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) ;
8724
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8725
            ok = 0 ;
8726
        end
8727
 
8728
        // finish a read on WISHBONE also
8729
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8730
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8731
        begin
8732
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8733
            test_fail("WB Slave didn't process single delayed read as expected") ;
8734
        end
8735
 
8736
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8737
        begin
8738
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8739
            ok = 0 ;
8740
        end
8741
 
8742
 
8743
        error_monitor_done = 1 ;
8744
    end
8745
    join
8746
 
8747
    if ( ok )
8748
        test_ok ;
8749
 
8750
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8751
 
8752
    // put wishbone slave in retry and pci target in completion mode
8753
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8754
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8755
 
8756
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8757
 
8758
    master1_check_received_data = 1 ;
8759
 
8760
    error_monitor_done = 0 ;
8761
    fork
8762
    begin:error_monitor_6
8763
        @(error_event_int or error_monitor_done) ;
8764
        if ( !error_monitor_done )
8765
        begin
8766
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8767
            ok = 0 ;
8768
        end
8769
    end
8770
    begin
8771
 
8772
        // do a write through Target
8773
        fork
8774
        begin
8775
            if ( target_mem_image == 1 )
8776
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8777
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8778
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8779
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8780
            else
8781
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8782
 
8783
            do_pause( 1 ) ;
8784
        end
8785
        begin
8786
            if ( target_mem_image == 1 )
8787
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8788
            else
8789
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8790
        end
8791
        join
8792
 
8793
        // start a read through WB slave
8794
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8795
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8796
        begin
8797
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8798
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8799
            ok = 0 ;
8800
        end
8801
 
8802
        // now wait for this read to finish on pci
8803
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8804
        if ( ok !== 1 )
8805
        begin
8806
            $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) ;
8807
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8808
            ok = 0 ;
8809
        end
8810
 
8811
        // repeat the read four times - it should be retried
8812
        for ( i = 0 ; i < 4 ; i = i + 1 )
8813
        begin
8814
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8815
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8816
            begin
8817
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8818
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8819
                ok = 0 ;
8820
            end
8821
        end
8822
 
8823
        // posted write through WB Slave - must go through
8824
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8825
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8826
        begin
8827
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8828
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8829
            ok = 0 ;
8830
        end
8831
 
8832
        // write must come through
8833
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8834
        if ( ok !== 1 )
8835
        begin
8836
            $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) ;
8837
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8838
            ok = 0 ;
8839
        end
8840
 
8841
        // do a read through pci target
8842
        if ( target_mem_image == 1 )
8843
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8844
                          pci_image_base + 12, 32'hDEAD_BEAF,
8845
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8846
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8847
        else
8848
            PCIU_IO_READ
8849
             (
8850
                `Test_Master_1,
8851
                pci_image_base + 12,
8852
                32'hDEAD_BEAF,
8853
                4'h0,
8854
                1,
8855
                `Test_Target_Retry_On
8856
             );
8857
 
8858
         do_pause( 1 ) ;
8859
 
8860
        // wait for current cycle to finish on WB
8861 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8862
//        @(posedge wb_clock) ;
8863
//        while( CYC_O === 1 )
8864
//            @(posedge wb_clock) ;
8865 15 mihad
 
8866
        // set slave response to acknowledge
8867
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8868
 
8869
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8870
        if ( ok !== 1 )
8871
        begin
8872
            $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) ;
8873
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8874
        end
8875
 
8876
        // check the read to finish on wb
8877
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8878
        if ( ok !== 1 )
8879
        begin
8880
            $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) ;
8881
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8882
        end
8883
 
8884
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8885
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8886
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8887
        begin
8888
            $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) ;
8889
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8890
            ok = 0 ;
8891
        end
8892
 
8893
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8894
        fork
8895
        begin
8896
            if ( target_mem_image == 1 )
8897
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8898
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8899
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8900
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8901
            else
8902
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8903
        end
8904
        begin
8905
            if ( target_mem_image == 1 )
8906
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8907
            else
8908
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8909
        end
8910
        join
8911
 
8912
        do_pause( 1 ) ;
8913
 
8914
        // complete a read in WB Slave Unit
8915
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8916
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8917
        begin
8918
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8919
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8920
            ok = 0 ;
8921
        end
8922
 
8923
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8924
        begin
8925
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8926
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8927
            ok = 0 ;
8928
        end
8929
 
8930
        // wait for statuses to be propagated from one side of bridge to another
8931
        repeat( 4 )
8932
            @(posedge pci_clock) ;
8933
 
8934
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8935
        fork
8936
        begin
8937
            if ( target_mem_image == 1 )
8938
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8939
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8940
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8941
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8942
            else
8943
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8944
 
8945
            do_pause( 1 ) ;
8946
        end
8947
        begin
8948
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8949
            if ( ok !== 1 )
8950
            begin
8951
                $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) ;
8952
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8953
            end
8954
        end
8955
        join
8956
 
8957
        // finish the last read in PCI Target Unit
8958
        if ( target_mem_image == 1 )
8959
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8960
                          pci_image_base + 12, 32'hDEAD_BEAF,
8961
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8962
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8963
        else
8964
            PCIU_IO_READ
8965
             (
8966
                `Test_Master_1,
8967
                pci_image_base + 12,
8968
                32'hDEAD_BEAF,
8969
                4'h0,
8970
                1,
8971
                `Test_Target_Normal_Completion
8972
             );
8973
 
8974
         do_pause( 1 ) ;
8975
 
8976
         error_monitor_done = 1 ;
8977
    end
8978
    join
8979
 
8980
    if ( ok )
8981
        test_ok ;
8982
 
8983
end
8984
endtask // transaction_ordering
8985
 
8986
task pci_transaction_progress_monitor ;
8987
    input [31:0] address ;
8988
    input [3:0]  bus_command ;
8989
    input [31:0] num_of_transfers ;
8990
    input [31:0] num_of_cycles ;
8991
    input check_transfers ;
8992
    input check_cycles ;
8993
    input doing_fast_back_to_back ;
8994
    output ok ;
8995
    reg in_use ;
8996
    integer deadlock_counter ;
8997
    integer transfer_counter ;
8998
    integer cycle_counter ;
8999
    integer deadlock_max_val ;
9000
begin:main
9001
 
9002
    if ( in_use === 1 )
9003
    begin
9004
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9005
        ok = 0 ;
9006
        disable main ;
9007
    end
9008
 
9009
    // approximate number of cycles on WB bus for maximum transaction length
9010
    deadlock_max_val = tb_init_waits + 100 +
9011
                       `WBW_DEPTH *
9012
                       (tb_subseq_waits + 1 +
9013
                       `ifdef REGISTER_WBS_OUTPUTS
9014
                       1) ;
9015
                       `else
9016
                       0) ;
9017
                       `endif
9018
 
9019
    // time used for maximum transaction length on WB
9020
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
9021
 
9022
    // maximum pci clock cycles
9023
    `ifdef PCI33
9024
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
9025
    `else
9026
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
9027
    `endif
9028
 
9029
    in_use = 1 ;
9030
    ok     = 1 ;
9031
 
9032
    fork
9033
    begin:wait_start
9034
 
9035
        deadlock_counter = 0 ;
9036
 
9037
        @(posedge pci_clock) ;
9038
 
9039
        if ( doing_fast_back_to_back !== 1 )
9040
        begin
9041
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
9042
            begin
9043 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
9044
                    deadlock_counter = 0 ;
9045
                else
9046
                    deadlock_counter = deadlock_counter + 1 ;
9047 15 mihad
                @(posedge pci_clock) ;
9048
            end
9049
            if ( FRAME !== 1 )
9050
            begin
9051
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9052
                in_use = 0 ;
9053
                ok     = 0 ;
9054
                disable main ;
9055
            end
9056
        end
9057
 
9058
        deadlock_counter = 0 ;
9059
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
9060
        begin
9061
            deadlock_counter = deadlock_counter + 1 ;
9062
            @(posedge pci_clock) ;
9063
        end
9064
 
9065
        if ( FRAME !== 0 )
9066
        begin
9067
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9068
            in_use = 0 ;
9069
            ok     = 0 ;
9070
            disable main ;
9071
        end
9072
    end //wait_start
9073
 
9074
    begin:addr_bc_monitor
9075
 
9076
        @(posedge pci_clock) ;
9077
 
9078
        if ( doing_fast_back_to_back !== 1 )
9079
        begin
9080
            while ( FRAME !== 1 )
9081
                @(posedge pci_clock) ;
9082
        end
9083
 
9084
        while( FRAME !== 0 )
9085
            @(posedge pci_clock) ;
9086
 
9087
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
9088
        if ( bus_command !== `BC_IACK )
9089
        begin
9090
            if ( AD !== address )
9091
            begin
9092
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
9093
                $display("Expected address = %h, detected address = %h ", address, AD) ;
9094
                ok = 0 ;
9095
            end
9096
        end
9097
 
9098
        if ( CBE !== bus_command )
9099
        begin
9100
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
9101
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
9102
            ok = 0 ;
9103
        end
9104
    end //addr_bc_monitor
9105
 
9106
    begin:transfer_checker
9107
        transfer_counter = 0 ;
9108
 
9109
        @(posedge pci_clock) ;
9110
 
9111
        if ( doing_fast_back_to_back !== 1 )
9112
        begin
9113
            while ( FRAME !== 1 )
9114
                @(posedge pci_clock) ;
9115
        end
9116
 
9117
        while( FRAME !== 0 )
9118
            @(posedge pci_clock) ;
9119
 
9120
        while( FRAME === 0 )
9121
        begin
9122
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
9123
                transfer_counter = transfer_counter + 1 ;
9124
            @(posedge pci_clock) ;
9125
        end
9126
 
9127
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
9128
        begin
9129
            @(posedge pci_clock) ;
9130
        end
9131
 
9132
        if ( (TRDY === 0) && (DEVSEL === 0) )
9133
                transfer_counter = transfer_counter + 1 ;
9134
 
9135
        if ( check_transfers === 1 )
9136
        begin
9137
            if ( transfer_counter !== num_of_transfers )
9138
            begin
9139
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9140
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9141
                ok = 0 ;
9142
            end
9143
        end
9144
    end //transfer_checker
9145
    begin:cycle_checker
9146
        if ( check_cycles )
9147
        begin
9148
            cycle_counter = 0 ;
9149
            @(posedge pci_clock) ;
9150
 
9151
            if ( doing_fast_back_to_back !== 1)
9152
            begin
9153
                while ( FRAME !== 1 )
9154
                    @(posedge pci_clock) ;
9155
            end
9156
 
9157
            while( FRAME !== 0 )
9158
                @(posedge pci_clock) ;
9159
 
9160
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9161
            begin
9162
                cycle_counter = cycle_counter + 1 ;
9163
                @(posedge pci_clock) ;
9164
            end
9165
 
9166
            if ( FRAME !== 1 )
9167
            begin
9168
                while ((FRAME === 0) && (MAS0_GNT === 0))
9169
                    @(posedge pci_clock) ;
9170
 
9171
                if ( FRAME !== 1 )
9172
                begin
9173
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9174
                        @(posedge pci_clock) ;
9175
 
9176
                    @(posedge pci_clock) ;
9177
 
9178
                    if ( FRAME !== 1 )
9179
                    begin
9180
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9181
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9182
                        ok = 0 ;
9183
                    end
9184
                end
9185
            end
9186
        end
9187
    end // cycle_checker
9188
    join
9189
 
9190
    in_use = 0 ;
9191
end
9192
endtask //pci_transaction_progress_monitor
9193
 
9194
reg CYC_O_previous ;
9195
always@(posedge wb_clock or posedge reset)
9196
begin
9197
    if ( reset )
9198
        CYC_O_previous <= #1 1'b0 ;
9199
    else
9200
        CYC_O_previous <= #1 CYC_O ;
9201
end
9202
 
9203
task wb_transaction_progress_monitor ;
9204
    input [31:0] address ;
9205
    input        write ;
9206
    input [31:0] num_of_transfers ;
9207
    input check_transfers ;
9208
    output ok ;
9209
    reg in_use ;
9210
    integer deadlock_counter ;
9211
    integer transfer_counter ;
9212
    integer deadlock_max_val ;
9213 73 mihad
    reg [2:0] slave_termination ;
9214
    reg       cab_asserted ;
9215 15 mihad
begin:main
9216
    if ( in_use === 1 )
9217
    begin
9218
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9219
        ok = 0 ;
9220
        disable main ;
9221
    end
9222
 
9223
    // number of cycles on WB bus for maximum transaction length
9224
    deadlock_max_val = 4 - tb_init_waits + 100 +
9225
                       `PCIW_DEPTH *
9226
                       (4 - tb_subseq_waits + 1) ;
9227
 
9228
    // time used for maximum transaction length on PCI
9229
    `ifdef PCI33
9230
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9231
    `else
9232
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9233
    `endif
9234
 
9235
    // maximum wb clock cycles
9236
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9237
 
9238 73 mihad
    in_use       = 1 ;
9239
    ok           = 1 ;
9240
    cab_asserted = 0 ;
9241 15 mihad
 
9242
    fork
9243
    begin:wait_start
9244
        deadlock_counter = 0 ;
9245
        @(posedge wb_clock) ;
9246
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9247
        begin
9248 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9249
                deadlock_counter = deadlock_counter + 1 ;
9250
            else
9251
                deadlock_counter = 0;
9252 15 mihad
            @(posedge wb_clock) ;
9253
        end
9254
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9255
        begin
9256
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9257
            in_use = 0 ;
9258
            ok     = 0 ;
9259
            disable main ;
9260
        end
9261
 
9262
        deadlock_counter = 0 ;
9263
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9264
        begin
9265
            deadlock_counter = deadlock_counter + 1 ;
9266
            @(posedge wb_clock) ;
9267
        end
9268
 
9269
        if ( CYC_O !== 1 )
9270
        begin
9271
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9272
            in_use = 0 ;
9273
            ok     = 0 ;
9274
            disable main ;
9275
        end
9276
    end //wait_start
9277
    begin:addr_monitor
9278
        @(posedge wb_clock) ;
9279
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9280
            @(posedge wb_clock) ;
9281
 
9282
        while( CYC_O !== 1 )
9283
            @(posedge wb_clock) ;
9284
 
9285
        while (STB_O !== 1 )
9286
            @(posedge wb_clock) ;
9287
 
9288
        if ( WE_O !== write )
9289
        begin
9290
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9291
            if ( write !== 1 )
9292
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9293
            else
9294
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9295
        end
9296
 
9297
        if ( ADR_O !== address )
9298
        begin
9299
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9300
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9301
            ok = 0 ;
9302
        end
9303
    end
9304
    begin:transfer_checker
9305
        transfer_counter = 0 ;
9306
        @(posedge wb_clock) ;
9307
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9308
            @(posedge wb_clock) ;
9309
 
9310
        while( CYC_O !== 1 )
9311
            @(posedge wb_clock) ;
9312
 
9313 63 mihad
        while( (CYC_O === 1) && ((transfer_counter <= `PCIW_DEPTH) || (transfer_counter <= `PCIR_DEPTH)) )
9314 15 mihad
        begin
9315 73 mihad
 
9316
            if (!cab_asserted)
9317
                cab_asserted = (CAB_O !== 1'b0) ;
9318
 
9319
            if (STB_O === 1)
9320
            begin
9321
                slave_termination = {ACK_I, ERR_I, RTY_I} ;
9322
                if (ACK_I)
9323
                    transfer_counter = transfer_counter + 1 ;
9324
            end
9325 15 mihad
            @(posedge wb_clock) ;
9326
        end
9327
 
9328 73 mihad
        if (cab_asserted)
9329
        begin
9330
            // cab was sampled asserted
9331
            // if number of transfers was less than 2 - check for extraordinary terminations
9332
            if (transfer_counter < 2)
9333
            begin
9334
                // 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.
9335
                // any other cases are wrong
9336
                case (slave_termination)
9337
                3'b000:begin end
9338
                3'b001:begin end
9339
                3'b010:begin end
9340
                default:begin
9341
                            ok = 0 ;
9342
                            $display("Time %t", $time) ;
9343
                            $display("WB_MASTER asserted CAB_O for single transfer") ;
9344
                        end
9345
                endcase
9346
            end
9347
        end
9348
        else
9349
        begin
9350
            // if cab is not asserted, then WB_MASTER should not read more than one data.
9351
            if (transfer_counter > 1)
9352
            begin
9353
                ok = 0 ;
9354
                $display("Time %t", $time) ;
9355
                $display("WB_MASTER didn't assert CAB_O for consecutive block transfer") ;
9356
            end
9357
        end
9358
 
9359 15 mihad
        if ( check_transfers === 1 )
9360
        begin
9361
            if ( transfer_counter !== num_of_transfers )
9362
            begin
9363
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9364
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9365
                ok = 0 ;
9366
            end
9367
        end
9368
    end //transfer_checker
9369
    join
9370
 
9371
    in_use = 0 ;
9372
end
9373
endtask // wb_transaction_progress_monitor
9374
 
9375
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9376
// so they are not re-entered
9377
task wb_transaction_progress_monitor_backup ;
9378
    input [31:0] address ;
9379
    input        write ;
9380
    input [31:0] num_of_transfers ;
9381
    input check_transfers ;
9382
    output ok ;
9383
    reg in_use ;
9384
    integer deadlock_counter ;
9385
    integer transfer_counter ;
9386
    integer deadlock_max_val ;
9387
begin:main
9388
    if ( in_use === 1 )
9389
    begin
9390
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9391
        ok = 0 ;
9392
        disable main ;
9393
    end
9394
 
9395
    // number of cycles on WB bus for maximum transaction length
9396
    deadlock_max_val = 4 - tb_init_waits + 100 +
9397
                       `PCIW_DEPTH *
9398
                       (4 - tb_subseq_waits + 1) ;
9399
 
9400
    // time used for maximum transaction length on PCI
9401
    `ifdef PCI33
9402
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9403
    `else
9404
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9405
    `endif
9406
 
9407
    // maximum wb clock cycles
9408
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9409
 
9410
    in_use = 1 ;
9411
    ok     = 1 ;
9412
 
9413
    fork
9414
    begin:wait_start
9415
        deadlock_counter = 0 ;
9416
        @(posedge wb_clock) ;
9417
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9418
        begin
9419 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9420
                deadlock_counter = deadlock_counter + 1 ;
9421
            else
9422
                deadlock_counter = 0;
9423 15 mihad
            @(posedge wb_clock) ;
9424
        end
9425
        if ( CYC_O !== 0 )
9426
        begin
9427
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9428
            in_use = 0 ;
9429
            ok     = 0 ;
9430
            disable main ;
9431
        end
9432
 
9433
        deadlock_counter = 0 ;
9434
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9435
        begin
9436
            deadlock_counter = deadlock_counter + 1 ;
9437
            @(posedge wb_clock) ;
9438
        end
9439
 
9440
        if ( CYC_O !== 1 )
9441
        begin
9442
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9443
            in_use = 0 ;
9444
            ok     = 0 ;
9445
            disable main ;
9446
        end
9447
    end //wait_start
9448
    begin:addr_monitor
9449
        @(posedge wb_clock) ;
9450
        while ( CYC_O !== 0 )
9451
            @(posedge wb_clock) ;
9452
 
9453
        while( CYC_O !== 1 )
9454
            @(posedge wb_clock) ;
9455
 
9456
        while (STB_O !== 1 )
9457
            @(posedge wb_clock) ;
9458
 
9459
        if ( WE_O !== write )
9460
        begin
9461
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9462
            if ( write !== 1 )
9463
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9464
            else
9465
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9466
        end
9467
 
9468
        if ( ADR_O !== address )
9469
        begin
9470
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9471
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9472
            ok = 0 ;
9473
        end
9474
    end
9475
    begin:transfer_checker
9476
        transfer_counter = 0 ;
9477
        @(posedge wb_clock) ;
9478
        while ( CYC_O !== 0 )
9479
            @(posedge wb_clock) ;
9480
 
9481
        while( CYC_O !== 1 )
9482
            @(posedge wb_clock) ;
9483
 
9484
        while( CYC_O === 1 )
9485
        begin
9486
            if ( (STB_O === 1) && (ACK_I === 1) )
9487
                transfer_counter = transfer_counter + 1 ;
9488
            @(posedge wb_clock) ;
9489
        end
9490
 
9491
        if ( check_transfers === 1 )
9492
        begin
9493
            if ( transfer_counter !== num_of_transfers )
9494
            begin
9495
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9496
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9497
                ok = 0 ;
9498
            end
9499
        end
9500
    end //transfer_checker
9501
    join
9502
 
9503
    in_use = 0 ;
9504
end
9505
endtask // wb_transaction_progress_monitor_backup
9506
 
9507
task wb_transaction_stop ;
9508
    input [31:0] num_of_transfers ;
9509
    integer transfer_counter ;
9510
begin:main
9511
    begin:transfer_checker
9512
        transfer_counter = 0 ;
9513
        @(posedge wb_clock) ;
9514
        while ( CYC_O !== 0 )
9515
            @(posedge wb_clock) ;
9516
 
9517
        while( CYC_O !== 1 )
9518
            @(posedge wb_clock) ;
9519
 
9520
        if ( (STB_O === 1) && (ACK_I === 1) )
9521
            transfer_counter = transfer_counter + 1 ;
9522
 
9523
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9524
        begin
9525
            @(posedge wb_clock) ;
9526
            if ( (STB_O === 1) && (ACK_I === 1) )
9527
                transfer_counter = transfer_counter + 1 ;
9528
        end
9529
    end //transfer_checker
9530
end
9531
endtask // wb_transaction_stop
9532
 
9533
task musnt_respond ;
9534
    output ok ;
9535
    reg in_use ;
9536
    integer i ;
9537
begin:main
9538
    if ( in_use === 1 )
9539
    begin
9540
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9541
        #20 $stop ;
9542
        ok = 0 ;
9543
        disable main ;
9544
    end
9545
 
9546
    in_use = 1 ;
9547
    ok = 1 ;
9548
 
9549
    fork
9550
    begin:wait_start
9551
        @(negedge FRAME) ;
9552
        disable count ;
9553
    end
9554
    begin:count
9555
        i = 0 ;
9556
        while ( i < 1000 )
9557
        begin
9558
            @(posedge pci_clock) ;
9559
            i = i + 1 ;
9560
        end
9561
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9562
        ok = 0 ;
9563
        disable wait_start ;
9564
    end
9565
    join
9566
 
9567
    @(posedge pci_clock) ;
9568
    while ( FRAME === 0 && ok )
9569
    begin
9570
        if ( DEVSEL !== 1 )
9571
        begin
9572
            ok = 0 ;
9573
        end
9574
        @(posedge pci_clock) ;
9575
    end
9576
 
9577
    while ( IRDY === 0 && ok )
9578
    begin
9579
        if ( DEVSEL !== 1 )
9580
        begin
9581
            ok = 0 ;
9582
        end
9583
        @(posedge pci_clock) ;
9584
    end
9585
    in_use = 0 ;
9586
end
9587
endtask
9588
 
9589
function [31:0] wb_to_pci_addr_convert ;
9590
    input [31:0] wb_address ;
9591
    input [31:0] translation_address ;
9592
    input [31:0] translate ;
9593
 
9594
    reg   [31:0] temp_address ;
9595
begin
9596
    if ( translate !== 1 )
9597
    begin
9598
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9599
    end
9600
    else
9601
    begin
9602
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9603
    end
9604
 
9605
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9606
    wb_to_pci_addr_convert = temp_address ;
9607
end
9608
endfunction //wb_to_pci_addr_convert
9609
 
9610 45 mihad
`ifdef HOST
9611 15 mihad
task find_pci_devices ;
9612
    integer device_num ;
9613
    reg     found ;
9614
    reg [11:0] pci_ctrl_offset ;
9615
    reg ok ;
9616
    reg [31:0] data ;
9617 45 mihad
    reg [31:0] expected_data ;
9618
 
9619
    reg [5:0]  reg_num ;
9620 15 mihad
begin:main
9621 45 mihad
 
9622
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9623 15 mihad
    pci_ctrl_offset = 12'h004 ;
9624
 
9625
    // enable master & target operation
9626
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9627
 
9628
    if ( ok !== 1 )
9629
    begin
9630
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9631 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9632 15 mihad
        disable main ;
9633
    end
9634
    // find all possible devices on pci bus by performing configuration cycles
9635 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9636 15 mihad
    begin
9637
        find_device ( device_num, found ) ;
9638
 
9639
        // check pci status register - if device is not present, Received Master Abort bit must be set
9640
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9641
 
9642
        if ( (data[29] !== 0) && (found !== 0) )
9643 45 mihad
        begin
9644 15 mihad
            $display( "Time %t ", $time ) ;
9645
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9646
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9647 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9648
            ok = 0 ;
9649 15 mihad
        end
9650
 
9651
        if ( (data[29] !== 1) && (found !== 1) )
9652
        begin
9653
            $display( "Time %t ", $time ) ;
9654
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9655
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9656 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9657
            ok = 0 ;
9658 15 mihad
        end
9659
 
9660
        // clear Master Abort status if set
9661
        if ( data[29] !== 0 )
9662
        begin
9663
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9664
        end
9665 45 mihad
 
9666
        if (found === 1)
9667
        begin
9668
            // first check if found target is supposed to exist
9669
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9670
            begin
9671
                $display("Time %t", $time) ;
9672
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9673
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9674
                ok = 0 ;
9675
            end
9676
            else
9677
            begin
9678
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9679
                begin
9680
 
9681
                    data = 32'hFFFF_FFFF ;
9682
 
9683
                    expected_data = 0 ;
9684
 
9685
                    if (reg_num == 4)
9686
                    begin
9687
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9688
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9689
                    end
9690
                    else if (reg_num == 5)
9691
                    begin
9692
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9693
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9694
                    end
9695
 
9696
                    // write base address 0
9697
                    generate_configuration_cycle
9698
                    (
9699
                        'h0,            //bus_num
9700
                        device_num,     //device_num
9701
                        'h0,            //func_num
9702
                        reg_num,        //reg_num
9703
                        'h0,            //type
9704
                        4'hF,           // byte_enables
9705
                        data,           //data
9706
                        1'b1            //read0_write1
9707
                    );
9708
 
9709
                    // read data back
9710
                    generate_configuration_cycle
9711
                    (
9712
                        'h0,            //bus_num
9713
                        device_num,     //device_num
9714
                        'h0,            //func_num
9715
                        reg_num,        //reg_num
9716
                        'h0,            //type
9717
                        4'hF,           // byte_enables
9718
                        data,           //data
9719
                        1'b0            //read0_write1
9720
                    );
9721
 
9722
                    if (data !== expected_data)
9723
                    begin
9724
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9725
                        $display("Data read back not as expected!");
9726
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9727
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9728
                        ok = 0 ;
9729
                    end
9730
                end
9731
            end
9732
        end
9733 15 mihad
    end
9734 45 mihad
 
9735
    if (ok)
9736
        test_ok ;
9737 15 mihad
end //main
9738
endtask //find_pci_devices
9739
 
9740
task find_device ;
9741
    input [31:0] device_num ;
9742
    output  found ;
9743
 
9744
    reg [31:0] read_data ;
9745
begin
9746
    found = 1'b0 ;
9747
 
9748
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9749 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9750 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9751
    else
9752
    begin
9753
        $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]) ;
9754
        found = 1'b1 ;
9755
    end
9756
end
9757
endtask //find_device
9758 45 mihad
`endif
9759 15 mihad
 
9760
/*task set_bridge_parameters ;
9761
    reg [11:0] current_offset ;
9762
    reg [2:0] result ;
9763
    reg [31:0] write_data ;
9764
begin
9765
    // set burst size
9766
    // set latency timer
9767
    current_offset = 12'h00C ;
9768
    // set burst size to 16 and latency timer to 8
9769
    write_data     = {24'h0000_08, system_burst_size} ;
9770
    config_write(current_offset, write_data, 4'b1111) ;
9771
 
9772
    // set io image
9773
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9774
    write_data = 32'h0000_000_3 ;
9775
    config_write(current_offset, write_data, 4'b1111) ;
9776
 
9777
 
9778
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9779
    write_data = 32'h0001_000_1 ;
9780
    config_write(current_offset, write_data, 4'b1111) ;
9781
 
9782
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9783
    write_data = 32'hFFFF_0000 ;
9784
    config_write(current_offset, write_data, 4'b1111) ;
9785
 
9786
    // set memory image
9787
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9788
    write_data = 32'h0000_000_7 ;
9789
    config_write(current_offset, write_data, 4'b1111) ;
9790
 
9791
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9792
    write_data = 32'h0002_000_0 ;
9793
    config_write(current_offset, write_data, 4'b1111) ;
9794
 
9795
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9796
    write_data = 32'h0001_0000 ;
9797
    config_write(current_offset, write_data, 4'b1111) ;
9798
 
9799
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9800
    write_data = 32'hFFFF_0000 ;
9801
    config_write(current_offset, write_data, 4'b1111) ;
9802
 
9803
    // set parameters for bridge's target unit
9804
    // image control 0
9805
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9806
    write_data     = 32'h0000_0002 ;
9807
    config_write(current_offset, write_data, 4'b0001) ;
9808
 
9809
    // base_address 0
9810
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9811
    write_data      = 32'h2000_0000 ;
9812
    config_write(current_offset, write_data, 4'b1111) ;
9813
 
9814
    // address mask 0
9815
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9816
    write_data     = 32'hFFFF_F000 ;
9817
    config_write(current_offset, write_data, 4'b1111) ;
9818
 
9819
    // command register - enable response to io and mem space and PCI master
9820
    current_offset = 12'h004 ;
9821
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9822
    config_write(current_offset, write_data, 4'b1111) ;
9823
end
9824
endtask // set_bridge_parameters
9825
*/
9826
 
9827
task configuration_cycle_write ;
9828
    input [7:0]  bus_num ;
9829
    input [4:0]  device_num ;
9830
    input [2:0]  func_num ;
9831
    input [5:0]  reg_num ;
9832
    input [1:0]  type ;
9833
    input [3:0]  byte_enables ;
9834
    input [31:0] data ;
9835
 
9836
    reg [31:0] write_address ;
9837
    reg in_use ;
9838
    reg ok ;
9839
begin:main
9840
 
9841
    if ( in_use === 1 )
9842
    begin
9843 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9844 15 mihad
        disable main ;
9845
    end
9846
 
9847 45 mihad
    if ( (device_num > 20) && (type === 0) )
9848 15 mihad
    begin
9849
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9850
        disable main ;
9851
    end
9852
 
9853
    in_use = 1 ;
9854
 
9855 45 mihad
 
9856
`ifdef HOST
9857
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9858
`else
9859
`ifdef GUEST
9860
 
9861 15 mihad
    if ( type )
9862
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9863
    else
9864
    begin
9865
        write_address = 0 ;
9866
        write_address[10:0] = { func_num, reg_num, type } ;
9867
        write_address[11 + device_num] = 1'b1 ;
9868
    end
9869 45 mihad
 
9870
    fork
9871 15 mihad
    begin
9872 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9873
                            write_address,
9874
                            data, ~byte_enables,
9875
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9876
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9877
        do_pause(1) ;
9878 15 mihad
    end
9879 45 mihad
    begin
9880
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9881
    end
9882
    join
9883
`endif
9884
`endif
9885
 
9886
    in_use = 0 ;
9887
end
9888
endtask // configuration_cycle_write
9889 15 mihad
 
9890 45 mihad
task configuration_cycle_read ;
9891
    input [7:0]  bus_num ;
9892
    input [4:0]  device_num ;
9893
    input [2:0]  func_num ;
9894
    input [5:0]  reg_num ;
9895
    input [1:0]  type ;
9896
    input [3:0]  byte_enables ;
9897
    output [31:0] data ;
9898 15 mihad
 
9899 45 mihad
    reg [31:0] read_address ;
9900
    reg in_use ;
9901 15 mihad
 
9902 45 mihad
    reg master_check_data_prev ;
9903
begin:main
9904 15 mihad
 
9905 45 mihad
    if ( in_use === 1 )
9906 15 mihad
    begin
9907 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9908
        data = 32'hxxxx_xxxx ;
9909
        disable main ;
9910 15 mihad
    end
9911
 
9912 45 mihad
    in_use = 1 ;
9913 15 mihad
 
9914 45 mihad
`ifdef HOST
9915
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9916
`else
9917
`ifdef GUEST
9918
     master_check_data_prev = master1_check_received_data ;
9919 15 mihad
     if ( type )
9920 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9921 15 mihad
     else
9922
     begin
9923 45 mihad
         read_address = 0 ;
9924
         read_address[10:0] = { func_num, reg_num, type } ;
9925
         read_address[11 + device_num] = 1'b1 ;
9926 15 mihad
     end
9927 45 mihad
 
9928
     fork
9929
     begin
9930
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9931
                 read_address,
9932 15 mihad
                 data, ~byte_enables,
9933
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9934
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9935 45 mihad
         do_pause(1) ;
9936
     end
9937
     begin
9938
         @(master1_received_data_valid) ;
9939
         data = master1_received_data ;
9940
     end
9941
     join
9942 15 mihad
 
9943 45 mihad
    master1_check_received_data = master_check_data_prev ;
9944
`endif
9945
`endif
9946
 
9947 15 mihad
    in_use = 0 ;
9948
 
9949 45 mihad
end //main
9950
endtask // configuration_cycle_read
9951
 
9952 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9953
task test_conf_cycle_type1_reference ;
9954
    reg [31:0] address ;
9955
    reg in_use ;
9956
 
9957
    reg master_check_data_prev ;
9958
    reg [31:0] data ;
9959
    reg monitor_ok ;
9960
    reg master_ok ;
9961
begin:main
9962
 
9963
    if ( in_use === 1 )
9964
    begin
9965
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9966
        disable main ;
9967
    end
9968
 
9969
    in_use = 1 ;
9970
 
9971
    master_check_data_prev = master1_check_received_data ;
9972
 
9973
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9974
    address = `TAR0_IDSEL_ADDR ;
9975
 
9976
    address[1:0] = 2'b01 ;
9977
 
9978
    `ifdef HOST
9979
        conf_cyc_type1_target_bus_num = 255 ;
9980
    `endif
9981
    master_ok = 1 ;
9982
    fork
9983
    begin
9984
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9985
        do_pause(1) ;
9986
    end
9987
    begin:error_monitor1
9988
        @(error_event_int) ;
9989
        master_ok = 0 ;
9990
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9991
    end
9992
    begin
9993
        pci_transaction_progress_monitor
9994
        (
9995
            address,                                                // expected address on PCI bus
9996
            `BC_CONF_READ,                                          // expected bus command on PCI bus
9997
            0,                                                      // expected number of succesfull data phases
9998
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9999
            1'b1,                                                   // monitor checking/not checking number of transfers
10000
            1'b0,                                                   // monitor checking/not checking number of cycles
10001
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10002
            monitor_ok                                              // status - 1 success, 0 failure
10003
        ) ;
10004
 
10005
        @(posedge pci_clock);
10006
        #1 ;
10007
 
10008
        if (master_ok)
10009
            disable error_monitor1 ;
10010
 
10011
        if (!monitor_ok)
10012
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10013
    end
10014
    join
10015
 
10016
    if (monitor_ok && master_ok)
10017
        test_ok ;
10018
 
10019
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
10020
    master_ok = 1 ;
10021
    fork
10022
    begin
10023
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
10024
        do_pause(1) ;
10025
    end
10026
    begin:error_monitor2
10027
        @(error_event_int) ;
10028
        master_ok = 0 ;
10029
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
10030
    end
10031
    begin
10032
        pci_transaction_progress_monitor
10033
        (
10034
            address,                                                // expected address on PCI bus
10035
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10036
            0,                                                      // expected number of succesfull data phases
10037
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10038
            1'b1,                                                   // monitor checking/not checking number of transfers
10039
            1'b0,                                                   // monitor checking/not checking number of cycles
10040
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10041
            monitor_ok                                              // status - 1 success, 0 failure
10042
        ) ;
10043
 
10044
        @(posedge pci_clock);
10045
        #1 ;
10046
 
10047
        if (master_ok)
10048
            disable error_monitor2 ;
10049
 
10050
        if (!monitor_ok)
10051
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
10052
    end
10053
    join
10054
 
10055
    master1_check_received_data = master_check_data_prev ;
10056
 
10057
    if (monitor_ok && master_ok)
10058
        test_ok ;
10059
 
10060
    in_use = 0 ;
10061
 
10062
end //main
10063
endtask // test_conf_cycle_type1_reference
10064
`endif
10065
 
10066 45 mihad
`ifdef HOST
10067
task generate_configuration_cycle ;
10068 15 mihad
    input [7:0]  bus_num ;
10069
    input [4:0]  device_num ;
10070
    input [2:0]  func_num ;
10071
    input [5:0]  reg_num ;
10072
    input [1:0]  type ;
10073
    input [3:0]  byte_enables ;
10074 45 mihad
    inout [31:0] data ;
10075
    input        read0_write1 ;
10076 15 mihad
 
10077
    reg `READ_STIM_TYPE read_data ;
10078
    reg `WB_TRANSFER_FLAGS  flags ;
10079
    reg `READ_RETURN_TYPE   read_status ;
10080
 
10081
    reg `WRITE_STIM_TYPE   write_data ;
10082
    reg `WRITE_RETURN_TYPE write_status ;
10083
 
10084 45 mihad
    reg [31:0] pci_address ;
10085 15 mihad
    reg in_use ;
10086 45 mihad
    reg ok ;
10087 15 mihad
 
10088
    reg [31:0] temp_var ;
10089
begin:main
10090
 
10091
    if ( in_use === 1 )
10092
    begin
10093 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
10094 15 mihad
        data = 32'hxxxx_xxxx ;
10095
        disable main ;
10096
    end
10097
 
10098 45 mihad
    in_use = 1 ;
10099
 
10100
    if ( type )
10101
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10102
    else
10103 15 mihad
    begin
10104 45 mihad
        pci_address = 0 ;
10105
        pci_address[10:0] = { func_num, reg_num, type } ;
10106
        if (device_num <= 20)
10107
            pci_address[11 + device_num] = 1'b1 ;
10108
    end
10109
 
10110
    // setup flags
10111
    flags = 0 ;
10112
    flags`INIT_WAITS   = tb_init_waits ;
10113
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10114
 
10115
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10116
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10117
 
10118
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10119
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10120
    write_data`WRITE_SEL      = 4'hF ;
10121
    write_data`WRITE_TAG_STIM = 0 ;
10122
 
10123
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10124
 
10125
    // check if write succeeded
10126
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10127
    begin
10128
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10129 15 mihad
        data = 32'hxxxx_xxxx ;
10130 45 mihad
        in_use = 0 ;
10131 15 mihad
        disable main ;
10132
    end
10133
 
10134 45 mihad
    // setup flags for wb master to handle retries and read and write data
10135
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10136
 
10137
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10138
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10139
    read_data`READ_SEL          = byte_enables ;
10140
    write_data`WRITE_SEL        = byte_enables ;
10141
    read_data`READ_TAG_STIM     = 0 ;
10142
    write_data`WRITE_TAG_STIM   = 0 ;
10143
    write_data`WRITE_DATA       = data ;
10144
 
10145
    ok = 0 ;
10146
 
10147
    fork
10148
    begin
10149
        if (read0_write1 === 0)
10150
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
10151
        else
10152
        if (read0_write1 === 1)
10153
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
10154
    end
10155
    begin
10156
        pci_transaction_progress_monitor
10157
        (
10158
            pci_address,                                            // expected address on PCI bus
10159
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10160
            1,                                                      // expected number of succesfull data phases
10161
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10162
            1'b0,                                                   // monitor checking/not checking number of transfers
10163
            1'b0,                                                   // monitor checking/not checking number of cycles
10164
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10165
            ok                                                      // status - 1 success, 0 failure
10166
        ) ;
10167
    end
10168
    join
10169
 
10170
    // check if transfer succeeded
10171
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10172
    begin
10173
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10174
        data = 32'hxxxx_xxxx ;
10175
        in_use = 0 ;
10176
        disable main ;
10177
    end
10178
 
10179
    if (!ok)
10180
    begin
10181
        data = 32'hxxxx_xxxx ;
10182
        in_use = 0 ;
10183
        disable main ;
10184
    end
10185
 
10186
    if (read0_write1 === 0)
10187
        data = read_status`READ_DATA ;
10188
 
10189
    in_use = 0 ;
10190
end
10191
endtask // generate_configuration_cycle
10192
 
10193
task test_configuration_cycle_target_abort ;
10194
    reg `READ_STIM_TYPE read_data ;
10195
    reg `WB_TRANSFER_FLAGS  flags ;
10196
    reg `READ_RETURN_TYPE   read_status ;
10197
 
10198
    reg `WRITE_STIM_TYPE   write_data ;
10199
    reg `WRITE_RETURN_TYPE write_status ;
10200
 
10201
    reg [31:0] pci_address ;
10202
    reg in_use ;
10203
    reg ok_pci ;
10204
    reg ok_wb  ;
10205
    reg ok     ;
10206
 
10207
    reg [31:0] temp_var ;
10208
 
10209
begin:main
10210
 
10211
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10212
 
10213
    if ( in_use === 1 )
10214
    begin
10215
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10216
        disable main ;
10217
    end
10218
 
10219 15 mihad
    in_use = 1 ;
10220
 
10221 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10222
 
10223 15 mihad
    // setup flags
10224
    flags = 0 ;
10225 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10226
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10227 15 mihad
 
10228
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10229
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10230
 
10231
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10232 45 mihad
    temp_var                  = 0 ;
10233
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10234
    write_data`WRITE_DATA     = temp_var ;
10235 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10236
    write_data`WRITE_TAG_STIM = 0 ;
10237
 
10238
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10239
 
10240
    // check if write succeeded
10241
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10242
    begin
10243
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10244 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10245
        in_use = 0 ;
10246 15 mihad
        disable main ;
10247
    end
10248
 
10249 45 mihad
    // setup flags for wb master to handle retries and read and write data
10250 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10251
 
10252 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10253
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10254 15 mihad
 
10255 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10256
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10257
    read_data`READ_SEL          = 4'hF ;
10258
    write_data`WRITE_SEL        = 4'hF ;
10259
    read_data`READ_TAG_STIM     = 0 ;
10260
    write_data`WRITE_TAG_STIM   = 0 ;
10261
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10262
 
10263
    ok_pci = 0 ;
10264
    ok_wb  = 1 ;
10265
 
10266
    // set target to terminate with target abort
10267
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10268
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10269
    fork
10270
    begin
10271
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10272
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10273
        begin
10274
            $display("Time %t", $time) ;
10275
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10276
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10277
            ok_wb = 0 ;
10278
        end
10279
 
10280
        config_read( 12'h4, 4'hF, temp_var ) ;
10281
        if ( temp_var[29] !== 0 )
10282
        begin
10283
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10284
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10285
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10286
            ok_wb = 0 ;
10287
        end
10288
 
10289
        if ( temp_var[28] !== 1 )
10290
        begin
10291
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10292
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10293
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10294
            ok_wb = 0 ;
10295
        end
10296
 
10297
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10298
 
10299
        if (ok !== 1)
10300
        begin
10301
            ok_wb = 0 ;
10302
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10303
            $display("Write to PCI Device Status Register failed") ;
10304
            test_fail("Write to PCI Device Status Register failed") ;
10305
        end
10306
 
10307
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10308
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10309
        begin
10310
            $display("Time %t", $time) ;
10311
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10312
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10313
            ok_wb = 0 ;
10314
        end
10315
 
10316
        config_read( 12'h4, 4'hF, temp_var ) ;
10317
        if ( temp_var[29] !== 0 )
10318
        begin
10319
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10320
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10321
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10322
            ok_wb = 0 ;
10323
        end
10324
 
10325
        if ( temp_var[28] !== 1 )
10326
        begin
10327
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10328
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10329
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10330
            ok_wb = 0 ;
10331
        end
10332
 
10333
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10334
 
10335
        if (ok !== 1)
10336
        begin
10337
            ok_wb = 0 ;
10338
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10339
            $display("Write to PCI Device Status Register failed") ;
10340
            test_fail("Write to PCI Device Status Register failed") ;
10341
        end
10342
    end
10343
    begin
10344
        pci_transaction_progress_monitor
10345
        (
10346
            pci_address,                                            // expected address on PCI bus
10347
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10348
            0,                                                      // expected number of succesfull data phases
10349
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10350
            1'b1,                                                   // monitor checking/not checking number of transfers
10351
            1'b0,                                                   // monitor checking/not checking number of cycles
10352
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10353
            ok_pci                                                  // status - 1 success, 0 failure
10354
        ) ;
10355
 
10356
        if (ok_pci)
10357
        begin
10358
            pci_transaction_progress_monitor
10359
            (
10360
                pci_address,                                            // expected address on PCI bus
10361
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10362
                0,                                                      // expected number of succesfull data phases
10363
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10364
                1'b1,                                                   // monitor checking/not checking number of transfers
10365
                1'b0,                                                   // monitor checking/not checking number of cycles
10366
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10367
                ok_pci                                                  // status - 1 success, 0 failure
10368
            ) ;
10369
        end
10370
 
10371
        if (!ok_pci)
10372
        begin
10373
            $display("Time %t", $time) ;
10374
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10375
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10376
        end
10377
    end
10378
    join
10379
 
10380
    if (ok_pci && ok_wb)
10381
    begin
10382
        test_ok ;
10383
    end
10384
 
10385
    in_use = 0 ;
10386
 
10387
    // set target to terminate normally
10388
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10389
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10390
end
10391
endtask // test_configuration_cycle_target_abort
10392
 
10393
task test_configuration_cycle_type1_generation ;
10394
    reg `READ_STIM_TYPE read_data ;
10395
    reg `WB_TRANSFER_FLAGS  flags ;
10396
    reg `READ_RETURN_TYPE   read_status ;
10397
 
10398
    reg `WRITE_STIM_TYPE   write_data ;
10399
    reg `WRITE_RETURN_TYPE write_status ;
10400
 
10401
    reg [31:0] pci_address ;
10402
    reg in_use ;
10403
    reg ok_pci ;
10404
    reg ok_wb  ;
10405
    reg ok     ;
10406
 
10407
    reg [31:0] temp_var ;
10408
 
10409
begin:main
10410
 
10411
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10412
    conf_cyc_type1_target_data = 0 ;
10413
    conf_cyc_type1_target_bus_num = 0;
10414
 
10415
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10416
 
10417
    if ( in_use === 1 )
10418
    begin
10419
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10420
        disable main ;
10421
    end
10422
 
10423
    in_use = 1 ;
10424
 
10425
    pci_address        = 32'hAAAA_AAAA ;
10426
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10427
 
10428
    // setup flags
10429
    flags = 0 ;
10430
    flags`INIT_WAITS   = tb_init_waits ;
10431
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10432
 
10433
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10434
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10435
 
10436
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10437
    write_data`WRITE_DATA     = pci_address ;
10438
    write_data`WRITE_SEL      = 4'hF ;
10439
    write_data`WRITE_TAG_STIM = 0 ;
10440
 
10441
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10442
 
10443
    // check if write succeeded
10444
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10445
    begin
10446
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10447
        test_fail("write to configuration cycle address register was not possible") ;
10448
        in_use = 0 ;
10449
        disable main ;
10450
    end
10451
 
10452
    // setup flags for wb master to handle retries and read and write data
10453
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10454
 
10455
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10456
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10457
 
10458
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10459
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10460
    read_data`READ_SEL          = 4'hF ;
10461
    write_data`WRITE_SEL        = 4'hF ;
10462
    read_data`READ_TAG_STIM     = 0 ;
10463
    write_data`WRITE_TAG_STIM   = 0 ;
10464
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10465
 
10466
    ok_pci = 0 ;
10467
    ok_wb  = 1 ;
10468
 
10469
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10470
    pci_address[31:24] = 0 ;
10471
    fork
10472
    begin
10473
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10474
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10475
        begin
10476
            $display("Time %t", $time) ;
10477
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10478
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10479
            ok_wb = 0 ;
10480
        end
10481
 
10482
        config_read( 12'h4, 4'hF, temp_var ) ;
10483
        if ( temp_var[29] !== 1 )
10484
        begin
10485
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10486
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10487
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10488
            ok_wb = 0 ;
10489
        end
10490
 
10491
        if ( temp_var[28] !== 0 )
10492
        begin
10493
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10494
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10495
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10496
            ok_wb = 0 ;
10497
        end
10498
 
10499
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10500
 
10501
        if (ok !== 1)
10502
        begin
10503
            ok_wb = 0 ;
10504
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10505
            $display("Write to PCI Device Status Register failed") ;
10506
            test_fail("Write to PCI Device Status Register failed") ;
10507
        end
10508
 
10509
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10510
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10511
        begin
10512
            $display("Time %t", $time) ;
10513
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10514
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10515
            ok_wb = 0 ;
10516
        end
10517
 
10518
        config_read( 12'h4, 4'hF, temp_var ) ;
10519
        if ( temp_var[29] !== 1 )
10520
        begin
10521
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10522
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10523
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10524
            ok_wb = 0 ;
10525
        end
10526
 
10527
        if ( temp_var[28] !== 0 )
10528
        begin
10529
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10530
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10531
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10532
            ok_wb = 0 ;
10533
        end
10534
 
10535
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10536
 
10537
        if (ok !== 1)
10538
        begin
10539
            ok_wb = 0 ;
10540
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10541
            $display("Write to PCI Device Status Register failed") ;
10542
            test_fail("Write to PCI Device Status Register failed") ;
10543
        end
10544
    end
10545
    begin
10546
        pci_transaction_progress_monitor
10547
        (
10548
            pci_address,                                            // expected address on PCI bus
10549
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10550
            0,                                                      // expected number of succesfull data phases
10551
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10552
            1'b1,                                                   // monitor checking/not checking number of transfers
10553
            1'b0,                                                   // monitor checking/not checking number of cycles
10554
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10555
            ok_pci                                                  // status - 1 success, 0 failure
10556
        ) ;
10557
 
10558
        if (ok_pci)
10559
        begin
10560
            pci_transaction_progress_monitor
10561
            (
10562
                pci_address,                                            // expected address on PCI bus
10563
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10564
                0,                                                      // expected number of succesfull data phases
10565
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10566
                1'b1,                                                   // monitor checking/not checking number of transfers
10567
                1'b0,                                                   // monitor checking/not checking number of cycles
10568
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10569
                ok_pci                                                  // status - 1 success, 0 failure
10570
            ) ;
10571
        end
10572
 
10573
        if (!ok_pci)
10574
        begin
10575
            $display("Time %t", $time) ;
10576
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10577
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10578
        end
10579
    end
10580
    join
10581
 
10582
    if (ok_pci && ok_wb)
10583
    begin
10584
        test_ok ;
10585
    end
10586
 
10587
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10588
    conf_cyc_type1_target_data = 0 ;
10589
    conf_cyc_type1_target_bus_num = 8'h55;
10590
 
10591
    pci_address      = 32'h5555_5555 ;
10592
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10593
 
10594
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10595
 
10596
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10597
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10598
 
10599
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10600
    write_data`WRITE_DATA     = pci_address ;
10601
    write_data`WRITE_SEL      = 4'hF ;
10602
    write_data`WRITE_TAG_STIM = 0 ;
10603
 
10604
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10605
 
10606
    // check if write succeeded
10607
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10608
    begin
10609
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10610
        test_fail("write to configuration cycle address register was not possible") ;
10611
        in_use = 0 ;
10612
        disable main ;
10613
    end
10614
 
10615
    // setup flags for wb master to handle retries and read and write data
10616
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10617
 
10618
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10619
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10620
 
10621
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10622
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10623
    read_data`READ_SEL          = 4'hF ;
10624
    write_data`WRITE_SEL        = 4'hF ;
10625
    read_data`READ_TAG_STIM     = 0 ;
10626
    write_data`WRITE_TAG_STIM   = 0 ;
10627
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10628
 
10629
    ok_pci = 0 ;
10630
    ok_wb  = 1 ;
10631
 
10632
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10633
    pci_address[31:24] = 0 ;
10634
    fork
10635
    begin
10636
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10637
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10638
        begin
10639
            $display("Time %t", $time) ;
10640
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10641
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10642
            ok_wb = 0 ;
10643
        end
10644
 
10645
        config_read( 12'h4, 4'hF, temp_var ) ;
10646
        if ( temp_var[29] !== 0 )
10647
        begin
10648
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10649
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10650
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10651
            ok_wb = 0 ;
10652
        end
10653
 
10654
        if ( temp_var[28] !== 1 )
10655
        begin
10656
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10657
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10658
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10659
            ok_wb = 0 ;
10660
        end
10661
 
10662
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10663
 
10664
        if (ok !== 1)
10665
        begin
10666
            ok_wb = 0 ;
10667
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10668
            $display("Write to PCI Device Status Register failed") ;
10669
            test_fail("Write to PCI Device Status Register failed") ;
10670
        end
10671
 
10672
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10673
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10674
        begin
10675
            $display("Time %t", $time) ;
10676
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10677
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10678
            ok_wb = 0 ;
10679
        end
10680
 
10681
        config_read( 12'h4, 4'hF, temp_var ) ;
10682
        if ( temp_var[29] !== 0 )
10683
        begin
10684
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10685
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10686
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10687
            ok_wb = 0 ;
10688
        end
10689
 
10690
        if ( temp_var[28] !== 1 )
10691
        begin
10692
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10693
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10694
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10695
            ok_wb = 0 ;
10696
        end
10697
 
10698
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10699
 
10700
        if (ok !== 1)
10701
        begin
10702
            ok_wb = 0 ;
10703
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10704
            $display("Write to PCI Device Status Register failed") ;
10705
            test_fail("Write to PCI Device Status Register failed") ;
10706
        end
10707
    end
10708
    begin
10709
        pci_transaction_progress_monitor
10710
        (
10711
            pci_address,                                            // expected address on PCI bus
10712
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10713
            0,                                                      // expected number of succesfull data phases
10714
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10715
            1'b1,                                                   // monitor checking/not checking number of transfers
10716
            1'b0,                                                   // monitor checking/not checking number of cycles
10717
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10718
            ok_pci                                                  // status - 1 success, 0 failure
10719
        ) ;
10720
 
10721
        if (ok_pci)
10722
        begin
10723
            pci_transaction_progress_monitor
10724
            (
10725
                pci_address,                                            // expected address on PCI bus
10726
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10727
                0,                                                      // expected number of succesfull data phases
10728
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10729
                1'b1,                                                   // monitor checking/not checking number of transfers
10730
                1'b0,                                                   // monitor checking/not checking number of cycles
10731
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10732
                ok_pci                                                  // status - 1 success, 0 failure
10733
            ) ;
10734
        end
10735
 
10736
        if (!ok_pci)
10737
        begin
10738
            $display("Time %t", $time) ;
10739
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10740
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10741
        end
10742
    end
10743
    join
10744
 
10745
    if (ok_pci && ok_wb)
10746
    begin
10747
        test_ok ;
10748
    end
10749
 
10750
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10751
 
10752
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10753
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10754
    conf_cyc_type1_target_bus_num = 8'hAA;
10755
 
10756
    pci_address      = 32'hAAAA_AAAA ;
10757
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10758
 
10759
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10760
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10761
 
10762
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10763
    write_data`WRITE_DATA     = pci_address ;
10764
    write_data`WRITE_SEL      = 4'hF ;
10765
    write_data`WRITE_TAG_STIM = 0 ;
10766
 
10767
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10768
 
10769
    // check if write succeeded
10770
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10771
    begin
10772
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10773
        test_fail("write to configuration cycle address register was not possible") ;
10774
        in_use = 0 ;
10775
        disable main ;
10776
    end
10777
 
10778
    // setup flags for wb master to handle retries and read and write data
10779
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10780
 
10781
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10782
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10783
 
10784
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10785
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10786
    read_data`READ_SEL          = 4'b0101 ;
10787
    write_data`WRITE_SEL        = 4'b1010 ;
10788
    read_data`READ_TAG_STIM     = 0 ;
10789
    write_data`WRITE_TAG_STIM   = 0 ;
10790
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10791
 
10792
    ok_pci = 0 ;
10793
    ok_wb  = 1 ;
10794
 
10795
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10796
    pci_address[31:24] = 0 ;
10797
 
10798
    fork
10799
    begin
10800
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10801
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10802
        begin
10803
            $display("Time %t", $time) ;
10804
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10805
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10806
            ok_wb = 0 ;
10807
        end
10808
 
10809
        config_read( 12'h4, 4'hF, temp_var ) ;
10810
        if ( temp_var[29] !== 0 )
10811
        begin
10812
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10813
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10814
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10815
            ok_wb = 0 ;
10816
        end
10817
 
10818
        if ( temp_var[28] !== 0 )
10819
        begin
10820
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10821
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10822
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10823
            ok_wb = 0 ;
10824
        end
10825
 
10826
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10827
 
10828
        if (ok !== 1)
10829
        begin
10830
            ok_wb = 0 ;
10831
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10832
            $display("Write to PCI Device Status Register failed") ;
10833
            test_fail("Write to PCI Device Status Register failed") ;
10834
        end
10835
 
10836
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10837
        begin
10838
            ok_wb = 0 ;
10839
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10840
            $display("Read Data provided by the bridge was not as expected!") ;
10841
            test_fail("Read Data provided by the bridge was not as expected") ;
10842
        end
10843
 
10844
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10845
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10846
        begin
10847
            $display("Time %t", $time) ;
10848
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10849
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10850
            ok_wb = 0 ;
10851
        end
10852
 
10853
        config_read( 12'h4, 4'hF, temp_var ) ;
10854
        if ( temp_var[29] !== 0 )
10855
        begin
10856
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10857
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10858
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10859
            ok_wb = 0 ;
10860
        end
10861
 
10862
        if ( temp_var[28] !== 0 )
10863
        begin
10864
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10865
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10866
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10867
            ok_wb = 0 ;
10868
        end
10869
 
10870
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10871
 
10872
        if (ok !== 1)
10873
        begin
10874
            ok_wb = 0 ;
10875
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10876
            $display("Write to PCI Device Status Register failed") ;
10877
            test_fail("Write to PCI Device Status Register failed") ;
10878
        end
10879
 
10880
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10881
        begin
10882
            ok_wb = 0 ;
10883
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10884
            $display("Data written by the bridge was not as expected!") ;
10885
            test_fail("Data written by the bridge was not as expected") ;
10886
        end
10887
 
10888
    end
10889
    begin
10890
        ok = 1 ;
10891
        repeat(8)
10892
        begin
10893
            pci_transaction_progress_monitor
10894
            (
10895
                pci_address,                                            // expected address on PCI bus
10896
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10897
                0,                                                      // expected number of succesfull data phases
10898
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10899
                1'b1,                                                   // monitor checking/not checking number of transfers
10900
                1'b0,                                                   // monitor checking/not checking number of cycles
10901
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10902
                ok_pci                                                  // status - 1 success, 0 failure
10903
            ) ;
10904
 
10905
            if (!ok_pci)
10906
            begin
10907
                ok = 0 ;
10908
                $display("Time %t", $time) ;
10909
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10910
            end
10911
        end
10912
 
10913
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10914
 
10915
        pci_transaction_progress_monitor
10916
        (
10917
            pci_address,                                            // expected address on PCI bus
10918
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10919
            1,                                                      // expected number of succesfull data phases
10920
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10921
            1'b1,                                                   // monitor checking/not checking number of transfers
10922
            1'b0,                                                   // monitor checking/not checking number of cycles
10923
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10924
            ok_pci                                                  // status - 1 success, 0 failure
10925
        ) ;
10926
 
10927
        if (!ok_pci)
10928
        begin
10929
            ok = 0 ;
10930
            $display("Time %t", $time) ;
10931
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10932
        end
10933
 
10934
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10935
        repeat(8)
10936
        begin
10937
            pci_transaction_progress_monitor
10938
            (
10939
                pci_address,                                            // expected address on PCI bus
10940
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10941
                0,                                                      // expected number of succesfull data phases
10942
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10943
                1'b1,                                                   // monitor checking/not checking number of transfers
10944
                1'b0,                                                   // monitor checking/not checking number of cycles
10945
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10946
                ok_pci                                                  // status - 1 success, 0 failure
10947
            ) ;
10948
 
10949
            if (!ok_pci)
10950
            begin
10951
                ok = 0 ;
10952
                $display("Time %t", $time) ;
10953
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10954
            end
10955
        end
10956
 
10957
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10958
        pci_transaction_progress_monitor
10959
        (
10960
            pci_address,                                            // expected address on PCI bus
10961
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10962
            1,                                                      // expected number of succesfull data phases
10963
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10964
            1'b1,                                                   // monitor checking/not checking number of transfers
10965
            1'b0,                                                   // monitor checking/not checking number of cycles
10966
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10967
            ok_pci                                                  // status - 1 success, 0 failure
10968
        ) ;
10969
 
10970
        if (!ok_pci)
10971
        begin
10972
            ok = 0 ;
10973
            $display("Time %t", $time) ;
10974
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10975
        end
10976
 
10977
        if (!ok)
10978
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10979
    end
10980
    join
10981
 
10982
    if (ok_pci && ok_wb)
10983
    begin
10984
        test_ok ;
10985
    end
10986
 
10987
    in_use = 0 ;
10988
end
10989
endtask // test_configuration_cycle_type1_generation
10990
`endif
10991
 
10992
task test_initial_conf_values ;
10993
    reg [11:0] register_offset ;
10994
    reg [31:0] expected_value ;
10995
    reg        failed ;
10996
`ifdef HOST
10997
    reg `READ_STIM_TYPE    read_data ;
10998
    reg `WB_TRANSFER_FLAGS flags ;
10999
    reg `READ_RETURN_TYPE  read_status ;
11000
 
11001
    reg `WRITE_STIM_TYPE   write_data ;
11002
    reg `WRITE_RETURN_TYPE write_status ;
11003
begin
11004
    failed     = 0 ;
11005
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11006
    flags      = 0 ;
11007
    read_data  = 0 ;
11008
    write_data = 0 ;
11009
 
11010
    read_data`READ_SEL = 4'hF ;
11011
 
11012
    flags`INIT_WAITS           = tb_init_waits ;
11013
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
11014
 
11015
    // test MEM/IO map bit initial value in each PCI BAR
11016
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
11017
 
11018
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11019
 
11020 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11021
 
11022 45 mihad
    `ifdef NO_CNF_IMAGE
11023
        `ifdef PCI_IMAGE0
11024
            if (`PCI_AM0)
11025
                expected_value = `PCI_BA0_MEM_IO ;
11026
            else
11027
                expected_value = 32'h0000_0000 ;
11028
        `else
11029
            expected_value = 32'h0000_0000 ;
11030
        `endif
11031
    `else
11032
        expected_value = 32'h0000_0000 ;
11033
    `endif
11034
 
11035 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11036
    begin
11037 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
11038
        failed = 1 ;
11039 15 mihad
    end
11040 45 mihad
    else
11041
    begin
11042
        if (read_status`READ_DATA !== expected_value)
11043
        begin
11044
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
11045
            failed = 1 ;
11046
        end
11047
    end
11048 15 mihad
 
11049 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
11050 15 mihad
 
11051 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11052
 
11053
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11054
 
11055
    if (`PCI_AM1)
11056
        expected_value = `PCI_BA1_MEM_IO ;
11057
    else
11058
        expected_value = 32'h0000_0000 ;
11059
 
11060
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11061
    begin
11062
        test_fail("read from P_BA1 register didn't succeede") ;
11063
        failed = 1 ;
11064
    end
11065
    else
11066
    begin
11067
        if (read_status`READ_DATA !== expected_value)
11068
        begin
11069
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
11070
            failed = 1 ;
11071
        end
11072
    end
11073
 
11074
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
11075
 
11076
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11077
 
11078
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11079
 
11080
    `ifdef PCI_IMAGE2
11081
        if (`PCI_AM2)
11082
            expected_value = `PCI_BA2_MEM_IO ;
11083
        else
11084
            expected_value = 32'h0000_0000 ;
11085 15 mihad
    `else
11086 45 mihad
        expected_value = 32'h0000_0000 ;
11087
    `endif
11088 15 mihad
 
11089 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11090
    begin
11091
        test_fail("read from P_BA2 register didn't succeede") ;
11092
        failed = 1 ;
11093
    end
11094
    else
11095
    begin
11096
        if (read_status`READ_DATA !== expected_value)
11097
        begin
11098
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
11099
            failed = 1 ;
11100
        end
11101
    end
11102 15 mihad
 
11103 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
11104
 
11105
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11106
 
11107
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11108
 
11109
    `ifdef PCI_IMAGE3
11110
        if (`PCI_AM3)
11111
            expected_value = `PCI_BA3_MEM_IO ;
11112
        else
11113
            expected_value = 32'h0000_0000 ;
11114
    `else
11115
        expected_value = 32'h0000_0000 ;
11116 15 mihad
    `endif
11117 45 mihad
 
11118
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11119
    begin
11120
        test_fail("read from P_BA3 register didn't succeede") ;
11121
        failed = 1 ;
11122
    end
11123
    else
11124
    begin
11125
        if (read_status`READ_DATA !== expected_value)
11126
        begin
11127
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
11128
            failed = 1 ;
11129
        end
11130
    end
11131
 
11132
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
11133
 
11134
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11135
 
11136
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11137
 
11138
    `ifdef PCI_IMAGE4
11139
        if (`PCI_AM4)
11140
            expected_value = `PCI_BA4_MEM_IO ;
11141
        else
11142
            expected_value = 32'h0000_0000 ;
11143
    `else
11144
        expected_value = 32'h0000_0000 ;
11145 15 mihad
    `endif
11146
 
11147 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11148
    begin
11149
        test_fail("read from P_BA4 register didn't succeede") ;
11150
        failed = 1 ;
11151
    end
11152
    else
11153
    begin
11154
        if (read_status`READ_DATA !== expected_value)
11155
        begin
11156
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11157
            failed = 1 ;
11158
        end
11159
    end
11160 15 mihad
 
11161 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11162 15 mihad
 
11163 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11164
 
11165
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11166
 
11167
    `ifdef PCI_IMAGE5
11168
        if(`PCI_AM5)
11169
            expected_value = `PCI_BA5_MEM_IO ;
11170
        else
11171
            expected_value = 32'h0000_0000 ;
11172
    `else
11173
        expected_value = 32'h0000_0000 ;
11174
    `endif
11175
 
11176
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11177
    begin
11178
        test_fail("read from P_BA5 register didn't succeede") ;
11179
        failed = 1 ;
11180
    end
11181
    else
11182
    begin
11183
        if (read_status`READ_DATA !== expected_value)
11184
        begin
11185
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11186
            failed = 1 ;
11187
        end
11188
    end
11189
 
11190
    // test Address Mask initial values
11191
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11192
 
11193
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11194
 
11195
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11196
 
11197
    `ifdef NO_CNF_IMAGE
11198
        `ifdef PCI_IMAGE0
11199
            expected_value = {`PCI_AM0, 12'h000};
11200
 
11201
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11202
        `else
11203
            expected_value = 32'h0000_0000 ;
11204
        `endif
11205
    `else
11206
        expected_value = 32'hFFFF_FFFF ;
11207
 
11208
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11209
    `endif
11210
 
11211
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11212
    begin
11213
        test_fail("read from P_AM0 register didn't succeede") ;
11214
        failed = 1 ;
11215
    end
11216
    else
11217
    begin
11218
        if (read_status`READ_DATA !== expected_value)
11219
        begin
11220
            test_fail("AM0 initial value was not set as defined");
11221
            failed = 1 ;
11222
        end
11223
    end
11224
 
11225
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11226
 
11227
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11228
 
11229
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11230
 
11231
    expected_value = {`PCI_AM1, 12'h000};
11232
 
11233
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11234
 
11235
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11236
    begin
11237
        test_fail("read from P_AM1 register didn't succeede") ;
11238
        failed = 1 ;
11239
    end
11240
    else
11241
    begin
11242
        if (read_status`READ_DATA !== expected_value)
11243
        begin
11244
            test_fail("AM1 initial value was not set as defined");
11245
            failed = 1 ;
11246
        end
11247
    end
11248
 
11249
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11250
 
11251
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11252
 
11253
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11254
 
11255
    `ifdef PCI_IMAGE2
11256
        expected_value = {`PCI_AM2, 12'h000};
11257
 
11258
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11259
    `else
11260
        expected_value = 32'h0000_0000 ;
11261
    `endif
11262
 
11263
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11264
    begin
11265
        test_fail("read from P_AM2 register didn't succeede") ;
11266
        failed = 1 ;
11267
    end
11268
    else
11269
    begin
11270
        if (read_status`READ_DATA !== expected_value)
11271
        begin
11272
            test_fail("AM2 initial value was not set as defined");
11273
            failed = 1 ;
11274
        end
11275
    end
11276
 
11277
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11278
 
11279
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11280
 
11281
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11282
 
11283
    `ifdef PCI_IMAGE3
11284
        expected_value = {`PCI_AM3, 12'h000};
11285
 
11286
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11287
    `else
11288
        expected_value = 32'h0000_0000 ;
11289
    `endif
11290
 
11291
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11292
    begin
11293
        test_fail("read from P_AM3 register didn't succeede") ;
11294
        failed = 1 ;
11295
    end
11296
    else
11297
    begin
11298
        if (read_status`READ_DATA !== expected_value)
11299
        begin
11300
            test_fail("AM3 initial value was not set as defined");
11301
            failed = 1 ;
11302
        end
11303
    end
11304
 
11305
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11306
 
11307
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11308
 
11309
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11310
 
11311
    `ifdef PCI_IMAGE4
11312
        expected_value = {`PCI_AM4, 12'h000};
11313
 
11314
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11315
    `else
11316
        expected_value = 32'h0000_0000 ;
11317
    `endif
11318
 
11319
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11320
    begin
11321
        test_fail("read from P_AM4 register didn't succeede") ;
11322
        failed = 1 ;
11323
    end
11324
    else
11325
    begin
11326
        if (read_status`READ_DATA !== expected_value)
11327
        begin
11328
            test_fail("AM4 initial value was not set as defined");
11329
            failed = 1 ;
11330
        end
11331
    end
11332
 
11333
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11334
 
11335
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11336
 
11337
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11338
 
11339
    `ifdef PCI_IMAGE5
11340
        expected_value = {`PCI_AM5, 12'h000};
11341
 
11342
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11343
    `else
11344
        expected_value = 32'h0000_0000 ;
11345
    `endif
11346
 
11347
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11348
    begin
11349
        test_fail("read from P_AM5 register didn't succeede") ;
11350
        failed = 1 ;
11351
    end
11352
    else
11353
    begin
11354
        if (read_status`READ_DATA !== expected_value)
11355
        begin
11356
            test_fail("AM5 initial value was not set as defined");
11357
            failed = 1 ;
11358
        end
11359
    end
11360
 
11361
`endif
11362
 
11363
`ifdef GUEST
11364
    reg [31:0] read_data ;
11365
begin
11366
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11367
    failed    = 0 ;
11368
 
11369
    // check all images' BARs
11370
 
11371
    // BAR0
11372
    configuration_cycle_read
11373
    (
11374
        8'h00,                          // bus number [7:0]
11375
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11376
        3'h0,                           // function number [2:0]
11377
        6'h4,                           // register number [5:0]
11378
        2'h0,                           // type [1:0]
11379
        4'hF,                           // byte enables [3:0]
11380
        read_data                       // data returned from configuration read [31:0]
11381
    ) ;
11382
 
11383
    expected_value = 32'h0000_0000 ;
11384
 
11385
    if( read_data !== expected_value)
11386
    begin
11387
        test_fail("initial value of BAR0 register not as expected") ;
11388
        failed = 1 ;
11389
    end
11390
 
11391
    // BAR1
11392
    configuration_cycle_read
11393
    (
11394
        8'h00,                          // bus number [7:0]
11395
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11396
        3'h0,                           // function number [2:0]
11397
        6'h5,                           // register number [5:0]
11398
        2'h0,                           // type [1:0]
11399
        4'hF,                           // byte enables [3:0]
11400
        read_data                       // data returned from configuration read [31:0]
11401
    ) ;
11402
 
11403
    if (`PCI_AM1)
11404
        expected_value = `PCI_BA1_MEM_IO ;
11405
    else
11406
        expected_value = 32'h0000_0000 ;
11407
 
11408
    if( read_data !== expected_value)
11409
    begin
11410
        test_fail("initial value of BAR1 register not as expected") ;
11411
        failed = 1 ;
11412
    end
11413
 
11414
    // BAR2
11415
    configuration_cycle_read
11416
    (
11417
        8'h00,                          // bus number [7:0]
11418
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11419
        3'h0,                           // function number [2:0]
11420
        6'h6,                           // register number [5:0]
11421
        2'h0,                           // type [1:0]
11422
        4'hF,                           // byte enables [3:0]
11423
        read_data                       // data returned from configuration read [31:0]
11424
    ) ;
11425
 
11426
    `ifdef PCI_IMAGE2
11427
    if (`PCI_AM2)
11428
        expected_value = `PCI_BA2_MEM_IO ;
11429
    else
11430
        expected_value = 32'h0000_0000 ;
11431
    `else
11432
    expected_value = 32'h0 ;
11433
    `endif
11434
 
11435
    if( read_data !== expected_value)
11436
    begin
11437
        test_fail("initial value of BAR2 register not as expected") ;
11438
        failed = 1 ;
11439
    end
11440
 
11441
    // BAR3
11442
    configuration_cycle_read
11443
    (
11444
        8'h00,                          // bus number [7:0]
11445
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11446
        3'h0,                           // function number [2:0]
11447
        6'h7,                           // register number [5:0]
11448
        2'h0,                           // type [1:0]
11449
        4'hF,                           // byte enables [3:0]
11450
        read_data                       // data returned from configuration read [31:0]
11451
    ) ;
11452
 
11453
    `ifdef PCI_IMAGE3
11454
    if(`PCI_AM3)
11455
        expected_value = `PCI_BA3_MEM_IO ;
11456
    else
11457
        expected_value = 32'h0000_0000 ;
11458
    `else
11459
    expected_value = 32'h0 ;
11460
    `endif
11461
 
11462
    if( read_data !== expected_value)
11463
    begin
11464
        test_fail("initial value of BAR3 register not as expected") ;
11465
        failed = 1 ;
11466
    end
11467
 
11468
    // BAR4
11469
    configuration_cycle_read
11470
    (
11471
        8'h00,                          // bus number [7:0]
11472
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11473
        3'h0,                           // function number [2:0]
11474
        6'h8,                           // register number [5:0]
11475
        2'h0,                           // type [1:0]
11476
        4'hF,                           // byte enables [3:0]
11477
        read_data                       // data returned from configuration read [31:0]
11478
    ) ;
11479
 
11480
    `ifdef PCI_IMAGE4
11481
    if (`PCI_AM4)
11482
        expected_value = `PCI_BA4_MEM_IO ;
11483
    else
11484
        expected_value = 32'h0000_0000 ;
11485
    `else
11486
    expected_value = 32'h0 ;
11487
    `endif
11488
 
11489
    if( read_data !== expected_value)
11490
    begin
11491
        test_fail("initial value of BAR4 register not as expected") ;
11492
        failed = 1 ;
11493
    end
11494
 
11495
    // BAR5
11496
    configuration_cycle_read
11497
    (
11498
        8'h00,                          // bus number [7:0]
11499
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11500
        3'h0,                           // function number [2:0]
11501
        6'h9,                           // register number [5:0]
11502
        2'h0,                           // type [1:0]
11503
        4'hF,                           // byte enables [3:0]
11504
        read_data                       // data returned from configuration read [31:0]
11505
    ) ;
11506
 
11507
    `ifdef PCI_IMAGE5
11508
    if(`PCI_AM5)
11509
        expected_value = `PCI_BA5_MEM_IO ;
11510
    else
11511
        expected_value = 32'h0000_0000 ;
11512
    `else
11513
    expected_value = 32'h0 ;
11514
    `endif
11515
 
11516
    if( read_data !== expected_value)
11517
    begin
11518
        test_fail("initial value of BAR5 register not as expected") ;
11519
        failed = 1 ;
11520
    end
11521
 
11522
    // write all 1s to BAR0
11523
    read_data = 32'hFFFF_FFFF ;
11524
 
11525
    // BAR0
11526
    configuration_cycle_write
11527
    (
11528
        8'h00,                          // bus number [7:0]
11529
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11530
        3'h0,                           // function number [2:0]
11531
        6'h4,                           // register number [5:0]
11532
        2'h0,                           // type [1:0]
11533
        4'hF,                           // byte enables [3:0]
11534
        read_data                       // data to write [31:0]
11535
    ) ;
11536
 
11537
    expected_value = 32'hFFFF_FFFF ;
11538
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11539
 
11540
    configuration_cycle_read
11541
    (
11542
        8'h00,                          // bus number [7:0]
11543
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11544
        3'h0,                           // function number [2:0]
11545
        6'h4,                           // register number [5:0]
11546
        2'h0,                           // type [1:0]
11547
        4'hF,                           // byte enables [3:0]
11548
        read_data                       // data to write [31:0]
11549
    ) ;
11550
 
11551
    if ( read_data !== expected_value )
11552
    begin
11553
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11554
        failed = 1 ;
11555
    end
11556
 
11557
    // write all 1s to BAR1
11558
    read_data = 32'hFFFF_FFFF ;
11559
 
11560
    // BAR1
11561
    configuration_cycle_write
11562
    (
11563
        8'h00,                          // bus number [7:0]
11564
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11565
        3'h0,                           // function number [2:0]
11566
        6'h5,                           // register number [5:0]
11567
        2'h0,                           // type [1:0]
11568
        4'hF,                           // byte enables [3:0]
11569
        read_data                       // data to write [31:0]
11570
    ) ;
11571
 
11572
    expected_value = {`PCI_AM1, 12'h000} ;
11573
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11574
    if (`PCI_AM1)
11575
        expected_value[0] = `PCI_BA1_MEM_IO ;
11576
 
11577
    configuration_cycle_read
11578
    (
11579
        8'h00,                          // bus number [7:0]
11580
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11581
        3'h0,                           // function number [2:0]
11582
        6'h5,                           // register number [5:0]
11583
        2'h0,                           // type [1:0]
11584
        4'hF,                           // byte enables [3:0]
11585
        read_data                       // data to write [31:0]
11586
    ) ;
11587
 
11588
    if ( read_data !== expected_value )
11589
    begin
11590
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11591
        failed = 1 ;
11592
    end
11593
 
11594
    // write all 1s to BAR2
11595
    read_data = 32'hFFFF_FFFF ;
11596
 
11597
    // BAR2
11598
    configuration_cycle_write
11599
    (
11600
        8'h00,                          // bus number [7:0]
11601
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11602
        3'h0,                           // function number [2:0]
11603
        6'h6,                           // register number [5:0]
11604
        2'h0,                           // type [1:0]
11605
        4'hF,                           // byte enables [3:0]
11606
        read_data                       // data to write [31:0]
11607
    ) ;
11608
 
11609
`ifdef PCI_IMAGE2
11610
    expected_value = {`PCI_AM2, 12'h000} ;
11611
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11612
    if (`PCI_AM2)
11613
        expected_value[0] = `PCI_BA2_MEM_IO ;
11614
`else
11615
    expected_value = 0 ;
11616
`endif
11617
 
11618
    configuration_cycle_read
11619
    (
11620
        8'h00,                          // bus number [7:0]
11621
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11622
        3'h0,                           // function number [2:0]
11623
        6'h6,                           // register number [5:0]
11624
        2'h0,                           // type [1:0]
11625
        4'hF,                           // byte enables [3:0]
11626
        read_data                       // data to write [31:0]
11627
    ) ;
11628
 
11629
    if ( read_data !== expected_value )
11630
    begin
11631
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11632
        failed = 1 ;
11633
    end
11634
 
11635
    // write all 1s to BAR3
11636
    read_data = 32'hFFFF_FFFF ;
11637
 
11638
    // BAR3
11639
    configuration_cycle_write
11640
    (
11641
        8'h00,                          // bus number [7:0]
11642
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11643
        3'h0,                           // function number [2:0]
11644
        6'h7,                           // register number [5:0]
11645
        2'h0,                           // type [1:0]
11646
        4'hF,                           // byte enables [3:0]
11647
        read_data                       // data to write [31:0]
11648
    ) ;
11649
 
11650
`ifdef PCI_IMAGE3
11651
    expected_value = {`PCI_AM3, 12'h000} ;
11652
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11653
    if(`PCI_AM3)
11654
        expected_value[0] = `PCI_BA3_MEM_IO ;
11655
`else
11656
    expected_value = 0 ;
11657
`endif
11658
 
11659
    configuration_cycle_read
11660
    (
11661
        8'h00,                          // bus number [7:0]
11662
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11663
        3'h0,                           // function number [2:0]
11664
        6'h7,                           // register number [5:0]
11665
        2'h0,                           // type [1:0]
11666
        4'hF,                           // byte enables [3:0]
11667
        read_data                       // data to write [31:0]
11668
    ) ;
11669
 
11670
    if ( read_data !== expected_value )
11671
    begin
11672
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11673
        failed = 1 ;
11674
    end
11675
 
11676
    // write all 1s to BAR4
11677
    read_data = 32'hFFFF_FFFF ;
11678
 
11679
    // BAR4
11680
    configuration_cycle_write
11681
    (
11682
        8'h00,                          // bus number [7:0]
11683
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11684
        3'h0,                           // function number [2:0]
11685
        6'h8,                           // register number [5:0]
11686
        2'h0,                           // type [1:0]
11687
        4'hF,                           // byte enables [3:0]
11688
        read_data                       // data to write [31:0]
11689
    ) ;
11690
 
11691
`ifdef PCI_IMAGE4
11692
    expected_value = {`PCI_AM4, 12'h000} ;
11693
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11694
    if(`PCI_AM4)
11695
        expected_value[0] = `PCI_BA4_MEM_IO ;
11696
`else
11697
    expected_value = 0 ;
11698
`endif
11699
 
11700
    configuration_cycle_read
11701
    (
11702
        8'h00,                          // bus number [7:0]
11703
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11704
        3'h0,                           // function number [2:0]
11705
        6'h8,                           // register number [5:0]
11706
        2'h0,                           // type [1:0]
11707
        4'hF,                           // byte enables [3:0]
11708
        read_data                       // data to write [31:0]
11709
    ) ;
11710
 
11711
    if ( read_data !== expected_value )
11712
    begin
11713
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11714
        failed = 1 ;
11715
    end
11716
 
11717
    // write all 1s to BAR5
11718
    read_data = 32'hFFFF_FFFF ;
11719
 
11720
    // BAR5
11721
    configuration_cycle_write
11722
    (
11723
        8'h00,                          // bus number [7:0]
11724
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11725
        3'h0,                           // function number [2:0]
11726
        6'h9,                           // register number [5:0]
11727
        2'h0,                           // type [1:0]
11728
        4'hF,                           // byte enables [3:0]
11729
        read_data                       // data to write [31:0]
11730
    ) ;
11731
 
11732
`ifdef PCI_IMAGE5
11733
    expected_value = {`PCI_AM5, 12'h000} ;
11734
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11735
    if(`PCI_AM5)
11736
        expected_value[0] = `PCI_BA5_MEM_IO ;
11737
`else
11738
    expected_value = 0 ;
11739
`endif
11740
 
11741
    configuration_cycle_read
11742
    (
11743
        8'h00,                          // bus number [7:0]
11744
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11745
        3'h0,                           // function number [2:0]
11746
        6'h9,                           // register number [5:0]
11747
        2'h0,                           // type [1:0]
11748
        4'hF,                           // byte enables [3:0]
11749
        read_data                       // data to write [31:0]
11750
    ) ;
11751
 
11752
    if ( read_data !== expected_value )
11753
    begin
11754
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11755
        failed = 1 ;
11756
    end
11757
`endif
11758
 
11759
    if (!failed)
11760
        test_ok ;
11761
end
11762
endtask
11763
 
11764 15 mihad
task display_warning;
11765
    input [31:0] error_address ;
11766
    input [31:0] expected_data ;
11767
    input [31:0] actual ;
11768
begin
11769
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11770
end
11771
endtask // display warning
11772
 
11773
/*############################################################################
11774
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11775
=====================
11776
############################################################################*/
11777
 
11778
// Task reslease the PCI bus for 'delay' clocks
11779
task do_pause;
11780
  input  [15:0] delay;
11781
  reg    [15:0] cnt;
11782
  begin
11783
    test_start <= 1'b0;  // no device is allowed to take this
11784
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11785
    begin
11786
      if (~pci_reset_comb)
11787
      begin
11788
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11789
      end
11790
      `NO_ELSE;
11791
    end
11792
  end
11793
endtask // do_pause
11794
 
11795
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11796
task DO_REF;
11797
  input  [79:0] name;
11798
  input  [2:0] master_number;
11799
  input  [PCI_BUS_DATA_RANGE:0] address;
11800
  input  [3:0] command;
11801
  input  [PCI_BUS_DATA_RANGE:0] data;
11802
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11803
  input  [9:0] size;
11804
  input   make_addr_par_error, make_data_par_error;
11805
  input  [7:0] master_wait_states;
11806
  input  [7:0] target_wait_states;
11807
  input  [1:0] target_devsel_speed;
11808
  input   fast_back_to_back;
11809
  input  [2:0] target_termination;
11810
  input   expect_master_abort;
11811
  reg     waiting;
11812
  begin
11813
// Cautiously wait for previous command to be done
11814
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11815
    begin
11816
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11817
      begin
11818
        if (~pci_reset_comb)
11819
        begin
11820
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11821
        end
11822
        `NO_ELSE;
11823
      end
11824
      else
11825
      begin
11826
        waiting = 1'b0;  // ready to do next command
11827
      end
11828
    end
11829
    next_test_name[79:0] <= name[79:0];
11830
    test_master_number <= master_number[2:0];
11831
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11832
    test_command[3:0] <= command[3:0] ;
11833
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11834
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11835
    test_size <= size;
11836
    test_make_addr_par_error <= make_addr_par_error;
11837
    test_make_data_par_error <= make_data_par_error;
11838
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11839
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11840
    test_target_initial_wait_states <= target_wait_states[7:4];
11841
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11842
    test_target_devsel_speed <= target_devsel_speed[1:0];
11843
    test_fast_back_to_back <= fast_back_to_back;
11844
    test_target_termination <= target_termination[2:0];
11845
    test_expect_master_abort <= expect_master_abort;
11846
    test_start <= 1'b1;
11847
    if (~pci_reset_comb)
11848
    begin
11849
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11850
    end
11851
    `NO_ELSE;
11852
// wait for new command to start
11853
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11854
    begin
11855
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11856
      begin
11857
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11858
      end
11859
      else
11860
      begin
11861
        waiting = 1'b0;  // ready to do next command
11862
      end
11863
    end
11864
  end
11865
endtask // DO_REF
11866
 
11867
// Use Macros defined in pci_defines.vh as paramaters
11868
 
11869
// DO_REF (name[79:0], master_number[2:0],
11870
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11871
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11872
//          make_addr_par_error, make_data_par_error,
11873
//          master_wait_states[8:0], target_wait_states[8:0],
11874
//          target_devsel_speed[1:0], fast_back_to_back,
11875
//          target_termination[2:0],
11876
//          expect_master_abort);
11877
//
11878
// Example:
11879
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11880
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11881
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11882
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11883
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11884
 
11885
// Access a location with no high-order bits set, assuring that no device responds
11886
task PCIU_CONFIG_READ_MASTER_ABORT;
11887
  input  [79:0] name;
11888
  input  [2:0] master_number;
11889 51 mihad
  input  [31:0] address ;
11890
  input  [3:0] be ;
11891 15 mihad
  begin
11892 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11893
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11894
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11895 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11896
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11897
  end
11898
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11899
 
11900
// Access a location with no high-order bits set, assuring that no device responds
11901
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11902
  input  [79:0] name;
11903
  input  [2:0] master_number;
11904 51 mihad
  input  [31:0] address ;
11905
  input  [3:0] be ;
11906 15 mihad
  begin
11907 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11908
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11909
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11910 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11911
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11912
  end
11913
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11914
 
11915
// Access a location with no high-order bits set, assuring that no device responds
11916
task PCIU_MEM_READ_MASTER_ABORT;
11917
  input  [79:0] name;
11918
  input  [2:0] master_number;
11919
  input  [9:0] size;
11920
  begin
11921
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11922
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11923
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11924
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11925
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11926
  end
11927
endtask // PCIU_MEM_READ_MASTER_ABORT
11928
 
11929
// Access a location with no high-order bits set, assuring that no device responds
11930
task PCIU_MEM_WRITE_MASTER_ABORT;
11931
  input  [79:0] name;
11932
  input  [2:0] master_number;
11933
  input  [9:0] size;
11934
  begin
11935
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11936
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11937
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11938
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11939
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11940
  end
11941
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11942
 
11943
// Do variable length transfers with various paramaters
11944
task PCIU_CONFIG_READ;
11945
  input  [79:0] name;
11946
  input  [2:0] master_number;
11947
  input  [PCI_BUS_DATA_RANGE:0] address;
11948
  input  [PCI_BUS_DATA_RANGE:0] data;
11949
  input  [3:0] be ;
11950
  input  [9:0] size;
11951
  input  [7:0] master_wait_states;
11952
  input  [7:0] target_wait_states;
11953
  input  [1:0] target_devsel_speed;
11954
  input  [2:0] target_termination;
11955
  begin
11956
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11957
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11958
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11959
              8'h0_0, target_wait_states[7:0],
11960
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11961
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11962
  end
11963
endtask // PCIU_CONFIG_READ
11964
 
11965
task PCIU_CONFIG_WRITE;
11966
  input  [79:0] name;
11967
  input  [2:0] master_number;
11968
  input  [PCI_BUS_DATA_RANGE:0] address;
11969
  input  [PCI_BUS_DATA_RANGE:0] data;
11970
  input  [3:0] be ;
11971
  input  [9:0] size;
11972
  input  [7:0] master_wait_states;
11973
  input  [7:0] target_wait_states;
11974
  input  [1:0] target_devsel_speed;
11975
  input  [2:0] target_termination;
11976
  begin
11977
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11978
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11979
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11980
              8'h0_0, target_wait_states[7:0],
11981
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11982
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11983
  end
11984
endtask // PCIU_CONFIG_WRITE
11985
 
11986
task PCIU_READ;
11987
  input  [2:0] master_number;
11988
  input  [PCI_BUS_DATA_RANGE:0] address;
11989
  input  [3:0] command;
11990
  input  [PCI_BUS_DATA_RANGE:0] data;
11991
  input  [3:0] byte_en;
11992
  input  [9:0] size;
11993
  input  [7:0] master_wait_states;
11994
  input  [7:0] target_wait_states;
11995
  input  [1:0] target_devsel_speed;
11996
  input  [2:0] target_termination;
11997
  reg    [79:0] name;
11998
  begin
11999
    if (command == `BC_MEM_READ)
12000
        name = "MEM_READ  " ;
12001
    else if (command == `BC_MEM_READ_LN)
12002
        name = "MEM_RD_LN " ;
12003
    else if (command == `BC_MEM_READ_MUL )
12004
        name = "MEM_RD_MUL" ;
12005
    else
12006
        name = "WRONG_READ" ;
12007
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12008
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12009
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12010
              8'h0_0, target_wait_states[7:0],
12011
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12012
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12013
  end
12014
endtask // PCIU_READ
12015
 
12016
task PCIU_MEM_READ;
12017
  input  [79:0] name;
12018
  input  [2:0] master_number;
12019
  input  [PCI_BUS_DATA_RANGE:0] address;
12020
  input  [PCI_BUS_DATA_RANGE:0] data;
12021
  input  [9:0] size;
12022
  input  [7:0] master_wait_states;
12023
  input  [7:0] target_wait_states;
12024
  input  [1:0] target_devsel_speed;
12025
  input  [2:0] target_termination;
12026
  begin
12027
 
12028
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12029
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12030
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12031
              8'h0_0, target_wait_states[7:0],
12032
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12033
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12034
  end
12035
endtask // PCIU_MEM_READ
12036
 
12037
task PCIU_IO_READ;
12038
  input  [2:0] master_number;
12039
  input  [PCI_BUS_DATA_RANGE:0] address;
12040
  input  [PCI_BUS_DATA_RANGE:0] data;
12041
  input  [3:0] byte_en ;
12042
  input  [9:0] size;
12043
  input  [2:0] target_termination ;
12044
  begin
12045
 
12046
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12047
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12048
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12049
              8'h0_0, `Test_One_Zero_Target_WS,
12050
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12051
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12052
  end
12053
endtask // PCIU_IO_READ
12054
 
12055
task PCIU_IO_READ_MAKE_PERR;
12056
  input  [2:0] master_number;
12057
  input  [PCI_BUS_DATA_RANGE:0] address;
12058
  input  [PCI_BUS_DATA_RANGE:0] data;
12059
  input  [3:0] byte_en ;
12060
  input  [9:0] size;
12061
  input  [2:0] target_termination ;
12062
  begin
12063
 
12064
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12065
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12066
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12067
              8'h0_0, `Test_One_Zero_Target_WS,
12068
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12069
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12070
  end
12071
endtask // PCIU_IO_READ_MAKE_PERR
12072
 
12073
task PCIU_MEM_READ_LN;
12074
  input  [79:0] name;
12075
  input  [2:0] master_number;
12076
  input  [PCI_BUS_DATA_RANGE:0] address;
12077
  input  [PCI_BUS_DATA_RANGE:0] data;
12078
  input  [9:0] size;
12079
  input  [7:0] master_wait_states;
12080
  input  [7:0] target_wait_states;
12081
  input  [1:0] target_devsel_speed;
12082
  input  [2:0] target_termination;
12083
  begin
12084
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12085
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12086
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12087
              8'h0_0, target_wait_states[7:0],
12088
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12089
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12090
  end
12091
endtask // PCIU_MEM_READ_LN
12092
 
12093
task PCIU_MEM_READ_MUL;
12094
  input  [79:0] name;
12095
  input  [2:0] master_number;
12096
  input  [PCI_BUS_DATA_RANGE:0] address;
12097
  input  [PCI_BUS_DATA_RANGE:0] data;
12098
  input  [9:0] size;
12099
  input  [7:0] master_wait_states;
12100
  input  [7:0] target_wait_states;
12101
  input  [1:0] target_devsel_speed;
12102
  input  [2:0] target_termination;
12103
  begin
12104
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12105
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12106
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12107
              8'h0_0, target_wait_states[7:0],
12108
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12109
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12110
  end
12111
endtask // PCIU_MEM_READ_MUL
12112
 
12113
task PCIU_MEM_READ_MAKE_PERR;
12114
  input  [79:0] name;
12115
  input  [2:0] master_number;
12116
  input  [PCI_BUS_DATA_RANGE:0] address;
12117
  input  [PCI_BUS_DATA_RANGE:0] data;
12118
  input  [9:0] size;
12119
  input  [7:0] master_wait_states;
12120
  input  [7:0] target_wait_states;
12121
  input  [1:0] target_devsel_speed;
12122
  input  [2:0] target_termination;
12123
  begin
12124
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12125
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12126
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12127
              8'h0_0, target_wait_states[7:0],
12128
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12129
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12130
  end
12131
endtask // PCIU_MEM_READ_MAKE_PERR
12132
 
12133
task PCIU_MEM_WRITE;
12134
  input  [79:0] name;
12135
  input  [2:0] master_number;
12136
  input  [PCI_BUS_DATA_RANGE:0] address;
12137
  input  [PCI_BUS_DATA_RANGE:0] data;
12138
  input  [3:0] byte_en;
12139
  input  [9:0] size;
12140
  input  [7:0] master_wait_states;
12141
  input  [7:0] target_wait_states;
12142
  input  [1:0] target_devsel_speed;
12143
  input  [2:0] target_termination;
12144
  begin
12145
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12146
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12147
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12148
              8'h0_0, target_wait_states[7:0],
12149
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12150
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12151
  end
12152
endtask // PCIU_MEM_WRITE
12153
 
12154
task PCIU_IO_WRITE;
12155
  input  [2:0] master_number;
12156
  input  [PCI_BUS_DATA_RANGE:0] address;
12157
  input  [PCI_BUS_DATA_RANGE:0] data;
12158
  input  [3:0] byte_en;
12159
  input  [9:0] size;
12160
  input  [2:0] target_termination ;
12161
  begin
12162
 
12163
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12164
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12165
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12166
              8'h0_0, `Test_One_Zero_Target_WS,
12167
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12168
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12169
  end
12170
endtask // PCIU_IO_WRITE
12171
 
12172
task PCIU_IO_WRITE_MAKE_PERR ;
12173
  input  [2:0] master_number;
12174
  input  [PCI_BUS_DATA_RANGE:0] address;
12175
  input  [PCI_BUS_DATA_RANGE:0] data;
12176
  input  [3:0] byte_en;
12177
  input  [9:0] size;
12178
  input  [2:0] target_termination ;
12179
  begin
12180
 
12181
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12182
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12183
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12184
              8'h0_0, `Test_One_Zero_Target_WS,
12185
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12186
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12187
  end
12188
endtask // PCIU_IO_WRITE
12189
 
12190
task PCIU_MEM_WRITE_MAKE_SERR;
12191
  input  [79:0] name;
12192
  input  [2:0] master_number;
12193
  input  [PCI_BUS_DATA_RANGE:0] address;
12194
  input  [PCI_BUS_DATA_RANGE:0] data;
12195
  input  [9:0] size;
12196
  input  [7:0] master_wait_states;
12197
  input  [7:0] target_wait_states;
12198
  input  [1:0] target_devsel_speed;
12199
  input  [2:0] target_termination;
12200
  begin
12201
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12202
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12203
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12204
              8'h0_0, target_wait_states[7:0],
12205
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12206
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12207
  end
12208
endtask // PCIU_MEM_WRITE_MAKE_SERR
12209
 
12210
task PCIU_MEM_WRITE_MAKE_PERR;
12211
  input  [79:0] name;
12212
  input  [2:0] master_number;
12213
  input  [PCI_BUS_DATA_RANGE:0] address;
12214
  input  [PCI_BUS_DATA_RANGE:0] data;
12215
  input  [9:0] size;
12216
  input  [7:0] master_wait_states;
12217
  input  [7:0] target_wait_states;
12218
  input  [1:0] target_devsel_speed;
12219
  input  [2:0] target_termination;
12220
  begin
12221
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12222
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12223
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12224
              8'h0_0, target_wait_states[7:0],
12225
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12226
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12227
  end
12228
endtask // PCIU_MEM_WRITE
12229
 
12230
/*--------------------------------------------------------------------------
12231
Initialization CASES
12232
--------------------------------------------------------------------------*/
12233
 
12234
// Initialize the basic Config Registers of the PCI bridge target device
12235
task configure_bridge_target;
12236
    reg [11:0] offset ;
12237
    reg [31:0] data ;
12238
    `ifdef HOST
12239
    reg `WRITE_STIM_TYPE   write_data ;
12240
    reg `WB_TRANSFER_FLAGS write_flags ;
12241
    reg `WRITE_RETURN_TYPE write_status ;
12242
    `else
12243
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12244
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12245
    `endif
12246
 
12247
    reg [31:0] temp_var ;
12248
begin
12249
`ifdef HOST //  set Header
12250
    offset  = 12'h4 ; // PCI Header Command register
12251
    data    = 32'h0000_0007 ; // enable master & target operation
12252
 
12253
    write_flags                      = 0 ;
12254
    write_flags`INIT_WAITS           = tb_init_waits ;
12255
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12256
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12257
 
12258
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12259
    write_data`WRITE_SEL      = 4'h1 ;
12260
    write_data`WRITE_TAG_STIM = 0 ;
12261
    write_data`WRITE_DATA     = data ;
12262
 
12263
    next_test_name[79:0] <= "Init_Tar_R";
12264
 
12265
    $display(" bridge target - Enabling master and target operation!");
12266
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12267
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12268
    begin
12269
        $display("Write to configuration space failed! Time %t ", $time) ;
12270
    end
12271
 
12272
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12273
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12274
 
12275
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12276
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12277
 
12278
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12279
    write_data`WRITE_SEL      = 4'hf ;
12280
    write_data`WRITE_TAG_STIM = 0 ;
12281
    write_data`WRITE_DATA     = data ;
12282
 
12283
 `ifdef  NO_CNF_IMAGE
12284
  `ifdef PCI_IMAGE0 //      set P_BA0
12285
 
12286
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12287
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12288
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12289
    begin
12290
        $display("Write to configuration space failed! Time %t ", $time) ;
12291
    end
12292
  `endif
12293
 `else //      set P_BA0
12294
 
12295
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12296
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12297
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12298
    begin
12299
        $display("Write to configuration space failed! Time %t ", $time) ;
12300
    end
12301
 `endif
12302
 
12303
`else // GUEST, set Header, set P_BA0
12304
    data            = 32'h0000_0007 ; // enable master & target operation
12305
    byte_enables    = 4'hF ;
12306
    $display(" bridge target - Enabling master and target operation!");
12307 45 mihad
    configuration_cycle_write(0,                        // bus number
12308
                              `TAR0_IDSEL_INDEX - 11,   // device number
12309
                              0,                        // function number
12310
                              1,                        // register number
12311
                              0,                        // type of configuration cycle
12312
                              byte_enables,             // byte enables
12313
                              data                      // data
12314 15 mihad
                             ) ;
12315
 
12316
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12317
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12318
    byte_enables = 4'hf ;
12319 45 mihad
    configuration_cycle_write(0,                        // bus number
12320
                              `TAR0_IDSEL_INDEX - 11,   // device number
12321
                              0,                        // function number
12322
                              4,                        // register number
12323
                              0,                        // type of configuration cycle
12324
                              byte_enables,             // byte enables
12325
                              data                      // data
12326 15 mihad
                             ) ;
12327
 
12328
`endif
12329
end
12330
endtask // configure_bridge_target
12331
 
12332
// Initialize the basic Config Registers of the PCI bridge target device
12333
task configure_bridge_target_base_addresses;
12334
    reg [11:0] offset ;
12335
    reg [31:0] data ;
12336
    `ifdef HOST
12337
    reg `WRITE_STIM_TYPE   write_data ;
12338
    reg `WB_TRANSFER_FLAGS write_flags ;
12339
    reg `WRITE_RETURN_TYPE write_status ;
12340
    `else
12341
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12342
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12343
    `endif
12344
 
12345
    reg [31:0] temp_var ;
12346
begin
12347
`ifdef HOST //  set Header
12348
    offset  = 12'h4 ; // PCI Header Command register
12349
    data    = 32'h0000_0007 ; // enable master & target operation
12350
 
12351
    write_flags                    = 0 ;
12352
    write_flags`INIT_WAITS         = tb_init_waits ;
12353
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12354
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12355
 
12356
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12357
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12358
 
12359
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12360
    write_data`WRITE_SEL      = 4'h1 ;
12361
    write_data`WRITE_TAG_STIM = 0 ;
12362
    write_data`WRITE_DATA     = data ;
12363
 
12364
    next_test_name[79:0] <= "Init_Tar_R";
12365
 
12366
    $display(" bridge target - Enabling master and target operation!");
12367
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12368
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12369
    begin
12370
        $display("Write to configuration space failed! Time %t ", $time) ;
12371
    end
12372
 
12373
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12374
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12375
 
12376
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12377
    write_data`WRITE_SEL      = 4'hf ;
12378
    write_data`WRITE_TAG_STIM = 0 ;
12379
    write_data`WRITE_DATA     = data ;
12380
 
12381
 `ifdef  NO_CNF_IMAGE
12382
  `ifdef PCI_IMAGE0 //      set P_BA0
12383
 
12384
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12385
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12386
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12387
    begin
12388
        $display("Write to configuration space failed! Time %t ", $time) ;
12389
    end
12390
  `endif
12391
 `else //      set P_BA0
12392
 
12393
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12394
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12395
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12396
    begin
12397
        $display("Write to configuration space failed! Time %t ", $time) ;
12398
    end
12399
 `endif
12400
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12401
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12402
 
12403
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12404
    write_data`WRITE_SEL      = 4'hf ;
12405
    write_data`WRITE_TAG_STIM = 0 ;
12406
    write_data`WRITE_DATA     = data ;
12407
 
12408
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12409
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12410
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12411
    begin
12412
        $display("Write to configuration space failed! Time %t ", $time) ;
12413
    end
12414
 `ifdef PCI_IMAGE2
12415
 
12416
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12417
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12418
 
12419
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12420
    write_data`WRITE_SEL      = 4'hf ;
12421
    write_data`WRITE_TAG_STIM = 0 ;
12422
    write_data`WRITE_DATA     = data ;
12423
 
12424
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12425
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12426
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12427
    begin
12428
        $display("Write to configuration space failed! Time %t ", $time) ;
12429
    end
12430
 `endif
12431
 `ifdef PCI_IMAGE3
12432
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12433
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12434
 
12435
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12436
    write_data`WRITE_SEL      = 4'hf ;
12437
    write_data`WRITE_TAG_STIM = 0 ;
12438
    write_data`WRITE_DATA     = data ;
12439
 
12440
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12441
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12442
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12443
    begin
12444
        $display("Write to configuration space failed! Time %t ", $time) ;
12445
    end
12446
 `endif
12447
 `ifdef PCI_IMAGE4
12448
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12449
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12450
 
12451
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12452
    write_data`WRITE_SEL      = 4'hf ;
12453
    write_data`WRITE_TAG_STIM = 0 ;
12454
    write_data`WRITE_DATA     = data ;
12455
 
12456
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12457
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12458
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12459
    begin
12460
        $display("Write to configuration space failed! Time %t ", $time) ;
12461
    end
12462
 `endif
12463
 `ifdef PCI_IMAGE5
12464
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12465
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12466
 
12467
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12468
    write_data`WRITE_SEL      = 4'hf ;
12469
    write_data`WRITE_TAG_STIM = 0 ;
12470
    write_data`WRITE_DATA     = data ;
12471
 
12472
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12473
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12474
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12475
    begin
12476
        $display("Write to configuration space failed! Time %t ", $time) ;
12477
    end
12478
 `endif
12479
 
12480
`else // GUEST, set Header, set P_BA0
12481
    data            = 32'h0000_0007 ; // enable master & target operation
12482
    byte_enables    = 4'hF ;
12483
    $display(" bridge target - Enabling master and target operation!");
12484 45 mihad
    configuration_cycle_write(0,                        // bus number
12485
                              `TAR0_IDSEL_INDEX - 11,   // device number
12486
                              0,                        // function number
12487
                              1,                        // register number
12488
                              0,                        // type of configuration cycle
12489
                              byte_enables,             // byte enables
12490
                              data                      // data
12491 15 mihad
                             ) ;
12492
 
12493
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12494
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12495
    byte_enables = 4'hf ;
12496 45 mihad
    configuration_cycle_write(0,                        // bus number
12497
                              `TAR0_IDSEL_INDEX - 11,   // device number
12498
                              0,                        // function number
12499
                              4,                        // register number
12500
                              0,                        // type of configuration cycle
12501
                              byte_enables,             // byte enables
12502
                              data                      // data
12503 15 mihad
                             ) ;
12504
 
12505
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12506
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12507
    byte_enables = 4'hf ;
12508 45 mihad
    configuration_cycle_write(0,                        // bus number
12509
                              `TAR0_IDSEL_INDEX - 11,   // device number
12510
                              0,                        // function number
12511
                              5,                        // register number
12512
                              0,                        // type of configuration cycle
12513
                              byte_enables,             // byte enables
12514
                              data                      // data
12515 15 mihad
                             ) ;
12516
 `ifdef PCI_IMAGE2
12517
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12518
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12519
    byte_enables = 4'hf ;
12520 45 mihad
    configuration_cycle_write(0,                        // bus number
12521
                              `TAR0_IDSEL_INDEX - 11,   // device number
12522
                              0,                        // function number
12523
                              6,                        // register number
12524
                              0,                        // type of configuration cycle
12525
                              byte_enables,             // byte enables
12526
                              data                      // data
12527 15 mihad
                             ) ;
12528
 `endif
12529
 `ifdef PCI_IMAGE3
12530
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12531
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12532
    byte_enables = 4'hf ;
12533 45 mihad
    configuration_cycle_write(0,                        // bus number
12534
                              `TAR0_IDSEL_INDEX - 11,   // device number
12535
                              0,                        // function number
12536
                              7,                        // register number
12537
                              0,                        // type of configuration cycle
12538
                              byte_enables,             // byte enables
12539
                              data                      // data
12540 15 mihad
                             ) ;
12541
 `endif
12542
 `ifdef PCI_IMAGE4
12543
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12544
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12545
    byte_enables = 4'hf ;
12546 45 mihad
    configuration_cycle_write(0,                        // bus number
12547
                              `TAR0_IDSEL_INDEX - 11,   // device number
12548
                              0,                        // function number
12549
                              8,                        // register number
12550
                              0,                        // type of configuration cycle
12551
                              byte_enables,             // byte enables
12552
                              data                      // data
12553 15 mihad
                             ) ;
12554
 `endif
12555
 `ifdef PCI_IMAGE5
12556
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12557
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12558
    byte_enables = 4'hf ;
12559 45 mihad
    configuration_cycle_write(0,                        // bus number
12560
                              `TAR0_IDSEL_INDEX - 11,   // device number
12561
                              0,                        // function number
12562
                              9,                        // register number
12563
                              0,                        // type of configuration cycle
12564
                              byte_enables,             // byte enables
12565
                              data                      // data
12566 15 mihad
                             ) ;
12567
 `endif
12568
`endif
12569
end
12570
endtask // configure_bridge_target_base_addresses
12571
 
12572
/*--------------------------------------------------------------------------
12573
Test CASES
12574
--------------------------------------------------------------------------*/
12575
 
12576
// function converts PCI address to WB with the same data as the pci_decoder does
12577
function [31:0] pci_to_wb_addr_convert ;
12578
 
12579
    input [31:0] pci_address ;
12580
    input [31:0] translation_address ;
12581
    input [31:0] translate ;
12582
 
12583
    reg   [31:0] temp_address ;
12584
begin
12585
    if ( translate !== 1 )
12586
    begin
12587
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12588
    end
12589
    else
12590
    begin
12591
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12592
    end
12593
 
12594
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12595
    pci_to_wb_addr_convert = temp_address ;
12596
end
12597
endfunction // pci_to_wb_addr_convert
12598
 
12599
// Test normal write and read to WB slave
12600
task test_normal_wr_rd;
12601
  input  [2:0]  Master_ID;
12602
  input  [PCI_BUS_DATA_RANGE:0] Address;
12603
  input  [PCI_BUS_DATA_RANGE:0] Data;
12604
  input  [3:0]  Be;
12605
  input  [2:0]  Image_num;
12606
  input  [9:0]  Set_size;
12607
  input         Set_addr_translation;
12608
  input         Set_prefetch_enable;
12609
  input  [7:0]  Cache_lsize;
12610
  input         Set_wb_wait_states;
12611
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12612
 
12613
  reg    [31:0] rd_address;
12614
  reg    [31:0] rd_data;
12615
  reg    [3:0]  rd_be;
12616
  reg    [11:0] addr_offset;
12617
  reg    [31:0] read_data;
12618
  reg           continue ;
12619
  reg           ok   ;
12620
  reg    [31:0] expect_address ;
12621
  reg    [31:0] expect_rd_address ;
12622
  reg           expect_we ;
12623
  reg    [9:0]  expect_length_wr ;
12624
  reg    [9:0]  expect_length_rd ;
12625
  reg    [9:0]  expect_length_rd1 ;
12626
  reg    [9:0]  expect_length_rd2 ;
12627
  reg    [3:0]  use_rd_cmd ;
12628
  integer       i ;
12629 35 mihad
  reg           error_monitor_done ;
12630 15 mihad
begin:main
12631
 
12632
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12633
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12634
    $display(" - errors will be reported, but they should not occur!");
12635
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12636
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12637
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12638
    if ( ok !== 1 )
12639
    begin
12640
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12641
        test_fail("write to P_ERR_CS register didn't succeede") ;
12642
        disable main;
12643
    end
12644
 
12645
    `ifdef  ADDR_TRAN_IMPL
12646
 
12647
    // set or clear address translation
12648
    if (Set_addr_translation)
12649
    begin
12650
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12651
        $display(" - address translation will be performed!");
12652
    end
12653
    else
12654
    begin
12655
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12656
        $display(" - address translation will not be performed!");
12657
    end
12658
    // set or clear pre-fetch enable
12659
    if (Set_prefetch_enable)
12660
    begin
12661
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12662
        $display(" - bursts can be performed!");
12663
    end
12664
    else
12665
    begin
12666
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12667
        $display(" - bursts can not be performed!");
12668
    end
12669
 
12670
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12671
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12672
    if ( ok !== 1 )
12673
    begin
12674
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12675
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12676
        disable main;
12677
    end
12678
 
12679
    // predict the address and control signals on WB bus
12680
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12681
    expect_we      = 1'b1 ; // WRITE
12682
 
12683
    `else
12684
 
12685
    // address translation is not implemented
12686
    $display("Address translation is NOT implemented for PCI images!");
12687
    // set or clear pre-fetch enable
12688
    if (Set_prefetch_enable)
12689
    begin
12690
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12691
        $display(" - bursts can be performed!");
12692
    end
12693
    else
12694
    begin
12695
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12696
        $display(" - bursts can not be performed!");
12697
    end
12698
 
12699
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12700
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12701
    if ( ok !== 1 )
12702
    begin
12703
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12704
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12705
        disable main;
12706
    end
12707
 
12708
    // predict the address and control signals on WB bus
12709
    expect_address = Address ;
12710
    expect_we      = 1'b1 ; // WRITE
12711
 
12712
    `endif
12713
 
12714
    // set WB SLAVE parameters
12715
    if (Set_wb_wait_states)
12716
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12717
    else
12718
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12719
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12720
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12721
 
12722
    if ( Set_size > (`PCIW_DEPTH - 2) )
12723
    begin
12724
        expect_length_wr = `PCIW_DEPTH - 2 ;
12725
    end
12726
    else
12727
    begin
12728
        expect_length_wr = Set_size ;
12729
    end
12730
    // write through the PCI bridge to WB slave
12731
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12732
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12733
 
12734
    fork
12735
    begin
12736
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12737
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12738
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12739
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12740
        do_pause( 1 ) ;
12741
    end
12742
    begin
12743
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12744
       if ( ok !== 1 )
12745
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12746
       else
12747
           test_ok ;
12748
    end
12749
    join
12750
 
12751
    // predict the address and control signals on WB bus
12752
    expect_we      = 1'b0 ; // READ
12753
 
12754
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12755
    $display("Memory read through PCI bridge to WB slave!");
12756
 
12757
    if ( expect_length_wr == 1 )
12758
    begin
12759
        if (Set_prefetch_enable)
12760
        begin
12761
            expect_length_rd1 = Cache_lsize ;
12762
            expect_length_rd2 = 0 ;
12763
                // If PCI behavioral master must check received DATA
12764
                master2_check_received_data = 0 ;
12765
                    master1_check_received_data = 0 ;
12766
        end
12767
        else
12768
        begin
12769
            expect_length_rd1 = 1 ;
12770
            expect_length_rd2 = 0 ;
12771
                // If PCI behavioral master must check received DATA
12772
                master2_check_received_data = 1 ;
12773
                    master1_check_received_data = 1 ;
12774
        end
12775
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12776
        expect_length_rd  = expect_length_rd1 ;
12777
    end
12778
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12779
    begin
12780
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12781
        expect_length_rd2 = 0 ;
12782
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12783
        expect_length_rd  = expect_length_rd1 ;
12784
                // If PCI behavioral master must check received DATA
12785
        master2_check_received_data = 1 ;
12786
            master1_check_received_data = 1 ;
12787
    end
12788
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12789
    begin
12790
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12791
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12792
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12793
        expect_length_rd  = expect_length_rd1 ;
12794
                // If PCI behavioral master must check received DATA
12795
                master2_check_received_data = 1 ;
12796
            master1_check_received_data = 1 ;
12797
    end
12798
    else
12799
    begin
12800
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12801
        begin
12802
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12803
            expect_length_rd2 = 0 ;
12804
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12805
            expect_length_rd  = expect_length_rd1 ;
12806
                // If PCI behavioral master must check received DATA
12807
                master2_check_received_data = 0 ;
12808
                    master1_check_received_data = 0 ;
12809
        end
12810
        else
12811
        begin
12812
            if ( expect_length_wr > Cache_lsize )
12813
            begin
12814
                expect_length_rd1 = Cache_lsize ;
12815
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12816
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12817
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12818
                else
12819
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12820
                expect_length_rd  = expect_length_rd1 ;
12821
                        // If PCI behavioral master must check received DATA
12822
                        master2_check_received_data = 1 ;
12823
                            master1_check_received_data = 1 ;
12824
            end
12825
            else
12826
            begin
12827
                expect_length_rd1 = Cache_lsize ;
12828
                expect_length_rd2 = 0 ;
12829
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12830
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12831
                else
12832
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12833
                expect_length_rd  = expect_length_wr ;
12834
                                if ( expect_length_wr == Cache_lsize )
12835
                        begin
12836
                                // If PCI behavioral master must check received DATA
12837
                                master2_check_received_data = 1 ;
12838
                                    master1_check_received_data = 1 ;
12839
                                end
12840
                                else
12841
                                begin
12842
                                // If PCI behavioral master must check received DATA
12843
                                master2_check_received_data = 0 ;
12844
                                    master1_check_received_data = 0 ;
12845
                end
12846
            end
12847
        end
12848
    end
12849
 
12850
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12851
    expect_rd_address = expect_address ;
12852
    rd_data[31:0] = Data[31:0];
12853
    rd_be[3:0] = Be[3:0];
12854
 
12855
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12856
    while (expect_length_rd2 > 0)
12857
    begin
12858
        // do read
12859
        $display("Read %d words!", expect_length_rd);
12860
 
12861
        fork
12862
        begin
12863
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12864
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12865
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12866
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12867
 
12868
            wb_transaction_stop( expect_length_rd - 1) ;
12869
 
12870
            do_pause( 1 ) ;
12871
        end
12872
        begin
12873
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12874
            if ( ok !== 1 )
12875
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12876
 
12877
            repeat( 3 )
12878
                @(posedge pci_clock) ;
12879
 
12880
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12881
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12882
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12883
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12884
 
12885
            do_pause( 1 ) ;
12886
            while ( FRAME === 0 )
12887
                @(posedge pci_clock) ;
12888
 
12889
            while ( IRDY === 0 )
12890
                @(posedge pci_clock) ;
12891
 
12892 35 mihad
            #1 ;
12893
            if ( !error_monitor_done )
12894
                disable monitor_error_event1 ;
12895 15 mihad
        end
12896
        begin:monitor_error_event1
12897 35 mihad
            error_monitor_done = 0 ;
12898 15 mihad
            @(error_event_int) ;
12899
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12900
            ok = 0 ;
12901 35 mihad
            error_monitor_done = 1 ;
12902 15 mihad
        end
12903
        join
12904
 
12905
        // increasing the starting address for PCI master and for WB transaction monitor
12906
        rd_address = rd_address + (4 * expect_length_rd) ;
12907
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12908
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12909
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12910
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12911
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12912
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12913
        for (i=0; i<expect_length_rd; i=i+1)
12914
            rd_be[3:0] = {Be[2:0], Be[3]};
12915
 
12916
        // set parameters for next read
12917
        if ( expect_length_rd2 == 1 )
12918
        begin
12919
                if (Set_prefetch_enable)
12920
                begin
12921
                    expect_length_rd1 = Cache_lsize ;
12922
                    expect_length_rd2 = 0 ;
12923
                        // If PCI behavioral master must check received DATA
12924
                        master2_check_received_data = 0 ;
12925
                            master1_check_received_data = 0 ;
12926
                end
12927
                else
12928
                begin
12929
                    expect_length_rd1 = 1 ;
12930
                    expect_length_rd2 = 0 ;
12931
                        // If PCI behavioral master must check received DATA
12932
                        master2_check_received_data = 1 ;
12933
                            master1_check_received_data = 1 ;
12934
                end
12935
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12936
            expect_length_rd  = expect_length_rd1 ;
12937
        end
12938
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12939
        begin
12940
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12941
            expect_length_rd2 = 0 ;
12942
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12943
            expect_length_rd  = expect_length_rd1 ;
12944
                        // If PCI behavioral master must check received DATA
12945
                        master2_check_received_data = 1 ;
12946
                    master1_check_received_data = 1 ;
12947
        end
12948
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12949
        begin
12950
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12951
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12952
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12953
            expect_length_rd  = expect_length_rd1 ;
12954
                        // If PCI behavioral master must check received DATA
12955
                        master2_check_received_data = 1 ;
12956
                    master1_check_received_data = 1 ;
12957
        end
12958
        else
12959
        begin
12960
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12961
            begin
12962
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12963
                expect_length_rd2 = 0 ;
12964
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12965
                expect_length_rd  = expect_length_rd1 ;
12966
                        // If PCI behavioral master must check received DATA
12967
                        master2_check_received_data = 0 ;
12968
                            master1_check_received_data = 0 ;
12969
            end
12970
            else
12971
            begin
12972
                if ( expect_length_rd2 > Cache_lsize )
12973
                begin
12974
                    expect_length_rd1 = Cache_lsize ;
12975
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12976
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12977
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12978
                    else
12979
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12980
                    expect_length_rd  = expect_length_rd1 ;
12981
                                // If PCI behavioral master must check received DATA
12982
                                master2_check_received_data = 1 ;
12983
                                    master1_check_received_data = 1 ;
12984
                end
12985
                else
12986
                begin
12987
                    expect_length_rd  = expect_length_rd2 ;
12988
                    expect_length_rd1 = Cache_lsize ;
12989
                    expect_length_rd2 = 0 ;
12990
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12991
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12992
                    else
12993
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12994
                                        if ( expect_length_rd2 == Cache_lsize )
12995
                                begin
12996
                                        // If PCI behavioral master must check received DATA
12997
                                        master2_check_received_data = 1 ;
12998
                                            master1_check_received_data = 1 ;
12999
                                        end
13000
                                        else
13001
                                        begin
13002
                                        // If PCI behavioral master must check received DATA
13003
                                        master2_check_received_data = 0 ;
13004
                                            master1_check_received_data = 0 ;
13005
                        end
13006
                end
13007
            end
13008
        end
13009
    end
13010
    // do last read
13011
    $display("Read %d words!", expect_length_rd);
13012
 
13013
    fork
13014
    begin
13015
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13016
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13017
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13018
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
13019
 
13020
        wb_transaction_stop(expect_length_rd - 1) ;
13021
        do_pause( 1 ) ;
13022
    end
13023
    begin
13024
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
13025
 
13026
        do_pause(3) ;
13027
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
13028
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
13029
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13030
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13031
        do_pause(1) ;
13032
 
13033
        while ( FRAME === 0 )
13034
            @(posedge pci_clock) ;
13035
 
13036
        while ( IRDY === 0 )
13037
            @(posedge pci_clock) ;
13038
 
13039 35 mihad
        #1 ;
13040
        if ( !error_monitor_done )
13041
            disable monitor_error_event2 ;
13042 15 mihad
    end
13043
    begin:monitor_error_event2
13044 35 mihad
        error_monitor_done = 0 ;
13045 15 mihad
        @(error_event_int) ;
13046
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13047
        ok = 0 ;
13048 35 mihad
        error_monitor_done = 1 ;
13049 15 mihad
    end
13050
    join
13051
 
13052
    if ( ok )
13053
        test_ok ;
13054
 
13055
    // Check that no ERRORs were reported
13056
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
13057
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
13058
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13059
    config_read( addr_offset, 4'hF, read_data ) ;
13060
    if ( read_data[8] !== 0 )
13061
    begin
13062
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
13063
        test_fail("error status was set even though no errors occured on WB bus") ;
13064
    end
13065
    else
13066
    begin
13067
        $display("No error was signaled, as expected!");
13068
        test_ok ;
13069
    end
13070
 
13071
end // main
13072
endtask // test_normal_wr_rd
13073
 
13074
// Test erroneous write to WB slave
13075
task test_wb_error_wr;
13076
  input  [2:0]  Master_ID;
13077
  input  [PCI_BUS_DATA_RANGE:0] Address;
13078
  input  [PCI_BUS_DATA_RANGE:0] Data;
13079
  input  [3:0]  Be;
13080
  input  [2:0]  Image_num;
13081
  input  [9:0]  Set_size;
13082
  input         Set_err_and_int_report;
13083
  input         Set_wb_wait_states;
13084
  input  [1:0]  Imm_BefLast_Last_error;
13085
 
13086
  reg    [11:0] addr_offset;
13087
  reg    [31:0] read_data;
13088
  reg           continue ;
13089
  reg           ok   ;
13090
  reg    [9:0]  expect_length ;
13091
  reg    [31:0] expect_address ;
13092
  reg    [0:0]  expect_we ;
13093
  reg    [31:0] rd_address;
13094
  reg    [31:0] rd_data;
13095
  reg    [3:0]  rd_be;
13096
  integer       i ;
13097
begin:main
13098
    if (Set_err_and_int_report)
13099
    begin
13100
        // enable ERROR reporting, because error must be reported and interrupt if required!
13101
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13102
        $display(" - errors will be reported when they will occur!");
13103
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
13104
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13105
        $display(" - interrupt will be reported when error will occur!");
13106
    end
13107
    else
13108
    begin
13109
        // disable ERROR reporting, because error and interrupt must not be reported!
13110
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13111
        $display(" - errors will NOT be reported when they will occur!");
13112
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
13113
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13114
        $display(" - interrupt will NOT be reported when error will occur!");
13115
    end
13116
    // enable/disable ERROR reporting
13117
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
13118
 
13119
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13120
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
13121
    if ( ok !== 1 )
13122
    begin
13123
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13124
        test_fail("PCI Error Control and Status register could not be written") ;
13125
        disable main;
13126
    end
13127
    // enable/disable INTERRUPT reporting
13128
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13129
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
13130
    if ( ok !== 1 )
13131
    begin
13132
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
13133
        test_fail("Interrupt Control register could not be written") ;
13134
        disable main;
13135
    end
13136
 
13137
    `ifdef  ADDR_TRAN_IMPL
13138
 
13139
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
13140
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13141
    config_read( addr_offset, 4'hF, read_data ) ;
13142
    if ( read_data[2] !== 0 )
13143
    begin
13144
        $display("Address translation is set for PCI image%d!", Image_num);
13145
        // predict the address and control signals on WB bus
13146
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13147
        expect_we      = 1'b1 ; // WRITE
13148
    end
13149
    else
13150
    begin
13151
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13152
        // predict the address and control signals on WB bus
13153
        expect_address = Address ;
13154
        expect_we      = 1'b1 ; // WRITE
13155
    end
13156
 
13157
    `else
13158
 
13159
    // address translation is not implemented
13160
    $display("Address translation is NOT implemented for PCI images!");
13161
    // predict the address and control signals on WB bus
13162
    expect_address = Address ;
13163
    expect_we      = 1'b1 ; // WRITE
13164
 
13165
    `endif
13166
 
13167
    if ( Set_size > (`PCIW_DEPTH - 2) )
13168
    begin
13169
        expect_length = `PCIW_DEPTH - 2 ;
13170
    end
13171
    else
13172
    begin
13173
        expect_length = Set_size ;
13174
    end
13175
 
13176
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13177
    begin
13178
        $display("ERR termination with first data!");
13179
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13180
    end
13181
    else if (Imm_BefLast_Last_error == 1)
13182
    begin
13183
        $display("ERR termination before last data!");
13184
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13185
    end
13186
    else
13187
    begin
13188
        $display("ERR termination with last data!");
13189
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13190
    end
13191
 
13192
    // write through the PCI bridge to WB slave
13193
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13194
    fork
13195
    begin
13196
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13197
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13198
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13199
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13200
        do_pause( 1 ) ;
13201
    end
13202
    begin
13203
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13204
        begin
13205
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13206
            if ( ok !== 1 )
13207
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13208
        end
13209
        else if (Imm_BefLast_Last_error == 1)
13210
        begin
13211
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 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
13216
        begin
13217
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 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
    end
13222
    begin
13223
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13224
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13225
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13226
        else if (Imm_BefLast_Last_error == 1)
13227
        begin
13228
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13229
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13230
            wb_transaction_stop(expect_length-2) ;
13231
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13232
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13233
        end
13234
        else
13235
        begin
13236
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13237
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13238
            wb_transaction_stop(expect_length-1) ;
13239
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13240
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13241
        end
13242
    end
13243
    join
13244
 
13245
    if ( ok )
13246
        test_ok ;
13247
 
13248
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13249
    begin
13250
        rd_data[31:0] = Data[31:0];
13251
        rd_address[31:0] = expect_address;
13252
        rd_be[3:0] = Be[3:0];
13253
    end
13254
    else if (Imm_BefLast_Last_error == 1)
13255
    begin
13256
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13257
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13258
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13259
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13260
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13261
        rd_be[3:0] = Be[3:0];
13262
        for (i=0; i<(expect_length-2); i=i+1)
13263
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13264
    end
13265
    else
13266
    begin
13267
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13268
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13269
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13270
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13271
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13272
        rd_be[3:0] = Be[3:0];
13273
        for (i=0; i<(expect_length-1); i=i+1)
13274
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13275
    end
13276
 
13277
    master2_check_received_data = 0 ;
13278
    master1_check_received_data = 0 ;
13279
 
13280
    // Check if ERRORs were reported
13281
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13282
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13283
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13284
 
13285
    ok = 1 ;
13286
    config_read( addr_offset, 4'hF, read_data ) ;
13287
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13288
    begin
13289
        $display("Error was signaled and reported, as expected!");
13290
        if (read_data[31:28] === rd_be)
13291
            $display("Byte enables written into P_ERR_CS register are as expected!");
13292
        else
13293
        begin
13294
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13295
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13296
            ok = 0 ;
13297
        end
13298
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13299
            $display("Bus command written into P_ERR_CS register is as expected!");
13300
        else
13301
        begin
13302
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13303
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13304
            ok = 0 ;
13305
        end
13306
 
13307
        if ( ok )
13308
            test_ok ;
13309
 
13310
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13311
 
13312
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13313
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13314
        config_read( addr_offset, 4'hF, read_data ) ;
13315
        if (read_data === rd_data)
13316
        begin
13317
            $display("Data written into P_ERR_DATA register is as expected!");
13318
            test_ok ;
13319
        end
13320
        else
13321
        begin
13322
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13323
            test_fail("PCI Erroneous Data register value was wrong") ;
13324
        end
13325
 
13326
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13327
 
13328
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13329
 
13330
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13331
        config_read( addr_offset, 4'hF, read_data ) ;
13332
        if (read_data === rd_address)
13333
        begin
13334
            $display("Address written into P_ERR_ADDR register is as expected!");
13335
            test_ok ;
13336
        end
13337
        else
13338
        begin
13339
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13340
            test_fail("PCI Erroneous Address register value was wrong") ;
13341
        end
13342
    end
13343
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13344
    begin
13345
        $display("Error was signaled and not reported, as expected!");
13346
        test_ok ;
13347
    end
13348
    else
13349
    begin
13350
        $display("Error was signaled and reported, as NOT expected!");
13351
        test_fail("Error status bit was set event though error reporting was disabled") ;
13352
    end
13353
 
13354
    // Check if Interrupts were reported
13355
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13356
 
13357
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13358
    ok = 1 ;
13359
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13360
    config_read( addr_offset, 4'hF, read_data ) ;
13361
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13362
    begin
13363
        $display("Interrupts was signaled and reported, as expected!");
13364
    end
13365
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13366
    begin
13367
        $display("Interrupts was signaled and not reported, as expected!");
13368
    end
13369
    else
13370
    begin
13371
        $display("Interrupt was signaled and reported, as NOT expected!");
13372
        test_fail("PCI Error Interrupt status was set when not expected") ;
13373
        ok = 0 ;
13374
    end
13375
 
13376
    `ifdef HOST
13377
    repeat( 4 )
13378
        @(posedge wb_clock) ;
13379
 
13380
    if ( INT_O === Set_err_and_int_report )
13381
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13382
    else
13383
    begin
13384
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13385
        test_fail("Interrupt request didn't have expected value") ;
13386
        ok = 0 ;
13387
    end
13388
 
13389
    `else // GUEST
13390
    repeat( 4 )
13391
        @(posedge pci_clock) ;
13392
 
13393
    if ( INTA === !Set_err_and_int_report )
13394
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13395
    else
13396
    begin
13397
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13398
        test_fail("Interrupt request didn't have expected value") ;
13399
        ok = 0 ;
13400
    end
13401
 
13402
    `endif
13403
 
13404
    if ( ok )
13405
        test_ok ;
13406
 
13407
    if (Set_err_and_int_report)
13408
    begin
13409
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13410
        $display("Error and Interrupt must be cleared!");
13411
        // clear  ERROR reporting bit
13412
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13413
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13414
        if ( ok !== 1 )
13415
        begin
13416
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13417
            test_fail("PCI Error Control and Status register could not be written to") ;
13418
            disable main;
13419
        end
13420
 
13421
        // clear INTERRUPT reporting bit
13422
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13423
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13424
        if ( ok !== 1 )
13425
        begin
13426
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13427
            test_fail("Interrupt Status register could not be written to") ;
13428
            disable main;
13429
        end
13430
 
13431
        test_ok ;
13432
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13433
        `ifdef HOST
13434
 
13435
        repeat(4)
13436
            @(posedge wb_clock) ;
13437
        if ( INT_O === 1'b0 )
13438
        begin
13439
            $display("Interrupt pin INT_O was correctly cleared!");
13440
            test_ok ;
13441
        end
13442
        else
13443
        begin
13444
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13445
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13446
            disable main;
13447
        end
13448
 
13449
        `else // GUEST
13450
 
13451
        repeat(4)
13452
            @(posedge pci_clock) ;
13453
        if ( INTA === 1'b1 )
13454
        begin
13455
            $display("Interrupt pin INTA was correctly cleared!");
13456
            test_ok ;
13457
        end
13458
        else
13459
        begin
13460
            $display("Interrupt pin INTA was NOT correctly cleared!");
13461
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13462
            disable main;
13463
        end
13464
 
13465
        `endif
13466
 
13467
    end
13468
    else
13469
    begin
13470
        $display("Error and Interrupt don't need to be cleared!");
13471
    end
13472
end // main
13473
endtask // test_wb_error_wr
13474
 
13475
task test_wb_error_rd;
13476
    reg    [11:0] addr_offset ;
13477
    reg    [11:0] ctrl_offset ;
13478
    reg    [11:0] ba_offset ;
13479
    reg    [11:0] am_offset ;
13480
    reg    [11:0] ta_offset ;
13481
    reg    [31:0] read_data;
13482
    reg           ok   ;
13483
    reg    [9:0]  expect_length ;
13484
    reg    [31:0] expect_address ;
13485
    reg    [0:0]  expect_we ;
13486
    reg    [31:0] rd_address;
13487
    reg    [31:0] rd_data;
13488
    reg    [3:0]  rd_be;
13489
    integer       i ;
13490
    reg           do_mem_aborts ;
13491
    reg           do_io_aborts ;
13492 35 mihad
    reg           error_monitor_done ;
13493 15 mihad
begin:main
13494
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13495
 
13496
    if ( target_mem_image !== -1 )
13497
    begin
13498
        do_mem_aborts = 1 ;
13499
 
13500
        if (target_mem_image === 1)
13501
        begin
13502
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13503
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13504
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13505
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13506
        end
13507
        else if (target_mem_image === 2)
13508
        begin
13509
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13510
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13511
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13512
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13513
        end
13514
        else if (target_mem_image === 3)
13515
        begin
13516
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13517
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13518
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13519
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13520
        end
13521
        else if (target_mem_image === 4)
13522
        begin
13523
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13524
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13525
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13526
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13527
        end
13528
        else if (target_mem_image === 5)
13529
        begin
13530
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13531
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13532
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13533
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13534
        end
13535
    end
13536
    else
13537
        do_mem_aborts = 0 ;
13538
 
13539
    if ( do_mem_aborts )
13540
    begin
13541
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13542
 
13543
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13544
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13545
        if ( ok !== 1 )
13546
        begin
13547
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13548
            test_fail("PCI Error Control and Status register could not be written") ;
13549
            disable main;
13550
        end
13551
 
13552
        // enable INTERRUPT reporting
13553
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13554
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13555
        if ( ok !== 1 )
13556
        begin
13557
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13558
            test_fail("Interrupt Control register could not be written") ;
13559
            disable main;
13560
        end
13561
 
13562
        addr_offset = 12'h010 + (4*target_mem_image) ;
13563
 
13564
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13565
        if ( ok !== 1 )
13566
        begin
13567
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13568
            test_fail("PCI Base Address register could not be written") ;
13569
            disable main;
13570
        end
13571
 
13572
        // disable address translation and enable prefetch so read bursts can be performed
13573
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13574
        if ( ok !== 1 )
13575
        begin
13576
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13577
            test_fail("PCI Image Control register could not be written") ;
13578
            disable main;
13579
        end
13580
 
13581
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13582
        if ( ok !== 1 )
13583
        begin
13584
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13585
            test_fail("PCI Address Mask register could not be written") ;
13586
            disable main;
13587
        end
13588
 
13589
        addr_offset = 12'h00C ;
13590
 
13591
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13592
        if ( ok !== 1 )
13593
        begin
13594
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13595
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13596
            disable main;
13597
        end
13598
 
13599
        // disable PCI master data checking
13600
        master1_check_received_data = 0 ;
13601
 
13602
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13603
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13604
 
13605
 
13606
        // do a single read error terminated on WB bus
13607
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13608
 
13609
        fork
13610
        begin
13611
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13612
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13613
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13614
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13615
 
13616
            do_pause( 1 ) ;
13617
        end
13618
        begin
13619
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13620
 
13621
            if ( ok !== 1 )
13622
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13623
 
13624
            do_pause(3) ;
13625
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13626
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13627
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13628
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13629
            do_pause(1) ;
13630
 
13631
            while ( FRAME === 0 )
13632
                @(posedge pci_clock) ;
13633
 
13634
            while ( IRDY === 0 )
13635
                @(posedge pci_clock) ;
13636
 
13637 35 mihad
            #1 ;
13638
            if ( !error_monitor_done )
13639
                disable monitor_error_event1 ;
13640 15 mihad
        end
13641
        begin:monitor_error_event1
13642 35 mihad
            error_monitor_done = 0 ;
13643 15 mihad
            @(error_event_int) ;
13644
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13645
            ok = 0 ;
13646 35 mihad
            error_monitor_done = 1 ;
13647 15 mihad
        end
13648
        join
13649
 
13650
        if ( ok )
13651
            test_ok ;
13652 26 mihad
 
13653
        @(posedge pci_clock) ;
13654
        @(posedge pci_clock) ;
13655
        @(posedge wb_clock) ;
13656
        @(posedge wb_clock) ;
13657 15 mihad
 
13658
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13659
        addr_offset = 12'h004 ;
13660
        config_read(addr_offset, 4'hF, read_data) ;
13661
        ok = 1 ;
13662
        if ( read_data[27] !== 1 )
13663
        begin
13664
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13665
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13666
            ok = 0 ;
13667
        end
13668
        if ( read_data[28] !== 0 )
13669
        begin
13670
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13671
            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") ;
13672
            ok = 0 ;
13673
        end
13674
        if ( read_data[29] !== 0 )
13675
        begin
13676
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13677
            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") ;
13678
            ok = 0 ;
13679
        end
13680
 
13681
        // clear statuses
13682
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13683
        if ( !ok )
13684
        begin
13685
            test_fail("write to PCI Device Status register failed") ;
13686
            $display("Couldn't write PCI Device Status register") ;
13687
            disable main ;
13688
        end
13689
 
13690
        if ( ok )
13691
            test_ok ;
13692
 
13693
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13694
 
13695
        ok = 1 ;
13696
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13697
 
13698
        config_read(addr_offset, 4'hF, read_data) ;
13699
        if (read_data[8] !== 0)
13700
        begin
13701
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13702
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13703
            ok = 0 ;
13704
        end
13705
        else
13706
            test_ok ;
13707
 
13708
        if ( ok !== 1 )
13709
        begin
13710
            config_write(addr_offset, read_data, 4'hF, ok) ;
13711
            if ( !ok )
13712
            begin
13713
                test_fail("PCI Error Control and Status register could not be written") ;
13714
                disable main ;
13715
            end
13716
        end
13717
 
13718
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13719
        fork
13720
        begin
13721
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13722
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13723
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13724
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13725
 
13726
            do_pause( 1 ) ;
13727
        end
13728
        begin
13729
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13730
 
13731
            if ( ok !== 1 )
13732
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13733
 
13734
            do_pause(3) ;
13735
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13736
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13737
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13738
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13739
            do_pause(1) ;
13740
 
13741
            while ( FRAME === 0 )
13742
                @(posedge pci_clock) ;
13743
 
13744
            while ( IRDY === 0 )
13745
                @(posedge pci_clock) ;
13746
 
13747 35 mihad
            #1 ;
13748
            if ( !error_monitor_done )
13749
                disable monitor_error_event2 ;
13750 15 mihad
        end
13751
        begin:monitor_error_event2
13752 35 mihad
            error_monitor_done = 0 ;
13753 15 mihad
            @(error_event_int) ;
13754
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13755
            ok = 0 ;
13756 35 mihad
            error_monitor_done = 1 ;
13757 15 mihad
        end
13758
        join
13759
 
13760
        if ( ok )
13761
            test_ok ;
13762
 
13763 26 mihad
        @(posedge pci_clock) ;
13764
        @(posedge pci_clock) ;
13765
        @(posedge wb_clock) ;
13766
        @(posedge wb_clock) ;
13767
 
13768 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13769
        addr_offset = 12'h004 ;
13770
        config_read(addr_offset, 4'hF, read_data) ;
13771
        ok = 1 ;
13772
        if ( read_data[27] !== 1 )
13773
        begin
13774
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13775
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13776
            ok = 0 ;
13777
        end
13778
        if ( read_data[28] !== 0 )
13779
        begin
13780
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13781
            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") ;
13782
            ok = 0 ;
13783
        end
13784
        if ( read_data[29] !== 0 )
13785
        begin
13786
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13787
            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") ;
13788
            ok = 0 ;
13789
        end
13790
 
13791
        // clear statuses
13792
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13793
        if ( !ok )
13794
        begin
13795
            test_fail("write to PCI Device Status register failed") ;
13796
            $display("Couldn't write PCI Device Status register") ;
13797
            disable main ;
13798
        end
13799
 
13800
        if ( ok )
13801
            test_ok ;
13802
 
13803
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13804
 
13805
        ok = 1 ;
13806
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13807
 
13808
        config_read(addr_offset, 4'hF, read_data) ;
13809
        if (read_data[8] !== 0)
13810
        begin
13811
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13812
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13813
            ok = 0 ;
13814
        end
13815
        else
13816
            test_ok ;
13817
 
13818
        if ( ok !== 1 )
13819
        begin
13820
            config_write(addr_offset, read_data, 4'hF, ok) ;
13821
            if ( !ok )
13822
            begin
13823
                test_fail("PCI Error Control and Status register could not be written") ;
13824
                disable main ;
13825
            end
13826
        end
13827
 
13828
        // do a single read error terminated on WB bus
13829
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13830
 
13831
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13832
 
13833
        fork
13834
        begin
13835
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13836
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13837
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13838
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13839
 
13840
            do_pause( 1 ) ;
13841
        end
13842
        begin
13843
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13844
 
13845
            if ( ok !== 1 )
13846
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13847
 
13848
            do_pause(3) ;
13849
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13850
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13851
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13852
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13853
            do_pause(1) ;
13854
 
13855
            while ( FRAME === 0 )
13856
                @(posedge pci_clock) ;
13857
 
13858
            while ( IRDY === 0 )
13859
                @(posedge pci_clock) ;
13860
 
13861 35 mihad
            if ( !error_monitor_done )
13862
                disable monitor_error_event3 ;
13863 15 mihad
        end
13864
        begin:monitor_error_event3
13865 35 mihad
            error_monitor_done = 0 ;
13866 15 mihad
            @(error_event_int) ;
13867
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13868
            ok = 0 ;
13869 35 mihad
            error_monitor_done = 1 ;
13870 15 mihad
        end
13871
        join
13872
 
13873
        if ( ok )
13874
            test_ok ;
13875
 
13876 26 mihad
        @(posedge pci_clock) ;
13877
        @(posedge pci_clock) ;
13878
        @(posedge wb_clock) ;
13879
        @(posedge wb_clock) ;
13880
 
13881 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13882
        addr_offset = 12'h004 ;
13883
        config_read(addr_offset, 4'hF, read_data) ;
13884
        ok = 1 ;
13885
        if ( read_data[27] !== 1 )
13886
        begin
13887
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13888
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13889
            ok = 0 ;
13890
        end
13891
        if ( read_data[28] !== 0 )
13892
        begin
13893
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13894
            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") ;
13895
            ok = 0 ;
13896
        end
13897
        if ( read_data[29] !== 0 )
13898
        begin
13899
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13900
            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") ;
13901
            ok = 0 ;
13902
        end
13903
 
13904
        // clear statuses
13905
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13906
        if ( !ok )
13907
        begin
13908
            test_fail("write to PCI Device Status register failed") ;
13909
            $display("Couldn't write PCI Device Status register") ;
13910
            disable main ;
13911
        end
13912
 
13913
        if ( ok )
13914
            test_ok ;
13915
 
13916
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13917
 
13918
        ok = 1 ;
13919
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13920
 
13921
        config_read(addr_offset, 4'hF, read_data) ;
13922
        if (read_data[8] !== 0)
13923
        begin
13924
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13925
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13926
            ok = 0 ;
13927
        end
13928
        else
13929
            test_ok ;
13930
 
13931
        if ( ok !== 1 )
13932
        begin
13933
            config_write(addr_offset, read_data, 4'hF, ok) ;
13934
            if ( !ok )
13935
            begin
13936
                test_fail("PCI Error Control and Status register could not be written") ;
13937
                disable main ;
13938
            end
13939
        end
13940
 
13941
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13942
 
13943
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13944
 
13945
        fork
13946
        begin
13947
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13948
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13949
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13950
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13951
 
13952
            do_pause( 1 ) ;
13953
        end
13954
        begin
13955
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13956
 
13957
            if ( ok !== 1 )
13958
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13959
 
13960
            do_pause(3) ;
13961
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13962
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13963
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13964
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13965
            do_pause(1) ;
13966
 
13967
            while ( FRAME === 0 )
13968
                @(posedge pci_clock) ;
13969
 
13970
            while ( IRDY === 0 )
13971
                @(posedge pci_clock) ;
13972
 
13973 35 mihad
            #1 ;
13974
            if ( !error_monitor_done )
13975
                disable monitor_error_event4 ;
13976 15 mihad
        end
13977
        begin:monitor_error_event4
13978 35 mihad
            error_monitor_done = 0 ;
13979 15 mihad
            @(error_event_int) ;
13980
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13981
            ok = 0 ;
13982 35 mihad
            error_monitor_done = 1 ;
13983 15 mihad
        end
13984
        begin
13985
            wb_transaction_stop( 1 ) ;
13986
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13987
        end
13988
        join
13989
 
13990
        if ( ok )
13991
            test_ok ;
13992
 
13993 26 mihad
        @(posedge pci_clock) ;
13994
        @(posedge pci_clock) ;
13995
        @(posedge wb_clock) ;
13996
        @(posedge wb_clock) ;
13997
 
13998 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13999
        addr_offset = 12'h004 ;
14000
        config_read(addr_offset, 4'hF, read_data) ;
14001
        ok = 1 ;
14002
        if ( read_data[27] !== 1 )
14003
        begin
14004
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14005
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14006
            ok = 0 ;
14007
        end
14008
        if ( read_data[28] !== 0 )
14009
        begin
14010
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14011
            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") ;
14012
            ok = 0 ;
14013
        end
14014
        if ( read_data[29] !== 0 )
14015
        begin
14016
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14017
            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") ;
14018
            ok = 0 ;
14019
        end
14020
 
14021
        // clear statuses
14022
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14023
        if ( !ok )
14024
        begin
14025
            test_fail("write to PCI Device Status register failed") ;
14026
            $display("Couldn't write PCI Device Status register") ;
14027
            disable main ;
14028
        end
14029
 
14030
        if ( ok )
14031
            test_ok ;
14032
 
14033
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14034
 
14035
        ok = 1 ;
14036
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14037
 
14038
        config_read(addr_offset, 4'hF, read_data) ;
14039
        if (read_data[8] !== 0)
14040
        begin
14041
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14042
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14043
            ok = 0 ;
14044
        end
14045
        else
14046
            test_ok ;
14047
 
14048
        if ( ok !== 1 )
14049
        begin
14050
            config_write(addr_offset, read_data, 4'hF, ok) ;
14051
            if ( !ok )
14052
            begin
14053
                test_fail("PCI Error Control and Status register could not be written") ;
14054
                disable main ;
14055
            end
14056
        end
14057
 
14058
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14059
 
14060
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14061
 
14062
        fork
14063
        begin
14064
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14065
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14066
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14067
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14068
 
14069
            do_pause( 1 ) ;
14070
        end
14071
        begin
14072
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14073
 
14074
            if ( ok !== 1 )
14075
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14076
 
14077
            do_pause(3) ;
14078
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14079
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14080
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14081
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14082
            do_pause(1) ;
14083
 
14084
            while ( FRAME === 0 )
14085
                @(posedge pci_clock) ;
14086
 
14087
            while ( IRDY === 0 )
14088
                @(posedge pci_clock) ;
14089
 
14090 35 mihad
            #1 ;
14091
            if ( !error_monitor_done )
14092
                disable monitor_error_event5 ;
14093 15 mihad
        end
14094
        begin:monitor_error_event5
14095 35 mihad
            error_monitor_done = 0 ;
14096 15 mihad
            @(error_event_int) ;
14097
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14098
            ok = 0 ;
14099 35 mihad
            error_monitor_done = 1 ;
14100 15 mihad
        end
14101
        begin
14102
            wb_transaction_stop( 3 ) ;
14103
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14104
        end
14105
        join
14106
 
14107
        if ( ok )
14108
            test_ok ;
14109
 
14110 26 mihad
        @(posedge pci_clock) ;
14111
        @(posedge pci_clock) ;
14112
        @(posedge wb_clock) ;
14113
        @(posedge wb_clock) ;
14114
 
14115 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14116
        addr_offset = 12'h004 ;
14117
        config_read(addr_offset, 4'hF, read_data) ;
14118
        ok = 1 ;
14119
        if ( read_data[27] !== 1 )
14120
        begin
14121
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14122
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14123
            ok = 0 ;
14124
        end
14125
        if ( read_data[28] !== 0 )
14126
        begin
14127
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14128
            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") ;
14129
            ok = 0 ;
14130
        end
14131
        if ( read_data[29] !== 0 )
14132
        begin
14133
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14134
            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") ;
14135
            ok = 0 ;
14136
        end
14137
 
14138
        // clear statuses
14139
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14140
        if ( !ok )
14141
        begin
14142
            test_fail("write to PCI Device Status register failed") ;
14143
            $display("Couldn't write PCI Device Status register") ;
14144
            disable main ;
14145
        end
14146
 
14147
        if ( ok )
14148
            test_ok ;
14149
 
14150
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14151
 
14152
        ok = 1 ;
14153
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14154
 
14155
        config_read(addr_offset, 4'hF, read_data) ;
14156
        if (read_data[8] !== 0)
14157
        begin
14158
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14159
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14160
            ok = 0 ;
14161
        end
14162
        else
14163
            test_ok ;
14164
 
14165
        if ( ok !== 1 )
14166
        begin
14167
            config_write(addr_offset, read_data, 4'hF, ok) ;
14168
            if ( !ok )
14169
            begin
14170
                test_fail("PCI Error Control and Status register could not be written") ;
14171
                disable main ;
14172
            end
14173
        end
14174
 
14175
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14176
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14177
        fork
14178
        begin
14179
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14180
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14181
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14182
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14183
 
14184
            do_pause( 1 ) ;
14185
        end
14186
        begin
14187
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14188
 
14189
            if ( ok !== 1 )
14190
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14191
 
14192
            do_pause(3) ;
14193
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14194
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14195
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14196
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14197
            do_pause(1) ;
14198
 
14199
            while ( FRAME === 0 )
14200
                @(posedge pci_clock) ;
14201
 
14202
            while ( IRDY === 0 )
14203
                @(posedge pci_clock) ;
14204
 
14205 35 mihad
            #1 ;
14206
            if ( !error_monitor_done )
14207
                disable monitor_error_event6 ;
14208 15 mihad
        end
14209
        begin:monitor_error_event6
14210 35 mihad
            error_monitor_done = 0 ;
14211 15 mihad
            @(error_event_int) ;
14212
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14213
            ok = 0 ;
14214 35 mihad
            error_monitor_done = 1 ;
14215 15 mihad
        end
14216
        begin
14217
            wb_transaction_stop( 3 ) ;
14218
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14219
        end
14220
        join
14221
 
14222
        if ( ok )
14223
            test_ok ;
14224
 
14225 26 mihad
        @(posedge pci_clock) ;
14226
        @(posedge pci_clock) ;
14227
        @(posedge wb_clock) ;
14228
        @(posedge wb_clock) ;
14229
 
14230 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14231
        addr_offset = 12'h004 ;
14232
        config_read(addr_offset, 4'hF, read_data) ;
14233
        ok = 1 ;
14234
        if ( read_data[27] !== 1 )
14235
        begin
14236
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14237
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14238
            ok = 0 ;
14239
        end
14240
        if ( read_data[28] !== 0 )
14241
        begin
14242
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14243
            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") ;
14244
            ok = 0 ;
14245
        end
14246
        if ( read_data[29] !== 0 )
14247
        begin
14248
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14249
            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") ;
14250
            ok = 0 ;
14251
        end
14252
 
14253
        // clear statuses
14254
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14255
        if ( !ok )
14256
        begin
14257
            test_fail("write to PCI Device Status register failed") ;
14258
            $display("Couldn't write PCI Device Status register") ;
14259
            disable main ;
14260
        end
14261
 
14262
        if ( ok )
14263
            test_ok ;
14264
 
14265
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14266
 
14267
        ok = 1 ;
14268
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14269
 
14270
        config_read(addr_offset, 4'hF, read_data) ;
14271
        if (read_data[8] !== 0)
14272
        begin
14273
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14274
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14275
            ok = 0 ;
14276
        end
14277
        else
14278
            test_ok ;
14279
 
14280
        if ( ok !== 1 )
14281
        begin
14282
            config_write(addr_offset, read_data, 4'hF, ok) ;
14283
            if ( !ok )
14284
            begin
14285
                test_fail("PCI Error Control and Status register could not be written") ;
14286
                disable main ;
14287
            end
14288
        end
14289
 
14290
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14291
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14292
        fork
14293
        begin
14294
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14295
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14296
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14297
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14298
 
14299
            do_pause( 1 ) ;
14300
        end
14301
        begin
14302
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14303
 
14304
            if ( ok !== 1 )
14305
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14306
 
14307
            do_pause(3) ;
14308
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14309
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14310
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14311
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14312
            do_pause(1) ;
14313
 
14314
            while ( FRAME === 0 )
14315
                @(posedge pci_clock) ;
14316
 
14317
            while ( IRDY === 0 )
14318
                @(posedge pci_clock) ;
14319
 
14320 35 mihad
            #1 ;
14321
            if ( !error_monitor_done )
14322
                disable monitor_error_event7 ;
14323 15 mihad
        end
14324
        begin:monitor_error_event7
14325 35 mihad
            error_monitor_done = 0 ;
14326 15 mihad
            @(error_event_int) ;
14327
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14328
            ok = 0 ;
14329 35 mihad
            error_monitor_done = 1 ;
14330 15 mihad
        end
14331
        begin
14332
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14333
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14334
        end
14335
        join
14336
 
14337
        if ( ok )
14338
            test_ok ;
14339
 
14340 26 mihad
        @(posedge pci_clock) ;
14341
        @(posedge pci_clock) ;
14342
        @(posedge wb_clock) ;
14343
        @(posedge wb_clock) ;
14344
 
14345 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14346
        addr_offset = 12'h004 ;
14347
        config_read(addr_offset, 4'hF, read_data) ;
14348
        ok = 1 ;
14349
        if ( read_data[27] !== 1 )
14350
        begin
14351
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14352
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14353
            ok = 0 ;
14354
        end
14355
        if ( read_data[28] !== 0 )
14356
        begin
14357
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14358
            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") ;
14359
            ok = 0 ;
14360
        end
14361
        if ( read_data[29] !== 0 )
14362
        begin
14363
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14364
            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") ;
14365
            ok = 0 ;
14366
        end
14367
 
14368
        // clear statuses
14369
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14370
        if ( !ok )
14371
        begin
14372
            test_fail("write to PCI Device Status register failed") ;
14373
            $display("Couldn't write PCI Device Status register") ;
14374
            disable main ;
14375
        end
14376
 
14377
        if ( ok )
14378
            test_ok ;
14379
 
14380
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14381
 
14382
        ok = 1 ;
14383
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14384
 
14385
        config_read(addr_offset, 4'hF, read_data) ;
14386
        if (read_data[8] !== 0)
14387
        begin
14388
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14389
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14390
            ok = 0 ;
14391
        end
14392
        else
14393
            test_ok ;
14394
 
14395
        if ( ok !== 1 )
14396
        begin
14397
            config_write(addr_offset, read_data, 4'hF, ok) ;
14398
            if ( !ok )
14399
            begin
14400
                test_fail("PCI Error Control and Status register could not be written") ;
14401
                disable main ;
14402
            end
14403
        end
14404
 
14405
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14406
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14407
        fork
14408
        begin
14409
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14410
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14411
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14412
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14413
 
14414
            do_pause( 1 ) ;
14415
        end
14416
        begin
14417
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14418
 
14419
            if ( ok !== 1 )
14420
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14421
 
14422
            do_pause(3) ;
14423
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14424
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14425
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14426
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14427
            do_pause(1) ;
14428
 
14429
            while ( FRAME === 0 )
14430
                @(posedge pci_clock) ;
14431
 
14432
            while ( IRDY === 0 )
14433
                @(posedge pci_clock) ;
14434
 
14435 35 mihad
            #1 ;
14436
            if ( !error_monitor_done )
14437
                disable monitor_error_event8 ;
14438 15 mihad
        end
14439
        begin:monitor_error_event8
14440 35 mihad
            error_monitor_done = 0 ;
14441 15 mihad
            @(error_event_int) ;
14442
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14443
            ok = 0 ;
14444 35 mihad
            error_monitor_done = 1 ;
14445 15 mihad
        end
14446
        begin
14447
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14448
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14449
        end
14450
        join
14451
 
14452
        if ( ok )
14453
            test_ok ;
14454
 
14455 26 mihad
        @(posedge pci_clock) ;
14456
        @(posedge pci_clock) ;
14457
        @(posedge wb_clock) ;
14458
        @(posedge wb_clock) ;
14459
 
14460 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14461
 
14462
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14463
        addr_offset = 12'h004 ;
14464
        config_read(addr_offset, 4'hF, read_data) ;
14465
        ok = 1 ;
14466
        if ( read_data[27] !== 1 )
14467
        begin
14468
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14469
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14470
            ok = 0 ;
14471
        end
14472
        if ( read_data[28] !== 0 )
14473
        begin
14474
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14475
            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") ;
14476
            ok = 0 ;
14477
        end
14478
        if ( read_data[29] !== 0 )
14479
        begin
14480
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14481
            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") ;
14482
            ok = 0 ;
14483
        end
14484
 
14485
        // clear statuses
14486
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14487
        if ( !ok )
14488
        begin
14489
            test_fail("write to PCI Device Status register failed") ;
14490
            $display("Couldn't write PCI Device Status register") ;
14491
            disable main ;
14492
        end
14493
 
14494
        if ( ok )
14495
            test_ok ;
14496
 
14497
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14498
 
14499
        ok = 1 ;
14500
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14501
 
14502
        config_read(addr_offset, 4'hF, read_data) ;
14503
        if (read_data[8] !== 0)
14504
        begin
14505
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14506
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14507
            ok = 0 ;
14508
        end
14509
        else
14510
            test_ok ;
14511
 
14512
        if ( ok !== 1 )
14513
        begin
14514
            config_write(addr_offset, read_data, 4'hF, ok) ;
14515
            if ( !ok )
14516
            begin
14517
                test_fail("PCI Error Control and Status register could not be written") ;
14518
                disable main ;
14519
            end
14520
        end
14521
 
14522
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14523
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14524
        fork
14525
        begin
14526
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14527
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14528
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14529
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14530
 
14531
            do_pause( 1 ) ;
14532
        end
14533
        begin
14534
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14535
 
14536
            if ( ok !== 1 )
14537
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14538
 
14539
            do_pause(3) ;
14540
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14541
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14542
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14543
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14544
            do_pause(1) ;
14545
 
14546
            while ( FRAME === 0 )
14547
                @(posedge pci_clock) ;
14548
 
14549
            while ( IRDY === 0 )
14550
                @(posedge pci_clock) ;
14551
 
14552 35 mihad
            #1 ;
14553
            if ( !error_monitor_done )
14554
                disable monitor_error_event9 ;
14555 15 mihad
        end
14556
        begin:monitor_error_event9
14557 35 mihad
            error_monitor_done = 0 ;
14558 15 mihad
            @(error_event_int) ;
14559
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14560
            ok = 0 ;
14561 35 mihad
            error_monitor_done = 1 ;
14562 15 mihad
        end
14563
        begin
14564
            wb_transaction_stop( 3 ) ;
14565
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14566
        end
14567
        join
14568
 
14569
        if ( ok )
14570
            test_ok ;
14571
 
14572
        // now check all other statuses too
14573
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14574
        ok = 1 ;
14575
 
14576
        addr_offset = 12'h004 ;
14577
        config_read(addr_offset, 4'hF, read_data) ;
14578
        if (read_data[31] !== 0)
14579
        begin
14580
            $display("Detected Parity Error bit set for no reason") ;
14581
            test_fail("Detected Parity Error bit was set for no reason") ;
14582
            ok = 0 ;
14583
        end
14584
 
14585
        if (read_data[30] !== 0)
14586
        begin
14587
            $display("Signaled System Error bit set for no reason") ;
14588
            test_fail("Signaled System Error bit was set for no reason") ;
14589
            ok = 0 ;
14590
        end
14591
 
14592
        if (read_data[29] !== 0)
14593
        begin
14594
            $display("Received Master Abort bit set for no reason") ;
14595
            test_fail("Received Master Abort bit was set for no reason") ;
14596
            ok = 0 ;
14597
        end
14598
 
14599
        if (read_data[28] !== 0)
14600
        begin
14601
            $display("Received Target Abort bit set for no reason");
14602
            test_fail("Received Target Abort bit was set for no reason") ;
14603
            ok = 0 ;
14604
        end
14605
 
14606
        if (read_data[27] !== 0)
14607
        begin
14608
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14609
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14610
            ok = 0 ;
14611
        end
14612
 
14613
        if (read_data[24] !== 0)
14614
        begin
14615
            $display("Master Data Parity Error bit set for no reason") ;
14616
            test_fail("Master Data Parity Error bit was set for no reason") ;
14617
            ok = 0 ;
14618
        end
14619
 
14620
        if ( ok )
14621
            test_ok ;
14622
 
14623
        test_name = "DISABLE IMAGE" ;
14624 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14625 15 mihad
        if ( ok !== 1 )
14626
        begin
14627
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14628
            test_fail("PCI Address Mask register could not be written") ;
14629
            disable main;
14630
        end
14631
    end
14632
 
14633
    if ( target_io_image !== -1 )
14634
    begin
14635
        do_io_aborts = 1 ;
14636
 
14637
        if (target_io_image === 1)
14638
        begin
14639
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14640
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14641
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14642
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14643
        end
14644
        else if (target_io_image === 2)
14645
        begin
14646
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14647
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14648
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14649
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14650
        end
14651
        else if (target_io_image === 3)
14652
        begin
14653
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14654
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14655
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14656
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14657
        end
14658
        else if (target_io_image === 4)
14659
        begin
14660
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14661
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14662
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14663
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14664
        end
14665
        else if (target_io_image === 5)
14666
        begin
14667
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14668
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14669
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14670
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14671
        end
14672
    end
14673
    else
14674
        do_io_aborts = 0 ;
14675
 
14676
    if ( do_io_aborts )
14677
    begin
14678
 
14679
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14680
 
14681
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14682
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14683
        if ( ok !== 1 )
14684
        begin
14685
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14686
            test_fail("PCI Error Control and Status register could not be written") ;
14687
            disable main;
14688
        end
14689
 
14690
        // enable INTERRUPT reporting
14691
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14692
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14693
        if ( ok !== 1 )
14694
        begin
14695
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14696
            test_fail("Interrupt Control register could not be written") ;
14697
            disable main;
14698
        end
14699
 
14700
        addr_offset = 12'h010 + (4*target_io_image) ;
14701
 
14702
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14703
        if ( ok !== 1 )
14704
        begin
14705
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14706
            test_fail("PCI Base Address register could not be written") ;
14707
            disable main;
14708
        end
14709
 
14710
        // disable address translation and enable prefetch so read bursts can be performed
14711
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14712
        if ( ok !== 1 )
14713
        begin
14714
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14715
            test_fail("PCI Image Control register could not be written") ;
14716
            disable main;
14717
        end
14718
 
14719
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14720
        if ( ok !== 1 )
14721
        begin
14722
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14723
            test_fail("PCI Address Mask register could not be written") ;
14724
            disable main;
14725
        end
14726
 
14727
        addr_offset = 12'h00C ;
14728
 
14729
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14730
        if ( ok !== 1 )
14731
        begin
14732
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14733
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14734
            disable main;
14735
        end
14736
 
14737
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14738
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14739
 
14740
        // do a single read error terminated on WB bus
14741
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14742
 
14743
        fork
14744
        begin
14745
            PCIU_IO_READ
14746
             (
14747
                `Test_Master_1,
14748
                Target_Base_Addr_R[target_io_image],
14749
                32'hAAAA_5555,
14750
                4'h0,
14751
                1,
14752
                `Test_Target_Retry_On
14753
             );
14754
 
14755
            do_pause( 1 ) ;
14756
        end
14757
        begin
14758
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14759
 
14760
            if ( ok !== 1 )
14761
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14762
 
14763
            do_pause(3) ;
14764
 
14765
            PCIU_IO_READ
14766
             (
14767
                `Test_Master_1,
14768
                Target_Base_Addr_R[target_io_image],
14769
                32'hAAAA_5555,
14770
                4'h0,
14771
                1,
14772
                `Test_Target_Abort_On
14773
             );
14774
 
14775
            do_pause( 1 ) ;
14776
 
14777
            while ( FRAME === 0 )
14778
                @(posedge pci_clock) ;
14779
 
14780
            while ( IRDY === 0 )
14781
                @(posedge pci_clock) ;
14782
 
14783 35 mihad
            #1 ;
14784
            if ( !error_monitor_done )
14785
                disable monitor_error_event10 ;
14786 15 mihad
        end
14787
        begin:monitor_error_event10
14788 35 mihad
            error_monitor_done = 0 ;
14789 15 mihad
            @(error_event_int) ;
14790
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14791
            ok = 0 ;
14792 35 mihad
            error_monitor_done = 1 ;
14793 15 mihad
        end
14794
        join
14795
 
14796
        if ( ok )
14797
            test_ok ;
14798
 
14799 26 mihad
        @(posedge pci_clock) ;
14800
        @(posedge pci_clock) ;
14801
        @(posedge wb_clock) ;
14802
        @(posedge wb_clock) ;
14803
 
14804 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14805
        addr_offset = 12'h004 ;
14806
        config_read(addr_offset, 4'hF, read_data) ;
14807
        ok = 1 ;
14808
        if ( read_data[27] !== 1 )
14809
        begin
14810
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14811
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14812
            ok = 0 ;
14813
        end
14814
        if ( read_data[28] !== 0 )
14815
        begin
14816
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14817
            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") ;
14818
            ok = 0 ;
14819
        end
14820
        if ( read_data[29] !== 0 )
14821
        begin
14822
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14823
            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") ;
14824
            ok = 0 ;
14825
        end
14826
 
14827
        // clear statuses
14828
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14829
        if ( !ok )
14830
        begin
14831
            test_fail("write to PCI Device Status register failed") ;
14832
            $display("Couldn't write PCI Device Status register") ;
14833
            disable main ;
14834
        end
14835
 
14836
        if ( ok )
14837
            test_ok ;
14838
 
14839
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14840
 
14841
        ok = 1 ;
14842
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14843
 
14844
        config_read(addr_offset, 4'hF, read_data) ;
14845
        if (read_data[8] !== 0)
14846
        begin
14847
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14848
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14849
            ok = 0 ;
14850
        end
14851
        else
14852
            test_ok ;
14853
 
14854
        if ( ok !== 1 )
14855
        begin
14856
            config_write(addr_offset, read_data, 4'hF, ok) ;
14857
            if ( !ok )
14858
            begin
14859
                test_fail("PCI Error Control and Status register could not be written") ;
14860
                disable main ;
14861
            end
14862
        end
14863
 
14864
        test_name = "DISABLE IMAGE" ;
14865 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14866 15 mihad
        if ( ok !== 1 )
14867
        begin
14868
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14869
            test_fail("PCI Address Mask register could not be written") ;
14870
            disable main;
14871
        end
14872
 
14873
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14874
 
14875
    end
14876
end // main
14877
endtask // test_wb_error_rd
14878
 
14879
task test_target_abort ;
14880
    input [2:0]  image_num ;
14881
    reg   [11:0] pci_ctrl_offset ;
14882
    reg   [11:0] ctrl_offset ;
14883
    reg   [11:0] ba_offset ;
14884
    reg   [11:0] am_offset ;
14885
    reg   [11:0] ta_offset ;
14886
    reg   [31:0] pci_address ;
14887
    reg   [3:0]  byte_enables ;
14888
    reg          ok ;
14889 35 mihad
    reg          error_monitor_done ;
14890 15 mihad
begin:main
14891
    pci_ctrl_offset = 12'h4 ;
14892
    if (image_num === 0)
14893
    begin
14894
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14895
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14896
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14897
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14898
    end
14899
    else if (image_num === 1)
14900
    begin
14901
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14902
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14903
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14904
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14905
    end
14906
    else if (image_num === 2)
14907
    begin
14908
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14909
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14910
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14911
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14912
    end
14913
    else if (image_num === 3)
14914
    begin
14915
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14916
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14917
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14918
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14919
    end
14920
    else if (image_num === 4)
14921
    begin
14922
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14923
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14924
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14925
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14926
    end
14927
    else if (image_num === 5)
14928
    begin
14929
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14930
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14931
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14932
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14933
    end
14934
 
14935
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14936
 
14937
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14938
    if ( ok !== 1 )
14939
    begin
14940
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14941
        test_fail("PCI Base Address register could not be written") ;
14942
        disable main ;
14943
    end
14944
 
14945
    // Set Address Mask of IMAGE
14946
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14947
    if ( ok !== 1 )
14948
    begin
14949
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14950
        test_fail("PCI Address Mask register could not be written") ;
14951
        disable main ;
14952
    end
14953
 
14954
    // Set Translation Address of IMAGE
14955
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14956
    if ( ok !== 1 )
14957
    begin
14958
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14959
        test_fail("PCI Translation Address Register could not be written") ;
14960
        disable main ;
14961
    end
14962
 
14963
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14964
    if ( ok !== 1 )
14965
    begin
14966
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14967
        test_fail("PCI Image Control register could not be written") ;
14968
        disable main ;
14969
    end
14970
 
14971
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14972
 
14973
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14974
 
14975
    pci_address  = Target_Base_Addr_R[image_num] ;
14976
    byte_enables = 4'b0001 ;
14977
 
14978
    fork
14979
    begin
14980
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14981
        do_pause ( 1 ) ;
14982
    end
14983
    begin:monitor_error_event1
14984 35 mihad
        error_monitor_done = 0 ;
14985 15 mihad
        @(error_event_int) ;
14986
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14987
        ok = 0 ;
14988 35 mihad
        error_monitor_done = 1 ;
14989 15 mihad
    end
14990
    begin
14991
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14992
        @(posedge pci_clock) ;
14993 35 mihad
        #1 ;
14994
        if ( !error_monitor_done )
14995
            disable monitor_error_event1 ;
14996 15 mihad
    end
14997
    join
14998
 
14999
    if ( ok )
15000
        test_ok ;
15001
 
15002
    ok = 1 ;
15003
 
15004
    fork
15005
    begin
15006
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15007
        do_pause ( 1 ) ;
15008
    end
15009
    begin:monitor_error_event2
15010 35 mihad
        error_monitor_done = 0 ;
15011 15 mihad
        @(error_event_int) ;
15012
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15013
        ok = 0 ;
15014 35 mihad
        error_monitor_done = 1 ;
15015 15 mihad
    end
15016
    begin
15017
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15018
        @(posedge pci_clock) ;
15019 35 mihad
        #1 ;
15020
        if ( !error_monitor_done )
15021
            disable monitor_error_event2 ;
15022 15 mihad
    end
15023
    join
15024
 
15025
    if ( ok )
15026
        test_ok ;
15027
 
15028
    ok = 1 ;
15029
 
15030
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
15031
    byte_enables = 4'b0011 ;
15032
 
15033
    fork
15034
    begin
15035
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15036
        do_pause ( 1 ) ;
15037
    end
15038
    begin:monitor_error_event3
15039 35 mihad
        error_monitor_done = 0 ;
15040 15 mihad
        @(error_event_int) ;
15041
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15042
        ok = 0 ;
15043 35 mihad
        error_monitor_done = 1 ;
15044 15 mihad
    end
15045
    begin
15046
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15047
        @(posedge pci_clock) ;
15048 35 mihad
        if ( !error_monitor_done )
15049
            disable monitor_error_event3 ;
15050 15 mihad
    end
15051
    join
15052
 
15053
    if ( ok )
15054
        test_ok ;
15055
 
15056
    ok = 1 ;
15057
 
15058
    byte_enables = 4'b0000 ;
15059
 
15060
    fork
15061
    begin
15062
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15063
        do_pause ( 1 ) ;
15064
    end
15065
    begin:monitor_error_event4
15066 35 mihad
        error_monitor_done = 0 ;
15067 15 mihad
        @(error_event_int) ;
15068
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15069
        ok = 0 ;
15070 35 mihad
        error_monitor_done = 1 ;
15071 15 mihad
    end
15072
    begin
15073
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15074
        @(posedge pci_clock) ;
15075 35 mihad
        #1 ;
15076
        if ( !error_monitor_done )
15077
            disable monitor_error_event4 ;
15078 15 mihad
    end
15079
    join
15080
 
15081
    if ( ok )
15082
        test_ok ;
15083
 
15084
    ok = 1 ;
15085
 
15086
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
15087
    byte_enables = 4'b0111 ;
15088
 
15089
    fork
15090
    begin
15091
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15092
        do_pause ( 1 ) ;
15093
    end
15094
    begin:monitor_error_event5
15095 35 mihad
        error_monitor_done = 0 ;
15096 15 mihad
        @(error_event_int) ;
15097
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15098
        ok = 0 ;
15099 35 mihad
        error_monitor_done = 1 ;
15100 15 mihad
    end
15101
    begin
15102
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15103
        @(posedge pci_clock) ;
15104 35 mihad
        #1 ;
15105
        if ( !error_monitor_done )
15106
            disable monitor_error_event5 ;
15107 15 mihad
    end
15108
    join
15109
 
15110
    if ( ok )
15111
        test_ok ;
15112
 
15113
    ok = 1 ;
15114
 
15115
    byte_enables = 4'b0010 ;
15116
 
15117
    fork
15118
    begin
15119
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15120
        do_pause ( 1 ) ;
15121
    end
15122
    begin:monitor_error_event6
15123 35 mihad
        error_monitor_done = 0 ;
15124 15 mihad
        @(error_event_int) ;
15125
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15126
        ok = 0 ;
15127 35 mihad
        error_monitor_done = 1 ;
15128 15 mihad
    end
15129
    begin
15130
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15131
        @(posedge pci_clock) ;
15132 35 mihad
        #1 ;
15133
        if ( !error_monitor_done )
15134
            disable monitor_error_event6 ;
15135 15 mihad
    end
15136
    join
15137
 
15138
    if ( ok )
15139
        test_ok ;
15140
 
15141
    ok = 1 ;
15142
    byte_enables = 4'b0001 ;
15143
 
15144
    fork
15145
    begin
15146
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15147
        do_pause ( 1 ) ;
15148
    end
15149
    begin:monitor_error_event7
15150 35 mihad
        error_monitor_done = 0 ;
15151 15 mihad
        @(error_event_int) ;
15152
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15153
        ok = 0 ;
15154 35 mihad
        error_monitor_done = 1 ;
15155 15 mihad
    end
15156
    begin
15157
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15158
        @(posedge pci_clock) ;
15159 35 mihad
        #1 ;
15160
        if ( !error_monitor_done )
15161
            disable monitor_error_event7 ;
15162 15 mihad
    end
15163
    join
15164
 
15165
    if ( ok )
15166
        test_ok ;
15167
 
15168
    ok = 1 ;
15169
    byte_enables = 4'b0000 ;
15170
 
15171
    fork
15172
    begin
15173
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15174
        do_pause ( 1 ) ;
15175
    end
15176
    begin:monitor_error_event8
15177 35 mihad
        error_monitor_done = 0 ;
15178 15 mihad
        @(error_event_int) ;
15179
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15180
        ok = 0 ;
15181 35 mihad
        error_monitor_done = 1 ;
15182 15 mihad
    end
15183
    begin
15184
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15185
        @(posedge pci_clock) ;
15186 35 mihad
        #1 ;
15187
        if ( !error_monitor_done )
15188
            disable monitor_error_event8 ;
15189 15 mihad
    end
15190
    join
15191
 
15192
    if ( ok )
15193
        test_ok ;
15194
 
15195
    ok = 1 ;
15196
 
15197
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15198
    byte_enables = 4'b0110 ;
15199
 
15200
    fork
15201
    begin
15202
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15203
        do_pause ( 1 ) ;
15204
    end
15205
    begin:monitor_error_event9
15206 35 mihad
        error_monitor_done = 0 ;
15207 15 mihad
        @(error_event_int) ;
15208
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15209
        ok = 0 ;
15210 35 mihad
        error_monitor_done = 1 ;
15211 15 mihad
    end
15212
    begin
15213
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15214
        @(posedge pci_clock) ;
15215 35 mihad
        #1 ;
15216
        if ( !error_monitor_done )
15217
            disable monitor_error_event9 ;
15218 15 mihad
    end
15219
    join
15220
 
15221
    if ( ok )
15222
        test_ok ;
15223
 
15224
    ok = 1 ;
15225
    fork
15226
    begin
15227
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15228
        do_pause ( 1 ) ;
15229
    end
15230
    begin:monitor_error_event10
15231 35 mihad
        error_monitor_done = 0 ;
15232 15 mihad
        @(error_event_int) ;
15233
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15234
        ok = 0 ;
15235 35 mihad
        error_monitor_done = 1 ;
15236 15 mihad
    end
15237
    begin
15238
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15239
        @(posedge pci_clock) ;
15240 35 mihad
 
15241
        #1 ;
15242
        if ( !error_monitor_done )
15243
            disable monitor_error_event10 ;
15244 15 mihad
    end
15245
    join
15246
 
15247
    if ( ok )
15248
        test_ok ;
15249
 
15250
    ok = 1 ;
15251
 
15252
    byte_enables = 4'b0001 ;
15253
 
15254
    fork
15255
    begin
15256
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15257
        do_pause ( 1 ) ;
15258
    end
15259
    begin:monitor_error_event11
15260 35 mihad
        error_monitor_done = 0 ;
15261 15 mihad
        @(error_event_int) ;
15262
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15263
        ok = 0 ;
15264 35 mihad
        error_monitor_done = 1 ;
15265 15 mihad
    end
15266
    begin
15267
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15268
        @(posedge pci_clock) ;
15269 35 mihad
        #1 ;
15270
        if ( !error_monitor_done )
15271
            disable monitor_error_event11 ;
15272 15 mihad
    end
15273
    join
15274
 
15275
    if ( ok )
15276
        test_ok ;
15277
 
15278
    ok = 1 ;
15279
 
15280
    byte_enables = 4'b0101 ;
15281
 
15282
    fork
15283
    begin
15284
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15285
        do_pause ( 1 ) ;
15286
    end
15287
    begin:monitor_error_event12
15288 35 mihad
        error_monitor_done = 0 ;
15289 15 mihad
        @(error_event_int) ;
15290
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15291
        ok = 0 ;
15292 35 mihad
        error_monitor_done = 1 ;
15293 15 mihad
    end
15294
    begin
15295
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15296
        @(posedge pci_clock) ;
15297 35 mihad
        #1 ;
15298
        if ( !error_monitor_done )
15299
            disable monitor_error_event12 ;
15300 15 mihad
    end
15301
    join
15302
 
15303
    if ( ok )
15304
        test_ok ;
15305
 
15306
    ok = 1 ;
15307
 
15308
    byte_enables = 4'b0011 ;
15309
 
15310
    fork
15311
    begin
15312
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15313
        do_pause ( 1 ) ;
15314
    end
15315
    begin:monitor_error_event13
15316 35 mihad
        error_monitor_done = 0 ;
15317 15 mihad
        @(error_event_int) ;
15318
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15319
        ok = 0 ;
15320 35 mihad
        error_monitor_done = 1 ;
15321 15 mihad
    end
15322
    begin
15323
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15324
        @(posedge pci_clock) ;
15325 35 mihad
        #1 ;
15326
        if ( !error_monitor_done )
15327
            disable monitor_error_event13 ;
15328 15 mihad
    end
15329
    join
15330
 
15331
    if ( ok )
15332
        test_ok ;
15333
 
15334
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15335
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15336
    ok = 1 ;
15337
    if ( pci_address[27] !== 1 )
15338
    begin
15339
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15340
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15341
        ok = 0 ;
15342
    end
15343
    if ( pci_address[28] !== 0 )
15344
    begin
15345
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15346
        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") ;
15347
        ok = 0 ;
15348
    end
15349
    if ( pci_address[29] !== 0 )
15350
    begin
15351
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15352
        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") ;
15353
        ok = 0 ;
15354
    end
15355
 
15356
    // clear statuses
15357
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15358
    if ( !ok )
15359
    begin
15360
        test_fail("write to PCI Device Status register failed") ;
15361
        $display("Couldn't write PCI Device Status register") ;
15362
        disable main ;
15363
    end
15364
 
15365
    if ( ok )
15366
        test_ok ;
15367
 
15368
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15369
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15370
    if ( pci_address[8] !== 0 )
15371
    begin
15372
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15373
    end
15374
    else
15375
        test_ok ;
15376
 
15377
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15378
 
15379
    test_name = "DISABLE IMAGE" ;
15380
 
15381 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15382 15 mihad
    if ( ok !== 1 )
15383
    begin
15384
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15385
        test_fail("PCI Address Mask register could not be written") ;
15386
        disable main ;
15387
    end
15388
end
15389
endtask // test_target_abort
15390
 
15391
task test_target_io_wr_rd ;
15392
    input [2:0]  image_num ;
15393
    input        translate_address ;
15394
    input [11:0] img_ctrl_offset ;
15395
    reg   [31:0] expect_address ;
15396
    reg   [31:0] pci_address ;
15397
    reg          translation ;
15398
    reg   [31:0] read_data ;
15399
    reg   [3:0]  byte_enables ;
15400
    reg          ok ;
15401
    reg          pci_ok ;
15402
    reg          wb_ok ;
15403
    integer      i ;
15404 35 mihad
    reg          error_monitor_done ;
15405 15 mihad
begin:main
15406
    `ifdef ADDR_TRAN_IMPL
15407
        translation = translate_address ;
15408
    `else
15409
        translation = 0 ;
15410
    `endif
15411
 
15412
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15413
 
15414
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15415
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15416
    if ( translation )
15417
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15418
    else
15419
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15420
 
15421
    if ( !ok )
15422
    begin
15423
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15424
        test_fail("PCI Image Control register could not be written") ;
15425
    end
15426
 
15427
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15428
    pci_address  = Target_Base_Addr_R[image_num] ;
15429
    byte_enables = 4'b0000 ;
15430
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15431
 
15432
    fork
15433
    begin
15434
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15435
        do_pause ( 1 ) ;
15436
    end
15437
    begin
15438
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15439
        if ( wb_ok !== 1 )
15440
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15441
 
15442 35 mihad
        #1 ;
15443
        if ( !error_monitor_done )
15444
            disable monitor_pci_error_1 ;
15445 15 mihad
    end
15446
    begin:monitor_pci_error_1
15447 35 mihad
        error_monitor_done = 0 ;
15448 15 mihad
        pci_ok = 1 ;
15449
        @(error_event_int) ;
15450
        pci_ok = 0 ;
15451
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15452 35 mihad
        error_monitor_done = 1 ;
15453 15 mihad
    end
15454
    join
15455
 
15456
    byte_enables = 4'b1111 ;
15457
    for ( i = 0 ; i < 4 ; i = i + 1 )
15458
    begin:loop_1
15459
        byte_enables[i] = 0 ;
15460
        if ( i > 0 )
15461
            byte_enables[i - 1] = 1 ;
15462
        fork
15463
        begin
15464
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15465
            do_pause ( 1 ) ;
15466
        end
15467
        begin
15468
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15469
            if ( wb_ok !== 1 )
15470
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15471
 
15472 35 mihad
            #1 ;
15473
            if ( !error_monitor_done )
15474
                disable monitor_pci_error_2 ;
15475 15 mihad
        end
15476
        begin:monitor_pci_error_2
15477 35 mihad
            error_monitor_done = 0 ;
15478 15 mihad
            pci_ok = 1 ;
15479
            @(error_event_int) ;
15480
            pci_ok = 0 ;
15481
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15482 35 mihad
            error_monitor_done = 1 ;
15483 15 mihad
        end
15484
        join
15485
 
15486
        if ( !pci_ok || !wb_ok )
15487
            disable loop_1 ;
15488
 
15489
        pci_address = pci_address + 1 ;
15490
        expect_address = expect_address + 1 ;
15491
    end
15492
 
15493
    if ( pci_ok && wb_ok )
15494
        test_ok ;
15495
 
15496
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15497
    pci_address  = Target_Base_Addr_R[image_num] ;
15498
    byte_enables = 4'b1100 ;
15499
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15500
 
15501
    master1_check_received_data = 1 ;
15502
    fork
15503
    begin
15504
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15505
        do_pause( 1 ) ;
15506
    end
15507
    begin
15508
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15509
        if ( wb_ok !== 1 )
15510
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15511
 
15512
        do_pause ( 2 ) ;
15513
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15514
        do_pause ( 16 ) ;
15515
 
15516 35 mihad
        #1 ;
15517
        if ( !error_monitor_done )
15518
            disable monitor_pci_error_3 ;
15519 15 mihad
    end
15520
    begin:monitor_pci_error_3
15521 35 mihad
        error_monitor_done = 0 ;
15522 15 mihad
        pci_ok = 1 ;
15523
        @(error_event_int) ;
15524
        pci_ok = 0 ;
15525
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15526 35 mihad
        error_monitor_done = 1 ;
15527 15 mihad
    end
15528
    join
15529
 
15530
    if ( !pci_ok || !wb_ok )
15531
    begin
15532
        disable main ;
15533
    end
15534
 
15535
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15536
    byte_enables = 4'b0011 ;
15537
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15538
 
15539
    master1_check_received_data = 1 ;
15540
    fork
15541
    begin
15542
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15543
        do_pause( 1 ) ;
15544
    end
15545
    begin
15546
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15547
        if ( wb_ok !== 1 )
15548
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15549
 
15550
        do_pause ( 2 ) ;
15551
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15552
        do_pause ( 16 ) ;
15553
 
15554 35 mihad
        #1 ;
15555
        if ( !error_monitor_done )
15556
            disable monitor_pci_error_4 ;
15557 15 mihad
    end
15558
    begin:monitor_pci_error_4
15559 35 mihad
        error_monitor_done = 0 ;
15560 15 mihad
        pci_ok = 1 ;
15561
        @(error_event_int) ;
15562
        pci_ok = 0 ;
15563
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15564 35 mihad
        error_monitor_done = 1 ;
15565 15 mihad
    end
15566
    join
15567
 
15568
    if ( !pci_ok || !wb_ok )
15569
    begin
15570
        disable main ;
15571
    end
15572
 
15573
    pci_address  = Target_Base_Addr_R[image_num] ;
15574
    byte_enables = 4'b0000 ;
15575
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15576
 
15577
    master1_check_received_data = 1 ;
15578
    fork
15579
    begin
15580
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15581
        do_pause( 1 ) ;
15582
    end
15583
    begin
15584
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15585
        if ( wb_ok !== 1 )
15586
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15587
 
15588
        do_pause ( 2 ) ;
15589
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15590
        do_pause ( 16 ) ;
15591
 
15592 35 mihad
        #1 ;
15593
        if ( !error_monitor_done )
15594
            disable monitor_pci_error_5 ;
15595 15 mihad
    end
15596
    begin:monitor_pci_error_5
15597 35 mihad
        error_monitor_done = 0 ;
15598 15 mihad
        pci_ok = 1 ;
15599
        @(error_event_int) ;
15600
        pci_ok = 0 ;
15601
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15602 35 mihad
        error_monitor_done = 1 ;
15603 15 mihad
    end
15604
    join
15605
 
15606
    if ( pci_ok && wb_ok )
15607
        test_ok ;
15608
end
15609
endtask // test_target_io_wr_rd
15610
 
15611
task test_target_io_err_wr ;
15612
    input [2:0]  image_num ;
15613
    input        translate_address ;
15614
    input [11:0] img_ctrl_offset ;
15615
    input        enable_error_report ;
15616
    input        enable_error_interrupt ;
15617
 
15618
    reg   [31:0] expect_address ;
15619
    reg   [31:0] pci_address ;
15620
    reg          translation ;
15621
    reg   [31:0] read_data ;
15622
    reg   [3:0]  byte_enables ;
15623
    reg          ok ;
15624
    reg          pci_ok ;
15625
    reg          wb_ok ;
15626
    integer      i ;
15627
    reg   [11:0] offset ;
15628 35 mihad
    reg          error_monitor_done ;
15629 15 mihad
begin:main
15630
    `ifdef ADDR_TRAN_IMPL
15631
        translation = translate_address ;
15632
    `else
15633
        translation = 0 ;
15634
    `endif
15635
 
15636
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15637
 
15638
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15639
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15640
    if ( translation )
15641
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15642
    else
15643
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15644
 
15645
    if ( !ok )
15646
    begin
15647
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15648
        test_fail("PCI Image Control register could not be written") ;
15649
    end
15650
 
15651
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15652
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15653
    if ( enable_error_report )
15654
    begin
15655
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15656
        if ( !ok )
15657
        begin
15658
            test_fail("PCI Error Control and Status register could not be written") ;
15659
            disable main ;
15660
        end
15661
    end
15662
    else
15663
    begin
15664
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15665
        if ( !ok )
15666
        begin
15667
            test_fail("PCI Error Control and Status register could not be written") ;
15668
            disable main ;
15669
        end
15670
    end
15671
 
15672
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15673
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15674
    if ( enable_error_interrupt )
15675
    begin
15676
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15677
        if ( !ok )
15678
        begin
15679
            test_fail("Interrupt Control register could not be written") ;
15680
            disable main ;
15681
        end
15682
    end
15683
    else
15684
    begin
15685
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15686
        if ( !ok )
15687
        begin
15688
            test_fail("Interrupt Control register could not be written") ;
15689
            disable main ;
15690
        end
15691
    end
15692
 
15693
    pci_address  = Target_Base_Addr_R[image_num] ;
15694
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15695
 
15696
    byte_enables = 4'b1111 ;
15697
 
15698
    for ( i = 0 ; i < 4 ; i = i + 1 )
15699
    begin:loop_1
15700
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15701
        byte_enables[i] = 0 ;
15702
        if ( i > 0 )
15703
            byte_enables[i - 1] = 1 ;
15704
 
15705
        fork
15706
        begin
15707
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15708
            do_pause ( 1 ) ;
15709
        end
15710
        begin
15711
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15712
            if ( wb_ok !== 1 )
15713
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15714
 
15715 35 mihad
            #1 ;
15716
            if ( !error_monitor_done )
15717
                disable monitor_pci_error_2 ;
15718 15 mihad
        end
15719
        begin:monitor_pci_error_2
15720 35 mihad
            error_monitor_done = 0 ;
15721 15 mihad
            pci_ok = 1 ;
15722
            @(error_event_int) ;
15723
            pci_ok = 0 ;
15724
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15725 35 mihad
            error_monitor_done = 1 ;
15726 15 mihad
        end
15727
        join
15728
 
15729
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15730
        `ifdef HOST
15731
 
15732
            repeat ( 4 )
15733
                @( posedge wb_clock ) ;
15734
 
15735
            if ( enable_error_interrupt && enable_error_report )
15736
            begin
15737
                if ( INT_O !== 1 )
15738
                begin
15739
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15740
                end
15741
            end
15742
            else
15743
            begin
15744
                if ( INT_O !== 0 )
15745
                begin
15746
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15747
                end
15748
            end
15749
        `else
15750
            repeat ( 4 )
15751
                @( posedge pci_clock ) ;
15752
 
15753
            if ( enable_error_interrupt && enable_error_report )
15754
            begin
15755
                if ( INTA !== 0 )
15756
                begin
15757
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15758
                end
15759
            end
15760
            else
15761
            begin
15762
                if ( INTA !== 1 )
15763
                begin
15764
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15765
                end
15766
            end
15767
        `endif
15768
 
15769
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15770
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15771
        config_read( offset, 4'hF, read_data ) ;
15772
        ok = 1 ;
15773
        if ( enable_error_report )
15774
        begin
15775
            if ( read_data[8] !== 1 )
15776
            begin
15777
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15778
                ok = 0 ;
15779
            end
15780
 
15781
            if ( read_data[9] !== 0 )
15782
            begin
15783
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15784
                ok = 0 ;
15785
            end
15786
 
15787
            if ( read_data[31:28] !== byte_enables )
15788
            begin
15789
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15790
                ok = 0 ;
15791
            end
15792
 
15793
            if ( read_data[27:24] !== `BC_IO_WRITE )
15794
            begin
15795
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15796
                ok = 0 ;
15797
            end
15798
 
15799
            if ( ok )
15800
                test_ok ;
15801
 
15802
            test_name = "CLEAR ERROR STATUS" ;
15803
            config_write( offset, read_data, 4'hF, ok ) ;
15804
            if ( !ok )
15805
                test_fail("PCI Error Control and Status register could not be written") ;
15806
 
15807
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15808
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15809
            config_read ( offset, 4'hf, read_data ) ;
15810
 
15811
            if ( read_data !== expect_address )
15812
            begin
15813
                test_fail("value in Erroneous Address register was incorrect") ;
15814
                ok = 0 ;
15815
            end
15816
 
15817
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15818
            config_read ( offset, 4'hf, read_data ) ;
15819
 
15820
            if ( read_data !== 32'hAAAA_AAAA )
15821
            begin
15822
                test_fail("value in Erroneous Data register was incorrect") ;
15823
                ok = 0 ;
15824
            end
15825
 
15826
            if ( ok )
15827
                test_ok ;
15828
 
15829
        end
15830
        else
15831
        begin
15832
            if ( read_data[8] !== 0 )
15833
            begin
15834
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15835
                ok = 0 ;
15836
            end
15837
            else
15838
                test_ok ;
15839
        end
15840
 
15841
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15842
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15843
        ok = 1 ;
15844
 
15845
        config_read ( offset, 4'hF, read_data ) ;
15846
        if ( enable_error_report && enable_error_interrupt )
15847
        begin
15848
            if ( read_data[2] !== 1 )
15849
            begin
15850
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15851
                ok = 0 ;
15852
            end
15853
 
15854
            test_name = "CLEARING INTERRUPT STATUS" ;
15855
            config_write( offset, read_data, 4'hF, ok ) ;
15856
            if ( !ok )
15857
                test_fail("Interrupt Status register could not be written") ;
15858
        end
15859
        else
15860
        begin
15861
            if ( read_data[2] !== 0 )
15862
            begin
15863
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15864
                ok = 0 ;
15865
            end
15866
        end
15867
 
15868
        if ( ok )
15869
            test_ok ;
15870
 
15871
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15872
        `ifdef HOST
15873
 
15874
            repeat ( 4 )
15875
                @( posedge wb_clock ) ;
15876
 
15877
            if ( INT_O !== 0 )
15878
            begin
15879
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15880
            end
15881
            else
15882
                test_ok ;
15883
 
15884
        `else
15885
            repeat ( 4 )
15886
                @( posedge pci_clock ) ;
15887
 
15888
            if ( INTA !== 1 )
15889
            begin
15890
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15891
            end
15892
            else
15893
                test_ok ;
15894
 
15895
        `endif
15896
 
15897
        pci_address = pci_address + 1 ;
15898
        expect_address = expect_address + 1 ;
15899
    end
15900
 
15901
end
15902
endtask // test_target_io_err_wr
15903
 
15904
task test_pci_image ;
15905
    input [2:0]  image_num ;
15906
    reg   [11:0] pci_ctrl_offset ;
15907
    reg   [11:0] ctrl_offset ;
15908
    reg   [11:0] ba_offset ;
15909
    reg   [11:0] am_offset ;
15910
    reg   [11:0] ta_offset ;
15911
    reg   [7:0]  cache_lsize ;
15912
    reg          ok ;
15913
    reg          test_io ;
15914
    reg          test_mem ;
15915
begin
15916
    pci_ctrl_offset = 12'h4 ;
15917
    if (image_num === 0)
15918
    begin
15919
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15920
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15921
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15922
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15923
    end
15924
    else if (image_num === 1)
15925
    begin
15926
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15927
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15928
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15929
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15930
    end
15931
    else if (image_num === 2)
15932
    begin
15933
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15934
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15935
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15936
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15937
    end
15938
    else if (image_num === 3)
15939
    begin
15940
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15941
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15942
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15943
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15944
    end
15945
    else if (image_num === 4)
15946
    begin
15947
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15948
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15949
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15950
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15951
    end
15952
    else if (image_num === 5)
15953
    begin
15954
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15955
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15956
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15957
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15958
    end
15959
 
15960
    `ifdef HOST
15961
        test_io  = 1 ;
15962
        test_mem = 1 ;
15963
    `else
15964
        if (image_num == 1)
15965
            test_io = `PCI_BA1_MEM_IO ;
15966
        else if ( image_num == 2 )
15967
            test_io = `PCI_BA2_MEM_IO ;
15968
        else if ( image_num == 3 )
15969
            test_io = `PCI_BA3_MEM_IO ;
15970
        else if ( image_num == 4 )
15971
            test_io = `PCI_BA4_MEM_IO ;
15972
        else if ( image_num == 5 )
15973
            test_io = `PCI_BA5_MEM_IO ;
15974
 
15975
        test_mem = !test_io ;
15976
    `endif
15977
 
15978
    $display(" ");
15979
    $display("########################################################################") ;
15980
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15981
    test_name = "PCI IMAGE SETTINGS" ;
15982
 
15983
    // Set Base Address of IMAGE
15984
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15985
    if ( ok !== 1 )
15986
    begin
15987
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15988
        test_fail("PCI Base Address register could not be written") ;
15989
    end
15990
 
15991
    // Set Address Mask of IMAGE
15992
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15993
    if ( ok !== 1 )
15994
    begin
15995
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15996
        test_fail("PCI Address Mask register could not be written") ;
15997
    end
15998
 
15999
    // Set Translation Address of IMAGE
16000
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16001
    if ( ok !== 1 )
16002
    begin
16003
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16004
        test_fail("PCI Translation Address register could not be written") ;
16005
    end
16006
 
16007
// Following are defines for byte enable signals !
16008
//      Byte Masks
16009
//      `Test_Byte_0                            (4'b1110)
16010
//      `Test_Byte_1                            (4'b1101)
16011
//      `Test_Byte_2                            (4'b1011)
16012
//      `Test_Byte_3                            (4'b0111)
16013
//      `Test_Half_0                            (4'b1100)
16014
//      `Test_Half_1                            (4'b0011)
16015
//      `Test_All_Bytes                         (4'b0000)
16016
 
16017
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
16018
    // Set Cache Line Size
16019
    cache_lsize = 8'h4 ;
16020
 
16021
    $display(" ");
16022
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16023
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16024
    if ( ok !== 1 )
16025
    begin
16026
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16027
        test_fail("PCI Device Control and Status register could not be written") ;
16028
    end
16029
 
16030
    if (test_mem)
16031
    begin
16032
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
16033
        // Task test_normal_wr_rd has the following parameters:
16034
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16035
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16036
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16037
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
16038
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
16039
 
16040
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16041
        // Set Cache Line Size
16042
        cache_lsize = 8'h4 ;
16043
 
16044
        $display(" ");
16045
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16046
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16047
        if ( ok !== 1 )
16048
        begin
16049
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16050
            test_fail("Cache Line Size register could not be written" ) ;
16051
        end
16052
 
16053
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
16054
        // Task test_normal_wr_rd has the following parameters:
16055
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16056
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16057
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16058
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
16059
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
16060
 
16061
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16062
        // Set Cache Line Size
16063
        cache_lsize = 8'h8 ;
16064
 
16065
        $display(" ");
16066
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16067
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16068
        if ( ok !== 1 )
16069
        begin
16070
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16071
            test_fail("Cache Line Size register could not be written" ) ;
16072
        end
16073
 
16074
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
16075
        // Task test_normal_wr_rd has the following parameters:
16076
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16077
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16078
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16079
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
16080
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16081
 
16082
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16083
        // Set Cache Line Size
16084
        cache_lsize = 8'h4 ;
16085
 
16086
        $display(" ");
16087
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16088
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16089
        if ( ok !== 1 )
16090
        begin
16091
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16092
            test_fail("Cache Line Size register could not be written" ) ;
16093
        end
16094
 
16095
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
16096
        // Task test_normal_wr_rd has the following parameters:
16097
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16098
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16099
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16100
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
16101
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16102
 
16103
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16104
        $display(" ");
16105
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
16106
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16107
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16108
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
16109
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
16110
 
16111
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16112
        $display(" ");
16113
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
16114
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16115
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16116
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
16117
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
16118
 
16119
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16120
        $display(" ");
16121
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
16122
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16123
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16124
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
16125
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
16126
 
16127
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16128
        $display(" ");
16129
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
16130
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16131
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16132
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
16133
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
16134
    end
16135
 
16136
    if ( test_io )
16137
    begin
16138
        test_name = "PCI IMAGE SETTINGS" ;
16139
 
16140
        // Set Base Address of IMAGE
16141
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
16142
        if ( ok !== 1 )
16143
        begin
16144
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16145
            test_fail("PCI Base Address register could not be written") ;
16146
        end
16147
 
16148
        // Set Address Mask of IMAGE
16149
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16150
        if ( ok !== 1 )
16151
        begin
16152
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16153
            test_fail("PCI Address Mask register could not be written") ;
16154
        end
16155
 
16156
        // Set Translation Address of IMAGE
16157
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16158
        if ( ok !== 1 )
16159
        begin
16160
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16161
            test_fail("PCI Translation Address register could not be written") ;
16162
        end
16163
 
16164
        // Set Cache Line Size
16165
        cache_lsize = 8'h4 ;
16166
 
16167
        $display(" ");
16168
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16169
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16170
        if ( ok !== 1 )
16171
        begin
16172
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16173
            test_fail("Cache Line Size register could not be written" ) ;
16174
        end
16175
 
16176
        test_target_io_wr_rd
16177
        (
16178
            image_num,    // image number
16179
            0,            // test with address translation
16180
            ctrl_offset   // image control register offset
16181
        ) ;
16182
 
16183
        test_target_io_wr_rd
16184
        (
16185
            image_num,    // image number
16186
            1,            // test with address translation
16187
            ctrl_offset   // image control register offset
16188
        ) ;
16189
 
16190
        test_target_io_err_wr
16191
        (
16192
            image_num,      // image number
16193
            0,              // address translation on/off
16194
            ctrl_offset,    // image control register offset
16195
            0,              // enable error reporting
16196
 
16197
        ) ;
16198
 
16199
        test_target_io_err_wr
16200
        (
16201
            image_num,      // image number
16202
            1,              // address translation on/off
16203
            ctrl_offset,    // image control register offset
16204
            0,              // enable error reporting
16205
            1               // enable error interrupts
16206
        ) ;
16207
 
16208
        test_target_io_err_wr
16209
        (
16210
            image_num,      // image number
16211
            0,              // address translation on/off
16212
            ctrl_offset,    // image control register offset
16213
            1,              // enable error reporting
16214
 
16215
        ) ;
16216
 
16217
        test_target_io_err_wr
16218
        (
16219
            image_num,      // image number
16220
            1,              // address translation on/off
16221
            ctrl_offset,    // image control register offset
16222
            1,              // enable error reporting
16223
            1               // enable error interrupts
16224
        ) ;
16225
    end
16226
 
16227
    // Test master abort with NON supported commands
16228
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16229
 
16230
    // disable the image
16231 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16232 15 mihad
end
16233
endtask //test_pci_image
16234
 
16235
task target_fast_back_to_back ;
16236
    reg   [11:0] pci_ctrl_offset ;
16237
    reg   [11:0] ctrl_offset ;
16238
    reg   [11:0] ba_offset ;
16239
    reg   [11:0] am_offset ;
16240
    reg   [11:0] ta_offset ;
16241
    reg   [11:0] cls_offset ;
16242
    reg          do_mem_fb2b ;
16243
    reg          do_io_fb2b ;
16244
    reg          ok ;
16245
begin:main
16246
 
16247
    if ( target_mem_image !== -1 )
16248
    begin
16249
        do_mem_fb2b = 1 ;
16250
 
16251
        if (target_mem_image === 1)
16252
        begin
16253
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16254
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16255
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16256
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16257
        end
16258
        else if (target_mem_image === 2)
16259
        begin
16260
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16261
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16262
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16263
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16264
        end
16265
        else if (target_mem_image === 3)
16266
        begin
16267
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16268
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16269
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16270
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16271
        end
16272
        else if (target_mem_image === 4)
16273
        begin
16274
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16275
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16276
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16277
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16278
        end
16279
        else if (target_mem_image === 5)
16280
        begin
16281
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16282
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16283
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16284
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16285
        end
16286
    end
16287
    else
16288
        do_mem_fb2b = 0 ;
16289
 
16290
    pci_ctrl_offset = 12'h4 ;
16291
    cls_offset      = 12'h00C ;
16292
 
16293
    if ( do_mem_fb2b )
16294
    begin
16295
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16296
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16297
        if ( ok !== 1 )
16298
        begin
16299
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16300
            test_fail("PCI Base Address register could not be written") ;
16301
            disable main ;
16302
        end
16303
 
16304
        // Set Address Mask of IMAGE
16305
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16306
        if ( ok !== 1 )
16307
        begin
16308
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16309
            test_fail("PCI Address Mask register could not be written") ;
16310
            disable main ;
16311
        end
16312
 
16313
        // Set Translation Address of IMAGE
16314
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16315
        if ( ok !== 1 )
16316
        begin
16317
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16318
            test_fail("PCI Translation Address Register could not be written") ;
16319
            disable main ;
16320
        end
16321
 
16322
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16323
        if ( ok !== 1 )
16324
        begin
16325
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16326
            test_fail("PCI Image Control register could not be written") ;
16327
            disable main ;
16328
        end
16329
 
16330
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16331
        if ( ok !== 1 )
16332
        begin
16333
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16334
            test_fail("Cache Line Size register could not be written") ;
16335
            disable main ;
16336
        end
16337
 
16338
        // enable master 1 fast_b2b
16339 45 mihad
        configuration_cycle_write(0,                        // bus number
16340
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16341
                                  0,                        // function number
16342
                                  1,                        // register number
16343
                                  0,                        // type of configuration cycle
16344
                                  4'b1111,                  // byte enables
16345
                                  32'hFFFF_FFFF             // data
16346 15 mihad
                                 ) ;
16347
 
16348
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16349
 
16350
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16351
        fork
16352
        begin
16353
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16354
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16355
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16356
                  0, `Test_One_Zero_Target_WS,
16357
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16358
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16359
 
16360
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16361
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16362
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16363
                  0, `Test_One_Zero_Target_WS,
16364
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16365
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16366
            do_pause(5) ;
16367
 
16368
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16369
        end
16370
        begin:wb_monitor1
16371
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16372
            if ( ok !== 1 )
16373
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16374
 
16375
            disable monitor_error_event1 ;
16376
        end
16377
        begin:monitor_error_event1
16378
            @(error_event_int) ;
16379
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16380
            ok = 0 ;
16381
            disable wb_monitor1 ;
16382
        end
16383
        join
16384
 
16385
        if ( ok )
16386
            test_ok ;
16387
 
16388
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16389
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16390
        fork
16391
        begin
16392
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16393
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16394
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16395
                  0, `Test_One_Zero_Target_WS,
16396
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16397
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16398
 
16399
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16400
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16401
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16402
                  0, `Test_One_Zero_Target_WS,
16403
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16404
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16405
            do_pause(5) ;
16406
 
16407
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16408
 
16409
        end
16410
        begin:wb_monitor2
16411
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16412
            if ( ok !== 1 )
16413
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16414
            else
16415
            begin
16416
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16417
                if ( ok !== 1 )
16418
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16419
            end
16420
 
16421
            disable monitor_error_event2 ;
16422
        end
16423
        begin:monitor_error_event2
16424
            @(error_event_int) ;
16425
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16426
            ok = 0 ;
16427
            disable wb_monitor2 ;
16428
        end
16429
        join
16430
 
16431
        if ( ok )
16432
            test_ok ;
16433
 
16434
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16435
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16436
        fork
16437
        begin
16438
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16439
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16440
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16441
                  0, `Test_One_Zero_Target_WS,
16442
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16443
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16444
 
16445
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16446
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16447
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16448
                  0, `Test_One_Zero_Target_WS,
16449
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16450
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16451
            do_pause(5) ;
16452
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16453
 
16454
        end
16455
        begin:wb_monitor3
16456
            fork
16457
            begin
16458
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16459
                if ( ok !== 1 )
16460
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16461
            end
16462
            begin
16463
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16464
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16465
                if ( ok !== 1 )
16466
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16467
            end
16468
            join
16469
 
16470
            if ( ok )
16471
            begin
16472
                fork
16473
                begin
16474
                    do_pause(3) ;
16475
 
16476
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16477
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16478
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16479
                        0, `Test_One_Zero_Target_WS,
16480
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16481
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16482
 
16483
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16484
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16485
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16486
                            0, `Test_One_Zero_Target_WS,
16487
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16488
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16489
 
16490
                    do_pause(1) ;
16491
                end
16492
                begin
16493
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16494
                    if ( ok !== 1 )
16495
                    begin
16496
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16497
                        disable monitor_error_event3 ;
16498
                    end
16499
                    else
16500
                    begin
16501
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16502
                        if ( ok !== 1 )
16503
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16504
                    end
16505
                end
16506 26 mihad
                begin
16507
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16508
                        if ( ok !== 1 )
16509
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16510
                end
16511 15 mihad
                join
16512
            end
16513
            disable monitor_error_event3 ;
16514
        end
16515
        begin:monitor_error_event3
16516
            @(error_event_int) ;
16517
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16518
            ok = 0 ;
16519
            disable wb_monitor3 ;
16520
        end
16521
        join
16522
 
16523
        if ( ok )
16524
            test_ok ;
16525
 
16526
        test_name = "DISABLING MEM IMAGE" ;
16527 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16528 15 mihad
        if ( ok !== 1 )
16529
        begin
16530
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16531
            test_fail("PCI Address Mask register could not be written") ;
16532
            disable main ;
16533
        end
16534
    end
16535
 
16536
    if ( target_io_image !== -1 )
16537
    begin
16538
        do_io_fb2b = 1 ;
16539
 
16540
        if (target_io_image === 1)
16541
        begin
16542
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16543
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16544
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16545
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16546
        end
16547
        else if (target_io_image === 2)
16548
        begin
16549
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16550
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16551
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16552
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16553
        end
16554
        else if (target_io_image === 3)
16555
        begin
16556
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16557
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16558
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16559
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16560
        end
16561
        else if (target_io_image === 4)
16562
        begin
16563
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16564
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16565
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16566
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16567
        end
16568
        else if (target_io_image === 5)
16569
        begin
16570
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16571
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16572
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16573
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16574
        end
16575
    end
16576
    else
16577
        do_io_fb2b = 0 ;
16578
 
16579
    if ( do_io_fb2b )
16580
    begin
16581
 
16582
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16583
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16584
        if ( ok !== 1 )
16585
        begin
16586
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16587
            test_fail("PCI Base Address register could not be written") ;
16588
            disable main ;
16589
        end
16590
 
16591
        // Set Address Mask of IMAGE
16592
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16593
        if ( ok !== 1 )
16594
        begin
16595
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16596
            test_fail("PCI Address Mask register could not be written") ;
16597
            disable main ;
16598
        end
16599
 
16600
        // Set Translation Address of IMAGE
16601
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16602
        if ( ok !== 1 )
16603
        begin
16604
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16605
            test_fail("PCI Translation Address Register could not be written") ;
16606
            disable main ;
16607
        end
16608
 
16609
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16610
        if ( ok !== 1 )
16611
        begin
16612
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16613
            test_fail("PCI Image Control register could not be written") ;
16614
            disable main ;
16615
        end
16616
 
16617
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16618
        if ( ok !== 1 )
16619
        begin
16620
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16621
            test_fail("Cache Line Size register could not be written") ;
16622
            disable main ;
16623
        end
16624
 
16625
        // enable master 1 fast_b2b
16626 45 mihad
        configuration_cycle_write(0,                        // bus number
16627
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16628
                                  0,                        // function number
16629
                                  1,                        // register number
16630
                                  0,                        // type of configuration cycle
16631
                                  4'b1111,                  // byte enables
16632
                                  32'hFFFF_FFFF             // data
16633 15 mihad
                                 ) ;
16634
 
16635
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16636
 
16637
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16638
        fork
16639
        begin
16640
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16641
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16642
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16643
                  0, `Test_One_Zero_Target_WS,
16644
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16645
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16646
 
16647
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16648
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16649
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16650
                  0, `Test_One_Zero_Target_WS,
16651
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16652
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16653
            do_pause(5) ;
16654
 
16655
        end
16656
        begin:wb_monitor4
16657
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16658
            if ( ok !== 1 )
16659
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16660
 
16661
            if ( ok )
16662
            begin
16663
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 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
            end
16667
 
16668
            disable monitor_error_event4 ;
16669
        end
16670
        begin:monitor_error_event4
16671
            @(error_event_int) ;
16672
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16673
            ok = 0 ;
16674
            disable wb_monitor4 ;
16675
        end
16676
        join
16677
 
16678
        if ( ok )
16679
            test_ok ;
16680
 
16681
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16682
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16683
        fork
16684
        begin
16685
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16686
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16687
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16688
                  0, `Test_One_Zero_Target_WS,
16689
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16690
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16691
 
16692
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16693
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16694
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16695
                  0, `Test_One_Zero_Target_WS,
16696
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16697
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16698
            do_pause(5) ;
16699
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16700
        end
16701
        begin:wb_monitor5
16702
            fork
16703
            begin
16704
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16705
                if ( ok !== 1 )
16706
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16707
            end
16708
            begin
16709
                wb_transaction_stop( 1 ) ;
16710
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16711
                if ( ok !== 1 )
16712
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16713
            end
16714
            join
16715
 
16716
            if ( ok )
16717
            begin
16718
                fork
16719
                begin
16720
                    do_pause(3) ;
16721
 
16722
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16723
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16724
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16725
                            0, `Test_One_Zero_Target_WS,
16726
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16727
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16728
 
16729
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16730
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16731
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16732
                            0, `Test_One_Zero_Target_WS,
16733
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16734
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16735
 
16736
                    do_pause(1) ;
16737
                end
16738
                begin
16739
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16740
                    if ( ok !== 1 )
16741
                    begin
16742
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16743
                        disable monitor_error_event5 ;
16744
                    end
16745
                    else
16746
                    begin
16747
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16748
                        if ( ok !== 1 )
16749
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16750
                    end
16751
                end
16752
                join
16753
            end
16754
            disable monitor_error_event5 ;
16755
        end
16756
        begin:monitor_error_event5
16757
            @(error_event_int) ;
16758
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16759
            ok = 0 ;
16760
            disable wb_monitor5 ;
16761
        end
16762
        join
16763
 
16764
        if ( ok )
16765
            test_ok ;
16766
 
16767
        test_name = "DISABLING IO IMAGE" ;
16768 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16769 15 mihad
        if ( ok !== 1 )
16770
        begin
16771
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16772
            test_fail("PCI Address Mask register could not be written") ;
16773
            disable main ;
16774
        end
16775
    end
16776
 
16777
end
16778
endtask //target_fast_back_to_back
16779
 
16780
task target_disconnects ;
16781
    reg   [11:0] pci_ctrl_offset ;
16782
    reg   [11:0] ctrl_offset ;
16783
    reg   [11:0] ba_offset ;
16784
    reg   [11:0] am_offset ;
16785
    reg   [11:0] ta_offset ;
16786
    reg   [11:0] cls_offset ;
16787
    reg          pci_ok ;
16788
    reg          wb_ok ;
16789
    reg          ok ;
16790
    reg   [31:0] pci_address ;
16791
    reg   [31:0] data ;
16792
    reg   [3:0]  byte_enables ;
16793
    reg   [9:0]  expect_length ;
16794
 
16795
    reg          do_mem_disconnects ;
16796
    reg          do_io_disconnects ;
16797 35 mihad
    reg          error_monitor_done ;
16798 15 mihad
begin:main
16799
    if ( target_mem_image !== -1 )
16800
    begin
16801
        do_mem_disconnects = 1 ;
16802
 
16803
        if (target_mem_image === 1)
16804
        begin
16805
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16806
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16807
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16808
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16809
        end
16810
        else if (target_mem_image === 2)
16811
        begin
16812
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16813
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16814
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16815
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16816
        end
16817
        else if (target_mem_image === 3)
16818
        begin
16819
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16820
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16821
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16822
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16823
        end
16824
        else if (target_mem_image === 4)
16825
        begin
16826
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16827
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16828
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16829
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16830
        end
16831
        else if (target_mem_image === 5)
16832
        begin
16833
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16834
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16835
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16836
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16837
        end
16838
    end
16839
    else
16840
        do_mem_disconnects = 0 ;
16841
 
16842
    pci_ctrl_offset = 12'h4 ;
16843
    cls_offset = 12'h00C ;
16844
 
16845
    master1_check_received_data = 0 ;
16846
    master2_check_received_data = 0 ;
16847
 
16848
    `ifdef HOST
16849
        `ifdef NO_CNF_IMAGE
16850
        `else
16851
            `define TEST_BURST_CONFIG_READ
16852
        `endif
16853
    `else
16854
        `define TEST_BURST_CONFIG_READ
16855
        `define TEST_BURST_CONFIG_WRITE
16856
    `endif
16857
 
16858
    `ifdef TEST_BURST_CONFIG_WRITE
16859
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16860
 
16861
        data = 32'h0000_08_08 ;
16862
 
16863 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16864 15 mihad
        byte_enables = 4'b0000 ;
16865
 
16866
        fork
16867
        begin
16868
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16869
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16870
                    byte_enables,
16871
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16872
                    8'h0_0, `Test_One_Zero_Target_WS,
16873
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16874
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16875
 
16876
            data = 32'h0000_04_04 ;
16877
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16878
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16879
                    byte_enables,
16880
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16881
                    8'h0_0, `Test_One_Zero_Target_WS,
16882
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16883
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16884
            do_pause( 1 ) ;
16885
            while ( FRAME !== 1 || IRDY !== 1 )
16886
                @(posedge pci_clock) ;
16887
 
16888 35 mihad
            #1 ;
16889
            if ( !error_monitor_done )
16890
                disable monitor_error_event1 ;
16891 15 mihad
        end
16892
        begin:monitor_error_event1
16893 35 mihad
            error_monitor_done = 0 ;
16894 15 mihad
            ok = 1 ;
16895
            @(error_event_int) ;
16896
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16897
            ok = 0 ;
16898 35 mihad
            error_monitor_done = 1 ;
16899 15 mihad
        end
16900
        join
16901
 
16902
        config_read(pci_address, 4'hF, data) ;
16903
        if ( data [15:0] !== 16'h04_04 )
16904
        begin
16905
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16906
        end
16907
        else if ( ok )
16908
            test_ok ;
16909
 
16910 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16911
 
16912
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16913 15 mihad
        data         = 32'h0000_0808 ;
16914
        byte_enables = 4'h0 ;
16915
        fork
16916
        begin
16917
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16918
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16919
                    byte_enables,
16920
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16921
                    8'h0_0, `Test_One_Zero_Target_WS,
16922
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16923
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16924
 
16925
            data = 32'h0000_04_04 ;
16926
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16927
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16928
                    byte_enables,
16929
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16930
                    8'h0_0, `Test_One_Zero_Target_WS,
16931
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16932
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16933
 
16934
            do_pause( 1 ) ;
16935
            while ( FRAME !== 1 || IRDY !== 1 )
16936
                @(posedge pci_clock) ;
16937
 
16938 35 mihad
            #1 ;
16939
            if ( !error_monitor_done )
16940
                disable monitor_error_event2 ;
16941 15 mihad
        end
16942
        begin:monitor_error_event2
16943 35 mihad
            error_monitor_done = 0 ;
16944 15 mihad
            ok = 1 ;
16945
            @(error_event_int) ;
16946
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16947
            ok = 0 ;
16948 35 mihad
            error_monitor_done = 1 ;
16949 15 mihad
        end
16950
        join
16951
 
16952
        config_read(pci_address, 4'hF, data) ;
16953
        if ( data [15:0] !== 16'h04_04 )
16954
        begin
16955
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16956
        end
16957
        else if ( ok )
16958
            test_ok ;
16959
    `endif
16960
 
16961
    `ifdef TEST_BURST_CONFIG_READ
16962
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16963
 
16964
        data = 32'h0000_04_04 ;
16965
 
16966 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16967 15 mihad
        byte_enables = 4'b0000 ;
16968
 
16969
        fork
16970
        begin
16971
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16972
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16973
                    byte_enables,
16974
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16975
                    8'h0_0, `Test_One_Zero_Target_WS,
16976
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16977
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16978
            do_pause( 1 ) ;
16979
 
16980
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16981
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16982
                    byte_enables,
16983
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16984
                    8'h0_0, `Test_One_Zero_Target_WS,
16985
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16986
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16987
            do_pause( 1 ) ;
16988
 
16989
            while ( FRAME !== 1 || IRDY !== 1 )
16990
                @(posedge pci_clock) ;
16991
 
16992 35 mihad
            if ( !error_monitor_done )
16993
                disable monitor_error_event3 ;
16994 15 mihad
        end
16995
        begin:monitor_error_event3
16996 35 mihad
            error_monitor_done = 0 ;
16997 15 mihad
            ok = 1 ;
16998
            @(error_event_int) ;
16999
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17000
            ok = 0 ;
17001 35 mihad
            error_monitor_done = 1 ;
17002 15 mihad
        end
17003
        join
17004
 
17005
        if ( ok )
17006
            test_ok ;
17007
 
17008 45 mihad
 
17009
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
17010
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
17011 15 mihad
        fork
17012
        begin
17013
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17014
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17015
                    byte_enables,
17016
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17017
                    8'h0_0, `Test_One_Zero_Target_WS,
17018
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17019
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17020
            do_pause( 1 ) ;
17021
 
17022
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17023
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
17024
                    byte_enables,
17025
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17026
                    8'h0_0, `Test_One_Zero_Target_WS,
17027
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
17028
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17029
            do_pause( 1 ) ;
17030
 
17031
            while ( FRAME !== 1 || IRDY !== 1 )
17032
                @(posedge pci_clock) ;
17033
 
17034 35 mihad
            #1 ;
17035
            if ( !error_monitor_done )
17036
                disable monitor_error_event4 ;
17037 15 mihad
        end
17038
        begin:monitor_error_event4
17039 35 mihad
            error_monitor_done = 0 ;
17040 15 mihad
            ok = 1 ;
17041
            @(error_event_int) ;
17042
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
17043
            ok = 0 ;
17044 35 mihad
            error_monitor_done = 1 ;
17045 15 mihad
        end
17046
        join
17047
 
17048
        if ( ok )
17049
            test_ok ;
17050
    `endif
17051
 
17052
    `ifdef TEST_BURST_CONFIG_READ
17053
        `undef TEST_BURST_CONFIG_READ
17054
    `endif
17055
 
17056
    `ifdef TEST_BURST_CONFIG_WRITE
17057
        `undef TEST_BURST_CONFIG_WRITE
17058
    `endif
17059
 
17060
    master1_check_received_data = 1 ;
17061
    master2_check_received_data = 1 ;
17062
 
17063
    if ( do_mem_disconnects )
17064
    begin
17065
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17066
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
17067
        if ( ok !== 1 )
17068
        begin
17069
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17070
            test_fail("PCI Base Address register could not be written") ;
17071
            disable main ;
17072
        end
17073
 
17074
        // Set Address Mask of IMAGE
17075
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
17076
        if ( ok !== 1 )
17077
        begin
17078
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17079
            test_fail("PCI Address Mask register could not be written") ;
17080
            disable main ;
17081
        end
17082
 
17083
        // Set Translation Address of IMAGE
17084
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
17085
        if ( ok !== 1 )
17086
        begin
17087
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17088
            test_fail("PCI Translation Address Register could not be written") ;
17089
            disable main ;
17090
        end
17091
 
17092
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17093
        if ( ok !== 1 )
17094
        begin
17095
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17096
            test_fail("PCI Image Control register could not be written") ;
17097
            disable main ;
17098
        end
17099
 
17100
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17101
        if ( ok !== 1 )
17102
        begin
17103
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17104
            test_fail("Cache Line Size register could not be written") ;
17105
            disable main ;
17106
        end
17107
 
17108
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17109
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17110
        data = 32'hAAAA_AAAA ;
17111
        byte_enables = 4'h0 ;
17112
        expect_length = `PCIW_DEPTH - 2 ;
17113
 
17114
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17115
        fork
17116
        begin
17117
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17118
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17119
                        byte_enables,
17120 73 mihad
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17121 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17122
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17123 73 mihad
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17124 15 mihad
            do_pause( 3 ) ;
17125
 
17126
            while ( FRAME !== 1 || IRDY !== 1 )
17127
                @(posedge pci_clock) ;
17128
 
17129 35 mihad
            #1 ;
17130
            if ( !error_monitor_done )
17131
                disable monitor_error_event5 ;
17132 15 mihad
        end
17133
        begin:monitor_error_event5
17134 35 mihad
            error_monitor_done = 0 ;
17135 15 mihad
            pci_ok = 1 ;
17136
            @(error_event_int) ;
17137
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17138
            pci_ok = 0 ;
17139 35 mihad
            error_monitor_done = 1 ;
17140 15 mihad
        end
17141
        begin
17142
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17143
            if ( wb_ok !== 1 )
17144
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17145
        end
17146
        join
17147
 
17148
        if ( wb_ok && pci_ok )
17149
            test_ok ;
17150
 
17151
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17152
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17153
        data = 32'hAAAA_AAAA ;
17154
        byte_enables = 4'h0 ;
17155
        expect_length = `PCIW_DEPTH - 2 ;
17156
 
17157
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17158
        fork
17159
        begin
17160
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17161
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17162
                        byte_enables,
17163 73 mihad
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17164 15 mihad
                        8'h0_0, `Test_One_Zero_Target_WS,
17165
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17166 73 mihad
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17167 15 mihad
            do_pause( 3 ) ;
17168
 
17169
            while ( FRAME !== 1 || IRDY !== 1 )
17170
                @(posedge pci_clock) ;
17171
 
17172 35 mihad
            #1 ;
17173
            if ( !error_monitor_done )
17174
                disable monitor_error_event6 ;
17175 15 mihad
        end
17176
        begin:monitor_error_event6
17177 35 mihad
            error_monitor_done = 0 ;
17178 15 mihad
            pci_ok = 1 ;
17179
            @(error_event_int) ;
17180
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17181
            pci_ok = 0 ;
17182 35 mihad
            error_monitor_done = 1 ;
17183 15 mihad
        end
17184
        begin
17185
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17186
            if ( wb_ok !== 1 )
17187
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17188
        end
17189
        join
17190
 
17191
        if ( wb_ok && pci_ok )
17192
            test_ok ;
17193
 
17194
        master1_check_received_data = 1 ;
17195
//        master2_check_received_data = 0 ;
17196
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17197
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17198
        data = 32'hAAAA_AAAA ;
17199
        byte_enables = 4'h0 ;
17200
        expect_length = 4 ;
17201
 
17202
        fork
17203
        begin
17204
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17205
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17206
                        byte_enables,
17207
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17208
                        8'h0_0, `Test_One_Zero_Target_WS,
17209
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17210
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17211
            do_pause( 1 ) ;
17212
 
17213
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17214
            if ( wb_ok !== 1 )
17215
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17216
 
17217
            do_pause(2) ;
17218
 
17219
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17220
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17221
                        byte_enables,
17222
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17223
                        8'h0_0, `Test_One_Zero_Target_WS,
17224
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17225
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17226
            do_pause( 3 ) ;
17227
 
17228
            while ( FRAME !== 1 || IRDY !== 1 )
17229
                @(posedge pci_clock) ;
17230
 
17231 35 mihad
            #1 ;
17232
            if ( !error_monitor_done )
17233
                disable monitor_error_event7 ;
17234 15 mihad
        end
17235
        begin:monitor_error_event7
17236 35 mihad
            error_monitor_done = 0 ;
17237 15 mihad
            pci_ok = 1 ;
17238
            @(error_event_int) ;
17239
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17240
            pci_ok = 0 ;
17241 35 mihad
            error_monitor_done = 1 ;
17242 15 mihad
        end
17243
        join
17244
 
17245
        if ( wb_ok && pci_ok )
17246
            test_ok ;
17247
 
17248
        master1_check_received_data = 1 ;
17249
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17250
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17251
        data = 32'hAAAA_AAAA ;
17252
        byte_enables = 4'h0 ;
17253
        expect_length = 4 ;
17254
 
17255
        fork
17256
        begin
17257
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17258
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17259
                        byte_enables,
17260
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17261
                        8'h0_0, `Test_One_Zero_Target_WS,
17262
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17263
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17264
            do_pause( 1 ) ;
17265
 
17266
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17267
            if ( wb_ok !== 1 )
17268
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17269
 
17270
            do_pause(2) ;
17271
 
17272
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17273
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17274
                        byte_enables,
17275
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17276
                        8'h0_0, `Test_One_Zero_Target_WS,
17277
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17278
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17279
            do_pause( 3 ) ;
17280
 
17281
            while ( FRAME !== 1 || IRDY !== 1 )
17282
                @(posedge pci_clock) ;
17283
 
17284 35 mihad
            #1 ;
17285
            if ( !error_monitor_done )
17286
                disable monitor_error_event8 ;
17287 15 mihad
        end
17288
        begin:monitor_error_event8
17289 35 mihad
            error_monitor_done = 0 ;
17290 15 mihad
            pci_ok = 1 ;
17291
            @(error_event_int) ;
17292
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17293
            pci_ok = 0 ;
17294 35 mihad
            error_monitor_done = 1 ;
17295 15 mihad
        end
17296
        join
17297
 
17298
        if ( wb_ok && pci_ok )
17299
            test_ok ;
17300
 
17301
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17302
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17303
        data = 32'hDEAF_BEAF ;
17304
        byte_enables = 4'h0 ;
17305
        expect_length = 1 ;
17306
 
17307
        fork
17308
        begin
17309
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17310
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17311
                        byte_enables,
17312
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17313
                        8'h0_0, `Test_One_Zero_Target_WS,
17314
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17315
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17316
            do_pause( 3 ) ;
17317
 
17318
            while ( FRAME !== 1 || IRDY !== 1 )
17319
                @(posedge pci_clock) ;
17320
 
17321 35 mihad
            #1 ;
17322
            if ( !error_monitor_done )
17323
                disable monitor_error_event9 ;
17324 15 mihad
        end
17325
        begin:monitor_error_event9
17326 35 mihad
            error_monitor_done = 0 ;
17327 15 mihad
            pci_ok = 1 ;
17328
            @(error_event_int) ;
17329
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17330
            pci_ok = 0 ;
17331 35 mihad
            error_monitor_done = 1 ;
17332 15 mihad
        end
17333
        begin
17334
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17335
            if ( wb_ok !== 1 )
17336
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17337
        end
17338
        join
17339
 
17340
        if ( wb_ok && pci_ok )
17341
            test_ok ;
17342
 
17343
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17344
        data = 32'hDEAD_BEAF ;
17345
        byte_enables = 4'h0 ;
17346
        expect_length = 1 ;
17347
 
17348
        fork
17349
        begin
17350
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17351
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17352
                        byte_enables,
17353
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17354
                        8'h0_0, `Test_One_Zero_Target_WS,
17355
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17356
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17357
            do_pause( 3 ) ;
17358
 
17359
            while ( FRAME !== 1 || IRDY !== 1 )
17360
                @(posedge pci_clock) ;
17361
 
17362 35 mihad
            #1 ;
17363
            if ( !error_monitor_done )
17364
                disable monitor_error_event10 ;
17365 15 mihad
        end
17366
        begin:monitor_error_event10
17367 35 mihad
            error_monitor_done = 0 ;
17368 15 mihad
            pci_ok = 1 ;
17369
            @(error_event_int) ;
17370
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17371
            pci_ok = 0 ;
17372 35 mihad
            error_monitor_done = 1 ;
17373 15 mihad
        end
17374
        begin
17375
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17376
            if ( wb_ok !== 1 )
17377
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17378
        end
17379
        join
17380
 
17381
        if ( wb_ok && pci_ok )
17382
            test_ok ;
17383
 
17384
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17385
        data = 32'hAAAA_AAAA ;
17386
        byte_enables = 4'h0 ;
17387
        expect_length = 1 ;
17388
 
17389
        fork
17390
        begin
17391
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17392
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17393
                        byte_enables,
17394
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17395
                        8'h0_0, `Test_One_Zero_Target_WS,
17396
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17397
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17398
            do_pause( 3 ) ;
17399
 
17400
            while ( FRAME !== 1 || IRDY !== 1 )
17401
                @(posedge pci_clock) ;
17402
 
17403 35 mihad
            #1 ;
17404
            if ( !error_monitor_done )
17405
                disable monitor_error_event11 ;
17406 15 mihad
        end
17407
        begin:monitor_error_event11
17408 35 mihad
            error_monitor_done = 0 ;
17409 15 mihad
            pci_ok = 1 ;
17410
            @(error_event_int) ;
17411
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17412
            pci_ok = 0 ;
17413 35 mihad
            error_monitor_done = 1 ;
17414 15 mihad
        end
17415
        begin
17416
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17417
            if ( wb_ok !== 1 )
17418
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17419
        end
17420
        join
17421
 
17422
        if ( wb_ok && pci_ok )
17423
            test_ok ;
17424
 
17425
        master1_check_received_data = 1 ;
17426
 
17427
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17428
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17429
        data = 32'hDEAF_BEAF ;
17430
        byte_enables = 4'h0 ;
17431
        expect_length = 1 ;
17432
 
17433
        fork
17434
        begin
17435
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17436
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17437
                        byte_enables,
17438
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17439
                        8'h0_0, `Test_One_Zero_Target_WS,
17440
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17441
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17442
            do_pause( 1 ) ;
17443
 
17444
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17445
            if ( wb_ok !== 1 )
17446
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17447
 
17448
            do_pause(3) ;
17449
 
17450
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17451
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17452
                        byte_enables,
17453
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17454
                        8'h0_0, `Test_One_Zero_Target_WS,
17455
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17456
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17457
            do_pause( 3 ) ;
17458
 
17459
            while ( FRAME !== 1 || IRDY !== 1 )
17460
                @(posedge pci_clock) ;
17461
 
17462 35 mihad
            #1 ;
17463
            if ( !error_monitor_done )
17464
                disable monitor_error_event12 ;
17465 15 mihad
        end
17466
        begin:monitor_error_event12
17467 35 mihad
            error_monitor_done = 0 ;
17468 15 mihad
            pci_ok = 1 ;
17469
            @(error_event_int) ;
17470
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17471
            pci_ok = 0 ;
17472 35 mihad
            error_monitor_done = 1 ;
17473 15 mihad
        end
17474
        join
17475
 
17476
        if ( wb_ok && pci_ok )
17477
            test_ok ;
17478
 
17479
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17480
        data = 32'hDEAD_BEAF ;
17481
        byte_enables = 4'h0 ;
17482
        expect_length = 1 ;
17483
 
17484
        fork
17485
        begin
17486
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17487
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17488
                        byte_enables,
17489
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17490
                        8'h0_0, `Test_One_Zero_Target_WS,
17491
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17492
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17493
            do_pause( 1 ) ;
17494
 
17495
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17496
            if ( wb_ok !== 1 )
17497
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17498
 
17499
            do_pause(3) ;
17500
 
17501
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17502
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17503
                        byte_enables,
17504
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17505
                        8'h0_0, `Test_One_Zero_Target_WS,
17506
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17507
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17508
            do_pause( 3 ) ;
17509
 
17510
            while ( FRAME !== 1 || IRDY !== 1 )
17511
                @(posedge pci_clock) ;
17512
 
17513 35 mihad
            #1 ;
17514
            if ( !error_monitor_done )
17515
                disable monitor_error_event13 ;
17516 15 mihad
        end
17517
        begin:monitor_error_event13
17518 35 mihad
            error_monitor_done = 0 ;
17519 15 mihad
            pci_ok = 1 ;
17520
            @(error_event_int) ;
17521
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17522
            pci_ok = 0 ;
17523 35 mihad
            error_monitor_done = 1 ;
17524 15 mihad
        end
17525
        join
17526
 
17527
        if ( wb_ok && pci_ok )
17528
            test_ok ;
17529
 
17530
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17531
        data = 32'hAAAA_AAAA ;
17532
        byte_enables = 4'h0 ;
17533
        expect_length = 1 ;
17534
 
17535
        fork
17536
        begin
17537
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17538
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17539
                        byte_enables,
17540
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17541
                        8'h0_0, `Test_One_Zero_Target_WS,
17542
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17543
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17544
            do_pause( 1 ) ;
17545
 
17546
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17547
            if ( wb_ok !== 1 )
17548
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17549
 
17550
            do_pause(3) ;
17551
 
17552
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17553
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17554
                        byte_enables,
17555
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17556
                        8'h0_0, `Test_One_Zero_Target_WS,
17557
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17558
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17559
            do_pause( 3 ) ;
17560
 
17561
            while ( FRAME !== 1 || IRDY !== 1 )
17562
                @(posedge pci_clock) ;
17563
 
17564 35 mihad
            #1 ;
17565
            if ( !error_monitor_done )
17566
                disable monitor_error_event14 ;
17567 15 mihad
        end
17568
        begin:monitor_error_event14
17569 35 mihad
            error_monitor_done = 0 ;
17570 15 mihad
            pci_ok = 1 ;
17571
            @(error_event_int) ;
17572
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17573
            pci_ok = 0 ;
17574 35 mihad
            error_monitor_done = 1 ;
17575 15 mihad
        end
17576
        join
17577
 
17578
        if ( wb_ok && pci_ok )
17579
            test_ok ;
17580
 
17581
        // disable the image
17582
        test_name = "DISABLING MEMORY IMAGE" ;
17583 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17584 15 mihad
        if ( ok !== 1 )
17585
        begin
17586
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17587
            test_fail("PCI Address Mask register could not be written") ;
17588
            disable main ;
17589
        end
17590
    end
17591
//*
17592
    if ( target_io_image !== -1 )
17593
    begin
17594
        do_io_disconnects = 1 ;
17595
 
17596
        if (target_io_image === 1)
17597
        begin
17598
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17599
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17600
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17601
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17602
        end
17603
        else if (target_io_image === 2)
17604
        begin
17605
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17606
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17607
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17608
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17609
        end
17610
        else if (target_io_image === 3)
17611
        begin
17612
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17613
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17614
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17615
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17616
        end
17617
        else if (target_io_image === 4)
17618
        begin
17619
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17620
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17621
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17622
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17623
        end
17624
        else if (target_io_image === 5)
17625
        begin
17626
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17627
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17628
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17629
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17630
        end
17631
    end
17632
    else
17633
        do_io_disconnects = 0 ;
17634
 
17635
    if ( do_io_disconnects )
17636
    begin
17637
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17638
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17639
        if ( ok !== 1 )
17640
        begin
17641
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17642
            test_fail("PCI Base Address register could not be written") ;
17643
            disable main ;
17644
        end
17645
 
17646
        // Set Address Mask of IMAGE
17647
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17648
        if ( ok !== 1 )
17649
        begin
17650
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17651
            test_fail("PCI Address Mask register could not be written") ;
17652
            disable main ;
17653
        end
17654
 
17655
        // Set Translation Address of IMAGE
17656
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17657
        if ( ok !== 1 )
17658
        begin
17659
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17660
            test_fail("PCI Translation Address Register could not be written") ;
17661
            disable main ;
17662
        end
17663
 
17664
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17665
        if ( ok !== 1 )
17666
        begin
17667
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17668
            test_fail("PCI Image Control register could not be written") ;
17669
            disable main ;
17670
        end
17671
 
17672
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17673
        if ( ok !== 1 )
17674
        begin
17675
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17676
            test_fail("Cache Line Size register could not be written") ;
17677
            disable main ;
17678
        end
17679
 
17680
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17681
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17682
        data = 32'h5555_5555 ;
17683
        byte_enables = 4'h0 ;
17684
        expect_length = 1 ;
17685
 
17686
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17687
 
17688
        fork
17689
        begin
17690
            PCIU_IO_WRITE
17691
            (
17692
                `Test_Master_1,             // which master
17693
                pci_address,                // to what address
17694
                data,                       // data
17695
                byte_enables,               // byte enable
17696
                expect_length + 1,          // length to request
17697
                `Test_Target_Retry_On       // expected target termination
17698
            ) ;
17699
 
17700
            do_pause( 3 ) ;
17701
 
17702
            while ( FRAME !== 1 || IRDY !== 1 )
17703
                @(posedge pci_clock) ;
17704
 
17705 35 mihad
            #1 ;
17706
            if ( !error_monitor_done )
17707
                disable monitor_error_event15 ;
17708 15 mihad
        end
17709
        begin:monitor_error_event15
17710 35 mihad
            error_monitor_done = 0 ;
17711 15 mihad
            pci_ok = 1 ;
17712
            @(error_event_int) ;
17713
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17714
            pci_ok = 0 ;
17715 35 mihad
            error_monitor_done = 1 ;
17716 15 mihad
        end
17717
        begin
17718
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17719
            if ( wb_ok !== 1 )
17720
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17721
        end
17722
        join
17723
 
17724
        if ( wb_ok && pci_ok )
17725
            test_ok ;
17726
 
17727
        data = 32'hAAAA_AAAA ;
17728
        fork
17729
        begin
17730
            PCIU_IO_WRITE
17731
            (
17732
                `Test_Master_1,             // which master
17733
                pci_address,                // to what address
17734
                data,                       // data
17735
                byte_enables,               // byte enable
17736
                expect_length + 2,          // length to request
17737
                `Test_Target_Retry_Before   // expected target termination
17738
            ) ;
17739
 
17740
            do_pause( 3 ) ;
17741
 
17742
            while ( FRAME !== 1 || IRDY !== 1 )
17743
                @(posedge pci_clock) ;
17744
 
17745 35 mihad
            #1 ;
17746
            if ( !error_monitor_done )
17747
                disable monitor_error_event16 ;
17748 15 mihad
        end
17749
        begin:monitor_error_event16
17750 35 mihad
            error_monitor_done = 0 ;
17751 15 mihad
            pci_ok = 1 ;
17752
            @(error_event_int) ;
17753
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17754
            pci_ok = 0 ;
17755 35 mihad
            error_monitor_done = 1 ;
17756 15 mihad
        end
17757
        begin
17758
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17759
            if ( wb_ok !== 1 )
17760
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17761
        end
17762
        join
17763
 
17764
        if ( wb_ok && pci_ok )
17765
            test_ok ;
17766
 
17767
        master2_check_received_data = 1 ;
17768
 
17769
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17770
 
17771
        fork
17772
        begin
17773
 
17774
             PCIU_IO_READ
17775
             (
17776
                `Test_Master_2,
17777
                pci_address[PCI_BUS_DATA_RANGE:0],
17778
                data,
17779
                byte_enables,
17780
                2,
17781
                `Test_Target_Retry_Before
17782
             );
17783
 
17784
            do_pause( 1 ) ;
17785
 
17786
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17787
            if ( wb_ok !== 1 )
17788
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17789
 
17790
            do_pause(3) ;
17791
 
17792
            PCIU_IO_READ
17793
             (
17794
                `Test_Master_2,
17795
                pci_address[PCI_BUS_DATA_RANGE:0],
17796
                data,
17797
                byte_enables,
17798
                expect_length + 1,
17799
                `Test_Target_Retry_On
17800
             );
17801
 
17802
            do_pause( 3 ) ;
17803
 
17804
            while ( FRAME !== 1 || IRDY !== 1 )
17805
                @(posedge pci_clock) ;
17806
 
17807 35 mihad
            #1 ;
17808
            if ( !error_monitor_done )
17809
                disable monitor_error_event17 ;
17810 15 mihad
        end
17811
        begin:monitor_error_event17
17812 35 mihad
            error_monitor_done = 0 ;
17813 15 mihad
            pci_ok = 1 ;
17814
            @(error_event_int) ;
17815
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17816
            pci_ok = 0 ;
17817 35 mihad
            error_monitor_done = 1 ;
17818 15 mihad
        end
17819
        join
17820
 
17821
        if ( wb_ok && pci_ok )
17822
            test_ok ;
17823
 
17824
        fork
17825
        begin
17826
 
17827
             PCIU_IO_READ
17828
             (
17829
                `Test_Master_2,
17830
                pci_address[PCI_BUS_DATA_RANGE:0],
17831
                data,
17832
                byte_enables,
17833
                2,
17834
                `Test_Target_Retry_Before
17835
             );
17836
 
17837
            do_pause( 1 ) ;
17838
 
17839
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17840
            if ( wb_ok !== 1 )
17841
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17842
 
17843
            do_pause(3) ;
17844
 
17845
            PCIU_IO_READ
17846
             (
17847
                `Test_Master_2,
17848
                pci_address[PCI_BUS_DATA_RANGE:0],
17849
                data,
17850
                byte_enables,
17851
                expect_length + 2,
17852
                `Test_Target_Retry_Before
17853
             );
17854
 
17855
            do_pause( 3 ) ;
17856
 
17857
            while ( FRAME !== 1 || IRDY !== 1 )
17858
                @(posedge pci_clock) ;
17859
 
17860 35 mihad
            #1 ;
17861
            if ( !error_monitor_done )
17862
                disable monitor_error_event18 ;
17863 15 mihad
        end
17864
        begin:monitor_error_event18
17865 35 mihad
            error_monitor_done = 0 ;
17866 15 mihad
            pci_ok = 1 ;
17867
            @(error_event_int) ;
17868
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17869
            pci_ok = 0 ;
17870 35 mihad
            error_monitor_done = 1 ;
17871 15 mihad
        end
17872
        join
17873
 
17874
        if ( wb_ok && pci_ok )
17875
            test_ok ;
17876
 
17877
        test_name = "DISABLING IO IMAGE" ;
17878 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17879 15 mihad
        if ( ok !== 1 )
17880
        begin
17881
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17882
            test_fail("PCI Address Mask register could not be written") ;
17883
            disable main ;
17884
        end
17885
    end
17886
//*/
17887
end
17888
endtask // target_disconnects
17889
 
17890
task target_unsupported_cmds ;
17891
        input [31:0] Address;
17892
        input [2:0]  image_num ;
17893
    reg          ok ;
17894
begin:main
17895
 
17896
    $display("  ") ;
17897
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17898
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17899 45 mihad
 
17900
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17901
    configuration_cycle_write
17902
    (
17903
        0,                        // bus number
17904
        `TAR1_IDSEL_INDEX - 11,   // device number
17905
        0,                        // function number
17906
        1,                        // register number
17907
        0,                        // type of configuration cycle
17908
        4'b0001,                  // byte enables
17909
        32'h0000_0044             // data
17910
    ) ;
17911
 
17912
    configuration_cycle_write
17913
    (
17914
        0,                        // bus number
17915
        `TAR2_IDSEL_INDEX - 11,   // device number
17916
        0,                        // function number
17917
        1,                        // register number
17918
        0,                        // type of configuration cycle
17919
        4'b0001,                  // byte enables
17920
        32'h0000_0044             // data
17921
    ) ;
17922
 
17923 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17924 15 mihad
    (
17925
        Address,                // first part of address in dual address cycle
17926
        Address,                // second part of address in dual address cycle
17927
        `BC_IACK,                       // dual address cycle command
17928
        `BC_IACK,               // normal command
17929
        4'h0,               // byte enables
17930
        32'h1234_5678,      // data
17931
        1'b0,               // make address parity error on first phase of dual address
17932
        1'b0,               // make address parity error on second phase of dual address
17933
        ok                  // result of operation
17934
    ) ;
17935
    if ( ok )
17936
        test_ok ;
17937
    else
17938
    begin
17939
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17940
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17941
    end
17942
 
17943
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17944
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17945 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17946 15 mihad
    (
17947
        Address,                // first part of address in dual address cycle
17948
        Address,                // second part of address in dual address cycle
17949
        `BC_SPECIAL,            // dual address cycle command
17950
        `BC_SPECIAL,            // normal command
17951
        4'h0,               // byte enables
17952
        32'h1234_5678,      // data
17953
        1'b0,               // make address parity error on first phase of dual address
17954
        1'b0,               // make address parity error on second phase of dual address
17955
        ok                  // result of operation
17956
    ) ;
17957
    if ( ok )
17958
        test_ok ;
17959
    else
17960
    begin
17961
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17962
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17963
    end
17964
 
17965
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17966
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17967 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17968 15 mihad
    (
17969
        Address,                // first part of address in dual address cycle
17970
        Address,                // second part of address in dual address cycle
17971
        `BC_RESERVED0,          // dual address cycle command
17972
        `BC_RESERVED0,      // normal command
17973
        4'h0,               // byte enables
17974
        32'h1234_5678,      // data
17975
        1'b0,               // make address parity error on first phase of dual address
17976
        1'b0,               // make address parity error on second phase of dual address
17977
        ok                  // result of operation
17978
    ) ;
17979
    if ( ok )
17980
        test_ok ;
17981
    else
17982
    begin
17983
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17984
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17985
    end
17986
 
17987
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17988
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17989 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
17990 15 mihad
    (
17991
        Address,                // first part of address in dual address cycle
17992
        Address,                // second part of address in dual address cycle
17993
        `BC_RESERVED1,          // dual address cycle command
17994
        `BC_RESERVED1,      // normal command
17995
        4'h0,               // byte enables
17996
        32'h1234_5678,      // data
17997
        1'b0,               // make address parity error on first phase of dual address
17998
        1'b0,               // make address parity error on second phase of dual address
17999
        ok                  // result of operation
18000
    ) ;
18001
    if ( ok )
18002
        test_ok ;
18003
    else
18004
    begin
18005
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18006
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
18007
    end
18008
 
18009
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
18010
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
18011 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18012 15 mihad
    (
18013
        Address,                // first part of address in dual address cycle
18014
        Address,                // second part of address in dual address cycle
18015
        `BC_RESERVED2,          // dual address cycle command
18016
        `BC_RESERVED2,      // normal command
18017
        4'h0,               // byte enables
18018
        32'h1234_5678,      // data
18019
        1'b0,               // make address parity error on first phase of dual address
18020
        1'b0,               // make address parity error on second phase of dual address
18021
        ok                  // result of operation
18022
    ) ;
18023
    if ( ok )
18024
        test_ok ;
18025
    else
18026
    begin
18027
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18028
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
18029
    end
18030
 
18031
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
18032
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
18033 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18034 15 mihad
    (
18035
        Address,                // first part of address in dual address cycle
18036
        Address,                // second part of address in dual address cycle
18037
        `BC_RESERVED3,          // dual address cycle command
18038
        `BC_RESERVED3,      // normal command
18039
        4'h0,               // byte enables
18040
        32'h1234_5678,      // data
18041
        1'b0,               // make address parity error on first phase of dual address
18042
        1'b0,               // make address parity error on second phase of dual address
18043
        ok                  // result of operation
18044
    ) ;
18045
    if ( ok )
18046
        test_ok ;
18047
    else
18048
    begin
18049
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18050
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
18051
    end
18052
 
18053
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
18054
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
18055
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
18056
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
18057 73 mihad
    ipci_unsupported_commands_master.unsupported_reference
18058 15 mihad
    (
18059
        Address,                // first part of address in dual address cycle
18060
        Address,                // second part of address in dual address cycle
18061
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
18062
        `BC_MEM_WRITE,      // normal command
18063
        4'h0,               // byte enables;
18064
        32'h1234_5678,      // data
18065
        1'b0,               // make address parity error on first phase of dual address
18066
        1'b0,               // make address parity error on second phase of dual address
18067
        ok                  // result of operation
18068
    ) ;
18069
    if ( ok )
18070
        test_ok ;
18071
    else
18072
    begin
18073
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18074
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
18075
    end
18076
 
18077 45 mihad
    // enable pci blue behavioral targets 1 and 2
18078
    configuration_cycle_write
18079
    (
18080
        0,                        // bus number
18081
        `TAR1_IDSEL_INDEX - 11,   // device number
18082
        0,                        // function number
18083
        1,                        // register number
18084
        0,                        // type of configuration cycle
18085
        4'b0001,                  // byte enables
18086
        32'h0000_0047             // data
18087
    ) ;
18088
 
18089
    configuration_cycle_write
18090
    (
18091
        0,                        // bus number
18092
        `TAR2_IDSEL_INDEX - 11,   // device number
18093
        0,                        // function number
18094
        1,                        // register number
18095
        0,                        // type of configuration cycle
18096
        4'b0001,                  // byte enables
18097
        32'h0000_0047             // data
18098
    ) ;
18099 15 mihad
end
18100
endtask // target_unsupported_cmds
18101
 
18102 63 mihad
`ifdef DISABLE_COMPLETION_EXPIRED_TESTS
18103
`else
18104 15 mihad
task target_completion_expiration ;
18105
    reg   [11:0] pci_ctrl_offset ;
18106
    reg   [11:0] pci_ba_offset ;
18107
    reg   [11:0] pci_am_offset ;
18108
    reg   [11:0] pci_device_ctrl_offset ;
18109
    reg   [11:0] pci_err_cs_offset ;
18110
    reg   [11:0] icr_offset ;
18111
    reg   [11:0] isr_offset ;
18112
    reg   [11:0] lat_tim_cls_offset ;
18113
 
18114
    reg [31:0] temp_val1 ;
18115
    reg [31:0] temp_val2 ;
18116
    reg        ok   ;
18117 33 mihad
    reg        ok_wb ;
18118
    reg        ok_pci ;
18119 15 mihad
 
18120
    reg [31:0] pci_image_base ;
18121
    integer i ;
18122 33 mihad
    integer clocks_after_completion ;
18123
    reg     error_monitor_done ;
18124
    reg     test_mem ;
18125 15 mihad
 
18126
begin:main
18127
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18128
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
18129
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
18130
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
18131
 
18132
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
18133
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
18134
    lat_tim_cls_offset = 12'hC ;
18135
    pci_device_ctrl_offset    = 12'h4 ;
18136
 
18137 33 mihad
    `ifdef HOST
18138
        test_mem = 1'b1 ;
18139
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
18140
    `else
18141
        test_mem = !`PCI_BA1_MEM_IO ;
18142
        pci_image_base = Target_Base_Addr_R[1] ;
18143
    `endif
18144 15 mihad
 
18145
    // enable master & target operation
18146
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
18147
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
18148
    if ( ok !== 1 )
18149
    begin
18150
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18151
        test_fail("write to PCI Device Control register failed") ;
18152
        disable main ;
18153
    end
18154
 
18155
    // prepare image control register
18156 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18157 15 mihad
    if ( ok !== 1 )
18158
    begin
18159
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18160
        test_fail("write to PCI Image Control register failed") ;
18161
        disable main ;
18162
    end
18163
 
18164
    // prepare base address register
18165
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18166
    if ( ok !== 1 )
18167
    begin
18168
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18169
        test_fail("write to PCI Base Address register failed") ;
18170
        disable main ;
18171
    end
18172
 
18173
    // write address mask register
18174
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18175
    if ( ok !== 1 )
18176
    begin
18177
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18178
        test_fail("write to PCI Address Mask register failed") ;
18179
        disable main ;
18180
    end
18181
 
18182
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18183
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18184
    if ( ok !== 1 )
18185
    begin
18186
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18187
        test_fail("write to PCI Error Control and Status register failed") ;
18188
        disable main ;
18189
    end
18190
 
18191 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18192 15 mihad
    if ( ok !== 1 )
18193
    begin
18194
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18195
        test_fail("write to Interrupt Control register failed") ;
18196
        disable main ;
18197
    end
18198
 
18199
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18200
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18201
    if ( ok !== 1 )
18202
    begin
18203
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18204
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18205
        disable main ;
18206
    end
18207
 
18208
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18209
 
18210
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18211 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18212
    master1_check_received_data = 0 ;
18213 15 mihad
 
18214 33 mihad
    ok_pci = 1 ;
18215
    // start a delayed read request
18216
    fork
18217
    begin
18218
        if ( test_mem )
18219
 
18220
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18221
                          pci_image_base, 32'h1234_5678,
18222
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18223
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18224
        else
18225
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18226
 
18227
        do_pause( 1 ) ;
18228
    end
18229
    begin:error_monitor1
18230 35 mihad
        error_monitor_done = 0 ;
18231 33 mihad
        @(error_event_int) ;
18232
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18233
        ok_pci = 0 ;
18234 35 mihad
        error_monitor_done = 1 ;
18235 33 mihad
    end
18236
    begin
18237
        if ( test_mem )
18238
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18239
        else
18240
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18241 15 mihad
 
18242 33 mihad
        if ( ok_wb !== 1 )
18243
        begin
18244
            test_fail("Bridge failed to process Target Memory read correctly") ;
18245
            disable main ;
18246
        end
18247
 
18248 35 mihad
        #1 ;
18249
        if ( !error_monitor_done )
18250 33 mihad
            disable error_monitor1 ;
18251
    end
18252
    join
18253
 
18254
    clocks_after_completion = 0 ;
18255
    // now do another - different transaction
18256
    fork
18257
    begin
18258
        if ( test_mem )
18259
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18260
                          pci_image_base + 4, 32'h1234_5678,
18261
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18262
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18263
        else
18264
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18265
 
18266
        while ( clocks_after_completion < 32'h0000_FFF0 )
18267
        begin
18268
            @(posedge pci_clock) ;
18269
            clocks_after_completion = clocks_after_completion + 1 ;
18270
        end
18271
 
18272
        do_pause('hFF) ;
18273
 
18274
        if ( test_mem )
18275
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18276
                          pci_image_base + 4, 32'h1234_5678,
18277
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18278
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18279
        else
18280
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18281
 
18282
        do_pause( 1 ) ;
18283
    end
18284
    begin:error_monitor2
18285 35 mihad
        error_monitor_done = 0 ;
18286 33 mihad
        @(error_event_int) ;
18287
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18288
        ok_pci = 0 ;
18289 35 mihad
        error_monitor_done = 1 ;
18290 33 mihad
    end
18291
    begin
18292
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18293
        repeat( 'hFF )
18294
            @(posedge pci_clock) ;
18295
 
18296
        if ( test_mem )
18297
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18298
        else
18299
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18300
 
18301
        if ( ok_wb !== 1 )
18302
        begin
18303
            test_fail("Bridge failed to process Target Memory read correctly") ;
18304
            disable main ;
18305
        end
18306
 
18307
        repeat(4)
18308
            @(posedge pci_clock) ;
18309
 
18310
        fork
18311
        begin
18312
            if ( test_mem )
18313
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18314
                              pci_image_base + 4, 32'h1234_5678,
18315
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18316
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18317
            else
18318
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18319
 
18320
            do_pause(1) ;
18321
        end
18322
        begin
18323
           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 ) ;
18324 35 mihad
           #1 ;
18325
           if ( !error_monitor_done )
18326 33 mihad
               disable error_monitor2 ;
18327
        end
18328
        join
18329
    end
18330
    join
18331
 
18332
    if ( ok && ok_pci && ok_wb )
18333
        test_ok ;
18334
 
18335
    if ( ok !== 1 )
18336
    begin
18337
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18338
        test_fail("write to PCI Address Mask register failed") ;
18339
        disable main ;
18340
    end
18341
 
18342
    // check statuses after this situation - none should be set
18343
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18344
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18345
    if ( ok !== 1 )
18346
    begin
18347
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18348
        test_fail("read from pci device status register failed") ;
18349
        disable main ;
18350
    end
18351
 
18352
    if ( temp_val1[31] )
18353
    begin
18354
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18355
        test_fail("detected parity error bit was set for no reason") ;
18356
    end
18357
 
18358
    if ( temp_val1[30] )
18359
    begin
18360
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18361
        test_fail("signaled system error bit was set for no reason") ;
18362
    end
18363
 
18364
    if ( temp_val1[29] )
18365
    begin
18366
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18367
        test_fail("received master abort bit was set for no reason") ;
18368
    end
18369
 
18370
    if ( temp_val1[28] )
18371
    begin
18372
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18373
        test_fail("received target abort bit was set for no reason") ;
18374
    end
18375
 
18376
    if ( temp_val1[27] )
18377
    begin
18378
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18379
        test_fail("signaled target abort bit was set for no reason") ;
18380
    end
18381
 
18382
    if ( temp_val1[24] )
18383
    begin
18384
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18385
        test_fail("Master Data parity error bit was set for no reason") ;
18386
    end
18387
 
18388
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18389
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18390
    if ( temp_val1[8] !== 0 )
18391
    begin
18392
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18393
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18394
    end
18395
    // test target retry counter expiration
18396
    // set wb slave to retry response
18397
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18398
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18399
    ok_pci = 1 ;
18400
 
18401
    fork
18402
    begin
18403
        if ( test_mem == 1 )
18404
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18405
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18406
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18407
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18408
        else
18409
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18410
 
18411
        do_pause(1) ;
18412
 
18413
        // do another write with same address and different data
18414
        if ( test_mem == 1 )
18415
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18416
                        pci_image_base, 32'h8765_4321, 4'h0,
18417
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18418
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18419
        else
18420
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18421
 
18422
        do_pause(1) ;
18423
    end
18424
    begin
18425
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18426
        begin
18427
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18428
            if ( ok_wb !== 1 )
18429
            begin
18430
                $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) ;
18431
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18432
                disable main ;
18433
            end
18434
        end
18435
 
18436
        // set WB slave to normal completion
18437
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18438
 
18439
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18440
        if ( ok_wb !== 1 )
18441
        begin
18442
            $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) ;
18443
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18444
            disable main ;
18445
        end
18446
 
18447 35 mihad
        #1 ;
18448
        if ( !error_monitor_done )
18449 33 mihad
            disable error_monitor3 ;
18450
    end
18451
    begin:error_monitor3
18452 35 mihad
        error_monitor_done = 0 ;
18453 33 mihad
        @(error_event_int) ;
18454
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18455
        ok_pci = 0 ;
18456 35 mihad
        error_monitor_done = 1 ;
18457 33 mihad
    end
18458
    join
18459
 
18460
    if ( ok_wb && ok_pci )
18461
    begin
18462
        test_ok ;
18463
    end
18464
 
18465
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18466
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18467
    if ( temp_val1[8] !== 1'b1 )
18468
    begin
18469
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18470
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18471
    end
18472
 
18473
    if ( temp_val1[9] !== 1 )
18474
    begin
18475
        $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) ;
18476
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18477
    end
18478
 
18479
    if ( temp_val1[10] !== 1 )
18480
    begin
18481
        $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) ;
18482
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18483
    end
18484
 
18485
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18486
    begin
18487
        $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) ;
18488
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18489
    end
18490
 
18491
    if ( temp_val1[31:28] !== 4'hA )
18492
    begin
18493
        $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) ;
18494
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18495
    end
18496
 
18497
    // clear error status register
18498
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18499
 
18500
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18501
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18502
    if ( temp_val1 !== pci_image_base )
18503
    begin
18504
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18505
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18506
    end
18507
 
18508
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18509
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18510
    if ( temp_val1 !== 32'hDEAD_BEAF )
18511
    begin
18512
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18513
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18514
    end
18515
 
18516
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18517
    ok_pci = 1 ;
18518
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18519
 
18520
    i = 0 ;
18521
    fork
18522
    begin
18523
        if ( test_mem )
18524
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18525
                          pci_image_base + 4, 32'h1234_5678,
18526
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18527
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18528
        else
18529
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18530
 
18531
        do_pause( 1 ) ;
18532
 
18533
    end
18534
    begin
18535
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18536
        begin
18537
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18538
            if ( ok_wb !== 1 )
18539
            begin
18540
                $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) ;
18541
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18542
                disable main ;
18543
            end
18544
        end
18545
 
18546
        // set WB slave to normal completion
18547
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18548
 
18549
        fork
18550
        begin
18551
            repeat(4)
18552
                @(posedge pci_clock) ;
18553
 
18554
            if ( test_mem )
18555
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18556
                              pci_image_base, 32'h8765_4321,
18557
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18558
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18559
            else
18560
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18561
 
18562
            do_pause(1) ;
18563
        end
18564
        begin
18565
 
18566
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18567
            if ( ok_wb !== 1 )
18568
            begin
18569
                $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) ;
18570
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18571
                disable main ;
18572
            end
18573
        end
18574
        join
18575
 
18576
        repeat( 4 )
18577
            @(posedge pci_clock) ;
18578
 
18579
        if ( test_mem )
18580
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18581
                          pci_image_base, 32'h8765_4321,
18582
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18583
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18584
        else
18585
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18586
 
18587
        do_pause(1) ;
18588
 
18589 35 mihad
        #1 ;
18590
        if ( !error_monitor_done )
18591 33 mihad
            disable error_monitor4 ;
18592
    end
18593
    begin:error_monitor4
18594 35 mihad
        error_monitor_done = 0 ;
18595 33 mihad
        @(error_event_int) ;
18596
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18597
        ok_pci = 0 ;
18598 35 mihad
        error_monitor_done = 1 ;
18599 33 mihad
    end
18600
    join
18601
 
18602
    if ( ok_wb && ok_pci )
18603
        test_ok ;
18604
 
18605
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18606
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18607
    if ( temp_val1[8] !== 1'b0 )
18608
    begin
18609
        $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) ;
18610
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18611
    end
18612
 
18613
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18614 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18615
    $fdisplay(pciu_mon_log_file_desc,
18616
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18617 33 mihad
    ok_pci = 1 ;
18618
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18619
 
18620
    fork
18621
    begin
18622
        if ( test_mem )
18623
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18624
                          pci_image_base + 4, 32'h1234_5678,
18625
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18626
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18627
        else
18628
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18629
 
18630
        do_pause( 1 ) ;
18631
 
18632
    end
18633
    begin
18634
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18635
        if ( ok_wb !== 1 )
18636
        begin
18637
            $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) ;
18638
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18639
            disable main ;
18640
        end
18641
 
18642
        repeat(4)
18643
            @(posedge pci_clock) ;
18644
 
18645
        fork
18646
        begin
18647
 
18648
            if ( test_mem )
18649
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18650
                              pci_image_base + 4, 32'h8765_4321,
18651
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18652
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18653
            else
18654
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18655
 
18656
            do_pause(1) ;
18657
 
18658
        end
18659
        begin
18660
 
18661
            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 ) ;
18662
            if ( ok !== 1 )
18663
            begin
18664
                $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) ;
18665
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18666
                disable main ;
18667
            end
18668
        end
18669
        join
18670
 
18671 35 mihad
        #1 ;
18672
        if ( !error_monitor_done )
18673 33 mihad
            disable error_monitor5 ;
18674
    end
18675
    begin:error_monitor5
18676 35 mihad
        error_monitor_done = 0 ;
18677 33 mihad
        @(error_event_int) ;
18678
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18679
        ok_pci = 0 ;
18680 35 mihad
        error_monitor_done = 1 ;
18681 33 mihad
    end
18682
    join
18683
 
18684
    if ( ok_wb && ok_pci )
18685
        test_ok ;
18686
 
18687
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18688
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18689
    if ( temp_val1[8] !== 1'b0 )
18690
    begin
18691
        $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) ;
18692
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18693
    end
18694
 
18695
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18696
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18697
    if ( temp_val1[25] !== 1'b1 )
18698
    begin
18699
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18700
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18701
    end
18702
 
18703
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18704
 
18705
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18706
    ok_pci = 1 ;
18707
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18708
 
18709
    fork
18710
    begin
18711
        if ( test_mem == 1 )
18712
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18713
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18714
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18715
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18716
        else
18717
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18718
 
18719
        do_pause(1) ;
18720
 
18721
        // do another write with same address and different data
18722
        if ( test_mem == 1 )
18723
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18724
                        pci_image_base, 32'h8765_6789, 4'h0,
18725
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18726
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18727
        else
18728
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18729
 
18730
        do_pause(1) ;
18731
    end
18732
    begin
18733
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18734
        if ( ok_wb !== 1 )
18735
        begin
18736
            $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) ;
18737
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18738
            disable main ;
18739
        end
18740
 
18741
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18742
 
18743
        if ( test_mem )
18744
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18745
        else
18746
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18747
 
18748
        if ( ok_wb !== 1 )
18749
        begin
18750
            $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) ;
18751
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18752
            disable main ;
18753
        end
18754
 
18755 35 mihad
        #1 ;
18756
        if ( !error_monitor_done )
18757 33 mihad
            disable error_monitor6 ;
18758
    end
18759
    begin:error_monitor6
18760 35 mihad
        error_monitor_done = 0 ;
18761 33 mihad
        @(error_event_int) ;
18762
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18763
        ok_pci = 0 ;
18764 35 mihad
        error_monitor_done = 1 ;
18765 33 mihad
    end
18766
    join
18767
 
18768
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18769
    $fdisplay(pciu_mon_log_file_desc,
18770
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18771
 
18772
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18773
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18774
    if ( temp_val1[8] !== 1'b1 )
18775
    begin
18776
        $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) ;
18777
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18778
    end
18779
 
18780
    if ( temp_val1[9] !== 0 )
18781
    begin
18782
        $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) ;
18783
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18784
    end
18785
 
18786
    if ( temp_val1[10] !== 1 )
18787
    begin
18788
        $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) ;
18789
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18790
    end
18791
 
18792
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18793
    begin
18794
        $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) ;
18795
        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") ;
18796
    end
18797
 
18798
    if ( temp_val1[31:28] !== 4'h0 )
18799
    begin
18800
        $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) ;
18801
        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") ;
18802
    end
18803
 
18804
    // clear error status register
18805
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18806
 
18807
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18808
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18809
    if ( temp_val1 !== pci_image_base )
18810
    begin
18811
        $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) ;
18812
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18813
    end
18814
 
18815
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18816
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18817
    if ( temp_val1 !== 32'hBEAF_DEAD )
18818
    begin
18819
        $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) ;
18820
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18821
    end
18822
 
18823
    // disable current image - write address mask register
18824 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18825 15 mihad
end
18826 57 mihad
endtask // target_completion_expiration
18827 15 mihad
 
18828 57 mihad
task master_completion_expiration ;
18829
    reg   [11:0] ctrl_offset ;
18830
    reg   [11:0] ba_offset ;
18831
    reg   [11:0] am_offset ;
18832
    reg `WRITE_STIM_TYPE write_data ;
18833
    reg `READ_STIM_TYPE  read_data ;
18834
    reg `READ_RETURN_TYPE read_status ;
18835
 
18836
    reg `WRITE_RETURN_TYPE write_status ;
18837
    reg `WB_TRANSFER_FLAGS write_flags ;
18838
    reg        ok   ;
18839
    reg [11:0] pci_ctrl_offset ;
18840
    reg [31:0] image_base ;
18841
    reg [31:0] target_address ;
18842
begin:main
18843
    pci_ctrl_offset = 12'h4 ;
18844
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
18845
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
18846
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
18847
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
18848
 
18849
    target_address  = `BEH_TAR1_MEM_START ;
18850
    image_base      = 0 ;
18851
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
18852
 
18853
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
18854
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
18855
    write_flags                      = 0 ;
18856
    write_flags`INIT_WAITS           = tb_init_waits ;
18857
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
18858
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18859
 
18860
    // enable master & target operation
18861
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
18862
    if ( ok !== 1 )
18863
    begin
18864
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18865
        test_fail("write to PCI Device Control register didn't succeede");
18866
        disable main ;
18867
    end
18868
 
18869
    // prepare image control register
18870
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
18871
    if ( ok !== 1 )
18872
    begin
18873
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
18874
        test_fail("write to WB Image Control register didn't succeede");
18875
        disable main ;
18876
    end
18877
 
18878
    // prepare base address register
18879
    config_write( ba_offset, image_base, 4'hF, ok ) ;
18880
    if ( ok !== 1 )
18881
    begin
18882
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
18883
        test_fail("write to WB Base Address register didn't succeede");
18884
        disable main ;
18885
    end
18886
 
18887
    // write address mask register
18888
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18889
    if ( ok !== 1 )
18890
    begin
18891
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18892
        test_fail("write to WB Address Mask register didn't succeede");
18893
        disable main ;
18894
    end
18895
 
18896
    fork
18897
    begin
18898
        // do not handle retries
18899
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
18900
 
18901
        // initiate a read request
18902
        read_data`READ_ADDRESS  = target_address ;
18903
        read_data`READ_SEL      = 4'hF ;
18904
        read_data`READ_TAG_STIM = 0 ;
18905
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18906
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
18907
        begin
18908
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18909
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
18910
            disable main ;
18911
        end
18912
 
18913
        // handle retries from now on
18914
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
18915
 
18916
        write_data`WRITE_ADDRESS = target_address + 4 ;
18917
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
18918
        write_data`WRITE_SEL     = 4'hF ;
18919
 
18920
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18921
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18922
        begin
18923
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
18924
            test_fail("WB Slave state machine failed to post single memory write");
18925
            disable main ;
18926
        end
18927
 
18928
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 100
18929
        repeat('h1_0000 - 100)
18930
            @(posedge wb_clock) ;
18931
 
18932
        // now perform a read
18933
        read_data`READ_ADDRESS  = target_address + 4 ;
18934
        read_data`READ_SEL      = 4'hF ;
18935
        read_data`READ_TAG_STIM = 0 ;
18936
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18937
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18938
        begin
18939
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18940
            test_fail("PCI bridge didn't process the read as expected");
18941
            disable main ;
18942
        end
18943
 
18944
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
18945
        begin
18946
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
18947
            test_fail("PCI bridge returned unexpected Read Data");
18948
        end
18949
        else if (ok === 1'b1)
18950
            test_ok ;
18951
    end
18952
    begin:monitors
18953
        // monitor first read, which will expire
18954
        pci_transaction_progress_monitor
18955
        (
18956
            target_address, // expected address
18957
            `BC_MEM_READ,   // expected bus command
18958
            1,              // expected number of transfers
18959
            0,              // expected number of cycles
18960
            1,              // check number of transfers true/false
18961
            0,              // check number of cycles true/false
18962
            0,              // is this fast B2B true/false
18963
            ok              // return 1 if as expected, anything else on error
18964
        ) ;
18965
 
18966
        if ( ok !== 1 )
18967
        begin
18968
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18969
            #1 disable monitors ;
18970
        end
18971
 
18972
        // monitor normal single write
18973
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
18974
        if ( ok !== 1 )
18975
        begin
18976
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18977
            #1 disable monitors ;
18978
        end
18979
 
18980
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
18981
        repeat('h1_0000 - 50)
18982
            @(posedge wb_clock) ;
18983
 
18984
        // monitor normal single memory read
18985
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
18986
        if ( ok !== 1 )
18987
        begin
18988
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
18989
        end
18990
    end
18991
    join
18992
 
18993
    // disable the image
18994
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
18995
    if ( ok !== 1 )
18996
    begin
18997
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18998
        test_fail("write to WB Address Mask register didn't succeede");
18999
    end
19000
end
19001
endtask // master_completion_expiration
19002 63 mihad
`endif
19003 57 mihad
 
19004 15 mihad
task config_write ;
19005
    input [11:0] offset ;
19006
    input [31:0] data ;
19007
    input [3:0]  byte_enable ;
19008
    output       ok ;
19009
    `ifdef HOST
19010
    reg   `WRITE_STIM_TYPE   write_data ;
19011
    reg   `WB_TRANSFER_FLAGS write_flags ;
19012
    reg   `WRITE_RETURN_TYPE write_status ;
19013
    `else
19014
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
19015
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
19016
    `endif
19017
    reg in_use ;
19018
    reg [31:0] temp_var ;
19019
begin
19020
    if ( in_use === 1 )
19021
    begin
19022
        $display("config_read task re-entered! Time %t ", $time) ;
19023
        ok = 0 ;
19024
        #20 $stop ;
19025
    end
19026
    else
19027
    begin
19028
        ok = 1 ;
19029
        in_use = 1 ;
19030
    end
19031
    `ifdef HOST
19032
    write_flags                    = 0 ;
19033
    write_flags`INIT_WAITS         = tb_init_waits ;
19034
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19035
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19036
 
19037
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19038
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19039
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
19040
    write_data`WRITE_SEL                         = byte_enable ;
19041
    write_data`WRITE_TAG_STIM                    = 0 ;
19042
    write_data`WRITE_DATA                        = data ;
19043
 
19044
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
19045
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
19046
    begin
19047
        $display("Write to configuration space failed! Time %t ", $time) ;
19048
        ok = 0 ;
19049
    end
19050
 
19051
    @(posedge wb_clock) ;
19052
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
19053
    // here we just wait for two guest cycles for conf space bits to synchronize
19054
    repeat( 2 )
19055
        @(posedge pci_clock) ;
19056
 
19057
    `else // GUEST
19058
    byte_enables_l = ~byte_enable ;
19059
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19060
 
19061
    fork
19062
    begin
19063
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19064
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
19065
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
19066
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19067
              8'h0_0, `Test_One_Zero_Target_WS,
19068
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
19069
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19070
    do_pause( 1 ) ;
19071
    end
19072
    begin
19073
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
19074
        @(posedge pci_clock) ;
19075
    end
19076
    join
19077
 
19078
     repeat( 2 )
19079
         @(posedge wb_clock) ;
19080
 
19081
    `endif
19082
    in_use = 0 ;
19083
end
19084
endtask // config_write
19085
 
19086
task config_read ;
19087
    input [11:0] offset ;
19088
    input [3:0]  byte_enable ;
19089
    output [31:0] data ;
19090
 
19091
    reg `READ_STIM_TYPE    read_data ;
19092
    reg `WB_TRANSFER_FLAGS read_flags ;
19093
    reg `READ_RETURN_TYPE  read_status ;
19094
 
19095
    reg [31:0] pci_address ;
19096
    reg [3:0] byte_enables_l ;
19097
 
19098
    reg master_check_data_prev ;
19099
    reg in_use ;
19100
    reg [31:0] temp_var ;
19101
begin:main
19102
    if ( in_use === 1 )
19103
    begin
19104
        $display("config_read task re-entered! Time %t ", $time) ;
19105
        data = 32'hxxxx_xxxx ;
19106
        disable main ;
19107
    end
19108
 
19109
    in_use = 1 ;
19110
 
19111
`ifdef HOST
19112 26 mihad
    repeat(4)
19113
        @(posedge pci_clock) ;
19114
    repeat(4)
19115
        @(posedge wb_clock) ;
19116 15 mihad
    read_flags                    = 0 ;
19117
    read_flags`INIT_WAITS         = tb_init_waits ;
19118
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19119
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19120
 
19121
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19122
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19123
 
19124
    read_data`READ_ADDRESS  = temp_var + offset ;
19125
    read_data`READ_SEL      = byte_enable ;
19126
    read_data`READ_TAG_STIM = 0 ;
19127
 
19128
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
19129
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19130
    begin
19131
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
19132
        #20 $stop ;
19133
    end
19134
    data = read_status`READ_DATA ;
19135
`else
19136
  `ifdef GUEST
19137 26 mihad
    repeat(4)
19138
        @(posedge wb_clock) ;
19139
    repeat(4)
19140
        @(posedge pci_clock) ;
19141 15 mihad
    master_check_data_prev = master2_check_received_data ;
19142
    master2_check_received_data = 0 ;
19143
 
19144
    byte_enables_l = ~byte_enable ;
19145
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19146
 
19147
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19148
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
19149
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19150
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19151
             8'h4_0, `Test_One_Zero_Target_WS,
19152
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19153
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19154
    do_pause( 1 ) ;
19155
 
19156
    @(master2_received_data_valid) ;
19157
    data = master2_received_data ;
19158
 
19159
    master2_check_received_data = master_check_data_prev ;
19160
  `endif
19161
`endif
19162
    in_use = 0 ;
19163
end
19164
endtask //config_read
19165
 
19166 62 mihad
`ifdef PCI_BIST
19167
`ifdef WB_RAM_DONT_SHARE
19168
    `ifdef PCI_RAM_DONT_SHARE
19169
        parameter bist_chain_length = 8 ;
19170
    `else
19171
        parameter bist_chain_length = 6 ;
19172
    `endif
19173
`else
19174
    `ifdef PCI_RAM_DONT_SHARE
19175 69 mihad
        parameter bist_chain_length = 6 ;
19176 62 mihad
    `else
19177 69 mihad
        parameter bist_chain_length = 4 ;
19178 62 mihad
    `endif
19179
`endif
19180
 
19181
task run_bist_test ;
19182
    reg [(bist_chain_length - 1):0] bist_result_vector ;
19183
    integer count ;
19184
    integer deadlock_count ;
19185
begin
19186
 
19187
    test_name = "BIST FOR RAMS RUN" ;
19188
 
19189 69 mihad
    scanb_en  = 0 ;
19190
    scanb_si  = 0 ;
19191
    scanb_rst = 0 ;
19192
    scanb_clk = 0 ;
19193 62 mihad
 
19194
    fork
19195
    begin
19196
        repeat(2)
19197
            @(posedge wb_clock) ;
19198
    end
19199
    begin
19200
        repeat(2)
19201
            @(posedge pci_clock) ;
19202
    end
19203
    join
19204
 
19205 69 mihad
    // test is run by reseting the test logic
19206
    scanb_rst <= 1'b1 ;
19207
 
19208
    // toggle scan clock for a few times
19209
    repeat (20)
19210
        #50 scanb_clk = !scanb_clk ;
19211
 
19212
    // release bist reset
19213
    scanb_rst <= 1'b0 ;
19214 62 mihad
 
19215
    bist_result_vector = 0 ;
19216
 
19217
    // result vector must be all 1s, because in RTL there cannot be a reason for BIST to fail
19218
    fork
19219
    begin:scan
19220
        while (bist_result_vector !== {bist_chain_length{1'b1}})
19221
        begin
19222 69 mihad
            #1 ;
19223
            @(posedge scanb_clk) ;
19224
            scanb_en <= #1 1'b1 ;
19225 62 mihad
            for (count = 0 ; count < bist_chain_length ; count = count + 1'b1)
19226
            begin
19227 69 mihad
                @(posedge scanb_clk) ;
19228
                bist_result_vector[count] = scanb_so ;
19229 62 mihad
            end
19230
 
19231 69 mihad
            scanb_en <= #1 1'b0 ;
19232 62 mihad
        end
19233
        #1 disable deadlock ;
19234 69 mihad
        @(negedge scanb_clk) ;
19235
        #1 disable scanb_clk_gen ;
19236 62 mihad
        test_ok ;
19237
    end
19238
    begin:deadlock
19239
        for (deadlock_count = 0; deadlock_count <= 100000; deadlock_count = deadlock_count + 1'b1)
19240
        begin
19241
            @(posedge pci_clock) ;
19242
            @(posedge wb_clock) ;
19243
        end
19244
 
19245
        test_fail("BIST Test didn't finish as expected") ;
19246 69 mihad
        scanb_en <= #1 1'b0 ;
19247 62 mihad
        disable scan ;
19248 69 mihad
        @(negedge scanb_clk) ;
19249 62 mihad
        #1 ;
19250 69 mihad
        disable scanb_clk_gen ;
19251 62 mihad
    end
19252 69 mihad
    begin:scanb_clk_gen
19253 62 mihad
        forever
19254 69 mihad
            #50 scanb_clk = !scanb_clk ;
19255 62 mihad
    end
19256
    join
19257
end
19258
endtask // run_bist_test
19259
`endif
19260
 
19261 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
19262
task target_special_corner_case_test ;
19263
    reg   [11:0]    pci_ctrl_offset ;
19264
    reg   [11:0]    ctrl_offset ;
19265
    reg   [11:0]    ba_offset ;
19266
    reg   [11:0]    am_offset ;
19267
    reg             ok_wb ;
19268
    reg             ok_pci ;
19269
    reg             test_mem ;
19270
    reg             master_check_data_previous ;
19271
begin:main
19272
    master_check_data_previous  = master1_check_received_data ;
19273
    master1_check_received_data = 1'b1 ;
19274
    pci_ctrl_offset = 12'h4 ;
19275
    // use image 1 for this test
19276
    ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
19277
    ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
19278
    am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
19279
 
19280
    // set behavioral slave cycle response
19281
    `ifdef REGISTER_WBM_OUTPUTS
19282
    wishbone_slave.cycle_response
19283
    (
19284
        3'b100,         // {ACK, ERR, RTY}
19285
        0,              // wait cycles
19286
        8'h0            // num of retries before termination
19287
    );
19288
    `else
19289
    wishbone_slave.cycle_response
19290
    (
19291
        3'b100,         // {ACK, ERR, RTY}
19292
        1,              // wait cycles
19293
        8'h0            // num of retries before termination
19294
    );
19295
    `endif
19296
 
19297
    `ifdef HOST
19298
        test_mem = 1 ;
19299
    `else
19300
        test_mem = `PCI_BA1_MEM_IO ;
19301
        test_mem = !test_mem ;
19302
    `endif
19303
 
19304
    test_name = "PCI TARGET UNIT SPECIAL CORNER CASE" ;
19305
 
19306
    // Set Base Address of IMAGE
19307
    config_write( ba_offset, Target_Base_Addr_R[1], 4'hF, ok_wb ) ;
19308
    if ( ok_wb !== 1 )
19309
    begin
19310 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19311 63 mihad
        test_fail("PCI Base Address register 1 could not be written") ;
19312
        #1 ;
19313
        disable main ;
19314
    end
19315
 
19316
    // Set Address Mask of IMAGE
19317
    config_write( am_offset, Target_Addr_Mask_R[1], 4'hF, ok_wb ) ;
19318
    if ( ok_wb !== 1 )
19319
    begin
19320 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_AM1 register! Time %t ", $time);
19321 63 mihad
        test_fail("PCI Address Mask register 1 could not be written") ;
19322
        #1 ;
19323
        disable main ;
19324
    end
19325
 
19326
    // Disable all the features of the PCI Image 1
19327
    config_write( ctrl_offset, 0, 4'hF, ok_wb ) ;
19328
    if ( ok_wb !== 1 )
19329
    begin
19330 69 mihad
        $display("Special Testcase didn't pass! Failed to write P_CTRL1 register! Time %t ", $time);
19331 63 mihad
        test_fail("PCI Image Control register 1 could not be written") ;
19332
        #1 ;
19333
        disable main ;
19334
    end
19335
 
19336
    // set waits to max, which means 0 on PCI
19337
    tb_init_waits   = 4 ;
19338
    tb_subseq_waits = 4 ;
19339
 
19340
    // do one dummy write, to receive a GNT park
19341
    if (test_mem)
19342
    begin
19343
        PCIU_MEM_WRITE
19344
        (
19345
            "MEM_WRITE ",                       // just the name
19346
            `Test_Master_1,                     // Behavioral Master to use for reference
19347
            Target_Base_Addr_R[1],              // Address of this transaction
19348
            32'hAAAA_AAAA,                      // Data For the transaction
19349
            4'h0,                               // Byte enables
19350
            1,                                  // length of transfer
19351
            `Test_One_Zero_Master_WS,           // Master Waits - don't care
19352
            `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19353
            `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19354
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19355
        );
19356
    end
19357
    else
19358
    begin
19359
        PCIU_IO_WRITE
19360
        (
19361
            `Test_Master_1,                     // Behavioral Master to use for reference
19362
            Target_Base_Addr_R[1],              // Address of this transaction
19363
            32'hAAAA_AAAA,                      // Data For the transaction
19364
            4'h0,                               // Byte enables
19365
            1,                                  // Size of transfer
19366
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19367
        ) ;
19368
    end
19369
 
19370
    do_pause( 1 ) ;
19371
    wb_transaction_progress_monitor
19372
    (
19373
        Target_Base_Addr_R[1],          // expected address
19374
        1'b1,                           // expected operation R/W
19375
        1,                              // 1
19376
        1'b1,                           // turn checking of transfers ON/OFF
19377
        ok_wb                           // succeeded/failed
19378
    ) ;
19379
 
19380
    if (ok_wb !== 1'b1)
19381
    begin
19382
        test_fail("WB Transaction Monitor detected invalid transaction on WB bus after posted memory write through target") ;
19383
        #1 ;
19384
        disable main ;
19385
    end
19386
 
19387
    fork
19388
    begin
19389
        if (test_mem)
19390
        begin
19391
            PCIU_MEM_WRITE
19392
            (
19393
                "MEM_WRITE ",                       // just the name
19394
                `Test_Master_1,                     // Behavioral Master to use for reference
19395
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19396
                32'hF0F0_F0F0,                      // Data For the transaction
19397
                4'h0,                               // Byte enables       
19398
                1,                                  // length of transfer
19399
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19400
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19401
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19402
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19403
            );
19404
        end
19405
        else
19406
        begin
19407
            PCIU_IO_WRITE
19408
            (
19409
                `Test_Master_1,                     // Behavioral Master to use for reference
19410
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19411
                32'hF0F0_F0F0,                      // Data For the transaction
19412
                4'h0,                               // Byte enables
19413
                1,                                  // Size of transfer
19414
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19415
            ) ;
19416
        end
19417
 
19418
        do_pause( 1 ) ;
19419
 
19420
        if (test_mem)
19421
        begin
19422
            PCIU_MEM_WRITE
19423
            (
19424
                "MEM_WRITE ",                       // just the name
19425
                `Test_Master_1,                     // Behavioral Master to use for reference
19426
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19427
                32'h0F0F_0F0F,                      // Data For the transaction
19428
                4'h0,                               // Byte enables
19429
                1,                                  // length of transfer
19430
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19431
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19432
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19433
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19434
            );
19435
        end
19436
        else
19437
        begin
19438
            PCIU_IO_WRITE
19439
            (
19440
                `Test_Master_1,                     // Behavioral Master to use for reference
19441
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19442
                32'h0F0F_0F0F,                      // Data For the transaction
19443
                4'h0,                               // Byte enables
19444
                1,                                  // Size of transfer
19445
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19446
            ) ;
19447
        end
19448
 
19449
        do_pause( 1 ) ;
19450
    end
19451
    begin
19452
        wb_transaction_progress_monitor
19453
        (
19454
            Target_Base_Addr_R[1] + 64,     // expected address
19455
            1'b1,                           // expected operation R/W
19456
            1,                              // expected number of transfers
19457
            1'b1,                           // turn checking of transfers ON/OFF
19458
            ok_wb                           // succeeded/failed
19459
        ) ;
19460
 
19461
        if ( ok_wb === 1 )
19462
        begin
19463
 
19464
            wb_transaction_progress_monitor
19465
            (
19466
                Target_Base_Addr_R[1] + 128,    // 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
        end
19473
 
19474
        @(posedge pci_clock) ;
19475
        #1 ;
19476
        disable pci_error_mon1 ;
19477
    end
19478
    begin:pci_error_mon1
19479
        ok_pci = 1 ;
19480
        @(error_event_int) ;
19481
        ok_pci = 0 ;
19482
    end
19483
    join
19484
 
19485
    if ( ok_wb !== 1'b1 )
19486
    begin
19487
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19488
    end
19489
 
19490
    if ( ok_pci !== 1'b1)
19491
    begin
19492
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19493
    end
19494
 
19495
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19496
    begin
19497
        #1 ;
19498
        disable main ;
19499
    end
19500
 
19501
    if ( test_mem )
19502
    begin
19503
        PCIU_MEM_READ
19504
        (
19505
            "MEM_READ  ",                   // description
19506
            `Test_Master_1,                 // behavioral master selection
19507
            Target_Base_Addr_R[1] + 64,     // address of access
19508
            32'hF0F0_F0F0,                  // expected read data
19509
            1,                              // number of transfers
19510
            8'h7_0,                         // don't care (wait cycles)
19511
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19512
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19513
            `Test_Target_Retry_On           // expected Target termination
19514
        );
19515
    end
19516
    else
19517
    begin
19518
        PCIU_IO_READ
19519
        (
19520
            `Test_Master_1,                 // behavioral master selection
19521
            Target_Base_Addr_R[1] + 64,     // address of access
19522
            32'hF0F0_F0F0,                  // expected read data
19523
            4'h0,                           // byte enables
19524
            1,                              // number of transfers
19525
            `Test_Target_Retry_On           // expected target termination
19526
        ) ;
19527
    end
19528
 
19529 64 mihad
    do_pause(1) ;
19530
 
19531 63 mihad
    wb_transaction_progress_monitor
19532
    (
19533
            Target_Base_Addr_R[1] + 64,     // expected address
19534
            1'b0,                           // expected operation R/W
19535
            1,                              // expected number transfers
19536
            1'b1,                           // turn checking of transfers ON/OFF
19537
            ok_wb                           // succeeded/failed
19538
    ) ;
19539
 
19540
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19541
    repeat(3)
19542
        @(posedge pci_clock) ;
19543
 
19544
    // now read data
19545
    fork
19546
    begin
19547
        if ( test_mem )
19548
        begin
19549
            PCIU_MEM_READ
19550
            (
19551
                "MEM_READ  ",                   // description
19552
                `Test_Master_1,                 // behavioral master selection
19553
                Target_Base_Addr_R[1] + 64,     // address of access
19554
                32'hF0F0_F0F0,                  // expected read data
19555
                1,                              // number of transfers
19556
                8'h7_0,                         // don't care (wait cycles)
19557
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19558
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19559
                `Test_Target_Normal_Completion  // expected Target termination
19560
            );
19561
        end
19562
        else
19563
        begin
19564
            PCIU_IO_READ
19565
            (
19566
                `Test_Master_1,                 // behavioral master selection
19567
                Target_Base_Addr_R[1] + 64,     // address of access
19568
                32'hF0F0_F0F0,                  // expected read data
19569
                4'h0,                           // byte enables
19570
                1,                              // number of transfers
19571
                `Test_Target_Normal_Completion  // expected target termination
19572
            ) ;
19573
        end
19574
 
19575 64 mihad
        do_pause(1) ;
19576 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19577
            @(posedge pci_clock) ;
19578
 
19579
        @(posedge pci_clock) ;
19580
        #1 ;
19581
        disable pci_error_mon2 ;
19582
    end
19583
    begin:pci_error_mon2
19584
        ok_pci = 1 ;
19585
        @(error_event_int) ;
19586
        ok_pci = 0 ;
19587
    end
19588
    join
19589
 
19590
    if ( ok_wb !== 1'b1 )
19591
    begin
19592
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19593
    end
19594
 
19595
    if ( ok_pci !== 1'b1)
19596
    begin
19597
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19598
    end
19599
 
19600
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19601
    begin
19602
        #1 ;
19603
        disable main ;
19604
    end
19605
 
19606
    if ( test_mem )
19607
    begin
19608
        PCIU_MEM_READ
19609
        (
19610
            "MEM_READ  ",                   // description
19611
            `Test_Master_1,                 // behavioral master selection
19612
            Target_Base_Addr_R[1] + 128,    // address of access
19613
            32'h0F0F_0F0F,                  // expected read data
19614
            1,                              // number of transfers
19615
            8'h7_0,                         // don't care (wait cycles)
19616
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19617
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19618
            `Test_Target_Retry_On           // expected Target termination
19619
        );
19620
    end
19621
    else
19622
    begin
19623
        PCIU_IO_READ
19624
        (
19625
            `Test_Master_1,                 // behavioral master selection
19626
            Target_Base_Addr_R[1] + 128,    // address of access
19627
            32'h0F0F_0F0F,                  // expected read data
19628
            4'h0,                           // byte enables
19629
            1,                              // number of transfers
19630
            `Test_Target_Retry_On           // expected target termination
19631
        ) ;
19632
    end
19633
 
19634 64 mihad
    do_pause(1) ;
19635 63 mihad
    wb_transaction_progress_monitor
19636
    (
19637
            Target_Base_Addr_R[1] + 128,    // expected address
19638
            1'b0,                           // expected operation R/W
19639
            1,                              // expected number transfers
19640
            1'b1,                           // turn checking of transfers ON/OFF
19641
            ok_wb                           // succeeded/failed
19642
    ) ;
19643
 
19644
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19645
    repeat(3)
19646
        @(posedge pci_clock) ;
19647
 
19648
    // now read data
19649
    fork
19650
    begin
19651
        if ( test_mem )
19652
        begin
19653
            PCIU_MEM_READ
19654
            (
19655
                "MEM_READ  ",                   // description
19656
                `Test_Master_1,                 // behavioral master selection
19657
                Target_Base_Addr_R[1] + 128,    // address of access
19658
                32'h0F0F_0F0F,                  // expected read data
19659
                1,                              // number of transfers
19660
                8'h7_0,                         // don't care (wait cycles)
19661
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19662
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19663
                `Test_Target_Normal_Completion  // expected Target termination
19664
            );
19665
        end
19666
        else
19667
        begin
19668
            PCIU_IO_READ
19669
            (
19670
                `Test_Master_1,                 // behavioral master selection
19671
                Target_Base_Addr_R[1] + 128,    // address of access
19672
                32'h0F0F_0F0F,                  // expected read data
19673
                4'h0,                           // byte enables
19674
                1,                              // number of transfers
19675
                `Test_Target_Normal_Completion  // expected target termination
19676
            ) ;
19677
        end
19678
 
19679 64 mihad
        do_pause(1) ;
19680 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19681
            @(posedge pci_clock) ;
19682
 
19683
        @(posedge pci_clock) ;
19684
        #1 ;
19685
        disable pci_error_mon3 ;
19686
    end
19687
    begin:pci_error_mon3
19688
        ok_pci = 1 ;
19689
        @(error_event_int) ;
19690
        ok_pci = 0 ;
19691
    end
19692
    join
19693
 
19694
    if ((ok_wb === 1'b1) && (ok_pci === 1'b1))
19695
        test_ok ;
19696
 
19697
    if ( ok_wb !== 1'b1 )
19698
    begin
19699
        test_fail("WB Master started invalid transaction or none at all after Target read was requested") ;
19700
    end
19701
 
19702
    if ( ok_pci !== 1'b1)
19703
    begin
19704
        test_fail("PCI Behavioral Master or Monitor signaled an error during read from PCI Bridge Target") ;
19705
    end
19706
 
19707 69 mihad
    // Disable used image
19708
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
19709
    if ( ok_wb !== 1 )
19710
    begin
19711
        $display("Special Testcase didn't pass! Failed to write P_BA1 register! Time %t ", $time);
19712
        test_fail("PCI Base Address register 1 could not be written") ;
19713
        #1 ;
19714
        disable main ;
19715
    end
19716
 
19717 63 mihad
    master1_check_received_data = master_check_data_previous ;
19718
end
19719
endtask // target_special_corner_case_test
19720
`endif
19721
 
19722 69 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
19723
task master_special_corner_case_test ;
19724
    reg   [11:0] ctrl_offset ;
19725
    reg   [11:0] ba_offset ;
19726
    reg   [11:0] am_offset ;
19727
    reg `WRITE_STIM_TYPE write_data ;
19728
    reg `READ_STIM_TYPE  read_data ;
19729
    reg `READ_RETURN_TYPE read_status ;
19730
 
19731
    reg `WRITE_RETURN_TYPE write_status ;
19732
    reg `WB_TRANSFER_FLAGS flags ;
19733
    reg ok_pci   ;
19734
    reg ok_wb ;
19735
 
19736
    reg [31:0] target_address ;
19737
 
19738
    reg [11:0] pci_ctrl_offset ;
19739
 
19740
    reg [31:0] image_base ;
19741
begin:main
19742
    test_name = "WISHBONE SLAVE UNIT SPECIAL CORNER CASE" ;
19743
    pci_ctrl_offset = 12'h4 ;
19744
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
19745
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
19746
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
19747
 
19748
    target_address  = `BEH_TAR1_MEM_START ;
19749
    image_base      = 0 ;
19750
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
19751
 
19752
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
19753
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
19754
 
19755
    flags                      = 0 ;
19756
    flags`INIT_WAITS           = 0 ;
19757
    flags`SUBSEQ_WAITS         = 0 ;
19758
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
19759
 
19760
    test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = `Test_Devsel_Fast ;
19761
    test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
19762
    test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
19763
 
19764
    // enable master & target operation
19765
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok_wb) ;
19766
    if ( ok_wb !== 1 )
19767
    begin
19768
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write PCI Device Control register! Time %t ", $time) ;
19769
        test_fail("write to PCI Device Control register didn't succeede");
19770
        disable main ;
19771
    end
19772
 
19773
    // prepare image control register
19774
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok_wb) ;
19775
    if ( ok_wb !== 1 )
19776
    begin
19777
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
19778
        test_fail("write to WB Image Control register didn't succeede");
19779
        disable main ;
19780
    end
19781
 
19782
    // prepare base address register
19783
    config_write( ba_offset, image_base, 4'hF, ok_wb ) ;
19784
    if ( ok_wb !== 1 )
19785
    begin
19786
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
19787
        test_fail("write to WB Base Address register didn't succeede");
19788
        disable main ;
19789
    end
19790
 
19791
    // write address mask register
19792
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok_wb ) ;
19793
    if ( ok_wb !== 1 )
19794
    begin
19795
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_AM1 register! Time %t ", $time) ;
19796
        test_fail("write to WB Address Mask register didn't succeede");
19797
        disable main ;
19798
    end
19799
 
19800
    fork
19801
    begin
19802
 
19803
        // do one dummy read, to receive bus gnt
19804
        read_data`READ_ADDRESS  = target_address ;
19805
        read_data`READ_SEL      = 4'hF ;
19806
        read_data`READ_TAG_STIM = 0 ;
19807
 
19808
        // handle retries
19809
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19810
 
19811
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19812
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19813
        begin
19814
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19815
            test_fail("PCI bridge didn't process the delayed read as expected");
19816
            disable main ;
19817
        end
19818
 
19819
        write_data`WRITE_ADDRESS = target_address + 64;
19820
        write_data`WRITE_DATA    = 32'hABCD_EF12 ;
19821
        write_data`WRITE_SEL     = 4'hF ;
19822
 
19823
        wishbone_master.blk_write_data[0] = write_data ;
19824
 
19825
        write_data`WRITE_ADDRESS = target_address + 128 ;
19826
        write_data`WRITE_DATA    = ~write_data`WRITE_DATA ;
19827
        write_data`WRITE_SEL     = 4'hF ;
19828
 
19829
        wishbone_master.blk_write_data[1] = write_data ;
19830
 
19831
        // no retries should happen
19832
        flags`WB_TRANSFER_AUTO_RTY = 0 ;
19833
 
19834
        flags`WB_TRANSFER_SIZE = 2 ;
19835
 
19836
        wishbone_master.wb_block_write( flags, write_status ) ;
19837
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
19838
        begin
19839
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process block memory write! Time %t ", $time) ;
19840
            test_fail("WB Slave state machine failed to post block memory write");
19841
            disable main ;
19842
        end
19843
 
19844
        // read data back
19845
        read_data`READ_ADDRESS  = target_address + 64 ;
19846
        read_data`READ_SEL      = 4'hF ;
19847
        read_data`READ_TAG_STIM = 0 ;
19848
 
19849
        // handle retries
19850
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19851
 
19852
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19853
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19854
        begin
19855
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19856
            test_fail("PCI bridge didn't process the delayed read as expected");
19857
            disable main ;
19858
        end
19859
 
19860
        if (read_status`READ_DATA !== 32'hABCD_EF12)
19861
        begin
19862
            display_warning(target_address + 64, 32'hABCD_EF12, read_status`READ_DATA) ;
19863
            test_fail("PCI bridge returned unexpected Read Data");
19864
            ok_wb = 0 ;
19865
        end
19866
 
19867
        // read second data back
19868
        read_data`READ_ADDRESS  = target_address + 128 ;
19869
        read_data`READ_SEL      = 4'hF ;
19870
        read_data`READ_TAG_STIM = 0 ;
19871
 
19872
        // handle retries
19873
        flags`WB_TRANSFER_AUTO_RTY = 1 ;
19874
 
19875
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
19876
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19877
        begin
19878
            $display("WISHBONE Slave Unit special corner case test didn't pass! Bridge failed to process single memory read! Time %t ", $time) ;
19879
            test_fail("PCI bridge didn't process the delayed read as expected");
19880
            disable main ;
19881
        end
19882
 
19883
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
19884
        begin
19885
            display_warning(target_address + 128, write_data`WRITE_DATA, read_status`READ_DATA) ;
19886
            test_fail("PCI bridge returned unexpected Read Data");
19887
            ok_wb = 0 ;
19888
        end
19889
    end
19890
    begin
19891
 
19892
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19893
        if ( ok_pci !== 1 )
19894
        begin
19895
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19896
        end
19897
 
19898
        if(ok_pci)
19899
        begin
19900
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
19901
            if ( ok_pci !== 1 )
19902
            begin
19903
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19904
            end
19905
        end
19906
 
19907
        if (ok_pci)
19908
        begin
19909
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok_pci ) ;
19910
            if ( ok_pci !== 1 )
19911
            begin
19912
                test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
19913
            end
19914
        end
19915
 
19916
        if (ok_pci)
19917
        begin
19918
            pci_transaction_progress_monitor( target_address + 64, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19919
            if ( ok_pci !== 1 )
19920
            begin
19921
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19922
            end
19923
        end
19924
 
19925
        if (ok_pci)
19926
        begin
19927
            pci_transaction_progress_monitor( target_address + 128, `BC_MEM_READ, 1, 0, 1, 0, 0, ok_pci ) ;
19928
            if ( ok_pci !== 1 )
19929
            begin
19930
                test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
19931
            end
19932
        end
19933
    end
19934
    join
19935
 
19936
    if (ok_wb && ok_pci)
19937
        test_ok ;
19938
 
19939
    // disable the image
19940
    config_write( ba_offset, 32'h0000_0000, 4'hF, ok_wb ) ;
19941
    if ( ok_wb !== 1 )
19942
    begin
19943
        $display("WISHBONE Slave Unit special corner case test didn't pass! Failed to write W_BA1 register! Time %t ", $time) ;
19944
        test_fail("write to WB Base Address register didn't succeede");
19945
        disable main ;
19946
    end
19947
end
19948
endtask // master_special_corner_case_test
19949
`endif
19950
 
19951 73 mihad
task test_target_overload ;
19952
    reg ok_pci ;
19953
    reg ok_wb  ;
19954
    reg ok ;
19955
    reg [2:0] test_image_num ;
19956
    reg addr_translated ;
19957
    integer transfered ;
19958
    reg [2:0] received_termination ;
19959
    integer total_transfers ;
19960
    reg [31:0] transaction_sizes [0:1024] ;
19961
    integer pci_transaction_num ;
19962
    integer wb_transaction_num ;
19963
    reg [31:0] current_wb_address ;
19964
    reg io_mapped ;
19965
    integer init_waits_backup ;
19966
    integer current_size ;
19967
begin:main
19968
    init_waits_backup = tb_init_waits ;
19969
    tb_init_waits = 0 ;
19970
 
19971
    `ifdef HOST
19972
    io_mapped = 1'b0 ;
19973
    `endif
19974
 
19975
    test_image_num = 'd1 ;
19976
    `ifdef GUEST
19977
    io_mapped = `PCI_BA1_MEM_IO ;
19978
    `endif
19979
 
19980
    `ifdef PCI_IMAGE2
19981
        test_image_num = 'd2 ;
19982
        `ifdef GUEST
19983
            io_mapped = `PCI_BA2_MEM_IO ;
19984
        `endif
19985
    `endif
19986
 
19987
    `ifdef PCI_IMAGE3
19988
        test_image_num = 'd3 ;
19989
        `ifdef GUEST
19990
            io_mapped = `PCI_BA3_MEM_IO ;
19991
        `endif
19992
    `endif
19993
 
19994
    `ifdef PCI_IMAGE4
19995
        test_image_num = 'd4 ;
19996
        `ifdef GUEST
19997
            io_mapped = `PCI_BA4_MEM_IO ;
19998
        `endif
19999
    `endif
20000
 
20001
    `ifdef PCI_IMAGE5
20002
        test_image_num = 'd5 ;
20003
        `ifdef GUEST
20004
            io_mapped = `PCI_BA5_MEM_IO ;
20005
        `endif
20006
    `endif
20007
 
20008
    test_name = "PCI TARGET OVERLOAD" ;
20009
    // configure target image 1 via bus accesses
20010
    pci_configure_pci_target_image
20011
    (
20012
        1'b1,                               // selects whether to configure image with bus accesses or directly with dot notation in the configuration space
20013
        test_image_num,                     // image number
20014
        Target_Base_Addr_R[test_image_num], // base address
20015
        Target_Addr_Mask_R[test_image_num], // address mask
20016
        Target_Tran_Addr_R[test_image_num], // translation address
20017
        1'b0,                               // io/mem mapping select
20018
        1'b0,                               // prefetch enable
20019
        1'b1,                               // address translation enable
20020
        ok                                  // finished succesfully
20021
    );
20022
    if (ok !== 1'b1)
20023
    begin
20024
        test_fail("configuration of PCI Target Image didn't succeede") ;
20025
        tb_init_waits = init_waits_backup ;
20026
        #1 disable main ;
20027
    end
20028
 
20029
    `ifdef ADDR_TRAN_IMPL
20030
        addr_translated = 1'b1 ;
20031
    `else
20032
        addr_translated = 1'b0 ;
20033
    `endif
20034
 
20035
    // set wb slave's response to max wait cycles
20036
    wishbone_slave.cycle_response
20037
    (
20038
        3'b100,          // ACK, ERR, RTY termination
20039
        tb_subseq_waits, // wait cycles before response
20040
 
20041
    ) ;
20042
 
20043
    ok_pci = 1 ;
20044
    ok_wb  = 1 ;
20045
    current_wb_address = pci_to_wb_addr_convert
20046
                               (
20047
                                    Target_Base_Addr_R[test_image_num], // pci address
20048
                                    Target_Tran_Addr_R[test_image_num], // translation address
20049
                                    addr_translated
20050
                               );
20051
    current_wb_address = current_wb_address & Target_Addr_Mask_R[test_image_num] ;
20052
 
20053
    for (current_size = 2 ; (current_size <= 1024) && ok_pci && ok_wb && ok ; current_size = current_size * 2)
20054
    begin
20055
 
20056
        total_transfers = 0 ;
20057
        pci_transaction_num = 0 ;
20058
        wb_transaction_num = 0 ;
20059
 
20060
        current_wb_address = current_wb_address & Target_Addr_Mask_R[test_image_num] ;
20061
        current_wb_address = current_wb_address + (('d1024 - current_size) * 4) ;
20062
        fork
20063
        begin
20064
            while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20065
            begin
20066
                // try transfering 4kB with no wait cycles through the target
20067
                ipci_unsupported_commands_master.normal_write_transfer
20068
                (
20069
                    // always write to the end of the 4kB window
20070
                    (('d1024 - current_size) * 4) + Target_Base_Addr_R[test_image_num] + (4 * total_transfers), // start_address
20071
                    io_mapped ? `BC_IO_WRITE : `BC_MEM_WRITE,                                                   // bus_command
20072
                    (current_size - total_transfers),                                                           // size
20073
                    4 - tb_subseq_waits[2:0],                                                                   // subsequent wait cycles
20074
                    transfered,                                                                                 // actual_transfer
20075
                    received_termination                                                                        // received_termination
20076
                );
20077
                if (transfered > 0)
20078
                begin
20079
                    transaction_sizes[pci_transaction_num] = transfered ;
20080
                    pci_transaction_num = pci_transaction_num + 1'b1 ;
20081
                end
20082
                total_transfers = total_transfers + transfered ;
20083
                if (received_termination > 2) // terminations with numbers 3(Target Abort), 4(Master Abort) and 5(Error) are not allowed
20084
                begin
20085
                    ok_pci = 0 ;
20086
                    if (received_termination == 3)
20087
                        test_fail("PCI Target signalled Target Abort") ;
20088
 
20089
                    if (received_termination == 4)
20090
                        test_fail("PCI Master generated Master Abort") ;
20091
 
20092
                    if (received_termination == 5)
20093
                        test_fail("PCI behavioral master signaled severe error") ;
20094
                end
20095
            end
20096
        end
20097
        begin:wb_monitoring
20098
            while (((total_transfers < current_size) || (pci_transaction_num > wb_transaction_num)) && ok_pci && ok_wb && ok)
20099
            begin
20100
                wait(pci_transaction_num > wb_transaction_num) ;
20101
                wb_transaction_progress_monitor
20102
                (
20103
                    current_wb_address,                     //address
20104
                    1'b1,                                   //write/read
20105
                    transaction_sizes[wb_transaction_num],  //num_of_transfers
20106
                    1'b1,                                   //check_transfers
20107
                    ok_wb                                   // success/fail
20108
                );
20109
                current_wb_address = current_wb_address + (transaction_sizes[wb_transaction_num] * 4) ;
20110
                wb_transaction_num = wb_transaction_num + 1'b1 ;
20111
                if (ok_wb !== 1'b1)
20112
                begin
20113
                    test_fail("WB Transaction progress monitor detected invalid transaction or none at all on WB bus");
20114
                end
20115
            end
20116
 
20117
            wb_transaction_num = wb_transaction_num - 1'b1 ;
20118
            current_wb_address = current_wb_address - (transaction_sizes[wb_transaction_num] * 4) ;
20119
 
20120
            if (ok)
20121
                #1 disable pci_monitoring ;
20122
        end
20123
        begin:pci_monitoring
20124
            @(error_event_int) ;
20125
            test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20126
            ok = 0 ;
20127
            ok_pci = 0 ;
20128
            ok_wb  = 0 ;
20129
        end
20130
        join
20131
    end
20132
 
20133
    if ((ok && ok_wb && ok_pci) === 1'b1)
20134
        test_ok ;
20135
 
20136
    tb_init_waits = init_waits_backup ;
20137
end
20138
endtask // test_target_overload
20139
 
20140
task test_master_overload ;
20141
    reg ok_pci ;
20142
    reg ok_wb  ;
20143
    reg ok ;
20144
    reg [2:0] test_image_num ;
20145
    integer transfered ;
20146
    reg [2:0] received_termination ;
20147
    integer total_transfers ;
20148
    reg [31:0] transaction_sizes [0:1024] ;
20149
    integer pci_transaction_num ;
20150
    integer wb_transaction_num ;
20151
    reg [31:0] current_pci_address ;
20152
    integer init_waits_backup ;
20153
    integer current_size ;
20154
 
20155
    reg `WRITE_STIM_TYPE write_data ;
20156
 
20157
    reg `WRITE_RETURN_TYPE write_status ;
20158
    reg `WB_TRANSFER_FLAGS write_flags ;
20159
 
20160
    reg [31:0] image_base ;
20161
    reg [31:0] target_address ;
20162
 
20163
    integer i ;
20164
begin:main
20165
 
20166
    // set behavioral target to respond normally
20167
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
20168
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
20169
 
20170
    test_image_num = 'd1 ;
20171
 
20172
    `ifdef WB_IMAGE2
20173
        test_image_num = 'd2 ;
20174
    `endif
20175
 
20176
    `ifdef WB_IMAGE3
20177
        test_image_num = 'd3 ;
20178
    `endif
20179
 
20180
    `ifdef WB_IMAGE4
20181
        test_image_num = 'd4 ;
20182
    `endif
20183
 
20184
    `ifdef WB_IMAGE5
20185
        test_image_num = 'd5 ;
20186
    `endif
20187
 
20188
    test_name = "MASTER OVERLOAD" ;
20189
 
20190
    target_address  = `BEH_TAR1_MEM_START ;
20191
    image_base      = 0 ;
20192
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
20193
 
20194
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
20195
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
20196
 
20197
    write_flags                      = 0 ;
20198
    write_flags`INIT_WAITS           = tb_init_waits ;
20199
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
20200
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
20201
    write_flags`WB_TRANSFER_CAB      = 1'b1 ;
20202
 
20203
    pci_configure_wb_slave_image
20204
    (
20205
        1'b1,           // use_bus
20206
        test_image_num, // image_num
20207
        image_base,     // base address
20208
        32'hFFFF_FFFF,  //  address mask
20209
        32'h0000_0000,  // translation address
20210
        1'b0,           // io/mem mapping select
20211
        1'b1,           // prefetch enable
20212
        1'b0,           // address translation enable
20213
        1'b1,           // memory read line enable
20214
        ok              // finished succesfully
20215
    ) ;
20216
 
20217
    if (ok !== 1'b1)
20218
    begin
20219
        test_fail("WB image configuration failed") ;
20220
        disable main ;
20221
    end
20222
 
20223
    // fill wishbone master's memory with data - inverted addresses
20224
    write_data = 0 ;
20225
    for (i = 0 ; i < 1024 ; i = i + 1)
20226
    begin
20227
        write_data`WRITE_ADDRESS = image_base + (4 * i) ;
20228
        write_data`WRITE_DATA    = ~(write_data`WRITE_ADDRESS);
20229
        wishbone_master.blk_write_data[i] = write_data ;
20230
    end
20231
 
20232
    ok_wb  = 1 ;
20233
    ok_pci = 1 ;
20234
 
20235
    total_transfers = 0 ;
20236
 
20237
    for (current_size = 2 ; (current_size <= 1024) && ok_pci && ok_wb && ok ; current_size = current_size * 2)
20238
    begin
20239
 
20240
        total_transfers = 0 ;
20241
        pci_transaction_num = 0 ;
20242
        wb_transaction_num = 0 ;
20243
 
20244
        current_pci_address = image_base ;
20245
        fork
20246
        begin
20247
            while ((total_transfers < current_size) && ok_pci && ok_wb && ok)
20248
            begin
20249
                // try transfering 4kB with no wait cycles through the wb slave unit
20250
                write_flags`WB_TRANSFER_SIZE = current_size - total_transfers ;
20251
                wishbone_master.wb_block_write(write_flags, write_status) ;
20252
                if (write_status`CYC_ERR || ((write_status`CYC_ERR !== 1'b1) && (write_status`CYC_RTY !== 1'b1) && (write_status`CYC_ACK !== 1'b1)))
20253
                begin
20254
                    test_fail("Wishbone slave signaled an error or did not respond to normal write access") ;
20255
                    ok_wb = 0 ;
20256
                end
20257
 
20258
                transfered = write_status`CYC_ACTUAL_TRANSFER ;
20259
                if (transfered > 0)
20260
                begin
20261
                    transaction_sizes[wb_transaction_num] = transfered ;
20262
                    wb_transaction_num = wb_transaction_num + 1'b1 ;
20263
                end
20264
                total_transfers = total_transfers + transfered ;
20265
            end
20266
        end
20267
        begin:pci_models_monitoring
20268
            while (((total_transfers < current_size) || (wb_transaction_num > pci_transaction_num)) && ok_pci && ok_wb && ok)
20269
            begin
20270
                wait(wb_transaction_num > pci_transaction_num) ;
20271
                pci_transaction_progress_monitor
20272
                (
20273
                    current_pci_address,                        // address
20274
                    `BC_MEM_WRITE,                              // bus_command
20275
                    transaction_sizes[pci_transaction_num],     // num_of_transfers
20276
                    0,                                          // num_of_cycles
20277
                    1'b1,                                       // check_transfers
20278
                    1'b0,                                       // check_cycles
20279
                    1'b0,                                       // doing_fast_back_to_back
20280
                    ok_pci                                      // ok
20281
                ) ;
20282
 
20283
                pci_transaction_num = pci_transaction_num + 1'b1 ;
20284
                if (ok_pci !== 1'b1)
20285
                begin
20286
                    test_fail("PCI Transaction progress monitor detected invalid transaction or none at all on PCI bus");
20287
                end
20288
            end
20289
 
20290
            if (ok)
20291
                #1 disable pci_monitoring ;
20292
        end
20293
        begin:pci_monitoring
20294
            @(error_event_int) ;
20295
            test_fail("PCI Bus monitor detected invalid operation on PCI bus") ;
20296
            ok = 0 ;
20297
            ok_pci = 0 ;
20298
            ok_wb  = 0 ;
20299
        end
20300
        join
20301
    end
20302
 
20303
    // disable the image
20304
    pci_configure_wb_slave_image
20305
    (
20306
        1'b1,           // use_bus
20307
        test_image_num, // image_num
20308
        image_base,     // base address
20309
        32'h0000_0000,  //  address mask
20310
        32'h0000_0000,  // translation address
20311
        1'b0,           // io/mem mapping select
20312
        1'b1,           // prefetch enable
20313
        1'b0,           // address translation enable
20314
        1'b1,           // memory read line enable
20315
        ok              // finished succesfully
20316
    ) ;
20317
 
20318
    if (ok !== 1'b1)
20319
    begin
20320
        test_fail("WB image configuration failed") ;
20321
        disable main ;
20322
    end
20323
 
20324
    if ((ok && ok_wb && ok_pci) === 1'b1)
20325
        test_ok ;
20326
end
20327
endtask // test_master_overload
20328
 
20329 15 mihad
task test_fail ;
20330
    input [7999:0] failure_reason ;
20331
    reg   [8007:0] display_failure ;
20332
    reg   [799:0] display_test ;
20333
begin
20334
    tests_failed = tests_failed + 1 ;
20335
 
20336
    display_failure = {failure_reason, "!"} ;
20337
    while ( display_failure[7999:7992] == 0 )
20338
        display_failure = display_failure << 8 ;
20339
 
20340
    display_test = test_name ;
20341
    while ( display_test[799:792] == 0 )
20342
       display_test = display_test << 8 ;
20343
 
20344 63 mihad
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20345 15 mihad
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
20346
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
20347
    $fdisplay( tb_log_file, " *FAILED* because") ;
20348
    $fdisplay( tb_log_file, " %s", display_failure ) ;
20349 63 mihad
    current_test_parameters ;
20350
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20351 15 mihad
    $fdisplay( tb_log_file, " " ) ;
20352
 
20353
    `ifdef STOP_ON_FAILURE
20354
    #20 $stop ;
20355
    `endif
20356
end
20357
endtask // test_fail
20358
 
20359
task test_ok ;
20360
    reg [799:0] display_test ;
20361
begin
20362
   tests_successfull = tests_successfull + 1 ;
20363
 
20364
   display_test = test_name ;
20365
   while ( display_test[799:792] == 0 )
20366
       display_test = display_test << 8 ;
20367
 
20368 63 mihad
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20369 15 mihad
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
20370
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
20371
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
20372 63 mihad
   current_test_parameters ;
20373
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
20374 15 mihad
   $fdisplay( tb_log_file, " " ) ;
20375
end
20376
endtask // test_ok
20377
 
20378
task test_summary;
20379
begin
20380 63 mihad
    $fdisplay(tb_log_file, "\n \n");
20381 15 mihad
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
20382
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
20383
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
20384
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
20385
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
20386
    $fclose(tb_log_file) ;
20387
end
20388
endtask
20389
 
20390 63 mihad
task current_test_parameters ;
20391
    reg [87:0] decode_speed_text ;
20392
begin
20393
    case (tb_target_decode_speed)
20394
        3'b000: decode_speed_text = "FAST       " ;
20395
        3'b001: decode_speed_text = "MEDIUM     " ;
20396
        3'b010: decode_speed_text = "SLOW       " ;
20397
        3'b011: decode_speed_text = "SUBTRACTIVE" ;
20398
    endcase
20399
 
20400
    $fdisplay( tb_log_file, "TEST PARAMETERS:") ;
20401
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Initial Wait States         = %d", (3'd4 - tb_init_waits)) ;
20402
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Subsequent Wait States      = %d", (3'd4 - tb_subseq_waits)) ;
20403
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' DEVSEL speed                = %s", decode_speed_text) ;
20404
 
20405
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Initial Wait States    = %d", tb_init_waits) ;
20406
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Subsequent Wait States = %d", tb_subseq_waits) ;
20407
end
20408
endtask
20409
 
20410 73 mihad
`include "pci_bench_common_tasks.v"
20411 15 mihad
endmodule

powered by: WebSVN 2.1.0

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