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

Subversion Repositories pci

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

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
//
43
 
44 15 mihad
`include "pci_constants.v"
45
`include "bus_commands.v"
46
`include "pci_testbench_defines.v"
47
`include "timescale.v"
48
 
49 51 mihad
`ifdef HOST
50
    `ifdef NO_CNF_IMAGE
51
    `else
52
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
53
    `endif
54
`else
55
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
56
`endif
57
 
58 15 mihad
module SYSTEM ;
59
 
60
`include "pci_blue_constants.vh"
61
`include "pci_blue_options.vh"
62
 
63
integer tests_successfull ;
64
integer tests_failed ;
65
integer tb_log_file ;
66
reg [799:0] test_name ;
67
 
68
reg pci_clock ;
69
reg wb_clock ;
70
reg reset ;
71
 
72
wire [4:0] arb_grant_out ;
73
 
74
wire [31:0] AD ;
75
wire [3:0]  CBE ;
76
pullup(INTA) ;
77
pullup(MAS0_REQ) ;
78
pullup(MAS1_REQ) ;
79
pullup(MAS2_REQ) ;
80
pullup(MAS3_REQ) ;
81
 
82
wire MAS0_GNT = ~arb_grant_out[0];
83
wire MAS1_GNT = ~arb_grant_out[1] ;
84
wire MAS2_GNT = ~arb_grant_out[2] ;
85
wire MAS3_GNT = ~arb_grant_out[3] ;
86
 
87
pullup(FRAME) ;
88
pullup(IRDY) ;
89 45 mihad
 
90
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
91
 
92 15 mihad
pullup(DEVSEL) ;
93
pullup(TRDY) ;
94
pullup(STOP) ;
95
wire   PAR ;
96
pullup(PERR) ;
97
pullup(SERR) ;
98
wire [3:0] MAS1_IDSEL ;
99
 
100
pullup lockpu ( LOCK ) ;
101
 
102
wire        RST_O ;
103
wire        INT_O ;
104
reg         INT_I ;
105
wire [31:0] ADR_I ;
106
wire [31:0] SDAT_I ;
107
wire [31:0] SDAT_O ;
108
wire [3:0]  SEL_I ;
109
wire        CYC_I ;
110
wire        STB_I ;
111
wire        WE_I ;
112
wire        CAB_I ;
113
wire        ACK_O ;
114
wire        RTY_O ;
115
wire        ERR_O ;
116
 
117
wire [31:0] ADR_O ;
118
wire [31:0] MDAT_I ;
119
wire [31:0] MDAT_O ;
120
wire [3:0]  SEL_O ;
121
wire        CYC_O ;
122
wire        STB_O ;
123
wire        WE_O ;
124
wire        CAB_O ;
125
wire        ACK_I ;
126
wire        RTY_I ;
127
wire        ERR_I ;
128
 
129 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
130
 
131
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
132
 
133 15 mihad
wire        reset_wb ; // reset to Wb devices
134
 
135
`ifdef GUEST
136
    wire    RST = ~reset ;
137
    assign  reset_wb = RST_O ;
138
`else
139
    pullup(RST) ;
140
    assign  reset_wb = reset ;
141
`endif
142
 
143
`define PCI_BRIDGE_INSTANCE bridge32_top
144
 
145
TOP `PCI_BRIDGE_INSTANCE
146
(
147
    .CLK    ( pci_clock),
148
    .AD     ( AD ),
149
    .CBE    ( CBE ),
150
    .RST    ( RST ),
151
    .INTA   ( INTA ),
152
    .REQ    ( MAS0_REQ ),
153
    .GNT    ( MAS0_GNT ),
154
    .FRAME  ( FRAME ),
155
    .IRDY   ( IRDY ),
156
    .IDSEL  ( TAR0_IDSEL),
157
    .DEVSEL ( DEVSEL ),
158
    .TRDY   ( TRDY ),
159
    .STOP   ( STOP ),
160
    .PAR    ( PAR ),
161
    .PERR   ( PERR ),
162
    .SERR   ( SERR ),
163
 
164
    .CLK_I  ( wb_clock ),
165
    .RST_I  ( reset ),
166
    .RST_O  ( RST_O ),
167
    .INT_I  ( INT_I ),
168
    .INT_O  ( INT_O ),
169
 
170
    // WISHBONE slave interface
171
    .ADR_I  ( ADR_I ),
172
    .SDAT_I ( SDAT_I ),
173
    .SDAT_O ( SDAT_O ),
174
    .SEL_I  ( SEL_I ),
175
    .CYC_I  ( CYC_I ),
176
    .STB_I  ( STB_I ),
177
    .WE_I   ( WE_I ),
178
    .CAB_I  ( CAB_I),
179
    .ACK_O  ( ACK_O ),
180
    .RTY_O  ( RTY_O ),
181
    .ERR_O  ( ERR_O ),
182
 
183
    // WISHBONE master interface
184
    .ADR_O  ( ADR_O ),
185
    .MDAT_I ( MDAT_I ),
186
    .MDAT_O ( MDAT_O ),
187
    .SEL_O  ( SEL_O ),
188
    .CYC_O  ( CYC_O ),
189
    .STB_O  ( STB_O ),
190
    .WE_O   ( WE_O ),
191
    .CAB_O  ( CAB_O ),
192
    .ACK_I  ( ACK_I ),
193
    .RTY_I  ( RTY_I ),
194
    .ERR_I  ( ERR_I )
195
) ;
196
 
197
WB_MASTER_BEHAVIORAL wishbone_master
198
(
199
    .CLK_I(wb_clock),
200
    .RST_I(reset_wb),
201
    .TAG_I(4'b0000),
202
    .TAG_O(),
203
    .ACK_I(ACK_O),
204
    .ADR_O(ADR_I),
205
    .CYC_O(CYC_I),
206
    .DAT_I(SDAT_O),
207
    .DAT_O(SDAT_I),
208
    .ERR_I(ERR_O),
209
    .RTY_I(RTY_O),
210
    .SEL_O(SEL_I),
211
    .STB_O(STB_I),
212
    .WE_O (WE_I),
213
    .CAB_O(CAB_I)
214
);
215
 
216
WB_SLAVE_BEHAVIORAL wishbone_slave
217
(
218
    .CLK_I              (wb_clock),
219
    .RST_I              (reset_wb),
220
    .ACK_O              (ACK_I),
221
    .ADR_I              (ADR_O),
222
    .CYC_I              (CYC_O),
223
    .DAT_O              (MDAT_I),
224
    .DAT_I              (MDAT_O),
225
    .ERR_O              (ERR_I),
226
    .RTY_O              (RTY_I),
227
    .SEL_I              (SEL_O),
228
    .STB_I              (STB_O),
229
    .WE_I               (WE_O),
230
    .CAB_I              (CAB_O)
231
);
232
 
233
integer wbu_mon_log_file_desc ;
234
integer pciu_mon_log_file_desc ;
235
WB_BUS_MON wbu_wb_mon(
236
                    .CLK_I(wb_clock),
237
                    .RST_I(reset_wb),
238
                    .ACK_I(ACK_O),
239
                    .ADDR_O(ADR_I),
240
                    .CYC_O(CYC_I),
241
                    .DAT_I(SDAT_O),
242
                    .DAT_O(SDAT_I),
243
                    .ERR_I(ERR_O),
244
                    .RTY_I(RTY_O),
245
                    .SEL_O(SEL_I),
246
                    .STB_O(STB_I),
247
                    .WE_O (WE_I),
248
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
249
                    .TAG_O(),
250
                    .CAB_O(CAB_I),
251
                    .log_file_desc ( wbu_mon_log_file_desc )
252
                  ) ;
253
 
254
WB_BUS_MON pciu_wb_mon(
255
                    .CLK_I(wb_clock),
256
                    .RST_I(reset_wb),
257
                    .ACK_I(ACK_I),
258
                    .ADDR_O(ADR_O),
259
                    .CYC_O(CYC_O),
260
                    .DAT_I(MDAT_I),
261
                    .DAT_O(MDAT_O),
262
                    .ERR_I(ERR_I),
263
                    .RTY_I(RTY_I),
264
                    .SEL_O(SEL_O),
265
                    .STB_O(STB_O),
266
                    .WE_O (WE_O),
267
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
268
                    .TAG_O(),
269
                    .CAB_O(CAB_O),
270
                    .log_file_desc( pciu_mon_log_file_desc )
271
                  ) ;
272
 
273
// some aditional signals are needed here because of the arbiter
274
reg [3:0] pci_ext_req_prev ;
275
always@(posedge pci_clock)
276
begin
277
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
278
end
279
reg pci_frame_prev ;
280
always@(posedge pci_clock)
281
begin
282
    pci_frame_prev <= FRAME ;
283
end
284
reg pci_irdy_prev ;
285
always@(posedge pci_clock)
286
begin
287
    pci_irdy_prev <= IRDY ;
288
end
289
 
290
pci_blue_arbiter pci_arbiter
291
(
292
  .pci_int_req_direct(1'b0),
293
  .pci_ext_req_prev(pci_ext_req_prev),
294
  .pci_int_gnt_direct_out(arb_grant_out[4]),
295
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
296
  .pci_frame_prev(~pci_frame_prev),
297
  .pci_irdy_prev(~pci_irdy_prev),
298
  .pci_irdy_now(~IRDY),
299
  .arbitration_enable(1'b1),
300
  .pci_clk(pci_clock),
301
  .pci_reset_comb(~RST)
302
);
303
 
304
reg [31:0] target_message ;
305
 
306
// define output enable signals for monitor inputs
307
// real output enable signals
308
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
309
`ifdef ACTIVE_LOW_OE
310
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
311
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
312
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
313
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
314
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
315
                        !devsel_t_s_oe,
316
                        !ad_oe,
317
                        !cbe_oe,
318
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
319
                        ;
320
`else
321
`ifdef ACTIVE_HIGH_OE
322
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
323
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
324
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
325
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
326
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
327
                        devsel_t_s_oe,
328
                        ad_oe,
329
                        cbe_oe,
330
                        `PCI_BRIDGE_INSTANCE.PERR_en}
331
                        ;
332
`endif
333
`endif
334
/*wire [5:0] oe_sigs_0 = {1'b0,
335
                        1'b0,
336
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
337
                        pci_target32.ad_enable,
338
                        1'b0,
339
                        pci_target32.err_enable | pci_target32.r_err_enable
340
                       } ;
341
*/
342
 
343
wire [5:0] oe_sigs_2 ;
344
wire [5:0] oe_sigs_1 ;
345
 
346
// signals which are used by test modules to know what to do
347
triand  test_accepted_l_int, error_event_int;
348
pullup  (test_accepted_l_int), (error_event_int);
349
 
350
wire    pci_reset_comb  = ~RST;
351
wire    pci_ext_clk     = pci_clock;
352
 
353
integer pci_mon_log_file_desc ;
354
pci_bus_monitor monitor32
355
(
356
    .pci_ext_ad                 (AD),
357
    .pci_ext_cbe_l              (CBE),
358
    .pci_ext_par                (PAR),
359
    .pci_ext_frame_l            (FRAME),
360
    .pci_ext_irdy_l             (IRDY),
361
    .pci_ext_devsel_l           (DEVSEL),
362
    .pci_ext_trdy_l             (TRDY),
363
    .pci_ext_stop_l             (STOP),
364
    .pci_ext_perr_l             (PERR),
365
    .pci_ext_serr_l             (SERR),
366
    .pci_real_req_l             (MAS0_REQ),
367
    .pci_real_gnt_l             (MAS0_GNT),
368
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
369
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
370
    .test_error_event           (error_event_int),
371
    .test_observe_r_oe_sigs     (r_oe_sigs),
372
    .test_observe_0_oe_sigs     (6'h00),
373
    .test_observe_1_oe_sigs     (oe_sigs_1),
374
    .test_observe_2_oe_sigs     (oe_sigs_2),
375
    .test_observe_3_oe_sigs     (6'h00),
376
    .pci_ext_reset_l            (RST),
377
    .pci_ext_clk                (pci_clock),
378
    .log_file_desc              (pci_mon_log_file_desc)
379
) ;
380
 
381
reg [2:0]  test_master_number ;
382
reg [31:0] test_address ;
383
reg [3:0]  test_command ;
384
reg [31:0] test_data ;
385
reg [3:0]  test_byte_enables_l ;
386
reg [9:0]  test_size ;
387
reg        test_make_addr_par_error ;
388
reg        test_make_data_par_error ;
389
reg [3:0]  test_master_initial_wait_states ;
390
reg [3:0]  test_master_subsequent_wait_states ;
391
reg [3:0]  test_target_initial_wait_states ;
392
reg [3:0]  test_target_subsequent_wait_states ;
393
reg [1:0]  test_target_devsel_speed ;
394
reg        test_fast_back_to_back ;
395
reg [2:0]  test_target_termination ;
396
reg        test_expect_master_abort ;
397
reg        test_start ;
398
reg [25:0] test_target_response ;
399
 
400
wire [31:0] master2_received_data ;
401
wire        master2_received_data_valid ;
402
reg         master2_check_received_data ;
403
pci_behaviorial_device pci_behaviorial_device2
404
(
405
    .pci_ext_ad(AD),
406
    .pci_ext_cbe_l(CBE),
407
    .pci_ext_par(PAR),
408
    .pci_ext_frame_l(FRAME),
409
    .pci_ext_irdy_l(IRDY),
410
    .pci_ext_devsel_l(DEVSEL),
411
    .pci_ext_trdy_l(TRDY),
412
    .pci_ext_stop_l(STOP),
413
    .pci_ext_perr_l(PERR),
414
    .pci_ext_serr_l(SERR),
415
    .pci_ext_idsel(TAR2_IDSEL),
416
    .pci_ext_inta_l(INTA),
417
    .pci_ext_req_l(MAS2_REQ),
418
    .pci_ext_gnt_l(MAS2_GNT),
419
    .pci_ext_reset_l(RST),
420
    .pci_ext_clk(pci_clock),
421
 
422
// Signals used by the test bench instead of using "." notation
423
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
424
    .test_master_number                 (test_master_number[2:0]),
425
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
426
    .test_command                       (test_command[3:0]),
427
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
428
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
429
    .test_size                          (test_size),
430
    .test_make_addr_par_error           (test_make_addr_par_error),
431
    .test_make_data_par_error           (test_make_data_par_error),
432
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
433
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
434
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
435
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
436
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
437
    .test_fast_back_to_back             (test_fast_back_to_back),
438
    .test_target_termination            (test_target_termination[2:0]),
439
    .test_expect_master_abort           (test_expect_master_abort),
440
    .test_start                         (test_start),
441
    .test_accepted_l                    (test_accepted_l_int),
442
    .test_error_event                   (error_event_int),
443
    .test_device_id                     (`Test_Master_2),
444
    .test_target_response               (test_target_response),
445
 
446
    .master_received_data               (master2_received_data),
447
    .master_received_data_valid         (master2_received_data_valid),
448
    .master_check_received_data         (master2_check_received_data)
449
);
450
 
451
wire [31:0] master1_received_data ;
452
wire        master1_received_data_valid ;
453
reg         master1_check_received_data ;
454
pci_behaviorial_device pci_behaviorial_device1
455
(
456
    .pci_ext_ad(AD),
457
    .pci_ext_cbe_l(CBE),
458
    .pci_ext_par(PAR),
459
    .pci_ext_frame_l(FRAME),
460
    .pci_ext_irdy_l(IRDY),
461
    .pci_ext_devsel_l(DEVSEL),
462
    .pci_ext_trdy_l(TRDY),
463
    .pci_ext_stop_l(STOP),
464
    .pci_ext_perr_l(PERR),
465
    .pci_ext_serr_l(SERR),
466
    .pci_ext_idsel(TAR1_IDSEL),
467
    .pci_ext_inta_l(INTA),
468
    .pci_ext_req_l(MAS1_REQ),
469
    .pci_ext_gnt_l(MAS1_GNT),
470
    .pci_ext_reset_l(RST),
471
    .pci_ext_clk(pci_clock),
472
 
473
// Signals used by the test bench instead of using "." notation
474
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
475
    .test_master_number                 (test_master_number[2:0]),
476
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
477
    .test_command                       (test_command[3:0]),
478
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
479
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
480
    .test_size                          (test_size),
481
    .test_make_addr_par_error           (test_make_addr_par_error),
482
    .test_make_data_par_error           (test_make_data_par_error),
483
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
484
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
485
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
486
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
487
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
488
    .test_fast_back_to_back             (test_fast_back_to_back),
489
    .test_target_termination            (test_target_termination[2:0]),
490
    .test_expect_master_abort           (test_expect_master_abort),
491
    .test_start                         (test_start),
492
    .test_accepted_l                    (test_accepted_l_int),
493
    .test_error_event                   (error_event_int),
494
    .test_device_id                     (`Test_Master_1),
495
    .test_target_response               (test_target_response),
496
 
497
    .master_received_data               (master1_received_data),
498
    .master_received_data_valid         (master1_received_data_valid),
499
    .master_check_received_data         (master1_check_received_data)
500
);
501
 
502
pci_unsupported_commands_master ipci_unsupported_commands_master
503
(
504
    .CLK    ( pci_clock),
505
    .AD     ( AD ),
506
    .CBE    ( CBE ),
507
    .RST    ( RST ),
508
    .REQ    ( MAS3_REQ ),
509
    .GNT    ( MAS3_GNT ),
510
    .FRAME  ( FRAME ),
511
    .IRDY   ( IRDY ),
512
    .DEVSEL ( DEVSEL ),
513
    .TRDY   ( TRDY ),
514
    .STOP   ( STOP ),
515
    .PAR    ( PAR )
516
) ;
517
 
518 45 mihad
`ifdef HOST
519
 
520
reg     [1:0]   conf_cyc_type1_target_response ;
521
reg     [31:0]  conf_cyc_type1_target_data ;
522
reg     [7:0]   conf_cyc_type1_target_bus_num ;
523
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
524
 
525
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
526
(
527
    .CLK              ( pci_clock),
528
    .AD               ( AD ),
529
    .CBE              ( CBE ),
530
    .RST              ( RST ),
531
    .FRAME            ( FRAME ),
532
    .IRDY             ( IRDY ),
533
    .DEVSEL           ( DEVSEL ),
534
    .TRDY             ( TRDY ),
535
    .STOP             ( STOP ),
536
    .PAR              ( PAR ),
537
 
538
    .response         ( conf_cyc_type1_target_response ),
539
    .data_out         ( conf_cyc_type1_target_data ),
540
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
541
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
542
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
543
    .bus_number       ( conf_cyc_type1_target_bus_num )
544
);
545
`endif
546
 
547 15 mihad
// pci clock generator
548
always
549
`ifdef PCI33
550
    #15 pci_clock = ~pci_clock ;
551
`else
552
`ifdef PCI66
553
    #7.5 pci_clock = ~pci_clock ;
554
`endif
555
`endif
556
 
557
// WISHBONE clock generation
558
always
559
    #(((1/`WB_FREQ)/2)) wb_clock = ~wb_clock ;
560
 
561
// Make test name visible when the Master starts working on it
562
reg     [79:0] present_test_name;
563
reg     [79:0] next_test_name;
564
wire    test_accepted = ~test_accepted_l_int;
565
always @(posedge test_accepted)
566
begin
567
    present_test_name <= next_test_name;
568
end
569
 
570
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
571
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
572
 
573
// basic configuration parameters for both behavioral devices
574
parameter [2:0] Master_ID_A                           = `Test_Master_1;
575
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
576
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
577
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
578
 
579
parameter [2:0] Master_ID_B                           = `Test_Master_2;
580
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
581
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
582
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
583
 
584
// basic configuration parameters for REAL device
585
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
586
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
587
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
588
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
589
 
590
// reg  [2:0]   ack_err_rty_termination ;
591
// reg          wait_cycles ;
592
// reg  [7:0]   num_of_retries ;
593
 
594
//reg [19:0] pci_config_base ;
595
reg [7:0] system_burst_size ;
596
reg [7:0] bridge_latency ;
597
integer   target_mem_image ;
598
integer   target_io_image ;
599
 
600
initial
601
begin
602
    next_test_name[79:0] <= "Nowhere___";
603
    reset = 1'b1 ;
604
    pci_clock = 1'b0 ;
605
    wb_clock  = 1'b1 ;
606
    target_message = 32'h0000_0000 ;
607
//  num_of_retries = 8'h01 ;
608
//  ack_err_rty_termination = 3'b100 ;
609
//  wait_cycles = 1'b0 ;
610
 
611
    // system paameters
612
    system_burst_size = 16 ;
613
    bridge_latency    = 8 ;
614
 
615
    // set initial values for controling the behavioral PCI master
616
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
617
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
618
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
619
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
620
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
621
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
622
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
623
 
624
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
625
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
626
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
627
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
628
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
629
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
630
 
631
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
632
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
633
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
634
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
635
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
636
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
637
 
638
    test_master_number = `Test_Master_2 ;
639
    test_address = 32'h0000_0000 ;
640
    test_command = `BC_RESERVED0 ;
641
    test_data = 32'h0000_0000 ;
642
    test_byte_enables_l   = 4'hF ;
643
    test_size = 0 ;
644
    test_make_addr_par_error = 0 ;
645
    test_make_data_par_error = 0;
646
    test_master_initial_wait_states = 0 ;
647
    test_master_subsequent_wait_states = 0 ;
648
    test_target_initial_wait_states = 0 ;
649
    test_target_subsequent_wait_states = 0;
650
    test_target_devsel_speed = `Test_Devsel_Fast ;
651
    test_fast_back_to_back = 0 ;
652
    test_target_termination = `Test_Target_Normal_Completion ;
653
    test_expect_master_abort = 0 ;
654
    test_start = 0 ;
655
    test_target_response = 0 ;
656
 
657
    master1_check_received_data = 0 ;
658
    master2_check_received_data = 0 ;
659
 
660 45 mihad
    `ifdef HOST
661
        conf_cyc_type1_target_response = 0 ;
662
        conf_cyc_type1_target_data = 0 ;
663
        conf_cyc_type1_target_bus_num = 255 ;
664
    `endif
665 15 mihad
 
666
    // fill memory and IO data with random values
667
    fill_memory ;
668
 
669
    INT_I = 0 ;
670
 
671
    // extract from constants which target image can be used as IO and which as memory
672
    `ifdef HOST
673
        target_mem_image = 1 ;
674
        target_io_image  = 1 ;
675
    `else
676
        target_mem_image = -1 ;
677
        target_io_image     = -1 ;
678
        if ( `PCI_BA1_MEM_IO === 0 )
679
            target_mem_image = 1 ;
680
        else
681
            target_io_image = 1 ;
682
 
683
        if ( target_mem_image === -1 )
684
        begin
685
            `ifdef PCI_IMAGE2
686
                if ( `PCI_BA2_MEM_IO === 0 )
687
                    target_mem_image = 2 ;
688
                else if ( target_io_image === -1 )
689
                    target_io_image = 2 ;
690
            `endif
691
        end
692
 
693
        if ( target_mem_image === -1 )
694
        begin
695
            `ifdef PCI_IMAGE3
696
                if ( `PCI_BA3_MEM_IO === 0 )
697
                    target_mem_image = 3 ;
698
                else if ( target_io_image === -1 )
699
                    target_io_image = 3 ;
700
            `endif
701
        end
702
 
703
        if ( target_mem_image === -1 )
704
        begin
705
            `ifdef PCI_IMAGE4
706
                if ( `PCI_BA4_MEM_IO === 0 )
707
                    target_mem_image = 4 ;
708
                else if ( target_io_image === -1 )
709
                    target_io_image = 4 ;
710
            `endif
711
        end
712
 
713
        if ( target_mem_image === -1 )
714
        begin
715
            `ifdef PCI_IMAGE5
716
                if ( `PCI_BA5_MEM_IO === 0 )
717
                    target_mem_image = 5 ;
718
                else if ( target_io_image === -1 )
719
                    target_io_image = 5 ;
720
            `endif
721
        end
722
    `endif
723
 
724
    tests_successfull = 0 ;
725
    tests_failed = 0 ;
726
 
727
    tb_log_file = $fopen("../log/pci_tb.log") ;
728
 
729
    if ( tb_log_file < 2 )
730
    begin
731
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
732
        $finish ;
733
    end
734
 
735
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
736
    $fdisplay( tb_log_file,"" ) ;
737
 
738
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
739
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
740
 
741
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
742
    begin
743
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
744
        $finish ;
745
    end
746
 
747
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
748
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
749
 
750
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
751
    if ( pci_mon_log_file_desc < 2 )
752
    begin
753
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
754
        $finish ;
755
    end
756
 
757
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
758
 
759
    run_tests ;
760
end
761
 
762
task fill_memory ;
763
    integer temp_index ;
764
begin
765
    // fill write memories with random data
766
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
767
    begin
768
        wmem_data[temp_index[9:0]] = $random ;
769 26 mihad
        # 1;
770 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
771 26 mihad
        # 1;
772 15 mihad
    end
773
    // fill WB slave behavioral MEMORY
774
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
775
    begin
776
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
777
        # 1;
778
    end
779
end
780
endtask // fill_memory
781
 
782
reg [2:0] tb_init_waits ;
783
reg [2:0] tb_subseq_waits ;
784
reg [2:0] tb_target_decode_speed ;
785
 
786
task run_tests ;
787
begin
788
    // first - reset logic
789
    do_reset ;
790 45 mihad
    test_initial_conf_values ;
791
 
792 15 mihad
    next_test_name[79:0] <= "Initing...";
793
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
794
 
795
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
796
    begin
797
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
798
        begin
799
 
800
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
801
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
802
 
803
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
804
            begin
805
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
806
 
807
                `ifdef HOST
808
                    configure_bridge_target ;
809
                    find_pci_devices ;
810 45 mihad
                    test_configuration_cycle_target_abort ;
811
                    test_configuration_cycle_type1_generation ;
812 15 mihad
                `endif
813
 
814
                @(posedge pci_clock) ;
815
                configure_target(1) ;
816
                @(posedge pci_clock) ;
817
                configure_target(2) ;
818
 
819
                `ifdef GUEST
820
                    configure_bridge_target ;
821
                `endif
822
 
823
               next_test_name[79:0] <= "WB_SLAVE..";
824
 
825
                $display("Testing WISHBONE slave images' features!") ;
826
                test_wb_image(1) ;
827
 
828
                `ifdef WB_IMAGE2
829
                    test_wb_image(2) ;
830
                `else
831
                    $display(" WB IMAGE 2 not implemented! ") ;
832
                `endif
833
 
834
                `ifdef WB_IMAGE3
835
                    test_wb_image(3) ;
836
                `else
837
                    $display(" WB IMAGE 3 not implemented! ") ;
838
                `endif
839
 
840
                `ifdef WB_IMAGE4
841
                    test_wb_image(4) ;
842
                `else
843
                    $display(" WB IMAGE 4 not implemented! ") ;
844
                `endif
845
 
846
                `ifdef WB_IMAGE5
847
                    test_wb_image(5) ;
848
                `else
849
                    $display(" WB IMAGE 5 not implemented! ") ;
850
                `endif
851
 
852
                wb_slave_errors ;
853
                wb_to_pci_error_handling ;
854
 
855
                parity_checking ;
856
 
857
                wb_to_pci_transactions ;
858
 
859
                `ifdef HOST
860
                iack_cycle ;
861
                `endif
862
 
863
            end
864
            $display(" ") ;
865
            $display("WB slave images' tests finished!") ;
866
 
867
            $display("########################################################################") ;
868
            $display("########################################################################") ;
869
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
870
            $display("########################################################################") ;
871
            $display("########################################################################") ;
872
 
873
            $display("Testing PCI target images' features!") ;
874
            configure_bridge_target_base_addresses ;
875
 
876 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
877
                test_conf_cycle_type1_reference ;
878
            `endif
879
 
880 15 mihad
            `ifdef HOST
881
             `ifdef NO_CNF_IMAGE
882
              `ifdef PCI_IMAGE0
883
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
884
            test_pci_image(0) ;
885
              `else
886
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
887
              `endif
888
             `else
889
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
890
             `endif
891
            `endif
892
 
893
            $display("PCI image 1 is ALWAYS implemented!") ;
894
            test_pci_image(1) ;
895
 
896
            `ifdef PCI_IMAGE2
897
            $display("PCI image 2 is implemented!") ;
898
            test_pci_image(2) ;
899
            `else
900
            $display("PCI image 2 is NOT implemented!") ;
901
            `endif
902
 
903
            `ifdef PCI_IMAGE3
904
            $display("PCI image 3 is implemented!") ;
905
            test_pci_image(3) ;
906
            `else
907
            $display("PCI image 3 is NOT implemented!") ;
908
            `endif
909
 
910
            `ifdef PCI_IMAGE4
911
            $display("PCI image 4 is implemented!") ;
912
            test_pci_image(4) ;
913
            `else
914
            $display("PCI image 4 is NOT implemented!") ;
915
            `endif
916
 
917
            `ifdef PCI_IMAGE5
918
            $display("PCI image 5 is implemented!") ;
919
            test_pci_image(5) ;
920
            `else
921
            $display("PCI image 5 is NOT implemented!") ;
922
            `endif
923
 
924
            test_wb_error_rd ;
925
 
926
            target_fast_back_to_back ;
927
            target_disconnects ;
928
 
929
            if ( target_io_image !== -1 )
930
                test_target_abort( target_io_image ) ;
931
            $display(" ") ;
932
            $display("PCI target images' tests finished!") ;
933
 
934
            transaction_ordering ;
935 33 mihad
 
936
            target_completion_expiration ;
937 15 mihad
            $display(" ") ;
938
            $display("PCI transaction ordering tests finished!") ;
939
        end
940
    end
941
 
942
    test_summary ;
943
 
944
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
945
    $stop ;
946
end
947
endtask // run_tests
948
 
949
task do_reset;
950
begin
951
    next_test_name[79:0] <= "Reset.....";
952
 
953
    reset = 1'b1 ;
954
    #100 ;
955
    `ifdef HOST
956
        @(posedge wb_clock) ;
957
    `else
958
    `ifdef GUEST
959
        @(posedge pci_clock) ;
960
    `endif
961
    `endif
962
 
963
    reset <= 1'b0 ;
964
 
965 45 mihad
    `ifdef HOST
966
        @(posedge wb_clock) ;
967
    `else
968
    `ifdef GUEST
969
        @(posedge pci_clock) ;
970
    `endif
971
    `endif
972
 
973 15 mihad
end
974
endtask
975
 
976
/*############################################################################
977
WB SLAVE UNIT tasks
978
===================
979
############################################################################*/
980
 
981
task configure_target ;
982 45 mihad
    input [1:0]  beh_dev_num ;
983 15 mihad
    reg   [31:0] base_address1 ;
984
    reg   [31:0] base_address2 ;
985
    reg   [2:0]  Master_ID;
986
    reg   [31:0] Target_Config_Addr;
987 45 mihad
    reg   [4:0]  device_num ;
988 15 mihad
begin
989 45 mihad
    if (beh_dev_num === 1)
990 15 mihad
    begin
991
        base_address1       = `BEH_TAR1_MEM_START ;
992
        base_address2       = `BEH_TAR1_IO_START  ;
993
        Master_ID           = `Test_Master_2 ;
994
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
995 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
996 15 mihad
    end
997
    else
998 45 mihad
    if (beh_dev_num === 2)
999 15 mihad
    begin
1000
        base_address1       = `BEH_TAR2_MEM_START ;
1001
        base_address2       = `BEH_TAR2_IO_START  ;
1002
        Master_ID           = `Test_Master_1 ;
1003
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1004 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1005 15 mihad
    end
1006
 
1007
    // write target's base addresses
1008
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1009
    // type 0 cycle, byte enables, base address
1010
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1011
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1012
 
1013
    // enable target's response and master
1014
    // enable parity errors, disable system error
1015
 
1016
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1017
 
1018
end
1019
endtask //configure_target
1020
 
1021
task test_wb_image ;
1022
    input [2:0]  image_num ;
1023
    reg   [11:0] ctrl_offset ;
1024
    reg   [11:0] ba_offset ;
1025
    reg   [11:0] am_offset ;
1026
    reg   [11:0] ta_offset ;
1027
    reg   [11:0] err_cs_offset ;
1028
    reg `WRITE_STIM_TYPE write_data ;
1029
    reg `READ_STIM_TYPE  read_data ;
1030
    reg `READ_RETURN_TYPE read_status ;
1031
 
1032
    reg `WRITE_RETURN_TYPE write_status ;
1033
    reg `WB_TRANSFER_FLAGS write_flags ;
1034
    reg [31:0] temp_val ;
1035
    reg        ok   ;
1036
    reg [11:0] pci_ctrl_offset ;
1037
    reg [31:0] image_base ;
1038
    reg [31:0] target_address ;
1039
    reg [31:0] translation_address ;
1040
    integer    i ;
1041
    integer    j ;
1042
begin:main
1043
    pci_ctrl_offset = 12'h4 ;
1044
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1045
    // image 0 can only be configuration image - start with 1
1046
    if (image_num === 1)
1047
    begin
1048
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1049
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1050
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1051
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1052
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1053
    end
1054
    else if (image_num === 2)
1055
    begin
1056
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1057
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1058
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1059
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1060
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1061
    end
1062
    else if (image_num === 3)
1063
    begin
1064
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1065
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1066
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1067
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1068
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1069
    end
1070
    else if (image_num === 4)
1071
    begin
1072
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1073
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1074
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1075
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1076
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1077
    end
1078
    else if (image_num === 5)
1079
    begin
1080
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1081
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1082
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1083
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1084
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1085
    end
1086
    else
1087
    begin
1088
        test_name   = "WB IMAGES' FEATURES TEST" ;
1089
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1090
        disable main ;
1091
    end
1092
 
1093
    target_address  = `BEH_TAR1_MEM_START ;
1094
    image_base      = 0 ;
1095
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1096
 
1097
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1098
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1099
    write_flags                      = 0 ;
1100
    write_flags`INIT_WAITS           = tb_init_waits ;
1101
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1102
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1103
 
1104
    test_name = "WB IMAGE CONFIGURATION" ;
1105
    // enable master & target operation
1106
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1107
    if ( ok !== 1 )
1108
    begin
1109
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1110
        test_fail("write to PCI Device Control register didn't succeede");
1111
        disable main ;
1112
    end
1113
 
1114
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1115
    if ( ok !== 1 )
1116
    begin
1117
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1118
        test_fail("write to WB Error Control and Status register didn't succeede");
1119
        disable main ;
1120
    end
1121
 
1122
    // prepare image control register
1123
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1124
    if ( ok !== 1 )
1125
    begin
1126
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1127
        test_fail("write to WB Image Control register didn't succeede");
1128
        disable main ;
1129
    end
1130
 
1131
    // prepare base address register
1132
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1133
    if ( ok !== 1 )
1134
    begin
1135
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1136
        test_fail("write to WB Base Address register didn't succeede");
1137
        disable main ;
1138
    end
1139
 
1140
    // write address mask register
1141
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1142
    if ( ok !== 1 )
1143
    begin
1144
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1145
        test_fail("write to WB Address Mask register didn't succeede");
1146
        disable main ;
1147
    end
1148
 
1149
    fork
1150
    begin
1151
        write_data`WRITE_ADDRESS = target_address ;
1152
        write_data`WRITE_DATA    = wmem_data[0] ;
1153
        write_data`WRITE_SEL     = 4'hF ;
1154
 
1155
        // handle retries from now on
1156
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1157
 
1158
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1159
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1160
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1161
        begin
1162
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1163
            test_fail("WB Slave state machine failed to post single memory write");
1164
            disable main ;
1165
        end
1166
 
1167
        // read written data back
1168
        read_data`READ_ADDRESS  = target_address ;
1169
        read_data`READ_SEL      = 4'hF ;
1170
        read_data`READ_TAG_STIM = 0 ;
1171
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1172
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1173
        begin
1174
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1175
            test_fail("PCI bridge didn't process the read as expected");
1176
            disable main ;
1177
        end
1178
 
1179
        if (read_status`READ_DATA !== wmem_data[0])
1180
        begin
1181
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1182
            test_fail("PCI bridge returned unexpected Read Data");
1183
        end
1184
        else
1185
            test_ok ;
1186
    end
1187
    begin
1188
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1189
        if ( ok !== 1 )
1190
        begin
1191
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1192
        end
1193
        else
1194
            test_ok ;
1195
 
1196
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1197
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1198
        if ( ok !== 1 )
1199
        begin
1200
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1201
        end
1202
    end
1203
    join
1204
 
1205
    // if address translation is implemented - try it out
1206
    translation_address = image_base ;
1207
    `ifdef ADDR_TRAN_IMPL
1208
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1209
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1210
    if ( ok !== 1 )
1211
    begin
1212
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1213
        test_fail("write to WB Image Translation Address Register failed") ;
1214
        disable main ;
1215
    end
1216
 
1217
    target_address  = `BEH_TAR2_MEM_START ;
1218
    image_base      = 0 ;
1219
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1220
 
1221
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1222
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1223
 
1224
    write_flags                      = 0 ;
1225
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1226
 
1227
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1228
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1229
    if ( ok !== 1 )
1230
    begin
1231
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1232
        test_fail("write to WB Image Base Address Register failed") ;
1233
        disable main ;
1234
    end
1235
 
1236
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1237
    // enable address translation
1238
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1239
    if ( ok !== 1 )
1240
    begin
1241
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1242
        test_fail("write to WB Image Control Register failed") ;
1243
        disable main ;
1244
    end
1245
 
1246
    `endif
1247
 
1248
    fork
1249
    begin
1250
        write_data`WRITE_ADDRESS = target_address + 4 ;
1251
        write_data`WRITE_DATA    = wmem_data[1] ;
1252
        write_data`WRITE_SEL     = 4'hF ;
1253
 
1254
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1255
 
1256
        `ifdef ADDR_TRAN_IMPL
1257
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1258
        `else
1259
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1260
        `endif
1261
 
1262
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1263
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1264
        begin
1265
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1266
            test_fail("WB Slave state machine failed to post single memory write") ;
1267
            disable main ;
1268
        end
1269
 
1270
        // read written data back
1271
        read_data`READ_ADDRESS  = target_address + 4 ;
1272
        read_data`READ_SEL      = 4'hF ;
1273
        read_data`READ_TAG_STIM = 0 ;
1274
 
1275
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1276
 
1277
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1278
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1279
        begin
1280
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1281
            test_fail("PCI bridge failed to process single delayed memory read") ;
1282
            disable main ;
1283
        end
1284
 
1285
        if (read_status`READ_DATA !== wmem_data[1])
1286
        begin
1287
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1288
            test_fail("PCI bridge returned unexpected Read Data");
1289
        end
1290
        else
1291
            test_ok ;
1292
    end
1293
    begin
1294
        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 ) ;
1295
        if ( ok !== 1 )
1296
        begin
1297
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1298
        end
1299
        else
1300
            test_ok ;
1301
 
1302
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1303
        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 ) ;
1304
        if ( ok !== 1 )
1305
        begin
1306
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1307
        end
1308
    end
1309
    join
1310
 
1311
    // 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
1312
    // prepare write data
1313
    for ( i = 0 ; i < 6 ; i = i + 1 )
1314
    begin
1315
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1316
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1317
        write_data`WRITE_SEL     = 4'hF ;
1318
        wishbone_master.blk_write_data[i] = write_data ;
1319
    end
1320
 
1321
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1322
    write_flags`WB_TRANSFER_CAB    = 1 ;
1323
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1324
 
1325
    fork
1326
    begin
1327
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1328
        wishbone_master.wb_block_write(write_flags, write_status) ;
1329
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1330
        begin
1331
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1332
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1333
            disable main ;
1334
        end
1335
    end
1336
    begin
1337
        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 ) ;
1338
        if ( ok !== 1 )
1339
        begin
1340
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1341
        end
1342
        else
1343
            test_ok ;
1344
    end
1345
    join
1346
 
1347
    // set burst size and latency timer
1348
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1349
 
1350
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1351
    write_flags`WB_TRANSFER_CAB    = 1 ;
1352
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1353
 
1354
    // prepare read data
1355
    for ( i = 0 ; i < 4 ; i = i + 1 )
1356
    begin
1357
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1358
        read_data`READ_SEL     = 4'hF ;
1359
        wishbone_master.blk_read_data_in[i] = read_data ;
1360
    end
1361
 
1362
    fork
1363
    begin
1364
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1365
        wishbone_master.wb_block_read(write_flags, read_status) ;
1366
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1367
        begin
1368
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1369
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1370
            disable main ;
1371
        end
1372
 
1373
        // check data read from target
1374
        for ( i = 0 ; i < 4 ; i = i + 1 )
1375
        begin
1376
            read_status = wishbone_master.blk_read_data_out[i] ;
1377
            if (read_status`READ_DATA !== wmem_data[2 + i])
1378
            begin
1379
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1380
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1381
            end
1382
        end
1383
    end
1384
    begin
1385
        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 ) ;
1386
        if ( ok !== 1 )
1387
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1388
        else
1389
            test_ok ;
1390
 
1391
        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 ) ;
1392
        if ( ok !== 1 )
1393
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1394
        else
1395
            test_ok ;
1396
 
1397
        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 ) ;
1398
        if ( ok !== 1 )
1399
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1400
        else
1401
            test_ok ;
1402
 
1403
        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 ) ;
1404
        if ( ok !== 1 )
1405
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1406
        else
1407
            test_ok ;
1408
 
1409
    end
1410
    join
1411
 
1412
    // now repeat this same burst read with various image features enabled or disabled
1413
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1414
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1415
    if (ok !== 1)
1416
    begin
1417
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1418
        test_fail("write to WB Image control register failed") ;
1419
        disable main ;
1420
    end
1421
 
1422
    fork
1423
    begin
1424
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1425
        wishbone_master.wb_block_read(write_flags, read_status) ;
1426
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1427
        begin
1428
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1429
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1430
            disable main ;
1431
        end
1432
 
1433
        // check data read from target
1434
        for ( i = 0 ; i < 4 ; i = i + 1 )
1435
        begin
1436
            read_status = wishbone_master.blk_read_data_out[i] ;
1437
            if (read_status`READ_DATA !== wmem_data[2 + i])
1438
            begin
1439
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1440
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1441
            end
1442
            else
1443
                test_ok ;
1444
        end
1445
    end
1446
    begin
1447
        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 ) ;
1448
        if ( ok !== 1 )
1449
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1450
    end
1451
    join
1452
 
1453
    read_data`READ_ADDRESS  = target_address ;
1454
    read_data`READ_SEL      = 4'hF ;
1455
    read_data`READ_TAG_STIM = 0 ;
1456
 
1457
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1458
    fork
1459
    begin
1460
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1461
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1462
        begin
1463
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1464
            test_fail("delayed single memory read wasn't processed as expected") ;
1465
            disable main ;
1466
        end
1467
 
1468
        if (read_status`READ_DATA !== wmem_data[0])
1469
        begin
1470
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1471
            test_fail("delayed single memory read data value returned was not as expected") ;
1472
        end
1473
        else
1474
            test_ok ;
1475
    end
1476
    begin
1477
        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 ) ;
1478
        if ( ok !== 1 )
1479
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1480
    end
1481
    join
1482
 
1483
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1484
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1485
    if (ok !== 1)
1486
    begin
1487
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1488
        test_fail("write to WB Image control register failed") ;
1489
        disable main ;
1490
    end
1491
 
1492
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1493
    fork
1494
    begin
1495
        wishbone_master.wb_block_read(write_flags, read_status) ;
1496
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1497
        begin
1498
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1499
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1500
            disable main ;
1501
        end
1502
 
1503
        // check data read from target
1504
        for ( i = 0 ; i < 4 ; i = i + 1 )
1505
        begin
1506
            read_status = wishbone_master.blk_read_data_out[i] ;
1507
            if (read_status`READ_DATA !== wmem_data[2 + i])
1508
            begin
1509
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1510
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1511
            end
1512
            else
1513
                test_ok ;
1514
        end
1515
    end
1516
    begin
1517
        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 ) ;
1518
        if ( ok !== 1 )
1519
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1520
    end
1521
    join
1522
 
1523
    read_data`READ_ADDRESS  = target_address + 4 ;
1524
    read_data`READ_SEL      = 4'hF ;
1525
    read_data`READ_TAG_STIM = 0 ;
1526
 
1527
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1528
    fork
1529
    begin
1530
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1531
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1532
        begin
1533
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1534
            test_fail("delayed single memory read wasn't processed as expected") ;
1535
            disable main ;
1536
        end
1537
 
1538
        if (read_status`READ_DATA !== wmem_data[1])
1539
        begin
1540
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1541
            test_fail("delayed single memory read data value returned was not as expected") ;
1542
        end
1543
        else
1544
            test_ok ;
1545
    end
1546
    begin
1547
        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 ) ;
1548
        if ( ok !== 1 )
1549
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1550
    end
1551
    join
1552
 
1553
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1554
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1555
    if (ok !== 1)
1556
    begin
1557
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1558
        test_fail("write to WB Image control register failed") ;
1559
        disable main ;
1560
    end
1561
 
1562
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1563
    fork
1564
    begin
1565
        wishbone_master.wb_block_read(write_flags, read_status) ;
1566
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1567
        begin
1568
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1569
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1570
            disable main ;
1571
        end
1572
 
1573
        // check data read from target
1574
        for ( i = 0 ; i < 4 ; i = i + 1 )
1575
        begin
1576
            read_status = wishbone_master.blk_read_data_out[i] ;
1577
            if (read_status`READ_DATA !== wmem_data[2 + i])
1578
            begin
1579
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1580
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1581
            end
1582
            else
1583
                test_ok ;
1584
        end
1585
    end
1586
    begin
1587
        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 ) ;
1588
        if ( ok !== 1 )
1589
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1590
    end
1591
    join
1592
 
1593
    read_data`READ_ADDRESS  = target_address + 8 ;
1594
    read_data`READ_SEL      = 4'hF ;
1595
    read_data`READ_TAG_STIM = 0 ;
1596
 
1597
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1598
    fork
1599
    begin
1600
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1601
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1602
        begin
1603
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1604
            test_fail("delayed single memory read wasn't processed as expected") ;
1605
            disable main ;
1606
        end
1607
 
1608
        if (read_status`READ_DATA !== wmem_data[2])
1609
        begin
1610
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1611
            test_fail("delayed single memory read data value returned was not as expected") ;
1612
        end
1613
        else
1614
            test_ok ;
1615
    end
1616
    begin
1617
        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 ) ;
1618
        if ( ok !== 1 )
1619
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1620
    end
1621
    join
1622
 
1623
    // map image to IO space
1624
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1625
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1626
    if ( ok !== 1 )
1627
    begin
1628
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1629
        test_fail("write to WB Image Base Address register failed") ;
1630
        disable main ;
1631
    end
1632
 
1633
    write_data`WRITE_ADDRESS = target_address ;
1634
    write_data`WRITE_DATA    = wmem_data[11] ;
1635
    write_data`WRITE_SEL     = 4'hF ;
1636
 
1637
    // handle retries from now on
1638
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1639
 
1640
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1641
    fork
1642
    begin
1643
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1644
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1645
        begin
1646
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1647
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1648
            disable main ;
1649
        end
1650
    end
1651
    begin
1652
        // currently IO commands not supported in behavioral models - master abort
1653
        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 ) ;
1654
        if ( ok !== 1 )
1655
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1656
        else
1657
            test_ok ;
1658
    end
1659
    join
1660
 
1661
    read_data`READ_ADDRESS  = target_address ;
1662
    read_data`READ_SEL      = 4'hF ;
1663
    read_data`READ_TAG_STIM = 0 ;
1664
 
1665
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1666
 
1667
    // currently io commands are not supported by behavioral target - transfer should not be completed
1668
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1669
    fork
1670
    begin
1671
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1672
        if (read_status`CYC_ERR !== 1)
1673
        begin
1674
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1675
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1676
            disable main ;
1677
        end
1678
        else
1679
            test_ok ;
1680
    end
1681
    begin
1682
        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 ) ;
1683
        if ( ok !== 1 )
1684
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1685
    end
1686
    join
1687
 
1688
    // test byte addressing
1689
    read_data`READ_ADDRESS = target_address + 2 ;
1690
    read_data`READ_SEL     = 4'b1100 ;
1691
 
1692
    fork
1693
    begin
1694
        // currently io commands are not supported by behavioral target - transfer should not be completed
1695
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1696
        if (read_status`CYC_ERR !== 1)
1697
        begin
1698
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1699
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1700
            disable main ;
1701
        end
1702
        else test_ok ;
1703
    end
1704
    begin
1705
        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 ) ;
1706
        if ( ok !== 1 )
1707
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1708
    end
1709
    join
1710
 
1711
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1712
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1713
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1714
    if ( ok !== 1 )
1715
    begin
1716
        test_fail("WB Base address register could not be written") ;
1717
        disable main ;
1718
    end
1719
 
1720
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1721
    if ( ok !== 1 )
1722
    begin
1723
        test_fail("WB Address Mask register could not be written") ;
1724
        disable main ;
1725
    end
1726
 
1727
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1728
    if ( ok !== 1 )
1729
    begin
1730
        test_fail("WB Image Control register could not be written") ;
1731
        disable main ;
1732
    end
1733
 
1734
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1735
    write_data`WRITE_DATA    = wmem_data[11] ;
1736
    write_data`WRITE_SEL     = 4'b1000 ;
1737
 
1738
    // handle retries from now on
1739
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1740
 
1741
    fork
1742
    begin
1743
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1744
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1745
        begin
1746
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1747
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1748
            disable main ;
1749
        end
1750
    end
1751
    begin
1752
        // currently IO commands not supported in behavioral models - master abort
1753
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1754
        if ( ok !== 1 )
1755
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1756
        else
1757
            test_ok ;
1758
    end
1759
    join
1760
 
1761
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1762
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1763
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1764
 
1765
    fork
1766
    begin
1767
        // currently io commands are not supported by behavioral target - transfer should not be completed
1768
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1769
        if (read_status`CYC_ERR !== 1)
1770
        begin
1771
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1772
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1773
            disable main ;
1774
        end
1775
        else test_ok ;
1776
    end
1777
    begin
1778
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1779
        if ( ok !== 1 )
1780
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1781
    end
1782
    join
1783
 
1784
    test_name = "DISABLING WB IMAGE" ;
1785
 
1786
    // disable current image
1787
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1788
    if ( ok !== 1 )
1789
    begin
1790
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1791
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1792
        disable main ;
1793
    end
1794
 
1795
    // clear master abort status bit
1796
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1797
    if ( ok !== 1 )
1798
    begin
1799
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1800
        test_fail("write to PCI Device Status register not accepted as expected") ;
1801
        disable main ;
1802
    end
1803
 
1804
end //main
1805
endtask //test_wb_image
1806
 
1807
task wb_slave_errors ;
1808
    reg   [11:0] ctrl_offset ;
1809
    reg   [11:0] ba_offset ;
1810
    reg   [11:0] am_offset ;
1811
    reg   [11:0] ta_offset ;
1812
    reg `WRITE_STIM_TYPE write_data ;
1813
    reg `READ_STIM_TYPE  read_data ;
1814
    reg `READ_RETURN_TYPE read_status ;
1815
 
1816
    reg `WRITE_RETURN_TYPE write_status ;
1817
    reg `WB_TRANSFER_FLAGS write_flags ;
1818
    reg [31:0] temp_val1 ;
1819
    reg [31:0] temp_val2 ;
1820
    reg        ok   ;
1821
    reg [11:0] pci_ctrl_offset ;
1822
    reg [31:0] image_base ;
1823
    reg [31:0] target_address ;
1824
    integer    i ;
1825
    reg skip ;
1826
fork
1827
begin:main
1828
 
1829
    `ifdef GUEST
1830
        skip = 1 ;
1831
    `else
1832
        skip = 0 ;
1833
    `endif
1834
 
1835
    pci_ctrl_offset = 12'h4 ;
1836
 
1837
    // image 1 is used for error testing, since it is always implemented
1838
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1839
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1840
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1841
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1842
 
1843
    target_address  = `BEH_TAR1_MEM_START ;
1844
    image_base      = 0 ;
1845
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1846
 
1847
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1848
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1849
    write_flags                    = 0 ;
1850
    write_flags`INIT_WAITS         = tb_init_waits ;
1851
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1852
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1853
 
1854
    // enable master & target operation
1855
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1856
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1857
    if ( ok !== 1 )
1858
    begin
1859
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1860
        test_fail("PCI Device Control register couldn't be written") ;
1861
        disable no_transaction ;
1862
        disable main ;
1863
    end
1864
 
1865
    // prepare image control register
1866
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1867
    if ( ok !== 1 )
1868
    begin
1869
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1870
        test_fail("WB Image Control register couldn't be written") ;
1871
        disable no_transaction ;
1872
        disable main ;
1873
    end
1874
 
1875
    // prepare base address register
1876
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1877
    if ( ok !== 1 )
1878
    begin
1879
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1880
        test_fail("WB Base Address register couldn't be written") ;
1881
        disable no_transaction ;
1882
        disable main ;
1883
    end
1884
 
1885
    // write address mask register
1886
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1887
    if ( ok !== 1 )
1888
    begin
1889
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1890
        test_fail("WB Address Mask register couldn't be written") ;
1891
        disable no_transaction ;
1892
        disable main ;
1893
    end
1894
 
1895
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1896
 
1897
    skip = 0 ;
1898
 
1899
    // memory mapped image - access is erroneous when address is not alligned
1900
    write_data`WRITE_ADDRESS = target_address + 1 ;
1901
    write_data`WRITE_DATA    = wmem_data[0] ;
1902
    write_data`WRITE_SEL     = 4'hF ;
1903
 
1904
    // handle retries from now on
1905
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1906
 
1907
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
1908
 
1909
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1910
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1911
    begin
1912
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1913
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1914
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1915
        disable no_transaction ;
1916
        disable main ;
1917
    end
1918
 
1919
    write_data`WRITE_ADDRESS = target_address + 2 ;
1920
 
1921
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1922
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1923
    begin
1924
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1925
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1926
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1927
        disable no_transaction ;
1928
        disable main ;
1929
 
1930
    end
1931
 
1932
    write_data`WRITE_ADDRESS = target_address + 3 ;
1933
 
1934
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1935
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1936
    begin
1937
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1938
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1939
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1940
        disable no_transaction ;
1941
        disable main ;
1942
    end
1943
 
1944
    test_ok ;
1945
 
1946
    // perform same tests for read accesses
1947
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
1948
 
1949
    read_data`READ_ADDRESS  = target_address + 2 ;
1950
    read_data`READ_SEL      = 4'hF ;
1951
    read_data`READ_TAG_STIM = 0 ;
1952
 
1953
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1954
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1955
    begin
1956
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1957
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1958
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
1959
        disable no_transaction ;
1960
        disable main ;
1961
    end
1962
 
1963
    test_ok ;
1964
 
1965
    // prepare write data
1966
    for ( i = 0 ; i < 6 ; i = i + 1 )
1967
    begin
1968
        write_data`WRITE_DATA    = wmem_data[i] ;
1969
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
1970
        write_data`WRITE_SEL     = 4'hF ;
1971
        wishbone_master.blk_write_data[i] = write_data ;
1972
    end
1973
 
1974
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1975
    write_flags`WB_TRANSFER_CAB    = 1 ;
1976
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1977
 
1978
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
1979
    wishbone_master.wb_block_write(write_flags, write_status) ;
1980
 
1981
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1982
    begin
1983
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1984
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1985
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
1986
        disable no_transaction ;
1987
        disable main ;
1988
    end
1989
 
1990
    // prepare read data
1991
    for ( i = 0 ; i < 6 ; i = i + 1 )
1992
    begin
1993
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
1994
        read_data`READ_SEL     = 4'hF ;
1995
        wishbone_master.blk_read_data_in[i] = read_data ;
1996
    end
1997
 
1998
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
1999
    wishbone_master.wb_block_read(write_flags, read_status) ;
2000
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2001
    begin
2002
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2003
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2004
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2005
        disable no_transaction ;
2006
        disable main ;
2007
    end
2008
 
2009
    test_ok ;
2010
 
2011
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2012
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2013
 
2014
    // map image to IO space
2015
    `ifdef GUEST
2016
        skip = 1 ;
2017
    `endif
2018
 
2019
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2020
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2021
    if ( ok !== 1 )
2022
    begin
2023
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2024
        test_fail("WB Image Base Address register couldn't be written") ;
2025
        disable no_transaction ;
2026
        disable main ;
2027
    end
2028
 
2029
    skip = 0 ;
2030
 
2031
    write_data`WRITE_ADDRESS = target_address ;
2032
    write_data`WRITE_DATA    = wmem_data[0] ;
2033
    write_data`WRITE_SEL     = 4'b1010 ;
2034
 
2035
    // don't handle retries
2036
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2037
 
2038
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2039
 
2040
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2041
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2042
    begin
2043
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2044
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2045
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2046
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2047
        disable no_transaction ;
2048
        disable main ;
2049
    end
2050
 
2051
    write_data`WRITE_ADDRESS = target_address + 1 ;
2052
    write_data`WRITE_SEL     = 4'b0011 ;
2053
 
2054
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2055
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2056
    begin
2057
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2058
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2059
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2060
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2061
        disable no_transaction ;
2062
        disable main ;
2063
    end
2064
 
2065
    write_data`WRITE_SEL     = 4'b1100 ;
2066
 
2067
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2068
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2069
    begin
2070
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2071
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2072
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2073
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2074
        disable no_transaction ;
2075
        disable main ;
2076
    end
2077
 
2078
    write_data`WRITE_ADDRESS = target_address + 2 ;
2079
    write_data`WRITE_SEL     = 4'b0101 ;
2080
 
2081
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2082
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2083
    begin
2084
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2085
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2086
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2087
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2088
        disable no_transaction ;
2089
        disable main ;
2090
    end
2091
 
2092
    write_data`WRITE_SEL     = 4'b1000 ;
2093
 
2094
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2095
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2096
    begin
2097
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2098
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2099
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2100
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2101
        disable no_transaction ;
2102
        disable main ;
2103
    end
2104
 
2105
    write_data`WRITE_ADDRESS = target_address + 3 ;
2106
    write_data`WRITE_SEL     = 4'b1010 ;
2107
 
2108
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2109
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2110
    begin
2111
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2112
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2113
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2114
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2115
        disable no_transaction ;
2116
        disable main ;
2117
    end
2118
 
2119
    write_data`WRITE_SEL     = 4'b0110 ;
2120
 
2121
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2122
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2123
    begin
2124
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2125
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2126
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2127
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2128
        disable no_transaction ;
2129
        disable main ;
2130
    end
2131
 
2132
    test_ok ;
2133
 
2134
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2135
 
2136
    read_data`READ_ADDRESS  = target_address + 3 ;
2137
    read_data`READ_SEL      = 4'hF ;
2138
    read_data`READ_TAG_STIM = 0 ;
2139
 
2140
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2141
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2142
    begin
2143
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2144
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2145
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2146
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2147
        disable no_transaction ;
2148
        disable main ;
2149
    end
2150
 
2151
    test_ok ;
2152
 
2153
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2154
    // prepare write data
2155
    for ( i = 0 ; i < 6 ; i = i + 1 )
2156
    begin
2157
        write_data`WRITE_DATA    = wmem_data[i] ;
2158
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2159
        write_data`WRITE_SEL     = 4'hF ;
2160
        wishbone_master.blk_write_data[i] = write_data ;
2161
    end
2162
 
2163
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2164
    write_flags`WB_TRANSFER_CAB    = 1 ;
2165
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2166
 
2167
    wishbone_master.wb_block_write(write_flags, write_status) ;
2168
 
2169
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2170
    begin
2171
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2172
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2173
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2174
        disable no_transaction ;
2175
        disable main ;
2176
    end
2177
 
2178
    test_ok ;
2179
 
2180
    test_name = "CAB I/O READ TO WB SLAVE" ;
2181
    // prepare read data
2182
    for ( i = 0 ; i < 6 ; i = i + 1 )
2183
    begin
2184
        read_data`READ_ADDRESS = target_address + 4*i ;
2185
        read_data`READ_SEL     = 4'hF ;
2186
        wishbone_master.blk_read_data_in[i] = read_data ;
2187
    end
2188
 
2189
    wishbone_master.wb_block_read(write_flags, read_status) ;
2190
 
2191
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2192
    begin
2193
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2194
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2195
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2196
        disable no_transaction ;
2197
        disable main ;
2198
    end
2199
 
2200
    test_ok ;
2201
 
2202
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2203
 
2204
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2205
 
2206
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2207
    write_data`WRITE_ADDRESS = target_address + 1 ;
2208
    write_data`WRITE_DATA    = wmem_data[0] ;
2209
    write_data`WRITE_SEL     = 4'hF ;
2210
 
2211
    // don't handle retries
2212
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2213
 
2214
    `ifdef HOST
2215
        `define DO_W_CONF_TEST
2216
        `define DO_R_CONF_TEST
2217
    `else
2218
        `ifdef WB_CNF_IMAGE
2219
             `define DO_R_CONF_TEST
2220
        `endif
2221
    `endif
2222
 
2223
    `ifdef DO_W_CONF_TEST
2224
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2225
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2226
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2227
    begin
2228
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2229
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2230
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2231
        disable no_transaction ;
2232
        disable main ;
2233
    end
2234
 
2235
    write_data`WRITE_ADDRESS = target_address + 2 ;
2236
 
2237
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2238
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2239
    begin
2240
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2241
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2242
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2243
        disable no_transaction ;
2244
        disable main ;
2245
    end
2246
 
2247
    write_data`WRITE_ADDRESS = target_address + 3 ;
2248
 
2249
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2250
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2251
    begin
2252
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2253
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2254
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2255
        disable no_transaction ;
2256
        disable main ;
2257
    end
2258
 
2259
    test_ok ;
2260
    `endif
2261
 
2262
    `ifdef DO_R_CONF_TEST
2263
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2264
    read_data`READ_ADDRESS  = target_address + 3 ;
2265
    read_data`READ_SEL      = 4'hF ;
2266
    read_data`READ_TAG_STIM = 0 ;
2267
 
2268
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2269
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2270
    begin
2271
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2272
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2273
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2274
        disable no_transaction ;
2275
        disable main ;
2276
    end
2277
 
2278
    test_ok ;
2279
    `endif
2280
 
2281
    `ifdef DO_W_CONF_TEST
2282
    // prepare write data
2283
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2284
    for ( i = 0 ; i < 6 ; i = i + 1 )
2285
    begin
2286
        write_data`WRITE_DATA    = wmem_data[i] ;
2287
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2288
        write_data`WRITE_SEL     = 4'hF ;
2289
        wishbone_master.blk_write_data[i] = write_data ;
2290
    end
2291
 
2292
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2293
    write_flags`WB_TRANSFER_CAB    = 1 ;
2294
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2295
 
2296
    wishbone_master.wb_block_write(write_flags, write_status) ;
2297
 
2298
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2299
    begin
2300
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2301
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2302
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2303
        disable no_transaction ;
2304
        disable main ;
2305
    end
2306
    test_ok ;
2307
    `endif
2308
 
2309
    `ifdef DO_R_CONF_TEST
2310
    // prepare read data
2311
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2312
    for ( i = 0 ; i < 6 ; i = i + 1 )
2313
    begin
2314
        read_data`READ_ADDRESS = target_address + 4*i ;
2315
        read_data`READ_SEL     = 4'hF ;
2316
        wishbone_master.blk_read_data_in[i] = read_data ;
2317
    end
2318
 
2319
    wishbone_master.wb_block_read(write_flags, read_status) ;
2320
 
2321
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2322
    begin
2323
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2324
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2325
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2326
        disable no_transaction ;
2327
        disable main ;
2328
    end
2329
    test_ok ;
2330
    `endif
2331
 
2332
    `ifdef GUEST
2333
        skip = 1 ;
2334
    `endif
2335
 
2336
    // disable image
2337
    test_name = "DISABLE IMAGE" ;
2338
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2339
    if ( ok !== 1 )
2340
    begin
2341
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2342
        test_fail("WB Address Mask register couldn't be written") ;
2343
        disable no_transaction ;
2344
        disable main ;
2345
    end
2346
 
2347
    skip = 0 ;
2348
 
2349
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2350
 
2351
    disable no_transaction ;
2352
end
2353
begin:no_transaction
2354
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2355
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2356
    forever
2357
    begin
2358
        @(posedge pci_clock) ;
2359
        if ( skip !== 1 )
2360
        begin
2361
            if ( FRAME !== 1 )
2362
            begin
2363
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2364
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2365
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2366
            end
2367
        end
2368
    end
2369
end
2370
join
2371
endtask //wb_slave_errors
2372
 
2373
task wb_to_pci_error_handling ;
2374
    reg   [11:0] ctrl_offset ;
2375
    reg   [11:0] ba_offset ;
2376
    reg   [11:0] am_offset ;
2377
    reg   [11:0] ta_offset ;
2378
    reg   [11:0] err_cs_offset ;
2379
    reg `WRITE_STIM_TYPE write_data ;
2380
    reg `READ_STIM_TYPE  read_data ;
2381
    reg `READ_RETURN_TYPE read_status ;
2382
 
2383
    reg `WRITE_RETURN_TYPE write_status ;
2384
    reg `WB_TRANSFER_FLAGS write_flags ;
2385
    reg [31:0] temp_val1 ;
2386
    reg [31:0] temp_val2 ;
2387
    reg        ok   ;
2388
    reg [11:0] pci_ctrl_offset ;
2389
    reg [31:0] image_base ;
2390
    reg [31:0] target_address ;
2391
    integer    num_of_trans ;
2392
    integer    current ;
2393
    integer    i ;
2394
begin:main
2395
 
2396
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2397
 
2398
    pci_ctrl_offset = 12'h4 ;
2399
 
2400
    // disable error interrupts and disable error reporting
2401
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2402
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2403
    if ( ok !== 1 )
2404
    begin
2405
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2406
        test_fail("PCI Device Control register couldn't be written") ;
2407
        disable main ;
2408
    end
2409
 
2410
    // image 1 is used for error testing, since it is always implemented
2411
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2412
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2413
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2414
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2415
 
2416
    // set master abort testing address to address that goes out of target's range
2417
    target_address  = `BEH_TAR1_MEM_START ;
2418
    image_base      = 0 ;
2419
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2420
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2421
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2422
 
2423
    write_flags                    = 0 ;
2424
    write_flags`INIT_WAITS         = tb_init_waits ;
2425
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2426
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2427
 
2428
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2429
 
2430
    // enable master & target operation
2431
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2432
    if ( ok !== 1 )
2433
    begin
2434
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2435
        test_fail("PCI Device Control register couldn't be written") ;
2436
        disable main ;
2437
    end
2438
 
2439
    // prepare image control register
2440
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2441
    if ( ok !== 1 )
2442
    begin
2443
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2444
        test_fail("WB Image Control register couldn't be written") ;
2445
        disable main ;
2446
    end
2447
 
2448
    // prepare base address register
2449
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2450
    if ( ok !== 1 )
2451
    begin
2452
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2453
        test_fail("WB Image Base Address register couldn't be written") ;
2454
        disable main ;
2455
    end
2456
 
2457
    // write address mask register
2458
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2459
    if ( ok !== 1 )
2460
    begin
2461
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2462
        test_fail("WB Image Address Mask register couldn't be written") ;
2463
        disable main ;
2464
    end
2465
 
2466
    // disable error reporting
2467
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2468
    if ( ~ok )
2469
    begin
2470
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2471
        test_fail("WB Error Control and Status register couldn't be written") ;
2472
        disable main ;
2473
    end
2474
 
2475
    // perform two writes - one to error address and one to OK address
2476
    // prepare write buffer
2477
 
2478
    write_data`WRITE_ADDRESS = target_address ;
2479
    write_data`WRITE_DATA    = wmem_data[100] ;
2480
    write_data`WRITE_SEL     = 4'hF ;
2481
 
2482
    wishbone_master.blk_write_data[0] = write_data ;
2483
 
2484
    write_flags`WB_TRANSFER_SIZE = 2 ;
2485
 
2486
    // don't handle retries
2487
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2488
    write_flags`WB_TRANSFER_CAB    = 0 ;
2489
 
2490
    $display("Introducing master abort error on single WB to PCI write!") ;
2491
 
2492
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2493
    // first disable target 1
2494
 
2495 45 mihad
    configuration_cycle_write(0,                        // bus number
2496
                              `TAR1_IDSEL_INDEX - 11,   // device number
2497
                              0,                        // function number
2498
                              1,                        // register number
2499
                              0,                        // type of configuration cycle
2500
                              4'b0001,                  // byte enables
2501
                              32'h0000_0000             // data
2502 15 mihad
                             ) ;
2503
 
2504
    fork
2505
    begin
2506
        // start no response monitor in parallel with writes
2507
        musnt_respond(ok) ;
2508
        if ( ok !== 1 )
2509
        begin
2510
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2511
            $display("Testbench is configured wrong!") ;
2512
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2513
        end
2514
        else
2515
            test_ok ;
2516
    end
2517
    begin
2518
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2519
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2520
       begin
2521
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2522
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2523
           test_fail("WB Slave state machine failed to post single memory write");
2524
           disable main ;
2525
       end
2526
    end
2527
    join
2528
 
2529
    /*// read data from second write
2530
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2531
    read_data`READ_ADDRESS = target_address ;
2532
    read_data`READ_SEL     = 4'hF ;
2533
    read_data`READ_TAG_STIM = 0 ;
2534
 
2535
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2536
 
2537
    if ( read_status`READ_DATA !== wmem_data[101] )
2538
    begin
2539
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2540
    end
2541
    */
2542
 
2543
    // read error status register - no errors should be reported since reporting was disabled
2544
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2545
 
2546
    @(posedge pci_clock) ;
2547
    // wait for two WB clocks for synchronization to be finished
2548
    repeat (2)
2549
        @(posedge wb_clock) ;
2550
 
2551
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2552
    if ( temp_val1[8] !== 0 )
2553
    begin
2554
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2555
        $display("Error reporting was disabled, but error was reported anyway!") ;
2556
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2557
        disable main ;
2558
    end
2559
    test_ok ;
2560
 
2561
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2562
    // check for interrupts - there should be no interrupt requests active
2563
    `ifdef HOST
2564
        repeat(4)
2565
            @(posedge wb_clock) ;
2566
 
2567
        if ( INT_O !== 0 )
2568
        begin
2569
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2570
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2571
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2572
        end
2573
        else
2574
            test_ok ;
2575
    `else
2576
    `ifdef GUEST
2577
        repeat( 4 )
2578
            @(posedge pci_clock) ;
2579
 
2580
        if ( INTA !== 1 )
2581
        begin
2582
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2583
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2584
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2585
        end
2586
        else
2587
            test_ok ;
2588
    `endif
2589
    `endif
2590
 
2591
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2592
    // check PCI status register
2593
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2594
    if ( temp_val1[29] !== 1 )
2595
    begin
2596
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2597
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2598
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2599
    end
2600
    else
2601
        test_ok ;
2602
 
2603
    // clear
2604
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2605
 
2606
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2607
 
2608
    $display("Introducing master abort error to CAB write!") ;
2609
    // now enable error reporting mechanism
2610
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2611
    // enable error interrupts
2612
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2613
 
2614
    // configure flags for CAB transfer
2615
    write_flags`WB_TRANSFER_CAB = 1 ;
2616
    write_flags`WB_TRANSFER_SIZE = 3 ;
2617
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2618
 
2619
    // prepare data for erroneous write
2620
    for ( i = 0 ; i < 3 ; i = i + 1 )
2621
    begin
2622
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2623
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2624
        write_data`WRITE_SEL     = 4'hF ;
2625
        wishbone_master.blk_write_data[i] = write_data ;
2626
    end
2627
 
2628
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2629
    fork
2630
    begin
2631
        wishbone_master.wb_block_write(write_flags, write_status) ;
2632
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2633
        begin
2634
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2635
            $display("Complete burst write through WB slave didn't succeed!") ;
2636
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2637
            disable main ;
2638
        end
2639
    end
2640
    begin
2641
        musnt_respond(ok) ;
2642
        if ( ok !== 1 )
2643
        begin
2644
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2645
            $display("Testbench is configured wrong!") ;
2646
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2647
        end
2648
        else
2649
            test_ok ;
2650
    end
2651
    join
2652
 
2653
    // check error status address, data, byte enables and bus command
2654
    // error status bit is signalled on PCI clock and synchronized to WB clock
2655
    // wait one PCI clock cycle
2656
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2657
    ok = 1 ;
2658
    @(posedge pci_clock) ;
2659
 
2660
    // wait for two WB clocks for synchronization to be finished
2661
    repeat (2)
2662
        @(posedge wb_clock) ;
2663
 
2664
    // read registers
2665
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2666
    if ( temp_val1[8] !== 1 )
2667
    begin
2668
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2669
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2670
        ok = 0 ;
2671
    end
2672
 
2673
    if ( temp_val1[9] !== 1 )
2674
    begin
2675
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2676
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2677
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2678
        ok = 0 ;
2679
    end
2680
 
2681
    if ( temp_val1[31:28] !== 0 )
2682
    begin
2683
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2684
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2685
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2686
        ok = 0 ;
2687
    end
2688
 
2689
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2690
    begin
2691
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2692
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2693
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2694
        ok = 0 ;
2695
    end
2696
 
2697
    // read error address register
2698
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2699
    if ( temp_val1 !== target_address )
2700
    begin
2701
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2702
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2703
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2704
        ok = 0 ;
2705
    end
2706
 
2707
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2708
    if ( temp_val1 !== wmem_data[110] )
2709
    begin
2710
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2711
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2712
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2713
        ok = 0 ;
2714
    end
2715
 
2716
    // check PCI status register
2717
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2718
    if ( temp_val1[29] !== 1 )
2719
    begin
2720
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2721
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2722
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2723
        ok = 0 ;
2724
    end
2725
 
2726
    if ( temp_val1[28] !== 0 )
2727
    begin
2728
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2729
        $display("Received Target Abort bit was set for no reason!") ;
2730
        test_fail("Received Target Abort bit was set for no reason") ;
2731
        ok = 0 ;
2732
    end
2733
 
2734
    if ( ok )
2735
        test_ok ;
2736
 
2737
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2738
 
2739
    // clear error status bit
2740
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2741
 
2742
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2743
 
2744
    ok = 1 ;
2745
 
2746
    `ifdef HOST
2747
        repeat(4)
2748
        @(posedge wb_clock) ;
2749
        if ( INT_O !== 1 )
2750
        begin
2751
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2752
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2753
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2754
            ok = 0 ;
2755
        end
2756
    `else
2757
    `ifdef GUEST
2758
        repeat(4)
2759
        @(posedge pci_clock) ;
2760
        if ( INTA !== 0 )
2761
        begin
2762
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2763
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2764
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2765
            ok = 0 ;
2766
        end
2767
    `endif
2768
    `endif
2769
 
2770
    // read interrupt status register
2771
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2772
    if ( temp_val1 !== 32'h0000_0002 )
2773
    begin
2774
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2775
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2776
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2777
        test_fail("Interrupt Status register returned wrong value") ;
2778
        ok = 0 ;
2779
    end
2780
 
2781
    if ( ok )
2782
        test_ok ;
2783
    // clear interrupt status bits
2784
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2785
 
2786
    ok = 1 ;
2787
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2788
    // wait for two clock cycles before checking interrupt request deassertion
2789
    `ifdef HOST
2790
        repeat (4)
2791
            @(posedge wb_clock) ;
2792
 
2793
        if ( INT_O !== 0 )
2794
        begin
2795
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2796
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2797
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2798
            ok = 0 ;
2799
        end
2800
    `else
2801
    `ifdef GUEST
2802
        repeat (4)
2803
            @(posedge pci_clock) ;
2804
 
2805
        if ( INTA !== 1 )
2806
        begin
2807
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2808
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2809
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2810
            ok = 0 ;
2811
        end
2812
    `endif
2813
    `endif
2814
 
2815
    if ( ok )
2816
        test_ok ;
2817
 
2818
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2819
    ok = 1 ;
2820
    // enable target
2821 45 mihad
    configuration_cycle_write(0,                        // bus number
2822
                              `TAR1_IDSEL_INDEX - 11,   // device number
2823
                              0,                        // function number
2824
                              1,                        // register number
2825
                              0,                        // type of configuration cycle
2826
                              4'b0001,                  // byte enables
2827
                              32'h0000_0007             // data
2828 15 mihad
                             ) ;
2829
    // prepare data for ok write
2830
    for ( i = 0 ; i < 3 ; i = i + 1 )
2831
    begin
2832
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2833
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2834
        write_data`WRITE_SEL     = 4'hF ;
2835
        wishbone_master.blk_write_data[i] = write_data ;
2836
    end
2837
 
2838
    wishbone_master.wb_block_write(write_flags, write_status) ;
2839
 
2840
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2841
    begin
2842
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2843
        $display("Complete burst write through WB slave didn't succeed!") ;
2844
        test_fail("WB Slave state machine failed to post CAB write") ;
2845
        disable main ;
2846
    end
2847
 
2848
    // do a read
2849
    for ( i = 0 ; i < 3 ; i = i + 1 )
2850
    begin
2851
        read_data`READ_ADDRESS = target_address + 4*i ;
2852
        read_data`READ_SEL     = 4'hF ;
2853
        wishbone_master.blk_read_data_in[i] = read_data ;
2854
    end
2855
 
2856
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2857
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2858
    write_flags`WB_TRANSFER_CAB    = 1 ;
2859
 
2860
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2861
 
2862
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2863
    begin
2864
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2865
        $display("Complete burst read through WB slave didn't succeed!") ;
2866
        test_fail("Delayed CAB write was not processed as expected") ;
2867
        disable main ;
2868
    end
2869
 
2870
    for ( i = 0 ; i < 3 ; i = i + 1 )
2871
    begin
2872
        read_status = wishbone_master.blk_read_data_out[i] ;
2873
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2874
        begin
2875
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2876
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2877
        end
2878
    end
2879
 
2880
    $display("Introducing master abort error to single read!") ;
2881
    // disable target
2882 45 mihad
    configuration_cycle_write(0,                        // bus number
2883
                              `TAR1_IDSEL_INDEX - 11,   // device number
2884
                              0,                        // function number
2885
                              1,                        // register number
2886
                              0,                        // type of configuration cycle
2887
                              4'b0001,                  // byte enables
2888
                              32'h0000_0000             // data
2889 15 mihad
                             ) ;
2890
    // set read data
2891
    read_data`READ_ADDRESS = target_address ;
2892
    read_data`READ_SEL     = 4'hF ;
2893
 
2894
    // enable automatic retry handling
2895
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2896
    write_flags`WB_TRANSFER_CAB    = 0 ;
2897
 
2898
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2899
    fork
2900
    begin
2901
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2902
    end
2903
    begin
2904
        musnt_respond(ok) ;
2905
        if ( ok !== 1 )
2906
        begin
2907
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2908
            $display("Testbench is configured wrong!") ;
2909
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2910
        end
2911
    end
2912
    join
2913
 
2914
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2915
    begin
2916
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2917
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2918
        $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) ;
2919
        test_fail("read didn't finish on WB bus as expected") ;
2920
        disable main ;
2921
    end
2922
 
2923
    test_ok ;
2924
 
2925
 
2926
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
2927
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
2928
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2929
    if ( temp_val1[8] !== 0 )
2930
    begin
2931
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2932
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
2933
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
2934
    end
2935
    else
2936
        test_ok ;
2937
 
2938
    // now check normal read operation
2939 45 mihad
    configuration_cycle_write(0,                        // bus number
2940
                              `TAR1_IDSEL_INDEX - 11,   // device number
2941
                              0,                        // function number
2942
                              1,                        // register number
2943
                              0,                        // type of configuration cycle
2944
                              4'b0001,                  // byte enables
2945
                              32'h0000_0007             // data
2946 15 mihad
                             ) ;
2947
 
2948 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
2949 15 mihad
    read_data`READ_ADDRESS = target_address ;
2950
    read_data`READ_SEL     = 4'hF ;
2951
 
2952
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2953
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
2954
    begin
2955
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2956
        $display("WB slave failed to process single read!") ;
2957
        $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) ;
2958
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
2959
        disable main ;
2960
    end
2961
 
2962
    if ( read_status`READ_DATA !== wmem_data[113] )
2963
    begin
2964
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
2965
        test_fail("when read finished on WB bus, wrong data was provided") ;
2966
    end
2967
    else
2968
        test_ok ;
2969
 
2970
    // check PCI status register
2971 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
2972 15 mihad
    ok = 1 ;
2973
 
2974
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2975
    if ( temp_val1[29] !== 1 )
2976
    begin
2977
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2978
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2979
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2980
        ok = 0 ;
2981
    end
2982
 
2983
    if ( temp_val1[28] !== 0 )
2984
    begin
2985
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2986
        $display("Received Target Abort bit was set for no reason!") ;
2987
        test_fail("Received Target Abort bit was set for no reason") ;
2988
        ok = 0 ;
2989
    end
2990
    if ( ok )
2991
        test_ok ;
2992
 
2993
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2994
 
2995
    $display("Introducing master abort error to CAB read!") ;
2996
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
2997
 
2998 45 mihad
    configuration_cycle_write(0,                        // bus number
2999
                              `TAR1_IDSEL_INDEX - 11,   // device number
3000
                              0,                        // function number
3001
                              1,                        // register number
3002
                              0,                        // type of configuration cycle
3003
                              4'b0001,                  // byte enables
3004
                              32'h0000_0000             // data
3005 15 mihad
                             ) ;
3006
 
3007
    for ( i = 0 ; i < 3 ; i = i + 1 )
3008
    begin
3009
        read_data`READ_ADDRESS = target_address + 4*i ;
3010
        read_data`READ_SEL     = 4'hF ;
3011
        wishbone_master.blk_read_data_in[i] = read_data ;
3012
    end
3013
 
3014
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3015
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3016
    write_flags`WB_TRANSFER_CAB    = 1 ;
3017
 
3018
    fork
3019
    begin
3020
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3021
    end
3022
    begin
3023
        musnt_respond(ok) ;
3024
        if ( ok !== 1 )
3025
        begin
3026
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3027
            $display("Testbench is configured wrong!") ;
3028
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3029
        end
3030
    end
3031
    join
3032
 
3033
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3034
    begin
3035
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3036
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3037
        $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) ;
3038
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3039
        disable main ;
3040
    end
3041
    else
3042
        test_ok ;
3043
 
3044
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3045
    ok = 1 ;
3046
    // check PCI status register
3047
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3048
    if ( temp_val1[29] !== 1 )
3049
    begin
3050
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3051
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3052
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3053
        ok = 0 ;
3054
    end
3055
 
3056
    if ( temp_val1[28] !== 0 )
3057
    begin
3058
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3059
        $display("Received Target Abort bit was set for no reason!") ;
3060
        test_fail("Received Target Abort bit was set for no reason") ;
3061
        ok = 0 ;
3062
    end
3063
 
3064
    if ( ok )
3065
        test_ok ;
3066
 
3067
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3068
 
3069
    $display("Introducing target abort termination to single write!") ;
3070
 
3071
    // disable error reporting and interrupts
3072
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3073
 
3074 45 mihad
    configuration_cycle_write(0,                        // bus number
3075
                              `TAR1_IDSEL_INDEX - 11,   // device number
3076
                              0,                        // function number
3077
                              1,                        // register number
3078
                              0,                        // type of configuration cycle
3079
                              4'b0001,                  // byte enables
3080
                              32'h0000_0007             // data
3081 15 mihad
                             ) ;
3082
 
3083
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3084
    if ( ok !== 1 )
3085
    begin
3086
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3087
        test_fail("WB Error Control and Status register couldn't be written to") ;
3088
        disable main ;
3089
    end
3090
 
3091
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3092
    if ( ok !== 1 )
3093
    begin
3094
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3095
        test_fail("Interrupt Control register couldn't be written to") ;
3096
        disable main ;
3097
    end
3098
 
3099
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3100
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3101
 
3102
    write_data`WRITE_ADDRESS = target_address ;
3103
    write_data`WRITE_DATA    = wmem_data[0] ;
3104
    write_data`WRITE_SEL     = 4'hF ;
3105
 
3106
    wishbone_master.blk_write_data[0] = write_data ;
3107
 
3108
    write_data`WRITE_ADDRESS = target_address + 4;
3109
    write_data`WRITE_DATA    = wmem_data[1] ;
3110
    write_data`WRITE_SEL     = 4'hF ;
3111
 
3112
    wishbone_master.blk_write_data[1] = write_data ;
3113
 
3114
    write_flags`WB_TRANSFER_SIZE = 2 ;
3115
 
3116
    // don't handle retries
3117
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3118
    write_flags`WB_TRANSFER_CAB    = 0 ;
3119
 
3120
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3121
    fork
3122
    begin
3123
        wishbone_master.wb_block_write(write_flags, write_status) ;
3124
 
3125
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3126
        begin
3127
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3128
            $display("Image writes were not accepted as expected!") ;
3129
            $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) ;
3130
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3131
            disable main ;
3132
        end
3133
 
3134
        // read data back to see, if it was written OK
3135
        read_data`READ_ADDRESS         = target_address + 4;
3136
        read_data`READ_SEL             = 4'hF ;
3137
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3138
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3139
    end
3140
    begin
3141
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3142
        if ( ok !== 1 )
3143
        begin
3144
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3145
        end
3146
        else
3147
            test_ok ;
3148
 
3149
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3150
 
3151
        // when first transaction finishes - enable normal target response!
3152
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3153
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3154
 
3155
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3156
        if ( ok !== 1 )
3157
        begin
3158
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3159
        end
3160
        else
3161
            test_ok ;
3162
 
3163
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3164
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3165
        if ( ok !== 1 )
3166
        begin
3167
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3168
        end
3169
    end
3170
    join
3171
 
3172
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3173
    begin
3174
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3175
        $display("Bridge failed to process single read after target abort terminated write!") ;
3176
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3177
        disable main ;
3178
    end
3179
 
3180
    if ( read_status`READ_DATA !== wmem_data[1] )
3181
    begin
3182
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3183
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3184
    end
3185
    else
3186
        test_ok ;
3187
 
3188
    // check interrupt and error statuses!
3189
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3190
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3191
    if ( temp_val1[8] !== 0 )
3192
    begin
3193
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3194
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3195
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3196
    end
3197
    else
3198
        test_ok ;
3199
 
3200
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3201
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3202
    if ( temp_val1[1] !== 0 )
3203
    begin
3204
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3205
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3206
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3207
    end
3208
    else
3209
        test_ok ;
3210
 
3211
    // check PCI status register
3212
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3213
    ok = 1 ;
3214
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3215
    if ( temp_val1[29] !== 0 )
3216
    begin
3217
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3218
        $display("Received Master Abort bit was set with no reason!") ;
3219
        test_fail("Received Master Abort bit was set with no reason") ;
3220
        ok = 0 ;
3221
    end
3222
 
3223
    if ( temp_val1[28] !== 1 )
3224
    begin
3225
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3226
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3227
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3228
        ok = 0 ;
3229
    end
3230
 
3231
    if ( ok )
3232
        test_ok ;
3233
 
3234
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3235
 
3236
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3237
 
3238
    $display("Introducing target abort termination to CAB write!") ;
3239
    // enable error reporting mechanism
3240
 
3241
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3242
    if ( ok !== 1 )
3243
    begin
3244
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3245
        test_fail("WB Error Control and Status register could not be written to") ;
3246
        disable main ;
3247
    end
3248
 
3249
    for ( i = 0 ; i < 3 ; i = i + 1 )
3250
    begin
3251
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3252
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3253
        write_data`WRITE_SEL     = 4'b1010 ;
3254
        wishbone_master.blk_write_data[i] = write_data ;
3255
    end
3256
 
3257
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3258
    write_flags`WB_TRANSFER_CAB    = 1 ;
3259
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3260
 
3261
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3262
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3263
 
3264
    fork
3265
    begin
3266
        wishbone_master.wb_block_write(write_flags, write_status) ;
3267
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3268
        begin
3269
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3270
            $display("Bridge failed to process complete CAB write!") ;
3271
            test_fail("bridge failed to post CAB Memory Write") ;
3272
            disable main ;
3273
        end
3274
    end
3275
    begin
3276
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3277
        if ( ok !== 1 )
3278
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3279
        else
3280
            test_ok ;
3281
    end
3282
    join
3283
 
3284
    // check statuses and data from error
3285
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3286
    ok = 1 ;
3287
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3288
    if ( temp_val1[8] !== 1 )
3289
    begin
3290
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3291
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3292
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3293
        ok = 0 ;
3294
    end
3295
 
3296
    if ( temp_val1[9] !== 0 )
3297
    begin
3298
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3299
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3300
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3301
        ok = 0 ;
3302
    end
3303
 
3304
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3305
    begin
3306
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3307
        $display("Value in W_ERR_CS register was wrong!") ;
3308
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3309
        test_fail("BE Field didn't provided expected value") ;
3310
        ok = 0 ;
3311
    end
3312
 
3313
    if ( ok )
3314
        test_ok ;
3315
 
3316
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3317
    ok = 1 ;
3318
    // check erroneous address and data
3319
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3320
    if ( temp_val1 !== (target_address + 8) )
3321
    begin
3322
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3323
        $display("Value in W_ERR_ADDR register was wrong!") ;
3324
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3325
        test_fail("Value in WB Erroneous Address register was wrong") ;
3326
        ok = 0 ;
3327
    end
3328
 
3329
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3330
    if ( temp_val1 !== wmem_data[120] )
3331
    begin
3332
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3333
        $display("Value in W_ERR_DATA register was wrong!") ;
3334
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3335
        test_fail("Value in WB Erroneous Data register was wrong") ;
3336
        ok = 0 ;
3337
    end
3338
 
3339
    if ( ok )
3340
        test_ok ;
3341
 
3342
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3343
    ok = 1 ;
3344
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3345
    if ( temp_val1[29] !== 0 )
3346
    begin
3347
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3348
        $display("Received Master Abort bit was set with no reason!") ;
3349
        test_fail("Received Master Abort bit was set for no reason") ;
3350
        ok = 0 ;
3351
    end
3352
 
3353
    if ( temp_val1[28] !== 1 )
3354
    begin
3355
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3356
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3357
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3358
        ok = 0 ;
3359
    end
3360
 
3361
    if ( ok )
3362
        test_ok ;
3363
 
3364
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3365
 
3366
    // clear error status bit and enable error interrupts
3367
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3368
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3369
 
3370
    // check if error bit was cleared
3371
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3372
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3373
    if ( temp_val1[8] !== 0 )
3374
    begin
3375
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3376
        $display("Error bit was not cleared even though one was written to its location!") ;
3377
        test_fail("Error bit was not cleared even though one was written to its location") ;
3378
    end
3379
 
3380
    // repeat same write with different target configuration
3381
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3382
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3383
 
3384
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3385
    fork
3386
    begin
3387
        write_flags`WB_TRANSFER_SIZE = 2 ;
3388
        wishbone_master.wb_block_write(write_flags, write_status) ;
3389
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3390
        begin
3391
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3392
            $display("Bridge failed to process complete CAB write!") ;
3393
            test_fail("bridge failed to post CAB Memory Write") ;
3394
            disable main ;
3395
        end
3396
 
3397
        write_flags`WB_TRANSFER_SIZE = 3 ;
3398
        wishbone_master.wb_block_write(write_flags, write_status) ;
3399
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3400
        begin
3401
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3402
            $display("Bridge failed to process complete CAB write!") ;
3403
            test_fail("bridge failed to post CAB Memory Write") ;
3404
            disable main ;
3405
        end
3406
    end
3407
    begin
3408
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3409
        if ( ok !== 1 )
3410
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3411
        else
3412
        begin
3413
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3414
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3415
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3416
            if ( ok !== 1 )
3417
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3418
            else
3419
                test_ok ;
3420
        end
3421
    end
3422
    join
3423
 
3424
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3425
    ok = 1 ;
3426
    // check statuses and data from error
3427
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3428
    if ( temp_val1[8] !== 1 )
3429
    begin
3430
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3431
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3432
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3433
        ok = 0 ;
3434
    end
3435
 
3436
    if ( temp_val1[9] !== 0 )
3437
    begin
3438
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3439
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3440
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3441
        ok = 0 ;
3442
    end
3443
 
3444
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3445
    begin
3446
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3447
        $display("Value in W_ERR_CS register was wrong!") ;
3448
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3449
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3450
        ok = 0 ;
3451
    end
3452
 
3453
    if ( ok )
3454
        test_ok ;
3455
 
3456
    // check erroneous address and data
3457
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3458
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3459
    ok = 1 ;
3460
    if ( temp_val1 !== (target_address + 8 + 4) )
3461
    begin
3462
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3463
        $display("Value in W_ERR_ADDR register was wrong!") ;
3464
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3465
        test_fail("Value in WB Erroneous Address register was wrong") ;
3466
        ok = 0 ;
3467
 
3468
    end
3469
 
3470
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3471
    if ( temp_val1 !== wmem_data[121] )
3472
    begin
3473
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3474
        $display("Value in W_ERR_DATA register was wrong!") ;
3475
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3476
        test_fail("Value in WB Erroneous Data register was wrong") ;
3477
        ok = 0 ;
3478
    end
3479
 
3480
    if ( ok )
3481
        test_ok ;
3482
 
3483
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3484
    `ifdef HOST
3485
        repeat(4)
3486
            @(posedge wb_clock) ;
3487
        if ( INT_O !== 1 )
3488
        begin
3489
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3490
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3491
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3492
        end
3493
        else
3494
            test_ok ;
3495
    `else
3496
    `ifdef GUEST
3497
        repeat(4)
3498
            @(posedge pci_clock) ;
3499
        if ( INTA !== 0 )
3500
        begin
3501
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3502
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3503
            test_fail("interrupt request was not presented on PCI bus") ;
3504
        end
3505
        else
3506
            test_ok ;
3507
    `endif
3508
    `endif
3509
 
3510
    // read interrupt status register
3511
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3512
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3513
    if ( temp_val1[1] !== 1 )
3514
    begin
3515
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3516
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3517
        test_fail("Expected Interrupt status bit wasn't set") ;
3518
    end
3519
 
3520
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3521
 
3522
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3523
    ok = 1 ;
3524
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3525
    if ( temp_val1[29] !== 0 )
3526
    begin
3527
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3528
        $display("Received Master Abort bit was set with no reason!") ;
3529
        test_fail("Received Master Abort bit was set with no reason") ;
3530
        ok = 0 ;
3531
    end
3532
 
3533
    if ( temp_val1[28] !== 1 )
3534
    begin
3535
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3536
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3537
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3538
        ok = 0 ;
3539
    end
3540
 
3541
    if ( ok )
3542
        test_ok ;
3543
 
3544
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3545
 
3546
    // clear interrupts and errors
3547
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3548
    repeat( 3 )
3549
        @(posedge pci_clock) ;
3550
 
3551
    repeat( 2 )
3552
        @(posedge wb_clock) ;
3553
 
3554
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3555
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3556
    if ( temp_val1[1] !== 0 )
3557
    begin
3558
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3559
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3560
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3561
    end
3562
    else
3563
        test_ok ;
3564
 
3565
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3566
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3567
    if ( temp_val1[8] !== 0 )
3568
    begin
3569
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3570
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3571
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3572
    end
3573
 
3574
 
3575
    $display("Introducing Target Abort error to single read!") ;
3576
    // set read data
3577
    read_data`READ_ADDRESS = target_address + 8 ;
3578
    read_data`READ_SEL     = 4'hF ;
3579
 
3580
    // enable automatic retry handling
3581
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3582
    write_flags`WB_TRANSFER_CAB    = 0 ;
3583
 
3584
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3585
 
3586
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3587
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3588
 
3589
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3590
 
3591
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3592
    begin
3593
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3594
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3595
        $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) ;
3596
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3597
        disable main ;
3598
    end
3599
    else
3600
        test_ok ;
3601
 
3602
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3603
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3604
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3605
    if ( temp_val1[8] !== 0 )
3606
    begin
3607
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3608
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3609
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3610
    end
3611
    else
3612
        test_ok ;
3613
 
3614
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3615
    ok = 1 ;
3616
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3617
    if ( temp_val1[29] !== 0 )
3618
    begin
3619
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3620
        $display("Received Master Abort bit was set with no reason!") ;
3621
        test_fail("Received Master Abort bit was set with no reason") ;
3622
        ok = 0 ;
3623
    end
3624
 
3625
    if ( temp_val1[28] !== 1 )
3626
    begin
3627
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3628
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3629
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3630
        ok = 0 ;
3631
    end
3632
 
3633
    if ( ok )
3634
        test_ok ;
3635
 
3636
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3637
 
3638
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3639
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3640
    if ( temp_val1[1] !== 0 )
3641
    begin
3642
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3643
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3644
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3645
    end
3646
    else
3647
        test_ok ;
3648
 
3649
    $display("Introducing Target Abort error to CAB read!") ;
3650
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3651
 
3652
    for ( i = 0 ; i < 4 ; i = i + 1 )
3653
    begin
3654
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3655
        read_data`READ_SEL     = 4'b1010 ;
3656
        wishbone_master.blk_read_data_in[i] = read_data ;
3657
    end
3658
 
3659
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3660
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3661
    write_flags`WB_TRANSFER_CAB    = 1 ;
3662
 
3663
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3664
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3665
 
3666
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3667
 
3668
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3669
    begin
3670
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3671
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3672
        $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) ;
3673
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3674
        disable main ;
3675
    end
3676
 
3677
    read_status = wishbone_master.blk_read_data_out[0] ;
3678
    temp_val1 = read_status`READ_DATA ;
3679
    temp_val2 = wmem_data[120] ;
3680
 
3681
    // last write to this address was with only two byte enables - check only those
3682
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3683
    begin
3684
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3685
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3686
    end
3687
    else
3688
        test_ok ;
3689
 
3690
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3691
    ok = 1 ;
3692
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3693
    if ( temp_val1[29] !== 0 )
3694
    begin
3695
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3696
        $display("Received Master Abort bit was set with no reason!") ;
3697
        test_fail("Received Master Abort bit was set with no reason") ;
3698
        ok = 0 ;
3699
    end
3700
 
3701
    if ( temp_val1[28] !== 1 )
3702
    begin
3703
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3704
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3705
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3706
        ok = 0 ;
3707
    end
3708
 
3709
    if ( ok )
3710
       test_ok ;
3711
 
3712
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3713
 
3714
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3715
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3716
 
3717
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3718
    for ( i = 0 ; i < 3 ; i = i + 1 )
3719
    begin
3720
        read_data`READ_ADDRESS = target_address + 4*i ;
3721
        read_data`READ_SEL     = 4'b1111 ;
3722
        wishbone_master.blk_read_data_in[i] = read_data ;
3723
    end
3724
 
3725
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3726
 
3727
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3728
 
3729
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3730
    begin
3731
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3732
        $display("Complete burst read through WB slave didn't succeed!") ;
3733
        test_fail("bridge didn't process Burst Read in an expected way") ;
3734
        disable main ;
3735
    end
3736
    else
3737
        test_ok ;
3738
 
3739
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3740
 
3741
    for ( i = 0 ; i < 3 ; i = i + 1 )
3742
    begin
3743
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3744
        read_data`READ_SEL     = 4'b1111 ;
3745
        wishbone_master.blk_read_data_in[i] = read_data ;
3746
    end
3747
 
3748
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3749
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3750
    write_flags`WB_TRANSFER_CAB    = 1 ;
3751
 
3752
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3753
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3754
 
3755
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3756
 
3757
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3758
    begin
3759
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3760
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3761
        $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) ;
3762
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3763
        disable main ;
3764
    end
3765
 
3766
    for ( i = 0 ; i < 3 ; i = i + 1 )
3767
    begin
3768
        ok = 1 ;
3769
        read_status = wishbone_master.blk_read_data_out[i] ;
3770
        temp_val1 = read_status`READ_DATA ;
3771
        temp_val2 = wmem_data[120 + i] ;
3772
 
3773
        // last write to this address was with only two byte enables - check only those
3774
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3775
        begin
3776
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3777
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3778
            ok = 0 ;
3779
        end
3780
    end
3781
 
3782
    if ( ok )
3783
        test_ok ;
3784
 
3785
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3786
    ok = 1 ;
3787
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3788
    if ( temp_val1[29] !== 0 )
3789
    begin
3790
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3791
        $display("Received Master Abort bit was set with no reason!") ;
3792
        test_fail("Received Master Abort bit was set with no reason") ;
3793
        ok = 0 ;
3794
    end
3795
 
3796
    if ( temp_val1[28] !== 1 )
3797
    begin
3798
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3799
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3800
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3801
        ok = 0 ;
3802
    end
3803
 
3804
    if ( ok )
3805
       test_ok ;
3806
 
3807
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3808
 
3809
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3810
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3811
 
3812
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3813
    for ( i = 0 ; i < 3 ; i = i + 1 )
3814
    begin
3815
        read_data`READ_ADDRESS = target_address + 4*i ;
3816
        read_data`READ_SEL     = 4'b1111 ;
3817
        wishbone_master.blk_read_data_in[i] = read_data ;
3818
    end
3819
 
3820
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3821
 
3822
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3823
 
3824
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3825
    begin
3826
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3827
        $display("Complete burst read through WB slave didn't succeed!") ;
3828
        test_fail("bridge didn't process Burst Read in an expected way") ;
3829
        disable main ;
3830
    end
3831
    else
3832
        test_ok ;
3833
 
3834
    // test error on IO write
3835
    // change base address
3836
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3837
    write_data`WRITE_SEL     = 4'b0101 ;
3838
    write_data`WRITE_ADDRESS = target_address ;
3839
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3840
 
3841
    write_flags`WB_TRANSFER_CAB    = 0 ;
3842
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3843
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3844
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3845
    fork
3846
    begin
3847
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3848
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3849
        begin
3850
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3851
            $display("WB slave failed to accept IO write!") ;
3852
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3853
            disable main ;
3854
        end
3855
    end
3856
    begin
3857
        musnt_respond(ok) ;
3858
        if ( ok !== 1 )
3859
        begin
3860
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3861
            $display("Testbench is configured wrong!") ;
3862
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3863
        end
3864
        else
3865
            test_ok ;
3866
    end
3867
    join
3868
 
3869
    // check statuses and everything else
3870
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3871
    ok = 1 ;
3872
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3873
    if ( temp_val1[8] !== 1 )
3874
    begin
3875
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3876
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3877
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3878
        ok = 0 ;
3879
    end
3880
 
3881
    if ( temp_val1[9] !== 1 )
3882
    begin
3883
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3884
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3885
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3886
        ok = 0 ;
3887
    end
3888
 
3889
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3890
    begin
3891
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3892
        $display("Value in W_ERR_CS register was wrong!") ;
3893
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3894
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3895
        ok = 0 ;
3896
    end
3897
 
3898
    if ( ok )
3899
        test_ok ;
3900
 
3901
    // check erroneous address and data
3902
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3903
    ok = 1 ;
3904
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3905
    if ( temp_val1 !== target_address )
3906
    begin
3907
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3908
        $display("Value in W_ERR_ADDR register was wrong!") ;
3909
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
3910
        test_fail("WB Erroneous Address register didn't provide right value") ;
3911
        ok = 0 ;
3912
    end
3913
 
3914
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3915
    if ( temp_val1 !== 32'hAAAA_AAAA )
3916
    begin
3917
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3918
        $display("Value in W_ERR_DATA register was wrong!") ;
3919
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
3920
        test_fail("WB Erroneous Data register didn't provide right value") ;
3921
        ok = 0 ;
3922
    end
3923
 
3924
    if ( ok )
3925
        test_ok ;
3926
 
3927
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3928
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3929
    if ( temp_val1[1] !== 1 )
3930
    begin
3931
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3932
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3933
        test_fail("expected interrupt status bit was not set") ;
3934
    end
3935
    else
3936
        test_ok ;
3937
 
3938
    // clear interrupts and errors
3939
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3940
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3941
 
3942
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3943
    ok = 1 ;
3944
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3945
    if ( temp_val1[29] !== 1 )
3946
    begin
3947
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3948
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
3949
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
3950
        ok = 0 ;
3951
    end
3952
 
3953
    if ( temp_val1[28] !== 0 )
3954
    begin
3955
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3956
        $display("Received Target Abort bit was set for no reason!") ;
3957
        test_fail("Received Target Abort bit was set for no reason") ;
3958
        ok = 0 ;
3959
    end
3960
 
3961
    if ( ok )
3962
        test_ok ;
3963
 
3964
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3965
 
3966
    // disable image
3967
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
3968
    if ( ok !== 1 )
3969
    begin
3970
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3971
        test_fail("WB Image Address Mask register couldn't be written") ;
3972
        disable main ;
3973
    end
3974
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
3975
 
3976
end
3977
endtask
3978
 
3979
task parity_checking ;
3980
    reg   [11:0] ctrl_offset ;
3981
    reg   [11:0] ba_offset ;
3982
    reg   [11:0] am_offset ;
3983
    reg   [11:0] ta_offset ;
3984
    reg `WRITE_STIM_TYPE write_data ;
3985
    reg `READ_STIM_TYPE  read_data ;
3986
    reg `READ_RETURN_TYPE read_status ;
3987
 
3988
    reg `WRITE_RETURN_TYPE write_status ;
3989
    reg `WB_TRANSFER_FLAGS write_flags ;
3990
    reg [31:0] temp_val1 ;
3991
    reg [31:0] temp_val2 ;
3992
    reg        ok   ;
3993
    reg [11:0] pci_ctrl_offset ;
3994
    reg [31:0] image_base ;
3995
    reg [31:0] target_address ;
3996
    reg [11:0] icr_offset ;
3997
    reg [11:0] isr_offset ;
3998
    reg [11:0] p_ba_offset ;
3999
    reg [11:0] p_am_offset ;
4000
    reg [11:0] p_ctrl_offset ;
4001
    integer    i ;
4002
    reg        perr_asserted ;
4003
begin:main
4004
    $display("******************************* Testing Parity Checker functions ********************************") ;
4005
    $display("Testing Parity Errors during Master Transactions!") ;
4006
    $display("Introducing Parity Erros to Master Writes!") ;
4007
    $fdisplay(pci_mon_log_file_desc,
4008
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4009
 
4010
    // image 1 is used for error testing, since it is always implemented
4011
    pci_ctrl_offset = 12'h004 ;
4012
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4013
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4014
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4015
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4016
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4017
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4018
 
4019
    // image 1 for PCI target
4020
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4021
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4022
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4023
 
4024
    target_address  = `BEH_TAR1_MEM_START ;
4025
    image_base      = 0 ;
4026
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4027
 
4028
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4029
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4030
    write_flags                    = 0 ;
4031
    write_flags`INIT_WAITS         = tb_init_waits ;
4032
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
4033
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4034
 
4035
    // enable master & target operation and disable parity functions
4036
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4037
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4038
    if ( ok !== 1 )
4039
    begin
4040
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4041
        test_fail("PCI Device Control register could not be written to") ;
4042
        disable main ;
4043
    end
4044
 
4045
    // prepare image control register
4046
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4047
    if ( ok !== 1 )
4048
    begin
4049
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4050
        test_fail("WB Image Control register could not be written to") ;
4051
        disable main ;
4052
    end
4053
 
4054
    // prepare base address register
4055
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4056
    if ( ok !== 1 )
4057
    begin
4058
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4059
        test_fail("WB Image Base Address register could not be written to") ;
4060
        disable main ;
4061
    end
4062
 
4063
    // write address mask register
4064
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4065
    if ( ok !== 1 )
4066
    begin
4067
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4068
        test_fail("WB Image Address Mask register could not be written to") ;
4069
        disable main ;
4070
    end
4071
 
4072
    // disable parity interrupts
4073
    config_write( icr_offset, 0, 4'hF, ok ) ;
4074
    if ( ok !== 1 )
4075
    begin
4076
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4077
        test_fail("Interrupt Control register could not be written to") ;
4078
        disable main ;
4079
    end
4080
 
4081
    write_data`WRITE_ADDRESS = target_address ;
4082
    write_data`WRITE_DATA    = wmem_data[0] ;
4083
    write_data`WRITE_SEL     = 4'b1111 ;
4084
 
4085
    // enable target's 1 response to parity errors
4086 45 mihad
    configuration_cycle_write(0,                        // bus number
4087
                              `TAR1_IDSEL_INDEX - 11,   // device number
4088
                              0,                        // function number
4089
                              1,                        // register number
4090
                              0,                        // type of configuration cycle
4091
                              4'b0001,                  // byte enables
4092
                              32'h0000_0047             // data
4093 15 mihad
                             ) ;
4094
 
4095
    // disable target's 2 response to parity errors
4096 45 mihad
    configuration_cycle_write(0,                        // bus number
4097
                              `TAR2_IDSEL_INDEX - 11,   // device number
4098
                              0,                        // function number
4099
                              1,                        // register number
4100
                              0,                        // type of configuration cycle
4101
                              4'b0001,                  // byte enables
4102
                              32'h0000_0007             // data
4103 15 mihad
                             ) ;
4104
 
4105
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4106
 
4107
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4108
    fork
4109
    begin
4110
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4111
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4112
        begin
4113
            $display("Parity checker testing failed! Time %t ", $time) ;
4114
            $display("Bridge failed to process single memory write!") ;
4115
            test_fail("bridge failed to post single WB memory write") ;
4116
            disable main ;
4117
        end
4118
    end
4119
    begin:wait_perr1
4120
        perr_asserted = 0 ;
4121
        @(posedge pci_clock) ;
4122
 
4123 35 mihad
        while ( PERR !== 0 )
4124 15 mihad
            @(posedge pci_clock) ;
4125
 
4126 35 mihad
        perr_asserted = 1 ;
4127 15 mihad
 
4128
    end
4129
    begin
4130
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4131
 
4132
        if ( ok !== 1 )
4133
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4134
 
4135 35 mihad
        repeat(2)
4136 15 mihad
            @(posedge pci_clock) ;
4137
 
4138 35 mihad
        #1 ;
4139
        if ( !perr_asserted )
4140
            disable wait_perr1 ;
4141 15 mihad
    end
4142
    join
4143
 
4144
    if ( perr_asserted && ok )
4145
    begin
4146
        test_ok ;
4147
    end
4148
    else
4149
    if ( ~perr_asserted )
4150
    begin
4151
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4152
        disable main ;
4153
    end
4154
 
4155
    // check all the statuses - if HOST is defined, wait for them to be synced
4156
    `ifdef HOST
4157
    repeat(4)
4158
        @(posedge wb_clock) ;
4159
    `endif
4160
 
4161
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4162
    ok = 1 ;
4163
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4164 45 mihad
    if ( temp_val1[31] !== 0 )
4165 15 mihad
    begin
4166
        $display("Parity checker testing failed! Time %t ", $time) ;
4167 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4168
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4169 15 mihad
        ok = 0 ;
4170
    end
4171
 
4172
    if ( temp_val1[30] !== 0 )
4173
    begin
4174
        $display("Parity checker testing failed! Time %t ", $time) ;
4175
        $display("Signalled System Error bit was set for no reason!") ;
4176
        test_fail("Signalled System Error bit was set for no reason") ;
4177
        ok = 0 ;
4178
    end
4179
 
4180
    if ( temp_val1[24] !== 0 )
4181
    begin
4182
        $display("Parity checker testing failed! Time %t ", $time) ;
4183
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4184
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4185
        ok = 0 ;
4186
    end
4187
 
4188
    if ( ok )
4189
        test_ok ;
4190
 
4191
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4192
    // clear parity bits and enable parity response
4193
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4194
    if ( ok !== 1 )
4195
    begin
4196
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4197
        test_fail("write to PCI Status Register failed") ;
4198
        disable main ;
4199
    end
4200
 
4201
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4202
    fork
4203
    begin
4204
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4205
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4206
        begin
4207
            $display("Parity checker testing failed! Time %t ", $time) ;
4208
            $display("Bridge failed to process single memory write!") ;
4209
            test_fail("bridge failed to post single memory write") ;
4210
            disable main ;
4211
        end
4212
    end
4213
    begin:wait_perr2
4214
        perr_asserted = 0 ;
4215
        @(posedge pci_clock) ;
4216
 
4217 35 mihad
        while ( PERR !== 0 )
4218 15 mihad
            @(posedge pci_clock) ;
4219
 
4220 35 mihad
        perr_asserted = 1 ;
4221 15 mihad
 
4222
    end
4223
    begin
4224
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4225
 
4226
        if ( ok !== 1 )
4227
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4228
 
4229 35 mihad
        repeat(2)
4230 15 mihad
            @(posedge pci_clock) ;
4231
 
4232 35 mihad
        #1 ;
4233
        if (!perr_asserted)
4234
            disable wait_perr2 ;
4235 15 mihad
    end
4236
    join
4237
 
4238
    if ( perr_asserted && ok )
4239
    begin
4240
        test_ok ;
4241
    end
4242
    else
4243
    if ( ~perr_asserted )
4244
    begin
4245
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4246
        disable main ;
4247
    end
4248
 
4249
    // check all the statuses - if HOST is defined, wait for them to be synced
4250
    `ifdef HOST
4251
    repeat(4)
4252
        @(posedge wb_clock) ;
4253
    `endif
4254
 
4255
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4256
    ok = 1 ;
4257
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4258 45 mihad
    if ( temp_val1[31] !== 0 )
4259 15 mihad
    begin
4260
        $display("Parity checker testing failed! Time %t ", $time) ;
4261 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4262
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4263 15 mihad
        ok = 0 ;
4264
    end
4265
 
4266
    if ( temp_val1[30] !== 0 )
4267
    begin
4268
        $display("Parity checker testing failed! Time %t ", $time) ;
4269
        $display("Signalled System Error bit was set for no reason!") ;
4270
        test_fail("Signalled System Error bit was set for no reason") ;
4271
        ok = 0 ;
4272
    end
4273
 
4274
    if ( temp_val1[24] !== 1 )
4275
    begin
4276
        $display("Parity checker testing failed! Time %t ", $time) ;
4277 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!") ;
4278
        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") ;
4279 15 mihad
        ok = 0 ;
4280
    end
4281
 
4282
    if ( ok )
4283
        test_ok ;
4284
 
4285
    // clear status bits and disable parity error response
4286
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4287
 
4288
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4289
 
4290
    // disable perr generation and perform a write - no bits should be set
4291
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4292
    fork
4293
    begin
4294
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4295
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4296
        begin
4297
            $display("Parity checker testing failed! Time %t ", $time) ;
4298
            $display("Bridge failed to process single memory write!") ;
4299
            test_fail("bridge failed to post single memory write") ;
4300
            disable main ;
4301
        end
4302
    end
4303
    begin
4304
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4305
 
4306
        if ( ok !== 1 )
4307
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4308
        else
4309
            test_ok ;
4310
 
4311
        repeat(3)
4312
            @(posedge pci_clock) ;
4313
    end
4314
    join
4315
 
4316
    `ifdef HOST
4317
    repeat(4)
4318
        @(posedge wb_clock) ;
4319
    `endif
4320
 
4321
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4322
    ok = 1 ;
4323
 
4324
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4325
    if ( temp_val1[31] !== 0 )
4326
    begin
4327
        $display("Parity checker testing failed! Time %t ", $time) ;
4328
        $display("Detected Parity Error bit was set for no reason!") ;
4329
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4330
        ok = 0 ;
4331
    end
4332
 
4333
    if ( temp_val1[30] !== 0 )
4334
    begin
4335
        $display("Parity checker testing failed! Time %t ", $time) ;
4336
        $display("Signalled System Error bit was set for no reason!") ;
4337
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4338
        ok = 0 ;
4339
    end
4340
 
4341
    if ( temp_val1[24] !== 0 )
4342
    begin
4343
        $display("Parity checker testing failed! Time %t ", $time) ;
4344
        $display("Master Data Parity Error bit was set for no reason!") ;
4345
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4346
        ok = 0 ;
4347
    end
4348
 
4349
    if ( ok )
4350
        test_ok ;
4351
 
4352
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4353
 
4354
    read_data = 0 ;
4355
    read_data`READ_ADDRESS  = target_address ;
4356
    read_data`READ_SEL      = 4'hF ;
4357
    read_data`READ_TAG_STIM = 0 ;
4358
 
4359
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4360
 
4361
    // enable parity and system error interrupts
4362
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4363
 
4364
    // enable parity error response
4365
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4366
 
4367
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4368
 
4369
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4370
    fork
4371
    begin
4372
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4373
    end
4374
    begin:wait_perr4
4375
        perr_asserted = 0 ;
4376
        @(posedge pci_clock) ;
4377 35 mihad
        while ( PERR !== 0 )
4378 15 mihad
            @(posedge pci_clock) ;
4379
 
4380 35 mihad
        perr_asserted = 1 ;
4381 15 mihad
 
4382
    end
4383
    begin
4384
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4385
 
4386
        if ( ok !== 1 )
4387
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4388
 
4389
        repeat(2)
4390
            @(posedge pci_clock) ;
4391
 
4392 35 mihad
        #1 ;
4393
        if ( !perr_asserted )
4394
            disable wait_perr4 ;
4395 15 mihad
    end
4396
    join
4397
 
4398
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4399
    begin
4400
        $display("Parity checker testing failed! Time %t ", $time) ;
4401
        $display("Bridge failed to process single memory read!") ;
4402
        test_fail("bridge didn't process single memory read correctly") ;
4403
        ok = 0 ;
4404
    end
4405
 
4406
    if ( perr_asserted && ok )
4407
    begin
4408
        test_ok ;
4409
    end
4410
    else
4411
    if ( ~perr_asserted )
4412
    begin
4413
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4414
        disable main ;
4415
    end
4416
 
4417
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4418
    // interrupt should also be present
4419
    `ifdef HOST
4420
        repeat(4)
4421 26 mihad
            @(posedge pci_clock) ;
4422
        repeat(4)
4423 15 mihad
            @(posedge wb_clock) ;
4424
 
4425
        if ( INT_O !== 1 )
4426
        begin
4427
            $display("Parity checker testing failed! Time %t ", $time) ;
4428
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4429
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4430
        end
4431
        else
4432
            test_ok ;
4433
    `else
4434
    `ifdef GUEST
4435 26 mihad
        repeat(4)
4436
            @(posedge wb_clock) ;
4437
        repeat(4)
4438 15 mihad
            @(posedge pci_clock) ;
4439
 
4440
        if ( INTA !== 1 )
4441
        begin
4442
            $display("Parity checker testing failed! Time %t ", $time) ;
4443
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4444
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4445
        end
4446
        else
4447
            test_ok ;
4448
    `endif
4449
    `endif
4450
 
4451
    // check statuses!
4452
 
4453
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4454
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4455
    ok = 1 ;
4456
 
4457
    if ( temp_val1[31] !== 1 )
4458
    begin
4459
        $display("Parity checker testing failed! Time %t ", $time) ;
4460 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4461
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4462 15 mihad
        ok = 0 ;
4463
    end
4464
 
4465
    if ( temp_val1[30] !== 0 )
4466
    begin
4467
        $display("Parity checker testing failed! Time %t ", $time) ;
4468
        $display("Signalled System Error bit was set for no reason!") ;
4469
        test_fail("Signalled System Error bit was set for no reason") ;
4470
        ok = 0 ;
4471
    end
4472
 
4473
    if ( temp_val1[24] !== 1 )
4474
    begin
4475
        $display("Parity checker testing failed! Time %t ", $time) ;
4476 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4477
        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") ;
4478 15 mihad
        ok = 0 ;
4479
    end
4480
 
4481
    if ( ok )
4482
        test_ok ;
4483
 
4484
    // clear statuses and disable parity error response
4485
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4486
 
4487
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4488
    ok = 1 ;
4489
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4490
 
4491
    if ( temp_val1[4] !== 0 )
4492
    begin
4493
        $display("Parity checker testing failed! Time %t ", $time) ;
4494
        $display("System error interrupt status bit set for no reason!") ;
4495
        test_fail("System error interrupt status bit set for no reason") ;
4496
        ok = 0 ;
4497
    end
4498
 
4499
    `ifdef HOST
4500
    if ( temp_val1[3] !== 1 )
4501
    begin
4502
        $display("Parity checker testing failed! Time %t ", $time) ;
4503
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4504
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4505
        ok = 0 ;
4506
    end
4507
    `else
4508
    if ( temp_val1[3] !== 0 )
4509
    begin
4510
        $display("Parity checker testing failed! Time %t ", $time) ;
4511
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4512
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4513
        ok = 0 ;
4514
    end
4515
    `endif
4516
 
4517
    if ( ok )
4518
        test_ok ;
4519
 
4520
    // clear int statuses
4521
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4522
 
4523
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4524
 
4525
    `ifdef HOST
4526
        repeat(4)
4527 26 mihad
            @(posedge pci_clock) ;
4528
        repeat(4)
4529 15 mihad
            @(posedge wb_clock) ;
4530
 
4531
        if ( INT_O !== 0 )
4532
        begin
4533
            $display("Parity checker testing failed! Time %t ", $time) ;
4534
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4535
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4536
        end
4537
        else
4538
            test_ok ;
4539
    `else
4540
    `ifdef GUEST
4541 26 mihad
        repeat(4)
4542
            @(posedge wb_clock) ;
4543
        repeat(4)
4544 15 mihad
            @(posedge pci_clock) ;
4545
 
4546
        if ( INTA !== 1 )
4547
        begin
4548
            $display("Parity checker testing failed! Time %t ", $time) ;
4549
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4550
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4551
        end
4552
        else
4553
            test_ok ;
4554
    `endif
4555
    `endif
4556
 
4557
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4558
 
4559
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4560
    fork
4561
    begin
4562
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4563
    end
4564
    begin:wait_perr5
4565
        perr_asserted = 0 ;
4566
        @(posedge pci_clock) ;
4567
        while ( PERR === 1 )
4568
            @(posedge pci_clock) ;
4569
 
4570
        perr_asserted = 1 ;
4571
        $display("Parity checker testing failed! Time %t ", $time) ;
4572 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4573
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4574 15 mihad
    end
4575
    begin
4576
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4577
        if ( ok !== 1 )
4578
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4579
 
4580
        // perr can be asserted on idle or next PCI address phase
4581
        repeat(2)
4582
            @(posedge pci_clock) ;
4583
 
4584 35 mihad
        #1 ;
4585
        if ( !perr_asserted )
4586
            disable wait_perr5 ;
4587 15 mihad
    end
4588
    join
4589
 
4590
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4591
    begin
4592
        $display("Parity checker testing failed! Time %t ", $time) ;
4593
        $display("Bridge failed to process single memory read!") ;
4594
        test_fail("bridge failed to process single memory read correctly") ;
4595
        ok = 0 ;
4596
    end
4597
 
4598
    if ( ok && !perr_asserted)
4599
        test_ok ;
4600
 
4601
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4602
 
4603
    // interrupts should not be present
4604
    `ifdef HOST
4605
        repeat( 4 )
4606 26 mihad
            @(posedge pci_clock) ;
4607
        repeat( 4 )
4608 15 mihad
            @(posedge wb_clock) ;
4609
        if ( INT_O !== 0 )
4610
        begin
4611
            $display("Parity checker testing failed! Time %t ", $time) ;
4612
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4613
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4614
        end
4615
        else
4616
            test_ok ;
4617
    `else
4618
    `ifdef GUEST
4619
        repeat( 4 )
4620 26 mihad
            @(posedge wb_clock) ;
4621
        repeat( 4 )
4622 15 mihad
            @(posedge pci_clock) ;
4623
        if ( INTA !== 1 )
4624
        begin
4625
            $display("Parity checker testing failed! Time %t ", $time) ;
4626
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4627
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4628
        end
4629
        else
4630
            test_ok ;
4631
    `endif
4632
    `endif
4633
 
4634
    // check statuses!
4635
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4636
    ok = 1 ;
4637
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4638
    if ( temp_val1[31] !== 1 )
4639
    begin
4640
        $display("Parity checker testing failed! Time %t ", $time) ;
4641 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4642 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4643
        ok = 0 ;
4644
    end
4645
 
4646
    if ( temp_val1[30] !== 0 )
4647
    begin
4648
        $display("Parity checker testing failed! Time %t ", $time) ;
4649
        $display("Signalled System Error bit was set for no reason!") ;
4650
        test_fail("Signalled System Error bit was set for no reason") ;
4651
        ok = 0 ;
4652
    end
4653
 
4654
    if ( temp_val1[24] !== 0 )
4655
    begin
4656
        $display("Parity checker testing failed! Time %t ", $time) ;
4657 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4658 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4659
        ok = 0 ;
4660
    end
4661
 
4662
    if ( ok )
4663
        test_ok ;
4664
 
4665
    // clear statuses
4666
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4667
 
4668
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4669
    ok = 1 ;
4670
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4671
 
4672
    if ( temp_val1[4] !== 0 )
4673
    begin
4674
        $display("Parity checker testing failed! Time %t ", $time) ;
4675
        $display("System error interrupt status bit set for no reason!") ;
4676
        test_fail("System error interrupt status bit set for no reason") ;
4677
        ok = 0 ;
4678
    end
4679
 
4680
    if ( temp_val1[3] !== 0 )
4681
    begin
4682
        $display("Parity checker testing failed! Time %t ", $time) ;
4683
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4684
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4685
        ok = 0 ;
4686
    end
4687
 
4688
    if ( ok )
4689
        test_ok ;
4690
 
4691
    // enable all responses to parity errors!
4692
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4693
 
4694
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4695
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4696
 
4697
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4698
 
4699
    // repeat a read
4700
    fork
4701
    begin
4702
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4703
    end
4704
    begin:wait_perr6
4705
        perr_asserted = 0 ;
4706
        @(posedge pci_clock) ;
4707
        while ( PERR === 1 )
4708
            @(posedge pci_clock) ;
4709
 
4710
        perr_asserted = 1 ;
4711
        $display("Parity checker testing failed! Time %t ", $time) ;
4712
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4713
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4714
    end
4715
    begin
4716
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4717
        if ( ok !== 1 )
4718
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4719
 
4720
        repeat(2)
4721
            @(posedge pci_clock) ;
4722
 
4723 35 mihad
        #1 ;
4724
        if ( !perr_asserted )
4725
            disable wait_perr6 ;
4726 15 mihad
    end
4727
    join
4728
 
4729
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4730
    begin
4731
        $display("Parity checker testing failed! Time %t ", $time) ;
4732
        $display("Bridge failed to process single memory read!") ;
4733
        test_fail("bridge didn't process single memory read as expected") ;
4734
        ok = 0 ;
4735
    end
4736
 
4737
    if ( ok && !perr_asserted)
4738
        test_ok ;
4739
 
4740
    // check statuses!
4741
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4742
    ok = 1 ;
4743
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4744
    if ( temp_val1[31] !== 0 )
4745
    begin
4746
        $display("Parity checker testing failed! Time %t ", $time) ;
4747
        $display("Detected Parity Error bit was set for no reason!") ;
4748
        test_fail("Detected Parity Error bit was set for no reason") ;
4749
        ok = 0 ;
4750
    end
4751
 
4752
    if ( temp_val1[30] !== 0 )
4753
    begin
4754
        $display("Parity checker testing failed! Time %t ", $time) ;
4755
        $display("Signalled System Error bit was set for no reason!") ;
4756
        test_fail("Signalled System Error bit was set for no reason") ;
4757
        ok = 0 ;
4758
    end
4759
 
4760
    if ( temp_val1[24] !== 0 )
4761
    begin
4762
        $display("Parity checker testing failed! Time %t ", $time) ;
4763
        $display("Master Data Parity Error bit was set for no reason!") ;
4764
        test_fail("Master Data Parity Error bit was set for no reason") ;
4765
        ok = 0 ;
4766
    end
4767
 
4768
    if ( ok )
4769
        test_ok ;
4770
 
4771
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4772
    ok = 1 ;
4773
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4774
 
4775
    if ( temp_val1[4] !== 0 )
4776
    begin
4777
        $display("Parity checker testing failed! Time %t ", $time) ;
4778
        $display("System error interrupt status bit set for no reason!") ;
4779
        test_fail("System error interrupt status bit set for no reason") ;
4780
        ok = 0 ;
4781
    end
4782
 
4783
    if ( temp_val1[3] !== 0 )
4784
    begin
4785
        $display("Parity checker testing failed! Time %t ", $time) ;
4786
        $display("Parity error interrupt status bit set for no reason!") ;
4787
        test_fail("Parity error interrupt status bit set for no reason") ;
4788
        ok = 0 ;
4789
    end
4790
 
4791
    if ( ok )
4792
        test_ok ;
4793
 
4794
    $display("Presenting address parity error on PCI bus!") ;
4795
    // enable parity errors - this should not affect system errors
4796
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4797
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4798
 
4799
    // perform PCI write
4800
    // check transaction progress
4801
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4802
    fork
4803
    begin
4804
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4805
               target_address, 32'h1234_5678,
4806
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4807
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4808
        do_pause( 1 ) ;
4809
    end
4810
    begin:wait_serr7
4811
        perr_asserted = 0 ;
4812
        @(posedge pci_clock) ;
4813
        while( SERR === 1 )
4814
            @(posedge pci_clock) ;
4815
 
4816
        perr_asserted = 1 ;
4817
        $display("Parity checker testing failed! Time %t ", $time) ;
4818
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4819
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4820
    end
4821
    begin
4822
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4823
        if ( ok !== 1 )
4824
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4825
 
4826 35 mihad
        if ( !perr_asserted )
4827
            disable wait_serr7 ;
4828 15 mihad
    end
4829
    join
4830
 
4831
    if ( ok && !perr_asserted)
4832
        test_ok ;
4833
 
4834
    // check statuses!
4835
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4836
    ok = 1 ;
4837
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4838
    if ( temp_val1[31] !== 1 )
4839
    begin
4840
        $display("Parity checker testing failed! Time %t ", $time) ;
4841
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4842
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4843
        ok = 0 ;
4844
    end
4845
 
4846
    if ( temp_val1[30] !== 0 )
4847
    begin
4848
        $display("Parity checker testing failed! Time %t ", $time) ;
4849
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4850
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4851
        ok = 0 ;
4852
    end
4853
 
4854
    if ( temp_val1[24] !== 0 )
4855
    begin
4856
        $display("Parity checker testing failed! Time %t ", $time) ;
4857
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4858
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4859
        ok = 0 ;
4860
    end
4861
 
4862
    if ( ok )
4863
        test_ok ;
4864
 
4865
    // clear statuses
4866
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4867
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4868
    fork
4869
    begin
4870
        ipci_unsupported_commands_master.master_reference
4871
        (
4872
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4873
            32'h5555_5555,      // second part of address in dual address cycle
4874
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4875
            `BC_MEM_WRITE,      // normal command
4876
            4'h0,               // byte enables
4877
            32'h1234_5678,      // data
4878
            1'b1,               // make address parity error on first phase of dual address
4879
            1'b0,               // make address parity error on second phase of dual address
4880
            ok                  // result of operation
4881
        ) ;
4882 35 mihad
        if ( !perr_asserted )
4883
            disable wait_serr8 ;
4884 15 mihad
    end
4885
    begin:wait_serr8
4886
        perr_asserted = 0 ;
4887
        @(posedge pci_clock) ;
4888
        while( SERR === 1 )
4889
            @(posedge pci_clock) ;
4890
 
4891
        perr_asserted = 1 ;
4892
        $display("Parity checker testing failed! Time %t ", $time) ;
4893
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4894
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4895
    end
4896
    join
4897
 
4898
    if ( ok && !perr_asserted)
4899
        test_ok ;
4900
 
4901
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4902
    fork
4903
    begin
4904
        ipci_unsupported_commands_master.master_reference
4905
        (
4906
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4907
            32'h5555_5555,      // second part of address in dual address cycle
4908
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4909
            `BC_MEM_WRITE,      // normal command
4910
            4'h0,               // byte enables
4911
            32'h1234_5678,      // data
4912
            1'b0,               // make address parity error on first phase of dual address
4913
            1'b1,               // make address parity error on second phase of dual address
4914
            ok                  // result of operation
4915
        ) ;
4916 35 mihad
        if ( !perr_asserted )
4917
            disable wait_serr9 ;
4918 15 mihad
    end
4919
    begin:wait_serr9
4920
        perr_asserted = 0 ;
4921
        @(posedge pci_clock) ;
4922
        while( SERR === 1 )
4923
            @(posedge pci_clock) ;
4924
 
4925
        perr_asserted = 1 ;
4926
        $display("Parity checker testing failed! Time %t ", $time) ;
4927
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4928
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4929
    end
4930
    join
4931
 
4932
    if ( ok && !perr_asserted)
4933
        test_ok ;
4934
 
4935
    // check statuses!
4936
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4937
    ok = 1 ;
4938
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4939
    if ( temp_val1[31] !== 1 )
4940
    begin
4941
        $display("Parity checker testing failed! Time %t ", $time) ;
4942
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4943
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4944
        ok = 0 ;
4945
    end
4946
 
4947
    if ( temp_val1[30] !== 0 )
4948
    begin
4949
        $display("Parity checker testing failed! Time %t ", $time) ;
4950
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4951
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4952
        ok = 0 ;
4953
    end
4954
 
4955
    if ( temp_val1[24] !== 0 )
4956
    begin
4957
        $display("Parity checker testing failed! Time %t ", $time) ;
4958
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4959
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4960
        ok = 0 ;
4961
    end
4962
 
4963
    if ( ok )
4964
        test_ok ;
4965
 
4966
    // clear statuses
4967
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4968
 
4969
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4970
    fork
4971
    begin
4972
        ipci_unsupported_commands_master.master_reference
4973
        (
4974
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4975
            32'h5555_5555,      // second part of address in dual address cycle
4976
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4977
            `BC_MEM_WRITE,      // normal command
4978
            4'h0,               // byte enables
4979
            32'h1234_5678,      // data
4980
            1'b1,               // make address parity error on first phase of dual address
4981
            1'b1,               // make address parity error on second phase of dual address
4982
            ok                  // result of operation
4983
        ) ;
4984 35 mihad
        if ( !perr_asserted )
4985
            disable wait_serr10 ;
4986 15 mihad
    end
4987
    begin:wait_serr10
4988
        perr_asserted = 0 ;
4989
        @(posedge pci_clock) ;
4990
        while( SERR === 1 )
4991
            @(posedge pci_clock) ;
4992
 
4993
        perr_asserted = 1 ;
4994
        $display("Parity checker testing failed! Time %t ", $time) ;
4995
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4996
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4997
    end
4998
    join
4999
 
5000
    if ( ok && !perr_asserted)
5001
        test_ok ;
5002
 
5003
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5004
 
5005
    `ifdef HOST
5006
        repeat(4)
5007 26 mihad
            @(posedge pci_clock) ;
5008
        repeat(4)
5009 15 mihad
            @(posedge wb_clock) ;
5010
        if ( INT_O !== 0 )
5011
        begin
5012
            $display("Parity checker testing failed! Time %t ", $time) ;
5013
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5014
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5015
        end
5016
        else
5017
            test_ok ;
5018
    `else
5019
    `ifdef GUEST
5020 26 mihad
        repeat(4)
5021
            @(posedge wb_clock) ;
5022
        repeat(4)
5023 15 mihad
            @(posedge pci_clock) ;
5024
 
5025
        if ( INTA !== 1 )
5026
        begin
5027
            $display("Parity checker testing failed! Time %t ", $time) ;
5028
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5029
            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") ;
5030
        end
5031
        else
5032
            test_ok ;
5033
    `endif
5034
    `endif
5035
 
5036
    // check statuses!
5037
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5038
    ok = 1 ;
5039
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5040
    if ( temp_val1[31] !== 1 )
5041
    begin
5042
        $display("Parity checker testing failed! Time %t ", $time) ;
5043
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5044
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5045
        ok = 0 ;
5046
    end
5047
 
5048
    if ( temp_val1[30] !== 0 )
5049
    begin
5050
        $display("Parity checker testing failed! Time %t ", $time) ;
5051
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5052
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5053
        ok = 0 ;
5054
    end
5055
 
5056
    if ( temp_val1[24] !== 0 )
5057
    begin
5058
        $display("Parity checker testing failed! Time %t ", $time) ;
5059
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5060
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5061
        ok = 0 ;
5062
    end
5063
 
5064
    if ( ok )
5065
        test_ok ;
5066
 
5067
    // clear statuses
5068
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5069
 
5070
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5071
    ok = 1 ;
5072
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5073
 
5074
    if ( temp_val1[4] !== 0 )
5075
    begin
5076
        $display("Parity checker testing failed! Time %t ", $time) ;
5077
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5078
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5079
        ok = 0 ;
5080
    end
5081
 
5082
    if ( temp_val1[3] !== 0 )
5083
    begin
5084
        $display("Parity checker testing failed! Time %t ", $time) ;
5085
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5086
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5087
        ok = 0 ;
5088
    end
5089
 
5090
    if ( ok )
5091
        test_ok ;
5092
 
5093
    // now enable system error signaling and test response
5094
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5095
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5096
 
5097
    fork
5098
    begin
5099
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5100
               target_address, 32'h1234_5678,
5101
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5102
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5103
        do_pause( 1 ) ;
5104
    end
5105
    begin:wait_serr11
5106
        perr_asserted = 0 ;
5107
        @(posedge pci_clock) ;
5108 35 mihad
        while( SERR !== 0 )
5109 15 mihad
            @(posedge pci_clock) ;
5110
 
5111 35 mihad
        perr_asserted = 1 ;
5112 15 mihad
    end
5113
    begin
5114
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5115
        if ( ok !== 1 )
5116
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5117
 
5118
        @(posedge pci_clock) ;
5119 35 mihad
        #1 ;
5120
        if ( !perr_asserted )
5121
            disable wait_serr11 ;
5122 15 mihad
    end
5123
    join
5124
 
5125
    if ( ok && perr_asserted)
5126
        test_ok ;
5127
    else
5128
    if ( !perr_asserted )
5129
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5130
 
5131
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5132
 
5133
    `ifdef HOST
5134
        repeat(4)
5135 26 mihad
            @(posedge pci_clock) ;
5136
        repeat(4)
5137 15 mihad
            @(posedge wb_clock) ;
5138
        if ( INT_O !== 1 )
5139
        begin
5140
            $display("Parity checker testing failed! Time %t ", $time) ;
5141
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5142
            test_fail("Interrupt Request was not triggered as expected") ;
5143
        end
5144
        else
5145
            test_ok ;
5146
    `else
5147
    `ifdef GUEST
5148 26 mihad
        repeat(4)
5149
            @(posedge wb_clock) ;
5150
        repeat(4)
5151 15 mihad
            @(posedge pci_clock) ;
5152
 
5153
        if ( INTA !== 1 )
5154
        begin
5155
            $display("Parity checker testing failed! Time %t ", $time) ;
5156
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5157
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5158
        end
5159
        else
5160
            test_ok ;
5161
    `endif
5162
    `endif
5163
 
5164
    // check statuses!
5165
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5166
    ok = 1 ;
5167
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5168
    if ( temp_val1[31] !== 1 )
5169
    begin
5170
        $display("Parity checker testing failed! Time %t ", $time) ;
5171
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5172
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5173
        ok = 0 ;
5174
    end
5175
 
5176
    if ( temp_val1[30] !== 1 )
5177
    begin
5178
        $display("Parity checker testing failed! Time %t ", $time) ;
5179
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5180
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5181
        ok = 0 ;
5182
    end
5183
 
5184
    if ( temp_val1[24] !== 0 )
5185
    begin
5186
        $display("Parity checker testing failed! Time %t ", $time) ;
5187
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5188
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5189
        ok = 0 ;
5190
    end
5191
 
5192
    if ( ok )
5193
        test_ok ;
5194
 
5195
    // clear statuses
5196
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5197
 
5198
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5199
 
5200
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5201
    ok = 1 ;
5202
 
5203
    `ifdef HOST
5204
    if ( temp_val1[4] !== 1 )
5205
    begin
5206
        $display("Parity checker testing failed! Time %t ", $time) ;
5207
        $display("System error interrupt status bit not set when expected!") ;
5208
        test_fail("System error interrupt status bit not set when expected") ;
5209
        ok = 0 ;
5210
    end
5211
    `else
5212
    if ( temp_val1[4] !== 0 )
5213
    begin
5214
        $display("Parity checker testing failed! Time %t ", $time) ;
5215
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5216
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5217
        ok = 0 ;
5218
    end
5219
    `endif
5220
 
5221
    if ( temp_val1[3] !== 0 )
5222
    begin
5223
        $display("Parity checker testing failed! Time %t ", $time) ;
5224
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5225
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5226
        ok = 0 ;
5227
    end
5228
 
5229
    if ( ok )
5230
        test_ok ;
5231
 
5232
    // clear statuses
5233
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5234
 
5235
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5236
    fork
5237
    begin
5238
        ipci_unsupported_commands_master.master_reference
5239
        (
5240
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5241
            32'h5555_5555,      // second part of address in dual address cycle
5242
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5243
            `BC_MEM_WRITE,      // normal command
5244
            4'h0,               // byte enables
5245
            32'h1234_5678,      // data
5246
            1'b1,               // make address parity error on first phase of dual address
5247
            1'b0,               // make address parity error on second phase of dual address
5248
            ok                  // result of operation
5249
        ) ;
5250 35 mihad
        if ( !perr_asserted )
5251
            disable wait_serr14 ;
5252 15 mihad
    end
5253
    begin:wait_serr14
5254
        perr_asserted = 0 ;
5255
        @(posedge pci_clock) ;
5256 35 mihad
        while( SERR !== 0 )
5257 15 mihad
            @(posedge pci_clock) ;
5258
 
5259 35 mihad
        perr_asserted = 1 ;
5260 15 mihad
    end
5261
    join
5262
 
5263
    if ( ok && perr_asserted)
5264
        test_ok ;
5265
    else
5266
    if ( !perr_asserted )
5267
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5268
 
5269
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5270
 
5271
    `ifdef HOST
5272
        repeat(4)
5273 26 mihad
            @(posedge pci_clock) ;
5274
        repeat(4)
5275 15 mihad
            @(posedge wb_clock) ;
5276
        if ( INT_O !== 1 )
5277
        begin
5278
            $display("Parity checker testing failed! Time %t ", $time) ;
5279
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5280
            test_fail("Interrupt Request was not triggered as expected") ;
5281
        end
5282
        else
5283
            test_ok ;
5284
    `else
5285
    `ifdef GUEST
5286 26 mihad
        repeat(4)
5287
            @(posedge wb_clock) ;
5288
        repeat(4)
5289 15 mihad
            @(posedge pci_clock) ;
5290
 
5291
        if ( INTA !== 1 )
5292
        begin
5293
            $display("Parity checker testing failed! Time %t ", $time) ;
5294
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5295
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5296
        end
5297
        else
5298
            test_ok ;
5299
    `endif
5300
    `endif
5301
 
5302
    // check statuses!
5303
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5304
    ok = 1 ;
5305
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5306
    if ( temp_val1[31] !== 1 )
5307
    begin
5308
        $display("Parity checker testing failed! Time %t ", $time) ;
5309
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5310
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5311
        ok = 0 ;
5312
    end
5313
 
5314
    if ( temp_val1[30] !== 1 )
5315
    begin
5316
        $display("Parity checker testing failed! Time %t ", $time) ;
5317
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5318
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5319
        ok = 0 ;
5320
    end
5321
 
5322
    if ( temp_val1[24] !== 0 )
5323
    begin
5324
        $display("Parity checker testing failed! Time %t ", $time) ;
5325
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5326
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5327
        ok = 0 ;
5328
    end
5329
 
5330
    if ( ok )
5331
        test_ok ;
5332
 
5333
    // clear statuses
5334
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5335
 
5336
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5337
 
5338
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5339
    ok = 1 ;
5340
 
5341
    `ifdef HOST
5342
    if ( temp_val1[4] !== 1 )
5343
    begin
5344
        $display("Parity checker testing failed! Time %t ", $time) ;
5345
        $display("System error interrupt status bit not set when expected!") ;
5346
        test_fail("System error interrupt status bit not set when expected") ;
5347
        ok = 0 ;
5348
    end
5349
    `else
5350
    if ( temp_val1[4] !== 0 )
5351
    begin
5352
        $display("Parity checker testing failed! Time %t ", $time) ;
5353
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5354
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5355
        ok = 0 ;
5356
    end
5357
    `endif
5358
 
5359
    if ( temp_val1[3] !== 0 )
5360
    begin
5361
        $display("Parity checker testing failed! Time %t ", $time) ;
5362
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5363
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5364
        ok = 0 ;
5365
    end
5366
 
5367
    if ( ok )
5368
        test_ok ;
5369
 
5370
    // clear statuses
5371
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5372
 
5373
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5374
    fork
5375
    begin
5376
        ipci_unsupported_commands_master.master_reference
5377
        (
5378
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5379
            32'h5555_5555,      // second part of address in dual address cycle
5380
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5381
            `BC_MEM_WRITE,      // normal command
5382
            4'h0,               // byte enables
5383
            32'h1234_5678,      // data
5384
            1'b0,               // make address parity error on first phase of dual address
5385
            1'b1,               // make address parity error on second phase of dual address
5386
            ok                  // result of operation
5387
        ) ;
5388 35 mihad
        if ( !perr_asserted )
5389
            disable wait_serr15 ;
5390 15 mihad
    end
5391
    begin:wait_serr15
5392
        perr_asserted = 0 ;
5393
        @(posedge pci_clock) ;
5394 35 mihad
        while( SERR !== 0 )
5395 15 mihad
            @(posedge pci_clock) ;
5396
 
5397 35 mihad
        perr_asserted = 1 ;
5398 15 mihad
    end
5399
    join
5400
 
5401
    if ( ok && perr_asserted)
5402
        test_ok ;
5403
    else
5404
    if ( !perr_asserted )
5405
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5406
 
5407
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5408
 
5409
    `ifdef HOST
5410
        repeat(4)
5411 26 mihad
            @(posedge pci_clock) ;
5412
        repeat(4)
5413 15 mihad
            @(posedge wb_clock) ;
5414
        if ( INT_O !== 1 )
5415
        begin
5416
            $display("Parity checker testing failed! Time %t ", $time) ;
5417
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5418
            test_fail("Interrupt Request was not triggered as expected") ;
5419
        end
5420
        else
5421
            test_ok ;
5422
    `else
5423
    `ifdef GUEST
5424 26 mihad
        repeat(4)
5425
            @(posedge wb_clock) ;
5426
        repeat(4)
5427 15 mihad
            @(posedge pci_clock) ;
5428
 
5429
        if ( INTA !== 1 )
5430
        begin
5431
            $display("Parity checker testing failed! Time %t ", $time) ;
5432
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5433
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5434
        end
5435
        else
5436
            test_ok ;
5437
    `endif
5438
    `endif
5439
 
5440
    // check statuses!
5441
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5442
    ok = 1 ;
5443
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5444
    if ( temp_val1[31] !== 1 )
5445
    begin
5446
        $display("Parity checker testing failed! Time %t ", $time) ;
5447
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5448
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5449
        ok = 0 ;
5450
    end
5451
 
5452
    if ( temp_val1[30] !== 1 )
5453
    begin
5454
        $display("Parity checker testing failed! Time %t ", $time) ;
5455
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5456
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5457
        ok = 0 ;
5458
    end
5459
 
5460
    if ( temp_val1[24] !== 0 )
5461
    begin
5462
        $display("Parity checker testing failed! Time %t ", $time) ;
5463
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5464
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5465
        ok = 0 ;
5466
    end
5467
 
5468
    if ( ok )
5469
        test_ok ;
5470
 
5471
    // clear statuses
5472
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5473
 
5474
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5475
 
5476
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5477
    ok = 1 ;
5478
 
5479
    `ifdef HOST
5480
    if ( temp_val1[4] !== 1 )
5481
    begin
5482
        $display("Parity checker testing failed! Time %t ", $time) ;
5483
        $display("System error interrupt status bit not set when expected!") ;
5484
        test_fail("System error interrupt status bit not set when expected") ;
5485
        ok = 0 ;
5486
    end
5487
    `else
5488
    if ( temp_val1[4] !== 0 )
5489
    begin
5490
        $display("Parity checker testing failed! Time %t ", $time) ;
5491
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5492
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5493
        ok = 0 ;
5494
    end
5495
    `endif
5496
 
5497
    if ( temp_val1[3] !== 0 )
5498
    begin
5499
        $display("Parity checker testing failed! Time %t ", $time) ;
5500
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5501
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5502
        ok = 0 ;
5503
    end
5504
 
5505
    if ( ok )
5506
        test_ok ;
5507
 
5508
    // clear statuses
5509
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5510
 
5511
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5512
    fork
5513
    begin
5514
        ipci_unsupported_commands_master.master_reference
5515
        (
5516
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5517
            32'h5555_5555,      // second part of address in dual address cycle
5518
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5519
            `BC_MEM_WRITE,      // normal command
5520
            4'h0,               // byte enables
5521
            32'h1234_5678,      // data
5522
            1'b1,               // make address parity error on first phase of dual address
5523
            1'b1,               // make address parity error on second phase of dual address
5524
            ok                  // result of operation
5525
        ) ;
5526 35 mihad
        if ( !perr_asserted )
5527
            disable wait_serr16 ;
5528 15 mihad
    end
5529
    begin:wait_serr16
5530
        perr_asserted = 0 ;
5531
        @(posedge pci_clock) ;
5532 35 mihad
        while( SERR !== 0 )
5533 15 mihad
            @(posedge pci_clock) ;
5534
 
5535 35 mihad
        perr_asserted = 1 ;
5536 15 mihad
    end
5537
    join
5538
 
5539
    if ( ok && perr_asserted)
5540
        test_ok ;
5541
    else
5542
    if ( !perr_asserted )
5543
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5544
 
5545
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5546
 
5547
    `ifdef HOST
5548
        repeat(4)
5549 26 mihad
            @(posedge pci_clock) ;
5550
        repeat(4)
5551 15 mihad
            @(posedge wb_clock) ;
5552
        if ( INT_O !== 1 )
5553
        begin
5554
            $display("Parity checker testing failed! Time %t ", $time) ;
5555
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5556
            test_fail("Interrupt Request was not triggered as expected") ;
5557
        end
5558
        else
5559
            test_ok ;
5560
    `else
5561
    `ifdef GUEST
5562 26 mihad
        repeat(4)
5563
            @(posedge wb_clock) ;
5564
        repeat(4)
5565 15 mihad
            @(posedge pci_clock) ;
5566
 
5567
        if ( INTA !== 1 )
5568
        begin
5569
            $display("Parity checker testing failed! Time %t ", $time) ;
5570
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5571
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5572
        end
5573
        else
5574
            test_ok ;
5575
    `endif
5576
    `endif
5577
 
5578
    // check statuses!
5579
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5580
    ok = 1 ;
5581
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5582
    if ( temp_val1[31] !== 1 )
5583
    begin
5584
        $display("Parity checker testing failed! Time %t ", $time) ;
5585
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5586
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5587
        ok = 0 ;
5588
    end
5589
 
5590
    if ( temp_val1[30] !== 1 )
5591
    begin
5592
        $display("Parity checker testing failed! Time %t ", $time) ;
5593
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5594
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5595
        ok = 0 ;
5596
    end
5597
 
5598
    if ( temp_val1[24] !== 0 )
5599
    begin
5600
        $display("Parity checker testing failed! Time %t ", $time) ;
5601
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5602
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5603
        ok = 0 ;
5604
    end
5605
 
5606
    if ( ok )
5607
        test_ok ;
5608
 
5609
    // clear statuses
5610
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5611
 
5612
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5613
 
5614
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5615
    ok = 1 ;
5616
 
5617
    `ifdef HOST
5618
    if ( temp_val1[4] !== 1 )
5619
    begin
5620
        $display("Parity checker testing failed! Time %t ", $time) ;
5621
        $display("System error interrupt status bit not set when expected!") ;
5622
        test_fail("System error interrupt status bit not set when expected") ;
5623
        ok = 0 ;
5624
    end
5625
    `else
5626
    if ( temp_val1[4] !== 0 )
5627
    begin
5628
        $display("Parity checker testing failed! Time %t ", $time) ;
5629
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5630
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5631
        ok = 0 ;
5632
    end
5633
    `endif
5634
 
5635
    if ( temp_val1[3] !== 0 )
5636
    begin
5637
        $display("Parity checker testing failed! Time %t ", $time) ;
5638
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5639
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5640
        ok = 0 ;
5641
    end
5642
 
5643
    if ( ok )
5644
        test_ok ;
5645
 
5646
    // clear statuses
5647
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5648
 
5649
    // now just disable Parity Error response - on Address par errors nothing should happen
5650
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5651
 
5652
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5653
    fork
5654
    begin
5655
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5656
               target_address, 32'h1234_5678,
5657
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5658
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5659
        do_pause( 1 ) ;
5660
    end
5661
    begin:wait_serr12
5662
        perr_asserted = 0 ;
5663
        @(posedge pci_clock) ;
5664
        while( SERR === 1 )
5665
            @(posedge pci_clock) ;
5666
 
5667
        perr_asserted = 1 ;
5668
        $display("Parity checker testing failed! Time %t ", $time) ;
5669
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5670
        test_fail("SERR asserted when parity error response was disabled") ;
5671
    end
5672
    begin
5673
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5674
        if ( ok !== 1 )
5675
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5676
 
5677 35 mihad
        @(posedge pci_clock) ;
5678
        #1 ;
5679
        if ( !perr_asserted )
5680
            disable wait_serr12 ;
5681 15 mihad
    end
5682
    join
5683
 
5684
    if ( ok && !perr_asserted )
5685
        test_ok ;
5686
 
5687
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5688
    `ifdef HOST
5689 26 mihad
        repeat (4)
5690
            @(posedge pci_clock) ;
5691 15 mihad
        repeat(4)
5692
            @(posedge wb_clock) ;
5693
        if ( INT_O !== 0 )
5694
        begin
5695
            $display("Parity checker testing failed! Time %t ", $time) ;
5696
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5697
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5698
        end
5699
        else
5700
            test_ok ;
5701
    `else
5702
    `ifdef GUEST
5703 26 mihad
        repeat(4)
5704
            @(posedge wb_clock) ;
5705
        repeat (4)
5706 15 mihad
            @(posedge pci_clock) ;
5707
 
5708
        if ( INTA !== 1 )
5709
        begin
5710
            $display("Parity checker testing failed! Time %t ", $time) ;
5711
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5712
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5713
        end
5714
        else
5715
            test_ok ;
5716
    `endif
5717
    `endif
5718
 
5719
    // check statuses!
5720
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5721
    ok = 1 ;
5722
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5723
    if ( temp_val1[31] !== 1 )
5724
    begin
5725
        $display("Parity checker testing failed! Time %t ", $time) ;
5726
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5727
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5728
        ok = 0 ;
5729
    end
5730
 
5731
    if ( temp_val1[30] !== 0 )
5732
    begin
5733
        $display("Parity checker testing failed! Time %t ", $time) ;
5734
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5735
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5736
        ok = 0 ;
5737
    end
5738
 
5739
    if ( temp_val1[24] !== 0 )
5740
    begin
5741
        $display("Parity checker testing failed! Time %t ", $time) ;
5742
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5743
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5744
        ok = 0 ;
5745
    end
5746
 
5747
    if ( ok )
5748
        test_ok ;
5749
 
5750
    // clear statuses
5751
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5752
 
5753
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5754
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5755
    ok = 1 ;
5756
    if ( temp_val1[4] !== 0 )
5757
    begin
5758
        $display("Parity checker testing failed! Time %t ", $time) ;
5759
        $display("System error interrupt status bit set when not expected!") ;
5760
        test_fail("System error interrupt status bit set when not expected") ;
5761
        ok = 0 ;
5762
    end
5763
 
5764
    if ( temp_val1[3] !== 0 )
5765
    begin
5766
        $display("Parity checker testing failed! Time %t ", $time) ;
5767
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5768
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5769
        ok = 0 ;
5770
    end
5771
 
5772
    if ( ok )
5773
        test_ok ;
5774
 
5775
    // clear statuses
5776
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5777
 
5778
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5779
    fork
5780
    begin
5781
        ipci_unsupported_commands_master.master_reference
5782
        (
5783
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5784
            32'h5555_5555,      // second part of address in dual address cycle
5785
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5786
            `BC_MEM_WRITE,      // normal command
5787
            4'h0,               // byte enables
5788
            32'h1234_5678,      // data
5789
            1'b1,               // make address parity error on first phase of dual address
5790
            1'b0,               // make address parity error on second phase of dual address
5791
            ok                  // result of operation
5792
        ) ;
5793 35 mihad
        if ( !perr_asserted )
5794
            disable wait_serr17 ;
5795 15 mihad
    end
5796
    begin:wait_serr17
5797
        perr_asserted = 0 ;
5798
        @(posedge pci_clock) ;
5799
        while( SERR === 1 )
5800
            @(posedge pci_clock) ;
5801
 
5802
        perr_asserted = 1 ;
5803
        $display("Parity checker testing failed! Time %t ", $time) ;
5804
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5805
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5806
    end
5807
    join
5808
 
5809
    if ( ok && !perr_asserted)
5810
        test_ok ;
5811
 
5812
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5813
    fork
5814
    begin
5815
        ipci_unsupported_commands_master.master_reference
5816
        (
5817
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5818
            32'h5555_5555,      // second part of address in dual address cycle
5819
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5820
            `BC_MEM_WRITE,      // normal command
5821
            4'h0,               // byte enables
5822
            32'h1234_5678,      // data
5823
            1'b0,               // make address parity error on first phase of dual address
5824
            1'b1,               // make address parity error on second phase of dual address
5825
            ok                  // result of operation
5826
        ) ;
5827 35 mihad
        if ( !perr_asserted )
5828
            disable wait_serr18 ;
5829 15 mihad
    end
5830
    begin:wait_serr18
5831
        perr_asserted = 0 ;
5832
        @(posedge pci_clock) ;
5833
        while( SERR === 1 )
5834
            @(posedge pci_clock) ;
5835
 
5836
        perr_asserted = 1 ;
5837
        $display("Parity checker testing failed! Time %t ", $time) ;
5838
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5839
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5840
    end
5841
    join
5842
 
5843
    if ( ok && !perr_asserted)
5844
        test_ok ;
5845
 
5846
    // check statuses!
5847
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5848
    ok = 1 ;
5849
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5850
    if ( temp_val1[31] !== 1 )
5851
    begin
5852
        $display("Parity checker testing failed! Time %t ", $time) ;
5853
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5854
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5855
        ok = 0 ;
5856
    end
5857
 
5858
    if ( temp_val1[30] !== 0 )
5859
    begin
5860
        $display("Parity checker testing failed! Time %t ", $time) ;
5861
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5862
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5863
        ok = 0 ;
5864
    end
5865
 
5866
    if ( temp_val1[24] !== 0 )
5867
    begin
5868
        $display("Parity checker testing failed! Time %t ", $time) ;
5869
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5870
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5871
        ok = 0 ;
5872
    end
5873
 
5874
    if ( ok )
5875
        test_ok ;
5876
 
5877
    // clear statuses
5878
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5879
 
5880
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5881
    fork
5882
    begin
5883
        ipci_unsupported_commands_master.master_reference
5884
        (
5885
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5886
            32'h5555_5555,      // second part of address in dual address cycle
5887
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5888
            `BC_MEM_WRITE,      // normal command
5889
            4'h0,               // byte enables
5890
            32'h1234_5678,      // data
5891
            1'b1,               // make address parity error on first phase of dual address
5892
            1'b1,               // make address parity error on second phase of dual address
5893
            ok                  // result of operation
5894
        ) ;
5895 35 mihad
        if ( !perr_asserted )
5896
            disable wait_serr19 ;
5897 15 mihad
    end
5898
    begin:wait_serr19
5899
        perr_asserted = 0 ;
5900
        @(posedge pci_clock) ;
5901
        while( SERR === 1 )
5902
            @(posedge pci_clock) ;
5903
 
5904
        perr_asserted = 1 ;
5905
        $display("Parity checker testing failed! Time %t ", $time) ;
5906
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5907
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5908
    end
5909
    join
5910
 
5911
    if ( ok && !perr_asserted)
5912
        test_ok ;
5913
 
5914
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5915
 
5916
    `ifdef HOST
5917
        repeat(4)
5918 26 mihad
            @(posedge pci_clock) ;
5919
        repeat(4)
5920 15 mihad
            @(posedge wb_clock) ;
5921
        if ( INT_O !== 0 )
5922
        begin
5923
            $display("Parity checker testing failed! Time %t ", $time) ;
5924
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5925
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5926
        end
5927
        else
5928
            test_ok ;
5929
    `else
5930
    `ifdef GUEST
5931 26 mihad
        repeat(4)
5932
            @(posedge wb_clock) ;
5933
        repeat(4)
5934 15 mihad
            @(posedge pci_clock) ;
5935
 
5936
        if ( INTA !== 1 )
5937
        begin
5938
            $display("Parity checker testing failed! Time %t ", $time) ;
5939
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5940
            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") ;
5941
        end
5942
        else
5943
            test_ok ;
5944
    `endif
5945
    `endif
5946
 
5947
    // check statuses!
5948
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5949
    ok = 1 ;
5950
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5951
    if ( temp_val1[31] !== 1 )
5952
    begin
5953
        $display("Parity checker testing failed! Time %t ", $time) ;
5954
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5955
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5956
        ok = 0 ;
5957
    end
5958
 
5959
    if ( temp_val1[30] !== 0 )
5960
    begin
5961
        $display("Parity checker testing failed! Time %t ", $time) ;
5962
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5963
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5964
        ok = 0 ;
5965
    end
5966
 
5967
    if ( temp_val1[24] !== 0 )
5968
    begin
5969
        $display("Parity checker testing failed! Time %t ", $time) ;
5970
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5971
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5972
        ok = 0 ;
5973
    end
5974
 
5975
    if ( ok )
5976
        test_ok ;
5977
 
5978
    // clear statuses
5979
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5980
 
5981
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
5982
 
5983
    // do normal write
5984
    fork
5985
    begin
5986
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
5987
               target_address, 32'h1234_5678, `Test_All_Bytes,
5988
               1, 8'h3_0, `Test_One_Zero_Target_WS,
5989
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5990
        do_pause( 1 ) ;
5991
    end
5992
    begin:wait_serr13
5993
        perr_asserted = 0 ;
5994
        @(posedge pci_clock) ;
5995
        while( SERR === 1 )
5996
            @(posedge pci_clock) ;
5997
 
5998
        perr_asserted = 1 ;
5999
        $display("Parity checker testing failed! Time %t ", $time) ;
6000
        $display("SERR asserted for no reason!") ;
6001
        test_fail("SERR was asserted for no reason") ;
6002
    end
6003
    begin
6004
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6005
        if ( ok !== 1 )
6006
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6007
 
6008 35 mihad
        @(posedge pci_clock) ;
6009
        #1 ;
6010
        if ( !perr_asserted )
6011
            disable wait_serr13 ;
6012 15 mihad
    end
6013
    join
6014
 
6015
    if ( ok && !perr_asserted )
6016
        test_ok ;
6017
 
6018
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6019
    `ifdef HOST
6020 26 mihad
        repeat( 4 )
6021
            @(posedge pci_clock) ;
6022 15 mihad
        repeat(4)
6023
            @(posedge wb_clock) ;
6024
        if ( INT_O !== 0 )
6025
        begin
6026
            $display("Parity checker testing failed! Time %t ", $time) ;
6027
            $display("Interrupt request asserted for no reason!") ;
6028
            test_fail("Interrupt request was asserted for no reason") ;
6029
        end
6030
        else
6031
            test_ok ;
6032
    `else
6033
    `ifdef GUEST
6034 26 mihad
        repeat(4)
6035
            @(posedge wb_clock) ;
6036
        repeat(4)
6037 15 mihad
            @(posedge pci_clock) ;
6038
 
6039
        if ( INTA !== 1 )
6040
        begin
6041
            $display("Parity checker testing failed! Time %t ", $time) ;
6042
            $display("Interrupt request asserted for no reason!") ;
6043
            test_fail("Interrupt request was asserted for no reason") ;
6044
        end
6045
        else
6046
            test_ok ;
6047
    `endif
6048
    `endif
6049
 
6050
    // check statuses!
6051
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6052
    ok = 1 ;
6053
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6054
    if ( temp_val1[31] !== 0 )
6055
    begin
6056
        $display("Parity checker testing failed! Time %t ", $time) ;
6057
        $display("Detected Parity Error bit was set for no reason!") ;
6058
        test_fail("Detected Parity Error bit was set for no reason") ;
6059
        ok = 0 ;
6060
    end
6061
 
6062
    if ( temp_val1[30] !== 0 )
6063
    begin
6064
        $display("Parity checker testing failed! Time %t ", $time) ;
6065
        $display("Signalled System Error bit was set for no reason!") ;
6066
        test_fail("Signalled System Error bit was set for no reason") ;
6067
        ok = 0 ;
6068
    end
6069
 
6070
    if ( temp_val1[24] !== 0 )
6071
    begin
6072
        $display("Parity checker testing failed! Time %t ", $time) ;
6073
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6074
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6075
        ok = 0 ;
6076
    end
6077
 
6078
    if ( ok )
6079
        test_ok ;
6080
 
6081
    // clear statuses
6082
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6083
 
6084
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6085
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6086
    ok = 1 ;
6087
 
6088
    if ( temp_val1[4] !== 0 )
6089
    begin
6090
        $display("Parity checker testing failed! Time %t ", $time) ;
6091
        $display("System error interrupt status bit set when not expected!") ;
6092
        test_fail("System error interrupt status bit set when not expected") ;
6093
        ok = 0 ;
6094
    end
6095
 
6096
    if ( temp_val1[3] !== 0 )
6097
    begin
6098
        $display("Parity checker testing failed! Time %t ", $time) ;
6099
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6100
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6101
        ok = 0 ;
6102
    end
6103
 
6104
    if ( ok )
6105
        test_ok ;
6106
 
6107
    // clear statuses
6108
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6109
 
6110
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6111
 
6112
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6113
 
6114
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6115
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6116
 
6117
    // setup target's image!
6118
    target_address  = Target_Base_Addr_R[1] ;
6119
 
6120
    // base address
6121
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6122
 
6123
    // address mask
6124
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6125
 
6126
    // image control
6127
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6128
 
6129
    // enable everything possible for parity checking
6130
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6131
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6132
 
6133
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6134
 
6135
    fork
6136
    begin
6137
        if ( target_mem_image === 1 )
6138
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6139
                   target_address, 32'h1234_5678,
6140
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6141
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6142
        else
6143
            PCIU_IO_WRITE_MAKE_PERR (
6144
                                    `Test_Master_1,
6145
                                    target_address,
6146
                                    32'h1234_5678,
6147
                                    4'h0,
6148
                                    1,
6149
                                    `Test_Target_Normal_Completion
6150
                                    );
6151
 
6152
        do_pause( 1 ) ;
6153
    end
6154
    begin:wait_perr11
6155
        perr_asserted = 0 ;
6156
        @(posedge pci_clock) ;
6157 35 mihad
        while ( PERR !== 0 )
6158 15 mihad
            @(posedge pci_clock) ;
6159
 
6160 35 mihad
        perr_asserted = 1 ;
6161 15 mihad
 
6162
    end
6163
    begin
6164
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6165
 
6166
        if ( ok !== 1 )
6167
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6168
 
6169
        repeat(2)
6170
            @(posedge pci_clock) ;
6171
 
6172 35 mihad
        #1 ;
6173
        if ( !perr_asserted )
6174
            disable wait_perr11 ;
6175 15 mihad
    end
6176
    join
6177
 
6178
    if ( ok && perr_asserted )
6179
        test_ok ;
6180
    else
6181
    if ( !perr_asserted )
6182
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6183
 
6184
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6185
    `ifdef HOST
6186 26 mihad
        repeat (4)
6187
            @(posedge pci_clock) ;
6188 15 mihad
        repeat(4)
6189
            @(posedge wb_clock) ;
6190
        if ( INT_O !== 0 )
6191
        begin
6192
            $display("Parity checker testing failed! Time %t ", $time) ;
6193
            $display("Interrupt request asserted for no reason!") ;
6194
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6195
        end
6196
        else
6197
            test_ok ;
6198
    `else
6199
    `ifdef GUEST
6200 26 mihad
        repeat(4)
6201
            @(posedge wb_clock) ;
6202
        repeat (4)
6203 15 mihad
            @(posedge pci_clock) ;
6204
 
6205
        if ( INTA !== 1 )
6206
        begin
6207
            $display("Parity checker testing failed! Time %t ", $time) ;
6208
            $display("Interrupt request asserted for no reason!") ;
6209
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6210
        end
6211
        else
6212
            test_ok ;
6213
 
6214
    `endif
6215
    `endif
6216
 
6217
    // check statuses!
6218
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6219
    ok = 1 ;
6220
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6221
    if ( temp_val1[31] !== 1 )
6222
    begin
6223
        $display("Parity checker testing failed! Time %t ", $time) ;
6224 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6225
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6226 15 mihad
        ok = 0 ;
6227
    end
6228
 
6229
    if ( temp_val1[30] !== 0 )
6230
    begin
6231
        $display("Parity checker testing failed! Time %t ", $time) ;
6232
        $display("Signalled System Error bit was set for no reason!") ;
6233
        test_fail("Signalled System Error bit was set for no reason") ;
6234
        ok = 0 ;
6235
    end
6236
 
6237
    if ( temp_val1[24] !== 0 )
6238
    begin
6239
        $display("Parity checker testing failed! Time %t ", $time) ;
6240
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6241
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6242
        ok = 0 ;
6243
    end
6244
 
6245
    if ( ok )
6246
        test_ok ;
6247
 
6248
    // clear statuses
6249
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6250
 
6251
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6252
 
6253
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6254
    ok = 1 ;
6255
    if ( temp_val1[4] !== 0 )
6256
    begin
6257
        $display("Parity checker testing failed! Time %t ", $time) ;
6258
        $display("System error interrupt status bit set when not expected!") ;
6259
        test_fail("System error interrupt status bit set when not expected") ;
6260
        ok = 0 ;
6261
    end
6262
 
6263
    if ( temp_val1[3] !== 0 )
6264
    begin
6265
        $display("Parity checker testing failed! Time %t ", $time) ;
6266
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6267
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6268
        ok = 0 ;
6269
    end
6270
 
6271
    if ( ok )
6272
        test_ok ;
6273
 
6274
    // clear statuses
6275
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6276
 
6277
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6278
 
6279
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6280
    fork
6281
    begin
6282
        if ( target_mem_image === 1 )
6283
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6284
                          target_address, 32'h1234_5678,
6285
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6286
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6287
        else
6288
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6289
 
6290
        do_pause( 1 ) ;
6291
    end
6292
    begin:wait_perr12
6293
        perr_asserted = 0 ;
6294
        @(posedge pci_clock) ;
6295 35 mihad
        while ( PERR !== 0 )
6296 15 mihad
            @(posedge pci_clock) ;
6297
 
6298 35 mihad
        perr_asserted = 1 ;
6299 15 mihad
    end
6300
    begin
6301
 
6302
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6303
        if ( ok !== 1 )
6304
        begin
6305
            test_fail("Bridge failed to process Target Memory read correctly") ;
6306
            disable main ;
6307
        end
6308
 
6309
        repeat(3)
6310
            @(posedge pci_clock) ;
6311
 
6312
        if ( target_mem_image === 1 )
6313
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6314
                    target_address, 32'h1234_5678,
6315
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6316
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6317
        else
6318
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6319
 
6320
        do_pause( 1 ) ;
6321
 
6322
    end
6323
    begin
6324
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6325
        if ( ok !== 1 )
6326
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6327
        else
6328
        begin
6329
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6330
            if ( ok !== 1 )
6331
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6332
        end
6333
 
6334 35 mihad
        repeat(2)
6335 15 mihad
            @(posedge pci_clock) ;
6336
 
6337 35 mihad
        #1 ;
6338
        if ( !perr_asserted )
6339
            disable wait_perr12 ;
6340 15 mihad
    end
6341
    join
6342
 
6343
    if ( ok && perr_asserted )
6344
        test_ok ;
6345
    else
6346
    if ( !perr_asserted )
6347
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6348
 
6349
 
6350
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6351
    `ifdef HOST
6352
        repeat(4)
6353 26 mihad
            @(posedge pci_clock) ;
6354
        repeat(4)
6355 15 mihad
            @(posedge wb_clock) ;
6356
        if ( INT_O !== 0 )
6357
        begin
6358
            $display("Parity checker testing failed! Time %t ", $time) ;
6359
            $display("Interrupt request asserted for no reason!") ;
6360
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6361
        end
6362
        else
6363
            test_ok ;
6364
    `else
6365
    `ifdef GUEST
6366 26 mihad
        repeat(4)
6367
            @(posedge wb_clock) ;
6368
        repeat(4)
6369 15 mihad
            @(posedge pci_clock) ;
6370
 
6371
        if ( INTA !== 1 )
6372
        begin
6373
            $display("Parity checker testing failed! Time %t ", $time) ;
6374
            $display("Interrupt request asserted for no reason!") ;
6375
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6376
        end
6377
        else
6378
            test_ok ;
6379
    `endif
6380
    `endif
6381
 
6382
    // check statuses!
6383
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6384
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6385
    ok = 1 ;
6386 45 mihad
    if ( temp_val1[31] !== 0 )
6387 15 mihad
    begin
6388
        $display("Parity checker testing failed! Time %t ", $time) ;
6389 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6390
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6391 15 mihad
        ok = 0 ;
6392
    end
6393
 
6394
    if ( temp_val1[30] !== 0 )
6395
    begin
6396
        $display("Parity checker testing failed! Time %t ", $time) ;
6397
        $display("Signalled System Error bit was set for no reason!") ;
6398
        test_fail("Signalled System Error bit was set for no reason") ;
6399
        ok = 0 ;
6400
    end
6401
 
6402
    if ( temp_val1[24] !== 0 )
6403
    begin
6404
        $display("Parity checker testing failed! Time %t ", $time) ;
6405
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6406
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6407
        ok = 0 ;
6408
    end
6409
 
6410
    if ( ok )
6411
        test_ok ;
6412
 
6413
    // clear statuses
6414
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6415
 
6416
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6417
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6418
    ok = 1 ;
6419
    if ( temp_val1[4] !== 0 )
6420
    begin
6421
        $display("Parity checker testing failed! Time %t ", $time) ;
6422
        $display("System error interrupt status bit set when not expected!") ;
6423
        test_fail("System error interrupt status bit set when not expected") ;
6424
        ok = 0 ;
6425
    end
6426
 
6427
    if ( temp_val1[3] !== 0 )
6428
    begin
6429
        $display("Parity checker testing failed! Time %t ", $time) ;
6430
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6431
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6432
        ok = 0 ;
6433
    end
6434
 
6435
    if ( ok )
6436
        test_ok ;
6437
    // clear statuses
6438
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6439
 
6440
    $fdisplay(pci_mon_log_file_desc,
6441
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6442
    test_name = "DISABLE USED IMAGES" ;
6443
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6444
    if ( ok !== 1 )
6445
    begin
6446
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6447
        test_fail("WB Image Address Mask register could not be written to") ;
6448
        disable main ;
6449
    end
6450
 
6451 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6452 15 mihad
    if ( ok !== 1 )
6453
    begin
6454
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6455
        test_fail("PCI Image Address Mask register could not be written to") ;
6456
        disable main ;
6457
    end
6458
 
6459
    // disable target's 1 response to parity errors
6460 45 mihad
    configuration_cycle_write(0,                        // bus number
6461
                              `TAR1_IDSEL_INDEX - 11,   // device number
6462
                              0,                        // function number
6463
                              1,                        // register number
6464
                              0,                        // type of configuration cycle
6465
                              4'b0001,                  // byte enables
6466
                              32'h0000_0007             // data
6467 15 mihad
                             ) ;
6468
 
6469
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6470
end
6471
endtask // parity_checking
6472
 
6473
task wb_to_pci_transactions ;
6474
    reg   [11:0] ctrl_offset ;
6475
    reg   [11:0] ba_offset ;
6476
    reg   [11:0] am_offset ;
6477
    reg   [11:0] pci_ctrl_offset ;
6478
    reg   [11:0] err_cs_offset ;
6479
    reg   [11:0] icr_offset ;
6480
    reg   [11:0] isr_offset ;
6481
    reg   [11:0] lat_tim_cls_offset ;
6482
 
6483
    reg `WRITE_STIM_TYPE  write_data ;
6484
    reg `READ_STIM_TYPE   read_data ;
6485
    reg `READ_RETURN_TYPE read_status ;
6486
 
6487
    reg `WRITE_RETURN_TYPE write_status ;
6488
    reg `WB_TRANSFER_FLAGS write_flags ;
6489
    reg [31:0] temp_val1 ;
6490
    reg [31:0] temp_val2 ;
6491
    reg        ok   ;
6492
 
6493
    reg [31:0] image_base ;
6494
    reg [31:0] target_address ;
6495
    integer i ;
6496
    integer required_reads ;
6497
    integer writes_left ;
6498
 
6499
begin:main
6500
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6501
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6502
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6503
    pci_ctrl_offset    = 12'h4 ;
6504
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6505
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6506
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6507
    lat_tim_cls_offset = 12'hC ;
6508
 
6509
    $display("Checking WB to PCI transaction lengths!") ;
6510
    target_address  = `BEH_TAR1_MEM_START ;
6511
    image_base      = 0 ;
6512
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6513
 
6514
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6515
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6516
    write_flags                    = 0 ;
6517
    write_flags`INIT_WAITS         = tb_init_waits ;
6518
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6519
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6520
 
6521
    // enable master & target operation
6522
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6523
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6524
    if ( ok !== 1 )
6525
    begin
6526
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6527
        test_fail("write to PCI Device Control register failed") ;
6528
        disable main ;
6529
    end
6530
 
6531
    // prepare image control register
6532
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6533
    if ( ok !== 1 )
6534
    begin
6535
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6536
        test_fail("write to WB Image Control register failed") ;
6537
        disable main ;
6538
    end
6539
 
6540
    // prepare base address register
6541
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6542
    if ( ok !== 1 )
6543
    begin
6544
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6545
        test_fail("write to WB Base Address register failed") ;
6546
        disable main ;
6547
    end
6548
 
6549
    // write address mask register
6550
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6551
    if ( ok !== 1 )
6552
    begin
6553
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6554
        test_fail("write to WB Address Mask register failed") ;
6555
        disable main ;
6556
    end
6557
 
6558
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6559
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6560
    if ( ok !== 1 )
6561
    begin
6562
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6563
        test_fail("write to WB Error Control and Status register failed") ;
6564
        disable main ;
6565
    end
6566
 
6567
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6568
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6569
    if ( ok !== 1 )
6570
    begin
6571
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6572
        test_fail("write to Interrupt Control register failed") ;
6573
        disable main ;
6574
    end
6575
 
6576
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6577
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6578
    if ( ok !== 1 )
6579
    begin
6580
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6581
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6582
        disable main ;
6583
    end
6584
 
6585
    $display("Testing single write transaction progress from WB to PCI!") ;
6586
    write_data`WRITE_ADDRESS = target_address ;
6587
    write_data`WRITE_DATA    = wmem_data[0] ;
6588
    write_data`WRITE_SEL     = 4'hF ;
6589
 
6590
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6591
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6592
 
6593
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6594
    fork
6595
    begin
6596
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6597
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6598
        begin
6599
            $display("Transaction progress testing failed! Time %t ", $time) ;
6600
            $display("Bridge failed to process single memory write!") ;
6601
            test_fail("bridge failed to post single memory write") ;
6602
            disable main ;
6603
        end
6604
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6605
    end
6606
    begin
6607
        // wait two retries, then enable target response
6608
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6609
        if ( ok !== 1 )
6610
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6611
        else
6612
            test_ok ;
6613
 
6614
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6615
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6616
        if ( ok !== 1 )
6617
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6618
        else
6619
            test_ok ;
6620
 
6621
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6622
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6623
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6624
 
6625
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6626
        if ( ok !== 1 )
6627
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6628
        else
6629
            test_ok ;
6630
    end
6631
    join
6632
 
6633
    $display("Testing burst write transaction progress from WB to PCI!") ;
6634
    write_data`WRITE_ADDRESS = target_address ;
6635
    write_data`WRITE_DATA    = wmem_data[0] ;
6636
    write_data`WRITE_SEL     = 4'hF ;
6637
 
6638
    wishbone_master.blk_write_data[0] = write_data ;
6639
 
6640
    write_data`WRITE_ADDRESS = target_address + 4 ;
6641
    write_data`WRITE_DATA    = wmem_data[1] ;
6642
    write_data`WRITE_SEL     = 4'hF ;
6643
 
6644
    wishbone_master.blk_write_data[1] = write_data ;
6645
 
6646
    write_flags`WB_TRANSFER_SIZE = 2 ;
6647
    write_flags`WB_TRANSFER_CAB  = 1 ;
6648
 
6649
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6650
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6651
 
6652
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6653
 
6654
    fork
6655
    begin
6656
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6657
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6658
        begin
6659
            $display("Transaction progress testing failed! Time %t ", $time) ;
6660
            $display("Bridge failed to process whole CAB memory write!") ;
6661
            test_fail("bridge failed to post whole CAB memory write") ;
6662
            disable main ;
6663
        end
6664
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6665
    end
6666
    begin
6667
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6668
        if ( ok !== 1 )
6669
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6670
        else
6671
            test_ok ;
6672
 
6673
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6674
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6675
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6676
 
6677
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6678
        if ( ok !== 1 )
6679
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6680
        else
6681
            test_ok ;
6682
 
6683
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6684
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6685
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6686
 
6687
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6688
        if ( ok !== 1 )
6689
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6690
        else
6691
            test_ok ;
6692
    end
6693
    join
6694
 
6695
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6696
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6697
 
6698
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6699
    // try same write with other terminations
6700
    fork
6701
    begin
6702
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6703
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6704
        begin
6705
            $display("Transaction progress testing failed! Time %t ", $time) ;
6706
            $display("Bridge failed to process whole CAB memory write!") ;
6707
            test_fail("bridge failed to post whole CAB memory write") ;
6708
            disable main ;
6709
        end
6710
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6711
    end
6712
    begin
6713
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6714
        if ( ok !== 1 )
6715
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6716
        else
6717
            test_ok ;
6718
 
6719
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6720
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6721
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6722
 
6723
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6724
        if ( ok !== 1 )
6725
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6726
        else
6727
            test_ok ;
6728
    end
6729
    join
6730
 
6731
    // repeat the write with normal completion
6732
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6733
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6734
 
6735
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6736
    fork
6737
    begin
6738
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6739
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6740
        begin
6741
            $display("Transaction progress testing failed! Time %t ", $time) ;
6742
            $display("Bridge failed to process whole CAB memory write!") ;
6743
            test_fail("bridge failed to post whole CAB memory write") ;
6744
            disable main ;
6745
        end
6746
    end
6747
    begin
6748
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6749
        if ( ok !== 1 )
6750
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6751
        else
6752
            test_ok ;
6753
    end
6754
    join
6755
 
6756
    // do the same thing with burst length of 3
6757
    write_data`WRITE_ADDRESS = target_address + 8 ;
6758
    write_data`WRITE_DATA    = wmem_data[2] ;
6759
    write_data`WRITE_SEL     = 4'hF ;
6760
 
6761
    wishbone_master.blk_write_data[2] = write_data ;
6762
 
6763
    write_flags`WB_TRANSFER_SIZE = 3 ;
6764
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6765
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6766
 
6767
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6768
 
6769
    fork
6770
    begin
6771
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6772
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6773
        begin
6774
            $display("Transaction progress testing failed! Time %t ", $time) ;
6775
            $display("Bridge failed to process whole CAB memory write!") ;
6776
            test_fail("bridge failed to post whole CAB memory write") ;
6777
            disable main ;
6778
        end
6779
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6780
    end
6781
    begin
6782
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6783
        if ( ok !== 1 )
6784
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6785
        else
6786
            test_ok ;
6787
 
6788
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6789
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6790
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6791
 
6792
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6793
        if ( ok !== 1 )
6794
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6795
        else
6796
            test_ok ;
6797
    end
6798
    join
6799
 
6800
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6801
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6802
 
6803
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6804
    fork
6805
    begin
6806
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6807
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6808
        begin
6809
            $display("Transaction progress testing failed! Time %t ", $time) ;
6810
            $display("Bridge failed to process whole CAB memory write!") ;
6811
            test_fail("bridge failed to post whole CAB memory write") ;
6812
            disable main ;
6813
        end
6814
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6815
    end
6816
    begin
6817
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6818
        if ( ok !== 1 )
6819
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6820
        else
6821
            test_ok ;
6822
 
6823
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6824
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6825
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6826
 
6827
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6828
        if ( ok !== 1 )
6829
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6830
        else
6831
            test_ok ;
6832
 
6833
    end
6834
    join
6835
 
6836
    // repeat with normal completion
6837
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6838
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6839
 
6840
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6841
    fork
6842
    begin
6843
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6844
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6845
        begin
6846
            $display("Transaction progress testing failed! Time %t ", $time) ;
6847
            $display("Bridge failed to process whole CAB memory write!") ;
6848
            test_fail("bridge failed to post whole CAB memory write") ;
6849
            disable main ;
6850
        end
6851
    end
6852
    begin
6853
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6854
        if ( ok !== 1 )
6855
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6856
        else
6857
            test_ok ;
6858
 
6859
    end
6860
    join
6861
 
6862
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6863
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6864
    begin
6865
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6866
        write_data`WRITE_DATA    = wmem_data[i] ;
6867
        write_data`WRITE_SEL     = 4'hF ;
6868
 
6869
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6870
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6871
 
6872
        wishbone_master.blk_write_data[i]   = write_data ;
6873
        wishbone_master.blk_read_data_in[i] = read_data ;
6874
    end
6875
 
6876
    write_flags`WB_TRANSFER_CAB      = 1 ;
6877
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6878
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6879
 
6880
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6881
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6882
 
6883
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6884
    fork
6885
    begin
6886
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6887
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6888
        begin
6889
            $display("Transaction progress testing failed! Time %t ", $time) ;
6890
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6891
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6892
            test_fail("bridge failed to post whole CAB memory write") ;
6893
            disable main ;
6894
        end
6895
 
6896
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6897
 
6898
        // read here just checks if data was transfered OK
6899
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6900
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6901
 
6902
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6903
 
6904
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6905
        begin
6906
            $display("Transaction progress testing failed! Time %t ", $time) ;
6907
            $display("Bridge processed CAB read wrong!") ;
6908
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
6909
        end
6910
 
6911
    end
6912
    begin
6913
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6914
        if ( ok !== 1 )
6915
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6916
        else
6917
            test_ok ;
6918
 
6919
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
6920
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6921
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6922
 
6923
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6924
        if ( ok !== 1 )
6925
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6926
        else
6927
            test_ok ;
6928
 
6929
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
6930
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6931
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6932
 
6933
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6934
        if ( ok !== 1 )
6935
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6936
        else
6937
            test_ok ;
6938
 
6939
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
6940
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6941
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6942
 
6943
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6944
        if ( ok !== 1 )
6945
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6946
        else
6947
            test_ok ;
6948
 
6949
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
6950
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6951
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6952
 
6953
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
6954
        if ( ok !== 1 )
6955
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6956
        else
6957
            test_ok ;
6958
 
6959
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
6960
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
6961
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
6962
        for ( i = 0 ; i < required_reads ; i = i + 1 )
6963
        begin
6964
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 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
        end
6968
    end
6969
    join
6970
 
6971
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
6972
    begin
6973
        read_status = wishbone_master.blk_read_data_out[i] ;
6974
        if (read_status`READ_DATA !== wmem_data[i])
6975
        begin
6976
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
6977
            test_fail("data read from target wasn't the same as data written to it") ;
6978
            ok = 0 ;
6979
        end
6980
    end
6981
 
6982
    if ( ok )
6983
        test_ok ;
6984
 
6985
    $display("Testing single read transaction progress from WB to PCI!") ;
6986
    read_data`READ_ADDRESS = target_address + 8 ;
6987
    read_data`READ_SEL     = 4'hF ;
6988
 
6989
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6990
 
6991
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
6992
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6993
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6994
 
6995
    fork
6996
    begin
6997
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6998
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6999
        begin
7000
            $display("Transaction progress testing failed! Time %t ", $time) ;
7001
            $display("Bridge processed single read wrong!") ;
7002
            test_fail("bridge processed single read wrong") ;
7003
            disable main ;
7004
        end
7005
 
7006
        if (read_status`READ_DATA !== wmem_data[2])
7007
        begin
7008
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7009
            test_fail("data returned from single read was not as expected") ;
7010
        end
7011
        else
7012
        if ( ok )
7013
            test_ok ;
7014
    end
7015
    begin
7016
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7017
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7018
 
7019
        if ( ok !== 1 )
7020
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7021
 
7022
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7023
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7024
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7025
 
7026
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7027
        if ( ok !== 1 )
7028
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7029
    end
7030
    join
7031
 
7032
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7033
 
7034
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7035
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7036
 
7037
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7038
    // first fill target's memory with enough data to fill WBR_FIFO
7039
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7040
    begin
7041
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7042
        write_data`WRITE_DATA    = wmem_data[i] ;
7043
        write_data`WRITE_SEL     = 4'hF ;
7044
 
7045
        wishbone_master.blk_write_data[i] = write_data ;
7046
    end
7047
 
7048
    write_flags`WB_TRANSFER_CAB = 1 ;
7049
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7050
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7051
 
7052
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7053
 
7054
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7055
    begin
7056
        $display("Transaction progress testing failed! Time %t ", $time) ;
7057
        $display("Bridge processed CAB write wrong!") ;
7058
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7059
        disable main ;
7060
    end
7061
 
7062
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7063
    // perform single read to force write data to pci
7064
    read_data`READ_ADDRESS = target_address + 8;
7065
    read_data`READ_SEL     = 4'hF ;
7066
 
7067
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7068
 
7069
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7070
    begin
7071
        $display("Transaction progress testing failed! Time %t ", $time) ;
7072
        $display("Bridge processed single read wrong!") ;
7073
        test_fail("bridge didn't process single memory read as expected") ;
7074
        disable main ;
7075
    end
7076
 
7077
    wishbone_master.blk_read_data_in[0] = read_data ;
7078
 
7079
    read_data`READ_ADDRESS = target_address + 12 ;
7080
    read_data`READ_SEL     = 4'hF ;
7081
 
7082
    wishbone_master.blk_read_data_in[1] = read_data ;
7083
 
7084
    read_data`READ_ADDRESS = target_address + 16 ;
7085
    read_data`READ_SEL     = 4'hF ;
7086
 
7087
    wishbone_master.blk_read_data_in[2] = read_data ;
7088
 
7089
    write_flags`WB_TRANSFER_CAB  = 1 ;
7090
    write_flags`WB_TRANSFER_SIZE = 2 ;
7091
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7092
    read_status = 0 ;
7093
 
7094
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7095
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7096
 
7097
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7098
 
7099
    ok = 1 ;
7100
    fork
7101
    begin
7102
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7103
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7104
 
7105
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7106
        begin
7107
            $display("Transaction progress testing failed! Time %t ", $time) ;
7108
            $display("Bridge processed CAB read wrong!") ;
7109
            test_fail("bridge didn't process disconnected burst read as expected") ;
7110
        end
7111
        else
7112
        begin
7113
 
7114
            read_status = wishbone_master.blk_read_data_out[0] ;
7115
 
7116
            if (read_status`READ_DATA !== wmem_data[2])
7117
            begin
7118
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7119
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7120
            end
7121
            else
7122
                test_ok ;
7123
        end
7124
 
7125
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7126
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7127
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7128
 
7129
        read_status = 0 ;
7130
 
7131
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7132
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7133
 
7134
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7135
        begin
7136
            $display("Transaction progress testing failed! Time %t ", $time) ;
7137
            $display("Bridge processed CAB read wrong!") ;
7138
            test_fail("bridge didn't process disconnected burst read as expected") ;
7139
        end
7140
        else
7141
        begin
7142
 
7143
            read_status = wishbone_master.blk_read_data_out[0] ;
7144
 
7145
            if (read_status`READ_DATA !== wmem_data[3])
7146
            begin
7147
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7148
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7149
            end
7150
            else
7151
                test_ok ;
7152
        end
7153
 
7154
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7155
        // complete delayed read which was requested
7156
        read_data = wishbone_master.blk_read_data_in[2] ;
7157
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7158
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7159
 
7160
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7161
        begin
7162
            $display("Transaction progress testing failed! Time %t ", $time) ;
7163
            $display("Bridge processed single out of burst read wrong!") ;
7164
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7165
        end
7166
        else
7167
        begin
7168
 
7169
            if (read_status`READ_DATA !== wmem_data[4])
7170
            begin
7171
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7172
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7173
            end
7174
            else
7175
                test_ok ;
7176
        end
7177
 
7178
    end
7179
    begin
7180
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7181
 
7182
        if ( ok !== 1 )
7183
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7184
 
7185
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7186
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7187
 
7188
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7189
        if ( ok !== 1 )
7190
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7191
 
7192
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7193
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7194
 
7195
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7196
        if ( ok !== 1 )
7197
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7198
    end
7199
    join
7200
 
7201
    // now try burst read with normal termination
7202
    read_data`READ_ADDRESS = target_address + 12 ;
7203
    read_data`READ_SEL     = 4'hF ;
7204
 
7205
    wishbone_master.blk_read_data_in[0] = read_data ;
7206
 
7207
    read_data`READ_ADDRESS = target_address + 16 ;
7208
    read_data`READ_SEL     = 4'hF ;
7209
 
7210
    wishbone_master.blk_read_data_in[1] = read_data ;
7211
 
7212
    write_flags`WB_TRANSFER_SIZE = 2 ;
7213
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7214
    write_flags`WB_TRANSFER_CAB = 1 ;
7215
 
7216
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7217
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7218
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7219
 
7220
    fork
7221
    begin
7222
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7223
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7224
        begin
7225
            $display("Transaction progress testing failed! Time %t ", $time) ;
7226
            $display("Bridge processed CAB read wrong!") ;
7227
            test_fail("bridge didn't process burst read as expected") ;
7228
            ok = 0 ;
7229
        end
7230
    end
7231
    begin
7232
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7233
        if ( ok !== 1 )
7234
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7235
    end
7236
    join
7237
 
7238
    if ( ok )
7239
    begin
7240
        read_status = wishbone_master.blk_read_data_out[0] ;
7241
        if ( read_status`READ_DATA !== wmem_data[3] )
7242
        begin
7243
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7244
            test_fail("data provided from normaly terminated read was wrong") ;
7245
            ok = 0 ;
7246
        end
7247
 
7248
        read_status = wishbone_master.blk_read_data_out[1] ;
7249
        if ( read_status`READ_DATA !== wmem_data[4] )
7250
        begin
7251
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7252
            test_fail("data provided from normaly terminated read was wrong") ;
7253
            ok = 0 ;
7254
        end
7255
    end
7256
 
7257
    if ( ok )
7258
        test_ok ;
7259
 
7260
    // disable memory read line command and enable prefetch
7261
    // prepare image control register
7262
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7263
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7264
    if ( ok !== 1 )
7265
    begin
7266
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7267
        test_fail("WB Image Control register couldn't be written to") ;
7268
        disable main ;
7269
    end
7270
 
7271
    write_flags`WB_TRANSFER_SIZE = 4 ;
7272
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7273
    write_flags`WB_TRANSFER_CAB = 1 ;
7274
 
7275
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7276
 
7277
    for ( i = 0 ; i < 4 ; i = i + 1 )
7278
    begin
7279
        read_data`READ_ADDRESS = target_address + i*4 ;
7280
        read_data`READ_SEL     = 4'b1010 ;
7281
 
7282
        wishbone_master.blk_read_data_in[i] = read_data ;
7283
    end
7284
 
7285
    fork
7286
    begin
7287
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7288
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7289
        begin
7290
            $display("Transaction progress testing failed! Time %t ", $time) ;
7291
            $display("Bridge processed CAB read wrong!") ;
7292
            test_fail("bridge didn't process prefetched burst read as expected") ;
7293
            ok = 0 ;
7294
        end
7295
    end
7296
    begin
7297
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7298
        if ( ok !== 1 )
7299
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7300
    end
7301
    join
7302
 
7303
    if ( ok )
7304
    begin
7305
        for ( i = 0 ; i < 4 ; i = i + 1 )
7306
        begin
7307
            read_status = wishbone_master.blk_read_data_out[i] ;
7308
            if ( read_status`READ_DATA !== wmem_data[i] )
7309
            begin
7310
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7311
                test_fail("burst read returned unexpected data") ;
7312
                ok = 0 ;
7313
            end
7314
        end
7315
    end
7316
 
7317
    if ( ok )
7318
        test_ok ;
7319
 
7320
    // do one single read with different byte enables
7321
    read_data`READ_ADDRESS = target_address + 4 ;
7322
    read_data`READ_SEL     = 4'b1010 ;
7323
 
7324
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7325
    fork
7326
    begin
7327
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7328
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7329
        begin
7330
            $display("Transaction progress testing failed! Time %t ", $time) ;
7331
            $display("Bridge processed single read wrong!") ;
7332
            test_fail("bridge didn't process single memory read as expected") ;
7333
            ok = 0 ;
7334
        end
7335
    end
7336
    begin
7337
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7338
        if ( ok !== 1 )
7339
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7340
    end
7341
    join
7342
 
7343
    // check read data
7344
    if ( ok )
7345
    begin
7346
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7347
        begin
7348
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7349
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7350
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7351
            ok = 0 ;
7352
            test_fail("unexpected data received from single read") ;
7353
        end
7354
    end
7355
 
7356
    if ( ok )
7357
         test_ok ;
7358
 
7359
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7360
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7361
 
7362
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7363
    if ( ok !== 1 )
7364
    begin
7365
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7366
        test_fail("WB Image Control register could not be written") ;
7367
        disable main ;
7368
    end
7369
 
7370
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7371
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7372
    begin
7373
        read_data`READ_ADDRESS = target_address + i*4 ;
7374
        read_data`READ_SEL     = 4'b1111 ;
7375
 
7376
        wishbone_master.blk_read_data_in[i] = read_data ;
7377
    end
7378
 
7379
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7380
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7381
    write_flags`WB_TRANSFER_CAB = 1 ;
7382
 
7383
    fork
7384
    begin
7385
        read_status         = 0 ;
7386
        read_status`CYC_RTY = 1 ;
7387
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7388
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7389
 
7390
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7391
        begin
7392
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7393
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7394
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7395
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7396
            ok = 0 ;
7397
        end
7398
    end
7399
    begin
7400
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7401
        if ( ok !== 1 )
7402
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7403
    end
7404
    join
7405
 
7406
    // now repeat single read to flush redundant read initiated
7407
    write_flags`WB_TRANSFER_SIZE = 1 ;
7408
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7409
    write_flags`WB_TRANSFER_CAB = 1 ;
7410
 
7411
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7412
    read_data`READ_SEL     = 4'hF ;
7413
 
7414
    wishbone_master.blk_read_data_in[0] = read_data ;
7415
 
7416
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7417
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7418
 
7419
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7420
    begin
7421
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7422
        $display(" PCI bridge failed to process single CAB read!") ;
7423
        test_fail("single CAB write was not processed as expected") ;
7424
    end
7425
 
7426
    // because last read could be very long on PCI - delete target abort status
7427
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7428
 
7429
    // write unsupported value to cache line size register
7430
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7431
 
7432
    read_data`READ_ADDRESS = target_address ;
7433
    read_data`READ_SEL     = 4'hF ;
7434
    wishbone_master.blk_read_data_in[0] = read_data ;
7435
 
7436
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7437
    // perform a read
7438
    fork
7439
    begin
7440
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7441
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7442
        begin
7443
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7444
            $display(" PCI bridge failed to process single CAB read!") ;
7445
            test_fail("burst read was not processed as expected") ;
7446
            ok = 0 ;
7447
        end
7448
    end
7449
    begin
7450
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7451
        if ( ok !== 1 )
7452
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7453
    end
7454
    join
7455
 
7456
    if ( ok )
7457
        test_ok ;
7458
 
7459
    // write 2 to cache line size register
7460
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7461
 
7462
    // perform a read
7463
    fork
7464
    begin
7465
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7466
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7467
        begin
7468
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7469
            $display(" PCI bridge failed to process single CAB read!") ;
7470
            test_fail("burst read was not processed as expected") ;
7471
            ok = 0 ;
7472
        end
7473
    end
7474
    begin
7475
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7476
        if ( ok !== 1 )
7477
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7478
    end
7479
    join
7480
 
7481
    if ( ok )
7482
        test_ok ;
7483
 
7484
    // write 0 to cache line size
7485
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7486
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7487
 
7488
    // perform a read
7489
    fork
7490
    begin
7491
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7492
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7493
        begin
7494
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7495
            $display(" PCI bridge failed to process single CAB read!") ;
7496
            test_fail("burst read was not processed as expected") ;
7497
            ok = 0 ;
7498
        end
7499
    end
7500
    begin
7501
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7502
        if ( ok !== 1 )
7503
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7504
    end
7505
    join
7506
 
7507
    if ( ok )
7508
        test_ok ;
7509
 
7510
    // write normal value to cls register
7511
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7512
 
7513
    $display("Testing Master's latency timer operation!") ;
7514
    $display("Testing Latency timer during Master Writes!") ;
7515
 
7516
    for ( i = 0 ; i < 6 ; i = i + 1 )
7517
    begin
7518
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7519
        write_data`WRITE_SEL     = 4'b1111 ;
7520
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7521
 
7522
        wishbone_master.blk_write_data[i] = write_data ;
7523
    end
7524
 
7525
    write_flags`WB_TRANSFER_SIZE = 6 ;
7526
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7527
    write_flags`WB_TRANSFER_CAB = 1 ;
7528
 
7529
    // start wb write, pci write and monitor in parallel
7530
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7531
    fork
7532
    begin
7533
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7534
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7535
        begin
7536
            $display("Transaction progress testing failed! Time %t ", $time) ;
7537
            $display("Bridge failed to process CAB write!") ;
7538
            test_fail("bridge didn't post whole burst memory write") ;
7539
            disable main ;
7540
        end
7541
    end
7542
    begin
7543
        // wait for bridge's master to start transaction
7544
        @(posedge pci_clock) ;
7545
        while ( FRAME === 1 )
7546
            @(posedge pci_clock) ;
7547
 
7548
        // start behavioral master request
7549
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7550
               target_address, wmem_data[1023], `Test_All_Bytes,
7551
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7552
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7553
 
7554
        do_pause ( 1 ) ;
7555
    end
7556
    begin
7557
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7558
        if ( ok !== 1 )
7559
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7560
        else
7561
            test_ok ;
7562
    end
7563
    join
7564
 
7565
    // perform a read to check data
7566
    for ( i = 0 ; i < 6 ; i = i + 1 )
7567
    begin
7568
        read_data`READ_ADDRESS = target_address + i*4 ;
7569
        read_data`READ_SEL     = 4'b1111 ;
7570
 
7571
        wishbone_master.blk_read_data_in[i] = read_data ;
7572
    end
7573
 
7574
    write_flags`WB_TRANSFER_SIZE = 6 ;
7575
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7576
    write_flags`WB_TRANSFER_CAB = 1 ;
7577
 
7578
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7579
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7580
 
7581
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7582
    begin
7583
        $display("Transaction progress testing failed! Time %t ", $time) ;
7584
        $display("Bridge failed to process CAB read!") ;
7585
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7586
        disable main ;
7587
    end
7588
 
7589
    ok = 1 ;
7590
    for ( i = 0 ; i < 6 ; i = i + 1 )
7591
    begin
7592
        read_status = wishbone_master.blk_read_data_out[i] ;
7593
 
7594
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7595
        begin
7596
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7597
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7598
            test_fail("unexpected data read back from PCI") ;
7599
            ok = 0 ;
7600
        end
7601
    end
7602
 
7603
    if ( ok )
7604
        test_ok ;
7605
 
7606
    $display("Testing Latency timer during Master Reads!") ;
7607
 
7608
    // at least 2 words are transfered during Master Reads terminated with timeout
7609
    write_flags`WB_TRANSFER_SIZE = 2 ;
7610
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7611
    fork
7612
    begin
7613
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7614
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7615
        begin
7616
            $display("Transaction progress testing failed! Time %t ", $time) ;
7617
            $display("Bridge failed to process CAB read!") ;
7618
            test_fail("bridge didn't process burst read as expected") ;
7619
            ok = 0 ;
7620
        end
7621
    end
7622
    begin
7623
        // wait for bridge's master to start transaction
7624
        @(posedge pci_clock) ;
7625
        while ( FRAME === 1 )
7626
            @(posedge pci_clock) ;
7627
 
7628
        // start behavioral master request
7629
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7630
               target_address, wmem_data[0], `Test_All_Bytes,
7631
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7632
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7633
 
7634
        do_pause ( 1 ) ;
7635
    end
7636
    begin
7637
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7638
        if ( ok !== 1 )
7639
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7640
    end
7641
    join
7642
 
7643
    // check data provided by target
7644
    if ( ok )
7645
    begin
7646
        for ( i = 0 ; i < 2 ; i = i + 1 )
7647
        begin
7648
            read_status = wishbone_master.blk_read_data_out[i] ;
7649
 
7650
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7651
            begin
7652
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7653
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7654
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7655
                ok = 0 ;
7656
            end
7657
        end
7658
    end
7659
    if ( ok )
7660
        test_ok ;
7661
 
7662
    test_name = "DISABLE_IMAGE" ;
7663
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7664
    if ( ok !== 1 )
7665
    begin
7666
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7667
        test_fail("write to WB Address Mask register failed") ;
7668
        disable main ;
7669
    end
7670
 
7671
end
7672
endtask //wb_to_pci_transactions
7673
 
7674
task iack_cycle ;
7675
    reg `READ_STIM_TYPE   read_data ;
7676
    reg `READ_RETURN_TYPE read_status ;
7677
    reg `WB_TRANSFER_FLAGS flags ;
7678
 
7679
    reg [31:0] temp_var ;
7680
    reg ok ;
7681 45 mihad
    reg ok_wb ;
7682
    reg ok_pci ;
7683
 
7684
    reg [31:0] irq_vector ;
7685 15 mihad
begin
7686
 
7687 45 mihad
    ok     = 1 ;
7688
    ok_wb  = 1 ;
7689
    ok_pci = 1 ;
7690
 
7691 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7692
 
7693
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7694
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7695
 
7696
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7697
    read_data`READ_SEL     = 4'hF ;
7698
 
7699
    flags = 0 ;
7700
 
7701
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7702
 
7703
    irq_vector  = 32'hAAAA_AAAA ;
7704
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7705
 
7706 45 mihad
    // disable both pci blue behavioral targets
7707
    configuration_cycle_write
7708
    (
7709
        0,                          // bus number [7:0]
7710
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7711
        0,                          // function number [2:0]
7712
        1,                          // register number [5:0]
7713
        0,                          // type [1:0]
7714
        4'h1,                       // byte enables [3:0]
7715
        32'h0000_0044               // data to write [31:0]
7716
    ) ;
7717
 
7718
    configuration_cycle_write
7719
    (
7720
        0,                          // bus number [7:0]
7721
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7722
        0,                          // function number [2:0]
7723
        1,                          // register number [5:0]
7724
        0,                          // type [1:0]
7725
        4'h1,                       // byte enables [3:0]
7726
        32'h0000_0044               // data to write [31:0]
7727
    ) ;
7728
 
7729 15 mihad
    fork
7730
    begin
7731
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7732
    end
7733
    begin
7734 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7735
        if ( ok_pci !== 1 )
7736 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7737
    end
7738
    join
7739
 
7740
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7741
    begin
7742 45 mihad
        ok_wb = 0 ;
7743 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7744
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7745
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7746
    end
7747 45 mihad
 
7748
    if ( ok_pci && ok_wb )
7749 15 mihad
        test_ok ;
7750 45 mihad
 
7751
    ok_wb = 1 ;
7752
    ok_pci = 1 ;
7753
    ok = 1 ;
7754 15 mihad
 
7755 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7756
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7757 15 mihad
 
7758
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7759 45 mihad
    // enable pci blue behavioral target 1
7760
    configuration_cycle_write
7761
    (
7762
        0,                          // bus number [7:0]
7763
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7764
        0,                          // function number [2:0]
7765
        1,                          // register number [5:0]
7766
        0,                          // type [1:0]
7767
        4'h1,                       // byte enables [3:0]
7768
        32'h0000_0047               // data to write [31:0]
7769
    ) ;
7770 15 mihad
    fork
7771
    begin
7772
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7773
    end
7774
    begin
7775 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7776
        if ( ok_pci !== 1 )
7777 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7778
    end
7779
    join
7780
 
7781
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7782
    begin
7783 45 mihad
        ok_wb = 0 ;
7784 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7785
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7786
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7787
    end
7788
 
7789
    if ( read_status`READ_DATA !== irq_vector )
7790
    begin
7791
        $display(" Time %t ", $time ) ;
7792
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7793
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7794 45 mihad
        ok_wb = 0 ;
7795 15 mihad
    end
7796
 
7797 45 mihad
    if ( ok_pci && ok_wb )
7798 15 mihad
        test_ok ;
7799
 
7800 45 mihad
    ok_pci = 1 ;
7801
    ok_wb  = 1 ;
7802
    ok     = 1 ;
7803
 
7804 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7805 45 mihad
    irq_vector  = 32'h5555_5555 ;
7806
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7807
 
7808 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7809
    fork
7810
    begin
7811
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7812
    end
7813
    begin
7814 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7815
        if ( ok_pci !== 1 )
7816 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7817
    end
7818
    join
7819
 
7820
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7821
    begin
7822
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7823
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7824
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7825 45 mihad
        ok_wb = 0 ;
7826 15 mihad
    end
7827
 
7828 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7829 15 mihad
    begin
7830
        $display(" Time %t ", $time ) ;
7831 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7832 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7833 45 mihad
        ok_wb = 0 ;
7834 15 mihad
    end
7835
 
7836 45 mihad
    if (ok_pci && ok_wb)
7837 15 mihad
        test_ok ;
7838
 
7839 45 mihad
    ok_pci = 1 ;
7840
    ok_wb  = 1 ;
7841
    ok     = 1 ;
7842 15 mihad
 
7843 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7844
 
7845
    // set target to terminate with target abort
7846
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7847
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7848
 
7849
    fork
7850
    begin
7851
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7852
    end
7853
    begin
7854
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7855
        if ( ok_pci !== 1 )
7856
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7857
    end
7858
    join
7859
 
7860
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7861
    begin
7862
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7863
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7864
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7865
        ok_wb = 0 ;
7866
    end
7867
 
7868
    // set target to terminate with target abort
7869
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7870
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7871
 
7872
    // enable pci blue behavioral target 2
7873
    configuration_cycle_write
7874
    (
7875
        0,                          // bus number [7:0]
7876
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7877
        0,                          // function number [2:0]
7878
        1,                          // register number [5:0]
7879
        0,                          // type [1:0]
7880
        4'h1,                       // byte enables [3:0]
7881
        32'h0000_0047               // data to write [31:0]
7882
    ) ;
7883
 
7884
    // read PCI Device status
7885
    config_read(12'h4, 4'hC, temp_var) ;
7886
    if (temp_var[29] !== 1)
7887
    begin
7888
        $display("Time %t", $time) ;
7889
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
7890
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
7891
        ok_wb = 0 ;
7892
    end
7893
 
7894
    if (temp_var[28] !== 1)
7895
    begin
7896
        $display("Time %t", $time) ;
7897
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
7898
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
7899
        ok_wb = 0 ;
7900
    end
7901
 
7902
    // clearing the status bits
7903
        config_write(12'h4, temp_var, 4'hC, ok);
7904
 
7905
    if ( ok && ok_pci && ok_wb )
7906
        test_ok ;
7907
 
7908 15 mihad
end
7909
endtask //iack_cycle
7910
 
7911
task transaction_ordering ;
7912
    reg   [11:0] wb_ctrl_offset ;
7913
    reg   [11:0] wb_ba_offset ;
7914
    reg   [11:0] wb_am_offset ;
7915
    reg   [11:0] pci_ctrl_offset ;
7916
    reg   [11:0] pci_ba_offset ;
7917
    reg   [11:0] pci_am_offset ;
7918
    reg   [11:0] pci_device_ctrl_offset ;
7919
    reg   [11:0] wb_err_cs_offset ;
7920
    reg   [11:0] pci_err_cs_offset ;
7921
    reg   [11:0] icr_offset ;
7922
    reg   [11:0] isr_offset ;
7923
    reg   [11:0] lat_tim_cls_offset ;
7924
 
7925
    reg `WRITE_STIM_TYPE  write_data ;
7926
    reg `READ_STIM_TYPE   read_data ;
7927
    reg `READ_RETURN_TYPE read_status ;
7928
 
7929
    reg `WRITE_RETURN_TYPE write_status ;
7930
    reg `WB_TRANSFER_FLAGS write_flags ;
7931
    reg [31:0] temp_val1 ;
7932
    reg [31:0] temp_val2 ;
7933
    reg        ok   ;
7934
 
7935
    reg [31:0] wb_image_base ;
7936
    reg [31:0] wb_target_address ;
7937
    reg [31:0] pci_image_base ;
7938
    integer i ;
7939
 
7940
    reg     error_monitor_done ;
7941
begin:main
7942
    write_flags`INIT_WAITS = tb_init_waits ;
7943
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
7944
 
7945
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
7946
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
7947
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
7948
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
7949
 
7950
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
7951
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
7952
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
7953
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
7954
 
7955
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
7956
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
7957
    lat_tim_cls_offset = 12'hC ;
7958
    pci_device_ctrl_offset    = 12'h4 ;
7959
 
7960
    wb_target_address  = `BEH_TAR1_MEM_START ;
7961
    wb_image_base      = 0 ;
7962
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
7963
 
7964
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
7965
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
7966
    write_flags                    = 0 ;
7967
    write_flags`INIT_WAITS         = 0 ;
7968
    write_flags`SUBSEQ_WAITS       = 0 ;
7969
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7970
 
7971
    pci_image_base = Target_Base_Addr_R[1] ;
7972
 
7973
    // enable master & target operation
7974
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
7975
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
7976
    if ( ok !== 1 )
7977
    begin
7978
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
7979
        test_fail("write to PCI Device Control register failed") ;
7980
        disable main ;
7981
    end
7982
 
7983
    // prepare image control register
7984
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7985
    if ( ok !== 1 )
7986
    begin
7987
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7988
        test_fail("write to WB Image Control register failed") ;
7989
        disable main ;
7990
    end
7991
 
7992
    // prepare base address register
7993
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
7994
    if ( ok !== 1 )
7995
    begin
7996
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
7997
        test_fail("write to WB Base Address register failed") ;
7998
        disable main ;
7999
    end
8000
 
8001
    // write address mask register
8002
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8003
    if ( ok !== 1 )
8004
    begin
8005
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8006
        test_fail("write to WB Address Mask register failed") ;
8007
        disable main ;
8008
    end
8009
 
8010
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8011
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8012
    if ( ok !== 1 )
8013
    begin
8014
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8015
        test_fail("write to WB Error Control and Status register failed") ;
8016
        disable main ;
8017
    end
8018
 
8019
    // prepare image control register
8020
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8021
    if ( ok !== 1 )
8022
    begin
8023
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8024
        test_fail("write to PCI Image Control register failed") ;
8025
        disable main ;
8026
    end
8027
 
8028
    // prepare base address register
8029
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8030
    if ( ok !== 1 )
8031
    begin
8032
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8033
        test_fail("write to PCI Base Address register failed") ;
8034
        disable main ;
8035
    end
8036
 
8037
    // write address mask register
8038
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8039
    if ( ok !== 1 )
8040
    begin
8041
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8042
        test_fail("write to PCI Address Mask register failed") ;
8043
        disable main ;
8044
    end
8045
 
8046
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8047
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8048
    if ( ok !== 1 )
8049
    begin
8050
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8051
        test_fail("write to PCI Error Control and Status register failed") ;
8052
        disable main ;
8053
    end
8054
 
8055
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8056
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8057
    if ( ok !== 1 )
8058
    begin
8059
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8060
        test_fail("write to Interrupt Control register failed") ;
8061
        disable main ;
8062
    end
8063
 
8064
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8065
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8066
    if ( ok !== 1 )
8067
    begin
8068
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8069
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8070
        disable main ;
8071
    end
8072
 
8073
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8074
 
8075
    // prepare wb_master write and read data
8076
    for ( i = 0 ; i < 4 ; i = i + 1 )
8077
    begin
8078
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8079
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8080
        write_data`WRITE_SEL     = 4'hF ;
8081
 
8082
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8083
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8084
 
8085
        wishbone_master.blk_write_data[i]   = write_data ;
8086
        wishbone_master.blk_read_data_in[i] = read_data ;
8087
    end
8088
 
8089
    // put wishbone slave in acknowledge and pci target in retry mode
8090
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8091
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8092
 
8093
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8094
 
8095
    fork
8096
    begin
8097
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8098
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8099
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8100
        begin
8101
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8102
            test_fail("Bridge didn't post single memory write as expected") ;
8103
        end
8104
 
8105
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8106
        if ( ok !== 1 )
8107
        begin
8108
            $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) ;
8109
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8110
            ok = 0 ;
8111
        end
8112
 
8113
        // now post single write to target - normal progress
8114
        if ( target_mem_image == 1 )
8115
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8116
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8117
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8118
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8119
        else
8120
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8121
 
8122
        do_pause( 1 ) ;
8123
 
8124
    end
8125
    begin:error_monitor_1
8126 35 mihad
        error_monitor_done = 0 ;
8127 15 mihad
        @(error_event_int) ;
8128
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8129
        ok = 0 ;
8130 35 mihad
        error_monitor_done = 1 ;
8131 15 mihad
    end
8132
    begin
8133
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8134
        if ( ok !== 1 )
8135
        begin
8136
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8137
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8138
        end
8139
        else
8140
        begin
8141 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8142
//            while ( FRAME === 0 || IRDY === 0 )
8143
//                @(posedge pci_clock) ;
8144 15 mihad
 
8145
            // enable response in PCI target
8146
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8147
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8148
 
8149
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8150
            if ( ok !== 1 )
8151
            begin
8152
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8153
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8154
            end
8155
        end
8156
 
8157 35 mihad
        #1 ;
8158
        if ( !error_monitor_done )
8159
            disable error_monitor_1 ;
8160 15 mihad
    end
8161
    join
8162
 
8163
    if ( ok )
8164
        test_ok ;
8165
 
8166
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8167
 
8168
    // put WISHBONE slave in retry mode
8169
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8170
 
8171
    fork
8172
    begin
8173
        // now post single write to target - normal progress
8174
        if ( target_mem_image == 1 )
8175
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8176
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8177
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8178
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8179
        else
8180
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8181
 
8182
        do_pause( 1 ) ;
8183
 
8184
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8185
        if ( ok !== 1 )
8186
        begin
8187
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8188
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8189
        end
8190
 
8191
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8192
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8193
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8194
        begin
8195
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8196
            test_fail("Bridge didn't post single memory write as expected") ;
8197
        end
8198
 
8199
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8200
        if ( ok !== 1 )
8201
        begin
8202
            $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) ;
8203
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8204
            ok = 0 ;
8205
        end
8206
 
8207
        wait ( CYC_O === 0 ) ;
8208
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8209
 
8210
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8211
        if ( ok !== 1 )
8212
        begin
8213
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8214
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8215
        end
8216
 
8217 35 mihad
        #1 ;
8218
        if ( !error_monitor_done )
8219
            disable error_monitor_2 ;
8220 15 mihad
    end
8221
    begin:error_monitor_2
8222 35 mihad
        error_monitor_done = 0 ;
8223 15 mihad
        @(error_event_int) ;
8224
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8225
        ok = 0 ;
8226 35 mihad
        error_monitor_done = 1 ;
8227 15 mihad
    end
8228
    join
8229
 
8230
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8231
 
8232
    // put wishbone slave in acknowledge and pci target in retry mode
8233
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8234
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8235
 
8236
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8237
 
8238
    fork
8239
    begin
8240
        write_flags`WB_TRANSFER_SIZE = 3 ;
8241
        write_flags`WB_TRANSFER_CAB  = 1 ;
8242
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8243
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8244
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8245
        begin
8246
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8247
            test_fail("Bridge didn't post burst memory write as expected") ;
8248
        end
8249
 
8250
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8251
        if ( ok !== 1 )
8252
        begin
8253
            $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) ;
8254
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8255
            ok = 0 ;
8256
        end
8257
 
8258
        // now post single write to target - normal progress
8259
        if ( target_mem_image == 1 )
8260
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8261
                        pci_image_base, 32'h5555_5555, 4'h0,
8262
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8263
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8264
        else
8265
        begin
8266
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8267
            do_pause( 1 ) ;
8268
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8269
        end
8270
 
8271
        do_pause( 1 ) ;
8272
 
8273
    end
8274
    begin:error_monitor_3
8275 35 mihad
        error_monitor_done = 0 ;
8276 15 mihad
        @(error_event_int) ;
8277
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8278
        ok = 0 ;
8279 35 mihad
        error_monitor_done = 1 ;
8280 15 mihad
    end
8281
    begin
8282
        if ( target_mem_image == 1 )
8283
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8284
        else
8285
        begin
8286
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8287
            if ( ok )
8288
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8289
        end
8290
 
8291
        if ( ok !== 1 )
8292
        begin
8293
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8294
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8295
        end
8296
        else
8297
        begin
8298 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8299
//            while ( FRAME === 0 || IRDY === 0 )
8300
//                @(posedge pci_clock) ;
8301 15 mihad
 
8302
            // enable response in PCI target
8303
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8304
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8305
 
8306
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8307
            if ( ok !== 1 )
8308
            begin
8309
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8310
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8311
            end
8312
        end
8313
 
8314 35 mihad
        #1 ;
8315
        if ( !error_monitor_done )
8316
            disable error_monitor_3 ;
8317 15 mihad
    end
8318
    join
8319
 
8320
    if ( ok )
8321
        test_ok ;
8322
 
8323
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8324
 
8325
    // put WISHBONE slave in retry mode
8326
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8327
 
8328
    fork
8329
    begin
8330
        // now post single write to target - normal progress
8331
        if ( target_mem_image == 1 )
8332
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8333
                        pci_image_base, 32'h5555_5555, 4'h0,
8334
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8335
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8336
        else
8337
        begin
8338
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8339
            do_pause( 1 ) ;
8340
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8341
        end
8342
 
8343
        do_pause( 1 ) ;
8344
 
8345
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8346
 
8347
        if ( ok !== 1 )
8348
        begin
8349
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8350
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8351
        end
8352
 
8353
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8354
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8355
        write_flags`WB_TRANSFER_CAB      = 1 ;
8356
 
8357
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8358
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8359
        begin
8360
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8361
            test_fail("Bridge didn't post burst memory write as expected") ;
8362
        end
8363
 
8364
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8365
        if ( ok !== 1 )
8366
        begin
8367
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after burst memory write was posted! Time %t ", $time) ;
8368
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8369
            ok = 0 ;
8370
        end
8371
 
8372
        @(posedge wb_clock) ;
8373
        while ( CYC_O === 1 )
8374
            @(posedge wb_clock) ;
8375
 
8376
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8377
 
8378
        if ( target_mem_image == 1 )
8379
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8380
        else
8381
        begin
8382
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8383
            if ( ok )
8384
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8385
        end
8386
 
8387 35 mihad
        #1 ;
8388
        if ( !error_monitor_done )
8389
            disable error_monitor_4 ;
8390 15 mihad
    end
8391
    begin:error_monitor_4
8392 35 mihad
        error_monitor_done = 0 ;
8393 15 mihad
        @(error_event_int) ;
8394
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8395
        ok = 0 ;
8396 35 mihad
        error_monitor_done = 1 ;
8397 15 mihad
    end
8398
    join
8399
 
8400
    if ( ok )
8401
        test_ok ;
8402
 
8403
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8404
 
8405
    // put wishbone slave in acknowledge and pci target in retry mode
8406
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8407
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8408
 
8409
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8410
 
8411
    master1_check_received_data = 1 ;
8412
 
8413
    error_monitor_done = 0 ;
8414
    fork
8415
    begin:error_monitor_5
8416
        @(error_event_int or error_monitor_done) ;
8417
        if ( !error_monitor_done )
8418
        begin
8419
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8420
            ok = 0 ;
8421
        end
8422
    end
8423
    begin
8424
 
8425
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8426
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8427
        begin
8428
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8429
            test_fail("Bridge didn't post single memory write as expected") ;
8430
        end
8431
 
8432
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8433
        if ( ok !== 1 )
8434
        begin
8435
            $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) ;
8436
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8437
            ok = 0 ;
8438
        end
8439
 
8440
        // start Read Through pci target
8441
        if ( target_mem_image == 1 )
8442
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8443
                          pci_image_base, 32'h5555_5555,
8444
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8445
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8446
        else
8447
            PCIU_IO_READ
8448
             (
8449
                `Test_Master_1,
8450
                pci_image_base,
8451
                32'h5555_5555,
8452
                4'h0,
8453
                1,
8454
                `Test_Target_Retry_On
8455
             );
8456
 
8457
         do_pause( 1 ) ;
8458
 
8459
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8460
         if ( ok !== 1 )
8461
         begin
8462
            $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) ;
8463
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8464
         end
8465
 
8466
         // repeat the read 4 times - it should be retried all the time by pci target
8467
        for ( i = 0 ; i < 4 ; i = i + 1 )
8468
        begin
8469
            if ( target_mem_image == 1 )
8470
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8471
                            pci_image_base, 32'h5555_5555,
8472
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8473
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8474
            else
8475
                PCIU_IO_READ
8476
                (
8477
                    `Test_Master_1,
8478
                    pci_image_base,
8479
                    32'h5555_5555,
8480
                    4'h0,
8481
                    1,
8482
                    `Test_Target_Retry_On
8483
                );
8484
 
8485
            do_pause( 1 ) ;
8486
        end
8487
 
8488
        // now do posted write through target - it must go through OK
8489
        if ( target_mem_image == 1 )
8490
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8491
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8492
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8493
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8494
        else
8495
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8496
 
8497
        do_pause( 1 ) ;
8498
 
8499
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8500
        if ( ok !== 1 )
8501
        begin
8502
           $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) ;
8503
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8504
        end
8505
 
8506
        // start a read through wb_slave
8507
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8508
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8509
        begin
8510
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8511
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8512
            ok = 0 ;
8513
        end
8514
 
8515 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8516
//        while ( FRAME === 0 || IRDY === 0 )
8517
//            @(posedge pci_clock) ;
8518 15 mihad
 
8519
        // set the target to normal completion
8520
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8521
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8522
 
8523
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8524
        if ( ok !== 1 )
8525
        begin
8526
            $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) ;
8527
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8528
            ok = 0 ;
8529
        end
8530
 
8531
        // now wait for delayed read to finish
8532
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8533
        if ( ok !== 1 )
8534
        begin
8535
            $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) ;
8536
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8537
            ok = 0 ;
8538
        end
8539
 
8540
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8541
        fork
8542
        begin
8543
                if ( target_mem_image == 1 )
8544
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8545
                                pci_image_base, 32'h5555_5555, 4'h0,
8546
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8547
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8548
                else
8549
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8550
 
8551
                do_pause( 1 ) ;
8552
                end
8553
                begin
8554
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8555
                end
8556
                join
8557
 
8558
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8559
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8560
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8561
        begin
8562
            $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) ;
8563
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8564
            ok = 0 ;
8565
        end
8566
 
8567
        fork
8568
        begin
8569
        // now complete a read from PCI Target
8570
            if ( target_mem_image == 1 )
8571
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8572
                            pci_image_base, 32'h5555_5555,
8573
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8574
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8575
            else
8576
                PCIU_IO_READ
8577
                (
8578
                    `Test_Master_1,
8579
                    pci_image_base,
8580
                    32'h5555_5555,
8581
                    4'h0,
8582
                    1,
8583
                    `Test_Target_Normal_Completion
8584
                );
8585
 
8586
            do_pause( 1 ) ;
8587
        end
8588
        begin
8589
            if ( target_mem_image == 1 )
8590
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8591
            else
8592
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8593
        end
8594
        join
8595
 
8596
        @(posedge pci_clock) ;
8597
        repeat( 4 )
8598
            @(posedge wb_clock) ;
8599
 
8600
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8601
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8602
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8603
        begin
8604
            $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) ;
8605
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8606
            ok = 0 ;
8607
        end
8608
 
8609
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8610
        if ( ok !== 1 )
8611
        begin
8612
            $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) ;
8613
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8614
            ok = 0 ;
8615
        end
8616
 
8617
        // finish a read on WISHBONE also
8618
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8619
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8620
        begin
8621
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8622
            test_fail("WB Slave didn't process single delayed read as expected") ;
8623
        end
8624
 
8625
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8626
        begin
8627
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8628
            ok = 0 ;
8629
        end
8630
 
8631
 
8632
        error_monitor_done = 1 ;
8633
    end
8634
    join
8635
 
8636
    if ( ok )
8637
        test_ok ;
8638
 
8639
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8640
 
8641
    // put wishbone slave in retry and pci target in completion mode
8642
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8643
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8644
 
8645
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8646
 
8647
    master1_check_received_data = 1 ;
8648
 
8649
    error_monitor_done = 0 ;
8650
    fork
8651
    begin:error_monitor_6
8652
        @(error_event_int or error_monitor_done) ;
8653
        if ( !error_monitor_done )
8654
        begin
8655
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8656
            ok = 0 ;
8657
        end
8658
    end
8659
    begin
8660
 
8661
        // do a write through Target
8662
        fork
8663
        begin
8664
            if ( target_mem_image == 1 )
8665
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8666
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8667
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8668
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8669
            else
8670
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8671
 
8672
            do_pause( 1 ) ;
8673
        end
8674
        begin
8675
            if ( target_mem_image == 1 )
8676
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8677
            else
8678
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8679
        end
8680
        join
8681
 
8682
        // start a read through WB slave
8683
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8684
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8685
        begin
8686
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8687
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8688
            ok = 0 ;
8689
        end
8690
 
8691
        // now wait for this read to finish on pci
8692
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8693
        if ( ok !== 1 )
8694
        begin
8695
            $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) ;
8696
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8697
            ok = 0 ;
8698
        end
8699
 
8700
        // repeat the read four times - it should be retried
8701
        for ( i = 0 ; i < 4 ; i = i + 1 )
8702
        begin
8703
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8704
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8705
            begin
8706
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8707
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8708
                ok = 0 ;
8709
            end
8710
        end
8711
 
8712
        // posted write through WB Slave - must go through
8713
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8714
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8715
        begin
8716
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8717
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8718
            ok = 0 ;
8719
        end
8720
 
8721
        // write must come through
8722
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8723
        if ( ok !== 1 )
8724
        begin
8725
            $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) ;
8726
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8727
            ok = 0 ;
8728
        end
8729
 
8730
        // do a read through pci target
8731
        if ( target_mem_image == 1 )
8732
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8733
                          pci_image_base + 12, 32'hDEAD_BEAF,
8734
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8735
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8736
        else
8737
            PCIU_IO_READ
8738
             (
8739
                `Test_Master_1,
8740
                pci_image_base + 12,
8741
                32'hDEAD_BEAF,
8742
                4'h0,
8743
                1,
8744
                `Test_Target_Retry_On
8745
             );
8746
 
8747
         do_pause( 1 ) ;
8748
 
8749
        // wait for current cycle to finish on WB
8750 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8751
//        @(posedge wb_clock) ;
8752
//        while( CYC_O === 1 )
8753
//            @(posedge wb_clock) ;
8754 15 mihad
 
8755
        // set slave response to acknowledge
8756
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8757
 
8758
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8759
        if ( ok !== 1 )
8760
        begin
8761
            $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) ;
8762
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8763
        end
8764
 
8765
        // check the read to finish on wb
8766
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8767
        if ( ok !== 1 )
8768
        begin
8769
            $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) ;
8770
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8771
        end
8772
 
8773
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8774
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8775
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8776
        begin
8777
            $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) ;
8778
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8779
            ok = 0 ;
8780
        end
8781
 
8782
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8783
        fork
8784
        begin
8785
            if ( target_mem_image == 1 )
8786
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8787
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8788
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8789
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8790
            else
8791
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8792
        end
8793
        begin
8794
            if ( target_mem_image == 1 )
8795
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8796
            else
8797
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8798
        end
8799
        join
8800
 
8801
        do_pause( 1 ) ;
8802
 
8803
        // complete a read in WB Slave Unit
8804
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8805
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8806
        begin
8807
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8808
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8809
            ok = 0 ;
8810
        end
8811
 
8812
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8813
        begin
8814
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8815
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8816
            ok = 0 ;
8817
        end
8818
 
8819
        // wait for statuses to be propagated from one side of bridge to another
8820
        repeat( 4 )
8821
            @(posedge pci_clock) ;
8822
 
8823
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8824
        fork
8825
        begin
8826
            if ( target_mem_image == 1 )
8827
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8828
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8829
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8830
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8831
            else
8832
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8833
 
8834
            do_pause( 1 ) ;
8835
        end
8836
        begin
8837
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8838
            if ( ok !== 1 )
8839
            begin
8840
                $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) ;
8841
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8842
            end
8843
        end
8844
        join
8845
 
8846
        // finish the last read in PCI Target Unit
8847
        if ( target_mem_image == 1 )
8848
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8849
                          pci_image_base + 12, 32'hDEAD_BEAF,
8850
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8851
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8852
        else
8853
            PCIU_IO_READ
8854
             (
8855
                `Test_Master_1,
8856
                pci_image_base + 12,
8857
                32'hDEAD_BEAF,
8858
                4'h0,
8859
                1,
8860
                `Test_Target_Normal_Completion
8861
             );
8862
 
8863
         do_pause( 1 ) ;
8864
 
8865
         error_monitor_done = 1 ;
8866
    end
8867
    join
8868
 
8869
    if ( ok )
8870
        test_ok ;
8871
 
8872
end
8873
endtask // transaction_ordering
8874
 
8875
task pci_transaction_progress_monitor ;
8876
    input [31:0] address ;
8877
    input [3:0]  bus_command ;
8878
    input [31:0] num_of_transfers ;
8879
    input [31:0] num_of_cycles ;
8880
    input check_transfers ;
8881
    input check_cycles ;
8882
    input doing_fast_back_to_back ;
8883
    output ok ;
8884
    reg in_use ;
8885
    integer deadlock_counter ;
8886
    integer transfer_counter ;
8887
    integer cycle_counter ;
8888
    integer deadlock_max_val ;
8889
begin:main
8890
 
8891
    if ( in_use === 1 )
8892
    begin
8893
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8894
        ok = 0 ;
8895
        disable main ;
8896
    end
8897
 
8898
    // approximate number of cycles on WB bus for maximum transaction length
8899
    deadlock_max_val = tb_init_waits + 100 +
8900
                       `WBW_DEPTH *
8901
                       (tb_subseq_waits + 1 +
8902
                       `ifdef REGISTER_WBS_OUTPUTS
8903
                       1) ;
8904
                       `else
8905
                       0) ;
8906
                       `endif
8907
 
8908
    // time used for maximum transaction length on WB
8909
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
8910
 
8911
    // maximum pci clock cycles
8912
    `ifdef PCI33
8913
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
8914
    `else
8915
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
8916
    `endif
8917
 
8918
    in_use = 1 ;
8919
    ok     = 1 ;
8920
 
8921
    fork
8922
    begin:wait_start
8923
 
8924
        deadlock_counter = 0 ;
8925
 
8926
        @(posedge pci_clock) ;
8927
 
8928
        if ( doing_fast_back_to_back !== 1 )
8929
        begin
8930
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
8931
            begin
8932 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
8933
                    deadlock_counter = 0 ;
8934
                else
8935
                    deadlock_counter = deadlock_counter + 1 ;
8936 15 mihad
                @(posedge pci_clock) ;
8937
            end
8938
            if ( FRAME !== 1 )
8939
            begin
8940
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8941
                in_use = 0 ;
8942
                ok     = 0 ;
8943
                disable main ;
8944
            end
8945
        end
8946
 
8947
        deadlock_counter = 0 ;
8948
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
8949
        begin
8950
            deadlock_counter = deadlock_counter + 1 ;
8951
            @(posedge pci_clock) ;
8952
        end
8953
 
8954
        if ( FRAME !== 0 )
8955
        begin
8956
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8957
            in_use = 0 ;
8958
            ok     = 0 ;
8959
            disable main ;
8960
        end
8961
    end //wait_start
8962
 
8963
    begin:addr_bc_monitor
8964
 
8965
        @(posedge pci_clock) ;
8966
 
8967
        if ( doing_fast_back_to_back !== 1 )
8968
        begin
8969
            while ( FRAME !== 1 )
8970
                @(posedge pci_clock) ;
8971
        end
8972
 
8973
        while( FRAME !== 0 )
8974
            @(posedge pci_clock) ;
8975
 
8976
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
8977
        if ( bus_command !== `BC_IACK )
8978
        begin
8979
            if ( AD !== address )
8980
            begin
8981
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
8982
                $display("Expected address = %h, detected address = %h ", address, AD) ;
8983
                ok = 0 ;
8984
            end
8985
        end
8986
 
8987
        if ( CBE !== bus_command )
8988
        begin
8989
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
8990
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
8991
            ok = 0 ;
8992
        end
8993
    end //addr_bc_monitor
8994
 
8995
    begin:transfer_checker
8996
        transfer_counter = 0 ;
8997
 
8998
        @(posedge pci_clock) ;
8999
 
9000
        if ( doing_fast_back_to_back !== 1 )
9001
        begin
9002
            while ( FRAME !== 1 )
9003
                @(posedge pci_clock) ;
9004
        end
9005
 
9006
        while( FRAME !== 0 )
9007
            @(posedge pci_clock) ;
9008
 
9009
        while( FRAME === 0 )
9010
        begin
9011
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
9012
                transfer_counter = transfer_counter + 1 ;
9013
            @(posedge pci_clock) ;
9014
        end
9015
 
9016
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
9017
        begin
9018
            @(posedge pci_clock) ;
9019
        end
9020
 
9021
        if ( (TRDY === 0) && (DEVSEL === 0) )
9022
                transfer_counter = transfer_counter + 1 ;
9023
 
9024
        if ( check_transfers === 1 )
9025
        begin
9026
            if ( transfer_counter !== num_of_transfers )
9027
            begin
9028
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9029
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9030
                ok = 0 ;
9031
            end
9032
        end
9033
    end //transfer_checker
9034
    begin:cycle_checker
9035
        if ( check_cycles )
9036
        begin
9037
            cycle_counter = 0 ;
9038
            @(posedge pci_clock) ;
9039
 
9040
            if ( doing_fast_back_to_back !== 1)
9041
            begin
9042
                while ( FRAME !== 1 )
9043
                    @(posedge pci_clock) ;
9044
            end
9045
 
9046
            while( FRAME !== 0 )
9047
                @(posedge pci_clock) ;
9048
 
9049
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9050
            begin
9051
                cycle_counter = cycle_counter + 1 ;
9052
                @(posedge pci_clock) ;
9053
            end
9054
 
9055
            if ( FRAME !== 1 )
9056
            begin
9057
                while ((FRAME === 0) && (MAS0_GNT === 0))
9058
                    @(posedge pci_clock) ;
9059
 
9060
                if ( FRAME !== 1 )
9061
                begin
9062
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9063
                        @(posedge pci_clock) ;
9064
 
9065
                    @(posedge pci_clock) ;
9066
 
9067
                    if ( FRAME !== 1 )
9068
                    begin
9069
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9070
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9071
                        ok = 0 ;
9072
                    end
9073
                end
9074
            end
9075
        end
9076
    end // cycle_checker
9077
    join
9078
 
9079
    in_use = 0 ;
9080
end
9081
endtask //pci_transaction_progress_monitor
9082
 
9083
reg CYC_O_previous ;
9084
always@(posedge wb_clock or posedge reset)
9085
begin
9086
    if ( reset )
9087
        CYC_O_previous <= #1 1'b0 ;
9088
    else
9089
        CYC_O_previous <= #1 CYC_O ;
9090
end
9091
 
9092
task wb_transaction_progress_monitor ;
9093
    input [31:0] address ;
9094
    input        write ;
9095
    input [31:0] num_of_transfers ;
9096
    input check_transfers ;
9097
    output ok ;
9098
    reg in_use ;
9099
    integer deadlock_counter ;
9100
    integer transfer_counter ;
9101
    integer deadlock_max_val ;
9102
begin:main
9103
    if ( in_use === 1 )
9104
    begin
9105
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9106
        ok = 0 ;
9107
        disable main ;
9108
    end
9109
 
9110
    // number of cycles on WB bus for maximum transaction length
9111
    deadlock_max_val = 4 - tb_init_waits + 100 +
9112
                       `PCIW_DEPTH *
9113
                       (4 - tb_subseq_waits + 1) ;
9114
 
9115
    // time used for maximum transaction length on PCI
9116
    `ifdef PCI33
9117
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9118
    `else
9119
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9120
    `endif
9121
 
9122
    // maximum wb clock cycles
9123
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9124
 
9125
    in_use = 1 ;
9126
    ok     = 1 ;
9127
 
9128
    fork
9129
    begin:wait_start
9130
        deadlock_counter = 0 ;
9131
        @(posedge wb_clock) ;
9132
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9133
        begin
9134 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9135
                deadlock_counter = deadlock_counter + 1 ;
9136
            else
9137
                deadlock_counter = 0;
9138 15 mihad
            @(posedge wb_clock) ;
9139
        end
9140
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9141
        begin
9142
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9143
            in_use = 0 ;
9144
            ok     = 0 ;
9145
            disable main ;
9146
        end
9147
 
9148
        deadlock_counter = 0 ;
9149
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9150
        begin
9151
            deadlock_counter = deadlock_counter + 1 ;
9152
            @(posedge wb_clock) ;
9153
        end
9154
 
9155
        if ( CYC_O !== 1 )
9156
        begin
9157
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9158
            in_use = 0 ;
9159
            ok     = 0 ;
9160
            disable main ;
9161
        end
9162
    end //wait_start
9163
    begin:addr_monitor
9164
        @(posedge wb_clock) ;
9165
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9166
            @(posedge wb_clock) ;
9167
 
9168
        while( CYC_O !== 1 )
9169
            @(posedge wb_clock) ;
9170
 
9171
        while (STB_O !== 1 )
9172
            @(posedge wb_clock) ;
9173
 
9174
        if ( WE_O !== write )
9175
        begin
9176
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9177
            if ( write !== 1 )
9178
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9179
            else
9180
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9181
        end
9182
 
9183
        if ( ADR_O !== address )
9184
        begin
9185
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9186
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9187
            ok = 0 ;
9188
        end
9189
    end
9190
    begin:transfer_checker
9191
        transfer_counter = 0 ;
9192
        @(posedge wb_clock) ;
9193
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9194
            @(posedge wb_clock) ;
9195
 
9196
        while( CYC_O !== 1 )
9197
            @(posedge wb_clock) ;
9198
 
9199
        while( CYC_O === 1 )
9200
        begin
9201
            if ( (STB_O === 1) && (ACK_I === 1) )
9202
                transfer_counter = transfer_counter + 1 ;
9203
            @(posedge wb_clock) ;
9204
        end
9205
 
9206
        if ( check_transfers === 1 )
9207
        begin
9208
            if ( transfer_counter !== num_of_transfers )
9209
            begin
9210
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9211
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9212
                ok = 0 ;
9213
            end
9214
        end
9215
    end //transfer_checker
9216
    join
9217
 
9218
    in_use = 0 ;
9219
end
9220
endtask // wb_transaction_progress_monitor
9221
 
9222
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9223
// so they are not re-entered
9224
task wb_transaction_progress_monitor_backup ;
9225
    input [31:0] address ;
9226
    input        write ;
9227
    input [31:0] num_of_transfers ;
9228
    input check_transfers ;
9229
    output ok ;
9230
    reg in_use ;
9231
    integer deadlock_counter ;
9232
    integer transfer_counter ;
9233
    integer deadlock_max_val ;
9234
begin:main
9235
    if ( in_use === 1 )
9236
    begin
9237
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9238
        ok = 0 ;
9239
        disable main ;
9240
    end
9241
 
9242
    // number of cycles on WB bus for maximum transaction length
9243
    deadlock_max_val = 4 - tb_init_waits + 100 +
9244
                       `PCIW_DEPTH *
9245
                       (4 - tb_subseq_waits + 1) ;
9246
 
9247
    // time used for maximum transaction length on PCI
9248
    `ifdef PCI33
9249
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9250
    `else
9251
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9252
    `endif
9253
 
9254
    // maximum wb clock cycles
9255
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9256
 
9257
    in_use = 1 ;
9258
    ok     = 1 ;
9259
 
9260
    fork
9261
    begin:wait_start
9262
        deadlock_counter = 0 ;
9263
        @(posedge wb_clock) ;
9264
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9265
        begin
9266 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9267
                deadlock_counter = deadlock_counter + 1 ;
9268
            else
9269
                deadlock_counter = 0;
9270 15 mihad
            @(posedge wb_clock) ;
9271
        end
9272
        if ( CYC_O !== 0 )
9273
        begin
9274
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9275
            in_use = 0 ;
9276
            ok     = 0 ;
9277
            disable main ;
9278
        end
9279
 
9280
        deadlock_counter = 0 ;
9281
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9282
        begin
9283
            deadlock_counter = deadlock_counter + 1 ;
9284
            @(posedge wb_clock) ;
9285
        end
9286
 
9287
        if ( CYC_O !== 1 )
9288
        begin
9289
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9290
            in_use = 0 ;
9291
            ok     = 0 ;
9292
            disable main ;
9293
        end
9294
    end //wait_start
9295
    begin:addr_monitor
9296
        @(posedge wb_clock) ;
9297
        while ( CYC_O !== 0 )
9298
            @(posedge wb_clock) ;
9299
 
9300
        while( CYC_O !== 1 )
9301
            @(posedge wb_clock) ;
9302
 
9303
        while (STB_O !== 1 )
9304
            @(posedge wb_clock) ;
9305
 
9306
        if ( WE_O !== write )
9307
        begin
9308
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9309
            if ( write !== 1 )
9310
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9311
            else
9312
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9313
        end
9314
 
9315
        if ( ADR_O !== address )
9316
        begin
9317
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9318
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9319
            ok = 0 ;
9320
        end
9321
    end
9322
    begin:transfer_checker
9323
        transfer_counter = 0 ;
9324
        @(posedge wb_clock) ;
9325
        while ( CYC_O !== 0 )
9326
            @(posedge wb_clock) ;
9327
 
9328
        while( CYC_O !== 1 )
9329
            @(posedge wb_clock) ;
9330
 
9331
        while( CYC_O === 1 )
9332
        begin
9333
            if ( (STB_O === 1) && (ACK_I === 1) )
9334
                transfer_counter = transfer_counter + 1 ;
9335
            @(posedge wb_clock) ;
9336
        end
9337
 
9338
        if ( check_transfers === 1 )
9339
        begin
9340
            if ( transfer_counter !== num_of_transfers )
9341
            begin
9342
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9343
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9344
                ok = 0 ;
9345
            end
9346
        end
9347
    end //transfer_checker
9348
    join
9349
 
9350
    in_use = 0 ;
9351
end
9352
endtask // wb_transaction_progress_monitor_backup
9353
 
9354
task wb_transaction_stop ;
9355
    input [31:0] num_of_transfers ;
9356
    integer transfer_counter ;
9357
begin:main
9358
    begin:transfer_checker
9359
        transfer_counter = 0 ;
9360
        @(posedge wb_clock) ;
9361
        while ( CYC_O !== 0 )
9362
            @(posedge wb_clock) ;
9363
 
9364
        while( CYC_O !== 1 )
9365
            @(posedge wb_clock) ;
9366
 
9367
        if ( (STB_O === 1) && (ACK_I === 1) )
9368
            transfer_counter = transfer_counter + 1 ;
9369
 
9370
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9371
        begin
9372
            @(posedge wb_clock) ;
9373
            if ( (STB_O === 1) && (ACK_I === 1) )
9374
                transfer_counter = transfer_counter + 1 ;
9375
        end
9376
    end //transfer_checker
9377
end
9378
endtask // wb_transaction_stop
9379
 
9380
task musnt_respond ;
9381
    output ok ;
9382
    reg in_use ;
9383
    integer i ;
9384
begin:main
9385
    if ( in_use === 1 )
9386
    begin
9387
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9388
        #20 $stop ;
9389
        ok = 0 ;
9390
        disable main ;
9391
    end
9392
 
9393
    in_use = 1 ;
9394
    ok = 1 ;
9395
 
9396
    fork
9397
    begin:wait_start
9398
        @(negedge FRAME) ;
9399
        disable count ;
9400
    end
9401
    begin:count
9402
        i = 0 ;
9403
        while ( i < 1000 )
9404
        begin
9405
            @(posedge pci_clock) ;
9406
            i = i + 1 ;
9407
        end
9408
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9409
        ok = 0 ;
9410
        disable wait_start ;
9411
    end
9412
    join
9413
 
9414
    @(posedge pci_clock) ;
9415
    while ( FRAME === 0 && ok )
9416
    begin
9417
        if ( DEVSEL !== 1 )
9418
        begin
9419
            ok = 0 ;
9420
        end
9421
        @(posedge pci_clock) ;
9422
    end
9423
 
9424
    while ( IRDY === 0 && ok )
9425
    begin
9426
        if ( DEVSEL !== 1 )
9427
        begin
9428
            ok = 0 ;
9429
        end
9430
        @(posedge pci_clock) ;
9431
    end
9432
    in_use = 0 ;
9433
end
9434
endtask
9435
 
9436
function [31:0] wb_to_pci_addr_convert ;
9437
    input [31:0] wb_address ;
9438
    input [31:0] translation_address ;
9439
    input [31:0] translate ;
9440
 
9441
    reg   [31:0] temp_address ;
9442
begin
9443
    if ( translate !== 1 )
9444
    begin
9445
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9446
    end
9447
    else
9448
    begin
9449
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9450
    end
9451
 
9452
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9453
    wb_to_pci_addr_convert = temp_address ;
9454
end
9455
endfunction //wb_to_pci_addr_convert
9456
 
9457 45 mihad
`ifdef HOST
9458 15 mihad
task find_pci_devices ;
9459
    integer device_num ;
9460
    reg     found ;
9461
    reg [11:0] pci_ctrl_offset ;
9462
    reg ok ;
9463
    reg [31:0] data ;
9464 45 mihad
    reg [31:0] expected_data ;
9465
 
9466
    reg [5:0]  reg_num ;
9467 15 mihad
begin:main
9468 45 mihad
 
9469
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9470 15 mihad
    pci_ctrl_offset = 12'h004 ;
9471
 
9472
    // enable master & target operation
9473
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9474
 
9475
    if ( ok !== 1 )
9476
    begin
9477
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9478 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9479 15 mihad
        disable main ;
9480
    end
9481
    // find all possible devices on pci bus by performing configuration cycles
9482 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9483 15 mihad
    begin
9484
        find_device ( device_num, found ) ;
9485
 
9486
        // check pci status register - if device is not present, Received Master Abort bit must be set
9487
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9488
 
9489
        if ( (data[29] !== 0) && (found !== 0) )
9490 45 mihad
        begin
9491 15 mihad
            $display( "Time %t ", $time ) ;
9492
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9493
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9494 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9495
            ok = 0 ;
9496 15 mihad
        end
9497
 
9498
        if ( (data[29] !== 1) && (found !== 1) )
9499
        begin
9500
            $display( "Time %t ", $time ) ;
9501
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9502
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9503 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9504
            ok = 0 ;
9505 15 mihad
        end
9506
 
9507
        // clear Master Abort status if set
9508
        if ( data[29] !== 0 )
9509
        begin
9510
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9511
        end
9512 45 mihad
 
9513
        if (found === 1)
9514
        begin
9515
            // first check if found target is supposed to exist
9516
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9517
            begin
9518
                $display("Time %t", $time) ;
9519
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9520
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9521
                ok = 0 ;
9522
            end
9523
            else
9524
            begin
9525
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9526
                begin
9527
 
9528
                    data = 32'hFFFF_FFFF ;
9529
 
9530
                    expected_data = 0 ;
9531
 
9532
                    if (reg_num == 4)
9533
                    begin
9534
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9535
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9536
                    end
9537
                    else if (reg_num == 5)
9538
                    begin
9539
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9540
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9541
                    end
9542
 
9543
                    // write base address 0
9544
                    generate_configuration_cycle
9545
                    (
9546
                        'h0,            //bus_num
9547
                        device_num,     //device_num
9548
                        'h0,            //func_num
9549
                        reg_num,        //reg_num
9550
                        'h0,            //type
9551
                        4'hF,           // byte_enables
9552
                        data,           //data
9553
                        1'b1            //read0_write1
9554
                    );
9555
 
9556
                    // read data back
9557
                    generate_configuration_cycle
9558
                    (
9559
                        'h0,            //bus_num
9560
                        device_num,     //device_num
9561
                        'h0,            //func_num
9562
                        reg_num,        //reg_num
9563
                        'h0,            //type
9564
                        4'hF,           // byte_enables
9565
                        data,           //data
9566
                        1'b0            //read0_write1
9567
                    );
9568
 
9569
                    if (data !== expected_data)
9570
                    begin
9571
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9572
                        $display("Data read back not as expected!");
9573
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9574
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9575
                        ok = 0 ;
9576
                    end
9577
                end
9578
            end
9579
        end
9580 15 mihad
    end
9581 45 mihad
 
9582
    if (ok)
9583
        test_ok ;
9584 15 mihad
end //main
9585
endtask //find_pci_devices
9586
 
9587
task find_device ;
9588
    input [31:0] device_num ;
9589
    output  found ;
9590
 
9591
    reg [31:0] read_data ;
9592
begin
9593
    found = 1'b0 ;
9594
 
9595
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9596 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9597 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9598
    else
9599
    begin
9600
        $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]) ;
9601
        found = 1'b1 ;
9602
    end
9603
end
9604
endtask //find_device
9605 45 mihad
`endif
9606 15 mihad
 
9607
/*task set_bridge_parameters ;
9608
    reg [11:0] current_offset ;
9609
    reg [2:0] result ;
9610
    reg [31:0] write_data ;
9611
begin
9612
    // set burst size
9613
    // set latency timer
9614
    current_offset = 12'h00C ;
9615
    // set burst size to 16 and latency timer to 8
9616
    write_data     = {24'h0000_08, system_burst_size} ;
9617
    config_write(current_offset, write_data, 4'b1111) ;
9618
 
9619
    // set io image
9620
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9621
    write_data = 32'h0000_000_3 ;
9622
    config_write(current_offset, write_data, 4'b1111) ;
9623
 
9624
 
9625
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9626
    write_data = 32'h0001_000_1 ;
9627
    config_write(current_offset, write_data, 4'b1111) ;
9628
 
9629
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9630
    write_data = 32'hFFFF_0000 ;
9631
    config_write(current_offset, write_data, 4'b1111) ;
9632
 
9633
    // set memory image
9634
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9635
    write_data = 32'h0000_000_7 ;
9636
    config_write(current_offset, write_data, 4'b1111) ;
9637
 
9638
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9639
    write_data = 32'h0002_000_0 ;
9640
    config_write(current_offset, write_data, 4'b1111) ;
9641
 
9642
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9643
    write_data = 32'h0001_0000 ;
9644
    config_write(current_offset, write_data, 4'b1111) ;
9645
 
9646
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9647
    write_data = 32'hFFFF_0000 ;
9648
    config_write(current_offset, write_data, 4'b1111) ;
9649
 
9650
    // set parameters for bridge's target unit
9651
    // image control 0
9652
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9653
    write_data     = 32'h0000_0002 ;
9654
    config_write(current_offset, write_data, 4'b0001) ;
9655
 
9656
    // base_address 0
9657
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9658
    write_data      = 32'h2000_0000 ;
9659
    config_write(current_offset, write_data, 4'b1111) ;
9660
 
9661
    // address mask 0
9662
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9663
    write_data     = 32'hFFFF_F000 ;
9664
    config_write(current_offset, write_data, 4'b1111) ;
9665
 
9666
    // command register - enable response to io and mem space and PCI master
9667
    current_offset = 12'h004 ;
9668
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9669
    config_write(current_offset, write_data, 4'b1111) ;
9670
end
9671
endtask // set_bridge_parameters
9672
*/
9673
 
9674
task configuration_cycle_write ;
9675
    input [7:0]  bus_num ;
9676
    input [4:0]  device_num ;
9677
    input [2:0]  func_num ;
9678
    input [5:0]  reg_num ;
9679
    input [1:0]  type ;
9680
    input [3:0]  byte_enables ;
9681
    input [31:0] data ;
9682
 
9683
    reg [31:0] write_address ;
9684
    reg in_use ;
9685
    reg ok ;
9686
begin:main
9687
 
9688
    if ( in_use === 1 )
9689
    begin
9690 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9691 15 mihad
        disable main ;
9692
    end
9693
 
9694 45 mihad
    if ( (device_num > 20) && (type === 0) )
9695 15 mihad
    begin
9696
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9697
        disable main ;
9698
    end
9699
 
9700
    in_use = 1 ;
9701
 
9702 45 mihad
 
9703
`ifdef HOST
9704
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9705
`else
9706
`ifdef GUEST
9707
 
9708 15 mihad
    if ( type )
9709
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9710
    else
9711
    begin
9712
        write_address = 0 ;
9713
        write_address[10:0] = { func_num, reg_num, type } ;
9714
        write_address[11 + device_num] = 1'b1 ;
9715
    end
9716 45 mihad
 
9717
    fork
9718 15 mihad
    begin
9719 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9720
                            write_address,
9721
                            data, ~byte_enables,
9722
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9723
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9724
        do_pause(1) ;
9725 15 mihad
    end
9726 45 mihad
    begin
9727
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9728
    end
9729
    join
9730
`endif
9731
`endif
9732
 
9733
    in_use = 0 ;
9734
end
9735
endtask // configuration_cycle_write
9736 15 mihad
 
9737 45 mihad
task configuration_cycle_read ;
9738
    input [7:0]  bus_num ;
9739
    input [4:0]  device_num ;
9740
    input [2:0]  func_num ;
9741
    input [5:0]  reg_num ;
9742
    input [1:0]  type ;
9743
    input [3:0]  byte_enables ;
9744
    output [31:0] data ;
9745 15 mihad
 
9746 45 mihad
    reg [31:0] read_address ;
9747
    reg in_use ;
9748 15 mihad
 
9749 45 mihad
    reg master_check_data_prev ;
9750
begin:main
9751 15 mihad
 
9752 45 mihad
    if ( in_use === 1 )
9753 15 mihad
    begin
9754 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9755
        data = 32'hxxxx_xxxx ;
9756
        disable main ;
9757 15 mihad
    end
9758
 
9759 45 mihad
    in_use = 1 ;
9760 15 mihad
 
9761 45 mihad
`ifdef HOST
9762
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9763
`else
9764
`ifdef GUEST
9765
     master_check_data_prev = master1_check_received_data ;
9766 15 mihad
     if ( type )
9767 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9768 15 mihad
     else
9769
     begin
9770 45 mihad
         read_address = 0 ;
9771
         read_address[10:0] = { func_num, reg_num, type } ;
9772
         read_address[11 + device_num] = 1'b1 ;
9773 15 mihad
     end
9774 45 mihad
 
9775
     fork
9776
     begin
9777
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9778
                 read_address,
9779 15 mihad
                 data, ~byte_enables,
9780
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9781
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9782 45 mihad
         do_pause(1) ;
9783
     end
9784
     begin
9785
         @(master1_received_data_valid) ;
9786
         data = master1_received_data ;
9787
     end
9788
     join
9789 15 mihad
 
9790 45 mihad
    master1_check_received_data = master_check_data_prev ;
9791
`endif
9792
`endif
9793
 
9794 15 mihad
    in_use = 0 ;
9795
 
9796 45 mihad
end //main
9797
endtask // configuration_cycle_read
9798
 
9799 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9800
task test_conf_cycle_type1_reference ;
9801
    reg [31:0] address ;
9802
    reg in_use ;
9803
 
9804
    reg master_check_data_prev ;
9805
    reg [31:0] data ;
9806
    reg monitor_ok ;
9807
    reg master_ok ;
9808
begin:main
9809
 
9810
    if ( in_use === 1 )
9811
    begin
9812
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9813
        disable main ;
9814
    end
9815
 
9816
    in_use = 1 ;
9817
 
9818
    master_check_data_prev = master1_check_received_data ;
9819
 
9820
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9821
    address = `TAR0_IDSEL_ADDR ;
9822
 
9823
    address[1:0] = 2'b01 ;
9824
 
9825
    `ifdef HOST
9826
        conf_cyc_type1_target_bus_num = 255 ;
9827
    `endif
9828
    master_ok = 1 ;
9829
    fork
9830
    begin
9831
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9832
        do_pause(1) ;
9833
    end
9834
    begin:error_monitor1
9835
        @(error_event_int) ;
9836
        master_ok = 0 ;
9837
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9838
    end
9839
    begin
9840
        pci_transaction_progress_monitor
9841
        (
9842
            address,                                                // expected address on PCI bus
9843
            `BC_CONF_READ,                                          // expected bus command on PCI bus
9844
            0,                                                      // expected number of succesfull data phases
9845
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9846
            1'b1,                                                   // monitor checking/not checking number of transfers
9847
            1'b0,                                                   // monitor checking/not checking number of cycles
9848
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9849
            monitor_ok                                              // status - 1 success, 0 failure
9850
        ) ;
9851
 
9852
        @(posedge pci_clock);
9853
        #1 ;
9854
 
9855
        if (master_ok)
9856
            disable error_monitor1 ;
9857
 
9858
        if (!monitor_ok)
9859
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9860
    end
9861
    join
9862
 
9863
    if (monitor_ok && master_ok)
9864
        test_ok ;
9865
 
9866
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
9867
    master_ok = 1 ;
9868
    fork
9869
    begin
9870
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
9871
        do_pause(1) ;
9872
    end
9873
    begin:error_monitor2
9874
        @(error_event_int) ;
9875
        master_ok = 0 ;
9876
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9877
    end
9878
    begin
9879
        pci_transaction_progress_monitor
9880
        (
9881
            address,                                                // expected address on PCI bus
9882
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
9883
            0,                                                      // expected number of succesfull data phases
9884
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9885
            1'b1,                                                   // monitor checking/not checking number of transfers
9886
            1'b0,                                                   // monitor checking/not checking number of cycles
9887
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9888
            monitor_ok                                              // status - 1 success, 0 failure
9889
        ) ;
9890
 
9891
        @(posedge pci_clock);
9892
        #1 ;
9893
 
9894
        if (master_ok)
9895
            disable error_monitor2 ;
9896
 
9897
        if (!monitor_ok)
9898
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9899
    end
9900
    join
9901
 
9902
    master1_check_received_data = master_check_data_prev ;
9903
 
9904
    if (monitor_ok && master_ok)
9905
        test_ok ;
9906
 
9907
    in_use = 0 ;
9908
 
9909
end //main
9910
endtask // test_conf_cycle_type1_reference
9911
`endif
9912
 
9913 45 mihad
`ifdef HOST
9914
task generate_configuration_cycle ;
9915 15 mihad
    input [7:0]  bus_num ;
9916
    input [4:0]  device_num ;
9917
    input [2:0]  func_num ;
9918
    input [5:0]  reg_num ;
9919
    input [1:0]  type ;
9920
    input [3:0]  byte_enables ;
9921 45 mihad
    inout [31:0] data ;
9922
    input        read0_write1 ;
9923 15 mihad
 
9924
    reg `READ_STIM_TYPE read_data ;
9925
    reg `WB_TRANSFER_FLAGS  flags ;
9926
    reg `READ_RETURN_TYPE   read_status ;
9927
 
9928
    reg `WRITE_STIM_TYPE   write_data ;
9929
    reg `WRITE_RETURN_TYPE write_status ;
9930
 
9931 45 mihad
    reg [31:0] pci_address ;
9932 15 mihad
    reg in_use ;
9933 45 mihad
    reg ok ;
9934 15 mihad
 
9935
    reg [31:0] temp_var ;
9936
begin:main
9937
 
9938
    if ( in_use === 1 )
9939
    begin
9940 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
9941 15 mihad
        data = 32'hxxxx_xxxx ;
9942
        disable main ;
9943
    end
9944
 
9945 45 mihad
    in_use = 1 ;
9946
 
9947
    if ( type )
9948
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9949
    else
9950 15 mihad
    begin
9951 45 mihad
        pci_address = 0 ;
9952
        pci_address[10:0] = { func_num, reg_num, type } ;
9953
        if (device_num <= 20)
9954
            pci_address[11 + device_num] = 1'b1 ;
9955
    end
9956
 
9957
    // setup flags
9958
    flags = 0 ;
9959
    flags`INIT_WAITS   = tb_init_waits ;
9960
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
9961
 
9962
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9963
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9964
 
9965
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9966
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9967
    write_data`WRITE_SEL      = 4'hF ;
9968
    write_data`WRITE_TAG_STIM = 0 ;
9969
 
9970
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
9971
 
9972
    // check if write succeeded
9973
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9974
    begin
9975
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9976 15 mihad
        data = 32'hxxxx_xxxx ;
9977 45 mihad
        in_use = 0 ;
9978 15 mihad
        disable main ;
9979
    end
9980
 
9981 45 mihad
    // setup flags for wb master to handle retries and read and write data
9982
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
9983
 
9984
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9985
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
9986
    read_data`READ_SEL          = byte_enables ;
9987
    write_data`WRITE_SEL        = byte_enables ;
9988
    read_data`READ_TAG_STIM     = 0 ;
9989
    write_data`WRITE_TAG_STIM   = 0 ;
9990
    write_data`WRITE_DATA       = data ;
9991
 
9992
    ok = 0 ;
9993
 
9994
    fork
9995
    begin
9996
        if (read0_write1 === 0)
9997
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
9998
        else
9999
        if (read0_write1 === 1)
10000
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
10001
    end
10002
    begin
10003
        pci_transaction_progress_monitor
10004
        (
10005
            pci_address,                                            // expected address on PCI bus
10006
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10007
            1,                                                      // expected number of succesfull data phases
10008
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10009
            1'b0,                                                   // monitor checking/not checking number of transfers
10010
            1'b0,                                                   // monitor checking/not checking number of cycles
10011
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10012
            ok                                                      // status - 1 success, 0 failure
10013
        ) ;
10014
    end
10015
    join
10016
 
10017
    // check if transfer succeeded
10018
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10019
    begin
10020
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10021
        data = 32'hxxxx_xxxx ;
10022
        in_use = 0 ;
10023
        disable main ;
10024
    end
10025
 
10026
    if (!ok)
10027
    begin
10028
        data = 32'hxxxx_xxxx ;
10029
        in_use = 0 ;
10030
        disable main ;
10031
    end
10032
 
10033
    if (read0_write1 === 0)
10034
        data = read_status`READ_DATA ;
10035
 
10036
    in_use = 0 ;
10037
end
10038
endtask // generate_configuration_cycle
10039
 
10040
task test_configuration_cycle_target_abort ;
10041
    reg `READ_STIM_TYPE read_data ;
10042
    reg `WB_TRANSFER_FLAGS  flags ;
10043
    reg `READ_RETURN_TYPE   read_status ;
10044
 
10045
    reg `WRITE_STIM_TYPE   write_data ;
10046
    reg `WRITE_RETURN_TYPE write_status ;
10047
 
10048
    reg [31:0] pci_address ;
10049
    reg in_use ;
10050
    reg ok_pci ;
10051
    reg ok_wb  ;
10052
    reg ok     ;
10053
 
10054
    reg [31:0] temp_var ;
10055
 
10056
begin:main
10057
 
10058
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10059
 
10060
    if ( in_use === 1 )
10061
    begin
10062
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10063
        disable main ;
10064
    end
10065
 
10066 15 mihad
    in_use = 1 ;
10067
 
10068 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10069
 
10070 15 mihad
    // setup flags
10071
    flags = 0 ;
10072 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10073
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10074 15 mihad
 
10075
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10076
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10077
 
10078
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10079 45 mihad
    temp_var                  = 0 ;
10080
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10081
    write_data`WRITE_DATA     = temp_var ;
10082 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10083
    write_data`WRITE_TAG_STIM = 0 ;
10084
 
10085
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10086
 
10087
    // check if write succeeded
10088
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10089
    begin
10090
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10091 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10092
        in_use = 0 ;
10093 15 mihad
        disable main ;
10094
    end
10095
 
10096 45 mihad
    // setup flags for wb master to handle retries and read and write data
10097 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10098
 
10099 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10100
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10101 15 mihad
 
10102 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10103
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10104
    read_data`READ_SEL          = 4'hF ;
10105
    write_data`WRITE_SEL        = 4'hF ;
10106
    read_data`READ_TAG_STIM     = 0 ;
10107
    write_data`WRITE_TAG_STIM   = 0 ;
10108
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10109
 
10110
    ok_pci = 0 ;
10111
    ok_wb  = 1 ;
10112
 
10113
    // set target to terminate with target abort
10114
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10115
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10116
    fork
10117
    begin
10118
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10119
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10120
        begin
10121
            $display("Time %t", $time) ;
10122
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10123
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10124
            ok_wb = 0 ;
10125
        end
10126
 
10127
        config_read( 12'h4, 4'hF, temp_var ) ;
10128
        if ( temp_var[29] !== 0 )
10129
        begin
10130
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10131
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10132
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10133
            ok_wb = 0 ;
10134
        end
10135
 
10136
        if ( temp_var[28] !== 1 )
10137
        begin
10138
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10139
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10140
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10141
            ok_wb = 0 ;
10142
        end
10143
 
10144
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10145
 
10146
        if (ok !== 1)
10147
        begin
10148
            ok_wb = 0 ;
10149
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10150
            $display("Write to PCI Device Status Register failed") ;
10151
            test_fail("Write to PCI Device Status Register failed") ;
10152
        end
10153
 
10154
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10155
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10156
        begin
10157
            $display("Time %t", $time) ;
10158
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10159
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10160
            ok_wb = 0 ;
10161
        end
10162
 
10163
        config_read( 12'h4, 4'hF, temp_var ) ;
10164
        if ( temp_var[29] !== 0 )
10165
        begin
10166
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10167
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10168
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10169
            ok_wb = 0 ;
10170
        end
10171
 
10172
        if ( temp_var[28] !== 1 )
10173
        begin
10174
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10175
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10176
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10177
            ok_wb = 0 ;
10178
        end
10179
 
10180
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10181
 
10182
        if (ok !== 1)
10183
        begin
10184
            ok_wb = 0 ;
10185
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10186
            $display("Write to PCI Device Status Register failed") ;
10187
            test_fail("Write to PCI Device Status Register failed") ;
10188
        end
10189
    end
10190
    begin
10191
        pci_transaction_progress_monitor
10192
        (
10193
            pci_address,                                            // expected address on PCI bus
10194
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10195
            0,                                                      // expected number of succesfull data phases
10196
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10197
            1'b1,                                                   // monitor checking/not checking number of transfers
10198
            1'b0,                                                   // monitor checking/not checking number of cycles
10199
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10200
            ok_pci                                                  // status - 1 success, 0 failure
10201
        ) ;
10202
 
10203
        if (ok_pci)
10204
        begin
10205
            pci_transaction_progress_monitor
10206
            (
10207
                pci_address,                                            // expected address on PCI bus
10208
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10209
                0,                                                      // expected number of succesfull data phases
10210
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10211
                1'b1,                                                   // monitor checking/not checking number of transfers
10212
                1'b0,                                                   // monitor checking/not checking number of cycles
10213
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10214
                ok_pci                                                  // status - 1 success, 0 failure
10215
            ) ;
10216
        end
10217
 
10218
        if (!ok_pci)
10219
        begin
10220
            $display("Time %t", $time) ;
10221
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10222
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10223
        end
10224
    end
10225
    join
10226
 
10227
    if (ok_pci && ok_wb)
10228
    begin
10229
        test_ok ;
10230
    end
10231
 
10232
    in_use = 0 ;
10233
 
10234
    // set target to terminate normally
10235
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10236
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10237
end
10238
endtask // test_configuration_cycle_target_abort
10239
 
10240
task test_configuration_cycle_type1_generation ;
10241
    reg `READ_STIM_TYPE read_data ;
10242
    reg `WB_TRANSFER_FLAGS  flags ;
10243
    reg `READ_RETURN_TYPE   read_status ;
10244
 
10245
    reg `WRITE_STIM_TYPE   write_data ;
10246
    reg `WRITE_RETURN_TYPE write_status ;
10247
 
10248
    reg [31:0] pci_address ;
10249
    reg in_use ;
10250
    reg ok_pci ;
10251
    reg ok_wb  ;
10252
    reg ok     ;
10253
 
10254
    reg [31:0] temp_var ;
10255
 
10256
begin:main
10257
 
10258
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10259
    conf_cyc_type1_target_data = 0 ;
10260
    conf_cyc_type1_target_bus_num = 0;
10261
 
10262
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10263
 
10264
    if ( in_use === 1 )
10265
    begin
10266
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10267
        disable main ;
10268
    end
10269
 
10270
    in_use = 1 ;
10271
 
10272
    pci_address        = 32'hAAAA_AAAA ;
10273
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10274
 
10275
    // setup flags
10276
    flags = 0 ;
10277
    flags`INIT_WAITS   = tb_init_waits ;
10278
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10279
 
10280
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10281
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10282
 
10283
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10284
    write_data`WRITE_DATA     = pci_address ;
10285
    write_data`WRITE_SEL      = 4'hF ;
10286
    write_data`WRITE_TAG_STIM = 0 ;
10287
 
10288
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10289
 
10290
    // check if write succeeded
10291
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10292
    begin
10293
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10294
        test_fail("write to configuration cycle address register was not possible") ;
10295
        in_use = 0 ;
10296
        disable main ;
10297
    end
10298
 
10299
    // setup flags for wb master to handle retries and read and write data
10300
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10301
 
10302
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10303
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10304
 
10305
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10306
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10307
    read_data`READ_SEL          = 4'hF ;
10308
    write_data`WRITE_SEL        = 4'hF ;
10309
    read_data`READ_TAG_STIM     = 0 ;
10310
    write_data`WRITE_TAG_STIM   = 0 ;
10311
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10312
 
10313
    ok_pci = 0 ;
10314
    ok_wb  = 1 ;
10315
 
10316
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10317
    pci_address[31:24] = 0 ;
10318
    fork
10319
    begin
10320
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10321
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10322
        begin
10323
            $display("Time %t", $time) ;
10324
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10325
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10326
            ok_wb = 0 ;
10327
        end
10328
 
10329
        config_read( 12'h4, 4'hF, temp_var ) ;
10330
        if ( temp_var[29] !== 1 )
10331
        begin
10332
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10333
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10334
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10335
            ok_wb = 0 ;
10336
        end
10337
 
10338
        if ( temp_var[28] !== 0 )
10339
        begin
10340
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10341
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10342
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10343
            ok_wb = 0 ;
10344
        end
10345
 
10346
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10347
 
10348
        if (ok !== 1)
10349
        begin
10350
            ok_wb = 0 ;
10351
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10352
            $display("Write to PCI Device Status Register failed") ;
10353
            test_fail("Write to PCI Device Status Register failed") ;
10354
        end
10355
 
10356
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10357
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10358
        begin
10359
            $display("Time %t", $time) ;
10360
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10361
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10362
            ok_wb = 0 ;
10363
        end
10364
 
10365
        config_read( 12'h4, 4'hF, temp_var ) ;
10366
        if ( temp_var[29] !== 1 )
10367
        begin
10368
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10369
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10370
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10371
            ok_wb = 0 ;
10372
        end
10373
 
10374
        if ( temp_var[28] !== 0 )
10375
        begin
10376
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10377
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10378
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10379
            ok_wb = 0 ;
10380
        end
10381
 
10382
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10383
 
10384
        if (ok !== 1)
10385
        begin
10386
            ok_wb = 0 ;
10387
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10388
            $display("Write to PCI Device Status Register failed") ;
10389
            test_fail("Write to PCI Device Status Register failed") ;
10390
        end
10391
    end
10392
    begin
10393
        pci_transaction_progress_monitor
10394
        (
10395
            pci_address,                                            // expected address on PCI bus
10396
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10397
            0,                                                      // expected number of succesfull data phases
10398
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10399
            1'b1,                                                   // monitor checking/not checking number of transfers
10400
            1'b0,                                                   // monitor checking/not checking number of cycles
10401
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10402
            ok_pci                                                  // status - 1 success, 0 failure
10403
        ) ;
10404
 
10405
        if (ok_pci)
10406
        begin
10407
            pci_transaction_progress_monitor
10408
            (
10409
                pci_address,                                            // expected address on PCI bus
10410
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10411
                0,                                                      // expected number of succesfull data phases
10412
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10413
                1'b1,                                                   // monitor checking/not checking number of transfers
10414
                1'b0,                                                   // monitor checking/not checking number of cycles
10415
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10416
                ok_pci                                                  // status - 1 success, 0 failure
10417
            ) ;
10418
        end
10419
 
10420
        if (!ok_pci)
10421
        begin
10422
            $display("Time %t", $time) ;
10423
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10424
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10425
        end
10426
    end
10427
    join
10428
 
10429
    if (ok_pci && ok_wb)
10430
    begin
10431
        test_ok ;
10432
    end
10433
 
10434
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10435
    conf_cyc_type1_target_data = 0 ;
10436
    conf_cyc_type1_target_bus_num = 8'h55;
10437
 
10438
    pci_address      = 32'h5555_5555 ;
10439
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10440
 
10441
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10442
 
10443
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10444
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10445
 
10446
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10447
    write_data`WRITE_DATA     = pci_address ;
10448
    write_data`WRITE_SEL      = 4'hF ;
10449
    write_data`WRITE_TAG_STIM = 0 ;
10450
 
10451
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10452
 
10453
    // check if write succeeded
10454
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10455
    begin
10456
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10457
        test_fail("write to configuration cycle address register was not possible") ;
10458
        in_use = 0 ;
10459
        disable main ;
10460
    end
10461
 
10462
    // setup flags for wb master to handle retries and read and write data
10463
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10464
 
10465
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10466
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10467
 
10468
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10469
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10470
    read_data`READ_SEL          = 4'hF ;
10471
    write_data`WRITE_SEL        = 4'hF ;
10472
    read_data`READ_TAG_STIM     = 0 ;
10473
    write_data`WRITE_TAG_STIM   = 0 ;
10474
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10475
 
10476
    ok_pci = 0 ;
10477
    ok_wb  = 1 ;
10478
 
10479
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10480
    pci_address[31:24] = 0 ;
10481
    fork
10482
    begin
10483
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10484
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10485
        begin
10486
            $display("Time %t", $time) ;
10487
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10488
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10489
            ok_wb = 0 ;
10490
        end
10491
 
10492
        config_read( 12'h4, 4'hF, temp_var ) ;
10493
        if ( temp_var[29] !== 0 )
10494
        begin
10495
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10496
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10497
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10498
            ok_wb = 0 ;
10499
        end
10500
 
10501
        if ( temp_var[28] !== 1 )
10502
        begin
10503
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10504
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10505
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10506
            ok_wb = 0 ;
10507
        end
10508
 
10509
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10510
 
10511
        if (ok !== 1)
10512
        begin
10513
            ok_wb = 0 ;
10514
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10515
            $display("Write to PCI Device Status Register failed") ;
10516
            test_fail("Write to PCI Device Status Register failed") ;
10517
        end
10518
 
10519
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10520
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10521
        begin
10522
            $display("Time %t", $time) ;
10523
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10524
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10525
            ok_wb = 0 ;
10526
        end
10527
 
10528
        config_read( 12'h4, 4'hF, temp_var ) ;
10529
        if ( temp_var[29] !== 0 )
10530
        begin
10531
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10532
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10533
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10534
            ok_wb = 0 ;
10535
        end
10536
 
10537
        if ( temp_var[28] !== 1 )
10538
        begin
10539
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10540
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10541
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10542
            ok_wb = 0 ;
10543
        end
10544
 
10545
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10546
 
10547
        if (ok !== 1)
10548
        begin
10549
            ok_wb = 0 ;
10550
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10551
            $display("Write to PCI Device Status Register failed") ;
10552
            test_fail("Write to PCI Device Status Register failed") ;
10553
        end
10554
    end
10555
    begin
10556
        pci_transaction_progress_monitor
10557
        (
10558
            pci_address,                                            // expected address on PCI bus
10559
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10560
            0,                                                      // expected number of succesfull data phases
10561
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10562
            1'b1,                                                   // monitor checking/not checking number of transfers
10563
            1'b0,                                                   // monitor checking/not checking number of cycles
10564
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10565
            ok_pci                                                  // status - 1 success, 0 failure
10566
        ) ;
10567
 
10568
        if (ok_pci)
10569
        begin
10570
            pci_transaction_progress_monitor
10571
            (
10572
                pci_address,                                            // expected address on PCI bus
10573
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10574
                0,                                                      // expected number of succesfull data phases
10575
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10576
                1'b1,                                                   // monitor checking/not checking number of transfers
10577
                1'b0,                                                   // monitor checking/not checking number of cycles
10578
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10579
                ok_pci                                                  // status - 1 success, 0 failure
10580
            ) ;
10581
        end
10582
 
10583
        if (!ok_pci)
10584
        begin
10585
            $display("Time %t", $time) ;
10586
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10587
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10588
        end
10589
    end
10590
    join
10591
 
10592
    if (ok_pci && ok_wb)
10593
    begin
10594
        test_ok ;
10595
    end
10596
 
10597
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10598
 
10599
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10600
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10601
    conf_cyc_type1_target_bus_num = 8'hAA;
10602
 
10603
    pci_address      = 32'hAAAA_AAAA ;
10604
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10605
 
10606
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10607
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10608
 
10609
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10610
    write_data`WRITE_DATA     = pci_address ;
10611
    write_data`WRITE_SEL      = 4'hF ;
10612
    write_data`WRITE_TAG_STIM = 0 ;
10613
 
10614
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10615
 
10616
    // check if write succeeded
10617
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10618
    begin
10619
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10620
        test_fail("write to configuration cycle address register was not possible") ;
10621
        in_use = 0 ;
10622
        disable main ;
10623
    end
10624
 
10625
    // setup flags for wb master to handle retries and read and write data
10626
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10627
 
10628
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10629
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10630
 
10631
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10632
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10633
    read_data`READ_SEL          = 4'b0101 ;
10634
    write_data`WRITE_SEL        = 4'b1010 ;
10635
    read_data`READ_TAG_STIM     = 0 ;
10636
    write_data`WRITE_TAG_STIM   = 0 ;
10637
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10638
 
10639
    ok_pci = 0 ;
10640
    ok_wb  = 1 ;
10641
 
10642
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10643
    pci_address[31:24] = 0 ;
10644
 
10645
    fork
10646
    begin
10647
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10648
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10649
        begin
10650
            $display("Time %t", $time) ;
10651
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10652
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10653
            ok_wb = 0 ;
10654
        end
10655
 
10656
        config_read( 12'h4, 4'hF, temp_var ) ;
10657
        if ( temp_var[29] !== 0 )
10658
        begin
10659
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10660
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10661
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10662
            ok_wb = 0 ;
10663
        end
10664
 
10665
        if ( temp_var[28] !== 0 )
10666
        begin
10667
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10668
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10669
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10670
            ok_wb = 0 ;
10671
        end
10672
 
10673
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10674
 
10675
        if (ok !== 1)
10676
        begin
10677
            ok_wb = 0 ;
10678
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10679
            $display("Write to PCI Device Status Register failed") ;
10680
            test_fail("Write to PCI Device Status Register failed") ;
10681
        end
10682
 
10683
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10684
        begin
10685
            ok_wb = 0 ;
10686
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10687
            $display("Read Data provided by the bridge was not as expected!") ;
10688
            test_fail("Read Data provided by the bridge was not as expected") ;
10689
        end
10690
 
10691
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10692
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10693
        begin
10694
            $display("Time %t", $time) ;
10695
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10696
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10697
            ok_wb = 0 ;
10698
        end
10699
 
10700
        config_read( 12'h4, 4'hF, temp_var ) ;
10701
        if ( temp_var[29] !== 0 )
10702
        begin
10703
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10704
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10705
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10706
            ok_wb = 0 ;
10707
        end
10708
 
10709
        if ( temp_var[28] !== 0 )
10710
        begin
10711
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10712
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10713
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10714
            ok_wb = 0 ;
10715
        end
10716
 
10717
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10718
 
10719
        if (ok !== 1)
10720
        begin
10721
            ok_wb = 0 ;
10722
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10723
            $display("Write to PCI Device Status Register failed") ;
10724
            test_fail("Write to PCI Device Status Register failed") ;
10725
        end
10726
 
10727
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10728
        begin
10729
            ok_wb = 0 ;
10730
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10731
            $display("Data written by the bridge was not as expected!") ;
10732
            test_fail("Data written by the bridge was not as expected") ;
10733
        end
10734
 
10735
    end
10736
    begin
10737
        ok = 1 ;
10738
        repeat(8)
10739
        begin
10740
            pci_transaction_progress_monitor
10741
            (
10742
                pci_address,                                            // expected address on PCI bus
10743
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10744
                0,                                                      // expected number of succesfull data phases
10745
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10746
                1'b1,                                                   // monitor checking/not checking number of transfers
10747
                1'b0,                                                   // monitor checking/not checking number of cycles
10748
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10749
                ok_pci                                                  // status - 1 success, 0 failure
10750
            ) ;
10751
 
10752
            if (!ok_pci)
10753
            begin
10754
                ok = 0 ;
10755
                $display("Time %t", $time) ;
10756
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10757
            end
10758
        end
10759
 
10760
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10761
 
10762
        pci_transaction_progress_monitor
10763
        (
10764
            pci_address,                                            // expected address on PCI bus
10765
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10766
            1,                                                      // expected number of succesfull data phases
10767
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10768
            1'b1,                                                   // monitor checking/not checking number of transfers
10769
            1'b0,                                                   // monitor checking/not checking number of cycles
10770
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10771
            ok_pci                                                  // status - 1 success, 0 failure
10772
        ) ;
10773
 
10774
        if (!ok_pci)
10775
        begin
10776
            ok = 0 ;
10777
            $display("Time %t", $time) ;
10778
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10779
        end
10780
 
10781
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10782
        repeat(8)
10783
        begin
10784
            pci_transaction_progress_monitor
10785
            (
10786
                pci_address,                                            // expected address on PCI bus
10787
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10788
                0,                                                      // expected number of succesfull data phases
10789
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10790
                1'b1,                                                   // monitor checking/not checking number of transfers
10791
                1'b0,                                                   // monitor checking/not checking number of cycles
10792
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10793
                ok_pci                                                  // status - 1 success, 0 failure
10794
            ) ;
10795
 
10796
            if (!ok_pci)
10797
            begin
10798
                ok = 0 ;
10799
                $display("Time %t", $time) ;
10800
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10801
            end
10802
        end
10803
 
10804
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10805
        pci_transaction_progress_monitor
10806
        (
10807
            pci_address,                                            // expected address on PCI bus
10808
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10809
            1,                                                      // expected number of succesfull data phases
10810
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10811
            1'b1,                                                   // monitor checking/not checking number of transfers
10812
            1'b0,                                                   // monitor checking/not checking number of cycles
10813
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10814
            ok_pci                                                  // status - 1 success, 0 failure
10815
        ) ;
10816
 
10817
        if (!ok_pci)
10818
        begin
10819
            ok = 0 ;
10820
            $display("Time %t", $time) ;
10821
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10822
        end
10823
 
10824
        if (!ok)
10825
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10826
    end
10827
    join
10828
 
10829
    if (ok_pci && ok_wb)
10830
    begin
10831
        test_ok ;
10832
    end
10833
 
10834
    in_use = 0 ;
10835
end
10836
endtask // test_configuration_cycle_type1_generation
10837
`endif
10838
 
10839
task test_initial_conf_values ;
10840
    reg [11:0] register_offset ;
10841
    reg [31:0] expected_value ;
10842
    reg        failed ;
10843
`ifdef HOST
10844
    reg `READ_STIM_TYPE    read_data ;
10845
    reg `WB_TRANSFER_FLAGS flags ;
10846
    reg `READ_RETURN_TYPE  read_status ;
10847
 
10848
    reg `WRITE_STIM_TYPE   write_data ;
10849
    reg `WRITE_RETURN_TYPE write_status ;
10850
begin
10851
    failed     = 0 ;
10852
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
10853
    flags      = 0 ;
10854
    read_data  = 0 ;
10855
    write_data = 0 ;
10856
 
10857
    read_data`READ_SEL = 4'hF ;
10858
 
10859
    flags`INIT_WAITS           = tb_init_waits ;
10860
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10861
 
10862
    // test MEM/IO map bit initial value in each PCI BAR
10863
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
10864
 
10865
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10866
 
10867 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10868
 
10869 45 mihad
    `ifdef NO_CNF_IMAGE
10870
        `ifdef PCI_IMAGE0
10871
            if (`PCI_AM0)
10872
                expected_value = `PCI_BA0_MEM_IO ;
10873
            else
10874
                expected_value = 32'h0000_0000 ;
10875
        `else
10876
            expected_value = 32'h0000_0000 ;
10877
        `endif
10878
    `else
10879
        expected_value = 32'h0000_0000 ;
10880
    `endif
10881
 
10882 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10883
    begin
10884 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
10885
        failed = 1 ;
10886 15 mihad
    end
10887 45 mihad
    else
10888
    begin
10889
        if (read_status`READ_DATA !== expected_value)
10890
        begin
10891
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
10892
            failed = 1 ;
10893
        end
10894
    end
10895 15 mihad
 
10896 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
10897 15 mihad
 
10898 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10899
 
10900
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10901
 
10902
    if (`PCI_AM1)
10903
        expected_value = `PCI_BA1_MEM_IO ;
10904
    else
10905
        expected_value = 32'h0000_0000 ;
10906
 
10907
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10908
    begin
10909
        test_fail("read from P_BA1 register didn't succeede") ;
10910
        failed = 1 ;
10911
    end
10912
    else
10913
    begin
10914
        if (read_status`READ_DATA !== expected_value)
10915
        begin
10916
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
10917
            failed = 1 ;
10918
        end
10919
    end
10920
 
10921
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
10922
 
10923
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10924
 
10925
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10926
 
10927
    `ifdef PCI_IMAGE2
10928
        if (`PCI_AM2)
10929
            expected_value = `PCI_BA2_MEM_IO ;
10930
        else
10931
            expected_value = 32'h0000_0000 ;
10932 15 mihad
    `else
10933 45 mihad
        expected_value = 32'h0000_0000 ;
10934
    `endif
10935 15 mihad
 
10936 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10937
    begin
10938
        test_fail("read from P_BA2 register didn't succeede") ;
10939
        failed = 1 ;
10940
    end
10941
    else
10942
    begin
10943
        if (read_status`READ_DATA !== expected_value)
10944
        begin
10945
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
10946
            failed = 1 ;
10947
        end
10948
    end
10949 15 mihad
 
10950 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
10951
 
10952
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10953
 
10954
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10955
 
10956
    `ifdef PCI_IMAGE3
10957
        if (`PCI_AM3)
10958
            expected_value = `PCI_BA3_MEM_IO ;
10959
        else
10960
            expected_value = 32'h0000_0000 ;
10961
    `else
10962
        expected_value = 32'h0000_0000 ;
10963 15 mihad
    `endif
10964 45 mihad
 
10965
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10966
    begin
10967
        test_fail("read from P_BA3 register didn't succeede") ;
10968
        failed = 1 ;
10969
    end
10970
    else
10971
    begin
10972
        if (read_status`READ_DATA !== expected_value)
10973
        begin
10974
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
10975
            failed = 1 ;
10976
        end
10977
    end
10978
 
10979
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
10980
 
10981
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10982
 
10983
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10984
 
10985
    `ifdef PCI_IMAGE4
10986
        if (`PCI_AM4)
10987
            expected_value = `PCI_BA4_MEM_IO ;
10988
        else
10989
            expected_value = 32'h0000_0000 ;
10990
    `else
10991
        expected_value = 32'h0000_0000 ;
10992 15 mihad
    `endif
10993
 
10994 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10995
    begin
10996
        test_fail("read from P_BA4 register didn't succeede") ;
10997
        failed = 1 ;
10998
    end
10999
    else
11000
    begin
11001
        if (read_status`READ_DATA !== expected_value)
11002
        begin
11003
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11004
            failed = 1 ;
11005
        end
11006
    end
11007 15 mihad
 
11008 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11009 15 mihad
 
11010 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11011
 
11012
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11013
 
11014
    `ifdef PCI_IMAGE5
11015
        if(`PCI_AM5)
11016
            expected_value = `PCI_BA5_MEM_IO ;
11017
        else
11018
            expected_value = 32'h0000_0000 ;
11019
    `else
11020
        expected_value = 32'h0000_0000 ;
11021
    `endif
11022
 
11023
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11024
    begin
11025
        test_fail("read from P_BA5 register didn't succeede") ;
11026
        failed = 1 ;
11027
    end
11028
    else
11029
    begin
11030
        if (read_status`READ_DATA !== expected_value)
11031
        begin
11032
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11033
            failed = 1 ;
11034
        end
11035
    end
11036
 
11037
    // test Address Mask initial values
11038
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11039
 
11040
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11041
 
11042
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11043
 
11044
    `ifdef NO_CNF_IMAGE
11045
        `ifdef PCI_IMAGE0
11046
            expected_value = {`PCI_AM0, 12'h000};
11047
 
11048
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11049
        `else
11050
            expected_value = 32'h0000_0000 ;
11051
        `endif
11052
    `else
11053
        expected_value = 32'hFFFF_FFFF ;
11054
 
11055
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11056
    `endif
11057
 
11058
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11059
    begin
11060
        test_fail("read from P_AM0 register didn't succeede") ;
11061
        failed = 1 ;
11062
    end
11063
    else
11064
    begin
11065
        if (read_status`READ_DATA !== expected_value)
11066
        begin
11067
            test_fail("AM0 initial value was not set as defined");
11068
            failed = 1 ;
11069
        end
11070
    end
11071
 
11072
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11073
 
11074
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11075
 
11076
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11077
 
11078
    expected_value = {`PCI_AM1, 12'h000};
11079
 
11080
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11081
 
11082
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11083
    begin
11084
        test_fail("read from P_AM1 register didn't succeede") ;
11085
        failed = 1 ;
11086
    end
11087
    else
11088
    begin
11089
        if (read_status`READ_DATA !== expected_value)
11090
        begin
11091
            test_fail("AM1 initial value was not set as defined");
11092
            failed = 1 ;
11093
        end
11094
    end
11095
 
11096
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11097
 
11098
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11099
 
11100
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11101
 
11102
    `ifdef PCI_IMAGE2
11103
        expected_value = {`PCI_AM2, 12'h000};
11104
 
11105
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11106
    `else
11107
        expected_value = 32'h0000_0000 ;
11108
    `endif
11109
 
11110
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11111
    begin
11112
        test_fail("read from P_AM2 register didn't succeede") ;
11113
        failed = 1 ;
11114
    end
11115
    else
11116
    begin
11117
        if (read_status`READ_DATA !== expected_value)
11118
        begin
11119
            test_fail("AM2 initial value was not set as defined");
11120
            failed = 1 ;
11121
        end
11122
    end
11123
 
11124
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11125
 
11126
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11127
 
11128
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11129
 
11130
    `ifdef PCI_IMAGE3
11131
        expected_value = {`PCI_AM3, 12'h000};
11132
 
11133
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11134
    `else
11135
        expected_value = 32'h0000_0000 ;
11136
    `endif
11137
 
11138
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11139
    begin
11140
        test_fail("read from P_AM3 register didn't succeede") ;
11141
        failed = 1 ;
11142
    end
11143
    else
11144
    begin
11145
        if (read_status`READ_DATA !== expected_value)
11146
        begin
11147
            test_fail("AM3 initial value was not set as defined");
11148
            failed = 1 ;
11149
        end
11150
    end
11151
 
11152
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11153
 
11154
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11155
 
11156
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11157
 
11158
    `ifdef PCI_IMAGE4
11159
        expected_value = {`PCI_AM4, 12'h000};
11160
 
11161
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11162
    `else
11163
        expected_value = 32'h0000_0000 ;
11164
    `endif
11165
 
11166
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11167
    begin
11168
        test_fail("read from P_AM4 register didn't succeede") ;
11169
        failed = 1 ;
11170
    end
11171
    else
11172
    begin
11173
        if (read_status`READ_DATA !== expected_value)
11174
        begin
11175
            test_fail("AM4 initial value was not set as defined");
11176
            failed = 1 ;
11177
        end
11178
    end
11179
 
11180
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11181
 
11182
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11183
 
11184
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11185
 
11186
    `ifdef PCI_IMAGE5
11187
        expected_value = {`PCI_AM5, 12'h000};
11188
 
11189
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11190
    `else
11191
        expected_value = 32'h0000_0000 ;
11192
    `endif
11193
 
11194
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11195
    begin
11196
        test_fail("read from P_AM5 register didn't succeede") ;
11197
        failed = 1 ;
11198
    end
11199
    else
11200
    begin
11201
        if (read_status`READ_DATA !== expected_value)
11202
        begin
11203
            test_fail("AM5 initial value was not set as defined");
11204
            failed = 1 ;
11205
        end
11206
    end
11207
 
11208
`endif
11209
 
11210
`ifdef GUEST
11211
    reg [31:0] read_data ;
11212
begin
11213
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11214
    failed    = 0 ;
11215
 
11216
    // check all images' BARs
11217
 
11218
    // BAR0
11219
    configuration_cycle_read
11220
    (
11221
        8'h00,                          // bus number [7:0]
11222
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11223
        3'h0,                           // function number [2:0]
11224
        6'h4,                           // register number [5:0]
11225
        2'h0,                           // type [1:0]
11226
        4'hF,                           // byte enables [3:0]
11227
        read_data                       // data returned from configuration read [31:0]
11228
    ) ;
11229
 
11230
    expected_value = 32'h0000_0000 ;
11231
 
11232
    if( read_data !== expected_value)
11233
    begin
11234
        test_fail("initial value of BAR0 register not as expected") ;
11235
        failed = 1 ;
11236
    end
11237
 
11238
    // BAR1
11239
    configuration_cycle_read
11240
    (
11241
        8'h00,                          // bus number [7:0]
11242
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11243
        3'h0,                           // function number [2:0]
11244
        6'h5,                           // register number [5:0]
11245
        2'h0,                           // type [1:0]
11246
        4'hF,                           // byte enables [3:0]
11247
        read_data                       // data returned from configuration read [31:0]
11248
    ) ;
11249
 
11250
    if (`PCI_AM1)
11251
        expected_value = `PCI_BA1_MEM_IO ;
11252
    else
11253
        expected_value = 32'h0000_0000 ;
11254
 
11255
    if( read_data !== expected_value)
11256
    begin
11257
        test_fail("initial value of BAR1 register not as expected") ;
11258
        failed = 1 ;
11259
    end
11260
 
11261
    // BAR2
11262
    configuration_cycle_read
11263
    (
11264
        8'h00,                          // bus number [7:0]
11265
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11266
        3'h0,                           // function number [2:0]
11267
        6'h6,                           // register number [5:0]
11268
        2'h0,                           // type [1:0]
11269
        4'hF,                           // byte enables [3:0]
11270
        read_data                       // data returned from configuration read [31:0]
11271
    ) ;
11272
 
11273
    `ifdef PCI_IMAGE2
11274
    if (`PCI_AM2)
11275
        expected_value = `PCI_BA2_MEM_IO ;
11276
    else
11277
        expected_value = 32'h0000_0000 ;
11278
    `else
11279
    expected_value = 32'h0 ;
11280
    `endif
11281
 
11282
    if( read_data !== expected_value)
11283
    begin
11284
        test_fail("initial value of BAR2 register not as expected") ;
11285
        failed = 1 ;
11286
    end
11287
 
11288
    // BAR3
11289
    configuration_cycle_read
11290
    (
11291
        8'h00,                          // bus number [7:0]
11292
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11293
        3'h0,                           // function number [2:0]
11294
        6'h7,                           // register number [5:0]
11295
        2'h0,                           // type [1:0]
11296
        4'hF,                           // byte enables [3:0]
11297
        read_data                       // data returned from configuration read [31:0]
11298
    ) ;
11299
 
11300
    `ifdef PCI_IMAGE3
11301
    if(`PCI_AM3)
11302
        expected_value = `PCI_BA3_MEM_IO ;
11303
    else
11304
        expected_value = 32'h0000_0000 ;
11305
    `else
11306
    expected_value = 32'h0 ;
11307
    `endif
11308
 
11309
    if( read_data !== expected_value)
11310
    begin
11311
        test_fail("initial value of BAR3 register not as expected") ;
11312
        failed = 1 ;
11313
    end
11314
 
11315
    // BAR4
11316
    configuration_cycle_read
11317
    (
11318
        8'h00,                          // bus number [7:0]
11319
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11320
        3'h0,                           // function number [2:0]
11321
        6'h8,                           // register number [5:0]
11322
        2'h0,                           // type [1:0]
11323
        4'hF,                           // byte enables [3:0]
11324
        read_data                       // data returned from configuration read [31:0]
11325
    ) ;
11326
 
11327
    `ifdef PCI_IMAGE4
11328
    if (`PCI_AM4)
11329
        expected_value = `PCI_BA4_MEM_IO ;
11330
    else
11331
        expected_value = 32'h0000_0000 ;
11332
    `else
11333
    expected_value = 32'h0 ;
11334
    `endif
11335
 
11336
    if( read_data !== expected_value)
11337
    begin
11338
        test_fail("initial value of BAR4 register not as expected") ;
11339
        failed = 1 ;
11340
    end
11341
 
11342
    // BAR5
11343
    configuration_cycle_read
11344
    (
11345
        8'h00,                          // bus number [7:0]
11346
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11347
        3'h0,                           // function number [2:0]
11348
        6'h9,                           // register number [5:0]
11349
        2'h0,                           // type [1:0]
11350
        4'hF,                           // byte enables [3:0]
11351
        read_data                       // data returned from configuration read [31:0]
11352
    ) ;
11353
 
11354
    `ifdef PCI_IMAGE5
11355
    if(`PCI_AM5)
11356
        expected_value = `PCI_BA5_MEM_IO ;
11357
    else
11358
        expected_value = 32'h0000_0000 ;
11359
    `else
11360
    expected_value = 32'h0 ;
11361
    `endif
11362
 
11363
    if( read_data !== expected_value)
11364
    begin
11365
        test_fail("initial value of BAR5 register not as expected") ;
11366
        failed = 1 ;
11367
    end
11368
 
11369
    // write all 1s to BAR0
11370
    read_data = 32'hFFFF_FFFF ;
11371
 
11372
    // BAR0
11373
    configuration_cycle_write
11374
    (
11375
        8'h00,                          // bus number [7:0]
11376
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11377
        3'h0,                           // function number [2:0]
11378
        6'h4,                           // register number [5:0]
11379
        2'h0,                           // type [1:0]
11380
        4'hF,                           // byte enables [3:0]
11381
        read_data                       // data to write [31:0]
11382
    ) ;
11383
 
11384
    expected_value = 32'hFFFF_FFFF ;
11385
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11386
 
11387
    configuration_cycle_read
11388
    (
11389
        8'h00,                          // bus number [7:0]
11390
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11391
        3'h0,                           // function number [2:0]
11392
        6'h4,                           // register number [5:0]
11393
        2'h0,                           // type [1:0]
11394
        4'hF,                           // byte enables [3:0]
11395
        read_data                       // data to write [31:0]
11396
    ) ;
11397
 
11398
    if ( read_data !== expected_value )
11399
    begin
11400
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11401
        failed = 1 ;
11402
    end
11403
 
11404
    // write all 1s to BAR1
11405
    read_data = 32'hFFFF_FFFF ;
11406
 
11407
    // BAR1
11408
    configuration_cycle_write
11409
    (
11410
        8'h00,                          // bus number [7:0]
11411
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11412
        3'h0,                           // function number [2:0]
11413
        6'h5,                           // register number [5:0]
11414
        2'h0,                           // type [1:0]
11415
        4'hF,                           // byte enables [3:0]
11416
        read_data                       // data to write [31:0]
11417
    ) ;
11418
 
11419
    expected_value = {`PCI_AM1, 12'h000} ;
11420
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11421
    if (`PCI_AM1)
11422
        expected_value[0] = `PCI_BA1_MEM_IO ;
11423
 
11424
    configuration_cycle_read
11425
    (
11426
        8'h00,                          // bus number [7:0]
11427
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11428
        3'h0,                           // function number [2:0]
11429
        6'h5,                           // register number [5:0]
11430
        2'h0,                           // type [1:0]
11431
        4'hF,                           // byte enables [3:0]
11432
        read_data                       // data to write [31:0]
11433
    ) ;
11434
 
11435
    if ( read_data !== expected_value )
11436
    begin
11437
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11438
        failed = 1 ;
11439
    end
11440
 
11441
    // write all 1s to BAR2
11442
    read_data = 32'hFFFF_FFFF ;
11443
 
11444
    // BAR2
11445
    configuration_cycle_write
11446
    (
11447
        8'h00,                          // bus number [7:0]
11448
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11449
        3'h0,                           // function number [2:0]
11450
        6'h6,                           // register number [5:0]
11451
        2'h0,                           // type [1:0]
11452
        4'hF,                           // byte enables [3:0]
11453
        read_data                       // data to write [31:0]
11454
    ) ;
11455
 
11456
`ifdef PCI_IMAGE2
11457
    expected_value = {`PCI_AM2, 12'h000} ;
11458
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11459
    if (`PCI_AM2)
11460
        expected_value[0] = `PCI_BA2_MEM_IO ;
11461
`else
11462
    expected_value = 0 ;
11463
`endif
11464
 
11465
    configuration_cycle_read
11466
    (
11467
        8'h00,                          // bus number [7:0]
11468
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11469
        3'h0,                           // function number [2:0]
11470
        6'h6,                           // register number [5:0]
11471
        2'h0,                           // type [1:0]
11472
        4'hF,                           // byte enables [3:0]
11473
        read_data                       // data to write [31:0]
11474
    ) ;
11475
 
11476
    if ( read_data !== expected_value )
11477
    begin
11478
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11479
        failed = 1 ;
11480
    end
11481
 
11482
    // write all 1s to BAR3
11483
    read_data = 32'hFFFF_FFFF ;
11484
 
11485
    // BAR3
11486
    configuration_cycle_write
11487
    (
11488
        8'h00,                          // bus number [7:0]
11489
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11490
        3'h0,                           // function number [2:0]
11491
        6'h7,                           // register number [5:0]
11492
        2'h0,                           // type [1:0]
11493
        4'hF,                           // byte enables [3:0]
11494
        read_data                       // data to write [31:0]
11495
    ) ;
11496
 
11497
`ifdef PCI_IMAGE3
11498
    expected_value = {`PCI_AM3, 12'h000} ;
11499
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11500
    if(`PCI_AM3)
11501
        expected_value[0] = `PCI_BA3_MEM_IO ;
11502
`else
11503
    expected_value = 0 ;
11504
`endif
11505
 
11506
    configuration_cycle_read
11507
    (
11508
        8'h00,                          // bus number [7:0]
11509
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11510
        3'h0,                           // function number [2:0]
11511
        6'h7,                           // register number [5:0]
11512
        2'h0,                           // type [1:0]
11513
        4'hF,                           // byte enables [3:0]
11514
        read_data                       // data to write [31:0]
11515
    ) ;
11516
 
11517
    if ( read_data !== expected_value )
11518
    begin
11519
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11520
        failed = 1 ;
11521
    end
11522
 
11523
    // write all 1s to BAR4
11524
    read_data = 32'hFFFF_FFFF ;
11525
 
11526
    // BAR4
11527
    configuration_cycle_write
11528
    (
11529
        8'h00,                          // bus number [7:0]
11530
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11531
        3'h0,                           // function number [2:0]
11532
        6'h8,                           // register number [5:0]
11533
        2'h0,                           // type [1:0]
11534
        4'hF,                           // byte enables [3:0]
11535
        read_data                       // data to write [31:0]
11536
    ) ;
11537
 
11538
`ifdef PCI_IMAGE4
11539
    expected_value = {`PCI_AM4, 12'h000} ;
11540
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11541
    if(`PCI_AM4)
11542
        expected_value[0] = `PCI_BA4_MEM_IO ;
11543
`else
11544
    expected_value = 0 ;
11545
`endif
11546
 
11547
    configuration_cycle_read
11548
    (
11549
        8'h00,                          // bus number [7:0]
11550
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11551
        3'h0,                           // function number [2:0]
11552
        6'h8,                           // register number [5:0]
11553
        2'h0,                           // type [1:0]
11554
        4'hF,                           // byte enables [3:0]
11555
        read_data                       // data to write [31:0]
11556
    ) ;
11557
 
11558
    if ( read_data !== expected_value )
11559
    begin
11560
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11561
        failed = 1 ;
11562
    end
11563
 
11564
    // write all 1s to BAR5
11565
    read_data = 32'hFFFF_FFFF ;
11566
 
11567
    // BAR5
11568
    configuration_cycle_write
11569
    (
11570
        8'h00,                          // bus number [7:0]
11571
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11572
        3'h0,                           // function number [2:0]
11573
        6'h9,                           // register number [5:0]
11574
        2'h0,                           // type [1:0]
11575
        4'hF,                           // byte enables [3:0]
11576
        read_data                       // data to write [31:0]
11577
    ) ;
11578
 
11579
`ifdef PCI_IMAGE5
11580
    expected_value = {`PCI_AM5, 12'h000} ;
11581
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11582
    if(`PCI_AM5)
11583
        expected_value[0] = `PCI_BA5_MEM_IO ;
11584
`else
11585
    expected_value = 0 ;
11586
`endif
11587
 
11588
    configuration_cycle_read
11589
    (
11590
        8'h00,                          // bus number [7:0]
11591
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11592
        3'h0,                           // function number [2:0]
11593
        6'h9,                           // register number [5:0]
11594
        2'h0,                           // type [1:0]
11595
        4'hF,                           // byte enables [3:0]
11596
        read_data                       // data to write [31:0]
11597
    ) ;
11598
 
11599
    if ( read_data !== expected_value )
11600
    begin
11601
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11602
        failed = 1 ;
11603
    end
11604
`endif
11605
 
11606
    if (!failed)
11607
        test_ok ;
11608
end
11609
endtask
11610
 
11611 15 mihad
task display_warning;
11612
    input [31:0] error_address ;
11613
    input [31:0] expected_data ;
11614
    input [31:0] actual ;
11615
begin
11616
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11617
end
11618
endtask // display warning
11619
 
11620
/*############################################################################
11621
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11622
=====================
11623
############################################################################*/
11624
 
11625
// Task reslease the PCI bus for 'delay' clocks
11626
task do_pause;
11627
  input  [15:0] delay;
11628
  reg    [15:0] cnt;
11629
  begin
11630
    test_start <= 1'b0;  // no device is allowed to take this
11631
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11632
    begin
11633
      if (~pci_reset_comb)
11634
      begin
11635
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11636
      end
11637
      `NO_ELSE;
11638
    end
11639
  end
11640
endtask // do_pause
11641
 
11642
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11643
task DO_REF;
11644
  input  [79:0] name;
11645
  input  [2:0] master_number;
11646
  input  [PCI_BUS_DATA_RANGE:0] address;
11647
  input  [3:0] command;
11648
  input  [PCI_BUS_DATA_RANGE:0] data;
11649
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11650
  input  [9:0] size;
11651
  input   make_addr_par_error, make_data_par_error;
11652
  input  [7:0] master_wait_states;
11653
  input  [7:0] target_wait_states;
11654
  input  [1:0] target_devsel_speed;
11655
  input   fast_back_to_back;
11656
  input  [2:0] target_termination;
11657
  input   expect_master_abort;
11658
  reg     waiting;
11659
  begin
11660
// Cautiously wait for previous command to be done
11661
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11662
    begin
11663
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11664
      begin
11665
        if (~pci_reset_comb)
11666
        begin
11667
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11668
        end
11669
        `NO_ELSE;
11670
      end
11671
      else
11672
      begin
11673
        waiting = 1'b0;  // ready to do next command
11674
      end
11675
    end
11676
    next_test_name[79:0] <= name[79:0];
11677
    test_master_number <= master_number[2:0];
11678
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11679
    test_command[3:0] <= command[3:0] ;
11680
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11681
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11682
    test_size <= size;
11683
    test_make_addr_par_error <= make_addr_par_error;
11684
    test_make_data_par_error <= make_data_par_error;
11685
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11686
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11687
    test_target_initial_wait_states <= target_wait_states[7:4];
11688
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11689
    test_target_devsel_speed <= target_devsel_speed[1:0];
11690
    test_fast_back_to_back <= fast_back_to_back;
11691
    test_target_termination <= target_termination[2:0];
11692
    test_expect_master_abort <= expect_master_abort;
11693
    test_start <= 1'b1;
11694
    if (~pci_reset_comb)
11695
    begin
11696
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11697
    end
11698
    `NO_ELSE;
11699
// wait for new command to start
11700
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11701
    begin
11702
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11703
      begin
11704
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11705
      end
11706
      else
11707
      begin
11708
        waiting = 1'b0;  // ready to do next command
11709
      end
11710
    end
11711
  end
11712
endtask // DO_REF
11713
 
11714
// Use Macros defined in pci_defines.vh as paramaters
11715
 
11716
// DO_REF (name[79:0], master_number[2:0],
11717
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11718
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11719
//          make_addr_par_error, make_data_par_error,
11720
//          master_wait_states[8:0], target_wait_states[8:0],
11721
//          target_devsel_speed[1:0], fast_back_to_back,
11722
//          target_termination[2:0],
11723
//          expect_master_abort);
11724
//
11725
// Example:
11726
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11727
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11728
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11729
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11730
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11731
 
11732
// Access a location with no high-order bits set, assuring that no device responds
11733
task PCIU_CONFIG_READ_MASTER_ABORT;
11734
  input  [79:0] name;
11735
  input  [2:0] master_number;
11736 51 mihad
  input  [31:0] address ;
11737
  input  [3:0] be ;
11738 15 mihad
  begin
11739 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11740
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11741
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11742 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11743
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11744
  end
11745
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11746
 
11747
// Access a location with no high-order bits set, assuring that no device responds
11748
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11749
  input  [79:0] name;
11750
  input  [2:0] master_number;
11751 51 mihad
  input  [31:0] address ;
11752
  input  [3:0] be ;
11753 15 mihad
  begin
11754 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11755
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11756
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11757 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11758
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11759
  end
11760
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11761
 
11762
// Access a location with no high-order bits set, assuring that no device responds
11763
task PCIU_MEM_READ_MASTER_ABORT;
11764
  input  [79:0] name;
11765
  input  [2:0] master_number;
11766
  input  [9:0] size;
11767
  begin
11768
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11769
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11770
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11771
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11772
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11773
  end
11774
endtask // PCIU_MEM_READ_MASTER_ABORT
11775
 
11776
// Access a location with no high-order bits set, assuring that no device responds
11777
task PCIU_MEM_WRITE_MASTER_ABORT;
11778
  input  [79:0] name;
11779
  input  [2:0] master_number;
11780
  input  [9:0] size;
11781
  begin
11782
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11783
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11784
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11785
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11786
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11787
  end
11788
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11789
 
11790
// Do variable length transfers with various paramaters
11791
task PCIU_CONFIG_READ;
11792
  input  [79:0] name;
11793
  input  [2:0] master_number;
11794
  input  [PCI_BUS_DATA_RANGE:0] address;
11795
  input  [PCI_BUS_DATA_RANGE:0] data;
11796
  input  [3:0] be ;
11797
  input  [9:0] size;
11798
  input  [7:0] master_wait_states;
11799
  input  [7:0] target_wait_states;
11800
  input  [1:0] target_devsel_speed;
11801
  input  [2:0] target_termination;
11802
  begin
11803
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11804
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11805
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11806
              8'h0_0, target_wait_states[7:0],
11807
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11808
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11809
  end
11810
endtask // PCIU_CONFIG_READ
11811
 
11812
task PCIU_CONFIG_WRITE;
11813
  input  [79:0] name;
11814
  input  [2:0] master_number;
11815
  input  [PCI_BUS_DATA_RANGE:0] address;
11816
  input  [PCI_BUS_DATA_RANGE:0] data;
11817
  input  [3:0] be ;
11818
  input  [9:0] size;
11819
  input  [7:0] master_wait_states;
11820
  input  [7:0] target_wait_states;
11821
  input  [1:0] target_devsel_speed;
11822
  input  [2:0] target_termination;
11823
  begin
11824
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11825
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11826
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11827
              8'h0_0, target_wait_states[7:0],
11828
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11829
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11830
  end
11831
endtask // PCIU_CONFIG_WRITE
11832
 
11833
task PCIU_READ;
11834
  input  [2:0] master_number;
11835
  input  [PCI_BUS_DATA_RANGE:0] address;
11836
  input  [3:0] command;
11837
  input  [PCI_BUS_DATA_RANGE:0] data;
11838
  input  [3:0] byte_en;
11839
  input  [9:0] size;
11840
  input  [7:0] master_wait_states;
11841
  input  [7:0] target_wait_states;
11842
  input  [1:0] target_devsel_speed;
11843
  input  [2:0] target_termination;
11844
  reg    [79:0] name;
11845
  begin
11846
    if (command == `BC_MEM_READ)
11847
        name = "MEM_READ  " ;
11848
    else if (command == `BC_MEM_READ_LN)
11849
        name = "MEM_RD_LN " ;
11850
    else if (command == `BC_MEM_READ_MUL )
11851
        name = "MEM_RD_MUL" ;
11852
    else
11853
        name = "WRONG_READ" ;
11854
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11855
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11856
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11857
              8'h0_0, target_wait_states[7:0],
11858
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11859
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11860
  end
11861
endtask // PCIU_READ
11862
 
11863
task PCIU_MEM_READ;
11864
  input  [79:0] name;
11865
  input  [2:0] master_number;
11866
  input  [PCI_BUS_DATA_RANGE:0] address;
11867
  input  [PCI_BUS_DATA_RANGE:0] data;
11868
  input  [9:0] size;
11869
  input  [7:0] master_wait_states;
11870
  input  [7:0] target_wait_states;
11871
  input  [1:0] target_devsel_speed;
11872
  input  [2:0] target_termination;
11873
  begin
11874
 
11875
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11876
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11877
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11878
              8'h0_0, target_wait_states[7:0],
11879
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11880
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11881
  end
11882
endtask // PCIU_MEM_READ
11883
 
11884
task PCIU_IO_READ;
11885
  input  [2:0] master_number;
11886
  input  [PCI_BUS_DATA_RANGE:0] address;
11887
  input  [PCI_BUS_DATA_RANGE:0] data;
11888
  input  [3:0] byte_en ;
11889
  input  [9:0] size;
11890
  input  [2:0] target_termination ;
11891
  begin
11892
 
11893
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11894
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11895
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11896
              8'h0_0, `Test_One_Zero_Target_WS,
11897
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11898
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11899
  end
11900
endtask // PCIU_IO_READ
11901
 
11902
task PCIU_IO_READ_MAKE_PERR;
11903
  input  [2:0] master_number;
11904
  input  [PCI_BUS_DATA_RANGE:0] address;
11905
  input  [PCI_BUS_DATA_RANGE:0] data;
11906
  input  [3:0] byte_en ;
11907
  input  [9:0] size;
11908
  input  [2:0] target_termination ;
11909
  begin
11910
 
11911
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11912
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11913
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11914
              8'h0_0, `Test_One_Zero_Target_WS,
11915
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11916
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11917
  end
11918
endtask // PCIU_IO_READ_MAKE_PERR
11919
 
11920
task PCIU_MEM_READ_LN;
11921
  input  [79:0] name;
11922
  input  [2:0] master_number;
11923
  input  [PCI_BUS_DATA_RANGE:0] address;
11924
  input  [PCI_BUS_DATA_RANGE:0] data;
11925
  input  [9:0] size;
11926
  input  [7:0] master_wait_states;
11927
  input  [7:0] target_wait_states;
11928
  input  [1:0] target_devsel_speed;
11929
  input  [2:0] target_termination;
11930
  begin
11931
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11932
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11933
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11934
              8'h0_0, target_wait_states[7:0],
11935
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11936
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11937
  end
11938
endtask // PCIU_MEM_READ_LN
11939
 
11940
task PCIU_MEM_READ_MUL;
11941
  input  [79:0] name;
11942
  input  [2:0] master_number;
11943
  input  [PCI_BUS_DATA_RANGE:0] address;
11944
  input  [PCI_BUS_DATA_RANGE:0] data;
11945
  input  [9:0] size;
11946
  input  [7:0] master_wait_states;
11947
  input  [7:0] target_wait_states;
11948
  input  [1:0] target_devsel_speed;
11949
  input  [2:0] target_termination;
11950
  begin
11951
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11952
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11953
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11954
              8'h0_0, target_wait_states[7:0],
11955
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11956
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11957
  end
11958
endtask // PCIU_MEM_READ_MUL
11959
 
11960
task PCIU_MEM_READ_MAKE_PERR;
11961
  input  [79:0] name;
11962
  input  [2:0] master_number;
11963
  input  [PCI_BUS_DATA_RANGE:0] address;
11964
  input  [PCI_BUS_DATA_RANGE:0] data;
11965
  input  [9:0] size;
11966
  input  [7:0] master_wait_states;
11967
  input  [7:0] target_wait_states;
11968
  input  [1:0] target_devsel_speed;
11969
  input  [2:0] target_termination;
11970
  begin
11971
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11972
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11973
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11974
              8'h0_0, target_wait_states[7:0],
11975
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11976
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11977
  end
11978
endtask // PCIU_MEM_READ_MAKE_PERR
11979
 
11980
task PCIU_MEM_WRITE;
11981
  input  [79:0] name;
11982
  input  [2:0] master_number;
11983
  input  [PCI_BUS_DATA_RANGE:0] address;
11984
  input  [PCI_BUS_DATA_RANGE:0] data;
11985
  input  [3:0] byte_en;
11986
  input  [9:0] size;
11987
  input  [7:0] master_wait_states;
11988
  input  [7:0] target_wait_states;
11989
  input  [1:0] target_devsel_speed;
11990
  input  [2:0] target_termination;
11991
  begin
11992
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11993
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11994
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11995
              8'h0_0, target_wait_states[7:0],
11996
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11997
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11998
  end
11999
endtask // PCIU_MEM_WRITE
12000
 
12001
task PCIU_IO_WRITE;
12002
  input  [2:0] master_number;
12003
  input  [PCI_BUS_DATA_RANGE:0] address;
12004
  input  [PCI_BUS_DATA_RANGE:0] data;
12005
  input  [3:0] byte_en;
12006
  input  [9:0] size;
12007
  input  [2:0] target_termination ;
12008
  begin
12009
 
12010
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12011
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12012
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12013
              8'h0_0, `Test_One_Zero_Target_WS,
12014
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12015
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12016
  end
12017
endtask // PCIU_IO_WRITE
12018
 
12019
task PCIU_IO_WRITE_MAKE_PERR ;
12020
  input  [2:0] master_number;
12021
  input  [PCI_BUS_DATA_RANGE:0] address;
12022
  input  [PCI_BUS_DATA_RANGE:0] data;
12023
  input  [3:0] byte_en;
12024
  input  [9:0] size;
12025
  input  [2:0] target_termination ;
12026
  begin
12027
 
12028
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12029
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12030
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12031
              8'h0_0, `Test_One_Zero_Target_WS,
12032
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12033
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12034
  end
12035
endtask // PCIU_IO_WRITE
12036
 
12037
task PCIU_MEM_WRITE_MAKE_SERR;
12038
  input  [79:0] name;
12039
  input  [2:0] master_number;
12040
  input  [PCI_BUS_DATA_RANGE:0] address;
12041
  input  [PCI_BUS_DATA_RANGE:0] data;
12042
  input  [9:0] size;
12043
  input  [7:0] master_wait_states;
12044
  input  [7:0] target_wait_states;
12045
  input  [1:0] target_devsel_speed;
12046
  input  [2:0] target_termination;
12047
  begin
12048
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12049
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12050
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12051
              8'h0_0, target_wait_states[7:0],
12052
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12053
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12054
  end
12055
endtask // PCIU_MEM_WRITE_MAKE_SERR
12056
 
12057
task PCIU_MEM_WRITE_MAKE_PERR;
12058
  input  [79:0] name;
12059
  input  [2:0] master_number;
12060
  input  [PCI_BUS_DATA_RANGE:0] address;
12061
  input  [PCI_BUS_DATA_RANGE:0] data;
12062
  input  [9:0] size;
12063
  input  [7:0] master_wait_states;
12064
  input  [7:0] target_wait_states;
12065
  input  [1:0] target_devsel_speed;
12066
  input  [2:0] target_termination;
12067
  begin
12068
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12069
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12070
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12071
              8'h0_0, target_wait_states[7:0],
12072
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12073
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12074
  end
12075
endtask // PCIU_MEM_WRITE
12076
 
12077
/*--------------------------------------------------------------------------
12078
Initialization CASES
12079
--------------------------------------------------------------------------*/
12080
 
12081
// Initialize the basic Config Registers of the PCI bridge target device
12082
task configure_bridge_target;
12083
    reg [11:0] offset ;
12084
    reg [31:0] data ;
12085
    `ifdef HOST
12086
    reg `WRITE_STIM_TYPE   write_data ;
12087
    reg `WB_TRANSFER_FLAGS write_flags ;
12088
    reg `WRITE_RETURN_TYPE write_status ;
12089
    `else
12090
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12091
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12092
    `endif
12093
 
12094
    reg [31:0] temp_var ;
12095
begin
12096
`ifdef HOST //  set Header
12097
    offset  = 12'h4 ; // PCI Header Command register
12098
    data    = 32'h0000_0007 ; // enable master & target operation
12099
 
12100
    write_flags                      = 0 ;
12101
    write_flags`INIT_WAITS           = tb_init_waits ;
12102
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12103
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12104
 
12105
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12106
    write_data`WRITE_SEL      = 4'h1 ;
12107
    write_data`WRITE_TAG_STIM = 0 ;
12108
    write_data`WRITE_DATA     = data ;
12109
 
12110
    next_test_name[79:0] <= "Init_Tar_R";
12111
 
12112
    $display(" bridge target - Enabling master and target operation!");
12113
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12114
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12115
    begin
12116
        $display("Write to configuration space failed! Time %t ", $time) ;
12117
    end
12118
 
12119
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12120
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12121
 
12122
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12123
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12124
 
12125
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12126
    write_data`WRITE_SEL      = 4'hf ;
12127
    write_data`WRITE_TAG_STIM = 0 ;
12128
    write_data`WRITE_DATA     = data ;
12129
 
12130
 `ifdef  NO_CNF_IMAGE
12131
  `ifdef PCI_IMAGE0 //      set P_BA0
12132
 
12133
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12134
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12135
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12136
    begin
12137
        $display("Write to configuration space failed! Time %t ", $time) ;
12138
    end
12139
  `endif
12140
 `else //      set P_BA0
12141
 
12142
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12143
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12144
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12145
    begin
12146
        $display("Write to configuration space failed! Time %t ", $time) ;
12147
    end
12148
 `endif
12149
 
12150
`else // GUEST, set Header, set P_BA0
12151
    data            = 32'h0000_0007 ; // enable master & target operation
12152
    byte_enables    = 4'hF ;
12153
    $display(" bridge target - Enabling master and target operation!");
12154 45 mihad
    configuration_cycle_write(0,                        // bus number
12155
                              `TAR0_IDSEL_INDEX - 11,   // device number
12156
                              0,                        // function number
12157
                              1,                        // register number
12158
                              0,                        // type of configuration cycle
12159
                              byte_enables,             // byte enables
12160
                              data                      // data
12161 15 mihad
                             ) ;
12162
 
12163
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12164
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12165
    byte_enables = 4'hf ;
12166 45 mihad
    configuration_cycle_write(0,                        // bus number
12167
                              `TAR0_IDSEL_INDEX - 11,   // device number
12168
                              0,                        // function number
12169
                              4,                        // register number
12170
                              0,                        // type of configuration cycle
12171
                              byte_enables,             // byte enables
12172
                              data                      // data
12173 15 mihad
                             ) ;
12174
 
12175
`endif
12176
end
12177
endtask // configure_bridge_target
12178
 
12179
// Initialize the basic Config Registers of the PCI bridge target device
12180
task configure_bridge_target_base_addresses;
12181
    reg [11:0] offset ;
12182
    reg [31:0] data ;
12183
    `ifdef HOST
12184
    reg `WRITE_STIM_TYPE   write_data ;
12185
    reg `WB_TRANSFER_FLAGS write_flags ;
12186
    reg `WRITE_RETURN_TYPE write_status ;
12187
    `else
12188
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12189
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12190
    `endif
12191
 
12192
    reg [31:0] temp_var ;
12193
begin
12194
`ifdef HOST //  set Header
12195
    offset  = 12'h4 ; // PCI Header Command register
12196
    data    = 32'h0000_0007 ; // enable master & target operation
12197
 
12198
    write_flags                    = 0 ;
12199
    write_flags`INIT_WAITS         = tb_init_waits ;
12200
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12201
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12202
 
12203
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12204
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12205
 
12206
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12207
    write_data`WRITE_SEL      = 4'h1 ;
12208
    write_data`WRITE_TAG_STIM = 0 ;
12209
    write_data`WRITE_DATA     = data ;
12210
 
12211
    next_test_name[79:0] <= "Init_Tar_R";
12212
 
12213
    $display(" bridge target - Enabling master and target operation!");
12214
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12215
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12216
    begin
12217
        $display("Write to configuration space failed! Time %t ", $time) ;
12218
    end
12219
 
12220
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12221
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12222
 
12223
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12224
    write_data`WRITE_SEL      = 4'hf ;
12225
    write_data`WRITE_TAG_STIM = 0 ;
12226
    write_data`WRITE_DATA     = data ;
12227
 
12228
 `ifdef  NO_CNF_IMAGE
12229
  `ifdef PCI_IMAGE0 //      set P_BA0
12230
 
12231
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12232
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12233
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12234
    begin
12235
        $display("Write to configuration space failed! Time %t ", $time) ;
12236
    end
12237
  `endif
12238
 `else //      set P_BA0
12239
 
12240
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12241
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12242
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12243
    begin
12244
        $display("Write to configuration space failed! Time %t ", $time) ;
12245
    end
12246
 `endif
12247
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12248
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12249
 
12250
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12251
    write_data`WRITE_SEL      = 4'hf ;
12252
    write_data`WRITE_TAG_STIM = 0 ;
12253
    write_data`WRITE_DATA     = data ;
12254
 
12255
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12256
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12257
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12258
    begin
12259
        $display("Write to configuration space failed! Time %t ", $time) ;
12260
    end
12261
 `ifdef PCI_IMAGE2
12262
 
12263
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12264
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12265
 
12266
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12267
    write_data`WRITE_SEL      = 4'hf ;
12268
    write_data`WRITE_TAG_STIM = 0 ;
12269
    write_data`WRITE_DATA     = data ;
12270
 
12271
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12272
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12273
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12274
    begin
12275
        $display("Write to configuration space failed! Time %t ", $time) ;
12276
    end
12277
 `endif
12278
 `ifdef PCI_IMAGE3
12279
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12280
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12281
 
12282
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12283
    write_data`WRITE_SEL      = 4'hf ;
12284
    write_data`WRITE_TAG_STIM = 0 ;
12285
    write_data`WRITE_DATA     = data ;
12286
 
12287
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12288
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12289
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12290
    begin
12291
        $display("Write to configuration space failed! Time %t ", $time) ;
12292
    end
12293
 `endif
12294
 `ifdef PCI_IMAGE4
12295
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12296
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12297
 
12298
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12299
    write_data`WRITE_SEL      = 4'hf ;
12300
    write_data`WRITE_TAG_STIM = 0 ;
12301
    write_data`WRITE_DATA     = data ;
12302
 
12303
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12304
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12305
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12306
    begin
12307
        $display("Write to configuration space failed! Time %t ", $time) ;
12308
    end
12309
 `endif
12310
 `ifdef PCI_IMAGE5
12311
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12312
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12313
 
12314
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12315
    write_data`WRITE_SEL      = 4'hf ;
12316
    write_data`WRITE_TAG_STIM = 0 ;
12317
    write_data`WRITE_DATA     = data ;
12318
 
12319
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12320
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12321
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12322
    begin
12323
        $display("Write to configuration space failed! Time %t ", $time) ;
12324
    end
12325
 `endif
12326
 
12327
`else // GUEST, set Header, set P_BA0
12328
    data            = 32'h0000_0007 ; // enable master & target operation
12329
    byte_enables    = 4'hF ;
12330
    $display(" bridge target - Enabling master and target operation!");
12331 45 mihad
    configuration_cycle_write(0,                        // bus number
12332
                              `TAR0_IDSEL_INDEX - 11,   // device number
12333
                              0,                        // function number
12334
                              1,                        // register number
12335
                              0,                        // type of configuration cycle
12336
                              byte_enables,             // byte enables
12337
                              data                      // data
12338 15 mihad
                             ) ;
12339
 
12340
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12341
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12342
    byte_enables = 4'hf ;
12343 45 mihad
    configuration_cycle_write(0,                        // bus number
12344
                              `TAR0_IDSEL_INDEX - 11,   // device number
12345
                              0,                        // function number
12346
                              4,                        // register number
12347
                              0,                        // type of configuration cycle
12348
                              byte_enables,             // byte enables
12349
                              data                      // data
12350 15 mihad
                             ) ;
12351
 
12352
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12353
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12354
    byte_enables = 4'hf ;
12355 45 mihad
    configuration_cycle_write(0,                        // bus number
12356
                              `TAR0_IDSEL_INDEX - 11,   // device number
12357
                              0,                        // function number
12358
                              5,                        // register number
12359
                              0,                        // type of configuration cycle
12360
                              byte_enables,             // byte enables
12361
                              data                      // data
12362 15 mihad
                             ) ;
12363
 `ifdef PCI_IMAGE2
12364
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12365
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12366
    byte_enables = 4'hf ;
12367 45 mihad
    configuration_cycle_write(0,                        // bus number
12368
                              `TAR0_IDSEL_INDEX - 11,   // device number
12369
                              0,                        // function number
12370
                              6,                        // register number
12371
                              0,                        // type of configuration cycle
12372
                              byte_enables,             // byte enables
12373
                              data                      // data
12374 15 mihad
                             ) ;
12375
 `endif
12376
 `ifdef PCI_IMAGE3
12377
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12378
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12379
    byte_enables = 4'hf ;
12380 45 mihad
    configuration_cycle_write(0,                        // bus number
12381
                              `TAR0_IDSEL_INDEX - 11,   // device number
12382
                              0,                        // function number
12383
                              7,                        // register number
12384
                              0,                        // type of configuration cycle
12385
                              byte_enables,             // byte enables
12386
                              data                      // data
12387 15 mihad
                             ) ;
12388
 `endif
12389
 `ifdef PCI_IMAGE4
12390
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12391
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12392
    byte_enables = 4'hf ;
12393 45 mihad
    configuration_cycle_write(0,                        // bus number
12394
                              `TAR0_IDSEL_INDEX - 11,   // device number
12395
                              0,                        // function number
12396
                              8,                        // register number
12397
                              0,                        // type of configuration cycle
12398
                              byte_enables,             // byte enables
12399
                              data                      // data
12400 15 mihad
                             ) ;
12401
 `endif
12402
 `ifdef PCI_IMAGE5
12403
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12404
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12405
    byte_enables = 4'hf ;
12406 45 mihad
    configuration_cycle_write(0,                        // bus number
12407
                              `TAR0_IDSEL_INDEX - 11,   // device number
12408
                              0,                        // function number
12409
                              9,                        // register number
12410
                              0,                        // type of configuration cycle
12411
                              byte_enables,             // byte enables
12412
                              data                      // data
12413 15 mihad
                             ) ;
12414
 `endif
12415
`endif
12416
end
12417
endtask // configure_bridge_target_base_addresses
12418
 
12419
/*--------------------------------------------------------------------------
12420
Test CASES
12421
--------------------------------------------------------------------------*/
12422
 
12423
// function converts PCI address to WB with the same data as the pci_decoder does
12424
function [31:0] pci_to_wb_addr_convert ;
12425
 
12426
    input [31:0] pci_address ;
12427
    input [31:0] translation_address ;
12428
    input [31:0] translate ;
12429
 
12430
    reg   [31:0] temp_address ;
12431
begin
12432
    if ( translate !== 1 )
12433
    begin
12434
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12435
    end
12436
    else
12437
    begin
12438
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12439
    end
12440
 
12441
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12442
    pci_to_wb_addr_convert = temp_address ;
12443
end
12444
endfunction // pci_to_wb_addr_convert
12445
 
12446
// Test normal write and read to WB slave
12447
task test_normal_wr_rd;
12448
  input  [2:0]  Master_ID;
12449
  input  [PCI_BUS_DATA_RANGE:0] Address;
12450
  input  [PCI_BUS_DATA_RANGE:0] Data;
12451
  input  [3:0]  Be;
12452
  input  [2:0]  Image_num;
12453
  input  [9:0]  Set_size;
12454
  input         Set_addr_translation;
12455
  input         Set_prefetch_enable;
12456
  input  [7:0]  Cache_lsize;
12457
  input         Set_wb_wait_states;
12458
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12459
 
12460
  reg    [31:0] rd_address;
12461
  reg    [31:0] rd_data;
12462
  reg    [3:0]  rd_be;
12463
  reg    [11:0] addr_offset;
12464
  reg    [31:0] read_data;
12465
  reg           continue ;
12466
  reg           ok   ;
12467
  reg    [31:0] expect_address ;
12468
  reg    [31:0] expect_rd_address ;
12469
  reg           expect_we ;
12470
  reg    [9:0]  expect_length_wr ;
12471
  reg    [9:0]  expect_length_rd ;
12472
  reg    [9:0]  expect_length_rd1 ;
12473
  reg    [9:0]  expect_length_rd2 ;
12474
  reg    [3:0]  use_rd_cmd ;
12475
  integer       i ;
12476 35 mihad
  reg           error_monitor_done ;
12477 15 mihad
begin:main
12478
 
12479
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12480
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12481
    $display(" - errors will be reported, but they should not occur!");
12482
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12483
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12484
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12485
    if ( ok !== 1 )
12486
    begin
12487
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12488
        test_fail("write to P_ERR_CS register didn't succeede") ;
12489
        disable main;
12490
    end
12491
 
12492
    `ifdef  ADDR_TRAN_IMPL
12493
 
12494
    // set or clear address translation
12495
    if (Set_addr_translation)
12496
    begin
12497
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12498
        $display(" - address translation will be performed!");
12499
    end
12500
    else
12501
    begin
12502
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12503
        $display(" - address translation will not be performed!");
12504
    end
12505
    // set or clear pre-fetch enable
12506
    if (Set_prefetch_enable)
12507
    begin
12508
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12509
        $display(" - bursts can be performed!");
12510
    end
12511
    else
12512
    begin
12513
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12514
        $display(" - bursts can not be performed!");
12515
    end
12516
 
12517
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12518
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12519
    if ( ok !== 1 )
12520
    begin
12521
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12522
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12523
        disable main;
12524
    end
12525
 
12526
    // predict the address and control signals on WB bus
12527
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12528
    expect_we      = 1'b1 ; // WRITE
12529
 
12530
    `else
12531
 
12532
    // address translation is not implemented
12533
    $display("Address translation is NOT implemented for PCI images!");
12534
    // set or clear pre-fetch enable
12535
    if (Set_prefetch_enable)
12536
    begin
12537
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12538
        $display(" - bursts can be performed!");
12539
    end
12540
    else
12541
    begin
12542
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12543
        $display(" - bursts can not be performed!");
12544
    end
12545
 
12546
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12547
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12548
    if ( ok !== 1 )
12549
    begin
12550
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12551
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12552
        disable main;
12553
    end
12554
 
12555
    // predict the address and control signals on WB bus
12556
    expect_address = Address ;
12557
    expect_we      = 1'b1 ; // WRITE
12558
 
12559
    `endif
12560
 
12561
    // set WB SLAVE parameters
12562
    if (Set_wb_wait_states)
12563
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12564
    else
12565
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12566
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12567
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12568
 
12569
    if ( Set_size > (`PCIW_DEPTH - 2) )
12570
    begin
12571
        expect_length_wr = `PCIW_DEPTH - 2 ;
12572
    end
12573
    else
12574
    begin
12575
        expect_length_wr = Set_size ;
12576
    end
12577
    // write through the PCI bridge to WB slave
12578
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12579
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12580
 
12581
    fork
12582
    begin
12583
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12584
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12585
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12586
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12587
        do_pause( 1 ) ;
12588
    end
12589
    begin
12590
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12591
       if ( ok !== 1 )
12592
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12593
       else
12594
           test_ok ;
12595
    end
12596
    join
12597
 
12598
    // predict the address and control signals on WB bus
12599
    expect_we      = 1'b0 ; // READ
12600
 
12601
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12602
    $display("Memory read through PCI bridge to WB slave!");
12603
 
12604
    if ( expect_length_wr == 1 )
12605
    begin
12606
        if (Set_prefetch_enable)
12607
        begin
12608
            expect_length_rd1 = Cache_lsize ;
12609
            expect_length_rd2 = 0 ;
12610
                // If PCI behavioral master must check received DATA
12611
                master2_check_received_data = 0 ;
12612
                    master1_check_received_data = 0 ;
12613
        end
12614
        else
12615
        begin
12616
            expect_length_rd1 = 1 ;
12617
            expect_length_rd2 = 0 ;
12618
                // If PCI behavioral master must check received DATA
12619
                master2_check_received_data = 1 ;
12620
                    master1_check_received_data = 1 ;
12621
        end
12622
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12623
        expect_length_rd  = expect_length_rd1 ;
12624
    end
12625
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12626
    begin
12627
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12628
        expect_length_rd2 = 0 ;
12629
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12630
        expect_length_rd  = expect_length_rd1 ;
12631
                // If PCI behavioral master must check received DATA
12632
        master2_check_received_data = 1 ;
12633
            master1_check_received_data = 1 ;
12634
    end
12635
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12636
    begin
12637
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12638
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12639
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12640
        expect_length_rd  = expect_length_rd1 ;
12641
                // If PCI behavioral master must check received DATA
12642
                master2_check_received_data = 1 ;
12643
            master1_check_received_data = 1 ;
12644
    end
12645
    else
12646
    begin
12647
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12648
        begin
12649
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12650
            expect_length_rd2 = 0 ;
12651
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12652
            expect_length_rd  = expect_length_rd1 ;
12653
                // If PCI behavioral master must check received DATA
12654
                master2_check_received_data = 0 ;
12655
                    master1_check_received_data = 0 ;
12656
        end
12657
        else
12658
        begin
12659
            if ( expect_length_wr > Cache_lsize )
12660
            begin
12661
                expect_length_rd1 = Cache_lsize ;
12662
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12663
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12664
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12665
                else
12666
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12667
                expect_length_rd  = expect_length_rd1 ;
12668
                        // If PCI behavioral master must check received DATA
12669
                        master2_check_received_data = 1 ;
12670
                            master1_check_received_data = 1 ;
12671
            end
12672
            else
12673
            begin
12674
                expect_length_rd1 = Cache_lsize ;
12675
                expect_length_rd2 = 0 ;
12676
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12677
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12678
                else
12679
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12680
                expect_length_rd  = expect_length_wr ;
12681
                                if ( expect_length_wr == Cache_lsize )
12682
                        begin
12683
                                // If PCI behavioral master must check received DATA
12684
                                master2_check_received_data = 1 ;
12685
                                    master1_check_received_data = 1 ;
12686
                                end
12687
                                else
12688
                                begin
12689
                                // If PCI behavioral master must check received DATA
12690
                                master2_check_received_data = 0 ;
12691
                                    master1_check_received_data = 0 ;
12692
                end
12693
            end
12694
        end
12695
    end
12696
 
12697
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12698
    expect_rd_address = expect_address ;
12699
    rd_data[31:0] = Data[31:0];
12700
    rd_be[3:0] = Be[3:0];
12701
 
12702
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12703
    while (expect_length_rd2 > 0)
12704
    begin
12705
        // do read
12706
        $display("Read %d words!", expect_length_rd);
12707
 
12708
        fork
12709
        begin
12710
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12711
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12712
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12713
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12714
 
12715
            wb_transaction_stop( expect_length_rd - 1) ;
12716
 
12717
            do_pause( 1 ) ;
12718
        end
12719
        begin
12720
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12721
            if ( ok !== 1 )
12722
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12723
 
12724
            repeat( 3 )
12725
                @(posedge pci_clock) ;
12726
 
12727
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12728
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12729
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12730
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12731
 
12732
            do_pause( 1 ) ;
12733
            while ( FRAME === 0 )
12734
                @(posedge pci_clock) ;
12735
 
12736
            while ( IRDY === 0 )
12737
                @(posedge pci_clock) ;
12738
 
12739 35 mihad
            #1 ;
12740
            if ( !error_monitor_done )
12741
                disable monitor_error_event1 ;
12742 15 mihad
        end
12743
        begin:monitor_error_event1
12744 35 mihad
            error_monitor_done = 0 ;
12745 15 mihad
            @(error_event_int) ;
12746
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12747
            ok = 0 ;
12748 35 mihad
            error_monitor_done = 1 ;
12749 15 mihad
        end
12750
        join
12751
 
12752
        // increasing the starting address for PCI master and for WB transaction monitor
12753
        rd_address = rd_address + (4 * expect_length_rd) ;
12754
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12755
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12756
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12757
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12758
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12759
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12760
        for (i=0; i<expect_length_rd; i=i+1)
12761
            rd_be[3:0] = {Be[2:0], Be[3]};
12762
 
12763
        // set parameters for next read
12764
        if ( expect_length_rd2 == 1 )
12765
        begin
12766
                if (Set_prefetch_enable)
12767
                begin
12768
                    expect_length_rd1 = Cache_lsize ;
12769
                    expect_length_rd2 = 0 ;
12770
                        // If PCI behavioral master must check received DATA
12771
                        master2_check_received_data = 0 ;
12772
                            master1_check_received_data = 0 ;
12773
                end
12774
                else
12775
                begin
12776
                    expect_length_rd1 = 1 ;
12777
                    expect_length_rd2 = 0 ;
12778
                        // If PCI behavioral master must check received DATA
12779
                        master2_check_received_data = 1 ;
12780
                            master1_check_received_data = 1 ;
12781
                end
12782
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12783
            expect_length_rd  = expect_length_rd1 ;
12784
        end
12785
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12786
        begin
12787
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12788
            expect_length_rd2 = 0 ;
12789
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12790
            expect_length_rd  = expect_length_rd1 ;
12791
                        // If PCI behavioral master must check received DATA
12792
                        master2_check_received_data = 1 ;
12793
                    master1_check_received_data = 1 ;
12794
        end
12795
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12796
        begin
12797
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12798
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12799
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12800
            expect_length_rd  = expect_length_rd1 ;
12801
                        // If PCI behavioral master must check received DATA
12802
                        master2_check_received_data = 1 ;
12803
                    master1_check_received_data = 1 ;
12804
        end
12805
        else
12806
        begin
12807
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12808
            begin
12809
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12810
                expect_length_rd2 = 0 ;
12811
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12812
                expect_length_rd  = expect_length_rd1 ;
12813
                        // If PCI behavioral master must check received DATA
12814
                        master2_check_received_data = 0 ;
12815
                            master1_check_received_data = 0 ;
12816
            end
12817
            else
12818
            begin
12819
                if ( expect_length_rd2 > Cache_lsize )
12820
                begin
12821
                    expect_length_rd1 = Cache_lsize ;
12822
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12823
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12824
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12825
                    else
12826
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12827
                    expect_length_rd  = expect_length_rd1 ;
12828
                                // If PCI behavioral master must check received DATA
12829
                                master2_check_received_data = 1 ;
12830
                                    master1_check_received_data = 1 ;
12831
                end
12832
                else
12833
                begin
12834
                    expect_length_rd  = expect_length_rd2 ;
12835
                    expect_length_rd1 = Cache_lsize ;
12836
                    expect_length_rd2 = 0 ;
12837
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12838
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12839
                    else
12840
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12841
                                        if ( expect_length_rd2 == Cache_lsize )
12842
                                begin
12843
                                        // If PCI behavioral master must check received DATA
12844
                                        master2_check_received_data = 1 ;
12845
                                            master1_check_received_data = 1 ;
12846
                                        end
12847
                                        else
12848
                                        begin
12849
                                        // If PCI behavioral master must check received DATA
12850
                                        master2_check_received_data = 0 ;
12851
                                            master1_check_received_data = 0 ;
12852
                        end
12853
                end
12854
            end
12855
        end
12856
    end
12857
    // do last read
12858
    $display("Read %d words!", expect_length_rd);
12859
 
12860
    fork
12861
    begin
12862
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12863
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12864
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12865
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12866
 
12867
        wb_transaction_stop(expect_length_rd - 1) ;
12868
        do_pause( 1 ) ;
12869
    end
12870
    begin
12871
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12872
 
12873
        do_pause(3) ;
12874
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12875
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12876
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12877
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12878
        do_pause(1) ;
12879
 
12880
        while ( FRAME === 0 )
12881
            @(posedge pci_clock) ;
12882
 
12883
        while ( IRDY === 0 )
12884
            @(posedge pci_clock) ;
12885
 
12886 35 mihad
        #1 ;
12887
        if ( !error_monitor_done )
12888
            disable monitor_error_event2 ;
12889 15 mihad
    end
12890
    begin:monitor_error_event2
12891 35 mihad
        error_monitor_done = 0 ;
12892 15 mihad
        @(error_event_int) ;
12893
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12894
        ok = 0 ;
12895 35 mihad
        error_monitor_done = 1 ;
12896 15 mihad
    end
12897
    join
12898
 
12899
    if ( ok )
12900
        test_ok ;
12901
 
12902
    // Check that no ERRORs were reported
12903
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
12904
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
12905
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12906
    config_read( addr_offset, 4'hF, read_data ) ;
12907
    if ( read_data[8] !== 0 )
12908
    begin
12909
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
12910
        test_fail("error status was set even though no errors occured on WB bus") ;
12911
    end
12912
    else
12913
    begin
12914
        $display("No error was signaled, as expected!");
12915
        test_ok ;
12916
    end
12917
 
12918
end // main
12919
endtask // test_normal_wr_rd
12920
 
12921
// Test erroneous write to WB slave
12922
task test_wb_error_wr;
12923
  input  [2:0]  Master_ID;
12924
  input  [PCI_BUS_DATA_RANGE:0] Address;
12925
  input  [PCI_BUS_DATA_RANGE:0] Data;
12926
  input  [3:0]  Be;
12927
  input  [2:0]  Image_num;
12928
  input  [9:0]  Set_size;
12929
  input         Set_err_and_int_report;
12930
  input         Set_wb_wait_states;
12931
  input  [1:0]  Imm_BefLast_Last_error;
12932
 
12933
  reg    [11:0] addr_offset;
12934
  reg    [31:0] read_data;
12935
  reg           continue ;
12936
  reg           ok   ;
12937
  reg    [9:0]  expect_length ;
12938
  reg    [31:0] expect_address ;
12939
  reg    [0:0]  expect_we ;
12940
  reg    [31:0] rd_address;
12941
  reg    [31:0] rd_data;
12942
  reg    [3:0]  rd_be;
12943
  integer       i ;
12944
begin:main
12945
    if (Set_err_and_int_report)
12946
    begin
12947
        // enable ERROR reporting, because error must be reported and interrupt if required!
12948
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12949
        $display(" - errors will be reported when they will occur!");
12950
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
12951
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
12952
        $display(" - interrupt will be reported when error will occur!");
12953
    end
12954
    else
12955
    begin
12956
        // disable ERROR reporting, because error and interrupt must not be reported!
12957
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12958
        $display(" - errors will NOT be reported when they will occur!");
12959
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
12960
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
12961
        $display(" - interrupt will NOT be reported when error will occur!");
12962
    end
12963
    // enable/disable ERROR reporting
12964
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
12965
 
12966
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12967
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
12968
    if ( ok !== 1 )
12969
    begin
12970
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12971
        test_fail("PCI Error Control and Status register could not be written") ;
12972
        disable main;
12973
    end
12974
    // enable/disable INTERRUPT reporting
12975
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
12976
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
12977
    if ( ok !== 1 )
12978
    begin
12979
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
12980
        test_fail("Interrupt Control register could not be written") ;
12981
        disable main;
12982
    end
12983
 
12984
    `ifdef  ADDR_TRAN_IMPL
12985
 
12986
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
12987
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12988
    config_read( addr_offset, 4'hF, read_data ) ;
12989
    if ( read_data[2] !== 0 )
12990
    begin
12991
        $display("Address translation is set for PCI image%d!", Image_num);
12992
        // predict the address and control signals on WB bus
12993
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
12994
        expect_we      = 1'b1 ; // WRITE
12995
    end
12996
    else
12997
    begin
12998
        $display("Address translation is NOT set for PCI image%d!", Image_num);
12999
        // predict the address and control signals on WB bus
13000
        expect_address = Address ;
13001
        expect_we      = 1'b1 ; // WRITE
13002
    end
13003
 
13004
    `else
13005
 
13006
    // address translation is not implemented
13007
    $display("Address translation is NOT implemented for PCI images!");
13008
    // predict the address and control signals on WB bus
13009
    expect_address = Address ;
13010
    expect_we      = 1'b1 ; // WRITE
13011
 
13012
    `endif
13013
 
13014
    if ( Set_size > (`PCIW_DEPTH - 2) )
13015
    begin
13016
        expect_length = `PCIW_DEPTH - 2 ;
13017
    end
13018
    else
13019
    begin
13020
        expect_length = Set_size ;
13021
    end
13022
 
13023
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13024
    begin
13025
        $display("ERR termination with first data!");
13026
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13027
    end
13028
    else if (Imm_BefLast_Last_error == 1)
13029
    begin
13030
        $display("ERR termination before last data!");
13031
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13032
    end
13033
    else
13034
    begin
13035
        $display("ERR termination with last data!");
13036
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13037
    end
13038
 
13039
    // write through the PCI bridge to WB slave
13040
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13041
    fork
13042
    begin
13043
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13044
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13045
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13046
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13047
        do_pause( 1 ) ;
13048
    end
13049
    begin
13050
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13051
        begin
13052
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13053
            if ( ok !== 1 )
13054
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13055
        end
13056
        else if (Imm_BefLast_Last_error == 1)
13057
        begin
13058
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13059
            if ( ok !== 1 )
13060
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13061
        end
13062
        else
13063
        begin
13064
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13065
            if ( ok !== 1 )
13066
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13067
        end
13068
    end
13069
    begin
13070
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13071
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13072
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13073
        else if (Imm_BefLast_Last_error == 1)
13074
        begin
13075
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13076
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13077
            wb_transaction_stop(expect_length-2) ;
13078
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13079
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13080
        end
13081
        else
13082
        begin
13083
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13084
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13085
            wb_transaction_stop(expect_length-1) ;
13086
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13087
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13088
        end
13089
    end
13090
    join
13091
 
13092
    if ( ok )
13093
        test_ok ;
13094
 
13095
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13096
    begin
13097
        rd_data[31:0] = Data[31:0];
13098
        rd_address[31:0] = expect_address;
13099
        rd_be[3:0] = Be[3:0];
13100
    end
13101
    else if (Imm_BefLast_Last_error == 1)
13102
    begin
13103
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13104
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13105
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13106
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13107
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13108
        rd_be[3:0] = Be[3:0];
13109
        for (i=0; i<(expect_length-2); i=i+1)
13110
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13111
    end
13112
    else
13113
    begin
13114
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13115
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13116
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13117
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13118
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13119
        rd_be[3:0] = Be[3:0];
13120
        for (i=0; i<(expect_length-1); i=i+1)
13121
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13122
    end
13123
 
13124
    master2_check_received_data = 0 ;
13125
    master1_check_received_data = 0 ;
13126
 
13127
    // Check if ERRORs were reported
13128
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13129
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13130
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13131
 
13132
    ok = 1 ;
13133
    config_read( addr_offset, 4'hF, read_data ) ;
13134
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13135
    begin
13136
        $display("Error was signaled and reported, as expected!");
13137
        if (read_data[31:28] === rd_be)
13138
            $display("Byte enables written into P_ERR_CS register are as expected!");
13139
        else
13140
        begin
13141
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13142
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13143
            ok = 0 ;
13144
        end
13145
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13146
            $display("Bus command written into P_ERR_CS register is as expected!");
13147
        else
13148
        begin
13149
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13150
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13151
            ok = 0 ;
13152
        end
13153
 
13154
        if ( ok )
13155
            test_ok ;
13156
 
13157
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13158
 
13159
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13160
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13161
        config_read( addr_offset, 4'hF, read_data ) ;
13162
        if (read_data === rd_data)
13163
        begin
13164
            $display("Data written into P_ERR_DATA register is as expected!");
13165
            test_ok ;
13166
        end
13167
        else
13168
        begin
13169
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13170
            test_fail("PCI Erroneous Data register value was wrong") ;
13171
        end
13172
 
13173
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13174
 
13175
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13176
 
13177
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13178
        config_read( addr_offset, 4'hF, read_data ) ;
13179
        if (read_data === rd_address)
13180
        begin
13181
            $display("Address written into P_ERR_ADDR register is as expected!");
13182
            test_ok ;
13183
        end
13184
        else
13185
        begin
13186
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13187
            test_fail("PCI Erroneous Address register value was wrong") ;
13188
        end
13189
    end
13190
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13191
    begin
13192
        $display("Error was signaled and not reported, as expected!");
13193
        test_ok ;
13194
    end
13195
    else
13196
    begin
13197
        $display("Error was signaled and reported, as NOT expected!");
13198
        test_fail("Error status bit was set event though error reporting was disabled") ;
13199
    end
13200
 
13201
    // Check if Interrupts were reported
13202
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13203
 
13204
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13205
    ok = 1 ;
13206
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13207
    config_read( addr_offset, 4'hF, read_data ) ;
13208
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13209
    begin
13210
        $display("Interrupts was signaled and reported, as expected!");
13211
    end
13212
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13213
    begin
13214
        $display("Interrupts was signaled and not reported, as expected!");
13215
    end
13216
    else
13217
    begin
13218
        $display("Interrupt was signaled and reported, as NOT expected!");
13219
        test_fail("PCI Error Interrupt status was set when not expected") ;
13220
        ok = 0 ;
13221
    end
13222
 
13223
    `ifdef HOST
13224
    repeat( 4 )
13225
        @(posedge wb_clock) ;
13226
 
13227
    if ( INT_O === Set_err_and_int_report )
13228
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13229
    else
13230
    begin
13231
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13232
        test_fail("Interrupt request didn't have expected value") ;
13233
        ok = 0 ;
13234
    end
13235
 
13236
    `else // GUEST
13237
    repeat( 4 )
13238
        @(posedge pci_clock) ;
13239
 
13240
    if ( INTA === !Set_err_and_int_report )
13241
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13242
    else
13243
    begin
13244
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13245
        test_fail("Interrupt request didn't have expected value") ;
13246
        ok = 0 ;
13247
    end
13248
 
13249
    `endif
13250
 
13251
    if ( ok )
13252
        test_ok ;
13253
 
13254
    if (Set_err_and_int_report)
13255
    begin
13256
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13257
        $display("Error and Interrupt must be cleared!");
13258
        // clear  ERROR reporting bit
13259
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13260
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13261
        if ( ok !== 1 )
13262
        begin
13263
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13264
            test_fail("PCI Error Control and Status register could not be written to") ;
13265
            disable main;
13266
        end
13267
 
13268
        // clear INTERRUPT reporting bit
13269
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13270
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13271
        if ( ok !== 1 )
13272
        begin
13273
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13274
            test_fail("Interrupt Status register could not be written to") ;
13275
            disable main;
13276
        end
13277
 
13278
        test_ok ;
13279
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13280
        `ifdef HOST
13281
 
13282
        repeat(4)
13283
            @(posedge wb_clock) ;
13284
        if ( INT_O === 1'b0 )
13285
        begin
13286
            $display("Interrupt pin INT_O was correctly cleared!");
13287
            test_ok ;
13288
        end
13289
        else
13290
        begin
13291
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13292
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13293
            disable main;
13294
        end
13295
 
13296
        `else // GUEST
13297
 
13298
        repeat(4)
13299
            @(posedge pci_clock) ;
13300
        if ( INTA === 1'b1 )
13301
        begin
13302
            $display("Interrupt pin INTA was correctly cleared!");
13303
            test_ok ;
13304
        end
13305
        else
13306
        begin
13307
            $display("Interrupt pin INTA was NOT correctly cleared!");
13308
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13309
            disable main;
13310
        end
13311
 
13312
        `endif
13313
 
13314
    end
13315
    else
13316
    begin
13317
        $display("Error and Interrupt don't need to be cleared!");
13318
    end
13319
end // main
13320
endtask // test_wb_error_wr
13321
 
13322
task test_wb_error_rd;
13323
    reg    [11:0] addr_offset ;
13324
    reg    [11:0] ctrl_offset ;
13325
    reg    [11:0] ba_offset ;
13326
    reg    [11:0] am_offset ;
13327
    reg    [11:0] ta_offset ;
13328
    reg    [31:0] read_data;
13329
    reg           ok   ;
13330
    reg    [9:0]  expect_length ;
13331
    reg    [31:0] expect_address ;
13332
    reg    [0:0]  expect_we ;
13333
    reg    [31:0] rd_address;
13334
    reg    [31:0] rd_data;
13335
    reg    [3:0]  rd_be;
13336
    integer       i ;
13337
    reg           do_mem_aborts ;
13338
    reg           do_io_aborts ;
13339 35 mihad
    reg           error_monitor_done ;
13340 15 mihad
begin:main
13341
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13342
 
13343
    if ( target_mem_image !== -1 )
13344
    begin
13345
        do_mem_aborts = 1 ;
13346
 
13347
        if (target_mem_image === 1)
13348
        begin
13349
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13350
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13351
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13352
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13353
        end
13354
        else if (target_mem_image === 2)
13355
        begin
13356
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13357
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13358
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13359
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13360
        end
13361
        else if (target_mem_image === 3)
13362
        begin
13363
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13364
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13365
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13366
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13367
        end
13368
        else if (target_mem_image === 4)
13369
        begin
13370
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13371
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13372
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13373
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13374
        end
13375
        else if (target_mem_image === 5)
13376
        begin
13377
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13378
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13379
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13380
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13381
        end
13382
    end
13383
    else
13384
        do_mem_aborts = 0 ;
13385
 
13386
    if ( do_mem_aborts )
13387
    begin
13388
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13389
 
13390
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13391
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13392
        if ( ok !== 1 )
13393
        begin
13394
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13395
            test_fail("PCI Error Control and Status register could not be written") ;
13396
            disable main;
13397
        end
13398
 
13399
        // enable INTERRUPT reporting
13400
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13401
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13402
        if ( ok !== 1 )
13403
        begin
13404
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13405
            test_fail("Interrupt Control register could not be written") ;
13406
            disable main;
13407
        end
13408
 
13409
        addr_offset = 12'h010 + (4*target_mem_image) ;
13410
 
13411
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13412
        if ( ok !== 1 )
13413
        begin
13414
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13415
            test_fail("PCI Base Address register could not be written") ;
13416
            disable main;
13417
        end
13418
 
13419
        // disable address translation and enable prefetch so read bursts can be performed
13420
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13421
        if ( ok !== 1 )
13422
        begin
13423
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13424
            test_fail("PCI Image Control register could not be written") ;
13425
            disable main;
13426
        end
13427
 
13428
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13429
        if ( ok !== 1 )
13430
        begin
13431
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13432
            test_fail("PCI Address Mask register could not be written") ;
13433
            disable main;
13434
        end
13435
 
13436
        addr_offset = 12'h00C ;
13437
 
13438
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13439
        if ( ok !== 1 )
13440
        begin
13441
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13442
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13443
            disable main;
13444
        end
13445
 
13446
        // disable PCI master data checking
13447
        master1_check_received_data = 0 ;
13448
 
13449
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13450
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13451
 
13452
 
13453
        // do a single read error terminated on WB bus
13454
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13455
 
13456
        fork
13457
        begin
13458
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13459
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13460
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13461
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13462
 
13463
            do_pause( 1 ) ;
13464
        end
13465
        begin
13466
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13467
 
13468
            if ( ok !== 1 )
13469
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13470
 
13471
            do_pause(3) ;
13472
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13473
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13474
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13475
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13476
            do_pause(1) ;
13477
 
13478
            while ( FRAME === 0 )
13479
                @(posedge pci_clock) ;
13480
 
13481
            while ( IRDY === 0 )
13482
                @(posedge pci_clock) ;
13483
 
13484 35 mihad
            #1 ;
13485
            if ( !error_monitor_done )
13486
                disable monitor_error_event1 ;
13487 15 mihad
        end
13488
        begin:monitor_error_event1
13489 35 mihad
            error_monitor_done = 0 ;
13490 15 mihad
            @(error_event_int) ;
13491
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13492
            ok = 0 ;
13493 35 mihad
            error_monitor_done = 1 ;
13494 15 mihad
        end
13495
        join
13496
 
13497
        if ( ok )
13498
            test_ok ;
13499 26 mihad
 
13500
        @(posedge pci_clock) ;
13501
        @(posedge pci_clock) ;
13502
        @(posedge wb_clock) ;
13503
        @(posedge wb_clock) ;
13504 15 mihad
 
13505
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13506
        addr_offset = 12'h004 ;
13507
        config_read(addr_offset, 4'hF, read_data) ;
13508
        ok = 1 ;
13509
        if ( read_data[27] !== 1 )
13510
        begin
13511
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13512
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13513
            ok = 0 ;
13514
        end
13515
        if ( read_data[28] !== 0 )
13516
        begin
13517
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13518
            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") ;
13519
            ok = 0 ;
13520
        end
13521
        if ( read_data[29] !== 0 )
13522
        begin
13523
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13524
            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") ;
13525
            ok = 0 ;
13526
        end
13527
 
13528
        // clear statuses
13529
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13530
        if ( !ok )
13531
        begin
13532
            test_fail("write to PCI Device Status register failed") ;
13533
            $display("Couldn't write PCI Device Status register") ;
13534
            disable main ;
13535
        end
13536
 
13537
        if ( ok )
13538
            test_ok ;
13539
 
13540
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13541
 
13542
        ok = 1 ;
13543
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13544
 
13545
        config_read(addr_offset, 4'hF, read_data) ;
13546
        if (read_data[8] !== 0)
13547
        begin
13548
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13549
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13550
            ok = 0 ;
13551
        end
13552
        else
13553
            test_ok ;
13554
 
13555
        if ( ok !== 1 )
13556
        begin
13557
            config_write(addr_offset, read_data, 4'hF, ok) ;
13558
            if ( !ok )
13559
            begin
13560
                test_fail("PCI Error Control and Status register could not be written") ;
13561
                disable main ;
13562
            end
13563
        end
13564
 
13565
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13566
        fork
13567
        begin
13568
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13569
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13570
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13571
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13572
 
13573
            do_pause( 1 ) ;
13574
        end
13575
        begin
13576
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13577
 
13578
            if ( ok !== 1 )
13579
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13580
 
13581
            do_pause(3) ;
13582
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13583
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13584
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13585
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13586
            do_pause(1) ;
13587
 
13588
            while ( FRAME === 0 )
13589
                @(posedge pci_clock) ;
13590
 
13591
            while ( IRDY === 0 )
13592
                @(posedge pci_clock) ;
13593
 
13594 35 mihad
            #1 ;
13595
            if ( !error_monitor_done )
13596
                disable monitor_error_event2 ;
13597 15 mihad
        end
13598
        begin:monitor_error_event2
13599 35 mihad
            error_monitor_done = 0 ;
13600 15 mihad
            @(error_event_int) ;
13601
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13602
            ok = 0 ;
13603 35 mihad
            error_monitor_done = 1 ;
13604 15 mihad
        end
13605
        join
13606
 
13607
        if ( ok )
13608
            test_ok ;
13609
 
13610 26 mihad
        @(posedge pci_clock) ;
13611
        @(posedge pci_clock) ;
13612
        @(posedge wb_clock) ;
13613
        @(posedge wb_clock) ;
13614
 
13615 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13616
        addr_offset = 12'h004 ;
13617
        config_read(addr_offset, 4'hF, read_data) ;
13618
        ok = 1 ;
13619
        if ( read_data[27] !== 1 )
13620
        begin
13621
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13622
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13623
            ok = 0 ;
13624
        end
13625
        if ( read_data[28] !== 0 )
13626
        begin
13627
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13628
            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") ;
13629
            ok = 0 ;
13630
        end
13631
        if ( read_data[29] !== 0 )
13632
        begin
13633
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13634
            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") ;
13635
            ok = 0 ;
13636
        end
13637
 
13638
        // clear statuses
13639
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13640
        if ( !ok )
13641
        begin
13642
            test_fail("write to PCI Device Status register failed") ;
13643
            $display("Couldn't write PCI Device Status register") ;
13644
            disable main ;
13645
        end
13646
 
13647
        if ( ok )
13648
            test_ok ;
13649
 
13650
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13651
 
13652
        ok = 1 ;
13653
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13654
 
13655
        config_read(addr_offset, 4'hF, read_data) ;
13656
        if (read_data[8] !== 0)
13657
        begin
13658
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13659
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13660
            ok = 0 ;
13661
        end
13662
        else
13663
            test_ok ;
13664
 
13665
        if ( ok !== 1 )
13666
        begin
13667
            config_write(addr_offset, read_data, 4'hF, ok) ;
13668
            if ( !ok )
13669
            begin
13670
                test_fail("PCI Error Control and Status register could not be written") ;
13671
                disable main ;
13672
            end
13673
        end
13674
 
13675
        // do a single read error terminated on WB bus
13676
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13677
 
13678
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13679
 
13680
        fork
13681
        begin
13682
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13683
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13684
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13685
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13686
 
13687
            do_pause( 1 ) ;
13688
        end
13689
        begin
13690
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13691
 
13692
            if ( ok !== 1 )
13693
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13694
 
13695
            do_pause(3) ;
13696
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13697
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13698
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13699
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13700
            do_pause(1) ;
13701
 
13702
            while ( FRAME === 0 )
13703
                @(posedge pci_clock) ;
13704
 
13705
            while ( IRDY === 0 )
13706
                @(posedge pci_clock) ;
13707
 
13708 35 mihad
            if ( !error_monitor_done )
13709
                disable monitor_error_event3 ;
13710 15 mihad
        end
13711
        begin:monitor_error_event3
13712 35 mihad
            error_monitor_done = 0 ;
13713 15 mihad
            @(error_event_int) ;
13714
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13715
            ok = 0 ;
13716 35 mihad
            error_monitor_done = 1 ;
13717 15 mihad
        end
13718
        join
13719
 
13720
        if ( ok )
13721
            test_ok ;
13722
 
13723 26 mihad
        @(posedge pci_clock) ;
13724
        @(posedge pci_clock) ;
13725
        @(posedge wb_clock) ;
13726
        @(posedge wb_clock) ;
13727
 
13728 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13729
        addr_offset = 12'h004 ;
13730
        config_read(addr_offset, 4'hF, read_data) ;
13731
        ok = 1 ;
13732
        if ( read_data[27] !== 1 )
13733
        begin
13734
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13735
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13736
            ok = 0 ;
13737
        end
13738
        if ( read_data[28] !== 0 )
13739
        begin
13740
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13741
            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") ;
13742
            ok = 0 ;
13743
        end
13744
        if ( read_data[29] !== 0 )
13745
        begin
13746
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13747
            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") ;
13748
            ok = 0 ;
13749
        end
13750
 
13751
        // clear statuses
13752
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13753
        if ( !ok )
13754
        begin
13755
            test_fail("write to PCI Device Status register failed") ;
13756
            $display("Couldn't write PCI Device Status register") ;
13757
            disable main ;
13758
        end
13759
 
13760
        if ( ok )
13761
            test_ok ;
13762
 
13763
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13764
 
13765
        ok = 1 ;
13766
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13767
 
13768
        config_read(addr_offset, 4'hF, read_data) ;
13769
        if (read_data[8] !== 0)
13770
        begin
13771
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13772
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13773
            ok = 0 ;
13774
        end
13775
        else
13776
            test_ok ;
13777
 
13778
        if ( ok !== 1 )
13779
        begin
13780
            config_write(addr_offset, read_data, 4'hF, ok) ;
13781
            if ( !ok )
13782
            begin
13783
                test_fail("PCI Error Control and Status register could not be written") ;
13784
                disable main ;
13785
            end
13786
        end
13787
 
13788
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13789
 
13790
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13791
 
13792
        fork
13793
        begin
13794
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13795
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13796
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13797
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13798
 
13799
            do_pause( 1 ) ;
13800
        end
13801
        begin
13802
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13803
 
13804
            if ( ok !== 1 )
13805
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13806
 
13807
            do_pause(3) ;
13808
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13809
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13810
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13811
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13812
            do_pause(1) ;
13813
 
13814
            while ( FRAME === 0 )
13815
                @(posedge pci_clock) ;
13816
 
13817
            while ( IRDY === 0 )
13818
                @(posedge pci_clock) ;
13819
 
13820 35 mihad
            #1 ;
13821
            if ( !error_monitor_done )
13822
                disable monitor_error_event4 ;
13823 15 mihad
        end
13824
        begin:monitor_error_event4
13825 35 mihad
            error_monitor_done = 0 ;
13826 15 mihad
            @(error_event_int) ;
13827
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13828
            ok = 0 ;
13829 35 mihad
            error_monitor_done = 1 ;
13830 15 mihad
        end
13831
        begin
13832
            wb_transaction_stop( 1 ) ;
13833
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13834
        end
13835
        join
13836
 
13837
        if ( ok )
13838
            test_ok ;
13839
 
13840 26 mihad
        @(posedge pci_clock) ;
13841
        @(posedge pci_clock) ;
13842
        @(posedge wb_clock) ;
13843
        @(posedge wb_clock) ;
13844
 
13845 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13846
        addr_offset = 12'h004 ;
13847
        config_read(addr_offset, 4'hF, read_data) ;
13848
        ok = 1 ;
13849
        if ( read_data[27] !== 1 )
13850
        begin
13851
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13852
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13853
            ok = 0 ;
13854
        end
13855
        if ( read_data[28] !== 0 )
13856
        begin
13857
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13858
            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") ;
13859
            ok = 0 ;
13860
        end
13861
        if ( read_data[29] !== 0 )
13862
        begin
13863
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13864
            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") ;
13865
            ok = 0 ;
13866
        end
13867
 
13868
        // clear statuses
13869
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13870
        if ( !ok )
13871
        begin
13872
            test_fail("write to PCI Device Status register failed") ;
13873
            $display("Couldn't write PCI Device Status register") ;
13874
            disable main ;
13875
        end
13876
 
13877
        if ( ok )
13878
            test_ok ;
13879
 
13880
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13881
 
13882
        ok = 1 ;
13883
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13884
 
13885
        config_read(addr_offset, 4'hF, read_data) ;
13886
        if (read_data[8] !== 0)
13887
        begin
13888
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13889
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13890
            ok = 0 ;
13891
        end
13892
        else
13893
            test_ok ;
13894
 
13895
        if ( ok !== 1 )
13896
        begin
13897
            config_write(addr_offset, read_data, 4'hF, ok) ;
13898
            if ( !ok )
13899
            begin
13900
                test_fail("PCI Error Control and Status register could not be written") ;
13901
                disable main ;
13902
            end
13903
        end
13904
 
13905
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
13906
 
13907
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13908
 
13909
        fork
13910
        begin
13911
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13912
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13913
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13914
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13915
 
13916
            do_pause( 1 ) ;
13917
        end
13918
        begin
13919
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
13920
 
13921
            if ( ok !== 1 )
13922
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13923
 
13924
            do_pause(3) ;
13925
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13926
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13927
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13928
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13929
            do_pause(1) ;
13930
 
13931
            while ( FRAME === 0 )
13932
                @(posedge pci_clock) ;
13933
 
13934
            while ( IRDY === 0 )
13935
                @(posedge pci_clock) ;
13936
 
13937 35 mihad
            #1 ;
13938
            if ( !error_monitor_done )
13939
                disable monitor_error_event5 ;
13940 15 mihad
        end
13941
        begin:monitor_error_event5
13942 35 mihad
            error_monitor_done = 0 ;
13943 15 mihad
            @(error_event_int) ;
13944
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13945
            ok = 0 ;
13946 35 mihad
            error_monitor_done = 1 ;
13947 15 mihad
        end
13948
        begin
13949
            wb_transaction_stop( 3 ) ;
13950
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13951
        end
13952
        join
13953
 
13954
        if ( ok )
13955
            test_ok ;
13956
 
13957 26 mihad
        @(posedge pci_clock) ;
13958
        @(posedge pci_clock) ;
13959
        @(posedge wb_clock) ;
13960
        @(posedge wb_clock) ;
13961
 
13962 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13963
        addr_offset = 12'h004 ;
13964
        config_read(addr_offset, 4'hF, read_data) ;
13965
        ok = 1 ;
13966
        if ( read_data[27] !== 1 )
13967
        begin
13968
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13969
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13970
            ok = 0 ;
13971
        end
13972
        if ( read_data[28] !== 0 )
13973
        begin
13974
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13975
            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") ;
13976
            ok = 0 ;
13977
        end
13978
        if ( read_data[29] !== 0 )
13979
        begin
13980
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13981
            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") ;
13982
            ok = 0 ;
13983
        end
13984
 
13985
        // clear statuses
13986
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13987
        if ( !ok )
13988
        begin
13989
            test_fail("write to PCI Device Status register failed") ;
13990
            $display("Couldn't write PCI Device Status register") ;
13991
            disable main ;
13992
        end
13993
 
13994
        if ( ok )
13995
            test_ok ;
13996
 
13997
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13998
 
13999
        ok = 1 ;
14000
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14001
 
14002
        config_read(addr_offset, 4'hF, read_data) ;
14003
        if (read_data[8] !== 0)
14004
        begin
14005
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14006
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14007
            ok = 0 ;
14008
        end
14009
        else
14010
            test_ok ;
14011
 
14012
        if ( ok !== 1 )
14013
        begin
14014
            config_write(addr_offset, read_data, 4'hF, ok) ;
14015
            if ( !ok )
14016
            begin
14017
                test_fail("PCI Error Control and Status register could not be written") ;
14018
                disable main ;
14019
            end
14020
        end
14021
 
14022
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14023
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14024
        fork
14025
        begin
14026
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14027
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14028
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14029
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14030
 
14031
            do_pause( 1 ) ;
14032
        end
14033
        begin
14034
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14035
 
14036
            if ( ok !== 1 )
14037
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14038
 
14039
            do_pause(3) ;
14040
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14041
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14042
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14043
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14044
            do_pause(1) ;
14045
 
14046
            while ( FRAME === 0 )
14047
                @(posedge pci_clock) ;
14048
 
14049
            while ( IRDY === 0 )
14050
                @(posedge pci_clock) ;
14051
 
14052 35 mihad
            #1 ;
14053
            if ( !error_monitor_done )
14054
                disable monitor_error_event6 ;
14055 15 mihad
        end
14056
        begin:monitor_error_event6
14057 35 mihad
            error_monitor_done = 0 ;
14058 15 mihad
            @(error_event_int) ;
14059
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14060
            ok = 0 ;
14061 35 mihad
            error_monitor_done = 1 ;
14062 15 mihad
        end
14063
        begin
14064
            wb_transaction_stop( 3 ) ;
14065
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14066
        end
14067
        join
14068
 
14069
        if ( ok )
14070
            test_ok ;
14071
 
14072 26 mihad
        @(posedge pci_clock) ;
14073
        @(posedge pci_clock) ;
14074
        @(posedge wb_clock) ;
14075
        @(posedge wb_clock) ;
14076
 
14077 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14078
        addr_offset = 12'h004 ;
14079
        config_read(addr_offset, 4'hF, read_data) ;
14080
        ok = 1 ;
14081
        if ( read_data[27] !== 1 )
14082
        begin
14083
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14084
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14085
            ok = 0 ;
14086
        end
14087
        if ( read_data[28] !== 0 )
14088
        begin
14089
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14090
            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") ;
14091
            ok = 0 ;
14092
        end
14093
        if ( read_data[29] !== 0 )
14094
        begin
14095
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14096
            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") ;
14097
            ok = 0 ;
14098
        end
14099
 
14100
        // clear statuses
14101
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14102
        if ( !ok )
14103
        begin
14104
            test_fail("write to PCI Device Status register failed") ;
14105
            $display("Couldn't write PCI Device Status register") ;
14106
            disable main ;
14107
        end
14108
 
14109
        if ( ok )
14110
            test_ok ;
14111
 
14112
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14113
 
14114
        ok = 1 ;
14115
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14116
 
14117
        config_read(addr_offset, 4'hF, read_data) ;
14118
        if (read_data[8] !== 0)
14119
        begin
14120
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14121
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14122
            ok = 0 ;
14123
        end
14124
        else
14125
            test_ok ;
14126
 
14127
        if ( ok !== 1 )
14128
        begin
14129
            config_write(addr_offset, read_data, 4'hF, ok) ;
14130
            if ( !ok )
14131
            begin
14132
                test_fail("PCI Error Control and Status register could not be written") ;
14133
                disable main ;
14134
            end
14135
        end
14136
 
14137
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14138
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14139
        fork
14140
        begin
14141
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14142
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14143
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14144
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14145
 
14146
            do_pause( 1 ) ;
14147
        end
14148
        begin
14149
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14150
 
14151
            if ( ok !== 1 )
14152
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14153
 
14154
            do_pause(3) ;
14155
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14156
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14157
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14158
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14159
            do_pause(1) ;
14160
 
14161
            while ( FRAME === 0 )
14162
                @(posedge pci_clock) ;
14163
 
14164
            while ( IRDY === 0 )
14165
                @(posedge pci_clock) ;
14166
 
14167 35 mihad
            #1 ;
14168
            if ( !error_monitor_done )
14169
                disable monitor_error_event7 ;
14170 15 mihad
        end
14171
        begin:monitor_error_event7
14172 35 mihad
            error_monitor_done = 0 ;
14173 15 mihad
            @(error_event_int) ;
14174
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14175
            ok = 0 ;
14176 35 mihad
            error_monitor_done = 1 ;
14177 15 mihad
        end
14178
        begin
14179
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14180
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14181
        end
14182
        join
14183
 
14184
        if ( ok )
14185
            test_ok ;
14186
 
14187 26 mihad
        @(posedge pci_clock) ;
14188
        @(posedge pci_clock) ;
14189
        @(posedge wb_clock) ;
14190
        @(posedge wb_clock) ;
14191
 
14192 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14193
        addr_offset = 12'h004 ;
14194
        config_read(addr_offset, 4'hF, read_data) ;
14195
        ok = 1 ;
14196
        if ( read_data[27] !== 1 )
14197
        begin
14198
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14199
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14200
            ok = 0 ;
14201
        end
14202
        if ( read_data[28] !== 0 )
14203
        begin
14204
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14205
            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") ;
14206
            ok = 0 ;
14207
        end
14208
        if ( read_data[29] !== 0 )
14209
        begin
14210
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14211
            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") ;
14212
            ok = 0 ;
14213
        end
14214
 
14215
        // clear statuses
14216
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14217
        if ( !ok )
14218
        begin
14219
            test_fail("write to PCI Device Status register failed") ;
14220
            $display("Couldn't write PCI Device Status register") ;
14221
            disable main ;
14222
        end
14223
 
14224
        if ( ok )
14225
            test_ok ;
14226
 
14227
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14228
 
14229
        ok = 1 ;
14230
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14231
 
14232
        config_read(addr_offset, 4'hF, read_data) ;
14233
        if (read_data[8] !== 0)
14234
        begin
14235
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14236
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14237
            ok = 0 ;
14238
        end
14239
        else
14240
            test_ok ;
14241
 
14242
        if ( ok !== 1 )
14243
        begin
14244
            config_write(addr_offset, read_data, 4'hF, ok) ;
14245
            if ( !ok )
14246
            begin
14247
                test_fail("PCI Error Control and Status register could not be written") ;
14248
                disable main ;
14249
            end
14250
        end
14251
 
14252
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14253
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14254
        fork
14255
        begin
14256
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14257
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14258
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14259
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14260
 
14261
            do_pause( 1 ) ;
14262
        end
14263
        begin
14264
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14265
 
14266
            if ( ok !== 1 )
14267
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14268
 
14269
            do_pause(3) ;
14270
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14271
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14272
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14273
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14274
            do_pause(1) ;
14275
 
14276
            while ( FRAME === 0 )
14277
                @(posedge pci_clock) ;
14278
 
14279
            while ( IRDY === 0 )
14280
                @(posedge pci_clock) ;
14281
 
14282 35 mihad
            #1 ;
14283
            if ( !error_monitor_done )
14284
                disable monitor_error_event8 ;
14285 15 mihad
        end
14286
        begin:monitor_error_event8
14287 35 mihad
            error_monitor_done = 0 ;
14288 15 mihad
            @(error_event_int) ;
14289
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14290
            ok = 0 ;
14291 35 mihad
            error_monitor_done = 1 ;
14292 15 mihad
        end
14293
        begin
14294
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14295
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14296
        end
14297
        join
14298
 
14299
        if ( ok )
14300
            test_ok ;
14301
 
14302 26 mihad
        @(posedge pci_clock) ;
14303
        @(posedge pci_clock) ;
14304
        @(posedge wb_clock) ;
14305
        @(posedge wb_clock) ;
14306
 
14307 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14308
 
14309
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14310
        addr_offset = 12'h004 ;
14311
        config_read(addr_offset, 4'hF, read_data) ;
14312
        ok = 1 ;
14313
        if ( read_data[27] !== 1 )
14314
        begin
14315
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14316
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14317
            ok = 0 ;
14318
        end
14319
        if ( read_data[28] !== 0 )
14320
        begin
14321
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14322
            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") ;
14323
            ok = 0 ;
14324
        end
14325
        if ( read_data[29] !== 0 )
14326
        begin
14327
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14328
            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") ;
14329
            ok = 0 ;
14330
        end
14331
 
14332
        // clear statuses
14333
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14334
        if ( !ok )
14335
        begin
14336
            test_fail("write to PCI Device Status register failed") ;
14337
            $display("Couldn't write PCI Device Status register") ;
14338
            disable main ;
14339
        end
14340
 
14341
        if ( ok )
14342
            test_ok ;
14343
 
14344
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14345
 
14346
        ok = 1 ;
14347
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14348
 
14349
        config_read(addr_offset, 4'hF, read_data) ;
14350
        if (read_data[8] !== 0)
14351
        begin
14352
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14353
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14354
            ok = 0 ;
14355
        end
14356
        else
14357
            test_ok ;
14358
 
14359
        if ( ok !== 1 )
14360
        begin
14361
            config_write(addr_offset, read_data, 4'hF, ok) ;
14362
            if ( !ok )
14363
            begin
14364
                test_fail("PCI Error Control and Status register could not be written") ;
14365
                disable main ;
14366
            end
14367
        end
14368
 
14369
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14370
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14371
        fork
14372
        begin
14373
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14374
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14375
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14376
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14377
 
14378
            do_pause( 1 ) ;
14379
        end
14380
        begin
14381
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14382
 
14383
            if ( ok !== 1 )
14384
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14385
 
14386
            do_pause(3) ;
14387
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14388
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14389
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14390
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14391
            do_pause(1) ;
14392
 
14393
            while ( FRAME === 0 )
14394
                @(posedge pci_clock) ;
14395
 
14396
            while ( IRDY === 0 )
14397
                @(posedge pci_clock) ;
14398
 
14399 35 mihad
            #1 ;
14400
            if ( !error_monitor_done )
14401
                disable monitor_error_event9 ;
14402 15 mihad
        end
14403
        begin:monitor_error_event9
14404 35 mihad
            error_monitor_done = 0 ;
14405 15 mihad
            @(error_event_int) ;
14406
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14407
            ok = 0 ;
14408 35 mihad
            error_monitor_done = 1 ;
14409 15 mihad
        end
14410
        begin
14411
            wb_transaction_stop( 3 ) ;
14412
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14413
        end
14414
        join
14415
 
14416
        if ( ok )
14417
            test_ok ;
14418
 
14419
        // now check all other statuses too
14420
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14421
        ok = 1 ;
14422
 
14423
        addr_offset = 12'h004 ;
14424
        config_read(addr_offset, 4'hF, read_data) ;
14425
        if (read_data[31] !== 0)
14426
        begin
14427
            $display("Detected Parity Error bit set for no reason") ;
14428
            test_fail("Detected Parity Error bit was set for no reason") ;
14429
            ok = 0 ;
14430
        end
14431
 
14432
        if (read_data[30] !== 0)
14433
        begin
14434
            $display("Signaled System Error bit set for no reason") ;
14435
            test_fail("Signaled System Error bit was set for no reason") ;
14436
            ok = 0 ;
14437
        end
14438
 
14439
        if (read_data[29] !== 0)
14440
        begin
14441
            $display("Received Master Abort bit set for no reason") ;
14442
            test_fail("Received Master Abort bit was set for no reason") ;
14443
            ok = 0 ;
14444
        end
14445
 
14446
        if (read_data[28] !== 0)
14447
        begin
14448
            $display("Received Target Abort bit set for no reason");
14449
            test_fail("Received Target Abort bit was set for no reason") ;
14450
            ok = 0 ;
14451
        end
14452
 
14453
        if (read_data[27] !== 0)
14454
        begin
14455
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14456
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14457
            ok = 0 ;
14458
        end
14459
 
14460
        if (read_data[24] !== 0)
14461
        begin
14462
            $display("Master Data Parity Error bit set for no reason") ;
14463
            test_fail("Master Data Parity Error bit was set for no reason") ;
14464
            ok = 0 ;
14465
        end
14466
 
14467
        if ( ok )
14468
            test_ok ;
14469
 
14470
        test_name = "DISABLE IMAGE" ;
14471 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14472 15 mihad
        if ( ok !== 1 )
14473
        begin
14474
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14475
            test_fail("PCI Address Mask register could not be written") ;
14476
            disable main;
14477
        end
14478
    end
14479
 
14480
    if ( target_io_image !== -1 )
14481
    begin
14482
        do_io_aborts = 1 ;
14483
 
14484
        if (target_io_image === 1)
14485
        begin
14486
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14487
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14488
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14489
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14490
        end
14491
        else if (target_io_image === 2)
14492
        begin
14493
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14494
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14495
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14496
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14497
        end
14498
        else if (target_io_image === 3)
14499
        begin
14500
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14501
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14502
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14503
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14504
        end
14505
        else if (target_io_image === 4)
14506
        begin
14507
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14508
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14509
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14510
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14511
        end
14512
        else if (target_io_image === 5)
14513
        begin
14514
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14515
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14516
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14517
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14518
        end
14519
    end
14520
    else
14521
        do_io_aborts = 0 ;
14522
 
14523
    if ( do_io_aborts )
14524
    begin
14525
 
14526
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14527
 
14528
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14529
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14530
        if ( ok !== 1 )
14531
        begin
14532
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14533
            test_fail("PCI Error Control and Status register could not be written") ;
14534
            disable main;
14535
        end
14536
 
14537
        // enable INTERRUPT reporting
14538
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14539
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14540
        if ( ok !== 1 )
14541
        begin
14542
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14543
            test_fail("Interrupt Control register could not be written") ;
14544
            disable main;
14545
        end
14546
 
14547
        addr_offset = 12'h010 + (4*target_io_image) ;
14548
 
14549
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14550
        if ( ok !== 1 )
14551
        begin
14552
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14553
            test_fail("PCI Base Address register could not be written") ;
14554
            disable main;
14555
        end
14556
 
14557
        // disable address translation and enable prefetch so read bursts can be performed
14558
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14559
        if ( ok !== 1 )
14560
        begin
14561
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14562
            test_fail("PCI Image Control register could not be written") ;
14563
            disable main;
14564
        end
14565
 
14566
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14567
        if ( ok !== 1 )
14568
        begin
14569
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14570
            test_fail("PCI Address Mask register could not be written") ;
14571
            disable main;
14572
        end
14573
 
14574
        addr_offset = 12'h00C ;
14575
 
14576
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14577
        if ( ok !== 1 )
14578
        begin
14579
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14580
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14581
            disable main;
14582
        end
14583
 
14584
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14585
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14586
 
14587
        // do a single read error terminated on WB bus
14588
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14589
 
14590
        fork
14591
        begin
14592
            PCIU_IO_READ
14593
             (
14594
                `Test_Master_1,
14595
                Target_Base_Addr_R[target_io_image],
14596
                32'hAAAA_5555,
14597
                4'h0,
14598
                1,
14599
                `Test_Target_Retry_On
14600
             );
14601
 
14602
            do_pause( 1 ) ;
14603
        end
14604
        begin
14605
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14606
 
14607
            if ( ok !== 1 )
14608
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14609
 
14610
            do_pause(3) ;
14611
 
14612
            PCIU_IO_READ
14613
             (
14614
                `Test_Master_1,
14615
                Target_Base_Addr_R[target_io_image],
14616
                32'hAAAA_5555,
14617
                4'h0,
14618
                1,
14619
                `Test_Target_Abort_On
14620
             );
14621
 
14622
            do_pause( 1 ) ;
14623
 
14624
            while ( FRAME === 0 )
14625
                @(posedge pci_clock) ;
14626
 
14627
            while ( IRDY === 0 )
14628
                @(posedge pci_clock) ;
14629
 
14630 35 mihad
            #1 ;
14631
            if ( !error_monitor_done )
14632
                disable monitor_error_event10 ;
14633 15 mihad
        end
14634
        begin:monitor_error_event10
14635 35 mihad
            error_monitor_done = 0 ;
14636 15 mihad
            @(error_event_int) ;
14637
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14638
            ok = 0 ;
14639 35 mihad
            error_monitor_done = 1 ;
14640 15 mihad
        end
14641
        join
14642
 
14643
        if ( ok )
14644
            test_ok ;
14645
 
14646 26 mihad
        @(posedge pci_clock) ;
14647
        @(posedge pci_clock) ;
14648
        @(posedge wb_clock) ;
14649
        @(posedge wb_clock) ;
14650
 
14651 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14652
        addr_offset = 12'h004 ;
14653
        config_read(addr_offset, 4'hF, read_data) ;
14654
        ok = 1 ;
14655
        if ( read_data[27] !== 1 )
14656
        begin
14657
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14658
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14659
            ok = 0 ;
14660
        end
14661
        if ( read_data[28] !== 0 )
14662
        begin
14663
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14664
            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") ;
14665
            ok = 0 ;
14666
        end
14667
        if ( read_data[29] !== 0 )
14668
        begin
14669
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14670
            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") ;
14671
            ok = 0 ;
14672
        end
14673
 
14674
        // clear statuses
14675
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14676
        if ( !ok )
14677
        begin
14678
            test_fail("write to PCI Device Status register failed") ;
14679
            $display("Couldn't write PCI Device Status register") ;
14680
            disable main ;
14681
        end
14682
 
14683
        if ( ok )
14684
            test_ok ;
14685
 
14686
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14687
 
14688
        ok = 1 ;
14689
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14690
 
14691
        config_read(addr_offset, 4'hF, read_data) ;
14692
        if (read_data[8] !== 0)
14693
        begin
14694
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14695
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14696
            ok = 0 ;
14697
        end
14698
        else
14699
            test_ok ;
14700
 
14701
        if ( ok !== 1 )
14702
        begin
14703
            config_write(addr_offset, read_data, 4'hF, ok) ;
14704
            if ( !ok )
14705
            begin
14706
                test_fail("PCI Error Control and Status register could not be written") ;
14707
                disable main ;
14708
            end
14709
        end
14710
 
14711
        test_name = "DISABLE IMAGE" ;
14712 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14713 15 mihad
        if ( ok !== 1 )
14714
        begin
14715
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14716
            test_fail("PCI Address Mask register could not be written") ;
14717
            disable main;
14718
        end
14719
 
14720
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14721
 
14722
    end
14723
end // main
14724
endtask // test_wb_error_rd
14725
 
14726
task test_target_abort ;
14727
    input [2:0]  image_num ;
14728
    reg   [11:0] pci_ctrl_offset ;
14729
    reg   [11:0] ctrl_offset ;
14730
    reg   [11:0] ba_offset ;
14731
    reg   [11:0] am_offset ;
14732
    reg   [11:0] ta_offset ;
14733
    reg   [31:0] pci_address ;
14734
    reg   [3:0]  byte_enables ;
14735
    reg          ok ;
14736 35 mihad
    reg          error_monitor_done ;
14737 15 mihad
begin:main
14738
    pci_ctrl_offset = 12'h4 ;
14739
    if (image_num === 0)
14740
    begin
14741
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14742
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14743
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14744
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14745
    end
14746
    else if (image_num === 1)
14747
    begin
14748
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14749
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14750
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14751
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14752
    end
14753
    else if (image_num === 2)
14754
    begin
14755
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14756
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14757
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14758
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14759
    end
14760
    else if (image_num === 3)
14761
    begin
14762
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14763
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14764
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14765
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14766
    end
14767
    else if (image_num === 4)
14768
    begin
14769
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14770
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14771
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14772
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14773
    end
14774
    else if (image_num === 5)
14775
    begin
14776
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14777
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14778
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14779
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14780
    end
14781
 
14782
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14783
 
14784
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14785
    if ( ok !== 1 )
14786
    begin
14787
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14788
        test_fail("PCI Base Address register could not be written") ;
14789
        disable main ;
14790
    end
14791
 
14792
    // Set Address Mask of IMAGE
14793
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14794
    if ( ok !== 1 )
14795
    begin
14796
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14797
        test_fail("PCI Address Mask register could not be written") ;
14798
        disable main ;
14799
    end
14800
 
14801
    // Set Translation Address of IMAGE
14802
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14803
    if ( ok !== 1 )
14804
    begin
14805
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14806
        test_fail("PCI Translation Address Register could not be written") ;
14807
        disable main ;
14808
    end
14809
 
14810
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14811
    if ( ok !== 1 )
14812
    begin
14813
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14814
        test_fail("PCI Image Control register could not be written") ;
14815
        disable main ;
14816
    end
14817
 
14818
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14819
 
14820
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14821
 
14822
    pci_address  = Target_Base_Addr_R[image_num] ;
14823
    byte_enables = 4'b0001 ;
14824
 
14825
    fork
14826
    begin
14827
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14828
        do_pause ( 1 ) ;
14829
    end
14830
    begin:monitor_error_event1
14831 35 mihad
        error_monitor_done = 0 ;
14832 15 mihad
        @(error_event_int) ;
14833
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14834
        ok = 0 ;
14835 35 mihad
        error_monitor_done = 1 ;
14836 15 mihad
    end
14837
    begin
14838
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14839
        @(posedge pci_clock) ;
14840 35 mihad
        #1 ;
14841
        if ( !error_monitor_done )
14842
            disable monitor_error_event1 ;
14843 15 mihad
    end
14844
    join
14845
 
14846
    if ( ok )
14847
        test_ok ;
14848
 
14849
    ok = 1 ;
14850
 
14851
    fork
14852
    begin
14853
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14854
        do_pause ( 1 ) ;
14855
    end
14856
    begin:monitor_error_event2
14857 35 mihad
        error_monitor_done = 0 ;
14858 15 mihad
        @(error_event_int) ;
14859
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14860
        ok = 0 ;
14861 35 mihad
        error_monitor_done = 1 ;
14862 15 mihad
    end
14863
    begin
14864
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14865
        @(posedge pci_clock) ;
14866 35 mihad
        #1 ;
14867
        if ( !error_monitor_done )
14868
            disable monitor_error_event2 ;
14869 15 mihad
    end
14870
    join
14871
 
14872
    if ( ok )
14873
        test_ok ;
14874
 
14875
    ok = 1 ;
14876
 
14877
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
14878
    byte_enables = 4'b0011 ;
14879
 
14880
    fork
14881
    begin
14882
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14883
        do_pause ( 1 ) ;
14884
    end
14885
    begin:monitor_error_event3
14886 35 mihad
        error_monitor_done = 0 ;
14887 15 mihad
        @(error_event_int) ;
14888
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14889
        ok = 0 ;
14890 35 mihad
        error_monitor_done = 1 ;
14891 15 mihad
    end
14892
    begin
14893
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14894
        @(posedge pci_clock) ;
14895 35 mihad
        if ( !error_monitor_done )
14896
            disable monitor_error_event3 ;
14897 15 mihad
    end
14898
    join
14899
 
14900
    if ( ok )
14901
        test_ok ;
14902
 
14903
    ok = 1 ;
14904
 
14905
    byte_enables = 4'b0000 ;
14906
 
14907
    fork
14908
    begin
14909
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14910
        do_pause ( 1 ) ;
14911
    end
14912
    begin:monitor_error_event4
14913 35 mihad
        error_monitor_done = 0 ;
14914 15 mihad
        @(error_event_int) ;
14915
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14916
        ok = 0 ;
14917 35 mihad
        error_monitor_done = 1 ;
14918 15 mihad
    end
14919
    begin
14920
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14921
        @(posedge pci_clock) ;
14922 35 mihad
        #1 ;
14923
        if ( !error_monitor_done )
14924
            disable monitor_error_event4 ;
14925 15 mihad
    end
14926
    join
14927
 
14928
    if ( ok )
14929
        test_ok ;
14930
 
14931
    ok = 1 ;
14932
 
14933
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
14934
    byte_enables = 4'b0111 ;
14935
 
14936
    fork
14937
    begin
14938
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14939
        do_pause ( 1 ) ;
14940
    end
14941
    begin:monitor_error_event5
14942 35 mihad
        error_monitor_done = 0 ;
14943 15 mihad
        @(error_event_int) ;
14944
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14945
        ok = 0 ;
14946 35 mihad
        error_monitor_done = 1 ;
14947 15 mihad
    end
14948
    begin
14949
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14950
        @(posedge pci_clock) ;
14951 35 mihad
        #1 ;
14952
        if ( !error_monitor_done )
14953
            disable monitor_error_event5 ;
14954 15 mihad
    end
14955
    join
14956
 
14957
    if ( ok )
14958
        test_ok ;
14959
 
14960
    ok = 1 ;
14961
 
14962
    byte_enables = 4'b0010 ;
14963
 
14964
    fork
14965
    begin
14966
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14967
        do_pause ( 1 ) ;
14968
    end
14969
    begin:monitor_error_event6
14970 35 mihad
        error_monitor_done = 0 ;
14971 15 mihad
        @(error_event_int) ;
14972
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14973
        ok = 0 ;
14974 35 mihad
        error_monitor_done = 1 ;
14975 15 mihad
    end
14976
    begin
14977
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14978
        @(posedge pci_clock) ;
14979 35 mihad
        #1 ;
14980
        if ( !error_monitor_done )
14981
            disable monitor_error_event6 ;
14982 15 mihad
    end
14983
    join
14984
 
14985
    if ( ok )
14986
        test_ok ;
14987
 
14988
    ok = 1 ;
14989
    byte_enables = 4'b0001 ;
14990
 
14991
    fork
14992
    begin
14993
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14994
        do_pause ( 1 ) ;
14995
    end
14996
    begin:monitor_error_event7
14997 35 mihad
        error_monitor_done = 0 ;
14998 15 mihad
        @(error_event_int) ;
14999
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15000
        ok = 0 ;
15001 35 mihad
        error_monitor_done = 1 ;
15002 15 mihad
    end
15003
    begin
15004
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15005
        @(posedge pci_clock) ;
15006 35 mihad
        #1 ;
15007
        if ( !error_monitor_done )
15008
            disable monitor_error_event7 ;
15009 15 mihad
    end
15010
    join
15011
 
15012
    if ( ok )
15013
        test_ok ;
15014
 
15015
    ok = 1 ;
15016
    byte_enables = 4'b0000 ;
15017
 
15018
    fork
15019
    begin
15020
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15021
        do_pause ( 1 ) ;
15022
    end
15023
    begin:monitor_error_event8
15024 35 mihad
        error_monitor_done = 0 ;
15025 15 mihad
        @(error_event_int) ;
15026
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15027
        ok = 0 ;
15028 35 mihad
        error_monitor_done = 1 ;
15029 15 mihad
    end
15030
    begin
15031
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15032
        @(posedge pci_clock) ;
15033 35 mihad
        #1 ;
15034
        if ( !error_monitor_done )
15035
            disable monitor_error_event8 ;
15036 15 mihad
    end
15037
    join
15038
 
15039
    if ( ok )
15040
        test_ok ;
15041
 
15042
    ok = 1 ;
15043
 
15044
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15045
    byte_enables = 4'b0110 ;
15046
 
15047
    fork
15048
    begin
15049
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15050
        do_pause ( 1 ) ;
15051
    end
15052
    begin:monitor_error_event9
15053 35 mihad
        error_monitor_done = 0 ;
15054 15 mihad
        @(error_event_int) ;
15055
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15056
        ok = 0 ;
15057 35 mihad
        error_monitor_done = 1 ;
15058 15 mihad
    end
15059
    begin
15060
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15061
        @(posedge pci_clock) ;
15062 35 mihad
        #1 ;
15063
        if ( !error_monitor_done )
15064
            disable monitor_error_event9 ;
15065 15 mihad
    end
15066
    join
15067
 
15068
    if ( ok )
15069
        test_ok ;
15070
 
15071
    ok = 1 ;
15072
    fork
15073
    begin
15074
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15075
        do_pause ( 1 ) ;
15076
    end
15077
    begin:monitor_error_event10
15078 35 mihad
        error_monitor_done = 0 ;
15079 15 mihad
        @(error_event_int) ;
15080
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15081
        ok = 0 ;
15082 35 mihad
        error_monitor_done = 1 ;
15083 15 mihad
    end
15084
    begin
15085
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15086
        @(posedge pci_clock) ;
15087 35 mihad
 
15088
        #1 ;
15089
        if ( !error_monitor_done )
15090
            disable monitor_error_event10 ;
15091 15 mihad
    end
15092
    join
15093
 
15094
    if ( ok )
15095
        test_ok ;
15096
 
15097
    ok = 1 ;
15098
 
15099
    byte_enables = 4'b0001 ;
15100
 
15101
    fork
15102
    begin
15103
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15104
        do_pause ( 1 ) ;
15105
    end
15106
    begin:monitor_error_event11
15107 35 mihad
        error_monitor_done = 0 ;
15108 15 mihad
        @(error_event_int) ;
15109
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15110
        ok = 0 ;
15111 35 mihad
        error_monitor_done = 1 ;
15112 15 mihad
    end
15113
    begin
15114
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15115
        @(posedge pci_clock) ;
15116 35 mihad
        #1 ;
15117
        if ( !error_monitor_done )
15118
            disable monitor_error_event11 ;
15119 15 mihad
    end
15120
    join
15121
 
15122
    if ( ok )
15123
        test_ok ;
15124
 
15125
    ok = 1 ;
15126
 
15127
    byte_enables = 4'b0101 ;
15128
 
15129
    fork
15130
    begin
15131
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15132
        do_pause ( 1 ) ;
15133
    end
15134
    begin:monitor_error_event12
15135 35 mihad
        error_monitor_done = 0 ;
15136 15 mihad
        @(error_event_int) ;
15137
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15138
        ok = 0 ;
15139 35 mihad
        error_monitor_done = 1 ;
15140 15 mihad
    end
15141
    begin
15142
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15143
        @(posedge pci_clock) ;
15144 35 mihad
        #1 ;
15145
        if ( !error_monitor_done )
15146
            disable monitor_error_event12 ;
15147 15 mihad
    end
15148
    join
15149
 
15150
    if ( ok )
15151
        test_ok ;
15152
 
15153
    ok = 1 ;
15154
 
15155
    byte_enables = 4'b0011 ;
15156
 
15157
    fork
15158
    begin
15159
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15160
        do_pause ( 1 ) ;
15161
    end
15162
    begin:monitor_error_event13
15163 35 mihad
        error_monitor_done = 0 ;
15164 15 mihad
        @(error_event_int) ;
15165
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15166
        ok = 0 ;
15167 35 mihad
        error_monitor_done = 1 ;
15168 15 mihad
    end
15169
    begin
15170
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15171
        @(posedge pci_clock) ;
15172 35 mihad
        #1 ;
15173
        if ( !error_monitor_done )
15174
            disable monitor_error_event13 ;
15175 15 mihad
    end
15176
    join
15177
 
15178
    if ( ok )
15179
        test_ok ;
15180
 
15181
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15182
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15183
    ok = 1 ;
15184
    if ( pci_address[27] !== 1 )
15185
    begin
15186
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15187
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15188
        ok = 0 ;
15189
    end
15190
    if ( pci_address[28] !== 0 )
15191
    begin
15192
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15193
        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") ;
15194
        ok = 0 ;
15195
    end
15196
    if ( pci_address[29] !== 0 )
15197
    begin
15198
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15199
        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") ;
15200
        ok = 0 ;
15201
    end
15202
 
15203
    // clear statuses
15204
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15205
    if ( !ok )
15206
    begin
15207
        test_fail("write to PCI Device Status register failed") ;
15208
        $display("Couldn't write PCI Device Status register") ;
15209
        disable main ;
15210
    end
15211
 
15212
    if ( ok )
15213
        test_ok ;
15214
 
15215
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15216
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15217
    if ( pci_address[8] !== 0 )
15218
    begin
15219
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15220
    end
15221
    else
15222
        test_ok ;
15223
 
15224
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15225
 
15226
    test_name = "DISABLE IMAGE" ;
15227
 
15228 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15229 15 mihad
    if ( ok !== 1 )
15230
    begin
15231
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15232
        test_fail("PCI Address Mask register could not be written") ;
15233
        disable main ;
15234
    end
15235
end
15236
endtask // test_target_abort
15237
 
15238
task test_target_io_wr_rd ;
15239
    input [2:0]  image_num ;
15240
    input        translate_address ;
15241
    input [11:0] img_ctrl_offset ;
15242
    reg   [31:0] expect_address ;
15243
    reg   [31:0] pci_address ;
15244
    reg          translation ;
15245
    reg   [31:0] read_data ;
15246
    reg   [3:0]  byte_enables ;
15247
    reg          ok ;
15248
    reg          pci_ok ;
15249
    reg          wb_ok ;
15250
    integer      i ;
15251 35 mihad
    reg          error_monitor_done ;
15252 15 mihad
begin:main
15253
    `ifdef ADDR_TRAN_IMPL
15254
        translation = translate_address ;
15255
    `else
15256
        translation = 0 ;
15257
    `endif
15258
 
15259
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15260
 
15261
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15262
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15263
    if ( translation )
15264
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15265
    else
15266
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15267
 
15268
    if ( !ok )
15269
    begin
15270
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15271
        test_fail("PCI Image Control register could not be written") ;
15272
    end
15273
 
15274
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15275
    pci_address  = Target_Base_Addr_R[image_num] ;
15276
    byte_enables = 4'b0000 ;
15277
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15278
 
15279
    fork
15280
    begin
15281
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15282
        do_pause ( 1 ) ;
15283
    end
15284
    begin
15285
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15286
        if ( wb_ok !== 1 )
15287
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15288
 
15289 35 mihad
        #1 ;
15290
        if ( !error_monitor_done )
15291
            disable monitor_pci_error_1 ;
15292 15 mihad
    end
15293
    begin:monitor_pci_error_1
15294 35 mihad
        error_monitor_done = 0 ;
15295 15 mihad
        pci_ok = 1 ;
15296
        @(error_event_int) ;
15297
        pci_ok = 0 ;
15298
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15299 35 mihad
        error_monitor_done = 1 ;
15300 15 mihad
    end
15301
    join
15302
 
15303
    byte_enables = 4'b1111 ;
15304
    for ( i = 0 ; i < 4 ; i = i + 1 )
15305
    begin:loop_1
15306
        byte_enables[i] = 0 ;
15307
        if ( i > 0 )
15308
            byte_enables[i - 1] = 1 ;
15309
        fork
15310
        begin
15311
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15312
            do_pause ( 1 ) ;
15313
        end
15314
        begin
15315
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15316
            if ( wb_ok !== 1 )
15317
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15318
 
15319 35 mihad
            #1 ;
15320
            if ( !error_monitor_done )
15321
                disable monitor_pci_error_2 ;
15322 15 mihad
        end
15323
        begin:monitor_pci_error_2
15324 35 mihad
            error_monitor_done = 0 ;
15325 15 mihad
            pci_ok = 1 ;
15326
            @(error_event_int) ;
15327
            pci_ok = 0 ;
15328
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15329 35 mihad
            error_monitor_done = 1 ;
15330 15 mihad
        end
15331
        join
15332
 
15333
        if ( !pci_ok || !wb_ok )
15334
            disable loop_1 ;
15335
 
15336
        pci_address = pci_address + 1 ;
15337
        expect_address = expect_address + 1 ;
15338
    end
15339
 
15340
    if ( pci_ok && wb_ok )
15341
        test_ok ;
15342
 
15343
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15344
    pci_address  = Target_Base_Addr_R[image_num] ;
15345
    byte_enables = 4'b1100 ;
15346
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15347
 
15348
    master1_check_received_data = 1 ;
15349
    fork
15350
    begin
15351
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15352
        do_pause( 1 ) ;
15353
    end
15354
    begin
15355
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15356
        if ( wb_ok !== 1 )
15357
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15358
 
15359
        do_pause ( 2 ) ;
15360
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15361
        do_pause ( 16 ) ;
15362
 
15363 35 mihad
        #1 ;
15364
        if ( !error_monitor_done )
15365
            disable monitor_pci_error_3 ;
15366 15 mihad
    end
15367
    begin:monitor_pci_error_3
15368 35 mihad
        error_monitor_done = 0 ;
15369 15 mihad
        pci_ok = 1 ;
15370
        @(error_event_int) ;
15371
        pci_ok = 0 ;
15372
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15373 35 mihad
        error_monitor_done = 1 ;
15374 15 mihad
    end
15375
    join
15376
 
15377
    if ( !pci_ok || !wb_ok )
15378
    begin
15379
        disable main ;
15380
    end
15381
 
15382
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15383
    byte_enables = 4'b0011 ;
15384
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15385
 
15386
    master1_check_received_data = 1 ;
15387
    fork
15388
    begin
15389
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15390
        do_pause( 1 ) ;
15391
    end
15392
    begin
15393
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15394
        if ( wb_ok !== 1 )
15395
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15396
 
15397
        do_pause ( 2 ) ;
15398
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15399
        do_pause ( 16 ) ;
15400
 
15401 35 mihad
        #1 ;
15402
        if ( !error_monitor_done )
15403
            disable monitor_pci_error_4 ;
15404 15 mihad
    end
15405
    begin:monitor_pci_error_4
15406 35 mihad
        error_monitor_done = 0 ;
15407 15 mihad
        pci_ok = 1 ;
15408
        @(error_event_int) ;
15409
        pci_ok = 0 ;
15410
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15411 35 mihad
        error_monitor_done = 1 ;
15412 15 mihad
    end
15413
    join
15414
 
15415
    if ( !pci_ok || !wb_ok )
15416
    begin
15417
        disable main ;
15418
    end
15419
 
15420
    pci_address  = Target_Base_Addr_R[image_num] ;
15421
    byte_enables = 4'b0000 ;
15422
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15423
 
15424
    master1_check_received_data = 1 ;
15425
    fork
15426
    begin
15427
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15428
        do_pause( 1 ) ;
15429
    end
15430
    begin
15431
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15432
        if ( wb_ok !== 1 )
15433
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15434
 
15435
        do_pause ( 2 ) ;
15436
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15437
        do_pause ( 16 ) ;
15438
 
15439 35 mihad
        #1 ;
15440
        if ( !error_monitor_done )
15441
            disable monitor_pci_error_5 ;
15442 15 mihad
    end
15443
    begin:monitor_pci_error_5
15444 35 mihad
        error_monitor_done = 0 ;
15445 15 mihad
        pci_ok = 1 ;
15446
        @(error_event_int) ;
15447
        pci_ok = 0 ;
15448
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15449 35 mihad
        error_monitor_done = 1 ;
15450 15 mihad
    end
15451
    join
15452
 
15453
    if ( pci_ok && wb_ok )
15454
        test_ok ;
15455
end
15456
endtask // test_target_io_wr_rd
15457
 
15458
task test_target_io_err_wr ;
15459
    input [2:0]  image_num ;
15460
    input        translate_address ;
15461
    input [11:0] img_ctrl_offset ;
15462
    input        enable_error_report ;
15463
    input        enable_error_interrupt ;
15464
 
15465
    reg   [31:0] expect_address ;
15466
    reg   [31:0] pci_address ;
15467
    reg          translation ;
15468
    reg   [31:0] read_data ;
15469
    reg   [3:0]  byte_enables ;
15470
    reg          ok ;
15471
    reg          pci_ok ;
15472
    reg          wb_ok ;
15473
    integer      i ;
15474
    reg   [11:0] offset ;
15475 35 mihad
    reg          error_monitor_done ;
15476 15 mihad
begin:main
15477
    `ifdef ADDR_TRAN_IMPL
15478
        translation = translate_address ;
15479
    `else
15480
        translation = 0 ;
15481
    `endif
15482
 
15483
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15484
 
15485
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15486
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15487
    if ( translation )
15488
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15489
    else
15490
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15491
 
15492
    if ( !ok )
15493
    begin
15494
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15495
        test_fail("PCI Image Control register could not be written") ;
15496
    end
15497
 
15498
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15499
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15500
    if ( enable_error_report )
15501
    begin
15502
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15503
        if ( !ok )
15504
        begin
15505
            test_fail("PCI Error Control and Status register could not be written") ;
15506
            disable main ;
15507
        end
15508
    end
15509
    else
15510
    begin
15511
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15512
        if ( !ok )
15513
        begin
15514
            test_fail("PCI Error Control and Status register could not be written") ;
15515
            disable main ;
15516
        end
15517
    end
15518
 
15519
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15520
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15521
    if ( enable_error_interrupt )
15522
    begin
15523
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15524
        if ( !ok )
15525
        begin
15526
            test_fail("Interrupt Control register could not be written") ;
15527
            disable main ;
15528
        end
15529
    end
15530
    else
15531
    begin
15532
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15533
        if ( !ok )
15534
        begin
15535
            test_fail("Interrupt Control register could not be written") ;
15536
            disable main ;
15537
        end
15538
    end
15539
 
15540
    pci_address  = Target_Base_Addr_R[image_num] ;
15541
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15542
 
15543
    byte_enables = 4'b1111 ;
15544
 
15545
    for ( i = 0 ; i < 4 ; i = i + 1 )
15546
    begin:loop_1
15547
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15548
        byte_enables[i] = 0 ;
15549
        if ( i > 0 )
15550
            byte_enables[i - 1] = 1 ;
15551
 
15552
        fork
15553
        begin
15554
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15555
            do_pause ( 1 ) ;
15556
        end
15557
        begin
15558
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15559
            if ( wb_ok !== 1 )
15560
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15561
 
15562 35 mihad
            #1 ;
15563
            if ( !error_monitor_done )
15564
                disable monitor_pci_error_2 ;
15565 15 mihad
        end
15566
        begin:monitor_pci_error_2
15567 35 mihad
            error_monitor_done = 0 ;
15568 15 mihad
            pci_ok = 1 ;
15569
            @(error_event_int) ;
15570
            pci_ok = 0 ;
15571
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15572 35 mihad
            error_monitor_done = 1 ;
15573 15 mihad
        end
15574
        join
15575
 
15576
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15577
        `ifdef HOST
15578
 
15579
            repeat ( 4 )
15580
                @( posedge wb_clock ) ;
15581
 
15582
            if ( enable_error_interrupt && enable_error_report )
15583
            begin
15584
                if ( INT_O !== 1 )
15585
                begin
15586
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15587
                end
15588
            end
15589
            else
15590
            begin
15591
                if ( INT_O !== 0 )
15592
                begin
15593
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15594
                end
15595
            end
15596
        `else
15597
            repeat ( 4 )
15598
                @( posedge pci_clock ) ;
15599
 
15600
            if ( enable_error_interrupt && enable_error_report )
15601
            begin
15602
                if ( INTA !== 0 )
15603
                begin
15604
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15605
                end
15606
            end
15607
            else
15608
            begin
15609
                if ( INTA !== 1 )
15610
                begin
15611
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15612
                end
15613
            end
15614
        `endif
15615
 
15616
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15617
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15618
        config_read( offset, 4'hF, read_data ) ;
15619
        ok = 1 ;
15620
        if ( enable_error_report )
15621
        begin
15622
            if ( read_data[8] !== 1 )
15623
            begin
15624
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15625
                ok = 0 ;
15626
            end
15627
 
15628
            if ( read_data[9] !== 0 )
15629
            begin
15630
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15631
                ok = 0 ;
15632
            end
15633
 
15634
            if ( read_data[31:28] !== byte_enables )
15635
            begin
15636
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15637
                ok = 0 ;
15638
            end
15639
 
15640
            if ( read_data[27:24] !== `BC_IO_WRITE )
15641
            begin
15642
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15643
                ok = 0 ;
15644
            end
15645
 
15646
            if ( ok )
15647
                test_ok ;
15648
 
15649
            test_name = "CLEAR ERROR STATUS" ;
15650
            config_write( offset, read_data, 4'hF, ok ) ;
15651
            if ( !ok )
15652
                test_fail("PCI Error Control and Status register could not be written") ;
15653
 
15654
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15655
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15656
            config_read ( offset, 4'hf, read_data ) ;
15657
 
15658
            if ( read_data !== expect_address )
15659
            begin
15660
                test_fail("value in Erroneous Address register was incorrect") ;
15661
                ok = 0 ;
15662
            end
15663
 
15664
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15665
            config_read ( offset, 4'hf, read_data ) ;
15666
 
15667
            if ( read_data !== 32'hAAAA_AAAA )
15668
            begin
15669
                test_fail("value in Erroneous Data register was incorrect") ;
15670
                ok = 0 ;
15671
            end
15672
 
15673
            if ( ok )
15674
                test_ok ;
15675
 
15676
        end
15677
        else
15678
        begin
15679
            if ( read_data[8] !== 0 )
15680
            begin
15681
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15682
                ok = 0 ;
15683
            end
15684
            else
15685
                test_ok ;
15686
        end
15687
 
15688
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15689
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15690
        ok = 1 ;
15691
 
15692
        config_read ( offset, 4'hF, read_data ) ;
15693
        if ( enable_error_report && enable_error_interrupt )
15694
        begin
15695
            if ( read_data[2] !== 1 )
15696
            begin
15697
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15698
                ok = 0 ;
15699
            end
15700
 
15701
            test_name = "CLEARING INTERRUPT STATUS" ;
15702
            config_write( offset, read_data, 4'hF, ok ) ;
15703
            if ( !ok )
15704
                test_fail("Interrupt Status register could not be written") ;
15705
        end
15706
        else
15707
        begin
15708
            if ( read_data[2] !== 0 )
15709
            begin
15710
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15711
                ok = 0 ;
15712
            end
15713
        end
15714
 
15715
        if ( ok )
15716
            test_ok ;
15717
 
15718
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15719
        `ifdef HOST
15720
 
15721
            repeat ( 4 )
15722
                @( posedge wb_clock ) ;
15723
 
15724
            if ( INT_O !== 0 )
15725
            begin
15726
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15727
            end
15728
            else
15729
                test_ok ;
15730
 
15731
        `else
15732
            repeat ( 4 )
15733
                @( posedge pci_clock ) ;
15734
 
15735
            if ( INTA !== 1 )
15736
            begin
15737
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15738
            end
15739
            else
15740
                test_ok ;
15741
 
15742
        `endif
15743
 
15744
        pci_address = pci_address + 1 ;
15745
        expect_address = expect_address + 1 ;
15746
    end
15747
 
15748
end
15749
endtask // test_target_io_err_wr
15750
 
15751
task test_pci_image ;
15752
    input [2:0]  image_num ;
15753
    reg   [11:0] pci_ctrl_offset ;
15754
    reg   [11:0] ctrl_offset ;
15755
    reg   [11:0] ba_offset ;
15756
    reg   [11:0] am_offset ;
15757
    reg   [11:0] ta_offset ;
15758
    reg   [7:0]  cache_lsize ;
15759
    reg          ok ;
15760
    reg          test_io ;
15761
    reg          test_mem ;
15762
begin
15763
    pci_ctrl_offset = 12'h4 ;
15764
    if (image_num === 0)
15765
    begin
15766
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15767
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15768
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15769
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15770
    end
15771
    else if (image_num === 1)
15772
    begin
15773
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15774
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15775
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15776
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15777
    end
15778
    else if (image_num === 2)
15779
    begin
15780
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15781
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15782
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15783
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15784
    end
15785
    else if (image_num === 3)
15786
    begin
15787
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15788
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15789
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15790
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15791
    end
15792
    else if (image_num === 4)
15793
    begin
15794
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15795
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15796
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15797
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15798
    end
15799
    else if (image_num === 5)
15800
    begin
15801
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15802
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15803
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15804
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15805
    end
15806
 
15807
    `ifdef HOST
15808
        test_io  = 1 ;
15809
        test_mem = 1 ;
15810
    `else
15811
        if (image_num == 1)
15812
            test_io = `PCI_BA1_MEM_IO ;
15813
        else if ( image_num == 2 )
15814
            test_io = `PCI_BA2_MEM_IO ;
15815
        else if ( image_num == 3 )
15816
            test_io = `PCI_BA3_MEM_IO ;
15817
        else if ( image_num == 4 )
15818
            test_io = `PCI_BA4_MEM_IO ;
15819
        else if ( image_num == 5 )
15820
            test_io = `PCI_BA5_MEM_IO ;
15821
 
15822
        test_mem = !test_io ;
15823
    `endif
15824
 
15825
    $display(" ");
15826
    $display("########################################################################") ;
15827
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15828
    test_name = "PCI IMAGE SETTINGS" ;
15829
 
15830
    // Set Base Address of IMAGE
15831
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15832
    if ( ok !== 1 )
15833
    begin
15834
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15835
        test_fail("PCI Base Address register could not be written") ;
15836
    end
15837
 
15838
    // Set Address Mask of IMAGE
15839
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15840
    if ( ok !== 1 )
15841
    begin
15842
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15843
        test_fail("PCI Address Mask register could not be written") ;
15844
    end
15845
 
15846
    // Set Translation Address of IMAGE
15847
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15848
    if ( ok !== 1 )
15849
    begin
15850
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15851
        test_fail("PCI Translation Address register could not be written") ;
15852
    end
15853
 
15854
// Following are defines for byte enable signals !
15855
//      Byte Masks
15856
//      `Test_Byte_0                            (4'b1110)
15857
//      `Test_Byte_1                            (4'b1101)
15858
//      `Test_Byte_2                            (4'b1011)
15859
//      `Test_Byte_3                            (4'b0111)
15860
//      `Test_Half_0                            (4'b1100)
15861
//      `Test_Half_1                            (4'b0011)
15862
//      `Test_All_Bytes                         (4'b0000)
15863
 
15864
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
15865
    // Set Cache Line Size
15866
    cache_lsize = 8'h4 ;
15867
 
15868
    $display(" ");
15869
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15870
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15871
    if ( ok !== 1 )
15872
    begin
15873
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15874
        test_fail("PCI Device Control and Status register could not be written") ;
15875
    end
15876
 
15877
    if (test_mem)
15878
    begin
15879
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
15880
        // Task test_normal_wr_rd has the following parameters:
15881
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15882
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15883
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15884
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
15885
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
15886
 
15887
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15888
        // Set Cache Line Size
15889
        cache_lsize = 8'h4 ;
15890
 
15891
        $display(" ");
15892
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15893
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15894
        if ( ok !== 1 )
15895
        begin
15896
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15897
            test_fail("Cache Line Size register could not be written" ) ;
15898
        end
15899
 
15900
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
15901
        // Task test_normal_wr_rd has the following parameters:
15902
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15903
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15904
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15905
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
15906
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
15907
 
15908
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15909
        // Set Cache Line Size
15910
        cache_lsize = 8'h8 ;
15911
 
15912
        $display(" ");
15913
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15914
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15915
        if ( ok !== 1 )
15916
        begin
15917
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15918
            test_fail("Cache Line Size register could not be written" ) ;
15919
        end
15920
 
15921
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
15922
        // Task test_normal_wr_rd has the following parameters:
15923
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15924
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15925
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15926
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
15927
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15928
 
15929
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15930
        // Set Cache Line Size
15931
        cache_lsize = 8'h4 ;
15932
 
15933
        $display(" ");
15934
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15935
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15936
        if ( ok !== 1 )
15937
        begin
15938
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15939
            test_fail("Cache Line Size register could not be written" ) ;
15940
        end
15941
 
15942
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
15943
        // Task test_normal_wr_rd has the following parameters:
15944
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15945
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15946
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15947
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
15948
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15949
 
15950
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
15951
        $display(" ");
15952
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
15953
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15954
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15955
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
15956
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
15957
 
15958
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
15959
        $display(" ");
15960
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
15961
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15962
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15963
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
15964
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
15965
 
15966
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
15967
        $display(" ");
15968
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
15969
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15970
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15971
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
15972
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
15973
 
15974
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
15975
        $display(" ");
15976
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
15977
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15978
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15979
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
15980
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
15981
    end
15982
 
15983
    if ( test_io )
15984
    begin
15985
        test_name = "PCI IMAGE SETTINGS" ;
15986
 
15987
        // Set Base Address of IMAGE
15988
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
15989
        if ( ok !== 1 )
15990
        begin
15991
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15992
            test_fail("PCI Base Address register could not be written") ;
15993
        end
15994
 
15995
        // Set Address Mask of IMAGE
15996
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15997
        if ( ok !== 1 )
15998
        begin
15999
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16000
            test_fail("PCI Address Mask register could not be written") ;
16001
        end
16002
 
16003
        // Set Translation Address of IMAGE
16004
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16005
        if ( ok !== 1 )
16006
        begin
16007
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16008
            test_fail("PCI Translation Address register could not be written") ;
16009
        end
16010
 
16011
        // Set Cache Line Size
16012
        cache_lsize = 8'h4 ;
16013
 
16014
        $display(" ");
16015
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16016
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16017
        if ( ok !== 1 )
16018
        begin
16019
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16020
            test_fail("Cache Line Size register could not be written" ) ;
16021
        end
16022
 
16023
        test_target_io_wr_rd
16024
        (
16025
            image_num,    // image number
16026
            0,            // test with address translation
16027
            ctrl_offset   // image control register offset
16028
        ) ;
16029
 
16030
        test_target_io_wr_rd
16031
        (
16032
            image_num,    // image number
16033
            1,            // test with address translation
16034
            ctrl_offset   // image control register offset
16035
        ) ;
16036
 
16037
        test_target_io_err_wr
16038
        (
16039
            image_num,      // image number
16040
            0,              // address translation on/off
16041
            ctrl_offset,    // image control register offset
16042
            0,              // enable error reporting
16043
 
16044
        ) ;
16045
 
16046
        test_target_io_err_wr
16047
        (
16048
            image_num,      // image number
16049
            1,              // address translation on/off
16050
            ctrl_offset,    // image control register offset
16051
            0,              // enable error reporting
16052
            1               // enable error interrupts
16053
        ) ;
16054
 
16055
        test_target_io_err_wr
16056
        (
16057
            image_num,      // image number
16058
            0,              // address translation on/off
16059
            ctrl_offset,    // image control register offset
16060
            1,              // enable error reporting
16061
 
16062
        ) ;
16063
 
16064
        test_target_io_err_wr
16065
        (
16066
            image_num,      // image number
16067
            1,              // address translation on/off
16068
            ctrl_offset,    // image control register offset
16069
            1,              // enable error reporting
16070
            1               // enable error interrupts
16071
        ) ;
16072
    end
16073
 
16074
    // Test master abort with NON supported commands
16075
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16076
 
16077
    // disable the image
16078 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16079 15 mihad
end
16080
endtask //test_pci_image
16081
 
16082
task target_fast_back_to_back ;
16083
    reg   [11:0] pci_ctrl_offset ;
16084
    reg   [11:0] ctrl_offset ;
16085
    reg   [11:0] ba_offset ;
16086
    reg   [11:0] am_offset ;
16087
    reg   [11:0] ta_offset ;
16088
    reg   [11:0] cls_offset ;
16089
    reg          do_mem_fb2b ;
16090
    reg          do_io_fb2b ;
16091
    reg          ok ;
16092
begin:main
16093
 
16094
    if ( target_mem_image !== -1 )
16095
    begin
16096
        do_mem_fb2b = 1 ;
16097
 
16098
        if (target_mem_image === 1)
16099
        begin
16100
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16101
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16102
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16103
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16104
        end
16105
        else if (target_mem_image === 2)
16106
        begin
16107
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16108
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16109
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16110
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16111
        end
16112
        else if (target_mem_image === 3)
16113
        begin
16114
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16115
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16116
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16117
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16118
        end
16119
        else if (target_mem_image === 4)
16120
        begin
16121
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16122
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16123
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16124
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16125
        end
16126
        else if (target_mem_image === 5)
16127
        begin
16128
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16129
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16130
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16131
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16132
        end
16133
    end
16134
    else
16135
        do_mem_fb2b = 0 ;
16136
 
16137
    pci_ctrl_offset = 12'h4 ;
16138
    cls_offset      = 12'h00C ;
16139
 
16140
    if ( do_mem_fb2b )
16141
    begin
16142
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16143
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16144
        if ( ok !== 1 )
16145
        begin
16146
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16147
            test_fail("PCI Base Address register could not be written") ;
16148
            disable main ;
16149
        end
16150
 
16151
        // Set Address Mask of IMAGE
16152
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16153
        if ( ok !== 1 )
16154
        begin
16155
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16156
            test_fail("PCI Address Mask register could not be written") ;
16157
            disable main ;
16158
        end
16159
 
16160
        // Set Translation Address of IMAGE
16161
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16162
        if ( ok !== 1 )
16163
        begin
16164
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16165
            test_fail("PCI Translation Address Register could not be written") ;
16166
            disable main ;
16167
        end
16168
 
16169
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16170
        if ( ok !== 1 )
16171
        begin
16172
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16173
            test_fail("PCI Image Control register could not be written") ;
16174
            disable main ;
16175
        end
16176
 
16177
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16178
        if ( ok !== 1 )
16179
        begin
16180
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16181
            test_fail("Cache Line Size register could not be written") ;
16182
            disable main ;
16183
        end
16184
 
16185
        // enable master 1 fast_b2b
16186 45 mihad
        configuration_cycle_write(0,                        // bus number
16187
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16188
                                  0,                        // function number
16189
                                  1,                        // register number
16190
                                  0,                        // type of configuration cycle
16191
                                  4'b1111,                  // byte enables
16192
                                  32'hFFFF_FFFF             // data
16193 15 mihad
                                 ) ;
16194
 
16195
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16196
 
16197
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16198
        fork
16199
        begin
16200
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16201
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16202
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16203
                  0, `Test_One_Zero_Target_WS,
16204
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16205
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16206
 
16207
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16208
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16209
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16210
                  0, `Test_One_Zero_Target_WS,
16211
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16212
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16213
            do_pause(5) ;
16214
 
16215
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16216
        end
16217
        begin:wb_monitor1
16218
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16219
            if ( ok !== 1 )
16220
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16221
 
16222
            disable monitor_error_event1 ;
16223
        end
16224
        begin:monitor_error_event1
16225
            @(error_event_int) ;
16226
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16227
            ok = 0 ;
16228
            disable wb_monitor1 ;
16229
        end
16230
        join
16231
 
16232
        if ( ok )
16233
            test_ok ;
16234
 
16235
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16236
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16237
        fork
16238
        begin
16239
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16240
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16241
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16242
                  0, `Test_One_Zero_Target_WS,
16243
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16244
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16245
 
16246
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16247
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16248
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16249
                  0, `Test_One_Zero_Target_WS,
16250
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16251
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16252
            do_pause(5) ;
16253
 
16254
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16255
 
16256
        end
16257
        begin:wb_monitor2
16258
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16259
            if ( ok !== 1 )
16260
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16261
            else
16262
            begin
16263
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16264
                if ( ok !== 1 )
16265
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16266
            end
16267
 
16268
            disable monitor_error_event2 ;
16269
        end
16270
        begin:monitor_error_event2
16271
            @(error_event_int) ;
16272
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16273
            ok = 0 ;
16274
            disable wb_monitor2 ;
16275
        end
16276
        join
16277
 
16278
        if ( ok )
16279
            test_ok ;
16280
 
16281
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16282
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16283
        fork
16284
        begin
16285
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16286
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16287
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16288
                  0, `Test_One_Zero_Target_WS,
16289
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16290
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16291
 
16292
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16293
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16294
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16295
                  0, `Test_One_Zero_Target_WS,
16296
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16297
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16298
            do_pause(5) ;
16299
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16300
 
16301
        end
16302
        begin:wb_monitor3
16303
            fork
16304
            begin
16305
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16306
                if ( ok !== 1 )
16307
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16308
            end
16309
            begin
16310
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16311
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16312
                if ( ok !== 1 )
16313
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16314
            end
16315
            join
16316
 
16317
            if ( ok )
16318
            begin
16319
                fork
16320
                begin
16321
                    do_pause(3) ;
16322
 
16323
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16324
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16325
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16326
                        0, `Test_One_Zero_Target_WS,
16327
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16328
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16329
 
16330
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16331
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16332
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16333
                            0, `Test_One_Zero_Target_WS,
16334
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16335
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16336
 
16337
                    do_pause(1) ;
16338
                end
16339
                begin
16340
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16341
                    if ( ok !== 1 )
16342
                    begin
16343
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16344
                        disable monitor_error_event3 ;
16345
                    end
16346
                    else
16347
                    begin
16348
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16349
                        if ( ok !== 1 )
16350
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16351
                    end
16352
                end
16353 26 mihad
                begin
16354
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16355
                        if ( ok !== 1 )
16356
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16357
                end
16358 15 mihad
                join
16359
            end
16360
            disable monitor_error_event3 ;
16361
        end
16362
        begin:monitor_error_event3
16363
            @(error_event_int) ;
16364
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16365
            ok = 0 ;
16366
            disable wb_monitor3 ;
16367
        end
16368
        join
16369
 
16370
        if ( ok )
16371
            test_ok ;
16372
 
16373
        test_name = "DISABLING MEM IMAGE" ;
16374 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16375 15 mihad
        if ( ok !== 1 )
16376
        begin
16377
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16378
            test_fail("PCI Address Mask register could not be written") ;
16379
            disable main ;
16380
        end
16381
    end
16382
 
16383
    if ( target_io_image !== -1 )
16384
    begin
16385
        do_io_fb2b = 1 ;
16386
 
16387
        if (target_io_image === 1)
16388
        begin
16389
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16390
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16391
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16392
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16393
        end
16394
        else if (target_io_image === 2)
16395
        begin
16396
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16397
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16398
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16399
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16400
        end
16401
        else if (target_io_image === 3)
16402
        begin
16403
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16404
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16405
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16406
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16407
        end
16408
        else if (target_io_image === 4)
16409
        begin
16410
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16411
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16412
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16413
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16414
        end
16415
        else if (target_io_image === 5)
16416
        begin
16417
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16418
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16419
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16420
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16421
        end
16422
    end
16423
    else
16424
        do_io_fb2b = 0 ;
16425
 
16426
    if ( do_io_fb2b )
16427
    begin
16428
 
16429
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16430
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16431
        if ( ok !== 1 )
16432
        begin
16433
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16434
            test_fail("PCI Base Address register could not be written") ;
16435
            disable main ;
16436
        end
16437
 
16438
        // Set Address Mask of IMAGE
16439
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16440
        if ( ok !== 1 )
16441
        begin
16442
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16443
            test_fail("PCI Address Mask register could not be written") ;
16444
            disable main ;
16445
        end
16446
 
16447
        // Set Translation Address of IMAGE
16448
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16449
        if ( ok !== 1 )
16450
        begin
16451
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16452
            test_fail("PCI Translation Address Register could not be written") ;
16453
            disable main ;
16454
        end
16455
 
16456
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16457
        if ( ok !== 1 )
16458
        begin
16459
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16460
            test_fail("PCI Image Control register could not be written") ;
16461
            disable main ;
16462
        end
16463
 
16464
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16465
        if ( ok !== 1 )
16466
        begin
16467
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16468
            test_fail("Cache Line Size register could not be written") ;
16469
            disable main ;
16470
        end
16471
 
16472
        // enable master 1 fast_b2b
16473 45 mihad
        configuration_cycle_write(0,                        // bus number
16474
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16475
                                  0,                        // function number
16476
                                  1,                        // register number
16477
                                  0,                        // type of configuration cycle
16478
                                  4'b1111,                  // byte enables
16479
                                  32'hFFFF_FFFF             // data
16480 15 mihad
                                 ) ;
16481
 
16482
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16483
 
16484
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16485
        fork
16486
        begin
16487
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16488
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16489
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16490
                  0, `Test_One_Zero_Target_WS,
16491
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16492
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16493
 
16494
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16495
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16496
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16497
                  0, `Test_One_Zero_Target_WS,
16498
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16499
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16500
            do_pause(5) ;
16501
 
16502
        end
16503
        begin:wb_monitor4
16504
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16505
            if ( ok !== 1 )
16506
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16507
 
16508
            if ( ok )
16509
            begin
16510
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16511
                if ( ok !== 1 )
16512
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16513
            end
16514
 
16515
            disable monitor_error_event4 ;
16516
        end
16517
        begin:monitor_error_event4
16518
            @(error_event_int) ;
16519
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16520
            ok = 0 ;
16521
            disable wb_monitor4 ;
16522
        end
16523
        join
16524
 
16525
        if ( ok )
16526
            test_ok ;
16527
 
16528
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16529
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16530
        fork
16531
        begin
16532
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16533
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16534
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16535
                  0, `Test_One_Zero_Target_WS,
16536
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16537
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16538
 
16539
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16540
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16541
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16542
                  0, `Test_One_Zero_Target_WS,
16543
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16544
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16545
            do_pause(5) ;
16546
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16547
        end
16548
        begin:wb_monitor5
16549
            fork
16550
            begin
16551
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16552
                if ( ok !== 1 )
16553
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16554
            end
16555
            begin
16556
                wb_transaction_stop( 1 ) ;
16557
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16558
                if ( ok !== 1 )
16559
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16560
            end
16561
            join
16562
 
16563
            if ( ok )
16564
            begin
16565
                fork
16566
                begin
16567
                    do_pause(3) ;
16568
 
16569
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16570
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16571
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16572
                            0, `Test_One_Zero_Target_WS,
16573
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16574
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16575
 
16576
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16577
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16578
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16579
                            0, `Test_One_Zero_Target_WS,
16580
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16581
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16582
 
16583
                    do_pause(1) ;
16584
                end
16585
                begin
16586
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16587
                    if ( ok !== 1 )
16588
                    begin
16589
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16590
                        disable monitor_error_event5 ;
16591
                    end
16592
                    else
16593
                    begin
16594
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16595
                        if ( ok !== 1 )
16596
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16597
                    end
16598
                end
16599
                join
16600
            end
16601
            disable monitor_error_event5 ;
16602
        end
16603
        begin:monitor_error_event5
16604
            @(error_event_int) ;
16605
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16606
            ok = 0 ;
16607
            disable wb_monitor5 ;
16608
        end
16609
        join
16610
 
16611
        if ( ok )
16612
            test_ok ;
16613
 
16614
        test_name = "DISABLING IO IMAGE" ;
16615 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16616 15 mihad
        if ( ok !== 1 )
16617
        begin
16618
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16619
            test_fail("PCI Address Mask register could not be written") ;
16620
            disable main ;
16621
        end
16622
    end
16623
 
16624
end
16625
endtask //target_fast_back_to_back
16626
 
16627
task target_disconnects ;
16628
    reg   [11:0] pci_ctrl_offset ;
16629
    reg   [11:0] ctrl_offset ;
16630
    reg   [11:0] ba_offset ;
16631
    reg   [11:0] am_offset ;
16632
    reg   [11:0] ta_offset ;
16633
    reg   [11:0] cls_offset ;
16634
    reg          pci_ok ;
16635
    reg          wb_ok ;
16636
    reg          ok ;
16637
    reg   [31:0] pci_address ;
16638
    reg   [31:0] data ;
16639
    reg   [3:0]  byte_enables ;
16640
    reg   [9:0]  expect_length ;
16641
 
16642
    reg          do_mem_disconnects ;
16643
    reg          do_io_disconnects ;
16644 35 mihad
    reg          error_monitor_done ;
16645 15 mihad
begin:main
16646
    if ( target_mem_image !== -1 )
16647
    begin
16648
        do_mem_disconnects = 1 ;
16649
 
16650
        if (target_mem_image === 1)
16651
        begin
16652
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16653
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16654
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16655
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16656
        end
16657
        else if (target_mem_image === 2)
16658
        begin
16659
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16660
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16661
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16662
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16663
        end
16664
        else if (target_mem_image === 3)
16665
        begin
16666
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16667
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16668
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16669
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16670
        end
16671
        else if (target_mem_image === 4)
16672
        begin
16673
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16674
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16675
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16676
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16677
        end
16678
        else if (target_mem_image === 5)
16679
        begin
16680
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16681
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16682
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16683
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16684
        end
16685
    end
16686
    else
16687
        do_mem_disconnects = 0 ;
16688
 
16689
    pci_ctrl_offset = 12'h4 ;
16690
    cls_offset = 12'h00C ;
16691
 
16692
    master1_check_received_data = 0 ;
16693
    master2_check_received_data = 0 ;
16694
 
16695
    `ifdef HOST
16696
        `ifdef NO_CNF_IMAGE
16697
        `else
16698
            `define TEST_BURST_CONFIG_READ
16699
        `endif
16700
    `else
16701
        `define TEST_BURST_CONFIG_READ
16702
        `define TEST_BURST_CONFIG_WRITE
16703
    `endif
16704
 
16705
    `ifdef TEST_BURST_CONFIG_WRITE
16706
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16707
 
16708
        data = 32'h0000_08_08 ;
16709
 
16710 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16711 15 mihad
        byte_enables = 4'b0000 ;
16712
 
16713
        fork
16714
        begin
16715
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16716
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16717
                    byte_enables,
16718
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16719
                    8'h0_0, `Test_One_Zero_Target_WS,
16720
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16721
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16722
 
16723
            data = 32'h0000_04_04 ;
16724
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16725
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16726
                    byte_enables,
16727
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16728
                    8'h0_0, `Test_One_Zero_Target_WS,
16729
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16730
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16731
            do_pause( 1 ) ;
16732
            while ( FRAME !== 1 || IRDY !== 1 )
16733
                @(posedge pci_clock) ;
16734
 
16735 35 mihad
            #1 ;
16736
            if ( !error_monitor_done )
16737
                disable monitor_error_event1 ;
16738 15 mihad
        end
16739
        begin:monitor_error_event1
16740 35 mihad
            error_monitor_done = 0 ;
16741 15 mihad
            ok = 1 ;
16742
            @(error_event_int) ;
16743
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16744
            ok = 0 ;
16745 35 mihad
            error_monitor_done = 1 ;
16746 15 mihad
        end
16747
        join
16748
 
16749
        config_read(pci_address, 4'hF, data) ;
16750
        if ( data [15:0] !== 16'h04_04 )
16751
        begin
16752
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16753
        end
16754
        else if ( ok )
16755
            test_ok ;
16756
 
16757 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16758
 
16759
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16760 15 mihad
        data         = 32'h0000_0808 ;
16761
        byte_enables = 4'h0 ;
16762
        fork
16763
        begin
16764
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16765
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16766
                    byte_enables,
16767
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16768
                    8'h0_0, `Test_One_Zero_Target_WS,
16769
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16770
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16771
 
16772
            data = 32'h0000_04_04 ;
16773
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16774
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16775
                    byte_enables,
16776
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16777
                    8'h0_0, `Test_One_Zero_Target_WS,
16778
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16779
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16780
 
16781
            do_pause( 1 ) ;
16782
            while ( FRAME !== 1 || IRDY !== 1 )
16783
                @(posedge pci_clock) ;
16784
 
16785 35 mihad
            #1 ;
16786
            if ( !error_monitor_done )
16787
                disable monitor_error_event2 ;
16788 15 mihad
        end
16789
        begin:monitor_error_event2
16790 35 mihad
            error_monitor_done = 0 ;
16791 15 mihad
            ok = 1 ;
16792
            @(error_event_int) ;
16793
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16794
            ok = 0 ;
16795 35 mihad
            error_monitor_done = 1 ;
16796 15 mihad
        end
16797
        join
16798
 
16799
        config_read(pci_address, 4'hF, data) ;
16800
        if ( data [15:0] !== 16'h04_04 )
16801
        begin
16802
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16803
        end
16804
        else if ( ok )
16805
            test_ok ;
16806
    `endif
16807
 
16808
    `ifdef TEST_BURST_CONFIG_READ
16809
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16810
 
16811
        data = 32'h0000_04_04 ;
16812
 
16813 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16814 15 mihad
        byte_enables = 4'b0000 ;
16815
 
16816
        fork
16817
        begin
16818
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16819
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16820
                    byte_enables,
16821
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16822
                    8'h0_0, `Test_One_Zero_Target_WS,
16823
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16824
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16825
            do_pause( 1 ) ;
16826
 
16827
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16828
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16829
                    byte_enables,
16830
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16831
                    8'h0_0, `Test_One_Zero_Target_WS,
16832
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16833
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16834
            do_pause( 1 ) ;
16835
 
16836
            while ( FRAME !== 1 || IRDY !== 1 )
16837
                @(posedge pci_clock) ;
16838
 
16839 35 mihad
            if ( !error_monitor_done )
16840
                disable monitor_error_event3 ;
16841 15 mihad
        end
16842
        begin:monitor_error_event3
16843 35 mihad
            error_monitor_done = 0 ;
16844 15 mihad
            ok = 1 ;
16845
            @(error_event_int) ;
16846
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16847
            ok = 0 ;
16848 35 mihad
            error_monitor_done = 1 ;
16849 15 mihad
        end
16850
        join
16851
 
16852
        if ( ok )
16853
            test_ok ;
16854
 
16855 45 mihad
 
16856
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
16857
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16858 15 mihad
        fork
16859
        begin
16860
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16861
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16862
                    byte_enables,
16863
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16864
                    8'h0_0, `Test_One_Zero_Target_WS,
16865
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16866
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16867
            do_pause( 1 ) ;
16868
 
16869
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16870
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16871
                    byte_enables,
16872
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16873
                    8'h0_0, `Test_One_Zero_Target_WS,
16874
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16875
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16876
            do_pause( 1 ) ;
16877
 
16878
            while ( FRAME !== 1 || IRDY !== 1 )
16879
                @(posedge pci_clock) ;
16880
 
16881 35 mihad
            #1 ;
16882
            if ( !error_monitor_done )
16883
                disable monitor_error_event4 ;
16884 15 mihad
        end
16885
        begin:monitor_error_event4
16886 35 mihad
            error_monitor_done = 0 ;
16887 15 mihad
            ok = 1 ;
16888
            @(error_event_int) ;
16889
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16890
            ok = 0 ;
16891 35 mihad
            error_monitor_done = 1 ;
16892 15 mihad
        end
16893
        join
16894
 
16895
        if ( ok )
16896
            test_ok ;
16897
    `endif
16898
 
16899
    `ifdef TEST_BURST_CONFIG_READ
16900
        `undef TEST_BURST_CONFIG_READ
16901
    `endif
16902
 
16903
    `ifdef TEST_BURST_CONFIG_WRITE
16904
        `undef TEST_BURST_CONFIG_WRITE
16905
    `endif
16906
 
16907
    master1_check_received_data = 1 ;
16908
    master2_check_received_data = 1 ;
16909
 
16910
    if ( do_mem_disconnects )
16911
    begin
16912
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
16913
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16914
        if ( ok !== 1 )
16915
        begin
16916
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16917
            test_fail("PCI Base Address register could not be written") ;
16918
            disable main ;
16919
        end
16920
 
16921
        // Set Address Mask of IMAGE
16922
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16923
        if ( ok !== 1 )
16924
        begin
16925
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16926
            test_fail("PCI Address Mask register could not be written") ;
16927
            disable main ;
16928
        end
16929
 
16930
        // Set Translation Address of IMAGE
16931
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16932
        if ( ok !== 1 )
16933
        begin
16934
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16935
            test_fail("PCI Translation Address Register could not be written") ;
16936
            disable main ;
16937
        end
16938
 
16939
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16940
        if ( ok !== 1 )
16941
        begin
16942
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16943
            test_fail("PCI Image Control register could not be written") ;
16944
            disable main ;
16945
        end
16946
 
16947
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
16948
        if ( ok !== 1 )
16949
        begin
16950
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16951
            test_fail("Cache Line Size register could not be written") ;
16952
            disable main ;
16953
        end
16954
 
16955
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
16956
        pci_address = Target_Base_Addr_R[target_mem_image] ;
16957
        data = 32'hAAAA_AAAA ;
16958
        byte_enables = 4'h0 ;
16959
        expect_length = `PCIW_DEPTH - 2 ;
16960
 
16961
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16962
        fork
16963
        begin
16964
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
16965
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16966
                        byte_enables,
16967
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
16968
                        8'h0_0, `Test_One_Zero_Target_WS,
16969
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16970
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16971
            do_pause( 3 ) ;
16972
 
16973
            while ( FRAME !== 1 || IRDY !== 1 )
16974
                @(posedge pci_clock) ;
16975
 
16976 35 mihad
            #1 ;
16977
            if ( !error_monitor_done )
16978
                disable monitor_error_event5 ;
16979 15 mihad
        end
16980
        begin:monitor_error_event5
16981 35 mihad
            error_monitor_done = 0 ;
16982 15 mihad
            pci_ok = 1 ;
16983
            @(error_event_int) ;
16984
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
16985
            pci_ok = 0 ;
16986 35 mihad
            error_monitor_done = 1 ;
16987 15 mihad
        end
16988
        begin
16989
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
16990
            if ( wb_ok !== 1 )
16991
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
16992
        end
16993
        join
16994
 
16995
        if ( wb_ok && pci_ok )
16996
            test_ok ;
16997
 
16998
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
16999
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17000
        data = 32'hAAAA_AAAA ;
17001
        byte_enables = 4'h0 ;
17002
        expect_length = `PCIW_DEPTH - 2 ;
17003
 
17004
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17005
        fork
17006
        begin
17007
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17008
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17009
                        byte_enables,
17010
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
17011
                        8'h0_0, `Test_One_Zero_Target_WS,
17012
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17013
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17014
            do_pause( 3 ) ;
17015
 
17016
            while ( FRAME !== 1 || IRDY !== 1 )
17017
                @(posedge pci_clock) ;
17018
 
17019 35 mihad
            #1 ;
17020
            if ( !error_monitor_done )
17021
                disable monitor_error_event6 ;
17022 15 mihad
        end
17023
        begin:monitor_error_event6
17024 35 mihad
            error_monitor_done = 0 ;
17025 15 mihad
            pci_ok = 1 ;
17026
            @(error_event_int) ;
17027
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17028
            pci_ok = 0 ;
17029 35 mihad
            error_monitor_done = 1 ;
17030 15 mihad
        end
17031
        begin
17032
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17033
            if ( wb_ok !== 1 )
17034
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17035
        end
17036
        join
17037
 
17038
        if ( wb_ok && pci_ok )
17039
            test_ok ;
17040
 
17041
        master1_check_received_data = 1 ;
17042
//        master2_check_received_data = 0 ;
17043
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17044
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17045
        data = 32'hAAAA_AAAA ;
17046
        byte_enables = 4'h0 ;
17047
        expect_length = 4 ;
17048
 
17049
        fork
17050
        begin
17051
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17052
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17053
                        byte_enables,
17054
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17055
                        8'h0_0, `Test_One_Zero_Target_WS,
17056
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17057
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17058
            do_pause( 1 ) ;
17059
 
17060
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17061
            if ( wb_ok !== 1 )
17062
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17063
 
17064
            do_pause(2) ;
17065
 
17066
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17067
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17068
                        byte_enables,
17069
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17070
                        8'h0_0, `Test_One_Zero_Target_WS,
17071
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17072
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17073
            do_pause( 3 ) ;
17074
 
17075
            while ( FRAME !== 1 || IRDY !== 1 )
17076
                @(posedge pci_clock) ;
17077
 
17078 35 mihad
            #1 ;
17079
            if ( !error_monitor_done )
17080
                disable monitor_error_event7 ;
17081 15 mihad
        end
17082
        begin:monitor_error_event7
17083 35 mihad
            error_monitor_done = 0 ;
17084 15 mihad
            pci_ok = 1 ;
17085
            @(error_event_int) ;
17086
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17087
            pci_ok = 0 ;
17088 35 mihad
            error_monitor_done = 1 ;
17089 15 mihad
        end
17090
        join
17091
 
17092
        if ( wb_ok && pci_ok )
17093
            test_ok ;
17094
 
17095
        master1_check_received_data = 1 ;
17096
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17097
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17098
        data = 32'hAAAA_AAAA ;
17099
        byte_enables = 4'h0 ;
17100
        expect_length = 4 ;
17101
 
17102
        fork
17103
        begin
17104
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17105
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17106
                        byte_enables,
17107
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17108
                        8'h0_0, `Test_One_Zero_Target_WS,
17109
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17110
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17111
            do_pause( 1 ) ;
17112
 
17113
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17114
            if ( wb_ok !== 1 )
17115
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17116
 
17117
            do_pause(2) ;
17118
 
17119
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17120
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17121
                        byte_enables,
17122
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17123
                        8'h0_0, `Test_One_Zero_Target_WS,
17124
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17125
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17126
            do_pause( 3 ) ;
17127
 
17128
            while ( FRAME !== 1 || IRDY !== 1 )
17129
                @(posedge pci_clock) ;
17130
 
17131 35 mihad
            #1 ;
17132
            if ( !error_monitor_done )
17133
                disable monitor_error_event8 ;
17134 15 mihad
        end
17135
        begin:monitor_error_event8
17136 35 mihad
            error_monitor_done = 0 ;
17137 15 mihad
            pci_ok = 1 ;
17138
            @(error_event_int) ;
17139
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17140
            pci_ok = 0 ;
17141 35 mihad
            error_monitor_done = 1 ;
17142 15 mihad
        end
17143
        join
17144
 
17145
        if ( wb_ok && pci_ok )
17146
            test_ok ;
17147
 
17148
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17149
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17150
        data = 32'hDEAF_BEAF ;
17151
        byte_enables = 4'h0 ;
17152
        expect_length = 1 ;
17153
 
17154
        fork
17155
        begin
17156
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17157
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17158
                        byte_enables,
17159
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17160
                        8'h0_0, `Test_One_Zero_Target_WS,
17161
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17162
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17163
            do_pause( 3 ) ;
17164
 
17165
            while ( FRAME !== 1 || IRDY !== 1 )
17166
                @(posedge pci_clock) ;
17167
 
17168 35 mihad
            #1 ;
17169
            if ( !error_monitor_done )
17170
                disable monitor_error_event9 ;
17171 15 mihad
        end
17172
        begin:monitor_error_event9
17173 35 mihad
            error_monitor_done = 0 ;
17174 15 mihad
            pci_ok = 1 ;
17175
            @(error_event_int) ;
17176
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17177
            pci_ok = 0 ;
17178 35 mihad
            error_monitor_done = 1 ;
17179 15 mihad
        end
17180
        begin
17181
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17182
            if ( wb_ok !== 1 )
17183
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17184
        end
17185
        join
17186
 
17187
        if ( wb_ok && pci_ok )
17188
            test_ok ;
17189
 
17190
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17191
        data = 32'hDEAD_BEAF ;
17192
        byte_enables = 4'h0 ;
17193
        expect_length = 1 ;
17194
 
17195
        fork
17196
        begin
17197
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17198
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17199
                        byte_enables,
17200
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17201
                        8'h0_0, `Test_One_Zero_Target_WS,
17202
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17203
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17204
            do_pause( 3 ) ;
17205
 
17206
            while ( FRAME !== 1 || IRDY !== 1 )
17207
                @(posedge pci_clock) ;
17208
 
17209 35 mihad
            #1 ;
17210
            if ( !error_monitor_done )
17211
                disable monitor_error_event10 ;
17212 15 mihad
        end
17213
        begin:monitor_error_event10
17214 35 mihad
            error_monitor_done = 0 ;
17215 15 mihad
            pci_ok = 1 ;
17216
            @(error_event_int) ;
17217
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17218
            pci_ok = 0 ;
17219 35 mihad
            error_monitor_done = 1 ;
17220 15 mihad
        end
17221
        begin
17222
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17223
            if ( wb_ok !== 1 )
17224
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17225
        end
17226
        join
17227
 
17228
        if ( wb_ok && pci_ok )
17229
            test_ok ;
17230
 
17231
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17232
        data = 32'hAAAA_AAAA ;
17233
        byte_enables = 4'h0 ;
17234
        expect_length = 1 ;
17235
 
17236
        fork
17237
        begin
17238
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17239
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17240
                        byte_enables,
17241
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17242
                        8'h0_0, `Test_One_Zero_Target_WS,
17243
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17244
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17245
            do_pause( 3 ) ;
17246
 
17247
            while ( FRAME !== 1 || IRDY !== 1 )
17248
                @(posedge pci_clock) ;
17249
 
17250 35 mihad
            #1 ;
17251
            if ( !error_monitor_done )
17252
                disable monitor_error_event11 ;
17253 15 mihad
        end
17254
        begin:monitor_error_event11
17255 35 mihad
            error_monitor_done = 0 ;
17256 15 mihad
            pci_ok = 1 ;
17257
            @(error_event_int) ;
17258
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17259
            pci_ok = 0 ;
17260 35 mihad
            error_monitor_done = 1 ;
17261 15 mihad
        end
17262
        begin
17263
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17264
            if ( wb_ok !== 1 )
17265
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17266
        end
17267
        join
17268
 
17269
        if ( wb_ok && pci_ok )
17270
            test_ok ;
17271
 
17272
        master1_check_received_data = 1 ;
17273
 
17274
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17275
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17276
        data = 32'hDEAF_BEAF ;
17277
        byte_enables = 4'h0 ;
17278
        expect_length = 1 ;
17279
 
17280
        fork
17281
        begin
17282
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17283
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17284
                        byte_enables,
17285
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17286
                        8'h0_0, `Test_One_Zero_Target_WS,
17287
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17288
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17289
            do_pause( 1 ) ;
17290
 
17291
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17292
            if ( wb_ok !== 1 )
17293
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17294
 
17295
            do_pause(3) ;
17296
 
17297
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17298
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17299
                        byte_enables,
17300
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17301
                        8'h0_0, `Test_One_Zero_Target_WS,
17302
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17303
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17304
            do_pause( 3 ) ;
17305
 
17306
            while ( FRAME !== 1 || IRDY !== 1 )
17307
                @(posedge pci_clock) ;
17308
 
17309 35 mihad
            #1 ;
17310
            if ( !error_monitor_done )
17311
                disable monitor_error_event12 ;
17312 15 mihad
        end
17313
        begin:monitor_error_event12
17314 35 mihad
            error_monitor_done = 0 ;
17315 15 mihad
            pci_ok = 1 ;
17316
            @(error_event_int) ;
17317
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17318
            pci_ok = 0 ;
17319 35 mihad
            error_monitor_done = 1 ;
17320 15 mihad
        end
17321
        join
17322
 
17323
        if ( wb_ok && pci_ok )
17324
            test_ok ;
17325
 
17326
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17327
        data = 32'hDEAD_BEAF ;
17328
        byte_enables = 4'h0 ;
17329
        expect_length = 1 ;
17330
 
17331
        fork
17332
        begin
17333
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17334
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17335
                        byte_enables,
17336
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17337
                        8'h0_0, `Test_One_Zero_Target_WS,
17338
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17339
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17340
            do_pause( 1 ) ;
17341
 
17342
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17343
            if ( wb_ok !== 1 )
17344
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17345
 
17346
            do_pause(3) ;
17347
 
17348
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17349
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17350
                        byte_enables,
17351
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17352
                        8'h0_0, `Test_One_Zero_Target_WS,
17353
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17354
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17355
            do_pause( 3 ) ;
17356
 
17357
            while ( FRAME !== 1 || IRDY !== 1 )
17358
                @(posedge pci_clock) ;
17359
 
17360 35 mihad
            #1 ;
17361
            if ( !error_monitor_done )
17362
                disable monitor_error_event13 ;
17363 15 mihad
        end
17364
        begin:monitor_error_event13
17365 35 mihad
            error_monitor_done = 0 ;
17366 15 mihad
            pci_ok = 1 ;
17367
            @(error_event_int) ;
17368
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17369
            pci_ok = 0 ;
17370 35 mihad
            error_monitor_done = 1 ;
17371 15 mihad
        end
17372
        join
17373
 
17374
        if ( wb_ok && pci_ok )
17375
            test_ok ;
17376
 
17377
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17378
        data = 32'hAAAA_AAAA ;
17379
        byte_enables = 4'h0 ;
17380
        expect_length = 1 ;
17381
 
17382
        fork
17383
        begin
17384
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17385
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17386
                        byte_enables,
17387
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17388
                        8'h0_0, `Test_One_Zero_Target_WS,
17389
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17390
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17391
            do_pause( 1 ) ;
17392
 
17393
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17394
            if ( wb_ok !== 1 )
17395
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17396
 
17397
            do_pause(3) ;
17398
 
17399
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17400
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17401
                        byte_enables,
17402
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17403
                        8'h0_0, `Test_One_Zero_Target_WS,
17404
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17405
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17406
            do_pause( 3 ) ;
17407
 
17408
            while ( FRAME !== 1 || IRDY !== 1 )
17409
                @(posedge pci_clock) ;
17410
 
17411 35 mihad
            #1 ;
17412
            if ( !error_monitor_done )
17413
                disable monitor_error_event14 ;
17414 15 mihad
        end
17415
        begin:monitor_error_event14
17416 35 mihad
            error_monitor_done = 0 ;
17417 15 mihad
            pci_ok = 1 ;
17418
            @(error_event_int) ;
17419
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17420
            pci_ok = 0 ;
17421 35 mihad
            error_monitor_done = 1 ;
17422 15 mihad
        end
17423
        join
17424
 
17425
        if ( wb_ok && pci_ok )
17426
            test_ok ;
17427
 
17428
        // disable the image
17429
        test_name = "DISABLING MEMORY IMAGE" ;
17430 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17431 15 mihad
        if ( ok !== 1 )
17432
        begin
17433
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17434
            test_fail("PCI Address Mask register could not be written") ;
17435
            disable main ;
17436
        end
17437
    end
17438
//*
17439
    if ( target_io_image !== -1 )
17440
    begin
17441
        do_io_disconnects = 1 ;
17442
 
17443
        if (target_io_image === 1)
17444
        begin
17445
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17446
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17447
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17448
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17449
        end
17450
        else if (target_io_image === 2)
17451
        begin
17452
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17453
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17454
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17455
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17456
        end
17457
        else if (target_io_image === 3)
17458
        begin
17459
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17460
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17461
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17462
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17463
        end
17464
        else if (target_io_image === 4)
17465
        begin
17466
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17467
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17468
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17469
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17470
        end
17471
        else if (target_io_image === 5)
17472
        begin
17473
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17474
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17475
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17476
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17477
        end
17478
    end
17479
    else
17480
        do_io_disconnects = 0 ;
17481
 
17482
    if ( do_io_disconnects )
17483
    begin
17484
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17485
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17486
        if ( ok !== 1 )
17487
        begin
17488
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17489
            test_fail("PCI Base Address register could not be written") ;
17490
            disable main ;
17491
        end
17492
 
17493
        // Set Address Mask of IMAGE
17494
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17495
        if ( ok !== 1 )
17496
        begin
17497
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17498
            test_fail("PCI Address Mask register could not be written") ;
17499
            disable main ;
17500
        end
17501
 
17502
        // Set Translation Address of IMAGE
17503
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17504
        if ( ok !== 1 )
17505
        begin
17506
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17507
            test_fail("PCI Translation Address Register could not be written") ;
17508
            disable main ;
17509
        end
17510
 
17511
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17512
        if ( ok !== 1 )
17513
        begin
17514
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17515
            test_fail("PCI Image Control register could not be written") ;
17516
            disable main ;
17517
        end
17518
 
17519
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17520
        if ( ok !== 1 )
17521
        begin
17522
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17523
            test_fail("Cache Line Size register could not be written") ;
17524
            disable main ;
17525
        end
17526
 
17527
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17528
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17529
        data = 32'h5555_5555 ;
17530
        byte_enables = 4'h0 ;
17531
        expect_length = 1 ;
17532
 
17533
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17534
 
17535
        fork
17536
        begin
17537
            PCIU_IO_WRITE
17538
            (
17539
                `Test_Master_1,             // which master
17540
                pci_address,                // to what address
17541
                data,                       // data
17542
                byte_enables,               // byte enable
17543
                expect_length + 1,          // length to request
17544
                `Test_Target_Retry_On       // expected target termination
17545
            ) ;
17546
 
17547
            do_pause( 3 ) ;
17548
 
17549
            while ( FRAME !== 1 || IRDY !== 1 )
17550
                @(posedge pci_clock) ;
17551
 
17552 35 mihad
            #1 ;
17553
            if ( !error_monitor_done )
17554
                disable monitor_error_event15 ;
17555 15 mihad
        end
17556
        begin:monitor_error_event15
17557 35 mihad
            error_monitor_done = 0 ;
17558 15 mihad
            pci_ok = 1 ;
17559
            @(error_event_int) ;
17560
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17561
            pci_ok = 0 ;
17562 35 mihad
            error_monitor_done = 1 ;
17563 15 mihad
        end
17564
        begin
17565
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17566
            if ( wb_ok !== 1 )
17567
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17568
        end
17569
        join
17570
 
17571
        if ( wb_ok && pci_ok )
17572
            test_ok ;
17573
 
17574
        data = 32'hAAAA_AAAA ;
17575
        fork
17576
        begin
17577
            PCIU_IO_WRITE
17578
            (
17579
                `Test_Master_1,             // which master
17580
                pci_address,                // to what address
17581
                data,                       // data
17582
                byte_enables,               // byte enable
17583
                expect_length + 2,          // length to request
17584
                `Test_Target_Retry_Before   // expected target termination
17585
            ) ;
17586
 
17587
            do_pause( 3 ) ;
17588
 
17589
            while ( FRAME !== 1 || IRDY !== 1 )
17590
                @(posedge pci_clock) ;
17591
 
17592 35 mihad
            #1 ;
17593
            if ( !error_monitor_done )
17594
                disable monitor_error_event16 ;
17595 15 mihad
        end
17596
        begin:monitor_error_event16
17597 35 mihad
            error_monitor_done = 0 ;
17598 15 mihad
            pci_ok = 1 ;
17599
            @(error_event_int) ;
17600
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17601
            pci_ok = 0 ;
17602 35 mihad
            error_monitor_done = 1 ;
17603 15 mihad
        end
17604
        begin
17605
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17606
            if ( wb_ok !== 1 )
17607
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17608
        end
17609
        join
17610
 
17611
        if ( wb_ok && pci_ok )
17612
            test_ok ;
17613
 
17614
        master2_check_received_data = 1 ;
17615
 
17616
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17617
 
17618
        fork
17619
        begin
17620
 
17621
             PCIU_IO_READ
17622
             (
17623
                `Test_Master_2,
17624
                pci_address[PCI_BUS_DATA_RANGE:0],
17625
                data,
17626
                byte_enables,
17627
                2,
17628
                `Test_Target_Retry_Before
17629
             );
17630
 
17631
            do_pause( 1 ) ;
17632
 
17633
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17634
            if ( wb_ok !== 1 )
17635
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17636
 
17637
            do_pause(3) ;
17638
 
17639
            PCIU_IO_READ
17640
             (
17641
                `Test_Master_2,
17642
                pci_address[PCI_BUS_DATA_RANGE:0],
17643
                data,
17644
                byte_enables,
17645
                expect_length + 1,
17646
                `Test_Target_Retry_On
17647
             );
17648
 
17649
            do_pause( 3 ) ;
17650
 
17651
            while ( FRAME !== 1 || IRDY !== 1 )
17652
                @(posedge pci_clock) ;
17653
 
17654 35 mihad
            #1 ;
17655
            if ( !error_monitor_done )
17656
                disable monitor_error_event17 ;
17657 15 mihad
        end
17658
        begin:monitor_error_event17
17659 35 mihad
            error_monitor_done = 0 ;
17660 15 mihad
            pci_ok = 1 ;
17661
            @(error_event_int) ;
17662
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17663
            pci_ok = 0 ;
17664 35 mihad
            error_monitor_done = 1 ;
17665 15 mihad
        end
17666
        join
17667
 
17668
        if ( wb_ok && pci_ok )
17669
            test_ok ;
17670
 
17671
        fork
17672
        begin
17673
 
17674
             PCIU_IO_READ
17675
             (
17676
                `Test_Master_2,
17677
                pci_address[PCI_BUS_DATA_RANGE:0],
17678
                data,
17679
                byte_enables,
17680
                2,
17681
                `Test_Target_Retry_Before
17682
             );
17683
 
17684
            do_pause( 1 ) ;
17685
 
17686
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17687
            if ( wb_ok !== 1 )
17688
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17689
 
17690
            do_pause(3) ;
17691
 
17692
            PCIU_IO_READ
17693
             (
17694
                `Test_Master_2,
17695
                pci_address[PCI_BUS_DATA_RANGE:0],
17696
                data,
17697
                byte_enables,
17698
                expect_length + 2,
17699
                `Test_Target_Retry_Before
17700
             );
17701
 
17702
            do_pause( 3 ) ;
17703
 
17704
            while ( FRAME !== 1 || IRDY !== 1 )
17705
                @(posedge pci_clock) ;
17706
 
17707 35 mihad
            #1 ;
17708
            if ( !error_monitor_done )
17709
                disable monitor_error_event18 ;
17710 15 mihad
        end
17711
        begin:monitor_error_event18
17712 35 mihad
            error_monitor_done = 0 ;
17713 15 mihad
            pci_ok = 1 ;
17714
            @(error_event_int) ;
17715
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17716
            pci_ok = 0 ;
17717 35 mihad
            error_monitor_done = 1 ;
17718 15 mihad
        end
17719
        join
17720
 
17721
        if ( wb_ok && pci_ok )
17722
            test_ok ;
17723
 
17724
        test_name = "DISABLING IO IMAGE" ;
17725 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17726 15 mihad
        if ( ok !== 1 )
17727
        begin
17728
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17729
            test_fail("PCI Address Mask register could not be written") ;
17730
            disable main ;
17731
        end
17732
    end
17733
//*/
17734
end
17735
endtask // target_disconnects
17736
 
17737
task target_unsupported_cmds ;
17738
        input [31:0] Address;
17739
        input [2:0]  image_num ;
17740
    reg          ok ;
17741
begin:main
17742
 
17743
    $display("  ") ;
17744
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17745
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17746 45 mihad
 
17747
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17748
    configuration_cycle_write
17749
    (
17750
        0,                        // bus number
17751
        `TAR1_IDSEL_INDEX - 11,   // device number
17752
        0,                        // function number
17753
        1,                        // register number
17754
        0,                        // type of configuration cycle
17755
        4'b0001,                  // byte enables
17756
        32'h0000_0044             // data
17757
    ) ;
17758
 
17759
    configuration_cycle_write
17760
    (
17761
        0,                        // bus number
17762
        `TAR2_IDSEL_INDEX - 11,   // device number
17763
        0,                        // function number
17764
        1,                        // register number
17765
        0,                        // type of configuration cycle
17766
        4'b0001,                  // byte enables
17767
        32'h0000_0044             // data
17768
    ) ;
17769
 
17770 15 mihad
    ipci_unsupported_commands_master.master_reference
17771
    (
17772
        Address,                // first part of address in dual address cycle
17773
        Address,                // second part of address in dual address cycle
17774
        `BC_IACK,                       // dual address cycle command
17775
        `BC_IACK,               // normal command
17776
        4'h0,               // byte enables
17777
        32'h1234_5678,      // data
17778
        1'b0,               // make address parity error on first phase of dual address
17779
        1'b0,               // make address parity error on second phase of dual address
17780
        ok                  // result of operation
17781
    ) ;
17782
    if ( ok )
17783
        test_ok ;
17784
    else
17785
    begin
17786
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17787
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17788
    end
17789
 
17790
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17791
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17792
    ipci_unsupported_commands_master.master_reference
17793
    (
17794
        Address,                // first part of address in dual address cycle
17795
        Address,                // second part of address in dual address cycle
17796
        `BC_SPECIAL,            // dual address cycle command
17797
        `BC_SPECIAL,            // normal command
17798
        4'h0,               // byte enables
17799
        32'h1234_5678,      // data
17800
        1'b0,               // make address parity error on first phase of dual address
17801
        1'b0,               // make address parity error on second phase of dual address
17802
        ok                  // result of operation
17803
    ) ;
17804
    if ( ok )
17805
        test_ok ;
17806
    else
17807
    begin
17808
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17809
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17810
    end
17811
 
17812
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17813
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17814
    ipci_unsupported_commands_master.master_reference
17815
    (
17816
        Address,                // first part of address in dual address cycle
17817
        Address,                // second part of address in dual address cycle
17818
        `BC_RESERVED0,          // dual address cycle command
17819
        `BC_RESERVED0,      // normal command
17820
        4'h0,               // byte enables
17821
        32'h1234_5678,      // data
17822
        1'b0,               // make address parity error on first phase of dual address
17823
        1'b0,               // make address parity error on second phase of dual address
17824
        ok                  // result of operation
17825
    ) ;
17826
    if ( ok )
17827
        test_ok ;
17828
    else
17829
    begin
17830
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17831
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17832
    end
17833
 
17834
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17835
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17836
    ipci_unsupported_commands_master.master_reference
17837
    (
17838
        Address,                // first part of address in dual address cycle
17839
        Address,                // second part of address in dual address cycle
17840
        `BC_RESERVED1,          // dual address cycle command
17841
        `BC_RESERVED1,      // normal command
17842
        4'h0,               // byte enables
17843
        32'h1234_5678,      // data
17844
        1'b0,               // make address parity error on first phase of dual address
17845
        1'b0,               // make address parity error on second phase of dual address
17846
        ok                  // result of operation
17847
    ) ;
17848
    if ( ok )
17849
        test_ok ;
17850
    else
17851
    begin
17852
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17853
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
17854
    end
17855
 
17856
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
17857
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
17858
    ipci_unsupported_commands_master.master_reference
17859
    (
17860
        Address,                // first part of address in dual address cycle
17861
        Address,                // second part of address in dual address cycle
17862
        `BC_RESERVED2,          // dual address cycle command
17863
        `BC_RESERVED2,      // normal command
17864
        4'h0,               // byte enables
17865
        32'h1234_5678,      // data
17866
        1'b0,               // make address parity error on first phase of dual address
17867
        1'b0,               // make address parity error on second phase of dual address
17868
        ok                  // result of operation
17869
    ) ;
17870
    if ( ok )
17871
        test_ok ;
17872
    else
17873
    begin
17874
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17875
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
17876
    end
17877
 
17878
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
17879
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
17880
    ipci_unsupported_commands_master.master_reference
17881
    (
17882
        Address,                // first part of address in dual address cycle
17883
        Address,                // second part of address in dual address cycle
17884
        `BC_RESERVED3,          // dual address cycle command
17885
        `BC_RESERVED3,      // normal command
17886
        4'h0,               // byte enables
17887
        32'h1234_5678,      // data
17888
        1'b0,               // make address parity error on first phase of dual address
17889
        1'b0,               // make address parity error on second phase of dual address
17890
        ok                  // result of operation
17891
    ) ;
17892
    if ( ok )
17893
        test_ok ;
17894
    else
17895
    begin
17896
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17897
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
17898
    end
17899
 
17900
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
17901
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
17902
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
17903
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
17904
    ipci_unsupported_commands_master.master_reference
17905
    (
17906
        Address,                // first part of address in dual address cycle
17907
        Address,                // second part of address in dual address cycle
17908
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
17909
        `BC_MEM_WRITE,      // normal command
17910
        4'h0,               // byte enables;
17911
        32'h1234_5678,      // data
17912
        1'b0,               // make address parity error on first phase of dual address
17913
        1'b0,               // make address parity error on second phase of dual address
17914
        ok                  // result of operation
17915
    ) ;
17916
    if ( ok )
17917
        test_ok ;
17918
    else
17919
    begin
17920
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17921
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
17922
    end
17923
 
17924 45 mihad
    // enable pci blue behavioral targets 1 and 2
17925
    configuration_cycle_write
17926
    (
17927
        0,                        // bus number
17928
        `TAR1_IDSEL_INDEX - 11,   // device number
17929
        0,                        // function number
17930
        1,                        // register number
17931
        0,                        // type of configuration cycle
17932
        4'b0001,                  // byte enables
17933
        32'h0000_0047             // data
17934
    ) ;
17935
 
17936
    configuration_cycle_write
17937
    (
17938
        0,                        // bus number
17939
        `TAR2_IDSEL_INDEX - 11,   // device number
17940
        0,                        // function number
17941
        1,                        // register number
17942
        0,                        // type of configuration cycle
17943
        4'b0001,                  // byte enables
17944
        32'h0000_0047             // data
17945
    ) ;
17946 15 mihad
end
17947
endtask // target_unsupported_cmds
17948
 
17949
task target_completion_expiration ;
17950
    reg   [11:0] pci_ctrl_offset ;
17951
    reg   [11:0] pci_ba_offset ;
17952
    reg   [11:0] pci_am_offset ;
17953
    reg   [11:0] pci_device_ctrl_offset ;
17954
    reg   [11:0] pci_err_cs_offset ;
17955
    reg   [11:0] icr_offset ;
17956
    reg   [11:0] isr_offset ;
17957
    reg   [11:0] lat_tim_cls_offset ;
17958
 
17959
    reg [31:0] temp_val1 ;
17960
    reg [31:0] temp_val2 ;
17961
    reg        ok   ;
17962 33 mihad
    reg        ok_wb ;
17963
    reg        ok_pci ;
17964 15 mihad
 
17965
    reg [31:0] pci_image_base ;
17966
    integer i ;
17967 33 mihad
    integer clocks_after_completion ;
17968
    reg     error_monitor_done ;
17969
    reg     test_mem ;
17970 15 mihad
 
17971
begin:main
17972
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17973
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
17974
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
17975
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
17976
 
17977
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
17978
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
17979
    lat_tim_cls_offset = 12'hC ;
17980
    pci_device_ctrl_offset    = 12'h4 ;
17981
 
17982 33 mihad
    `ifdef HOST
17983
        test_mem = 1'b1 ;
17984
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
17985
    `else
17986
        test_mem = !`PCI_BA1_MEM_IO ;
17987
        pci_image_base = Target_Base_Addr_R[1] ;
17988
    `endif
17989 15 mihad
 
17990
    // enable master & target operation
17991
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
17992
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
17993
    if ( ok !== 1 )
17994
    begin
17995
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
17996
        test_fail("write to PCI Device Control register failed") ;
17997
        disable main ;
17998
    end
17999
 
18000
    // prepare image control register
18001 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18002 15 mihad
    if ( ok !== 1 )
18003
    begin
18004
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18005
        test_fail("write to PCI Image Control register failed") ;
18006
        disable main ;
18007
    end
18008
 
18009
    // prepare base address register
18010
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18011
    if ( ok !== 1 )
18012
    begin
18013
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18014
        test_fail("write to PCI Base Address register failed") ;
18015
        disable main ;
18016
    end
18017
 
18018
    // write address mask register
18019
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18020
    if ( ok !== 1 )
18021
    begin
18022
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18023
        test_fail("write to PCI Address Mask register failed") ;
18024
        disable main ;
18025
    end
18026
 
18027
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18028
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18029
    if ( ok !== 1 )
18030
    begin
18031
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18032
        test_fail("write to PCI Error Control and Status register failed") ;
18033
        disable main ;
18034
    end
18035
 
18036 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18037 15 mihad
    if ( ok !== 1 )
18038
    begin
18039
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18040
        test_fail("write to Interrupt Control register failed") ;
18041
        disable main ;
18042
    end
18043
 
18044
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18045
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18046
    if ( ok !== 1 )
18047
    begin
18048
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18049
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18050
        disable main ;
18051
    end
18052
 
18053
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18054
 
18055
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18056 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18057
    master1_check_received_data = 0 ;
18058 15 mihad
 
18059 33 mihad
    ok_pci = 1 ;
18060
    // start a delayed read request
18061
    fork
18062
    begin
18063
        if ( test_mem )
18064
 
18065
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18066
                          pci_image_base, 32'h1234_5678,
18067
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18068
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18069
        else
18070
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18071
 
18072
        do_pause( 1 ) ;
18073
    end
18074
    begin:error_monitor1
18075 35 mihad
        error_monitor_done = 0 ;
18076 33 mihad
        @(error_event_int) ;
18077
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18078
        ok_pci = 0 ;
18079 35 mihad
        error_monitor_done = 1 ;
18080 33 mihad
    end
18081
    begin
18082
        if ( test_mem )
18083
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18084
        else
18085
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18086 15 mihad
 
18087 33 mihad
        if ( ok_wb !== 1 )
18088
        begin
18089
            test_fail("Bridge failed to process Target Memory read correctly") ;
18090
            disable main ;
18091
        end
18092
 
18093 35 mihad
        #1 ;
18094
        if ( !error_monitor_done )
18095 33 mihad
            disable error_monitor1 ;
18096
    end
18097
    join
18098
 
18099
    clocks_after_completion = 0 ;
18100
    // now do another - different transaction
18101
    fork
18102
    begin
18103
        if ( test_mem )
18104
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18105
                          pci_image_base + 4, 32'h1234_5678,
18106
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18107
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18108
        else
18109
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18110
 
18111
        while ( clocks_after_completion < 32'h0000_FFF0 )
18112
        begin
18113
            @(posedge pci_clock) ;
18114
            clocks_after_completion = clocks_after_completion + 1 ;
18115
        end
18116
 
18117
        do_pause('hFF) ;
18118
 
18119
        if ( test_mem )
18120
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18121
                          pci_image_base + 4, 32'h1234_5678,
18122
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18123
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18124
        else
18125
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18126
 
18127
        do_pause( 1 ) ;
18128
    end
18129
    begin:error_monitor2
18130 35 mihad
        error_monitor_done = 0 ;
18131 33 mihad
        @(error_event_int) ;
18132
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18133
        ok_pci = 0 ;
18134 35 mihad
        error_monitor_done = 1 ;
18135 33 mihad
    end
18136
    begin
18137
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18138
        repeat( 'hFF )
18139
            @(posedge pci_clock) ;
18140
 
18141
        if ( test_mem )
18142
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18143
        else
18144
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18145
 
18146
        if ( ok_wb !== 1 )
18147
        begin
18148
            test_fail("Bridge failed to process Target Memory read correctly") ;
18149
            disable main ;
18150
        end
18151
 
18152
        repeat(4)
18153
            @(posedge pci_clock) ;
18154
 
18155
        fork
18156
        begin
18157
            if ( test_mem )
18158
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18159
                              pci_image_base + 4, 32'h1234_5678,
18160
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18161
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18162
            else
18163
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18164
 
18165
            do_pause(1) ;
18166
        end
18167
        begin
18168
           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 ) ;
18169 35 mihad
           #1 ;
18170
           if ( !error_monitor_done )
18171 33 mihad
               disable error_monitor2 ;
18172
        end
18173
        join
18174
    end
18175
    join
18176
 
18177
    if ( ok && ok_pci && ok_wb )
18178
        test_ok ;
18179
 
18180
    if ( ok !== 1 )
18181
    begin
18182
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18183
        test_fail("write to PCI Address Mask register failed") ;
18184
        disable main ;
18185
    end
18186
 
18187
    // check statuses after this situation - none should be set
18188
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18189
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18190
    if ( ok !== 1 )
18191
    begin
18192
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18193
        test_fail("read from pci device status register failed") ;
18194
        disable main ;
18195
    end
18196
 
18197
    if ( temp_val1[31] )
18198
    begin
18199
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18200
        test_fail("detected parity error bit was set for no reason") ;
18201
    end
18202
 
18203
    if ( temp_val1[30] )
18204
    begin
18205
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18206
        test_fail("signaled system error bit was set for no reason") ;
18207
    end
18208
 
18209
    if ( temp_val1[29] )
18210
    begin
18211
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18212
        test_fail("received master abort bit was set for no reason") ;
18213
    end
18214
 
18215
    if ( temp_val1[28] )
18216
    begin
18217
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18218
        test_fail("received target abort bit was set for no reason") ;
18219
    end
18220
 
18221
    if ( temp_val1[27] )
18222
    begin
18223
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18224
        test_fail("signaled target abort bit was set for no reason") ;
18225
    end
18226
 
18227
    if ( temp_val1[24] )
18228
    begin
18229
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18230
        test_fail("Master Data parity error bit was set for no reason") ;
18231
    end
18232
 
18233
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18234
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18235
    if ( temp_val1[8] !== 0 )
18236
    begin
18237
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18238
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18239
    end
18240
    // test target retry counter expiration
18241
    // set wb slave to retry response
18242
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18243
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18244
    ok_pci = 1 ;
18245
 
18246
    fork
18247
    begin
18248
        if ( test_mem == 1 )
18249
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18250
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18251
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18252
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18253
        else
18254
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18255
 
18256
        do_pause(1) ;
18257
 
18258
        // do another write with same address and different data
18259
        if ( test_mem == 1 )
18260
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18261
                        pci_image_base, 32'h8765_4321, 4'h0,
18262
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18263
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18264
        else
18265
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18266
 
18267
        do_pause(1) ;
18268
    end
18269
    begin
18270
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18271
        begin
18272
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18273
            if ( ok_wb !== 1 )
18274
            begin
18275
                $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) ;
18276
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18277
                disable main ;
18278
            end
18279
        end
18280
 
18281
        // set WB slave to normal completion
18282
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18283
 
18284
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18285
        if ( ok_wb !== 1 )
18286
        begin
18287
            $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) ;
18288
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18289
            disable main ;
18290
        end
18291
 
18292 35 mihad
        #1 ;
18293
        if ( !error_monitor_done )
18294 33 mihad
            disable error_monitor3 ;
18295
    end
18296
    begin:error_monitor3
18297 35 mihad
        error_monitor_done = 0 ;
18298 33 mihad
        @(error_event_int) ;
18299
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18300
        ok_pci = 0 ;
18301 35 mihad
        error_monitor_done = 1 ;
18302 33 mihad
    end
18303
    join
18304
 
18305
    if ( ok_wb && ok_pci )
18306
    begin
18307
        test_ok ;
18308
    end
18309
 
18310
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18311
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18312
    if ( temp_val1[8] !== 1'b1 )
18313
    begin
18314
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18315
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18316
    end
18317
 
18318
    if ( temp_val1[9] !== 1 )
18319
    begin
18320
        $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) ;
18321
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18322
    end
18323
 
18324
    if ( temp_val1[10] !== 1 )
18325
    begin
18326
        $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) ;
18327
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18328
    end
18329
 
18330
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18331
    begin
18332
        $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) ;
18333
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18334
    end
18335
 
18336
    if ( temp_val1[31:28] !== 4'hA )
18337
    begin
18338
        $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) ;
18339
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18340
    end
18341
 
18342
    // clear error status register
18343
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18344
 
18345
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18346
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18347
    if ( temp_val1 !== pci_image_base )
18348
    begin
18349
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18350
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18351
    end
18352
 
18353
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18354
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18355
    if ( temp_val1 !== 32'hDEAD_BEAF )
18356
    begin
18357
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18358
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18359
    end
18360
 
18361
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18362
    ok_pci = 1 ;
18363
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18364
 
18365
    i = 0 ;
18366
    fork
18367
    begin
18368
        if ( test_mem )
18369
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18370
                          pci_image_base + 4, 32'h1234_5678,
18371
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18372
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18373
        else
18374
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18375
 
18376
        do_pause( 1 ) ;
18377
 
18378
    end
18379
    begin
18380
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18381
        begin
18382
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18383
            if ( ok_wb !== 1 )
18384
            begin
18385
                $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) ;
18386
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18387
                disable main ;
18388
            end
18389
        end
18390
 
18391
        // set WB slave to normal completion
18392
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18393
 
18394
        fork
18395
        begin
18396
            repeat(4)
18397
                @(posedge pci_clock) ;
18398
 
18399
            if ( test_mem )
18400
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18401
                              pci_image_base, 32'h8765_4321,
18402
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18403
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18404
            else
18405
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18406
 
18407
            do_pause(1) ;
18408
        end
18409
        begin
18410
 
18411
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18412
            if ( ok_wb !== 1 )
18413
            begin
18414
                $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) ;
18415
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18416
                disable main ;
18417
            end
18418
        end
18419
        join
18420
 
18421
        repeat( 4 )
18422
            @(posedge pci_clock) ;
18423
 
18424
        if ( test_mem )
18425
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18426
                          pci_image_base, 32'h8765_4321,
18427
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18428
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18429
        else
18430
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18431
 
18432
        do_pause(1) ;
18433
 
18434 35 mihad
        #1 ;
18435
        if ( !error_monitor_done )
18436 33 mihad
            disable error_monitor4 ;
18437
    end
18438
    begin:error_monitor4
18439 35 mihad
        error_monitor_done = 0 ;
18440 33 mihad
        @(error_event_int) ;
18441
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18442
        ok_pci = 0 ;
18443 35 mihad
        error_monitor_done = 1 ;
18444 33 mihad
    end
18445
    join
18446
 
18447
    if ( ok_wb && ok_pci )
18448
        test_ok ;
18449
 
18450
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18451
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18452
    if ( temp_val1[8] !== 1'b0 )
18453
    begin
18454
        $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) ;
18455
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18456
    end
18457
 
18458
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18459 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18460
    $fdisplay(pciu_mon_log_file_desc,
18461
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18462 33 mihad
    ok_pci = 1 ;
18463
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18464
 
18465
    fork
18466
    begin
18467
        if ( test_mem )
18468
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18469
                          pci_image_base + 4, 32'h1234_5678,
18470
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18471
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18472
        else
18473
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18474
 
18475
        do_pause( 1 ) ;
18476
 
18477
    end
18478
    begin
18479
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18480
        if ( ok_wb !== 1 )
18481
        begin
18482
            $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) ;
18483
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18484
            disable main ;
18485
        end
18486
 
18487
        repeat(4)
18488
            @(posedge pci_clock) ;
18489
 
18490
        fork
18491
        begin
18492
 
18493
            if ( test_mem )
18494
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18495
                              pci_image_base + 4, 32'h8765_4321,
18496
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18497
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18498
            else
18499
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18500
 
18501
            do_pause(1) ;
18502
 
18503
        end
18504
        begin
18505
 
18506
            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 ) ;
18507
            if ( ok !== 1 )
18508
            begin
18509
                $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) ;
18510
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18511
                disable main ;
18512
            end
18513
        end
18514
        join
18515
 
18516 35 mihad
        #1 ;
18517
        if ( !error_monitor_done )
18518 33 mihad
            disable error_monitor5 ;
18519
    end
18520
    begin:error_monitor5
18521 35 mihad
        error_monitor_done = 0 ;
18522 33 mihad
        @(error_event_int) ;
18523
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18524
        ok_pci = 0 ;
18525 35 mihad
        error_monitor_done = 1 ;
18526 33 mihad
    end
18527
    join
18528
 
18529
    if ( ok_wb && ok_pci )
18530
        test_ok ;
18531
 
18532
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18533
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18534
    if ( temp_val1[8] !== 1'b0 )
18535
    begin
18536
        $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) ;
18537
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18538
    end
18539
 
18540
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18541
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18542
    if ( temp_val1[25] !== 1'b1 )
18543
    begin
18544
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18545
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18546
    end
18547
 
18548
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18549
 
18550
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18551
    ok_pci = 1 ;
18552
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18553
 
18554
    fork
18555
    begin
18556
        if ( test_mem == 1 )
18557
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18558
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18559
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18560
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18561
        else
18562
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18563
 
18564
        do_pause(1) ;
18565
 
18566
        // do another write with same address and different data
18567
        if ( test_mem == 1 )
18568
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18569
                        pci_image_base, 32'h8765_6789, 4'h0,
18570
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18571
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18572
        else
18573
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18574
 
18575
        do_pause(1) ;
18576
    end
18577
    begin
18578
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18579
        if ( ok_wb !== 1 )
18580
        begin
18581
            $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) ;
18582
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18583
            disable main ;
18584
        end
18585
 
18586
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18587
 
18588
        if ( test_mem )
18589
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18590
        else
18591
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18592
 
18593
        if ( ok_wb !== 1 )
18594
        begin
18595
            $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) ;
18596
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18597
            disable main ;
18598
        end
18599
 
18600 35 mihad
        #1 ;
18601
        if ( !error_monitor_done )
18602 33 mihad
            disable error_monitor6 ;
18603
    end
18604
    begin:error_monitor6
18605 35 mihad
        error_monitor_done = 0 ;
18606 33 mihad
        @(error_event_int) ;
18607
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18608
        ok_pci = 0 ;
18609 35 mihad
        error_monitor_done = 1 ;
18610 33 mihad
    end
18611
    join
18612
 
18613
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18614
    $fdisplay(pciu_mon_log_file_desc,
18615
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18616
 
18617
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18618
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18619
    if ( temp_val1[8] !== 1'b1 )
18620
    begin
18621
        $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) ;
18622
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18623
    end
18624
 
18625
    if ( temp_val1[9] !== 0 )
18626
    begin
18627
        $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) ;
18628
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18629
    end
18630
 
18631
    if ( temp_val1[10] !== 1 )
18632
    begin
18633
        $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) ;
18634
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18635
    end
18636
 
18637
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18638
    begin
18639
        $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) ;
18640
        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") ;
18641
    end
18642
 
18643
    if ( temp_val1[31:28] !== 4'h0 )
18644
    begin
18645
        $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) ;
18646
        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") ;
18647
    end
18648
 
18649
    // clear error status register
18650
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18651
 
18652
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18653
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18654
    if ( temp_val1 !== pci_image_base )
18655
    begin
18656
        $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) ;
18657
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18658
    end
18659
 
18660
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18661
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18662
    if ( temp_val1 !== 32'hBEAF_DEAD )
18663
    begin
18664
        $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) ;
18665
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18666
    end
18667
 
18668
    // disable current image - write address mask register
18669 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18670 15 mihad
end
18671
endtask // target_completion_expired
18672
 
18673
task config_write ;
18674
    input [11:0] offset ;
18675
    input [31:0] data ;
18676
    input [3:0]  byte_enable ;
18677
    output       ok ;
18678
    `ifdef HOST
18679
    reg   `WRITE_STIM_TYPE   write_data ;
18680
    reg   `WB_TRANSFER_FLAGS write_flags ;
18681
    reg   `WRITE_RETURN_TYPE write_status ;
18682
    `else
18683
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
18684
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
18685
    `endif
18686
    reg in_use ;
18687
    reg [31:0] temp_var ;
18688
begin
18689
    if ( in_use === 1 )
18690
    begin
18691
        $display("config_read task re-entered! Time %t ", $time) ;
18692
        ok = 0 ;
18693
        #20 $stop ;
18694
    end
18695
    else
18696
    begin
18697
        ok = 1 ;
18698
        in_use = 1 ;
18699
    end
18700
    `ifdef HOST
18701
    write_flags                    = 0 ;
18702
    write_flags`INIT_WAITS         = tb_init_waits ;
18703
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18704
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18705
 
18706
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18707
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18708
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
18709
    write_data`WRITE_SEL                         = byte_enable ;
18710
    write_data`WRITE_TAG_STIM                    = 0 ;
18711
    write_data`WRITE_DATA                        = data ;
18712
 
18713
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18714
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18715
    begin
18716
        $display("Write to configuration space failed! Time %t ", $time) ;
18717
        ok = 0 ;
18718
    end
18719
 
18720
    @(posedge wb_clock) ;
18721
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
18722
    // here we just wait for two guest cycles for conf space bits to synchronize
18723
    repeat( 2 )
18724
        @(posedge pci_clock) ;
18725
 
18726
    `else // GUEST
18727
    byte_enables_l = ~byte_enable ;
18728
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18729
 
18730
    fork
18731
    begin
18732
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
18733
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
18734
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
18735
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18736
              8'h0_0, `Test_One_Zero_Target_WS,
18737
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
18738
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
18739
    do_pause( 1 ) ;
18740
    end
18741
    begin
18742
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
18743
        @(posedge pci_clock) ;
18744
    end
18745
    join
18746
 
18747
     repeat( 2 )
18748
         @(posedge wb_clock) ;
18749
 
18750
    `endif
18751
    in_use = 0 ;
18752
end
18753
endtask // config_write
18754
 
18755
task config_read ;
18756
    input [11:0] offset ;
18757
    input [3:0]  byte_enable ;
18758
    output [31:0] data ;
18759
 
18760
    reg `READ_STIM_TYPE    read_data ;
18761
    reg `WB_TRANSFER_FLAGS read_flags ;
18762
    reg `READ_RETURN_TYPE  read_status ;
18763
 
18764
    reg [31:0] pci_address ;
18765
    reg [3:0] byte_enables_l ;
18766
 
18767
    reg master_check_data_prev ;
18768
    reg in_use ;
18769
    reg [31:0] temp_var ;
18770
begin:main
18771
    if ( in_use === 1 )
18772
    begin
18773
        $display("config_read task re-entered! Time %t ", $time) ;
18774
        data = 32'hxxxx_xxxx ;
18775
        disable main ;
18776
    end
18777
 
18778
    in_use = 1 ;
18779
 
18780
`ifdef HOST
18781 26 mihad
    repeat(4)
18782
        @(posedge pci_clock) ;
18783
    repeat(4)
18784
        @(posedge wb_clock) ;
18785 15 mihad
    read_flags                    = 0 ;
18786
    read_flags`INIT_WAITS         = tb_init_waits ;
18787
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18788
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18789
 
18790
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18791
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18792
 
18793
    read_data`READ_ADDRESS  = temp_var + offset ;
18794
    read_data`READ_SEL      = byte_enable ;
18795
    read_data`READ_TAG_STIM = 0 ;
18796
 
18797
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
18798
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18799
    begin
18800
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
18801
        #20 $stop ;
18802
    end
18803
    data = read_status`READ_DATA ;
18804
`else
18805
  `ifdef GUEST
18806 26 mihad
    repeat(4)
18807
        @(posedge wb_clock) ;
18808
    repeat(4)
18809
        @(posedge pci_clock) ;
18810 15 mihad
    master_check_data_prev = master2_check_received_data ;
18811
    master2_check_received_data = 0 ;
18812
 
18813
    byte_enables_l = ~byte_enable ;
18814
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18815
 
18816
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
18817
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
18818
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
18819
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18820
             8'h4_0, `Test_One_Zero_Target_WS,
18821
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
18822
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
18823
    do_pause( 1 ) ;
18824
 
18825
    @(master2_received_data_valid) ;
18826
    data = master2_received_data ;
18827
 
18828
    master2_check_received_data = master_check_data_prev ;
18829
  `endif
18830
`endif
18831
    in_use = 0 ;
18832
end
18833
endtask //config_read
18834
 
18835
task test_fail ;
18836
    input [7999:0] failure_reason ;
18837
    reg   [8007:0] display_failure ;
18838
    reg   [799:0] display_test ;
18839
begin
18840
    tests_failed = tests_failed + 1 ;
18841
 
18842
    display_failure = {failure_reason, "!"} ;
18843
    while ( display_failure[7999:7992] == 0 )
18844
        display_failure = display_failure << 8 ;
18845
 
18846
    display_test = test_name ;
18847
    while ( display_test[799:792] == 0 )
18848
       display_test = display_test << 8 ;
18849
 
18850
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18851
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
18852
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
18853
    $fdisplay( tb_log_file, " *FAILED* because") ;
18854
    $fdisplay( tb_log_file, " %s", display_failure ) ;
18855
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18856
    $fdisplay( tb_log_file, " " ) ;
18857
 
18858
    `ifdef STOP_ON_FAILURE
18859
    #20 $stop ;
18860
    `endif
18861
end
18862
endtask // test_fail
18863
 
18864
task test_ok ;
18865
    reg [799:0] display_test ;
18866
begin
18867
   tests_successfull = tests_successfull + 1 ;
18868
 
18869
   display_test = test_name ;
18870
   while ( display_test[799:792] == 0 )
18871
       display_test = display_test << 8 ;
18872
 
18873
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18874
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
18875
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
18876
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
18877
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18878
   $fdisplay( tb_log_file, " " ) ;
18879
end
18880
endtask // test_ok
18881
 
18882
task test_summary;
18883
begin
18884
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
18885
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
18886
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
18887
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
18888
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
18889
    $fclose(tb_log_file) ;
18890
end
18891
endtask
18892
 
18893
endmodule

powered by: WebSVN 2.1.0

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