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

Subversion Repositories pci

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

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

Line No. Rev Author Line
1 15 mihad
`include "pci_constants.v"
2
`include "bus_commands.v"
3
`include "pci_testbench_defines.v"
4
`include "timescale.v"
5
 
6
module SYSTEM ;
7
 
8
`include "pci_blue_constants.vh"
9
`include "pci_blue_options.vh"
10
 
11
integer tests_successfull ;
12
integer tests_failed ;
13
integer tb_log_file ;
14
reg [799:0] test_name ;
15
 
16
reg pci_clock ;
17
reg wb_clock ;
18
reg reset ;
19
 
20
wire [4:0] arb_grant_out ;
21
 
22
wire [31:0] AD ;
23
wire [3:0]  CBE ;
24
pullup(INTA) ;
25
pullup(MAS0_REQ) ;
26
pullup(MAS1_REQ) ;
27
pullup(MAS2_REQ) ;
28
pullup(MAS3_REQ) ;
29
 
30
wire MAS0_GNT = ~arb_grant_out[0];
31
wire MAS1_GNT = ~arb_grant_out[1] ;
32
wire MAS2_GNT = ~arb_grant_out[2] ;
33
wire MAS3_GNT = ~arb_grant_out[3] ;
34
 
35
pullup(FRAME) ;
36
pullup(IRDY) ;
37
wire        TAR0_IDSEL = AD[11] ;
38
`define     TAR0_IDSEL_INDEX    11
39
`define     TAR0_IDSEL_ADDR     32'h0000_0800
40
pullup(DEVSEL) ;
41
pullup(TRDY) ;
42
pullup(STOP) ;
43
wire   PAR ;
44
pullup(PERR) ;
45
pullup(SERR) ;
46
wire [3:0] MAS1_IDSEL ;
47
 
48
pullup lockpu ( LOCK ) ;
49
 
50
wire        RST_O ;
51
wire        INT_O ;
52
reg         INT_I ;
53
wire [31:0] ADR_I ;
54
wire [31:0] SDAT_I ;
55
wire [31:0] SDAT_O ;
56
wire [3:0]  SEL_I ;
57
wire        CYC_I ;
58
wire        STB_I ;
59
wire        WE_I ;
60
wire        CAB_I ;
61
wire        ACK_O ;
62
wire        RTY_O ;
63
wire        ERR_O ;
64
 
65
wire [31:0] ADR_O ;
66
wire [31:0] MDAT_I ;
67
wire [31:0] MDAT_O ;
68
wire [3:0]  SEL_O ;
69
wire        CYC_O ;
70
wire        STB_O ;
71
wire        WE_O ;
72
wire        CAB_O ;
73
wire        ACK_I ;
74
wire        RTY_I ;
75
wire        ERR_I ;
76
wire        TAR1_IDSEL = AD[12] ;
77
`define     TAR1_IDSEL_INDEX    12
78
`define     TAR1_IDSEL_ADDR     32'h0000_1000
79
wire        TAR2_IDSEL = AD[13] ;
80
`define     TAR2_IDSEL_INDEX    13
81
`define     TAR2_IDSEL_ADDR     32'h0000_2000
82
 
83
wire        reset_wb ; // reset to Wb devices
84
 
85
`ifdef GUEST
86
    wire    RST = ~reset ;
87
    assign  reset_wb = RST_O ;
88
`else
89
    pullup(RST) ;
90
    assign  reset_wb = reset ;
91
`endif
92
 
93
`define PCI_BRIDGE_INSTANCE bridge32_top
94
 
95
TOP `PCI_BRIDGE_INSTANCE
96
(
97
    .CLK    ( pci_clock),
98
    .AD     ( AD ),
99
    .CBE    ( CBE ),
100
    .RST    ( RST ),
101
    .INTA   ( INTA ),
102
    .REQ    ( MAS0_REQ ),
103
    .GNT    ( MAS0_GNT ),
104
    .FRAME  ( FRAME ),
105
    .IRDY   ( IRDY ),
106
    .IDSEL  ( TAR0_IDSEL),
107
    .DEVSEL ( DEVSEL ),
108
    .TRDY   ( TRDY ),
109
    .STOP   ( STOP ),
110
    .PAR    ( PAR ),
111
    .PERR   ( PERR ),
112
    .SERR   ( SERR ),
113
 
114
    .CLK_I  ( wb_clock ),
115
    .RST_I  ( reset ),
116
    .RST_O  ( RST_O ),
117
    .INT_I  ( INT_I ),
118
    .INT_O  ( INT_O ),
119
 
120
    // WISHBONE slave interface
121
    .ADR_I  ( ADR_I ),
122
    .SDAT_I ( SDAT_I ),
123
    .SDAT_O ( SDAT_O ),
124
    .SEL_I  ( SEL_I ),
125
    .CYC_I  ( CYC_I ),
126
    .STB_I  ( STB_I ),
127
    .WE_I   ( WE_I ),
128
    .CAB_I  ( CAB_I),
129
    .ACK_O  ( ACK_O ),
130
    .RTY_O  ( RTY_O ),
131
    .ERR_O  ( ERR_O ),
132
 
133
    // WISHBONE master interface
134
    .ADR_O  ( ADR_O ),
135
    .MDAT_I ( MDAT_I ),
136
    .MDAT_O ( MDAT_O ),
137
    .SEL_O  ( SEL_O ),
138
    .CYC_O  ( CYC_O ),
139
    .STB_O  ( STB_O ),
140
    .WE_O   ( WE_O ),
141
    .CAB_O  ( CAB_O ),
142
    .ACK_I  ( ACK_I ),
143
    .RTY_I  ( RTY_I ),
144
    .ERR_I  ( ERR_I )
145
) ;
146
 
147
WB_MASTER_BEHAVIORAL wishbone_master
148
(
149
    .CLK_I(wb_clock),
150
    .RST_I(reset_wb),
151
    .TAG_I(4'b0000),
152
    .TAG_O(),
153
    .ACK_I(ACK_O),
154
    .ADR_O(ADR_I),
155
    .CYC_O(CYC_I),
156
    .DAT_I(SDAT_O),
157
    .DAT_O(SDAT_I),
158
    .ERR_I(ERR_O),
159
    .RTY_I(RTY_O),
160
    .SEL_O(SEL_I),
161
    .STB_O(STB_I),
162
    .WE_O (WE_I),
163
    .CAB_O(CAB_I)
164
);
165
 
166
WB_SLAVE_BEHAVIORAL wishbone_slave
167
(
168
    .CLK_I              (wb_clock),
169
    .RST_I              (reset_wb),
170
    .ACK_O              (ACK_I),
171
    .ADR_I              (ADR_O),
172
    .CYC_I              (CYC_O),
173
    .DAT_O              (MDAT_I),
174
    .DAT_I              (MDAT_O),
175
    .ERR_O              (ERR_I),
176
    .RTY_O              (RTY_I),
177
    .SEL_I              (SEL_O),
178
    .STB_I              (STB_O),
179
    .WE_I               (WE_O),
180
    .CAB_I              (CAB_O)
181
);
182
 
183
integer wbu_mon_log_file_desc ;
184
integer pciu_mon_log_file_desc ;
185
WB_BUS_MON wbu_wb_mon(
186
                    .CLK_I(wb_clock),
187
                    .RST_I(reset_wb),
188
                    .ACK_I(ACK_O),
189
                    .ADDR_O(ADR_I),
190
                    .CYC_O(CYC_I),
191
                    .DAT_I(SDAT_O),
192
                    .DAT_O(SDAT_I),
193
                    .ERR_I(ERR_O),
194
                    .RTY_I(RTY_O),
195
                    .SEL_O(SEL_I),
196
                    .STB_O(STB_I),
197
                    .WE_O (WE_I),
198
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
199
                    .TAG_O(),
200
                    .CAB_O(CAB_I),
201
                    .log_file_desc ( wbu_mon_log_file_desc )
202
                  ) ;
203
 
204
WB_BUS_MON pciu_wb_mon(
205
                    .CLK_I(wb_clock),
206
                    .RST_I(reset_wb),
207
                    .ACK_I(ACK_I),
208
                    .ADDR_O(ADR_O),
209
                    .CYC_O(CYC_O),
210
                    .DAT_I(MDAT_I),
211
                    .DAT_O(MDAT_O),
212
                    .ERR_I(ERR_I),
213
                    .RTY_I(RTY_I),
214
                    .SEL_O(SEL_O),
215
                    .STB_O(STB_O),
216
                    .WE_O (WE_O),
217
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
218
                    .TAG_O(),
219
                    .CAB_O(CAB_O),
220
                    .log_file_desc( pciu_mon_log_file_desc )
221
                  ) ;
222
 
223
reg irq_respond ;
224
reg [31:0] irq_vector ;
225
PCI_BEHAVIORAL_IACK_TARGET interrupt_control
226
(
227
    .CLK              ( pci_clock),
228
    .AD               ( AD ),
229
    .CBE              ( CBE ),
230
    .RST              ( RST ),
231
    .FRAME            ( FRAME ),
232
    .IRDY             ( IRDY ),
233
    .DEVSEL           ( DEVSEL ),
234
    .TRDY             ( TRDY ),
235
    .STOP             ( STOP ),
236
    .PAR              ( PAR ),
237
    .respond          ( irq_respond ),
238
    .interrupt_vector ( irq_vector)
239
);
240
 
241
// some aditional signals are needed here because of the arbiter
242
reg [3:0] pci_ext_req_prev ;
243
always@(posedge pci_clock)
244
begin
245
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
246
end
247
reg pci_frame_prev ;
248
always@(posedge pci_clock)
249
begin
250
    pci_frame_prev <= FRAME ;
251
end
252
reg pci_irdy_prev ;
253
always@(posedge pci_clock)
254
begin
255
    pci_irdy_prev <= IRDY ;
256
end
257
 
258
pci_blue_arbiter pci_arbiter
259
(
260
  .pci_int_req_direct(1'b0),
261
  .pci_ext_req_prev(pci_ext_req_prev),
262
  .pci_int_gnt_direct_out(arb_grant_out[4]),
263
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
264
  .pci_frame_prev(~pci_frame_prev),
265
  .pci_irdy_prev(~pci_irdy_prev),
266
  .pci_irdy_now(~IRDY),
267
  .arbitration_enable(1'b1),
268
  .pci_clk(pci_clock),
269
  .pci_reset_comb(~RST)
270
);
271
 
272
reg [31:0] target_message ;
273
 
274
// define output enable signals for monitor inputs
275
// real output enable signals
276
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
277
`ifdef ACTIVE_LOW_OE
278
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
279
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
280
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
281
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
282
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
283
                        !devsel_t_s_oe,
284
                        !ad_oe,
285
                        !cbe_oe,
286
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
287
                        ;
288
`else
289
`ifdef ACTIVE_HIGH_OE
290
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
291
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
292
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
293
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
294
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
295
                        devsel_t_s_oe,
296
                        ad_oe,
297
                        cbe_oe,
298
                        `PCI_BRIDGE_INSTANCE.PERR_en}
299
                        ;
300
`endif
301
`endif
302
/*wire [5:0] oe_sigs_0 = {1'b0,
303
                        1'b0,
304
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
305
                        pci_target32.ad_enable,
306
                        1'b0,
307
                        pci_target32.err_enable | pci_target32.r_err_enable
308
                       } ;
309
*/
310
 
311
wire [5:0] oe_sigs_2 ;
312
wire [5:0] oe_sigs_1 ;
313
 
314
// signals which are used by test modules to know what to do
315
triand  test_accepted_l_int, error_event_int;
316
pullup  (test_accepted_l_int), (error_event_int);
317
 
318
wire    pci_reset_comb  = ~RST;
319
wire    pci_ext_clk     = pci_clock;
320
 
321
integer pci_mon_log_file_desc ;
322
pci_bus_monitor monitor32
323
(
324
    .pci_ext_ad                 (AD),
325
    .pci_ext_cbe_l              (CBE),
326
    .pci_ext_par                (PAR),
327
    .pci_ext_frame_l            (FRAME),
328
    .pci_ext_irdy_l             (IRDY),
329
    .pci_ext_devsel_l           (DEVSEL),
330
    .pci_ext_trdy_l             (TRDY),
331
    .pci_ext_stop_l             (STOP),
332
    .pci_ext_perr_l             (PERR),
333
    .pci_ext_serr_l             (SERR),
334
    .pci_real_req_l             (MAS0_REQ),
335
    .pci_real_gnt_l             (MAS0_GNT),
336
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
337
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
338
    .test_error_event           (error_event_int),
339
    .test_observe_r_oe_sigs     (r_oe_sigs),
340
    .test_observe_0_oe_sigs     (6'h00),
341
    .test_observe_1_oe_sigs     (oe_sigs_1),
342
    .test_observe_2_oe_sigs     (oe_sigs_2),
343
    .test_observe_3_oe_sigs     (6'h00),
344
    .pci_ext_reset_l            (RST),
345
    .pci_ext_clk                (pci_clock),
346
    .log_file_desc              (pci_mon_log_file_desc)
347
) ;
348
 
349
reg [2:0]  test_master_number ;
350
reg [31:0] test_address ;
351
reg [3:0]  test_command ;
352
reg [31:0] test_data ;
353
reg [3:0]  test_byte_enables_l ;
354
reg [9:0]  test_size ;
355
reg        test_make_addr_par_error ;
356
reg        test_make_data_par_error ;
357
reg [3:0]  test_master_initial_wait_states ;
358
reg [3:0]  test_master_subsequent_wait_states ;
359
reg [3:0]  test_target_initial_wait_states ;
360
reg [3:0]  test_target_subsequent_wait_states ;
361
reg [1:0]  test_target_devsel_speed ;
362
reg        test_fast_back_to_back ;
363
reg [2:0]  test_target_termination ;
364
reg        test_expect_master_abort ;
365
reg        test_start ;
366
reg [25:0] test_target_response ;
367
 
368
wire [31:0] master2_received_data ;
369
wire        master2_received_data_valid ;
370
reg         master2_check_received_data ;
371
pci_behaviorial_device pci_behaviorial_device2
372
(
373
    .pci_ext_ad(AD),
374
    .pci_ext_cbe_l(CBE),
375
    .pci_ext_par(PAR),
376
    .pci_ext_frame_l(FRAME),
377
    .pci_ext_irdy_l(IRDY),
378
    .pci_ext_devsel_l(DEVSEL),
379
    .pci_ext_trdy_l(TRDY),
380
    .pci_ext_stop_l(STOP),
381
    .pci_ext_perr_l(PERR),
382
    .pci_ext_serr_l(SERR),
383
    .pci_ext_idsel(TAR2_IDSEL),
384
    .pci_ext_inta_l(INTA),
385
    .pci_ext_req_l(MAS2_REQ),
386
    .pci_ext_gnt_l(MAS2_GNT),
387
    .pci_ext_reset_l(RST),
388
    .pci_ext_clk(pci_clock),
389
 
390
// Signals used by the test bench instead of using "." notation
391
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
392
    .test_master_number                 (test_master_number[2:0]),
393
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
394
    .test_command                       (test_command[3:0]),
395
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
396
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
397
    .test_size                          (test_size),
398
    .test_make_addr_par_error           (test_make_addr_par_error),
399
    .test_make_data_par_error           (test_make_data_par_error),
400
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
401
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
402
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
403
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
404
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
405
    .test_fast_back_to_back             (test_fast_back_to_back),
406
    .test_target_termination            (test_target_termination[2:0]),
407
    .test_expect_master_abort           (test_expect_master_abort),
408
    .test_start                         (test_start),
409
    .test_accepted_l                    (test_accepted_l_int),
410
    .test_error_event                   (error_event_int),
411
    .test_device_id                     (`Test_Master_2),
412
    .test_target_response               (test_target_response),
413
 
414
    .master_received_data               (master2_received_data),
415
    .master_received_data_valid         (master2_received_data_valid),
416
    .master_check_received_data         (master2_check_received_data)
417
);
418
 
419
wire [31:0] master1_received_data ;
420
wire        master1_received_data_valid ;
421
reg         master1_check_received_data ;
422
pci_behaviorial_device pci_behaviorial_device1
423
(
424
    .pci_ext_ad(AD),
425
    .pci_ext_cbe_l(CBE),
426
    .pci_ext_par(PAR),
427
    .pci_ext_frame_l(FRAME),
428
    .pci_ext_irdy_l(IRDY),
429
    .pci_ext_devsel_l(DEVSEL),
430
    .pci_ext_trdy_l(TRDY),
431
    .pci_ext_stop_l(STOP),
432
    .pci_ext_perr_l(PERR),
433
    .pci_ext_serr_l(SERR),
434
    .pci_ext_idsel(TAR1_IDSEL),
435
    .pci_ext_inta_l(INTA),
436
    .pci_ext_req_l(MAS1_REQ),
437
    .pci_ext_gnt_l(MAS1_GNT),
438
    .pci_ext_reset_l(RST),
439
    .pci_ext_clk(pci_clock),
440
 
441
// Signals used by the test bench instead of using "." notation
442
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
443
    .test_master_number                 (test_master_number[2:0]),
444
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
445
    .test_command                       (test_command[3:0]),
446
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
447
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
448
    .test_size                          (test_size),
449
    .test_make_addr_par_error           (test_make_addr_par_error),
450
    .test_make_data_par_error           (test_make_data_par_error),
451
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
452
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
453
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
454
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
455
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
456
    .test_fast_back_to_back             (test_fast_back_to_back),
457
    .test_target_termination            (test_target_termination[2:0]),
458
    .test_expect_master_abort           (test_expect_master_abort),
459
    .test_start                         (test_start),
460
    .test_accepted_l                    (test_accepted_l_int),
461
    .test_error_event                   (error_event_int),
462
    .test_device_id                     (`Test_Master_1),
463
    .test_target_response               (test_target_response),
464
 
465
    .master_received_data               (master1_received_data),
466
    .master_received_data_valid         (master1_received_data_valid),
467
    .master_check_received_data         (master1_check_received_data)
468
);
469
 
470
pci_unsupported_commands_master ipci_unsupported_commands_master
471
(
472
    .CLK    ( pci_clock),
473
    .AD     ( AD ),
474
    .CBE    ( CBE ),
475
    .RST    ( RST ),
476
    .REQ    ( MAS3_REQ ),
477
    .GNT    ( MAS3_GNT ),
478
    .FRAME  ( FRAME ),
479
    .IRDY   ( IRDY ),
480
    .DEVSEL ( DEVSEL ),
481
    .TRDY   ( TRDY ),
482
    .STOP   ( STOP ),
483
    .PAR    ( PAR )
484
) ;
485
 
486
// pci clock generator
487
always
488
`ifdef PCI33
489
    #15 pci_clock = ~pci_clock ;
490
`else
491
`ifdef PCI66
492
    #7.5 pci_clock = ~pci_clock ;
493
`endif
494
`endif
495
 
496
// WISHBONE clock generation
497
always
498
    #(((1/`WB_FREQ)/2)) wb_clock = ~wb_clock ;
499
 
500
// Make test name visible when the Master starts working on it
501
reg     [79:0] present_test_name;
502
reg     [79:0] next_test_name;
503
wire    test_accepted = ~test_accepted_l_int;
504
always @(posedge test_accepted)
505
begin
506
    present_test_name <= next_test_name;
507
end
508
 
509
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
510
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
511
 
512
// basic configuration parameters for both behavioral devices
513
parameter [2:0] Master_ID_A                           = `Test_Master_1;
514
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
515
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
516
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
517
 
518
parameter [2:0] Master_ID_B                           = `Test_Master_2;
519
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
520
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
521
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
522
 
523
// basic configuration parameters for REAL device
524
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
525
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
526
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
527
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
528
 
529
// reg  [2:0]   ack_err_rty_termination ;
530
// reg          wait_cycles ;
531
// reg  [7:0]   num_of_retries ;
532
 
533
//reg [19:0] pci_config_base ;
534
reg [7:0] system_burst_size ;
535
reg [7:0] bridge_latency ;
536
integer   target_mem_image ;
537
integer   target_io_image ;
538
 
539
initial
540
begin
541
    next_test_name[79:0] <= "Nowhere___";
542
    reset = 1'b1 ;
543
    pci_clock = 1'b0 ;
544
    wb_clock  = 1'b1 ;
545
    target_message = 32'h0000_0000 ;
546
//  num_of_retries = 8'h01 ;
547
//  ack_err_rty_termination = 3'b100 ;
548
//  wait_cycles = 1'b0 ;
549
 
550
    // system paameters
551
    system_burst_size = 16 ;
552
    bridge_latency    = 8 ;
553
 
554
    // set initial values for controling the behavioral PCI master
555
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
556
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
557
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
558
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
559
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
560
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
561
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
562
 
563
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
564
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
565
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
566
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
567
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
568
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
569
 
570
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
571
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
572
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
573
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
574
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
575
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
576
 
577
    test_master_number = `Test_Master_2 ;
578
    test_address = 32'h0000_0000 ;
579
    test_command = `BC_RESERVED0 ;
580
    test_data = 32'h0000_0000 ;
581
    test_byte_enables_l   = 4'hF ;
582
    test_size = 0 ;
583
    test_make_addr_par_error = 0 ;
584
    test_make_data_par_error = 0;
585
    test_master_initial_wait_states = 0 ;
586
    test_master_subsequent_wait_states = 0 ;
587
    test_target_initial_wait_states = 0 ;
588
    test_target_subsequent_wait_states = 0;
589
    test_target_devsel_speed = `Test_Devsel_Fast ;
590
    test_fast_back_to_back = 0 ;
591
    test_target_termination = `Test_Target_Normal_Completion ;
592
    test_expect_master_abort = 0 ;
593
    test_start = 0 ;
594
    test_target_response = 0 ;
595
 
596
    master1_check_received_data = 0 ;
597
    master2_check_received_data = 0 ;
598
 
599
    irq_respond = 1 ;
600
    irq_vector  = 32'hAAAA_AAAA ;
601
 
602
    // fill memory and IO data with random values
603
    fill_memory ;
604
 
605
    INT_I = 0 ;
606
 
607
    // extract from constants which target image can be used as IO and which as memory
608
    `ifdef HOST
609
        target_mem_image = 1 ;
610
        target_io_image  = 1 ;
611
    `else
612
        target_mem_image = -1 ;
613
        target_io_image     = -1 ;
614
        if ( `PCI_BA1_MEM_IO === 0 )
615
            target_mem_image = 1 ;
616
        else
617
            target_io_image = 1 ;
618
 
619
        if ( target_mem_image === -1 )
620
        begin
621
            `ifdef PCI_IMAGE2
622
                if ( `PCI_BA2_MEM_IO === 0 )
623
                    target_mem_image = 2 ;
624
                else if ( target_io_image === -1 )
625
                    target_io_image = 2 ;
626
            `endif
627
        end
628
 
629
        if ( target_mem_image === -1 )
630
        begin
631
            `ifdef PCI_IMAGE3
632
                if ( `PCI_BA3_MEM_IO === 0 )
633
                    target_mem_image = 3 ;
634
                else if ( target_io_image === -1 )
635
                    target_io_image = 3 ;
636
            `endif
637
        end
638
 
639
        if ( target_mem_image === -1 )
640
        begin
641
            `ifdef PCI_IMAGE4
642
                if ( `PCI_BA4_MEM_IO === 0 )
643
                    target_mem_image = 4 ;
644
                else if ( target_io_image === -1 )
645
                    target_io_image = 4 ;
646
            `endif
647
        end
648
 
649
        if ( target_mem_image === -1 )
650
        begin
651
            `ifdef PCI_IMAGE5
652
                if ( `PCI_BA5_MEM_IO === 0 )
653
                    target_mem_image = 5 ;
654
                else if ( target_io_image === -1 )
655
                    target_io_image = 5 ;
656
            `endif
657
        end
658
    `endif
659
 
660
    tests_successfull = 0 ;
661
    tests_failed = 0 ;
662
 
663
    tb_log_file = $fopen("../log/pci_tb.log") ;
664
 
665
    if ( tb_log_file < 2 )
666
    begin
667
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
668
        $finish ;
669
    end
670
 
671
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
672
    $fdisplay( tb_log_file,"" ) ;
673
 
674
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
675
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
676
 
677
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
678
    begin
679
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
680
        $finish ;
681
    end
682
 
683
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
684
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
685
 
686
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
687
    if ( pci_mon_log_file_desc < 2 )
688
    begin
689
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
690
        $finish ;
691
    end
692
 
693
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
694
 
695
    run_tests ;
696
end
697
 
698
task fill_memory ;
699
    integer temp_index ;
700
begin
701
    // fill write memories with random data
702
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
703
    begin
704
        wmem_data[temp_index[9:0]] = $random ;
705
        wio_data[temp_index[9:0]]  = $random ;
706
    end
707
    // fill WB slave behavioral MEMORY
708
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
709
    begin
710
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
711
        # 1;
712
    end
713
end
714
endtask // fill_memory
715
 
716
reg [2:0] tb_init_waits ;
717
reg [2:0] tb_subseq_waits ;
718
reg [2:0] tb_target_decode_speed ;
719
 
720
task run_tests ;
721
begin
722
    // first - reset logic
723
    do_reset ;
724
    next_test_name[79:0] <= "Initing...";
725
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
726
 
727
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
728
    begin
729
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
730
        begin
731
 
732
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
733
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
734
 
735
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
736
            begin
737
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
738
 
739
                `ifdef HOST
740
                    configure_bridge_target ;
741
                    find_pci_devices ;
742
                `endif
743
 
744
                @(posedge pci_clock) ;
745
                configure_target(1) ;
746
                @(posedge pci_clock) ;
747
                configure_target(2) ;
748
 
749
                `ifdef GUEST
750
                    configure_bridge_target ;
751
                `endif
752
 
753
               next_test_name[79:0] <= "WB_SLAVE..";
754
 
755
                $display("Testing WISHBONE slave images' features!") ;
756
                test_wb_image(1) ;
757
 
758
                `ifdef WB_IMAGE2
759
                    test_wb_image(2) ;
760
                `else
761
                    $display(" WB IMAGE 2 not implemented! ") ;
762
                `endif
763
 
764
                `ifdef WB_IMAGE3
765
                    test_wb_image(3) ;
766
                `else
767
                    $display(" WB IMAGE 3 not implemented! ") ;
768
                `endif
769
 
770
                `ifdef WB_IMAGE4
771
                    test_wb_image(4) ;
772
                `else
773
                    $display(" WB IMAGE 4 not implemented! ") ;
774
                `endif
775
 
776
                `ifdef WB_IMAGE5
777
                    test_wb_image(5) ;
778
                `else
779
                    $display(" WB IMAGE 5 not implemented! ") ;
780
                `endif
781
 
782
                wb_slave_errors ;
783
                wb_to_pci_error_handling ;
784
 
785
                parity_checking ;
786
 
787
                wb_to_pci_transactions ;
788
 
789
                `ifdef HOST
790
                iack_cycle ;
791
                `endif
792
 
793
            end
794
            $display(" ") ;
795
            $display("WB slave images' tests finished!") ;
796
 
797
            $display("########################################################################") ;
798
            $display("########################################################################") ;
799
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
800
            $display("########################################################################") ;
801
            $display("########################################################################") ;
802
 
803
            $display("Testing PCI target images' features!") ;
804
            configure_bridge_target_base_addresses ;
805
 
806
            `ifdef HOST
807
             `ifdef NO_CNF_IMAGE
808
              `ifdef PCI_IMAGE0
809
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
810
            test_pci_image(0) ;
811
              `else
812
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
813
              `endif
814
             `else
815
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
816
             `endif
817
            `endif
818
 
819
            $display("PCI image 1 is ALWAYS implemented!") ;
820
            test_pci_image(1) ;
821
 
822
            `ifdef PCI_IMAGE2
823
            $display("PCI image 2 is implemented!") ;
824
            test_pci_image(2) ;
825
            `else
826
            $display("PCI image 2 is NOT implemented!") ;
827
            `endif
828
 
829
            `ifdef PCI_IMAGE3
830
            $display("PCI image 3 is implemented!") ;
831
            test_pci_image(3) ;
832
            `else
833
            $display("PCI image 3 is NOT implemented!") ;
834
            `endif
835
 
836
            `ifdef PCI_IMAGE4
837
            $display("PCI image 4 is implemented!") ;
838
            test_pci_image(4) ;
839
            `else
840
            $display("PCI image 4 is NOT implemented!") ;
841
            `endif
842
 
843
            `ifdef PCI_IMAGE5
844
            $display("PCI image 5 is implemented!") ;
845
            test_pci_image(5) ;
846
            `else
847
            $display("PCI image 5 is NOT implemented!") ;
848
            `endif
849
 
850
            test_wb_error_rd ;
851
 
852
            target_fast_back_to_back ;
853
            target_disconnects ;
854
 
855
            if ( target_io_image !== -1 )
856
                test_target_abort( target_io_image ) ;
857
            $display(" ") ;
858
            $display("PCI target images' tests finished!") ;
859
 
860
            transaction_ordering ;
861
            $display(" ") ;
862
            $display("PCI transaction ordering tests finished!") ;
863
        end
864
    end
865
 
866
    test_summary ;
867
 
868
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
869
    $stop ;
870
end
871
endtask // run_tests
872
 
873
task do_reset;
874
begin
875
    next_test_name[79:0] <= "Reset.....";
876
 
877
    reset = 1'b1 ;
878
    #100 ;
879
    `ifdef HOST
880
        @(posedge wb_clock) ;
881
    `else
882
    `ifdef GUEST
883
        @(posedge pci_clock) ;
884
    `endif
885
    `endif
886
 
887
    reset <= 1'b0 ;
888
 
889
end
890
endtask
891
 
892
/*############################################################################
893
WB SLAVE UNIT tasks
894
===================
895
############################################################################*/
896
 
897
task configure_target ;
898
    input [1:0]  device_num ;
899
    reg   [31:0] base_address1 ;
900
    reg   [31:0] base_address2 ;
901
    reg   [2:0]  Master_ID;
902
    reg   [31:0] Target_Config_Addr;
903
begin
904
    if (device_num === 1)
905
    begin
906
        base_address1       = `BEH_TAR1_MEM_START ;
907
        base_address2       = `BEH_TAR1_IO_START  ;
908
        Master_ID           = `Test_Master_2 ;
909
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
910
    end
911
    else
912
    if (device_num === 2)
913
    begin
914
        base_address1       = `BEH_TAR2_MEM_START ;
915
        base_address2       = `BEH_TAR2_IO_START  ;
916
        Master_ID           = `Test_Master_1 ;
917
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
918
    end
919
 
920
    // write target's base addresses
921
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
922
    // type 0 cycle, byte enables, base address
923
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
924
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
925
 
926
    // enable target's response and master
927
    // enable parity errors, disable system error
928
 
929
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
930
 
931
end
932
endtask //configure_target
933
 
934
task test_wb_image ;
935
    input [2:0]  image_num ;
936
    reg   [11:0] ctrl_offset ;
937
    reg   [11:0] ba_offset ;
938
    reg   [11:0] am_offset ;
939
    reg   [11:0] ta_offset ;
940
    reg   [11:0] err_cs_offset ;
941
    reg `WRITE_STIM_TYPE write_data ;
942
    reg `READ_STIM_TYPE  read_data ;
943
    reg `READ_RETURN_TYPE read_status ;
944
 
945
    reg `WRITE_RETURN_TYPE write_status ;
946
    reg `WB_TRANSFER_FLAGS write_flags ;
947
    reg [31:0] temp_val ;
948
    reg        ok   ;
949
    reg [11:0] pci_ctrl_offset ;
950
    reg [31:0] image_base ;
951
    reg [31:0] target_address ;
952
    reg [31:0] translation_address ;
953
    integer    i ;
954
    integer    j ;
955
begin:main
956
    pci_ctrl_offset = 12'h4 ;
957
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
958
    // image 0 can only be configuration image - start with 1
959
    if (image_num === 1)
960
    begin
961
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
962
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
963
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
964
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
965
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
966
    end
967
    else if (image_num === 2)
968
    begin
969
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
970
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
971
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
972
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
973
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
974
    end
975
    else if (image_num === 3)
976
    begin
977
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
978
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
979
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
980
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
981
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
982
    end
983
    else if (image_num === 4)
984
    begin
985
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
986
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
987
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
988
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
989
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
990
    end
991
    else if (image_num === 5)
992
    begin
993
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
994
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
995
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
996
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
997
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
998
    end
999
    else
1000
    begin
1001
        test_name   = "WB IMAGES' FEATURES TEST" ;
1002
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1003
        disable main ;
1004
    end
1005
 
1006
    target_address  = `BEH_TAR1_MEM_START ;
1007
    image_base      = 0 ;
1008
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1009
 
1010
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1011
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1012
    write_flags                      = 0 ;
1013
    write_flags`INIT_WAITS           = tb_init_waits ;
1014
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1015
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1016
 
1017
    test_name = "WB IMAGE CONFIGURATION" ;
1018
    // enable master & target operation
1019
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1020
    if ( ok !== 1 )
1021
    begin
1022
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1023
        test_fail("write to PCI Device Control register didn't succeede");
1024
        disable main ;
1025
    end
1026
 
1027
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1028
    if ( ok !== 1 )
1029
    begin
1030
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1031
        test_fail("write to WB Error Control and Status register didn't succeede");
1032
        disable main ;
1033
    end
1034
 
1035
    // prepare image control register
1036
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1037
    if ( ok !== 1 )
1038
    begin
1039
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1040
        test_fail("write to WB Image Control register didn't succeede");
1041
        disable main ;
1042
    end
1043
 
1044
    // prepare base address register
1045
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1046
    if ( ok !== 1 )
1047
    begin
1048
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1049
        test_fail("write to WB Base Address register didn't succeede");
1050
        disable main ;
1051
    end
1052
 
1053
    // write address mask register
1054
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1055
    if ( ok !== 1 )
1056
    begin
1057
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1058
        test_fail("write to WB Address Mask register didn't succeede");
1059
        disable main ;
1060
    end
1061
 
1062
    fork
1063
    begin
1064
        write_data`WRITE_ADDRESS = target_address ;
1065
        write_data`WRITE_DATA    = wmem_data[0] ;
1066
        write_data`WRITE_SEL     = 4'hF ;
1067
 
1068
        // handle retries from now on
1069
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1070
 
1071
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1072
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1073
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1074
        begin
1075
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1076
            test_fail("WB Slave state machine failed to post single memory write");
1077
            disable main ;
1078
        end
1079
 
1080
        // read written data back
1081
        read_data`READ_ADDRESS  = target_address ;
1082
        read_data`READ_SEL      = 4'hF ;
1083
        read_data`READ_TAG_STIM = 0 ;
1084
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1085
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1086
        begin
1087
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1088
            test_fail("PCI bridge didn't process the read as expected");
1089
            disable main ;
1090
        end
1091
 
1092
        if (read_status`READ_DATA !== wmem_data[0])
1093
        begin
1094
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1095
            test_fail("PCI bridge returned unexpected Read Data");
1096
        end
1097
        else
1098
            test_ok ;
1099
    end
1100
    begin
1101
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1102
        if ( ok !== 1 )
1103
        begin
1104
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1105
        end
1106
        else
1107
            test_ok ;
1108
 
1109
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1110
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1111
        if ( ok !== 1 )
1112
        begin
1113
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1114
        end
1115
    end
1116
    join
1117
 
1118
    // if address translation is implemented - try it out
1119
    translation_address = image_base ;
1120
    `ifdef ADDR_TRAN_IMPL
1121
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1122
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1123
    if ( ok !== 1 )
1124
    begin
1125
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1126
        test_fail("write to WB Image Translation Address Register failed") ;
1127
        disable main ;
1128
    end
1129
 
1130
    target_address  = `BEH_TAR2_MEM_START ;
1131
    image_base      = 0 ;
1132
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1133
 
1134
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1135
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1136
 
1137
    write_flags                      = 0 ;
1138
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1139
 
1140
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1141
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1142
    if ( ok !== 1 )
1143
    begin
1144
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1145
        test_fail("write to WB Image Base Address Register failed") ;
1146
        disable main ;
1147
    end
1148
 
1149
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1150
    // enable address translation
1151
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1152
    if ( ok !== 1 )
1153
    begin
1154
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1155
        test_fail("write to WB Image Control Register failed") ;
1156
        disable main ;
1157
    end
1158
 
1159
    `endif
1160
 
1161
    fork
1162
    begin
1163
        write_data`WRITE_ADDRESS = target_address + 4 ;
1164
        write_data`WRITE_DATA    = wmem_data[1] ;
1165
        write_data`WRITE_SEL     = 4'hF ;
1166
 
1167
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1168
 
1169
        `ifdef ADDR_TRAN_IMPL
1170
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1171
        `else
1172
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1173
        `endif
1174
 
1175
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1176
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1177
        begin
1178
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1179
            test_fail("WB Slave state machine failed to post single memory write") ;
1180
            disable main ;
1181
        end
1182
 
1183
        // read written data back
1184
        read_data`READ_ADDRESS  = target_address + 4 ;
1185
        read_data`READ_SEL      = 4'hF ;
1186
        read_data`READ_TAG_STIM = 0 ;
1187
 
1188
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1189
 
1190
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1191
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1192
        begin
1193
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1194
            test_fail("PCI bridge failed to process single delayed memory read") ;
1195
            disable main ;
1196
        end
1197
 
1198
        if (read_status`READ_DATA !== wmem_data[1])
1199
        begin
1200
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1201
            test_fail("PCI bridge returned unexpected Read Data");
1202
        end
1203
        else
1204
            test_ok ;
1205
    end
1206
    begin
1207
        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 ) ;
1208
        if ( ok !== 1 )
1209
        begin
1210
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1211
        end
1212
        else
1213
            test_ok ;
1214
 
1215
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1216
        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 ) ;
1217
        if ( ok !== 1 )
1218
        begin
1219
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1220
        end
1221
    end
1222
    join
1223
 
1224
    // 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
1225
    // prepare write data
1226
    for ( i = 0 ; i < 6 ; i = i + 1 )
1227
    begin
1228
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1229
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1230
        write_data`WRITE_SEL     = 4'hF ;
1231
        wishbone_master.blk_write_data[i] = write_data ;
1232
    end
1233
 
1234
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1235
    write_flags`WB_TRANSFER_CAB    = 1 ;
1236
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1237
 
1238
    fork
1239
    begin
1240
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1241
        wishbone_master.wb_block_write(write_flags, write_status) ;
1242
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1243
        begin
1244
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1245
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1246
            disable main ;
1247
        end
1248
    end
1249
    begin
1250
        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 ) ;
1251
        if ( ok !== 1 )
1252
        begin
1253
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1254
        end
1255
        else
1256
            test_ok ;
1257
    end
1258
    join
1259
 
1260
    // set burst size and latency timer
1261
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1262
 
1263
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1264
    write_flags`WB_TRANSFER_CAB    = 1 ;
1265
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1266
 
1267
    // prepare read data
1268
    for ( i = 0 ; i < 4 ; i = i + 1 )
1269
    begin
1270
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1271
        read_data`READ_SEL     = 4'hF ;
1272
        wishbone_master.blk_read_data_in[i] = read_data ;
1273
    end
1274
 
1275
    fork
1276
    begin
1277
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1278
        wishbone_master.wb_block_read(write_flags, read_status) ;
1279
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1280
        begin
1281
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1282
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1283
            disable main ;
1284
        end
1285
 
1286
        // check data read from target
1287
        for ( i = 0 ; i < 4 ; i = i + 1 )
1288
        begin
1289
            read_status = wishbone_master.blk_read_data_out[i] ;
1290
            if (read_status`READ_DATA !== wmem_data[2 + i])
1291
            begin
1292
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1293
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1294
            end
1295
        end
1296
    end
1297
    begin
1298
        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 ) ;
1299
        if ( ok !== 1 )
1300
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1301
        else
1302
            test_ok ;
1303
 
1304
        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 ) ;
1305
        if ( ok !== 1 )
1306
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1307
        else
1308
            test_ok ;
1309
 
1310
        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 ) ;
1311
        if ( ok !== 1 )
1312
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1313
        else
1314
            test_ok ;
1315
 
1316
        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 ) ;
1317
        if ( ok !== 1 )
1318
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1319
        else
1320
            test_ok ;
1321
 
1322
    end
1323
    join
1324
 
1325
    // now repeat this same burst read with various image features enabled or disabled
1326
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1327
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1328
    if (ok !== 1)
1329
    begin
1330
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1331
        test_fail("write to WB Image control register failed") ;
1332
        disable main ;
1333
    end
1334
 
1335
    fork
1336
    begin
1337
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1338
        wishbone_master.wb_block_read(write_flags, read_status) ;
1339
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1340
        begin
1341
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1342
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1343
            disable main ;
1344
        end
1345
 
1346
        // check data read from target
1347
        for ( i = 0 ; i < 4 ; i = i + 1 )
1348
        begin
1349
            read_status = wishbone_master.blk_read_data_out[i] ;
1350
            if (read_status`READ_DATA !== wmem_data[2 + i])
1351
            begin
1352
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1353
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1354
            end
1355
            else
1356
                test_ok ;
1357
        end
1358
    end
1359
    begin
1360
        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 ) ;
1361
        if ( ok !== 1 )
1362
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1363
    end
1364
    join
1365
 
1366
    read_data`READ_ADDRESS  = target_address ;
1367
    read_data`READ_SEL      = 4'hF ;
1368
    read_data`READ_TAG_STIM = 0 ;
1369
 
1370
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1371
    fork
1372
    begin
1373
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1374
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1375
        begin
1376
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1377
            test_fail("delayed single memory read wasn't processed as expected") ;
1378
            disable main ;
1379
        end
1380
 
1381
        if (read_status`READ_DATA !== wmem_data[0])
1382
        begin
1383
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1384
            test_fail("delayed single memory read data value returned was not as expected") ;
1385
        end
1386
        else
1387
            test_ok ;
1388
    end
1389
    begin
1390
        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 ) ;
1391
        if ( ok !== 1 )
1392
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1393
    end
1394
    join
1395
 
1396
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1397
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1398
    if (ok !== 1)
1399
    begin
1400
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1401
        test_fail("write to WB Image control register failed") ;
1402
        disable main ;
1403
    end
1404
 
1405
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1406
    fork
1407
    begin
1408
        wishbone_master.wb_block_read(write_flags, read_status) ;
1409
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1410
        begin
1411
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1412
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1413
            disable main ;
1414
        end
1415
 
1416
        // check data read from target
1417
        for ( i = 0 ; i < 4 ; i = i + 1 )
1418
        begin
1419
            read_status = wishbone_master.blk_read_data_out[i] ;
1420
            if (read_status`READ_DATA !== wmem_data[2 + i])
1421
            begin
1422
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1423
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1424
            end
1425
            else
1426
                test_ok ;
1427
        end
1428
    end
1429
    begin
1430
        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 ) ;
1431
        if ( ok !== 1 )
1432
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1433
    end
1434
    join
1435
 
1436
    read_data`READ_ADDRESS  = target_address + 4 ;
1437
    read_data`READ_SEL      = 4'hF ;
1438
    read_data`READ_TAG_STIM = 0 ;
1439
 
1440
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1441
    fork
1442
    begin
1443
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1444
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1445
        begin
1446
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1447
            test_fail("delayed single memory read wasn't processed as expected") ;
1448
            disable main ;
1449
        end
1450
 
1451
        if (read_status`READ_DATA !== wmem_data[1])
1452
        begin
1453
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1454
            test_fail("delayed single memory read data value returned was not as expected") ;
1455
        end
1456
        else
1457
            test_ok ;
1458
    end
1459
    begin
1460
        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 ) ;
1461
        if ( ok !== 1 )
1462
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1463
    end
1464
    join
1465
 
1466
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1467
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1468
    if (ok !== 1)
1469
    begin
1470
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1471
        test_fail("write to WB Image control register failed") ;
1472
        disable main ;
1473
    end
1474
 
1475
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1476
    fork
1477
    begin
1478
        wishbone_master.wb_block_read(write_flags, read_status) ;
1479
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1480
        begin
1481
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1482
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1483
            disable main ;
1484
        end
1485
 
1486
        // check data read from target
1487
        for ( i = 0 ; i < 4 ; i = i + 1 )
1488
        begin
1489
            read_status = wishbone_master.blk_read_data_out[i] ;
1490
            if (read_status`READ_DATA !== wmem_data[2 + i])
1491
            begin
1492
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1493
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1494
            end
1495
            else
1496
                test_ok ;
1497
        end
1498
    end
1499
    begin
1500
        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 ) ;
1501
        if ( ok !== 1 )
1502
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1503
    end
1504
    join
1505
 
1506
    read_data`READ_ADDRESS  = target_address + 8 ;
1507
    read_data`READ_SEL      = 4'hF ;
1508
    read_data`READ_TAG_STIM = 0 ;
1509
 
1510
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1511
    fork
1512
    begin
1513
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1514
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1515
        begin
1516
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1517
            test_fail("delayed single memory read wasn't processed as expected") ;
1518
            disable main ;
1519
        end
1520
 
1521
        if (read_status`READ_DATA !== wmem_data[2])
1522
        begin
1523
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1524
            test_fail("delayed single memory read data value returned was not as expected") ;
1525
        end
1526
        else
1527
            test_ok ;
1528
    end
1529
    begin
1530
        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 ) ;
1531
        if ( ok !== 1 )
1532
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1533
    end
1534
    join
1535
 
1536
    // map image to IO space
1537
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1538
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1539
    if ( ok !== 1 )
1540
    begin
1541
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1542
        test_fail("write to WB Image Base Address register failed") ;
1543
        disable main ;
1544
    end
1545
 
1546
    write_data`WRITE_ADDRESS = target_address ;
1547
    write_data`WRITE_DATA    = wmem_data[11] ;
1548
    write_data`WRITE_SEL     = 4'hF ;
1549
 
1550
    // handle retries from now on
1551
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1552
 
1553
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1554
    fork
1555
    begin
1556
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1557
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1558
        begin
1559
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1560
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1561
            disable main ;
1562
        end
1563
    end
1564
    begin
1565
        // currently IO commands not supported in behavioral models - master abort
1566
        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 ) ;
1567
        if ( ok !== 1 )
1568
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1569
        else
1570
            test_ok ;
1571
    end
1572
    join
1573
 
1574
    read_data`READ_ADDRESS  = target_address ;
1575
    read_data`READ_SEL      = 4'hF ;
1576
    read_data`READ_TAG_STIM = 0 ;
1577
 
1578
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1579
 
1580
    // currently io commands are not supported by behavioral target - transfer should not be completed
1581
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1582
    fork
1583
    begin
1584
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1585
        if (read_status`CYC_ERR !== 1)
1586
        begin
1587
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1588
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1589
            disable main ;
1590
        end
1591
        else
1592
            test_ok ;
1593
    end
1594
    begin
1595
        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 ) ;
1596
        if ( ok !== 1 )
1597
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1598
    end
1599
    join
1600
 
1601
    // test byte addressing
1602
    read_data`READ_ADDRESS = target_address + 2 ;
1603
    read_data`READ_SEL     = 4'b1100 ;
1604
 
1605
    fork
1606
    begin
1607
        // currently io commands are not supported by behavioral target - transfer should not be completed
1608
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1609
        if (read_status`CYC_ERR !== 1)
1610
        begin
1611
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1612
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1613
            disable main ;
1614
        end
1615
        else test_ok ;
1616
    end
1617
    begin
1618
        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 ) ;
1619
        if ( ok !== 1 )
1620
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1621
    end
1622
    join
1623
 
1624
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1625
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1626
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1627
    if ( ok !== 1 )
1628
    begin
1629
        test_fail("WB Base address register could not be written") ;
1630
        disable main ;
1631
    end
1632
 
1633
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1634
    if ( ok !== 1 )
1635
    begin
1636
        test_fail("WB Address Mask register could not be written") ;
1637
        disable main ;
1638
    end
1639
 
1640
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1641
    if ( ok !== 1 )
1642
    begin
1643
        test_fail("WB Image Control register could not be written") ;
1644
        disable main ;
1645
    end
1646
 
1647
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1648
    write_data`WRITE_DATA    = wmem_data[11] ;
1649
    write_data`WRITE_SEL     = 4'b1000 ;
1650
 
1651
    // handle retries from now on
1652
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1653
 
1654
    fork
1655
    begin
1656
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1657
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1658
        begin
1659
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1660
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1661
            disable main ;
1662
        end
1663
    end
1664
    begin
1665
        // currently IO commands not supported in behavioral models - master abort
1666
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1667
        if ( ok !== 1 )
1668
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1669
        else
1670
            test_ok ;
1671
    end
1672
    join
1673
 
1674
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1675
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1676
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1677
 
1678
    fork
1679
    begin
1680
        // currently io commands are not supported by behavioral target - transfer should not be completed
1681
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1682
        if (read_status`CYC_ERR !== 1)
1683
        begin
1684
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1685
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1686
            disable main ;
1687
        end
1688
        else test_ok ;
1689
    end
1690
    begin
1691
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1692
        if ( ok !== 1 )
1693
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1694
    end
1695
    join
1696
 
1697
    test_name = "DISABLING WB IMAGE" ;
1698
 
1699
    // disable current image
1700
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1701
    if ( ok !== 1 )
1702
    begin
1703
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1704
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1705
        disable main ;
1706
    end
1707
 
1708
    // clear master abort status bit
1709
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1710
    if ( ok !== 1 )
1711
    begin
1712
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1713
        test_fail("write to PCI Device Status register not accepted as expected") ;
1714
        disable main ;
1715
    end
1716
 
1717
end //main
1718
endtask //test_wb_image
1719
 
1720
task wb_slave_errors ;
1721
    reg   [11:0] ctrl_offset ;
1722
    reg   [11:0] ba_offset ;
1723
    reg   [11:0] am_offset ;
1724
    reg   [11:0] ta_offset ;
1725
    reg `WRITE_STIM_TYPE write_data ;
1726
    reg `READ_STIM_TYPE  read_data ;
1727
    reg `READ_RETURN_TYPE read_status ;
1728
 
1729
    reg `WRITE_RETURN_TYPE write_status ;
1730
    reg `WB_TRANSFER_FLAGS write_flags ;
1731
    reg [31:0] temp_val1 ;
1732
    reg [31:0] temp_val2 ;
1733
    reg        ok   ;
1734
    reg [11:0] pci_ctrl_offset ;
1735
    reg [31:0] image_base ;
1736
    reg [31:0] target_address ;
1737
    integer    i ;
1738
    reg skip ;
1739
fork
1740
begin:main
1741
 
1742
    `ifdef GUEST
1743
        skip = 1 ;
1744
    `else
1745
        skip = 0 ;
1746
    `endif
1747
 
1748
    pci_ctrl_offset = 12'h4 ;
1749
 
1750
    // image 1 is used for error testing, since it is always implemented
1751
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1752
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1753
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1754
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1755
 
1756
    target_address  = `BEH_TAR1_MEM_START ;
1757
    image_base      = 0 ;
1758
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1759
 
1760
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1761
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1762
    write_flags                    = 0 ;
1763
    write_flags`INIT_WAITS         = tb_init_waits ;
1764
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1765
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1766
 
1767
    // enable master & target operation
1768
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1769
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1770
    if ( ok !== 1 )
1771
    begin
1772
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1773
        test_fail("PCI Device Control register couldn't be written") ;
1774
        disable no_transaction ;
1775
        disable main ;
1776
    end
1777
 
1778
    // prepare image control register
1779
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1780
    if ( ok !== 1 )
1781
    begin
1782
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1783
        test_fail("WB Image Control register couldn't be written") ;
1784
        disable no_transaction ;
1785
        disable main ;
1786
    end
1787
 
1788
    // prepare base address register
1789
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1790
    if ( ok !== 1 )
1791
    begin
1792
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1793
        test_fail("WB Base Address register couldn't be written") ;
1794
        disable no_transaction ;
1795
        disable main ;
1796
    end
1797
 
1798
    // write address mask register
1799
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1800
    if ( ok !== 1 )
1801
    begin
1802
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1803
        test_fail("WB Address Mask register couldn't be written") ;
1804
        disable no_transaction ;
1805
        disable main ;
1806
    end
1807
 
1808
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1809
 
1810
    skip = 0 ;
1811
 
1812
    // memory mapped image - access is erroneous when address is not alligned
1813
    write_data`WRITE_ADDRESS = target_address + 1 ;
1814
    write_data`WRITE_DATA    = wmem_data[0] ;
1815
    write_data`WRITE_SEL     = 4'hF ;
1816
 
1817
    // handle retries from now on
1818
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1819
 
1820
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
1821
 
1822
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1823
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1824
    begin
1825
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1826
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1827
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1828
        disable no_transaction ;
1829
        disable main ;
1830
    end
1831
 
1832
    write_data`WRITE_ADDRESS = target_address + 2 ;
1833
 
1834
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1835
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1836
    begin
1837
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1838
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1839
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1840
        disable no_transaction ;
1841
        disable main ;
1842
 
1843
    end
1844
 
1845
    write_data`WRITE_ADDRESS = target_address + 3 ;
1846
 
1847
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1848
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1849
    begin
1850
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1851
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1852
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1853
        disable no_transaction ;
1854
        disable main ;
1855
    end
1856
 
1857
    test_ok ;
1858
 
1859
    // perform same tests for read accesses
1860
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
1861
 
1862
    read_data`READ_ADDRESS  = target_address + 2 ;
1863
    read_data`READ_SEL      = 4'hF ;
1864
    read_data`READ_TAG_STIM = 0 ;
1865
 
1866
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1867
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1868
    begin
1869
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1870
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1871
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
1872
        disable no_transaction ;
1873
        disable main ;
1874
    end
1875
 
1876
    test_ok ;
1877
 
1878
    // prepare write data
1879
    for ( i = 0 ; i < 6 ; i = i + 1 )
1880
    begin
1881
        write_data`WRITE_DATA    = wmem_data[i] ;
1882
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
1883
        write_data`WRITE_SEL     = 4'hF ;
1884
        wishbone_master.blk_write_data[i] = write_data ;
1885
    end
1886
 
1887
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1888
    write_flags`WB_TRANSFER_CAB    = 1 ;
1889
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1890
 
1891
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
1892
    wishbone_master.wb_block_write(write_flags, write_status) ;
1893
 
1894
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1895
    begin
1896
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1897
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1898
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
1899
        disable no_transaction ;
1900
        disable main ;
1901
    end
1902
 
1903
    // prepare read data
1904
    for ( i = 0 ; i < 6 ; i = i + 1 )
1905
    begin
1906
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
1907
        read_data`READ_SEL     = 4'hF ;
1908
        wishbone_master.blk_read_data_in[i] = read_data ;
1909
    end
1910
 
1911
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
1912
    wishbone_master.wb_block_read(write_flags, read_status) ;
1913
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1914
    begin
1915
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1916
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1917
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
1918
        disable no_transaction ;
1919
        disable main ;
1920
    end
1921
 
1922
    test_ok ;
1923
 
1924
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1925
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
1926
 
1927
    // map image to IO space
1928
    `ifdef GUEST
1929
        skip = 1 ;
1930
    `endif
1931
 
1932
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
1933
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1934
    if ( ok !== 1 )
1935
    begin
1936
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1937
        test_fail("WB Image Base Address register couldn't be written") ;
1938
        disable no_transaction ;
1939
        disable main ;
1940
    end
1941
 
1942
    skip = 0 ;
1943
 
1944
    write_data`WRITE_ADDRESS = target_address ;
1945
    write_data`WRITE_DATA    = wmem_data[0] ;
1946
    write_data`WRITE_SEL     = 4'b1010 ;
1947
 
1948
    // don't handle retries
1949
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1950
 
1951
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
1952
 
1953
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1954
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1955
    begin
1956
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1957
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1958
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1959
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1960
        disable no_transaction ;
1961
        disable main ;
1962
    end
1963
 
1964
    write_data`WRITE_ADDRESS = target_address + 1 ;
1965
    write_data`WRITE_SEL     = 4'b0011 ;
1966
 
1967
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1968
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1969
    begin
1970
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1971
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1972
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1973
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1974
        disable no_transaction ;
1975
        disable main ;
1976
    end
1977
 
1978
    write_data`WRITE_SEL     = 4'b1100 ;
1979
 
1980
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
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 erroneous access to IO mapped address! Time %t ", $time) ;
1984
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1985
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1986
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1987
        disable no_transaction ;
1988
        disable main ;
1989
    end
1990
 
1991
    write_data`WRITE_ADDRESS = target_address + 2 ;
1992
    write_data`WRITE_SEL     = 4'b0101 ;
1993
 
1994
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1995
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1996
    begin
1997
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1998
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1999
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2000
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2001
        disable no_transaction ;
2002
        disable main ;
2003
    end
2004
 
2005
    write_data`WRITE_SEL     = 4'b1000 ;
2006
 
2007
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2008
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2009
    begin
2010
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2011
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2012
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2013
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2014
        disable no_transaction ;
2015
        disable main ;
2016
    end
2017
 
2018
    write_data`WRITE_ADDRESS = target_address + 3 ;
2019
    write_data`WRITE_SEL     = 4'b1010 ;
2020
 
2021
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2022
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2023
    begin
2024
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2025
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2026
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2027
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2028
        disable no_transaction ;
2029
        disable main ;
2030
    end
2031
 
2032
    write_data`WRITE_SEL     = 4'b0110 ;
2033
 
2034
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2035
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2036
    begin
2037
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2038
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2039
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2040
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2041
        disable no_transaction ;
2042
        disable main ;
2043
    end
2044
 
2045
    test_ok ;
2046
 
2047
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2048
 
2049
    read_data`READ_ADDRESS  = target_address + 3 ;
2050
    read_data`READ_SEL      = 4'hF ;
2051
    read_data`READ_TAG_STIM = 0 ;
2052
 
2053
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2054
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2055
    begin
2056
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2057
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2058
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2059
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2060
        disable no_transaction ;
2061
        disable main ;
2062
    end
2063
 
2064
    test_ok ;
2065
 
2066
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2067
    // prepare write data
2068
    for ( i = 0 ; i < 6 ; i = i + 1 )
2069
    begin
2070
        write_data`WRITE_DATA    = wmem_data[i] ;
2071
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2072
        write_data`WRITE_SEL     = 4'hF ;
2073
        wishbone_master.blk_write_data[i] = write_data ;
2074
    end
2075
 
2076
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2077
    write_flags`WB_TRANSFER_CAB    = 1 ;
2078
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2079
 
2080
    wishbone_master.wb_block_write(write_flags, write_status) ;
2081
 
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 CAB access to IO mapped address! Time %t ", $time) ;
2085
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2086
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2087
        disable no_transaction ;
2088
        disable main ;
2089
    end
2090
 
2091
    test_ok ;
2092
 
2093
    test_name = "CAB I/O READ TO WB SLAVE" ;
2094
    // prepare read data
2095
    for ( i = 0 ; i < 6 ; i = i + 1 )
2096
    begin
2097
        read_data`READ_ADDRESS = target_address + 4*i ;
2098
        read_data`READ_SEL     = 4'hF ;
2099
        wishbone_master.blk_read_data_in[i] = read_data ;
2100
    end
2101
 
2102
    wishbone_master.wb_block_read(write_flags, read_status) ;
2103
 
2104
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2105
    begin
2106
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2107
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2108
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2109
        disable no_transaction ;
2110
        disable main ;
2111
    end
2112
 
2113
    test_ok ;
2114
 
2115
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2116
 
2117
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2118
 
2119
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2120
    write_data`WRITE_ADDRESS = target_address + 1 ;
2121
    write_data`WRITE_DATA    = wmem_data[0] ;
2122
    write_data`WRITE_SEL     = 4'hF ;
2123
 
2124
    // don't handle retries
2125
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2126
 
2127
    `ifdef HOST
2128
        `define DO_W_CONF_TEST
2129
        `define DO_R_CONF_TEST
2130
    `else
2131
        `ifdef WB_CNF_IMAGE
2132
             `define DO_R_CONF_TEST
2133
        `endif
2134
    `endif
2135
 
2136
    `ifdef DO_W_CONF_TEST
2137
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2138
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2139
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2140
    begin
2141
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2142
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2143
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2144
        disable no_transaction ;
2145
        disable main ;
2146
    end
2147
 
2148
    write_data`WRITE_ADDRESS = target_address + 2 ;
2149
 
2150
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2151
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2152
    begin
2153
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2154
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2155
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2156
        disable no_transaction ;
2157
        disable main ;
2158
    end
2159
 
2160
    write_data`WRITE_ADDRESS = target_address + 3 ;
2161
 
2162
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2163
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2164
    begin
2165
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2166
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2167
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2168
        disable no_transaction ;
2169
        disable main ;
2170
    end
2171
 
2172
    test_ok ;
2173
    `endif
2174
 
2175
    `ifdef DO_R_CONF_TEST
2176
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2177
    read_data`READ_ADDRESS  = target_address + 3 ;
2178
    read_data`READ_SEL      = 4'hF ;
2179
    read_data`READ_TAG_STIM = 0 ;
2180
 
2181
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2182
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2183
    begin
2184
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2185
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2186
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2187
        disable no_transaction ;
2188
        disable main ;
2189
    end
2190
 
2191
    test_ok ;
2192
    `endif
2193
 
2194
    `ifdef DO_W_CONF_TEST
2195
    // prepare write data
2196
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2197
    for ( i = 0 ; i < 6 ; i = i + 1 )
2198
    begin
2199
        write_data`WRITE_DATA    = wmem_data[i] ;
2200
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2201
        write_data`WRITE_SEL     = 4'hF ;
2202
        wishbone_master.blk_write_data[i] = write_data ;
2203
    end
2204
 
2205
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2206
    write_flags`WB_TRANSFER_CAB    = 1 ;
2207
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2208
 
2209
    wishbone_master.wb_block_write(write_flags, write_status) ;
2210
 
2211
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2212
    begin
2213
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2214
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2215
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2216
        disable no_transaction ;
2217
        disable main ;
2218
    end
2219
    test_ok ;
2220
    `endif
2221
 
2222
    `ifdef DO_R_CONF_TEST
2223
    // prepare read data
2224
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2225
    for ( i = 0 ; i < 6 ; i = i + 1 )
2226
    begin
2227
        read_data`READ_ADDRESS = target_address + 4*i ;
2228
        read_data`READ_SEL     = 4'hF ;
2229
        wishbone_master.blk_read_data_in[i] = read_data ;
2230
    end
2231
 
2232
    wishbone_master.wb_block_read(write_flags, read_status) ;
2233
 
2234
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2235
    begin
2236
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2237
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2238
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2239
        disable no_transaction ;
2240
        disable main ;
2241
    end
2242
    test_ok ;
2243
    `endif
2244
 
2245
    `ifdef GUEST
2246
        skip = 1 ;
2247
    `endif
2248
 
2249
    // disable image
2250
    test_name = "DISABLE IMAGE" ;
2251
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2252
    if ( ok !== 1 )
2253
    begin
2254
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2255
        test_fail("WB Address Mask register couldn't be written") ;
2256
        disable no_transaction ;
2257
        disable main ;
2258
    end
2259
 
2260
    skip = 0 ;
2261
 
2262
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2263
 
2264
    disable no_transaction ;
2265
end
2266
begin:no_transaction
2267
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2268
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2269
    forever
2270
    begin
2271
        @(posedge pci_clock) ;
2272
        if ( skip !== 1 )
2273
        begin
2274
            if ( FRAME !== 1 )
2275
            begin
2276
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2277
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2278
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2279
            end
2280
        end
2281
    end
2282
end
2283
join
2284
endtask //wb_slave_errors
2285
 
2286
task wb_to_pci_error_handling ;
2287
    reg   [11:0] ctrl_offset ;
2288
    reg   [11:0] ba_offset ;
2289
    reg   [11:0] am_offset ;
2290
    reg   [11:0] ta_offset ;
2291
    reg   [11:0] err_cs_offset ;
2292
    reg `WRITE_STIM_TYPE write_data ;
2293
    reg `READ_STIM_TYPE  read_data ;
2294
    reg `READ_RETURN_TYPE read_status ;
2295
 
2296
    reg `WRITE_RETURN_TYPE write_status ;
2297
    reg `WB_TRANSFER_FLAGS write_flags ;
2298
    reg [31:0] temp_val1 ;
2299
    reg [31:0] temp_val2 ;
2300
    reg        ok   ;
2301
    reg [11:0] pci_ctrl_offset ;
2302
    reg [31:0] image_base ;
2303
    reg [31:0] target_address ;
2304
    integer    num_of_trans ;
2305
    integer    current ;
2306
    integer    i ;
2307
begin:main
2308
 
2309
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2310
 
2311
    pci_ctrl_offset = 12'h4 ;
2312
 
2313
    // disable error interrupts and disable error reporting
2314
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2315
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2316
    if ( ok !== 1 )
2317
    begin
2318
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2319
        test_fail("PCI Device Control register couldn't be written") ;
2320
        disable main ;
2321
    end
2322
 
2323
    // image 1 is used for error testing, since it is always implemented
2324
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2325
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2326
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2327
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2328
 
2329
    // set master abort testing address to address that goes out of target's range
2330
    target_address  = `BEH_TAR1_MEM_START ;
2331
    image_base      = 0 ;
2332
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2333
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2334
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2335
 
2336
    write_flags                    = 0 ;
2337
    write_flags`INIT_WAITS         = tb_init_waits ;
2338
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2339
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2340
 
2341
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2342
 
2343
    // enable master & target operation
2344
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2345
    if ( ok !== 1 )
2346
    begin
2347
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2348
        test_fail("PCI Device Control register couldn't be written") ;
2349
        disable main ;
2350
    end
2351
 
2352
    // prepare image control register
2353
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2354
    if ( ok !== 1 )
2355
    begin
2356
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2357
        test_fail("WB Image Control register couldn't be written") ;
2358
        disable main ;
2359
    end
2360
 
2361
    // prepare base address register
2362
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2363
    if ( ok !== 1 )
2364
    begin
2365
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2366
        test_fail("WB Image Base Address register couldn't be written") ;
2367
        disable main ;
2368
    end
2369
 
2370
    // write address mask register
2371
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2372
    if ( ok !== 1 )
2373
    begin
2374
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2375
        test_fail("WB Image Address Mask register couldn't be written") ;
2376
        disable main ;
2377
    end
2378
 
2379
    // disable error reporting
2380
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2381
    if ( ~ok )
2382
    begin
2383
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2384
        test_fail("WB Error Control and Status register couldn't be written") ;
2385
        disable main ;
2386
    end
2387
 
2388
    // perform two writes - one to error address and one to OK address
2389
    // prepare write buffer
2390
 
2391
    write_data`WRITE_ADDRESS = target_address ;
2392
    write_data`WRITE_DATA    = wmem_data[100] ;
2393
    write_data`WRITE_SEL     = 4'hF ;
2394
 
2395
    wishbone_master.blk_write_data[0] = write_data ;
2396
 
2397
    write_flags`WB_TRANSFER_SIZE = 2 ;
2398
 
2399
    // don't handle retries
2400
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2401
    write_flags`WB_TRANSFER_CAB    = 0 ;
2402
 
2403
    $display("Introducing master abort error on single WB to PCI write!") ;
2404
 
2405
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2406
    // first disable target 1
2407
 
2408
    configuration_cycle_write(0,             // bus number
2409
                              1,             // device number
2410
                              0,             // function number
2411
                              1,             // register number
2412
                              0,             // type of configuration cycle
2413
                              4'b0001,       // byte enables
2414
                              32'h0000_0000  // data
2415
                             ) ;
2416
 
2417
    fork
2418
    begin
2419
        // start no response monitor in parallel with writes
2420
        musnt_respond(ok) ;
2421
        if ( ok !== 1 )
2422
        begin
2423
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2424
            $display("Testbench is configured wrong!") ;
2425
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2426
        end
2427
        else
2428
            test_ok ;
2429
    end
2430
    begin
2431
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2432
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2433
       begin
2434
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2435
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2436
           test_fail("WB Slave state machine failed to post single memory write");
2437
           disable main ;
2438
       end
2439
    end
2440
    join
2441
 
2442
    /*// read data from second write
2443
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2444
    read_data`READ_ADDRESS = target_address ;
2445
    read_data`READ_SEL     = 4'hF ;
2446
    read_data`READ_TAG_STIM = 0 ;
2447
 
2448
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2449
 
2450
    if ( read_status`READ_DATA !== wmem_data[101] )
2451
    begin
2452
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2453
    end
2454
    */
2455
 
2456
    // read error status register - no errors should be reported since reporting was disabled
2457
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2458
 
2459
    @(posedge pci_clock) ;
2460
    // wait for two WB clocks for synchronization to be finished
2461
    repeat (2)
2462
        @(posedge wb_clock) ;
2463
 
2464
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2465
    if ( temp_val1[8] !== 0 )
2466
    begin
2467
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2468
        $display("Error reporting was disabled, but error was reported anyway!") ;
2469
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2470
        disable main ;
2471
    end
2472
    test_ok ;
2473
 
2474
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2475
    // check for interrupts - there should be no interrupt requests active
2476
    `ifdef HOST
2477
        repeat(4)
2478
            @(posedge wb_clock) ;
2479
 
2480
        if ( INT_O !== 0 )
2481
        begin
2482
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2483
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2484
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2485
        end
2486
        else
2487
            test_ok ;
2488
    `else
2489
    `ifdef GUEST
2490
        repeat( 4 )
2491
            @(posedge pci_clock) ;
2492
 
2493
        if ( INTA !== 1 )
2494
        begin
2495
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2496
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2497
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2498
        end
2499
        else
2500
            test_ok ;
2501
    `endif
2502
    `endif
2503
 
2504
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2505
    // check PCI status register
2506
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2507
    if ( temp_val1[29] !== 1 )
2508
    begin
2509
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2510
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2511
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2512
    end
2513
    else
2514
        test_ok ;
2515
 
2516
    // clear
2517
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2518
 
2519
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2520
 
2521
    $display("Introducing master abort error to CAB write!") ;
2522
    // now enable error reporting mechanism
2523
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2524
    // enable error interrupts
2525
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2526
 
2527
    // configure flags for CAB transfer
2528
    write_flags`WB_TRANSFER_CAB = 1 ;
2529
    write_flags`WB_TRANSFER_SIZE = 3 ;
2530
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2531
 
2532
    // prepare data for erroneous write
2533
    for ( i = 0 ; i < 3 ; i = i + 1 )
2534
    begin
2535
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2536
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2537
        write_data`WRITE_SEL     = 4'hF ;
2538
        wishbone_master.blk_write_data[i] = write_data ;
2539
    end
2540
 
2541
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2542
    fork
2543
    begin
2544
        wishbone_master.wb_block_write(write_flags, write_status) ;
2545
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2546
        begin
2547
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2548
            $display("Complete burst write through WB slave didn't succeed!") ;
2549
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2550
            disable main ;
2551
        end
2552
    end
2553
    begin
2554
        musnt_respond(ok) ;
2555
        if ( ok !== 1 )
2556
        begin
2557
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2558
            $display("Testbench is configured wrong!") ;
2559
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2560
        end
2561
        else
2562
            test_ok ;
2563
    end
2564
    join
2565
 
2566
    // check error status address, data, byte enables and bus command
2567
    // error status bit is signalled on PCI clock and synchronized to WB clock
2568
    // wait one PCI clock cycle
2569
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2570
    ok = 1 ;
2571
    @(posedge pci_clock) ;
2572
 
2573
    // wait for two WB clocks for synchronization to be finished
2574
    repeat (2)
2575
        @(posedge wb_clock) ;
2576
 
2577
    // read registers
2578
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2579
    if ( temp_val1[8] !== 1 )
2580
    begin
2581
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2582
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2583
        ok = 0 ;
2584
    end
2585
 
2586
    if ( temp_val1[9] !== 1 )
2587
    begin
2588
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2589
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2590
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2591
        ok = 0 ;
2592
    end
2593
 
2594
    if ( temp_val1[31:28] !== 0 )
2595
    begin
2596
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2597
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2598
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2599
        ok = 0 ;
2600
    end
2601
 
2602
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2603
    begin
2604
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2605
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2606
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2607
        ok = 0 ;
2608
    end
2609
 
2610
    // read error address register
2611
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2612
    if ( temp_val1 !== target_address )
2613
    begin
2614
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2615
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2616
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2617
        ok = 0 ;
2618
    end
2619
 
2620
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2621
    if ( temp_val1 !== wmem_data[110] )
2622
    begin
2623
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2624
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2625
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2626
        ok = 0 ;
2627
    end
2628
 
2629
    // check PCI status register
2630
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2631
    if ( temp_val1[29] !== 1 )
2632
    begin
2633
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2634
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2635
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2636
        ok = 0 ;
2637
    end
2638
 
2639
    if ( temp_val1[28] !== 0 )
2640
    begin
2641
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2642
        $display("Received Target Abort bit was set for no reason!") ;
2643
        test_fail("Received Target Abort bit was set for no reason") ;
2644
        ok = 0 ;
2645
    end
2646
 
2647
    if ( ok )
2648
        test_ok ;
2649
 
2650
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2651
 
2652
    // clear error status bit
2653
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2654
 
2655
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2656
 
2657
    ok = 1 ;
2658
 
2659
    `ifdef HOST
2660
        repeat(4)
2661
        @(posedge wb_clock) ;
2662
        if ( INT_O !== 1 )
2663
        begin
2664
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2665
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2666
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2667
            ok = 0 ;
2668
        end
2669
    `else
2670
    `ifdef GUEST
2671
        repeat(4)
2672
        @(posedge pci_clock) ;
2673
        if ( INTA !== 0 )
2674
        begin
2675
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2676
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2677
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2678
            ok = 0 ;
2679
        end
2680
    `endif
2681
    `endif
2682
 
2683
    // read interrupt status register
2684
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2685
    if ( temp_val1 !== 32'h0000_0002 )
2686
    begin
2687
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2688
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2689
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2690
        test_fail("Interrupt Status register returned wrong value") ;
2691
        ok = 0 ;
2692
    end
2693
 
2694
    if ( ok )
2695
        test_ok ;
2696
    // clear interrupt status bits
2697
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2698
 
2699
    ok = 1 ;
2700
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2701
    // wait for two clock cycles before checking interrupt request deassertion
2702
    `ifdef HOST
2703
        repeat (4)
2704
            @(posedge wb_clock) ;
2705
 
2706
        if ( INT_O !== 0 )
2707
        begin
2708
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2709
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2710
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2711
            ok = 0 ;
2712
        end
2713
    `else
2714
    `ifdef GUEST
2715
        repeat (4)
2716
            @(posedge pci_clock) ;
2717
 
2718
        if ( INTA !== 1 )
2719
        begin
2720
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2721
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2722
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2723
            ok = 0 ;
2724
        end
2725
    `endif
2726
    `endif
2727
 
2728
    if ( ok )
2729
        test_ok ;
2730
 
2731
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2732
    ok = 1 ;
2733
    // enable target
2734
    configuration_cycle_write(0,             // bus number
2735
                              1,             // device number
2736
                              0,             // function number
2737
                              1,             // register number
2738
                              0,             // type of configuration cycle
2739
                              4'b0001,       // byte enables
2740
                              32'h0000_0007  // data
2741
                             ) ;
2742
    // prepare data for ok write
2743
    for ( i = 0 ; i < 3 ; i = i + 1 )
2744
    begin
2745
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2746
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2747
        write_data`WRITE_SEL     = 4'hF ;
2748
        wishbone_master.blk_write_data[i] = write_data ;
2749
    end
2750
 
2751
    wishbone_master.wb_block_write(write_flags, write_status) ;
2752
 
2753
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2754
    begin
2755
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2756
        $display("Complete burst write through WB slave didn't succeed!") ;
2757
        test_fail("WB Slave state machine failed to post CAB write") ;
2758
        disable main ;
2759
    end
2760
 
2761
    // do a read
2762
    for ( i = 0 ; i < 3 ; i = i + 1 )
2763
    begin
2764
        read_data`READ_ADDRESS = target_address + 4*i ;
2765
        read_data`READ_SEL     = 4'hF ;
2766
        wishbone_master.blk_read_data_in[i] = read_data ;
2767
    end
2768
 
2769
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2770
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2771
    write_flags`WB_TRANSFER_CAB    = 1 ;
2772
 
2773
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2774
 
2775
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2776
    begin
2777
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2778
        $display("Complete burst read through WB slave didn't succeed!") ;
2779
        test_fail("Delayed CAB write was not processed as expected") ;
2780
        disable main ;
2781
    end
2782
 
2783
    for ( i = 0 ; i < 3 ; i = i + 1 )
2784
    begin
2785
        read_status = wishbone_master.blk_read_data_out[i] ;
2786
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2787
        begin
2788
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2789
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2790
        end
2791
    end
2792
 
2793
    $display("Introducing master abort error to single read!") ;
2794
    // disable target
2795
    configuration_cycle_write(0,             // bus number
2796
                              1,             // device number
2797
                              0,             // function number
2798
                              1,             // register number
2799
                              0,             // type of configuration cycle
2800
                              4'b0001,       // byte enables
2801
                              32'h0000_0000  // data
2802
                             ) ;
2803
    // set read data
2804
    read_data`READ_ADDRESS = target_address ;
2805
    read_data`READ_SEL     = 4'hF ;
2806
 
2807
    // enable automatic retry handling
2808
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2809
    write_flags`WB_TRANSFER_CAB    = 0 ;
2810
 
2811
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2812
    fork
2813
    begin
2814
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2815
    end
2816
    begin
2817
        musnt_respond(ok) ;
2818
        if ( ok !== 1 )
2819
        begin
2820
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2821
            $display("Testbench is configured wrong!") ;
2822
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2823
        end
2824
    end
2825
    join
2826
 
2827
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2828
    begin
2829
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2830
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2831
        $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) ;
2832
        test_fail("read didn't finish on WB bus as expected") ;
2833
        disable main ;
2834
    end
2835
 
2836
    test_ok ;
2837
 
2838
 
2839
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
2840
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
2841
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2842
    if ( temp_val1[8] !== 0 )
2843
    begin
2844
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2845
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
2846
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
2847
    end
2848
    else
2849
        test_ok ;
2850
 
2851
    // now check normal read operation
2852
    configuration_cycle_write(0,             // bus number
2853
                              1,             // device number
2854
                              0,             // function number
2855
                              1,             // register number
2856
                              0,             // type of configuration cycle
2857
                              4'b0001,       // byte enables
2858
                              32'h0000_0007  // data
2859
                             ) ;
2860
 
2861
    test_name = "CHECK NORMAL READ AFTER ERROR TERMINATED READ" ;
2862
    read_data`READ_ADDRESS = target_address ;
2863
    read_data`READ_SEL     = 4'hF ;
2864
 
2865
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2866
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
2867
    begin
2868
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2869
        $display("WB slave failed to process single read!") ;
2870
        $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) ;
2871
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
2872
        disable main ;
2873
    end
2874
 
2875
    if ( read_status`READ_DATA !== wmem_data[113] )
2876
    begin
2877
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
2878
        test_fail("when read finished on WB bus, wrong data was provided") ;
2879
    end
2880
    else
2881
        test_ok ;
2882
 
2883
    // check PCI status register
2884
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT ON DELAYED READ" ;
2885
    ok = 1 ;
2886
 
2887
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2888
    if ( temp_val1[29] !== 1 )
2889
    begin
2890
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2891
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2892
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2893
        ok = 0 ;
2894
    end
2895
 
2896
    if ( temp_val1[28] !== 0 )
2897
    begin
2898
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2899
        $display("Received Target Abort bit was set for no reason!") ;
2900
        test_fail("Received Target Abort bit was set for no reason") ;
2901
        ok = 0 ;
2902
    end
2903
    if ( ok )
2904
        test_ok ;
2905
 
2906
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2907
 
2908
    $display("Introducing master abort error to CAB read!") ;
2909
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
2910
 
2911
    configuration_cycle_write(0,             // bus number
2912
                              1,             // device number
2913
                              0,             // function number
2914
                              1,             // register number
2915
                              0,             // type of configuration cycle
2916
                              4'b0001,       // byte enables
2917
                              32'h0000_0000  // data
2918
                             ) ;
2919
 
2920
    for ( i = 0 ; i < 3 ; i = i + 1 )
2921
    begin
2922
        read_data`READ_ADDRESS = target_address + 4*i ;
2923
        read_data`READ_SEL     = 4'hF ;
2924
        wishbone_master.blk_read_data_in[i] = read_data ;
2925
    end
2926
 
2927
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2928
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2929
    write_flags`WB_TRANSFER_CAB    = 1 ;
2930
 
2931
    fork
2932
    begin
2933
        wishbone_master.wb_block_read( write_flags, read_status ) ;
2934
    end
2935
    begin
2936
        musnt_respond(ok) ;
2937
        if ( ok !== 1 )
2938
        begin
2939
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2940
            $display("Testbench is configured wrong!") ;
2941
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2942
        end
2943
    end
2944
    join
2945
 
2946
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2947
    begin
2948
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2949
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2950
        $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) ;
2951
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
2952
        disable main ;
2953
    end
2954
    else
2955
        test_ok ;
2956
 
2957
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
2958
    ok = 1 ;
2959
    // check PCI status register
2960
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2961
    if ( temp_val1[29] !== 1 )
2962
    begin
2963
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2964
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2965
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2966
        ok = 0 ;
2967
    end
2968
 
2969
    if ( temp_val1[28] !== 0 )
2970
    begin
2971
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2972
        $display("Received Target Abort bit was set for no reason!") ;
2973
        test_fail("Received Target Abort bit was set for no reason") ;
2974
        ok = 0 ;
2975
    end
2976
 
2977
    if ( ok )
2978
        test_ok ;
2979
 
2980
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2981
 
2982
    $display("Introducing target abort termination to single write!") ;
2983
 
2984
    // disable error reporting and interrupts
2985
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
2986
 
2987
    configuration_cycle_write(0,             // bus number
2988
                              1,             // device number
2989
                              0,             // function number
2990
                              1,             // register number
2991
                              0,             // type of configuration cycle
2992
                              4'b0001,       // byte enables
2993
                              32'h0000_0007  // data
2994
                             ) ;
2995
 
2996
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
2997
    if ( ok !== 1 )
2998
    begin
2999
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3000
        test_fail("WB Error Control and Status register couldn't be written to") ;
3001
        disable main ;
3002
    end
3003
 
3004
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3005
    if ( ok !== 1 )
3006
    begin
3007
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3008
        test_fail("Interrupt Control register couldn't be written to") ;
3009
        disable main ;
3010
    end
3011
 
3012
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3013
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3014
 
3015
    write_data`WRITE_ADDRESS = target_address ;
3016
    write_data`WRITE_DATA    = wmem_data[0] ;
3017
    write_data`WRITE_SEL     = 4'hF ;
3018
 
3019
    wishbone_master.blk_write_data[0] = write_data ;
3020
 
3021
    write_data`WRITE_ADDRESS = target_address + 4;
3022
    write_data`WRITE_DATA    = wmem_data[1] ;
3023
    write_data`WRITE_SEL     = 4'hF ;
3024
 
3025
    wishbone_master.blk_write_data[1] = write_data ;
3026
 
3027
    write_flags`WB_TRANSFER_SIZE = 2 ;
3028
 
3029
    // don't handle retries
3030
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3031
    write_flags`WB_TRANSFER_CAB    = 0 ;
3032
 
3033
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3034
    fork
3035
    begin
3036
        wishbone_master.wb_block_write(write_flags, write_status) ;
3037
 
3038
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3039
        begin
3040
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3041
            $display("Image writes were not accepted as expected!") ;
3042
            $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) ;
3043
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3044
            disable main ;
3045
        end
3046
 
3047
        // read data back to see, if it was written OK
3048
        read_data`READ_ADDRESS         = target_address + 4;
3049
        read_data`READ_SEL             = 4'hF ;
3050
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3051
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3052
    end
3053
    begin
3054
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3055
        if ( ok !== 1 )
3056
        begin
3057
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3058
        end
3059
        else
3060
            test_ok ;
3061
 
3062
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3063
 
3064
        // when first transaction finishes - enable normal target response!
3065
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3066
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3067
 
3068
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3069
        if ( ok !== 1 )
3070
        begin
3071
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3072
        end
3073
        else
3074
            test_ok ;
3075
 
3076
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3077
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3078
        if ( ok !== 1 )
3079
        begin
3080
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3081
        end
3082
    end
3083
    join
3084
 
3085
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3086
    begin
3087
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3088
        $display("Bridge failed to process single read after target abort terminated write!") ;
3089
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3090
        disable main ;
3091
    end
3092
 
3093
    if ( read_status`READ_DATA !== wmem_data[1] )
3094
    begin
3095
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3096
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3097
    end
3098
    else
3099
        test_ok ;
3100
 
3101
    // check interrupt and error statuses!
3102
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3103
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3104
    if ( temp_val1[8] !== 0 )
3105
    begin
3106
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3107
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3108
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3109
    end
3110
    else
3111
        test_ok ;
3112
 
3113
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3114
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3115
    if ( temp_val1[1] !== 0 )
3116
    begin
3117
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3118
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3119
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3120
    end
3121
    else
3122
        test_ok ;
3123
 
3124
    // check PCI status register
3125
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3126
    ok = 1 ;
3127
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3128
    if ( temp_val1[29] !== 0 )
3129
    begin
3130
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3131
        $display("Received Master Abort bit was set with no reason!") ;
3132
        test_fail("Received Master Abort bit was set with no reason") ;
3133
        ok = 0 ;
3134
    end
3135
 
3136
    if ( temp_val1[28] !== 1 )
3137
    begin
3138
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3139
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3140
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3141
        ok = 0 ;
3142
    end
3143
 
3144
    if ( ok )
3145
        test_ok ;
3146
 
3147
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3148
 
3149
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3150
 
3151
    $display("Introducing target abort termination to CAB write!") ;
3152
    // enable error reporting mechanism
3153
 
3154
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3155
    if ( ok !== 1 )
3156
    begin
3157
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3158
        test_fail("WB Error Control and Status register could not be written to") ;
3159
        disable main ;
3160
    end
3161
 
3162
    for ( i = 0 ; i < 3 ; i = i + 1 )
3163
    begin
3164
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3165
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3166
        write_data`WRITE_SEL     = 4'b1010 ;
3167
        wishbone_master.blk_write_data[i] = write_data ;
3168
    end
3169
 
3170
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3171
    write_flags`WB_TRANSFER_CAB    = 1 ;
3172
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3173
 
3174
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3175
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3176
 
3177
    fork
3178
    begin
3179
        wishbone_master.wb_block_write(write_flags, write_status) ;
3180
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3181
        begin
3182
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3183
            $display("Bridge failed to process complete CAB write!") ;
3184
            test_fail("bridge failed to post CAB Memory Write") ;
3185
            disable main ;
3186
        end
3187
    end
3188
    begin
3189
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3190
        if ( ok !== 1 )
3191
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3192
        else
3193
            test_ok ;
3194
    end
3195
    join
3196
 
3197
    // check statuses and data from error
3198
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3199
    ok = 1 ;
3200
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3201
    if ( temp_val1[8] !== 1 )
3202
    begin
3203
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3204
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3205
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3206
        ok = 0 ;
3207
    end
3208
 
3209
    if ( temp_val1[9] !== 0 )
3210
    begin
3211
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3212
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3213
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3214
        ok = 0 ;
3215
    end
3216
 
3217
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3218
    begin
3219
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3220
        $display("Value in W_ERR_CS register was wrong!") ;
3221
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3222
        test_fail("BE Field didn't provided expected value") ;
3223
        ok = 0 ;
3224
    end
3225
 
3226
    if ( ok )
3227
        test_ok ;
3228
 
3229
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3230
    ok = 1 ;
3231
    // check erroneous address and data
3232
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3233
    if ( temp_val1 !== (target_address + 8) )
3234
    begin
3235
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3236
        $display("Value in W_ERR_ADDR register was wrong!") ;
3237
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3238
        test_fail("Value in WB Erroneous Address register was wrong") ;
3239
        ok = 0 ;
3240
    end
3241
 
3242
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3243
    if ( temp_val1 !== wmem_data[120] )
3244
    begin
3245
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3246
        $display("Value in W_ERR_DATA register was wrong!") ;
3247
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3248
        test_fail("Value in WB Erroneous Data register was wrong") ;
3249
        ok = 0 ;
3250
    end
3251
 
3252
    if ( ok )
3253
        test_ok ;
3254
 
3255
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3256
    ok = 1 ;
3257
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3258
    if ( temp_val1[29] !== 0 )
3259
    begin
3260
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3261
        $display("Received Master Abort bit was set with no reason!") ;
3262
        test_fail("Received Master Abort bit was set for no reason") ;
3263
        ok = 0 ;
3264
    end
3265
 
3266
    if ( temp_val1[28] !== 1 )
3267
    begin
3268
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3269
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3270
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3271
        ok = 0 ;
3272
    end
3273
 
3274
    if ( ok )
3275
        test_ok ;
3276
 
3277
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3278
 
3279
    // clear error status bit and enable error interrupts
3280
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3281
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3282
 
3283
    // check if error bit was cleared
3284
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3285
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3286
    if ( temp_val1[8] !== 0 )
3287
    begin
3288
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3289
        $display("Error bit was not cleared even though one was written to its location!") ;
3290
        test_fail("Error bit was not cleared even though one was written to its location") ;
3291
    end
3292
 
3293
    // repeat same write with different target configuration
3294
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3295
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3296
 
3297
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3298
    fork
3299
    begin
3300
        write_flags`WB_TRANSFER_SIZE = 2 ;
3301
        wishbone_master.wb_block_write(write_flags, write_status) ;
3302
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3303
        begin
3304
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3305
            $display("Bridge failed to process complete CAB write!") ;
3306
            test_fail("bridge failed to post CAB Memory Write") ;
3307
            disable main ;
3308
        end
3309
 
3310
        write_flags`WB_TRANSFER_SIZE = 3 ;
3311
        wishbone_master.wb_block_write(write_flags, write_status) ;
3312
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3313
        begin
3314
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3315
            $display("Bridge failed to process complete CAB write!") ;
3316
            test_fail("bridge failed to post CAB Memory Write") ;
3317
            disable main ;
3318
        end
3319
    end
3320
    begin
3321
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3322
        if ( ok !== 1 )
3323
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3324
        else
3325
        begin
3326
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3327
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3328
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3329
            if ( ok !== 1 )
3330
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3331
            else
3332
                test_ok ;
3333
        end
3334
    end
3335
    join
3336
 
3337
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3338
    ok = 1 ;
3339
    // check statuses and data from error
3340
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3341
    if ( temp_val1[8] !== 1 )
3342
    begin
3343
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3344
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3345
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3346
        ok = 0 ;
3347
    end
3348
 
3349
    if ( temp_val1[9] !== 0 )
3350
    begin
3351
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3352
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3353
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3354
        ok = 0 ;
3355
    end
3356
 
3357
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3358
    begin
3359
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3360
        $display("Value in W_ERR_CS register was wrong!") ;
3361
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3362
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3363
        ok = 0 ;
3364
    end
3365
 
3366
    if ( ok )
3367
        test_ok ;
3368
 
3369
    // check erroneous address and data
3370
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3371
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3372
    ok = 1 ;
3373
    if ( temp_val1 !== (target_address + 8 + 4) )
3374
    begin
3375
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3376
        $display("Value in W_ERR_ADDR register was wrong!") ;
3377
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3378
        test_fail("Value in WB Erroneous Address register was wrong") ;
3379
        ok = 0 ;
3380
 
3381
    end
3382
 
3383
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3384
    if ( temp_val1 !== wmem_data[121] )
3385
    begin
3386
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3387
        $display("Value in W_ERR_DATA register was wrong!") ;
3388
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3389
        test_fail("Value in WB Erroneous Data register was wrong") ;
3390
        ok = 0 ;
3391
    end
3392
 
3393
    if ( ok )
3394
        test_ok ;
3395
 
3396
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3397
    `ifdef HOST
3398
        repeat(4)
3399
            @(posedge wb_clock) ;
3400
        if ( INT_O !== 1 )
3401
        begin
3402
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3403
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3404
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3405
        end
3406
        else
3407
            test_ok ;
3408
    `else
3409
    `ifdef GUEST
3410
        repeat(4)
3411
            @(posedge pci_clock) ;
3412
        if ( INTA !== 0 )
3413
        begin
3414
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3415
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3416
            test_fail("interrupt request was not presented on PCI bus") ;
3417
        end
3418
        else
3419
            test_ok ;
3420
    `endif
3421
    `endif
3422
 
3423
    // read interrupt status register
3424
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3425
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3426
    if ( temp_val1[1] !== 1 )
3427
    begin
3428
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3429
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3430
        test_fail("Expected Interrupt status bit wasn't set") ;
3431
    end
3432
 
3433
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3434
 
3435
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3436
    ok = 1 ;
3437
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3438
    if ( temp_val1[29] !== 0 )
3439
    begin
3440
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3441
        $display("Received Master Abort bit was set with no reason!") ;
3442
        test_fail("Received Master Abort bit was set with no reason") ;
3443
        ok = 0 ;
3444
    end
3445
 
3446
    if ( temp_val1[28] !== 1 )
3447
    begin
3448
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3449
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3450
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3451
        ok = 0 ;
3452
    end
3453
 
3454
    if ( ok )
3455
        test_ok ;
3456
 
3457
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3458
 
3459
    // clear interrupts and errors
3460
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3461
    repeat( 3 )
3462
        @(posedge pci_clock) ;
3463
 
3464
    repeat( 2 )
3465
        @(posedge wb_clock) ;
3466
 
3467
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3468
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3469
    if ( temp_val1[1] !== 0 )
3470
    begin
3471
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3472
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3473
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3474
    end
3475
    else
3476
        test_ok ;
3477
 
3478
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3479
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3480
    if ( temp_val1[8] !== 0 )
3481
    begin
3482
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3483
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3484
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3485
    end
3486
 
3487
 
3488
    $display("Introducing Target Abort error to single read!") ;
3489
    // set read data
3490
    read_data`READ_ADDRESS = target_address + 8 ;
3491
    read_data`READ_SEL     = 4'hF ;
3492
 
3493
    // enable automatic retry handling
3494
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3495
    write_flags`WB_TRANSFER_CAB    = 0 ;
3496
 
3497
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3498
 
3499
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3500
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3501
 
3502
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3503
 
3504
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3505
    begin
3506
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3507
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3508
        $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) ;
3509
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3510
        disable main ;
3511
    end
3512
    else
3513
        test_ok ;
3514
 
3515
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3516
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3517
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3518
    if ( temp_val1[8] !== 0 )
3519
    begin
3520
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3521
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3522
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3523
    end
3524
    else
3525
        test_ok ;
3526
 
3527
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3528
    ok = 1 ;
3529
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3530
    if ( temp_val1[29] !== 0 )
3531
    begin
3532
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3533
        $display("Received Master Abort bit was set with no reason!") ;
3534
        test_fail("Received Master Abort bit was set with no reason") ;
3535
        ok = 0 ;
3536
    end
3537
 
3538
    if ( temp_val1[28] !== 1 )
3539
    begin
3540
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3541
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3542
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3543
        ok = 0 ;
3544
    end
3545
 
3546
    if ( ok )
3547
        test_ok ;
3548
 
3549
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3550
 
3551
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3552
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3553
    if ( temp_val1[1] !== 0 )
3554
    begin
3555
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3556
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3557
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3558
    end
3559
    else
3560
        test_ok ;
3561
 
3562
    $display("Introducing Target Abort error to CAB read!") ;
3563
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3564
 
3565
    for ( i = 0 ; i < 4 ; i = i + 1 )
3566
    begin
3567
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3568
        read_data`READ_SEL     = 4'b1010 ;
3569
        wishbone_master.blk_read_data_in[i] = read_data ;
3570
    end
3571
 
3572
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3573
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3574
    write_flags`WB_TRANSFER_CAB    = 1 ;
3575
 
3576
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3577
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3578
 
3579
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3580
 
3581
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3582
    begin
3583
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3584
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3585
        $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) ;
3586
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3587
        disable main ;
3588
    end
3589
 
3590
    read_status = wishbone_master.blk_read_data_out[0] ;
3591
    temp_val1 = read_status`READ_DATA ;
3592
    temp_val2 = wmem_data[120] ;
3593
 
3594
    // last write to this address was with only two byte enables - check only those
3595
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3596
    begin
3597
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3598
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3599
    end
3600
    else
3601
        test_ok ;
3602
 
3603
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3604
    ok = 1 ;
3605
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3606
    if ( temp_val1[29] !== 0 )
3607
    begin
3608
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3609
        $display("Received Master Abort bit was set with no reason!") ;
3610
        test_fail("Received Master Abort bit was set with no reason") ;
3611
        ok = 0 ;
3612
    end
3613
 
3614
    if ( temp_val1[28] !== 1 )
3615
    begin
3616
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3617
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3618
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3619
        ok = 0 ;
3620
    end
3621
 
3622
    if ( ok )
3623
       test_ok ;
3624
 
3625
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3626
 
3627
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3628
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3629
 
3630
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3631
    for ( i = 0 ; i < 3 ; i = i + 1 )
3632
    begin
3633
        read_data`READ_ADDRESS = target_address + 4*i ;
3634
        read_data`READ_SEL     = 4'b1111 ;
3635
        wishbone_master.blk_read_data_in[i] = read_data ;
3636
    end
3637
 
3638
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3639
 
3640
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3641
 
3642
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3643
    begin
3644
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3645
        $display("Complete burst read through WB slave didn't succeed!") ;
3646
        test_fail("bridge didn't process Burst Read in an expected way") ;
3647
        disable main ;
3648
    end
3649
    else
3650
        test_ok ;
3651
 
3652
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3653
 
3654
    for ( i = 0 ; i < 3 ; i = i + 1 )
3655
    begin
3656
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3657
        read_data`READ_SEL     = 4'b1111 ;
3658
        wishbone_master.blk_read_data_in[i] = read_data ;
3659
    end
3660
 
3661
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3662
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3663
    write_flags`WB_TRANSFER_CAB    = 1 ;
3664
 
3665
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3666
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3667
 
3668
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3669
 
3670
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3671
    begin
3672
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3673
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3674
        $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) ;
3675
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3676
        disable main ;
3677
    end
3678
 
3679
    for ( i = 0 ; i < 3 ; i = i + 1 )
3680
    begin
3681
        ok = 1 ;
3682
        read_status = wishbone_master.blk_read_data_out[i] ;
3683
        temp_val1 = read_status`READ_DATA ;
3684
        temp_val2 = wmem_data[120 + i] ;
3685
 
3686
        // last write to this address was with only two byte enables - check only those
3687
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3688
        begin
3689
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3690
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3691
            ok = 0 ;
3692
        end
3693
    end
3694
 
3695
    if ( ok )
3696
        test_ok ;
3697
 
3698
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3699
    ok = 1 ;
3700
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3701
    if ( temp_val1[29] !== 0 )
3702
    begin
3703
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3704
        $display("Received Master Abort bit was set with no reason!") ;
3705
        test_fail("Received Master Abort bit was set with no reason") ;
3706
        ok = 0 ;
3707
    end
3708
 
3709
    if ( temp_val1[28] !== 1 )
3710
    begin
3711
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3712
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3713
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3714
        ok = 0 ;
3715
    end
3716
 
3717
    if ( ok )
3718
       test_ok ;
3719
 
3720
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3721
 
3722
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3723
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3724
 
3725
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3726
    for ( i = 0 ; i < 3 ; i = i + 1 )
3727
    begin
3728
        read_data`READ_ADDRESS = target_address + 4*i ;
3729
        read_data`READ_SEL     = 4'b1111 ;
3730
        wishbone_master.blk_read_data_in[i] = read_data ;
3731
    end
3732
 
3733
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3734
 
3735
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3736
 
3737
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3738
    begin
3739
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3740
        $display("Complete burst read through WB slave didn't succeed!") ;
3741
        test_fail("bridge didn't process Burst Read in an expected way") ;
3742
        disable main ;
3743
    end
3744
    else
3745
        test_ok ;
3746
 
3747
    // test error on IO write
3748
    // change base address
3749
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3750
    write_data`WRITE_SEL     = 4'b0101 ;
3751
    write_data`WRITE_ADDRESS = target_address ;
3752
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3753
 
3754
    write_flags`WB_TRANSFER_CAB    = 0 ;
3755
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3756
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3757
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3758
    fork
3759
    begin
3760
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3761
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3762
        begin
3763
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3764
            $display("WB slave failed to accept IO write!") ;
3765
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3766
            disable main ;
3767
        end
3768
    end
3769
    begin
3770
        musnt_respond(ok) ;
3771
        if ( ok !== 1 )
3772
        begin
3773
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3774
            $display("Testbench is configured wrong!") ;
3775
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3776
        end
3777
        else
3778
            test_ok ;
3779
    end
3780
    join
3781
 
3782
    // check statuses and everything else
3783
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3784
    ok = 1 ;
3785
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3786
    if ( temp_val1[8] !== 1 )
3787
    begin
3788
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3789
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3790
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3791
        ok = 0 ;
3792
    end
3793
 
3794
    if ( temp_val1[9] !== 1 )
3795
    begin
3796
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3797
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3798
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3799
        ok = 0 ;
3800
    end
3801
 
3802
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3803
    begin
3804
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3805
        $display("Value in W_ERR_CS register was wrong!") ;
3806
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3807
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3808
        ok = 0 ;
3809
    end
3810
 
3811
    if ( ok )
3812
        test_ok ;
3813
 
3814
    // check erroneous address and data
3815
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3816
    ok = 1 ;
3817
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3818
    if ( temp_val1 !== target_address )
3819
    begin
3820
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3821
        $display("Value in W_ERR_ADDR register was wrong!") ;
3822
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
3823
        test_fail("WB Erroneous Address register didn't provide right value") ;
3824
        ok = 0 ;
3825
    end
3826
 
3827
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3828
    if ( temp_val1 !== 32'hAAAA_AAAA )
3829
    begin
3830
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3831
        $display("Value in W_ERR_DATA register was wrong!") ;
3832
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
3833
        test_fail("WB Erroneous Data register didn't provide right value") ;
3834
        ok = 0 ;
3835
    end
3836
 
3837
    if ( ok )
3838
        test_ok ;
3839
 
3840
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3841
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3842
    if ( temp_val1[1] !== 1 )
3843
    begin
3844
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3845
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3846
        test_fail("expected interrupt status bit was not set") ;
3847
    end
3848
    else
3849
        test_ok ;
3850
 
3851
    // clear interrupts and errors
3852
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3853
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3854
 
3855
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3856
    ok = 1 ;
3857
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3858
    if ( temp_val1[29] !== 1 )
3859
    begin
3860
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3861
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
3862
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
3863
        ok = 0 ;
3864
    end
3865
 
3866
    if ( temp_val1[28] !== 0 )
3867
    begin
3868
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3869
        $display("Received Target Abort bit was set for no reason!") ;
3870
        test_fail("Received Target Abort bit was set for no reason") ;
3871
        ok = 0 ;
3872
    end
3873
 
3874
    if ( ok )
3875
        test_ok ;
3876
 
3877
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3878
 
3879
    // disable image
3880
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
3881
    if ( ok !== 1 )
3882
    begin
3883
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3884
        test_fail("WB Image Address Mask register couldn't be written") ;
3885
        disable main ;
3886
    end
3887
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
3888
 
3889
end
3890
endtask
3891
 
3892
task parity_checking ;
3893
    reg   [11:0] ctrl_offset ;
3894
    reg   [11:0] ba_offset ;
3895
    reg   [11:0] am_offset ;
3896
    reg   [11:0] ta_offset ;
3897
    reg `WRITE_STIM_TYPE write_data ;
3898
    reg `READ_STIM_TYPE  read_data ;
3899
    reg `READ_RETURN_TYPE read_status ;
3900
 
3901
    reg `WRITE_RETURN_TYPE write_status ;
3902
    reg `WB_TRANSFER_FLAGS write_flags ;
3903
    reg [31:0] temp_val1 ;
3904
    reg [31:0] temp_val2 ;
3905
    reg        ok   ;
3906
    reg [11:0] pci_ctrl_offset ;
3907
    reg [31:0] image_base ;
3908
    reg [31:0] target_address ;
3909
    reg [11:0] icr_offset ;
3910
    reg [11:0] isr_offset ;
3911
    reg [11:0] p_ba_offset ;
3912
    reg [11:0] p_am_offset ;
3913
    reg [11:0] p_ctrl_offset ;
3914
    integer    i ;
3915
    reg        perr_asserted ;
3916
begin:main
3917
    $display("******************************* Testing Parity Checker functions ********************************") ;
3918
    $display("Testing Parity Errors during Master Transactions!") ;
3919
    $display("Introducing Parity Erros to Master Writes!") ;
3920
    $fdisplay(pci_mon_log_file_desc,
3921
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
3922
 
3923
    // image 1 is used for error testing, since it is always implemented
3924
    pci_ctrl_offset = 12'h004 ;
3925
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
3926
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
3927
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
3928
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
3929
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
3930
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
3931
 
3932
    // image 1 for PCI target
3933
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
3934
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
3935
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
3936
 
3937
    target_address  = `BEH_TAR1_MEM_START ;
3938
    image_base      = 0 ;
3939
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
3940
 
3941
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
3942
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
3943
    write_flags                    = 0 ;
3944
    write_flags`INIT_WAITS         = tb_init_waits ;
3945
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
3946
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3947
 
3948
    // enable master & target operation and disable parity functions
3949
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
3950
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
3951
    if ( ok !== 1 )
3952
    begin
3953
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
3954
        test_fail("PCI Device Control register could not be written to") ;
3955
        disable main ;
3956
    end
3957
 
3958
    // prepare image control register
3959
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
3960
    if ( ok !== 1 )
3961
    begin
3962
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
3963
        test_fail("WB Image Control register could not be written to") ;
3964
        disable main ;
3965
    end
3966
 
3967
    // prepare base address register
3968
    config_write( ba_offset, image_base, 4'hF, ok ) ;
3969
    if ( ok !== 1 )
3970
    begin
3971
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
3972
        test_fail("WB Image Base Address register could not be written to") ;
3973
        disable main ;
3974
    end
3975
 
3976
    // write address mask register
3977
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
3978
    if ( ok !== 1 )
3979
    begin
3980
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3981
        test_fail("WB Image Address Mask register could not be written to") ;
3982
        disable main ;
3983
    end
3984
 
3985
    // disable parity interrupts
3986
    config_write( icr_offset, 0, 4'hF, ok ) ;
3987
    if ( ok !== 1 )
3988
    begin
3989
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
3990
        test_fail("Interrupt Control register could not be written to") ;
3991
        disable main ;
3992
    end
3993
 
3994
    write_data`WRITE_ADDRESS = target_address ;
3995
    write_data`WRITE_DATA    = wmem_data[0] ;
3996
    write_data`WRITE_SEL     = 4'b1111 ;
3997
 
3998
    // enable target's 1 response to parity errors
3999
    configuration_cycle_write(0,             // bus number
4000
                              1,             // device number
4001
                              0,             // function number
4002
                              1,             // register number
4003
                              0,             // type of configuration cycle
4004
                              4'b0001,       // byte enables
4005
                              32'h0000_0047  // data
4006
                             ) ;
4007
 
4008
    // disable target's 2 response to parity errors
4009
    configuration_cycle_write(0,             // bus number
4010
                              2,             // device number
4011
                              0,             // function number
4012
                              1,             // register number
4013
                              0,             // type of configuration cycle
4014
                              4'b0001,       // byte enables
4015
                              32'h0000_0007  // data
4016
                             ) ;
4017
 
4018
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4019
 
4020
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4021
    fork
4022
    begin
4023
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4024
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4025
        begin
4026
            $display("Parity checker testing failed! Time %t ", $time) ;
4027
            $display("Bridge failed to process single memory write!") ;
4028
            test_fail("bridge failed to post single WB memory write") ;
4029
            disable main ;
4030
        end
4031
    end
4032
    begin:wait_perr1
4033
        perr_asserted = 0 ;
4034
        @(posedge pci_clock) ;
4035
 
4036
        while ( PERR === 1 )
4037
            @(posedge pci_clock) ;
4038
 
4039
        if ( PERR === 0 )
4040
            perr_asserted = 1 ;
4041
 
4042
    end
4043
    begin
4044
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4045
 
4046
        if ( ok !== 1 )
4047
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4048
 
4049
        repeat(3)
4050
            @(posedge pci_clock) ;
4051
 
4052
        disable wait_perr1 ;
4053
    end
4054
    join
4055
 
4056
    if ( perr_asserted && ok )
4057
    begin
4058
        test_ok ;
4059
    end
4060
    else
4061
    if ( ~perr_asserted )
4062
    begin
4063
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4064
        disable main ;
4065
    end
4066
 
4067
    // check all the statuses - if HOST is defined, wait for them to be synced
4068
    `ifdef HOST
4069
    repeat(4)
4070
        @(posedge wb_clock) ;
4071
    `endif
4072
 
4073
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4074
    ok = 1 ;
4075
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4076
    if ( temp_val1[31] !== 1 )
4077
    begin
4078
        $display("Parity checker testing failed! Time %t ", $time) ;
4079
        $display("Detected Parity Error bit was not set after parity error on PCI bus!") ;
4080
        test_fail("Detected Parity Error bit was not set after Write Master Data Parity Error") ;
4081
        ok = 0 ;
4082
    end
4083
 
4084
    if ( temp_val1[30] !== 0 )
4085
    begin
4086
        $display("Parity checker testing failed! Time %t ", $time) ;
4087
        $display("Signalled System Error bit was set for no reason!") ;
4088
        test_fail("Signalled System Error bit was set for no reason") ;
4089
        ok = 0 ;
4090
    end
4091
 
4092
    if ( temp_val1[24] !== 0 )
4093
    begin
4094
        $display("Parity checker testing failed! Time %t ", $time) ;
4095
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4096
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4097
        ok = 0 ;
4098
    end
4099
 
4100
    if ( ok )
4101
        test_ok ;
4102
 
4103
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4104
    // clear parity bits and enable parity response
4105
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4106
    if ( ok !== 1 )
4107
    begin
4108
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4109
        test_fail("write to PCI Status Register failed") ;
4110
        disable main ;
4111
    end
4112
 
4113
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4114
    fork
4115
    begin
4116
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4117
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4118
        begin
4119
            $display("Parity checker testing failed! Time %t ", $time) ;
4120
            $display("Bridge failed to process single memory write!") ;
4121
            test_fail("bridge failed to post single memory write") ;
4122
            disable main ;
4123
        end
4124
    end
4125
    begin:wait_perr2
4126
        perr_asserted = 0 ;
4127
        @(posedge pci_clock) ;
4128
 
4129
        while ( PERR === 1 )
4130
            @(posedge pci_clock) ;
4131
 
4132
        if ( PERR === 0 )
4133
            perr_asserted = 1 ;
4134
 
4135
    end
4136
    begin
4137
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4138
 
4139
        if ( ok !== 1 )
4140
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4141
 
4142
        repeat(3)
4143
            @(posedge pci_clock) ;
4144
 
4145
        disable wait_perr2 ;
4146
    end
4147
    join
4148
 
4149
    if ( perr_asserted && ok )
4150
    begin
4151
        test_ok ;
4152
    end
4153
    else
4154
    if ( ~perr_asserted )
4155
    begin
4156
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4157
        disable main ;
4158
    end
4159
 
4160
    // check all the statuses - if HOST is defined, wait for them to be synced
4161
    `ifdef HOST
4162
    repeat(4)
4163
        @(posedge wb_clock) ;
4164
    `endif
4165
 
4166
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4167
    ok = 1 ;
4168
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4169
    if ( temp_val1[31] !== 1 )
4170
    begin
4171
        $display("Parity checker testing failed! Time %t ", $time) ;
4172
        $display("Detected Parity Error bit was not set after parity error on PCI bus!") ;
4173
        test_fail("Detected Parity Error bit was not set after parity error on PCI bus") ;
4174
        ok = 0 ;
4175
    end
4176
 
4177
    if ( temp_val1[30] !== 0 )
4178
    begin
4179
        $display("Parity checker testing failed! Time %t ", $time) ;
4180
        $display("Signalled System Error bit was set for no reason!") ;
4181
        test_fail("Signalled System Error bit was set for no reason") ;
4182
        ok = 0 ;
4183
    end
4184
 
4185
    if ( temp_val1[24] !== 1 )
4186
    begin
4187
        $display("Parity checker testing failed! Time %t ", $time) ;
4188
        $display("Master Data Parity Error bit wasn't set even though Parity Error Response bit was set!") ;
4189
        test_fail("Master Data Parity Error bit wasn't set after Parity Error on PCI bus, even though Parity Error Response bit was set") ;
4190
        ok = 0 ;
4191
    end
4192
 
4193
    if ( ok )
4194
        test_ok ;
4195
 
4196
    // clear status bits and disable parity error response
4197
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4198
 
4199
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4200
 
4201
    // disable perr generation and perform a write - no bits should be set
4202
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4203
    fork
4204
    begin
4205
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4206
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4207
        begin
4208
            $display("Parity checker testing failed! Time %t ", $time) ;
4209
            $display("Bridge failed to process single memory write!") ;
4210
            test_fail("bridge failed to post single memory write") ;
4211
            disable main ;
4212
        end
4213
    end
4214
    begin
4215
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4216
 
4217
        if ( ok !== 1 )
4218
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4219
        else
4220
            test_ok ;
4221
 
4222
        repeat(3)
4223
            @(posedge pci_clock) ;
4224
    end
4225
    join
4226
 
4227
    `ifdef HOST
4228
    repeat(4)
4229
        @(posedge wb_clock) ;
4230
    `endif
4231
 
4232
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4233
    ok = 1 ;
4234
 
4235
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4236
    if ( temp_val1[31] !== 0 )
4237
    begin
4238
        $display("Parity checker testing failed! Time %t ", $time) ;
4239
        $display("Detected Parity Error bit was set for no reason!") ;
4240
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4241
        ok = 0 ;
4242
    end
4243
 
4244
    if ( temp_val1[30] !== 0 )
4245
    begin
4246
        $display("Parity checker testing failed! Time %t ", $time) ;
4247
        $display("Signalled System Error bit was set for no reason!") ;
4248
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4249
        ok = 0 ;
4250
    end
4251
 
4252
    if ( temp_val1[24] !== 0 )
4253
    begin
4254
        $display("Parity checker testing failed! Time %t ", $time) ;
4255
        $display("Master Data Parity Error bit was set for no reason!") ;
4256
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4257
        ok = 0 ;
4258
    end
4259
 
4260
    if ( ok )
4261
        test_ok ;
4262
 
4263
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4264
 
4265
    read_data = 0 ;
4266
    read_data`READ_ADDRESS  = target_address ;
4267
    read_data`READ_SEL      = 4'hF ;
4268
    read_data`READ_TAG_STIM = 0 ;
4269
 
4270
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4271
 
4272
    // enable parity and system error interrupts
4273
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4274
 
4275
    // enable parity error response
4276
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4277
 
4278
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4279
 
4280
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4281
    fork
4282
    begin
4283
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4284
    end
4285
    begin:wait_perr4
4286
        perr_asserted = 0 ;
4287
        @(posedge pci_clock) ;
4288
        while ( PERR === 1 )
4289
            @(posedge pci_clock) ;
4290
 
4291
        if ( PERR === 0 )
4292
            perr_asserted = 1 ;
4293
 
4294
    end
4295
    begin
4296
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4297
 
4298
        if ( ok !== 1 )
4299
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4300
 
4301
        repeat(2)
4302
            @(posedge pci_clock) ;
4303
 
4304
        disable wait_perr4 ;
4305
    end
4306
    join
4307
 
4308
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4309
    begin
4310
        $display("Parity checker testing failed! Time %t ", $time) ;
4311
        $display("Bridge failed to process single memory read!") ;
4312
        test_fail("bridge didn't process single memory read correctly") ;
4313
        ok = 0 ;
4314
    end
4315
 
4316
    if ( perr_asserted && ok )
4317
    begin
4318
        test_ok ;
4319
    end
4320
    else
4321
    if ( ~perr_asserted )
4322
    begin
4323
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4324
        disable main ;
4325
    end
4326
 
4327
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4328
    // interrupt should also be present
4329
    `ifdef HOST
4330
        repeat(4)
4331
            @(posedge wb_clock) ;
4332
 
4333
        if ( INT_O !== 1 )
4334
        begin
4335
            $display("Parity checker testing failed! Time %t ", $time) ;
4336
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4337
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4338
        end
4339
        else
4340
            test_ok ;
4341
    `else
4342
    `ifdef GUEST
4343
        repeat( 4 )
4344
            @(posedge pci_clock) ;
4345
 
4346
        if ( INTA !== 1 )
4347
        begin
4348
            $display("Parity checker testing failed! Time %t ", $time) ;
4349
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4350
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4351
        end
4352
        else
4353
            test_ok ;
4354
    `endif
4355
    `endif
4356
 
4357
    // check statuses!
4358
 
4359
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4360
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4361
    ok = 1 ;
4362
 
4363
    if ( temp_val1[31] !== 1 )
4364
    begin
4365
        $display("Parity checker testing failed! Time %t ", $time) ;
4366
        $display("Detected Parity Error bit was not set when parity error was presented on Read transaction!") ;
4367
        test_fail("Detected Parity Error bit was not set when parity error was presented on Read transaction") ;
4368
        ok = 0 ;
4369
    end
4370
 
4371
    if ( temp_val1[30] !== 0 )
4372
    begin
4373
        $display("Parity checker testing failed! Time %t ", $time) ;
4374
        $display("Signalled System Error bit was set for no reason!") ;
4375
        test_fail("Signalled System Error bit was set for no reason") ;
4376
        ok = 0 ;
4377
    end
4378
 
4379
    if ( temp_val1[24] !== 1 )
4380
    begin
4381
        $display("Parity checker testing failed! Time %t ", $time) ;
4382
        $display("Master Data Parity Error bit was not set when parity error was presented during read transaction!") ;
4383
        test_fail("Master Data Parity Error bit was not set when parity error was presented during read transaction and Parity Error Response was enabled") ;
4384
        ok = 0 ;
4385
    end
4386
 
4387
    if ( ok )
4388
        test_ok ;
4389
 
4390
    // clear statuses and disable parity error response
4391
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4392
 
4393
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4394
    ok = 1 ;
4395
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4396
 
4397
    if ( temp_val1[4] !== 0 )
4398
    begin
4399
        $display("Parity checker testing failed! Time %t ", $time) ;
4400
        $display("System error interrupt status bit set for no reason!") ;
4401
        test_fail("System error interrupt status bit set for no reason") ;
4402
        ok = 0 ;
4403
    end
4404
 
4405
    `ifdef HOST
4406
    if ( temp_val1[3] !== 1 )
4407
    begin
4408
        $display("Parity checker testing failed! Time %t ", $time) ;
4409
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4410
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4411
        ok = 0 ;
4412
    end
4413
    `else
4414
    if ( temp_val1[3] !== 0 )
4415
    begin
4416
        $display("Parity checker testing failed! Time %t ", $time) ;
4417
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4418
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4419
        ok = 0 ;
4420
    end
4421
    `endif
4422
 
4423
    if ( ok )
4424
        test_ok ;
4425
 
4426
    // clear int statuses
4427
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4428
 
4429
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4430
 
4431
    `ifdef HOST
4432
        repeat(4)
4433
            @(posedge wb_clock) ;
4434
 
4435
        if ( INT_O !== 0 )
4436
        begin
4437
            $display("Parity checker testing failed! Time %t ", $time) ;
4438
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4439
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4440
        end
4441
        else
4442
            test_ok ;
4443
    `else
4444
    `ifdef GUEST
4445
        repeat( 4 )
4446
            @(posedge pci_clock) ;
4447
 
4448
        if ( INTA !== 1 )
4449
        begin
4450
            $display("Parity checker testing failed! Time %t ", $time) ;
4451
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4452
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4453
        end
4454
        else
4455
            test_ok ;
4456
    `endif
4457
    `endif
4458
 
4459
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4460
 
4461
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4462
    fork
4463
    begin
4464
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4465
    end
4466
    begin:wait_perr5
4467
        perr_asserted = 0 ;
4468
        @(posedge pci_clock) ;
4469
        while ( PERR === 1 )
4470
            @(posedge pci_clock) ;
4471
 
4472
        perr_asserted = 1 ;
4473
        $display("Parity checker testing failed! Time %t ", $time) ;
4474
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4475
        test_fail("Bridge asserted PERR during read transaction when Parity Error response was disabled") ;
4476
    end
4477
    begin
4478
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4479
        if ( ok !== 1 )
4480
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4481
 
4482
        // perr can be asserted on idle or next PCI address phase
4483
        repeat(2)
4484
            @(posedge pci_clock) ;
4485
 
4486
        disable wait_perr5 ;
4487
    end
4488
    join
4489
 
4490
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4491
    begin
4492
        $display("Parity checker testing failed! Time %t ", $time) ;
4493
        $display("Bridge failed to process single memory read!") ;
4494
        test_fail("bridge failed to process single memory read correctly") ;
4495
        ok = 0 ;
4496
    end
4497
 
4498
    if ( ok && !perr_asserted)
4499
        test_ok ;
4500
 
4501
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4502
 
4503
    // interrupts should not be present
4504
    `ifdef HOST
4505
        repeat( 4 )
4506
            @(posedge wb_clock) ;
4507
        if ( INT_O !== 0 )
4508
        begin
4509
            $display("Parity checker testing failed! Time %t ", $time) ;
4510
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4511
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4512
        end
4513
        else
4514
            test_ok ;
4515
    `else
4516
    `ifdef GUEST
4517
        repeat( 4 )
4518
            @(posedge pci_clock) ;
4519
        if ( INTA !== 1 )
4520
        begin
4521
            $display("Parity checker testing failed! Time %t ", $time) ;
4522
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4523
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4524
        end
4525
        else
4526
            test_ok ;
4527
    `endif
4528
    `endif
4529
 
4530
    // check statuses!
4531
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4532
    ok = 1 ;
4533
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4534
    if ( temp_val1[31] !== 1 )
4535
    begin
4536
        $display("Parity checker testing failed! Time %t ", $time) ;
4537
        $display("Detected Parity Error bit was not set when parity error was presented on Read transaction!") ;
4538
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4539
        ok = 0 ;
4540
    end
4541
 
4542
    if ( temp_val1[30] !== 0 )
4543
    begin
4544
        $display("Parity checker testing failed! Time %t ", $time) ;
4545
        $display("Signalled System Error bit was set for no reason!") ;
4546
        test_fail("Signalled System Error bit was set for no reason") ;
4547
        ok = 0 ;
4548
    end
4549
 
4550
    if ( temp_val1[24] !== 0 )
4551
    begin
4552
        $display("Parity checker testing failed! Time %t ", $time) ;
4553
        $display("Master Data Parity Error bit was set when parity error was presented during read transaction, but Parity Response was disabled!") ;
4554
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4555
        ok = 0 ;
4556
    end
4557
 
4558
    if ( ok )
4559
        test_ok ;
4560
 
4561
    // clear statuses
4562
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4563
 
4564
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4565
    ok = 1 ;
4566
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4567
 
4568
    if ( temp_val1[4] !== 0 )
4569
    begin
4570
        $display("Parity checker testing failed! Time %t ", $time) ;
4571
        $display("System error interrupt status bit set for no reason!") ;
4572
        test_fail("System error interrupt status bit set for no reason") ;
4573
        ok = 0 ;
4574
    end
4575
 
4576
    if ( temp_val1[3] !== 0 )
4577
    begin
4578
        $display("Parity checker testing failed! Time %t ", $time) ;
4579
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4580
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4581
        ok = 0 ;
4582
    end
4583
 
4584
    if ( ok )
4585
        test_ok ;
4586
 
4587
    // enable all responses to parity errors!
4588
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4589
 
4590
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4591
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4592
 
4593
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4594
 
4595
    // repeat a read
4596
    fork
4597
    begin
4598
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4599
    end
4600
    begin:wait_perr6
4601
        perr_asserted = 0 ;
4602
        @(posedge pci_clock) ;
4603
        while ( PERR === 1 )
4604
            @(posedge pci_clock) ;
4605
 
4606
        perr_asserted = 1 ;
4607
        $display("Parity checker testing failed! Time %t ", $time) ;
4608
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4609
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4610
    end
4611
    begin
4612
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4613
        if ( ok !== 1 )
4614
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4615
 
4616
        repeat(2)
4617
            @(posedge pci_clock) ;
4618
 
4619
        disable wait_perr6 ;
4620
    end
4621
    join
4622
 
4623
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4624
    begin
4625
        $display("Parity checker testing failed! Time %t ", $time) ;
4626
        $display("Bridge failed to process single memory read!") ;
4627
        test_fail("bridge didn't process single memory read as expected") ;
4628
        ok = 0 ;
4629
    end
4630
 
4631
    if ( ok && !perr_asserted)
4632
        test_ok ;
4633
 
4634
    // check statuses!
4635
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4636
    ok = 1 ;
4637
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4638
    if ( temp_val1[31] !== 0 )
4639
    begin
4640
        $display("Parity checker testing failed! Time %t ", $time) ;
4641
        $display("Detected Parity Error bit was set for no reason!") ;
4642
        test_fail("Detected Parity Error bit was set for no reason") ;
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
        $display("Master Data Parity Error bit was set for no reason!") ;
4658
        test_fail("Master Data Parity Error bit was set for no reason") ;
4659
        ok = 0 ;
4660
    end
4661
 
4662
    if ( ok )
4663
        test_ok ;
4664
 
4665
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4666
    ok = 1 ;
4667
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4668
 
4669
    if ( temp_val1[4] !== 0 )
4670
    begin
4671
        $display("Parity checker testing failed! Time %t ", $time) ;
4672
        $display("System error interrupt status bit set for no reason!") ;
4673
        test_fail("System error interrupt status bit set for no reason") ;
4674
        ok = 0 ;
4675
    end
4676
 
4677
    if ( temp_val1[3] !== 0 )
4678
    begin
4679
        $display("Parity checker testing failed! Time %t ", $time) ;
4680
        $display("Parity error interrupt status bit set for no reason!") ;
4681
        test_fail("Parity error interrupt status bit set for no reason") ;
4682
        ok = 0 ;
4683
    end
4684
 
4685
    if ( ok )
4686
        test_ok ;
4687
 
4688
    $display("Presenting address parity error on PCI bus!") ;
4689
    // enable parity errors - this should not affect system errors
4690
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4691
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4692
 
4693
    // perform PCI write
4694
    // check transaction progress
4695
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4696
    fork
4697
    begin
4698
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4699
               target_address, 32'h1234_5678,
4700
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4701
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4702
        do_pause( 1 ) ;
4703
    end
4704
    begin:wait_serr7
4705
        perr_asserted = 0 ;
4706
        @(posedge pci_clock) ;
4707
        while( SERR === 1 )
4708
            @(posedge pci_clock) ;
4709
 
4710
        perr_asserted = 1 ;
4711
        $display("Parity checker testing failed! Time %t ", $time) ;
4712
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4713
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4714
    end
4715
    begin
4716
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4717
        if ( ok !== 1 )
4718
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4719
 
4720
        disable wait_serr7 ;
4721
    end
4722
    join
4723
 
4724
    if ( ok && !perr_asserted)
4725
        test_ok ;
4726
 
4727
    // check statuses!
4728
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4729
    ok = 1 ;
4730
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4731
    if ( temp_val1[31] !== 1 )
4732
    begin
4733
        $display("Parity checker testing failed! Time %t ", $time) ;
4734
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4735
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4736
        ok = 0 ;
4737
    end
4738
 
4739
    if ( temp_val1[30] !== 0 )
4740
    begin
4741
        $display("Parity checker testing failed! Time %t ", $time) ;
4742
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4743
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4744
        ok = 0 ;
4745
    end
4746
 
4747
    if ( temp_val1[24] !== 0 )
4748
    begin
4749
        $display("Parity checker testing failed! Time %t ", $time) ;
4750
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4751
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4752
        ok = 0 ;
4753
    end
4754
 
4755
    if ( ok )
4756
        test_ok ;
4757
 
4758
    // clear statuses
4759
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4760
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4761
    fork
4762
    begin
4763
        ipci_unsupported_commands_master.master_reference
4764
        (
4765
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4766
            32'h5555_5555,      // second part of address in dual address cycle
4767
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4768
            `BC_MEM_WRITE,      // normal command
4769
            4'h0,               // byte enables
4770
            32'h1234_5678,      // data
4771
            1'b1,               // make address parity error on first phase of dual address
4772
            1'b0,               // make address parity error on second phase of dual address
4773
            ok                  // result of operation
4774
        ) ;
4775
        disable wait_serr8 ;
4776
    end
4777
    begin:wait_serr8
4778
        perr_asserted = 0 ;
4779
        @(posedge pci_clock) ;
4780
        while( SERR === 1 )
4781
            @(posedge pci_clock) ;
4782
 
4783
        perr_asserted = 1 ;
4784
        $display("Parity checker testing failed! Time %t ", $time) ;
4785
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4786
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4787
    end
4788
    join
4789
 
4790
    if ( ok && !perr_asserted)
4791
        test_ok ;
4792
 
4793
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4794
    fork
4795
    begin
4796
        ipci_unsupported_commands_master.master_reference
4797
        (
4798
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4799
            32'h5555_5555,      // second part of address in dual address cycle
4800
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4801
            `BC_MEM_WRITE,      // normal command
4802
            4'h0,               // byte enables
4803
            32'h1234_5678,      // data
4804
            1'b0,               // make address parity error on first phase of dual address
4805
            1'b1,               // make address parity error on second phase of dual address
4806
            ok                  // result of operation
4807
        ) ;
4808
        disable wait_serr9 ;
4809
    end
4810
    begin:wait_serr9
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
    join
4822
 
4823
    if ( ok && !perr_asserted)
4824
        test_ok ;
4825
 
4826
    // check statuses!
4827
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4828
    ok = 1 ;
4829
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4830
    if ( temp_val1[31] !== 1 )
4831
    begin
4832
        $display("Parity checker testing failed! Time %t ", $time) ;
4833
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4834
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4835
        ok = 0 ;
4836
    end
4837
 
4838
    if ( temp_val1[30] !== 0 )
4839
    begin
4840
        $display("Parity checker testing failed! Time %t ", $time) ;
4841
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4842
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4843
        ok = 0 ;
4844
    end
4845
 
4846
    if ( temp_val1[24] !== 0 )
4847
    begin
4848
        $display("Parity checker testing failed! Time %t ", $time) ;
4849
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4850
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4851
        ok = 0 ;
4852
    end
4853
 
4854
    if ( ok )
4855
        test_ok ;
4856
 
4857
    // clear statuses
4858
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4859
 
4860
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4861
    fork
4862
    begin
4863
        ipci_unsupported_commands_master.master_reference
4864
        (
4865
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4866
            32'h5555_5555,      // second part of address in dual address cycle
4867
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4868
            `BC_MEM_WRITE,      // normal command
4869
            4'h0,               // byte enables
4870
            32'h1234_5678,      // data
4871
            1'b1,               // make address parity error on first phase of dual address
4872
            1'b1,               // make address parity error on second phase of dual address
4873
            ok                  // result of operation
4874
        ) ;
4875
        disable wait_serr10 ;
4876
    end
4877
    begin:wait_serr10
4878
        perr_asserted = 0 ;
4879
        @(posedge pci_clock) ;
4880
        while( SERR === 1 )
4881
            @(posedge pci_clock) ;
4882
 
4883
        perr_asserted = 1 ;
4884
        $display("Parity checker testing failed! Time %t ", $time) ;
4885
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4886
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4887
    end
4888
    join
4889
 
4890
    if ( ok && !perr_asserted)
4891
        test_ok ;
4892
 
4893
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
4894
 
4895
    `ifdef HOST
4896
        repeat(4)
4897
            @(posedge wb_clock) ;
4898
        if ( INT_O !== 0 )
4899
        begin
4900
            $display("Parity checker testing failed! Time %t ", $time) ;
4901
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
4902
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
4903
        end
4904
        else
4905
            test_ok ;
4906
    `else
4907
    `ifdef GUEST
4908
        repeat( 4 )
4909
            @(posedge pci_clock) ;
4910
 
4911
        if ( INTA !== 1 )
4912
        begin
4913
            $display("Parity checker testing failed! Time %t ", $time) ;
4914
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
4915
            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") ;
4916
        end
4917
        else
4918
            test_ok ;
4919
    `endif
4920
    `endif
4921
 
4922
    // check statuses!
4923
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4924
    ok = 1 ;
4925
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4926
    if ( temp_val1[31] !== 1 )
4927
    begin
4928
        $display("Parity checker testing failed! Time %t ", $time) ;
4929
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4930
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4931
        ok = 0 ;
4932
    end
4933
 
4934
    if ( temp_val1[30] !== 0 )
4935
    begin
4936
        $display("Parity checker testing failed! Time %t ", $time) ;
4937
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4938
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4939
        ok = 0 ;
4940
    end
4941
 
4942
    if ( temp_val1[24] !== 0 )
4943
    begin
4944
        $display("Parity checker testing failed! Time %t ", $time) ;
4945
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4946
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4947
        ok = 0 ;
4948
    end
4949
 
4950
    if ( ok )
4951
        test_ok ;
4952
 
4953
    // clear statuses
4954
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4955
 
4956
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4957
    ok = 1 ;
4958
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4959
 
4960
    if ( temp_val1[4] !== 0 )
4961
    begin
4962
        $display("Parity checker testing failed! Time %t ", $time) ;
4963
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
4964
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
4965
        ok = 0 ;
4966
    end
4967
 
4968
    if ( temp_val1[3] !== 0 )
4969
    begin
4970
        $display("Parity checker testing failed! Time %t ", $time) ;
4971
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
4972
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
4973
        ok = 0 ;
4974
    end
4975
 
4976
    if ( ok )
4977
        test_ok ;
4978
 
4979
    // now enable system error signaling and test response
4980
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
4981
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4982
 
4983
    fork
4984
    begin
4985
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4986
               target_address, 32'h1234_5678,
4987
               1, 8'h7_0, `Test_One_Zero_Target_WS,
4988
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4989
        do_pause( 1 ) ;
4990
    end
4991
    begin:wait_serr11
4992
        perr_asserted = 0 ;
4993
        @(posedge pci_clock) ;
4994
        while( SERR === 1 )
4995
            @(posedge pci_clock) ;
4996
 
4997
        if ( SERR === 0 )
4998
            perr_asserted = 1 ;
4999
    end
5000
    begin
5001
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5002
        if ( ok !== 1 )
5003
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5004
 
5005
        @(posedge pci_clock) ;
5006
        #2 ;
5007
        disable wait_serr11 ;
5008
    end
5009
    join
5010
 
5011
    if ( ok && perr_asserted)
5012
        test_ok ;
5013
    else
5014
    if ( !perr_asserted )
5015
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5016
 
5017
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5018
 
5019
    `ifdef HOST
5020
        repeat(4)
5021
            @(posedge wb_clock) ;
5022
        if ( INT_O !== 1 )
5023
        begin
5024
            $display("Parity checker testing failed! Time %t ", $time) ;
5025
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5026
            test_fail("Interrupt Request was not triggered as expected") ;
5027
        end
5028
        else
5029
            test_ok ;
5030
    `else
5031
    `ifdef GUEST
5032
        repeat( 4 )
5033
            @(posedge pci_clock) ;
5034
 
5035
        if ( INTA !== 1 )
5036
        begin
5037
            $display("Parity checker testing failed! Time %t ", $time) ;
5038
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5039
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5040
        end
5041
        else
5042
            test_ok ;
5043
    `endif
5044
    `endif
5045
 
5046
    // check statuses!
5047
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5048
    ok = 1 ;
5049
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5050
    if ( temp_val1[31] !== 1 )
5051
    begin
5052
        $display("Parity checker testing failed! Time %t ", $time) ;
5053
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5054
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5055
        ok = 0 ;
5056
    end
5057
 
5058
    if ( temp_val1[30] !== 1 )
5059
    begin
5060
        $display("Parity checker testing failed! Time %t ", $time) ;
5061
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5062
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5063
        ok = 0 ;
5064
    end
5065
 
5066
    if ( temp_val1[24] !== 0 )
5067
    begin
5068
        $display("Parity checker testing failed! Time %t ", $time) ;
5069
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5070
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5071
        ok = 0 ;
5072
    end
5073
 
5074
    if ( ok )
5075
        test_ok ;
5076
 
5077
    // clear statuses
5078
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5079
 
5080
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5081
 
5082
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5083
    ok = 1 ;
5084
 
5085
    `ifdef HOST
5086
    if ( temp_val1[4] !== 1 )
5087
    begin
5088
        $display("Parity checker testing failed! Time %t ", $time) ;
5089
        $display("System error interrupt status bit not set when expected!") ;
5090
        test_fail("System error interrupt status bit not set when expected") ;
5091
        ok = 0 ;
5092
    end
5093
    `else
5094
    if ( temp_val1[4] !== 0 )
5095
    begin
5096
        $display("Parity checker testing failed! Time %t ", $time) ;
5097
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5098
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5099
        ok = 0 ;
5100
    end
5101
    `endif
5102
 
5103
    if ( temp_val1[3] !== 0 )
5104
    begin
5105
        $display("Parity checker testing failed! Time %t ", $time) ;
5106
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5107
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5108
        ok = 0 ;
5109
    end
5110
 
5111
    if ( ok )
5112
        test_ok ;
5113
 
5114
    // clear statuses
5115
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5116
 
5117
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5118
    fork
5119
    begin
5120
        ipci_unsupported_commands_master.master_reference
5121
        (
5122
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5123
            32'h5555_5555,      // second part of address in dual address cycle
5124
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5125
            `BC_MEM_WRITE,      // normal command
5126
            4'h0,               // byte enables
5127
            32'h1234_5678,      // data
5128
            1'b1,               // make address parity error on first phase of dual address
5129
            1'b0,               // make address parity error on second phase of dual address
5130
            ok                  // result of operation
5131
        ) ;
5132
        disable wait_serr14 ;
5133
    end
5134
    begin:wait_serr14
5135
        perr_asserted = 0 ;
5136
        @(posedge pci_clock) ;
5137
        while( SERR === 1 )
5138
            @(posedge pci_clock) ;
5139
 
5140
        if ( SERR === 0 )
5141
            perr_asserted = 1 ;
5142
    end
5143
    join
5144
 
5145
    if ( ok && perr_asserted)
5146
        test_ok ;
5147
    else
5148
    if ( !perr_asserted )
5149
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5150
 
5151
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5152
 
5153
    `ifdef HOST
5154
        repeat(4)
5155
            @(posedge wb_clock) ;
5156
        if ( INT_O !== 1 )
5157
        begin
5158
            $display("Parity checker testing failed! Time %t ", $time) ;
5159
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5160
            test_fail("Interrupt Request was not triggered as expected") ;
5161
        end
5162
        else
5163
            test_ok ;
5164
    `else
5165
    `ifdef GUEST
5166
        repeat( 4 )
5167
            @(posedge pci_clock) ;
5168
 
5169
        if ( INTA !== 1 )
5170
        begin
5171
            $display("Parity checker testing failed! Time %t ", $time) ;
5172
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5173
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5174
        end
5175
        else
5176
            test_ok ;
5177
    `endif
5178
    `endif
5179
 
5180
    // check statuses!
5181
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5182
    ok = 1 ;
5183
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5184
    if ( temp_val1[31] !== 1 )
5185
    begin
5186
        $display("Parity checker testing failed! Time %t ", $time) ;
5187
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5188
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5189
        ok = 0 ;
5190
    end
5191
 
5192
    if ( temp_val1[30] !== 1 )
5193
    begin
5194
        $display("Parity checker testing failed! Time %t ", $time) ;
5195
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5196
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5197
        ok = 0 ;
5198
    end
5199
 
5200
    if ( temp_val1[24] !== 0 )
5201
    begin
5202
        $display("Parity checker testing failed! Time %t ", $time) ;
5203
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5204
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5205
        ok = 0 ;
5206
    end
5207
 
5208
    if ( ok )
5209
        test_ok ;
5210
 
5211
    // clear statuses
5212
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5213
 
5214
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5215
 
5216
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5217
    ok = 1 ;
5218
 
5219
    `ifdef HOST
5220
    if ( temp_val1[4] !== 1 )
5221
    begin
5222
        $display("Parity checker testing failed! Time %t ", $time) ;
5223
        $display("System error interrupt status bit not set when expected!") ;
5224
        test_fail("System error interrupt status bit not set when expected") ;
5225
        ok = 0 ;
5226
    end
5227
    `else
5228
    if ( temp_val1[4] !== 0 )
5229
    begin
5230
        $display("Parity checker testing failed! Time %t ", $time) ;
5231
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5232
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5233
        ok = 0 ;
5234
    end
5235
    `endif
5236
 
5237
    if ( temp_val1[3] !== 0 )
5238
    begin
5239
        $display("Parity checker testing failed! Time %t ", $time) ;
5240
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5241
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5242
        ok = 0 ;
5243
    end
5244
 
5245
    if ( ok )
5246
        test_ok ;
5247
 
5248
    // clear statuses
5249
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5250
 
5251
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5252
    fork
5253
    begin
5254
        ipci_unsupported_commands_master.master_reference
5255
        (
5256
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5257
            32'h5555_5555,      // second part of address in dual address cycle
5258
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5259
            `BC_MEM_WRITE,      // normal command
5260
            4'h0,               // byte enables
5261
            32'h1234_5678,      // data
5262
            1'b0,               // make address parity error on first phase of dual address
5263
            1'b1,               // make address parity error on second phase of dual address
5264
            ok                  // result of operation
5265
        ) ;
5266
        disable wait_serr15 ;
5267
    end
5268
    begin:wait_serr15
5269
        perr_asserted = 0 ;
5270
        @(posedge pci_clock) ;
5271
        while( SERR === 1 )
5272
            @(posedge pci_clock) ;
5273
 
5274
        if ( SERR === 0 )
5275
            perr_asserted = 1 ;
5276
    end
5277
    join
5278
 
5279
    if ( ok && perr_asserted)
5280
        test_ok ;
5281
    else
5282
    if ( !perr_asserted )
5283
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5284
 
5285
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5286
 
5287
    `ifdef HOST
5288
        repeat(4)
5289
            @(posedge wb_clock) ;
5290
        if ( INT_O !== 1 )
5291
        begin
5292
            $display("Parity checker testing failed! Time %t ", $time) ;
5293
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5294
            test_fail("Interrupt Request was not triggered as expected") ;
5295
        end
5296
        else
5297
            test_ok ;
5298
    `else
5299
    `ifdef GUEST
5300
        repeat( 4 )
5301
            @(posedge pci_clock) ;
5302
 
5303
        if ( INTA !== 1 )
5304
        begin
5305
            $display("Parity checker testing failed! Time %t ", $time) ;
5306
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5307
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5308
        end
5309
        else
5310
            test_ok ;
5311
    `endif
5312
    `endif
5313
 
5314
    // check statuses!
5315
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5316
    ok = 1 ;
5317
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5318
    if ( temp_val1[31] !== 1 )
5319
    begin
5320
        $display("Parity checker testing failed! Time %t ", $time) ;
5321
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5322
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5323
        ok = 0 ;
5324
    end
5325
 
5326
    if ( temp_val1[30] !== 1 )
5327
    begin
5328
        $display("Parity checker testing failed! Time %t ", $time) ;
5329
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5330
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5331
        ok = 0 ;
5332
    end
5333
 
5334
    if ( temp_val1[24] !== 0 )
5335
    begin
5336
        $display("Parity checker testing failed! Time %t ", $time) ;
5337
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5338
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5339
        ok = 0 ;
5340
    end
5341
 
5342
    if ( ok )
5343
        test_ok ;
5344
 
5345
    // clear statuses
5346
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5347
 
5348
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5349
 
5350
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5351
    ok = 1 ;
5352
 
5353
    `ifdef HOST
5354
    if ( temp_val1[4] !== 1 )
5355
    begin
5356
        $display("Parity checker testing failed! Time %t ", $time) ;
5357
        $display("System error interrupt status bit not set when expected!") ;
5358
        test_fail("System error interrupt status bit not set when expected") ;
5359
        ok = 0 ;
5360
    end
5361
    `else
5362
    if ( temp_val1[4] !== 0 )
5363
    begin
5364
        $display("Parity checker testing failed! Time %t ", $time) ;
5365
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5366
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5367
        ok = 0 ;
5368
    end
5369
    `endif
5370
 
5371
    if ( temp_val1[3] !== 0 )
5372
    begin
5373
        $display("Parity checker testing failed! Time %t ", $time) ;
5374
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5375
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5376
        ok = 0 ;
5377
    end
5378
 
5379
    if ( ok )
5380
        test_ok ;
5381
 
5382
    // clear statuses
5383
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5384
 
5385
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5386
    fork
5387
    begin
5388
        ipci_unsupported_commands_master.master_reference
5389
        (
5390
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5391
            32'h5555_5555,      // second part of address in dual address cycle
5392
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5393
            `BC_MEM_WRITE,      // normal command
5394
            4'h0,               // byte enables
5395
            32'h1234_5678,      // data
5396
            1'b1,               // make address parity error on first phase of dual address
5397
            1'b1,               // make address parity error on second phase of dual address
5398
            ok                  // result of operation
5399
        ) ;
5400
        disable wait_serr16 ;
5401
    end
5402
    begin:wait_serr16
5403
        perr_asserted = 0 ;
5404
        @(posedge pci_clock) ;
5405
        while( SERR === 1 )
5406
            @(posedge pci_clock) ;
5407
 
5408
        if ( SERR === 0 )
5409
            perr_asserted = 1 ;
5410
    end
5411
    join
5412
 
5413
    if ( ok && perr_asserted)
5414
        test_ok ;
5415
    else
5416
    if ( !perr_asserted )
5417
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5418
 
5419
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5420
 
5421
    `ifdef HOST
5422
        repeat(4)
5423
            @(posedge wb_clock) ;
5424
        if ( INT_O !== 1 )
5425
        begin
5426
            $display("Parity checker testing failed! Time %t ", $time) ;
5427
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5428
            test_fail("Interrupt Request was not triggered as expected") ;
5429
        end
5430
        else
5431
            test_ok ;
5432
    `else
5433
    `ifdef GUEST
5434
        repeat( 4 )
5435
            @(posedge pci_clock) ;
5436
 
5437
        if ( INTA !== 1 )
5438
        begin
5439
            $display("Parity checker testing failed! Time %t ", $time) ;
5440
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5441
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5442
        end
5443
        else
5444
            test_ok ;
5445
    `endif
5446
    `endif
5447
 
5448
    // check statuses!
5449
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5450
    ok = 1 ;
5451
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5452
    if ( temp_val1[31] !== 1 )
5453
    begin
5454
        $display("Parity checker testing failed! Time %t ", $time) ;
5455
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5456
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5457
        ok = 0 ;
5458
    end
5459
 
5460
    if ( temp_val1[30] !== 1 )
5461
    begin
5462
        $display("Parity checker testing failed! Time %t ", $time) ;
5463
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5464
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5465
        ok = 0 ;
5466
    end
5467
 
5468
    if ( temp_val1[24] !== 0 )
5469
    begin
5470
        $display("Parity checker testing failed! Time %t ", $time) ;
5471
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5472
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5473
        ok = 0 ;
5474
    end
5475
 
5476
    if ( ok )
5477
        test_ok ;
5478
 
5479
    // clear statuses
5480
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5481
 
5482
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5483
 
5484
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5485
    ok = 1 ;
5486
 
5487
    `ifdef HOST
5488
    if ( temp_val1[4] !== 1 )
5489
    begin
5490
        $display("Parity checker testing failed! Time %t ", $time) ;
5491
        $display("System error interrupt status bit not set when expected!") ;
5492
        test_fail("System error interrupt status bit not set when expected") ;
5493
        ok = 0 ;
5494
    end
5495
    `else
5496
    if ( temp_val1[4] !== 0 )
5497
    begin
5498
        $display("Parity checker testing failed! Time %t ", $time) ;
5499
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5500
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5501
        ok = 0 ;
5502
    end
5503
    `endif
5504
 
5505
    if ( temp_val1[3] !== 0 )
5506
    begin
5507
        $display("Parity checker testing failed! Time %t ", $time) ;
5508
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5509
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5510
        ok = 0 ;
5511
    end
5512
 
5513
    if ( ok )
5514
        test_ok ;
5515
 
5516
    // clear statuses
5517
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5518
 
5519
    // now just disable Parity Error response - on Address par errors nothing should happen
5520
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5521
 
5522
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5523
    fork
5524
    begin
5525
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5526
               target_address, 32'h1234_5678,
5527
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5528
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5529
        do_pause( 1 ) ;
5530
    end
5531
    begin:wait_serr12
5532
        perr_asserted = 0 ;
5533
        @(posedge pci_clock) ;
5534
        while( SERR === 1 )
5535
            @(posedge pci_clock) ;
5536
 
5537
        perr_asserted = 1 ;
5538
        $display("Parity checker testing failed! Time %t ", $time) ;
5539
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5540
        test_fail("SERR asserted when parity error response was disabled") ;
5541
    end
5542
    begin
5543
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5544
        if ( ok !== 1 )
5545
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5546
 
5547
        disable wait_serr12 ;
5548
    end
5549
    join
5550
 
5551
    if ( ok && !perr_asserted )
5552
        test_ok ;
5553
 
5554
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5555
    `ifdef HOST
5556
        repeat(4)
5557
            @(posedge wb_clock) ;
5558
        if ( INT_O !== 0 )
5559
        begin
5560
            $display("Parity checker testing failed! Time %t ", $time) ;
5561
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5562
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5563
        end
5564
        else
5565
            test_ok ;
5566
    `else
5567
    `ifdef GUEST
5568
        repeat ( 4 )
5569
            @(posedge pci_clock) ;
5570
 
5571
        if ( INTA !== 1 )
5572
        begin
5573
            $display("Parity checker testing failed! Time %t ", $time) ;
5574
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5575
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5576
        end
5577
        else
5578
            test_ok ;
5579
    `endif
5580
    `endif
5581
 
5582
    // check statuses!
5583
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5584
    ok = 1 ;
5585
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5586
    if ( temp_val1[31] !== 1 )
5587
    begin
5588
        $display("Parity checker testing failed! Time %t ", $time) ;
5589
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5590
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5591
        ok = 0 ;
5592
    end
5593
 
5594
    if ( temp_val1[30] !== 0 )
5595
    begin
5596
        $display("Parity checker testing failed! Time %t ", $time) ;
5597
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5598
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5599
        ok = 0 ;
5600
    end
5601
 
5602
    if ( temp_val1[24] !== 0 )
5603
    begin
5604
        $display("Parity checker testing failed! Time %t ", $time) ;
5605
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5606
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5607
        ok = 0 ;
5608
    end
5609
 
5610
    if ( ok )
5611
        test_ok ;
5612
 
5613
    // clear statuses
5614
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5615
 
5616
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5617
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5618
    ok = 1 ;
5619
    if ( temp_val1[4] !== 0 )
5620
    begin
5621
        $display("Parity checker testing failed! Time %t ", $time) ;
5622
        $display("System error interrupt status bit set when not expected!") ;
5623
        test_fail("System error interrupt status bit set when not expected") ;
5624
        ok = 0 ;
5625
    end
5626
 
5627
    if ( temp_val1[3] !== 0 )
5628
    begin
5629
        $display("Parity checker testing failed! Time %t ", $time) ;
5630
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5631
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5632
        ok = 0 ;
5633
    end
5634
 
5635
    if ( ok )
5636
        test_ok ;
5637
 
5638
    // clear statuses
5639
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5640
 
5641
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5642
    fork
5643
    begin
5644
        ipci_unsupported_commands_master.master_reference
5645
        (
5646
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5647
            32'h5555_5555,      // second part of address in dual address cycle
5648
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5649
            `BC_MEM_WRITE,      // normal command
5650
            4'h0,               // byte enables
5651
            32'h1234_5678,      // data
5652
            1'b1,               // make address parity error on first phase of dual address
5653
            1'b0,               // make address parity error on second phase of dual address
5654
            ok                  // result of operation
5655
        ) ;
5656
        disable wait_serr17 ;
5657
    end
5658
    begin:wait_serr17
5659
        perr_asserted = 0 ;
5660
        @(posedge pci_clock) ;
5661
        while( SERR === 1 )
5662
            @(posedge pci_clock) ;
5663
 
5664
        perr_asserted = 1 ;
5665
        $display("Parity checker testing failed! Time %t ", $time) ;
5666
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5667
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5668
    end
5669
    join
5670
 
5671
    if ( ok && !perr_asserted)
5672
        test_ok ;
5673
 
5674
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5675
    fork
5676
    begin
5677
        ipci_unsupported_commands_master.master_reference
5678
        (
5679
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5680
            32'h5555_5555,      // second part of address in dual address cycle
5681
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5682
            `BC_MEM_WRITE,      // normal command
5683
            4'h0,               // byte enables
5684
            32'h1234_5678,      // data
5685
            1'b0,               // make address parity error on first phase of dual address
5686
            1'b1,               // make address parity error on second phase of dual address
5687
            ok                  // result of operation
5688
        ) ;
5689
        disable wait_serr18 ;
5690
    end
5691
    begin:wait_serr18
5692
        perr_asserted = 0 ;
5693
        @(posedge pci_clock) ;
5694
        while( SERR === 1 )
5695
            @(posedge pci_clock) ;
5696
 
5697
        perr_asserted = 1 ;
5698
        $display("Parity checker testing failed! Time %t ", $time) ;
5699
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5700
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5701
    end
5702
    join
5703
 
5704
    if ( ok && !perr_asserted)
5705
        test_ok ;
5706
 
5707
    // check statuses!
5708
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5709
    ok = 1 ;
5710
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5711
    if ( temp_val1[31] !== 1 )
5712
    begin
5713
        $display("Parity checker testing failed! Time %t ", $time) ;
5714
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5715
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5716
        ok = 0 ;
5717
    end
5718
 
5719
    if ( temp_val1[30] !== 0 )
5720
    begin
5721
        $display("Parity checker testing failed! Time %t ", $time) ;
5722
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5723
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5724
        ok = 0 ;
5725
    end
5726
 
5727
    if ( temp_val1[24] !== 0 )
5728
    begin
5729
        $display("Parity checker testing failed! Time %t ", $time) ;
5730
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5731
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5732
        ok = 0 ;
5733
    end
5734
 
5735
    if ( ok )
5736
        test_ok ;
5737
 
5738
    // clear statuses
5739
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5740
 
5741
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5742
    fork
5743
    begin
5744
        ipci_unsupported_commands_master.master_reference
5745
        (
5746
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5747
            32'h5555_5555,      // second part of address in dual address cycle
5748
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5749
            `BC_MEM_WRITE,      // normal command
5750
            4'h0,               // byte enables
5751
            32'h1234_5678,      // data
5752
            1'b1,               // make address parity error on first phase of dual address
5753
            1'b1,               // make address parity error on second phase of dual address
5754
            ok                  // result of operation
5755
        ) ;
5756
        disable wait_serr19 ;
5757
    end
5758
    begin:wait_serr19
5759
        perr_asserted = 0 ;
5760
        @(posedge pci_clock) ;
5761
        while( SERR === 1 )
5762
            @(posedge pci_clock) ;
5763
 
5764
        perr_asserted = 1 ;
5765
        $display("Parity checker testing failed! Time %t ", $time) ;
5766
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5767
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5768
    end
5769
    join
5770
 
5771
    if ( ok && !perr_asserted)
5772
        test_ok ;
5773
 
5774
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5775
 
5776
    `ifdef HOST
5777
        repeat(4)
5778
            @(posedge wb_clock) ;
5779
        if ( INT_O !== 0 )
5780
        begin
5781
            $display("Parity checker testing failed! Time %t ", $time) ;
5782
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5783
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5784
        end
5785
        else
5786
            test_ok ;
5787
    `else
5788
    `ifdef GUEST
5789
        repeat( 4 )
5790
            @(posedge pci_clock) ;
5791
 
5792
        if ( INTA !== 1 )
5793
        begin
5794
            $display("Parity checker testing failed! Time %t ", $time) ;
5795
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5796
            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") ;
5797
        end
5798
        else
5799
            test_ok ;
5800
    `endif
5801
    `endif
5802
 
5803
    // check statuses!
5804
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5805
    ok = 1 ;
5806
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5807
    if ( temp_val1[31] !== 1 )
5808
    begin
5809
        $display("Parity checker testing failed! Time %t ", $time) ;
5810
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5811
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5812
        ok = 0 ;
5813
    end
5814
 
5815
    if ( temp_val1[30] !== 0 )
5816
    begin
5817
        $display("Parity checker testing failed! Time %t ", $time) ;
5818
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5819
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5820
        ok = 0 ;
5821
    end
5822
 
5823
    if ( temp_val1[24] !== 0 )
5824
    begin
5825
        $display("Parity checker testing failed! Time %t ", $time) ;
5826
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5827
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5828
        ok = 0 ;
5829
    end
5830
 
5831
    if ( ok )
5832
        test_ok ;
5833
 
5834
    // clear statuses
5835
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5836
 
5837
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
5838
 
5839
    // do normal write
5840
    fork
5841
    begin
5842
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
5843
               target_address, 32'h1234_5678, `Test_All_Bytes,
5844
               1, 8'h3_0, `Test_One_Zero_Target_WS,
5845
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5846
        do_pause( 1 ) ;
5847
    end
5848
    begin:wait_serr13
5849
        perr_asserted = 0 ;
5850
        @(posedge pci_clock) ;
5851
        while( SERR === 1 )
5852
            @(posedge pci_clock) ;
5853
 
5854
        perr_asserted = 1 ;
5855
        $display("Parity checker testing failed! Time %t ", $time) ;
5856
        $display("SERR asserted for no reason!") ;
5857
        test_fail("SERR was asserted for no reason") ;
5858
    end
5859
    begin
5860
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5861
        if ( ok !== 1 )
5862
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5863
 
5864
        disable wait_serr13 ;
5865
    end
5866
    join
5867
 
5868
    if ( ok && !perr_asserted )
5869
        test_ok ;
5870
 
5871
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
5872
    `ifdef HOST
5873
        repeat(4)
5874
            @(posedge wb_clock) ;
5875
        if ( INT_O !== 0 )
5876
        begin
5877
            $display("Parity checker testing failed! Time %t ", $time) ;
5878
            $display("Interrupt request asserted for no reason!") ;
5879
            test_fail("Interrupt request was asserted for no reason") ;
5880
        end
5881
        else
5882
            test_ok ;
5883
    `else
5884
    `ifdef GUEST
5885
        repeat( 4 )
5886
            @(posedge pci_clock) ;
5887
 
5888
        if ( INTA !== 1 )
5889
        begin
5890
            $display("Parity checker testing failed! Time %t ", $time) ;
5891
            $display("Interrupt request asserted for no reason!") ;
5892
            test_fail("Interrupt request was asserted for no reason") ;
5893
        end
5894
        else
5895
            test_ok ;
5896
    `endif
5897
    `endif
5898
 
5899
    // check statuses!
5900
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
5901
    ok = 1 ;
5902
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5903
    if ( temp_val1[31] !== 0 )
5904
    begin
5905
        $display("Parity checker testing failed! Time %t ", $time) ;
5906
        $display("Detected Parity Error bit was set for no reason!") ;
5907
        test_fail("Detected Parity Error bit was set for no reason") ;
5908
        ok = 0 ;
5909
    end
5910
 
5911
    if ( temp_val1[30] !== 0 )
5912
    begin
5913
        $display("Parity checker testing failed! Time %t ", $time) ;
5914
        $display("Signalled System Error bit was set for no reason!") ;
5915
        test_fail("Signalled System Error bit was set for no reason") ;
5916
        ok = 0 ;
5917
    end
5918
 
5919
    if ( temp_val1[24] !== 0 )
5920
    begin
5921
        $display("Parity checker testing failed! Time %t ", $time) ;
5922
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5923
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5924
        ok = 0 ;
5925
    end
5926
 
5927
    if ( ok )
5928
        test_ok ;
5929
 
5930
    // clear statuses
5931
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5932
 
5933
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5934
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
5935
    ok = 1 ;
5936
 
5937
    if ( temp_val1[4] !== 0 )
5938
    begin
5939
        $display("Parity checker testing failed! Time %t ", $time) ;
5940
        $display("System error interrupt status bit set when not expected!") ;
5941
        test_fail("System error interrupt status bit set when not expected") ;
5942
        ok = 0 ;
5943
    end
5944
 
5945
    if ( temp_val1[3] !== 0 )
5946
    begin
5947
        $display("Parity checker testing failed! Time %t ", $time) ;
5948
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5949
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5950
        ok = 0 ;
5951
    end
5952
 
5953
    if ( ok )
5954
        test_ok ;
5955
 
5956
    // clear statuses
5957
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5958
 
5959
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
5960
 
5961
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
5962
 
5963
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
5964
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
5965
 
5966
    // setup target's image!
5967
    target_address  = Target_Base_Addr_R[1] ;
5968
 
5969
    // base address
5970
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
5971
 
5972
    // address mask
5973
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
5974
 
5975
    // image control
5976
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
5977
 
5978
    // enable everything possible for parity checking
5979
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
5980
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
5981
 
5982
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
5983
 
5984
    fork
5985
    begin
5986
        if ( target_mem_image === 1 )
5987
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
5988
                   target_address, 32'h1234_5678,
5989
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
5990
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5991
        else
5992
            PCIU_IO_WRITE_MAKE_PERR (
5993
                                    `Test_Master_1,
5994
                                    target_address,
5995
                                    32'h1234_5678,
5996
                                    4'h0,
5997
                                    1,
5998
                                    `Test_Target_Normal_Completion
5999
                                    );
6000
 
6001
        do_pause( 1 ) ;
6002
    end
6003
    begin:wait_perr11
6004
        perr_asserted = 0 ;
6005
        @(posedge pci_clock) ;
6006
        while ( PERR === 1 )
6007
            @(posedge pci_clock) ;
6008
 
6009
        if ( PERR === 0 )
6010
            perr_asserted = 1 ;
6011
 
6012
    end
6013
    begin
6014
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6015
 
6016
        if ( ok !== 1 )
6017
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6018
 
6019
        repeat(2)
6020
            @(posedge pci_clock) ;
6021
 
6022
        disable wait_perr11 ;
6023
    end
6024
    join
6025
 
6026
    if ( ok && perr_asserted )
6027
        test_ok ;
6028
    else
6029
    if ( !perr_asserted )
6030
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6031
 
6032
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6033
    `ifdef HOST
6034
        repeat(4)
6035
            @(posedge wb_clock) ;
6036
        if ( INT_O !== 0 )
6037
        begin
6038
            $display("Parity checker testing failed! Time %t ", $time) ;
6039
            $display("Interrupt request asserted for no reason!") ;
6040
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6041
        end
6042
        else
6043
            test_ok ;
6044
    `else
6045
    `ifdef GUEST
6046
        repeat ( 4 )
6047
            @(posedge pci_clock) ;
6048
 
6049
        if ( INTA !== 1 )
6050
        begin
6051
            $display("Parity checker testing failed! Time %t ", $time) ;
6052
            $display("Interrupt request asserted for no reason!") ;
6053
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6054
        end
6055
        else
6056
            test_ok ;
6057
 
6058
    `endif
6059
    `endif
6060
 
6061
    // check statuses!
6062
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6063
    ok = 1 ;
6064
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6065
    if ( temp_val1[31] !== 1 )
6066
    begin
6067
        $display("Parity checker testing failed! Time %t ", $time) ;
6068
        $display("Detected Parity Error bit was not set after Target detected parity error!") ;
6069
        test_fail("Detected Parity Error bit was not set after Target detected parity error") ;
6070
        ok = 0 ;
6071
    end
6072
 
6073
    if ( temp_val1[30] !== 0 )
6074
    begin
6075
        $display("Parity checker testing failed! Time %t ", $time) ;
6076
        $display("Signalled System Error bit was set for no reason!") ;
6077
        test_fail("Signalled System Error bit was set for no reason") ;
6078
        ok = 0 ;
6079
    end
6080
 
6081
    if ( temp_val1[24] !== 0 )
6082
    begin
6083
        $display("Parity checker testing failed! Time %t ", $time) ;
6084
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6085
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6086
        ok = 0 ;
6087
    end
6088
 
6089
    if ( ok )
6090
        test_ok ;
6091
 
6092
    // clear statuses
6093
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6094
 
6095
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6096
 
6097
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6098
    ok = 1 ;
6099
    if ( temp_val1[4] !== 0 )
6100
    begin
6101
        $display("Parity checker testing failed! Time %t ", $time) ;
6102
        $display("System error interrupt status bit set when not expected!") ;
6103
        test_fail("System error interrupt status bit set when not expected") ;
6104
        ok = 0 ;
6105
    end
6106
 
6107
    if ( temp_val1[3] !== 0 )
6108
    begin
6109
        $display("Parity checker testing failed! Time %t ", $time) ;
6110
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6111
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6112
        ok = 0 ;
6113
    end
6114
 
6115
    if ( ok )
6116
        test_ok ;
6117
 
6118
    // clear statuses
6119
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6120
 
6121
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6122
 
6123
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6124
    fork
6125
    begin
6126
        if ( target_mem_image === 1 )
6127
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6128
                          target_address, 32'h1234_5678,
6129
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6130
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6131
        else
6132
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6133
 
6134
        do_pause( 1 ) ;
6135
    end
6136
    begin:wait_perr12
6137
        perr_asserted = 0 ;
6138
        @(posedge pci_clock) ;
6139
        while ( PERR === 1 )
6140
            @(posedge pci_clock) ;
6141
 
6142
        if ( PERR === 0 )
6143
            perr_asserted = 1 ;
6144
    end
6145
    begin
6146
 
6147
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6148
        if ( ok !== 1 )
6149
        begin
6150
            test_fail("Bridge failed to process Target Memory read correctly") ;
6151
            disable main ;
6152
        end
6153
 
6154
        repeat(3)
6155
            @(posedge pci_clock) ;
6156
 
6157
        if ( target_mem_image === 1 )
6158
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6159
                    target_address, 32'h1234_5678,
6160
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6161
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6162
        else
6163
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6164
 
6165
        do_pause( 1 ) ;
6166
 
6167
    end
6168
    begin
6169
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6170
        if ( ok !== 1 )
6171
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6172
        else
6173
        begin
6174
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6175
            if ( ok !== 1 )
6176
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6177
        end
6178
 
6179
        repeat(3)
6180
            @(posedge pci_clock) ;
6181
 
6182
        disable wait_perr12 ;
6183
    end
6184
    join
6185
 
6186
    if ( ok && perr_asserted )
6187
        test_ok ;
6188
    else
6189
    if ( !perr_asserted )
6190
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6191
 
6192
 
6193
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6194
    `ifdef HOST
6195
        repeat(4)
6196
            @(posedge wb_clock) ;
6197
        if ( INT_O !== 0 )
6198
        begin
6199
            $display("Parity checker testing failed! Time %t ", $time) ;
6200
            $display("Interrupt request asserted for no reason!") ;
6201
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6202
        end
6203
        else
6204
            test_ok ;
6205
    `else
6206
    `ifdef GUEST
6207
        repeat( 4 )
6208
            @(posedge pci_clock) ;
6209
 
6210
        if ( INTA !== 1 )
6211
        begin
6212
            $display("Parity checker testing failed! Time %t ", $time) ;
6213
            $display("Interrupt request asserted for no reason!") ;
6214
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6215
        end
6216
        else
6217
            test_ok ;
6218
    `endif
6219
    `endif
6220
 
6221
    // check statuses!
6222
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6223
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6224
    ok = 1 ;
6225
    if ( temp_val1[31] !== 1 )
6226
    begin
6227
        $display("Parity checker testing failed! Time %t ", $time) ;
6228
        $display("Detected Parity Error bit was not set after Target receive PERR asserted!") ;
6229
        test_fail("Detected Parity Error bit was not set after Target received PERR asserted on read reference") ;
6230
        ok = 0 ;
6231
    end
6232
 
6233
    if ( temp_val1[30] !== 0 )
6234
    begin
6235
        $display("Parity checker testing failed! Time %t ", $time) ;
6236
        $display("Signalled System Error bit was set for no reason!") ;
6237
        test_fail("Signalled System Error bit was set for no reason") ;
6238
        ok = 0 ;
6239
    end
6240
 
6241
    if ( temp_val1[24] !== 0 )
6242
    begin
6243
        $display("Parity checker testing failed! Time %t ", $time) ;
6244
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6245
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6246
        ok = 0 ;
6247
    end
6248
 
6249
    if ( ok )
6250
        test_ok ;
6251
 
6252
    // clear statuses
6253
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6254
 
6255
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6256
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6257
    ok = 1 ;
6258
    if ( temp_val1[4] !== 0 )
6259
    begin
6260
        $display("Parity checker testing failed! Time %t ", $time) ;
6261
        $display("System error interrupt status bit set when not expected!") ;
6262
        test_fail("System error interrupt status bit set when not expected") ;
6263
        ok = 0 ;
6264
    end
6265
 
6266
    if ( temp_val1[3] !== 0 )
6267
    begin
6268
        $display("Parity checker testing failed! Time %t ", $time) ;
6269
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6270
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6271
        ok = 0 ;
6272
    end
6273
 
6274
    if ( ok )
6275
        test_ok ;
6276
    // clear statuses
6277
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6278
 
6279
    $fdisplay(pci_mon_log_file_desc,
6280
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6281
    test_name = "DISABLE USED IMAGES" ;
6282
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6283
    if ( ok !== 1 )
6284
    begin
6285
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6286
        test_fail("WB Image Address Mask register could not be written to") ;
6287
        disable main ;
6288
    end
6289
 
6290
    config_write( p_am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6291
    if ( ok !== 1 )
6292
    begin
6293
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6294
        test_fail("PCI Image Address Mask register could not be written to") ;
6295
        disable main ;
6296
    end
6297
 
6298
    // disable target's 1 response to parity errors
6299
    configuration_cycle_write(0,             // bus number
6300
                              1,             // device number
6301
                              0,             // function number
6302
                              1,             // register number
6303
                              0,             // type of configuration cycle
6304
                              4'b0001,       // byte enables
6305
                              32'h0000_0007  // data
6306
                             ) ;
6307
 
6308
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6309
end
6310
endtask // parity_checking
6311
 
6312
task wb_to_pci_transactions ;
6313
    reg   [11:0] ctrl_offset ;
6314
    reg   [11:0] ba_offset ;
6315
    reg   [11:0] am_offset ;
6316
    reg   [11:0] pci_ctrl_offset ;
6317
    reg   [11:0] err_cs_offset ;
6318
    reg   [11:0] icr_offset ;
6319
    reg   [11:0] isr_offset ;
6320
    reg   [11:0] lat_tim_cls_offset ;
6321
 
6322
    reg `WRITE_STIM_TYPE  write_data ;
6323
    reg `READ_STIM_TYPE   read_data ;
6324
    reg `READ_RETURN_TYPE read_status ;
6325
 
6326
    reg `WRITE_RETURN_TYPE write_status ;
6327
    reg `WB_TRANSFER_FLAGS write_flags ;
6328
    reg [31:0] temp_val1 ;
6329
    reg [31:0] temp_val2 ;
6330
    reg        ok   ;
6331
 
6332
    reg [31:0] image_base ;
6333
    reg [31:0] target_address ;
6334
    integer i ;
6335
    integer required_reads ;
6336
    integer writes_left ;
6337
 
6338
begin:main
6339
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6340
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6341
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6342
    pci_ctrl_offset    = 12'h4 ;
6343
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6344
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6345
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6346
    lat_tim_cls_offset = 12'hC ;
6347
 
6348
    $display("Checking WB to PCI transaction lengths!") ;
6349
    target_address  = `BEH_TAR1_MEM_START ;
6350
    image_base      = 0 ;
6351
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6352
 
6353
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6354
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6355
    write_flags                    = 0 ;
6356
    write_flags`INIT_WAITS         = tb_init_waits ;
6357
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6358
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6359
 
6360
    // enable master & target operation
6361
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6362
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6363
    if ( ok !== 1 )
6364
    begin
6365
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6366
        test_fail("write to PCI Device Control register failed") ;
6367
        disable main ;
6368
    end
6369
 
6370
    // prepare image control register
6371
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6372
    if ( ok !== 1 )
6373
    begin
6374
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6375
        test_fail("write to WB Image Control register failed") ;
6376
        disable main ;
6377
    end
6378
 
6379
    // prepare base address register
6380
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6381
    if ( ok !== 1 )
6382
    begin
6383
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6384
        test_fail("write to WB Base Address register failed") ;
6385
        disable main ;
6386
    end
6387
 
6388
    // write address mask register
6389
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6390
    if ( ok !== 1 )
6391
    begin
6392
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6393
        test_fail("write to WB Address Mask register failed") ;
6394
        disable main ;
6395
    end
6396
 
6397
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6398
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6399
    if ( ok !== 1 )
6400
    begin
6401
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6402
        test_fail("write to WB Error Control and Status register failed") ;
6403
        disable main ;
6404
    end
6405
 
6406
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6407
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6408
    if ( ok !== 1 )
6409
    begin
6410
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6411
        test_fail("write to Interrupt Control register failed") ;
6412
        disable main ;
6413
    end
6414
 
6415
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6416
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6417
    if ( ok !== 1 )
6418
    begin
6419
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6420
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6421
        disable main ;
6422
    end
6423
 
6424
    $display("Testing single write transaction progress from WB to PCI!") ;
6425
    write_data`WRITE_ADDRESS = target_address ;
6426
    write_data`WRITE_DATA    = wmem_data[0] ;
6427
    write_data`WRITE_SEL     = 4'hF ;
6428
 
6429
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6430
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6431
 
6432
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6433
    fork
6434
    begin
6435
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6436
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6437
        begin
6438
            $display("Transaction progress testing failed! Time %t ", $time) ;
6439
            $display("Bridge failed to process single memory write!") ;
6440
            test_fail("bridge failed to post single memory write") ;
6441
            disable main ;
6442
        end
6443
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6444
    end
6445
    begin
6446
        // wait two retries, then enable target response
6447
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6448
        if ( ok !== 1 )
6449
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6450
        else
6451
            test_ok ;
6452
 
6453
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6454
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6455
        if ( ok !== 1 )
6456
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6457
        else
6458
            test_ok ;
6459
 
6460
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6461
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6462
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6463
 
6464
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6465
        if ( ok !== 1 )
6466
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6467
        else
6468
            test_ok ;
6469
    end
6470
    join
6471
 
6472
    $display("Testing burst write transaction progress from WB to PCI!") ;
6473
    write_data`WRITE_ADDRESS = target_address ;
6474
    write_data`WRITE_DATA    = wmem_data[0] ;
6475
    write_data`WRITE_SEL     = 4'hF ;
6476
 
6477
    wishbone_master.blk_write_data[0] = write_data ;
6478
 
6479
    write_data`WRITE_ADDRESS = target_address + 4 ;
6480
    write_data`WRITE_DATA    = wmem_data[1] ;
6481
    write_data`WRITE_SEL     = 4'hF ;
6482
 
6483
    wishbone_master.blk_write_data[1] = write_data ;
6484
 
6485
    write_flags`WB_TRANSFER_SIZE = 2 ;
6486
    write_flags`WB_TRANSFER_CAB  = 1 ;
6487
 
6488
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6489
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6490
 
6491
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6492
 
6493
    fork
6494
    begin
6495
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6496
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6497
        begin
6498
            $display("Transaction progress testing failed! Time %t ", $time) ;
6499
            $display("Bridge failed to process whole CAB memory write!") ;
6500
            test_fail("bridge failed to post whole CAB memory write") ;
6501
            disable main ;
6502
        end
6503
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6504
    end
6505
    begin
6506
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6507
        if ( ok !== 1 )
6508
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6509
        else
6510
            test_ok ;
6511
 
6512
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6513
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6514
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6515
 
6516
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6517
        if ( ok !== 1 )
6518
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6519
        else
6520
            test_ok ;
6521
 
6522
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6523
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6524
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6525
 
6526
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6527
        if ( ok !== 1 )
6528
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6529
        else
6530
            test_ok ;
6531
    end
6532
    join
6533
 
6534
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6535
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6536
 
6537
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6538
    // try same write with other terminations
6539
    fork
6540
    begin
6541
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6542
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6543
        begin
6544
            $display("Transaction progress testing failed! Time %t ", $time) ;
6545
            $display("Bridge failed to process whole CAB memory write!") ;
6546
            test_fail("bridge failed to post whole CAB memory write") ;
6547
            disable main ;
6548
        end
6549
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6550
    end
6551
    begin
6552
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6553
        if ( ok !== 1 )
6554
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6555
        else
6556
            test_ok ;
6557
 
6558
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6559
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6560
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6561
 
6562
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6563
        if ( ok !== 1 )
6564
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6565
        else
6566
            test_ok ;
6567
    end
6568
    join
6569
 
6570
    // repeat the write with normal completion
6571
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6572
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6573
 
6574
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6575
    fork
6576
    begin
6577
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6578
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6579
        begin
6580
            $display("Transaction progress testing failed! Time %t ", $time) ;
6581
            $display("Bridge failed to process whole CAB memory write!") ;
6582
            test_fail("bridge failed to post whole CAB memory write") ;
6583
            disable main ;
6584
        end
6585
    end
6586
    begin
6587
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6588
        if ( ok !== 1 )
6589
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6590
        else
6591
            test_ok ;
6592
    end
6593
    join
6594
 
6595
    // do the same thing with burst length of 3
6596
    write_data`WRITE_ADDRESS = target_address + 8 ;
6597
    write_data`WRITE_DATA    = wmem_data[2] ;
6598
    write_data`WRITE_SEL     = 4'hF ;
6599
 
6600
    wishbone_master.blk_write_data[2] = write_data ;
6601
 
6602
    write_flags`WB_TRANSFER_SIZE = 3 ;
6603
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6604
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6605
 
6606
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6607
 
6608
    fork
6609
    begin
6610
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6611
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6612
        begin
6613
            $display("Transaction progress testing failed! Time %t ", $time) ;
6614
            $display("Bridge failed to process whole CAB memory write!") ;
6615
            test_fail("bridge failed to post whole CAB memory write") ;
6616
            disable main ;
6617
        end
6618
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6619
    end
6620
    begin
6621
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6622
        if ( ok !== 1 )
6623
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6624
        else
6625
            test_ok ;
6626
 
6627
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6628
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6629
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6630
 
6631
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6632
        if ( ok !== 1 )
6633
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6634
        else
6635
            test_ok ;
6636
    end
6637
    join
6638
 
6639
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6640
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6641
 
6642
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6643
    fork
6644
    begin
6645
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6646
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6647
        begin
6648
            $display("Transaction progress testing failed! Time %t ", $time) ;
6649
            $display("Bridge failed to process whole CAB memory write!") ;
6650
            test_fail("bridge failed to post whole CAB memory write") ;
6651
            disable main ;
6652
        end
6653
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6654
    end
6655
    begin
6656
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6657
        if ( ok !== 1 )
6658
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6659
        else
6660
            test_ok ;
6661
 
6662
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6663
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6664
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6665
 
6666
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6667
        if ( ok !== 1 )
6668
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6669
        else
6670
            test_ok ;
6671
 
6672
    end
6673
    join
6674
 
6675
    // repeat with normal completion
6676
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6677
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6678
 
6679
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6680
    fork
6681
    begin
6682
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6683
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6684
        begin
6685
            $display("Transaction progress testing failed! Time %t ", $time) ;
6686
            $display("Bridge failed to process whole CAB memory write!") ;
6687
            test_fail("bridge failed to post whole CAB memory write") ;
6688
            disable main ;
6689
        end
6690
    end
6691
    begin
6692
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6693
        if ( ok !== 1 )
6694
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6695
        else
6696
            test_ok ;
6697
 
6698
    end
6699
    join
6700
 
6701
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6702
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6703
    begin
6704
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6705
        write_data`WRITE_DATA    = wmem_data[i] ;
6706
        write_data`WRITE_SEL     = 4'hF ;
6707
 
6708
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6709
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6710
 
6711
        wishbone_master.blk_write_data[i]   = write_data ;
6712
        wishbone_master.blk_read_data_in[i] = read_data ;
6713
    end
6714
 
6715
    write_flags`WB_TRANSFER_CAB      = 1 ;
6716
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6717
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6718
 
6719
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6720
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6721
 
6722
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6723
    fork
6724
    begin
6725
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6726
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6727
        begin
6728
            $display("Transaction progress testing failed! Time %t ", $time) ;
6729
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6730
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6731
            test_fail("bridge failed to post whole CAB memory write") ;
6732
            disable main ;
6733
        end
6734
 
6735
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6736
 
6737
        // read here just checks if data was transfered OK
6738
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6739
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6740
 
6741
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6742
 
6743
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6744
        begin
6745
            $display("Transaction progress testing failed! Time %t ", $time) ;
6746
            $display("Bridge processed CAB read wrong!") ;
6747
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
6748
        end
6749
 
6750
    end
6751
    begin
6752
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6753
        if ( ok !== 1 )
6754
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6755
        else
6756
            test_ok ;
6757
 
6758
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
6759
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6760
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6761
 
6762
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6763
        if ( ok !== 1 )
6764
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6765
        else
6766
            test_ok ;
6767
 
6768
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
6769
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6770
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6771
 
6772
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6773
        if ( ok !== 1 )
6774
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6775
        else
6776
            test_ok ;
6777
 
6778
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
6779
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6780
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6781
 
6782
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 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 = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
6789
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6790
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6791
 
6792
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 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
 
6798
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
6799
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
6800
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
6801
        for ( i = 0 ; i < required_reads ; i = i + 1 )
6802
        begin
6803
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
6804
            if ( ok !== 1 )
6805
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6806
        end
6807
    end
6808
    join
6809
 
6810
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
6811
    begin
6812
        read_status = wishbone_master.blk_read_data_out[i] ;
6813
        if (read_status`READ_DATA !== wmem_data[i])
6814
        begin
6815
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
6816
            test_fail("data read from target wasn't the same as data written to it") ;
6817
            ok = 0 ;
6818
        end
6819
    end
6820
 
6821
    if ( ok )
6822
        test_ok ;
6823
 
6824
    $display("Testing single read transaction progress from WB to PCI!") ;
6825
    read_data`READ_ADDRESS = target_address + 8 ;
6826
    read_data`READ_SEL     = 4'hF ;
6827
 
6828
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6829
 
6830
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
6831
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6832
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6833
 
6834
    fork
6835
    begin
6836
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6837
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6838
        begin
6839
            $display("Transaction progress testing failed! Time %t ", $time) ;
6840
            $display("Bridge processed single read wrong!") ;
6841
            test_fail("bridge processed single read wrong") ;
6842
            disable main ;
6843
        end
6844
 
6845
        if (read_status`READ_DATA !== wmem_data[2])
6846
        begin
6847
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
6848
            test_fail("data returned from single read was not as expected") ;
6849
        end
6850
        else
6851
        if ( ok )
6852
            test_ok ;
6853
    end
6854
    begin
6855
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
6856
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6857
 
6858
        if ( ok !== 1 )
6859
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6860
 
6861
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
6862
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6863
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6864
 
6865
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6866
        if ( ok !== 1 )
6867
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6868
    end
6869
    join
6870
 
6871
    $display("Testing CAB read transaction progress from WB to PCI!") ;
6872
 
6873
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6874
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6875
 
6876
    test_name = "FILL TARGET MEMORY WITH DATA" ;
6877
    // first fill target's memory with enough data to fill WBR_FIFO
6878
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
6879
    begin
6880
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6881
        write_data`WRITE_DATA    = wmem_data[i] ;
6882
        write_data`WRITE_SEL     = 4'hF ;
6883
 
6884
        wishbone_master.blk_write_data[i] = write_data ;
6885
    end
6886
 
6887
    write_flags`WB_TRANSFER_CAB = 1 ;
6888
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6889
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
6890
 
6891
    wishbone_master.wb_block_write( write_flags, write_status ) ;
6892
 
6893
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
6894
    begin
6895
        $display("Transaction progress testing failed! Time %t ", $time) ;
6896
        $display("Bridge processed CAB write wrong!") ;
6897
        test_fail("bridge didn't process all the writes as it was supposed too") ;
6898
        disable main ;
6899
    end
6900
 
6901
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
6902
    // perform single read to force write data to pci
6903
    read_data`READ_ADDRESS = target_address + 8;
6904
    read_data`READ_SEL     = 4'hF ;
6905
 
6906
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6907
 
6908
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6909
    begin
6910
        $display("Transaction progress testing failed! Time %t ", $time) ;
6911
        $display("Bridge processed single read wrong!") ;
6912
        test_fail("bridge didn't process single memory read as expected") ;
6913
        disable main ;
6914
    end
6915
 
6916
    wishbone_master.blk_read_data_in[0] = read_data ;
6917
 
6918
    read_data`READ_ADDRESS = target_address + 12 ;
6919
    read_data`READ_SEL     = 4'hF ;
6920
 
6921
    wishbone_master.blk_read_data_in[1] = read_data ;
6922
 
6923
    read_data`READ_ADDRESS = target_address + 16 ;
6924
    read_data`READ_SEL     = 4'hF ;
6925
 
6926
    wishbone_master.blk_read_data_in[2] = read_data ;
6927
 
6928
    write_flags`WB_TRANSFER_CAB  = 1 ;
6929
    write_flags`WB_TRANSFER_SIZE = 2 ;
6930
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6931
    read_status = 0 ;
6932
 
6933
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6934
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6935
 
6936
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
6937
 
6938
    ok = 1 ;
6939
    fork
6940
    begin
6941
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
6942
            wishbone_master.wb_block_read( write_flags, read_status ) ;
6943
 
6944
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6945
        begin
6946
            $display("Transaction progress testing failed! Time %t ", $time) ;
6947
            $display("Bridge processed CAB read wrong!") ;
6948
            test_fail("bridge didn't process disconnected burst read as expected") ;
6949
        end
6950
        else
6951
        begin
6952
 
6953
            read_status = wishbone_master.blk_read_data_out[0] ;
6954
 
6955
            if (read_status`READ_DATA !== wmem_data[2])
6956
            begin
6957
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
6958
                test_fail("bridge provided wrong read data on disconnected burst read") ;
6959
            end
6960
            else
6961
                test_ok ;
6962
        end
6963
 
6964
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
6965
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
6966
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
6967
 
6968
        read_status = 0 ;
6969
 
6970
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
6971
            wishbone_master.wb_block_read( write_flags, read_status ) ;
6972
 
6973
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6974
        begin
6975
            $display("Transaction progress testing failed! Time %t ", $time) ;
6976
            $display("Bridge processed CAB read wrong!") ;
6977
            test_fail("bridge didn't process disconnected burst read as expected") ;
6978
        end
6979
        else
6980
        begin
6981
 
6982
            read_status = wishbone_master.blk_read_data_out[0] ;
6983
 
6984
            if (read_status`READ_DATA !== wmem_data[3])
6985
            begin
6986
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
6987
                test_fail("bridge provided wrong read data on disconnected burst read") ;
6988
            end
6989
            else
6990
                test_ok ;
6991
        end
6992
 
6993
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
6994
        // complete delayed read which was requested
6995
        read_data = wishbone_master.blk_read_data_in[2] ;
6996
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6997
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6998
 
6999
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7000
        begin
7001
            $display("Transaction progress testing failed! Time %t ", $time) ;
7002
            $display("Bridge processed single out of burst read wrong!") ;
7003
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7004
        end
7005
        else
7006
        begin
7007
 
7008
            if (read_status`READ_DATA !== wmem_data[4])
7009
            begin
7010
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7011
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7012
            end
7013
            else
7014
                test_ok ;
7015
        end
7016
 
7017
    end
7018
    begin
7019
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7020
 
7021
        if ( ok !== 1 )
7022
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7023
 
7024
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7025
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7026
 
7027
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7028
        if ( ok !== 1 )
7029
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7030
 
7031
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7032
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7033
 
7034
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7035
        if ( ok !== 1 )
7036
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7037
    end
7038
    join
7039
 
7040
    // now try burst read with normal termination
7041
    read_data`READ_ADDRESS = target_address + 12 ;
7042
    read_data`READ_SEL     = 4'hF ;
7043
 
7044
    wishbone_master.blk_read_data_in[0] = read_data ;
7045
 
7046
    read_data`READ_ADDRESS = target_address + 16 ;
7047
    read_data`READ_SEL     = 4'hF ;
7048
 
7049
    wishbone_master.blk_read_data_in[1] = read_data ;
7050
 
7051
    write_flags`WB_TRANSFER_SIZE = 2 ;
7052
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7053
    write_flags`WB_TRANSFER_CAB = 1 ;
7054
 
7055
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7056
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7057
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7058
 
7059
    fork
7060
    begin
7061
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7062
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7063
        begin
7064
            $display("Transaction progress testing failed! Time %t ", $time) ;
7065
            $display("Bridge processed CAB read wrong!") ;
7066
            test_fail("bridge didn't process burst read as expected") ;
7067
            ok = 0 ;
7068
        end
7069
    end
7070
    begin
7071
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7072
        if ( ok !== 1 )
7073
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7074
    end
7075
    join
7076
 
7077
    if ( ok )
7078
    begin
7079
        read_status = wishbone_master.blk_read_data_out[0] ;
7080
        if ( read_status`READ_DATA !== wmem_data[3] )
7081
        begin
7082
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7083
            test_fail("data provided from normaly terminated read was wrong") ;
7084
            ok = 0 ;
7085
        end
7086
 
7087
        read_status = wishbone_master.blk_read_data_out[1] ;
7088
        if ( read_status`READ_DATA !== wmem_data[4] )
7089
        begin
7090
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7091
            test_fail("data provided from normaly terminated read was wrong") ;
7092
            ok = 0 ;
7093
        end
7094
    end
7095
 
7096
    if ( ok )
7097
        test_ok ;
7098
 
7099
    // disable memory read line command and enable prefetch
7100
    // prepare image control register
7101
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7102
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7103
    if ( ok !== 1 )
7104
    begin
7105
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7106
        test_fail("WB Image Control register couldn't be written to") ;
7107
        disable main ;
7108
    end
7109
 
7110
    write_flags`WB_TRANSFER_SIZE = 4 ;
7111
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7112
    write_flags`WB_TRANSFER_CAB = 1 ;
7113
 
7114
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7115
 
7116
    for ( i = 0 ; i < 4 ; i = i + 1 )
7117
    begin
7118
        read_data`READ_ADDRESS = target_address + i*4 ;
7119
        read_data`READ_SEL     = 4'b1010 ;
7120
 
7121
        wishbone_master.blk_read_data_in[i] = read_data ;
7122
    end
7123
 
7124
    fork
7125
    begin
7126
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7127
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7128
        begin
7129
            $display("Transaction progress testing failed! Time %t ", $time) ;
7130
            $display("Bridge processed CAB read wrong!") ;
7131
            test_fail("bridge didn't process prefetched burst read as expected") ;
7132
            ok = 0 ;
7133
        end
7134
    end
7135
    begin
7136
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7137
        if ( ok !== 1 )
7138
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7139
    end
7140
    join
7141
 
7142
    if ( ok )
7143
    begin
7144
        for ( i = 0 ; i < 4 ; i = i + 1 )
7145
        begin
7146
            read_status = wishbone_master.blk_read_data_out[i] ;
7147
            if ( read_status`READ_DATA !== wmem_data[i] )
7148
            begin
7149
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7150
                test_fail("burst read returned unexpected data") ;
7151
                ok = 0 ;
7152
            end
7153
        end
7154
    end
7155
 
7156
    if ( ok )
7157
        test_ok ;
7158
 
7159
    // do one single read with different byte enables
7160
    read_data`READ_ADDRESS = target_address + 4 ;
7161
    read_data`READ_SEL     = 4'b1010 ;
7162
 
7163
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7164
    fork
7165
    begin
7166
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7167
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7168
        begin
7169
            $display("Transaction progress testing failed! Time %t ", $time) ;
7170
            $display("Bridge processed single read wrong!") ;
7171
            test_fail("bridge didn't process single memory read as expected") ;
7172
            ok = 0 ;
7173
        end
7174
    end
7175
    begin
7176
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7177
        if ( ok !== 1 )
7178
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7179
    end
7180
    join
7181
 
7182
    // check read data
7183
    if ( ok )
7184
    begin
7185
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7186
        begin
7187
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7188
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7189
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7190
            ok = 0 ;
7191
            test_fail("unexpected data received from single read") ;
7192
        end
7193
    end
7194
 
7195
    if ( ok )
7196
         test_ok ;
7197
 
7198
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7199
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7200
 
7201
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7202
    if ( ok !== 1 )
7203
    begin
7204
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7205
        test_fail("WB Image Control register could not be written") ;
7206
        disable main ;
7207
    end
7208
 
7209
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7210
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7211
    begin
7212
        read_data`READ_ADDRESS = target_address + i*4 ;
7213
        read_data`READ_SEL     = 4'b1111 ;
7214
 
7215
        wishbone_master.blk_read_data_in[i] = read_data ;
7216
    end
7217
 
7218
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7219
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7220
    write_flags`WB_TRANSFER_CAB = 1 ;
7221
 
7222
    fork
7223
    begin
7224
        read_status         = 0 ;
7225
        read_status`CYC_RTY = 1 ;
7226
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7227
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7228
 
7229
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7230
        begin
7231
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7232
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7233
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7234
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7235
            ok = 0 ;
7236
        end
7237
    end
7238
    begin
7239
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7240
        if ( ok !== 1 )
7241
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7242
    end
7243
    join
7244
 
7245
    // now repeat single read to flush redundant read initiated
7246
    write_flags`WB_TRANSFER_SIZE = 1 ;
7247
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7248
    write_flags`WB_TRANSFER_CAB = 1 ;
7249
 
7250
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7251
    read_data`READ_SEL     = 4'hF ;
7252
 
7253
    wishbone_master.blk_read_data_in[0] = read_data ;
7254
 
7255
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7256
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7257
 
7258
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7259
    begin
7260
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7261
        $display(" PCI bridge failed to process single CAB read!") ;
7262
        test_fail("single CAB write was not processed as expected") ;
7263
    end
7264
 
7265
    // because last read could be very long on PCI - delete target abort status
7266
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7267
 
7268
    // write unsupported value to cache line size register
7269
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7270
 
7271
    read_data`READ_ADDRESS = target_address ;
7272
    read_data`READ_SEL     = 4'hF ;
7273
    wishbone_master.blk_read_data_in[0] = read_data ;
7274
 
7275
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7276
    // perform a read
7277
    fork
7278
    begin
7279
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7280
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7281
        begin
7282
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7283
            $display(" PCI bridge failed to process single CAB read!") ;
7284
            test_fail("burst read was not processed as expected") ;
7285
            ok = 0 ;
7286
        end
7287
    end
7288
    begin
7289
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7290
        if ( ok !== 1 )
7291
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7292
    end
7293
    join
7294
 
7295
    if ( ok )
7296
        test_ok ;
7297
 
7298
    // write 2 to cache line size register
7299
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7300
 
7301
    // perform a read
7302
    fork
7303
    begin
7304
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7305
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7306
        begin
7307
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7308
            $display(" PCI bridge failed to process single CAB read!") ;
7309
            test_fail("burst read was not processed as expected") ;
7310
            ok = 0 ;
7311
        end
7312
    end
7313
    begin
7314
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7315
        if ( ok !== 1 )
7316
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7317
    end
7318
    join
7319
 
7320
    if ( ok )
7321
        test_ok ;
7322
 
7323
    // write 0 to cache line size
7324
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7325
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7326
 
7327
    // perform a read
7328
    fork
7329
    begin
7330
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7331
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7332
        begin
7333
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7334
            $display(" PCI bridge failed to process single CAB read!") ;
7335
            test_fail("burst read was not processed as expected") ;
7336
            ok = 0 ;
7337
        end
7338
    end
7339
    begin
7340
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7341
        if ( ok !== 1 )
7342
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7343
    end
7344
    join
7345
 
7346
    if ( ok )
7347
        test_ok ;
7348
 
7349
    // write normal value to cls register
7350
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7351
 
7352
    $display("Testing Master's latency timer operation!") ;
7353
    $display("Testing Latency timer during Master Writes!") ;
7354
 
7355
    for ( i = 0 ; i < 6 ; i = i + 1 )
7356
    begin
7357
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7358
        write_data`WRITE_SEL     = 4'b1111 ;
7359
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7360
 
7361
        wishbone_master.blk_write_data[i] = write_data ;
7362
    end
7363
 
7364
    write_flags`WB_TRANSFER_SIZE = 6 ;
7365
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7366
    write_flags`WB_TRANSFER_CAB = 1 ;
7367
 
7368
    // start wb write, pci write and monitor in parallel
7369
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7370
    fork
7371
    begin
7372
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7373
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7374
        begin
7375
            $display("Transaction progress testing failed! Time %t ", $time) ;
7376
            $display("Bridge failed to process CAB write!") ;
7377
            test_fail("bridge didn't post whole burst memory write") ;
7378
            disable main ;
7379
        end
7380
    end
7381
    begin
7382
        // wait for bridge's master to start transaction
7383
        @(posedge pci_clock) ;
7384
        while ( FRAME === 1 )
7385
            @(posedge pci_clock) ;
7386
 
7387
        // start behavioral master request
7388
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7389
               target_address, wmem_data[1023], `Test_All_Bytes,
7390
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7391
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7392
 
7393
        do_pause ( 1 ) ;
7394
    end
7395
    begin
7396
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7397
        if ( ok !== 1 )
7398
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7399
        else
7400
            test_ok ;
7401
    end
7402
    join
7403
 
7404
    // perform a read to check data
7405
    for ( i = 0 ; i < 6 ; i = i + 1 )
7406
    begin
7407
        read_data`READ_ADDRESS = target_address + i*4 ;
7408
        read_data`READ_SEL     = 4'b1111 ;
7409
 
7410
        wishbone_master.blk_read_data_in[i] = read_data ;
7411
    end
7412
 
7413
    write_flags`WB_TRANSFER_SIZE = 6 ;
7414
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7415
    write_flags`WB_TRANSFER_CAB = 1 ;
7416
 
7417
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7418
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7419
 
7420
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7421
    begin
7422
        $display("Transaction progress testing failed! Time %t ", $time) ;
7423
        $display("Bridge failed to process CAB read!") ;
7424
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7425
        disable main ;
7426
    end
7427
 
7428
    ok = 1 ;
7429
    for ( i = 0 ; i < 6 ; i = i + 1 )
7430
    begin
7431
        read_status = wishbone_master.blk_read_data_out[i] ;
7432
 
7433
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7434
        begin
7435
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7436
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7437
            test_fail("unexpected data read back from PCI") ;
7438
            ok = 0 ;
7439
        end
7440
    end
7441
 
7442
    if ( ok )
7443
        test_ok ;
7444
 
7445
    $display("Testing Latency timer during Master Reads!") ;
7446
 
7447
    // at least 2 words are transfered during Master Reads terminated with timeout
7448
    write_flags`WB_TRANSFER_SIZE = 2 ;
7449
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7450
    fork
7451
    begin
7452
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7453
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7454
        begin
7455
            $display("Transaction progress testing failed! Time %t ", $time) ;
7456
            $display("Bridge failed to process CAB read!") ;
7457
            test_fail("bridge didn't process burst read as expected") ;
7458
            ok = 0 ;
7459
        end
7460
    end
7461
    begin
7462
        // wait for bridge's master to start transaction
7463
        @(posedge pci_clock) ;
7464
        while ( FRAME === 1 )
7465
            @(posedge pci_clock) ;
7466
 
7467
        // start behavioral master request
7468
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7469
               target_address, wmem_data[0], `Test_All_Bytes,
7470
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7471
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7472
 
7473
        do_pause ( 1 ) ;
7474
    end
7475
    begin
7476
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7477
        if ( ok !== 1 )
7478
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7479
    end
7480
    join
7481
 
7482
    // check data provided by target
7483
    if ( ok )
7484
    begin
7485
        for ( i = 0 ; i < 2 ; i = i + 1 )
7486
        begin
7487
            read_status = wishbone_master.blk_read_data_out[i] ;
7488
 
7489
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7490
            begin
7491
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7492
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7493
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7494
                ok = 0 ;
7495
            end
7496
        end
7497
    end
7498
    if ( ok )
7499
        test_ok ;
7500
 
7501
    test_name = "DISABLE_IMAGE" ;
7502
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7503
    if ( ok !== 1 )
7504
    begin
7505
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7506
        test_fail("write to WB Address Mask register failed") ;
7507
        disable main ;
7508
    end
7509
 
7510
end
7511
endtask //wb_to_pci_transactions
7512
 
7513
task iack_cycle ;
7514
    reg `READ_STIM_TYPE   read_data ;
7515
    reg `READ_RETURN_TYPE read_status ;
7516
    reg `WB_TRANSFER_FLAGS flags ;
7517
 
7518
    reg [31:0] temp_var ;
7519
    reg ok ;
7520
begin
7521
 
7522
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7523
 
7524
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7525
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7526
 
7527
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7528
    read_data`READ_SEL     = 4'hF ;
7529
 
7530
    flags = 0 ;
7531
 
7532
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7533
 
7534
    irq_respond = 0 ;
7535
    irq_vector  = 32'hAAAA_AAAA ;
7536
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7537
 
7538
    fork
7539
    begin
7540
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7541
    end
7542
    begin
7543
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok) ;
7544
        if ( ok !== 1 )
7545
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7546
    end
7547
    join
7548
 
7549
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7550
    begin
7551
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7552
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7553
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7554
    end
7555
    else
7556
    if ( ok )
7557
        test_ok ;
7558
        // clearing the status bits
7559
        config_write(12'h4, 32'hFFFF_0000, 4'hC, ok);
7560
 
7561
    irq_respond = 1 ;
7562
    irq_vector  = 32'h5555_5555 ;
7563
 
7564
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7565
    fork
7566
    begin
7567
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7568
    end
7569
    begin
7570
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok) ;
7571
        if ( ok !== 1 )
7572
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7573
    end
7574
    join
7575
 
7576
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7577
    begin
7578
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7579
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7580
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7581
        ok = 0 ;
7582
    end
7583
 
7584
    if ( read_status`READ_DATA !== irq_vector )
7585
    begin
7586
        $display(" Time %t ", $time ) ;
7587
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7588
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7589
        ok = 0 ;
7590
    end
7591
 
7592
    if ( ok )
7593
        test_ok ;
7594
 
7595
    read_data`READ_SEL = 4'b0101 ;
7596
    irq_vector  = 32'hAAAA_AAAA ;
7597
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7598
    fork
7599
    begin
7600
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7601
    end
7602
    begin
7603
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok) ;
7604
        if ( ok !== 1 )
7605
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7606
    end
7607
    join
7608
 
7609
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7610
    begin
7611
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7612
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7613
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7614
        ok = 0 ;
7615
    end
7616
 
7617
    if ( read_status`READ_DATA !== 32'h00AA_00AA )
7618
    begin
7619
        $display(" Time %t ", $time ) ;
7620
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h00AA_00AA, read_status`READ_DATA ) ;
7621
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7622
        ok = 0 ;
7623
    end
7624
 
7625
    if ( ok )
7626
        test_ok ;
7627
 
7628
 
7629
end
7630
endtask //iack_cycle
7631
 
7632
task transaction_ordering ;
7633
    reg   [11:0] wb_ctrl_offset ;
7634
    reg   [11:0] wb_ba_offset ;
7635
    reg   [11:0] wb_am_offset ;
7636
    reg   [11:0] pci_ctrl_offset ;
7637
    reg   [11:0] pci_ba_offset ;
7638
    reg   [11:0] pci_am_offset ;
7639
    reg   [11:0] pci_device_ctrl_offset ;
7640
    reg   [11:0] wb_err_cs_offset ;
7641
    reg   [11:0] pci_err_cs_offset ;
7642
    reg   [11:0] icr_offset ;
7643
    reg   [11:0] isr_offset ;
7644
    reg   [11:0] lat_tim_cls_offset ;
7645
 
7646
    reg `WRITE_STIM_TYPE  write_data ;
7647
    reg `READ_STIM_TYPE   read_data ;
7648
    reg `READ_RETURN_TYPE read_status ;
7649
 
7650
    reg `WRITE_RETURN_TYPE write_status ;
7651
    reg `WB_TRANSFER_FLAGS write_flags ;
7652
    reg [31:0] temp_val1 ;
7653
    reg [31:0] temp_val2 ;
7654
    reg        ok   ;
7655
 
7656
    reg [31:0] wb_image_base ;
7657
    reg [31:0] wb_target_address ;
7658
    reg [31:0] pci_image_base ;
7659
    integer i ;
7660
 
7661
    reg     error_monitor_done ;
7662
begin:main
7663
    write_flags`INIT_WAITS = tb_init_waits ;
7664
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
7665
 
7666
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
7667
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
7668
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
7669
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
7670
 
7671
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
7672
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
7673
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
7674
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
7675
 
7676
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
7677
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
7678
    lat_tim_cls_offset = 12'hC ;
7679
    pci_device_ctrl_offset    = 12'h4 ;
7680
 
7681
    wb_target_address  = `BEH_TAR1_MEM_START ;
7682
    wb_image_base      = 0 ;
7683
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
7684
 
7685
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
7686
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
7687
    write_flags                    = 0 ;
7688
    write_flags`INIT_WAITS         = 0 ;
7689
    write_flags`SUBSEQ_WAITS       = 0 ;
7690
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7691
 
7692
    pci_image_base = Target_Base_Addr_R[1] ;
7693
 
7694
    // enable master & target operation
7695
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
7696
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
7697
    if ( ok !== 1 )
7698
    begin
7699
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
7700
        test_fail("write to PCI Device Control register failed") ;
7701
        disable main ;
7702
    end
7703
 
7704
    // prepare image control register
7705
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7706
    if ( ok !== 1 )
7707
    begin
7708
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7709
        test_fail("write to WB Image Control register failed") ;
7710
        disable main ;
7711
    end
7712
 
7713
    // prepare base address register
7714
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
7715
    if ( ok !== 1 )
7716
    begin
7717
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
7718
        test_fail("write to WB Base Address register failed") ;
7719
        disable main ;
7720
    end
7721
 
7722
    // write address mask register
7723
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7724
    if ( ok !== 1 )
7725
    begin
7726
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7727
        test_fail("write to WB Address Mask register failed") ;
7728
        disable main ;
7729
    end
7730
 
7731
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7732
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7733
    if ( ok !== 1 )
7734
    begin
7735
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
7736
        test_fail("write to WB Error Control and Status register failed") ;
7737
        disable main ;
7738
    end
7739
 
7740
    // prepare image control register
7741
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7742
    if ( ok !== 1 )
7743
    begin
7744
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
7745
        test_fail("write to PCI Image Control register failed") ;
7746
        disable main ;
7747
    end
7748
 
7749
    // prepare base address register
7750
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
7751
    if ( ok !== 1 )
7752
    begin
7753
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
7754
        test_fail("write to PCI Base Address register failed") ;
7755
        disable main ;
7756
    end
7757
 
7758
    // write address mask register
7759
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7760
    if ( ok !== 1 )
7761
    begin
7762
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
7763
        test_fail("write to PCI Address Mask register failed") ;
7764
        disable main ;
7765
    end
7766
 
7767
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7768
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7769
    if ( ok !== 1 )
7770
    begin
7771
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
7772
        test_fail("write to PCI Error Control and Status register failed") ;
7773
        disable main ;
7774
    end
7775
 
7776
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
7777
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7778
    if ( ok !== 1 )
7779
    begin
7780
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
7781
        test_fail("write to Interrupt Control register failed") ;
7782
        disable main ;
7783
    end
7784
 
7785
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
7786
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
7787
    if ( ok !== 1 )
7788
    begin
7789
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
7790
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
7791
        disable main ;
7792
    end
7793
 
7794
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
7795
 
7796
    // prepare wb_master write and read data
7797
    for ( i = 0 ; i < 4 ; i = i + 1 )
7798
    begin
7799
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
7800
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
7801
        write_data`WRITE_SEL     = 4'hF ;
7802
 
7803
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
7804
        read_data`READ_SEL       = write_data`WRITE_SEL ;
7805
 
7806
        wishbone_master.blk_write_data[i]   = write_data ;
7807
        wishbone_master.blk_read_data_in[i] = read_data ;
7808
    end
7809
 
7810
    // put wishbone slave in acknowledge and pci target in retry mode
7811
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
7812
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7813
 
7814
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
7815
 
7816
    fork
7817
    begin
7818
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7819
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
7820
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
7821
        begin
7822
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
7823
            test_fail("Bridge didn't post single memory write as expected") ;
7824
        end
7825
 
7826
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7827
        if ( ok !== 1 )
7828
        begin
7829
            $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) ;
7830
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
7831
            ok = 0 ;
7832
        end
7833
 
7834
        // now post single write to target - normal progress
7835
        if ( target_mem_image == 1 )
7836
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
7837
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
7838
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
7839
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7840
        else
7841
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
7842
 
7843
        do_pause( 1 ) ;
7844
 
7845
    end
7846
    begin:error_monitor_1
7847
        @(error_event_int) ;
7848
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
7849
        ok = 0 ;
7850
    end
7851
    begin
7852
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
7853
        if ( ok !== 1 )
7854
        begin
7855
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
7856
            test_fail("WB Master didn't start expected transaction on WB bus") ;
7857
        end
7858
        else
7859
        begin
7860
            while ( FRAME !== 1 || IRDY !== 1 )
7861
                @(posedge pci_clock) ;
7862
 
7863
            // enable response in PCI target
7864
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
7865
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7866
 
7867
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7868
            if ( ok !== 1 )
7869
            begin
7870
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
7871
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
7872
            end
7873
        end
7874
 
7875
        disable error_monitor_1 ;
7876
    end
7877
    join
7878
 
7879
    if ( ok )
7880
        test_ok ;
7881
 
7882
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
7883
 
7884
    // put WISHBONE slave in retry mode
7885
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
7886
 
7887
    fork
7888
    begin
7889
        // now post single write to target - normal progress
7890
        if ( target_mem_image == 1 )
7891
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
7892
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
7893
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
7894
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7895
        else
7896
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
7897
 
7898
        do_pause( 1 ) ;
7899
 
7900
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
7901
        if ( ok !== 1 )
7902
        begin
7903
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
7904
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
7905
        end
7906
 
7907
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7908
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
7909
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
7910
        begin
7911
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
7912
            test_fail("Bridge didn't post single memory write as expected") ;
7913
        end
7914
 
7915
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7916
        if ( ok !== 1 )
7917
        begin
7918
            $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) ;
7919
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
7920
            ok = 0 ;
7921
        end
7922
 
7923
        wait ( CYC_O === 0 ) ;
7924
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
7925
 
7926
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
7927
        if ( ok !== 1 )
7928
        begin
7929
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
7930
            test_fail("WB Master didn't start expected transaction on WB bus") ;
7931
        end
7932
 
7933
        disable error_monitor_2 ;
7934
    end
7935
    begin:error_monitor_2
7936
        @(error_event_int) ;
7937
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
7938
        ok = 0 ;
7939
    end
7940
    join
7941
 
7942
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
7943
 
7944
    // put wishbone slave in acknowledge and pci target in retry mode
7945
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
7946
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7947
 
7948
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
7949
 
7950
    fork
7951
    begin
7952
        write_flags`WB_TRANSFER_SIZE = 3 ;
7953
        write_flags`WB_TRANSFER_CAB  = 1 ;
7954
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7955
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7956
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
7957
        begin
7958
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
7959
            test_fail("Bridge didn't post burst memory write as expected") ;
7960
        end
7961
 
7962
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7963
        if ( ok !== 1 )
7964
        begin
7965
            $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) ;
7966
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
7967
            ok = 0 ;
7968
        end
7969
 
7970
        // now post single write to target - normal progress
7971
        if ( target_mem_image == 1 )
7972
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
7973
                        pci_image_base, 32'h5555_5555, 4'h0,
7974
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
7975
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7976
        else
7977
        begin
7978
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
7979
            do_pause( 1 ) ;
7980
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
7981
        end
7982
 
7983
        do_pause( 1 ) ;
7984
 
7985
    end
7986
    begin:error_monitor_3
7987
        @(error_event_int) ;
7988
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
7989
        ok = 0 ;
7990
    end
7991
    begin
7992
        if ( target_mem_image == 1 )
7993
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
7994
        else
7995
        begin
7996
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
7997
            if ( ok )
7998
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
7999
        end
8000
 
8001
        if ( ok !== 1 )
8002
        begin
8003
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8004
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8005
        end
8006
        else
8007
        begin
8008
            while ( FRAME !== 1 || IRDY !== 1 )
8009
                @(posedge pci_clock) ;
8010
 
8011
            // enable response in PCI target
8012
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8013
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8014
 
8015
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8016
            if ( ok !== 1 )
8017
            begin
8018
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8019
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8020
            end
8021
        end
8022
 
8023
        disable error_monitor_3 ;
8024
    end
8025
    join
8026
 
8027
    if ( ok )
8028
        test_ok ;
8029
 
8030
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8031
 
8032
    // put WISHBONE slave in retry mode
8033
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8034
 
8035
    fork
8036
    begin
8037
        // now post single write to target - normal progress
8038
        if ( target_mem_image == 1 )
8039
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8040
                        pci_image_base, 32'h5555_5555, 4'h0,
8041
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8042
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8043
        else
8044
        begin
8045
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8046
            do_pause( 1 ) ;
8047
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8048
        end
8049
 
8050
        do_pause( 1 ) ;
8051
 
8052
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8053
 
8054
        if ( ok !== 1 )
8055
        begin
8056
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8057
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8058
        end
8059
 
8060
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8061
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8062
        write_flags`WB_TRANSFER_CAB      = 1 ;
8063
 
8064
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8065
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8066
        begin
8067
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8068
            test_fail("Bridge didn't post burst memory write as expected") ;
8069
        end
8070
 
8071
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8072
        if ( ok !== 1 )
8073
        begin
8074
            $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) ;
8075
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8076
            ok = 0 ;
8077
        end
8078
 
8079
        @(posedge wb_clock) ;
8080
        while ( CYC_O === 1 )
8081
            @(posedge wb_clock) ;
8082
 
8083
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8084
 
8085
        if ( target_mem_image == 1 )
8086
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8087
        else
8088
        begin
8089
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8090
            if ( ok )
8091
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8092
        end
8093
 
8094
 
8095
        disable error_monitor_4 ;
8096
    end
8097
    begin:error_monitor_4
8098
        @(error_event_int) ;
8099
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8100
        ok = 0 ;
8101
    end
8102
    join
8103
 
8104
    if ( ok )
8105
        test_ok ;
8106
 
8107
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8108
 
8109
    // put wishbone slave in acknowledge and pci target in retry mode
8110
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8111
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8112
 
8113
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8114
 
8115
    master1_check_received_data = 1 ;
8116
 
8117
    error_monitor_done = 0 ;
8118
    fork
8119
    begin:error_monitor_5
8120
        @(error_event_int or error_monitor_done) ;
8121
        if ( !error_monitor_done )
8122
        begin
8123
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8124
            ok = 0 ;
8125
        end
8126
    end
8127
    begin
8128
 
8129
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8130
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8131
        begin
8132
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8133
            test_fail("Bridge didn't post single memory write as expected") ;
8134
        end
8135
 
8136
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8137
        if ( ok !== 1 )
8138
        begin
8139
            $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) ;
8140
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8141
            ok = 0 ;
8142
        end
8143
 
8144
        // start Read Through pci target
8145
        if ( target_mem_image == 1 )
8146
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8147
                          pci_image_base, 32'h5555_5555,
8148
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8149
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8150
        else
8151
            PCIU_IO_READ
8152
             (
8153
                `Test_Master_1,
8154
                pci_image_base,
8155
                32'h5555_5555,
8156
                4'h0,
8157
                1,
8158
                `Test_Target_Retry_On
8159
             );
8160
 
8161
         do_pause( 1 ) ;
8162
 
8163
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8164
         if ( ok !== 1 )
8165
         begin
8166
            $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) ;
8167
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8168
         end
8169
 
8170
         // repeat the read 4 times - it should be retried all the time by pci target
8171
        for ( i = 0 ; i < 4 ; i = i + 1 )
8172
        begin
8173
            if ( target_mem_image == 1 )
8174
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8175
                            pci_image_base, 32'h5555_5555,
8176
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8177
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8178
            else
8179
                PCIU_IO_READ
8180
                (
8181
                    `Test_Master_1,
8182
                    pci_image_base,
8183
                    32'h5555_5555,
8184
                    4'h0,
8185
                    1,
8186
                    `Test_Target_Retry_On
8187
                );
8188
 
8189
            do_pause( 1 ) ;
8190
        end
8191
 
8192
        // now do posted write through target - it must go through OK
8193
        if ( target_mem_image == 1 )
8194
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8195
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8196
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8197
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8198
        else
8199
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8200
 
8201
        do_pause( 1 ) ;
8202
 
8203
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8204
        if ( ok !== 1 )
8205
        begin
8206
           $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) ;
8207
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8208
        end
8209
 
8210
        // start a read through wb_slave
8211
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8212
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8213
        begin
8214
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8215
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8216
            ok = 0 ;
8217
        end
8218
 
8219
        @(posedge pci_clock) ;
8220
        while ( FRAME !== 1 || IRDY !== 1 )
8221
            @(posedge pci_clock) ;
8222
 
8223
        // set the target to normal completion
8224
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8225
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8226
 
8227
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8228
        if ( ok !== 1 )
8229
        begin
8230
            $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) ;
8231
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8232
            ok = 0 ;
8233
        end
8234
 
8235
        // now wait for delayed read to finish
8236
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8237
        if ( ok !== 1 )
8238
        begin
8239
            $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) ;
8240
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8241
            ok = 0 ;
8242
        end
8243
 
8244
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8245
        fork
8246
        begin
8247
                if ( target_mem_image == 1 )
8248
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8249
                                pci_image_base, 32'h5555_5555, 4'h0,
8250
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8251
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8252
                else
8253
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8254
 
8255
                do_pause( 1 ) ;
8256
                end
8257
                begin
8258
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8259
                end
8260
                join
8261
 
8262
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8263
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8264
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8265
        begin
8266
            $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) ;
8267
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8268
            ok = 0 ;
8269
        end
8270
 
8271
        fork
8272
        begin
8273
        // now complete a read from PCI Target
8274
            if ( target_mem_image == 1 )
8275
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8276
                            pci_image_base, 32'h5555_5555,
8277
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8278
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8279
            else
8280
                PCIU_IO_READ
8281
                (
8282
                    `Test_Master_1,
8283
                    pci_image_base,
8284
                    32'h5555_5555,
8285
                    4'h0,
8286
                    1,
8287
                    `Test_Target_Normal_Completion
8288
                );
8289
 
8290
            do_pause( 1 ) ;
8291
        end
8292
        begin
8293
            if ( target_mem_image == 1 )
8294
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8295
            else
8296
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8297
        end
8298
        join
8299
 
8300
        @(posedge pci_clock) ;
8301
        repeat( 4 )
8302
            @(posedge wb_clock) ;
8303
 
8304
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8305
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8306
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8307
        begin
8308
            $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) ;
8309
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8310
            ok = 0 ;
8311
        end
8312
 
8313
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8314
        if ( ok !== 1 )
8315
        begin
8316
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8317
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8318
            ok = 0 ;
8319
        end
8320
 
8321
        // finish a read on WISHBONE also
8322
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8323
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8324
        begin
8325
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8326
            test_fail("WB Slave didn't process single delayed read as expected") ;
8327
        end
8328
 
8329
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8330
        begin
8331
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8332
            ok = 0 ;
8333
        end
8334
 
8335
 
8336
        error_monitor_done = 1 ;
8337
    end
8338
    join
8339
 
8340
    if ( ok )
8341
        test_ok ;
8342
 
8343
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8344
 
8345
    // put wishbone slave in retry and pci target in completion mode
8346
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8347
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8348
 
8349
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8350
 
8351
    master1_check_received_data = 1 ;
8352
 
8353
    error_monitor_done = 0 ;
8354
    fork
8355
    begin:error_monitor_6
8356
        @(error_event_int or error_monitor_done) ;
8357
        if ( !error_monitor_done )
8358
        begin
8359
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8360
            ok = 0 ;
8361
        end
8362
    end
8363
    begin
8364
 
8365
        // do a write through Target
8366
        fork
8367
        begin
8368
            if ( target_mem_image == 1 )
8369
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8370
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8371
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8372
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8373
            else
8374
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8375
 
8376
            do_pause( 1 ) ;
8377
        end
8378
        begin
8379
            if ( target_mem_image == 1 )
8380
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8381
            else
8382
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8383
        end
8384
        join
8385
 
8386
        // start a read through WB slave
8387
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8388
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8389
        begin
8390
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8391
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8392
            ok = 0 ;
8393
        end
8394
 
8395
        // now wait for this read to finish on pci
8396
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8397
        if ( ok !== 1 )
8398
        begin
8399
            $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) ;
8400
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8401
            ok = 0 ;
8402
        end
8403
 
8404
        // repeat the read four times - it should be retried
8405
        for ( i = 0 ; i < 4 ; i = i + 1 )
8406
        begin
8407
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8408
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8409
            begin
8410
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8411
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8412
                ok = 0 ;
8413
            end
8414
        end
8415
 
8416
        // posted write through WB Slave - must go through
8417
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8418
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8419
        begin
8420
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8421
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8422
            ok = 0 ;
8423
        end
8424
 
8425
        // write must come through
8426
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8427
        if ( ok !== 1 )
8428
        begin
8429
            $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) ;
8430
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8431
            ok = 0 ;
8432
        end
8433
 
8434
        // do a read through pci target
8435
        if ( target_mem_image == 1 )
8436
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8437
                          pci_image_base + 12, 32'hDEAD_BEAF,
8438
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8439
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8440
        else
8441
            PCIU_IO_READ
8442
             (
8443
                `Test_Master_1,
8444
                pci_image_base + 12,
8445
                32'hDEAD_BEAF,
8446
                4'h0,
8447
                1,
8448
                `Test_Target_Retry_On
8449
             );
8450
 
8451
         do_pause( 1 ) ;
8452
 
8453
        // wait for current cycle to finish on WB
8454
        @(posedge wb_clock) ;
8455
        while( CYC_O === 1 )
8456
            @(posedge wb_clock) ;
8457
 
8458
        // set slave response to acknowledge
8459
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8460
 
8461
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8462
        if ( ok !== 1 )
8463
        begin
8464
            $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) ;
8465
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8466
        end
8467
 
8468
        // check the read to finish on wb
8469
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8470
        if ( ok !== 1 )
8471
        begin
8472
            $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) ;
8473
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8474
        end
8475
 
8476
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8477
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8478
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8479
        begin
8480
            $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) ;
8481
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8482
            ok = 0 ;
8483
        end
8484
 
8485
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8486
        fork
8487
        begin
8488
            if ( target_mem_image == 1 )
8489
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8490
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8491
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8492
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8493
            else
8494
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8495
        end
8496
        begin
8497
            if ( target_mem_image == 1 )
8498
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8499
            else
8500
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8501
        end
8502
        join
8503
 
8504
        do_pause( 1 ) ;
8505
 
8506
        // complete a read in WB Slave Unit
8507
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8508
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8509
        begin
8510
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8511
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8512
            ok = 0 ;
8513
        end
8514
 
8515
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8516
        begin
8517
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8518
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8519
            ok = 0 ;
8520
        end
8521
 
8522
        // wait for statuses to be propagated from one side of bridge to another
8523
        repeat( 4 )
8524
            @(posedge pci_clock) ;
8525
 
8526
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8527
        fork
8528
        begin
8529
            if ( target_mem_image == 1 )
8530
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8531
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8532
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8533
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8534
            else
8535
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8536
 
8537
            do_pause( 1 ) ;
8538
        end
8539
        begin
8540
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8541
            if ( ok !== 1 )
8542
            begin
8543
                $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) ;
8544
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8545
            end
8546
        end
8547
        join
8548
 
8549
        // finish the last read in PCI Target Unit
8550
        if ( target_mem_image == 1 )
8551
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8552
                          pci_image_base + 12, 32'hDEAD_BEAF,
8553
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8554
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8555
        else
8556
            PCIU_IO_READ
8557
             (
8558
                `Test_Master_1,
8559
                pci_image_base + 12,
8560
                32'hDEAD_BEAF,
8561
                4'h0,
8562
                1,
8563
                `Test_Target_Normal_Completion
8564
             );
8565
 
8566
         do_pause( 1 ) ;
8567
 
8568
         error_monitor_done = 1 ;
8569
    end
8570
    join
8571
 
8572
    if ( ok )
8573
        test_ok ;
8574
 
8575
end
8576
endtask // transaction_ordering
8577
 
8578
task pci_transaction_progress_monitor ;
8579
    input [31:0] address ;
8580
    input [3:0]  bus_command ;
8581
    input [31:0] num_of_transfers ;
8582
    input [31:0] num_of_cycles ;
8583
    input check_transfers ;
8584
    input check_cycles ;
8585
    input doing_fast_back_to_back ;
8586
    output ok ;
8587
    reg in_use ;
8588
    integer deadlock_counter ;
8589
    integer transfer_counter ;
8590
    integer cycle_counter ;
8591
    integer deadlock_max_val ;
8592
begin:main
8593
 
8594
    if ( in_use === 1 )
8595
    begin
8596
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8597
        ok = 0 ;
8598
        disable main ;
8599
    end
8600
 
8601
    // approximate number of cycles on WB bus for maximum transaction length
8602
    deadlock_max_val = tb_init_waits + 100 +
8603
                       `WBW_DEPTH *
8604
                       (tb_subseq_waits + 1 +
8605
                       `ifdef REGISTER_WBS_OUTPUTS
8606
                       1) ;
8607
                       `else
8608
                       0) ;
8609
                       `endif
8610
 
8611
    // time used for maximum transaction length on WB
8612
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
8613
 
8614
    // maximum pci clock cycles
8615
    `ifdef PCI33
8616
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
8617
    `else
8618
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
8619
    `endif
8620
 
8621
    in_use = 1 ;
8622
    ok     = 1 ;
8623
 
8624
    fork
8625
    begin:wait_start
8626
 
8627
        deadlock_counter = 0 ;
8628
 
8629
        @(posedge pci_clock) ;
8630
 
8631
        if ( doing_fast_back_to_back !== 1 )
8632
        begin
8633
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
8634
            begin
8635
                deadlock_counter = deadlock_counter + 1 ;
8636
                @(posedge pci_clock) ;
8637
            end
8638
            if ( FRAME !== 1 )
8639
            begin
8640
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8641
                in_use = 0 ;
8642
                ok     = 0 ;
8643
                disable main ;
8644
            end
8645
        end
8646
 
8647
        deadlock_counter = 0 ;
8648
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
8649
        begin
8650
            deadlock_counter = deadlock_counter + 1 ;
8651
            @(posedge pci_clock) ;
8652
        end
8653
 
8654
        if ( FRAME !== 0 )
8655
        begin
8656
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8657
            in_use = 0 ;
8658
            ok     = 0 ;
8659
            disable main ;
8660
        end
8661
    end //wait_start
8662
 
8663
    begin:addr_bc_monitor
8664
 
8665
        @(posedge pci_clock) ;
8666
 
8667
        if ( doing_fast_back_to_back !== 1 )
8668
        begin
8669
            while ( FRAME !== 1 )
8670
                @(posedge pci_clock) ;
8671
        end
8672
 
8673
        while( FRAME !== 0 )
8674
            @(posedge pci_clock) ;
8675
 
8676
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
8677
        if ( bus_command !== `BC_IACK )
8678
        begin
8679
            if ( AD !== address )
8680
            begin
8681
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
8682
                $display("Expected address = %h, detected address = %h ", address, AD) ;
8683
                ok = 0 ;
8684
            end
8685
        end
8686
 
8687
        if ( CBE !== bus_command )
8688
        begin
8689
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
8690
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
8691
            ok = 0 ;
8692
        end
8693
    end //addr_bc_monitor
8694
 
8695
    begin:transfer_checker
8696
        transfer_counter = 0 ;
8697
 
8698
        @(posedge pci_clock) ;
8699
 
8700
        if ( doing_fast_back_to_back !== 1 )
8701
        begin
8702
            while ( FRAME !== 1 )
8703
                @(posedge pci_clock) ;
8704
        end
8705
 
8706
        while( FRAME !== 0 )
8707
            @(posedge pci_clock) ;
8708
 
8709
        while( FRAME === 0 )
8710
        begin
8711
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
8712
                transfer_counter = transfer_counter + 1 ;
8713
            @(posedge pci_clock) ;
8714
        end
8715
 
8716
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
8717
        begin
8718
            @(posedge pci_clock) ;
8719
        end
8720
 
8721
        if ( (TRDY === 0) && (DEVSEL === 0) )
8722
                transfer_counter = transfer_counter + 1 ;
8723
 
8724
        if ( check_transfers === 1 )
8725
        begin
8726
            if ( transfer_counter !== num_of_transfers )
8727
            begin
8728
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
8729
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
8730
                ok = 0 ;
8731
            end
8732
        end
8733
    end //transfer_checker
8734
    begin:cycle_checker
8735
        if ( check_cycles )
8736
        begin
8737
            cycle_counter = 0 ;
8738
            @(posedge pci_clock) ;
8739
 
8740
            if ( doing_fast_back_to_back !== 1)
8741
            begin
8742
                while ( FRAME !== 1 )
8743
                    @(posedge pci_clock) ;
8744
            end
8745
 
8746
            while( FRAME !== 0 )
8747
                @(posedge pci_clock) ;
8748
 
8749
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
8750
            begin
8751
                cycle_counter = cycle_counter + 1 ;
8752
                @(posedge pci_clock) ;
8753
            end
8754
 
8755
            if ( FRAME !== 1 )
8756
            begin
8757
                while ((FRAME === 0) && (MAS0_GNT === 0))
8758
                    @(posedge pci_clock) ;
8759
 
8760
                if ( FRAME !== 1 )
8761
                begin
8762
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
8763
                        @(posedge pci_clock) ;
8764
 
8765
                    @(posedge pci_clock) ;
8766
 
8767
                    if ( FRAME !== 1 )
8768
                    begin
8769
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
8770
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
8771
                        ok = 0 ;
8772
                    end
8773
                end
8774
            end
8775
        end
8776
    end // cycle_checker
8777
    join
8778
 
8779
    in_use = 0 ;
8780
end
8781
endtask //pci_transaction_progress_monitor
8782
 
8783
reg CYC_O_previous ;
8784
always@(posedge wb_clock or posedge reset)
8785
begin
8786
    if ( reset )
8787
        CYC_O_previous <= #1 1'b0 ;
8788
    else
8789
        CYC_O_previous <= #1 CYC_O ;
8790
end
8791
 
8792
task wb_transaction_progress_monitor ;
8793
    input [31:0] address ;
8794
    input        write ;
8795
    input [31:0] num_of_transfers ;
8796
    input check_transfers ;
8797
    output ok ;
8798
    reg in_use ;
8799
    integer deadlock_counter ;
8800
    integer transfer_counter ;
8801
    integer deadlock_max_val ;
8802
begin:main
8803
    if ( in_use === 1 )
8804
    begin
8805
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8806
        ok = 0 ;
8807
        disable main ;
8808
    end
8809
 
8810
    // number of cycles on WB bus for maximum transaction length
8811
    deadlock_max_val = 4 - tb_init_waits + 100 +
8812
                       `PCIW_DEPTH *
8813
                       (4 - tb_subseq_waits + 1) ;
8814
 
8815
    // time used for maximum transaction length on PCI
8816
    `ifdef PCI33
8817
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
8818
    `else
8819
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
8820
    `endif
8821
 
8822
    // maximum wb clock cycles
8823
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
8824
 
8825
    in_use = 1 ;
8826
    ok     = 1 ;
8827
 
8828
    fork
8829
    begin:wait_start
8830
        deadlock_counter = 0 ;
8831
        @(posedge wb_clock) ;
8832
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
8833
        begin
8834
            deadlock_counter = deadlock_counter + 1 ;
8835
            @(posedge wb_clock) ;
8836
        end
8837
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
8838
        begin
8839
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8840
            in_use = 0 ;
8841
            ok     = 0 ;
8842
            disable main ;
8843
        end
8844
 
8845
        deadlock_counter = 0 ;
8846
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
8847
        begin
8848
            deadlock_counter = deadlock_counter + 1 ;
8849
            @(posedge wb_clock) ;
8850
        end
8851
 
8852
        if ( CYC_O !== 1 )
8853
        begin
8854
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8855
            in_use = 0 ;
8856
            ok     = 0 ;
8857
            disable main ;
8858
        end
8859
    end //wait_start
8860
    begin:addr_monitor
8861
        @(posedge wb_clock) ;
8862
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
8863
            @(posedge wb_clock) ;
8864
 
8865
        while( CYC_O !== 1 )
8866
            @(posedge wb_clock) ;
8867
 
8868
        while (STB_O !== 1 )
8869
            @(posedge wb_clock) ;
8870
 
8871
        if ( WE_O !== write )
8872
        begin
8873
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
8874
            if ( write !== 1 )
8875
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
8876
            else
8877
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
8878
        end
8879
 
8880
        if ( ADR_O !== address )
8881
        begin
8882
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
8883
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
8884
            ok = 0 ;
8885
        end
8886
    end
8887
    begin:transfer_checker
8888
        transfer_counter = 0 ;
8889
        @(posedge wb_clock) ;
8890
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
8891
            @(posedge wb_clock) ;
8892
 
8893
        while( CYC_O !== 1 )
8894
            @(posedge wb_clock) ;
8895
 
8896
        while( CYC_O === 1 )
8897
        begin
8898
            if ( (STB_O === 1) && (ACK_I === 1) )
8899
                transfer_counter = transfer_counter + 1 ;
8900
            @(posedge wb_clock) ;
8901
        end
8902
 
8903
        if ( check_transfers === 1 )
8904
        begin
8905
            if ( transfer_counter !== num_of_transfers )
8906
            begin
8907
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
8908
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
8909
                ok = 0 ;
8910
            end
8911
        end
8912
    end //transfer_checker
8913
    join
8914
 
8915
    in_use = 0 ;
8916
end
8917
endtask // wb_transaction_progress_monitor
8918
 
8919
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
8920
// so they are not re-entered
8921
task wb_transaction_progress_monitor_backup ;
8922
    input [31:0] address ;
8923
    input        write ;
8924
    input [31:0] num_of_transfers ;
8925
    input check_transfers ;
8926
    output ok ;
8927
    reg in_use ;
8928
    integer deadlock_counter ;
8929
    integer transfer_counter ;
8930
    integer deadlock_max_val ;
8931
begin:main
8932
    if ( in_use === 1 )
8933
    begin
8934
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8935
        ok = 0 ;
8936
        disable main ;
8937
    end
8938
 
8939
    // number of cycles on WB bus for maximum transaction length
8940
    deadlock_max_val = 4 - tb_init_waits + 100 +
8941
                       `PCIW_DEPTH *
8942
                       (4 - tb_subseq_waits + 1) ;
8943
 
8944
    // time used for maximum transaction length on PCI
8945
    `ifdef PCI33
8946
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
8947
    `else
8948
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
8949
    `endif
8950
 
8951
    // maximum wb clock cycles
8952
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
8953
 
8954
    in_use = 1 ;
8955
    ok     = 1 ;
8956
 
8957
    fork
8958
    begin:wait_start
8959
        deadlock_counter = 0 ;
8960
        @(posedge wb_clock) ;
8961
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
8962
        begin
8963
            deadlock_counter = deadlock_counter + 1 ;
8964
            @(posedge wb_clock) ;
8965
        end
8966
        if ( CYC_O !== 0 )
8967
        begin
8968
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8969
            in_use = 0 ;
8970
            ok     = 0 ;
8971
            disable main ;
8972
        end
8973
 
8974
        deadlock_counter = 0 ;
8975
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
8976
        begin
8977
            deadlock_counter = deadlock_counter + 1 ;
8978
            @(posedge wb_clock) ;
8979
        end
8980
 
8981
        if ( CYC_O !== 1 )
8982
        begin
8983
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8984
            in_use = 0 ;
8985
            ok     = 0 ;
8986
            disable main ;
8987
        end
8988
    end //wait_start
8989
    begin:addr_monitor
8990
        @(posedge wb_clock) ;
8991
        while ( CYC_O !== 0 )
8992
            @(posedge wb_clock) ;
8993
 
8994
        while( CYC_O !== 1 )
8995
            @(posedge wb_clock) ;
8996
 
8997
        while (STB_O !== 1 )
8998
            @(posedge wb_clock) ;
8999
 
9000
        if ( WE_O !== write )
9001
        begin
9002
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9003
            if ( write !== 1 )
9004
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9005
            else
9006
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9007
        end
9008
 
9009
        if ( ADR_O !== address )
9010
        begin
9011
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9012
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9013
            ok = 0 ;
9014
        end
9015
    end
9016
    begin:transfer_checker
9017
        transfer_counter = 0 ;
9018
        @(posedge wb_clock) ;
9019
        while ( CYC_O !== 0 )
9020
            @(posedge wb_clock) ;
9021
 
9022
        while( CYC_O !== 1 )
9023
            @(posedge wb_clock) ;
9024
 
9025
        while( CYC_O === 1 )
9026
        begin
9027
            if ( (STB_O === 1) && (ACK_I === 1) )
9028
                transfer_counter = transfer_counter + 1 ;
9029
            @(posedge wb_clock) ;
9030
        end
9031
 
9032
        if ( check_transfers === 1 )
9033
        begin
9034
            if ( transfer_counter !== num_of_transfers )
9035
            begin
9036
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9037
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9038
                ok = 0 ;
9039
            end
9040
        end
9041
    end //transfer_checker
9042
    join
9043
 
9044
    in_use = 0 ;
9045
end
9046
endtask // wb_transaction_progress_monitor_backup
9047
 
9048
task wb_transaction_stop ;
9049
    input [31:0] num_of_transfers ;
9050
    integer transfer_counter ;
9051
begin:main
9052
    begin:transfer_checker
9053
        transfer_counter = 0 ;
9054
        @(posedge wb_clock) ;
9055
        while ( CYC_O !== 0 )
9056
            @(posedge wb_clock) ;
9057
 
9058
        while( CYC_O !== 1 )
9059
            @(posedge wb_clock) ;
9060
 
9061
        if ( (STB_O === 1) && (ACK_I === 1) )
9062
            transfer_counter = transfer_counter + 1 ;
9063
 
9064
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9065
        begin
9066
            @(posedge wb_clock) ;
9067
            if ( (STB_O === 1) && (ACK_I === 1) )
9068
                transfer_counter = transfer_counter + 1 ;
9069
        end
9070
    end //transfer_checker
9071
end
9072
endtask // wb_transaction_stop
9073
 
9074
task musnt_respond ;
9075
    output ok ;
9076
    reg in_use ;
9077
    integer i ;
9078
begin:main
9079
    if ( in_use === 1 )
9080
    begin
9081
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9082
        #20 $stop ;
9083
        ok = 0 ;
9084
        disable main ;
9085
    end
9086
 
9087
    in_use = 1 ;
9088
    ok = 1 ;
9089
 
9090
    fork
9091
    begin:wait_start
9092
        @(negedge FRAME) ;
9093
        disable count ;
9094
    end
9095
    begin:count
9096
        i = 0 ;
9097
        while ( i < 1000 )
9098
        begin
9099
            @(posedge pci_clock) ;
9100
            i = i + 1 ;
9101
        end
9102
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9103
        ok = 0 ;
9104
        disable wait_start ;
9105
    end
9106
    join
9107
 
9108
    @(posedge pci_clock) ;
9109
    while ( FRAME === 0 && ok )
9110
    begin
9111
        if ( DEVSEL !== 1 )
9112
        begin
9113
            ok = 0 ;
9114
        end
9115
        @(posedge pci_clock) ;
9116
    end
9117
 
9118
    while ( IRDY === 0 && ok )
9119
    begin
9120
        if ( DEVSEL !== 1 )
9121
        begin
9122
            ok = 0 ;
9123
        end
9124
        @(posedge pci_clock) ;
9125
    end
9126
    in_use = 0 ;
9127
end
9128
endtask
9129
 
9130
function [31:0] wb_to_pci_addr_convert ;
9131
    input [31:0] wb_address ;
9132
    input [31:0] translation_address ;
9133
    input [31:0] translate ;
9134
 
9135
    reg   [31:0] temp_address ;
9136
begin
9137
    if ( translate !== 1 )
9138
    begin
9139
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9140
    end
9141
    else
9142
    begin
9143
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9144
    end
9145
 
9146
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9147
    wb_to_pci_addr_convert = temp_address ;
9148
end
9149
endfunction //wb_to_pci_addr_convert
9150
 
9151
task find_pci_devices ;
9152
    integer device_num ;
9153
    reg     found ;
9154
    reg [11:0] pci_ctrl_offset ;
9155
    reg ok ;
9156
    reg [31:0] data ;
9157
begin:main
9158
    pci_ctrl_offset = 12'h004 ;
9159
 
9160
    // enable master & target operation
9161
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9162
 
9163
    if ( ok !== 1 )
9164
    begin
9165
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9166
        $stop ;
9167
        disable main ;
9168
    end
9169
    // find all possible devices on pci bus by performing configuration cycles
9170
    for ( device_num = 0 ; device_num <= 20 ; device_num = device_num + 1 )
9171
    begin
9172
        find_device ( device_num, found ) ;
9173
 
9174
        // check pci status register - if device is not present, Received Master Abort bit must be set
9175
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9176
 
9177
        if ( (data[29] !== 0) && (found !== 0) )
9178
    begin
9179
            $display( "Time %t ", $time ) ;
9180
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9181
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9182
            #20 $stop ;
9183
        end
9184
 
9185
        if ( (data[29] !== 1) && (found !== 1) )
9186
        begin
9187
            $display( "Time %t ", $time ) ;
9188
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9189
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9190
            #20 $stop ;
9191
        end
9192
 
9193
        // clear Master Abort status if set
9194
        if ( data[29] !== 0 )
9195
        begin
9196
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9197
        end
9198
    end
9199
end //main
9200
endtask //find_pci_devices
9201
 
9202
task find_device ;
9203
    input [31:0] device_num ;
9204
    output  found ;
9205
 
9206
    reg [31:0] read_data ;
9207
begin
9208
    found = 1'b0 ;
9209
 
9210
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9211
    if ( read_data == 32'hFFFF_FFFF)
9212
        $display("Device %d not present on PCI bus!", device_num) ;
9213
    else
9214
    begin
9215
        $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]) ;
9216
        found = 1'b1 ;
9217
    end
9218
end
9219
endtask //find_device
9220
 
9221
/*task set_bridge_parameters ;
9222
    reg [11:0] current_offset ;
9223
    reg [2:0] result ;
9224
    reg [31:0] write_data ;
9225
begin
9226
    // set burst size
9227
    // set latency timer
9228
    current_offset = 12'h00C ;
9229
    // set burst size to 16 and latency timer to 8
9230
    write_data     = {24'h0000_08, system_burst_size} ;
9231
    config_write(current_offset, write_data, 4'b1111) ;
9232
 
9233
    // set io image
9234
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9235
    write_data = 32'h0000_000_3 ;
9236
    config_write(current_offset, write_data, 4'b1111) ;
9237
 
9238
 
9239
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9240
    write_data = 32'h0001_000_1 ;
9241
    config_write(current_offset, write_data, 4'b1111) ;
9242
 
9243
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9244
    write_data = 32'hFFFF_0000 ;
9245
    config_write(current_offset, write_data, 4'b1111) ;
9246
 
9247
    // set memory image
9248
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9249
    write_data = 32'h0000_000_7 ;
9250
    config_write(current_offset, write_data, 4'b1111) ;
9251
 
9252
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9253
    write_data = 32'h0002_000_0 ;
9254
    config_write(current_offset, write_data, 4'b1111) ;
9255
 
9256
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9257
    write_data = 32'h0001_0000 ;
9258
    config_write(current_offset, write_data, 4'b1111) ;
9259
 
9260
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9261
    write_data = 32'hFFFF_0000 ;
9262
    config_write(current_offset, write_data, 4'b1111) ;
9263
 
9264
    // set parameters for bridge's target unit
9265
    // image control 0
9266
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9267
    write_data     = 32'h0000_0002 ;
9268
    config_write(current_offset, write_data, 4'b0001) ;
9269
 
9270
    // base_address 0
9271
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9272
    write_data      = 32'h2000_0000 ;
9273
    config_write(current_offset, write_data, 4'b1111) ;
9274
 
9275
    // address mask 0
9276
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9277
    write_data     = 32'hFFFF_F000 ;
9278
    config_write(current_offset, write_data, 4'b1111) ;
9279
 
9280
    // command register - enable response to io and mem space and PCI master
9281
    current_offset = 12'h004 ;
9282
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9283
    config_write(current_offset, write_data, 4'b1111) ;
9284
end
9285
endtask // set_bridge_parameters
9286
*/
9287
 
9288
task configuration_cycle_write ;
9289
    input [7:0]  bus_num ;
9290
    input [4:0]  device_num ;
9291
    input [2:0]  func_num ;
9292
    input [5:0]  reg_num ;
9293
    input [1:0]  type ;
9294
    input [3:0]  byte_enables ;
9295
    input [31:0] data ;
9296
 
9297
    `ifdef HOST
9298
    reg `WRITE_STIM_TYPE write_data ;
9299
    reg `WB_TRANSFER_FLAGS write_flags ;
9300
    reg `WRITE_RETURN_TYPE write_status ;
9301
    `endif
9302
 
9303
    reg [31:0] write_address ;
9304
    reg [31:0] temp_var ;
9305
    reg in_use ;
9306
    reg ok ;
9307
begin:main
9308
 
9309
    if ( in_use === 1 )
9310
    begin
9311
        $display(" Task conf_write re-entered! Time %t ", $time ) ;
9312
        disable main ;
9313
    end
9314
 
9315
    if ( device_num > 20 )
9316
    begin
9317
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9318
        disable main ;
9319
    end
9320
 
9321
    in_use = 1 ;
9322
 
9323
    if ( type )
9324
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9325
    else
9326
    begin
9327
        write_address = 0 ;
9328
        write_address[10:0] = { func_num, reg_num, type } ;
9329
        write_address[11 + device_num] = 1'b1 ;
9330
    end
9331
 
9332
fork
9333
begin
9334
    `ifdef HOST
9335
    // setup write flags
9336
    write_flags                    = 0 ;
9337
    write_flags`INIT_WAITS         = tb_init_waits ;
9338
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
9339
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
9340
 
9341
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9342
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9343
 
9344
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9345
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9346
    write_data`WRITE_SEL      = 4'hF ;
9347
    write_data`WRITE_TAG_STIM = 0 ;
9348
 
9349
    wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
9350
 
9351
    // check if write succeeded
9352
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9353
    begin
9354
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9355
        $stop ;
9356
    end
9357
 
9358
    // write to configuration data register
9359
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
9360
 
9361
    write_data`WRITE_ADDRESS = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9362
    write_data`WRITE_DATA    = data ;
9363
    write_data`WRITE_SEL     = byte_enables ;
9364
 
9365
    wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
9366
 
9367
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9368
    begin
9369
        $display("Configuration cycle generation failed! Time %t ", $time) ;
9370
        $stop ;
9371
    end
9372
 
9373
    `else
9374
    `ifdef GUEST
9375
 
9376
     if ( type )
9377
         write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9378
     else
9379
     begin
9380
         write_address = 0 ;
9381
         write_address[10:0] = { func_num, reg_num, type } ;
9382
         write_address[11 + device_num] = 1'b1 ;
9383
     end
9384
     PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9385
                 write_address,
9386
                 data, ~byte_enables,
9387
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9388
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9389
     do_pause(1) ;
9390
    `endif
9391
    `endif
9392
end
9393
begin
9394
    pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9395
end
9396
join
9397
 
9398
    in_use = 0 ;
9399
end
9400
endtask // configuration_cycle_write
9401
 
9402
task configuration_cycle_read ;
9403
    input [7:0]  bus_num ;
9404
    input [4:0]  device_num ;
9405
    input [2:0]  func_num ;
9406
    input [5:0]  reg_num ;
9407
    input [1:0]  type ;
9408
    input [3:0]  byte_enables ;
9409
    output [31:0] data ;
9410
 
9411
    reg `READ_STIM_TYPE read_data ;
9412
    reg `WB_TRANSFER_FLAGS  flags ;
9413
    reg `READ_RETURN_TYPE   read_status ;
9414
 
9415
    reg `WRITE_STIM_TYPE   write_data ;
9416
    reg `WRITE_RETURN_TYPE write_status ;
9417
 
9418
    reg [31:0] read_address ;
9419
    reg in_use ;
9420
 
9421
    reg [31:0] temp_var ;
9422
    reg master_check_data_prev ;
9423
begin:main
9424
 
9425
    if ( in_use === 1 )
9426
    begin
9427
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9428
        data = 32'hxxxx_xxxx ;
9429
        disable main ;
9430
    end
9431
 
9432
    if ( device_num > 20 )
9433
    begin
9434
        $display("Configuration cycle generation only supports access to 20 devices!") ;
9435
        data = 32'hxxxx_xxxx ;
9436
        disable main ;
9437
    end
9438
 
9439
    in_use = 1 ;
9440
 
9441
    `ifdef HOST
9442
    // setup flags
9443
    flags = 0 ;
9444
 
9445
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9446
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9447
 
9448
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9449
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9450
    write_data`WRITE_SEL      = 4'hF ;
9451
    write_data`WRITE_TAG_STIM = 0 ;
9452
 
9453
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
9454
 
9455
    // check if write succeeded
9456
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9457
    begin
9458
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9459
        $stop ;
9460
        data = 32'hFFFF_FFFF ;
9461
        disable main ;
9462
    end
9463
 
9464
    // read from configuration data register
9465
    // setup flags for wb master to handle retries
9466
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
9467
 
9468
    read_data`READ_ADDRESS  = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9469
    read_data`READ_SEL      = 4'hF ;
9470
    read_data`READ_TAG_STIM = 0 ;
9471
 
9472
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
9473
 
9474
    // check if read succeeded
9475
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
9476
    begin
9477
        $display("Configuration cycle generation failed! Configuration read not processed correctly by the bridge! Time %t ", $time) ;
9478
        $stop ;
9479
        data = 32'hFFFF_FFFF ;
9480
        disable main ;
9481
    end
9482
 
9483
 
9484
    data = read_status`READ_DATA ;
9485
    `else
9486
    `ifdef GUEST
9487
     master_check_data_prev = master1_check_received_data ;
9488
     if ( type )
9489
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9490
     else
9491
     begin
9492
         read_address = 0 ;
9493
         read_address[10:0] = { func_num, reg_num, type } ;
9494
         read_address[11 + device_num] = 1'b1 ;
9495
     end
9496
 
9497
     fork
9498
     begin
9499
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9500
                 read_address,
9501
                 data, ~byte_enables,
9502
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9503
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9504
         do_pause(1) ;
9505
     end
9506
     begin
9507
         @(master1_received_data_valid) ;
9508
         data = master1_received_data ;
9509
     end
9510
     join
9511
 
9512
    master1_check_received_data = master_check_data_prev ;
9513
    `endif
9514
    `endif
9515
 
9516
    in_use = 0 ;
9517
 
9518
end //main
9519
endtask // configuration_cycle_read
9520
 
9521
task display_warning;
9522
    input [31:0] error_address ;
9523
    input [31:0] expected_data ;
9524
    input [31:0] actual ;
9525
begin
9526
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
9527
end
9528
endtask // display warning
9529
 
9530
/*############################################################################
9531
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
9532
=====================
9533
############################################################################*/
9534
 
9535
// Task reslease the PCI bus for 'delay' clocks
9536
task do_pause;
9537
  input  [15:0] delay;
9538
  reg    [15:0] cnt;
9539
  begin
9540
    test_start <= 1'b0;  // no device is allowed to take this
9541
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
9542
    begin
9543
      if (~pci_reset_comb)
9544
      begin
9545
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9546
      end
9547
      `NO_ELSE;
9548
    end
9549
  end
9550
endtask // do_pause
9551
 
9552
// Reference task for using pci_behavioral_master! (from Blue Beaver)
9553
task DO_REF;
9554
  input  [79:0] name;
9555
  input  [2:0] master_number;
9556
  input  [PCI_BUS_DATA_RANGE:0] address;
9557
  input  [3:0] command;
9558
  input  [PCI_BUS_DATA_RANGE:0] data;
9559
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
9560
  input  [9:0] size;
9561
  input   make_addr_par_error, make_data_par_error;
9562
  input  [7:0] master_wait_states;
9563
  input  [7:0] target_wait_states;
9564
  input  [1:0] target_devsel_speed;
9565
  input   fast_back_to_back;
9566
  input  [2:0] target_termination;
9567
  input   expect_master_abort;
9568
  reg     waiting;
9569
  begin
9570
// Cautiously wait for previous command to be done
9571
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
9572
    begin
9573
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
9574
      begin
9575
        if (~pci_reset_comb)
9576
        begin
9577
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9578
        end
9579
        `NO_ELSE;
9580
      end
9581
      else
9582
      begin
9583
        waiting = 1'b0;  // ready to do next command
9584
      end
9585
    end
9586
    next_test_name[79:0] <= name[79:0];
9587
    test_master_number <= master_number[2:0];
9588
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
9589
    test_command[3:0] <= command[3:0] ;
9590
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
9591
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
9592
    test_size <= size;
9593
    test_make_addr_par_error <= make_addr_par_error;
9594
    test_make_data_par_error <= make_data_par_error;
9595
    test_master_initial_wait_states <= 4 - tb_init_waits ;
9596
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
9597
    test_target_initial_wait_states <= target_wait_states[7:4];
9598
    test_target_subsequent_wait_states <= target_wait_states[3:0];
9599
    test_target_devsel_speed <= target_devsel_speed[1:0];
9600
    test_fast_back_to_back <= fast_back_to_back;
9601
    test_target_termination <= target_termination[2:0];
9602
    test_expect_master_abort <= expect_master_abort;
9603
    test_start <= 1'b1;
9604
    if (~pci_reset_comb)
9605
    begin
9606
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9607
    end
9608
    `NO_ELSE;
9609
// wait for new command to start
9610
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
9611
    begin
9612
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
9613
      begin
9614
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9615
      end
9616
      else
9617
      begin
9618
        waiting = 1'b0;  // ready to do next command
9619
      end
9620
    end
9621
  end
9622
endtask // DO_REF
9623
 
9624
// Use Macros defined in pci_defines.vh as paramaters
9625
 
9626
// DO_REF (name[79:0], master_number[2:0],
9627
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
9628
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
9629
//          make_addr_par_error, make_data_par_error,
9630
//          master_wait_states[8:0], target_wait_states[8:0],
9631
//          target_devsel_speed[1:0], fast_back_to_back,
9632
//          target_termination[2:0],
9633
//          expect_master_abort);
9634
//
9635
// Example:
9636
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
9637
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
9638
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
9639
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
9640
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
9641
 
9642
// Access a location with no high-order bits set, assuring that no device responds
9643
task PCIU_CONFIG_READ_MASTER_ABORT;
9644
  input  [79:0] name;
9645
  input  [2:0] master_number;
9646
  input  [9:0] size;
9647
  begin
9648
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9649
               PCI_COMMAND_CONFIG_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
9650
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
9651
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9652
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9653
  end
9654
endtask // PCIU_CONFIG_READ_MASTER_ABORT
9655
 
9656
// Access a location with no high-order bits set, assuring that no device responds
9657
task PCIU_CONFIG_WRITE_MASTER_ABORT;
9658
  input  [79:0] name;
9659
  input  [2:0] master_number;
9660
  input  [9:0] size;
9661
  begin
9662
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9663
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
9664
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
9665
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9666
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9667
  end
9668
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
9669
 
9670
// Access a location with no high-order bits set, assuring that no device responds
9671
task PCIU_MEM_READ_MASTER_ABORT;
9672
  input  [79:0] name;
9673
  input  [2:0] master_number;
9674
  input  [9:0] size;
9675
  begin
9676
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9677
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
9678
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
9679
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9680
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9681
  end
9682
endtask // PCIU_MEM_READ_MASTER_ABORT
9683
 
9684
// Access a location with no high-order bits set, assuring that no device responds
9685
task PCIU_MEM_WRITE_MASTER_ABORT;
9686
  input  [79:0] name;
9687
  input  [2:0] master_number;
9688
  input  [9:0] size;
9689
  begin
9690
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9691
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
9692
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
9693
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9694
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9695
  end
9696
endtask // PCIU_MEM_WRITE_MASTER_ABORT
9697
 
9698
// Do variable length transfers with various paramaters
9699
task PCIU_CONFIG_READ;
9700
  input  [79:0] name;
9701
  input  [2:0] master_number;
9702
  input  [PCI_BUS_DATA_RANGE:0] address;
9703
  input  [PCI_BUS_DATA_RANGE:0] data;
9704
  input  [3:0] be ;
9705
  input  [9:0] size;
9706
  input  [7:0] master_wait_states;
9707
  input  [7:0] target_wait_states;
9708
  input  [1:0] target_devsel_speed;
9709
  input  [2:0] target_termination;
9710
  begin
9711
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9712
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
9713
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9714
              8'h0_0, target_wait_states[7:0],
9715
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9716
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9717
  end
9718
endtask // PCIU_CONFIG_READ
9719
 
9720
task PCIU_CONFIG_WRITE;
9721
  input  [79:0] name;
9722
  input  [2:0] master_number;
9723
  input  [PCI_BUS_DATA_RANGE:0] address;
9724
  input  [PCI_BUS_DATA_RANGE:0] data;
9725
  input  [3:0] be ;
9726
  input  [9:0] size;
9727
  input  [7:0] master_wait_states;
9728
  input  [7:0] target_wait_states;
9729
  input  [1:0] target_devsel_speed;
9730
  input  [2:0] target_termination;
9731
  begin
9732
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9733
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
9734
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9735
              8'h0_0, target_wait_states[7:0],
9736
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9737
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9738
  end
9739
endtask // PCIU_CONFIG_WRITE
9740
 
9741
task PCIU_READ;
9742
  input  [2:0] master_number;
9743
  input  [PCI_BUS_DATA_RANGE:0] address;
9744
  input  [3:0] command;
9745
  input  [PCI_BUS_DATA_RANGE:0] data;
9746
  input  [3:0] byte_en;
9747
  input  [9:0] size;
9748
  input  [7:0] master_wait_states;
9749
  input  [7:0] target_wait_states;
9750
  input  [1:0] target_devsel_speed;
9751
  input  [2:0] target_termination;
9752
  reg    [79:0] name;
9753
  begin
9754
    if (command == `BC_MEM_READ)
9755
        name = "MEM_READ  " ;
9756
    else if (command == `BC_MEM_READ_LN)
9757
        name = "MEM_RD_LN " ;
9758
    else if (command == `BC_MEM_READ_MUL )
9759
        name = "MEM_RD_MUL" ;
9760
    else
9761
        name = "WRONG_READ" ;
9762
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9763
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9764
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9765
              8'h0_0, target_wait_states[7:0],
9766
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9767
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9768
  end
9769
endtask // PCIU_READ
9770
 
9771
task PCIU_MEM_READ;
9772
  input  [79:0] name;
9773
  input  [2:0] master_number;
9774
  input  [PCI_BUS_DATA_RANGE:0] address;
9775
  input  [PCI_BUS_DATA_RANGE:0] data;
9776
  input  [9:0] size;
9777
  input  [7:0] master_wait_states;
9778
  input  [7:0] target_wait_states;
9779
  input  [1:0] target_devsel_speed;
9780
  input  [2:0] target_termination;
9781
  begin
9782
 
9783
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9784
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9785
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9786
              8'h0_0, target_wait_states[7:0],
9787
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9788
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9789
  end
9790
endtask // PCIU_MEM_READ
9791
 
9792
task PCIU_IO_READ;
9793
  input  [2:0] master_number;
9794
  input  [PCI_BUS_DATA_RANGE:0] address;
9795
  input  [PCI_BUS_DATA_RANGE:0] data;
9796
  input  [3:0] byte_en ;
9797
  input  [9:0] size;
9798
  input  [2:0] target_termination ;
9799
  begin
9800
 
9801
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9802
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
9803
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9804
              8'h0_0, `Test_One_Zero_Target_WS,
9805
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9806
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9807
  end
9808
endtask // PCIU_IO_READ
9809
 
9810
task PCIU_IO_READ_MAKE_PERR;
9811
  input  [2:0] master_number;
9812
  input  [PCI_BUS_DATA_RANGE:0] address;
9813
  input  [PCI_BUS_DATA_RANGE:0] data;
9814
  input  [3:0] byte_en ;
9815
  input  [9:0] size;
9816
  input  [2:0] target_termination ;
9817
  begin
9818
 
9819
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9820
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
9821
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9822
              8'h0_0, `Test_One_Zero_Target_WS,
9823
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9824
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9825
  end
9826
endtask // PCIU_IO_READ_MAKE_PERR
9827
 
9828
task PCIU_MEM_READ_LN;
9829
  input  [79:0] name;
9830
  input  [2:0] master_number;
9831
  input  [PCI_BUS_DATA_RANGE:0] address;
9832
  input  [PCI_BUS_DATA_RANGE:0] data;
9833
  input  [9:0] size;
9834
  input  [7:0] master_wait_states;
9835
  input  [7:0] target_wait_states;
9836
  input  [1:0] target_devsel_speed;
9837
  input  [2:0] target_termination;
9838
  begin
9839
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9840
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9841
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9842
              8'h0_0, target_wait_states[7:0],
9843
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9844
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9845
  end
9846
endtask // PCIU_MEM_READ_LN
9847
 
9848
task PCIU_MEM_READ_MUL;
9849
  input  [79:0] name;
9850
  input  [2:0] master_number;
9851
  input  [PCI_BUS_DATA_RANGE:0] address;
9852
  input  [PCI_BUS_DATA_RANGE:0] data;
9853
  input  [9:0] size;
9854
  input  [7:0] master_wait_states;
9855
  input  [7:0] target_wait_states;
9856
  input  [1:0] target_devsel_speed;
9857
  input  [2:0] target_termination;
9858
  begin
9859
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9860
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9861
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9862
              8'h0_0, target_wait_states[7:0],
9863
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9864
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9865
  end
9866
endtask // PCIU_MEM_READ_MUL
9867
 
9868
task PCIU_MEM_READ_MAKE_PERR;
9869
  input  [79:0] name;
9870
  input  [2:0] master_number;
9871
  input  [PCI_BUS_DATA_RANGE:0] address;
9872
  input  [PCI_BUS_DATA_RANGE:0] data;
9873
  input  [9:0] size;
9874
  input  [7:0] master_wait_states;
9875
  input  [7:0] target_wait_states;
9876
  input  [1:0] target_devsel_speed;
9877
  input  [2:0] target_termination;
9878
  begin
9879
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9880
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9881
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9882
              8'h0_0, target_wait_states[7:0],
9883
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9884
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9885
  end
9886
endtask // PCIU_MEM_READ_MAKE_PERR
9887
 
9888
task PCIU_MEM_WRITE;
9889
  input  [79:0] name;
9890
  input  [2:0] master_number;
9891
  input  [PCI_BUS_DATA_RANGE:0] address;
9892
  input  [PCI_BUS_DATA_RANGE:0] data;
9893
  input  [3:0] byte_en;
9894
  input  [9:0] size;
9895
  input  [7:0] master_wait_states;
9896
  input  [7:0] target_wait_states;
9897
  input  [1:0] target_devsel_speed;
9898
  input  [2:0] target_termination;
9899
  begin
9900
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9901
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9902
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9903
              8'h0_0, target_wait_states[7:0],
9904
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9905
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9906
  end
9907
endtask // PCIU_MEM_WRITE
9908
 
9909
task PCIU_IO_WRITE;
9910
  input  [2:0] master_number;
9911
  input  [PCI_BUS_DATA_RANGE:0] address;
9912
  input  [PCI_BUS_DATA_RANGE:0] data;
9913
  input  [3:0] byte_en;
9914
  input  [9:0] size;
9915
  input  [2:0] target_termination ;
9916
  begin
9917
 
9918
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9919
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9920
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9921
              8'h0_0, `Test_One_Zero_Target_WS,
9922
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9923
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9924
  end
9925
endtask // PCIU_IO_WRITE
9926
 
9927
task PCIU_IO_WRITE_MAKE_PERR ;
9928
  input  [2:0] master_number;
9929
  input  [PCI_BUS_DATA_RANGE:0] address;
9930
  input  [PCI_BUS_DATA_RANGE:0] data;
9931
  input  [3:0] byte_en;
9932
  input  [9:0] size;
9933
  input  [2:0] target_termination ;
9934
  begin
9935
 
9936
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9937
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9938
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9939
              8'h0_0, `Test_One_Zero_Target_WS,
9940
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9941
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9942
  end
9943
endtask // PCIU_IO_WRITE
9944
 
9945
task PCIU_MEM_WRITE_MAKE_SERR;
9946
  input  [79:0] name;
9947
  input  [2:0] master_number;
9948
  input  [PCI_BUS_DATA_RANGE:0] address;
9949
  input  [PCI_BUS_DATA_RANGE:0] data;
9950
  input  [9:0] size;
9951
  input  [7:0] master_wait_states;
9952
  input  [7:0] target_wait_states;
9953
  input  [1:0] target_devsel_speed;
9954
  input  [2:0] target_termination;
9955
  begin
9956
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9957
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9958
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
9959
              8'h0_0, target_wait_states[7:0],
9960
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9961
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9962
  end
9963
endtask // PCIU_MEM_WRITE_MAKE_SERR
9964
 
9965
task PCIU_MEM_WRITE_MAKE_PERR;
9966
  input  [79:0] name;
9967
  input  [2:0] master_number;
9968
  input  [PCI_BUS_DATA_RANGE:0] address;
9969
  input  [PCI_BUS_DATA_RANGE:0] data;
9970
  input  [9:0] size;
9971
  input  [7:0] master_wait_states;
9972
  input  [7:0] target_wait_states;
9973
  input  [1:0] target_devsel_speed;
9974
  input  [2:0] target_termination;
9975
  begin
9976
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9977
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9978
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9979
              8'h0_0, target_wait_states[7:0],
9980
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9981
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9982
  end
9983
endtask // PCIU_MEM_WRITE
9984
 
9985
/*--------------------------------------------------------------------------
9986
Initialization CASES
9987
--------------------------------------------------------------------------*/
9988
 
9989
// Initialize the basic Config Registers of the PCI bridge target device
9990
task configure_bridge_target;
9991
    reg [11:0] offset ;
9992
    reg [31:0] data ;
9993
    `ifdef HOST
9994
    reg `WRITE_STIM_TYPE   write_data ;
9995
    reg `WB_TRANSFER_FLAGS write_flags ;
9996
    reg `WRITE_RETURN_TYPE write_status ;
9997
    `else
9998
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
9999
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
10000
    `endif
10001
 
10002
    reg [31:0] temp_var ;
10003
begin
10004
`ifdef HOST //  set Header
10005
    offset  = 12'h4 ; // PCI Header Command register
10006
    data    = 32'h0000_0007 ; // enable master & target operation
10007
 
10008
    write_flags                      = 0 ;
10009
    write_flags`INIT_WAITS           = tb_init_waits ;
10010
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10011
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
10012
 
10013
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
10014
    write_data`WRITE_SEL      = 4'h1 ;
10015
    write_data`WRITE_TAG_STIM = 0 ;
10016
    write_data`WRITE_DATA     = data ;
10017
 
10018
    next_test_name[79:0] <= "Init_Tar_R";
10019
 
10020
    $display(" bridge target - Enabling master and target operation!");
10021
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10022
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10023
    begin
10024
        $display("Write to configuration space failed! Time %t ", $time) ;
10025
    end
10026
 
10027
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10028
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10029
 
10030
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
10031
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10032
 
10033
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10034
    write_data`WRITE_SEL      = 4'hf ;
10035
    write_data`WRITE_TAG_STIM = 0 ;
10036
    write_data`WRITE_DATA     = data ;
10037
 
10038
 `ifdef  NO_CNF_IMAGE
10039
  `ifdef PCI_IMAGE0 //      set P_BA0
10040
 
10041
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10042
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10043
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10044
    begin
10045
        $display("Write to configuration space failed! Time %t ", $time) ;
10046
    end
10047
  `endif
10048
 `else //      set P_BA0
10049
 
10050
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10051
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10052
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10053
    begin
10054
        $display("Write to configuration space failed! Time %t ", $time) ;
10055
    end
10056
 `endif
10057
 
10058
`else // GUEST, set Header, set P_BA0
10059
    data            = 32'h0000_0007 ; // enable master & target operation
10060
    byte_enables    = 4'hF ;
10061
    $display(" bridge target - Enabling master and target operation!");
10062
    configuration_cycle_write(0,             // bus number
10063
                              0,             // device number
10064
                              0,             // function number
10065
                              1,             // register number
10066
                              0,             // type of configuration cycle
10067
                              byte_enables,  // byte enables
10068
                              data           // data
10069
                             ) ;
10070
 
10071
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10072
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10073
    byte_enables = 4'hf ;
10074
    configuration_cycle_write(0,             // bus number
10075
                              0,             // device number
10076
                              0,             // function number
10077
                              4,             // register number
10078
                              0,             // type of configuration cycle
10079
                              byte_enables,  // byte enables
10080
                              data           // data
10081
                             ) ;
10082
 
10083
`endif
10084
end
10085
endtask // configure_bridge_target
10086
 
10087
// Initialize the basic Config Registers of the PCI bridge target device
10088
task configure_bridge_target_base_addresses;
10089
    reg [11:0] offset ;
10090
    reg [31:0] data ;
10091
    `ifdef HOST
10092
    reg `WRITE_STIM_TYPE   write_data ;
10093
    reg `WB_TRANSFER_FLAGS write_flags ;
10094
    reg `WRITE_RETURN_TYPE write_status ;
10095
    `else
10096
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
10097
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
10098
    `endif
10099
 
10100
    reg [31:0] temp_var ;
10101
begin
10102
`ifdef HOST //  set Header
10103
    offset  = 12'h4 ; // PCI Header Command register
10104
    data    = 32'h0000_0007 ; // enable master & target operation
10105
 
10106
    write_flags                    = 0 ;
10107
    write_flags`INIT_WAITS         = tb_init_waits ;
10108
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
10109
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
10110
 
10111
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10112
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10113
 
10114
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10115
    write_data`WRITE_SEL      = 4'h1 ;
10116
    write_data`WRITE_TAG_STIM = 0 ;
10117
    write_data`WRITE_DATA     = data ;
10118
 
10119
    next_test_name[79:0] <= "Init_Tar_R";
10120
 
10121
    $display(" bridge target - Enabling master and target operation!");
10122
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10123
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10124
    begin
10125
        $display("Write to configuration space failed! Time %t ", $time) ;
10126
    end
10127
 
10128
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
10129
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10130
 
10131
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10132
    write_data`WRITE_SEL      = 4'hf ;
10133
    write_data`WRITE_TAG_STIM = 0 ;
10134
    write_data`WRITE_DATA     = data ;
10135
 
10136
 `ifdef  NO_CNF_IMAGE
10137
  `ifdef PCI_IMAGE0 //      set P_BA0
10138
 
10139
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10140
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10141
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10142
    begin
10143
        $display("Write to configuration space failed! Time %t ", $time) ;
10144
    end
10145
  `endif
10146
 `else //      set P_BA0
10147
 
10148
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10149
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10150
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10151
    begin
10152
        $display("Write to configuration space failed! Time %t ", $time) ;
10153
    end
10154
 `endif
10155
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
10156
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
10157
 
10158
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10159
    write_data`WRITE_SEL      = 4'hf ;
10160
    write_data`WRITE_TAG_STIM = 0 ;
10161
    write_data`WRITE_DATA     = data ;
10162
 
10163
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
10164
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10165
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10166
    begin
10167
        $display("Write to configuration space failed! Time %t ", $time) ;
10168
    end
10169
 `ifdef PCI_IMAGE2
10170
 
10171
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
10172
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
10173
 
10174
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10175
    write_data`WRITE_SEL      = 4'hf ;
10176
    write_data`WRITE_TAG_STIM = 0 ;
10177
    write_data`WRITE_DATA     = data ;
10178
 
10179
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
10180
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10181
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10182
    begin
10183
        $display("Write to configuration space failed! Time %t ", $time) ;
10184
    end
10185
 `endif
10186
 `ifdef PCI_IMAGE3
10187
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
10188
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
10189
 
10190
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10191
    write_data`WRITE_SEL      = 4'hf ;
10192
    write_data`WRITE_TAG_STIM = 0 ;
10193
    write_data`WRITE_DATA     = data ;
10194
 
10195
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
10196
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10197
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10198
    begin
10199
        $display("Write to configuration space failed! Time %t ", $time) ;
10200
    end
10201
 `endif
10202
 `ifdef PCI_IMAGE4
10203
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
10204
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
10205
 
10206
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10207
    write_data`WRITE_SEL      = 4'hf ;
10208
    write_data`WRITE_TAG_STIM = 0 ;
10209
    write_data`WRITE_DATA     = data ;
10210
 
10211
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
10212
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10213
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10214
    begin
10215
        $display("Write to configuration space failed! Time %t ", $time) ;
10216
    end
10217
 `endif
10218
 `ifdef PCI_IMAGE5
10219
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
10220
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
10221
 
10222
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10223
    write_data`WRITE_SEL      = 4'hf ;
10224
    write_data`WRITE_TAG_STIM = 0 ;
10225
    write_data`WRITE_DATA     = data ;
10226
 
10227
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
10228
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10229
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10230
    begin
10231
        $display("Write to configuration space failed! Time %t ", $time) ;
10232
    end
10233
 `endif
10234
 
10235
`else // GUEST, set Header, set P_BA0
10236
    data            = 32'h0000_0007 ; // enable master & target operation
10237
    byte_enables    = 4'hF ;
10238
    $display(" bridge target - Enabling master and target operation!");
10239
    configuration_cycle_write(0,             // bus number
10240
                              0,             // device number
10241
                              0,             // function number
10242
                              1,             // register number
10243
                              0,             // type of configuration cycle
10244
                              byte_enables,  // byte enables
10245
                              data           // data
10246
                             ) ;
10247
 
10248
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10249
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10250
    byte_enables = 4'hf ;
10251
    configuration_cycle_write(0,             // bus number
10252
                              0,             // device number
10253
                              0,             // function number
10254
                              4,             // register number
10255
                              0,             // type of configuration cycle
10256
                              byte_enables,  // byte enables
10257
                              data           // data
10258
                             ) ;
10259
 
10260
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
10261
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
10262
    byte_enables = 4'hf ;
10263
    configuration_cycle_write(0,             // bus number
10264
                              0,             // device number
10265
                              0,             // function number
10266
                              5,             // register number
10267
                              0,             // type of configuration cycle
10268
                              byte_enables,  // byte enables
10269
                              data           // data
10270
                             ) ;
10271
 `ifdef PCI_IMAGE2
10272
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
10273
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
10274
    byte_enables = 4'hf ;
10275
    configuration_cycle_write(0,             // bus number
10276
                              0,             // device number
10277
                              0,             // function number
10278
                              6,             // register number
10279
                              0,             // type of configuration cycle
10280
                              byte_enables,  // byte enables
10281
                              data           // data
10282
                             ) ;
10283
 `endif
10284
 `ifdef PCI_IMAGE3
10285
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
10286
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
10287
    byte_enables = 4'hf ;
10288
    configuration_cycle_write(0,             // bus number
10289
                              0,             // device number
10290
                              0,             // function number
10291
                              7,             // register number
10292
                              0,             // type of configuration cycle
10293
                              byte_enables,  // byte enables
10294
                              data           // data
10295
                             ) ;
10296
 `endif
10297
 `ifdef PCI_IMAGE4
10298
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
10299
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
10300
    byte_enables = 4'hf ;
10301
    configuration_cycle_write(0,             // bus number
10302
                              0,             // device number
10303
                              0,             // function number
10304
                              8,             // register number
10305
                              0,             // type of configuration cycle
10306
                              byte_enables,  // byte enables
10307
                              data           // data
10308
                             ) ;
10309
 `endif
10310
 `ifdef PCI_IMAGE5
10311
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
10312
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
10313
    byte_enables = 4'hf ;
10314
    configuration_cycle_write(0,             // bus number
10315
                              0,             // device number
10316
                              0,             // function number
10317
                              9,             // register number
10318
                              0,             // type of configuration cycle
10319
                              byte_enables,  // byte enables
10320
                              data           // data
10321
                             ) ;
10322
 `endif
10323
`endif
10324
end
10325
endtask // configure_bridge_target_base_addresses
10326
 
10327
/*--------------------------------------------------------------------------
10328
Test CASES
10329
--------------------------------------------------------------------------*/
10330
 
10331
// function converts PCI address to WB with the same data as the pci_decoder does
10332
function [31:0] pci_to_wb_addr_convert ;
10333
 
10334
    input [31:0] pci_address ;
10335
    input [31:0] translation_address ;
10336
    input [31:0] translate ;
10337
 
10338
    reg   [31:0] temp_address ;
10339
begin
10340
    if ( translate !== 1 )
10341
    begin
10342
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10343
    end
10344
    else
10345
    begin
10346
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10347
    end
10348
 
10349
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
10350
    pci_to_wb_addr_convert = temp_address ;
10351
end
10352
endfunction // pci_to_wb_addr_convert
10353
 
10354
// Test normal write and read to WB slave
10355
task test_normal_wr_rd;
10356
  input  [2:0]  Master_ID;
10357
  input  [PCI_BUS_DATA_RANGE:0] Address;
10358
  input  [PCI_BUS_DATA_RANGE:0] Data;
10359
  input  [3:0]  Be;
10360
  input  [2:0]  Image_num;
10361
  input  [9:0]  Set_size;
10362
  input         Set_addr_translation;
10363
  input         Set_prefetch_enable;
10364
  input  [7:0]  Cache_lsize;
10365
  input         Set_wb_wait_states;
10366
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
10367
 
10368
  reg    [31:0] rd_address;
10369
  reg    [31:0] rd_data;
10370
  reg    [3:0]  rd_be;
10371
  reg    [11:0] addr_offset;
10372
  reg    [31:0] read_data;
10373
  reg           continue ;
10374
  reg           ok   ;
10375
  reg    [31:0] expect_address ;
10376
  reg    [31:0] expect_rd_address ;
10377
  reg           expect_we ;
10378
  reg    [9:0]  expect_length_wr ;
10379
  reg    [9:0]  expect_length_rd ;
10380
  reg    [9:0]  expect_length_rd1 ;
10381
  reg    [9:0]  expect_length_rd2 ;
10382
  reg    [3:0]  use_rd_cmd ;
10383
  integer       i ;
10384
begin:main
10385
 
10386
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
10387
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10388
    $display(" - errors will be reported, but they should not occur!");
10389
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
10390
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10391
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
10392
    if ( ok !== 1 )
10393
    begin
10394
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
10395
        test_fail("write to P_ERR_CS register didn't succeede") ;
10396
        disable main;
10397
    end
10398
 
10399
    `ifdef  ADDR_TRAN_IMPL
10400
 
10401
    // set or clear address translation
10402
    if (Set_addr_translation)
10403
    begin
10404
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10405
        $display(" - address translation will be performed!");
10406
    end
10407
    else
10408
    begin
10409
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10410
        $display(" - address translation will not be performed!");
10411
    end
10412
    // set or clear pre-fetch enable
10413
    if (Set_prefetch_enable)
10414
    begin
10415
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10416
        $display(" - bursts can be performed!");
10417
    end
10418
    else
10419
    begin
10420
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10421
        $display(" - bursts can not be performed!");
10422
    end
10423
 
10424
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10425
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
10426
    if ( ok !== 1 )
10427
    begin
10428
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
10429
        test_fail("write to P_IMG_CTRL didn't succeede") ;
10430
        disable main;
10431
    end
10432
 
10433
    // predict the address and control signals on WB bus
10434
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
10435
    expect_we      = 1'b1 ; // WRITE
10436
 
10437
    `else
10438
 
10439
    // address translation is not implemented
10440
    $display("Address translation is NOT implemented for PCI images!");
10441
    // set or clear pre-fetch enable
10442
    if (Set_prefetch_enable)
10443
    begin
10444
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10445
        $display(" - bursts can be performed!");
10446
    end
10447
    else
10448
    begin
10449
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10450
        $display(" - bursts can not be performed!");
10451
    end
10452
 
10453
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10454
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
10455
    if ( ok !== 1 )
10456
    begin
10457
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
10458
        test_fail("write to P_IMG_CTRL didn't succeede") ;
10459
        disable main;
10460
    end
10461
 
10462
    // predict the address and control signals on WB bus
10463
    expect_address = Address ;
10464
    expect_we      = 1'b1 ; // WRITE
10465
 
10466
    `endif
10467
 
10468
    // set WB SLAVE parameters
10469
    if (Set_wb_wait_states)
10470
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
10471
    else
10472
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
10473
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
10474
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
10475
 
10476
    if ( Set_size > (`PCIW_DEPTH - 2) )
10477
    begin
10478
        expect_length_wr = `PCIW_DEPTH - 2 ;
10479
    end
10480
    else
10481
    begin
10482
        expect_length_wr = Set_size ;
10483
    end
10484
    // write through the PCI bridge to WB slave
10485
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
10486
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
10487
 
10488
    fork
10489
    begin
10490
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
10491
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
10492
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10493
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10494
        do_pause( 1 ) ;
10495
    end
10496
    begin
10497
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
10498
       if ( ok !== 1 )
10499
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
10500
       else
10501
           test_ok ;
10502
    end
10503
    join
10504
 
10505
    // predict the address and control signals on WB bus
10506
    expect_we      = 1'b0 ; // READ
10507
 
10508
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
10509
    $display("Memory read through PCI bridge to WB slave!");
10510
 
10511
    if ( expect_length_wr == 1 )
10512
    begin
10513
        if (Set_prefetch_enable)
10514
        begin
10515
            expect_length_rd1 = Cache_lsize ;
10516
            expect_length_rd2 = 0 ;
10517
                // If PCI behavioral master must check received DATA
10518
                master2_check_received_data = 0 ;
10519
                    master1_check_received_data = 0 ;
10520
        end
10521
        else
10522
        begin
10523
            expect_length_rd1 = 1 ;
10524
            expect_length_rd2 = 0 ;
10525
                // If PCI behavioral master must check received DATA
10526
                master2_check_received_data = 1 ;
10527
                    master1_check_received_data = 1 ;
10528
        end
10529
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10530
        expect_length_rd  = expect_length_rd1 ;
10531
    end
10532
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
10533
    begin
10534
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
10535
        expect_length_rd2 = 0 ;
10536
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10537
        expect_length_rd  = expect_length_rd1 ;
10538
                // If PCI behavioral master must check received DATA
10539
        master2_check_received_data = 1 ;
10540
            master1_check_received_data = 1 ;
10541
    end
10542
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
10543
    begin
10544
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
10545
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
10546
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10547
        expect_length_rd  = expect_length_rd1 ;
10548
                // If PCI behavioral master must check received DATA
10549
                master2_check_received_data = 1 ;
10550
            master1_check_received_data = 1 ;
10551
    end
10552
    else
10553
    begin
10554
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
10555
        begin
10556
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10557
            expect_length_rd2 = 0 ;
10558
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10559
            expect_length_rd  = expect_length_rd1 ;
10560
                // If PCI behavioral master must check received DATA
10561
                master2_check_received_data = 0 ;
10562
                    master1_check_received_data = 0 ;
10563
        end
10564
        else
10565
        begin
10566
            if ( expect_length_wr > Cache_lsize )
10567
            begin
10568
                expect_length_rd1 = Cache_lsize ;
10569
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
10570
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10571
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10572
                else
10573
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10574
                expect_length_rd  = expect_length_rd1 ;
10575
                        // If PCI behavioral master must check received DATA
10576
                        master2_check_received_data = 1 ;
10577
                            master1_check_received_data = 1 ;
10578
            end
10579
            else
10580
            begin
10581
                expect_length_rd1 = Cache_lsize ;
10582
                expect_length_rd2 = 0 ;
10583
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10584
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10585
                else
10586
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10587
                expect_length_rd  = expect_length_wr ;
10588
                                if ( expect_length_wr == Cache_lsize )
10589
                        begin
10590
                                // If PCI behavioral master must check received DATA
10591
                                master2_check_received_data = 1 ;
10592
                                    master1_check_received_data = 1 ;
10593
                                end
10594
                                else
10595
                                begin
10596
                                // If PCI behavioral master must check received DATA
10597
                                master2_check_received_data = 0 ;
10598
                                    master1_check_received_data = 0 ;
10599
                end
10600
            end
10601
        end
10602
    end
10603
 
10604
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
10605
    expect_rd_address = expect_address ;
10606
    rd_data[31:0] = Data[31:0];
10607
    rd_be[3:0] = Be[3:0];
10608
 
10609
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
10610
    while (expect_length_rd2 > 0)
10611
    begin
10612
        // do read
10613
        $display("Read %d words!", expect_length_rd);
10614
 
10615
        fork
10616
        begin
10617
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10618
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10619
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10620
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
10621
 
10622
            wb_transaction_stop( expect_length_rd - 1) ;
10623
 
10624
            do_pause( 1 ) ;
10625
        end
10626
        begin
10627
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
10628
            if ( ok !== 1 )
10629
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
10630
 
10631
            repeat( 3 )
10632
                @(posedge pci_clock) ;
10633
 
10634
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10635
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10636
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10637
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10638
 
10639
            do_pause( 1 ) ;
10640
            while ( FRAME === 0 )
10641
                @(posedge pci_clock) ;
10642
 
10643
            while ( IRDY === 0 )
10644
                @(posedge pci_clock) ;
10645
 
10646
            disable monitor_error_event1 ;
10647
        end
10648
        begin:monitor_error_event1
10649
            @(error_event_int) ;
10650
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
10651
            ok = 0 ;
10652
        end
10653
        join
10654
 
10655
        // increasing the starting address for PCI master and for WB transaction monitor
10656
        rd_address = rd_address + (4 * expect_length_rd) ;
10657
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
10658
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
10659
        rd_data[31:24] = Data[31:24] + expect_length_rd;
10660
        rd_data[23:16] = Data[23:16] + expect_length_rd;
10661
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
10662
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
10663
        for (i=0; i<expect_length_rd; i=i+1)
10664
            rd_be[3:0] = {Be[2:0], Be[3]};
10665
 
10666
        // set parameters for next read
10667
        if ( expect_length_rd2 == 1 )
10668
        begin
10669
                if (Set_prefetch_enable)
10670
                begin
10671
                    expect_length_rd1 = Cache_lsize ;
10672
                    expect_length_rd2 = 0 ;
10673
                        // If PCI behavioral master must check received DATA
10674
                        master2_check_received_data = 0 ;
10675
                            master1_check_received_data = 0 ;
10676
                end
10677
                else
10678
                begin
10679
                    expect_length_rd1 = 1 ;
10680
                    expect_length_rd2 = 0 ;
10681
                        // If PCI behavioral master must check received DATA
10682
                        master2_check_received_data = 1 ;
10683
                            master1_check_received_data = 1 ;
10684
                end
10685
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10686
            expect_length_rd  = expect_length_rd1 ;
10687
        end
10688
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
10689
        begin
10690
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10691
            expect_length_rd2 = 0 ;
10692
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10693
            expect_length_rd  = expect_length_rd1 ;
10694
                        // If PCI behavioral master must check received DATA
10695
                        master2_check_received_data = 1 ;
10696
                    master1_check_received_data = 1 ;
10697
        end
10698
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
10699
        begin
10700
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10701
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
10702
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10703
            expect_length_rd  = expect_length_rd1 ;
10704
                        // If PCI behavioral master must check received DATA
10705
                        master2_check_received_data = 1 ;
10706
                    master1_check_received_data = 1 ;
10707
        end
10708
        else
10709
        begin
10710
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
10711
            begin
10712
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
10713
                expect_length_rd2 = 0 ;
10714
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10715
                expect_length_rd  = expect_length_rd1 ;
10716
                        // If PCI behavioral master must check received DATA
10717
                        master2_check_received_data = 0 ;
10718
                            master1_check_received_data = 0 ;
10719
            end
10720
            else
10721
            begin
10722
                if ( expect_length_rd2 > Cache_lsize )
10723
                begin
10724
                    expect_length_rd1 = Cache_lsize ;
10725
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
10726
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10727
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10728
                    else
10729
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10730
                    expect_length_rd  = expect_length_rd1 ;
10731
                                // If PCI behavioral master must check received DATA
10732
                                master2_check_received_data = 1 ;
10733
                                    master1_check_received_data = 1 ;
10734
                end
10735
                else
10736
                begin
10737
                    expect_length_rd  = expect_length_rd2 ;
10738
                    expect_length_rd1 = Cache_lsize ;
10739
                    expect_length_rd2 = 0 ;
10740
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10741
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10742
                    else
10743
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10744
                                        if ( expect_length_rd2 == Cache_lsize )
10745
                                begin
10746
                                        // If PCI behavioral master must check received DATA
10747
                                        master2_check_received_data = 1 ;
10748
                                            master1_check_received_data = 1 ;
10749
                                        end
10750
                                        else
10751
                                        begin
10752
                                        // If PCI behavioral master must check received DATA
10753
                                        master2_check_received_data = 0 ;
10754
                                            master1_check_received_data = 0 ;
10755
                        end
10756
                end
10757
            end
10758
        end
10759
    end
10760
    // do last read
10761
    $display("Read %d words!", expect_length_rd);
10762
 
10763
    fork
10764
    begin
10765
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10766
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10767
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10768
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
10769
 
10770
        wb_transaction_stop(expect_length_rd - 1) ;
10771
        do_pause( 1 ) ;
10772
    end
10773
    begin
10774
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
10775
 
10776
        do_pause(3) ;
10777
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10778
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10779
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10780
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10781
        do_pause(1) ;
10782
 
10783
        while ( FRAME === 0 )
10784
            @(posedge pci_clock) ;
10785
 
10786
        while ( IRDY === 0 )
10787
            @(posedge pci_clock) ;
10788
 
10789
        disable monitor_error_event2 ;
10790
    end
10791
    begin:monitor_error_event2
10792
        @(error_event_int) ;
10793
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
10794
        ok = 0 ;
10795
    end
10796
    join
10797
 
10798
    if ( ok )
10799
        test_ok ;
10800
 
10801
    // Check that no ERRORs were reported
10802
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
10803
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
10804
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10805
    config_read( addr_offset, 4'hF, read_data ) ;
10806
    if ( read_data[8] !== 0 )
10807
    begin
10808
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
10809
        test_fail("error status was set even though no errors occured on WB bus") ;
10810
    end
10811
    else
10812
    begin
10813
        $display("No error was signaled, as expected!");
10814
        test_ok ;
10815
    end
10816
 
10817
end // main
10818
endtask // test_normal_wr_rd
10819
 
10820
// Test erroneous write to WB slave
10821
task test_wb_error_wr;
10822
  input  [2:0]  Master_ID;
10823
  input  [PCI_BUS_DATA_RANGE:0] Address;
10824
  input  [PCI_BUS_DATA_RANGE:0] Data;
10825
  input  [3:0]  Be;
10826
  input  [2:0]  Image_num;
10827
  input  [9:0]  Set_size;
10828
  input         Set_err_and_int_report;
10829
  input         Set_wb_wait_states;
10830
  input  [1:0]  Imm_BefLast_Last_error;
10831
 
10832
  reg    [11:0] addr_offset;
10833
  reg    [31:0] read_data;
10834
  reg           continue ;
10835
  reg           ok   ;
10836
  reg    [9:0]  expect_length ;
10837
  reg    [31:0] expect_address ;
10838
  reg    [0:0]  expect_we ;
10839
  reg    [31:0] rd_address;
10840
  reg    [31:0] rd_data;
10841
  reg    [3:0]  rd_be;
10842
  integer       i ;
10843
begin:main
10844
    if (Set_err_and_int_report)
10845
    begin
10846
        // enable ERROR reporting, because error must be reported and interrupt if required!
10847
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10848
        $display(" - errors will be reported when they will occur!");
10849
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
10850
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
10851
        $display(" - interrupt will be reported when error will occur!");
10852
    end
10853
    else
10854
    begin
10855
        // disable ERROR reporting, because error and interrupt must not be reported!
10856
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10857
        $display(" - errors will NOT be reported when they will occur!");
10858
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
10859
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
10860
        $display(" - interrupt will NOT be reported when error will occur!");
10861
    end
10862
    // enable/disable ERROR reporting
10863
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
10864
 
10865
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10866
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
10867
    if ( ok !== 1 )
10868
    begin
10869
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
10870
        test_fail("PCI Error Control and Status register could not be written") ;
10871
        disable main;
10872
    end
10873
    // enable/disable INTERRUPT reporting
10874
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
10875
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
10876
    if ( ok !== 1 )
10877
    begin
10878
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
10879
        test_fail("Interrupt Control register could not be written") ;
10880
        disable main;
10881
    end
10882
 
10883
    `ifdef  ADDR_TRAN_IMPL
10884
 
10885
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
10886
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10887
    config_read( addr_offset, 4'hF, read_data ) ;
10888
    if ( read_data[2] !== 0 )
10889
    begin
10890
        $display("Address translation is set for PCI image%d!", Image_num);
10891
        // predict the address and control signals on WB bus
10892
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
10893
        expect_we      = 1'b1 ; // WRITE
10894
    end
10895
    else
10896
    begin
10897
        $display("Address translation is NOT set for PCI image%d!", Image_num);
10898
        // predict the address and control signals on WB bus
10899
        expect_address = Address ;
10900
        expect_we      = 1'b1 ; // WRITE
10901
    end
10902
 
10903
    `else
10904
 
10905
    // address translation is not implemented
10906
    $display("Address translation is NOT implemented for PCI images!");
10907
    // predict the address and control signals on WB bus
10908
    expect_address = Address ;
10909
    expect_we      = 1'b1 ; // WRITE
10910
 
10911
    `endif
10912
 
10913
    if ( Set_size > (`PCIW_DEPTH - 2) )
10914
    begin
10915
        expect_length = `PCIW_DEPTH - 2 ;
10916
    end
10917
    else
10918
    begin
10919
        expect_length = Set_size ;
10920
    end
10921
 
10922
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
10923
    begin
10924
        $display("ERR termination with first data!");
10925
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
10926
    end
10927
    else if (Imm_BefLast_Last_error == 1)
10928
    begin
10929
        $display("ERR termination before last data!");
10930
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
10931
    end
10932
    else
10933
    begin
10934
        $display("ERR termination with last data!");
10935
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
10936
    end
10937
 
10938
    // write through the PCI bridge to WB slave
10939
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
10940
    fork
10941
    begin
10942
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
10943
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
10944
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10945
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10946
        do_pause( 1 ) ;
10947
    end
10948
    begin
10949
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
10950
        begin
10951
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
10952
            if ( ok !== 1 )
10953
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
10954
        end
10955
        else if (Imm_BefLast_Last_error == 1)
10956
        begin
10957
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
10958
            if ( ok !== 1 )
10959
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
10960
        end
10961
        else
10962
        begin
10963
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
10964
            if ( ok !== 1 )
10965
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
10966
        end
10967
    end
10968
    begin
10969
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
10970
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
10971
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
10972
        else if (Imm_BefLast_Last_error == 1)
10973
        begin
10974
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
10975
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
10976
            wb_transaction_stop(expect_length-2) ;
10977
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
10978
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
10979
        end
10980
        else
10981
        begin
10982
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
10983
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
10984
            wb_transaction_stop(expect_length-1) ;
10985
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
10986
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
10987
        end
10988
    end
10989
    join
10990
 
10991
    if ( ok )
10992
        test_ok ;
10993
 
10994
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
10995
    begin
10996
        rd_data[31:0] = Data[31:0];
10997
        rd_address[31:0] = expect_address;
10998
        rd_be[3:0] = Be[3:0];
10999
    end
11000
    else if (Imm_BefLast_Last_error == 1)
11001
    begin
11002
        rd_data[31:24] = Data[31:24] + expect_length - 2;
11003
        rd_data[23:16] = Data[23:16] + expect_length - 2;
11004
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
11005
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
11006
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
11007
        rd_be[3:0] = Be[3:0];
11008
        for (i=0; i<(expect_length-2); i=i+1)
11009
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
11010
    end
11011
    else
11012
    begin
11013
        rd_data[31:24] = Data[31:24] + expect_length - 1;
11014
        rd_data[23:16] = Data[23:16] + expect_length - 1;
11015
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
11016
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
11017
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
11018
        rd_be[3:0] = Be[3:0];
11019
        for (i=0; i<(expect_length-1); i=i+1)
11020
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
11021
    end
11022
 
11023
    master2_check_received_data = 0 ;
11024
    master1_check_received_data = 0 ;
11025
 
11026
    // Check if ERRORs were reported
11027
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
11028
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11029
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
11030
 
11031
    ok = 1 ;
11032
    config_read( addr_offset, 4'hF, read_data ) ;
11033
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
11034
    begin
11035
        $display("Error was signaled and reported, as expected!");
11036
        if (read_data[31:28] === rd_be)
11037
            $display("Byte enables written into P_ERR_CS register are as expected!");
11038
        else
11039
        begin
11040
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
11041
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
11042
            ok = 0 ;
11043
        end
11044
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
11045
            $display("Bus command written into P_ERR_CS register is as expected!");
11046
        else
11047
        begin
11048
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
11049
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
11050
            ok = 0 ;
11051
        end
11052
 
11053
        if ( ok )
11054
            test_ok ;
11055
 
11056
        $display("Reading the PCI Error Data register P_ERR_DATA.");
11057
 
11058
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11059
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
11060
        config_read( addr_offset, 4'hF, read_data ) ;
11061
        if (read_data === rd_data)
11062
        begin
11063
            $display("Data written into P_ERR_DATA register is as expected!");
11064
            test_ok ;
11065
        end
11066
        else
11067
        begin
11068
            $display("Data written into P_ERR_DATA register is NOT as expected!");
11069
            test_fail("PCI Erroneous Data register value was wrong") ;
11070
        end
11071
 
11072
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
11073
 
11074
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11075
 
11076
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
11077
        config_read( addr_offset, 4'hF, read_data ) ;
11078
        if (read_data === rd_address)
11079
        begin
11080
            $display("Address written into P_ERR_ADDR register is as expected!");
11081
            test_ok ;
11082
        end
11083
        else
11084
        begin
11085
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
11086
            test_fail("PCI Erroneous Address register value was wrong") ;
11087
        end
11088
    end
11089
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
11090
    begin
11091
        $display("Error was signaled and not reported, as expected!");
11092
        test_ok ;
11093
    end
11094
    else
11095
    begin
11096
        $display("Error was signaled and reported, as NOT expected!");
11097
        test_fail("Error status bit was set event though error reporting was disabled") ;
11098
    end
11099
 
11100
    // Check if Interrupts were reported
11101
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
11102
 
11103
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11104
    ok = 1 ;
11105
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
11106
    config_read( addr_offset, 4'hF, read_data ) ;
11107
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
11108
    begin
11109
        $display("Interrupts was signaled and reported, as expected!");
11110
    end
11111
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
11112
    begin
11113
        $display("Interrupts was signaled and not reported, as expected!");
11114
    end
11115
    else
11116
    begin
11117
        $display("Interrupt was signaled and reported, as NOT expected!");
11118
        test_fail("PCI Error Interrupt status was set when not expected") ;
11119
        ok = 0 ;
11120
    end
11121
 
11122
    `ifdef HOST
11123
    repeat( 4 )
11124
        @(posedge wb_clock) ;
11125
 
11126
    if ( INT_O === Set_err_and_int_report )
11127
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
11128
    else
11129
    begin
11130
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
11131
        test_fail("Interrupt request didn't have expected value") ;
11132
        ok = 0 ;
11133
    end
11134
 
11135
    `else // GUEST
11136
    repeat( 4 )
11137
        @(posedge pci_clock) ;
11138
 
11139
    if ( INTA === !Set_err_and_int_report )
11140
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
11141
    else
11142
    begin
11143
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
11144
        test_fail("Interrupt request didn't have expected value") ;
11145
        ok = 0 ;
11146
    end
11147
 
11148
    `endif
11149
 
11150
    if ( ok )
11151
        test_ok ;
11152
 
11153
    if (Set_err_and_int_report)
11154
    begin
11155
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11156
        $display("Error and Interrupt must be cleared!");
11157
        // clear  ERROR reporting bit
11158
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11159
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
11160
        if ( ok !== 1 )
11161
        begin
11162
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
11163
            test_fail("PCI Error Control and Status register could not be written to") ;
11164
            disable main;
11165
        end
11166
 
11167
        // clear INTERRUPT reporting bit
11168
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
11169
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
11170
        if ( ok !== 1 )
11171
        begin
11172
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
11173
            test_fail("Interrupt Status register could not be written to") ;
11174
            disable main;
11175
        end
11176
 
11177
        test_ok ;
11178
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
11179
        `ifdef HOST
11180
 
11181
        repeat(4)
11182
            @(posedge wb_clock) ;
11183
        if ( INT_O === 1'b0 )
11184
        begin
11185
            $display("Interrupt pin INT_O was correctly cleared!");
11186
            test_ok ;
11187
        end
11188
        else
11189
        begin
11190
            $display("Interrupt pin INT_O was NOT correctly cleared!");
11191
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
11192
            disable main;
11193
        end
11194
 
11195
        `else // GUEST
11196
 
11197
        repeat(4)
11198
            @(posedge pci_clock) ;
11199
        if ( INTA === 1'b1 )
11200
        begin
11201
            $display("Interrupt pin INTA was correctly cleared!");
11202
            test_ok ;
11203
        end
11204
        else
11205
        begin
11206
            $display("Interrupt pin INTA was NOT correctly cleared!");
11207
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
11208
            disable main;
11209
        end
11210
 
11211
        `endif
11212
 
11213
    end
11214
    else
11215
    begin
11216
        $display("Error and Interrupt don't need to be cleared!");
11217
    end
11218
end // main
11219
endtask // test_wb_error_wr
11220
 
11221
task test_wb_error_rd;
11222
    reg    [11:0] addr_offset ;
11223
    reg    [11:0] ctrl_offset ;
11224
    reg    [11:0] ba_offset ;
11225
    reg    [11:0] am_offset ;
11226
    reg    [11:0] ta_offset ;
11227
    reg    [31:0] read_data;
11228
    reg           ok   ;
11229
    reg    [9:0]  expect_length ;
11230
    reg    [31:0] expect_address ;
11231
    reg    [0:0]  expect_we ;
11232
    reg    [31:0] rd_address;
11233
    reg    [31:0] rd_data;
11234
    reg    [3:0]  rd_be;
11235
    integer       i ;
11236
    reg           do_mem_aborts ;
11237
    reg           do_io_aborts ;
11238
begin:main
11239
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
11240
 
11241
    if ( target_mem_image !== -1 )
11242
    begin
11243
        do_mem_aborts = 1 ;
11244
 
11245
        if (target_mem_image === 1)
11246
        begin
11247
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
11248
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
11249
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
11250
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
11251
        end
11252
        else if (target_mem_image === 2)
11253
        begin
11254
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
11255
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
11256
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
11257
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
11258
        end
11259
        else if (target_mem_image === 3)
11260
        begin
11261
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
11262
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
11263
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
11264
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
11265
        end
11266
        else if (target_mem_image === 4)
11267
        begin
11268
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
11269
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
11270
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
11271
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
11272
        end
11273
        else if (target_mem_image === 5)
11274
        begin
11275
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
11276
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
11277
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
11278
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
11279
        end
11280
    end
11281
    else
11282
        do_mem_aborts = 0 ;
11283
 
11284
    if ( do_mem_aborts )
11285
    begin
11286
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
11287
 
11288
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11289
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
11290
        if ( ok !== 1 )
11291
        begin
11292
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
11293
            test_fail("PCI Error Control and Status register could not be written") ;
11294
            disable main;
11295
        end
11296
 
11297
        // enable INTERRUPT reporting
11298
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
11299
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
11300
        if ( ok !== 1 )
11301
        begin
11302
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
11303
            test_fail("Interrupt Control register could not be written") ;
11304
            disable main;
11305
        end
11306
 
11307
        addr_offset = 12'h010 + (4*target_mem_image) ;
11308
 
11309
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
11310
        if ( ok !== 1 )
11311
        begin
11312
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
11313
            test_fail("PCI Base Address register could not be written") ;
11314
            disable main;
11315
        end
11316
 
11317
        // disable address translation and enable prefetch so read bursts can be performed
11318
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
11319
        if ( ok !== 1 )
11320
        begin
11321
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
11322
            test_fail("PCI Image Control register could not be written") ;
11323
            disable main;
11324
        end
11325
 
11326
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
11327
        if ( ok !== 1 )
11328
        begin
11329
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
11330
            test_fail("PCI Address Mask register could not be written") ;
11331
            disable main;
11332
        end
11333
 
11334
        addr_offset = 12'h00C ;
11335
 
11336
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
11337
        if ( ok !== 1 )
11338
        begin
11339
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
11340
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
11341
            disable main;
11342
        end
11343
 
11344
        // disable PCI master data checking
11345
        master1_check_received_data = 0 ;
11346
 
11347
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11348
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11349
 
11350
 
11351
        // do a single read error terminated on WB bus
11352
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
11353
 
11354
        fork
11355
        begin
11356
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11357
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11358
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11359
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
11360
 
11361
            do_pause( 1 ) ;
11362
        end
11363
        begin
11364
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11365
 
11366
            if ( ok !== 1 )
11367
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11368
 
11369
            do_pause(3) ;
11370
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11371
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11372
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11373
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
11374
            do_pause(1) ;
11375
 
11376
            while ( FRAME === 0 )
11377
                @(posedge pci_clock) ;
11378
 
11379
            while ( IRDY === 0 )
11380
                @(posedge pci_clock) ;
11381
 
11382
            disable monitor_error_event1 ;
11383
        end
11384
        begin:monitor_error_event1
11385
            @(error_event_int) ;
11386
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11387
            ok = 0 ;
11388
        end
11389
        join
11390
 
11391
        if ( ok )
11392
            test_ok ;
11393
 
11394
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11395
        addr_offset = 12'h004 ;
11396
        config_read(addr_offset, 4'hF, read_data) ;
11397
        ok = 1 ;
11398
        if ( read_data[27] !== 1 )
11399
        begin
11400
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11401
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11402
            ok = 0 ;
11403
        end
11404
        if ( read_data[28] !== 0 )
11405
        begin
11406
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11407
            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") ;
11408
            ok = 0 ;
11409
        end
11410
        if ( read_data[29] !== 0 )
11411
        begin
11412
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11413
            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") ;
11414
            ok = 0 ;
11415
        end
11416
 
11417
        // clear statuses
11418
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11419
        if ( !ok )
11420
        begin
11421
            test_fail("write to PCI Device Status register failed") ;
11422
            $display("Couldn't write PCI Device Status register") ;
11423
            disable main ;
11424
        end
11425
 
11426
        if ( ok )
11427
            test_ok ;
11428
 
11429
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11430
 
11431
        ok = 1 ;
11432
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11433
 
11434
        config_read(addr_offset, 4'hF, read_data) ;
11435
        if (read_data[8] !== 0)
11436
        begin
11437
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11438
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11439
            ok = 0 ;
11440
        end
11441
        else
11442
            test_ok ;
11443
 
11444
        if ( ok !== 1 )
11445
        begin
11446
            config_write(addr_offset, read_data, 4'hF, ok) ;
11447
            if ( !ok )
11448
            begin
11449
                test_fail("PCI Error Control and Status register could not be written") ;
11450
                disable main ;
11451
            end
11452
        end
11453
 
11454
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11455
        fork
11456
        begin
11457
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11458
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11459
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11460
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11461
 
11462
            do_pause( 1 ) ;
11463
        end
11464
        begin
11465
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11466
 
11467
            if ( ok !== 1 )
11468
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11469
 
11470
            do_pause(3) ;
11471
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11472
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11473
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11474
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11475
            do_pause(1) ;
11476
 
11477
            while ( FRAME === 0 )
11478
                @(posedge pci_clock) ;
11479
 
11480
            while ( IRDY === 0 )
11481
                @(posedge pci_clock) ;
11482
 
11483
            disable monitor_error_event2 ;
11484
        end
11485
        begin:monitor_error_event2
11486
            @(error_event_int) ;
11487
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11488
            ok = 0 ;
11489
        end
11490
        join
11491
 
11492
        if ( ok )
11493
            test_ok ;
11494
 
11495
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11496
        addr_offset = 12'h004 ;
11497
        config_read(addr_offset, 4'hF, read_data) ;
11498
        ok = 1 ;
11499
        if ( read_data[27] !== 1 )
11500
        begin
11501
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11502
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11503
            ok = 0 ;
11504
        end
11505
        if ( read_data[28] !== 0 )
11506
        begin
11507
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11508
            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") ;
11509
            ok = 0 ;
11510
        end
11511
        if ( read_data[29] !== 0 )
11512
        begin
11513
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11514
            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") ;
11515
            ok = 0 ;
11516
        end
11517
 
11518
        // clear statuses
11519
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11520
        if ( !ok )
11521
        begin
11522
            test_fail("write to PCI Device Status register failed") ;
11523
            $display("Couldn't write PCI Device Status register") ;
11524
            disable main ;
11525
        end
11526
 
11527
        if ( ok )
11528
            test_ok ;
11529
 
11530
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11531
 
11532
        ok = 1 ;
11533
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11534
 
11535
        config_read(addr_offset, 4'hF, read_data) ;
11536
        if (read_data[8] !== 0)
11537
        begin
11538
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11539
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11540
            ok = 0 ;
11541
        end
11542
        else
11543
            test_ok ;
11544
 
11545
        if ( ok !== 1 )
11546
        begin
11547
            config_write(addr_offset, read_data, 4'hF, ok) ;
11548
            if ( !ok )
11549
            begin
11550
                test_fail("PCI Error Control and Status register could not be written") ;
11551
                disable main ;
11552
            end
11553
        end
11554
 
11555
        // do a single read error terminated on WB bus
11556
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
11557
 
11558
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11559
 
11560
        fork
11561
        begin
11562
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11563
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11564
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11565
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11566
 
11567
            do_pause( 1 ) ;
11568
        end
11569
        begin
11570
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11571
 
11572
            if ( ok !== 1 )
11573
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11574
 
11575
            do_pause(3) ;
11576
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11577
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11578
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11579
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11580
            do_pause(1) ;
11581
 
11582
            while ( FRAME === 0 )
11583
                @(posedge pci_clock) ;
11584
 
11585
            while ( IRDY === 0 )
11586
                @(posedge pci_clock) ;
11587
 
11588
            disable monitor_error_event3 ;
11589
        end
11590
        begin:monitor_error_event3
11591
            @(error_event_int) ;
11592
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11593
            ok = 0 ;
11594
        end
11595
        join
11596
 
11597
        if ( ok )
11598
            test_ok ;
11599
 
11600
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11601
        addr_offset = 12'h004 ;
11602
        config_read(addr_offset, 4'hF, read_data) ;
11603
        ok = 1 ;
11604
        if ( read_data[27] !== 1 )
11605
        begin
11606
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11607
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11608
            ok = 0 ;
11609
        end
11610
        if ( read_data[28] !== 0 )
11611
        begin
11612
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11613
            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") ;
11614
            ok = 0 ;
11615
        end
11616
        if ( read_data[29] !== 0 )
11617
        begin
11618
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11619
            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") ;
11620
            ok = 0 ;
11621
        end
11622
 
11623
        // clear statuses
11624
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11625
        if ( !ok )
11626
        begin
11627
            test_fail("write to PCI Device Status register failed") ;
11628
            $display("Couldn't write PCI Device Status register") ;
11629
            disable main ;
11630
        end
11631
 
11632
        if ( ok )
11633
            test_ok ;
11634
 
11635
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11636
 
11637
        ok = 1 ;
11638
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11639
 
11640
        config_read(addr_offset, 4'hF, read_data) ;
11641
        if (read_data[8] !== 0)
11642
        begin
11643
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11644
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11645
            ok = 0 ;
11646
        end
11647
        else
11648
            test_ok ;
11649
 
11650
        if ( ok !== 1 )
11651
        begin
11652
            config_write(addr_offset, read_data, 4'hF, ok) ;
11653
            if ( !ok )
11654
            begin
11655
                test_fail("PCI Error Control and Status register could not be written") ;
11656
                disable main ;
11657
            end
11658
        end
11659
 
11660
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
11661
 
11662
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11663
 
11664
        fork
11665
        begin
11666
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11667
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11668
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11669
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11670
 
11671
            do_pause( 1 ) ;
11672
        end
11673
        begin
11674
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
11675
 
11676
            if ( ok !== 1 )
11677
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11678
 
11679
            do_pause(3) ;
11680
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11681
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11682
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11683
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11684
            do_pause(1) ;
11685
 
11686
            while ( FRAME === 0 )
11687
                @(posedge pci_clock) ;
11688
 
11689
            while ( IRDY === 0 )
11690
                @(posedge pci_clock) ;
11691
 
11692
            disable monitor_error_event4 ;
11693
        end
11694
        begin:monitor_error_event4
11695
            @(error_event_int) ;
11696
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11697
            ok = 0 ;
11698
        end
11699
        begin
11700
            wb_transaction_stop( 1 ) ;
11701
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11702
        end
11703
        join
11704
 
11705
        if ( ok )
11706
            test_ok ;
11707
 
11708
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11709
        addr_offset = 12'h004 ;
11710
        config_read(addr_offset, 4'hF, read_data) ;
11711
        ok = 1 ;
11712
        if ( read_data[27] !== 1 )
11713
        begin
11714
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11715
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11716
            ok = 0 ;
11717
        end
11718
        if ( read_data[28] !== 0 )
11719
        begin
11720
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11721
            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") ;
11722
            ok = 0 ;
11723
        end
11724
        if ( read_data[29] !== 0 )
11725
        begin
11726
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11727
            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") ;
11728
            ok = 0 ;
11729
        end
11730
 
11731
        // clear statuses
11732
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11733
        if ( !ok )
11734
        begin
11735
            test_fail("write to PCI Device Status register failed") ;
11736
            $display("Couldn't write PCI Device Status register") ;
11737
            disable main ;
11738
        end
11739
 
11740
        if ( ok )
11741
            test_ok ;
11742
 
11743
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11744
 
11745
        ok = 1 ;
11746
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11747
 
11748
        config_read(addr_offset, 4'hF, read_data) ;
11749
        if (read_data[8] !== 0)
11750
        begin
11751
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11752
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11753
            ok = 0 ;
11754
        end
11755
        else
11756
            test_ok ;
11757
 
11758
        if ( ok !== 1 )
11759
        begin
11760
            config_write(addr_offset, read_data, 4'hF, ok) ;
11761
            if ( !ok )
11762
            begin
11763
                test_fail("PCI Error Control and Status register could not be written") ;
11764
                disable main ;
11765
            end
11766
        end
11767
 
11768
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
11769
 
11770
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11771
 
11772
        fork
11773
        begin
11774
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11775
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11776
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11777
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11778
 
11779
            do_pause( 1 ) ;
11780
        end
11781
        begin
11782
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
11783
 
11784
            if ( ok !== 1 )
11785
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11786
 
11787
            do_pause(3) ;
11788
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11789
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11790
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11791
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
11792
            do_pause(1) ;
11793
 
11794
            while ( FRAME === 0 )
11795
                @(posedge pci_clock) ;
11796
 
11797
            while ( IRDY === 0 )
11798
                @(posedge pci_clock) ;
11799
 
11800
            disable monitor_error_event5 ;
11801
        end
11802
        begin:monitor_error_event5
11803
            @(error_event_int) ;
11804
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11805
            ok = 0 ;
11806
        end
11807
        begin
11808
            wb_transaction_stop( 3 ) ;
11809
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11810
        end
11811
        join
11812
 
11813
        if ( ok )
11814
            test_ok ;
11815
 
11816
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11817
        addr_offset = 12'h004 ;
11818
        config_read(addr_offset, 4'hF, read_data) ;
11819
        ok = 1 ;
11820
        if ( read_data[27] !== 1 )
11821
        begin
11822
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11823
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11824
            ok = 0 ;
11825
        end
11826
        if ( read_data[28] !== 0 )
11827
        begin
11828
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11829
            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") ;
11830
            ok = 0 ;
11831
        end
11832
        if ( read_data[29] !== 0 )
11833
        begin
11834
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11835
            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") ;
11836
            ok = 0 ;
11837
        end
11838
 
11839
        // clear statuses
11840
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11841
        if ( !ok )
11842
        begin
11843
            test_fail("write to PCI Device Status register failed") ;
11844
            $display("Couldn't write PCI Device Status register") ;
11845
            disable main ;
11846
        end
11847
 
11848
        if ( ok )
11849
            test_ok ;
11850
 
11851
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11852
 
11853
        ok = 1 ;
11854
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11855
 
11856
        config_read(addr_offset, 4'hF, read_data) ;
11857
        if (read_data[8] !== 0)
11858
        begin
11859
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11860
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11861
            ok = 0 ;
11862
        end
11863
        else
11864
            test_ok ;
11865
 
11866
        if ( ok !== 1 )
11867
        begin
11868
            config_write(addr_offset, read_data, 4'hF, ok) ;
11869
            if ( !ok )
11870
            begin
11871
                test_fail("PCI Error Control and Status register could not be written") ;
11872
                disable main ;
11873
            end
11874
        end
11875
 
11876
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
11877
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11878
        fork
11879
        begin
11880
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11881
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11882
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11883
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11884
 
11885
            do_pause( 1 ) ;
11886
        end
11887
        begin
11888
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
11889
 
11890
            if ( ok !== 1 )
11891
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11892
 
11893
            do_pause(3) ;
11894
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11895
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11896
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11897
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11898
            do_pause(1) ;
11899
 
11900
            while ( FRAME === 0 )
11901
                @(posedge pci_clock) ;
11902
 
11903
            while ( IRDY === 0 )
11904
                @(posedge pci_clock) ;
11905
 
11906
            disable monitor_error_event6 ;
11907
        end
11908
        begin:monitor_error_event6
11909
            @(error_event_int) ;
11910
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11911
            ok = 0 ;
11912
        end
11913
        begin
11914
            wb_transaction_stop( 3 ) ;
11915
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11916
        end
11917
        join
11918
 
11919
        if ( ok )
11920
            test_ok ;
11921
 
11922
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11923
        addr_offset = 12'h004 ;
11924
        config_read(addr_offset, 4'hF, read_data) ;
11925
        ok = 1 ;
11926
        if ( read_data[27] !== 1 )
11927
        begin
11928
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11929
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11930
            ok = 0 ;
11931
        end
11932
        if ( read_data[28] !== 0 )
11933
        begin
11934
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11935
            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") ;
11936
            ok = 0 ;
11937
        end
11938
        if ( read_data[29] !== 0 )
11939
        begin
11940
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11941
            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") ;
11942
            ok = 0 ;
11943
        end
11944
 
11945
        // clear statuses
11946
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11947
        if ( !ok )
11948
        begin
11949
            test_fail("write to PCI Device Status register failed") ;
11950
            $display("Couldn't write PCI Device Status register") ;
11951
            disable main ;
11952
        end
11953
 
11954
        if ( ok )
11955
            test_ok ;
11956
 
11957
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11958
 
11959
        ok = 1 ;
11960
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11961
 
11962
        config_read(addr_offset, 4'hF, read_data) ;
11963
        if (read_data[8] !== 0)
11964
        begin
11965
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11966
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11967
            ok = 0 ;
11968
        end
11969
        else
11970
            test_ok ;
11971
 
11972
        if ( ok !== 1 )
11973
        begin
11974
            config_write(addr_offset, read_data, 4'hF, ok) ;
11975
            if ( !ok )
11976
            begin
11977
                test_fail("PCI Error Control and Status register could not be written") ;
11978
                disable main ;
11979
            end
11980
        end
11981
 
11982
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
11983
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11984
        fork
11985
        begin
11986
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11987
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
11988
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11989
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11990
 
11991
            do_pause( 1 ) ;
11992
        end
11993
        begin
11994
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
11995
 
11996
            if ( ok !== 1 )
11997
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11998
 
11999
            do_pause(3) ;
12000
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12001
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12002
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12003
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
12004
            do_pause(1) ;
12005
 
12006
            while ( FRAME === 0 )
12007
                @(posedge pci_clock) ;
12008
 
12009
            while ( IRDY === 0 )
12010
                @(posedge pci_clock) ;
12011
 
12012
            disable monitor_error_event7 ;
12013
        end
12014
        begin:monitor_error_event7
12015
            @(error_event_int) ;
12016
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12017
            ok = 0 ;
12018
        end
12019
        begin
12020
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
12021
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12022
        end
12023
        join
12024
 
12025
        if ( ok )
12026
            test_ok ;
12027
 
12028
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12029
        addr_offset = 12'h004 ;
12030
        config_read(addr_offset, 4'hF, read_data) ;
12031
        ok = 1 ;
12032
        if ( read_data[27] !== 1 )
12033
        begin
12034
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12035
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12036
            ok = 0 ;
12037
        end
12038
        if ( read_data[28] !== 0 )
12039
        begin
12040
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12041
            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") ;
12042
            ok = 0 ;
12043
        end
12044
        if ( read_data[29] !== 0 )
12045
        begin
12046
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12047
            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") ;
12048
            ok = 0 ;
12049
        end
12050
 
12051
        // clear statuses
12052
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12053
        if ( !ok )
12054
        begin
12055
            test_fail("write to PCI Device Status register failed") ;
12056
            $display("Couldn't write PCI Device Status register") ;
12057
            disable main ;
12058
        end
12059
 
12060
        if ( ok )
12061
            test_ok ;
12062
 
12063
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12064
 
12065
        ok = 1 ;
12066
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12067
 
12068
        config_read(addr_offset, 4'hF, read_data) ;
12069
        if (read_data[8] !== 0)
12070
        begin
12071
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12072
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12073
            ok = 0 ;
12074
        end
12075
        else
12076
            test_ok ;
12077
 
12078
        if ( ok !== 1 )
12079
        begin
12080
            config_write(addr_offset, read_data, 4'hF, ok) ;
12081
            if ( !ok )
12082
            begin
12083
                test_fail("PCI Error Control and Status register could not be written") ;
12084
                disable main ;
12085
            end
12086
        end
12087
 
12088
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
12089
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12090
        fork
12091
        begin
12092
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12093
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12094
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12095
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12096
 
12097
            do_pause( 1 ) ;
12098
        end
12099
        begin
12100
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
12101
 
12102
            if ( ok !== 1 )
12103
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12104
 
12105
            do_pause(3) ;
12106
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12107
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12108
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12109
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
12110
            do_pause(1) ;
12111
 
12112
            while ( FRAME === 0 )
12113
                @(posedge pci_clock) ;
12114
 
12115
            while ( IRDY === 0 )
12116
                @(posedge pci_clock) ;
12117
 
12118
            disable monitor_error_event8 ;
12119
        end
12120
        begin:monitor_error_event8
12121
            @(error_event_int) ;
12122
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12123
            ok = 0 ;
12124
        end
12125
        begin
12126
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
12127
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12128
        end
12129
        join
12130
 
12131
        if ( ok )
12132
            test_ok ;
12133
 
12134
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12135
 
12136
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12137
        addr_offset = 12'h004 ;
12138
        config_read(addr_offset, 4'hF, read_data) ;
12139
        ok = 1 ;
12140
        if ( read_data[27] !== 1 )
12141
        begin
12142
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12143
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12144
            ok = 0 ;
12145
        end
12146
        if ( read_data[28] !== 0 )
12147
        begin
12148
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12149
            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") ;
12150
            ok = 0 ;
12151
        end
12152
        if ( read_data[29] !== 0 )
12153
        begin
12154
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12155
            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") ;
12156
            ok = 0 ;
12157
        end
12158
 
12159
        // clear statuses
12160
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12161
        if ( !ok )
12162
        begin
12163
            test_fail("write to PCI Device Status register failed") ;
12164
            $display("Couldn't write PCI Device Status register") ;
12165
            disable main ;
12166
        end
12167
 
12168
        if ( ok )
12169
            test_ok ;
12170
 
12171
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12172
 
12173
        ok = 1 ;
12174
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12175
 
12176
        config_read(addr_offset, 4'hF, read_data) ;
12177
        if (read_data[8] !== 0)
12178
        begin
12179
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12180
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12181
            ok = 0 ;
12182
        end
12183
        else
12184
            test_ok ;
12185
 
12186
        if ( ok !== 1 )
12187
        begin
12188
            config_write(addr_offset, read_data, 4'hF, ok) ;
12189
            if ( !ok )
12190
            begin
12191
                test_fail("PCI Error Control and Status register could not be written") ;
12192
                disable main ;
12193
            end
12194
        end
12195
 
12196
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
12197
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12198
        fork
12199
        begin
12200
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12201
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12202
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12203
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12204
 
12205
            do_pause( 1 ) ;
12206
        end
12207
        begin
12208
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
12209
 
12210
            if ( ok !== 1 )
12211
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12212
 
12213
            do_pause(3) ;
12214
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12215
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12216
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12217
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12218
            do_pause(1) ;
12219
 
12220
            while ( FRAME === 0 )
12221
                @(posedge pci_clock) ;
12222
 
12223
            while ( IRDY === 0 )
12224
                @(posedge pci_clock) ;
12225
 
12226
            disable monitor_error_event9 ;
12227
        end
12228
        begin:monitor_error_event9
12229
            @(error_event_int) ;
12230
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12231
            ok = 0 ;
12232
        end
12233
        begin
12234
            wb_transaction_stop( 3 ) ;
12235
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12236
        end
12237
        join
12238
 
12239
        if ( ok )
12240
            test_ok ;
12241
 
12242
        // now check all other statuses too
12243
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
12244
        ok = 1 ;
12245
 
12246
        addr_offset = 12'h004 ;
12247
        config_read(addr_offset, 4'hF, read_data) ;
12248
        if (read_data[31] !== 0)
12249
        begin
12250
            $display("Detected Parity Error bit set for no reason") ;
12251
            test_fail("Detected Parity Error bit was set for no reason") ;
12252
            ok = 0 ;
12253
        end
12254
 
12255
        if (read_data[30] !== 0)
12256
        begin
12257
            $display("Signaled System Error bit set for no reason") ;
12258
            test_fail("Signaled System Error bit was set for no reason") ;
12259
            ok = 0 ;
12260
        end
12261
 
12262
        if (read_data[29] !== 0)
12263
        begin
12264
            $display("Received Master Abort bit set for no reason") ;
12265
            test_fail("Received Master Abort bit was set for no reason") ;
12266
            ok = 0 ;
12267
        end
12268
 
12269
        if (read_data[28] !== 0)
12270
        begin
12271
            $display("Received Target Abort bit set for no reason");
12272
            test_fail("Received Target Abort bit was set for no reason") ;
12273
            ok = 0 ;
12274
        end
12275
 
12276
        if (read_data[27] !== 0)
12277
        begin
12278
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
12279
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
12280
            ok = 0 ;
12281
        end
12282
 
12283
        if (read_data[24] !== 0)
12284
        begin
12285
            $display("Master Data Parity Error bit set for no reason") ;
12286
            test_fail("Master Data Parity Error bit was set for no reason") ;
12287
            ok = 0 ;
12288
        end
12289
 
12290
        if ( ok )
12291
            test_ok ;
12292
 
12293
        test_name = "DISABLE IMAGE" ;
12294
        config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
12295
        if ( ok !== 1 )
12296
        begin
12297
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12298
            test_fail("PCI Address Mask register could not be written") ;
12299
            disable main;
12300
        end
12301
    end
12302
 
12303
    if ( target_io_image !== -1 )
12304
    begin
12305
        do_io_aborts = 1 ;
12306
 
12307
        if (target_io_image === 1)
12308
        begin
12309
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
12310
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
12311
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
12312
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
12313
        end
12314
        else if (target_io_image === 2)
12315
        begin
12316
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
12317
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
12318
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
12319
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
12320
        end
12321
        else if (target_io_image === 3)
12322
        begin
12323
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
12324
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
12325
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
12326
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
12327
        end
12328
        else if (target_io_image === 4)
12329
        begin
12330
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
12331
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
12332
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
12333
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
12334
        end
12335
        else if (target_io_image === 5)
12336
        begin
12337
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
12338
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
12339
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
12340
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
12341
        end
12342
    end
12343
    else
12344
        do_io_aborts = 0 ;
12345
 
12346
    if ( do_io_aborts )
12347
    begin
12348
 
12349
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
12350
 
12351
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12352
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
12353
        if ( ok !== 1 )
12354
        begin
12355
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12356
            test_fail("PCI Error Control and Status register could not be written") ;
12357
            disable main;
12358
        end
12359
 
12360
        // enable INTERRUPT reporting
12361
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
12362
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
12363
        if ( ok !== 1 )
12364
        begin
12365
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
12366
            test_fail("Interrupt Control register could not be written") ;
12367
            disable main;
12368
        end
12369
 
12370
        addr_offset = 12'h010 + (4*target_io_image) ;
12371
 
12372
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
12373
        if ( ok !== 1 )
12374
        begin
12375
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
12376
            test_fail("PCI Base Address register could not be written") ;
12377
            disable main;
12378
        end
12379
 
12380
        // disable address translation and enable prefetch so read bursts can be performed
12381
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
12382
        if ( ok !== 1 )
12383
        begin
12384
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
12385
            test_fail("PCI Image Control register could not be written") ;
12386
            disable main;
12387
        end
12388
 
12389
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
12390
        if ( ok !== 1 )
12391
        begin
12392
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12393
            test_fail("PCI Address Mask register could not be written") ;
12394
            disable main;
12395
        end
12396
 
12397
        addr_offset = 12'h00C ;
12398
 
12399
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
12400
        if ( ok !== 1 )
12401
        begin
12402
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
12403
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
12404
            disable main;
12405
        end
12406
 
12407
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
12408
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12409
 
12410
        // do a single read error terminated on WB bus
12411
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
12412
 
12413
        fork
12414
        begin
12415
            PCIU_IO_READ
12416
             (
12417
                `Test_Master_1,
12418
                Target_Base_Addr_R[target_io_image],
12419
                32'hAAAA_5555,
12420
                4'h0,
12421
                1,
12422
                `Test_Target_Retry_On
12423
             );
12424
 
12425
            do_pause( 1 ) ;
12426
        end
12427
        begin
12428
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
12429
 
12430
            if ( ok !== 1 )
12431
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12432
 
12433
            do_pause(3) ;
12434
 
12435
            PCIU_IO_READ
12436
             (
12437
                `Test_Master_1,
12438
                Target_Base_Addr_R[target_io_image],
12439
                32'hAAAA_5555,
12440
                4'h0,
12441
                1,
12442
                `Test_Target_Abort_On
12443
             );
12444
 
12445
            do_pause( 1 ) ;
12446
 
12447
            while ( FRAME === 0 )
12448
                @(posedge pci_clock) ;
12449
 
12450
            while ( IRDY === 0 )
12451
                @(posedge pci_clock) ;
12452
 
12453
            disable monitor_error_event10 ;
12454
        end
12455
        begin:monitor_error_event10
12456
            @(error_event_int) ;
12457
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12458
            ok = 0 ;
12459
        end
12460
        join
12461
 
12462
        if ( ok )
12463
            test_ok ;
12464
 
12465
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12466
        addr_offset = 12'h004 ;
12467
        config_read(addr_offset, 4'hF, read_data) ;
12468
        ok = 1 ;
12469
        if ( read_data[27] !== 1 )
12470
        begin
12471
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12472
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12473
            ok = 0 ;
12474
        end
12475
        if ( read_data[28] !== 0 )
12476
        begin
12477
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12478
            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") ;
12479
            ok = 0 ;
12480
        end
12481
        if ( read_data[29] !== 0 )
12482
        begin
12483
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12484
            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") ;
12485
            ok = 0 ;
12486
        end
12487
 
12488
        // clear statuses
12489
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12490
        if ( !ok )
12491
        begin
12492
            test_fail("write to PCI Device Status register failed") ;
12493
            $display("Couldn't write PCI Device Status register") ;
12494
            disable main ;
12495
        end
12496
 
12497
        if ( ok )
12498
            test_ok ;
12499
 
12500
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12501
 
12502
        ok = 1 ;
12503
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12504
 
12505
        config_read(addr_offset, 4'hF, read_data) ;
12506
        if (read_data[8] !== 0)
12507
        begin
12508
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12509
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12510
            ok = 0 ;
12511
        end
12512
        else
12513
            test_ok ;
12514
 
12515
        if ( ok !== 1 )
12516
        begin
12517
            config_write(addr_offset, read_data, 4'hF, ok) ;
12518
            if ( !ok )
12519
            begin
12520
                test_fail("PCI Error Control and Status register could not be written") ;
12521
                disable main ;
12522
            end
12523
        end
12524
 
12525
        test_name = "DISABLE IMAGE" ;
12526
        config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
12527
        if ( ok !== 1 )
12528
        begin
12529
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12530
            test_fail("PCI Address Mask register could not be written") ;
12531
            disable main;
12532
        end
12533
 
12534
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12535
 
12536
    end
12537
end // main
12538
endtask // test_wb_error_rd
12539
 
12540
task test_target_abort ;
12541
    input [2:0]  image_num ;
12542
    reg   [11:0] pci_ctrl_offset ;
12543
    reg   [11:0] ctrl_offset ;
12544
    reg   [11:0] ba_offset ;
12545
    reg   [11:0] am_offset ;
12546
    reg   [11:0] ta_offset ;
12547
    reg   [31:0] pci_address ;
12548
    reg   [3:0]  byte_enables ;
12549
    reg          ok ;
12550
begin:main
12551
    pci_ctrl_offset = 12'h4 ;
12552
    if (image_num === 0)
12553
    begin
12554
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
12555
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
12556
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
12557
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
12558
    end
12559
    else if (image_num === 1)
12560
    begin
12561
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
12562
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
12563
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
12564
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
12565
    end
12566
    else if (image_num === 2)
12567
    begin
12568
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
12569
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
12570
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
12571
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
12572
    end
12573
    else if (image_num === 3)
12574
    begin
12575
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
12576
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
12577
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
12578
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
12579
    end
12580
    else if (image_num === 4)
12581
    begin
12582
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
12583
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
12584
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
12585
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
12586
    end
12587
    else if (image_num === 5)
12588
    begin
12589
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
12590
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
12591
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
12592
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
12593
    end
12594
 
12595
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
12596
 
12597
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
12598
    if ( ok !== 1 )
12599
    begin
12600
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
12601
        test_fail("PCI Base Address register could not be written") ;
12602
        disable main ;
12603
    end
12604
 
12605
    // Set Address Mask of IMAGE
12606
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
12607
    if ( ok !== 1 )
12608
    begin
12609
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
12610
        test_fail("PCI Address Mask register could not be written") ;
12611
        disable main ;
12612
    end
12613
 
12614
    // Set Translation Address of IMAGE
12615
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
12616
    if ( ok !== 1 )
12617
    begin
12618
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
12619
        test_fail("PCI Translation Address Register could not be written") ;
12620
        disable main ;
12621
    end
12622
 
12623
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
12624
    if ( ok !== 1 )
12625
    begin
12626
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
12627
        test_fail("PCI Image Control register could not be written") ;
12628
        disable main ;
12629
    end
12630
 
12631
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
12632
 
12633
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
12634
 
12635
    pci_address  = Target_Base_Addr_R[image_num] ;
12636
    byte_enables = 4'b0001 ;
12637
 
12638
    fork
12639
    begin
12640
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12641
        do_pause ( 1 ) ;
12642
    end
12643
    begin:monitor_error_event1
12644
        @(error_event_int) ;
12645
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12646
        ok = 0 ;
12647
    end
12648
    begin
12649
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12650
        @(posedge pci_clock) ;
12651
        disable monitor_error_event1 ;
12652
    end
12653
    join
12654
 
12655
    if ( ok )
12656
        test_ok ;
12657
 
12658
    ok = 1 ;
12659
 
12660
    fork
12661
    begin
12662
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12663
        do_pause ( 1 ) ;
12664
    end
12665
    begin:monitor_error_event2
12666
        @(error_event_int) ;
12667
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12668
        ok = 0 ;
12669
    end
12670
    begin
12671
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12672
        @(posedge pci_clock) ;
12673
        disable monitor_error_event2 ;
12674
    end
12675
    join
12676
 
12677
    if ( ok )
12678
        test_ok ;
12679
 
12680
    ok = 1 ;
12681
 
12682
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
12683
    byte_enables = 4'b0011 ;
12684
 
12685
    fork
12686
    begin
12687
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12688
        do_pause ( 1 ) ;
12689
    end
12690
    begin:monitor_error_event3
12691
        @(error_event_int) ;
12692
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12693
        ok = 0 ;
12694
    end
12695
    begin
12696
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12697
        @(posedge pci_clock) ;
12698
        disable monitor_error_event3 ;
12699
    end
12700
    join
12701
 
12702
    if ( ok )
12703
        test_ok ;
12704
 
12705
    ok = 1 ;
12706
 
12707
    byte_enables = 4'b0000 ;
12708
 
12709
    fork
12710
    begin
12711
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12712
        do_pause ( 1 ) ;
12713
    end
12714
    begin:monitor_error_event4
12715
        @(error_event_int) ;
12716
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12717
        ok = 0 ;
12718
    end
12719
    begin
12720
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12721
        @(posedge pci_clock) ;
12722
        disable monitor_error_event4 ;
12723
    end
12724
    join
12725
 
12726
    if ( ok )
12727
        test_ok ;
12728
 
12729
    ok = 1 ;
12730
 
12731
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
12732
    byte_enables = 4'b0111 ;
12733
 
12734
    fork
12735
    begin
12736
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12737
        do_pause ( 1 ) ;
12738
    end
12739
    begin:monitor_error_event5
12740
        @(error_event_int) ;
12741
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12742
        ok = 0 ;
12743
    end
12744
    begin
12745
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12746
        @(posedge pci_clock) ;
12747
        disable monitor_error_event5 ;
12748
    end
12749
    join
12750
 
12751
    if ( ok )
12752
        test_ok ;
12753
 
12754
    ok = 1 ;
12755
 
12756
    byte_enables = 4'b0010 ;
12757
 
12758
    fork
12759
    begin
12760
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12761
        do_pause ( 1 ) ;
12762
    end
12763
    begin:monitor_error_event6
12764
        @(error_event_int) ;
12765
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12766
        ok = 0 ;
12767
    end
12768
    begin
12769
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12770
        @(posedge pci_clock) ;
12771
        disable monitor_error_event6 ;
12772
    end
12773
    join
12774
 
12775
    if ( ok )
12776
        test_ok ;
12777
 
12778
    ok = 1 ;
12779
    byte_enables = 4'b0001 ;
12780
 
12781
    fork
12782
    begin
12783
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12784
        do_pause ( 1 ) ;
12785
    end
12786
    begin:monitor_error_event7
12787
        @(error_event_int) ;
12788
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12789
        ok = 0 ;
12790
    end
12791
    begin
12792
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12793
        @(posedge pci_clock) ;
12794
        disable monitor_error_event7 ;
12795
    end
12796
    join
12797
 
12798
    if ( ok )
12799
        test_ok ;
12800
 
12801
    ok = 1 ;
12802
    byte_enables = 4'b0000 ;
12803
 
12804
    fork
12805
    begin
12806
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12807
        do_pause ( 1 ) ;
12808
    end
12809
    begin:monitor_error_event8
12810
        @(error_event_int) ;
12811
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12812
        ok = 0 ;
12813
    end
12814
    begin
12815
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12816
        @(posedge pci_clock) ;
12817
        disable monitor_error_event8 ;
12818
    end
12819
    join
12820
 
12821
    if ( ok )
12822
        test_ok ;
12823
 
12824
    ok = 1 ;
12825
 
12826
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
12827
    byte_enables = 4'b0110 ;
12828
 
12829
    fork
12830
    begin
12831
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
12832
        do_pause ( 1 ) ;
12833
    end
12834
    begin:monitor_error_event9
12835
        @(error_event_int) ;
12836
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12837
        ok = 0 ;
12838
    end
12839
    begin
12840
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12841
        @(posedge pci_clock) ;
12842
        disable monitor_error_event9 ;
12843
    end
12844
    join
12845
 
12846
    if ( ok )
12847
        test_ok ;
12848
 
12849
    ok = 1 ;
12850
    fork
12851
    begin
12852
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
12853
        do_pause ( 1 ) ;
12854
    end
12855
    begin:monitor_error_event10
12856
        @(error_event_int) ;
12857
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12858
        ok = 0 ;
12859
    end
12860
    begin
12861
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12862
        @(posedge pci_clock) ;
12863
        disable monitor_error_event10 ;
12864
    end
12865
    join
12866
 
12867
    if ( ok )
12868
        test_ok ;
12869
 
12870
    ok = 1 ;
12871
 
12872
    byte_enables = 4'b0001 ;
12873
 
12874
    fork
12875
    begin
12876
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12877
        do_pause ( 1 ) ;
12878
    end
12879
    begin:monitor_error_event11
12880
        @(error_event_int) ;
12881
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12882
        ok = 0 ;
12883
    end
12884
    begin
12885
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12886
        @(posedge pci_clock) ;
12887
        disable monitor_error_event11 ;
12888
    end
12889
    join
12890
 
12891
    if ( ok )
12892
        test_ok ;
12893
 
12894
    ok = 1 ;
12895
 
12896
    byte_enables = 4'b0101 ;
12897
 
12898
    fork
12899
    begin
12900
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12901
        do_pause ( 1 ) ;
12902
    end
12903
    begin:monitor_error_event12
12904
        @(error_event_int) ;
12905
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12906
        ok = 0 ;
12907
    end
12908
    begin
12909
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12910
        @(posedge pci_clock) ;
12911
        disable monitor_error_event12 ;
12912
    end
12913
    join
12914
 
12915
    if ( ok )
12916
        test_ok ;
12917
 
12918
    ok = 1 ;
12919
 
12920
    byte_enables = 4'b0011 ;
12921
 
12922
    fork
12923
    begin
12924
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12925
        do_pause ( 1 ) ;
12926
    end
12927
    begin:monitor_error_event13
12928
        @(error_event_int) ;
12929
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12930
        ok = 0 ;
12931
    end
12932
    begin
12933
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12934
        @(posedge pci_clock) ;
12935
        disable monitor_error_event13 ;
12936
    end
12937
    join
12938
 
12939
    if ( ok )
12940
        test_ok ;
12941
 
12942
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12943
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
12944
    ok = 1 ;
12945
    if ( pci_address[27] !== 1 )
12946
    begin
12947
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
12948
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
12949
        ok = 0 ;
12950
    end
12951
    if ( pci_address[28] !== 0 )
12952
    begin
12953
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
12954
        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") ;
12955
        ok = 0 ;
12956
    end
12957
    if ( pci_address[29] !== 0 )
12958
    begin
12959
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
12960
        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") ;
12961
        ok = 0 ;
12962
    end
12963
 
12964
    // clear statuses
12965
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
12966
    if ( !ok )
12967
    begin
12968
        test_fail("write to PCI Device Status register failed") ;
12969
        $display("Couldn't write PCI Device Status register") ;
12970
        disable main ;
12971
    end
12972
 
12973
    if ( ok )
12974
        test_ok ;
12975
 
12976
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
12977
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
12978
    if ( pci_address[8] !== 0 )
12979
    begin
12980
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
12981
    end
12982
    else
12983
        test_ok ;
12984
 
12985
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
12986
 
12987
    test_name = "DISABLE IMAGE" ;
12988
 
12989
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h7FFF_FFFF, 4'hF, ok ) ;
12990
    if ( ok !== 1 )
12991
    begin
12992
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
12993
        test_fail("PCI Address Mask register could not be written") ;
12994
        disable main ;
12995
    end
12996
end
12997
endtask // test_target_abort
12998
 
12999
task test_target_io_wr_rd ;
13000
    input [2:0]  image_num ;
13001
    input        translate_address ;
13002
    input [11:0] img_ctrl_offset ;
13003
    reg   [31:0] expect_address ;
13004
    reg   [31:0] pci_address ;
13005
    reg          translation ;
13006
    reg   [31:0] read_data ;
13007
    reg   [3:0]  byte_enables ;
13008
    reg          ok ;
13009
    reg          pci_ok ;
13010
    reg          wb_ok ;
13011
    integer      i ;
13012
begin:main
13013
    `ifdef ADDR_TRAN_IMPL
13014
        translation = translate_address ;
13015
    `else
13016
        translation = 0 ;
13017
    `endif
13018
 
13019
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
13020
 
13021
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
13022
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
13023
    if ( translation )
13024
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
13025
    else
13026
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
13027
 
13028
    if ( !ok )
13029
    begin
13030
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
13031
        test_fail("PCI Image Control register could not be written") ;
13032
    end
13033
 
13034
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
13035
    pci_address  = Target_Base_Addr_R[image_num] ;
13036
    byte_enables = 4'b0000 ;
13037
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13038
 
13039
    fork
13040
    begin
13041
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
13042
        do_pause ( 1 ) ;
13043
    end
13044
    begin
13045
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
13046
        if ( wb_ok !== 1 )
13047
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13048
 
13049
        disable monitor_pci_error_1 ;
13050
    end
13051
    begin:monitor_pci_error_1
13052
        pci_ok = 1 ;
13053
        @(error_event_int) ;
13054
        pci_ok = 0 ;
13055
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
13056
    end
13057
    join
13058
 
13059
    byte_enables = 4'b1111 ;
13060
    for ( i = 0 ; i < 4 ; i = i + 1 )
13061
    begin:loop_1
13062
        byte_enables[i] = 0 ;
13063
        if ( i > 0 )
13064
            byte_enables[i - 1] = 1 ;
13065
        fork
13066
        begin
13067
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13068
            do_pause ( 1 ) ;
13069
        end
13070
        begin
13071
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
13072
            if ( wb_ok !== 1 )
13073
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13074
 
13075
            disable monitor_pci_error_2 ;
13076
        end
13077
        begin:monitor_pci_error_2
13078
            pci_ok = 1 ;
13079
            @(error_event_int) ;
13080
            pci_ok = 0 ;
13081
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
13082
        end
13083
        join
13084
 
13085
        if ( !pci_ok || !wb_ok )
13086
            disable loop_1 ;
13087
 
13088
        pci_address = pci_address + 1 ;
13089
        expect_address = expect_address + 1 ;
13090
    end
13091
 
13092
    if ( pci_ok && wb_ok )
13093
        test_ok ;
13094
 
13095
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
13096
    pci_address  = Target_Base_Addr_R[image_num] ;
13097
    byte_enables = 4'b1100 ;
13098
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13099
 
13100
    master1_check_received_data = 1 ;
13101
    fork
13102
    begin
13103
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13104
        do_pause( 1 ) ;
13105
    end
13106
    begin
13107
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13108
        if ( wb_ok !== 1 )
13109
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13110
 
13111
        do_pause ( 2 ) ;
13112
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13113
        do_pause ( 16 ) ;
13114
 
13115
        disable monitor_pci_error_3 ;
13116
    end
13117
    begin:monitor_pci_error_3
13118
        pci_ok = 1 ;
13119
        @(error_event_int) ;
13120
        pci_ok = 0 ;
13121
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13122
    end
13123
    join
13124
 
13125
    if ( !pci_ok || !wb_ok )
13126
    begin
13127
        disable main ;
13128
    end
13129
 
13130
    pci_address  = Target_Base_Addr_R[image_num] + 2;
13131
    byte_enables = 4'b0011 ;
13132
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13133
 
13134
    master1_check_received_data = 1 ;
13135
    fork
13136
    begin
13137
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13138
        do_pause( 1 ) ;
13139
    end
13140
    begin
13141
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13142
        if ( wb_ok !== 1 )
13143
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13144
 
13145
        do_pause ( 2 ) ;
13146
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13147
        do_pause ( 16 ) ;
13148
 
13149
        disable monitor_pci_error_4 ;
13150
    end
13151
    begin:monitor_pci_error_4
13152
        pci_ok = 1 ;
13153
        @(error_event_int) ;
13154
        pci_ok = 0 ;
13155
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13156
    end
13157
    join
13158
 
13159
    if ( !pci_ok || !wb_ok )
13160
    begin
13161
        disable main ;
13162
    end
13163
 
13164
    pci_address  = Target_Base_Addr_R[image_num] ;
13165
    byte_enables = 4'b0000 ;
13166
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13167
 
13168
    master1_check_received_data = 1 ;
13169
    fork
13170
    begin
13171
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13172
        do_pause( 1 ) ;
13173
    end
13174
    begin
13175
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13176
        if ( wb_ok !== 1 )
13177
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13178
 
13179
        do_pause ( 2 ) ;
13180
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13181
        do_pause ( 16 ) ;
13182
 
13183
        disable monitor_pci_error_5 ;
13184
    end
13185
    begin:monitor_pci_error_5
13186
        pci_ok = 1 ;
13187
        @(error_event_int) ;
13188
        pci_ok = 0 ;
13189
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13190
    end
13191
    join
13192
 
13193
    if ( pci_ok && wb_ok )
13194
        test_ok ;
13195
end
13196
endtask // test_target_io_wr_rd
13197
 
13198
task test_target_io_err_wr ;
13199
    input [2:0]  image_num ;
13200
    input        translate_address ;
13201
    input [11:0] img_ctrl_offset ;
13202
    input        enable_error_report ;
13203
    input        enable_error_interrupt ;
13204
 
13205
    reg   [31:0] expect_address ;
13206
    reg   [31:0] pci_address ;
13207
    reg          translation ;
13208
    reg   [31:0] read_data ;
13209
    reg   [3:0]  byte_enables ;
13210
    reg          ok ;
13211
    reg          pci_ok ;
13212
    reg          wb_ok ;
13213
    integer      i ;
13214
    reg   [11:0] offset ;
13215
begin:main
13216
    `ifdef ADDR_TRAN_IMPL
13217
        translation = translate_address ;
13218
    `else
13219
        translation = 0 ;
13220
    `endif
13221
 
13222
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
13223
 
13224
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
13225
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
13226
    if ( translation )
13227
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
13228
    else
13229
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
13230
 
13231
    if ( !ok )
13232
    begin
13233
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
13234
        test_fail("PCI Image Control register could not be written") ;
13235
    end
13236
 
13237
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
13238
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13239
    if ( enable_error_report )
13240
    begin
13241
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
13242
        if ( !ok )
13243
        begin
13244
            test_fail("PCI Error Control and Status register could not be written") ;
13245
            disable main ;
13246
        end
13247
    end
13248
    else
13249
    begin
13250
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
13251
        if ( !ok )
13252
        begin
13253
            test_fail("PCI Error Control and Status register could not be written") ;
13254
            disable main ;
13255
        end
13256
    end
13257
 
13258
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
13259
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
13260
    if ( enable_error_interrupt )
13261
    begin
13262
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
13263
        if ( !ok )
13264
        begin
13265
            test_fail("Interrupt Control register could not be written") ;
13266
            disable main ;
13267
        end
13268
    end
13269
    else
13270
    begin
13271
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
13272
        if ( !ok )
13273
        begin
13274
            test_fail("Interrupt Control register could not be written") ;
13275
            disable main ;
13276
        end
13277
    end
13278
 
13279
    pci_address  = Target_Base_Addr_R[image_num] ;
13280
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13281
 
13282
    byte_enables = 4'b1111 ;
13283
 
13284
    for ( i = 0 ; i < 4 ; i = i + 1 )
13285
    begin:loop_1
13286
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
13287
        byte_enables[i] = 0 ;
13288
        if ( i > 0 )
13289
            byte_enables[i - 1] = 1 ;
13290
 
13291
        fork
13292
        begin
13293
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13294
            do_pause ( 1 ) ;
13295
        end
13296
        begin
13297
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
13298
            if ( wb_ok !== 1 )
13299
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13300
 
13301
            disable monitor_pci_error_2 ;
13302
        end
13303
        begin:monitor_pci_error_2
13304
            pci_ok = 1 ;
13305
            @(error_event_int) ;
13306
            pci_ok = 0 ;
13307
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
13308
        end
13309
        join
13310
 
13311
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
13312
        `ifdef HOST
13313
 
13314
            repeat ( 4 )
13315
                @( posedge wb_clock ) ;
13316
 
13317
            if ( enable_error_interrupt && enable_error_report )
13318
            begin
13319
                if ( INT_O !== 1 )
13320
                begin
13321
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
13322
                end
13323
            end
13324
            else
13325
            begin
13326
                if ( INT_O !== 0 )
13327
                begin
13328
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
13329
                end
13330
            end
13331
        `else
13332
            repeat ( 4 )
13333
                @( posedge pci_clock ) ;
13334
 
13335
            if ( enable_error_interrupt && enable_error_report )
13336
            begin
13337
                if ( INTA !== 0 )
13338
                begin
13339
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
13340
                end
13341
            end
13342
            else
13343
            begin
13344
                if ( INTA !== 1 )
13345
                begin
13346
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
13347
                end
13348
            end
13349
        `endif
13350
 
13351
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
13352
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13353
        config_read( offset, 4'hF, read_data ) ;
13354
        ok = 1 ;
13355
        if ( enable_error_report )
13356
        begin
13357
            if ( read_data[8] !== 1 )
13358
            begin
13359
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
13360
                ok = 0 ;
13361
            end
13362
 
13363
            if ( read_data[9] !== 0 )
13364
            begin
13365
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
13366
                ok = 0 ;
13367
            end
13368
 
13369
            if ( read_data[31:28] !== byte_enables )
13370
            begin
13371
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
13372
                ok = 0 ;
13373
            end
13374
 
13375
            if ( read_data[27:24] !== `BC_IO_WRITE )
13376
            begin
13377
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
13378
                ok = 0 ;
13379
            end
13380
 
13381
            if ( ok )
13382
                test_ok ;
13383
 
13384
            test_name = "CLEAR ERROR STATUS" ;
13385
            config_write( offset, read_data, 4'hF, ok ) ;
13386
            if ( !ok )
13387
                test_fail("PCI Error Control and Status register could not be written") ;
13388
 
13389
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
13390
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13391
            config_read ( offset, 4'hf, read_data ) ;
13392
 
13393
            if ( read_data !== expect_address )
13394
            begin
13395
                test_fail("value in Erroneous Address register was incorrect") ;
13396
                ok = 0 ;
13397
            end
13398
 
13399
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13400
            config_read ( offset, 4'hf, read_data ) ;
13401
 
13402
            if ( read_data !== 32'hAAAA_AAAA )
13403
            begin
13404
                test_fail("value in Erroneous Data register was incorrect") ;
13405
                ok = 0 ;
13406
            end
13407
 
13408
            if ( ok )
13409
                test_ok ;
13410
 
13411
        end
13412
        else
13413
        begin
13414
            if ( read_data[8] !== 0 )
13415
            begin
13416
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
13417
                ok = 0 ;
13418
            end
13419
            else
13420
                test_ok ;
13421
        end
13422
 
13423
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
13424
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
13425
        ok = 1 ;
13426
 
13427
        config_read ( offset, 4'hF, read_data ) ;
13428
        if ( enable_error_report && enable_error_interrupt )
13429
        begin
13430
            if ( read_data[2] !== 1 )
13431
            begin
13432
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
13433
                ok = 0 ;
13434
            end
13435
 
13436
            test_name = "CLEARING INTERRUPT STATUS" ;
13437
            config_write( offset, read_data, 4'hF, ok ) ;
13438
            if ( !ok )
13439
                test_fail("Interrupt Status register could not be written") ;
13440
        end
13441
        else
13442
        begin
13443
            if ( read_data[2] !== 0 )
13444
            begin
13445
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
13446
                ok = 0 ;
13447
            end
13448
        end
13449
 
13450
        if ( ok )
13451
            test_ok ;
13452
 
13453
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
13454
        `ifdef HOST
13455
 
13456
            repeat ( 4 )
13457
                @( posedge wb_clock ) ;
13458
 
13459
            if ( INT_O !== 0 )
13460
            begin
13461
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
13462
            end
13463
            else
13464
                test_ok ;
13465
 
13466
        `else
13467
            repeat ( 4 )
13468
                @( posedge pci_clock ) ;
13469
 
13470
            if ( INTA !== 1 )
13471
            begin
13472
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
13473
            end
13474
            else
13475
                test_ok ;
13476
 
13477
        `endif
13478
 
13479
        pci_address = pci_address + 1 ;
13480
        expect_address = expect_address + 1 ;
13481
    end
13482
 
13483
end
13484
endtask // test_target_io_err_wr
13485
 
13486
task test_pci_image ;
13487
    input [2:0]  image_num ;
13488
    reg   [11:0] pci_ctrl_offset ;
13489
    reg   [11:0] ctrl_offset ;
13490
    reg   [11:0] ba_offset ;
13491
    reg   [11:0] am_offset ;
13492
    reg   [11:0] ta_offset ;
13493
    reg   [7:0]  cache_lsize ;
13494
    reg          ok ;
13495
    reg          test_io ;
13496
    reg          test_mem ;
13497
begin
13498
    pci_ctrl_offset = 12'h4 ;
13499
    if (image_num === 0)
13500
    begin
13501
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
13502
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
13503
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
13504
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
13505
    end
13506
    else if (image_num === 1)
13507
    begin
13508
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13509
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13510
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13511
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13512
    end
13513
    else if (image_num === 2)
13514
    begin
13515
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13516
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13517
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13518
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13519
    end
13520
    else if (image_num === 3)
13521
    begin
13522
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13523
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13524
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13525
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13526
    end
13527
    else if (image_num === 4)
13528
    begin
13529
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13530
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13531
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13532
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13533
    end
13534
    else if (image_num === 5)
13535
    begin
13536
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13537
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13538
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13539
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13540
    end
13541
 
13542
    `ifdef HOST
13543
        test_io  = 1 ;
13544
        test_mem = 1 ;
13545
    `else
13546
        if (image_num == 1)
13547
            test_io = `PCI_BA1_MEM_IO ;
13548
        else if ( image_num == 2 )
13549
            test_io = `PCI_BA2_MEM_IO ;
13550
        else if ( image_num == 3 )
13551
            test_io = `PCI_BA3_MEM_IO ;
13552
        else if ( image_num == 4 )
13553
            test_io = `PCI_BA4_MEM_IO ;
13554
        else if ( image_num == 5 )
13555
            test_io = `PCI_BA5_MEM_IO ;
13556
 
13557
        test_mem = !test_io ;
13558
    `endif
13559
 
13560
    $display(" ");
13561
    $display("########################################################################") ;
13562
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
13563
    test_name = "PCI IMAGE SETTINGS" ;
13564
 
13565
    // Set Base Address of IMAGE
13566
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
13567
    if ( ok !== 1 )
13568
    begin
13569
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
13570
        test_fail("PCI Base Address register could not be written") ;
13571
    end
13572
 
13573
    // Set Address Mask of IMAGE
13574
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
13575
    if ( ok !== 1 )
13576
    begin
13577
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
13578
        test_fail("PCI Address Mask register could not be written") ;
13579
    end
13580
 
13581
    // Set Translation Address of IMAGE
13582
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
13583
    if ( ok !== 1 )
13584
    begin
13585
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
13586
        test_fail("PCI Translation Address register could not be written") ;
13587
    end
13588
 
13589
// Following are defines for byte enable signals !
13590
//      Byte Masks
13591
//      `Test_Byte_0                            (4'b1110)
13592
//      `Test_Byte_1                            (4'b1101)
13593
//      `Test_Byte_2                            (4'b1011)
13594
//      `Test_Byte_3                            (4'b0111)
13595
//      `Test_Half_0                            (4'b1100)
13596
//      `Test_Half_1                            (4'b0011)
13597
//      `Test_All_Bytes                         (4'b0000)
13598
 
13599
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
13600
    // Set Cache Line Size
13601
    cache_lsize = 8'h4 ;
13602
 
13603
    $display(" ");
13604
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13605
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13606
    if ( ok !== 1 )
13607
    begin
13608
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13609
        test_fail("PCI Device Control and Status register could not be written") ;
13610
    end
13611
 
13612
    if (test_mem)
13613
    begin
13614
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
13615
        // Task test_normal_wr_rd has the following parameters:
13616
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13617
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13618
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13619
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
13620
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
13621
 
13622
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13623
        // Set Cache Line Size
13624
        cache_lsize = 8'h4 ;
13625
 
13626
        $display(" ");
13627
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13628
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13629
        if ( ok !== 1 )
13630
        begin
13631
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13632
            test_fail("Cache Line Size register could not be written" ) ;
13633
        end
13634
 
13635
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
13636
        // Task test_normal_wr_rd has the following parameters:
13637
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13638
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13639
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13640
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
13641
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
13642
 
13643
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13644
        // Set Cache Line Size
13645
        cache_lsize = 8'h8 ;
13646
 
13647
        $display(" ");
13648
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13649
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13650
        if ( ok !== 1 )
13651
        begin
13652
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13653
            test_fail("Cache Line Size register could not be written" ) ;
13654
        end
13655
 
13656
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
13657
        // Task test_normal_wr_rd has the following parameters:
13658
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13659
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13660
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13661
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
13662
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
13663
 
13664
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13665
        // Set Cache Line Size
13666
        cache_lsize = 8'h4 ;
13667
 
13668
        $display(" ");
13669
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13670
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13671
        if ( ok !== 1 )
13672
        begin
13673
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13674
            test_fail("Cache Line Size register could not be written" ) ;
13675
        end
13676
 
13677
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
13678
        // Task test_normal_wr_rd has the following parameters:
13679
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13680
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13681
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13682
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
13683
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
13684
 
13685
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
13686
        $display(" ");
13687
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
13688
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13689
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13690
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
13691
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
13692
 
13693
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
13694
        $display(" ");
13695
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
13696
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13697
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13698
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
13699
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
13700
 
13701
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
13702
        $display(" ");
13703
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
13704
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13705
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13706
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
13707
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
13708
 
13709
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
13710
        $display(" ");
13711
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
13712
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13713
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13714
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
13715
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
13716
    end
13717
 
13718
    if ( test_io )
13719
    begin
13720
        test_name = "PCI IMAGE SETTINGS" ;
13721
 
13722
        // Set Base Address of IMAGE
13723
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
13724
        if ( ok !== 1 )
13725
        begin
13726
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
13727
            test_fail("PCI Base Address register could not be written") ;
13728
        end
13729
 
13730
        // Set Address Mask of IMAGE
13731
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
13732
        if ( ok !== 1 )
13733
        begin
13734
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
13735
            test_fail("PCI Address Mask register could not be written") ;
13736
        end
13737
 
13738
        // Set Translation Address of IMAGE
13739
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
13740
        if ( ok !== 1 )
13741
        begin
13742
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
13743
            test_fail("PCI Translation Address register could not be written") ;
13744
        end
13745
 
13746
        // Set Cache Line Size
13747
        cache_lsize = 8'h4 ;
13748
 
13749
        $display(" ");
13750
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13751
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13752
        if ( ok !== 1 )
13753
        begin
13754
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13755
            test_fail("Cache Line Size register could not be written" ) ;
13756
        end
13757
 
13758
        test_target_io_wr_rd
13759
        (
13760
            image_num,    // image number
13761
            0,            // test with address translation
13762
            ctrl_offset   // image control register offset
13763
        ) ;
13764
 
13765
        test_target_io_wr_rd
13766
        (
13767
            image_num,    // image number
13768
            1,            // test with address translation
13769
            ctrl_offset   // image control register offset
13770
        ) ;
13771
 
13772
        test_target_io_err_wr
13773
        (
13774
            image_num,      // image number
13775
            0,              // address translation on/off
13776
            ctrl_offset,    // image control register offset
13777
            0,              // enable error reporting
13778
 
13779
        ) ;
13780
 
13781
        test_target_io_err_wr
13782
        (
13783
            image_num,      // image number
13784
            1,              // address translation on/off
13785
            ctrl_offset,    // image control register offset
13786
            0,              // enable error reporting
13787
            1               // enable error interrupts
13788
        ) ;
13789
 
13790
        test_target_io_err_wr
13791
        (
13792
            image_num,      // image number
13793
            0,              // address translation on/off
13794
            ctrl_offset,    // image control register offset
13795
            1,              // enable error reporting
13796
 
13797
        ) ;
13798
 
13799
        test_target_io_err_wr
13800
        (
13801
            image_num,      // image number
13802
            1,              // address translation on/off
13803
            ctrl_offset,    // image control register offset
13804
            1,              // enable error reporting
13805
            1               // enable error interrupts
13806
        ) ;
13807
    end
13808
 
13809
    // Test master abort with NON supported commands
13810
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
13811
 
13812
    // disable the image
13813
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h7FFF_FFFF, 4'hF, ok ) ;
13814
end
13815
endtask //test_pci_image
13816
 
13817
task target_fast_back_to_back ;
13818
    reg   [11:0] pci_ctrl_offset ;
13819
    reg   [11:0] ctrl_offset ;
13820
    reg   [11:0] ba_offset ;
13821
    reg   [11:0] am_offset ;
13822
    reg   [11:0] ta_offset ;
13823
    reg   [11:0] cls_offset ;
13824
    reg          do_mem_fb2b ;
13825
    reg          do_io_fb2b ;
13826
    reg          ok ;
13827
begin:main
13828
 
13829
    if ( target_mem_image !== -1 )
13830
    begin
13831
        do_mem_fb2b = 1 ;
13832
 
13833
        if (target_mem_image === 1)
13834
        begin
13835
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13836
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13837
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13838
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13839
        end
13840
        else if (target_mem_image === 2)
13841
        begin
13842
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13843
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13844
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13845
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13846
        end
13847
        else if (target_mem_image === 3)
13848
        begin
13849
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13850
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13851
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13852
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13853
        end
13854
        else if (target_mem_image === 4)
13855
        begin
13856
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13857
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13858
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13859
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13860
        end
13861
        else if (target_mem_image === 5)
13862
        begin
13863
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13864
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13865
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13866
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13867
        end
13868
    end
13869
    else
13870
        do_mem_fb2b = 0 ;
13871
 
13872
    pci_ctrl_offset = 12'h4 ;
13873
    cls_offset      = 12'h00C ;
13874
 
13875
    if ( do_mem_fb2b )
13876
    begin
13877
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
13878
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13879
        if ( ok !== 1 )
13880
        begin
13881
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
13882
            test_fail("PCI Base Address register could not be written") ;
13883
            disable main ;
13884
        end
13885
 
13886
        // Set Address Mask of IMAGE
13887
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
13888
        if ( ok !== 1 )
13889
        begin
13890
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
13891
            test_fail("PCI Address Mask register could not be written") ;
13892
            disable main ;
13893
        end
13894
 
13895
        // Set Translation Address of IMAGE
13896
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
13897
        if ( ok !== 1 )
13898
        begin
13899
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
13900
            test_fail("PCI Translation Address Register could not be written") ;
13901
            disable main ;
13902
        end
13903
 
13904
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
13905
        if ( ok !== 1 )
13906
        begin
13907
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
13908
            test_fail("PCI Image Control register could not be written") ;
13909
            disable main ;
13910
        end
13911
 
13912
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
13913
        if ( ok !== 1 )
13914
        begin
13915
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
13916
            test_fail("Cache Line Size register could not be written") ;
13917
            disable main ;
13918
        end
13919
 
13920
        // enable master 1 fast_b2b
13921
        configuration_cycle_write(0,             // bus number
13922
                                  1,             // device number
13923
                                  0,             // function number
13924
                                  1,             // register number
13925
                                  0,             // type of configuration cycle
13926
                                  4'b1111,       // byte enables
13927
                                  32'hFFFF_FFFF  // data
13928
                                 ) ;
13929
 
13930
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
13931
 
13932
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
13933
        fork
13934
        begin
13935
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
13936
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
13937
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
13938
                  0, `Test_One_Zero_Target_WS,
13939
                  `Test_Devsel_Medium, `Test_Fast_B2B,
13940
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
13941
 
13942
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
13943
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
13944
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
13945
                  0, `Test_One_Zero_Target_WS,
13946
                  `Test_Devsel_Medium, `Test_Fast_B2B,
13947
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
13948
            do_pause(5) ;
13949
 
13950
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
13951
        end
13952
        begin:wb_monitor1
13953
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
13954
            if ( ok !== 1 )
13955
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
13956
 
13957
            disable monitor_error_event1 ;
13958
        end
13959
        begin:monitor_error_event1
13960
            @(error_event_int) ;
13961
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
13962
            ok = 0 ;
13963
            disable wb_monitor1 ;
13964
        end
13965
        join
13966
 
13967
        if ( ok )
13968
            test_ok ;
13969
 
13970
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
13971
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
13972
        fork
13973
        begin
13974
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
13975
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
13976
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
13977
                  0, `Test_One_Zero_Target_WS,
13978
                  `Test_Devsel_Medium, `Test_Fast_B2B,
13979
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
13980
 
13981
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
13982
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
13983
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
13984
                  0, `Test_One_Zero_Target_WS,
13985
                  `Test_Devsel_Medium, `Test_Fast_B2B,
13986
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
13987
            do_pause(5) ;
13988
 
13989
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
13990
 
13991
        end
13992
        begin:wb_monitor2
13993
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
13994
            if ( ok !== 1 )
13995
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
13996
            else
13997
            begin
13998
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
13999
                if ( ok !== 1 )
14000
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14001
            end
14002
 
14003
            disable monitor_error_event2 ;
14004
        end
14005
        begin:monitor_error_event2
14006
            @(error_event_int) ;
14007
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14008
            ok = 0 ;
14009
            disable wb_monitor2 ;
14010
        end
14011
        join
14012
 
14013
        if ( ok )
14014
            test_ok ;
14015
 
14016
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
14017
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14018
        fork
14019
        begin
14020
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14021
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14022
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14023
                  0, `Test_One_Zero_Target_WS,
14024
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14025
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14026
 
14027
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
14028
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14029
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14030
                  0, `Test_One_Zero_Target_WS,
14031
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14032
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14033
            do_pause(5) ;
14034
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14035
 
14036
        end
14037
        begin:wb_monitor3
14038
            fork
14039
            begin
14040
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14041
                if ( ok !== 1 )
14042
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14043
            end
14044
            begin
14045
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
14046
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
14047
                if ( ok !== 1 )
14048
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14049
            end
14050
            join
14051
 
14052
            if ( ok )
14053
            begin
14054
                fork
14055
                begin
14056
                    do_pause(3) ;
14057
 
14058
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14059
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
14060
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14061
                        0, `Test_One_Zero_Target_WS,
14062
                        `Test_Devsel_Medium, `Test_Fast_B2B,
14063
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14064
 
14065
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
14066
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14067
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14068
                            0, `Test_One_Zero_Target_WS,
14069
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14070
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14071
 
14072
                    do_pause(1) ;
14073
                end
14074
                begin
14075
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
14076
                    if ( ok !== 1 )
14077
                    begin
14078
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14079
                        disable monitor_error_event3 ;
14080
                    end
14081
                    else
14082
                    begin
14083
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
14084
                        if ( ok !== 1 )
14085
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14086
                    end
14087
                end
14088
                join
14089
            end
14090
            disable monitor_error_event3 ;
14091
        end
14092
        begin:monitor_error_event3
14093
            @(error_event_int) ;
14094
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14095
            ok = 0 ;
14096
            disable wb_monitor3 ;
14097
        end
14098
        join
14099
 
14100
        if ( ok )
14101
            test_ok ;
14102
 
14103
        test_name = "DISABLING MEM IMAGE" ;
14104
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
14105
        if ( ok !== 1 )
14106
        begin
14107
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14108
            test_fail("PCI Address Mask register could not be written") ;
14109
            disable main ;
14110
        end
14111
    end
14112
 
14113
    if ( target_io_image !== -1 )
14114
    begin
14115
        do_io_fb2b = 1 ;
14116
 
14117
        if (target_io_image === 1)
14118
        begin
14119
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14120
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14121
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14122
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14123
        end
14124
        else if (target_io_image === 2)
14125
        begin
14126
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14127
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14128
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14129
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14130
        end
14131
        else if (target_io_image === 3)
14132
        begin
14133
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14134
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14135
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14136
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14137
        end
14138
        else if (target_io_image === 4)
14139
        begin
14140
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14141
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14142
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14143
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14144
        end
14145
        else if (target_io_image === 5)
14146
        begin
14147
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14148
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14149
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14150
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14151
        end
14152
    end
14153
    else
14154
        do_io_fb2b = 0 ;
14155
 
14156
    if ( do_io_fb2b )
14157
    begin
14158
 
14159
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
14160
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14161
        if ( ok !== 1 )
14162
        begin
14163
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14164
            test_fail("PCI Base Address register could not be written") ;
14165
            disable main ;
14166
        end
14167
 
14168
        // Set Address Mask of IMAGE
14169
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
14170
        if ( ok !== 1 )
14171
        begin
14172
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14173
            test_fail("PCI Address Mask register could not be written") ;
14174
            disable main ;
14175
        end
14176
 
14177
        // Set Translation Address of IMAGE
14178
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
14179
        if ( ok !== 1 )
14180
        begin
14181
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14182
            test_fail("PCI Translation Address Register could not be written") ;
14183
            disable main ;
14184
        end
14185
 
14186
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14187
        if ( ok !== 1 )
14188
        begin
14189
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14190
            test_fail("PCI Image Control register could not be written") ;
14191
            disable main ;
14192
        end
14193
 
14194
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
14195
        if ( ok !== 1 )
14196
        begin
14197
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14198
            test_fail("Cache Line Size register could not be written") ;
14199
            disable main ;
14200
        end
14201
 
14202
        // enable master 1 fast_b2b
14203
        configuration_cycle_write(0,             // bus number
14204
                                  1,             // device number
14205
                                  0,             // function number
14206
                                  1,             // register number
14207
                                  0,             // type of configuration cycle
14208
                                  4'b1111,       // byte enables
14209
                                  32'hFFFF_FFFF  // data
14210
                                 ) ;
14211
 
14212
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14213
 
14214
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
14215
        fork
14216
        begin
14217
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
14218
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
14219
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14220
                  0, `Test_One_Zero_Target_WS,
14221
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14222
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14223
 
14224
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
14225
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
14226
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14227
                  0, `Test_One_Zero_Target_WS,
14228
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14229
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14230
            do_pause(5) ;
14231
 
14232
        end
14233
        begin:wb_monitor4
14234
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
14235
            if ( ok !== 1 )
14236
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14237
 
14238
            if ( ok )
14239
            begin
14240
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
14241
                if ( ok !== 1 )
14242
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14243
            end
14244
 
14245
            disable monitor_error_event4 ;
14246
        end
14247
        begin:monitor_error_event4
14248
            @(error_event_int) ;
14249
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14250
            ok = 0 ;
14251
            disable wb_monitor4 ;
14252
        end
14253
        join
14254
 
14255
        if ( ok )
14256
            test_ok ;
14257
 
14258
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
14259
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14260
        fork
14261
        begin
14262
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
14263
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
14264
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14265
                  0, `Test_One_Zero_Target_WS,
14266
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14267
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14268
 
14269
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
14270
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
14271
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14272
                  0, `Test_One_Zero_Target_WS,
14273
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14274
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14275
            do_pause(5) ;
14276
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14277
        end
14278
        begin:wb_monitor5
14279
            fork
14280
            begin
14281
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
14282
                if ( ok !== 1 )
14283
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14284
            end
14285
            begin
14286
                wb_transaction_stop( 1 ) ;
14287
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
14288
                if ( ok !== 1 )
14289
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14290
            end
14291
            join
14292
 
14293
            if ( ok )
14294
            begin
14295
                fork
14296
                begin
14297
                    do_pause(3) ;
14298
 
14299
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
14300
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
14301
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14302
                            0, `Test_One_Zero_Target_WS,
14303
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14304
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14305
 
14306
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
14307
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
14308
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14309
                            0, `Test_One_Zero_Target_WS,
14310
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14311
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14312
 
14313
                    do_pause(1) ;
14314
                end
14315
                begin
14316
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
14317
                    if ( ok !== 1 )
14318
                    begin
14319
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14320
                        disable monitor_error_event5 ;
14321
                    end
14322
                    else
14323
                    begin
14324
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
14325
                        if ( ok !== 1 )
14326
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14327
                    end
14328
                end
14329
                join
14330
            end
14331
            disable monitor_error_event5 ;
14332
        end
14333
        begin:monitor_error_event5
14334
            @(error_event_int) ;
14335
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14336
            ok = 0 ;
14337
            disable wb_monitor5 ;
14338
        end
14339
        join
14340
 
14341
        if ( ok )
14342
            test_ok ;
14343
 
14344
        test_name = "DISABLING IO IMAGE" ;
14345
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
14346
        if ( ok !== 1 )
14347
        begin
14348
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14349
            test_fail("PCI Address Mask register could not be written") ;
14350
            disable main ;
14351
        end
14352
    end
14353
 
14354
end
14355
endtask //target_fast_back_to_back
14356
 
14357
task target_disconnects ;
14358
    reg   [11:0] pci_ctrl_offset ;
14359
    reg   [11:0] ctrl_offset ;
14360
    reg   [11:0] ba_offset ;
14361
    reg   [11:0] am_offset ;
14362
    reg   [11:0] ta_offset ;
14363
    reg   [11:0] cls_offset ;
14364
    reg          pci_ok ;
14365
    reg          wb_ok ;
14366
    reg          ok ;
14367
    reg   [31:0] pci_address ;
14368
    reg   [31:0] data ;
14369
    reg   [3:0]  byte_enables ;
14370
    reg   [9:0]  expect_length ;
14371
 
14372
    reg          do_mem_disconnects ;
14373
    reg          do_io_disconnects ;
14374
begin:main
14375
    if ( target_mem_image !== -1 )
14376
    begin
14377
        do_mem_disconnects = 1 ;
14378
 
14379
        if (target_mem_image === 1)
14380
        begin
14381
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14382
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14383
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14384
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14385
        end
14386
        else if (target_mem_image === 2)
14387
        begin
14388
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14389
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14390
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14391
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14392
        end
14393
        else if (target_mem_image === 3)
14394
        begin
14395
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14396
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14397
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14398
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14399
        end
14400
        else if (target_mem_image === 4)
14401
        begin
14402
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14403
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14404
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14405
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14406
        end
14407
        else if (target_mem_image === 5)
14408
        begin
14409
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14410
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14411
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14412
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14413
        end
14414
    end
14415
    else
14416
        do_mem_disconnects = 0 ;
14417
 
14418
    pci_ctrl_offset = 12'h4 ;
14419
    cls_offset = 12'h00C ;
14420
 
14421
    master1_check_received_data = 0 ;
14422
    master2_check_received_data = 0 ;
14423
 
14424
    `ifdef HOST
14425
        `ifdef NO_CNF_IMAGE
14426
        `else
14427
            `define TEST_BURST_CONFIG_READ
14428
        `endif
14429
    `else
14430
        `define TEST_BURST_CONFIG_READ
14431
        `define TEST_BURST_CONFIG_WRITE
14432
    `endif
14433
 
14434
    `ifdef TEST_BURST_CONFIG_WRITE
14435
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
14436
 
14437
        data = 32'h0000_08_08 ;
14438
 
14439
        test_name = "TARGET DISCONNECT ON BURST WRITE TO CONFIGURATION SPACE" ;
14440
        byte_enables = 4'b0000 ;
14441
 
14442
        fork
14443
        begin
14444
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14445
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14446
                    byte_enables,
14447
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14448
                    8'h0_0, `Test_One_Zero_Target_WS,
14449
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14450
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14451
 
14452
            data = 32'h0000_04_04 ;
14453
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14454
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14455
                    byte_enables,
14456
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14457
                    8'h0_0, `Test_One_Zero_Target_WS,
14458
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14459
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14460
            do_pause( 1 ) ;
14461
            while ( FRAME !== 1 || IRDY !== 1 )
14462
                @(posedge pci_clock) ;
14463
 
14464
            disable monitor_error_event1 ;
14465
        end
14466
        begin:monitor_error_event1
14467
            ok = 1 ;
14468
            @(error_event_int) ;
14469
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14470
            ok = 0 ;
14471
        end
14472
        join
14473
 
14474
        config_read(pci_address, 4'hF, data) ;
14475
        if ( data [15:0] !== 16'h04_04 )
14476
        begin
14477
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
14478
        end
14479
        else if ( ok )
14480
            test_ok ;
14481
 
14482
        pci_address  = {20'h0000_0, 1'b1, 11'h00C} ;
14483
        data         = 32'h0000_0808 ;
14484
        byte_enables = 4'h0 ;
14485
        fork
14486
        begin
14487
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14488
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
14489
                    byte_enables,
14490
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14491
                    8'h0_0, `Test_One_Zero_Target_WS,
14492
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14493
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14494
 
14495
            data = 32'h0000_04_04 ;
14496
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14497
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
14498
                    byte_enables,
14499
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14500
                    8'h0_0, `Test_One_Zero_Target_WS,
14501
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14502
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14503
 
14504
            do_pause( 1 ) ;
14505
            while ( FRAME !== 1 || IRDY !== 1 )
14506
                @(posedge pci_clock) ;
14507
 
14508
            disable monitor_error_event2 ;
14509
        end
14510
        begin:monitor_error_event2
14511
            ok = 1 ;
14512
            @(error_event_int) ;
14513
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14514
            ok = 0 ;
14515
        end
14516
        join
14517
 
14518
        config_read(pci_address, 4'hF, data) ;
14519
        if ( data [15:0] !== 16'h04_04 )
14520
        begin
14521
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
14522
        end
14523
        else if ( ok )
14524
            test_ok ;
14525
    `endif
14526
 
14527
    `ifdef TEST_BURST_CONFIG_READ
14528
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
14529
 
14530
        data = 32'h0000_04_04 ;
14531
 
14532
        test_name = "TARGET DISCONNECT ON BURST READ FROM CONFIGURATION SPACE" ;
14533
        byte_enables = 4'b0000 ;
14534
 
14535
        fork
14536
        begin
14537
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14538
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
14539
                    byte_enables,
14540
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14541
                    8'h0_0, `Test_One_Zero_Target_WS,
14542
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14543
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14544
            do_pause( 1 ) ;
14545
 
14546
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14547
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
14548
                    byte_enables,
14549
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14550
                    8'h0_0, `Test_One_Zero_Target_WS,
14551
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14552
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14553
            do_pause( 1 ) ;
14554
 
14555
            while ( FRAME !== 1 || IRDY !== 1 )
14556
                @(posedge pci_clock) ;
14557
 
14558
            disable monitor_error_event3 ;
14559
        end
14560
        begin:monitor_error_event3
14561
            ok = 1 ;
14562
            @(error_event_int) ;
14563
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14564
            ok = 0 ;
14565
        end
14566
        join
14567
 
14568
        if ( ok )
14569
            test_ok ;
14570
 
14571
        pci_address  = {20'h0000_0, 1'b1, 11'h00C} ;
14572
        fork
14573
        begin
14574
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14575
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
14576
                    byte_enables,
14577
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14578
                    8'h0_0, `Test_One_Zero_Target_WS,
14579
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14580
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14581
            do_pause( 1 ) ;
14582
 
14583
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14584
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
14585
                    byte_enables,
14586
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14587
                    8'h0_0, `Test_One_Zero_Target_WS,
14588
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14589
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14590
            do_pause( 1 ) ;
14591
 
14592
            while ( FRAME !== 1 || IRDY !== 1 )
14593
                @(posedge pci_clock) ;
14594
 
14595
            disable monitor_error_event4 ;
14596
        end
14597
        begin:monitor_error_event4
14598
            ok = 1 ;
14599
            @(error_event_int) ;
14600
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14601
            ok = 0 ;
14602
        end
14603
        join
14604
 
14605
        if ( ok )
14606
            test_ok ;
14607
    `endif
14608
 
14609
    `ifdef TEST_BURST_CONFIG_READ
14610
        `undef TEST_BURST_CONFIG_READ
14611
    `endif
14612
 
14613
    `ifdef TEST_BURST_CONFIG_WRITE
14614
        `undef TEST_BURST_CONFIG_WRITE
14615
    `endif
14616
 
14617
    master1_check_received_data = 1 ;
14618
    master2_check_received_data = 1 ;
14619
 
14620
    if ( do_mem_disconnects )
14621
    begin
14622
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
14623
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
14624
        if ( ok !== 1 )
14625
        begin
14626
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14627
            test_fail("PCI Base Address register could not be written") ;
14628
            disable main ;
14629
        end
14630
 
14631
        // Set Address Mask of IMAGE
14632
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
14633
        if ( ok !== 1 )
14634
        begin
14635
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14636
            test_fail("PCI Address Mask register could not be written") ;
14637
            disable main ;
14638
        end
14639
 
14640
        // Set Translation Address of IMAGE
14641
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
14642
        if ( ok !== 1 )
14643
        begin
14644
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14645
            test_fail("PCI Translation Address Register could not be written") ;
14646
            disable main ;
14647
        end
14648
 
14649
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14650
        if ( ok !== 1 )
14651
        begin
14652
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14653
            test_fail("PCI Image Control register could not be written") ;
14654
            disable main ;
14655
        end
14656
 
14657
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
14658
        if ( ok !== 1 )
14659
        begin
14660
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14661
            test_fail("Cache Line Size register could not be written") ;
14662
            disable main ;
14663
        end
14664
 
14665
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
14666
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14667
        data = 32'hAAAA_AAAA ;
14668
        byte_enables = 4'h0 ;
14669
        expect_length = `PCIW_DEPTH - 2 ;
14670
 
14671
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14672
        fork
14673
        begin
14674
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
14675
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14676
                        byte_enables,
14677
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
14678
                        8'h0_0, `Test_One_Zero_Target_WS,
14679
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14680
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14681
            do_pause( 3 ) ;
14682
 
14683
            while ( FRAME !== 1 || IRDY !== 1 )
14684
                @(posedge pci_clock) ;
14685
 
14686
            disable monitor_error_event5 ;
14687
        end
14688
        begin:monitor_error_event5
14689
            pci_ok = 1 ;
14690
            @(error_event_int) ;
14691
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14692
            pci_ok = 0 ;
14693
        end
14694
        begin
14695
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14696
            if ( wb_ok !== 1 )
14697
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14698
        end
14699
        join
14700
 
14701
        if ( wb_ok && pci_ok )
14702
            test_ok ;
14703
 
14704
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
14705
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14706
        data = 32'hAAAA_AAAA ;
14707
        byte_enables = 4'h0 ;
14708
        expect_length = `PCIW_DEPTH - 2 ;
14709
 
14710
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14711
        fork
14712
        begin
14713
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
14714
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14715
                        byte_enables,
14716
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
14717
                        8'h0_0, `Test_One_Zero_Target_WS,
14718
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14719
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14720
            do_pause( 3 ) ;
14721
 
14722
            while ( FRAME !== 1 || IRDY !== 1 )
14723
                @(posedge pci_clock) ;
14724
 
14725
            disable monitor_error_event6 ;
14726
        end
14727
        begin:monitor_error_event6
14728
            pci_ok = 1 ;
14729
            @(error_event_int) ;
14730
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14731
            pci_ok = 0 ;
14732
        end
14733
        begin
14734
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14735
            if ( wb_ok !== 1 )
14736
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14737
        end
14738
        join
14739
 
14740
        if ( wb_ok && pci_ok )
14741
            test_ok ;
14742
 
14743
        master1_check_received_data = 1 ;
14744
//        master2_check_received_data = 0 ;
14745
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
14746
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14747
        data = 32'hAAAA_AAAA ;
14748
        byte_enables = 4'h0 ;
14749
        expect_length = 4 ;
14750
 
14751
        fork
14752
        begin
14753
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14754
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14755
                        byte_enables,
14756
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14757
                        8'h0_0, `Test_One_Zero_Target_WS,
14758
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14759
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14760
            do_pause( 1 ) ;
14761
 
14762
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
14763
            if ( wb_ok !== 1 )
14764
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14765
 
14766
            do_pause(2) ;
14767
 
14768
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14769
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14770
                        byte_enables,
14771
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14772
                        8'h0_0, `Test_One_Zero_Target_WS,
14773
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14774
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
14775
            do_pause( 3 ) ;
14776
 
14777
            while ( FRAME !== 1 || IRDY !== 1 )
14778
                @(posedge pci_clock) ;
14779
 
14780
            disable monitor_error_event7 ;
14781
        end
14782
        begin:monitor_error_event7
14783
            pci_ok = 1 ;
14784
            @(error_event_int) ;
14785
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
14786
            pci_ok = 0 ;
14787
        end
14788
        join
14789
 
14790
        if ( wb_ok && pci_ok )
14791
            test_ok ;
14792
 
14793
        master1_check_received_data = 1 ;
14794
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
14795
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14796
        data = 32'hAAAA_AAAA ;
14797
        byte_enables = 4'h0 ;
14798
        expect_length = 4 ;
14799
 
14800
        fork
14801
        begin
14802
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14803
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14804
                        byte_enables,
14805
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14806
                        8'h0_0, `Test_One_Zero_Target_WS,
14807
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14808
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14809
            do_pause( 1 ) ;
14810
 
14811
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
14812
            if ( wb_ok !== 1 )
14813
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14814
 
14815
            do_pause(2) ;
14816
 
14817
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14818
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14819
                        byte_enables,
14820
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14821
                        8'h0_0, `Test_One_Zero_Target_WS,
14822
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14823
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
14824
            do_pause( 3 ) ;
14825
 
14826
            while ( FRAME !== 1 || IRDY !== 1 )
14827
                @(posedge pci_clock) ;
14828
 
14829
            disable monitor_error_event8 ;
14830
        end
14831
        begin:monitor_error_event8
14832
            pci_ok = 1 ;
14833
            @(error_event_int) ;
14834
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
14835
            pci_ok = 0 ;
14836
        end
14837
        join
14838
 
14839
        if ( wb_ok && pci_ok )
14840
            test_ok ;
14841
 
14842
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
14843
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
14844
        data = 32'hDEAF_BEAF ;
14845
        byte_enables = 4'h0 ;
14846
        expect_length = 1 ;
14847
 
14848
        fork
14849
        begin
14850
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
14851
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14852
                        byte_enables,
14853
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14854
                        8'h0_0, `Test_One_Zero_Target_WS,
14855
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14856
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14857
            do_pause( 3 ) ;
14858
 
14859
            while ( FRAME !== 1 || IRDY !== 1 )
14860
                @(posedge pci_clock) ;
14861
 
14862
            disable monitor_error_event9 ;
14863
        end
14864
        begin:monitor_error_event9
14865
            pci_ok = 1 ;
14866
            @(error_event_int) ;
14867
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14868
            pci_ok = 0 ;
14869
        end
14870
        begin
14871
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14872
            if ( wb_ok !== 1 )
14873
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14874
        end
14875
        join
14876
 
14877
        if ( wb_ok && pci_ok )
14878
            test_ok ;
14879
 
14880
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
14881
        data = 32'hDEAD_BEAF ;
14882
        byte_enables = 4'h0 ;
14883
        expect_length = 1 ;
14884
 
14885
        fork
14886
        begin
14887
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
14888
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14889
                        byte_enables,
14890
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14891
                        8'h0_0, `Test_One_Zero_Target_WS,
14892
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14893
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14894
            do_pause( 3 ) ;
14895
 
14896
            while ( FRAME !== 1 || IRDY !== 1 )
14897
                @(posedge pci_clock) ;
14898
 
14899
            disable monitor_error_event10 ;
14900
        end
14901
        begin:monitor_error_event10
14902
            pci_ok = 1 ;
14903
            @(error_event_int) ;
14904
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14905
            pci_ok = 0 ;
14906
        end
14907
        begin
14908
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14909
            if ( wb_ok !== 1 )
14910
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14911
        end
14912
        join
14913
 
14914
        if ( wb_ok && pci_ok )
14915
            test_ok ;
14916
 
14917
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
14918
        data = 32'hAAAA_AAAA ;
14919
        byte_enables = 4'h0 ;
14920
        expect_length = 1 ;
14921
 
14922
        fork
14923
        begin
14924
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
14925
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14926
                        byte_enables,
14927
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14928
                        8'h0_0, `Test_One_Zero_Target_WS,
14929
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14930
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14931
            do_pause( 3 ) ;
14932
 
14933
            while ( FRAME !== 1 || IRDY !== 1 )
14934
                @(posedge pci_clock) ;
14935
 
14936
            disable monitor_error_event11 ;
14937
        end
14938
        begin:monitor_error_event11
14939
            pci_ok = 1 ;
14940
            @(error_event_int) ;
14941
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14942
            pci_ok = 0 ;
14943
        end
14944
        begin
14945
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14946
            if ( wb_ok !== 1 )
14947
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14948
        end
14949
        join
14950
 
14951
        if ( wb_ok && pci_ok )
14952
            test_ok ;
14953
 
14954
        master1_check_received_data = 1 ;
14955
 
14956
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
14957
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
14958
        data = 32'hDEAF_BEAF ;
14959
        byte_enables = 4'h0 ;
14960
        expect_length = 1 ;
14961
 
14962
        fork
14963
        begin
14964
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
14965
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14966
                        byte_enables,
14967
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14968
                        8'h0_0, `Test_One_Zero_Target_WS,
14969
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14970
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14971
            do_pause( 1 ) ;
14972
 
14973
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
14974
            if ( wb_ok !== 1 )
14975
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14976
 
14977
            do_pause(3) ;
14978
 
14979
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
14980
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14981
                        byte_enables,
14982
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14983
                        8'h0_0, `Test_One_Zero_Target_WS,
14984
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14985
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14986
            do_pause( 3 ) ;
14987
 
14988
            while ( FRAME !== 1 || IRDY !== 1 )
14989
                @(posedge pci_clock) ;
14990
 
14991
            disable monitor_error_event12 ;
14992
        end
14993
        begin:monitor_error_event12
14994
            pci_ok = 1 ;
14995
            @(error_event_int) ;
14996
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
14997
            pci_ok = 0 ;
14998
        end
14999
        join
15000
 
15001
        if ( wb_ok && pci_ok )
15002
            test_ok ;
15003
 
15004
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
15005
        data = 32'hDEAD_BEAF ;
15006
        byte_enables = 4'h0 ;
15007
        expect_length = 1 ;
15008
 
15009
        fork
15010
        begin
15011
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15012
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15013
                        byte_enables,
15014
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15015
                        8'h0_0, `Test_One_Zero_Target_WS,
15016
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15017
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15018
            do_pause( 1 ) ;
15019
 
15020
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15021
            if ( wb_ok !== 1 )
15022
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15023
 
15024
            do_pause(3) ;
15025
 
15026
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15027
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15028
                        byte_enables,
15029
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15030
                        8'h0_0, `Test_One_Zero_Target_WS,
15031
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15032
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15033
            do_pause( 3 ) ;
15034
 
15035
            while ( FRAME !== 1 || IRDY !== 1 )
15036
                @(posedge pci_clock) ;
15037
 
15038
            disable monitor_error_event13 ;
15039
        end
15040
        begin:monitor_error_event13
15041
            pci_ok = 1 ;
15042
            @(error_event_int) ;
15043
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15044
            pci_ok = 0 ;
15045
        end
15046
        join
15047
 
15048
        if ( wb_ok && pci_ok )
15049
            test_ok ;
15050
 
15051
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
15052
        data = 32'hAAAA_AAAA ;
15053
        byte_enables = 4'h0 ;
15054
        expect_length = 1 ;
15055
 
15056
        fork
15057
        begin
15058
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15059
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
15060
                        byte_enables,
15061
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15062
                        8'h0_0, `Test_One_Zero_Target_WS,
15063
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15064
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15065
            do_pause( 1 ) ;
15066
 
15067
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15068
            if ( wb_ok !== 1 )
15069
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15070
 
15071
            do_pause(3) ;
15072
 
15073
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15074
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
15075
                        byte_enables,
15076
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15077
                        8'h0_0, `Test_One_Zero_Target_WS,
15078
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15079
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15080
            do_pause( 3 ) ;
15081
 
15082
            while ( FRAME !== 1 || IRDY !== 1 )
15083
                @(posedge pci_clock) ;
15084
 
15085
            disable monitor_error_event14 ;
15086
        end
15087
        begin:monitor_error_event14
15088
            pci_ok = 1 ;
15089
            @(error_event_int) ;
15090
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15091
            pci_ok = 0 ;
15092
        end
15093
        join
15094
 
15095
        if ( wb_ok && pci_ok )
15096
            test_ok ;
15097
 
15098
        // disable the image
15099
        test_name = "DISABLING MEMORY IMAGE" ;
15100
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
15101
        if ( ok !== 1 )
15102
        begin
15103
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15104
            test_fail("PCI Address Mask register could not be written") ;
15105
            disable main ;
15106
        end
15107
    end
15108
//*
15109
    if ( target_io_image !== -1 )
15110
    begin
15111
        do_io_disconnects = 1 ;
15112
 
15113
        if (target_io_image === 1)
15114
        begin
15115
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15116
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15117
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15118
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15119
        end
15120
        else if (target_io_image === 2)
15121
        begin
15122
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15123
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15124
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15125
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15126
        end
15127
        else if (target_io_image === 3)
15128
        begin
15129
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15130
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15131
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15132
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15133
        end
15134
        else if (target_io_image === 4)
15135
        begin
15136
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15137
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15138
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15139
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15140
        end
15141
        else if (target_io_image === 5)
15142
        begin
15143
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15144
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15145
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15146
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15147
        end
15148
    end
15149
    else
15150
        do_io_disconnects = 0 ;
15151
 
15152
    if ( do_io_disconnects )
15153
    begin
15154
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
15155
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
15156
        if ( ok !== 1 )
15157
        begin
15158
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
15159
            test_fail("PCI Base Address register could not be written") ;
15160
            disable main ;
15161
        end
15162
 
15163
        // Set Address Mask of IMAGE
15164
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
15165
        if ( ok !== 1 )
15166
        begin
15167
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15168
            test_fail("PCI Address Mask register could not be written") ;
15169
            disable main ;
15170
        end
15171
 
15172
        // Set Translation Address of IMAGE
15173
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
15174
        if ( ok !== 1 )
15175
        begin
15176
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
15177
            test_fail("PCI Translation Address Register could not be written") ;
15178
            disable main ;
15179
        end
15180
 
15181
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
15182
        if ( ok !== 1 )
15183
        begin
15184
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
15185
            test_fail("PCI Image Control register could not be written") ;
15186
            disable main ;
15187
        end
15188
 
15189
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
15190
        if ( ok !== 1 )
15191
        begin
15192
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
15193
            test_fail("Cache Line Size register could not be written") ;
15194
            disable main ;
15195
        end
15196
 
15197
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
15198
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
15199
        data = 32'h5555_5555 ;
15200
        byte_enables = 4'h0 ;
15201
        expect_length = 1 ;
15202
 
15203
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
15204
 
15205
        fork
15206
        begin
15207
            PCIU_IO_WRITE
15208
            (
15209
                `Test_Master_1,             // which master
15210
                pci_address,                // to what address
15211
                data,                       // data
15212
                byte_enables,               // byte enable
15213
                expect_length + 1,          // length to request
15214
                `Test_Target_Retry_On       // expected target termination
15215
            ) ;
15216
 
15217
            do_pause( 3 ) ;
15218
 
15219
            while ( FRAME !== 1 || IRDY !== 1 )
15220
                @(posedge pci_clock) ;
15221
 
15222
            disable monitor_error_event15 ;
15223
        end
15224
        begin:monitor_error_event15
15225
            pci_ok = 1 ;
15226
            @(error_event_int) ;
15227
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
15228
            pci_ok = 0 ;
15229
        end
15230
        begin
15231
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15232
            if ( wb_ok !== 1 )
15233
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15234
        end
15235
        join
15236
 
15237
        if ( wb_ok && pci_ok )
15238
            test_ok ;
15239
 
15240
        data = 32'hAAAA_AAAA ;
15241
        fork
15242
        begin
15243
            PCIU_IO_WRITE
15244
            (
15245
                `Test_Master_1,             // which master
15246
                pci_address,                // to what address
15247
                data,                       // data
15248
                byte_enables,               // byte enable
15249
                expect_length + 2,          // length to request
15250
                `Test_Target_Retry_Before   // expected target termination
15251
            ) ;
15252
 
15253
            do_pause( 3 ) ;
15254
 
15255
            while ( FRAME !== 1 || IRDY !== 1 )
15256
                @(posedge pci_clock) ;
15257
 
15258
            disable monitor_error_event16 ;
15259
        end
15260
        begin:monitor_error_event16
15261
            pci_ok = 1 ;
15262
            @(error_event_int) ;
15263
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
15264
            pci_ok = 0 ;
15265
        end
15266
        begin
15267
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15268
            if ( wb_ok !== 1 )
15269
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15270
        end
15271
        join
15272
 
15273
        if ( wb_ok && pci_ok )
15274
            test_ok ;
15275
 
15276
        master2_check_received_data = 1 ;
15277
 
15278
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
15279
 
15280
        fork
15281
        begin
15282
 
15283
             PCIU_IO_READ
15284
             (
15285
                `Test_Master_2,
15286
                pci_address[PCI_BUS_DATA_RANGE:0],
15287
                data,
15288
                byte_enables,
15289
                2,
15290
                `Test_Target_Retry_Before
15291
             );
15292
 
15293
            do_pause( 1 ) ;
15294
 
15295
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15296
            if ( wb_ok !== 1 )
15297
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15298
 
15299
            do_pause(3) ;
15300
 
15301
            PCIU_IO_READ
15302
             (
15303
                `Test_Master_2,
15304
                pci_address[PCI_BUS_DATA_RANGE:0],
15305
                data,
15306
                byte_enables,
15307
                expect_length + 1,
15308
                `Test_Target_Retry_On
15309
             );
15310
 
15311
            do_pause( 3 ) ;
15312
 
15313
            while ( FRAME !== 1 || IRDY !== 1 )
15314
                @(posedge pci_clock) ;
15315
 
15316
            disable monitor_error_event17 ;
15317
        end
15318
        begin:monitor_error_event17
15319
            pci_ok = 1 ;
15320
            @(error_event_int) ;
15321
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15322
            pci_ok = 0 ;
15323
        end
15324
        join
15325
 
15326
        if ( wb_ok && pci_ok )
15327
            test_ok ;
15328
 
15329
        fork
15330
        begin
15331
 
15332
             PCIU_IO_READ
15333
             (
15334
                `Test_Master_2,
15335
                pci_address[PCI_BUS_DATA_RANGE:0],
15336
                data,
15337
                byte_enables,
15338
                2,
15339
                `Test_Target_Retry_Before
15340
             );
15341
 
15342
            do_pause( 1 ) ;
15343
 
15344
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15345
            if ( wb_ok !== 1 )
15346
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15347
 
15348
            do_pause(3) ;
15349
 
15350
            PCIU_IO_READ
15351
             (
15352
                `Test_Master_2,
15353
                pci_address[PCI_BUS_DATA_RANGE:0],
15354
                data,
15355
                byte_enables,
15356
                expect_length + 2,
15357
                `Test_Target_Retry_Before
15358
             );
15359
 
15360
            do_pause( 3 ) ;
15361
 
15362
            while ( FRAME !== 1 || IRDY !== 1 )
15363
                @(posedge pci_clock) ;
15364
 
15365
            disable monitor_error_event18 ;
15366
        end
15367
        begin:monitor_error_event18
15368
            pci_ok = 1 ;
15369
            @(error_event_int) ;
15370
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15371
            pci_ok = 0 ;
15372
        end
15373
        join
15374
 
15375
        if ( wb_ok && pci_ok )
15376
            test_ok ;
15377
 
15378
        test_name = "DISABLING IO IMAGE" ;
15379
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
15380
        if ( ok !== 1 )
15381
        begin
15382
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15383
            test_fail("PCI Address Mask register could not be written") ;
15384
            disable main ;
15385
        end
15386
    end
15387
//*/
15388
end
15389
endtask // target_disconnects
15390
 
15391
task target_unsupported_cmds ;
15392
        input [31:0] Address;
15393
        input [2:0]  image_num ;
15394
    reg          ok ;
15395
begin:main
15396
        // PCI IACK behavioral Target must NOT respond!!!
15397
    irq_respond = 0 ;
15398
 
15399
    $display("  ") ;
15400
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
15401
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
15402
    ipci_unsupported_commands_master.master_reference
15403
    (
15404
        Address,                // first part of address in dual address cycle
15405
        Address,                // second part of address in dual address cycle
15406
        `BC_IACK,                       // dual address cycle command
15407
        `BC_IACK,               // normal command
15408
        4'h0,               // byte enables
15409
        32'h1234_5678,      // data
15410
        1'b0,               // make address parity error on first phase of dual address
15411
        1'b0,               // make address parity error on second phase of dual address
15412
        ok                  // result of operation
15413
    ) ;
15414
    if ( ok )
15415
        test_ok ;
15416
    else
15417
    begin
15418
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15419
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
15420
    end
15421
 
15422
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
15423
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
15424
    ipci_unsupported_commands_master.master_reference
15425
    (
15426
        Address,                // first part of address in dual address cycle
15427
        Address,                // second part of address in dual address cycle
15428
        `BC_SPECIAL,            // dual address cycle command
15429
        `BC_SPECIAL,            // normal command
15430
        4'h0,               // byte enables
15431
        32'h1234_5678,      // data
15432
        1'b0,               // make address parity error on first phase of dual address
15433
        1'b0,               // make address parity error on second phase of dual address
15434
        ok                  // result of operation
15435
    ) ;
15436
    if ( ok )
15437
        test_ok ;
15438
    else
15439
    begin
15440
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15441
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
15442
    end
15443
 
15444
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
15445
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
15446
    ipci_unsupported_commands_master.master_reference
15447
    (
15448
        Address,                // first part of address in dual address cycle
15449
        Address,                // second part of address in dual address cycle
15450
        `BC_RESERVED0,          // dual address cycle command
15451
        `BC_RESERVED0,      // normal command
15452
        4'h0,               // byte enables
15453
        32'h1234_5678,      // data
15454
        1'b0,               // make address parity error on first phase of dual address
15455
        1'b0,               // make address parity error on second phase of dual address
15456
        ok                  // result of operation
15457
    ) ;
15458
    if ( ok )
15459
        test_ok ;
15460
    else
15461
    begin
15462
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15463
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
15464
    end
15465
 
15466
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
15467
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
15468
    ipci_unsupported_commands_master.master_reference
15469
    (
15470
        Address,                // first part of address in dual address cycle
15471
        Address,                // second part of address in dual address cycle
15472
        `BC_RESERVED1,          // dual address cycle command
15473
        `BC_RESERVED1,      // normal command
15474
        4'h0,               // byte enables
15475
        32'h1234_5678,      // data
15476
        1'b0,               // make address parity error on first phase of dual address
15477
        1'b0,               // make address parity error on second phase of dual address
15478
        ok                  // result of operation
15479
    ) ;
15480
    if ( ok )
15481
        test_ok ;
15482
    else
15483
    begin
15484
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15485
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
15486
    end
15487
 
15488
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
15489
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
15490
    ipci_unsupported_commands_master.master_reference
15491
    (
15492
        Address,                // first part of address in dual address cycle
15493
        Address,                // second part of address in dual address cycle
15494
        `BC_RESERVED2,          // dual address cycle command
15495
        `BC_RESERVED2,      // normal command
15496
        4'h0,               // byte enables
15497
        32'h1234_5678,      // data
15498
        1'b0,               // make address parity error on first phase of dual address
15499
        1'b0,               // make address parity error on second phase of dual address
15500
        ok                  // result of operation
15501
    ) ;
15502
    if ( ok )
15503
        test_ok ;
15504
    else
15505
    begin
15506
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15507
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
15508
    end
15509
 
15510
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
15511
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
15512
    ipci_unsupported_commands_master.master_reference
15513
    (
15514
        Address,                // first part of address in dual address cycle
15515
        Address,                // second part of address in dual address cycle
15516
        `BC_RESERVED3,          // dual address cycle command
15517
        `BC_RESERVED3,      // normal command
15518
        4'h0,               // byte enables
15519
        32'h1234_5678,      // data
15520
        1'b0,               // make address parity error on first phase of dual address
15521
        1'b0,               // make address parity error on second phase of dual address
15522
        ok                  // result of operation
15523
    ) ;
15524
    if ( ok )
15525
        test_ok ;
15526
    else
15527
    begin
15528
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15529
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
15530
    end
15531
 
15532
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
15533
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
15534
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
15535
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
15536
    ipci_unsupported_commands_master.master_reference
15537
    (
15538
        Address,                // first part of address in dual address cycle
15539
        Address,                // second part of address in dual address cycle
15540
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
15541
        `BC_MEM_WRITE,      // normal command
15542
        4'h0,               // byte enables;
15543
        32'h1234_5678,      // data
15544
        1'b0,               // make address parity error on first phase of dual address
15545
        1'b0,               // make address parity error on second phase of dual address
15546
        ok                  // result of operation
15547
    ) ;
15548
    if ( ok )
15549
        test_ok ;
15550
    else
15551
    begin
15552
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15553
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
15554
    end
15555
 
15556
    irq_respond = 1 ;
15557
 
15558
end
15559
endtask // target_unsupported_cmds
15560
 
15561
task target_completion_expiration ;
15562
    reg   [11:0] pci_ctrl_offset ;
15563
    reg   [11:0] pci_ba_offset ;
15564
    reg   [11:0] pci_am_offset ;
15565
    reg   [11:0] pci_device_ctrl_offset ;
15566
    reg   [11:0] pci_err_cs_offset ;
15567
    reg   [11:0] icr_offset ;
15568
    reg   [11:0] isr_offset ;
15569
    reg   [11:0] lat_tim_cls_offset ;
15570
 
15571
    reg [31:0] temp_val1 ;
15572
    reg [31:0] temp_val2 ;
15573
    reg        ok   ;
15574
 
15575
    reg [31:0] pci_image_base ;
15576
    integer i ;
15577
 
15578
    reg     error_monitor_done ;
15579
begin:main
15580
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15581
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
15582
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
15583
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15584
 
15585
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
15586
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
15587
    lat_tim_cls_offset = 12'hC ;
15588
    pci_device_ctrl_offset    = 12'h4 ;
15589
 
15590
    pci_image_base = Target_Base_Addr_R[1] ;
15591
 
15592
    // enable master & target operation
15593
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
15594
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
15595
    if ( ok !== 1 )
15596
    begin
15597
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
15598
        test_fail("write to PCI Device Control register failed") ;
15599
        disable main ;
15600
    end
15601
 
15602
    // prepare image control register
15603
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
15604
    if ( ok !== 1 )
15605
    begin
15606
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
15607
        test_fail("write to PCI Image Control register failed") ;
15608
        disable main ;
15609
    end
15610
 
15611
    // prepare base address register
15612
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
15613
    if ( ok !== 1 )
15614
    begin
15615
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
15616
        test_fail("write to PCI Base Address register failed") ;
15617
        disable main ;
15618
    end
15619
 
15620
    // write address mask register
15621
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
15622
    if ( ok !== 1 )
15623
    begin
15624
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
15625
        test_fail("write to PCI Address Mask register failed") ;
15626
        disable main ;
15627
    end
15628
 
15629
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
15630
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
15631
    if ( ok !== 1 )
15632
    begin
15633
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
15634
        test_fail("write to PCI Error Control and Status register failed") ;
15635
        disable main ;
15636
    end
15637
 
15638
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
15639
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
15640
    if ( ok !== 1 )
15641
    begin
15642
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
15643
        test_fail("write to Interrupt Control register failed") ;
15644
        disable main ;
15645
    end
15646
 
15647
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
15648
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
15649
    if ( ok !== 1 )
15650
    begin
15651
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
15652
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
15653
        disable main ;
15654
    end
15655
 
15656
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
15657
 
15658
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
15659
    test_name = "FLUSH OF DELAYED READ NOT COMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
15660
 
15661
 
15662
end
15663
endtask // target_completion_expired
15664
 
15665
task config_write ;
15666
    input [11:0] offset ;
15667
    input [31:0] data ;
15668
    input [3:0]  byte_enable ;
15669
    output       ok ;
15670
    `ifdef HOST
15671
    reg   `WRITE_STIM_TYPE   write_data ;
15672
    reg   `WB_TRANSFER_FLAGS write_flags ;
15673
    reg   `WRITE_RETURN_TYPE write_status ;
15674
    `else
15675
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
15676
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
15677
    `endif
15678
    reg in_use ;
15679
    reg [31:0] temp_var ;
15680
begin
15681
    if ( in_use === 1 )
15682
    begin
15683
        $display("config_read task re-entered! Time %t ", $time) ;
15684
        ok = 0 ;
15685
        #20 $stop ;
15686
    end
15687
    else
15688
    begin
15689
        ok = 1 ;
15690
        in_use = 1 ;
15691
    end
15692
    `ifdef HOST
15693
    write_flags                    = 0 ;
15694
    write_flags`INIT_WAITS         = tb_init_waits ;
15695
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
15696
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
15697
 
15698
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
15699
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
15700
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
15701
    write_data`WRITE_SEL                         = byte_enable ;
15702
    write_data`WRITE_TAG_STIM                    = 0 ;
15703
    write_data`WRITE_DATA                        = data ;
15704
 
15705
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
15706
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
15707
    begin
15708
        $display("Write to configuration space failed! Time %t ", $time) ;
15709
        ok = 0 ;
15710
    end
15711
 
15712
    @(posedge wb_clock) ;
15713
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
15714
    // here we just wait for two guest cycles for conf space bits to synchronize
15715
    repeat( 2 )
15716
        @(posedge pci_clock) ;
15717
 
15718
    `else // GUEST
15719
    byte_enables_l = ~byte_enable ;
15720
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
15721
 
15722
    fork
15723
    begin
15724
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
15725
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15726
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
15727
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15728
              8'h0_0, `Test_One_Zero_Target_WS,
15729
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
15730
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
15731
    do_pause( 1 ) ;
15732
    end
15733
    begin
15734
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
15735
        @(posedge pci_clock) ;
15736
    end
15737
    join
15738
 
15739
     repeat( 2 )
15740
         @(posedge wb_clock) ;
15741
 
15742
    `endif
15743
    in_use = 0 ;
15744
end
15745
endtask // config_write
15746
 
15747
task config_read ;
15748
    input [11:0] offset ;
15749
    input [3:0]  byte_enable ;
15750
    output [31:0] data ;
15751
 
15752
    reg `READ_STIM_TYPE    read_data ;
15753
    reg `WB_TRANSFER_FLAGS read_flags ;
15754
    reg `READ_RETURN_TYPE  read_status ;
15755
 
15756
    reg [31:0] pci_address ;
15757
    reg [3:0] byte_enables_l ;
15758
 
15759
    reg master_check_data_prev ;
15760
    reg in_use ;
15761
    reg [31:0] temp_var ;
15762
begin:main
15763
    if ( in_use === 1 )
15764
    begin
15765
        $display("config_read task re-entered! Time %t ", $time) ;
15766
        data = 32'hxxxx_xxxx ;
15767
        disable main ;
15768
    end
15769
 
15770
    in_use = 1 ;
15771
 
15772
`ifdef HOST
15773
    read_flags                    = 0 ;
15774
    read_flags`INIT_WAITS         = tb_init_waits ;
15775
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
15776
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
15777
 
15778
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
15779
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
15780
 
15781
    read_data`READ_ADDRESS  = temp_var + offset ;
15782
    read_data`READ_SEL      = byte_enable ;
15783
    read_data`READ_TAG_STIM = 0 ;
15784
 
15785
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
15786
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
15787
    begin
15788
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
15789
        #20 $stop ;
15790
    end
15791
    data = read_status`READ_DATA ;
15792
`else
15793
  `ifdef GUEST
15794
    master_check_data_prev = master2_check_received_data ;
15795
    master2_check_received_data = 0 ;
15796
 
15797
    byte_enables_l = ~byte_enable ;
15798
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
15799
 
15800
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
15801
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
15802
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
15803
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15804
             8'h4_0, `Test_One_Zero_Target_WS,
15805
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
15806
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
15807
    do_pause( 1 ) ;
15808
 
15809
    @(master2_received_data_valid) ;
15810
    data = master2_received_data ;
15811
 
15812
    master2_check_received_data = master_check_data_prev ;
15813
  `endif
15814
`endif
15815
    in_use = 0 ;
15816
end
15817
endtask //config_read
15818
 
15819
task test_fail ;
15820
    input [7999:0] failure_reason ;
15821
    reg   [8007:0] display_failure ;
15822
    reg   [799:0] display_test ;
15823
begin
15824
    tests_failed = tests_failed + 1 ;
15825
 
15826
    display_failure = {failure_reason, "!"} ;
15827
    while ( display_failure[7999:7992] == 0 )
15828
        display_failure = display_failure << 8 ;
15829
 
15830
    display_test = test_name ;
15831
    while ( display_test[799:792] == 0 )
15832
       display_test = display_test << 8 ;
15833
 
15834
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
15835
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
15836
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
15837
    $fdisplay( tb_log_file, " *FAILED* because") ;
15838
    $fdisplay( tb_log_file, " %s", display_failure ) ;
15839
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
15840
    $fdisplay( tb_log_file, " " ) ;
15841
 
15842
    `ifdef STOP_ON_FAILURE
15843
    #20 $stop ;
15844
    `endif
15845
end
15846
endtask // test_fail
15847
 
15848
task test_ok ;
15849
    reg [799:0] display_test ;
15850
begin
15851
   tests_successfull = tests_successfull + 1 ;
15852
 
15853
   display_test = test_name ;
15854
   while ( display_test[799:792] == 0 )
15855
       display_test = display_test << 8 ;
15856
 
15857
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
15858
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
15859
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
15860
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
15861
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
15862
   $fdisplay( tb_log_file, " " ) ;
15863
end
15864
endtask // test_ok
15865
 
15866
task test_summary;
15867
begin
15868
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
15869
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
15870
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
15871
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
15872
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
15873
    $fclose(tb_log_file) ;
15874
end
15875
endtask
15876
 
15877
endmodule

powered by: WebSVN 2.1.0

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